class EditEquipDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditEquipDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '45' not in user.powers:
            self.close()
        if user.powers['45'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['45'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.EC = EquipmentController()
        self.ori_detail = dict()
        self.new_detail = dict()

        self.lineEdit_dept.setup('Department', RETURN_ROW_DEPT,
                                 CONDITION_KEY_DEPT, TREEHEADER_NAME_DEPT,
                                 None, 350, 190)
        self.lineEdit_maintainer.setup('Clerks', RETURN_ROW_MAINTAINER,
                                       CONDITION_KEY_MAINTAINER,
                                       TREEHEADER_NAME_MAINTAINER, None, 350,
                                       190)
        self.get_detail()
        self.get_check_detail()

    def get_detail(self):
        if self.autoid is None:
            return
        key_dict = {'autoid': self.autoid}
        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ, **key_dict)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.lineEdit_id.setText(self.ori_detail['eqno'])
        self.lineEdit_name.setText(self.ori_detail['eqname'])
        self.lineEdit_NO.setText(self.ori_detail['serialno'])
        self.lineEdit_spec.setText(self.ori_detail['spec'])
        self.lineEdit_price.setText(self.ori_detail['price'])
        self.lineEdit_producer.setText(self.ori_detail['manufacturer'])
        self.lineEdit_makedate.setText(self.ori_detail['makedate'])
        self.lineEdit_indate.setText(self.ori_detail['indate'])
        self.comboBox_type.setCurrentIndex(self.ori_detail['eqtype'])
        self.lineEdit_location.setText(self.ori_detail['instposition'])
        self.lineEdit_parameter.setText(self.ori_detail['parameter'])
        self.lineEdit_performance.setText(self.ori_detail['performance'])
        self.lineEdit_dept.setText(self.ori_detail['deptid'] + ' ' +
                                   self.ori_detail['deptname'])
        self.lineEdit_maintainer.setText(
            self.ori_detail['maintainerid'] + ' ' + \
            self.ori_detail['maintainername']
        )
        self.lineEdit_remark.setText(self.ori_detail['remark'])
        self.comboBox_status.setCurrentIndex(self.ori_detail['status'])

    def get_check_detail(self):
        self.treeWidget_checklist.clear()
        # self.treeWidget_checklist.hideColumn(0)
        if self.autoid is None:
            return
        key_dict = {'eqid': self.autoid}
        res = self.EC.get_data(2, False, *VALUES_TUPLE_EQCHECK, **key_dict)
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_checklist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STAUTS[item['status']])
            qtreeitem.setText(2, str(item['checkdate']))
            qtreeitem.setText(3, item['company'])
            qtreeitem.setText(4, item['result'])
            qtreeitem.setText(5,
                              item['registerid'] + ' ' + item['registername'])
        for i in range(1, 6):
            self.treeWidget_checklist.resizeColumnToContents(i)

    @pyqtSlot(str)
    def on_lineEdit_id_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['eqno']:
                self.new_detail['eqno'] = p_str
            else:
                try:
                    del self.new_detail['eqno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['eqno'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_name_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['eqname']:
                self.new_detail['eqname'] = p_str
            else:
                try:
                    del self.new_detail['eqname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['eqname'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_NO_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['serialno']:
                self.new_detail['serialno'] = p_str
            else:
                try:
                    del self.new_detail['serialno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['serialno'] = 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(str)
    def on_lineEdit_price_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['price']:
                self.new_detail['price'] = p_str
            else:
                try:
                    del self.new_detail['price']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['price'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_producer_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['manufacturer']:
                self.new_detail['manufacturer'] = p_str
            else:
                try:
                    del self.new_detail['manufacturer']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['manufacturer'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_makedate_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['makedate']:
                self.new_detail['makedate'] = p_str
            else:
                try:
                    del self.new_detail['makedate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['makedate'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_indate_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['indate']:
                self.new_detail['indate'] = p_str
            else:
                try:
                    del self.new_detail['indate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['indate'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_location_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['instposition']:
                self.new_detail['instposition'] = p_str
            else:
                try:
                    del self.new_detail['instposition']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['instposition'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_parameter_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['parameter']:
                self.new_detail['parameter'] = p_str
            else:
                try:
                    del self.new_detail['parameter']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['parameter'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_performance_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['performance']:
                self.new_detail['performance'] = p_str
            else:
                try:
                    del self.new_detail['performance']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['performance'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_dept_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['deptid'] or name != self.ori_detail[
                    'deptname']:
                self.new_detail['deptid'] = id
                self.new_detail['deptname'] = name
            else:
                try:
                    del self.new_detail['deptid']
                    del self.new_detail['deptname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['deptid'] = id
            self.new_detail['deptname'] = name

    @pyqtSlot(str)
    def on_lineEdit_maintainer_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['maintainerid'] or name != self.ori_detail[
                    'maintainername']:
                self.new_detail['maintainerid'] = id
                self.new_detail['maintainername'] = name
            else:
                try:
                    del self.new_detail['maintainerid']
                    del self.new_detail['maintainername']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['maintainerid'] = id
            self.new_detail['maintainername'] = name

    @pyqtSlot(str)
    def on_lineEdit_remark_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['remark']:
                self.new_detail['remark'] = p_str
            else:
                try:
                    del self.new_detail['remark']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['remark'] = p_str

    @pyqtSlot(int)
    def on_comboBox_type_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail['eqtype']:
                self.new_detail['eqtype'] = p_int
            else:
                try:
                    del self.new_detail['eqtype']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['eqtype'] = p_int

    @pyqtSlot(int)
    def on_comboBox_status_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail['status']:
                self.new_detail['status'] = p_int
            else:
                try:
                    del self.new_detail['status']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['status'] = p_int

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not self.autoid or 'eqno' in self.new_detail:
            eqno = self.lineEdit_id.text()
            key_dict = {'eqno': eqno}
            res = self.EC.get_data(0, True, 'autoid', **key_dict)
            if len(res):
                msg = MessageBox(self, text="设备编号重复")
                msg.show()
                return
        if len(self.new_detail):
            if self.autoid:
                condition = {'autoid': self.autoid}
                self.EC.update_data(0, condition, **self.new_detail)
            else:
                self.EC.update_data(0, **self.new_detail)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()

    @pyqtSlot(QPoint)
    def on_treeWidget_checklist_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("删除校验记录")
        menu.addSeparator()
        button4 = menu.addAction("提交完成")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            detail = EditEquCheckDetailModule(eqid=self.autoid, parent=self)
            detail.accepted.connect(self.get_check_detail)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            status = current_item.text(1)
            if status == "完成":
                return
            detail = EditEquCheckDetailModule(id, self.autoid, self)
            detail.accepted.connect(self.get_check_detail)
            detail.show()
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            print(id)
            condition = {'autoid': id}
            self.EC.delete_data(2, condition)
            self.get_check_detail()
        elif action == button4:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            detail = {'status': 1}
            self.EC.update_data(2, condition, **detail)
            self.get_check_detail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_checklist_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        id = int(qtreeitem.text(0))
        detail = EditEquCheckDetailModule(id, self.autoid, self)
        detail.accepted.connect(self.get_check_detail)
        detail.show()
Example #2
0
class EqRunListModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(EqRunListModule, self).__init__(parent)
        self.setupUi(self)
        if '46' not in user.powers:
            self.close()
        if user.powers['46'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['46'])

        self.EC = EquipmentController()
        self.deptid = ''
        self.eqtype = -1
        self.eqno = ''
        self.treeWidget_equuiplist.hideColumn(0)
        self.treeWidget_deptlist.hideColumn(1)
        self.treeWidget_recordslist.hideColumn(0)
        self.get_dept_detail()
        self.get_eq_detail()

    def get_eq_detail(self):
        self.treeWidget_equuiplist.clear()
        key_dict = dict()
        if self.deptid != '':
            key_dict['deptid'] = self.deptid
        if self.eqtype != -1:
            key_dict['eqtype'] = self.eqtype

        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_equuiplist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['eqno'])
            qtreeitem.setText(2, item['eqname'])
            qtreeitem.setText(3, item['instposition'])
        for i in range(1, 4):
            self.treeWidget_equuiplist.resizeColumnToContents(i)

    def get_dept_detail(self):
        self.treeWidget_deptlist.clear()
        all_dept = QTreeWidgetItem(self.treeWidget_deptlist)
        all_dept.setText(0, "全部部门")
        all_dept.setText(1, "")
        self.treeWidget_deptlist.expandAll()
        res = self.EC.get_data(0, False, *VALUES_TUPLE_DP).distinct()
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(all_dept)
            qtreeitem.setText(0, item['deptname'])
            qtreeitem.setText(1, item['deptid'])
        self.treeWidget_deptlist.resizeColumnToContents(0)

    def get_run_note(self):
        self.treeWidget_recordslist.clear()
        index = self.tabWidget.currentIndex()
        key_dict = {'eqno': self.eqno, 'status': index}
        res = self.EC.get_data(1, False, *VALUES_TUPLE_RUN, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_recordslist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(
                1,
                str(item['runstarttime'])
                if type(item['runstarttime']) is datetime.datetime else '')
            qtreeitem.setText(2, str(item['runtime']))
            qtreeitem.setText(3, item['fillerid'] + ' ' + item['fillername'])
            qtreeitem.setText(4, item['dictid'] + ' ' + item['dictname'])
            qtreeitem.setText(5, item['batchno'])
        for i in range(1, 6):
            self.treeWidget_recordslist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_equuiplist_itemDoubleClicked(self, qtreeitem, p_int):
        self.eqno = qtreeitem.text(1)
        self.get_run_note()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_deptlist_itemDoubleClicked(self, qtreeitem, p_int):
        self.deptid = qtreeitem.text(1)
        self.get_eq_detail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_equiplist_itemDoubleClicked(self, qtreeitem, p_int):
        self.eqid = qtreeitem.text(0)
        self.get_run_note()

    @pyqtSlot(int)
    def on_toolBox_currentChanged(self, p_int):
        current_tool = getattr(self, 'page_' + str(p_int))
        current_tool.setLayout(self.gridLayout_3)
        self.eqtype = p_int - 1
        self.get_eq_detail()

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        current_tool = getattr(self, 'tab_' + str(p_int))
        current_tool.setLayout(self.gridLayout_2)
        self.get_run_note()

    @pyqtSlot(QPoint)
    def on_treeWidget_recordslist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        index = self.tabWidget.currentIndex()
        menu = QMenu()
        button1 = menu.addAction("增加运行记录")
        button2 = menu.addAction("修改运行记录")
        button3 = menu.addAction("删除运行记录")
        menu.addSeparator()
        button4 = menu.addAction("提交完成")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            if self.eqno != '':
                detail = EqrunnoteModule(eqno=self.eqno,
                                         edit=False,
                                         parent=self)
                detail.accepted.connect(self.get_run_note)
                detail.show()
        elif action == button2:
            if current_item is not None and index == 0:
                id = int(current_item.text(0))
                detail = EqrunnoteModule(autoid=id, edit=False, parent=self)
                detail.accepted.connect(self.get_run_note)
                detail.show()
        elif action == button3:
            if current_item is not None:
                id = int(current_item.text(0))
                condition = {'autoid': id}
                self.EC.delete_data(1, condition)
                self.get_run_note()
        elif action == button4:
            if current_item is not None and index == 0:
                id = int(current_item.text(0))
                condition = {'autoid': id}
                kwargs = {'status': 1}
                self.EC.update_data(1, condition, **kwargs)
                self.get_run_note()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_recordslist_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = EqrunnoteModule(autoid=id, edit=False, parent=self)
        detail.accepted.connect(self.get_run_note)
        detail.show()
class EquipmentListModule(QDialog, Ui_Form):
    def __init__(self, parent=None):
        super(EquipmentListModule, self).__init__(parent)
        self.setupUi(self)
        if '45' not in user.powers:
            self.close()
        if user.powers['45'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['45'])
        self.EC = EquipmentController()
        self.ori_detail = dict()
        self.new_detail = dict()
        self.deptid = ''
        self.get_dept_detail()
        self.get_eq_detail()

    def get_eq_detail(self):
        self.treeWidget_equuiplist.clear()
        self.treeWidget_equuiplist.hideColumn(0)
        key_dict = dict()
        if self.deptid != '':
            key_dict['deptid'] = self.deptid
        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_equuiplist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, EQTYPE[item['eqtype']])
            qtreeitem.setText(2, STATUS[item['status']])
            qtreeitem.setText(3, item['eqno'])
            qtreeitem.setText(4, item['eqname'])
            qtreeitem.setText(5, item['serialno'])
            qtreeitem.setText(6, item['spec'])
            qtreeitem.setText(7, item['manufacturer'])
            qtreeitem.setText(8, item['makedate'])
            qtreeitem.setText(9, item['indate'])
            qtreeitem.setText(10, item['instposition'])
            qtreeitem.setText(11, item['parameter'])
            qtreeitem.setText(12, item['performance'])
        for i in range(1, 13):
            self.treeWidget_equuiplist.resizeColumnToContents(i)

    def get_dept_detail(self):
        self.treeWidget_deptlist.clear()
        self.treeWidget_deptlist.hideColumn(1)
        all_dept = QTreeWidgetItem(self.treeWidget_deptlist)
        all_dept.setText(0, "全部部门")
        all_dept.setText(1, "")
        self.treeWidget_deptlist.expandAll()
        res = self.EC.get_data(0, False, *VALUES_TUPLE_DP).distinct()
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(all_dept)
            qtreeitem.setText(0, item['deptname'])
            qtreeitem.setText(1, item['deptid'])
        self.treeWidget_deptlist.resizeColumnToContents(0)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_equuiplist_itemDoubleClicked(self, qtreeitem, p_int):
        autoid = int(qtreeitem.text(0))
        detail = EditEquipDetailModule(autoid, self)
        detail.accepted.connect(self.get_eq_detail)
        detail.accepted.connect(self.get_dept_detail)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_deptlist_itemDoubleClicked(self, qtreeitem, p_int):
        self.deptid = qtreeitem.text(1)
        self.get_eq_detail()

    @pyqtSlot(QPoint)
    def on_treeWidget_equuiplist_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 = EditEquipDetailModule(parent=self)
            detail.accepted.connect(self.get_eq_detail)
            detail.accepted.connect(self.get_dept_detail)
            detail.show()
        elif action == button2:
            if current_item is not None:
                id = int(current_item.text(0))
                detail = EditEquipDetailModule(id, self)
                detail.accepted.connect(self.get_eq_detail)
                detail.accepted.connect(self.get_dept_detail)
                detail.show()
        elif action == button3:
            if current_item is not None:
                id = int(current_item.text(0))
                condition = {'autoid': id}
                self.EC.delete_data(0, condition)
                self.get_eq_detail()
                self.get_dept_detail()
Example #4
0
class EqGeneralRecorsListModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(EqGeneralRecorsListModule, 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'])

        self.EC = EquipmentController()
        self.SC = SelfdefinedformatController()
        self.deptid = ''
        self.eqtype = -1
        self.eqno = ''

        self.treeWidget_equuiplist.hideColumn(0)
        self.treeWidget_deptlist.hideColumn(1)
        self.treeWidget_recordslist.hideColumn(0)
        self.get_dept_detail()
        self.get_eq_detail()

    def get_eq_detail(self):
        self.treeWidget_equuiplist.clear()
        key_dict = dict()
        if self.deptid != '':
            key_dict['deptid'] = self.deptid
        if self.eqtype != -1:
            key_dict['eqtype'] = self.eqtype

        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_equuiplist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['eqno'])
            qtreeitem.setText(2, item['eqname'])
            qtreeitem.setText(3, item['instposition'])
        for i in range(1, 4):
            self.treeWidget_equuiplist.resizeColumnToContents(i)

    def get_dept_detail(self):
        self.treeWidget_deptlist.clear()
        all_dept = QTreeWidgetItem(self.treeWidget_deptlist)
        all_dept.setText(0, "全部部门")
        all_dept.setText(1, "")
        self.treeWidget_deptlist.expandAll()
        res = self.EC.get_data(0, False, *VALUES_TUPLE_DP).distinct()
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(all_dept)
            qtreeitem.setText(0, item['deptname'])
            qtreeitem.setText(1, item['deptid'])
        self.treeWidget_deptlist.resizeColumnToContents(0)

    def get_generalrecors_note(self):
        self.treeWidget_recordslist.clear()
        index = self.tabWidget.currentIndex()
        key_dict = {
            'eqno': self.eqno,
            'status': index,
        }
        res = self.EC.get_data(5, False, *VALUES_TUPLE_RECORDS, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_recordslist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['formname'])
            qtreeitem.setText(
                2, item['createtime'].strftime('%Y-%m-%d %H:%M')
                if type(item['createtime']) is datetime.datetime else '')
            qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname'])
        for i in range(1, 4):
            self.treeWidget_recordslist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_equuiplist_itemDoubleClicked(self, qtreeitem, p_int):
        self.eqno = qtreeitem.text(1)
        self.get_generalrecors_note()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_deptlist_itemDoubleClicked(self, qtreeitem, p_int):
        self.deptid = qtreeitem.text(1)
        self.get_eq_detail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_equiplist_itemDoubleClicked(self, qtreeitem, p_int):
        self.eqid = qtreeitem.text(0)
        self.get_generalrecors_note()

    @pyqtSlot(int)
    def on_toolBox_currentChanged(self, p_int):
        current_tool = getattr(self, 'page_' + str(p_int))
        current_tool.setLayout(self.gridLayout_3)
        self.eqtype = p_int - 1
        self.get_eq_detail()

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        current_tool = getattr(self, 'tab_' + str(p_int))
        current_tool.setLayout(self.gridLayout_2)
        self.get_generalrecors_note()

    @pyqtSlot(QPoint)
    def on_treeWidget_recordslist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        index = self.tabWidget.currentIndex()
        menu = QMenu()
        button1 = menu.addAction("增加一般记录")
        button2 = menu.addAction("修改一般记录")
        button3 = menu.addAction("删除一般记录")
        menu.addSeparator()
        button4 = menu.addAction("提交完成")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            if self.eqno != '':
                detail = SelectGeneralRecordsModule(self)
                detail.accepted.connect(self.get_generalrecors_note)
                detail.selected.connect(self.new_general_records)
                detail.show()
        elif action == button2:
            if current_item is not None and index == 0:
                id = int(current_item.text(0))
                detail = GeneralRecordModule(id, self)
                detail.accepted.connect(self.get_generalrecors_note)
                detail.show()
        elif action == button3:
            if current_item is not None:
                id = int(current_item.text(0))
                condition = {'autoid': id}
                self.EC.delete_data(5, condition)
                self.get_generalrecors_note()
        elif action == button4:
            if current_item is not None and index == 0:
                id = int(current_item.text(0))
                condition = {'autoid': id}
                kwargs = {'status': 1}
                self.EC.update_data(5, condition, **kwargs)
                self.get_generalrecors_note()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_recordslist_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = GeneralRecordModule(id, self)
        detail.accepted.connect(self.get_generalrecors_note)
        detail.show()

    def new_general_records(self, id_tuple):
        if len(id_tuple) == 0:
            return
        else:
            key_dict = dict()
            key_dict['autoid__in'] = id_tuple
            res = self.SC.get_selfdefinedformat(False, *VALUES_TUPLE_SD,
                                                **key_dict)
            for item in res:
                kwargs = {
                    'eqno': self.eqno,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'formname': item['formatname'],
                    'kind': item['kind'],
                    'subkind': item['subkind'],
                    'format': item['format'],
                    'createtime': user.now_time
                }
                self.EC.update_data(5, **kwargs)
class LabrecordsController(object):
    def __init__(self):
        self.SFC = SelfdefinedformatController()
        self.EC = EquipmentController()
        self.SC = StuffController()
        self.PC = ProductController()

    def get_labrecord(self, flag=False, *args, **kwargs):
        return LabModel.get_labrecord(flag, *args, **kwargs)

    def get_labitem(self, flag=False, *args, **kwargs):
        return LabModel.get_labitem(flag, *args, **kwargs)

    def get_labimages(self, flag=False, kind=2, scid=0):
        values_list_rela = [
            'autoid', 'title', 'imageid', 'creatorid', 'creatorname',
            'createdate'
        ]
        key_dict_rela = {'kind': kind, 'scid': scid}
        res = ImagesModel.get_rela(flag, *values_list_rela, **key_dict_rela)
        if not len(res):
            return []
        img_list = []
        for item in res:
            img_list.append(item['imageid'])
        values_list_img = ['autoid', 'img', 'ext']
        key_dict_img = {'autoid__in': img_list}
        image_list = ImagesModel.get_img(flag, *values_list_img,
                                         **key_dict_img)
        for it in res:
            for value in image_list:
                if it['imageid'] == value['autoid']:
                    it.update({'image': value['img'], 'ext': value['ext']})
                    break
        return res

    def select_oricheckpaper(self, dictid, itemtype=0):
        if not dictid:
            return []
        if itemtype in (0, 1, 2):
            condition = {'stuffid': dictid}
            res = self.SC.get_data(0, True, *VALUES_TUPLE_ID, **condition)
            if not len(res):
                return []
            id = res[0]
        elif itemtype in (3, 4, 5, 6):
            condition = {'prodid': dictid}
            res = self.PC.get_data(1, True, *VALUES_TUPLE_ID, **condition)
            if not len(res):
                return []
            id = res[0]
        else:
            id = int(dictid)
        key_dict = {'dictid': id, 'itemtype': itemtype}
        sdfid_list = LabModel.get_oricheckpapersetting(True, *VALUES_TUPLE_SD,
                                                       **key_dict)
        if len(sdfid_list):
            values_list_sdf = ['autoid', 'kind', 'formatname']
            key_dict_sdf = {'autoid__in': sdfid_list}
            return self.SFC.get_selfdefinedformat(False, *values_list_sdf,
                                                  **key_dict_sdf)
        else:
            return []

    def get_selfdefineformat(self, flag=False, *args, **kwargs):
        return self.SFC.get_selfdefinedformat(False, *args, **kwargs)

    def get_oricheckpaper(self, flag=False, *args, **kwargs):
        return LabModel.get_oricheckpaper(flag, *args, **kwargs)

    def get_paperno(self, lrid):
        return LabModel.get_paperno(lrid)

    def update_labrecord(self, autoid=0, *args, **kwargs):
        return LabModel.update_labrecord(autoid, *args, **kwargs)

    def delete_labrecord(self, autoid=0, *args, **kwargs):
        return LabModel.delete_labrecord(autoid, *args, **kwargs)

    def update_labitem(self, autoid=0, *args, **kwargs):
        return LabModel.update_labitem(autoid, *args, **kwargs)

    def delete_labitem(self, autoid=0, *args, **kwargs):
        return LabModel.delete_labitem(autoid, *args, **kwargs)

    def update_labimages(self, relakwargs, imgkwargs, relaid=0, imgid=0):
        return ImagesModel.update_img(relakwargs, imgkwargs, relaid, imgid)

    def create_oricheckpaper(self, opid, op_detail, sdfid, sdf_detail):
        with transaction.atomic():
            p1 = transaction.savepoint()
            condition = {'autoid': sdfid}
            res = self.SFC.get_data(0, False, *VALUES_TUPLE_SDF, **condition)
            if not len(res):
                transaction.savepoint_rollback(p1)
                return False
            sdf_data = {
                'formname': res[0]['formatname'],
                'formcontent': res[0]['format']
            }
            sdf_data.update(sdf_detail)
            oripaper = self.update_data(2, **sdf_data)
            condition_2 = {'opid_id': opid}
            res_2 = self.get_data(8, False, **condition_2)
            for item in res_2:
                eqrun_data = {
                    'eqno': item.eqid.eqno,
                    'rtype': 1,
                    'pid': oripaper.autoid
                }
                eqrun_data.update(op_detail)
                self.EC.update_data(1, **eqrun_data)
            return oripaper

    def delete_labimages(self, relaid, imgid):
        return ImagesModel.delete_img(relaid, imgid)

    def delete_oricheckpaper(self, id):
        with transaction.atomic():
            p1 = transaction.savepoint()
            condition = {'autoid': id}
            self.delete_data(2, **condition)
            condition_eqrun = {'pid': id, 'rtype': 1}
            self.EC.delete_data(1, **condition_eqrun)
            return True

    def get_data(self, table_num: int, display_flag=False, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "查询" + TABLE_SET[table_num][1]
        return LabModel.get_data(table_str, err_msg, display_flag, *args,
                                 **kwargs)

    def update_data(self, table_num: int, condition={}, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "更新" + TABLE_SET[table_num][1]
        return LabModel.update_data(table_str, err_msg, condition, *args,
                                    **kwargs)

    def delete_data(self, table_num: int, condition={}, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "删除" + TABLE_SET[table_num][1]
        return LabModel.delete_data(table_str, err_msg, condition, *args,
                                    **kwargs)

    def create_labrecord(self, checkitem_id, itemtype, date, *args, **kwargs):
        with transaction.atomic():
            p1 = transaction.savepoint()

            new_labrecor = self.update_data(0, **kwargs)
            lrid = new_labrecor.autoid
            key_dict_checkitem = {
                'stuffid': checkitem_id,
                'itemtype': itemtype
            }
            checkitems = self.get_data(4, False, *VALUES_TUPLE_CHECKITEM,
                                       **key_dict_checkitem)
            for item in checkitems:
                kwargs_checkitem = {
                    'lrid': lrid,
                    'seqid': item['seqid'],
                    'itemname': item['itemname'],
                    'kind': item['kind'],
                    'referencevalue': item['referencevalue'],
                    'labvalue': item['referencevalue'],
                    'putintype': item['putintype'],
                    'startdate': date,
                    'enddate': date,
                    'checked': 2
                }
                self.update_data(1, **kwargs_checkitem)
            return lrid

    def delete_labrecord_and_detail(self, lrid=0, *args, **kwargs):
        with transaction.atomic():
            p1 = transaction.savepoint()
            if lrid != 0:
                condition_lr = {'autoid': lrid}
                condition_detail = {'autoid': lrid}
            else:
                condition_lr = {'autoid__in': args}
                condition_detail = {'autoid__in': args}
            self.delete_data(0, condition_lr)
            self.delete_data(1, condition_detail)
            self.delete_data(2, condition_detail)

    def delete_sample_record(self, srid):
        with transaction.atomic():
            p1 = transaction.savepoint()
            condition = {'srid_id': srid}
            lrid_list = self.get_data(7, False, **condition).extra(
                select={
                    'lrid': 'Labrecords.autoid'
                },
                tables=['Labrecords'],
                where=[
                    'Labrecords.ciid=Observationrecords.autoid',
                    'Labrecords.labtype=6'
                ]).values_list(*VALUES_TUPLE_OB, flat=True)
            if len(lrid_list):
                self.delete_labrecord_and_detail(*lrid_list)
            condition = {'autoid': srid}
            self.delete_data(6, condition)