class DeptClerksModule(QWidget, Ui_clerks): def __init__(self, parent=None): super(DeptClerksModule, self).__init__(parent) self.setupUi(self) if '0' not in user.powers: self.close() if user.powers['0'] == 0: self.close() self.power = '{:03b}'.format(user.powers['0']) self.treeWidget_deptlist.hideColumn(2) self.treeWidget_userlist.hideColumn(0) self.CC = ClerksController() self.current_deptid = None self.disabled = 0 # 全部部门信息 self.alldeptment = [] # 全部人员信息 self.allclerks = [] # 增加部门列表里的内容 self.get_deptment_list() self.get_clerks_list() def get_clerks_list(self): self.treeWidget_userlist.clear() condition = {'disabled': self.disabled} if self.current_deptid is None or self.current_deptid == '0': res = self.CC.get_data(0, False, *VALUES_TUPLE_CL, **condition) else: res = self.CC.get_data(0, False, **condition).extra( tables=['clerkdept'], where=['clerkdept.deptid=' + self.current_deptid, 'clerks.autoid=clerkdept.clerkid'] ).values(*VALUES_TUPLE_CL) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_userlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['clerkid']) qtreeitem.setText(2, item['clerkname']) qtreeitem.setText(3, item['sex']) qtreeitem.setText( 4, str(item['birthday']) if type(item['birthday']) is datetime.date else '' ) qtreeitem.setText( 5, str(item['entranceday']) if type(item['entranceday']) is datetime.date else '') qtreeitem.setText(6, item['edudegree']) qtreeitem.setText(7, item['marrystatus']) qtreeitem.setText(8, '*'*14 + item['idno'][-4:]) qtreeitem.setText(9, item['telno']) for i in range(10): self.treeWidget_userlist.resizeColumnToContents(i) # 人员列表双击的功能 @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_userlist_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0': return autoid = int(qtreeitem.text(0)) detail = ClerkDtailModule(autoid, self) detail.accepted.connect(self.get_clerks_list) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_deptlist_itemClicked(self, qtreeitem, p_int): self.current_deptid = qtreeitem.text(2) self.get_clerks_list() @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): getattr(self, 'tab_' + str(p_int)).setLayout(self.gridLayout_2) self.disabled = p_int self.get_clerks_list() # 部门菜单右键功能 @pyqtSlot(QPoint) def on_treeWidget_deptlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return current_item = self.treeWidget_deptlist.currentItem() menu = QMenu() item1 = menu.addAction("新建部门") item2 = menu.addAction("修改部门") item3 = menu.addAction("删除部门") # 把坐标转换为屏幕坐标 screenpos = self.treeWidget_deptlist.mapToGlobal(pos) # 设置菜单显示的位置,返回点击了哪个功能 action = menu.exec(screenpos) # 根据点击了哪个功能绑定对应的事件 if action == item1: detail = ModifyDeptmentModule(parent=self) detail.accepted.connect(self.get_deptment_list) detail.show() elif action == item2: if current_item is None: return autoid = int(current_item.text(2)) if autoid == 0: return detail = ModifyDeptmentModule(autoid, self) detail.accepted.connect(self.get_deptment_list) detail.show() elif action == item3: if current_item is None: return autoid = int(current_item.text(2)) if autoid == 0: return s = QTreeWidgetItem() if current_item.childCount() > 0: msg = MessageBox( self, text='无法删除部门', informative='当前部门下还有子部门' ) msg.exec() return condition = {'autoid': autoid} self.CC.delete_data(2, condition) self.get_deptment_list() else: pass # 人员菜单右键功能 @pyqtSlot(QPoint) def on_treeWidget_userlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return menu = QMenu() item1 = menu.addAction("新增人员信息") item2 = menu.addAction("修改人员信息") item3 = menu.addAction("删除人员信息") # 把坐标转换为屏幕坐标 screenpos = self.treeWidget_userlist.mapToGlobal(pos) # 设置菜单显示的位置,返回点击了哪个功能 action = menu.exec(screenpos) # 根据点击了哪个功能绑定对应的事件 if action == item1: detail = CreateClerkModule(self) detail.accepted.connect(self.get_clerks_list) detail.show() elif action == item2: self.modify_deptment(self.treeWidget_deptlist) elif action == item3: self.delete_deptment() else: pass # 刷新部门列表的内容 def get_deptment_list(self): # 清空“全部部门”下的所有子节点 self.treeWidget_deptlist.clear() # 查询所有部门信息 self.alldeptment = self.CC.get_data(2, False, *VALUES_TUPLE_DEPT) # 获得“全部部门”的item地址 alldeptitem = QTreeWidgetItem(self.treeWidget_deptlist) alldeptitem.setText(1, "全部部门") alldeptitem.setText(2, "0") # 把全部部门作为父节点,把查询到的部门信息添加到“全部部门”下 self.adddeptitem(alldeptitem, *self.alldeptment) # 设置“全部部门”为当前选中项目 self.treeWidget_deptlist.setCurrentItem(alldeptitem) self.current_deptid = '0' # 展开“所有部门” self.treeWidget_deptlist.expandAll() for i in range(2): self.treeWidget_deptlist.resizeColumnToContents(i) # 添加部门列表的内容 # parent 树根节点 # aldeptitem “全部部门”的地址,作为其他节点的父节点 # items 需要增加的节点内容 # 方法:首先遍历item,判断parentid是否为空,若为空,则判断deptid对应的节点 # 是否已经被创建,若已存在则设置deptid和deptname的值,若没有被创建 # 则建立对应的节点(父节点为alldeptitem),并设置deptid和deptname的值 # # 若parentid不为空,则把父节点设置为parentid对应的节点,若父节点还没 # 被创建则先建立父节点并设置deptid = parentid,用于后续查询节点用。 def adddeptitem(self, alldeptitem, *items): for item in items: if 'hasset' in item: continue # 有上级部门 if item['parentid'] != '': # 获取/建立上级部门的节点 parent_treeitem = self.create_parent_treeitem( alldeptitem, item['parentid'], *items ) else: parent_treeitem = alldeptitem childtreeitem = QTreeWidgetItem(parent_treeitem) childtreeitem.setText(0, item["deptid"]) childtreeitem.setText(1, item["deptname"]) childtreeitem.setText(2, str(item["autoid"])) # 添加所有部门,逐层添加上级部门,直到上级部门已经存在 def create_parent_treeitem(self, alldeptitem, parent_id, *items): # 直接在树节点中寻找上级节点 parent_item = self.treeWidget_deptlist.findItems( parent_id, Qt.MatchExactly | Qt.MatchRecursive, 0 ) # 存在上级节点 if len(parent_item): return parent_item[0] # 不存在上级节点,则遍历所有部门,找到对应的记录后新建一个子节点 else: flag = False for item in items: if parent_id == item['deptid']: item['hasset'] = True flag = True if item['parentid'] == '': grand_item = QTreeWidgetItem(alldeptitem) grand_item.setText(0, item['deptid']) grand_item.setText(1, item['deptname']) grand_item.setText(2, str(item['autoid'])) else: grand_item = self.create_parent_treeitem( alldeptitem, item['parentid'], *items ) return grand_item if not flag: return alldeptitem
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)