class GeneralRecordModule(QDialog, Ui_Dialog):
    edited = pyqtSignal(int)

    def __init__(self, autoid, parent=None):
        super(GeneralRecordModule, self).__init__(parent)
        self.setupUi(self)
        if '50' not in user.powers:
            self.close()
        if user.powers['50'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['50'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.ori_detail = dict()
        self.autoid = autoid
        self.EC = EquipmentController()
        self.current_content = object

        # 获取记录内容
        self.get_general_record()

    def get_general_record(self):
        values_list = ('formname', 'format')
        key_dict = {'autoid': self.autoid}
        res = self.EC.get_data(5, False, *values_list, **key_dict)
        if len(res):
            self.label_formname.setText(res[0]['formname'])
            ori_paper = res[0]['format']
            self.current_content = XMLReadWrite(self)
            self.current_content.openxml(ori_paper)
            self.gridLayout_6.addWidget(self.current_content)
            self.current_content.__setattr__('autoid', self.autoid)

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        condition = {'autoid': self.autoid}
        kwargs = {'formcontent': self.current_content.get_content()}
        res = self.EC.update_data(5, condition, **kwargs)
        if res:
            self.current_content.flat = 0
            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.current_content.flat = 0
        self.close()
class 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()
Beispiel #3
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()
Beispiel #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 EditEquCheckDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, eqid=0, parent=None):
        super(EditEquCheckDetailModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid = autoid
        self.eqid = eqid
        self.EC = EquipmentController()
        self.ori_detail = dict()
        self.new_detail = dict()

        self.get_detail()
        self.get_company_items()

    def get_detail(self):
        if self.autoid is None:
            self.dateEdit_checkdate.setDate(user.now_date)
            return
        key_dict = {'autoid': self.autoid}
        res = self.EC.get_data(2, False, *VALUES_TUPLE_EQCHECK, **key_dict)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.dateEdit_checkdate.setDate(self.ori_detail['checkdate'])
        self.lineEdit_result.setText(self.ori_detail['result'])

    def get_company_items(self):
        items = self.EC.get_data(2, True, *VALUES_TUPLE_COMPANY).distinct()
        self.comboBox_company.addItems(items)
        if len(self.ori_detail):
            self.comboBox_company.setCurrentText(self.ori_detail['company'])
        else:
            self.comboBox_company.setCurrentText('')

    @pyqtSlot(QDate)
    def on_dateEdit_checkdate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['checkdate']) is str:
                self.new_detail['checkdate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['checkdate']):
                self.new_detail['checkdate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['checkdate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['checkdate'] = q_date.toPyDate()

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

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

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if len(self.new_detail):
            self.new_detail['registerid'] = user.user_id
            self.new_detail['registername'] = user.user_name
            if self.autoid:
                condition = {'autoid': self.autoid}
                self.EC.update_data(2, condition, **self.new_detail)
            else:
                self.new_detail['eqid'] = self.eqid
                self.EC.update_data(2, **self.new_detail)
        self.accept()

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

    @pyqtSlot()
    def on_pushButton_apply_clicked(self):
        self.new_detail['status'] = 1
        self.new_detail['registerid'] = user.user_id
        self.new_detail['registername'] = user.user_name
        if self.autoid:
            condition = {'autoid': self.autoid}
            self.EC.update_data(2, condition, **self.new_detail)
        else:
            self.new_detail['eqid'] = self.eqid
            self.EC.update_data(2, **self.new_detail)
        self.accept()
class EqrunnoteModule(QDialog, Ui_Dialog):
    def __init__(self,
                 autoid=None,
                 eqno='',
                 status=0,
                 starttime=user.currentdatetime,
                 endtime=user.currentdatetime,
                 edit=False,
                 parent=None):
        super(EqrunnoteModule, self).__init__(parent)
        self.setupUi(self)
        if edit:
            self.power = '111'
        else:
            if '46' in user.powers:
                self.close()
            if user.powers['46'] == 0:
                self.close()
            self.power = '{:03b}'.format(user.powers['46'])
            if self.power[1] == '0':
                self.pushButton_accept.setVisible(False)
                self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.starttime = starttime
        self.endtime = endtime
        self.eqno = eqno
        self.status = status

        self.maintenance = bin(0)
        self.ori_detail = object
        self.new_detail = {}
        self.EC = EquipmentController()
        # 获取记录详细内容
        self.get_eq_run_note_detail(autoid)
        reg = QRegExp('^[0-9]+$')
        self.lineEdit_runtime_day.setValidator(QRegExpValidator(reg))
        self.lineEdit_runtime_hour.setValidator(QRegExpValidator(reg))
        self.lineEdit_runtime_minute.setValidator(QRegExpValidator(reg))

    # 获取详细运行记录
    def get_eq_run_note_detail(self, autoid):
        if self.autoid is None:
            self.dateTimeEdit_runstarttime.setDateTime(QDateTime(user.time))
            self.dateTimeEdit_runendtime.setDateTime(QDateTime(user.time))
            return
        key_dict = {'autoid': autoid}
        res = self.EC.get_data(1, False, **key_dict).extra(
            select={'eqname': 'equipments.eqname'},
            tables=['equipments'],
            where=['equipments.eqno=eqrunnotes.eqno'])
        if len(res):
            self.ori_detail = res[0]
            self.label_equipment.setText(self.ori_detail.eqno + ' ' +
                                         self.ori_detail.eqname)
            self.lineEdit_product.setText(self.ori_detail.dictid + ' ' +
                                          self.ori_detail.dictname)
            self.lineEdit_batchno.setText(self.ori_detail.batchno)
            if type(self.ori_detail.runstarttime) is datetime.datetime:
                self.dateTimeEdit_runstarttime.setDateTime(
                    self.ori_detail.runstarttime)
            else:
                self.dateTimeEdit_runstarttime.setDateTime(self.starttime())
            if type(self.ori_detail.runendtime) is datetime.datetime:
                self.dateTimeEdit_runendtime.setDateTime(
                    self.ori_detail.runendtime)
            else:
                self.dateTimeEdit_runendtime.setDateTime(self.endtime())
            self.set_runtime(self.ori_detail.runtime)
            self.comboBox_runstatus.setCurrentIndex(
                int(self.ori_detail.runstatus))
            self.lineEdit_remark.setText(self.ori_detail.remark)
            if self.ori_detail.fillerid and self.ori_detail.fillername:
                self.pushButton_filler.setText(self.ori_detail.fillerid + ' ' +
                                               self.ori_detail.fillername)
            self.comboBox_startstatus.setCurrentIndex(
                int(self.ori_detail.startstatus))
            self.comboBox_stopstatus.setCurrentIndex(
                int(self.ori_detail.stopstatus))
            self.maintenance = self.ori_detail.maintenance
            bin_list = bin(self.ori_detail.maintenance)[2:]
            for i in range(1, len(bin(self.ori_detail.maintenance)[2:]) + 1):
                try:
                    getattr(self,
                            "checkBox_" + str(i)).setChecked(int(bin_list[-i]))
                except IndexError:
                    break
            if self.ori_detail.status == 1:
                self.pushButton_accept.setVisible(False)
                self.pushButton_cancel.setVisible(False)

    # 修改开始运行时间
    @pyqtSlot(QDateTime)
    def on_dateTimeEdit_runstarttime_dateTimeChanged(self, q_time):

        if not q_time.isValid():
            return
        qdtime = q_time.toPyDateTime().strftime('%Y-%m-%d %H:%M')
        try:
            if qdtime != self.ori_detail.runstarttime.\
                    strftime('%Y-%m-%d %H:%M'):
                self.new_detail['runstarttime'] = qdtime
                #'yyyy-MM-dd hh:mm:ss')

            else:
                try:
                    del self.new_detail['runstarttime']
                except KeyError:
                    pass
        except AttributeError:
            self.new_detail['runstarttime'] = qdtime
        runtime = int(
            (self.dateTimeEdit_runendtime.dateTime().toSecsSinceEpoch() -
             q_time.toSecsSinceEpoch()) / 60)
        self.set_runtime(runtime)
        self.new_detail['runtime'] = runtime

    # 修改结束运行时间
    @pyqtSlot(QDateTime)
    def on_dateTimeEdit_runendtime_dateTimeChanged(self, q_time):
        if not q_time.isValid():
            return
        qdtime = q_time.toPyDateTime().strftime('%Y-%m-%d %H:%M')
        try:
            if qdtime != self.ori_detail.runendtime.strftime('%Y-%m-%d %H:%M'):
                self.new_detail['runendtime'] = qdtime

            else:
                try:
                    del self.new_detail['runendtime']
                except KeyError:
                    pass
        except AttributeError:
            self.new_detail['runendtime'] = qdtime
        runtime = int(
            (q_time.toSecsSinceEpoch() -
             self.dateTimeEdit_runstarttime.dateTime().toSecsSinceEpoch()) /
            60)
        self.set_runtime(runtime)
        self.new_detail['runtime'] = runtime

    # 修改运行时长-day
    @pyqtSlot(str)
    def on_lineEdit_runtime_day_textEdited(self, p_str):
        self.modify_runtime()

    # 修改运行时长-hour
    @pyqtSlot(str)
    def on_lineEdit_runtime_hour_textEdited(self, p_str):
        self.modify_runtime()

    # 修改运行时长-minute
    @pyqtSlot(str)
    def on_lineEdit_runtime_minute_textEdited(self, p_str):
        self.modify_runtime()

    # 修改运行时长
    def modify_runtime(self):
        day = int(self.lineEdit_runtime_day.text()
                  ) if self.lineEdit_runtime_day.text() else 0
        hour = int(self.lineEdit_runtime_hour.text()
                   ) if self.lineEdit_runtime_hour.text() else 0
        minute = int(self.lineEdit_runtime_minute.text()
                     ) if self.lineEdit_runtime_minute.text() else 0

        try:
            runtime = day * 86400 + hour * 3600 + minute * 60
            if runtime != self.ori_detail.runtime:
                self.new_detail['runtime'] = runtime
            else:
                try:
                    del self.new_detail['runtime']
                except KeyError:
                    pass
            self.dateTimeEdit_runendtime.setDateTime(
                QDateTime.fromSecsSinceEpoch(self.dateTimeEdit_runstarttime.
                                             dateTime().toSecsSinceEpoch() +
                                             runtime))
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['runtime'] = runtime

    # 修改运行情况
    @pyqtSlot(int)
    def on_comboBox_runstatus_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail.runstatus:
                self.new_detail['runstatus'] = p_int
            else:
                try:
                    del self.new_detail['runstatus']
                except KeyError:
                    pass
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['runstatus'] = p_int

    # 修改开机准备
    @pyqtSlot(int)
    def on_comboBox_startstatus_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail.startstatus:
                self.new_detail['startstatus'] = p_int
            else:
                try:
                    del self.new_detail['startstatus']
                except KeyError:
                    pass
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['startstatus'] = p_int

    # 修改停机保养
    @pyqtSlot(int)
    def on_comboBox_stopstatus_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail.stopstatus:
                self.new_detail['stopstatus'] = p_int
            else:
                try:
                    del self.new_detail['stopstatus']
                except KeyError:
                    pass
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['stopstatus'] = p_int

    # 修改备注
    @pyqtSlot(str)
    def on_lineEdit_remark_textEdited(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 ValueError:
            pass
        except AttributeError:
            self.new_detail['remark'] = p_str

    # 修改填写人
    @pyqtSlot(bool, str)
    def on_pushButton_filler_signChanged(self, p_bool, p_str):
        try:
            fillerid, fillername = p_str.split(' ') if p_bool else ('', '')
            if fillerid != self.ori_detail.fillerid and fillername != self.ori_detail.fillername:
                self.new_detail['fillerid'] = fillerid
                self.new_detail['fillername'] = fillername
            else:
                try:
                    del self.new_detail['fillerid']
                    del self.new_detail['fillername']
                except KeyError:
                    pass
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['fillerid'] = fillerid
            self.new_detail['fillername'] = fillername

    @pyqtSlot(bool)
    def on_checkBox_1_clicked(self, p_int):
        self.set_maintenance(1, p_int)

    @pyqtSlot(bool)
    def on_checkBox_2_clicked(self, p_int):
        self.set_maintenance(2, p_int)

    @pyqtSlot(bool)
    def on_checkBox_3_clicked(self, p_int):
        self.set_maintenance(3, p_int)

    @pyqtSlot(bool)
    def on_checkBox_4_clicked(self, p_int):
        self.set_maintenance(4, p_int)

    @pyqtSlot(bool)
    def on_checkBox_5_clicked(self, p_int):
        self.set_maintenance(5, p_int)

    @pyqtSlot(bool)
    def on_checkBox_6_clicked(self, p_int):
        self.set_maintenance(6, p_int)

    @pyqtSlot(bool)
    def on_checkBox_7_clicked(self, p_int):
        self.set_maintenance(7, p_int)

    @pyqtSlot(bool)
    def on_checkBox_8_clicked(self, p_int):
        self.set_maintenance(8, p_int)

    @pyqtSlot(bool)
    def on_checkBox_9_clicked(self, p_int):
        self.set_maintenance(9, p_int)

    @pyqtSlot(bool)
    def on_checkBox_10_clicked(self, p_int):
        self.set_maintenance(10, p_int)

    # 设置设备状态
    # pos:第几个位置
    # status:该位置的值
    def set_maintenance(self, pos, status):
        values = 2**(pos - 1) * (1 if status else -1)
        self.maintenance += values
        try:
            if self.maintenance != self.ori_detail.maintenance:
                self.new_detail['maintenance'] = self.maintenance
            else:
                try:
                    del self.new_detail['maintenance']
                except KeyError:
                    pass
        except ValueError:
            pass
        except AttributeError:
            self.new_detail['maintenance'] = self.maintenance

    # 确认
    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        print(self.new_detail)
        if len(self.new_detail):
            if self.autoid is None:
                self.new_detail['eqno'] = self.eqno
                self.new_detail['status'] = self.status
                self.EC.update_data(1, **self.new_detail)
            else:
                condition = {'autoid': self.autoid}
                self.EC.update_data(1, condition, **self.new_detail)
        self.accept()

    # 取消
    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()

    # 把整数转为天-时-分
    def set_runtime(self, p_int: int):

        day = int(p_int / 1440)
        hour = (p_int % 1440 // 60) if p_int > 0 else int(p_int % -1440 / 60)
        minute = p_int % (60 if p_int > 0 else -60)
        self.lineEdit_runtime_day.setText(str(day))
        self.lineEdit_runtime_hour.setText(str(hour))
        self.lineEdit_runtime_minute.setText(str(minute))
Beispiel #7
0
class AccidentModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, eqno=None, parent=None):
        super(AccidentModule, self).__init__(parent)
        self.setupUi(self)
        if '49' not in user.powers:
            self.close()
        if user.powers['49'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['49'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.eqno = eqno
        self.ori_detail = dict()
        self.new_detail = dict()
        self.EC = EquipmentController()
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            self.dateTimeEdit_occurdate.setDateTime(user.time)
            self.dateEdit_filldate.setDate(user.now_date)
            if self.eqno is not None:
                key_dict = {'eqno': self.eqno}
                res = self.EC.get_data(0, True, *VALUES_TUPLE_EQ, **key_dict)
                if len(res):
                    self.label_eqno.setText(self.eqno)
                    self.label_eqname.setText(res[0])
            return
        key_dict = {'autoid': self.autoid}
        res = self.EC.get_data(4, False, **key_dict).extra(
            select={
                'eqname': 'equipments.eqname'
            },
            tables=['equipments'],
            where=['equipments.eqno=eqaccidentnotes.eqno'
                   ]).values(*VALUES_TUPLE_NOTE)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.label_eqno.setText(self.ori_detail['eqno'])
        self.label_eqname.setText(self.ori_detail['eqname'])
        self.lineEdit_place.setText(self.ori_detail['place'])
        self.dateTimeEdit_occurdate.setDateTime(self.ori_detail['occurdate'])
        self.lineEdit_factormen.setText(self.ori_detail['factormen'])
        self.lineEdit_kind.setText(self.ori_detail['kind'])
        self.lineEdit_injury.setText(self.ori_detail['injury'])
        self.plainTextEdit_brief.setPlainText(self.ori_detail['brief'])
        self.plainTextEdit_reason.setPlainText(self.ori_detail['reason'])
        self.plainTextEdit_loss.setPlainText(self.ori_detail['loss'])
        self.plainTextEdit_treatadvice.setPlainText(
            self.ori_detail['treatadvice'])
        self.plainTextEdit_chargeradvice.setPlainText(
            self.ori_detail['chargeradvice'])
        self.pushButton_filler.setSign(
            True,
            self.ori_detail['fillerid'] + ' ' + self.ori_detail['fillername'])
        self.dateEdit_filldate.setDate(self.ori_detail['filldate'])
        if self.ori_detail['status'] == 1:
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)

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

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

    @pyqtSlot()
    def on_plainTextEdit_brief_textChanged(self):
        p_str = self.plainTextEdit_brief.toPlainText()
        try:
            if p_str != self.ori_detail['brief']:
                self.new_detail['brief'] = p_str
            else:
                try:
                    del self.new_detail['brief']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['brief'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_reason_textChanged(self):
        p_str = self.plainTextEdit_reason.toPlainText()
        try:
            if p_str != self.ori_detail['reason']:
                self.new_detail['reason'] = p_str
            else:
                try:
                    del self.new_detail['reason']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['reason'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_loss_textChanged(self):
        p_str = self.plainTextEdit_loss.toPlainText()
        try:
            if p_str != self.ori_detail['loss']:
                self.new_detail['loss'] = p_str
            else:
                try:
                    del self.new_detail['loss']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['loss'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_treatadvice_textChanged(self):
        p_str = self.plainTextEdit_loss.toPlainText()
        try:
            if p_str != self.ori_detail['treatadvice']:
                self.new_detail['treatadvice'] = p_str
            else:
                try:
                    del self.new_detail['treatadvice']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['treatadvice'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_chargeradvice_textChanged(self):
        p_str = self.plainTextEdit_loss.toPlainText()
        try:
            if p_str != self.ori_detail['chargeradvice']:
                self.new_detail['chargeradvice'] = p_str
            else:
                try:
                    del self.new_detail['chargeradvice']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['chargeradvice'] = p_str

    @pyqtSlot(bool, str)
    def on_pushButton_filler_signChanged(self, p_bool, p_str):
        id, name = p_str.split(' ') if p_bool else ('', '')
        try:
            if id != self.ori_detail['fillerid'] or name != self.ori_detail[
                    'fillername']:
                self.new_detail['fillerid'] = id
                self.new_detail['fillername'] = name
            else:
                try:
                    del self.new_detail['fillerid']
                    del self.new_detail['fillername']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['fillerid'] = id
            self.new_detail['fillername'] = name

    @pyqtSlot(QDate)
    def on_dateEdit_filldate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['filldate']) is str:
                self.new_detail['filldate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['filldate']):
                self.new_detail['filldate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['filldate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['filldate'] = q_date.toPyDate()

    @pyqtSlot(QDateTime)
    def on_dateTimeEdit_occurdate_dateTimeChanged(self, q_time):
        if not q_time.isValid():
            return
        qdtime = q_time.toPyDateTime().strftime('%Y-%m-%d %H:%M')
        try:
            if qdtime != self.ori_detail['occurdate'].\
                    strftime('%Y-%m-%d %H:%M'):
                self.new_detail['occurdate'] = qdtime
            else:
                try:
                    del self.new_detail['occurdate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['occurdate'] = qdtime

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        condition = dict()
        if len(self.new_detail):
            if self.autoid is None:
                self.new_detail['eqno'] = self.eqno
            else:
                condition['autoid'] = self.autoid
            self.EC.update_data(4, condition, **self.new_detail)
        self.accept()

    pyqtSlot()

    def on_pushButton_cancel_clicked(self):
        self.close()
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)
Beispiel #9
0
class RepairedModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, eqno=None, parent=None):
        super(RepairedModule, self).__init__(parent)
        self.setupUi(self)
        if '48' not in user.powers:
            self.close()
        if user.powers['48'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['48'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.eqno = eqno
        self.ori_detail = dict()
        self.new_detail = dict()
        self.EC = EquipmentController()
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            self.dateEdit_finishdate.setDate(user.now_date)
            if self.eqno is not None:
                key_dict = {'eqno': self.eqno}
                res = self.EC.get_data(0, True, *VALUES_TUPLE_EQ, **key_dict)
                if len(res):
                    self.label_eqno.setText(self.eqno)
                    self.label_eqname.setText(res[0])
            return
        key_dict = {'autoid': self.autoid, 'kind': 0}
        res = self.EC.get_data(3, False, **key_dict).extra(
            select={
                'eqname': 'equipments.eqname'
            },
            tables=['equipments'],
            where=['equipments.eqno=eqrepairnotes.eqno'
                   ]).values(*VALUES_TUPLE_NOTE)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.label_eqno.setText(self.ori_detail['eqno'])
        self.label_eqname.setText(self.ori_detail['eqname'])
        self.lineEdit_mainpoint.setText(self.ori_detail['mainpoint'])
        self.plainTextEdit_repaired.setPlainText(
            self.ori_detail['partrepairing'])
        self.plainTextEdit_part.setPlainText(self.ori_detail['partreplacing'])
        self.plainTextEdit_running.setPlainText(self.ori_detail['testrunning'])
        self.pushButton_repairer.setSign(
            True, self.ori_detail['repairerid'] + ' ' +
            self.ori_detail['repairername'])
        self.dateEdit_finishdate.setDate(self.ori_detail['finishdate'])

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

    @pyqtSlot()
    def on_plainTextEdit_repaired_textChanged(self):
        p_str = self.plainTextEdit_repaired.toPlainText()
        try:
            if p_str != self.ori_detail['partrepairing']:
                self.new_detail['partrepairing'] = p_str
            else:
                try:
                    del self.new_detail['partrepairing']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['partrepairing'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_part_textChanged(self):
        p_str = self.plainTextEdit_part.toPlainText()
        try:
            if p_str != self.ori_detail['partreplacing']:
                self.new_detail['partreplacing'] = p_str
            else:
                try:
                    del self.new_detail['partreplacing']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['partreplacing'] = p_str

    @pyqtSlot()
    def on_plainTextEdit_running_textChanged(self):
        p_str = self.plainTextEdit_running.toPlainText()
        try:
            if p_str != self.ori_detail['testrunning']:
                self.new_detail['testrunning'] = p_str
            else:
                try:
                    del self.new_detail['testrunning']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['testrunning'] = p_str

    @pyqtSlot(bool, str)
    def on_pushButton_repairer_signChanged(self, p_bool, p_str):
        id, name = p_str.split(' ') if p_bool else ('', '')
        try:
            if id != self.ori_detail['repairerid'] or name != self.ori_detail[
                    'repairername']:
                self.new_detail['repairerid'] = id
                self.new_detail['repairername'] = name
            else:
                try:
                    del self.new_detail['repairerid']
                    del self.new_detail['repairername']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['repairerid'] = id
            self.new_detail['repairername'] = name

    @pyqtSlot(QDate)
    def on_dateEdit_finishdate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['finishdate']) is str:
                self.new_detail['finishdate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['finishdate']):
                self.new_detail['finishdate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['finishdate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['finishdate'] = q_date.toPyDate()

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if len(self.new_detail):
            if self.autoid is None:
                self.new_detail['eqno'] = self.eqno
                self.new_detail['kind'] = 0
            self.EC.update_data(3, **self.new_detail)
        self.accept()

    pyqtSlot()

    def on_pushButton_cancel_clicked(self):
        self.close()