UI界面作为主入口
#coding:utf8 #!/usr/bin/env python #@author: 9527 import wx import PicturepackageUI import QueryProjectCodeList import ProjectNumberManager import PronjectInfoQuery import json class MainFrame(wx.Frame): """从wx.Frame派生主窗口类""" def __init__(self, parent): """构造函数""" wx.Frame.__init__(self, parent, style=wx.DEFAULT_FRAME_STYLE) #*********************** self.ButtonValue1 = '' #*********************** self.SetTitle('项目编码管理工具') self.SetIcon(PicturepackageUI.find_png.GetIcon()) self.SetSize((750,420)) # 设置窗口大小,宽750*高420 self._init_ui() # 初始化界面 self.Center() # 窗口在屏幕上居中 #*************************************** #绘制界面 def _init_ui(self): """初始化界面""" panel = wx.Panel(self, -1) # 创建容器面板 sizer = wx.GridBagSizer(10, 10)# 每个控件之间横纵间隔10像素 #***************************************************************** st = wx.StaticText(panel, -1, "选择产品线") sizer.Add(st, (1, 0), flag=wx.ALIGN_RIGHT) # 在第1行0列,右对齐 self.professional = wx.ComboBox(panel, -1, choices=self.Get_ProductLineInfo()) self.professional.Bind(wx.EVT_COMBOBOX, self.on_select) sizer.Add(self.professional, (1, 1), (1, 3), flag=wx.EXPAND| wx.RIGHT, border=20) # 在第1行1列,跨3列 #************************************************* #已存在编码显示 st2 = wx.StaticText(panel, -1, "禅道已有\n项目编码") sizer.Add(st2, (3, 0), flag=wx.ALIGN_RIGHT | wx.LEFT, border=20) # 在第3行0列,距离左边缘20像素,右对齐 self.ExistingCode = wx.TextCtrl(panel, -1,size=(-1,200),style=wx.TE_MULTILINE)#静态文本框宽度自适应,高度50 sizer.Add(self.ExistingCode, (3, 1), (1, 3), flag=wx.EXPAND| wx.RIGHT, border=20) # 在第2行1列,跨3列 self.ExistingCode.Bind(wx.EVT_LISTBOX, self.OnCopy)#绑定复制等右键菜单功能 #************************************************** #可用新编码 st = wx.StaticText(panel, -1, "可用编码") sizer.Add(st, (2, 0), flag=wx.ALIGN_RIGHT | wx.LEFT, border=20) # 在第2行0列,距离左边缘20像素,右对齐 self.NewCreateCode = wx.TextCtrl(panel, -1,size=(-1, 50),style=wx.TE_MULTILINE)#静态文本框宽度自适应,高度50 sizer.Add(self.NewCreateCode, (2, 1), (1, 3), flag=wx.EXPAND| wx.RIGHT, border=20) # 在第2行1列,跨3列 self.NewCreateCode.Bind(wx.EVT_LISTBOX, self.OnCopy)#绑定复制等右键菜单功能 sizer.AddGrowableCol(3) # 设置第3列可增长 #******************************************* #信息输入框 self.QuerySerialInfo1 = wx.TextCtrl(panel, -1,value = "请输入要查询的编码") sizer.Add(self.QuerySerialInfo1, (1, 4), (1, 11), flag=wx.EXPAND | wx.RIGHT, border=30) # 在第1行4列,跨3列,距离右边缘30像素 #查询按钮 btn_query = wx.Button(panel, -1, "查询") sizer.Add(btn_query, (2, 4), (1, 9), flag=wx.ALIGN_CENTER | wx.BOTTOM, border=20) # 在第4行0列,跨4列, 居中 btn_query.Bind(wx.EVT_BUTTON,self.get_queryinputinfo) #显示查询结果信息 self.queryresult1 = wx.TextCtrl(panel, -1,size=(-1,200),style=wx.TE_MULTILINE)#静态文本框宽度自适应,高度200 sizer.Add(self.queryresult1, (3, 4), (1, 11), flag=wx.EXPAND| wx.RIGHT, border=20) # 在第2行1列,跨3列 self.queryresult1.Bind(wx.EVT_LISTBOX, self.OnCopy)#绑定复制等右键菜单功能 #******************************************* panel.SetSizer(sizer) panel.Layout() #****************************************** #定义各种操作实现方法 #触发查询信息操作生效,基于此,查询与显示 def get_queryinputinfo(self,event): InfoGroup = ["项目信息查询结果\n"] queryinputinfo = self.QuerySerialInfo1.GetValue() A = PronjectInfoQuery.PronjectInfoQuery(queryinputinfo) B = A.format_data() try : for key, value in B.items(): InfoGroup.append(key + ':' + str(value)) except: InfoGroup = B pass self.queryresult1.SetValue("\n".join(InfoGroup))#设置文本框内 #触发选择产品线信息生效,基于此,查询与显示 def on_select(self,event): selectresult= self.professional.GetValue() choices = self.Get_ExistingProjectNumber(selectresult) self.ExistingCode.SetValue("\n".join(choices))#设置已存在编码文本框内容 #wx.TextCtrl不支持显示列表,用join转换为字符串 choices1 = self.Create_NewCode(selectresult)#获取创建的新项目编码 self.NewCreateCode.SetValue(choices1)#设置新编码文本框内容 #复制方法 def OnCopy(self, event): text_ctrl = event.GetEventObject() menu = wx.Menu() menu.Append(wx.ID_COPY, 'Copy') text_ctrl.PopupMenu(menu) wx.TheClipboard.Open() wx.TheClipboard.SetData(wx.TextDataObject(text_ctrl.GetValue())) wx.TheClipboard.Close() #创建新编码 def Create_NewCode(self,ProductLine): Product01 = ProjectNumberManager.Generate_Project_Num(ProductLine) NewCode = Product01.generate_project_code() return NewCode #获取产品线组列表 def Get_ProductLineInfo(self): with open('ProductLineDict.json', 'r',encoding='utf-8') as f: data = json.load(f) keys_list = list(data.keys()) return keys_list #获取当前产品线已存在项目编码列表 def Get_ExistingProjectNumber(self,ProductLine): QueryExistingList = QueryProjectCodeList.QueryProjectCodeList(ProductLine) QueryExistingResult = QueryExistingList.QueryList() data_list = [x[0] for x in QueryExistingResult] return data_list #*********************************************************************************** if __name__ == '__main__': app = wx.App() frame = MainFrame(None) frame.Show() app.MainLoop()
项目可用编码管理模块
#coding:utf8 #!/usr/bin/env python #@author: 9527 import re import datetime import DatabaseQuery import json #项目编号生成 class Generate_Project_Num(): def __init__(self,ProductLinName): self.ProductLine = ProductLinName self.product = self.get_ProductLine(self.ProductLine) self.year = self.get_year() self.serial_number = self.get_serialNumber() #获取产品线对应简称 def get_ProductLine(self,ProuctLine): with open('ProductLineDict.json', 'r',encoding='utf-8') as f: data = json.load(f) value = data.get(self.ProductLine) return value #确认当前年份信息 def get_year(self): currentyear = datetime.datetime.now().year return currentyear #确认序列号 def get_serialNumber(self): serialNumber = 0 while True: #str(serialNumber).zfill(3)设置显示样式为3位,如5显示为005 project_code = "XXXX-" + self.product +"-"+ str(self.year) +"-"+str(serialNumber).zfill(3)#校验三位尾数 project_code1 = "XXXX-" + self.product +"-"+ str(self.year) +"-"+str(serialNumber).zfill(4)#校验四位尾数 sql = "SELECT code FROM zt_project WHERE code='%s'"%project_code sql1 = "SELECT code FROM zt_project WHERE code='%s'"%project_code1 Query1 = DatabaseQuery.DatabaseQuery(sql) Query2 = Query1.Queryfunc() Query1.Close() Query3 = DatabaseQuery.DatabaseQuery(sql1) Query4 = Query3.Queryfunc() Query3.Close() #查询两次,排除尾数位不同的影响 if len(Query2) or len(Query4) != 0: serialNumber += 1 else: break return serialNumber #生成项目编号 def generate_project_code(self): # 定义项目编号规则 pattern = re.compile(r'XXXX-(\w+)-(\d{4})-(\d{3})') project_code = 'XXXX-{}-{}-{:03d}'.format(self.product, self.year, self.serial_number) return project_code
数据库查询模块
#coding:utf8 #!/usr/bin/env python #@author: 9527 import MySQLdb #查询数据库 class DatabaseQuery(): def __init__(self,InputInfo): self.QueryData = InputInfo # 连接禅道数据库 self.conn = MySQLdb.connect( host='192.168.1.1', port=3306, user='XXXXXX, passwd='XXXXX', db='zentaoep', charset='utf8' ) # 使用cursor()方法获取操作游标 self.cursor = self.conn.cursor() def Queryfunc(self): sql = self.QueryData # 使用execute()方法执行SQL语句 self.cursor.execute(sql) # 使用fetchall()方法获取所有记录 data = self.cursor.fetchall() return data ''' # 遍历结果 for row in data: project_code = row[0] return project_code ''' def Close(self): try: if self.cursor is not None: self.cursor.close() finally: if self.conn is not None: self.conn.close()
查询已存在编码模块
#coding:utf8 #!/usr/bin/env python #@author: 9527 import DatabaseQuery import json class QueryProjectCodeList(): def __init__(self,ProductLine): self.ProductLine = ProductLine self.sql = self.get_ProductLine(self.ProductLine) #获取产品线对应简称,整理查询语句 def get_ProductLine(self,ProuctLine): with open('ProductLineDict.json', 'r',encoding='utf-8') as f: data = json.load(f) value = "%-" + str(data.get(self.ProductLine))+ "-%" #value = "%-" + str(dic.get(self.ProductLine))+ "-%" sql = "SELECT code FROM zt_project WHERE code LIKE '%s'"%value return sql def QueryList(self): Query1 = DatabaseQuery.DatabaseQuery(self.sql) Query2 = Query1.Queryfunc() Query1.Close() return Query2 ''' a = QueryProjectCodeList("XXXX") b = a.QueryList() data_list = [x[0] for x in b] print(data_list) '''
项目信息查询模块
#coding:utf8 #!/usr/bin/env python #@author: 9527 import DatabaseQuery #import datetime class PronjectInfoQuery(): def __init__(self,ProjectNumber): self.ProjectNumber = ProjectNumber def get_ProjectInfo(self,target): sql = "SELECT * FROM zt_project WHERE code='%s'" %target Query1 = DatabaseQuery.DatabaseQuery(sql) Query2 = Query1.Queryfunc() Query1.Close() try : return Query2[0] except: return Query2 def format_data(self): dic = {"禅道序号":"","所属产品线":"","项目名称":"","编码":"","开始时间":"","截止时间":"","当前状态":"","类型":""} BcakInfo = self.get_ProjectInfo(self.ProjectNumber) try: dic["禅道序号"] = BcakInfo[0] dic["所属产品线"] = BcakInfo[1] dic["项目名称"] = BcakInfo[7] dic["编码"] = BcakInfo[8] #日期格式转换 date1 = BcakInfo[13] dic["开始时间"] = date1.strftime('%Y-%m-%d') date2 = BcakInfo[14] dic["截止时间"] = date2.strftime('%Y-%m-%d') dic["当前状态"] = BcakInfo[16] #数字与类型转换 if BcakInfo[17] == '1': dic["类型"] = "一类" elif BcakInfo[17] == '2': dic["类型"] = "二类" elif BcakInfo[17] == '3': dic["类型"] = "三类" elif BcakInfo[17] == '4': dic["类型"] = "四类" elif BcakInfo[17] == '5': dic["类型"] = "五类" else : dic["类型"] = "其他类" return dic except: return "未查询到相关信息" ''' A = PronjectInfoQuery("XXXX-old-2055-0002") B = A.format_data() print(B) '''
图标位图模块
#coding:utf8 from wx.lib.embeddedimage import PyEmbeddedImage monitor_png = PyEmbeddedImage("") find_png = PyEmbeddedImage("iVBORw0KGgoAAAANSUhEUgAAAJUAAACMCAYAAAB1e+scAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAx0SURBVHhe7Z35UxRnHof3H0u2UrVbyf6wx69rzGV2k5hERRLMYRKNimIwh9Go6xVi1NIYNRrQCEYIJHgEBFGGQ0BAroGZ6em5z/7s+7YNAr4O3TMvme7m+6l6qpTpeXum34f36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Q0fP0CNC8RmgwqQTvcetkFSSUBlTrBscHJlgIo3q3B+bRGCJzfw4iyZVKpVaUlJNo7KZIJ8NclRVvI3bWTSpstksIpGwcKeEu9E0aw9wMy0VD18CIdop4V5iMesPwbUkFU88Hl+S3eBShPdMvIeyGstS8fDxFZcrGo3akAgm+cyts9u2dN8d0M+FiT+/PYgn4mwslTZq3FrykoqH97PcYruRZMK3tN3BmerLtuX8Tw3o6R9EOp0Wfgc7YHUcNTt5S2XX8CUqZ2t+xqlzl2zNlabrUIL2+otasuI6qS43XhdWou04X4uBodGCWgS7xlVS8d/8Hy7UO4ZfmlsRjcWNT++euEYq/hvfNzwx57KK3Wn13ENA5Q/yd1dcI5UaieHmvEV1TqD73hgbGLurC3SFVHy20jfsFVaa3dFbq2DY+CbuiCukUkJRdORYqWl3OnqHkLZ4fc3OcbxU6XQG/fed2UrNZmxSMb6R8+N4qXxKCO3dc9c9OZFbrLVKpvI7g223OFoqXgluaKU4fJIx6g244ryVY6XiB59Px3PdoOA0PP0jiCXs/4cnF4pjpdLHUg47L7UQbV2D+tjK6a2VraTiB5OvMuSrIBYiEo1haMSLASaWmxjz+hGLJ4TfeT6FXvhdrNhGKn6Q+PodvlbLDHy9D7/rxW08WLIs/s7z4ccrGotaXu672LGFVMlkYs7iMMIaXK5M2j4zx6JLxX/LQuy3TnSwCPPwxYm8O7RDii4VXwMtOkiEdfiiPzuk6FKFw3SHjiysPptzsVJ0qUQHh8gPksqI6OAQ+UFSGREdHCI/SCojooND5AdJZUR0cIj8IKmMxOMxQhL53vwpO0WXiuK+kFQU6SGpKNJDUlGkh6SiSA9JRZEc4P/71aMwqhjkYAAAAABJRU5ErkJggg==") Lock_png = PyEmbeddedImage("")
json文件格式
{ "BABA": "9527", "没关系呀": "大家都是神经病", "HelloKitt": "喵喵", "娃哈哈": "Wahaha" }
标签:编码,ProductLine,self,查询,工具,dic,data,def,wx From: https://www.cnblogs.com/babashi9527/p/17120189.html