import string
import os
import re
import collections
from numpy import *
import pymssql
import datetime
import easygui
import math
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
def getmaterial(): #从数据库中导入物料表
L1={}
L=[]
connect = pymssql.connect('DESKTOP-7SPJM8G', 'sa', '123456', 'ERP') #服务器名,账户,密码,数据库名
cursor = connect.cursor() #创建一个游标对象,通过cursor来执行
sql = "select * from 物料表"
cursor.execute(sql) #执行sql语句
row = cursor.fetchone() #读取查询结果,
while row: #循环读取所有结果
L.extend([row])
row = cursor.fetchone()
return L
def getdeploy(): #从数据库中导入调配构成表
L1=[]
connect = pymssql.connect('DESKTOP-7SPJM8G', 'sa', '123456', 'ERP') #服务器名,账户,密码,数据库名
cursor = connect.cursor() #创建一个游标对象,通过cursor来执行
sql = "select * from 调配构成表"
cursor.execute(sql) #执行sql语句
row = cursor.fetchone() #读取查询结果,
while row: #循环读取所有结果
L1.extend([row])
row = cursor.fetchone()
return L1
def GetBOM(): #从数据库中导入BOM
L1=[]
connect = pymssql.connect('DESKTOP-7SPJM8G', 'sa', '123456', 'ERP') #服务器名,账户,密码,数据库名
cursor = connect.cursor() #创建一个游标对象,过cursor来执行
sql = "select * from BOM"
cursor.execute(sql) #执行sql语句
row = cursor.fetchone() #读取查询结果,
while row: #循环读取所有结果
L1.extend([row])
row = cursor.fetchone()
return L1
def lowlevel(x): #找出低一级层次的其所有子物料
L1=[]
connect = pymssql.connect('DESKTOP-7SPJM8G', 'sa', '123456', 'ERP') #服务器名,账户,密码,数据库名
cursor = connect.cursor() #创建一个游标对象,通过cursor来执行
sql = "select * from 调配构成表 where 父物料名称='"+x+"'"
cursor.execute(sql) #执行sql语句
row = cursor.fetchone() #读取查询结果,
while row: #循环读取所有结果
L1.extend([row])
row = cursor.fetchone()
return L1
def findnumber(x,L): #查找商品编号
for a in L:
if a[1]==x:
return a[0]
break
def mps(z,i,x,Lmps): #深度遍历,生成生产计划
i=i+1
L1=lowlevel(x) #找出低一级层次的其所有子物料
for a in L1:
if a[2]==1: #若为生产型
Lmps[len(Lmps)]=createLmps1(z,i,a,Lmps)
x=a[1]
mps(z,i,x,Lmps) #继续遍历
else: #若类型为采购
Lmps[len(Lmps)]=createLmps2(z,i,a,Lmps)
return Lmps
def mps2(b,Ldick,IM1,IM2): #深度遍历,检查所有的中间物料库存使用情况
#print(Ldick)
L1=lowlevel(b[2]) #找出低一级层次的其所有子物料
for i in range(0,len(IM1)): #优先级数值最小的生产型物料使用库存
if b[2]==IM1[i]:
if b[3]>=IM2[i]:
b[3]=b[3]-IM2[i]
IM2[i]=0
else:
IM2[i]=IM2[i]-b[3]
b[3]=0
Ldick[findLmps2(b[2],b[-2],b[-1],Ldick)]=b #修改该生产型的需求数
for a in L1:
#print(a)
if a[2]==1: #若为生产型
Ldick[findLmps2(a[1],b[-2]+1,b[-1],Ldick)]=createLmps1(b[-1],b[-2]+1,a,Ldick) #修改该生产型的生产型子物料需求数
x=findLmps2(a[1],b[-2]+1,b[-1],Ldick)
mps2(Ldick[findLmps2(a[1],b[-2]+1,b[-1],Ldick)],Ldick,IM1,IM2) #继续遍历
else: #若类型为采购
Ldick[findLmps2(a[1],b[-2]+1,b[-1],Ldick)]=createLmps2(b[-1],b[-2]+1,a,Ldick) #修改该采购型的生产型子物料需求数
return Ldick
def createLmps2(z,i,L1,L2): #生成 “采购” 类型的商品的输出格式
Lp=[]
L3=[]
L3=list(L2.values())
#print(L3)
for a in L3:
if a[2]==L1[0] and a[6]==i-1 and a[7]==z:
Lp=a
if len(Lp)==0:
return ''
time=str((datetime.datetime.strptime(Lp[4], '%Y-%m-%d')+datetime.timedelta(days=-(L1[7]+L1[8]+L1[9]))))[0:10]
y=[]
y=['采购',findnumber(str(L1[1]),bom),str(L1[1]),math.ceil(L1[3]*Lp[3]/(1-L1[4])),time,Lp[4],i,z]
return y
def createLmps1(z,i,L1,L2): #生成 “生产” 类型的商品的输出格式
Lp=[]
L3=[]
L3=list(L2.values())
#print(L3)
for a in L3:
if a[2]==L1[0] and a[6]==i-1 and a[7]==z:
Lp=a
time=str((datetime.datetime.strptime(Lp[4], '%Y-%m-%d')+datetime.timedelta(days=-(L1[7]+L1[8]+L1[9]))))[0:10]
y=[]
y=['生产',findnumber(str(L1[1]),bom),str(L1[1]),math.ceil(L1[3]*Lp[3]/(1-L1[4])),time,Lp[4],i,z]
return y
def inventory(): #从数据库中导入库存表
L1={}
L=[]
connect = pymssql.connect('DESKTOP-7SPJM8G', 'sa', '123456', 'ERP') #服务器名,账户,密码,数据库名
cursor = connect.cursor() #创建一个游标对象,python里的sql语句都要通过cursor来执行
sql = "select * from 库存"
cursor.execute(sql) #执行sql语句
row = cursor.fetchone() #读取查询结果,
while row: #循环读取所有结果
L.extend([row])
row = cursor.fetchone()
for a in L:
L1[a[1]]=a[2]+a[3] #计算当前每件商品总库存
return L1
def findLmps2(x,y,z,Ldick): #找到某条数据在Ldick中的位置
i=0
Lmps2=list(Ldick.values())
for a in Lmps2:
if x==a[2] and y==a[6] and z==a[7]:
break
i=i+1
return i
class Table(QWidget): #建立输出表格界面
def __init__(self,parent=None):
super(Table, self).__init__(parent)
#设置标题与初始大小
self.setWindowTitle('MRP计算结果')
self.resize(2000,1000)
#设置数据层次结构,i行6列
self.model=QStandardItemModel(i,6)
#设置水平方向6个头标签文本内容
self.model.setHorizontalHeaderLabels(['调配方式','物料号','物料名称','需求数量','日程下达日期','日程完成日期'])
for row in range(i):
for column in range(6):
a=Lmps2[row]
item=QStandardItem(a[column])
#设置每个位置的文本值
self.model.setItem(row,column,item)
#实例化表格视图,设置模型为自定义的模型
self.tableView=QTableView()
self.tableView.setModel(self.model)
# #水平方向标签拓展剩下的窗口部分,填满表格
self.tableView.horizontalHeader().setStretchLastSection(True)
# #水平方向,表格大小拓展到适当的尺寸
self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
#设置布局
layout=QVBoxLayout()
layout.addWidget(self.tableView)
self.setLayout(layout)
if __name__ == '__main__':
erp1=getdeploy() #得到调配构成表
erp2=getmaterial() #得到物料表
bom=GetBOM() #得到BOM表
IM=inventory() #得到所有商品库存
#print(erp1)
z=1
#L=[['眼镜',100,'2020-05-30'],['眼镜',20,'2020-04-30']]
while 1:
Lt={}
num=easygui.integerbox(msg='请输入想要生产的商品个数:',title='ERP实验')
for i in range(0,num):
Lt[i]=easygui.multenterbox(msg='请输入第'+str(i+1)+'条MPS记录', title='ERP实验', fields=['产品名称','数量','完工日期'])
L=list(Lt.values())
for a in L:
a[1]=int(a[1])
Lmps={}
for k in L:
Lp=[]
k[2]=datetime.datetime.strptime(k[2], '%Y-%m-%d') #将日期由字符型转为时间
电子商务课程ERP实验 python+SQLserver简单实验
需积分: 48 104 浏览量
2020-06-04
11:36:27
上传
评论 4
收藏 254KB RAR 举报
长明Hunch
- 粉丝: 1
- 资源: 2
最新资源
- java-leetcode面试题解Stack之第331题验证二叉树的前序序列化-题解.zip
- 基于matlab实现的免疫粒子群算法用于PID整定 采用线性惯性系数,自适应交叉变异方法.rar
- 基于matlab实现的粒子群算法的实现,二维粒子群算法描述,自适应变异.rar
- 基于matlab实现的和Smulink 制冷空调仿真资料集(资料+代码+案例).rar
- 基于matlab实现的图像特征提取以及匹配,sift代码 可用于图片检索中,同比SURF,其算法可以较好的识别图像中文字.rar
- 基于matlab实现的人脸识别中描述人脸之间的相似性,也不仅仅用于人脸也可以识别图像,文字等 .rar
- 基于matlab实现的遗传算法和BP神经网络控制倒立摆的程序,用遗传算法优化神经网络权值阈值以达到更好的控制效果.rar
- 基于matlab实现的用pso对bp神经网络进行优化,对pid控制器进行优化设计.rar
- P沟道MOSFET场效应管AO3401中文规格书
- 基于matlab实现的运用图像处理计数对文字图片中的汉字进行识别,并统计图片中文字个数.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈