def __init__(self, autoid=None, parent=None): super(EditSelfDefineFormatDetailModule, self).__init__(parent) self.setupUi(self) self.setWindowFlag(Qt.WindowMinMaxButtonsHint) if '3' not in user.powers: self.close() if user.powers['3'] == 0: self.close() self.power = '{:03b}'.format(user.powers['3']) if self.power[1] == '0': self.pushButton_accept.setEnabled(False) self.pushButton_close.setEnabled(False) self.autoid = autoid self.detail = QWidget() self.dom = QDomDocument() self.current_widget = QWidget() self.nodelist = None self.SC = SelfdefinedformatController() self.ori_detail = {} self.new_detail = {} self.format_content = '<?xml version="1.0"?><GMPPaper />' self.current_content = XMLReadWrite() self.current_elemnt = None res = self.get_detail() self.set_kind() self.set_subkind() if res: self.set_formtype() self.set_widgetlist() self.set_format() for i in range(0, 17): getattr(self, 'checkBox_' + str(2**i)).toggled.connect( self.on_formattype_toggled)
def on_treeWidget_revalution_itemDoubleClicked(self, qtreeitem, p_int): if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_save_clicked() self.docid = int(qtreeitem.text(0)) key_dict = {'autoid': self.docid} res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_7.isEmpty(): self.gridLayout_7.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_7.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid)
def on_treeWidget_report_itemDoubleClicked(self, qtreeitem, p_int): if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.reportid = int(qtreeitem.text(0)) condition = {'autoid': self.reportid} res = self.VC.get_data(2, True, *VALUES_TUPLE_RP_DETAIL, **condition) if not len(res): return content = str(res[0]) if not self.gridLayout_11.isEmpty(): self.gridLayout_11.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_11.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.reportid)
def set_format(self): if not self.gridLayout_2.isEmpty(): self.gridLayout_2.removeWidget(self.current_content) self.format_content = self.dom.toString(-1) self.current_content.close() self.current_content = XMLReadWrite() self.current_content.openxml(self.dom.toString(-1)) self.gridLayout_2.addWidget(self.current_content)
def get_oricheckpaper(self): values_list = ('formcontent', ) key_dict = {'autoid': self.autoid} res = self.LC.get_oricheckpaper(True, *values_list, **key_dict) if len(res): ori_paper = res[0] self.current_content = XMLReadWrite(self) self.current_content.openxml(ori_paper) self.gridLayout_6.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.autoid)
def get_general_record(self): values_list = ('formname', 'format') key_dict = {'autoid': self.autoid} res = self.EC.get_data(5, False, *values_list, **key_dict) if len(res): self.label_formname.setText(res[0]['formname']) ori_paper = res[0]['format'] self.current_content = XMLReadWrite(self) self.current_content.openxml(ori_paper) self.gridLayout_6.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.autoid)
def on_treeWidget_revalution_customContextMenuRequested(self, pos): if self.power[1] == '0': return if self.autoid is None: return sender_widget = self.sender() current_item = sender_widget.currentItem() menu = QMenu() button1 = menu.addAction("增加记录") button2 = menu.addAction("修改记录") button3 = menu.addAction("删除记录") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = SelectSelfDefineFormatModule('4', self) detail.selected.connect(self.new_records) detail.accepted.connect(self.get_format) detail.show() elif action == button2: if current_item is None: return if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.docid = int(current_item.text(0)) key_dict = {'autoid': self.docid} res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_7.isEmpty(): self.gridLayout_7.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_7.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid) elif action == button3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.SC.delete_data(4, condition) self.get_format()
def on_treeWidget_report_customContextMenuRequested(self, pos): current_item = self.treeWidget_report.currentItem() global_pos = self.treeWidget_report.mapToGlobal(pos) menu = QMenu() action_1 = menu.addAction("增加") action_2 = menu.addAction("修改") action_3 = menu.addAction("删除") action = menu.exec(global_pos) if action == action_1: detail = SelectSelfDefineFormatModule("512", self) detail.selected.connect(self.add_oricheckpaper) detail.selected.connect(self.get_report) detail.show() elif action == action_2: if current_item is None: return if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.reportid = int(current_item.text(0)) condition = {'autoid': self.reportid} res = self.VC.get_data(2, True, *VALUES_TUPLE_RP_DETAIL, **condition) if not len(res): return content = str(res[0]) if not self.gridLayout_11.isEmpty(): self.gridLayout_11.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_11.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.reportid) elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.VC.delete_data(2, condition) self.get_report()
def __init__(self, kind, parent=None): super(AuxiliaryRecordModule, self).__init__(parent) self.setupUi(self) if kind == 0: index = '12' elif kind == 1: index = '25' elif kind == 2: index = '32' else: index = '-1' if index not in user.powers: self.close() if user.powers[index] == 0: self.close() self.power = '{:03b}'.format(user.powers[index]) if self.power[1] == '0': self.pushButton_accept.setEnabled(False) self.pushButton_cancel.setEnabled(False) self.kind = kind self.year = user.NIAN self.month = user.YUE self.docid = 0 self.current_content = QWidget() self.AC = AuxiliaryRecordController() self.SC = SelfdefinedformatController() self.treeWidget_itemlist.hideColumn(0) self.treeWidget_itemlist.hideColumn(4) self.get_year_list()
def __init__(self, autoid=None, vdpid=0, parent=None): super(VerificationDetailModule, self).__init__(parent) self.setupUi(self) self.autoid = autoid self.vdpid = vdpid self.filename = None self.doc = None self.reportid = 0 self.current_content = QWidget() self.current_img = object self.current_page = object self.label_image.setScaledContents(True) self.status = 0 self.current_docid = 0 self.ori_detail = {} self.new_detail = {} self.VC = VerificationController() self.SC = SelfdefinedformatController() self.lineEdit_product.setup(DB_TABLE_TUPLE[0], RETURN_ROW[0], CONDITION_KEY[0], TREEHEADER_NAME, None, 330, 200) self.treeWidget_report.hideColumn(0) self.treeWidget_labreport.hideColumn(0) self.treeWidget_labreport.hideColumn(1) self.treeWidget_pp_record.hideColumn(0) self.treeWidget_pp_record.hideColumn(1) self.label_other.setVisible(False) self.lineEdit_other.setVisible(False) self.get_plan() self.show_plandoc() self.get_report() self.get_producingplan_records() self.get_lab_records()
class GeneralRecordModule(QDialog, Ui_Dialog): edited = pyqtSignal(int) def __init__(self, autoid, parent=None): super(GeneralRecordModule, self).__init__(parent) self.setupUi(self) if '50' not in user.powers: self.close() if user.powers['50'] == 0: self.close() self.power = '{:03b}'.format(user.powers['50']) if self.power[1] == '0': self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.ori_detail = dict() self.autoid = autoid self.EC = EquipmentController() self.current_content = object # 获取记录内容 self.get_general_record() def get_general_record(self): values_list = ('formname', 'format') key_dict = {'autoid': self.autoid} res = self.EC.get_data(5, False, *values_list, **key_dict) if len(res): self.label_formname.setText(res[0]['formname']) ori_paper = res[0]['format'] self.current_content = XMLReadWrite(self) self.current_content.openxml(ori_paper) self.gridLayout_6.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.autoid) @pyqtSlot() def on_pushButton_accept_clicked(self): condition = {'autoid': self.autoid} kwargs = {'formcontent': self.current_content.get_content()} res = self.EC.update_data(5, condition, **kwargs) if res: self.current_content.flat = 0 self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.current_content.flat = 0 self.close()
class ViewFormat(QDialog, Ui_Dialog): def __init__(self, dom, parent=None): super(ViewFormat, self).__init__(parent) self.dom = dom self.setupUi(self) self.current_content = XMLReadWrite() self.set_format() def set_format(self): if not self.gridLayout_2.isEmpty(): self.gridLayout_2.removeWidget(self.current_content) self.format_content = self.dom.toString(-1) self.current_content.close() self.current_content = XMLReadWrite() self.current_content.openxml(self.dom.toString(-1)) self.gridLayout_2.addWidget(self.current_content) @pyqtSlot() def on_pushButton_clicked(self): xml = self.current_content.get_content()
def __init__(self, autoid=None, parent=None): super(EditSupplyerDetailModule, self).__init__(parent) self.setupUi(self) if '3' not in user.powers: self.close() if user.powers['3'] == 0: self.close() self.power = '{:03b}'.format(user.powers['3']) if self.power[1] == '0': self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.autoid = autoid self.docid = 0 self.current_content = QWidget() self.ori_detail = dict() self.new_detail = dict() self.current_img = object self.current_page = object self.SC = SupplyerController() self.SDC = SelfdefinedformatController() self.IC = ImageController() self.treeWidget_stuff.hideColumn(0) self.treeWidget_revalution.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(1) # 自动缩放 self.label_image.setScaledContents(True) return_row = ('parentid', 'autoid', 'kindname') condition_key = {'autoid', 'kindname', 'inputcode'} treeheader_name = ['parentid', '编号', '名称'] condition = {'kind': 0} self.lineEdit_kind.setup('Treestructure', return_row, condition_key, treeheader_name, condition, treewidth=300) self.get_detail()
class EditSelfDefineFormatDetailModule(QDialog, Ui_Dialog): def __init__(self, autoid=None, parent=None): super(EditSelfDefineFormatDetailModule, self).__init__(parent) self.setupUi(self) self.setWindowFlag(Qt.WindowMinMaxButtonsHint) if '3' not in user.powers: self.close() if user.powers['3'] == 0: self.close() self.power = '{:03b}'.format(user.powers['3']) if self.power[1] == '0': self.pushButton_accept.setEnabled(False) self.pushButton_close.setEnabled(False) self.autoid = autoid self.detail = QWidget() self.dom = QDomDocument() self.current_widget = QWidget() self.nodelist = None self.SC = SelfdefinedformatController() self.ori_detail = {} self.new_detail = {} self.format_content = '<?xml version="1.0"?><GMPPaper />' self.current_content = XMLReadWrite() self.current_elemnt = None res = self.get_detail() self.set_kind() self.set_subkind() if res: self.set_formtype() self.set_widgetlist() self.set_format() for i in range(0, 17): getattr(self, 'checkBox_' + str(2**i)).toggled.connect( self.on_formattype_toggled) def get_detail(self): if self.autoid is None: return False condition = {'autoid': self.autoid} res = self.SC.get_data(0, False, *VALUES_TUPLE_SD, **condition) if not len(res): return self.ori_detail = res[0] self.lineEdit_formatname.setText(self.ori_detail['formatname']) self.comboBox_orientation.setCurrentIndex( self.ori_detail['orientation']) self.checkBox_flag.setChecked(self.ori_detail['flag']) self.format_content = self.ori_detail['format'] return True def set_kind(self): items = self.SC.get_data(0, True, *VALUES_TUPLE_KIND).distinct() if len(items): self.comboBox_kind.addItems(items) if len(self.ori_detail): self.comboBox_kind.setCurrentText(self.ori_detail['kind']) else: self.comboBox_kind.setCurrentText('') def set_subkind(self): items = self.SC.get_data(0, True, *VALUES_TUPLE_SUBKIND).distinct() if len(items): self.comboBox_subkind.addItems(items) if len(self.ori_detail): self.comboBox_subkind.setCurrentText(self.ori_detail['subkind']) else: self.comboBox_subkind.setCurrentText('') def set_formtype(self): if self.ori_detail['formtype'] == 0: return formtype = '{:017b}'.format(self.ori_detail['formtype']) for i in range(0, 17): getattr(self, 'checkBox_' + str(2**i)).setChecked(int(formtype[i])) def set_format(self): if not self.gridLayout_5.isEmpty(): # self.gridLayout_5.removeWidget(self.current_content) self.format_content = self.dom.toString(-1) self.current_content.clear() self.current_content.scrollArea.setHidden(True) else: self.gridLayout_5.addWidget(self.current_content) self.current_content.openxml(self.format_content, True) self.current_content.scrollArea.setHidden(False) def set_widgetlist(self): self.treeWidget_widgetlist.clear() file = self.format_content qfile = QFile(file) self.dom = QDomDocument() # 找到文件,则设置引擎,否则向xml文件直接添加数据 if qfile.open(QFile.ReadWrite | QFile.Text): self.dom.setContent(QFile) # self.file = QFile else: self.dom.setContent(file) # self.file = file if self.dom.isNull(): return False # 获得根目录的元素,返回QDomElement <GMPPaper> element = self.dom.documentElement() # 获得第一个子元素,返回QDomNode n = element.firstChild() # 如果没有读到文档结尾,而且没有出现错误 self.nodelist = element.childNodes() line_number = 1 for i in range(len(self.nodelist)): tag_name = self.nodelist.item(i).toElement().tagName() qtreeitem = QTreeWidgetItem(self.treeWidget_widgetlist) qtreeitem.setText(0, str(i)) qtreeitem.setText(1, str(line_number)) qtreeitem.setText(2, TAG_NAME_DICT[tag_name]) if tag_name == "br": line_number += 1 if qfile.isOpen(): qfile.close() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_widgetlist_itemClicked(self, qtreeitem, p_int): index = int(qtreeitem.text(0)) childrens = self.current_content.scrollAreaWidgetContents.children() item = childrens[index] item.setFocus() self.showsetting(item) @pyqtSlot(QMouseEvent) def mouseDoubleClickEvent(self, event): pos = event.pos() widget = self.childAt(pos) super(EditSelfDefineFormatDetailModule, self).mouseDoubleClickEvent(event) def mousePressEvent(self, event): pos = event.pos() widget = self.childAt(pos) self.showsetting(widget) def showsetting(self, widget): if not hasattr(widget, 'index') or self.current_widget == widget: self.current_elemnt = None return try: self.current_widget.leave() except AttributeError: if hasattr(self.current_widget.parent(), 'leave'): self.current_widget.parent().leave() except RuntimeError: pass self.current_widget = widget index = widget.index item = self.treeWidget_widgetlist.topLevelItem(index) if not self.gridLayout_6.isEmpty(): self.gridLayout_6.removeWidget(self.detail) self.detail.close() self.treeWidget_widgetlist.setCurrentItem(item) self.current_elemnt = self.nodelist.item(index).toElement() if self.current_elemnt.tagName() not in WIDGET_TYPE: self.detail.close() return self.detail = WIDGET_TYPE[self.current_elemnt.tagName()]( self.current_elemnt, self) self.detail.edited.connect(self.set_format) self.gridLayout_6.addWidget(self.detail) @pyqtSlot() def on_pushButton_1_clicked(self): new_element = self.dom.createElement("Title") new_element.setAttribute("width", 18) text = self.dom.createTextNode("新标题") new_element.appendChild(text) if self.current_elemnt is None or not hasattr(self.current_elemnt, 'tagName'): self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_2_clicked(self): new_element = self.dom.createElement("TextBox") new_element.setAttribute("width", 30) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_3_clicked(self): new_element = self.dom.createElement("Signature") new_element.setAttribute("width", 30) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_4_clicked(self): new_element = self.dom.createElement("Memo") new_element.setAttribute("width", 50) new_element.setAttribute("height", 3) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_5_clicked(self): new_element = self.dom.createElement("ComboBox") new_element.setAttribute("width", 30) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_6_clicked(self): new_element = self.dom.createElement("CheckBox") new_element.setAttribute("width", 30) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_7_clicked(self): new_element = self.dom.createElement("Box") new_element.setAttribute("width", 50) new_element.setAttribute("height", 3) new_element.setAttribute("PenWidth", 2) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_8_clicked(self): new_element = self.dom.createElement("Expr") new_element.setAttribute("width", 30) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_9_clicked(self): new_element = self.dom.createElement("br") # new_element.setAttribute("width", 20) if self.current_elemnt is None: self.dom.documentElement().appendChild(new_element) else: self.dom.documentElement().insertBefore(new_element, self.current_elemnt) self.flush() @pyqtSlot() def on_pushButton_10_clicked(self): if self.current_widget is None or not hasattr(self.current_widget, 'index'): return index = self.current_widget.index self.nodelist.item(index) try: self.dom.documentElement().removeChild(self.current_elemnt) except TypeError: pass self.flush() def flush(self): # index = self.treeWidget_widgetlist.currentIndex().data(Qt.DisplayRole) current_item = self.treeWidget_widgetlist.currentItem() if current_item is None: index = None else: index = current_item.text(0) self.set_format() self.set_widgetlist() if index is not None: self.current_elemnt = self.nodelist.item(int(index)) newindex = self.treeWidget_widgetlist.model().index(int(index), 0) try: self.current_content.scrollAreaWidgetContents.children()[int( index)].setFocus() except IndexError: pass else: count = self.treeWidget_widgetlist.topLevelItemCount() self.current_elemnt = self.nodelist.item(count - 1) newindex = self.treeWidget_widgetlist.model().index(count - 1, 0) try: self.current_content.scrollAreaWidgetContents.children()[ count - 1].setFocus() except IndexError: pass self.treeWidget_widgetlist.setCurrentIndex(newindex) @pyqtSlot(str) def on_lineEdit_formatname_textChanged(self, p_str): try: if p_str != self.ori_detail['formatname']: self.new_detail['formatname'] = p_str else: try: del self.new_detail['formatname'] except KeyError: pass except KeyError: self.new_detail['formatname'] = p_str @pyqtSlot(str) def on_comboBox_kind_currentTextChanged(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_comboBox_subkind_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['subkind']: self.new_detail['subkind'] = p_str else: try: del self.new_detail['subkind'] except KeyError: pass except KeyError: self.new_detail['subkind'] = p_str @pyqtSlot(int) def on_comboBox_orientation_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail['orientation']: self.new_detail['orientation'] = p_int else: try: del self.new_detail['orientation'] except KeyError: pass except KeyError: self.new_detail['orientation'] = p_int @pyqtSlot(bool) def on_checkBox_flag_toggled(self, p_bool): p_int = 1 if p_bool else 0 try: if p_int != self.ori_detail['flag']: self.new_detail['flag'] = p_int else: try: del self.new_detail['flag'] except KeyError: pass except KeyError: self.new_detail['flag'] = p_int @pyqtSlot(bool) def on_formattype_toggled(self, p_bool): combobox = self.sender() try: num = int( combobox.objectName().split("_")[1]) * (1 if p_bool else -1) except (IndexError, ValueError): return if 'formtype' in self.new_detail: self.new_detail['formtype'] += num elif len(self.ori_detail): self.new_detail['formtype'] = self.ori_detail['formtype'] + num else: self.new_detail['formtype'] = num @pyqtSlot() def on_pushButton_accept_clicked(self): xml = self.dom.toString(-1) self.new_detail['format'] = xml if self.autoid is not None: condition = {'autoid': self.autoid} self.SC.update_data(0, condition=condition, **self.new_detail) else: self.SC.update_data(0, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_view_clicked(self): detail = ViewFormat(self.dom, self) detail.show() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class EditSupplyerDetailModule(QDialog, Ui_Dialog): def __init__(self, autoid=None, parent=None): super(EditSupplyerDetailModule, self).__init__(parent) self.setupUi(self) if '3' not in user.powers: self.close() if user.powers['3'] == 0: self.close() self.power = '{:03b}'.format(user.powers['3']) if self.power[1] == '0': self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.autoid = autoid self.docid = 0 self.current_content = QWidget() self.ori_detail = dict() self.new_detail = dict() self.current_img = object self.current_page = object self.SC = SupplyerController() self.SDC = SelfdefinedformatController() self.IC = ImageController() self.treeWidget_stuff.hideColumn(0) self.treeWidget_revalution.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(0) self.treeWidget_imagenamelist.hideColumn(1) # 自动缩放 self.label_image.setScaledContents(True) return_row = ('parentid', 'autoid', 'kindname') condition_key = {'autoid', 'kindname', 'inputcode'} treeheader_name = ['parentid', '编号', '名称'] condition = {'kind': 0} self.lineEdit_kind.setup('Treestructure', return_row, condition_key, treeheader_name, condition, treewidth=300) self.get_detail() def get_detail(self): if self.autoid is None: self.dateEdit_validdate.setDate(user.now_date) return key_dict = {'autoid': self.autoid} res = self.SC.get_data(0, False, *VALUE_TUPLE_SUP, **key_dict) if not len(res): return self.ori_detail = res[0] self.lineEdit_supid.setText(self.ori_detail['supid']) self.lineEdit_supname.setText(self.ori_detail['supname']) self.lineEdit_inputcode.setText(self.ori_detail['inputcode']) self.lineEdit_kind.setText( str(self.ori_detail['tstkind']) + ' ' + self.ori_detail['tstname']) self.lineEdit_address.setText(self.ori_detail['address']) self.lineEdit_postzip.setText(self.ori_detail['postzip']) self.lineEdit_charger.setText(self.ori_detail['charger']) self.lineEdit_telno.setText(self.ori_detail['telno']) self.lineEdit_chargertitle.setText(self.ori_detail['chargertitle']) self.lineEdit_email.setText(self.ori_detail['email']) self.lineEdit_bankname.setText(self.ori_detail['bankname']) self.lineEdit_bankaccount.setText(self.ori_detail['bankaccount']) self.lineEdit_taxno.setText(self.ori_detail['taxno']) self.dateEdit_validdate.setDate(self.ori_detail['validdate']) self.plainTextEdit_remark.setPlainText(self.ori_detail['remark']) def get_image(self): self.treeWidget_imagenamelist.clear() if self.autoid is None: return key_dict = {'scid': self.autoid, 'kind': 0} res = self.IC.get_data(0, False, *VALUE_TUPLE_IMRELA, **key_dict) 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_format(self): if self.autoid is None: return self.treeWidget_revalution.clear() key_dict = {'spid': self.autoid} res = self.SC.get_data(4, False, *VALUE_TUPLE_SR, **key_dict) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_revalution) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['title']) qtreeitem.setText(2, str(item['createdate'])) qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname']) for i in range(1, 4): self.treeWidget_revalution.resizeColumnToContents(i) def get_stuff(self): if self.autoid is None: return self.treeWidget_stuff.clear() key_dict = {'spid': self.autoid} res = self.SC.get_data(1, False, **key_dict).extra( select={ 'autoid': 'stuffdictionary.autoid', 'stuffid': 'stuffdictionary.stuffid', 'stuffname': 'stuffdictionary.stuffname', 'stufftype': 'stuffdictionary.stufftype', 'spec': 'stuffdictionary.spec', 'package': 'stuffdictionary.package' }, tables=['stuffdictionary'], where=['stuffdictionary.autoid=stuffsupplyers.sdid' ]).values(*VALUE_TUPLE_STUFF) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_stuff) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, STUFFTYPE[item['stufftype']]) qtreeitem.setText(2, item['stuffid']) qtreeitem.setText(3, item['stuffname']) qtreeitem.setText(4, item['spec']) qtreeitem.setText(5, item['package']) for i in range(1, 6): self.treeWidget_stuff.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int): img_id = int(qtreeitem.text(1)) key_dict = {'autoid': img_id} res = self.IC.get_data(1, False, *VALUE_TUPLE_IM, **key_dict) if not len(res): return ext = res[0]['ext'] image = res[0]['img'] if ext.lower() == 'pdf': self.comboBox_jumpto.setVisible(True) self.pushButton_prepage.setVisible(True) self.pushButton_nextpage.setVisible(True) self.current_img = fitz.Document(stream=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(image) self.current_img = QPixmap.fromImage(img) self.label_image.setPixmap(self.current_img) # 默认放大为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 (ValueError, AttributeError): 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(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_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': 0, 'scid': self.autoid, 'title': imagename_no_ext, 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date } res = self.IC.update_images(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.IC.update_images(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.IC.delete_images(rela_id, img_id) if res == "accept": self.get_image() @pyqtSlot(str) def on_lineEdit_supid_textChanged(self, p_str): try: if p_str != self.ori_detail['supid']: self.new_detail['supid'] = p_str else: try: del self.new_detail['supid'] except KeyError: pass except KeyError: self.new_detail['supid'] = p_str @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 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(str) def on_lineEdit_supname_textChanged(self, p_str): self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str)) try: if p_str != self.ori_detail['supname']: self.new_detail['supname'] = p_str else: try: del self.new_detail['supname'] except KeyError: pass except KeyError: self.new_detail['supname'] = p_str @pyqtSlot(str) def on_lineEdit_kind_textChanged(self, p_str): if len(p_str.split(' ')) != 2 and p_str != '': return id, name = p_str.split(' ') if p_str != '' else ('', '') try: if id != self.ori_detail['tstkind'] or name != \ self.ori_detail['tstname']: self.new_detail['tstkind'] = id self.new_detail['tstname'] = name else: try: del self.new_detail['tstkind'] del self.new_detail['tstname'] except KeyError: pass except KeyError: self.new_detail['tstkind'] = id self.new_detail['tstname'] = name @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_address_textChanged(self, p_str): try: if p_str != self.ori_detail['address']: self.new_detail['address'] = p_str else: try: del self.new_detail['address'] except KeyError: pass except KeyError: self.new_detail['address'] = p_str @pyqtSlot(str) def on_lineEdit_postzip_textChanged(self, p_str): try: if p_str != self.ori_detail['postzip']: self.new_detail['postzip'] = p_str else: try: del self.new_detail['postzip'] except KeyError: pass except KeyError: self.new_detail['postzip'] = p_str @pyqtSlot(str) def on_lineEdit_charger_textChanged(self, p_str): try: if p_str != self.ori_detail['charger']: self.new_detail['charger'] = p_str else: try: del self.new_detail['charger'] except KeyError: pass except KeyError: self.new_detail['charger'] = p_str @pyqtSlot(str) def on_lineEdit_telno_textChanged(self, p_str): try: if p_str != self.ori_detail['telno']: self.new_detail['telno'] = p_str else: try: del self.new_detail['telno'] except KeyError: pass except KeyError: self.new_detail['telno'] = p_str @pyqtSlot(str) def on_lineEdit_chargertitle_textChanged(self, p_str): try: if p_str != self.ori_detail['chargertitle']: self.new_detail['chargertitle'] = p_str else: try: del self.new_detail['chargertitle'] except KeyError: pass except KeyError: self.new_detail['chargertitle'] = p_str @pyqtSlot(str) def on_lineEdit_email_textChanged(self, p_str): try: if p_str != self.ori_detail['email']: self.new_detail['email'] = p_str else: try: del self.new_detail['email'] except KeyError: pass except KeyError: self.new_detail['email'] = p_str @pyqtSlot(str) def on_lineEdit_bankname_textChanged(self, p_str): try: if p_str != self.ori_detail['bankname']: self.new_detail['bankname'] = p_str else: try: del self.new_detail['bankname'] except KeyError: pass except KeyError: self.new_detail['bankname'] = p_str @pyqtSlot(str) def on_lineEdit_bankaccount_textChanged(self, p_str): try: if p_str != self.ori_detail['bankaccount']: self.new_detail['bankaccount'] = p_str else: try: del self.new_detail['bankaccount'] except KeyError: pass except KeyError: self.new_detail['bankaccount'] = p_str @pyqtSlot(str) def on_lineEdit_taxno_textChanged(self, p_str): try: if p_str != self.ori_detail['taxno']: self.new_detail['taxno'] = p_str else: try: del self.new_detail['taxno'] except KeyError: pass except KeyError: self.new_detail['taxno'] = p_str @pyqtSlot(QDate) def on_dateEdit_validdate_dateChanged(self, q_date): try: if type(self.ori_detail['validdate']) is str: self.new_detail['validdate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['validdate']): self.new_detail['validdate'] = q_date.toPyDate() else: try: del self.new_detail['validdate'] except KeyError: pass except KeyError: self.new_detail['validdate'] = q_date.toPyDate() @pyqtSlot() def on_plainTextEdit_remark_textChanged(self): p_str = self.plainTextEdit_remark.toPlainText() 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_pushButton_accept_clicked(self): if not len(self.new_detail): return condition = dict() if self.autoid is not None: condition['autoid'] = self.autoid self.SC.update_data(0, condition, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_revalution_itemDoubleClicked(self, qtreeitem, p_int): if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_save_clicked() self.docid = int(qtreeitem.text(0)) key_dict = {'autoid': self.docid} res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_7.isEmpty(): self.gridLayout_7.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_7.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid) @pyqtSlot() def on_pushButton_save_clicked(self): if self.docid == 0: return if not hasattr(self.current_content, 'flat'): return newcontent = self.current_content.get_content() condition = {'autoid': self.docid} kwargs = {'conclusion': newcontent} self.SC.update_data(4, condition, **kwargs) self.current_content.flat = 0 @pyqtSlot() def on_pushButton_undo_clicked(self): if hasattr(self.current_content, 'flat'): self.current_content.flat = 0 @pyqtSlot(QPoint) def on_treeWidget_revalution_customContextMenuRequested(self, pos): if self.power[1] == '0': return if self.autoid is None: return sender_widget = self.sender() current_item = sender_widget.currentItem() menu = QMenu() button1 = menu.addAction("增加记录") button2 = menu.addAction("修改记录") button3 = menu.addAction("删除记录") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = SelectSelfDefineFormatModule('4', self) detail.selected.connect(self.new_records) detail.accepted.connect(self.get_format) detail.show() elif action == button2: if current_item is None: return if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.docid = int(current_item.text(0)) key_dict = {'autoid': self.docid} res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_7.isEmpty(): self.gridLayout_7.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_7.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid) elif action == button3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.SC.delete_data(4, condition) self.get_format() def new_records(self, q_list): detail = { 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date, 'spid': self.autoid } key_dict = {'autoid__in': q_list} sd_list = self.SDC.get_data(0, **key_dict) for item in q_list: for sd in sd_list: if item == sd.autoid: detail['title'] = sd.formatname detail['conclusion'] = sd.format self.SC.update_data(4, **detail) break @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): if p_int == 0: self.get_detail() elif p_int == 1: self.get_image() elif p_int == 2: self.get_format() elif p_int == 3: self.get_stuff() else: pass
def on_treewidget_filetree_itemClicked(self, qitem, p_int): try: # 判断之前是否有打开过文档且没有保存 if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QtWidgets.QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() except (AttributeError, TypeError): pass finally: if not self.gridLayout_4.isEmpty(): self.gridLayout_4.removeWidget(self.current_content) self.current_content.close() self.label_filename.setText(qitem.text(0)) self.current_docid = qitem.text(3) # 点击的是内建文档 if qitem.text(1) == '2': doctype = int(qitem.text(3)) # 生产指令 if doctype == -1: self.current_content = PorductionInstructionModule( self.autoid, self) # 领料单 if doctype in (-2, -3, -4): self.current_content = StuffdrawpaperModule( qitem.text(4), self) # 退料单 elif doctype in (-5, -6, -7): self.current_content = StuffReturnPaperModule( qitem.text(4), self) # 批包装指令 elif doctype == -8: self.current_content = PackageInstructionModule( self.autoid, self) # 批剩余(残次)标签、包装材料销毁记录 elif doctype == -9: pass # 称量配料记录 elif doctype == -10: pass # 半成品登记/发放记录 elif doctype in (-11, -12): self.current_content = MidproddrawnoteModule( self.autoid, abs(doctype) - 11) # 前处理入库单 elif doctype == -14: self.current_content = PreProdPutInModule(autoid=self.autoid, parent=self) # 成品寄库单 elif doctype == -13: self.current_content = ProductputinModule( int(qitem.text(4)), self) # 请验单 if doctype in (-15, -16, -17, -18): docid = qitem.text(2) if docid == "-1": self.current_content = CheckreportModule(autoid=int( qitem.text(4)), is_view=True, parent=self) else: self.current_content = ApplycheckModule(autoid=int( qitem.text(4)), parent=self) # 清场合格证(副本) elif doctype == -19: self.current_content = CleanconfirmityCopyModule( int(qitem.text(4)), self) # 清场合格证(正本) elif doctype == -20: self.current_content = CleanconfirmityOriginalModule( qitem.text(4), int(qitem.parent().text(3)), self) # 库存零头领取单 elif doctype == -21: pass # 尾料销毁记录 elif doctype == -22: pass # 产品二维码 elif doctype == -23: self.current_content = QrcodelistModule(self.autoid, self) # 小、中包装二维码关联 elif doctype == -24: pass # 大、中包装二维码关联 elif doctype == -25: pass # 巨、大包装二维码关联 elif doctype == -26: pass # 零头登记记录 elif doctype == -27: self.current_content = OddmentregisternoteModule( self.autoid, self) # 零头发放记录 elif doctype == -28: self.current_content = OddmentdrawnoteModule(self.autoid, self) # 退货产品领料单 elif doctype == -29: pass self.gridLayout_4.addWidget(self.current_content) # 点击的是自定义文档 elif qitem.text(1) == '3': # 自定义文档在Forms表里的id formatid = qitem.text(3) document = self.wsmodels.get_form(formatid) if document is not None: content = document.format self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_4.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.autoid) # 点击的是岗位名 elif qitem.text(1) == '1': self.current_content = PostdetailModule(qitem.text(2), self.detail[0].lineid, qitem.text(3), qitem.text(0), self) self.gridLayout_4.addWidget(self.current_content) # 点击的是封面 elif qitem.text(1) == '0': self.current_content = HomePageModule(self.autoid, self) self.gridLayout_4.addWidget(self.current_content)
def __init__(self, dom, parent=None): super(ViewFormat, self).__init__(parent) self.dom = dom self.setupUi(self) self.current_content = XMLReadWrite() self.set_format()
class AuxiliaryRecordModule(QWidget, Ui_Form): def __init__(self, kind, parent=None): super(AuxiliaryRecordModule, self).__init__(parent) self.setupUi(self) if kind == 0: index = '12' elif kind == 1: index = '25' elif kind == 2: index = '32' else: index = '-1' if index not in user.powers: self.close() if user.powers[index] == 0: self.close() self.power = '{:03b}'.format(user.powers[index]) if self.power[1] == '0': self.pushButton_accept.setEnabled(False) self.pushButton_cancel.setEnabled(False) self.kind = kind self.year = user.NIAN self.month = user.YUE self.docid = 0 self.current_content = QWidget() self.AC = AuxiliaryRecordController() self.SC = SelfdefinedformatController() self.treeWidget_itemlist.hideColumn(0) self.treeWidget_itemlist.hideColumn(4) self.get_year_list() def get_year_list(self): key_dict = {'deptid': user.dept_id} res = self.AC.get_data(0, True, *VALUES_TUPLE_YEAR, **key_dict).\ annotate(Min('createdate')) if len(res): self.comboBox_year.addItems(map(str, res)) else: self.comboBox_year.addItem(user.NIAN) if self.comboBox_year.findText(user.NIAN, Qt.MatchExactly) == -1: self.comboBox_year.addItem(user.NIAN) self.comboBox_year.setCurrentText(user.NIAN) self.tabWidget_itemlist.setCurrentIndex(int(user.YUE) - 1) def get_item_list(self): self.treeWidget_itemlist.clear() key_dict = { 'deptid': user.dept_id, 'kind': self.kind, 'createdate__year': self.year, 'createdate__month': self.month } res = self.AC.get_data(0, False, *VALUES_TUPLE_ITEM, **key_dict) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_itemlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['title']) qtreeitem.setText( 2, str(item['createdate']) if type(item['createdate']) is datetime.date else '') qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname']) qtreeitem.setText(4, str(item['sdid'])) for i in range(1, 4): self.treeWidget_itemlist.resizeColumnToContents(i) @pyqtSlot(int) def on_tabWidget_itemlist_currentChanged(self, p_int): self.month = p_int + 1 tab = getattr(self, 'tab_' + str(p_int)) tab.setLayout(self.gridLayout_2) self.get_item_list() @pyqtSlot(str) def on_comboBox_year_currentTextChanged(self, p_str): if p_str in ('', ' '): return self.year = int(p_str) self.get_item_list() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_itemlist_itemDoubleClicked(self, qtreeitem, p_int): if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.docid = int(qtreeitem.text(0)) key_dict = {'autoid': self.docid} res = self.AC.get_data(0, True, *VALUES_TUPLE_CONTENT, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_3.isEmpty(): self.gridLayout_3.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_3.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid) @pyqtSlot() def on_pushButton_accept_clicked(self): if self.docid == 0: return if not hasattr(self.current_content, 'flat'): return newcontent = self.current_content.get_content() condition = {'autoid': self.docid} kwargs = {'ar': newcontent} self.AC.update_data(0, condition, **kwargs) self.current_content.flat = 0 @pyqtSlot() def on_pushButton_cancel_clicked(self): if hasattr(self.current_content, 'flat'): self.current_content.flat = 0 @pyqtSlot(QPoint) def on_treeWidget_itemlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return sender_widget = self.sender() current_item = sender_widget.currentItem() menu = QMenu() button1 = menu.addAction("增加记录") button2 = menu.addAction("修改记录") button3 = menu.addAction("删除记录") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = SelectSelfDefineFormatModule(SD_TYPE[self.kind], self) detail.selected.connect(self.new_records) detail.accepted.connect(self.get_item_list) detail.show() elif action == button2: if current_item is None: return if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.docid = int(current_item.text(0)) key_dict = {'autoid': self.docid} res = self.AC.get_data(0, True, *VALUES_TUPLE_CONTENT, **key_dict) if not len(res): return content = str(res[0]) if not self.gridLayout_3.isEmpty(): self.gridLayout_3.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_3.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.docid) elif action == button3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.AC.delete_data(0, condition) self.get_item_list() def new_records(self, q_list): detail = { 'kind': self.kind, 'creatorid': user.user_id, 'creatorname': user.user_name, 'deptid': user.dept_id, 'deptname': user.dept_name, 'createdate': user.now_date } key_dict = {'autoid__in': q_list} sd_list = self.SC.get_data(0, **key_dict) for item in q_list: for sd in sd_list: if item == sd.autoid: detail['sdid'] = item detail['title'] = sd.formatname detail['ar'] = sd.format self.AC.update_data(0, **detail) break
class VerificationDetailModule(QDialog, Ui_Dialog): updated = pyqtSignal() def __init__(self, autoid=None, vdpid=0, parent=None): super(VerificationDetailModule, self).__init__(parent) self.setupUi(self) self.autoid = autoid self.vdpid = vdpid self.filename = None self.doc = None self.reportid = 0 self.current_content = QWidget() self.current_img = object self.current_page = object self.label_image.setScaledContents(True) self.status = 0 self.current_docid = 0 self.ori_detail = {} self.new_detail = {} self.VC = VerificationController() self.SC = SelfdefinedformatController() self.lineEdit_product.setup(DB_TABLE_TUPLE[0], RETURN_ROW[0], CONDITION_KEY[0], TREEHEADER_NAME, None, 330, 200) self.treeWidget_report.hideColumn(0) self.treeWidget_labreport.hideColumn(0) self.treeWidget_labreport.hideColumn(1) self.treeWidget_pp_record.hideColumn(0) self.treeWidget_pp_record.hideColumn(1) self.label_other.setVisible(False) self.lineEdit_other.setVisible(False) self.get_plan() self.show_plandoc() self.get_report() self.get_producingplan_records() self.get_lab_records() def get_plan(self): if self.autoid is None: self.tabWidget.setTabVisible(1, False) self.tabWidget.setTabVisible(2, False) self.tabWidget.setTabVisible(3, False) self.tabWidget.setTabVisible(4, False) self.tabWidget.setTabVisible(5, False) self.dateEdit_valstartdate.setDate(user.now_date) self.dateEdit_valenddate.setDate(user.now_date) self.dateEdit_createdate.setDate(user.now_date) self.pushButton_examine.setVisible(False) self.pushButton_approval.setVisible(False) self.pushButton_finish.setVisible(False) return condition = {'autoid': self.autoid} res = self.VC.get_data(1, False, *VALUES_TUPLE_PLAN, **condition) if not len(res): return self.ori_detail = res[0] self.comboBox_valtype.setCurrentIndex(self.ori_detail['valtype']) self.comboBox_kind.setCurrentIndex(self.ori_detail['kind']) if self.ori_detail['kind'] < 2: self.lineEdit_product.setText(self.ori_detail['prodid'] + ' ' + self.ori_detail['prodname']) else: self.lineEdit_other.setText(self.ori_detail['prodnamether']) self.dateEdit_valstartdate.setDate(self.ori_detail['valstartdate']) self.dateEdit_valenddate.setDate(self.ori_detail['valenddate']) self.lineEdit_doctitle.setText(self.ori_detail['doctitle']) self.label_creator.setText(self.ori_detail['creatorid'] + ' ' + self.ori_detail['creatorname']) self.dateEdit_createdate.setDate(self.ori_detail['createdate'] if type( self.ori_detail['createdate']) is datetime.date else user.now_date) self.label_examiner.setText(self.ori_detail['auditorid'] + ' ' + self.ori_detail['auditorname']) self.dateEdit_auditdate.setDate(self.ori_detail['auditdate'] if type( self.ori_detail['auditdate']) is datetime.date else user.now_date) self.label_approver.setText(self.ori_detail['approverid'] + ' ' + self.ori_detail['approvername']) self.dateEdit_approvedate.setDate(self.ori_detail['approvedate'] if type(self.ori_detail['approvedate']) is datetime.date else user.now_date) if self.ori_detail['status'] == 1: self.pushButton_upload.setVisible(False) self.pushButton_apply.setVisible(False) self.pushButton_examine.setVisible(False) self.pushButton_approval.setVisible(False) self.pushButton_finish.setVisible(False) def show_plandoc(self): if not len(self.ori_detail): return ext = self.ori_detail['ext'] title = self.ori_detail['doctitle'] self.doc = self.ori_detail['doc'] if ext in ("doc", "docx"): self.groupBox_pdf.setVisible(False) self.axWidget.setVisible(True) self.axWidget.clear() if not (self.axWidget.setControl("Word.Application") or self.axWidget.setControl("Kwps.Application")): msg = MessageBox(self, text="没有安装Word/WPS文字!") msg.show() return self.open_office(title + '.' + ext) elif ext == "pdf": self.axWidget.setVisible(False) self.axWidget.clear() self.groupBox_pdf.setVisible(True) self.open_pdf(title + '.' + ext) elif ext in ("xls", "xlsx"): self.groupBox_pdf.setVisible(False) self.axWidget.setVisible(True) self.axWidget.clear() if not (self.axWidget.setControl("Excel.Application") or self.axWidget.setControl("Ket.Application")): msg = MessageBox(self, text="没有安装Excel/WPS表格!") msg.show() return self.open_office(title + '.' + ext) def get_report(self): self.treeWidget_report.clear() if self.autoid is None: return condition = {'vdrid_id': self.autoid} res = self.VC.get_data(2, False, *VALUES_TUPLE_REPORT, *condition) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_report) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['formname']) qtreeitem.setText(2, item['creatorid'] + ' ' + item['creatorname']) qtreeitem.setText(3, str(item['createdate'])) for i in range(1, 4): self.treeWidget_report.resizeColumnToContents(i) def get_producingplan_records(self): self.treeWidget_pp_record.clear() condition = {'kind': 0, 'vdrid_id': self.autoid} res = self.VC.get_data(3, False, **condition).extra( select={ 'prodid': 'prodid', 'prodname': 'prodname', 'spec': 'spec', 'package': 'package', 'batchno': 'batchno', 'status': 'status', 'makedate': 'makedate' }, tables=['Producingplan'], where=['Producingplan.autoid=Validaterelationrecords.ppid' ]).values(*VALUES_TUPLE_PP) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_pp_record) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['ppid'])) qtreeitem.setText(2, STATUS_PP[item['status']]) qtreeitem.setText(3, item['prodid']) qtreeitem.setText(4, item['prodname']) qtreeitem.setText(5, item['batchno']) qtreeitem.setText(6, item['spec']) qtreeitem.setText(7, item['package']) qtreeitem.setText(8, str(item['makedate'])) for i in range(1, 9): self.treeWidget_pp_record.resizeColumnToContents(i) def get_lab_records(self): self.treeWidget_labreport.clear() condition = {'kind': 1, 'vdrid_id': self.autoid} res = self.VC.get_data(3, False, **condition).extra( select={ 'chkid': 'chkid', 'chkname': 'chkname', 'spec': 'spec', 'package': 'package', 'batchno': 'batchno', 'status': 'status', 'paperno': 'paperno' }, tables=['Labrecords'], where=['Labrecords.autoid=Validaterelationrecords.ppid' ]).values(*VALUES_TUPLE_LR) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_labreport) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['ppid'])) qtreeitem.setText(2, STATUS_LR[item['status']]) qtreeitem.setText(3, item['chkid']) qtreeitem.setText(4, item['chkname']) qtreeitem.setText(5, item['batchno']) qtreeitem.setText(6, item['spec']) qtreeitem.setText(7, item['package']) for i in range(1, 8): self.treeWidget_labreport.resizeColumnToContents(i) @pyqtSlot(QPoint) def on_treeWidget_pp_record_customContextMenuRequested(self, pos): current_item = self.treeWidget_pp_record.currentItem() global_pos = self.treeWidget_pp_record.mapToGlobal(pos) menu = QMenu() action_1 = menu.addAction("新建生产记录") action_2 = menu.addAction("关联生产记录") action_3 = menu.addAction("删除记录") action = menu.exec(global_pos) if action == action_1: detail = EditProducingplan(parent=self) detail.created.connect(self.created_producingplan) detail.created.connect(self.get_producingplan_records) detail.show() elif action == action_2: detail = SelectRecordsModule(0, self) detail.selected.connect(self.add_pp_or_lr_records) detail.selected.connect(self.get_producingplan_records) detail.show() elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.VC.delete_data(3, condition) self.get_producingplan_records() def created_producingplan(self, ppid): self.add_pp_or_lr_records(0, [ ppid, ]) @pyqtSlot(QPoint) def on_treeWidget_labreport_customContextMenuRequested(self, pos): current_item = self.treeWidget_labreport.currentItem() global_pos = self.treeWidget_labreport.mapToGlobal(pos) menu = QMenu() action_1 = menu.addAction("新建请验单") action_2 = menu.addAction("关联检验记录") action_3 = menu.addAction("删除记录") action = menu.exec(global_pos) if action == action_1: pass elif action == action_2: detail = SelectRecordsModule(1, self) detail.selected.connect(self.add_pp_or_lr_records) detail.selected.connect(self.get_lab_records) detail.show() elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.VC.delete_data(3, condition) self.get_lab_records() def add_pp_or_lr_records(self, p_int, id_list): for item in id_list: detail = {'vdrid_id': self.autoid, 'kind': p_int, 'ppid': item} self.VC.update_data(3, **detail) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_pp_record_itemDoubleClicked(self, qtreeitem, p_int): id = int(qtreeitem.text(1)) try: detail = ProducingModule(autoid=id, parent=self) detail.show() except ValueError: pass @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_labreport_itemDoubleClicked(self, qtreeitem, p_int): id = int(qtreeitem.text(1)) detail = CheckreportModule(autoid=id, is_view=True, parent=self) detail.show() @pyqtSlot(QPoint) def on_treeWidget_report_customContextMenuRequested(self, pos): current_item = self.treeWidget_report.currentItem() global_pos = self.treeWidget_report.mapToGlobal(pos) menu = QMenu() action_1 = menu.addAction("增加") action_2 = menu.addAction("修改") action_3 = menu.addAction("删除") action = menu.exec(global_pos) if action == action_1: detail = SelectSelfDefineFormatModule("512", self) detail.selected.connect(self.add_oricheckpaper) detail.selected.connect(self.get_report) detail.show() elif action == action_2: if current_item is None: return if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.reportid = int(current_item.text(0)) condition = {'autoid': self.reportid} res = self.VC.get_data(2, True, *VALUES_TUPLE_RP_DETAIL, **condition) if not len(res): return content = str(res[0]) if not self.gridLayout_11.isEmpty(): self.gridLayout_11.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_11.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.reportid) elif action == action_3: if current_item is None: return id = int(current_item.text(0)) condition = {'autoid': id} self.VC.delete_data(2, condition) self.get_report() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_report_itemDoubleClicked(self, qtreeitem, p_int): if hasattr(self.current_content, 'flat'): if self.current_content.flat: dialog = MessageBox(self, title="提醒", text="文档尚未保存", informative="是否要保存文档", yes_text="保存", no_text="放弃保存") result = dialog.exec() if result == QMessageBox.Yes: # 调用保存的槽函数 self.on_pushButton_accept_clicked() self.reportid = int(qtreeitem.text(0)) condition = {'autoid': self.reportid} res = self.VC.get_data(2, True, *VALUES_TUPLE_RP_DETAIL, **condition) if not len(res): return content = str(res[0]) if not self.gridLayout_11.isEmpty(): self.gridLayout_11.removeWidget(self.current_content) self.current_content.close() self.current_content = XMLReadWrite(self) self.current_content.openxml(content) self.gridLayout_11.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.reportid) @pyqtSlot() def on_pushButton_accept_clicked(self): if self.reportid == 0: return if not hasattr(self.current_content, 'flat'): return newcontent = self.current_content.get_content() condition = {'autoid': self.reportid} kwargs = {'formcontent': newcontent} self.VC.update_data(2, condition, **kwargs) self.current_content.flat = 0 @pyqtSlot() def on_pushButton_cancel_clicked(self): if hasattr(self.current_content, 'flat'): self.current_content.flat = 0 def add_oricheckpaper(self, sdfid_list): condition = {'autoid__in': sdfid_list} res = self.SC.get_data(0, False, *VALUES_TUPLE_SD, **condition) for item in res: condition = { 'vdrid_id': self.autoid, 'formname': item['formatname'], 'formcontent': item['format'], 'creatorid': user.user_id, 'creatorname': user.user_name, 'createdate': user.now_date } self.VC.update_data(2, **condition) self.get_report() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_records_itemDoubleClicked(self, qtreeitem, p_int): id = int(qtreeitem.text(0)) detail = VerificationDetailModule(autoid=id, parent=self) detail.updated.connect(self.get_reports) detail.show() def open_office(self, filename): if not os.path.exists(os.getcwd() + '\\temp'): os.makedirs(os.getcwd() + '\\temp') self.filename = os.getcwd() + '\\temp\\' + filename with open(self.filename, 'wb') as fp: fp.write(self.doc) fp.close() fp = None self.axWidget.setControl(self.filename) def open_pdf(self, filename): self.current_img = fitz.Document(stream=self.doc, 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) self.horizontalSlider_zoom.setValue(20) @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(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(int) def on_comboBox_valtype_currentIndexChanged(self, p_int): try: if p_int != self.ori_detail['valtype']: self.new_detail['valtype'] = p_int else: try: del self.new_detail['valtype'] except KeyError: pass except KeyError: self.new_detail['valtype'] = p_int @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 KeyError: self.new_detail['kind'] = p_int # if 'prodid' in self.new_detail: # del self.new_detail['prodid'] # if 'prodname' in self.new_detail: # del self.new_detail['prodname'] if p_int < 2: self.label_prodname.setVisible(True) self.lineEdit_product.setVisible(True) self.label_other.setVisible(False) self.lineEdit_other.setVisible(False) self.lineEdit_product.setText('') self.lineEdit_product.setup(DB_TABLE_TUPLE[p_int], RETURN_ROW[p_int], CONDITION_KEY[p_int], TREEHEADER_NAME, None, 300, 200) else: self.label_prodname.setVisible(False) self.lineEdit_product.setVisible(False) self.label_other.setVisible(True) self.lineEdit_other.setVisible(True) self.lineEdit_other.setText('') @pyqtSlot() def on_pushButton_upload_clicked(self): fileurl, type = QFileDialog.getOpenFileName( self, "打开文件", os.path.expanduser("~") + "\Desktop", "选择文件(*.docx *.doc *.pdf);;All File(*.*)") if not fileurl: return filename = fileurl.split("/")[-1] name_no_ext = filename.split(".")[0] ext = fileurl.split(".")[1] if ext.lower() not in ('doc', 'docx', 'xls', 'xlsx', 'pdf'): return fp = open(fileurl, 'rb') with fp: file_byte = fp.read() fp.close() fp = None self.lineEdit_doctitle.setText(name_no_ext) self.new_detail['doc'] = file_byte self.doc = file_byte self.new_detail['ext'] = ext.lower() self.new_detail['doctitle'] = name_no_ext if ext in ("doc", "docx"): self.groupBox_pdf.setVisible(False) self.axWidget.setVisible(True) self.axWidget.clear() if not (self.axWidget.setControl("Word.Application") or self.axWidget.setControl("Kwps.Application")): msg = MessageBox(self, text="没有安装Word/WPS文字!") msg.show() return self.open_office(name_no_ext + '.' + ext) elif ext == "pdf": self.axWidget.setVisible(False) self.axWidget.clear() self.groupBox_pdf.setVisible(True) self.open_pdf(name_no_ext + '.' + ext) elif ext in ("xls", "xlsx"): self.groupBox_pdf.setVisible(False) self.axWidget.setVisible(True) self.axWidget.clear() if not (self.axWidget.setControl("Excel.Application") or self.axWidget.setControl("Ket.Application")): msg = MessageBox(self, text="没有安装Excel/WPS表格!") msg.show() return self.open_office(name_no_ext + '.' + ext) @pyqtSlot(object) def on_lineEdit_product_getItem(self, qtreeitem): if qtreeitem is None: self.new_detail['prodid'] = '' self.new_detail['prodname'] = '' return id, name = qtreeitem.text(1), qtreeitem.text(2) try: if id != self.ori_detail['prodid'] and name != self.ori_detail[ 'prodname']: self.new_detail['prodid'] = id self.new_detail['prodname'] = name else: try: del self.new_detail['prodid'] del self.new_detail['prodname'] except KeyError: pass except KeyError: self.new_detail['prodid'] = id self.new_detail['prodname'] = name @pyqtSlot(str) def on_lineEdit_other_textChanged(self, p_str): try: if p_str != self.ori_detail['prodname']: self.new_detail['prodid'] = '' self.new_detail['prodname'] = p_str else: try: del self.new_detail['prodid'] del self.new_detail['prodname'] except KeyError: pass except KeyError: self.new_detail['prodid'] = '' self.new_detail['prodname'] = p_str @pyqtSlot(QDate) def on_dateEdit_valstartdate_dateChanged(self, q_date): try: if type(self.ori_detail['valstartdate']) is str: self.new_detail['valstartdate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['valstartdate']): self.new_detail['valstartdate'] = q_date.toPyDate() else: try: del self.new_detail['valstartdate'] except KeyError: pass except KeyError: self.new_detail['valstartdate'] = q_date.toPyDate() @pyqtSlot(QDate) def on_dateEdit_valenddate_dateChanged(self, q_date): try: if type(self.ori_detail['valenddate']) is str: self.new_detail['valenddate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['valenddate']): self.new_detail['valenddate'] = q_date.toPyDate() else: try: del self.new_detail['valenddate'] except KeyError: pass except KeyError: self.new_detail['valenddate'] = q_date.toPyDate() @pyqtSlot(QDate) def on_dateEdit_createdate_dateChanged(self, q_date): try: if type(self.ori_detail['createdate']) is str: self.new_detail['createdate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['createdate']): self.new_detail['createdate'] = q_date.toPyDate() else: try: del self.new_detail['createdate'] except KeyError: pass except KeyError: self.new_detail['createdate'] = q_date.toPyDate() @pyqtSlot(QDate) def on_dateEdit_auditdate_dateChanged(self, q_date): try: if type(self.ori_detail['auditdate']) is str: self.new_detail['auditdate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['auditdate']): self.new_detail['auditdate'] = q_date.toPyDate() else: try: del self.new_detail['auditdate'] except KeyError: pass except KeyError: self.new_detail['auditdate'] = q_date.toPyDate() @pyqtSlot(QDate) def on_dateEdit_approvedate_dateChanged(self, q_date): try: if type(self.ori_detail['approvedate']) is str: self.new_detail['approvedate'] = q_date.toPyDate() return if q_date != QDate(self.ori_detail['approvedate']): self.new_detail['approvedate'] = q_date.toPyDate() else: try: del self.new_detail['approvedate'] except KeyError: pass except KeyError: self.new_detail['approvedate'] = q_date.toPyDate() @pyqtSlot() def on_pushButton_apply_clicked(self): self.new_detail['creatorid'] = user.user_id self.new_detail['creatorname'] = user.user_name self.label_creator.setText(user.user_id + ' ' + user.user_name) if self.autoid is None: self.new_detail['vdpid_id'] = self.vdpid res = self.VC.update_data(1, **self.new_detail) self.autoid = res.autoid self.tabWidget.setTabVisible(1, True) self.tabWidget.setTabVisible(2, True) self.tabWidget.setTabVisible(3, True) self.tabWidget.setTabVisible(4, True) self.tabWidget.setTabVisible(5, True) self.pushButton_examine.setVisible(True) self.pushButton_approval.setVisible(True) else: condition = {'autoid': self.autoid} self.VC.update_data(1, condition, **self.new_detail) self.updated.emit() @pyqtSlot() def on_pushButton_examine_clicked(self): self.new_detail['examineid'] = user.user_id self.new_detail['examinename'] = user.user_name condition = {'autoid': self.autoid} self.VC.update_data(1, condition, **self.new_detail) self.updated.emit() @pyqtSlot() def on_pushButton_approval_clicked(self): self.new_detail['approvalid'] = user.user_id self.new_detail['approvalname'] = user.user_name condition = {'autoid': self.autoid} self.VC.update_data(1, condition, **self.new_detail) self.updated.emit() @pyqtSlot() def on_pushButton_finish_clicked(self): self.new_detail['status'] = 1 condition = {'autoid': self.autoid} self.VC.update_data(1, condition, **self.new_detail) self.updated.emit() def closeEvent(self, event): self.axWidget.clear() if self.filename is not None and os.path.exists(self.filename): os.remove(self.filename) super(VerificationDetailModule, self).closeEvent(event)
class OricheckpaperModule(QWidget, Ui_Form): deleted = pyqtSignal() def __init__(self, autoid, is_view, parent=None): super(OricheckpaperModule, self).__init__(parent) self.setupUi(self) self.is_view = is_view if is_view: self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_delete.setVisible(False) self.ori_detail = dict() self.autoid = autoid self.LC = LabrecordsController() self.current_content = object # 获取记录内容 self.get_oricheckpaper() # 获取设备运行记录 self.get_equiprunnote() self.treeWidget_equipment.setContextMenuPolicy(3) self.treeWidget_equipment.customContextMenuRequested.connect( self.eqrun_menu) def get_oricheckpaper(self): values_list = ('formcontent', ) key_dict = {'autoid': self.autoid} res = self.LC.get_oricheckpaper(True, *values_list, **key_dict) if len(res): ori_paper = res[0] self.current_content = XMLReadWrite(self) self.current_content.openxml(ori_paper) self.gridLayout_6.addWidget(self.current_content) self.current_content.__setattr__('autoid', self.autoid) def get_equiprunnote(self): self.treeWidget_equipment.clear() EC = EquipmentController() ''' values_list = ( 'autoid', 'eqno', 'eqname', 'fillerid', 'fillername', 'runstarttime', 'runendtime', 'runtime', 'runstatus' ) key_dict = { 'pid': self.autoid, 'rtype': 1 } ''' key_dict = {'pid': self.autoid, 'rtype': 1} eqrunnotes = EC.get_data(1, False, **key_dict).extra( select={'eqname': 'equipments.eqname'}, tables=['equipments'], where=['equipments.eqno=eqrunnotes.eqno']) if len(eqrunnotes): for item in eqrunnotes: qtreeitem = QTreeWidgetItem(self.treeWidget_equipment) qtreeitem.setText(0, str(item.autoid)) qtreeitem.setText(1, item.eqno + ' ' + item.eqname) qtreeitem.setText(2, item.fillerid + ' ' + item.fillername) qtreeitem.setText(3, str(item.runstarttime)) qtreeitem.setText(4, str(item.runendtime)) qtreeitem.setText(5, str(item.runtime) + ' ' + '分钟') qtreeitem.setText(6, RUN_STATUS[item.runstatus]) self.treeWidget_equipment.hideColumn(0) for i in range(1, 7): self.treeWidget_equipment.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_equipment_itemDoubleClicked(self, qitem, p_int): eqrun_detail = EqrunnoteModule(qitem.text(0), edit=not self.is_view, parent=self) eqrun_detail.accepted.connect(self.get_equiprunnote) eqrun_detail.show() # 设备运行记录右键菜单功能 def eqrun_menu(self, pos): if self.is_view: 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) select_items = sender_widget.selectedItems() autoid_list = [] for item in select_items: autoid_list.append(int(item.text(0))) if len(select_items): EC = EquipmentController() # 编辑运行记录 if action == button1: eqrun_detail = EqrunnoteModule( autoid=sender_widget.currentItem().text(0), edit=not self.is_view, parent=self) res = eqrun_detail.exec() # 复制运行记录 elif action == button2: res = EC.insert_equip_run_note(autoid_list) # 删除运行记录 elif action == button3: res = EC.delete_equip_run_note(autoid_list) if res: self.get_equiprunnote() @pyqtSlot() def on_pushButton_accept_clicked(self): condition = { 'autoid': self.autoid, 'formcontent': self.current_content.get_content() } self.LC.update_data(2, **condition) self.current_content.flat = 0 # 运行记录双击功能 @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_equipment_itemDoubleClicked(self, qitem, p_int): if self.is_view: return eqrun_detail = EqrunnoteModule(autoid=qitem.text(0), edit=not self.is_view, parent=self) eqrun_detail.accepted.connect(self.get_equiprunnote) eqrun_detail.show() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.current_content.flat = 0 @pyqtSlot() def on_pushButton_delete_clicked(self): res = self.LC.delete_oricheckpaper(self.autoid) if res: self.deleted.emit() self.close()