class SelectRecordsModule(QDialog, Ui_Dialog): selected = pyqtSignal(int, list) def __init__(self, kind, parent=None): super(SelectRecordsModule, self).__init__(parent) self.kind = kind self.detail = [] self.PC = ProductController() self.LC = LabrecordsController() self.setupUi(self) self.treeWidget_filelist.hideColumn(1) # 或取记录 self.get_generalrecords() def get_generalrecords(self): if self.kind == 0: res = self.PC.get_data(3, False, *VALUES_TUPLE_PP) for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_filelist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['prodid']) qtreeitem.setText(2, item['prodname']) qtreeitem.setText(3, item['batchno']) qtreeitem.setText(4, item['spec']) qtreeitem.setText(5, item['package']) else: res = self.LC.get_data(0, False, *VALUES_TUPLE_LR) for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_filelist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['chkid']) qtreeitem.setText(2, item['chkname']) qtreeitem.setText(3, item['batchno']) qtreeitem.setText(4, item['spec']) qtreeitem.setText(5, item['package']) for i in range(1, 6): self.treeWidget_filelist.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_filelist_itemDoubleClicked(self, qitem, p_int): self.selected.emit(self.kind, [int(qitem.text(0)),]) self.accept() @pyqtSlot() def on_pushButton_accept_clicked(self): items = self.treeWidget_filelist.selectedItems() select_list = [] for item in items: select_list.append(int(item.text(0))) if len(select_list): self.selected.emit(self.kind, select_list) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class ProductDetail(ProductDetailModule): def __init__(self, autoid=None, parent=None): super().__init__(parent) self.autoid = autoid self.PC = ProductController() self.flush_basedata() def flush_basedata(self): condition = {'autoid': self.autoid} res = self.PC.get_data(1, False, **condition) if not len(res): return self.set_data(res[0]) self.oridetail = model_to_dict(res[0]) def set_data(self, detail): self.prodid.setText(detail.prodid) self.prodname.setText(detail.prodname) self.commonname.setText(detail.commonname) self.medkind.setCurrentText(detail.medkind) self.externalno.setText(detail.externalno) self.allowno.setText(detail.allowno) self.inputcode.setText(detail.inputcode) self.spec.setText(detail.spec) self.packageLv.setCurrentIndex(int(detail.packagelv)) self.package_2.setText(detail.package) self.checkunit.setCurrentIndex(detail.checkunit) self.expireddates.setText(str(detail.expireddates)) self.storage.setText(detail.storage) if detail.plid: productline = ProductLineConroller() productlinedetail = productline.get_productline(autoid=detail.plid) if productlinedetail: self.workshop.setText(productlinedetail[0].deptname) self.productionline.setText(productlinedetail[0].linename) if detail.wplid: productline = ProductLineConroller() productlinedetail = productline.get_productline( autoid=detail.wplid) if productlinedetail: self.bworkshop.setText(productlinedetail[0].deptname) self.bproductionline.setText(productlinedetail[0].linename)
class EditFormulaModule(QDialog, Ui_Dialog): def __init__(self, autoid=None, prodid=None, prodtype=0, parent=None): super(EditFormulaModule, self).__init__(parent) self.setupUi(self) self.autoid = autoid self.prodid = prodid self.prodtype = prodtype self.ori_detail = {} self.new_detail = {} self.PC = ProductController() self.set_validator() return_row = ("stufftype", "kind", ) condition_key = {'kind', } treeheader_name = ["type", "物料种类"] self.lineEdit_stuffkind.setup( 'Stuffdictionary', return_row, condition_key, treeheader_name, None, 745, 200 ) self.get_detail() def get_detail(self): if self.autoid is None: return condition = {'autoid': self.autoid} res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition) if not len(res): return self.ori_detail = res[0] self.lineEdit_stuffkind.setText(self.ori_detail['stuffkind']) self.comboBox_stufftype.setCurrentIndex(self.ori_detail['stufftype']) self.lineEdit_formula.setText(self.ori_detail['formula']) self.lineEdit_presexpression.setText(self.ori_detail['presexpression']) self.lineEdit_pracexpression.setText(self.ori_detail['pracexpression']) self.lineEdit_drawexpression.setText(self.ori_detail['drawexpression']) self.lineEdit_presunit.setText(self.ori_detail['presunit']) self.lineEdit_pracunit.setText(self.ori_detail['pracunit']) self.lineEdit_drawunit.setText(self.ori_detail['drawunit']) self.lineEdit_precision.setText(str(self.ori_detail['precision'])) self.lineEdit_loss.setText(str(self.ori_detail['loss'])) def set_validator(self): intvalidator = QIntValidator() intvalidator.setBottom(0) self.lineEdit_precision.setValidator(intvalidator) doublevalidator = QDoubleValidator() doublevalidator.setRange(0, 100) self.lineEdit_loss.setValidator(doublevalidator) @pyqtSlot(object) def on_lineEdit_stuffkind_getItem(self, qtreeitem): self.comboBox_stufftype.setCurrentIndex(int(qtreeitem.text(0))) p_str = qtreeitem.text(1) try: if p_str != self.ori_detail['stuffkind']: self.new_detail['stuffkind'] = p_str else: try: del self.new_detail['stuffkind'] except KeyError: pass except KeyError: self.new_detail['stuffkind'] = p_str @pyqtSlot(int) def on_comboBox_stufftype_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail['stufftype']: self.new_detail['stufftype'] = p_int else: try: del self.new_detail['stufftype'] except KeyError: pass except KeyError: self.new_detail['stufftype'] = p_int @pyqtSlot(str) def on_lineEdit_formula_textChanged(self, p_str): try: if p_str != self.ori_detail['formula']: self.new_detail['formula'] = p_str else: try: del self.new_detail['formula'] except KeyError: pass except KeyError: self.new_detail['formula'] = p_str @pyqtSlot(str) def on_lineEdit_presexpression_textChanged(self, p_str): try: if p_str != self.ori_detail['presexpression']: self.new_detail['presexpression'] = p_str else: try: del self.new_detail['presexpression'] except KeyError: pass except KeyError: self.new_detail['presexpression'] = p_str @pyqtSlot(str) def on_lineEdit_pracexpression_textChanged(self, p_str): try: if p_str != self.ori_detail['pracexpression']: self.new_detail['pracexpression'] = p_str else: try: del self.new_detail['pracexpression'] except KeyError: pass except KeyError: self.new_detail['pracexpression'] = p_str @pyqtSlot(str) def on_lineEdit_drawexpression_textChanged(self, p_str): try: if p_str != self.ori_detail['drawexpression']: self.new_detail['drawexpression'] = p_str else: try: del self.new_detail['drawexpression'] except KeyError: pass except KeyError: self.new_detail['drawexpression'] = p_str @pyqtSlot(str) def on_lineEdit_presunit_textChanged(self, p_str): try: if p_str != self.ori_detail['presunit']: self.new_detail['presunit'] = p_str else: try: del self.new_detail['presunit'] except KeyError: pass except KeyError: self.new_detail['presunit'] = p_str @pyqtSlot(str) def on_lineEdit_pracunit_textChanged(self, p_str): try: if p_str != self.ori_detail['pracunit']: self.new_detail['pracunit'] = p_str else: try: del self.new_detail['pracunit'] except KeyError: pass except KeyError: self.new_detail['pracunit'] = p_str @pyqtSlot(str) def on_lineEdit_drawunit_textChanged(self, p_str): try: if p_str != self.ori_detail['drawunit']: self.new_detail['drawunit'] = p_str else: try: del self.new_detail['drawunit'] except KeyError: pass except KeyError: self.new_detail['drawunit'] = p_str @pyqtSlot(str) def on_lineEdit_precision_textChanged(self, p_str): p_int = int(p_str) try: if p_int != self.ori_detail['precision']: self.new_detail['precision'] = p_int else: try: del self.new_detail['precision'] except KeyError: pass except KeyError: self.new_detail['precision'] = p_int @pyqtSlot(str) def on_lineEdit_loss_textChanged(self, p_str): p_float = float(p_str) try: if p_float != self.ori_detail['loss']: self.new_detail['loss'] = p_float else: try: del self.new_detail['loss'] except KeyError: pass except KeyError: self.new_detail['loss'] = p_float @pyqtSlot() def on_pushButton_accept_clicked(self): print(self.new_detail) if not len(self.new_detail): return if self.autoid is None: self.new_detail['prodid'] = self.prodid self.new_detail['prodtype'] = self.prodtype self.PC.update_data(6, **self.new_detail) else: condition = {'autoid': self.autoid} self.PC.update_data(6, condition, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class EditSampleRecordDetailModule(QDialog, Ui_Dialog): def __init__(self, autoid, parent=None): super(EditSampleRecordDetailModule, self).__init__(parent) self.setupUi(self) if '50' not in user.powers: self.close() if user.powers['10'] == 0: self.close() self.power = '{:03b}'.format(user.powers['10']) if self.power[1] == '0': self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.autoid = autoid self.checkitem_id = None self.ori_detail = object self.new_detail = {} self.lr_list = [] self.LC = LabrecordsController() self.PC = ProductController() self.get_detail() self.get_observation_record() self.get_labrecord_list() def get_detail(self): condition = {'autoid': self.autoid} res = self.LC.get_data(6, False, **condition) if len(res) != 1: self.pushButton_accept.setEnabled(False) self.pushButton_cancel.setEnabled(False) return self.ori_detail = res[0] self.lineEdit_product.setText(self.ori_detail.ppid.prodid + ' ' + self.ori_detail.ppid.prodname) self.lineEdit_commonname.setText(self.ori_detail.ppid.commonname) self.lineEdit_batchno.setText(self.ori_detail.ppid.batchno) self.lineEdit_spec.setText(self.ori_detail.ppid.spec) self.lineEdit_package.setText(self.ori_detail.ppid.package) self.lineEdit_makedate.setText(str(self.ori_detail.ppid.makedate)) self.lineEdit_samplequantity.setText( str(self.ori_detail.samplequantity)) self.lineEdit_unit.setText(self.ori_detail.unit) self.comboBox_kind.setCurrentIndex(self.ori_detail.kind) if self.ori_detail.status != 0: self.pushButton_accept.setEnabled(False) self.pushButton_cancel.setEnabled(False) def get_observation_record(self): self.treeWidget_observation.clear() condition = {'srid': self.autoid} res = self.LC.get_data(7, False, **condition) if not len(res): return lrid_list = res.values_list(*VALUES_TUPLE_LRID, flat=True) condition_lr = {'ciid__in': lrid_list, 'labtype': 6} self.lr_list = self.LC.get_data(0, False, *VALUES_TUPLE_LR, **(condition_lr)) for item in res.values(*VALUES_TUPLE_OB): qtreeitem = QTreeWidgetItem(self.treeWidget_observation) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(2, item['obsperiod']) qtreeitem.setText(3, str(item['obsdate'])) qtreeitem.setText(4, str(item['samplequantity'])) qtreeitem.setText(5, item['unit']) qtreeitem.setText(6, item['conclusion']) for it in self.lr_list: if it['ciid'] == item['autoid']: qtreeitem.setText(1, str(it['autoid'])) qtreeitem.setText(7, STATUS[it['status']]) break for i in range(2, 8): self.treeWidget_observation.resizeColumnToContents(i) def get_labrecord_list(self): self.treeWidget_labrecord.clear() if self.ori_detail is None: return for item in self.lr_list: qtreeitem = QTreeWidgetItem(self.treeWidget_labrecord) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['paperno']) qtreeitem.setText(2, str(item['reportdate'])) qtreeitem.setText(3, STATUS[item['status']]) @pyqtSlot(QPoint) def on_treeWidget_observation_customContextMenuRequested(self, pos): if self.ori_detail is None: return if self.ori_detail.status != 0: return current_item = self.treeWidget_observation.currentItem() menu = QMenu() action_1 = menu.addAction("增加") action_2 = menu.addAction("修改") action_3 = menu.addAction("删除") menu.addSeparator() action_4 = menu.addAction("提交请验") action_5 = menu.addAction("取消请验") global_pos = self.treeWidget_observation.mapToGlobal(pos) action = menu.exec(global_pos) if action == action_1: unit = self.lineEdit_unit.text() detail = EditObservationModule(srid=self.autoid, unit=unit, parent=self) detail.accepted.connect(self.get_observation_record) detail.show() elif action == action_2: if current_item is None: return id = int(current_item.text(0)) detail = EditObservationModule(autoid=id, parent=self) detail.accepted.connect(self.get_observation_record) detail.show() elif action == action_3: if current_item is None: return condition = {'autoid': int(current_item.text(0))} self.LC.delete_data(7, condition) lrid = current_item.text(1) if lrid != '': self.LC.delete_labrecord_and_detail(int(lrid)) self.get_observation_record() elif action == action_4: if self.ori_detail is None or current_item is None: return if current_item.text(1) == '': if self.checkitem_id is None: prodid = self.ori_detail.ppid.prodid condition = {'prodid': prodid} res = self.PC.get_data(1, True, *VALUES_TUPLE_PD, **condition) if not len(res): return self.checkitem_id = res[0] kwargs = { 'labtype': 6, 'chkid': self.ori_detail.ppid.prodid, 'chkname': self.ori_detail.ppid.prodname, 'batchno': self.ori_detail.ppid.batchno, 'spec': self.ori_detail.ppid.spec, 'package': self.ori_detail.ppid.package, 'ciid': int(current_item.text(0)), 'createdate': user.now_date, 'checkamount': self.ori_detail.samplequantity, 'caunit': self.ori_detail.unit, 'sampleamount': decimal.Decimal(current_item.text(4)), 'sampleunit': current_item.text(5), } lrid = self.LC.create_labrecord(self.checkitem_id, 6, user.now_date, **kwargs) else: lrid = int(current_item.text(1)) detail = ApplycheckModule(lrid, 6, self) detail.rejected.connect(lambda: self.delete_check_report(lrid)) detail.applyed.connect(detail.accept) detail.accepted.connect(self.get_observation_record) detail.accepted.connect(self.get_labrecord_list) detail.show() elif action == action_5: if current_item is None: return lrid = current_item.text(1) if lrid != '': self.LC.delete_labrecord(int(lrid)) self.get_observation_record() else: pass def delete_check_report(self, lrid): self.LC.delete_labrecord(lrid) self.get_observation_record() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_observation_itemDoubleClicked(self, qtreeitem, p_int): id = int(qtreeitem.text(0)) detail = EditObservationModule(autoid=id, parent=self) detail.accepted.connect(self.get_observation_record) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_labrecord_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0': return id = int(qtreeitem.text(0)) detail = CheckreportModule(id, True, self) detail.show() @pyqtSlot(str) def on_lineEdit_samplequantity_textChanged(self, p_str): p_data = decimal.Decimal(p_str) try: if p_data != self.ori_detail.samplequantity: self.new_detail['samplequantity'] = p_data else: try: del self.new_detail['samplequantity'] except KeyError: pass except ValueError: self.new_detail['samplequantity'] = p_data @pyqtSlot(str) def on_lineEdit_unit_textChanged(self, p_str): try: if p_str != self.ori_detail.unit: self.new_detail['unit'] = p_str else: try: del self.new_detail['unit'] except KeyError: pass except ValueError: self.new_detail['unit'] = p_str @pyqtSlot(int) def on_comboBox_kind_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail.kind: self.new_detail['kind'] = p_int else: try: del self.new_detail['kind'] except KeyError: pass except ValueError: self.new_detail['kind'] = p_int @pyqtSlot() def on_pushButton_accept_clicked(self): if not len(self.new_detail): return condiition = {'autoid': self.autoid} self.LC.update_data(6, condiition, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class SelectProdictionListModule(QDialog, Ui_Dialog): def __init__(self, parent=None): super(SelectProdictionListModule, self).__init__(parent) self.setupUi(self) # 用于显示不用的批记录,0为没有找到留样记录的批记录,1为全部批记录 self.type = 0 self.PC = ProductController() self.LC = LabrecordsController() self.get_detail() def get_detail(self): self.treeWidget_productlist.clear() condition_pp = {'pltype': 0, 'status__gte': 2} pp_list = self.PC.get_data( 3, False, *VALUES_TUPLE_PP, **condition_pp ).order_by('-autoid') if self.type == 0: res = self.LC.get_data(6,True, *VALUES_TUPLE_SP) conditon = {'autoid__in': res} pp_list = pp_list.exclude(**conditon) if not len(pp_list): return for item in pp_list: qtreeitem = QTreeWidgetItem(self.treeWidget_productlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['prodid']) qtreeitem.setText(2, item['prodname']) qtreeitem.setText(3, item['commonname']) qtreeitem.setText(4, item['batchno']) qtreeitem.setText(5, str(item['planamount'])) qtreeitem.setText(6, item['spunit']) qtreeitem.setText(7, item['spec']) qtreeitem.setText(8, item['package']) qtreeitem.setText(9, str(item['makedate'])) qtreeitem.setText(10, str(item['executedate'])) for i in range(1, 11): self.treeWidget_productlist.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_productlist_itemDoubleClicked(self, qtreeitem, p_int): detail = { 'ppid_id': int(qtreeitem.text(0)), 'creatorid': user.user_id, 'creatorname': user.user_name, 'sampledate': user.now_date, 'unit': qtreeitem.text(6), 'expireddate': qtreeitem.text(10) } sample_record = self.LC.update_data(6, **detail) detail = EditSampleRecordDetailModule(sample_record.autoid, self.parent()) detail.rejected.connect(self.accept) detail.accepted.connect(self.accept) detail.show() self.close() @pyqtSlot(bool) def on_radioButton_unmake_clicked(self, p_bool): if p_bool: self.type = 0 self.get_detail() @pyqtSlot(bool) def on_radioButton_all_clicked(self, p_bool): if p_bool: self.type = 1 self.get_detail() @pyqtSlot() def on_pushButton_accept_clicked(self): current_item = self.treeWidget_productlist.currentItem() if current_item is None: return detail = { 'ppid_id': int(current_item.text(0)), 'creatorid': user.user_id, 'creatorname': user.user_name, 'sampledate': user.now_date, 'unit': current_item.text(6), 'expireddate': current_item.text(10) } sample_record = self.LC.update_data(6, **detail) detail = EditSampleRecordDetailModule(sample_record.autoid, self.parent()) detail.rejected.connect(self.accept) detail.accepted.connect(self.accept) detail.show() self.close() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class EditProducingplan(QDialog, Ui_Dialog): created = pyqtSignal(int) def __init__(self, autoid=None, parent=None): super(EditProducingplan, self).__init__(parent) self.setupUi(self) # if '20' not in user.powers: # self.close() # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) # if user.powers['20'] == 0: # self.close() # self.power = '{:03b}'.format(user.powers['20']) # if self.power[1] == '0': # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) self.PC = ProductController() self.WC = WarehouseController() self.autoid = autoid self.prod_id = 0 self.ori_detail = {} self.new_detail = {} self.detail = {} self.stuff_list = [] self.stuff_repository = [] self.no_enough_stuff_list = [] self.treewidget_meterial.hideColumn(1) self.treeWidget_package.hideColumn(1) # 公式错误信息 self.errormsg = [] self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY, VALUE_NAME, None, 650, 250) self.prodname.getItem.connect(self.setproduct) self.set_validator() if autoid is not None: self.get_detail() self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial) self.set_treewidget_formula((3, 4), self.treeWidget_package) else: self.makedate.setDate(QDate.currentDate()) def set_validator(self): doubleValitor = QDoubleValidator() doubleValitor.setBottom(0) doubleValitor.setDecimals(2) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.planamount.setValidator(doubleValitor) def setproduct(self, qtreeitem: QTreeWidgetItem): self.prod_id = qtreeitem.text(0) self.commonname.setText(qtreeitem.text(3)) self.spec.setText(qtreeitem.text(4)) self.package_2.setText(qtreeitem.text(5)) if self.prod_id: # flag:产品的类型,0成品,1半成品,2退货, 3验证 flag = self.productkind.currentIndex() key_dict = {'autoid': self.prod_id} res = self.PC.get_product_or_stuff_dictionary( flag, False, **key_dict) if res: self.unit.setText(res[0].spunit) if flag in (0, 1): lineid = res[0].plid elif flag == 2: lineid = res[0].wplid elif flag == 3: lineid = res[0].vplid else: lineid = 0 if lineid: productline = ProductLineConroller() pline = productline.get_productline(lineid, flag) if pline: self.prodline.setText(pline[0].linename) self.productworkshop.setText(pline[0].deptid + ' ' + pline[0].deptname) def set_autoid(self, autoid: int): self.autoid = autoid # 查询autoid对应的记录,并关联到表格中 self.get_detail() self.new_detail.clear() def get_detail(self): res = self.PC.get_producingplan(autoid=self.autoid) if res: # 把生产指令的内容填入表格中 self.set_data(res[0]) self.ori_detail = model_to_dict(res[0]) self.detail = self.ori_detail else: errordialig = QErrorMessage(self) errordialig.setWindowTitle("错误") # 初始化编辑生产指令的内容 def set_data(self, detail): self.productkind.setCurrentIndex(detail.pltype) self.prodname.setText(detail.prodid + ' ' + detail.prodname) self.commonname.setText(detail.commonname) self.spec.setText(detail.spec) self.package_2.setText(detail.package) self.planamount.setText(str(detail.planamount)) self.unit.setText(detail.spunit) self.batchno.setText(detail.batchno) self.makedate.setDate( QDate(detail.makedate) if type(detail.makedate) is datetime.date else user.now_date) self.remarks.setText(detail.remark) lineid = detail.lineid if lineid: productline = ProductLineConroller() pline = productline.get_productline(lineid, detail.pltype) if pline: self.prodline.setText(pline[0].linename) self.productworkshop.setText(pline[0].deptid + ' ' + pline[0].deptname) self.new_detail['linename'] = pline[0].linename self.new_detail['workshopid'] = pline[0].deptid self.new_detail['workshopname'] = pline[0].deptname def set_treewidget_formula(self, stufftype=(0, 1, 2), qtree=None): prodtype = 1 if self.productkind.currentIndex() == 1 else 0 qtree.clear() condition = { 'prodid': self.prod_id, 'stufftype__in': stufftype, 'prodtype': prodtype } # 获取配方 self.formula = self.PC.get_data(6, False, *VALUES_TUPLE_PD, **condition) if not len(self.formula): return stuffkind_list = self.formula.values_list('stuffkind', flat=True) condition_sk = {'stuffkind__in': stuffkind_list, 'amount__gt': 0} self.stuff_repository = self.WC.get_data(2, False, *VALUES_TUPLE_SD, **condition_sk) for it in self.stuff_repository: condition_lock = {'srid': it['autoid']} drawamount_list = self.PC.get_data( 7, True, *VALUES_TUPLE_SL, **condition_lock).exclude(ppid=self.autoid) it['realamount'] = it['amount'] - sum(drawamount_list) for item in self.formula: parent_treeitem = QTreeWidgetItem(qtree) parent_treeitem.setText(0, item['stuffkind']) parent_treeitem.setText(2, item['formula']) stuffkind = item['stuffkind'] condition_sf = {'stuffkind': stuffkind, 'amount__gt': 0} # 获取库存 stuffrepository = self.WC.get_data(2, False, *VALUES_TUPLE_SD, **condition_sf) if not len(stuffrepository): brush = QBrush(1) brush.setColor(QColor(255, 85, 0)) for i in range(0, 13): parent_treeitem.setBackground(i, brush) # Decimal(rnd(eval(presexpression, evalenv(self)), # precision)) parent_treeitem.setText( 6, str(self.no_stuffrep_count_presamount(item)) + item['presunit']) self.no_enough_stuff_list.append(stuffkind) continue draw_status = self.draw_stuff(item) if not draw_status: self.no_enough_stuff_list.append(stuffkind) brush = QBrush(1) brush.setColor(QColor(255, 255, 127)) for i in range(1, 13): parent_treeitem.setBackground(i, brush) for it in stuffrepository: condition_lock = {'srid': it['autoid']} drawamount_list = self.PC.get_data(7, True, *VALUES_TUPLE_SL, **condition_lock) qtreeitem = QTreeWidgetItem(parent_treeitem) qtreeitem.setText(1, str(it['autoid'])) qtreeitem.setText(0, it['stuffname']) qtreeitem.setText(3, it['batchno']) qtreeitem.setText(4, str(it['amount'])) qtreeitem.setText(5, str(sum(drawamount_list))) for sr in self.stuff_list: if it['autoid'] == sr['autoid']: qtreeitem.setText( 7, str(sr['newpracamount']) + item['pracunit']) qtreeitem.setText( 8, str(sr['drawamount']) + item['drawunit']) parent_treeitem.setText( 6, str(sr['presamount']) + item['presunit']) break if stufftype == (0, 1, 2): qtreeitem.setText(9, str(it['content']) + it['cunit']) qtreeitem.setText(10, str(it['water']) + '%') qtreeitem.setText(11, str(it['rdensity'])) qtreeitem.setText(12, str(it['impurity'])) qtree.expandAll() qtree.resizeColumnToContents(0) for i in range(2, 13 if stufftype == (0, 1, 2) else 9): qtree.resizeColumnToContents(i) qtree.collapseAll() def no_stuffrep_count_presamount(self, item): stuffkind = item['stuffkind'] precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression(item['presexpression'], 1) # 计划量 try: presamount = Decimal( rnd(eval(presexpression, evalenv(self)), precision)) return presamount except SyntaxError: if stuffkind + ' 计划量' not in self.errormsg: self.errormsg.append(stuffkind + ' 计划量') return 0 # 系统根据配方自动领料 def draw_stuff(self, item): stuffkind = item['stuffkind'] precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression(item['presexpression'], 1) # 计划量 try: presamount = Decimal( rnd(eval(presexpression, evalenv(self)), precision)) except SyntaxError: if stuffkind + ' 计划量' not in self.errormsg: self.errormsg.append(stuffkind + ' 计划量') presamount = 0 # 实际量公式,去除系统变量 pracexpression = self.reckon_expression(item['pracexpression'], 1) # 领取量公式,去除系统变量 drawexpression = self.reckon_expression(item['drawexpression'], 1) # 计算领料量,返回领料情况res, 和标记:是否已经领购料 res = self.reckon_drawamount(stuffkind, presamount, precision, pracexpression, drawexpression, loss) if len(res): self.stuff_list_additem(res) return self.is_drawamount_enough(stuffkind, presamount) # 判断领取的物料是否足够 def is_drawamount_enough(self, stuffkind, presamount): new_presamount = 0 for item in self.stuff_list: if item['stuffkind'] == stuffkind: new_presamount += item['newpresamount'] return True if new_presamount >= presamount else False # 把领取的物料加到领料记录中,如果发现重复的情况则替换旧的记录 def stuff_list_additem(self, newitems): for newitem in newitems: flat = 0 for item in self.stuff_list: if newitem['autoid'] == item['autoid']: # item = newitem flat = 1 break if flat == 0: self.stuff_list.append(newitem) # 计算系统变量 def reckon_expression(self, expression, iterdepth): # iterdepth:迭代深度,超过50则抛出RuntimeError # 产品信息变量,ex: @planamount@, @spec@, @package@ if iterdepth > 50: raise RuntimeError pattern = re.findall(r'@[%?!()()::.#\w]*@', expression) for item in pattern: # 引用其他物料 if len(item[1:-1].split('.')) == 2: var_name, var_item = item[1:-1].split('.') value = Decimal('0') # 标记是否找到了对应的物料 find_stuff_flag = 0 for stuff in self.stuff_list: if stuff['stuffkind'] == var_name: find_stuff_flag = 1 if var_item == '计划量': value = stuff[VAR_ITEM[var_item]] expression = expression.replace(item, str(value)) break else: value += stuff[VAR_ITEM[var_item]] expression = expression.replace(item, str(value)) # 没有找到对应的物料则再本领料单中继续寻找 if find_stuff_flag == 0: for item in self.formula: try: if item['stuffkind'] == var_name: # stuffkind = item.text(2) precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression( item['presexpression'], iterdepth + 1) # 计划量 try: presamount = Decimal( rnd( eval(presexpression, evalenv(self)), precision)) except SyntaxError: if var_name + ' 计划量' not in self.errormsg: self.errormsg.append(var_name + ' 计划量') presamount = 0 # 把计划量加到产品信息变量中 # self.detail['presamount'] = presamount # 实际量公式,去除系统变量 pracexpression = self.reckon_expression( item['pracexpression'], iterdepth + 1) # 领取量公式,去除系统变量 drawexpression = self.reckon_expression( item['drawexpression'], iterdepth + 1) # 计算领料量,返回领料情况res, 和标记:是否已经领购料 res = self.reckon_drawamount( var_name, presamount, precision, pracexpression, drawexpression, loss) if len(res): self.stuff_list_additem(res) # self.is_drawamount_enough() expression = self.reckon_expression( expression, iterdepth + 1) except RuntimeError: break # 引用生产指令的参数 else: key = item.replace('@', '') if key in self.detail: expression = expression.replace(item, str(self.detail[key])) # pattern_1 = re.findall(r'@[%?!()()::.#\w]*@', expression) return expression # 计算实际量 def reckon_pracamount(self, autoid, presamount, precision, expression): # stuffkind: 物料种类 # presamount: 计划量 # expression: 实际量的公式 stuff_detail = [] # 最终要领取的批次和实际量 # 分析公式,获取变量 pattern = re.findall(r'@\w*@', expression) # 把变量设置为对应的值 for item in self.stuff_repository: if autoid != item['autoid']: continue for key in pattern: k = key.replace('@', '') if k == 'presamount': expression = expression.replace(key, str(presamount)) elif k in item: expression = expression.replace(key, str(item[k])) elif k in self.detail: expression = expression.replace(key, str(self.detail[k])) try: pracamount = Decimal( rnd(eval(expression, evalenv(self)), precision)) except SyntaxError: if item['stuffkind'] + ' 实际量' not in self.errormsg: self.errormsg.append(item['stuffkind'] + ' 实际量') pracamount = 0 item['pracamount'] = pracamount # 计算领取量 # stuffkindorsrid: 根据flat决定类型, True是物料种类,False是srid # presamount: 计划量 # precision: 计算结果精度 # prac_expression: 实际量公式 # draw_expression: 领取公式 # loss: 损耗限度 # flat: 是否需要继续领下一批物料,默认为True即继续领下一批物料, # False则不再领取下一批物料 def reckon_drawamount(self, stuffkindorsrid, presamount, precision, prac_expression, draw_expression, loss=0, flat=True): # 要领取的物料批次 draw_list = [] # 已经领取了的量 has_drawamount = 0 # 分析公式,获取变量 pattern = re.findall(r'@\w*@', draw_expression) # 把变量设置为对应的值 for item in self.stuff_repository: item['presamount'] = presamount new_expression = draw_expression if has_drawamount != 0: presamount -= has_drawamount has_drawamount = 0 if stuffkindorsrid != (item['stuffkind'] if flat else str(item['autoid'])): continue item['loss'] = loss item['newpresamount'] = presamount item['precision'] = precision # 算出该批次对应的实际量 self.reckon_pracamount(item['autoid'], presamount, precision, prac_expression) for key in pattern: k = key.replace('@', '') if k in item: new_expression = new_expression.replace(key, str(item[k])) elif k in self.detail: new_expression = new_expression.replace( key, str(self.detail[k])) try: drawamount = Decimal( rnd(eval(new_expression, evalenv(self)), precision)) except SyntaxError: if stuffkindorsrid + ' 领取量' not in self.errormsg: self.errormsg.append(stuffkindorsrid + ' 领取量') drawamount = 0 continue if item['realamount'] >= drawamount: item['drawamount'] = drawamount item['newpracamount'] = item['pracamount'] draw_list.append(item) break else: # 转化为计划量 = 领取量 * 计划量 / 实际量 has_drawamount = Decimal( rnd(item['realamount'] * presamount / item['pracamount'], precision)) item['newpresamount'] = has_drawamount item['newpracamount'] = rnd(item['realamount'], precision) item['drawamount'] = rnd(item['realamount'], precision) draw_list.append(item) if not flat: # 指定库存记录时,默认按领够料处理 break return draw_list # 产品种类改变时 @pyqtSlot(int) def on_productkind_currentIndexChanged(self, p_int): if p_int in (0, 2, 3): self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY, VALUE_NAME, None, 650, 250) else: self.prodname.setup(DB_TABLE[1], STUFF_VALUE_TUPLE, STUFF_KEY, VALUE_NAME, None, 650, 250) # 修改计划量时触发 @pyqtSlot() def on_planamount_editingFinished(self): p_str = self.planamount.text() planamount = Decimal(p_str) if p_str != '' else 0 try: if planamount != self.ori_detail['planamount']: self.new_detail['planamount'] = planamount self.detail['planamount'] = planamount else: try: del self.new_detail['planamount'] except KeyError: pass except KeyError: self.new_detail['planamount'] = planamount self.detail['planamount'] = planamount self.stuff_list = [] self.stuff_repository = [] self.no_enough_stuff_list = [] self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial) self.set_treewidget_formula((3, 4), self.treeWidget_package) # 修改批号时触发 @pyqtSlot(str) def on_batchno_textEdited(self, p_str): try: if p_str != self.ori_detail['batchno']: self.new_detail['batchno'] = p_str else: try: del self.new_detail['batchno'] except KeyError: pass except KeyError: self.new_detail['batchno'] = p_str # 修改生产日期时触发 @pyqtSlot(QDate) def on_makedate_dateChanged(self, q_date): p_date = q_date.toPyDate() try: if p_date != self.ori_detail['makedate']: self.new_detail['makedate'] = p_date else: try: del self.new_detail['makedate'] except KeyError: pass except KeyError: self.new_detail['makedate'] = p_date # 修改备注时触发 @pyqtSlot(str) def on_remarks_textChanged(self, p_str): try: if p_str != self.ori_detail['remark']: self.new_detail['remark'] = p_str else: try: del self.new_detail['remark'] except KeyError: pass except KeyError: self.new_detail['remark'] = p_str @pyqtSlot() def on_accept_button_clicked(self): if self.prodname.flat == 0: text = "没有找到对应的产品信息,请修改后重试!" informative = "选择好产品名称后请不要再修改,否则将导致系统无法找到正确的产品!" errordialig = MessageBox(self, text=text, informative=informative) errordialig.exec() self.prodname.setFocus() return if len(self.no_enough_stuff_list): text = "以下物料不足!" informative = ";\n".join(self.no_enough_stuff_list) errordialig = MessageBox(self, text=text, informative=informative, yes_text="继续下达指令") res = errordialig.exec() if res == 65536: self.prodname.setFocus() return # 有修改过数据 if self.new_detail: try: # 修改过记录,把当前的人员和日期存入修改记录中 self.new_detail['instructorid'] = user.user_id self.new_detail['instructorname'] = user.user_name self.new_detail['plandate'] = user.now_date self.new_detail['deptid'] = user.dept_id self.new_detail['deptname'] = user.dept_name self.new_detail['bpconstitutorid'] = user.user_id self.new_detail['bpconstitutorname'] = user.user_name self.new_detail['bpconsdate'] = user.now_date # autoid不为空,则为修改记录 # 否则为插入记录 if self.autoid: self.PC.update_producingplan(autoid=self.autoid, **self.new_detail) condition = {'ppid': self.autoid} self.PC.delete_data(7, condition) else: prodtype = self.productkind.currentIndex() prod_id = self.prodname.namelist.currentItem().text(0) self.new_detail['id'] = prod_id ppid = self.PC.update_producingplan(prodtype=prodtype, **self.new_detail) self.autoid = ppid self.created.emit(self.autoid) for item in self.stuff_list: detail = { 'ppid': self.autoid, 'srid': item['autoid'], 'drawamount': item['drawamount'], 'stuffkind': item['stuffkind'] } self.PC.update_data(7, **detail) self.accept() except Exception as e: SaveExcept(e, "提交生产指令时出错", **self.new_detail) else: self.close() @pyqtSlot() def on_cancel_button_clicked(self): self.close() @pyqtSlot() def on_pushButton_audit_clicked(self): if len(self.no_enough_stuff_list): text = "以下物料不足!无法执行指令!" informative = ";\n".join(self.no_enough_stuff_list) errordialig = MessageBox(self, text=text, informative=informative) errordialig.exec() return if self.autoid is None: self.new_detail['instructorid'] = user.user_id self.new_detail['instructorname'] = user.user_name self.new_detail['plandate'] = user.now_date self.new_detail['deptid'] = user.dept_id self.new_detail['deptname'] = user.dept_name self.new_detail['bpconstitutorid'] = user.user_id self.new_detail['bpconstitutorname'] = user.user_name self.new_detail['bpconsdate'] = user.now_date self.new_detail['status'] = 1 self.new_detail['statustime'] = user.now_time self.new_detail['warrantorid'] = user.user_id self.new_detail['warrantorname'] = user.user_name self.new_detail['warrantdate'] = user.now_date self.new_detail['qadate'] = user.now_date self.new_detail['bpwarrantorid'] = user.user_id self.new_detail['bpwarrantorname'] = user.user_name self.new_detail['bpwarrantdate'] = user.now_date if self.autoid is None: prodtype = self.productkind.currentIndex() prod_id = self.prodname.namelist.currentItem().text(0) self.new_detail['id'] = prod_id ppid = self.PC.update_producingplan(prodtype=prodtype, **self.new_detail) self.autoid = ppid self.created.emit(self.autoid) # self.PC.update_data(3, **self.new_detail) else: condition = {'autoid': self.autoid} self.PC.update_data(3, condition, **self.new_detail) for item in self.stuff_list: if item['drawamount'] == 0: continue detail = { 'ppid': self.autoid, 'srid': item['autoid'], 'drawamount': item['drawamount'], 'stuffkind': item['stuffkind'] } self.PC.update_data(7, **detail) self.accept()
class LabrecordsController(object): def __init__(self): self.SFC = SelfdefinedformatController() self.EC = EquipmentController() self.SC = StuffController() self.PC = ProductController() def get_labrecord(self, flag=False, *args, **kwargs): return LabModel.get_labrecord(flag, *args, **kwargs) def get_labitem(self, flag=False, *args, **kwargs): return LabModel.get_labitem(flag, *args, **kwargs) def get_labimages(self, flag=False, kind=2, scid=0): values_list_rela = [ 'autoid', 'title', 'imageid', 'creatorid', 'creatorname', 'createdate' ] key_dict_rela = {'kind': kind, 'scid': scid} res = ImagesModel.get_rela(flag, *values_list_rela, **key_dict_rela) if not len(res): return [] img_list = [] for item in res: img_list.append(item['imageid']) values_list_img = ['autoid', 'img', 'ext'] key_dict_img = {'autoid__in': img_list} image_list = ImagesModel.get_img(flag, *values_list_img, **key_dict_img) for it in res: for value in image_list: if it['imageid'] == value['autoid']: it.update({'image': value['img'], 'ext': value['ext']}) break return res def select_oricheckpaper(self, dictid, itemtype=0): if not dictid: return [] if itemtype in (0, 1, 2): condition = {'stuffid': dictid} res = self.SC.get_data(0, True, *VALUES_TUPLE_ID, **condition) if not len(res): return [] id = res[0] elif itemtype in (3, 4, 5, 6): condition = {'prodid': dictid} res = self.PC.get_data(1, True, *VALUES_TUPLE_ID, **condition) if not len(res): return [] id = res[0] else: id = int(dictid) key_dict = {'dictid': id, 'itemtype': itemtype} sdfid_list = LabModel.get_oricheckpapersetting(True, *VALUES_TUPLE_SD, **key_dict) if len(sdfid_list): values_list_sdf = ['autoid', 'kind', 'formatname'] key_dict_sdf = {'autoid__in': sdfid_list} return self.SFC.get_selfdefinedformat(False, *values_list_sdf, **key_dict_sdf) else: return [] def get_selfdefineformat(self, flag=False, *args, **kwargs): return self.SFC.get_selfdefinedformat(False, *args, **kwargs) def get_oricheckpaper(self, flag=False, *args, **kwargs): return LabModel.get_oricheckpaper(flag, *args, **kwargs) def get_paperno(self, lrid): return LabModel.get_paperno(lrid) def update_labrecord(self, autoid=0, *args, **kwargs): return LabModel.update_labrecord(autoid, *args, **kwargs) def delete_labrecord(self, autoid=0, *args, **kwargs): return LabModel.delete_labrecord(autoid, *args, **kwargs) def update_labitem(self, autoid=0, *args, **kwargs): return LabModel.update_labitem(autoid, *args, **kwargs) def delete_labitem(self, autoid=0, *args, **kwargs): return LabModel.delete_labitem(autoid, *args, **kwargs) def update_labimages(self, relakwargs, imgkwargs, relaid=0, imgid=0): return ImagesModel.update_img(relakwargs, imgkwargs, relaid, imgid) def create_oricheckpaper(self, opid, op_detail, sdfid, sdf_detail): with transaction.atomic(): p1 = transaction.savepoint() condition = {'autoid': sdfid} res = self.SFC.get_data(0, False, *VALUES_TUPLE_SDF, **condition) if not len(res): transaction.savepoint_rollback(p1) return False sdf_data = { 'formname': res[0]['formatname'], 'formcontent': res[0]['format'] } sdf_data.update(sdf_detail) oripaper = self.update_data(2, **sdf_data) condition_2 = {'opid_id': opid} res_2 = self.get_data(8, False, **condition_2) for item in res_2: eqrun_data = { 'eqno': item.eqid.eqno, 'rtype': 1, 'pid': oripaper.autoid } eqrun_data.update(op_detail) self.EC.update_data(1, **eqrun_data) return oripaper def delete_labimages(self, relaid, imgid): return ImagesModel.delete_img(relaid, imgid) def delete_oricheckpaper(self, id): with transaction.atomic(): p1 = transaction.savepoint() condition = {'autoid': id} self.delete_data(2, **condition) condition_eqrun = {'pid': id, 'rtype': 1} self.EC.delete_data(1, **condition_eqrun) return True def get_data(self, table_num: int, display_flag=False, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "查询" + TABLE_SET[table_num][1] return LabModel.get_data(table_str, err_msg, display_flag, *args, **kwargs) def update_data(self, table_num: int, condition={}, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "更新" + TABLE_SET[table_num][1] return LabModel.update_data(table_str, err_msg, condition, *args, **kwargs) def delete_data(self, table_num: int, condition={}, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "删除" + TABLE_SET[table_num][1] return LabModel.delete_data(table_str, err_msg, condition, *args, **kwargs) def create_labrecord(self, checkitem_id, itemtype, date, *args, **kwargs): with transaction.atomic(): p1 = transaction.savepoint() new_labrecor = self.update_data(0, **kwargs) lrid = new_labrecor.autoid key_dict_checkitem = { 'stuffid': checkitem_id, 'itemtype': itemtype } checkitems = self.get_data(4, False, *VALUES_TUPLE_CHECKITEM, **key_dict_checkitem) for item in checkitems: kwargs_checkitem = { 'lrid': lrid, 'seqid': item['seqid'], 'itemname': item['itemname'], 'kind': item['kind'], 'referencevalue': item['referencevalue'], 'labvalue': item['referencevalue'], 'putintype': item['putintype'], 'startdate': date, 'enddate': date, 'checked': 2 } self.update_data(1, **kwargs_checkitem) return lrid def delete_labrecord_and_detail(self, lrid=0, *args, **kwargs): with transaction.atomic(): p1 = transaction.savepoint() if lrid != 0: condition_lr = {'autoid': lrid} condition_detail = {'autoid': lrid} else: condition_lr = {'autoid__in': args} condition_detail = {'autoid__in': args} self.delete_data(0, condition_lr) self.delete_data(1, condition_detail) self.delete_data(2, condition_detail) def delete_sample_record(self, srid): with transaction.atomic(): p1 = transaction.savepoint() condition = {'srid_id': srid} lrid_list = self.get_data(7, False, **condition).extra( select={ 'lrid': 'Labrecords.autoid' }, tables=['Labrecords'], where=[ 'Labrecords.ciid=Observationrecords.autoid', 'Labrecords.labtype=6' ]).values_list(*VALUES_TUPLE_OB, flat=True) if len(lrid_list): self.delete_labrecord_and_detail(*lrid_list) condition = {'autoid': srid} self.delete_data(6, condition)
class EditStuffDetailModule(QDialog, Ui_Dialog): def __init__(self, autoid=None, parent=None): super(EditStuffDetailModule, self).__init__(parent) self.setupUi(self) self.autoid = autoid self.SC = StuffController() self.LC = LabrecordsController() self.PC = ProductController() self.SPC = SupplyerController() self.ori_detail = {} self.new_detail = {} self.get_detail() if len(self.ori_detail): stufftype = self.ori_detail['stufftype'] if stufftype == 1: self.tab.removeTab(4) self.tab.removeTab(1) else: self.tab.removeTab(3) self.tab.removeTab(2) self.get_formula() self.get_checkitem(0, self.treeWidget_checkitem) self.get_checkitem(2, self.treeWidget_precheckitem) self.get_stuffsupplyer() def get_detail(self): if self.autoid is None: self.tab.setTabVisible(1, False) self.tab.setTabVisible(2, False) self.tab.setTabVisible(3, False) self.tab.setTabVisible(4, False) return condition = {'autoid': self.autoid} res = self.SC.get_data(0, False, *VALUES_TUPLE_SD, **condition) if len(res) != 1: return self.ori_detail = res[0] self.comboBox_stufftype.setCurrentIndex(self.ori_detail['stufftype']) self.lineEdit_stuffid.setText(self.ori_detail['stuffid']) self.lineEdit_stuffname.setText(self.ori_detail['stuffname']) self.lineEdit_kind.setText(self.ori_detail['kind']) self.lineEdit_allowno.setText(self.ori_detail['allowno']) self.lineEdit_inputcode.setText(self.ori_detail['inputcode']) self.lineEdit_spec.setText(self.ori_detail['spec']) self.comboBox_packageLv.setCurrentIndex(self.ori_detail['packagelv']) self.lineEdit_package.setText(self.ori_detail['package']) self.comboBox_midcheckunit.setCurrentText( self.ori_detail['midcheckunit']) self.comboBox_prodcheckunit.setCurrentText( self.ori_detail['prodcheckunit']) self.lineEdit_expired.setText(str(self.ori_detail['expireddays'])) self.lineEdit_storage.setText(self.ori_detail['storage']) self.lineEdit_lowlimit.setText(str(self.ori_detail['lowlimit'])) self.lineEdit_upperlimit.setText(str(self.ori_detail['upperlimit'])) self.lineEdit_recheck.setText(str(self.ori_detail['countercheckdays'])) self.lineEdit_cunit.setText(self.ori_detail['cunit']) def get_checkitem(self, itemtype, tree): tree.clear() condition = {'stuffid': self.autoid, 'itemtype': itemtype} res = self.LC.get_data(4, False, *VALUES_TUPLE_CI, **condition). \ order_by('seqid') if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(tree) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['seqid'])) qtreeitem.setText(2, item['kind']) qtreeitem.setText(3, item['itemname']) qtreeitem.setText(4, item['referencevalue']) qtreeitem.setText(5, RESTYPE[item['restype']]) qtreeitem.setText(6, PUTINTYPE[item['putintype']]) for i in range(1, 7): tree.resizeColumnToContents(i) def get_formula(self): if self.autoid is None: return self.treeWidget_formula.clear() condition = {'prodid': self.autoid, 'prodtype': 1} res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_formula) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, STUFFTYPE[item['stufftype']]) qtreeitem.setText(2, item['stuffkind']) qtreeitem.setText(3, item['formula']) qtreeitem.setText(4, item['presexpression']) qtreeitem.setText(5, item['presunit']) qtreeitem.setText(6, item['pracexpression']) qtreeitem.setText(7, item['pracunit']) qtreeitem.setText(8, item['drawexpression']) qtreeitem.setText(9, item['drawunit']) qtreeitem.setText(10, str(item['precision'])) qtreeitem.setText(11, str(item['loss']) + "%") for i in range(1, 12): self.treeWidget_formula.resizeColumnToContents(i) def get_stuffsupplyer(self): self.treeWidget_stuffsupplyer.clear() condition = {'sdid_id': self.autoid} res = self.SPC.get_data(1, **condition) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_stuffsupplyer) qtreeitem.setText(0, str(item.autoid)) qtreeitem.setText(1, item.spid.supid) qtreeitem.setText(2, item.spid.supname) qtreeitem.setText(3, item.producer) for i in range(1, 4): self.treeWidget_stuffsupplyer.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_precheckitem_itemDoubleClicked(self, p_int): self.on_checkitem_itemDoubleClicked(self.treeWidget_precheckitem, 2) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_checkitem_itemDoubleClicked(self, p_int): self.on_checkitem_itemDoubleClicked(self.treeWidget_checkitem, 0) # 原料检验项目,双击打开详细信息 def on_checkitem_itemDoubleClicked(self, tree, itemtype): # if self.power[1] == '0': # return detail = SetCheckItem(self, tree.currentItem().text(0)) detail.accepted.connect(lambda: self.get_checkitem(itemtype, tree)) detail.show() @pyqtSlot(QPoint) def on_treeWidget_precheckitem_customContextMenuRequested(self, pos): self.on_checkitem_customContextMenuRequested( self.treeWidget_precheckitem, 2, pos) @pyqtSlot(QPoint) def on_treeWidget_checkitem_customContextMenuRequested(self, pos): self.on_checkitem_customContextMenuRequested(self.treeWidget_checkitem, 0, pos) # 检验项目的右键菜单功能 def on_checkitem_customContextMenuRequested(self, tree, itemtype, pos): # if self.power[1] == '0': # return menu = QMenu() button1 = menu.addAction("增加") button2 = menu.addAction("修改") button3 = menu.addAction("删除") button4 = menu.addAction("复制") button5 = menu.addAction("黏贴") global_pos = tree.mapToGlobal(pos) action = menu.exec(global_pos) # 增加 if action == button1: set_check_item = SetCheckItem(self, prodid=self.autoid, itemtype=itemtype) set_check_item.accepted.connect( lambda: self.get_checkitem(itemtype, tree)) set_check_item.show() # 修改 elif action == button2: current_item = tree.currentItem() if current_item is None: return id = int(current_item.text(0)) set_check_item = SetCheckItem(self, autoid=id) set_check_item.accepted.connect( lambda: self.get_checkitem(itemtype, tree)) set_check_item.show() # 删除 elif action == button3: select_item = tree.selectedItems() checkitem_autoid = [] for item in select_item: checkitem_autoid.append(item.text(0)) condition = {'autoid__in': checkitem_autoid} self.LC.delete_data(4, condition) self.get_checkitem(itemtype, tree) # 复制 elif action == button4: clipboard = QApplication.clipboard() items = tree.selectedItems() select_item = tree.mimeData(items) clipboard.setMimeData(select_item) # 黏贴 elif action == button5: try: clipboard = QApplication.clipboard() data = clipboard.mimeData() # 获取当前行数,加1即为新的行号 count = tree.topLevelItemCount() res = tree.dropMimeData(tree.invisibleRootItem(), count + 1, data, Qt.CopyAction) finnal_index = tree.topLevelItemCount() if res: while count < finnal_index: tree_item = tree.topLevelItem(count) if tree_item is None: raise AttributeError detail = dict() detail["seqid"] = tree_item.text(1) detail["kind"] = tree_item.text(2) detail["itemname"] = tree_item.text(3) detail["referencevalue"] = tree_item.text(4) detail["restype"] = RESTYPE.index(tree_item.text(5)) detail["putintype"] = PUTINTYPE.index( tree_item.text(6)) detail["stuffid"] = self.autoid detail["itemtype"] = itemtype new_item = self.LC.update_data(4, **detail) tree_item.setText(0, str(new_item.autoid)) count += 1 except Exception as e: pass else: pass @pyqtSlot(QPoint) def on_treeWidget_formula_customContextMenuRequested(self, pos): # if self.power[1] == '0': # return current_item = self.treeWidget_formula.currentItem() menu = QMenu() action_1 = menu.addAction("增加") action_2 = menu.addAction("修改") action_3 = menu.addAction("删除") global_pos = self.treeWidget_formula.mapToGlobal(pos) action = menu.exec(global_pos) if action == action_1: detail = EditFormulaModule(prodid=self.autoid, prodtype=1, parent=self) detail.accepted.connect(self.get_formula) detail.show() elif action == action_2: if current_item is None: return id = int(current_item.text(0)) detail = EditFormulaModule(autoid=id, parent=self) detail.accepted.connect(self.get_formula) detail.show() elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.PC.delete_data(6, condition) self.get_formula() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_formula_itemDoubleClicked(self, qtreeitem, p_int): # if self.power[1] == '0': # return id = int(qtreeitem.text(0)) detail = EditFormulaModule(autoid=id, parent=self) detail.accepted.connect(self.get_formula) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_stuffsupplyer_itemDoubleClicked(self, qtreeitem, p_int): id = int(qtreeitem.text(0)) detail = StuffSupplyerModule(autoid=id, parent=self) detail.accepted.connect(self.get_stuffsupplyer) detail.show() # 物料供应商和生产厂家的右键菜单功能 @pyqtSlot(QPoint) def on_treeWidget_stuffsupplyer_customContextMenuRequested(self, pos): # 返回调用者的对象 current_item = self.treeWidget_stuffsupplyer.currentItem() menu = QMenu() button1 = menu.addAction("增加") button2 = menu.addAction("修改") button3 = menu.addAction("删除") button4 = menu.addAction("复制") button5 = menu.addAction("黏贴") global_pos = self.treeWidget_stuffsupplyer.mapToGlobal(pos) action = menu.exec(global_pos) # 增加 if action == button1: detail = StuffSupplyerModule(sdid=self.autoid, parent=self) detail.accepted.connect(self.get_stuffsupplyer) detail.show() # 修改 elif action == button2: if current_item is None: return id = int(current_item.text(0)) detail = StuffSupplyerModule(autoid=id, parent=self) detail.accepted.connect(self.get_stuffsupplyer) detail.show() # 删除 elif action == button3: select_item = self.treeWidget_stuffsupplyer.selectedItems() item_autoid = [] for item in select_item: item_autoid.append(int(item.text(0))) self.SPC.delete_data(1, *item_autoid) self.get_stuffsupplyer() # 复制 elif action == button4: clipboard = QApplication.clipboard() # 当前选择的项目 items = self.treeWidget_stuffsupplyer.selectedItems() # 把项目转为Mime对象 select_item = self.treeWidget_stuffsupplyer.mimeData(items) # 把Mime对象存入剪切板 clipboard.setMimeData(select_item) # 黏贴 elif action == button5: clipboard = QApplication.clipboard() # 获取剪切板里的内容 data = clipboard.mimeData() # 获取当前行数,加1即为新的行号 count = self.treeWidget_stuffsupplyer.topLevelItemCount() # dropMineData,把Mime对象转回Qtreeitem # 第一个参数:要添加到的父节点 # 第二个参数:行号 # 第三个参数:Mime数据 res = self.treeWidget_stuffsupplyer.dropMimeData( self.treeWidget_stuffsupplyer.invisibleRootItem(), count + 1, data, Qt.CopyAction) # 黏贴完成后的行数 finnal_index = self.treeWidget_stuffsupplyer.topLevelItemCount() if res: # 把黏贴的数据加入数据库中 # 数据从count到finnal_index即为黏贴的行号 while count < finnal_index: tree_item = self.treeWidget_stuffsupplyer.topLevelItem( count) if tree_item is None: return condition = {'autoid': int(tree_item.text(0))} res = self.SPC.get_data(1, **condition) if len(res) != 1: return ori_data = res[0] detail = dict() detail["spid_id"] = ori_data.spid_id detail["producer"] = ori_data.producer detail["sdid_id"] = self.autoid self.SPC.update_data(1, **detail) count += 1 self.get_stuffsupplyer() else: pass # 修改种类时触发 @pyqtSlot(int) def on_comboBox_stufftype_currentIndexChanged(self, p_int): try: if p_int != int(self.ori_detail['stufftype']): self.new_detail['stufftype'] = p_int else: try: del self.new_detail['stufftype'] except KeyError: pass except KeyError: self.new_detail['stufftype'] = p_int # 修改编号时触发 @pyqtSlot(str) def on_lineEdit_stuffid_textChanged(self, p_str): try: if p_str != self.ori_detail['stuffid']: self.new_detail['stuffid'] = p_str else: try: del self.new_detail['stuffid'] except KeyError: pass except KeyError: self.new_detail['stuffid'] = p_str # 修改名称时触发 @pyqtSlot(str) def on_lineEdit_stuffname_textChanged(self, p_str): try: if p_str != self.ori_detail['stuffname']: self.new_detail['stuffname'] = p_str self.lineEdit_inputcode.setText( Inputcode.make_inputcode(p_str)) self.lineEdit_kind.setText(p_str) else: try: del self.new_detail['stuffname'] except KeyError: pass except KeyError: self.new_detail['stuffname'] = p_str # 修改种类时触发 @pyqtSlot(str) def on_lineEdit_kind_textChanged(self, p_str): try: if p_str != self.ori_detail['kind']: self.new_detail['kind'] = p_str else: try: del self.new_detail['kind'] except KeyError: pass except KeyError: self.new_detail['kind'] = p_str # 修改批准文号时触发 @pyqtSlot(str) def on_lineEdit_allowno_textChanged(self, p_str): try: if p_str != self.ori_detail['allowno']: self.new_detail['allowno'] = p_str else: try: del self.new_detail['allowno'] except KeyError: pass except KeyError: self.new_detail['allowno'] = p_str # 修改输入码时触发 @pyqtSlot(str) def on_lineEdit_inputcode_textChanged(self, p_str): try: if p_str != self.ori_detail['inputcode']: self.new_detail['inputcode'] = p_str else: try: del self.new_detail['inputcode'] except KeyError: pass except KeyError: self.new_detail['inputcode'] = p_str # 修改含量规格时触发 @pyqtSlot(str) def on_lineEdit_spec_textChanged(self, p_str): try: if p_str != self.ori_detail['spec']: self.new_detail['spec'] = p_str else: try: del self.new_detail['spec'] except KeyError: pass except KeyError: self.new_detail['spec'] = p_str # 修改包装级别时触发 @pyqtSlot(int) def on_comboBox_packageLv_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail['packagelv']: self.new_detail['packagelv'] = p_int else: try: del self.new_detail['packagelv'] except KeyError: pass except KeyError: self.new_detail['packagelv'] = p_int # 修改包装情况时触发 @pyqtSlot() def on_lineEdit_package_editingFinished(self): p_str = self.lineEdit_package.text() try: if p_str != self.ori_detail['package']: if self.set_package_rate(p_str): self.new_detail['package'] = p_str else: try: del self.new_detail['package'] except KeyError: pass except KeyError: if self.set_package_rate(p_str): self.new_detail['package'] = p_str def set_package_rate(self, package): lv = self.comboBox_packageLv.currentIndex() + 1 items = re.split(r'\*|×|x|X', package) if len(items) != lv: msg = MessageBox(title="错误1!", informative="包装比例错误!") msg.exec() return False num_tuple = ('basicamount', 'spamount', 'mpamount') unit_tuple = ('basicunit', 'spunit', 'mpunit', 'bpunit') try: for i in range(len(items)): values = re.findall(r'\d+|\w+', items[i]) self.new_detail[num_tuple[i]] = values[0] self.new_detail[unit_tuple[i]] = values[1] self.new_detail[unit_tuple[i + 1]] = values[2] return True except: msg = MessageBox(title="错误2!", informative="包装比例错误!") msg.exec() return False # 修改入库单位时触发 @pyqtSlot(str) def on_comboBox_midcheckunit_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['midcheckunit']: self.new_detail['midcheckunit'] = p_str else: try: del self.new_detail['midcheckunit'] except KeyError: pass except KeyError: self.new_detail['midcheckunit'] = p_str # 修改取样单位时触发 @pyqtSlot(str) def on_comboBox_prodcheckunit_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['prodcheckunit']: self.new_detail['prodcheckunit'] = p_str else: try: del self.new_detail['prodcheckunit'] except KeyError: pass except KeyError: self.new_detail['prodcheckunit'] = p_str # 修改库存上限时触发 @pyqtSlot(str) def on_lineEdit_upperlimit_textChanged(self, p_str): p_int = float(p_str) try: if p_int != self.ori_detail['upperlimit']: self.new_detail['upperlimit'] = p_int else: try: del self.new_detail['upperlimit'] except KeyError: pass except KeyError: self.new_detail['upperlimit'] = p_int # 修改库存下限时触发 @pyqtSlot(str) def on_lineEdit_lowlimit_textChanged(self, p_str): p_int = float(p_str) try: if p_int != self.ori_detail['lowlimit']: self.new_detail['lowlimit'] = p_int else: try: del self.new_detail['lowlimit'] except KeyError: pass except KeyError: self.new_detail['lowlimit'] = p_int # 修改复检天数时触发 @pyqtSlot(str) def on_lineEdit_recheck_textChanged(self, p_str): p_int = int(p_str) try: if p_int != self.ori_detail['countercheckdays']: self.new_detail['countercheckdays'] = p_int else: try: del self.new_detail['countercheckdays'] except KeyError: pass except KeyError: self.new_detail['countercheckdays'] = p_int # 修改有效期时触发 @pyqtSlot(str) def on_lineEdit_expired_textChanged(self, p_str): p_int = int(p_str) try: if p_int != self.ori_detail['expireddays']: self.new_detail['expireddays'] = p_int else: try: del self.new_detail['expireddays'] except KeyError: pass except KeyError: self.new_detail['expireddays'] = p_int # 修改效价单位时触发 @pyqtSlot(str) def on_lineEdit_cunit_textChanged(self, p_int): try: if p_int != self.ori_detail['cunit']: self.new_detail['cunit'] = p_int else: try: del self.new_detail['cunit'] except KeyError: pass except KeyError: self.new_detail['cunit'] = p_int # 修改储存条件时触发 @pyqtSlot(str) def on_lineEdit_storage_textChanged(self, p_int): try: if p_int != self.ori_detail['storage']: self.new_detail['storage'] = p_int else: try: del self.new_detail['storage'] except KeyError: pass except KeyError: self.new_detail['storage'] = p_int # 修改生产线和车间时触发 @pyqtSlot() def on_toolButton_workshop_clicked(self): setpl = SetProductLine(parent=self, pltype=1) setpl.select_line_signal.connect(self.setproductline) setpl.show() def setproductline(self, linedetail: dict): try: if linedetail['autoid'] != self.ori_detail['plid']: self.new_detail['plid'] = linedetail['autoid'] self.toolButton_workshop.setText(linedetail['deptname']) self.label_productionline.setText(linedetail['linename']) else: try: del self.new_detail['plid'] except KeyError: pass except KeyError: self.new_detail['plid'] = linedetail['autoid'] self.toolButton_workshop.setText(linedetail['deptname']) self.label_productionline.setText(linedetail['linename']) # 确认 @pyqtSlot() def on_pushButton_accept_clicked(self): if len(self.new_detail): if self.autoid is None: res = self.SC.update_data(0, **self.new_detail) self.autoid = res.autoid else: condition = {'autoiod': self.autoid} self.SC.update_data(0, condition, **self.new_detail) self.accept() # 取消 @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class EditProductDetailModule(QDialog, Ui_Dialog): check_item = CheckItem() def __init__(self, autoid=None, parent=None): super(EditProductDetailModule, self).__init__(parent) self.setupUi(self) if '2s' not in user.powers: self.close() if user.powers['2'] == 0: self.cloe() self.power = '{:03b}'.format(user.powers['2']) self.autoid = autoid self.img_status = 0 self.images_list = [] self.current_img = object self.current_page = object self.PC = ProductController() self.PLC = ProductLineConroller() self.LC = LabrecordsController() self.IC = ImageController() self.ori_detail = {} self.new_detail = {} self.get_detail() # 获取种类的下拉列表 self.get_medkind_list() self.get_qrtype() self.get_workshop() self.get_bworkshop() self.get_vworkshop() self.get_formula() self.get_images() self.get_checkitem(3, self.treeWidget_precheckitem) self.get_checkitem(4, self.treeWidget_prodcheckitem) self.get_checkitem(6, self.treeWidget_samplecheckitem) self.treeWidget_formula.hideColumn(0) self.treeWidget_precheckitem.hideColumn(0) self.treeWidget_prodcheckitem.hideColumn(0) self.treeWidget_samplecheckitem.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(1) def get_detail(self): if self.autoid is None: for i in range(5): self.tab.removeTab(i) self.pushButton_accept.setText("增加") return condition = {'autoid': self.autoid} res = self.PC.get_data(1, False, *VALUES_TUPLE_PD, **condition) if len(res) != 1: return self.ori_detail = res[0] self.lineEdit_prodid.setText(self.ori_detail['prodid']) self.lineEdit_prodname.setText(self.ori_detail['prodname']) self.lineEdit_commonname.setText(self.ori_detail['commonname']) self.lineEdit_allowno.setText(self.ori_detail['allowno']) self.lineEdit_inputcode.setText(self.ori_detail['inputcode']) self.lineEdit_spec.setText(self.ori_detail['spec']) self.comboBox_packageLv.setCurrentIndex(self.ori_detail['packagelv']) self.lineEdit_package.setText(self.ori_detail['package']) self.comboBox_midcheckunit.setCurrentText( self.ori_detail['midcheckunit'] ) self.comboBox_prodcheckunit.setCurrentText( self.ori_detail['prodcheckunit'] ) self.lineEdit_expireddates.setText(str(self.ori_detail['expireddates'])) self.lineEdit_storage.setText(self.ori_detail['storage']) def get_medkind_list(self): items = self.PC.get_data(1, True, *VALUES_TUPLE_MEDKIND).distinct() self.comboBox_medkind.addItems(items) if len(self.ori_detail): self.comboBox_medkind.setCurrentText(self.ori_detail['medkind']) def get_qrtype(self): if not len(self.ori_detail): return qrtype = '{:04b}'.format(self.ori_detail['qrtype']) self.checkBox_bp.setCheckState(2 if qrtype[0] == '1' else 0) self.checkBox_lp.setCheckState(2 if qrtype[1] == '1' else 0) self.checkBox_mp.setCheckState(2 if qrtype[2] == '1' else 0) self.checkBox_sp.setCheckState(2 if qrtype[3] == '1' else 0) def get_workshop(self): if not len(self.ori_detail) or self.ori_detail['plid'] == 0: return condition = {'autoid': self.ori_detail['plid']} res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition) if not len(res): return self.toolButton_workshop.setText(res[0]['deptname']) self.label_productionline.setText(res[0]['linename']) def get_bworkshop(self): if not len(self.ori_detail) or self.ori_detail['wplid'] == 0: return condition = {'autoid': self.ori_detail['wplid']} res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition) if not len(res): return self.toolButton_bworkshop.setText(res[0]['deptname']) self.label_bproductionline.setText(res[0]['linename']) def get_vworkshop(self): if not len(self.ori_detail) or self.ori_detail['vplid'] == 0: return condition = {'autoid': self.ori_detail['vplid']} res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition) if not len(res): return self.toolButton_vworkshop.setText(res[0]['deptname']) self.label_vproductionline.setText(res[0]['linename']) def get_checkitem(self, itemtype, tree): tree.clear() condition = {'stuffid': self.autoid, 'itemtype': itemtype} res = self.LC.get_data(4, False, *VALUES_TUPLE_CI, **condition). \ order_by('seqid') if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(tree) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['seqid'])) qtreeitem.setText(2, item['kind']) qtreeitem.setText(3, item['itemname']) qtreeitem.setText(4, item['referencevalue']) qtreeitem.setText(5, RESTYPE[item['restype']]) qtreeitem.setText(6, PUTINTYPE[item['putintype']]) for i in range(1, 7): tree.resizeColumnToContents(i) def get_formula(self): if self.autoid is None: return self.treeWidget_formula.clear() condition = {'prodid': self.autoid, 'prodtype': 0} res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_formula) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, STUFFTYPE[item['stufftype']]) qtreeitem.setText(2, item['stuffkind']) qtreeitem.setText(3, item['formula']) qtreeitem.setText(4, item['presexpression']) qtreeitem.setText(5, item['presunit']) qtreeitem.setText(6, item['pracexpression']) qtreeitem.setText(7, item['pracunit']) qtreeitem.setText(8, item['drawexpression']) qtreeitem.setText(9, item['drawunit']) qtreeitem.setText(10, str(item['precision'])) qtreeitem.setText(11, str(item['loss']) + "%") for i in range(1, 12): self.treeWidget_formula.resizeColumnToContents(i) def get_images(self): self.treeWidget_imagenamelist.clear() condition = {'prodid': self.autoid, 'flag': self.img_status} res = self.PC.get_data(2, False, **condition) if not len(res): return self.images_list = res for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist) qtreeitem.setText(0, str(item.autoid)) qtreeitem.setText(1, str(item.imgid_id)) qtreeitem.setText(2, item.imagename) qtreeitem.setText(3, item.modifierid + item.modifiername) qtreeitem.setText(4, str(item.modifydate)) @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): getattr(self, 'tab_' + str(p_int + 7)).setLayout(self.gridLayout_8) self.img_status = p_int self.get_images() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0': return rela_id = int(qtreeitem.text(0)) for item in self.images_list: if item.autoid == rela_id: if item.imgid.ext.lower() == 'pdf': self.comboBox_jumpto.setVisible(True) self.pushButton_prepage.setVisible(True) self.pushButton_nextpage.setVisible(True) self.current_img = fitz.Document(stream=item.imgid.img, filetype='pdf') page_count = self.current_img.pageCount page_list = [] self.comboBox_jumpto.clear() for i in range(1, page_count + 1): page_list.append('第' + str(i) + '页') self.comboBox_jumpto.addItems(page_list) self.current_page = self.current_img.loadPage(0) else: self.comboBox_jumpto.setVisible(False) self.pushButton_prepage.setVisible(False) self.pushButton_nextpage.setVisible(False) img = QImage.fromData(item.imgid.img) self.current_img = QPixmap.fromImage(img) self.label_image.setPixmap(self.current_img) break # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged self.horizontalSlider_zoom.setValue(30) @pyqtSlot(int) def on_horizontalSlider_zoom_valueChanged(self, p_int): try: self.label_zoom.setText(str(p_int * 10) + '%') # 把当前页面转为QPixmap,并缩放为p_int/10 cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10) self.label_image.setPixmap(cover) except (AttributeError, ValueError): size = self.current_img.size() new_pixmap = self.current_img.scaled(size.width() * p_int / 10, size.height() * p_int / 10) self.label_image.setPixmap(new_pixmap) @pyqtSlot(QPoint) def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos): if self.power[1] == '0': return # 返回调用者的对象 sender_widget = self.sender() menu = QMenu() button1 = menu.addAction("新增图片") button2 = menu.addAction("修改图片") button3 = menu.addAction("删除图片") button4 = menu.addAction("设为生效/失效") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) res = "rollback" # 增加 if action == button1: img_names, img_type = QFileDialog.getOpenFileNames( self, "打开图片", os.path.expanduser("~") + "\Desktop", "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)" ) for item in img_names: imagename_no_ext = item.split("/")[-1] image_ext = item.split(".")[1] if image_ext.lower() not in ("jpg", "png", "bmp", "gif", "pdf"): continue fp = open(item, 'rb') with fp: image_byte = fp.read() fp.close() imagedetail = { 'img': image_byte, 'ext': image_ext } reladetail = { 'prodid': self.autoid, 'imagename': imagename_no_ext, 'modifierid': user.user_id, 'modifiername': user.user_name, 'modifydate': user.now_date } res = self.IC.update_productlabel(reladetail, imagedetail) # 修改 elif action == button2: current_item = self.treeWidget_imagenamelist.currentItem() if current_item is None: return rela_id = int(current_item.text(0)) img_id = int(current_item.text(1)) img_name, img_type = QFileDialog.getOpenFileName( self, "打开图片", os.path.expanduser("~") + "\Desktop", "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)" ) imagename_no_ext = img_name.split("/")[-1] image_ext = img_name.split(".")[1] if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"): fp = open(img_name, 'rb') with fp: image_byte = fp.read() fp.close() imagedetail = { 'img': image_byte, 'ext': image_ext } reladetail = { 'imagename': imagename_no_ext, 'modifierid': user.user_id, 'modifiername': user.user_name, 'modifydate': user.now_date } res = self.IC.update_productlabel( reladetail, imagedetail, rela_id, img_id ) # 删除 elif action == button3: select_item = sender_widget.selectedItems() img_id = [] for item in select_item: img_id.append(int(item.text(1))) condition = {'autoid__in': img_id} self.IC.delete_data(1, condition) res = "accept" elif action == button4: select_item = sender_widget.selectedItems() rela_id = [] for item in select_item: rela_id.append(int(item.text(0))) if not len(rela_id): return condition = {'autoid__in': rela_id} detail = {'flag': 1 if self.img_status == 0 else 0} self.PC.update_data(2, condition, **detail) res = "accept" if res == "accept": self.get_images() @pyqtSlot(int) def on_comboBox_jumpto_currentIndexChanged(self, p_int): try: self.current_page = self.current_img.loadPage(p_int) self.on_horizontalSlider_zoom_valueChanged( self.horizontalSlider_zoom.value()) except (AttributeError, ValueError): pass @pyqtSlot() def on_pushButton_prepage_clicked(self): index = self.comboBox_jumpto.currentIndex() if index - 1 >= 0: try: self.current_page = self.current_img.loadPage(index - 1) self.comboBox_jumpto.setCurrentIndex(index - 1) except (AttributeError, ValueError): pass @pyqtSlot() def on_pushButton_nextpage_clicked(self): index = self.comboBox_jumpto.currentIndex() if index + 1 < self.comboBox_jumpto.count(): try: self.current_page = self.current_img.loadPage(index + 1) self.comboBox_jumpto.setCurrentIndex(index + 1) except (AttributeError, ValueError): pass @pyqtSlot(QPoint) def on_treeWidget_formula_customContextMenuRequested(self, pos): if self.power[1] == '0': return current_item = self.treeWidget_formula.currentItem() menu = QMenu() action_1 = menu.addAction("增加") action_2 = menu.addAction("修改") action_3 = menu.addAction("删除") global_pos = self.treeWidget_formula.mapToGlobal(pos) action = menu.exec(global_pos) if action == action_1: detail = EditFormulaModule( prodid=self.autoid, prodtype=0, parent=self ) detail.accepted.connect(self.get_formula) detail.show() elif action == action_2: if current_item is None: return id = int(current_item.text(0)) detail = EditFormulaModule(autoid=id, parent=self) detail.accepted.connect(self.get_formula) detail.show() elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.PC.delete_data(6, condition) self.get_formula() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_formula_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0': return id = int(qtreeitem.text(0)) detail = EditFormulaModule(autoid=id, parent=self) detail.accepted.connect(self.get_formula) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_precheckitem_itemDoubleClicked(self, qtreeitem, p_int): self.on_checkitem_itemDoubleClicked(self.treeWidget_precheckitem, 3) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_prodcheckitem_itemDoubleClicked(self, qtreeitem, p_int): self.on_checkitem_itemDoubleClicked(self.treeWidget_prodcheckitem, 4) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_samplecheckitem_itemDoubleClicked(self, qtreeitem, p_int): self.on_checkitem_itemDoubleClicked(self.treeWidget_samplecheckitem, 6) # 中间产品/成品/留样检验项目,双击打开详细信息 def on_checkitem_itemDoubleClicked(self, tree, itemtype): if self.power[1] == '0': return detail = SetCheckItem(self, tree.currentItem().text(0)) detail.accepted.connect(lambda: self.get_checkitem(itemtype, tree)) detail.show() @pyqtSlot(QPoint) def on_treeWidget_precheckitem_customContextMenuRequested(self, pos): self.on_checkitem_customContextMenuRequested( self.treeWidget_precheckitem, 3, pos ) @pyqtSlot(QPoint) def on_treeWidget_prodcheckitem_customContextMenuRequested(self, pos): self.on_checkitem_customContextMenuRequested( self.treeWidget_prodcheckitem, 4, pos ) @pyqtSlot(QPoint) def on_treeWidget_samplecheckitem_customContextMenuRequested(self, pos): self.on_checkitem_customContextMenuRequested( self.treeWidget_samplecheckitem, 6, pos ) # 检验项目的右键菜单功能 def on_checkitem_customContextMenuRequested(self, tree, itemtype, pos): if self.power[1] == '0': return menu = QMenu() button1 = menu.addAction("增加") button2 = menu.addAction("修改") button3 = menu.addAction("删除") button4 = menu.addAction("复制") button5 = menu.addAction("黏贴") global_pos = tree.mapToGlobal(pos) action = menu.exec(global_pos) # 增加 if action == button1: set_check_item = SetCheckItem( self, prodid=self.autoid, itemtype=itemtype ) set_check_item.accepted.connect( lambda: self.get_checkitem(itemtype, tree) ) set_check_item.show() # 修改 elif action == button2: current_item = tree.currentItem() if current_item is None: return id = int(current_item.text(0)) set_check_item = SetCheckItem( self, autoid=id ) set_check_item.accepted.connect( lambda: self.get_checkitem(itemtype, tree) ) set_check_item.show() # 删除 elif action == button3: select_item = tree.selectedItems() checkitem_autoid = [] for item in select_item: checkitem_autoid.append(item.text(0)) condition = {'autoid__in': checkitem_autoid} self.LC.delete_data(4, condition) self.get_checkitem(itemtype, tree) # 复制 elif action == button4: clipboard = QApplication.clipboard() items = tree.selectedItems() select_item = tree.mimeData(items) clipboard.setMimeData(select_item) # 黏贴 elif action == button5: try: clipboard = QApplication.clipboard() data = clipboard.mimeData() # 获取当前行数,加1即为新的行号 count = tree.topLevelItemCount() res = tree.dropMimeData( tree.invisibleRootItem(), count + 1, data, Qt.CopyAction) finnal_index = tree.topLevelItemCount() if res: while count < finnal_index: tree_item = tree.topLevelItem(count) if tree_item is None: raise AttributeError detail = dict() detail["seqid"] = tree_item.text(1) detail["kind"] = tree_item.text(2) detail["itemname"] = tree_item.text(3) detail["referencevalue"] = tree_item.text(4) detail["restype"] = RESTYPE.index(tree_item.text(5)) detail["putintype"] = PUTINTYPE.index(tree_item.text(6)) detail["stuffid"] = self.autoid detail["itemtype"] = itemtype new_item = self.LC.update_data(4, **detail) tree_item.setText(0, str(new_item.autoid)) count += 1 except Exception as e: pass else: pass # 修改编号时触发 @pyqtSlot(str) def on_lineEdit_prodid_textChanged(self, p_str): try: if p_str != self.ori_detail['prodid']: self.new_detail['prodid'] = p_str else: try: del self.new_detail['prodid'] except KeyError: pass except KeyError: self.new_detail['prodid'] = p_str # 修改名称时触发 @pyqtSlot(str) def on_lineEdit_prodname_textChanged(self, p_str): self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str)) try: if p_str != self.ori_detail['prodname']: self.new_detail['prodname'] = p_str else: try: del self.new_detail['prodname'] except KeyError: pass except KeyError: self.new_detail['prodname'] = p_str # 修改输入码时触发 @pyqtSlot(str) def on_lineEdit_commonname_textChanged(self, p_str): try: if p_str != self.ori_detail['commonname']: self.new_detail['commonname'] = p_str else: try: del self.new_detail['commonname'] except KeyError: pass except KeyError: self.new_detail['inputcode'] = p_str @pyqtSlot(str) def on_lineEdit_allowno_textChanged(self, p_str): try: if p_str != self.ori_detail['allowno']: self.new_detail['allowno'] = p_str else: try: del self.new_detail['allowno'] except KeyError: pass except KeyError: self.new_detail['allowno'] = p_str @pyqtSlot(str) def on_lineEdit_inputcode_textChanged(self, p_str): try: if p_str != self.ori_detail['inputcode']: self.new_detail['inputcode'] = p_str else: try: del self.new_detail['inputcode'] except KeyError: pass except KeyError: self.new_detail['inputcode'] = p_str @pyqtSlot(str) def on_lineEdit_spec_textChanged(self, p_str): try: if p_str != self.ori_detail['spec']: self.new_detail['spec'] = p_str else: try: del self.new_detail['spec'] except KeyError: pass except KeyError: self.new_detail['spec'] = p_str # 修改包装级别时触发 @pyqtSlot(int) def on_comboBox_packageLv_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail['packagelv']: self.new_detail['packagelv'] = p_int else: try: del self.new_detail['packagelv'] except KeyError: pass except KeyError: self.new_detail['packagelv'] = p_int # 修改包装情况时触发 @pyqtSlot() def on_lineEdit_package_editingFinished(self): p_str = self.lineEdit_package.text() try: if p_str != self.ori_detail['package']: if self.set_package_rate(p_str): self.new_detail['package'] = p_str else: try: del self.new_detail['package'] except KeyError: pass except KeyError: if self.set_package_rate(p_str): self.new_detail['package'] = p_str def set_package_rate(self, package): lv = self.comboBox_packageLv.currentIndex() + 1 items = re.split(r'\*|×|x|X', package) if len(items) != lv: msg = MessageBox(title="错误1!", informative="包装比例错误!") msg.exec() return False num_tuple = ('basicamount', 'spamount', 'mpamount', 'bpamount') unit_tuple = ('basicunit', 'spunit', 'mpunit', 'bpunit', 'lpunit') try: for i in range(len(items)): values = re.findall(r'\d+|\w+', items[i]) self.new_detail[num_tuple[i]] = values[0] self.new_detail[unit_tuple[i]] = values[1] self.new_detail[unit_tuple[i + 1]] = values[2] return True except: msg = MessageBox(title="错误2!", informative="包装比例错误!") msg.exec() return False @pyqtSlot(str) def on_comboBox_medkind_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['medkind']: self.new_detail['medkind'] = p_str else: try: del self.new_detail['medkind'] except KeyError: pass except KeyError: self.new_detail['medkind'] = p_str @pyqtSlot(str) def on_comboBox_midcheckunit_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['midcheckunit']: self.new_detail['midcheckunit'] = p_str else: try: del self.new_detail['midcheckunit'] except KeyError: pass except KeyError: self.new_detail['midcheckunit'] = p_str @pyqtSlot(str) def on_comboBox_prodcheckunit_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['prodcheckunit']: self.new_detail['prodcheckunit'] = p_str else: try: del self.new_detail['prodcheckunit'] except KeyError: pass except KeyError: self.new_detail['prodcheckunit'] = p_str @pyqtSlot(str) def on_lineEdit_expireddates_textChanged(self, p_str): try: if p_str != self.ori_detail['expireddates']: self.new_detail['expireddates'] = p_str else: try: del self.new_detail['expireddates'] except KeyError: pass except KeyError: self.new_detail['expireddates'] = p_str @pyqtSlot(str) def on_lineEdit_storage_textChanged(self, p_str): try: if p_str != self.ori_detail['storage']: self.new_detail['storage'] = p_str else: try: del self.new_detail['storage'] except KeyError: pass except KeyError: self.new_detail['storage'] = p_str @pyqtSlot(bool) def on_checkBox_lp_toggled(self, p_bool): status = 8 * (1 if p_bool else -1) if 'qrtype' in self.new_detail: self.new_detail['qrtype'] += status else: self.new_detail['qrtype'] = status @pyqtSlot(bool) def on_checkBox_bp_toggled(self, p_bool): status = 4 * (1 if p_bool else -1) if 'qrtype' in self.new_detail: self.new_detail['qrtype'] += status else: self.new_detail['qrtype'] = status @pyqtSlot(bool) def on_checkBox_mp_toggled(self, p_bool): status = 2 * (1 if p_bool else -1) if 'qrtype' in self.new_detail: self.new_detail['qrtype'] += status else: self.new_detail['qrtype'] = status @pyqtSlot(bool) def on_checkBox_sp_toggled(self, p_bool): status = 1 if p_bool else -1 if 'qrtype' in self.new_detail: self.new_detail['qrtype'] += status else: self.new_detail['qrtype'] = status # 修改生产线和车间时触发 @pyqtSlot() def on_toolButton_workshop_clicked(self): setpl = SetProductLine(parent=self, pltype=0) setpl.select_line_signal.connect(self.setproductline) setpl.show() def setproductline(self, linedetail: dict): try: if linedetail['autoid'] != self.ori_detail['plid']: self.new_detail['plid'] = linedetail['autoid'] self.toolButton_workshop.setText(linedetail['deptname']) self.label_productionline.setText(linedetail['linename']) else: try: del self.new_detail['plid'] except KeyError: pass except KeyError: self.new_detail['plid'] = linedetail['autoid'] self.toolButton_workshop.setText(linedetail['deptname']) self.label_productionline.setText(linedetail['linename']) # 修改退货线和车间时触发 @pyqtSlot() def on_toolButton_bworkshop_clicked(self): setpl = SetProductLine(parent=self, pltype=2) setpl.select_line_signal.connect(self.setwpproductline) setpl.show() def setwpproductline(self, linedetail: dict): try: if linedetail['autoid'] != self.ori_detail['wplid']: self.new_detail['wplid'] = linedetail['autoid'] self.toolButton_bworkshop.setText(linedetail['deptname']) self.label_bproductionline.setText(linedetail['linename']) else: try: del self.new_detail['wplid'] except KeyError: pass except KeyError: self.new_detail['wplid'] = linedetail['autoid'] self.toolButton_bworkshop.setText(linedetail['deptname']) self.label_bproductionline.setText(linedetail['linename']) # 修改验证线和车间时触发 @pyqtSlot() def on_toolButton_vworkshop_clicked(self): setpl = SetProductLine(parent=self, pltype=3) setpl.select_line_signal.connect(self.setvproductline) setpl.show() def setvproductline(self, linedetail: dict): try: if linedetail['autoid'] != self.ori_detail['vplid']: self.new_detail['vplid'] = linedetail['autoid'] self.toolButton_vworkshop.setText(linedetail['deptname']) self.label_vproductionline.setText(linedetail['linename']) else: try: del self.new_detail['vplid'] except KeyError: pass except KeyError: self.new_detail['vplid'] = linedetail['autoid'] self.toolButton_vworkshop.setText(linedetail['deptname']) self.label_vproductionline.setText(linedetail['linename']) # 确认 @pyqtSlot() def on_pushButton_accept_clicked(self): if not len(self.new_detail): return if self.autoid: condition = {'autoid': self.autoid} self.PC.update_data(1, condition, **self.new_detail) else: self.PC.update_data(1, **self.new_detail) self.accept() # 取消 @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class CheckreportModule(QMainWindow, Ui_MainWindow): accepted = pyqtSignal() def __init__(self, autoid, is_view=False, parent=None): super(CheckreportModule, self).__init__(parent) self.setupUi(self) if is_view: self.power = '000' else: if '8' not in user.powers: self.close() if user.powers['8'] == 0: self.close() self.power = '{:03b}'.format(user.powers['8']) if self.power[1] == '0': self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) self.pushButton_add_oripaper.setVisible(False) if self.power[2] == '0': self.pushButton_print.setVisible(False) self.is_view = is_view self.autoid = autoid self.ori_detail = dict() self.new_detail = dict() self.ori_checkitem = [] self.new_checkitem = [] self.images_list = [] self.current_img = object self.current_page = object self.LC = LabrecordsController() self.SC = StuffController() self.PC = ProductController() # 自动缩放 self.label_image.setScaledContents(True) # 获取当前报告的信息 has_find_report = self.get_report_detail(self.autoid) # 获取检验项目 self.get_checkitem() if has_find_report: # 获取检验依据的下拉项目 self.get_combobox_items(self.comboBox_checkgist, 'checkgist', chkid=self.ori_detail['chkid']) # 获取结论的下拉项目 self.get_combobox_items(self.comboBox_result, 'result', chkid=self.ori_detail['chkid']) # 获取图片 self.get_images(autoid) # 获取原始检验记录 self.get_oricheckpaper(autoid) # 检验项目的右键菜单功能 if len(self.ori_detail): if self.ori_detail['paperno'] == '': self.get_paperno() self.new_paperstatus = self.ori_detail['paperstatus'] # 根据签名情况确定是否允许修改签名 self.set_paperstatus() def set_paperstatus(self): paperstatus = self.ori_detail['paperstatus'] if paperstatus == 1: # 检验人已经签名 self.pushButton_reporter.setEnabled(True) self.pushButton_checker.setEnabled(True) self.pushButton_warrantor.setEnabled(True) elif paperstatus == 2: # 复核人已经签名 self.pushButton_reporter.setEnabled(False) self.pushButton_checker.setEnabled(True) self.pushButton_warrantor.setEnabled(True) elif paperstatus == 3: # 审核人已经签名 self.pushButton_reporter.setEnabled(False) self.pushButton_checker.setEnabled(False) self.pushButton_warrantor.setEnabled(True) def get_report_detail(self, autoid): key_dict = {'autoid': autoid} res = self.LC.get_labrecord(False, *VALUES_TUPLE_LR, **key_dict) if len(res) == 1: self.ori_detail = res[0] self.label_chkitem.setText(self.ori_detail['chkid'] + self.ori_detail['chkname']) self.label_spec.setText(self.ori_detail['spec']) self.label_package.setText(self.ori_detail['package']) self.label_applydate.setText(str(self.ori_detail['sampledate'])) self.label_sampleamount.setText( str(self.ori_detail['sampleamount']) + self.ori_detail['sampleunit']) self.label_sampledate.setText(str(self.ori_detail['sampledate'])) self.label_samplesource.setText(self.ori_detail['samplesource']) self.label_checkamount.setText( str(self.ori_detail['checkamount']) + self.ori_detail['caunit']) self.label_batchno.setText(self.ori_detail['batchno']) self.label_supplyer.setText(self.ori_detail['supplyer']) self.label_producer.setText(self.ori_detail['producer']) self.label_mbatchno.setText(self.ori_detail['mbatchno']) self.lineEdit_paperno.setText(self.ori_detail['paperno']) self.dateEdit_reportdate.setDate( self.ori_detail['reportdate'] if type(self.ori_detail['reportdate']) is datetime.date else user. now_date) self.comboBox_checkgist.addItem(self.ori_detail['checkgist']) self.comboBox_checkgist.setCurrentText( self.ori_detail['checkgist']) self.pushButton_reporter.setText(self.ori_detail['reporterid'] + ' ' + self.ori_detail['reportername']) self.pushButton_checker.setText(self.ori_detail['checkerid'] + ' ' + self.ori_detail['checkername']) self.pushButton_warrantor.setText(self.ori_detail['warrantorid'] + ' ' + self.ori_detail['warrantorname']) self.comboBox_result.addItem(self.ori_detail['result']) self.comboBox_result.setCurrentText(self.ori_detail['result']) self.checkBox_conclusion.setCheckState( self.ori_detail['conclusion']) if self.ori_detail['status'] > 2: self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) if self.ori_detail['labtype'] not in (0, 1): self.label_mbatchno_text.setVisible(False) self.label_mbatchno.setVisible(False) self.label_supplyer_text.setVisible(False) self.label_supplyer.setVisible(False) self.label_producer_text.setVisible(False) self.label_producer.setVisible(False) self.label_sepc_text.setText("含量规格:") self.label_batchno_text.setText("批 号:") return True else: return False def get_checkitem(self): values_list = [ 'autoid', 'kind', 'itemname', 'labvalue', 'referencevalue', 'checked', 'startdate', 'enddate', 'checkerid', 'checkername', 'result' ] key_dict = {'lrid': self.autoid} res = self.LC.get_labitem(False, *values_list, **key_dict) self.ori_checkitem = res.order_by('kind', 'seqid') self.treeWidget_checkitem.clear() if not len(self.ori_checkitem): return for item in self.ori_checkitem: qtreeitem = QTreeWidgetItem(self.treeWidget_checkitem) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['kind']) qtreeitem.setText(2, item['itemname']) qtreeitem.setText( 3, str(item['startdate']) if type(item['startdate']) is datetime.date else '') qtreeitem.setText( 4, str(item['enddate']) if type(item['enddate']) is datetime.date else '') qtreeitem.setText(5, item['referencevalue']) qtreeitem.setText(6, item['labvalue']) qtreeitem.setText(7, CHECK_RESULT[item['result']]) qtreeitem.setText(8, item['checkerid'] + item['checkername']) qtreeitem.setCheckState(1, item['checked']) if item['result'] == 1: brush = QBrush(1) brush.setColor(QColor(255, 0, 0)) # for i in range(1, 9): qtreeitem.setBackground(7, brush) self.treeWidget_checkitem.hideColumn(0) for i in range(1, 8): self.treeWidget_checkitem.resizeColumnToContents(i) if self.treeWidget_checkitem.columnWidth(i) > 200: self.treeWidget_checkitem.setColumnWidth(i, 200) # 检验依据和结论获取下拉内容 def get_combobox_items(self, qcombobox: QComboBox, *args, **kwargs): if type(qcombobox) == QComboBox: text = qcombobox.currentText() res = self.LC.get_labrecord(True, *args, **kwargs) key = dict(zip(args, [ text, ])) items = res.exclude(**key) qcombobox.addItems(set(items)) def get_paperno(self): res = self.LC.get_paperno(self.autoid) self.lineEdit_paperno.setText(res[0]) def get_images(self, lrid): self.treeWidget_imagenamelist.clear() res = self.LC.get_labimages(False, scid=lrid) self.images_list = res for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['imageid'])) qtreeitem.setText(2, item['title']) qtreeitem.setText(3, item['creatorid'] + item['creatorname']) qtreeitem.setText(4, str(item['createdate'])) def get_oricheckpaper(self, lrid): if self.is_view: return values_list = ['autoid', 'formname'] key_dict = {'lrid': lrid} res = self.LC.get_oricheckpaper(False, *values_list, **key_dict) for item in res: tabpage = QWidget() tabpage.setObjectName("oriid_" + str(item['autoid'])) self.tabWidget.addTab(tabpage, item['formname']) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_checkitem_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0' or self.ori_detail['status'] > 2: return item_id = int(qtreeitem.text(0)) detail = EditcheckitemModule(item_id, self) detail.accepted.connect(self.get_checkitem) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_checkitem_itemClicked(self, qtreeitem, p_int): if self.power[1] == '0' or self.ori_detail['status'] > 2: return if p_int == 1: newstate = qtreeitem.checkState(1) for item in self.ori_checkitem: if int(qtreeitem.text(0)) == item['autoid']: if newstate != item['checked']: it = { 'autoid': int(qtreeitem.text(0)), 'checked': newstate } self.new_checkitem.append(it) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int): rela_id = int(qtreeitem.text(0)) for item in self.images_list: if item['autoid'] == rela_id: if item['ext'].lower() == 'pdf': self.comboBox_jumpto.setVisible(True) self.pushButton_prepage.setVisible(True) self.pushButton_nextpage.setVisible(True) self.current_img = fitz.Document(stream=item['image'], filetype='pdf') page_count = self.current_img.pageCount page_list = [] self.comboBox_jumpto.clear() for i in range(1, page_count + 1): page_list.append('第' + str(i) + '页') self.comboBox_jumpto.addItems(page_list) self.current_page = self.current_img.loadPage(0) else: self.comboBox_jumpto.setVisible(False) self.pushButton_prepage.setVisible(False) self.pushButton_nextpage.setVisible(False) img = QImage.fromData(item['image']) self.current_img = QPixmap.fromImage(img) self.label_image.setPixmap(self.current_img) break # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged self.horizontalSlider_zoom.setValue(30) @pyqtSlot(int) def on_horizontalSlider_zoom_valueChanged(self, p_int): try: self.label_zoom.setText(str(p_int * 10) + '%') # 把当前页面转为QPixmap,并缩放为p_int/10 cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10) self.label_image.setPixmap(cover) except (AttributeError, ValueError): size = self.current_img.size() new_pixmap = self.current_img.scaled(size.width() * p_int / 10, size.height() * p_int / 10) self.label_image.setPixmap(new_pixmap) @pyqtSlot(QPoint) def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos): if self.power[1] == '0': return # 返回调用者的对象 sender_widget = self.sender() menu = QMenu() button1 = menu.addAction("新增图片") button2 = menu.addAction("修改图片") button3 = menu.addAction("删除图片") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) res = "rollback" # 增加 if action == button1: img_names, img_type = QFileDialog.getOpenFileNames( self, "打开图片", os.path.expanduser("~") + "\Desktop", "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)") for item in img_names: imagename_no_ext = item.split("/")[-1] image_ext = item.split(".")[1] if image_ext.lower() not in ("jpg", "png", "bmp", "gif", "pdf"): continue fp = open(item, 'rb') with fp: image_byte = fp.read() fp.close() imagedetail = {'img': image_byte, 'ext': image_ext} reladetail = { 'kind': 2, 'scid': self.autoid, 'title': imagename_no_ext, 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date } res = self.LC.update_labimages(reladetail, imagedetail) # 修改 elif action == button2: rela_id = self.treeWidget_imagenamelist.currentItem().text(0) img_id = self.treeWidget_imagenamelist.currentItem().text(1) img_name, img_type = QFileDialog.getOpenFileName( self, "打开图片", os.path.expanduser("~") + "\Desktop", "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)") imagename_no_ext = img_name.split("/")[-1] image_ext = img_name.split(".")[1] if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"): fp = open(img_name, 'rb') with fp: image_byte = fp.read() fp.close() imagedetail = {'img': image_byte, 'ext': image_ext} reladetail = { 'title': imagename_no_ext, 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date } res = self.LC.update_labimages(reladetail, imagedetail, rela_id, img_id) # 删除 elif action == button3: select_item = sender_widget.selectedItems() rela_id = [] img_id = [] for item in select_item: rela_id.append(item.text(0)) img_id.append(item.text(1)) res = self.LC.delete_labimages(rela_id, img_id) if res == "accept": self.get_images(self.autoid) @pyqtSlot(int) def on_comboBox_jumpto_currentIndexChanged(self, p_int): try: self.current_page = self.current_img.loadPage(p_int) self.on_horizontalSlider_zoom_valueChanged( self.horizontalSlider_zoom.value()) except (AttributeError, ValueError): pass @pyqtSlot() def on_pushButton_prepage_clicked(self): index = self.comboBox_jumpto.currentIndex() if index - 1 >= 0: try: self.current_page = self.current_img.loadPage(index - 1) self.comboBox_jumpto.setCurrentIndex(index - 1) except (AttributeError, ValueError): pass @pyqtSlot() def on_pushButton_nextpage_clicked(self): index = self.comboBox_jumpto.currentIndex() if index + 1 < self.comboBox_jumpto.count(): try: self.current_page = self.current_img.loadPage(index + 1) self.comboBox_jumpto.setCurrentIndex(index + 1) except (AttributeError, ValueError): pass @pyqtSlot() def on_pushButton_add_oripaper_clicked(self): chkid = self.ori_detail['chkid'] itemtype = int(self.ori_detail['labtype']) if itemtype in (0, 1, 2): itemtype = 0 condition = {'stuffid': chkid} res = self.SC.get_data(0, True, *VALUES_TUPLE_ID, **condition) if not len(res): return dictid = res[0] elif itemtype in (3, 4, 5, 6): if itemtype > 4: itemtype = 4 condition = {'prodid': chkid} res = self.PC.get_data(1, True, *VALUES_TUPLE_ID, **condition) if not len(res): return dictid = res[0] else: dictid = chkid detail = SelectoricheckpaperModule(dictid, itemtype, self) detail.selected.connect(self.selectoricheckpaper) detail.show() @pyqtSlot(list) def selectoricheckpaper(self, p_list): if not len(p_list): return for item in p_list: sdf_detail = { 'lrid': self.autoid, 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date } op_detail = { 'batchno': self.ori_detail['batchno'], 'dictid': self.ori_detail['chkid'], 'dictname': self.ori_detail['chkname'] } res = self.LC.create_oricheckpaper(item[0], op_detail, item[1], sdf_detail) if not res: return tabpage = QWidget() tabpage.setObjectName("oriid_" + str(res.autoid)) self.tabWidget.addTab(tabpage, res.formname) @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): if p_int <= 1: return # 点击的是原始检验记录 current_widget = self.tabWidget.currentWidget() if current_widget.children(): return objname = current_widget.objectName() try: ori_id = int(objname.split('_')[1]) except TypeError: # TypeError:objname的第二段不是数字 return is_finished = True if self.ori_detail['status'] > 2 else False self.current_content = OricheckpaperModule(ori_id, is_finished, self) self.current_content.deleted.connect(self.deleted_tab) gridlayout = QGridLayout(current_widget) gridlayout.addWidget(self.current_content) def deleted_tab(self): index = self.tabWidget.currentIndex() self.tabWidget.removeTab(index) @pyqtSlot(str) def on_lineEdit_paperno_textChanged(self, p_str): try: if p_str != self.ori_detail['paperno']: self.new_detail['paperno'] = p_str else: try: del self.new_detail['paperno'] except KeyError: pass except KeyError: self.new_detail['paperno'] = p_str @pyqtSlot(QDate) def on_dateEdit_reportdate_dateChanged(self, q_date): try: if type(self.ori_detail['reportdate']) is str: self.new_detail['reportdate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['reportdate']): self.new_detail['reportdate'] = q_date.toPyDate() else: try: del self.new_detail['reportdate'] except KeyError: pass except KeyError: self.new_detail['reportdate'] = q_date.toPyDate() @pyqtSlot(str) def on_comboBox_checkgist_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['checkgist']: self.new_detail['checkgist'] = p_str else: try: del self.new_detail['checkgist'] except KeyError: pass except KeyError: self.new_detail['checkgist'] = p_str @pyqtSlot(str) def on_comboBox_result_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['result']: self.new_detail['result'] = p_str else: try: del self.new_detail['result'] except KeyError: pass except KeyError: self.new_detail['result'] = p_str @pyqtSlot(int) def on_checkBox_conclusion_stateChanged(self, p_int): try: if p_int != self.ori_detail['conclusion']: self.new_detail['conclusion'] = p_int else: try: del self.new_detail['conclusion'] except KeyError: pass except KeyError: self.new_detail['conclusion'] = p_int @pyqtSlot(bool, str) def on_pushButton_reporter_signChanged(self, p_bool, p_str): id, name = p_str.split(' ') if p_bool else ('', '') try: if id != self.ori_detail['reporterid'] or name != self.ori_detail[ 'opertername']: self.new_detail['reporterid'] = id self.new_detail['reportername'] = name if id != '': self.new_paperstatus = 1 else: self.new_paperstatus = 0 else: try: del self.new_detail['reporterid'] del self.new_detail['reportername'] except KeyError: pass except KeyError: self.new_detail['reporterid'] = id self.new_detail['reportername'] = name @pyqtSlot(bool, str) def on_pushButton_checker_signChanged(self, p_bool, p_str): id, name = p_str.split(' ') if p_bool else ('', '') try: if id != self.ori_detail['checkerid'] or name != self.ori_detail[ 'checkername']: self.new_detail['checkerid'] = id self.new_detail['checkername'] = name if id != '': self.new_paperstatus = 2 else: self.new_paperstatus = 1 else: try: del self.new_detail['checkerid'] del self.new_detail['checkername'] except KeyError: pass except KeyError: self.new_detail['checkerid'] = id self.new_detail['checkername'] = name @pyqtSlot(bool, str) def on_pushButton_warrantor_signChanged(self, p_bool, p_str): id, name = p_str.split(' ') if p_bool else ('', '') try: if id != self.ori_detail['warrantorid'] or name != self.ori_detail[ 'warrantorname']: self.new_detail['warrantorid'] = id self.new_detail['warrantorname'] = name if id != '': self.new_paperstatus = 3 else: self.new_paperstatus = 2 else: try: del self.new_detail['warrantorid'] del self.new_detail['warrantorname'] except KeyError: pass except KeyError: self.new_detail['warrantorid'] = id self.new_detail['warrantorname'] = name @pyqtSlot() def on_pushButton_save_clicked(self): if self.new_paperstatus != self.ori_detail['paperstatus']: self.new_detail['paperstatus'] = self.new_paperstatus if len(self.new_detail): res = self.LC.update_labrecord(self.autoid, **self.new_detail) if res: self.new_detail = {} if len(self.new_checkitem): for item in self.new_checkitem: res = self.LC.update_labitem(**item) if res: self.new_checkitem = {} self.accepted.emit() # self.close() @pyqtSlot() def on_pushButton_accept_clicked(self): if self.new_paperstatus != self.ori_detail['paperstatus']: self.new_detail['paperstatus'] = self.new_paperstatus if self.checkBox_conclusion.checkState() == 0: self.new_detail['status'] = 4 else: self.new_detail['status'] = 3 res = self.LC.update_labrecord(self.autoid, **self.new_detail) if res: self.new_detail = {} if len(self.new_checkitem): for item in self.new_checkitem: res = self.LC.update_labitem(**item) if res: self.new_checkitem = {} self.accepted.emit() self.close() def closeEvent(self, qcloseevent): if self.power[1] == '0' or self.ori_detail['status'] > 2: return if len(self.new_detail): qdialog = MessageBox(self, title="提醒", text="检验报告书", informative="是否保存修改?") res = qdialog.exec() if res == 16384: self.on_pushButton_save_clicked() for i in range(2, self.tabWidget.count() + 1): widgets = self.tabWidget.widget(i) try: for item in widgets.children(): try: if item.current_content.flat == 1: qdialog = MessageBox( self, title="提醒", text=self.tabWidget.tabText(i), informative="是否保存修改?") res = qdialog.exec() if res == 16384: item.on_pushButton_accept_clicked() except AttributeError: pass except AttributeError: pass