def update_staff(self): indexes = self.selectionModel().selectedRows() if(len(indexes)) == 1: dialog = Dialog() id_text = self.item(indexes[0].row(), 0).text() staff_item = StaffManager.get_one_item_by_user_id(int(id_text)) dialog.name_edit.setText(staff_item.name) dialog.employee_id_edit.setText(staff_item.employee_id) dialog.phone_number_edit.setText(staff_item.phone_number) dialog.tel_number_edit.setText(staff_item.tel_number) dialog.birth_date_edit.setDate(staff_item.birth_date) dialog.title_edit.setCurrentIndex(dialog.title_edit.findText(staff_item.title)) dialog.position_edit.setCurrentIndex(dialog.position_edit.findText(staff_item.position)) dialog.education_edit.setCurrentIndex(dialog.education_edit.findText(staff_item.education)) dialog.description_edit.setText(staff_item.description) dialog.name_edit.setReadOnly(True) if dialog.exec_(): dic = dialog.get_add_datas() dic['id'] = int(id_text) StaffManager.updata_staff(dic) search_datas = StaffManager.search_all_staff() self.refresh_staff(search_datas) dialog.destroy() else: # 弹出警告 ToolsManager.information_box(u"注意", u"请选择一行进行更新!")
def add_staff(self): dialog = Dialog() if dialog.exec_(): dic = dialog.get_add_datas() user = User(**dic) StaffManager.add_staff(user) search_datas = StaffManager.search_all_staff() self.refresh_staff(search_datas) dialog.destroy()
def delete_staff(self): indexes = self.selectionModel().selectedRows() if len(indexes) == 0: ToolsManager.information_box(u"注意", u"请选择一行或多行进行删除!") else: button = ToolsManager.question_box(u"提醒", u"是否删除选中行?") if button == QtGui.QMessageBox.Ok: ids_list = [] for index in sorted(indexes): id_text = self.item(index.row(), 0).text() ids_list.append(int(id_text)) StaffManager.delete_staff(ids_list) StaffManager.delete_staff_project_by_staff_ids(ids_list) search_datas = StaffManager.search_all_staff() self.refresh_staff(search_datas) else: pass
def __init__(self,parent=None): super(MyTable,self).__init__(parent) head_labels = constant.STAFF_COLUMN self.setColumnCount(len(head_labels)) self.setRowCount(0) self.setHorizontalHeaderLabels(head_labels) search_datas = StaffManager.search_all_staff() self.refresh_staff(search_datas)
def get_and_show_idle_staff(self): search_datas = StaffManager.search_idle_staff() head_labels = constant.STAFF_COLUMN self.setColumnCount(len(head_labels)) self.setHorizontalHeaderLabels(head_labels) self.refresh_staff(search_datas)
def search_staff_by_name_and_date(self, **kwargs): outing_days, search_datas = StaffManager.calculate_outing_info(**kwargs) head_labels = constant.STAFF_SEARCH_COLUMN self.setColumnCount(len(head_labels)) self.setHorizontalHeaderLabels(head_labels) self.refresh_staff(search_datas)
def __init__(self, parent=None): super(staff_tab, self).__init__(parent) # 查询区域的按钮 self.addButton = QtGui.QPushButton(u"添加人员") self.deleteButton = QtGui.QPushButton(u"删除人员") self.updateButton = QtGui.QPushButton(u"更新人员") self.allStaffButton = QtGui.QPushButton(u"所有人员") self.idleStaffButton = QtGui.QPushButton(u"在位人员") self.idleStaffButton.setToolTip(u'未出差人员') name_label = QtGui.QLabel(u'姓名') self.name_edit = QtGui.QLineEdit() name_list = [unicode(query.name) for query in StaffManager.get_all_staff()] name_str = QtCore.QStringList(name_list) #预先设置字典 self.name_edit.setCompleter(QtGui.QCompleter(name_str)) # 将字典添加到lineEdit中 start_time_label = QtGui.QLabel(u'起始日期') self.start_time_edit = QtGui.QDateEdit(self) self.start_time_edit.setDateTime(QtCore.QDateTime.currentDateTime()) self.start_time_edit.setDisplayFormat("yyyy-MM-dd") self.start_time_edit.setCalendarPopup(True) self.end_time_edit = QtGui.QDateEdit(self) self.end_time_edit.setDateTime(QtCore.QDateTime.currentDateTime()) self.end_time_edit.setDisplayFormat("yyyy-MM-dd") self.end_time_edit.setCalendarPopup(True) end_time_label = QtGui.QLabel(u'终止日期') searchButton = QtGui.QPushButton(u"搜索") searchButton.setToolTip(u'搜索某人在某段时间内参加的工程情况') searchVbox = QtGui.QVBoxLayout() searchHbox1 = QtGui.QHBoxLayout() searchHbox1.addWidget(name_label) searchHbox1.addWidget(self.name_edit) searchHbox1.addWidget(start_time_label) searchHbox1.addWidget(self.start_time_edit) searchHbox1.addWidget(end_time_label) searchHbox1.addWidget(self.end_time_edit) searchHbox1.addWidget(searchButton) searchHbox1.addStretch(1) searchHbox1.addWidget(self.addButton) searchHbox1.addWidget(self.deleteButton) searchHbox1.addWidget(self.updateButton) searchHbox1.addWidget(self.allStaffButton) searchHbox1.addWidget(self.idleStaffButton) searchVbox.addLayout(searchHbox1) editAreaHbox = QtGui.QHBoxLayout() editAreaHbox.addLayout(searchVbox) # editAreaHbox.addStretch(1) vbox = QtGui.QVBoxLayout() self.my_table = MyTable() self.my_table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.my_table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) vbox.addLayout(editAreaHbox) vbox.addWidget(self.my_table) self.setLayout(vbox) self.setWindowTitle('box layout') self.connect(self.addButton, QtCore.SIGNAL('clicked()'), self.my_table.add_staff) self.connect(self.deleteButton, QtCore.SIGNAL('clicked()'), self.my_table.delete_staff) self.connect(self.allStaffButton, QtCore.SIGNAL('clicked()'), self.show_all_staff) self.connect(self.updateButton, QtCore.SIGNAL('clicked()'), self.my_table.update_staff) self.connect(self.idleStaffButton, QtCore.SIGNAL('clicked()'), self.show_idle_staff) searchButton.clicked.connect(lambda: self.collect_data())