コード例 #1
0
 def get_equiprunnote(self):
     self.treeWidget_equipment.clear()
     EC = EquipmentController()
     '''
     values_list = (
         'autoid', 'eqno', 'eqname', 'fillerid', 'fillername',
         'runstarttime', 'runendtime', 'runtime', 'runstatus'
     )
     key_dict = {
         'pid': self.autoid,
         'rtype': 1
     }
     '''
     key_dict = {'pid': self.autoid, 'rtype': 1}
     eqrunnotes = EC.get_data(1, False, **key_dict).extra(
         select={'eqname': 'equipments.eqname'},
         tables=['equipments'],
         where=['equipments.eqno=eqrunnotes.eqno'])
     if len(eqrunnotes):
         for item in eqrunnotes:
             qtreeitem = QTreeWidgetItem(self.treeWidget_equipment)
             qtreeitem.setText(0, str(item.autoid))
             qtreeitem.setText(1, item.eqno + ' ' + item.eqname)
             qtreeitem.setText(2, item.fillerid + ' ' + item.fillername)
             qtreeitem.setText(3, str(item.runstarttime))
             qtreeitem.setText(4, str(item.runendtime))
             qtreeitem.setText(5, str(item.runtime) + ' ' + '分钟')
             qtreeitem.setText(6, RUN_STATUS[item.runstatus])
         self.treeWidget_equipment.hideColumn(0)
         for i in range(1, 7):
             self.treeWidget_equipment.resizeColumnToContents(i)
コード例 #2
0
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()
コード例 #3
0
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()
コード例 #4
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()
コード例 #5
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)
コード例 #6
0
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()
コード例 #7
0
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()
コード例 #8
0
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))
コード例 #9
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()
コード例 #10
0
class SelectOriCheckPaperEquipmentModule(QDialog, Ui_Dialog):
    def __init__(self, opid, parent=None):
        super(SelectOriCheckPaperEquipmentModule, self).__init__(parent)
        self.setupUi(self)
        self.opid = opid
        self.LC = LabrecordsController()
        self.EC = EquipmentController()
        self.get_detail()
        self.get_equipments()
        self.treeWidget_useeq.hideColumn(0)
        self.treeWidget_eqlist.hideColumn(2)

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

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

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

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

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
コード例 #11
0
class ProductLineListModule(QWidget, Ui_Form):

    def __init__(self, parent=None):
        super(ProductLineListModule, self).__init__(parent)
        self.setupUi(self)

        if '5' not in user.powers:
            self.close()
        if user.powers['5'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['5'])
        self.treeWidget_productline.hideColumn(1)
        self.treeWidget_productline.hideColumn(2)
        self.treeWidget_productline.hideColumn(3)
        self.treeWidget_format.hideColumn(1)
        self.treeWidget_equipment.hideColumn(2)
        self.treeWidget_document.hideColumn(1)
        self.PC = ProductLineConroller()
        self.SC = SelfdefinedformatController()
        self.EC = EquipmentController()
        self.DC = DocumentController()
        self.get_selfdefineformat()
        self.get_equipment_list()
        self.get_document_list()
        self.get_product_line_list()

    def get_selfdefineformat(self):
        # self.treeWidget_format.clear()
        res = self.SC.get_data(0, False, *VALUES_TUPLE_SD).extra(
            where=['formtype&2']
        )
        if not len(res):
            return
        for item in res:
            kind = item['subkind']
            if kind != '':
                match_list = self.treeWidget_format.findItems(
                    kind, Qt.MatchExactly, 0
                )
                if len(match_list):
                    parent = match_list[0]
                else:
                    parent = QTreeWidgetItem(self.treeWidget_format)
                    parent.setText(0, kind)
                    parent.setText(1, '0')
            else:
                parent = self.treeWidget_format
            qtreeitem = QTreeWidgetItem(parent)
            qtreeitem.setText(0, item['formatname'])
            qtreeitem.setText(1, str(item['autoid']))

    def get_equipment_list(self):
        self.treeWidget_equipment.clear()
        res = self.EC.get_data(0, False, *VALUES_TUPLE_EQ)
        if not len(res):
            return
        for item in res:
            kind = item['deptname']
            if kind != '':
                match_list = self.treeWidget_equipment.findItems(
                    kind, Qt.MatchExactly, 0
                )
                if len(match_list):
                    parent = match_list[0]
                else:
                    parent = QTreeWidgetItem(self.treeWidget_equipment)
                    parent.setText(0, kind)
                    parent.setText(2, '0')
            else:
                parent = self.treeWidget_equipment
            qtreeitem = QTreeWidgetItem(parent)
            qtreeitem.setText(0, item['eqno'] + ' ' + item['eqname'])
            qtreeitem.setText(1, item['instposition'])
            qtreeitem.setText(2, str(item['autoid']))
        self.treeWidget_equipment.resizeColumnToContents(0)

    def get_document_list(self):
        self.treeWidget_document.clear()
        res = self.DC.get_data(0, False, *VALUES_TUPLE_DC)
        if not len(res):
            return
        for item in res:
            kind = item['kind']
            if kind != '':
                match_list = self.treeWidget_document.findItems(
                    kind, Qt.MatchExactly, 0
                )
                if len(match_list):
                    parent = match_list[0]
                else:
                    parent = QTreeWidgetItem(self.treeWidget_document)
                    parent.setText(0, kind)
                    parent.setText(1, '0')
            else:
                parent = self.treeWidget_document
            qtreeitem = QTreeWidgetItem(parent)
            qtreeitem.setText(0, item['docno'] + ' ' + item['title'])
            qtreeitem.setText(1, str(item['autoid']))

    def get_product_line_list(self):
        # 第三列位当前行的类型
        # -1:种类
        # 0:生产线名
        # 1:岗位名
        # 2:生产文档;3:岗位设备;4:操作文档
        self.treeWidget_productline.clear()
        res = self.PC.get_data(0, False, *VALUES_TUPLE_PL)
        if not len(res):
            return
        for item in res:
            kind = item['kind']
            if kind != '':
                match_list = self.treeWidget_productline.findItems(
                    kind, Qt.MatchExactly, 0
                )
                if len(match_list):
                    parent = match_list[0]
                else:
                    parent = QTreeWidgetItem(self.treeWidget_productline)
                    parent.setText(0, kind)
                    parent.setText(1, '-1')
                    parent.setText(2, '-1')
            else:
                parent = self.treeWidget_productline
            qtreeitem = QTreeWidgetItem(parent)
            qtreeitem.setText(0, item['linename'])
            qtreeitem.setText(1, str(item['autoid']))
            qtreeitem.setText(2, '0')
            self.add_postname(item['autoid'], qtreeitem)

    @pyqtSlot(QPoint)
    def on_treeWidget_productline_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        current_item = self.treeWidget_productline.currentItem()
        menu = QMenu()
        button1 = menu.addAction("新增生产线")
        button2 = menu.addAction("修改生产线")
        button3 = menu.addAction("删除生产线")
        menu.addSeparator()
        button4 = menu.addAction("新增岗位")
        button5 = menu.addAction("修改岗位")
        button6 = menu.addAction("删除岗位")
        menu.addSeparator()
        button7 = menu.addAction("删除记录/设备/文档")
        global_pos = self.treeWidget_productline.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            detail = EditProductLineDetailModule(parent=self)
            detail.accepted.connect(self.get_product_line_list)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            if current_item.text(2) != '0':
                return
            id = int(current_item.text(1))
            detail = EditProductLineDetailModule(id, self)
            detail.accepted.connect(self.get_product_line_list)
            detail.show()
        elif action == button3:
            if current_item is None or current_item.text(2) != '0':
                return
            id = int(current_item.text(1))
            condition = {'autoid': id}
            self.PC.delete_data(0, condition)
            self.get_product_line_list()
        elif action == button4:
            if current_item is None:
                return
            type = int(current_item.text(2))
            if type == 0:
                parent_item = current_item
                seqid = current_item.childCount()  + 1
                plid = int(current_item.text(1))
            elif type == 1:
                parent_item = current_item.parent()
                seqid = int(parent_item.text(3)) if parent_item.text(3) != '' \
                    else parent_item.childCount()  + 1
                plid = int(parent_item.text(1))
            else:
                return
            detail = EditWorkFlowDetailModule(
                plid=plid, seqid=seqid, parent=self
            )
            detail.accepted.connect(lambda :self.add_postname(plid, parent_item))
            detail.show()
        elif action == button5:
            if current_item is None:
                return
            if current_item.text(2) != '1':
                return
            parent_item = current_item.parent()
            plid = int(parent_item.text(1))
            id = int(current_item.text(1))
            detail = EditWorkFlowDetailModule(autoid=id, plid=plid, parent=self)
            detail.accepted.connect(lambda :self.add_postname(plid, parent_item))
            detail.show()
        elif action == button6:
            if current_item is None or current_item.text(2) != '1':
                return
            wfid = int(current_item.text(1))
            seqid = int(current_item.text(3))
            parent_item = current_item.parent()
            plid = int(parent_item.text(1))
            self.PC.delet_post(wfid, seqid)
            self.add_postname(plid, parent_item)
        elif action == button7:
            if current_item is None:
                return
            id = int(current_item.text(1))
            type = int(current_item.text(2))
            seqid = int(current_item.text(3))
            parent_item = current_item.parent()
            if parent_item is None:
                return
            wfid = int(parent_item.parent().text(1))
            if type not in (2, 3, 4) or id == 0:
                return
            condition = {'autoid': id}
            self.PC.delete_data(type+1, condition)
            condition_update = {'seqid__gt': seqid}
            detail = {'seqid': F('seqid')-1}
            self.PC.update_data(type+1, condition_update, **detail)
            getattr(self, FUN_LIST[type-1])(wfid, parent_item)

    @pyqtSlot(QDropEvent, QPoint)
    def on_treeWidget_productline_droped(self, event, pos):
        if self.power[1] == '0':
            return
        data = event.mimeData().data('application/x-qabstractitemmodeldatalist')
        data_items = decode_data(data)
        parent_item = self.treeWidget_productline.itemAt(pos)
        if parent_item.text(2) in ('-1', '0'):
            return

        from_tree = event.source()

        if from_tree == self.treeWidget_format:
            self.on_treeWidget_format_draged(data_items, parent_item)
        elif from_tree == self.treeWidget_equipment:
            self.on_treeWidget_equipment_draged(data_items, parent_item)
        elif from_tree == self.treeWidget_document:
            self.on_treeWidget_document_draged(data_items, parent_item)
        # 生产线自己内部调整位置
        elif from_tree == self.treeWidget_productline:
            self.on_treeWidget_productline_draged(data_items, parent_item)
        else:
            pass

    def add_postname(self, plid, parent_item):
        parent_item.takeChildren()
        condition = {'plid': plid}
        res = self.PC.get_data(1, False, *VALUES_TUPLE_WF, **condition)
        for item in res.order_by('seqid'):
            new_qtreeitem = QTreeWidgetItem(parent_item)
            new_qtreeitem.setText(0, item['postname'])
            new_qtreeitem.setText(1, str(item['autoid']))
            new_qtreeitem.setText(2, '1')
            new_qtreeitem.setText(3, str(item['seqid']))
            format_tree = QTreeWidgetItem(new_qtreeitem)
            format_tree.setText(0, "生产文档")
            format_tree.setText(1, "0")
            format_tree.setText(2, "2")
            format_tree.setText(3, "0")
            self.add_post_formats(item['autoid'], format_tree)
            eq_tree = QTreeWidgetItem(new_qtreeitem)
            eq_tree.setText(0, "岗位设备")
            eq_tree.setText(1, "0")
            eq_tree.setText(2, "3")
            eq_tree.setText(3, "0")
            self.add_post_equipments(item['autoid'], eq_tree)
            dc_tree = QTreeWidgetItem(new_qtreeitem)
            dc_tree.setText(0, "操作文档")
            dc_tree.setText(1, "0")
            dc_tree.setText(2, "4")
            dc_tree.setText(3, "0")
            self.add_post_documnets(item['autoid'], dc_tree)

    def add_post_formats(self, wfid, parent_item):
        parent_item.takeChildren()
        condition_fm = {'wfid_id': wfid}
        res = self.PC.get_data(3, False, **condition_fm)
        for item in res.order_by('seqid'):
            new_qtreeitem = QTreeWidgetItem(parent_item)
            try:
                if item.docid_id >=0:
                    new_qtreeitem.setText(0, item.docid.formatname)
                else:
                    new_qtreeitem.setText(0, GENERAL_DOC[item.docid_id])
            except ObjectDoesNotExist:
                new_qtreeitem.setText(0, "")
            new_qtreeitem.setText(1, str(item.autoid))
            new_qtreeitem.setText(2, "2")
            new_qtreeitem.setText(3, str(item.seqid))

    def add_post_equipments(self, wfid, parent_item):
        parent_item.takeChildren()
        condition_eq = {'wfid_id': wfid}
        res = self.PC.get_data(4, False, **condition_eq)
        for item in res.order_by('seqid'):
            new_qtreeitem = QTreeWidgetItem(parent_item)
            try:
                new_qtreeitem.setText(0,
                                      item.eqid.eqno + ' ' + item.eqid.eqname)
            except ObjectDoesNotExist:
                new_qtreeitem.setText(0, '')
            new_qtreeitem.setText(1, str(item.autoid))
            new_qtreeitem.setText(2, "3")
            new_qtreeitem.setText(3, str(item.seqid))

    def add_post_documnets(self, wfid, parent_item):
        parent_item.takeChildren()
        condition_dc = {'wfid_id': wfid}
        res = self.PC.get_data(5, False, **condition_dc)
        for item in res.order_by('seqid'):
            new_qtreeitem = QTreeWidgetItem(parent_item)
            try:
                new_qtreeitem.setText(
                    0, item.docid.docno + ' ' + item.docid.title
                )
            except ObjectDoesNotExist:
                new_qtreeitem.setText(0, '')
            new_qtreeitem.setText(1, str(item.autoid))
            new_qtreeitem.setText(2, "4")
            new_qtreeitem.setText(3, str(item.seqid))

    def on_treeWidget_format_draged(self, data, receive_item):
        if self.power[1] == '0':
            return
        # drop_autoid = int(data[1][0])
        qtreeitem = self.treeWidget_format.currentItem()
        drop_autoid = int(qtreeitem.text(1))
        if receive_item.text(2) != '2' or drop_autoid == 0:
            return
        if receive_item.text(1) == '0':
            # 文档直接拖到了"生产文档"上,则新记录放在最后的位置上
            wfid = int(receive_item.parent().text(1))
            seqid = int(receive_item.childCount() + 1)
            parent_item = receive_item
        else:
            # 文档直接拖到了具体的文档上,则新记录占用这个位置,且后面的记录seqid+1
            wfid = int(receive_item.parent().parent().text(1))
            seqid = int(receive_item.text(3))
            condition = {'wfid_id': wfid, 'seqid__gte': seqid}
            detail = {'seqid': F('seqid') + 1}
            parent_item = receive_item.parent()
            self.PC.update_data(3, condition, **detail)
        kwargs = {
            'wfid_id': wfid,
            'seqid': seqid,
            'docid_id': drop_autoid
        }
        self.PC.update_data(3, **kwargs)
        self.add_post_formats(wfid, parent_item)

    def on_treeWidget_equipment_draged(self, data, receive_item):
        if self.power[1] == '0':
            return
        # drop_autoid = int(data[2][0])
        qtreeitem = self.treeWidget_equipment.currentItem()
        drop_autoid = int(qtreeitem.text(2))
        if receive_item.text(2) != '3' or drop_autoid == 0:
            return
        if receive_item.text(1) == '0':
            # 文档直接拖到了"生产文档"上,则新记录放在最后的位置上
            wfid = int(receive_item.parent().text(1))
            seqid = int(receive_item.childCount() + 1)
            parent_item = receive_item
        else:
            # 文档直接拖到了具体的文档上,则新记录占用这个位置,且后面的记录seqid+1
            wfid = int(receive_item.parent().parent().text(1))
            seqid = int(receive_item.text(3))
            condition = {'wfid_id': wfid, 'seqid__gte': seqid}
            detail = {'seqid': F('seqid') + 1}
            parent_item = receive_item.parent()
            self.PC.update_data(5, condition, **detail)
        kwargs = {
            'wfid_id': wfid,
            'seqid': seqid,
            'eqid_id': drop_autoid
        }
        self.PC.update_data(4, **kwargs)
        self.add_post_equipments(wfid, parent_item)

    def on_treeWidget_document_draged(self, data, receive_item):
        if self.power[1] == '0':
            return
        # drop_autoid = int(data[1][0])
        qtreeitem = self.treeWidget_document.currentItem()
        drop_autoid = int(qtreeitem.text(1))
        if receive_item.text(2) != '4' or drop_autoid == 0:
            return
        if receive_item.text(1) == '0':
            # 文档直接拖到了"生产文档"上,则新记录放在最后的位置上
            wfid = int(receive_item.parent().text(1))
            seqid = int(receive_item.childCount() + 1)
            parent_item = receive_item
        else:
            # 文档直接拖到了具体的文档上,则新记录占用这个位置,且后面的记录seqid+1
            wfid = int(receive_item.parent().parent().text(1))
            seqid = int(receive_item.text(3))
            condition = {'wfid_id': wfid, 'seqid__gte': seqid}
            detail = {'seqid': F('seqid') + 1}
            parent_item = receive_item.parent()
            self.PC.update_data(5, condition, **detail)
        kwargs = {
            'wfid_id': wfid,
            'seqid': seqid,
            'docid_id': drop_autoid
        }
        self.PC.update_data(5, **kwargs)
        self.add_post_documnets(wfid, parent_item)

    def on_treeWidget_productline_draged(self, data, receive_item):
        if self.power[1] == '0':
            return
        # drop_autoid = int(data[1][0])
        # drop_type = int(data[2][0])
        # drop_seqid = int(data[3][0])
        # receive_id = receive_item.text(1)
        qtreeitem = self.treeWidget_productline.currentItem()
        drop_autoid = int(qtreeitem.text(1))
        drop_type = int(qtreeitem.text(2))
        drop_seqid = int(qtreeitem.text(3))
        receive_id = receive_item.text(1)
        if drop_type in (2, 3, 4):
            # 拖拽的项目类型不一致
            if drop_type != int(receive_item.text(2)):
                return
            # 拖拽的是生产文档
            if receive_id == '0':
                # 接收的是"生产文档"
                parent_item = receive_item
                wfid = int(receive_item.parent().text(1))
                condition_other = {'wfid_id': wfid, 'seqid__gt': drop_seqid}
                detail_other = {'seqid': F('seqid') - 1}
                new_seqid = receive_item.childCount()
                condition_this = {'autoid': drop_autoid}
                detail_this = {'seqid': new_seqid}
            else:
                # 接收的是生产记录
                parent_item = receive_item.parent()
                wfid = int(receive_item.parent().parent().text(1))
                receive_seqid = int(receive_item.text(3))
                condition_other = {
                    'wfid_id': wfid,
                    'seqid__gte': receive_seqid,
                    'seqid__lt': drop_seqid
                }
                detail_other = {'seqid': F('seqid') + 1}
                condition_this = {'autoid': drop_autoid}
                detail_this = {'seqid': receive_seqid}
            self.PC.update_data(drop_type+1, condition_other, **detail_other)
            self.PC.update_data(drop_type+1, condition_this, **detail_this)
            getattr(self, FUN_LIST[drop_type-1])(wfid, parent_item)
        # 拖拽的是岗位
        elif drop_type == 1:
            receive_type = receive_item.text(2)
            # 接收的是"生产线名称"
            if receive_type == '0':
                parent_item = receive_item
                plid = int(parent_item.text(1))
                condition_other = {'plid': plid, 'seqid__gt': drop_seqid}
                detail_other = {'seqid': F('seqid') - 1}
                new_seqid = receive_item.childCount()
                condition_this = {'autoid': drop_autoid}
                detail_this = {'seqid': new_seqid}
            # 接收的是岗位名
            elif receive_type == '1':

                parent_item = receive_item.parent()
                plid = int(parent_item.text(1))
                receive_seqid = int(receive_item.text(3))
                condition_other = {
                    'plid': plid,
                    'seqid__gte': receive_seqid,
                    'seqid__lt': drop_seqid
                }
                detail_other = {'seqid': F('seqid') + 1}
                condition_this = {'autoid': drop_autoid}
                detail_this = {'seqid': receive_seqid}
            else:
                return
            self.PC.update_data(1, condition_other, **detail_other)
            self.PC.update_data(1, condition_this, **detail_this)
            getattr(self, FUN_LIST[drop_type - 1])(plid, parent_item)
        else:
            pass
コード例 #12
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()