代码拉取完成,页面将自动刷新
import wx
import wx.grid
import wx.lib.intctrl # 限制输入为整数
from sqlconnection import SqlCon
import datetime
import re
from material import Material, MatClass
from user import User
from location import Location
import barcode
from barcode.writer import ImageWriter
import numpy as np
class UserFrame(wx.Frame):
"""
搭建用户界面的固定框架和按键
"""
def __init__(self, parent):
# 建立和数据库sqlite的连接
self.sql_con = SqlCon()
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"胶料管理系统", pos=wx.DefaultPosition, size=wx.Size(1024, 768),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
###############################################################################################################
# 整体框架为纵向排列
bSizer6 = wx.BoxSizer(wx.VERTICAL)
# 1v ###########################################################################################################
# 系统名称
m_staticText6 = wx.StaticText(self, wx.ID_ANY, u"胶 料 管 理 系 统", wx.DefaultPosition, wx.DefaultSize,
wx.ALIGN_CENTER_HORIZONTAL)
m_staticText6.Wrap(-1)
m_staticText6.SetFont(
wx.Font(30, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "黑体"))
bSizer6.Add(m_staticText6, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND, 20)
# 2v1h #########################################################################################################
# 界面左侧的“选择操作”按键区域
self.bSizer7 = wx.BoxSizer(wx.HORIZONTAL) # 该Sizer所含框架会随着按钮的动作发生变化
sbSizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"选择操作"), wx.VERTICAL)
# 2v1h1v #######################################################################################################
# “生成条码”按键
self.m_button2 = wx.Button(sbSizer2.GetStaticBox(), 1, u"生成条码", wx.DefaultPosition, wx.Size(150, 50), 0)
self.m_button2.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
sbSizer2.Add(self.m_button2, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.EXPAND | wx.FIXED_MINSIZE | wx.TOP,
40)
# 2v1h2v #######################################################################################################
# “入库”按键
self.m_button3 = wx.Button(sbSizer2.GetStaticBox(), 2, u"入库", wx.DefaultPosition, wx.Size(-1, 50), 0)
self.m_button3.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
sbSizer2.Add(self.m_button3, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.FIXED_MINSIZE | wx.EXPAND, 40)
# 2v1h3v #######################################################################################################
# “出库”按键
self.m_button4 = wx.Button(sbSizer2.GetStaticBox(), 3, u"出库", wx.DefaultPosition, wx.Size(-1, 50), 0)
self.m_button4.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
sbSizer2.Add(self.m_button4, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.FIXED_MINSIZE | wx.EXPAND, 40)
# 2v1h4v #######################################################################################################
# “盘库”按键
self.m_button5 = wx.Button(sbSizer2.GetStaticBox(), 4, u"库存明细", wx.DefaultPosition, wx.Size(-1, 50), 0)
self.m_button5.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
sbSizer2.Add(self.m_button5, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.FIXED_MINSIZE | wx.EXPAND, 40)
# 2v1h5v #######################################################################################################
# “退出”按键
self.m_button6 = wx.Button(sbSizer2.GetStaticBox(), 5, u"退出", wx.DefaultPosition, wx.Size(-1, 50), 0)
self.m_button6.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
sbSizer2.Add(self.m_button6, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.FIXED_MINSIZE | wx.EXPAND, 40)
# 通过绑定按键的动作来刷新界面
self.Bind(wx.EVT_BUTTON, self.click_button, id=1, id2=5)
self.bSizer7.Add(sbSizer2, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.FIXED_MINSIZE | wx.RIGHT, 10)
bSizer6.Add(self.bSizer7, 1, wx.ALL | wx.EXPAND | wx.FIXED_MINSIZE, 5)
self.SetSizer(bSizer6)
self.Layout()
self.Centre(wx.BOTH)
def __del__(self):
self.sql_con.db_cursor.close()
def click_button(self, event):
"""
监控用户界面左侧按键的动作并切换界面的函数
"""
source_id = event.GetId()
if source_id == 1:
create_code_button = CodeCreate(None)
create_code_button.Show()
self.Close(True)
elif source_id == 2:
user_load_button = UserLoad(None)
user_load_button.Show()
self.Close(True)
elif source_id == 3:
user_unload_button = UserUnload(None)
user_unload_button.Show()
self.Close(True)
elif source_id == 4:
stocktaking_button = Stocktaking(None)
stocktaking_button.Show()
self.Close(True)
elif source_id == 5:
from login import LoginMain
login_button = LoginMain(None)
login_button.Show()
self.Close(True)
event.Skip()
class CodeCreate(UserFrame):
"""
生成条码的界面
"""
def __init__(self, parent):
super().__init__(parent)
self._cls_active = MatClass.cls_active()
# 2v2h #########################################################################################################
# “生产条码”界面框
code_create = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"生成条码"), wx.VERTICAL)
cc_bSizer8 = wx.BoxSizer(wx.VERTICAL)
# 2v2h1v #######################################################################################################
# “ERP编码”和“物料名称”
cc_bSizer9 = wx.BoxSizer(wx.HORIZONTAL)
cc_staticText7 = wx.StaticText(code_create.GetStaticBox(), wx.ID_ANY, u"ERP编码:", wx.DefaultPosition,
wx.Size(120, -1), wx.ALIGN_RIGHT)
cc_staticText7.Wrap(-1)
cc_staticText7.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer9.Add(cc_staticText7, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
cc_choice2Choices = self._cls_active[:, 1] # 自动获取mat_class_info数据库中激活的项目ERP编号
self.cc_choice2 = wx.Choice(code_create.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.Size(200, -1),
cc_choice2Choices, 0)
self.cc_choice2.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.cc_choice2.SetSelection(0)
self.cc_choice2.Bind(wx.EVT_CHOICE, self.cc_choice2OnChoice) # 选定ERP编码后自动更改到对应的物料名称
cc_bSizer9.Add(self.cc_choice2, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.FIXED_MINSIZE, 5)
cc_staticText10 = wx.StaticText(code_create.GetStaticBox(), wx.ID_ANY, u"物料名称:", wx.DefaultPosition,
wx.Size(150, -1), wx.ALIGN_RIGHT)
cc_staticText10.Wrap(-1)
cc_staticText10.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer9.Add(cc_staticText10, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 30)
cc_choice5Choices = self._cls_active[:, 2] # 自动获取mat_class_info数据库中激活的项目胶料名称
self.cc_choice5 = wx.Choice(code_create.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
cc_choice5Choices, 0)
self.cc_choice5.SetSelection(0)
self.cc_choice5.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.cc_choice5.Bind(wx.EVT_CHOICE, self.cc_choice5OnChoice) # 选定物料名称后自动更改到对应的ERP编码
cc_bSizer9.Add(self.cc_choice5, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.FIXED_MINSIZE, 5)
cc_bSizer8.Add(cc_bSizer9, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.EXPAND | wx.FIXED_MINSIZE | wx.TOP,
20)
# 2v2h2v #######################################################################################################
# “批号”、“桶数”和“来源”
cc_bSizer10 = wx.BoxSizer(wx.HORIZONTAL)
cc_staticText8 = wx.StaticText(code_create.GetStaticBox(), wx.ID_ANY, u"批号:", wx.DefaultPosition,
wx.Size(120, -1), wx.ALIGN_RIGHT)
cc_staticText8.Wrap(-1)
cc_staticText8.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer10.Add(cc_staticText8, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.FIXED_MINSIZE, 5)
self.cc_textCtrl2 = wx.TextCtrl(code_create.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition,
wx.Size(250, -1), 0)
self.cc_textCtrl2.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer10.Add(self.cc_textCtrl2, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.FIXED_MINSIZE, 5)
cc_staticText12 = wx.StaticText(code_create.GetStaticBox(), wx.ID_ANY, u"桶数:", wx.DefaultPosition,
wx.Size(120, -1), wx.ALIGN_RIGHT)
cc_staticText12.Wrap(-1)
cc_staticText12.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer10.Add(cc_staticText12, 0, wx.ALIGN_CENTER_VERTICAL | wx.FIXED_MINSIZE | wx.LEFT, 30)
self.cc_textCtrl3 = wx.lib.intctrl.IntCtrl(code_create.GetStaticBox(), wx.ID_ANY, 0, wx.DefaultPosition,
wx.Size(100, -1), 0)
self.cc_textCtrl3.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
cc_bSizer10.Add(self.cc_textCtrl3, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.FIXED_MINSIZE, 5)
cc_bSizer8.Add(cc_bSizer10, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.EXPAND | wx.FIXED_MINSIZE | wx.TOP,
20)
# 2v2h3v #######################################################################################################
# “条码列表”
cc_sbSizer4 = wx.StaticBoxSizer(wx.StaticBox(code_create.GetStaticBox(), wx.ID_ANY, u"条码列表"), wx.VERTICAL)
self.cc_textCtrl4 = wx.TextCtrl(cc_sbSizer4.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition,
wx.Size(400, 350), wx.TE_MULTILINE)
cc_sbSizer4.Add(self.cc_textCtrl4, 0, wx.ALIGN_CENTER | wx.TOP, 20)
# 2v2h4v #######################################################################################################
# “生产条码”和“打印条码”按键
cc_bSizer12 = wx.BoxSizer(wx.HORIZONTAL)
self.cc_button5 = wx.Button(cc_sbSizer4.GetStaticBox(), wx.ID_ANY, u"生成条码", wx.DefaultPosition, wx.DefaultSize,
0)
self.cc_button5.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.cc_button5.Bind(wx.EVT_LEFT_UP, self.cc_button5OnClick)
cc_bSizer12.Add(self.cc_button5, 0, wx.ALL, 5)
self.cc_button6 = wx.Button(cc_sbSizer4.GetStaticBox(), wx.ID_ANY, u"打印条码", wx.DefaultPosition, wx.DefaultSize,
0)
self.cc_button6.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.cc_button6.Bind(wx.EVT_LEFT_UP, self.cc_button6OnClick)
cc_bSizer12.Add(self.cc_button6, 0, wx.ALL, 5)
cc_sbSizer4.Add(cc_bSizer12, 1, wx.ALIGN_CENTER_HORIZONTAL, 5)
cc_bSizer8.Add(cc_sbSizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 5)
code_create.Add(cc_bSizer8, 1, wx.EXPAND | wx.FIXED_MINSIZE, 5)
self.bSizer7.Add(code_create, 1, wx.EXPAND | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10)
def cc_choice2OnChoice(self, event):
"""
更改ERP编码下拉菜单后,物料名称随之改变
"""
self.cc_choice5.SetSelection(self.cc_choice2.GetSelection())
event.Skip()
def cc_choice5OnChoice(self, event):
"""
更改物料名称下拉菜单后,ERP编码随之改变
"""
self.cc_choice2.SetSelection(self.cc_choice5.GetSelection())
event.Skip()
def cc_button5OnClick(self, event):
"""
“生成条码”按键点击后读取数据库barcode内容,并且按照桶数生成新的barcode,显示并保存到数据库
mat_info里,barcode的定义规则“D年月日C类编号M顺序号"
:param event:
:return:
"""
date_today = datetime.datetime.now().strftime("%y%m%d")
class_id = 'C' + str(self._cls_active[self.cc_choice5.GetSelection(), 0])
max_barcode = Material.max_barcode_per_day(date_today)
if max_barcode:
first_num = int(re.search(r'M(\d*)$', max_barcode[0]).group(1)) + 1
else:
first_num = 1
barcode_list = ['D' + date_today + class_id + 'M' + str(first_num + i)
for i in range(self.cc_textCtrl3.GetValue())]
self.cc_textCtrl4.SetValue('\n'.join(barcode_list))
for barcode_element in barcode_list:
mat = Material(cls_id=self._cls_active[self.cc_choice5.GetSelection(), 0],
batch_num=self.cc_textCtrl2.GetValue(),
barcode=barcode_element)
print('mat:', mat)
mat.mat_register()
for i in barcode_list:
barcode_image = barcode.get('code128', i, writer=ImageWriter())
barcode_image.save(r'.\barcode_image\\'+i)
event.Skip()
def cc_button6OnClick(self, event):
pattern = re.compile(r'D\d{6}C\d*M\d*')
results = pattern.findall(self.cc_textCtrl4.GetValue())
for i in results:
printout = MyPrintout(self, i)
printer = wx.Printer() # 第一步创建预览设备
printer.Print(self, printout)
event.Skip()
class MyPrintout(wx.Printout):
def __init__(self, canvas, filename):
wx.Printout.__init__(self)
self.canvas = canvas
self.filename = filename
def OnBeginDocument(self, start, end):
return super(MyPrintout, self).OnBeginDocument(start, end)
def OnEndDocument(self):
super(MyPrintout, self).OnEndDocument()
def OnBeginPrinting(self):
super(MyPrintout, self).OnBeginPrinting()
def OnEndPrinting(self):
super(MyPrintout, self).OnEndPrinting()
def OnPreparePrinting(self):
super(MyPrintout, self).OnPreparePrinting()
def OnPrintPage(self, page):
dc = self.GetDC()
mat_info = Material(barcode=self.filename)
mat_info.mat_search()
img = wx.Image(r'.\barcode_image\\'+self.filename+'.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
dc.DrawBitmap(img, (dc.GetSize()[0]-img.GetSize()[0])/2, 0, False)
txt = u'名称: {}\n规格: {}\n批号: {}'.format(mat_info.cls_name, mat_info.cls_spec, mat_info.batch_num)
dc.DrawText(txt, (dc.GetSize()[0]-img.GetSize()[0])/2, img.GetSize()[1])
return True
class UserLoad(UserFrame):
"""
入库界面
"""
def __init__(self, parent):
super().__init__(parent)
self._user_active = User.user_active()
# 2v2h #########################################################################################################
# “入库”界面框
user_load = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"入库"), wx.VERTICAL)
ul_bSizer1 = wx.BoxSizer(wx.VERTICAL)
# 2v2h1v ######################################################################################################
# “条码输入区”
self.ul_staticText1 = wx.StaticText(user_load.GetStaticBox(), wx.ID_ANY, u"条码输入区(注:不超过99桶)",
wx.DefaultPosition, wx.DefaultSize, 0)
self.ul_staticText1.Wrap(-1)
self.ul_staticText1.SetFont(
wx.Font(20, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
ul_bSizer1.Add(self.ul_staticText1, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.ul_textCtrl1 = wx.TextCtrl(user_load.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition,
wx.Size(400, 200), wx.TE_MULTILINE)
self.ul_textCtrl1.SetFocus()
ul_bSizer1.Add(self.ul_textCtrl1, 0, wx.ALIGN_CENTER | wx.TOP, 5)
# 2v2h2v #######################################################################################################
# “入库人”
ul_bSizer9 = wx.BoxSizer(wx.HORIZONTAL)
self.ul_staticText61 = wx.StaticText(user_load.GetStaticBox(), wx.ID_ANY, u"入库人:", wx.DefaultPosition,
wx.DefaultSize, 0)
self.ul_staticText61.Wrap(-1)
self.ul_staticText61.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
ul_bSizer9.Add(self.ul_staticText61, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
ul_choice2Choices = self._user_active[:, 1]
self.ul_choice2 = wx.Choice(user_load.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
ul_choice2Choices, 0)
self.ul_choice2.SetSelection(0)
self.ul_choice2.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
ul_bSizer9.Add(self.ul_choice2, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
ul_choice3Choices = self._user_active[:, 1]
self.ul_choice3 = wx.Choice(user_load.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
ul_choice3Choices, 0)
self.ul_choice3.SetSelection(0)
self.ul_choice3.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
ul_bSizer9.Add(self.ul_choice3, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
ul_bSizer1.Add(ul_bSizer9, 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
# 2v2h3v ######################################################################################################
# “入库汇总”
ul_sbSizer4 = wx.StaticBoxSizer(wx.StaticBox(user_load.GetStaticBox(), wx.ID_ANY, u"入库汇总"), wx.VERTICAL)
ul_bSizer10 = wx.BoxSizer(wx.VERTICAL)
self.ul_grid1 = wx.grid.Grid(ul_sbSizer4.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.Size(-1, 200), 0)
# Grid
self.ul_grid1.CreateGrid(99, 8)
self.ul_grid1.EnableEditing(False)
self.ul_grid1.EnableGridLines(True)
self.ul_grid1.EnableDragGridSize(False)
self.ul_grid1.SetMargins(0, 0)
# Columns
self.ul_grid1.EnableDragColMove(False)
self.ul_grid1.EnableDragColSize(True)
self.ul_grid1.SetColLabelSize(30)
self.ul_grid1.SetColLabelValue(0, u"ERP编码")
self.ul_grid1.SetColLabelValue(1, u"胶料名称")
self.ul_grid1.SetColLabelValue(2, u"规格型号")
self.ul_grid1.SetColLabelValue(3, u"批号")
self.ul_grid1.SetColLabelValue(4, u"桶数")
self.ul_grid1.SetColLabelValue(5, u"来源")
self.ul_grid1.SetColLabelValue(6, u"质量状态")
self.ul_grid1.SetColLabelValue(7, u"入库人")
self.ul_grid1.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Rows
self.ul_grid1.EnableDragRowSize(True)
self.ul_grid1.SetRowLabelSize(30)
self.ul_grid1.SetRowLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Cell Defaults
self.ul_grid1.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.ul_grid1.AutoSizeColumns(True)
ul_bSizer10.Add(self.ul_grid1, 0, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
ul_bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.ul_button1 = wx.Button(ul_sbSizer4.GetStaticBox(), wx.ID_ANY, u"入库确认", wx.DefaultPosition, wx.DefaultSize,
0)
self.ul_button1.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.ul_button1.Bind(wx.EVT_BUTTON, self.ul_button1OnClick)
ul_bSizer2.Add(self.ul_button1, 0, wx.ALL, 5)
ul_bSizer10.Add(ul_bSizer2, 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
ul_sbSizer4.Add(ul_bSizer10, 1, wx.EXPAND, 5)
ul_bSizer1.Add(ul_sbSizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 5)
user_load.Add(ul_bSizer1, 1, wx.EXPAND | wx.FIXED_MINSIZE, 5)
self.bSizer7.Add(user_load, 1, wx.EXPAND | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(1000)
self.grid_content = []
def OnTimer(self, event):
"""
自动读取条码框中符合格式要求的barcode码,并自动显示入库信息
:param event:
:return:
"""
pattern = re.compile(r'D\d{6}C\d*M\d*')
results = set(pattern.findall(self.ul_textCtrl1.GetValue()))
grid_content = []
grid_content_display = []
for result in results:
mat_info = Material(barcode=result)
if not mat_info.mat_search():
continue
flow_result = mat_info.flow_status()
if flow_result:
if flow_result[5] == '出库':
location = flow_result[6]
else:
raise Exception('胶料已经入库,不能再次入库!')
else:
location = 1
grid_content.append((mat_info.erp_code, mat_info.cls_name, mat_info.cls_spec, mat_info.batch_num,
location, mat_info.mat_quality_status,
self.ul_choice2.GetStringSelection() + '/' + self.ul_choice3.GetStringSelection(),
mat_info.mat_id))
grid_content_display.append((mat_info.erp_code, mat_info.cls_name, mat_info.cls_spec, mat_info.batch_num,
location, mat_info.mat_quality_status,
self.ul_choice2.GetStringSelection() + '/'
+ self.ul_choice3.GetStringSelection()))
self.grid_content = grid_content
grid_display = [(i, grid_content_display.count(i)) for i in set(grid_content_display)]
for i in range(len(grid_display)):
loc_name = Location(loc_id=grid_display[i][0][4])
self.ul_grid1.SetCellValue(
i, 0, '{}'.format(grid_display[i][0][0] if grid_display[i][0][0] == 0 or grid_display[i][0][0] else ''))
self.ul_grid1.SetCellValue(
i, 1, '{}'.format(grid_display[i][0][1] if grid_display[i][0][1] == 0 or grid_display[i][0][1] else ''))
self.ul_grid1.SetCellValue(
i, 2, '{}'.format(grid_display[i][0][2] if grid_display[i][0][2] == 0 or grid_display[i][0][2] else ''))
self.ul_grid1.SetCellValue(
i, 3, '{}'.format(grid_display[i][0][3] if grid_display[i][0][3] == 0 or grid_display[i][0][3] else ''))
self.ul_grid1.SetCellValue(
i, 4, '{}'.format(grid_display[i][1] if grid_display[i][1] == 0 or grid_display[i][1] else ''))
self.ul_grid1.SetCellValue(i, 5, loc_name.loc_match()[0])
self.ul_grid1.SetCellValue(
i, 6, '{}'.format(grid_display[i][0][5] if grid_display[i][0][5] == 0 or grid_display[i][0][5] else ''))
self.ul_grid1.SetCellValue(
i, 7, '{}'.format(grid_display[i][0][6] if grid_display[i][0][6] == 0 or grid_display[i][0][6] else ''))
self.ul_grid1.AutoSizeColumns(True)
event.Skip()
def ul_button1OnClick(self, event):
datetime_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for i in self.grid_content:
load = Material(mat_id=i[-1])
load.loading(self._user_active[self.ul_choice2.GetSelection(), 0],
self._user_active[self.ul_choice3.GetSelection(), 0], datetime_now, i[4])
self.ul_textCtrl1.Clear()
self.ul_grid1.ClearGrid()
event.Skip()
class UserUnload(UserFrame):
"""
出库界面
"""
def __init__(self, parent):
super().__init__(parent)
self._user_active = User.user_active()
self._loc_active = Location.loc_active()
# 2v2h #########################################################################################################
# “出库”界面框
user_unload = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"出库"), wx.VERTICAL)
uu_bSizer1 = wx.BoxSizer(wx.VERTICAL)
# 2v2h1v #######################################################################################################
# “条码输入区”
self.uu_staticText1 = wx.StaticText(user_unload.GetStaticBox(), wx.ID_ANY, u"条码输入区(注:不超过99桶)",
wx.DefaultPosition, wx.DefaultSize, 0)
self.uu_staticText1.Wrap(-1)
self.uu_staticText1.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer1.Add(self.uu_staticText1, 0, wx.ALIGN_CENTER | wx.ALL, 5)
self.uu_textCtrl1 = wx.TextCtrl(user_unload.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition,
wx.Size(400, 200), wx.TE_MULTILINE)
self.uu_textCtrl1.SetFocus()
uu_bSizer1.Add(self.uu_textCtrl1, 0, wx.ALIGN_CENTER | wx.BOTTOM, 30)
uu_bSizer9 = wx.BoxSizer(wx.HORIZONTAL)
# 2v2h2v #######################################################################################################
# “出库人”和“出库地”
self.uu_staticText61 = wx.StaticText(user_unload.GetStaticBox(), wx.ID_ANY, u"出库人:", wx.DefaultPosition,
wx.DefaultSize, 0)
self.uu_staticText61.Wrap(-1)
self.uu_staticText61.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer9.Add(self.uu_staticText61, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 80)
uu_choice2Choices = self._user_active[:, 1]
self.uu_choice2 = wx.Choice(user_unload.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
uu_choice2Choices, 0)
self.uu_choice2.SetSelection(0)
self.uu_choice2.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer9.Add(self.uu_choice2, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
uu_choice3Choices = self._user_active[:, 1]
self.uu_choice3 = wx.Choice(user_unload.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
uu_choice3Choices, 0)
self.uu_choice3.SetSelection(0)
self.uu_choice3.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer9.Add(self.uu_choice3, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.uu_staticText7 = wx.StaticText(user_unload.GetStaticBox(), wx.ID_ANY, u"出库地:", wx.DefaultPosition,
wx.DefaultSize, 0)
self.uu_staticText7.Wrap(-1)
self.uu_staticText7.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer9.Add(self.uu_staticText7, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT, 100)
m_choice4Choices = self._loc_active[:, 1]
self.m_choice4 = wx.Choice(user_unload.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
m_choice4Choices, 0)
self.m_choice4.SetSelection(0)
self.m_choice4.SetFont(
wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
uu_bSizer9.Add(self.m_choice4, 0, wx.ALL, 5)
uu_bSizer1.Add(uu_bSizer9, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND, 5)
# 2v2h3v #######################################################################################################
# “出库汇总”
uu_sbSizer4 = wx.StaticBoxSizer(wx.StaticBox(user_unload.GetStaticBox(), wx.ID_ANY, u"出库汇总"), wx.VERTICAL)
uu_bSizer10 = wx.BoxSizer(wx.VERTICAL)
self.uu_grid1 = wx.grid.Grid(uu_sbSizer4.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.Size(-1, 200), 0)
# Grid
self.uu_grid1.CreateGrid(99, 8)
self.uu_grid1.EnableEditing(False)
self.uu_grid1.EnableGridLines(True)
self.uu_grid1.EnableDragGridSize(False)
self.uu_grid1.SetMargins(0, 0)
# Columns
self.uu_grid1.AutoSizeColumns()
self.uu_grid1.EnableDragColMove(False)
self.uu_grid1.EnableDragColSize(True)
self.uu_grid1.SetColLabelSize(30)
self.uu_grid1.SetColLabelValue(0, u"ERP编码")
self.uu_grid1.SetColLabelValue(1, u"胶料名称")
self.uu_grid1.SetColLabelValue(2, u"规格型号")
self.uu_grid1.SetColLabelValue(3, u"批号")
self.uu_grid1.SetColLabelValue(4, u"桶数")
self.uu_grid1.SetColLabelValue(5, u"出库地")
self.uu_grid1.SetColLabelValue(6, u"质量状态")
self.uu_grid1.SetColLabelValue(7, u"出库人")
self.uu_grid1.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Rows
self.uu_grid1.AutoSizeRows()
self.uu_grid1.EnableDragRowSize(True)
self.uu_grid1.SetRowLabelSize(80)
self.uu_grid1.SetRowLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Cell Defaults
self.uu_grid1.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.uu_grid1.AutoSizeColumns(True)
uu_bSizer10.Add(self.uu_grid1, 0, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
uu_bSizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.uu_button1 = wx.Button(uu_sbSizer4.GetStaticBox(), wx.ID_ANY, u"出库确认", wx.DefaultPosition, wx.DefaultSize,
0)
self.uu_button1.SetFont(
wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))
self.uu_button1.Bind(wx.EVT_BUTTON, self.uu_button1OnClick)
uu_bSizer2.Add(self.uu_button1, 0, wx.ALL, 5)
uu_bSizer10.Add(uu_bSizer2, 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
uu_sbSizer4.Add(uu_bSizer10, 1, wx.EXPAND, 5)
uu_bSizer1.Add(uu_sbSizer4, 1, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, 5)
user_unload.Add(uu_bSizer1, 1, wx.EXPAND | wx.FIXED_MINSIZE, 5)
self.bSizer7.Add(user_unload, 1, wx.EXPAND | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(1000)
self.grid_content = []
def OnTimer(self, event):
"""
自动读取条码框中符合格式要求的barcode码,并自动显示出库信息
:param event:
:return:
"""
_pattern = re.compile(r'D\d{6}C\d*M\d*')
_results = set(_pattern.findall(self.uu_textCtrl1.GetValue()))
grid_content = []
grid_content_display = []
for _result in _results:
mat_info = Material(barcode=_result)
if not mat_info.mat_search():
continue
flow_result = mat_info.flow_status()
if flow_result[5] == '入库':
grid_content.append((mat_info.erp_code, mat_info.cls_name, mat_info.cls_spec, mat_info.batch_num,
self._loc_active[self.m_choice4.GetSelection(), 0],
mat_info.mat_quality_status,
self.uu_choice2.GetStringSelection() + '/' + self.uu_choice3.GetStringSelection(),
mat_info.mat_id))
grid_content_display.append(
(mat_info.erp_code, mat_info.cls_name, mat_info.cls_spec, mat_info.batch_num,
self.m_choice4.GetStringSelection(), mat_info.mat_quality_status,
self.uu_choice2.GetStringSelection() + '/' + self.uu_choice3.GetStringSelection()))
else:
raise Exception('没有入库信息,不能出库!!')
self.grid_content = grid_content
grid_display = [(i, grid_content_display.count(i)) for i in set(grid_content_display)]
for i in range(len(grid_display)):
self.uu_grid1.SetCellValue(
i, 0, '{}'.format(grid_display[i][0][0] if grid_display[i][0][0] == 0 or grid_display[i][0][0] else ''))
self.uu_grid1.SetCellValue(
i, 1, '{}'.format(grid_display[i][0][1] if grid_display[i][0][1] == 0 or grid_display[i][0][1] else ''))
self.uu_grid1.SetCellValue(
i, 2, '{}'.format(grid_display[i][0][2] if grid_display[i][0][2] == 0 or grid_display[i][0][2] else ''))
self.uu_grid1.SetCellValue(
i, 3, '{}'.format(grid_display[i][0][3] if grid_display[i][0][3] == 0 or grid_display[i][0][3] else ''))
self.uu_grid1.SetCellValue(
i, 4, '{}'.format(grid_display[i][1] if grid_display[i][1] == 0 or grid_display[i][1] else ''))
self.uu_grid1.SetCellValue(
i, 5, '{}'.format(grid_display[i][0][4] if grid_display[i][0][4] == 0 or grid_display[i][0][4] else ''))
self.uu_grid1.SetCellValue(
i, 6, '{}'.format(grid_display[i][0][5] if grid_display[i][0][5] == 0 or grid_display[i][0][5] else ''))
self.uu_grid1.SetCellValue(
i, 7, '{}'.format(grid_display[i][0][6] if grid_display[i][0][6] == 0 or grid_display[i][0][6] else ''))
self.uu_grid1.AutoSizeColumns(True)
event.Skip()
def uu_button1OnClick(self, event):
datetime_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for i in self.grid_content:
unload = Material(mat_id=i[-1])
unload.unloading(self._user_active[self.uu_choice2.GetSelection(), 0],
self._user_active[self.uu_choice3.GetSelection(), 0], datetime_now, i[4])
self.uu_textCtrl1.Clear()
self.uu_grid1.ClearGrid()
event.Skip()
class Stocktaking(UserFrame):
"""
盘库界面
"""
def __init__(self, parent):
super().__init__(parent)
stocktaking = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"库存明细"), wx.VERTICAL)
self.ss_grid1 = wx.grid.Grid(self, wx.ID_ANY, wx.DefaultPosition, wx.Size(-1, 100), 0)
# Grid
self.ss_grid1.CreateGrid(999, 7)
self.ss_grid1.EnableEditing(True)
self.ss_grid1.EnableGridLines(True)
self.ss_grid1.EnableDragGridSize(False)
self.ss_grid1.SetMargins(0, 0)
# Columns
self.ss_grid1.EnableDragColMove(False)
self.ss_grid1.EnableDragColSize(True)
self.ss_grid1.SetColLabelSize(30)
self.ss_grid1.SetColLabelValue(0, u"Barcode")
self.ss_grid1.SetColLabelValue(1, u"胶料名称")
self.ss_grid1.SetColLabelValue(2, u"规格")
self.ss_grid1.SetColLabelValue(3, u"批号")
self.ss_grid1.SetColLabelValue(4, u"质量状态")
self.ss_grid1.SetColLabelValue(5, u"质量明细")
self.ss_grid1.SetColLabelValue(6, u"呆滞天数")
self.ss_grid1.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Rows
self.ss_grid1.EnableDragRowSize(True)
self.ss_grid1.SetRowLabelSize(30)
self.ss_grid1.SetRowLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
# Cell Defaults
self.ss_grid1.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
results = Material.mat_in_stock() # 获取在库的胶料信息
if results.size > 0:
grid_display = []
grid_cls_name = []
grid_cls_spec_int = []
for result in results:
mat_stock = Material(mat_id=result[0])
mat_stock.mat_search()
dead_time = datetime.datetime.now() - datetime.datetime.strptime(result[1], '%Y-%m-%d %H:%M:%S')
grid_display.append((mat_stock.barcode, mat_stock.cls_name, mat_stock.cls_spec, mat_stock.batch_num,
mat_stock.mat_quality_status, mat_stock.mat_quality_detail,
'{:2d}'.format(dead_time.days))) # 整数改为字符串,可正常排序
grid_cls_name.append(mat_stock.cls_name)
grid_cls_spec_int.append(mat_stock.cls_spec_int)
grid_display_np = np.array(grid_display)
ind = np.lexsort((grid_display_np[:, 6], grid_display_np[:, 1]))[::-1] # 按照胶料名称和呆滞时间排逆序
grid_display_np = grid_display_np[ind]
for i in range(grid_display_np.shape[0]):
for j in range(grid_display_np.shape[1]):
a = grid_display_np[i, j]
self.ss_grid1.SetCellValue(i, j, '{}'.format(a if a == 0 or a else ''))
self.ss_grid1.AutoSizeColumns(True)
stocktaking.Add(self.ss_grid1, 1, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
self.bSizer7.Add(stocktaking, 1, wx.EXPAND | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10)
if __name__ == '__main__':
app = wx.App(False)
user_frame = UserFrame(None)
user_frame.Show()
app.MainLoop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。