def init_data(self, OrderID: str): SQL = f""" SELECT o.fOrderID, o.fOrderDate, o.fWarehousingDate , o.fSupplierName, o.fNUIT , o.fCity, o.fEndereco, o.fEmail , o.fContato, o.fCelular , o.fTelefone, o.fAmount , o.fTax, o.fPayable, o.fDesconto , o.fPurchaser , d.fQuant, d.fProductID, d.fPrice , d.fAmount as fAmount_detail, if(isnull(o.fNote),' ',o.fNote) AS fNote1 FROM v_product_warehousereceipt_order o RIGHT JOIN t_product_warehousereceipt_order_detail d ON o.fOrderID = d.fOrderID WHERE d.fOrderID='{OrderID}' """ db = JPDb() data = db.getDict(SQL) data.sort(key=lambda x: (x['fSupplierName'], x['fCity'], x['fAmount'] is None, x['fAmount'])) self.DataSource = data
def on_tableView_currentChanged(self, index1, index2): if index2.row() != -1: if self.checkDirty(): self.saveRight(index2) uid = self.dataInfo.DataRows[index1.row()].Data(0) ins_sql = """ INSERT INTO sysuserright (fUserID, fRightID, fHasRight) SELECT {uid}, fNMID, fDefault FROM sysnavigationmenus WHERE fEnabled = 1 AND NOT fNMID IN ( SELECT fRightID FROM sysuserright WHERE fUserID = {uid})""" sql = """ SELECT u.fUsername, m.*, ord(ur.fHasRight) AS fHasRight FROM sysnavigationmenus m LEFT JOIN sysuserright ur ON m.fNMID = ur.fRightID LEFT JOIN sysusers u ON ur.fUserID = u.fUserID WHERE ur.fUserID = {} AND ord(m.fEnabled) = 1 ORDER BY fDispIndex """ db = JPDb() db.executeTransaction(ins_sql.format(uid=uid)) items = db.getDict(sql.format(uid)) self.ui.treeWidget.itemChanged.disconnect(self.onItemChanged) loadTreeview(self.ui.treeWidget, items) self.ui.treeWidget.itemChanged.connect(self.onItemChanged)
def __init__(self, parent=None, flags=Qt.WindowFlags()): super().__init__(parent=parent, flags=flags) self.ui = Ui_Dialog() self.ui.setupUi(self) #self.ui.treeView.setModel(TreeModel()) # self.ui.treeWidget.setItemDelegateForColumn() self.ui.treeWidget.setColumnCount(18) self.ui.treeWidget.setHeaderLabels([ '显示文本', '显示顺序', '图标', '默认权限', '前景色', '背景色', 'fObjectName', 'fFormMode', 'fArg', 'fIcon', 'fDefault', 'fNodeBackvolor', 'fNodeForeColor', 'fNodeFontBold', 'fExpanded', 'fDescription', 'fLevel', 'fIsCommandButton' ]) self.SQL = """ SELECT fNMID, fDispIndex, fParentId, fEnabled, fMenuText , fCommand, fObjectName, fFormMode, fArg, fIcon , fDefault, fNodeBackvolor, fNodeForeColor, fNodeFontBold, fExpanded , fDescription, fLevel, fIsCommandButton FROM sysnavigationmenus ORDER BY fDispIndex """ db = JPDb() lst = db.getDict(self.SQL) loadTreeview(self.ui.treeWidget, lst)
def __refreshCurrentUserRight(self): db = JPDb() uid = self.currentUserID() sql_1 = """ SELECT 1, n.fNMID, n.fDispIndex, n.fParentId, n.fMenuText, n.fObjectName, n.fIcon, n.fIsCommandButton+0 AS fIsCommandButton, 1 as fHasRight FROM sysnavigationmenus n where n.fNMID in (1,11,13,135,136,137) or n.fDefault=1 """ sql_else = """ SELECT ur.fUserID, n.fNMID, n.fDispIndex, n.fParentId, n.fMenuText, n.fObjectName, n.fIcon, n.fIsCommandButton+0 AS fIsCommandButton, ur.fHasRight+0 as fHasRight FROM sysnavigationmenus n left JOIN ( SELECT * FROM sysuserright WHERE fUserID = {} ) ur ON n.fNMID = ur.fRightID WHERE (n.fEnabled = 1 and ur.fHasRight=1) or n.fDefault=1 ORDER BY n.fParentId, n.fDispIndex """.format(uid) exesql = sql_1 if uid == 1 else sql_else re = db.getDict(exesql) menu = [r for r in re if r['fIsCommandButton'] == 0] for r in menu: r['btns'] = [ b for b in re if b['fParentId'] == r['fNMID'] and b['fIsCommandButton'] == 1 ] self.__CurrentUserRight = menu
def init_data(self, OrderID: str): SQL = """ SELECT o.*, if(not isnull(fNumerBegin) and not isnull(fNumerBegin), concat(fNumerBegin , ' VIE ' ,fNumerEnd),'') AS Numeracao, if(isnull(fNote),' ',fNote) as fNote1 FROM v_order o WHERE o.fOrderID ='{}'""" db = JPDb() data = db.getDict(SQL.format(OrderID)) data.sort(key=lambda x: (x['fCustomerName'], x['fCity'], x['fAmount'] is None, x['fAmount'])) self.DataSource = data
def init_data(self, OrderID: str): SQL = """SELECT o.* , if(isnull(fNote), ' ', fNote) AS fNote1 , d.fQuant, d.fProductName, d.fLength, d.fWidth, d.fPrice , d.fAmount AS fAmountDetail FROM v_quotation o RIGHT JOIN t_quotation_detail d ON o.fOrderID = d.fOrderID WHERE d.fOrderID = '{}'""" db = JPDb() data = db.getDict(SQL.format(OrderID)) data.sort(key=lambda x: (x['fCustomerName'], x['fCity'], x['fAmount'] is None, x['fAmount'])) self.DataSource = data
def init_data(self, OrderID: str): SQL = """ SELECT o.fOrderID, o.fOrderDate, o.fRequiredDeliveryDate , o.fCustomerName, o.fNUIT , o.fCity, o.fEndereco, o.fEmail , o.fContato, o.fCelular , o.fTelefone, o.fAmount , o.fTax, o.fPayable, o.fDesconto , o.fVendedor , if(isnull(fNote), ' ', fNote) AS fNote1 , d.fQuant, d.fProductName, d.fLength, d.fWidth, d.fPrice , d.fAmount as fAmount_detail , if(isnull(fNote), ' ', fNote) AS fNote1 FROM v_order o RIGHT JOIN t_order_detail d ON o.fOrderID = d.fOrderID WHERE d.fOrderID = '{}' """ db = JPDb() data = db.getDict(SQL.format(OrderID)) # data.sort(key=lambda x: (x['fCustomerName'], x['fCity'], x['fAmount'] # is None, x['fAmount'])) self.DataSource = data
class JPPub(QObject): MainForm = None UserSaveData = pyqtSignal(str) SingnalPopMessage = pyqtSignal(str) def __init__(self): if self.MainForm is None: super().__init__() self.user = JPUser() self.db = JPDb() self.__ConfigData = None self.INITCustomer() self.INITSupplier() self.INITEnum() sql = """ SELECT fNMID, fMenuText, fParentId, fCommand, fObjectName, fIcon, cast(fIsCommandButton AS SIGNED) AS fIsCommandButton FROM sysnavigationmenus WHERE fEnabled=1 AND fNMID>1 ORDER BY fDispIndex """ self.__sysNavigationMenusDict = self.db.getDict(sql) def INITEnum(self): def getEnumDict() -> dict: sql = '''select fTypeID,fTitle,fItemID,fSpare1, fSpare2,fNote from t_enumeration''' rows = self.db.getDataList(sql) return { k: [row1[1:] for row1 in rows if row1[0] == k] for k in set(row[0] for row in rows) } self.__EnumDict = getEnumDict() def INITCustomer(self): sql = '''select fCustomerName,fCustomerID, fNUIT,fCity,fContato,fTaxRegCer from t_customer''' self.__allCustomerList = self.db.getDataList(sql) def INITSupplier(self): sql = '''select fSupplierName,fSupplierID, fNUIT,fCity,fContato,fTaxRegCer from t_supplier''' self.__allSupplieList = self.db.getDataList(sql) def getEnumList(self, enum_type_id: int): self.INITEnum() return self.__EnumDict[enum_type_id] def getSupplierList(self): self.INITSupplier() return self.__allSupplierList def getCustomerList(self): self.INITCustomer() return self.__allCustomerList def getSysNavigationMenusDict(self): return self.__sysNavigationMenusDict def getConfigData(self) -> dict: sql = "select fValue from sysconfig where fName='configValue'" conn = JPDb().currentConn cur = conn.cursor() cur.execute(sql) conn.commit() mydic = loads(b64decode(cur._result.rows[0][0])) # 防止没有设置信息时,给定初始值 # copys copys = [ 'BillCopys_Order', 'BillCopys_PrintingOrder', 'BillCopys_OutboundOrder', 'BillCopys_WarehouseRreceipt', 'BillCopys_QuotationOrder', 'BillCopys_QuotationPrintingOrder' ] for item in copys: if item not in mydic.keys(): mydic[item] = 'atendimento;1;producao;0;cliente;1;caixa;1' if 'TaxRegCerPath' not in mydic.keys(): mydic['TaxRegCerPath'] = '' txt = '您还没有设置客户税务登记证件位置\n' txt = txt + 'You haven\'t set up the location of the customer\'s tax registration certificate yet' QMessageBox.information(self.MainForm, '提示', txt) else: if not ospath.exists(mydic['TaxRegCerPath']): txt = '您设置的客户税务登记证件位置不存在\n' txt = txt + 'The location of the customer tax registration certificate you set does not exist' QMessageBox.information(self.MainForm, '提示', txt) return mydic def getCopysInfo(self, billname: str): try: info_str = self.getConfigData()[billname] info_lst = info_str.split(';') mydic = [] for i in range(len(info_lst)): if i % 2 == 0: mydic.append({ 'title': info_lst[i], 'flag': True if info_lst[i + 1] == '1' else False }) return mydic except Exception as e: msg = '读取单据联次信息出现错误,信息如下:\n' msg = msg + str(e) QMessageBox.warning(self, '提示', msg, QMessageBox.Yes, QMessageBox.Yes) def saveConfigData(self, data: dict): sql = "update sysconfig set fValue=%s where fName='configValue'" conn = JPDb().currentConn cur = conn.cursor() cur.execute(sql, b64encode(dumps(data))) conn.commit() # 保存后刷新当前配置文件 self.__ConfigData = data def ConfigData(self, RefResh=False): if RefResh or self.__ConfigData is None: self.__ConfigData = self.getConfigData() return self.__ConfigData def broadcastMessage(self, tablename=None, action=None, PK=None): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) PORT = 1060 network = '<broadcast>' act = { 'confirmation': '确认', 'Submit': '提交', 'edit': '修改', 'new': '新增', 'delete': '删除', 'createOrder': '由报价单生成新订单' } tn = { 't_order': '订单表', 'sysusers': '用户表', 't_receivables': '收款表', 't_customer': '客户表', 't_quotation': '报价单表', 't_product_information': '产品信息表', 't_product_outbound_order': '出库单表', 't_product_warehousereceipt_order': '入库单表', 't_supplier': '供应商表' } curtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') curtab = tn[tablename] curact = act[action] curpk = PK obj_user = JPUser() uid = obj_user.currentUserID() curuser = [v[1] for v in obj_user.getAllUserList() if v[0] == uid][0] txt = f'{curtime}:\n用户[{curuser}]操作;\n[{curtab}]有新的记录被用户[{curact}],\n编号为[{curpk}]' msg = json.dumps((tablename, txt)) s.sendto(msg.encode('utf-8'), (network, PORT)) s.close() def receiveMessage(self, app): # 收发消息类 class MyThreadRec(QThread): def __init__(self, pub, notify, rec, *args, **kwargs): super().__init__(*args, **kwargs) self.rec = rec self.pub = pub self.notify = notify self.currentIP = None def run(self): while True: data, address = self.rec.recvfrom(65535) txt = json.loads(data.decode('utf-8')) # 发送信息方是本机时不处理 if address[0] != self.currentIP: if self.pub.ConfigData()['AutoRefreshWhenDataChange']: self.pub.UserSaveData.emit(txt[0]) if self.pub.ConfigData()['BubbleTipsWhenDataChange']: self.pub.SingnalPopMessage.emit(txt[1]) time.sleep(1) self.rec = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.rec.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) PORT = 1060 self.rec.bind(('', PORT)) self.rec.setblocking(True) self.notify = WindowNotify(app=app) self.ThreadRec = MyThreadRec(self, self.notify, self.rec) myname = socket.getfqdn(socket.gethostname()) self.ThreadRec.currentIP = socket.gethostbyname(myname) self.SingnalPopMessage.connect(self.popMessage) self.ThreadRec.start() def popMessage(self, txt): self.notify.show(content=txt) self.notify.showAnimation()
class JPPub(QObject): MainForm = None UserSaveData = pyqtSignal(str) SingnalPopMessage = pyqtSignal(str) def __init__(self): if self.MainForm is None: super().__init__() self.user = JPUser() self.db = JPDb() self.__ConfigData = None sql = ('SELECT fNMID, fMenuText, fParentId, ' 'fCommand, fObjectName, fIcon,' 'cast(fIsCommandButton AS SIGNED) AS fIsCommandButton ' 'FROM sysnavigationmenus ' 'WHERE fEnabled=1 AND fNMID>1 ' 'ORDER BY fDispIndex') self.__sysNavigationMenusDict = self.db.getDict(sql) @lazy_Property def _getEnumDict(self) -> dict: sql = ('select fTypeID,fTitle,fItemID,fSpare1,' 'fSpare2,fNote from t_enumeration') rows = self.db.getDataList(sql) return { k: [row1[1:] for row1 in rows if row1[0] == k] for k in set(row[0] for row in rows) } def getEnumList(self, enum_type_id: int): return self._getEnumDict[enum_type_id] def getSysNavigationMenusDict(self): return self.__sysNavigationMenusDict def getConfigData(self) -> dict: sql = "select fValue from sysconfig where fName='configValue'" conn = JPDb().currentConn cur = conn.cursor() cur.execute(sql) conn.commit() mydic = loads(b64decode(cur._result.rows[0][0])) # 防止没有设置信息时,给定初始值 # copys copys = [ 'BillCopys_Order', 'BillCopys_PrintingOrder', 'BillCopys_OutboundOrder', 'BillCopys_WarehouseRreceipt', 'BillCopys_QuotationOrder', 'BillCopys_QuotationPrintingOrder' ] for item in copys: if item not in mydic.keys(): mydic[item] = 'atendimento;1;producao;0;cliente;1;caixa;1' if 'archives_path' not in mydic.keys(): mydic['archives_path'] = '' txt = '您还没有设置附件文件存放位置' QMessageBox.information(self.MainForm, '提示', txt) else: if not ospath.exists(mydic['archives_path']): txt = '您设置的设置附件文件存放位置不存在' QMessageBox.information(self.MainForm, '提示', txt) return mydic def getCopysInfo(self, billname: str): try: info_str = self.getConfigData()[billname] info_lst = info_str.split(';') mydic = [] for i in range(len(info_lst)): if i % 2 == 0: mydic.append({ 'title': info_lst[i], 'flag': True if info_lst[i + 1] == '1' else False }) return mydic except Exception as e: msg = '读取单据联次信息出现错误,信息如下:\n' msg = msg + str(e) QMessageBox.warning(self, '提示', msg, QMessageBox.Yes, QMessageBox.Yes) def saveConfigData(self, data: dict): sql = "update sysconfig set fValue=%s where fName='configValue'" conn = JPDb().currentConn cur = conn.cursor() cur.execute(sql, b64encode(dumps(data))) conn.commit() # 保存后刷新当前配置文件 self.__ConfigData = data def ConfigData(self, RefResh=False): if RefResh or self.__ConfigData is None: self.__ConfigData = self.getConfigData() return self.__ConfigData def broadcastMessage(self, tablename=None, action=None, PK=None): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) PORT = 1060 network = '<broadcast>' act = { 'confirmation': '确认', 'Submit': '提交', 'edit': '修改', 'new': '新增', 'delete': '删除', 'createOrder': '由报价单生成新订单' } tn = { 't_order': '订单表', 'sysusers': '用户表', 't_receivables': '收款表', 't_customer': '客户表', 't_quotation': '报价单表', 't_product_information': '产品信息表', 't_product_outbound_order': '出库单表', 't_product_warehousereceipt_order': '入库单表', 't_supplier': '供应商表' } curtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') curtab = tn[tablename] curact = act[action] curpk = PK obj_user = JPUser() uid = obj_user.currentUserID() curuser = [v[1] for v in obj_user.getAllUserList() if v[0] == uid][0] txt = ('{curtime}:\n用户[{curuser}]操作;\n' '[{curtab}]有新的记录被用户[{curact}],' '\n编号为[{curpk}]') txt = txt.format(curtime=curtime, curuser=curuser, curtab=curtab, curpk=curp, curact=curact) msg = json.dumps((tablename, txt)) s.sendto(msg.encode('utf-8'), (network, PORT)) s.close() def receiveMessage(self, app): # 收发消息类 class MyThreadRec(QThread): def __init__(self, pub, notify, rec, *args, **kwargs): super().__init__(*args, **kwargs) self.rec = rec self.pub = pub self.notify = notify self.currentIP = None def run(self): while True: data, address = self.rec.recvfrom(65535) txt = json.loads(data.decode('utf-8')) # 发送信息方是本机时不处理 if address[0] != self.currentIP: if self.pub.ConfigData()['AutoRefreshWhenDataChange']: self.pub.UserSaveData.emit(txt[0]) if self.pub.ConfigData()['BubbleTipsWhenDataChange']: self.pub.SingnalPopMessage.emit(txt[1]) time.sleep(1) self.rec = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.rec.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) PORT = 1060 self.rec.bind(('', PORT)) self.rec.setblocking(True) self.notify = WindowNotify(app=app) self.ThreadRec = MyThreadRec(self, self.notify, self.rec) myname = socket.getfqdn(socket.gethostname()) self.ThreadRec.currentIP = socket.gethostbyname(myname) self.SingnalPopMessage.connect(self.popMessage) self.ThreadRec.start() def popMessage(self, txt): self.notify.show(content=txt) self.notify.showAnimation() def getOrSetlastOpenDir(self, path: str = None): """返回或设置最后打开文件夹,如果path给一个文件名或路径名,则设置,不给值则返回一个值""" subKey = r'Software\project_m' key = winreg.HKEY_CURRENT_USER try: newkey = winreg.OpenKey(key, subKey) except WindowsError: newkey = winreg.CreateKey(key, subKey) winreg.SetValue(newkey, "recentPath", winreg.REG_SZ, getcwd()) if not path: return winreg.QueryValue(key, subKey + r'\recentPath') else: if ospath.isfile(path): path = ospath.dirname(path) winreg.SetValue(newkey, "recentPath", winreg.REG_SZ, path) def __checkFileExist(self, path): return path def getIcoPath(self, fileName: str): p = getcwd() + "\\res\\ico\\{}".format(fileName) return self.__checkFileExist(p) def getLogoPath(self, fileName: str): p = getcwd() + "\\res\\{}".format(fileName) return self.__checkFileExist(p)