class DaliyRecordsList(QWidget, Ui_Form):
    def __init__(self, kind, parent=None):
        super(DaliyRecordsList, self).__init__(parent)
        self.setupUi(self)
        if kind == 0:
            index = '51'
        elif kind == 1:
            index = '52'
        elif kind == 2:
            index = '13'
        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])
        self.kind = kind
        self.LC = LabrecordsController()
        self.stuffid = ''
        self.kindname = ''
        self.status = tuple()
        self.treeWidget_kindname.hideColumn(1)
        self.treeWidget_reportlist.hideColumn(0)

        self.get_location_list()

    def get_location_list(self):
        key_dict = {'kind': self.kind}
        res = self.LC.get_data(5, False, *VALUES_TUPLE_KIND, **key_dict)
        if not len(res):
            return
        for item in res:
            parentid = str(item['parentid'])
            if parentid == '0':
                qtreeitem = QTreeWidgetItem(self.treeWidget_kindname)
            else:
                items = self.treeWidget_kindname.findItems(parentid, Qt.MatchContains, 1)
                if len(items):
                    qtreeitem = QTreeWidgetItem(items[0])
                else:
                    qtreeitem = QTreeWidgetItem(self.treeWidget_kindname)
            qtreeitem.setText(0 , item['kindname'])
            qtreeitem.setText(1 , str(item['autoid']))
        self.treeWidget_kindname.resizeColumnToContents(0)

    def get_detail(self):
        self.treeWidget_reportlist.clear()
        key_dict = {
            'chkid': self.stuffid,
            'labtype': self.kind + 7,
            'status__in': self.status
        }
        res = self.LC.get_data(0, False, *VALUES_TUPLE_LR, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_reportlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STATUS[item['status']])
            qtreeitem.setText(2, item['paperno'])
            qtreeitem.setText(
                3, str(item['applydate']) if type(item['applydate']) is
                                             datetime.date else '')
            qtreeitem.setText(4, item['applyerid'] + ' ' + item['applyername'])

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kindname_itemDoubleClicked(self, qtreeitem, p_int):
        self.kindname = qtreeitem.text(0)
        self.stuffid = qtreeitem.text(1)
        self.get_detail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kindname_itemClicked(self, qtreeitem, p_int):
        self.kindname = qtreeitem.text(0)
        self.stuffid = qtreeitem.text(1)
        self.get_detail()

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        if p_int == 0:
            self.status = (0,)
        elif p_int == 1:
            self.status = (1, 2)
        else:
            self.status = (3, 4)
        tab = getattr(self, 'tab_' + str(p_int))
        tab.setLayout(self.gridLayout_2)
        self.get_detail()

    @pyqtSlot(QPoint)
    def on_treeWidget_reportlist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        index = self.tabWidget.currentIndex()
        if index > 2 or self.stuffid == '':
            return
        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 = ApplyDaliycheckModule(
                kind=self.kind+7, chkid=self.stuffid, source=self.kindname,
                parent=self
            )
            detail.accepted.connect(self.get_detail)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = ApplyDaliycheckModule(
                autoid=id, parent=self
            )
            detail.accepted.connect(self.get_detail)
            detail.show()
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            self.LC.delete_data(0, autoid=id)
            self.LC.delete_data(1, lrid=id)
            self.LC.delete_data(2, lrid=id)
            self.get_detail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_reportlist_itemDoubleClicked(self, qtreeitem, p_int):
        index = self.tabWidget.currentIndex()
        id = int(qtreeitem.text(0))
        if index == 2:
            detail = CheckreportModule(id, True, self)
            detail.show()
        else:
            detail = ApplyDaliycheckModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_detail)
            detail.show()
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()
Exemplo n.º 3
0
class DaliyRecordsetting(QWidget, Ui_Form):

    def __init__(self, parent=None):
        super(DaliyRecordsetting, self).__init__(parent)
        self.setupUi(self)
        # if '8' not in user.powers:
        #     self.close()
        # if user.powers['16'] == 0:
        #     self.close()
        # self.power = '{:03b}'.format(user.powers['16'])
        self.LC = LabrecordsController()

        # self.treeWidget_kindname.hideColumn(1)
        # self.treeWidget_reportlist.hideColumn(0)
        self.kind = 1
        self.kind_id = 0
        self.dictid = 0
        self.get_location_list()

    def get_location_list(self):
        self.treeWidget_kindname.clear()
        key_dict = {'kind': self.kind}
        res = self.LC.get_data(5, False, *VALUES_TUPLE_KIND, **key_dict)
        if not len(res):
            return
        for item in res:
            parentid = str(item['parentid'])
            if parentid == '0':
                qtreeitem = QTreeWidgetItem(self.treeWidget_kindname)
            else:
                items = self.treeWidget_kindname.findItems(parentid, Qt.MatchContains, 1)
                if len(items):
                    qtreeitem = QTreeWidgetItem(items[0])
                else:
                    qtreeitem = QTreeWidgetItem(self.treeWidget_kindname)
            qtreeitem.setText(0 , item['kindname'])
            qtreeitem.setText(1 , str(item['autoid']))
        self.treeWidget_kindname.resizeColumnToContents(0)

    def get_checkitem(self):
        self.treeWidget_checkitem.clear()
        condition = {'stuffid': self.dictid, 'itemtype': self.kind+6}
        res = self.LC.get_data(4, False, *VALUES_TUPLE_CHECKITEM, **condition)
        if not len(res):
            return
        for item in res.order_by('seqid'):
            qtreitem = QTreeWidgetItem(self.treeWidget_checkitem)
            qtreitem.setText(0, str(item['autoid']))
            qtreitem.setText(1, str(item['seqid']))
            qtreitem.setText(2, item['kind'])
            qtreitem.setText(3, item['itemname'])
            qtreitem.setText(4, item['referencevalue'])
        for i in range(1, 5):
            self.treeWidget_checkitem.resizeColumnToContents(i)

    def get_oricheckpaper(self):
        self.treeWidget_oricheckpaper.clear()
        condition = {'dictid': self.dictid, 'itemtype': self.kind+6}
        res = self.LC.get_data(3, False, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_oricheckpaper)
            qtreeitem.setText(0, str(item.autoid))
            qtreeitem.setText(1, item.sdfid.formatname)
            qtreeitem.setText(2, item.creatorid + ' ' + item.creatorname)
            qtreeitem.setText(3, str(item.createdate))
        for i in range(1, 4):
            self.treeWidget_oricheckpaper.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kindname_itemClicked(self, qtreeitem, p_int):
        self.dictid = int(qtreeitem.text(1))
        self.get_checkitem()
        self.get_oricheckpaper()

    @pyqtSlot(int)
    def on_tabWidget_kind_currentChanged(self, p_int):
        self.kind = p_int + 1
        tab = getattr(self, 'tab_' + str(p_int))
        tab.setLayout(self.gridLayout_4)
        self.get_location_list()
        self.treeWidget_checkitem.clear()
        self.treeWidget_oricheckpaper.clear()

    @pyqtSlot(QPoint)
    def on_treeWidget_kindname_customContextMenuRequested(self, pos):
        # if self.power[1] == '0':
        #     return
        current_item = self.treeWidget_kindname.currentItem()
        menu = QMenu()
        button1 = menu.addAction("增加分类")
        button2 = menu.addAction("修改分类")
        button3 = menu.addAction("删除分类")
        global_pos = self.treeWidget_kindname.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            if current_item is None:
                parent_item = self.treeWidget_kindname
                parent_id = 0
            else:
                parent_item = current_item
                parent_id = int(current_item.text(1))
            kwargs = {
                'kind': self.kind,
                'kindname': "新建分类",
                'parentid': parent_id,
                'inputcode': Inputcode.make_inputcode("新建分类")
            }
            kind_object = self.LC.update_data(5, **kwargs)
            qtreeitem = QTreeWidgetItem(parent_item)
            qtreeitem.setText(0, "新建分类")
            qtreeitem.setText(1, str(kind_object.autoid))

            self.treeWidget_kindname.openPersistentEditor(qtreeitem, 0)
            self.treeWidget_kindname.setCurrentItem(qtreeitem)
        elif action == button2:
            if current_item is None:
                return
            self.treeWidget_kindname.setCurrentItem(None)
            self.treeWidget_kindname.openPersistentEditor(current_item, 0)
            self.treeWidget_kindname.setCurrentItem(current_item, 0)
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(1))
            condition = {'autoid': id}
            self.LC.delete_data(5, condition)
            self.get_location_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kindname_itemChanged(self, qtreeitem, p_int):
        if self.treeWidget_kindname.isPersistentEditorOpen(qtreeitem, p_int):
            self.treeWidget_kindname.closePersistentEditor(qtreeitem, p_int)
            id = int(qtreeitem.text(1))
            new_kindname = qtreeitem.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.LC.update_data(5, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
    def on_treeWidget_kindname_currentItemChanged(self, qtreeitem, qtreeitem_1):
        if self.treeWidget_kindname.isPersistentEditorOpen(qtreeitem_1, 0):
            self.treeWidget_kindname.closePersistentEditor(qtreeitem_1, 0)
            id = int(qtreeitem_1.text(1))
            new_kindname = qtreeitem_1.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.LC.update_data(5, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kindname_itemDoubleClicked(self, qtreeitem, p_int):
        self.treeWidget_kindname.openPersistentEditor(qtreeitem, p_int)

    @pyqtSlot(QPoint)
    def on_treeWidget_checkitem_customContextMenuRequested(self, pos):
        # if self.power[1] == '0':
        #     return
        current_item = self.treeWidget_checkitem.currentItem()
        menu = QMenu()
        button1 = menu.addAction("增加检验项目")
        button2 = menu.addAction("修改检验项目")
        button3 = menu.addAction("删除检验项目")
        global_pos = self.treeWidget_checkitem.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            if self.dictid == 0:
                return
            detail = SetCheckItem(
                parent=self, prodid=self.dictid, itemtype=self.kind+6
            )
            detail.typelabel.setVisible(False)
            detail.restype.setVisible(False)
            detail.inputlabel.setVisible(False)
            detail.putintype.setVisible(False)
            detail.accepted.connect(self.get_checkitem)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = SetCheckItem(parent=self, autoid=id)
            detail.accepted.connect(self.get_checkitem)
            detail.typelabel.setVisible(False)
            detail.restype.setVisible(False)
            detail.inputlabel.setVisible(False)
            detail.putintype.setVisible(False)
            detail.show()
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            self.LC.delete_data(4, autoid=id)
            self.get_checkitem()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_checkitem_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = SetCheckItem(parent=self, autoid=id)
        detail.accepted.connect(self.get_checkitem)
        detail.typelabel.setVisible(False)
        detail.restype.setVisible(False)
        detail.inputlabel.setVisible(False)
        detail.putintype.setVisible(False)
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_oricheckpaper_customContextMenuRequested(self, pos):

        # if self.power[1] == '0':
        #     return
        current_item = self.treeWidget_oricheckpaper.currentItem()
        global_pos = self.treeWidget_oricheckpaper.mapToGlobal(pos)
        menu = QMenu()
        action_1 = menu.addAction("增加检验记录")
        action_2 = menu.addAction("删除检验记录")
        menu.addSeparator()
        action_3 = menu.addAction("增加检验设备")
        action = menu.exec(global_pos)
        if action == action_1:
            if self.dictid == 0:
                return
            detail = SelectSelfDefineFormatModule("1024", self)
            detail.selected.connect(self.add_oricheckpaper)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.LC.delete_data(3, **condition)
            self.get_oricheckpaper(self.treeWidget_stuffcheckpaper, 0)

        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = SelectOriCheckPaperEquipmentModule(id ,self)
            detail.show()

    def add_oricheckpaper(self, sdfid_list):
        for item in sdfid_list:
            condition = {
                'dictid': self.dictid,
                'itemtype': self.kind + 6,
                'sdfid_id': item,
                'creatorid': user.user_id,
                'creatorname': user.user_name,
                'createdate': user.now_date
            }
            self.LC.update_data(3, **condition)
        self.get_oricheckpaper()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
class SelectOriCheckPaperEquipmentModule(QDialog, Ui_Dialog):
    def __init__(self, opid, parent=None):
        super(SelectOriCheckPaperEquipmentModule, self).__init__(parent)
        self.setupUi(self)
        self.opid = opid
        self.LC = LabrecordsController()
        self.EC = EquipmentController()
        self.get_detail()
        self.get_equipments()
        self.treeWidget_useeq.hideColumn(0)
        self.treeWidget_eqlist.hideColumn(2)

    def get_detail(self):
        self.treeWidget_useeq.clear()
        condition = {'opid_id': self.opid}
        res = self.LC.get_data(8, False, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_useeq)
            qtreeitem.setText(0, str(item.autoid))
            qtreeitem.setText(1, item.eqid.eqno)
            qtreeitem.setText(2, item.eqid.eqname)
        self.treeWidget_useeq.resizeColumnToContents(1)
        self.treeWidget_useeq.resizeColumnToContents(2)

    def get_equipments(self):
        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ)
        if not len(res):
            return
        for item in res:
            deptname = item['deptname']
            parents = self.treeWidget_eqlist.findItems(deptname,
                                                       Qt.MatchExactly, 0)
            if len(parents):
                parent_item = parents[0]
            else:
                parent_item = QTreeWidgetItem(self.treeWidget_eqlist)
                parent_item.setText(0, deptname)
                parent_item.setText(2, '0')
            qtreeitem = QTreeWidgetItem(parent_item)
            qtreeitem.setText(0, item['eqno'])
            qtreeitem.setText(1, item['eqname'])
            qtreeitem.setText(2, str(item['autoid']))

    @pyqtSlot(QPoint)
    def on_treeWidget_useeq_customContextMenuRequested(self, pos):
        items = self.treeWidget_useeq.selectedItems()
        if not len(items):
            return
        menu = QMenu()
        action_1 = menu.addAction("删除")
        global_pos = self.treeWidget_useeq.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == action_1:
            id_list = []
            for item in items:
                id_list.append(int(item.text(0)))
            condition = {'autoid__in': id_list}
            self.LC.delete_data(8, condition)
            self.get_detail()

    @pyqtSlot(QDropEvent, QPoint)
    def on_treeWidget_useeq_droped(self, event, pos):
        event.ignore()
        if event.source() != self.treeWidget_eqlist:
            return
        items = self.treeWidget_eqlist.selectedItems()
        if not len(items):
            return
        for item in items:
            if item.text(2) == '0':
                continue
            condition = {'opid_id': self.opid, 'eqid_id': int(item.text(2))}
            self.LC.update_data(8, **condition)
        self.get_detail()

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        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()