コード例 #1
0
    def __init__(self, autoid, parent=None):
        # 根据人员权限确定是否能打开模块;是否能修改人员信息
        super(ClerkDtailModule, self).__init__(parent)
        self.setupUi(self)

        # 当前人员的clerkid,主键
        self.autoid = autoid
        self.trainingstatus = 0
        self.healthstatus = 0
        self.CC = ClerksController()
        self.IC = ImageController()
        self.ori_detail = {}
        self.new_detail = {}
        self.treeWidget_deptlist.hideColumn(0)
        self.treeWidget_experience.hideColumn(0)
        self.treeWidget_train.hideColumn(0)
        self.treeWidget_health.hideColumn(0)
        self.get_detail()
        self.get_clerkdept()
        self.get_experience()
        self.get_training()
        self.get_health()
        # 初始化填写格式
        self.init_lineedit_content()
        # 初始化权限列表
        self.init_authority()
        # 初始化下拉菜单的内容
        self.init_combo_content()
        return_row = ('autoid', 'deptid', 'deptname')
        condition_key = {'deptid', 'deptname', 'inputcode'}
        treeheader_name = ["id", "编号", "部门名"]
        self.lineEdit_deptment.setup('Department', return_row, condition_key,
                                     treeheader_name, None, 300, 200)
コード例 #2
0
 def delete_productlabel(autoid, *args):
     try:
         with transaction.atomic():
             image_model = ImageController()
             image_list = Productlabel.objects.filter(
                 autoid__in=autoid).values_list("imgid", flat=True)
             image_model.delete_image(autoid=image_list)
             return Productlabel.objects.filter(autoid__in=autoid).delete()
     except Exception as e:
         SaveExcept(e, "删除产品标签图时出错", autoid=autoid, args=args)
コード例 #3
0
 def __init__(self, autoid, parent=None):
     super(HomePageModule, self).__init__(parent)
     self.setupUi(self)
     self.autoid=autoid
     self.current_img = object
     self.current_page = object
     self.PC = ProductController()
     self.WC = WorkshopController()
     self.IC = ImageController()
     # 自动缩放
     self.label_image.setScaledContents(True)
     self.get_detail()
     self.get_images()
     self.scrollArea.setVisible(False)
     self.groupBox.setVisible(False)
コード例 #4
0
 def __init__(self, parent=None):
     super(ClientListModule, self).__init__(parent)
     self.setupUi(self)
     if '54' not in user.powers:
         self.close()
     if user.powers['54'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['54'])
     self.SC = SaleController()
     self.IC = ImageController()
     self.kind_list = []
     self.curremt_kind = 0
     self.treeWidget_kind.hideColumn(1)
     self.treeWidget_detail.hideColumn(0)
     self.get_kind_list()
     self.get_client_list()
コード例 #5
0
 def __init__(self, autoid=None, parent=None):
     super(EditClientDetailModule, self).__init__(parent)
     self.setupUi(self)
     if '54' not in user.powers:
         self.close()
     if user.powers['54'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['54'])
     if self.power[1] == '0':
         self.pushButton_accept.setVisible(False)
         self.pushButton_cancel.setVisible(False)
     self.autoid = autoid
     self.ori_detail = dict()
     self.new_detail = dict()
     self.current_img = object
     self.current_page = object
     self.province_list = []
     self.city_list = []
     self.county_list = []
     self.province_id = ''
     self.city_id = ''
     self.county_id = ''
     self.qyname = ''
     self.SC = SaleController()
     self.IC = ImageController()
     self.treeWidget_imagenamelist.hideColumn(0)
     self.treeWidget_imagenamelist.hideColumn(1)
     # 自动缩放
     self.label_image.setScaledContents(True)
     return_row = ('parentid', 'autoid', 'kindname')
     condition_key = {'autoid', 'kindname', 'inputcode'}
     treeheader_name = ['parentid', '编号', '名称']
     condition = {'kind': 4}
     self.lineEdit_tstkind.setup('Treestructure',
                                 return_row,
                                 condition_key,
                                 treeheader_name,
                                 condition,
                                 treewidth=300)
     self.get_detail()
     self.get_province()
     if len(self.ori_detail):
         self.get_city(self.ori_detail['province'])
         self.get_county(self.ori_detail['city'])
コード例 #6
0
 def __init__(self, autoid=None, parent=None):
     super(EditSupplyerDetailModule, self).__init__(parent)
     self.setupUi(self)
     if '3' not in user.powers:
         self.close()
     if user.powers['3'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['3'])
     if self.power[1] == '0':
         self.pushButton_accept.setVisible(False)
         self.pushButton_cancel.setVisible(False)
     self.autoid = autoid
     self.docid = 0
     self.current_content = QWidget()
     self.ori_detail = dict()
     self.new_detail = dict()
     self.current_img = object
     self.current_page = object
     self.SC = SupplyerController()
     self.SDC = SelfdefinedformatController()
     self.IC = ImageController()
     self.treeWidget_stuff.hideColumn(0)
     self.treeWidget_revalution.hideColumn(0)
     self.treeWidget_imagenamelist.hideColumn(0)
     self.treeWidget_imagenamelist.hideColumn(1)
     # 自动缩放
     self.label_image.setScaledContents(True)
     return_row = ('parentid', 'autoid', 'kindname')
     condition_key = {'autoid', 'kindname', 'inputcode'}
     treeheader_name = ['parentid', '编号', '名称']
     condition = {'kind': 0}
     self.lineEdit_kind.setup('Treestructure',
                              return_row,
                              condition_key,
                              treeheader_name,
                              condition,
                              treewidth=300)
     self.get_detail()
コード例 #7
0
    def __init__(self, autoid=None, parent=None):
        super(EditProductDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '2s' not in user.powers:
            self.close()
        if user.powers['2'] == 0:
            self.cloe()
        self.power = '{:03b}'.format(user.powers['2'])
        self.autoid = autoid
        self.img_status = 0
        self.images_list = []
        self.current_img = object
        self.current_page = object
        self.PC = ProductController()
        self.PLC = ProductLineConroller()
        self.LC = LabrecordsController()
        self.IC = ImageController()

        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        # 获取种类的下拉列表
        self.get_medkind_list()
        self.get_qrtype()
        self.get_workshop()
        self.get_bworkshop()
        self.get_vworkshop()
        self.get_formula()
        self.get_images()
        self.get_checkitem(3, self.treeWidget_precheckitem)
        self.get_checkitem(4, self.treeWidget_prodcheckitem)
        self.get_checkitem(6, self.treeWidget_samplecheckitem)
        self.treeWidget_formula.hideColumn(0)
        self.treeWidget_precheckitem.hideColumn(0)
        self.treeWidget_prodcheckitem.hideColumn(0)
        self.treeWidget_samplecheckitem.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)
コード例 #8
0
class EditClientDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditClientDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '54' not in user.powers:
            self.close()
        if user.powers['54'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['54'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.ori_detail = dict()
        self.new_detail = dict()
        self.current_img = object
        self.current_page = object
        self.province_list = []
        self.city_list = []
        self.county_list = []
        self.province_id = ''
        self.city_id = ''
        self.county_id = ''
        self.qyname = ''
        self.SC = SaleController()
        self.IC = ImageController()
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)
        # 自动缩放
        self.label_image.setScaledContents(True)
        return_row = ('parentid', 'autoid', 'kindname')
        condition_key = {'autoid', 'kindname', 'inputcode'}
        treeheader_name = ['parentid', '编号', '名称']
        condition = {'kind': 4}
        self.lineEdit_tstkind.setup('Treestructure',
                                    return_row,
                                    condition_key,
                                    treeheader_name,
                                    condition,
                                    treewidth=300)
        self.get_detail()
        self.get_province()
        if len(self.ori_detail):
            self.get_city(self.ori_detail['province'])
            self.get_county(self.ori_detail['city'])

    def get_detail(self):
        if self.autoid is None:
            return
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_data(0, False, *VALUE_TUPLE_SUP, **key_dict)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.lineEdit_clientid.setText(self.ori_detail['clientid'])
        self.lineEdit_clientname.setText(self.ori_detail['clientname'])
        self.lineEdit_inputcode.setText(self.ori_detail['inputcode'])
        self.lineEdit_tstkind.setText(
            str(self.ori_detail['tstkind']) + ' ' + self.ori_detail['tstname'])
        self.lineEdit_address.setText(self.ori_detail['address'])
        self.lineEdit_postzip.setText(self.ori_detail['postzip'])
        self.lineEdit_charger.setText(self.ori_detail['charger'])
        self.lineEdit_telno.setText(self.ori_detail['telno'])
        self.lineEdit_chargertitle.setText(self.ori_detail['chargertitle'])
        self.lineEdit_email.setText(self.ori_detail['email'])
        self.lineEdit_bankname.setText(self.ori_detail['bankname'])
        self.lineEdit_bankaccount.setText(self.ori_detail['bankaccount'])
        self.lineEdit_taxno.setText(self.ori_detail['taxno'])
        self.plainTextEdit_remark.setPlainText(self.ori_detail['remark'])
        self.comboBox_kind.setCurrentIndex(self.ori_detail['kind'])
        self.lineEdit_unitcode.setText(self.ori_detail['unitcode'])

    def get_province(self):
        condition = {'itemtype': 1}
        self.province_list = self.SC.get_data(5, False, *VALUE_TUPLE_RI,
                                              **condition)
        self.comboBox_province.addItems(
            self.province_list.values_list('itemname', flat=True))
        if not len(self.ori_detail) or self.ori_detail['province'] == '':
            return
        self.comboBox_province.setCurrentText(self.ori_detail['province'])

    def get_city(self, province_name=''):
        self.comboBox_city.clear()
        condition = {'itemtype': 1, 'itemname': province_name}
        res = self.SC.get_data(5, True, *VALUE_TUPLE_II, **condition)
        if not len(res):
            return
        condition_city = {'itemtype': 2, 'parentitemid': res[0]}
        self.city_list = self.SC.get_data(5, False, *VALUE_TUPLE_RI,
                                          **condition_city)
        self.comboBox_city.addItems(
            self.city_list.values_list('itemname', flat=True))
        if not len(self.ori_detail) or self.ori_detail['city'] == '':
            return
        if self.comboBox_city.findText(self.ori_detail['city'],
                                       Qt.MatchExactly):
            self.comboBox_city.setCurrentText(self.ori_detail['city'])

    def get_county(self, county_name=''):
        self.comboBox_county.clear()
        condition = {'itemtype': 2, 'itemname': county_name}
        res = self.SC.get_data(5, True, *VALUE_TUPLE_II, **condition)
        if not len(res):
            return
        condition_city = {'itemtype': 3, 'parentitemid': res[0]}
        self.county_list = self.SC.get_data(5, False, *VALUE_TUPLE_RI,
                                            **condition_city)
        self.comboBox_county.addItems(
            self.county_list.values_list('itemname', flat=True))
        if not len(self.ori_detail) or self.ori_detail['county'] == '':
            return
        if self.comboBox_county.findText(self.ori_detail['county'],
                                         Qt.MatchExactly):
            self.comboBox_county.setCurrentText(self.ori_detail['county'])

    def get_image(self):
        self.treeWidget_imagenamelist.clear()
        if self.autoid is None:
            return
        key_dict = {'scid': self.autoid, 'kind': 0}
        res = self.IC.get_data(0, False, *VALUE_TUPLE_IMRELA, **key_dict)
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['imageid']))
            qtreeitem.setText(2, item['title'])
            qtreeitem.setText(3, item['creatorid'] + item['creatorname'])
            qtreeitem.setText(4, str(item['createdate']))

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):

        img_id = int(qtreeitem.text(1))
        key_dict = {'autoid': img_id}
        res = self.IC.get_data(1, False, *VALUE_TUPLE_IM, **key_dict)
        if not len(res):
            return
        ext = res[0]['ext']
        image = res[0]['img']

        if ext.lower() == 'pdf':
            self.comboBox_jumpto.setVisible(True)
            self.pushButton_prepage.setVisible(True)
            self.pushButton_nextpage.setVisible(True)
            self.current_img = fitz.Document(stream=image, filetype='pdf')
            page_count = self.current_img.pageCount
            page_list = []
            self.comboBox_jumpto.clear()
            for i in range(1, page_count + 1):
                page_list.append('第' + str(i) + '页')
            self.comboBox_jumpto.addItems(page_list)
            self.current_page = self.current_img.loadPage(0)

        else:
            self.comboBox_jumpto.setVisible(False)
            self.pushButton_prepage.setVisible(False)
            self.pushButton_nextpage.setVisible(False)
            img = QImage.fromData(image)
            self.current_img = QPixmap.fromImage(img)
            self.label_image.setPixmap(self.current_img)

        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except (ValueError, AttributeError):
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot(QPoint)
    def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        # 返回调用者的对象
        sender_widget = self.sender()
        menu = QMenu()
        button1 = menu.addAction("新增图片")
        button2 = menu.addAction("修改图片")
        button3 = menu.addAction("删除图片")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        res = "rollback"
        # 增加
        if action == button1:
            img_names, img_type = QFileDialog.getOpenFileNames(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            for item in img_names:
                imagename_no_ext = item.split("/")[-1]
                image_ext = item.split(".")[1]
                if image_ext.lower() not in ("jpg", "png", "bmp", "gif",
                                             "pdf"):
                    continue
                fp = open(item, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'kind': 1,
                    'scid': self.autoid,
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail)

        # 修改
        elif action == button2:
            rela_id = self.treeWidget_imagenamelist.currentItem().text(0)
            img_id = self.treeWidget_imagenamelist.currentItem().text(1)
            img_name, img_type = QFileDialog.getOpenFileName(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            imagename_no_ext = img_name.split("/")[-1]
            image_ext = img_name.split(".")[1]
            if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"):
                fp = open(img_name, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail, rela_id,
                                            img_id)

        # 删除
        elif action == button3:
            select_item = sender_widget.selectedItems()
            rela_id = []
            img_id = []
            for item in select_item:
                rela_id.append(item.text(0))
                img_id.append(item.text(1))
            res = self.IC.delete_images(rela_id, img_id)

        if res == "accept":
            self.get_image()

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

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

    @pyqtSlot(str)
    def on_lineEdit_clientname_textChanged(self, p_str):
        self.qyname = p_str
        self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str))
        try:
            if p_str != self.ori_detail['clientname']:
                self.new_detail['clientname'] = p_str
            else:
                try:
                    del self.new_detail['clientname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['clientname'] = p_str

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

    @pyqtSlot(str)
    def on_comboBox_province_currentTextChanged(self, p_str):
        for item in self.province_list:
            if item['itemname'] == p_str:
                self.province_id = item['itemid']
                break
        try:
            if p_str != self.ori_detail['province']:
                self.get_city(p_str)
                self.new_detail['province'] = p_str
            else:
                try:
                    del self.new_detail['province']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['province'] = p_str

    @pyqtSlot(str)
    def on_comboBox_city_currentTextChanged(self, p_str):
        for item in self.city_list:
            if item['itemname'] == p_str:
                self.city_id = item['itemid']
                break
        try:
            if p_str != self.ori_detail['city']:
                self.new_detail['city'] = p_str
                self.get_county(p_str)
            else:
                try:
                    del self.new_detail['city']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['city'] = p_str

    @pyqtSlot(str)
    def on_comboBox_county_currentTextChanged(self, p_str):
        for item in self.county_list:
            if item['itemname'] == p_str:
                self.county_id = item['itemid']
                break
        try:
            if p_str != self.ori_detail['county']:
                self.new_detail['county'] = p_str
            else:
                try:
                    del self.new_detail['county']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['county'] = p_str

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

    @pyqtSlot(str)
    def on_lineEdit_tstkind_textChanged(self, p_str):
        if len(p_str.split(' ')) != 2 and p_str != '':
            return
        id, name = p_str.split(' ') if p_str != '' else ('', '')
        try:
            if id != self.ori_detail['tstkind'] or name != \
                    self.ori_detail['tstname']:
                self.new_detail['tstkind'] = id
                self.new_detail['tstname'] = name
            else:
                try:
                    del self.new_detail['tstkind']
                    del self.new_detail['tstname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['tstkind'] = id
            self.new_detail['tstname'] = name

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

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

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

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

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

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

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

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

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

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

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

    @pyqtSlot()
    def on_pushButton_get_unitcode_clicked(self):
        detail = SelectClientCodeModule(self.province_id, self.city_id,
                                        self.county_id, self.qyname, self)
        detail.selected.connect(self.set_clientname_and_unitcode)
        detail.show()

    def set_clientname_and_unitcode(self, p_str_1, p_str_2):
        self.lineEdit_clientname.setText(p_str_1)
        self.lineEdit_unitcode.setText(p_str_2)

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        condition = dict()
        if self.autoid is not None:
            condition['autoid'] = self.autoid
        self.SC.update_data(0, condition, **self.new_detail)
        self.accept()

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

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        if p_int == 0:
            self.get_detail()
        elif p_int == 1:
            self.get_image()
        else:
            pass
コード例 #9
0
class EditSupplyerDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditSupplyerDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '3' not in user.powers:
            self.close()
        if user.powers['3'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['3'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.docid = 0
        self.current_content = QWidget()
        self.ori_detail = dict()
        self.new_detail = dict()
        self.current_img = object
        self.current_page = object
        self.SC = SupplyerController()
        self.SDC = SelfdefinedformatController()
        self.IC = ImageController()
        self.treeWidget_stuff.hideColumn(0)
        self.treeWidget_revalution.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)
        # 自动缩放
        self.label_image.setScaledContents(True)
        return_row = ('parentid', 'autoid', 'kindname')
        condition_key = {'autoid', 'kindname', 'inputcode'}
        treeheader_name = ['parentid', '编号', '名称']
        condition = {'kind': 0}
        self.lineEdit_kind.setup('Treestructure',
                                 return_row,
                                 condition_key,
                                 treeheader_name,
                                 condition,
                                 treewidth=300)
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            self.dateEdit_validdate.setDate(user.now_date)
            return
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_data(0, False, *VALUE_TUPLE_SUP, **key_dict)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.lineEdit_supid.setText(self.ori_detail['supid'])
        self.lineEdit_supname.setText(self.ori_detail['supname'])
        self.lineEdit_inputcode.setText(self.ori_detail['inputcode'])
        self.lineEdit_kind.setText(
            str(self.ori_detail['tstkind']) + ' ' + self.ori_detail['tstname'])
        self.lineEdit_address.setText(self.ori_detail['address'])
        self.lineEdit_postzip.setText(self.ori_detail['postzip'])
        self.lineEdit_charger.setText(self.ori_detail['charger'])
        self.lineEdit_telno.setText(self.ori_detail['telno'])
        self.lineEdit_chargertitle.setText(self.ori_detail['chargertitle'])
        self.lineEdit_email.setText(self.ori_detail['email'])
        self.lineEdit_bankname.setText(self.ori_detail['bankname'])
        self.lineEdit_bankaccount.setText(self.ori_detail['bankaccount'])
        self.lineEdit_taxno.setText(self.ori_detail['taxno'])
        self.dateEdit_validdate.setDate(self.ori_detail['validdate'])
        self.plainTextEdit_remark.setPlainText(self.ori_detail['remark'])

    def get_image(self):
        self.treeWidget_imagenamelist.clear()
        if self.autoid is None:
            return
        key_dict = {'scid': self.autoid, 'kind': 0}
        res = self.IC.get_data(0, False, *VALUE_TUPLE_IMRELA, **key_dict)
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['imageid']))
            qtreeitem.setText(2, item['title'])
            qtreeitem.setText(3, item['creatorid'] + item['creatorname'])
            qtreeitem.setText(4, str(item['createdate']))

    def get_format(self):
        if self.autoid is None:
            return
        self.treeWidget_revalution.clear()
        key_dict = {'spid': self.autoid}
        res = self.SC.get_data(4, False, *VALUE_TUPLE_SR, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_revalution)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['title'])
            qtreeitem.setText(2, str(item['createdate']))
            qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname'])
        for i in range(1, 4):
            self.treeWidget_revalution.resizeColumnToContents(i)

    def get_stuff(self):
        if self.autoid is None:
            return
        self.treeWidget_stuff.clear()
        key_dict = {'spid': self.autoid}
        res = self.SC.get_data(1, False, **key_dict).extra(
            select={
                'autoid': 'stuffdictionary.autoid',
                'stuffid': 'stuffdictionary.stuffid',
                'stuffname': 'stuffdictionary.stuffname',
                'stufftype': 'stuffdictionary.stufftype',
                'spec': 'stuffdictionary.spec',
                'package': 'stuffdictionary.package'
            },
            tables=['stuffdictionary'],
            where=['stuffdictionary.autoid=stuffsupplyers.sdid'
                   ]).values(*VALUE_TUPLE_STUFF)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_stuff)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STUFFTYPE[item['stufftype']])
            qtreeitem.setText(2, item['stuffid'])
            qtreeitem.setText(3, item['stuffname'])
            qtreeitem.setText(4, item['spec'])
            qtreeitem.setText(5, item['package'])
        for i in range(1, 6):
            self.treeWidget_stuff.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):

        img_id = int(qtreeitem.text(1))
        key_dict = {'autoid': img_id}
        res = self.IC.get_data(1, False, *VALUE_TUPLE_IM, **key_dict)
        if not len(res):
            return
        ext = res[0]['ext']
        image = res[0]['img']

        if ext.lower() == 'pdf':
            self.comboBox_jumpto.setVisible(True)
            self.pushButton_prepage.setVisible(True)
            self.pushButton_nextpage.setVisible(True)
            self.current_img = fitz.Document(stream=image, filetype='pdf')
            page_count = self.current_img.pageCount
            page_list = []
            self.comboBox_jumpto.clear()
            for i in range(1, page_count + 1):
                page_list.append('第' + str(i) + '页')
            self.comboBox_jumpto.addItems(page_list)
            self.current_page = self.current_img.loadPage(0)

        else:
            self.comboBox_jumpto.setVisible(False)
            self.pushButton_prepage.setVisible(False)
            self.pushButton_nextpage.setVisible(False)
            img = QImage.fromData(image)
            self.current_img = QPixmap.fromImage(img)
            self.label_image.setPixmap(self.current_img)

        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except (ValueError, AttributeError):
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot(QPoint)
    def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        # 返回调用者的对象
        sender_widget = self.sender()
        menu = QMenu()
        button1 = menu.addAction("新增图片")
        button2 = menu.addAction("修改图片")
        button3 = menu.addAction("删除图片")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        res = "rollback"
        # 增加
        if action == button1:
            img_names, img_type = QFileDialog.getOpenFileNames(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            for item in img_names:
                imagename_no_ext = item.split("/")[-1]
                image_ext = item.split(".")[1]
                if image_ext.lower() not in ("jpg", "png", "bmp", "gif",
                                             "pdf"):
                    continue
                fp = open(item, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'kind': 0,
                    'scid': self.autoid,
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail)

        # 修改
        elif action == button2:
            rela_id = self.treeWidget_imagenamelist.currentItem().text(0)
            img_id = self.treeWidget_imagenamelist.currentItem().text(1)
            img_name, img_type = QFileDialog.getOpenFileName(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            imagename_no_ext = img_name.split("/")[-1]
            image_ext = img_name.split(".")[1]
            if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"):
                fp = open(img_name, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail, rela_id,
                                            img_id)

        # 删除
        elif action == button3:
            select_item = sender_widget.selectedItems()
            rela_id = []
            img_id = []
            for item in select_item:
                rela_id.append(item.text(0))
                img_id.append(item.text(1))
            res = self.IC.delete_images(rela_id, img_id)

        if res == "accept":
            self.get_image()

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

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

    @pyqtSlot(str)
    def on_lineEdit_supname_textChanged(self, p_str):
        self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str))
        try:
            if p_str != self.ori_detail['supname']:
                self.new_detail['supname'] = p_str
            else:
                try:
                    del self.new_detail['supname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['supname'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_kind_textChanged(self, p_str):
        if len(p_str.split(' ')) != 2 and p_str != '':
            return
        id, name = p_str.split(' ') if p_str != '' else ('', '')
        try:
            if id != self.ori_detail['tstkind'] or name != \
                    self.ori_detail['tstname']:
                self.new_detail['tstkind'] = id
                self.new_detail['tstname'] = name
            else:
                try:
                    del self.new_detail['tstkind']
                    del self.new_detail['tstname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['tstkind'] = id
            self.new_detail['tstname'] = name

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

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

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

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

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

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

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

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

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

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

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

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

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        condition = dict()
        if self.autoid is not None:
            condition['autoid'] = self.autoid
        self.SC.update_data(0, condition, **self.new_detail)
        self.accept()

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

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_revalution_itemDoubleClicked(self, qtreeitem, p_int):
        if hasattr(self.current_content, 'flat'):
            if self.current_content.flat:
                dialog = MessageBox(self,
                                    title="提醒",
                                    text="文档尚未保存",
                                    informative="是否要保存文档",
                                    yes_text="保存",
                                    no_text="放弃保存")
                result = dialog.exec()
                if result == QMessageBox.Yes:
                    # 调用保存的槽函数
                    self.on_pushButton_save_clicked()
        self.docid = int(qtreeitem.text(0))
        key_dict = {'autoid': self.docid}
        res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict)
        if not len(res):
            return
        content = str(res[0])
        if not self.gridLayout_7.isEmpty():
            self.gridLayout_7.removeWidget(self.current_content)
            self.current_content.close()
        self.current_content = XMLReadWrite(self)
        self.current_content.openxml(content)
        self.gridLayout_7.addWidget(self.current_content)
        self.current_content.__setattr__('autoid', self.docid)

    @pyqtSlot()
    def on_pushButton_save_clicked(self):
        if self.docid == 0:
            return
        if not hasattr(self.current_content, 'flat'):
            return
        newcontent = self.current_content.get_content()
        condition = {'autoid': self.docid}
        kwargs = {'conclusion': newcontent}
        self.SC.update_data(4, condition, **kwargs)
        self.current_content.flat = 0

    @pyqtSlot()
    def on_pushButton_undo_clicked(self):
        if hasattr(self.current_content, 'flat'):
            self.current_content.flat = 0

    @pyqtSlot(QPoint)
    def on_treeWidget_revalution_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        if self.autoid is None:
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        menu = QMenu()
        button1 = menu.addAction("增加记录")
        button2 = menu.addAction("修改记录")
        button3 = menu.addAction("删除记录")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == button1:
            detail = SelectSelfDefineFormatModule('4', self)
            detail.selected.connect(self.new_records)
            detail.accepted.connect(self.get_format)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            if hasattr(self.current_content, 'flat'):
                if self.current_content.flat:
                    dialog = MessageBox(self,
                                        title="提醒",
                                        text="文档尚未保存",
                                        informative="是否要保存文档",
                                        yes_text="保存",
                                        no_text="放弃保存")
                    result = dialog.exec()
                    if result == QMessageBox.Yes:
                        # 调用保存的槽函数
                        self.on_pushButton_accept_clicked()
            self.docid = int(current_item.text(0))
            key_dict = {'autoid': self.docid}
            res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict)
            if not len(res):
                return
            content = str(res[0])
            if not self.gridLayout_7.isEmpty():
                self.gridLayout_7.removeWidget(self.current_content)
                self.current_content.close()
            self.current_content = XMLReadWrite(self)
            self.current_content.openxml(content)
            self.gridLayout_7.addWidget(self.current_content)
            self.current_content.__setattr__('autoid', self.docid)
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.SC.delete_data(4, condition)
            self.get_format()

    def new_records(self, q_list):
        detail = {
            'creatorid': user.user_id,
            'creatorname': user.user_name,
            'createdate': user.now_date,
            'spid': self.autoid
        }
        key_dict = {'autoid__in': q_list}
        sd_list = self.SDC.get_data(0, **key_dict)
        for item in q_list:
            for sd in sd_list:
                if item == sd.autoid:
                    detail['title'] = sd.formatname
                    detail['conclusion'] = sd.format
                    self.SC.update_data(4, **detail)
                    break

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        if p_int == 0:
            self.get_detail()
        elif p_int == 1:
            self.get_image()
        elif p_int == 2:
            self.get_format()
        elif p_int == 3:
            self.get_stuff()
        else:
            pass
コード例 #10
0
class HomePageModule(QWidget, Ui_Form):

    def __init__(self, autoid, parent=None):
        super(HomePageModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid=autoid
        self.current_img = object
        self.current_page = object
        self.PC = ProductController()
        self.WC = WorkshopController()
        self.IC = ImageController()
        # 自动缩放
        self.label_image.setScaledContents(True)
        self.get_detail()
        self.get_images()
        self.scrollArea.setVisible(False)
        self.groupBox.setVisible(False)

    def get_detail(self):
        key_dict = {'autoid': self.autoid}
        res = self.PC.get_producingplan(False, *VALUES_TUPLE_PP, **key_dict)
        if not len(res):
            return
        pp_detail = res[0]
        self.label_product.setText(pp_detail['prodid'] + pp_detail['prodname'])
        self.label_commonname.setText(pp_detail['commonname'])
        self.label_spec.setText(pp_detail['spec'])
        self.label_package.setText(pp_detail['package'])
        self.label_batchno.setText(pp_detail['batchno'])
        self.label_realamout.setText(
            to_str(pp_detail['realamount']) + pp_detail['spunit']
        )
        self.label_makedate.setText(str(pp_detail['makedate']))

    def get_images(self):
        self.treeWidget_imagenamelist.clear()
        self.treeWidget_imagenamelist.hideColumn(0)
        key_dict = {'ppid': self.autoid}
        imgid_list = self.WC.get_plids(True,*VALUES_TUPLE_PLIB, **key_dict)
        if not len(imgid_list):
            return

        for item in imgid_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item['imgid']))
            qtreeitem.setText(1, str(item['title']))
            qtreeitem.setText(2, str(item['ext']))
        self.treeWidget_imagenamelist.resizeColumnToContents(1)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):
        self.scrollArea.setVisible(True)
        self.groupBox.setVisible(True)
        img_id = int(qtreeitem.text(0))
        ext = qtreeitem.text(2).lower()
        key_dict = {
            'autoid': img_id
        }
        img_list = self.IC.get_image(False, *VALUES_TUPLE_IMG, **key_dict)
        if not len(img_list):
            return
        image = img_list[0]
        if ext == 'pdf':
            self.comboBox_jumpto.setVisible(True)
            self.pushButton_prepage.setVisible(True)
            self.pushButton_nextpage.setVisible(True)
            self.current_img = fitz.Document(stream=image['img'],
                                             filetype='pdf')
            page_count = self.current_img.pageCount
            page_list = []
            self.comboBox_jumpto.clear()
            for i in range(1, page_count + 1):
                page_list.append('第' + str(i) + '页')
            self.comboBox_jumpto.addItems(page_list)
            self.current_page = self.current_img.loadPage(0)

        else:
            self.comboBox_jumpto.setVisible(False)
            self.pushButton_prepage.setVisible(False)
            self.pushButton_nextpage.setVisible(False)
            img = QImage.fromData(image['img'])
            self.current_img = QPixmap.fromImage(img)
            self.label_image.setPixmap(self.current_img)

        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except AttributeError:
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass
コード例 #11
0
class ClientListModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(ClientListModule, self).__init__(parent)
        self.setupUi(self)
        if '54' not in user.powers:
            self.close()
        if user.powers['54'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['54'])
        self.SC = SaleController()
        self.IC = ImageController()
        self.kind_list = []
        self.curremt_kind = 0
        self.treeWidget_kind.hideColumn(1)
        self.treeWidget_detail.hideColumn(0)
        self.get_kind_list()
        self.get_client_list()

    def get_kind_list(self):
        self.treeWidget_kind.clear()
        key_dict = {'kind': 4}
        self.kind_list = self.SC.get_data(4, False, *VALUES_TUPLE_KIND,
                                          **key_dict)
        # if not len(self.kind_list):
        #     return
        self.set_kind_list(self.kind_list)
        # self.treeWidget_kind.resizeColumnToContents(0)
        self.treeWidget_kind.expandAll()

    def set_kind_list(self, items):
        qtreeitem_all = QTreeWidgetItem(self.treeWidget_kind)
        qtreeitem_all.setText(0, "全部")
        qtreeitem_all.setText(1, "0")
        for item in items:
            res = self.treeWidget_kind.findItems(str(item['autoid']),
                                                 Qt.MatchRecursive, 1)
            if len(res):
                continue
            if item['parentid'] != 0:
                parent_item = self.find_kind_item(item['parentid'])
                qtreeitem = QTreeWidgetItem(parent_item)
            else:
                qtreeitem = QTreeWidgetItem(qtreeitem_all)
            qtreeitem.setText(0, item['kindname'])
            qtreeitem.setText(1, str(item['autoid']))

    def find_kind_item(self, parentid, i=0):
        res = self.treeWidget_kind.findItems(str(parentid), Qt.MatchRecursive,
                                             1)
        if len(res):
            return res[0]
        else:
            parent = self.treeWidget_kind.topLevelItem(0)
            try:
                if i > 10:
                    # 手动设置最大循环深度位10
                    raise RecursionError
                for item in self.kind_list:
                    if item['autoid'] == parentid:
                        parent_id = item['parentid']
                        if parent_id == 0:
                            parent = QTreeWidgetItem(
                                self.treeWidget_kind.topLevelItem(0))
                            parent.setText(0, item['kindname'])
                            parent.setText(1, str(item['autoid']))
                            break
                        else:
                            i += 1
                            parent = self.find_kind_item(parent_id, i)
                            break
                return parent
            except RecursionError:
                return parent

    def get_client_list(self):
        self.treeWidget_detail.clear()
        key_dict = dict()
        if self.curremt_kind != 0:
            key_dict['tstkind'] = self.curremt_kind
        res = self.SC.get_data(0, False, *VALUES_TUPLE_SP, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_detail)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['clientid'])
            qtreeitem.setText(2, item['clientname'])
            qtreeitem.setText(3, item['address'])
            qtreeitem.setText(4, item['charger'])
            qtreeitem.setText(5, item['telno'])
            qtreeitem.setText(6, item['taxno'])
        for i in range(1, 7):
            self.treeWidget_detail.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemClicked(self, qtreeitem, p_int):
        self.curremt_kind = int(qtreeitem.text(1))
        self.get_client_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_detail_itemDoubleClicked(self, qtreeitem, p_int):
        # if self.power[1] == '0':
        #     return
        id = int(qtreeitem.text(0))
        detail = EditClientDetailModule(id, self)
        detail.accepted.connect(self.get_client_list)
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_kind_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:
            if current_item is None:
                parent_item = self.treeWidget_kind.topLevelItem(0)
            else:
                parent_item = current_item
            parent_id = int(parent_item.text(1))
            kwargs = {
                'kind': 4,
                'kindname': "新建分类",
                'parentid': parent_id,
                'inputcode': Inputcode.make_inputcode("新建分类")
            }
            kind_object = self.SC.update_data(4, **kwargs)
            qtreeitem = QTreeWidgetItem(parent_item)
            qtreeitem.setText(0, "新建分类")
            qtreeitem.setText(1, str(kind_object.autoid))

            self.treeWidget_kind.openPersistentEditor(qtreeitem, 0)
            self.treeWidget_kind.setCurrentItem(qtreeitem)
        elif action == button2:
            if current_item is None:
                return
            self.treeWidget_kind.setCurrentItem(None)
            self.treeWidget_kind.openPersistentEditor(current_item, 0)
            self.treeWidget_kind.setCurrentItem(current_item, 0)

        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(1))
            condition = {'autoid': id}
            self.SC.delete_data(4, condition)
            self.get_kind_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemChanged(self, qtreeitem, p_int):
        if self.treeWidget_kind.isPersistentEditorOpen(qtreeitem, p_int):
            self.treeWidget_kind.closePersistentEditor(qtreeitem, p_int)
            id = int(qtreeitem.text(1))
            new_kindname = qtreeitem.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.SC.update_data(4, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
    def on_treeWidget_kind_currentItemChanged(self, qtreeitem, qtreeitem_1):
        if self.treeWidget_kind.isPersistentEditorOpen(qtreeitem_1, 0):
            self.treeWidget_kind.closePersistentEditor(qtreeitem_1, 0)
            id = int(qtreeitem_1.text(1))
            new_kindname = qtreeitem_1.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.SC.update_data(4, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemDoubleClicked(self, qtreeitem, p_int):
        self.treeWidget_kind.openPersistentEditor(qtreeitem, p_int)

    @pyqtSlot(QPoint)
    def on_treeWidget_detail_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 = EditClientDetailModule(parent=self)
            detail.accepted.connect(self.get_client_list)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = EditClientDetailModule(id, self)
            detail.accepted.connect(self.get_client_list)
            detail.show()
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            condition_3 = {'scid': id, 'kind': 1}
            self.SC.delete_data(0, condition)
            img_id_list = self.IC.get_data(0, True, *VALUES_TUPLE_IM,
                                           **condition_3)
            condition_4 = {'autoid__in': img_id_list}
            self.IC.delete_data(1, condition_4)
            self.IC.delete_data(0, condition_3)
            self.get_client_list()
コード例 #12
0
class ClerkDtailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid, parent=None):
        # 根据人员权限确定是否能打开模块;是否能修改人员信息
        super(ClerkDtailModule, self).__init__(parent)
        self.setupUi(self)

        # 当前人员的clerkid,主键
        self.autoid = autoid
        self.trainingstatus = 0
        self.healthstatus = 0
        self.CC = ClerksController()
        self.IC = ImageController()
        self.ori_detail = {}
        self.new_detail = {}
        self.treeWidget_deptlist.hideColumn(0)
        self.treeWidget_experience.hideColumn(0)
        self.treeWidget_train.hideColumn(0)
        self.treeWidget_health.hideColumn(0)
        self.get_detail()
        self.get_clerkdept()
        self.get_experience()
        self.get_training()
        self.get_health()
        # 初始化填写格式
        self.init_lineedit_content()
        # 初始化权限列表
        self.init_authority()
        # 初始化下拉菜单的内容
        self.init_combo_content()
        return_row = ('autoid', 'deptid', 'deptname')
        condition_key = {'deptid', 'deptname', 'inputcode'}
        treeheader_name = ["id", "编号", "部门名"]
        self.lineEdit_deptment.setup('Department', return_row, condition_key,
                                     treeheader_name, None, 300, 200)

    def get_detail(self):
        if self.autoid is None:
            return
        condition = {'autoid': self.autoid}
        res = self.CC.get_data(0, False, *VALUES_TUPLE_CL, **condition)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.clerkid.setText(self.ori_detail['clerkid'])
        self.clerkname.setText(self.ori_detail['clerkname'])
        self.inputcode.setText(self.ori_detail['inputcode'])
        self.sex.setCurrentText(self.ori_detail['sex'])
        self.birthday.setText(str(self.ori_detail['birthday']))
        self.marrystatus.setCurrentText(self.ori_detail['marrystatus'])
        self.nation.setCurrentText(self.ori_detail['nation'])
        self.native_2.setText(self.ori_detail['native'])
        self.policystatus.setCurrentText(self.ori_detail['policystatus'])
        self.idno.setText('*' * 14 + self.ori_detail['idno'][-4:])
        self.address.setText(self.ori_detail['address'])
        self.telno.setText(self.ori_detail['telno'])
        self.entranceday.setText(str(self.ori_detail['entranceday']))
        self.special.setText(self.ori_detail['special'])
        self.schoolname.setText(self.ori_detail['schoolname'])
        self.strongsuit.setText(self.ori_detail['strongsuit'])
        if self.ori_detail['portraitid'] not in ('', 0):
            condition = {'autoid': self.ori_detail['portraitid']}
            res = self.IC.get_data(1, True, *VALUES_TUPLE_IM, **condition)
            if len(res) == 1:
                img = res[0]
                pixmap = QPixmap.fromImage(QImage.fromData(img))
                self.clerk_image.setPixmap(
                    pixmap.scaled(340, 290, Qt.KeepAspectRatio))

    def get_clerkdept(self):
        if self.autoid is None:
            return
        self.treeWidget_deptlist.clear()
        condition = {'clerkid_id': self.autoid}
        res = self.CC.get_data(1, False, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_deptlist)
            qtreeitem.setText(0, str(item.autoid))
            qtreeitem.setText(1, item.deptid.deptid)
            qtreeitem.setText(2, item.deptid.deptname)
            qtreeitem.setText(3, item.position)
        for i in range(3):
            self.treeWidget_deptlist.resizeColumnToContents(i)

    def get_experience(self):
        if self.autoid is None:
            return
        self.treeWidget_experience.clear()
        condition = {'clerkid_id': self.autoid}
        res = self.CC.get_data(3, False, *VALUES_TUPLE_EXP, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_experience)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, EXPTYPE[item['exptype']])
            qtreeitem.setText(2, str(item['fromdate']))
            qtreeitem.setText(3, str(item['todate']))
            qtreeitem.setText(4, item['company'])
            qtreeitem.setText(5, item['experience'])
            qtreeitem.setText(6, item['position'])
            qtreeitem.setText(7, item['remark'])
        for i in range(1, 8):
            self.treeWidget_experience.resizeColumnToContents(i)

    def get_training(self):
        if self.autoid is None:
            return
        self.treeWidget_train.clear()
        condition = {'clerkid_id': self.autoid, 'status': self.trainingstatus}
        res = self.CC.get_data(4, False, *VALUES_TUPLE_TRAIN, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_train)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['fromdate']))
            qtreeitem.setText(2, str(item['todate']))
            qtreeitem.setText(3, item['position'])
            qtreeitem.setText(4, item['training'])
            qtreeitem.setText(5, item['teachingtime'])
            qtreeitem.setText(6, item['teacher'])
            qtreeitem.setText(7, item['score'])
        for i in range(1, 8):
            self.treeWidget_train.resizeColumnToContents(i)

    def get_health(self):
        if self.autoid is None:
            return
        self.treeWidget_health.clear()
        condition = {'clerkid_id': self.autoid, 'status': self.healthstatus}
        res = self.CC.get_data(5, False, *VALUES_TUPLE_HEALTH, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_health)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['checkdate']))
            qtreeitem.setText(2, item['hospital'])
            qtreeitem.setText(3, item['checkitem'])
            qtreeitem.setText(4, item['healthstatus'])
        for i in range(1, 5):
            self.treeWidget_health.resizeColumnToContents(i)

    @pyqtSlot(int)
    def on_tabWidget_2_currentChanged(self, p_int):
        self.trainingstatus = p_int
        self.tabWidget_2.currentWidget().setLayout(self.gridLayout_11)
        self.get_training()

    @pyqtSlot(int)
    def on_tabWidget_3_currentChanged(self, p_int):
        self.healthstatus = p_int
        self.tabWidget_3.currentWidget().setLayout(self.gridLayout_3)
        self.get_health()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_experience_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = ExprienceDetailModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_experience)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_train_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = TrainingRecordDetailModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_training)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_health_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = HealthRecordDetailModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_health)
        detail.show()

    # 校验人员编号的修改
    @pyqtSlot(str)
    def on_clerkid_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['clerkid']:
                self.new_detail['clerkid'] = p_str
            else:
                try:
                    del self.new_detail['clerkid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['clerkid'] = p_str

    # 人员姓名
    @pyqtSlot(str)
    def on_clerkname_textChanged(self, p_str):
        # 把人员名称拼音关联到输入码
        self.inputcode.setText(Inputcode.make_inputcode(p_str))
        try:
            if p_str != self.ori_detail['clerkname']:
                self.new_detail['clerkname'] = p_str
            else:
                try:
                    del self.new_detail['clerkname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['clerkname'] = p_str

    # 快速输入码
    @pyqtSlot(str)
    def on_inputcode_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['inputcode']:
                self.new_detail['inputcode'] = p_str
            else:
                try:
                    del self.new_detail['inputcode']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['inputcode'] = p_str

    # 性别
    @pyqtSlot(str)
    def on_sex_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['sex']:
                self.new_detail['sex'] = p_str
            else:
                try:
                    del self.new_detail['sex']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['sex'] = p_str

    # 出生日期
    @pyqtSlot(str)
    def on_birthday_textChanged(self, p_str):
        try:
            if p_str != str(self.ori_detail['birthday']):
                self.new_detail['birthday'] = p_str
            else:
                try:
                    del self.new_detail['birthday']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['birthday'] = p_str

    # 婚姻状态
    @pyqtSlot(str)
    def on_marrystatus_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['marrystatus']:
                self.new_detail['marrystatus'] = p_str
            else:
                try:
                    del self.new_detail['marrystatus']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['marrystatus'] = p_str

    # 民族
    @pyqtSlot(str)
    def on_nation_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['nation']:
                self.new_detail['nation'] = p_str
            else:
                try:
                    del self.new_detail['nation']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['nation'] = p_str

    # 籍贯
    @pyqtSlot(str)
    def on_native_2_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['native']:
                self.new_detail['native'] = p_str
            else:
                try:
                    del self.new_detail['native']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['native'] = p_str

    # 政治面貌
    @pyqtSlot(str)
    def on_policystatus_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['policystatus']:
                self.new_detail['policystatus'] = p_str
            else:
                try:
                    del self.new_detail['policystatus']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['policystatus'] = p_str

    # 身份证号码
    @pyqtSlot(str)
    def on_idno_textEdited(self, p_str):
        try:
            if p_str != self.ori_detail['idno']:
                self.new_detail['idno'] = p_str
            else:
                try:
                    del self.new_detail['idno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['idno'] = p_str

    # 地址
    @pyqtSlot(str)
    def on_address_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['address']:
                self.new_detail['address'] = p_str
            else:
                try:
                    del self.new_detail['address']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['address'] = p_str

    # 雇佣日期
    @pyqtSlot(str)
    def on_entranceday_textChanged(self, p_str):
        try:
            if p_str != str(self.ori_detail['entranceday']):
                self.new_detail['entranceday'] = p_str
            else:
                try:
                    del self.new_detail['entranceday']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['entranceday'] = p_str

    # 文化程度
    @pyqtSlot(str)
    def on_edudegree_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['edudegree']:
                self.new_detail['edudegree'] = p_str
            else:
                try:
                    del self.new_detail['edudegree']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['edudegree'] = p_str

    # 专业
    @pyqtSlot(str)
    def on_special_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['special']:
                self.new_detail['special'] = p_str
            else:
                try:
                    del self.new_detail['special']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['special'] = p_str

    # 毕业学校
    @pyqtSlot(str)
    def on_schoolname_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['schoolname']:
                self.new_detail['schoolname'] = p_str
            else:
                try:
                    del self.new_detail['schoolname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['schoolname'] = p_str

    # 职称
    @pyqtSlot(str)
    def on_techtitle_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['techtitle']:
                self.new_detail['techtitle'] = p_str
            else:
                try:
                    del self.new_detail['techtitle']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['techtitle'] = p_str

    # 工作前年限
    @pyqtSlot(str)
    def on_strongsuit_textChanged(self, p_str):
        try:
            p_float = float(p_str)
            if p_float != self.ori_detail['strongsuit']:
                self.new_detail['strongsuit'] = p_float
            else:
                try:
                    del self.new_detail['strongsuit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['strongsuit'] = p_float

    # 上传图片功能
    @pyqtSlot()
    def on_setimage_clicked(self):
        img_name, img_type = QFileDialog.getOpenFileName(
            self.clerk_image, "打开图片", "c:\\", "*.jpg;;*.png;;All Files(*)")
        img = QPixmap(img_name).scaled(self.clerk_image.width(),
                                       self.clerk_image.height(),
                                       Qt.KeepAspectRatio)
        fp = open(img_name, 'rb')
        with fp:
            image_byte = fp.read()
            fp.close()
        image_ext = img_name.split(".")[1]
        detail = {'img': image_byte, 'ext': image_ext}
        if len(self.ori_detail) and self.ori_detail['portraitid'] not in ('',
                                                                          0):
            condition = {'autoid': self.ori_detail['portraitid']}
            self.IC.update_data(1, condition, **detail)
        else:
            image = self.IC.update_data(1, **detail)
            self.new_detail['portraitid'] = image.autoid
        self.clerk_image.setPixmap(img)

    # 修改权限
    @pyqtSlot()
    def on_pushButton_editpower_clicked(self):
        detail = EditPowersModule(self.autoid, self)
        detail.accepted.connect(self.init_authority)
        detail.show()

    @pyqtSlot()
    def on_pushButton_add_clicked(self):
        try:
            deptid = int(self.lineEdit_deptment.namelist.currentItem().text(0))
        except ValueError:
            return
        post = self.comboBox_post.currentText()
        detail = {
            'position': post,
            'deptid_id': deptid,
            'clerkid_id': self.autoid
        }
        self.CC.update_data(1, **detail)
        self.get_clerkdept()

    @pyqtSlot(QPoint)
    def on_treeWidget_deptlist_customContextMenuRequested(self, pos):
        screenpos = self.treeWidget_deptlist.mapToGlobal(pos)
        current_item = self.treeWidget_deptlist.currentItem()
        menu = QMenu(self.treeWidget_deptlist)
        action_1 = menu.addAction("删除")
        action = menu.exec(screenpos)
        if action == action_1:
            if current_item is None:
                return
            id = int(current_item.text(0))
            conditin = {'autoid': id}
            self.CC.delete_data(1, conditin)
            self.get_clerkdept()

    @pyqtSlot(QPoint)
    def on_treeWidget_experience_customContextMenuRequested(self, pos):
        screenpos = self.treeWidget_experience.mapToGlobal(pos)
        current_item = self.treeWidget_experience.currentItem()
        menu = QMenu(self.treeWidget_deptlist)
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        action = menu.exec(screenpos)
        if action == action_1:
            detail = ExprienceDetailModule(clerkid=self.autoid, parent=self)
            detail.accepted.connect(self.get_experience)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = ExprienceDetailModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_experience)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.CC.delete_data(3, condition)
            self.get_experience()

    @pyqtSlot(QPoint)
    def on_treeWidget_train_customContextMenuRequested(self, pos):
        screenpos = self.treeWidget_train.mapToGlobal(pos)
        current_item = self.treeWidget_train.currentItem()
        menu = QMenu(self.treeWidget_deptlist)
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        menu.addSeparator()
        action_4 = menu.addAction("提交")
        action = menu.exec(screenpos)
        if action == action_1:
            detail = TrainingRecordDetailModule(clerkid=self.autoid,
                                                parent=self)
            detail.accepted.connect(self.get_training)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = TrainingRecordDetailModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_training)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.CC.delete_data(4, condition)
            self.get_training()
        elif action == action_4:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            detail = {'status': 1}
            self.CC.update_data(4, condition, **detail)
            self.get_training()

    @pyqtSlot(QPoint)
    def on_treeWidget_health_customContextMenuRequested(self, pos):
        screenpos = self.treeWidget_health.mapToGlobal(pos)
        current_item = self.treeWidget_health.currentItem()
        menu = QMenu(self.treeWidget_deptlist)
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        menu.addSeparator()
        action_4 = menu.addAction("提交")
        action = menu.exec(screenpos)
        if action == action_1:
            detail = HealthRecordDetailModule(clerkid=self.autoid, parent=self)
            detail.accepted.connect(self.get_health)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = HealthRecordDetailModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_health)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.CC.delete_data(5, condition)
            self.get_health()
        elif action == action_4:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            detail = {'status': 1}
            self.CC.update_data(5, condition, **detail)
            self.get_health()

    # 确认功能
    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        print(self.new_detail)
        if not len(self.new_detail):
            return
        condition = {'autoid': self.autoid}
        self.CC.update_data(0, condition, **self.new_detail)
        self.accept()

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

    # 初始化填写内容的格式
    def init_lineedit_content(self):
        # 入职前工作年限,格式应该为纯数字
        double_valitor = QDoubleValidator()
        double_valitor.setRange(0, 100)
        double_valitor.setDecimals(1)
        self.strongsuit.setValidator(double_valitor)

        # 出生日期、雇佣日期,格式yyyy-MM-DD
        reg = QRegExp('^[23][0-9]{3}-[0-9]{2}-[0-9]{2}$')
        day_validator = QRegExpValidator()
        day_validator.setRegExp(reg)
        self.birthday.setValidator(day_validator)
        self.entranceday.setValidator(day_validator)

        # 匹配身份证
        reg = QRegExp('^\d{17}(\d|X)$')
        id_validator = QRegExpValidator()
        id_validator.setRegExp(reg)
        self.idno.setValidator(id_validator)

        # 匹配电话号码,纯数字
        reg = QRegExp('[0-9]{11}')
        tel_validator = QRegExpValidator()
        tel_validator.setRegExp(reg)
        self.telno.setValidator(tel_validator)

    # 初始化下拉列表
    def init_combo_content(self):
        items = self.CC.get_data(0, True, *VALUES_TUPLE_ED).distinct()
        if len(items):
            self.edudegree.addItems(items)
        if len(self.ori_detail):
            self.edudegree.setCurrentText(self.ori_detail['edudegree'])
        items = self.CC.get_data(0, True, *VALUES_TUPLE_TE).distinct()
        if len(items):
            self.techtitle.addItems(items)
        if len(self.ori_detail):
            self.techtitle.setCurrentText(self.ori_detail['techtitle'])
        items = self.CC.get_data(1, True, *VALUES_TUPLE_PO).distinct()
        if len(items):
            self.comboBox_post.addItems(items)

    # 初始化权限列表
    def init_authority(self):
        if not len(self.ori_detail):
            return
        self.treeWidget_powers.clear()
        condition = {'autoid': self.autoid}
        res = self.CC.get_data(0, True, *VALUES_TUPLE_POWERS, **condition)
        if len(res) != 1:
            return
        authority = res[0]
        if authority == '':
            return
        authority = json.loads(authority)
        for k in sorted(authority, key=int):
            qtreeitem = QTreeWidgetItem(self.treeWidget_powers)
            power = '{:03b}'.format(int(authority[k]))
            qtreeitem.setText(0, MODULE_NAME[int(k)])
            qtreeitem.setCheckState(1, 2 if power[0] == '1' else 0)
            qtreeitem.setCheckState(2, 2 if power[1] == '1' else 0)
            qtreeitem.setCheckState(3, 2 if power[2] == '1' else 0)
コード例 #13
0
class EditProductDetailModule(QDialog, Ui_Dialog):
    check_item = CheckItem()

    def __init__(self, autoid=None, parent=None):
        super(EditProductDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '2s' not in user.powers:
            self.close()
        if user.powers['2'] == 0:
            self.cloe()
        self.power = '{:03b}'.format(user.powers['2'])
        self.autoid = autoid
        self.img_status = 0
        self.images_list = []
        self.current_img = object
        self.current_page = object
        self.PC = ProductController()
        self.PLC = ProductLineConroller()
        self.LC = LabrecordsController()
        self.IC = ImageController()

        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        # 获取种类的下拉列表
        self.get_medkind_list()
        self.get_qrtype()
        self.get_workshop()
        self.get_bworkshop()
        self.get_vworkshop()
        self.get_formula()
        self.get_images()
        self.get_checkitem(3, self.treeWidget_precheckitem)
        self.get_checkitem(4, self.treeWidget_prodcheckitem)
        self.get_checkitem(6, self.treeWidget_samplecheckitem)
        self.treeWidget_formula.hideColumn(0)
        self.treeWidget_precheckitem.hideColumn(0)
        self.treeWidget_prodcheckitem.hideColumn(0)
        self.treeWidget_samplecheckitem.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)

    def get_detail(self):
        if self.autoid is None:
            for i in range(5):
                self.tab.removeTab(i)
            self.pushButton_accept.setText("增加")
            return
        condition = {'autoid': self.autoid}
        res = self.PC.get_data(1, False, *VALUES_TUPLE_PD, **condition)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.lineEdit_prodid.setText(self.ori_detail['prodid'])
        self.lineEdit_prodname.setText(self.ori_detail['prodname'])
        self.lineEdit_commonname.setText(self.ori_detail['commonname'])
        self.lineEdit_allowno.setText(self.ori_detail['allowno'])
        self.lineEdit_inputcode.setText(self.ori_detail['inputcode'])
        self.lineEdit_spec.setText(self.ori_detail['spec'])
        self.comboBox_packageLv.setCurrentIndex(self.ori_detail['packagelv'])
        self.lineEdit_package.setText(self.ori_detail['package'])
        self.comboBox_midcheckunit.setCurrentText(
            self.ori_detail['midcheckunit']
        )
        self.comboBox_prodcheckunit.setCurrentText(
            self.ori_detail['prodcheckunit']
        )
        self.lineEdit_expireddates.setText(str(self.ori_detail['expireddates']))
        self.lineEdit_storage.setText(self.ori_detail['storage'])

    def get_medkind_list(self):
        items = self.PC.get_data(1, True, *VALUES_TUPLE_MEDKIND).distinct()
        self.comboBox_medkind.addItems(items)
        if len(self.ori_detail):
            self.comboBox_medkind.setCurrentText(self.ori_detail['medkind'])

    def get_qrtype(self):
        if not len(self.ori_detail):
            return
        qrtype = '{:04b}'.format(self.ori_detail['qrtype'])
        self.checkBox_bp.setCheckState(2 if qrtype[0] == '1' else 0)
        self.checkBox_lp.setCheckState(2 if qrtype[1] == '1' else 0)
        self.checkBox_mp.setCheckState(2 if qrtype[2] == '1' else 0)
        self.checkBox_sp.setCheckState(2 if qrtype[3] == '1' else 0)

    def get_workshop(self):
        if not len(self.ori_detail) or self.ori_detail['plid'] == 0:
            return
        condition = {'autoid': self.ori_detail['plid']}
        res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition)
        if not len(res):
            return
        self.toolButton_workshop.setText(res[0]['deptname'])
        self.label_productionline.setText(res[0]['linename'])

    def get_bworkshop(self):
        if not len(self.ori_detail) or self.ori_detail['wplid'] == 0:
            return
        condition = {'autoid': self.ori_detail['wplid']}
        res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition)
        if not len(res):
            return
        self.toolButton_bworkshop.setText(res[0]['deptname'])
        self.label_bproductionline.setText(res[0]['linename'])

    def get_vworkshop(self):
        if not len(self.ori_detail) or self.ori_detail['vplid'] == 0:
            return
        condition = {'autoid': self.ori_detail['vplid']}
        res = self.PLC.get_data(0, False, *VALUES_TUPLE_PL, **condition)
        if not len(res):
            return
        self.toolButton_vworkshop.setText(res[0]['deptname'])
        self.label_vproductionline.setText(res[0]['linename'])

    def get_checkitem(self, itemtype, tree):
        tree.clear()
        condition = {'stuffid': self.autoid, 'itemtype': itemtype}
        res = self.LC.get_data(4, False, *VALUES_TUPLE_CI, **condition). \
            order_by('seqid')
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(tree)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['seqid']))
            qtreeitem.setText(2, item['kind'])
            qtreeitem.setText(3, item['itemname'])
            qtreeitem.setText(4, item['referencevalue'])
            qtreeitem.setText(5, RESTYPE[item['restype']])
            qtreeitem.setText(6, PUTINTYPE[item['putintype']])
        for i in range(1, 7):
            tree.resizeColumnToContents(i)

    def get_formula(self):
        if self.autoid is None:
            return
        self.treeWidget_formula.clear()
        condition = {'prodid': self.autoid, 'prodtype': 0}
        res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_formula)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STUFFTYPE[item['stufftype']])
            qtreeitem.setText(2, item['stuffkind'])
            qtreeitem.setText(3, item['formula'])
            qtreeitem.setText(4, item['presexpression'])
            qtreeitem.setText(5, item['presunit'])
            qtreeitem.setText(6, item['pracexpression'])
            qtreeitem.setText(7, item['pracunit'])
            qtreeitem.setText(8, item['drawexpression'])
            qtreeitem.setText(9, item['drawunit'])
            qtreeitem.setText(10, str(item['precision']))
            qtreeitem.setText(11, str(item['loss']) + "%")
        for i in range(1, 12):
            self.treeWidget_formula.resizeColumnToContents(i)

    def get_images(self):
        self.treeWidget_imagenamelist.clear()
        condition = {'prodid': self.autoid, 'flag': self.img_status}
        res = self.PC.get_data(2, False, **condition)
        if not len(res):
            return
        self.images_list = res
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item.autoid))
            qtreeitem.setText(1, str(item.imgid_id))
            qtreeitem.setText(2, item.imagename)
            qtreeitem.setText(3, item.modifierid + item.modifiername)
            qtreeitem.setText(4, str(item.modifydate))

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        getattr(self, 'tab_' + str(p_int + 7)).setLayout(self.gridLayout_8)
        self.img_status = p_int
        self.get_images()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        rela_id = int(qtreeitem.text(0))
        for item in self.images_list:
            if item.autoid == rela_id:

                if item.imgid.ext.lower() == 'pdf':
                    self.comboBox_jumpto.setVisible(True)
                    self.pushButton_prepage.setVisible(True)
                    self.pushButton_nextpage.setVisible(True)
                    self.current_img = fitz.Document(stream=item.imgid.img,
                                                     filetype='pdf')
                    page_count = self.current_img.pageCount
                    page_list = []
                    self.comboBox_jumpto.clear()
                    for i in range(1, page_count + 1):
                        page_list.append('第' + str(i) + '页')
                    self.comboBox_jumpto.addItems(page_list)
                    self.current_page = self.current_img.loadPage(0)

                else:
                    self.comboBox_jumpto.setVisible(False)
                    self.pushButton_prepage.setVisible(False)
                    self.pushButton_nextpage.setVisible(False)
                    img = QImage.fromData(item.imgid.img)
                    self.current_img = QPixmap.fromImage(img)
                    self.label_image.setPixmap(self.current_img)
                break
        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except (AttributeError, ValueError):
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(QPoint)
    def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        # 返回调用者的对象
        sender_widget = self.sender()
        menu = QMenu()
        button1 = menu.addAction("新增图片")
        button2 = menu.addAction("修改图片")
        button3 = menu.addAction("删除图片")
        button4 = menu.addAction("设为生效/失效")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        res = "rollback"
        # 增加
        if action == button1:
            img_names, img_type = QFileDialog.getOpenFileNames(
                self, "打开图片", os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)"
            )
            for item in img_names:
                imagename_no_ext = item.split("/")[-1]
                image_ext = item.split(".")[1]
                if image_ext.lower() not in ("jpg", "png", "bmp", "gif", "pdf"):
                    continue
                fp = open(item, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {
                    'img': image_byte,
                    'ext': image_ext
                }
                reladetail = {
                    'prodid': self.autoid,
                    'imagename': imagename_no_ext,
                    'modifierid': user.user_id,
                    'modifiername': user.user_name,
                    'modifydate': user.now_date
                }

                res = self.IC.update_productlabel(reladetail, imagedetail)
        # 修改
        elif action == button2:
            current_item = self.treeWidget_imagenamelist.currentItem()
            if current_item is None:
                return
            rela_id = int(current_item.text(0))
            img_id = int(current_item.text(1))
            img_name, img_type = QFileDialog.getOpenFileName(
                self, "打开图片", os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)"
            )
            imagename_no_ext = img_name.split("/")[-1]
            image_ext = img_name.split(".")[1]
            if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"):
                fp = open(img_name, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {
                    'img': image_byte,
                    'ext': image_ext
                }
                reladetail = {
                    'imagename': imagename_no_ext,
                    'modifierid': user.user_id,
                    'modifiername': user.user_name,
                    'modifydate': user.now_date
                }

                res = self.IC.update_productlabel(
                    reladetail, imagedetail, rela_id, img_id
                )
        # 删除
        elif action == button3:
            select_item = sender_widget.selectedItems()
            img_id = []
            for item in select_item:
                img_id.append(int(item.text(1)))
            condition = {'autoid__in': img_id}
            self.IC.delete_data(1, condition)
            res = "accept"

        elif action == button4:
            select_item = sender_widget.selectedItems()
            rela_id = []
            for item in select_item:
                rela_id.append(int(item.text(0)))
            if not len(rela_id):
                return
            condition = {'autoid__in': rela_id}
            detail = {'flag': 1 if self.img_status == 0 else 0}
            self.PC.update_data(2, condition, **detail)
            res = "accept"
        if res == "accept":
            self.get_images()

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot(QPoint)
    def on_treeWidget_formula_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        current_item = self.treeWidget_formula.currentItem()
        menu = QMenu()
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        global_pos = self.treeWidget_formula.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == action_1:
            detail = EditFormulaModule(
                prodid=self.autoid, prodtype=0, parent=self
            )
            detail.accepted.connect(self.get_formula)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = EditFormulaModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_formula)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.PC.delete_data(6, condition)
            self.get_formula()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_formula_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        id = int(qtreeitem.text(0))
        detail = EditFormulaModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_formula)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_precheckitem_itemDoubleClicked(self, qtreeitem, p_int):
        self.on_checkitem_itemDoubleClicked(self.treeWidget_precheckitem, 3)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_prodcheckitem_itemDoubleClicked(self, qtreeitem, p_int):
        self.on_checkitem_itemDoubleClicked(self.treeWidget_prodcheckitem, 4)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_samplecheckitem_itemDoubleClicked(self, qtreeitem, p_int):
        self.on_checkitem_itemDoubleClicked(self.treeWidget_samplecheckitem, 6)

    # 中间产品/成品/留样检验项目,双击打开详细信息
    def on_checkitem_itemDoubleClicked(self, tree, itemtype):
        if self.power[1] == '0':
            return
        detail = SetCheckItem(self, tree.currentItem().text(0))
        detail.accepted.connect(lambda: self.get_checkitem(itemtype, tree))
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_precheckitem_customContextMenuRequested(self, pos):
        self.on_checkitem_customContextMenuRequested(
            self.treeWidget_precheckitem, 3, pos
        )

    @pyqtSlot(QPoint)
    def on_treeWidget_prodcheckitem_customContextMenuRequested(self, pos):
        self.on_checkitem_customContextMenuRequested(
            self.treeWidget_prodcheckitem, 4, pos
        )

    @pyqtSlot(QPoint)
    def on_treeWidget_samplecheckitem_customContextMenuRequested(self, pos):
        self.on_checkitem_customContextMenuRequested(
            self.treeWidget_samplecheckitem, 6, pos
        )

    # 检验项目的右键菜单功能
    def on_checkitem_customContextMenuRequested(self, tree, itemtype, pos):
        if self.power[1] == '0':
            return
        menu = QMenu()
        button1 = menu.addAction("增加")
        button2 = menu.addAction("修改")
        button3 = menu.addAction("删除")
        button4 = menu.addAction("复制")
        button5 = menu.addAction("黏贴")
        global_pos = tree.mapToGlobal(pos)
        action = menu.exec(global_pos)
        # 增加
        if action == button1:
            set_check_item = SetCheckItem(
                self, prodid=self.autoid, itemtype=itemtype
            )
            set_check_item.accepted.connect(
                lambda: self.get_checkitem(itemtype, tree)
            )
            set_check_item.show()
        # 修改
        elif action == button2:
            current_item = tree.currentItem()
            if current_item is None:
                return
            id = int(current_item.text(0))
            set_check_item = SetCheckItem(
                self, autoid=id
            )
            set_check_item.accepted.connect(
                lambda: self.get_checkitem(itemtype, tree)
            )
            set_check_item.show()
        # 删除
        elif action == button3:
            select_item = tree.selectedItems()
            checkitem_autoid = []
            for item in select_item:
                checkitem_autoid.append(item.text(0))
                condition = {'autoid__in': checkitem_autoid}
            self.LC.delete_data(4, condition)
            self.get_checkitem(itemtype, tree)
        # 复制
        elif action == button4:
            clipboard = QApplication.clipboard()
            items = tree.selectedItems()
            select_item = tree.mimeData(items)
            clipboard.setMimeData(select_item)
        # 黏贴
        elif action == button5:
            try:
                clipboard = QApplication.clipboard()
                data = clipboard.mimeData()
                # 获取当前行数,加1即为新的行号
                count = tree.topLevelItemCount()
                res = tree.dropMimeData(
                    tree.invisibleRootItem(), count + 1, data,
                    Qt.CopyAction)
                finnal_index = tree.topLevelItemCount()
                if res:
                    while count < finnal_index:
                        tree_item = tree.topLevelItem(count)
                        if tree_item is None:
                            raise AttributeError
                        detail = dict()
                        detail["seqid"] = tree_item.text(1)
                        detail["kind"] = tree_item.text(2)
                        detail["itemname"] = tree_item.text(3)
                        detail["referencevalue"] = tree_item.text(4)
                        detail["restype"] = RESTYPE.index(tree_item.text(5))
                        detail["putintype"] = PUTINTYPE.index(tree_item.text(6))
                        detail["stuffid"] = self.autoid
                        detail["itemtype"] = itemtype
                        new_item = self.LC.update_data(4, **detail)
                        tree_item.setText(0, str(new_item.autoid))
                        count += 1
            except Exception as e:
                pass
        else:
            pass

    # 修改编号时触发
    @pyqtSlot(str)
    def on_lineEdit_prodid_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['prodid']:
                self.new_detail['prodid'] = p_str
            else:
                try:
                    del self.new_detail['prodid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['prodid'] = p_str

    # 修改名称时触发
    @pyqtSlot(str)
    def on_lineEdit_prodname_textChanged(self, p_str):
        self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str))
        try:
            if p_str != self.ori_detail['prodname']:
                self.new_detail['prodname'] = p_str
            else:
                try:
                    del self.new_detail['prodname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['prodname'] = p_str

    # 修改输入码时触发
    @pyqtSlot(str)
    def on_lineEdit_commonname_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['commonname']:
                self.new_detail['commonname'] = p_str
            else:
                try:
                    del self.new_detail['commonname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['inputcode'] = p_str

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

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

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

    # 修改包装级别时触发
    @pyqtSlot(int)
    def on_comboBox_packageLv_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail['packagelv']:
                self.new_detail['packagelv'] = p_int
            else:
                try:
                    del self.new_detail['packagelv']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['packagelv'] = p_int

    # 修改包装情况时触发
    @pyqtSlot()
    def on_lineEdit_package_editingFinished(self):
        p_str = self.lineEdit_package.text()
        try:
            if p_str != self.ori_detail['package']:
                if self.set_package_rate(p_str):
                    self.new_detail['package'] = p_str
            else:
                try:
                    del self.new_detail['package']
                except KeyError:
                    pass
        except KeyError:
            if self.set_package_rate(p_str):
                self.new_detail['package'] = p_str

    def set_package_rate(self, package):
        lv = self.comboBox_packageLv.currentIndex() + 1
        items = re.split(r'\*|×|x|X', package)
        if len(items) != lv:
            msg = MessageBox(title="错误1!", informative="包装比例错误!")
            msg.exec()
            return False
        num_tuple = ('basicamount', 'spamount', 'mpamount', 'bpamount')
        unit_tuple = ('basicunit', 'spunit', 'mpunit', 'bpunit', 'lpunit')
        try:
            for i in range(len(items)):
                values = re.findall(r'\d+|\w+', items[i])
                self.new_detail[num_tuple[i]] = values[0]
                self.new_detail[unit_tuple[i]] = values[1]
            self.new_detail[unit_tuple[i + 1]] = values[2]
            return True
        except:
            msg = MessageBox(title="错误2!", informative="包装比例错误!")
            msg.exec()
            return False

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

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

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

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

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

    @pyqtSlot(bool)
    def on_checkBox_lp_toggled(self, p_bool):
        status = 8 * (1 if p_bool else -1)
        if 'qrtype' in self.new_detail:
            self.new_detail['qrtype'] += status
        else:
            self.new_detail['qrtype'] = status

    @pyqtSlot(bool)
    def on_checkBox_bp_toggled(self, p_bool):
        status = 4 * (1 if p_bool else -1)
        if 'qrtype' in self.new_detail:
            self.new_detail['qrtype'] += status
        else:
            self.new_detail['qrtype'] = status

    @pyqtSlot(bool)
    def on_checkBox_mp_toggled(self, p_bool):
        status = 2 * (1 if p_bool else -1)
        if 'qrtype' in self.new_detail:
            self.new_detail['qrtype'] += status
        else:
            self.new_detail['qrtype'] = status

    @pyqtSlot(bool)
    def on_checkBox_sp_toggled(self, p_bool):
        status = 1 if p_bool else -1
        if 'qrtype' in self.new_detail:
            self.new_detail['qrtype'] += status
        else:
            self.new_detail['qrtype'] = status

    # 修改生产线和车间时触发
    @pyqtSlot()
    def on_toolButton_workshop_clicked(self):
        setpl = SetProductLine(parent=self, pltype=0)
        setpl.select_line_signal.connect(self.setproductline)
        setpl.show()

    def setproductline(self, linedetail: dict):
        try:
            if linedetail['autoid'] != self.ori_detail['plid']:
                self.new_detail['plid'] = linedetail['autoid']
                self.toolButton_workshop.setText(linedetail['deptname'])
                self.label_productionline.setText(linedetail['linename'])
            else:
                try:
                    del self.new_detail['plid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['plid'] = linedetail['autoid']
            self.toolButton_workshop.setText(linedetail['deptname'])
            self.label_productionline.setText(linedetail['linename'])

    # 修改退货线和车间时触发
    @pyqtSlot()
    def on_toolButton_bworkshop_clicked(self):
        setpl = SetProductLine(parent=self, pltype=2)
        setpl.select_line_signal.connect(self.setwpproductline)
        setpl.show()

    def setwpproductline(self, linedetail: dict):
        try:
            if linedetail['autoid'] != self.ori_detail['wplid']:
                self.new_detail['wplid'] = linedetail['autoid']
                self.toolButton_bworkshop.setText(linedetail['deptname'])
                self.label_bproductionline.setText(linedetail['linename'])
            else:
                try:
                    del self.new_detail['wplid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['wplid'] = linedetail['autoid']
            self.toolButton_bworkshop.setText(linedetail['deptname'])
            self.label_bproductionline.setText(linedetail['linename'])

    # 修改验证线和车间时触发
    @pyqtSlot()
    def on_toolButton_vworkshop_clicked(self):
        setpl = SetProductLine(parent=self, pltype=3)
        setpl.select_line_signal.connect(self.setvproductline)
        setpl.show()

    def setvproductline(self, linedetail: dict):
        try:
            if linedetail['autoid'] != self.ori_detail['vplid']:
                self.new_detail['vplid'] = linedetail['autoid']
                self.toolButton_vworkshop.setText(linedetail['deptname'])
                self.label_vproductionline.setText(linedetail['linename'])
            else:
                try:
                    del self.new_detail['vplid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['vplid'] = linedetail['autoid']
            self.toolButton_vworkshop.setText(linedetail['deptname'])
            self.label_vproductionline.setText(linedetail['linename'])

    # 确认
    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        if self.autoid:
            condition = {'autoid': self.autoid}
            self.PC.update_data(1, condition, **self.new_detail)
        else:
            self.PC.update_data(1, **self.new_detail)
        self.accept()

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