def press_query_drive_fixing_btn(self): mydata = StoreMysql().get_column_name('drives') self.execltableWidget.setColumnCount(len(mydata)) for index, i in enumerate(mydata): print(index) print(i) item = QtWidgets.QTableWidgetItem() item.setText(i[0]) self.execltableWidget.setHorizontalHeaderItem(index, item) data = StoreMysql().get_drive_fixing_info() self.execltableWidget.setRowCount(len(data)) for x, info in enumerate(data): print(x, info) for y, cell in enumerate(info): print(y, cell) if y < len(mydata): try: item = QtWidgets.QTableWidgetItem(str(cell)) self.execltableWidget.setItem(x, y, item) except: pass else: pass self.query_message.setText("查询成功")
def press_query_drive_by_prefix_id_btn(self): tmp = self.query_drive_prefix.text() if tmp == "": self.query_message.setText("请输入前缀") return False else: ... mydata = StoreMysql().get_column_name('drives') self.execltableWidget.setColumnCount(len(mydata)) for index, i in enumerate(mydata): print(index) print(i) item = QtWidgets.QTableWidgetItem() item.setText(i[0]) self.execltableWidget.setHorizontalHeaderItem(index, item) data = StoreMysql().get_drive_info_by_prefix_info(tmp) self.execltableWidget.setRowCount(len(data)) for x, info in enumerate(data): print(x, info) for y, cell in enumerate(info): print(y, cell) if y < len(mydata): try: item = QtWidgets.QTableWidgetItem(str(cell)) self.execltableWidget.setItem(x, y, item) except: pass else: pass self.execltableWidget.sortByColumn(3, Qt.AscendingOrder)
def press_query_drive_by_time_btn(self): start_t = self.start_date.text() end_t = self.end_date.text() if start_t == end_t: self.query_message.setText("请选择不同时间段") return False else: ... mydata = StoreMysql().get_column_name('drives') self.execltableWidget.setColumnCount(len(mydata)) for index, i in enumerate(mydata): print(index) print(i) item = QtWidgets.QTableWidgetItem() item.setText(i[0]) self.execltableWidget.setHorizontalHeaderItem(index, item) data = StoreMysql().get_drive_info_by_time_info(start_t, end_t) self.execltableWidget.setRowCount(len(data)) for x, info in enumerate(data): print(x, info) for y, cell in enumerate(info): print(y, cell) if y < len(mydata): try: item = QtWidgets.QTableWidgetItem(str(cell)) self.execltableWidget.setItem(x, y, item) except: pass else: pass
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) # self.stackedWidget.setCurrentIndex(0) self.drive_number.hide() self.label_30.hide() self.button_connect() self.user_info = StoreMysql().get_userinfo() self.userType = "" self.current_user_id = 0 self.current_user_name = "cbr" self.welcomeUser.setText("") self.data = StoreMysql().get_devices_info() self.pay = 0.0 self.status_dict = {0: 'Error', 1: 'Normal', 2: 'Fixing'} # self.horizontalWidget.hide() # 拍照片定时器 self.timer = QTimer(self) # 初始化一个定时器 self.timer.timeout.connect(self.auto_update_user_info) self.timer.start(1000 * 60 * 5) # 设置计时间隔并启动 # self.fixer_fixing_status.addItem() self.message_clear = QTimer(self) self.message_clear.timeout.connect(self.auto_clear_message) self.message_clear.start(1000 * 4) # 设置计时间隔并启动
def press_drives_change_btn(self): now_row = self.tableWidget.currentRow() print("当前行", now_row) # a,b,c,d,e,f drives_uuid = self.tableWidget.item(now_row, 0).text() drive_name = self.tableWidget.item(now_row, 1).text() drive_type = self.tableWidget.item(now_row, 2).text() drive_status = self.tableWidget.item(now_row, 3).text() drive_version = self.tableWidget.item(now_row, 4).text() drive_specification = self.tableWidget.item(now_row, 5).text() drive_product = self.tableWidget.item(now_row, 6).text() drive_department = self.tableWidget.item(now_row, 7).text() drive_etype = self.tableWidget.item(now_row, 8).text() drive_ereason = self.tableWidget.item(now_row, 9).text() # uuid, name, type, status, version, specification, product, department, etpye, ereason status = StoreMysql().update_devices_info( drives_uuid, drive_name, drive_type, drive_status, drive_version, drive_specification, drive_product, drive_department, drive_etype, drive_ereason) if status: # user_name, drive_name, drive_id, opers, status self.record_to_log(self.current_user_name, drive_name, drives_uuid, "修改设备信息", "成功") self.ware_message.setText('成功修改') self.reflash_drive_widget() else: self.record_to_log(self.current_user_name, drive_name, drives_uuid, "修改设备信息", "失败") self.ware_message.setText('修改失败')
def press_search_drives_btn(self): print('搜索商品信息') # self.count.setText() drives_id = self.fixer_search_drives.text() if drives_id != '': try: data = StoreMysql().search_devices(drives_id=drives_id)[0] if data: self.fixer_drive_name.setText(data[1]) self.fixer_drive_version.setText(data[4]) self.fixer_drive_id.setText(data[0]) self.fixer_drive_spec.setText(data[5]) self.fixer_drive_status.setText(self.status_dict[data[3]]) self.fixer_drive_etpye.setText(data[8]) self.fixer_drive_ereason.setText(data[9]) self.fixer_drive_department.setText(data[7]) # todo 添加信息到 日志表 self.fixer_fixing_status.setCurrentIndex(data[3]) record = "user {} 接入 {} 设备ID:{} 进行维修,设备当前状态:{}".format( self.current_user_name, data[1], data[0], self.status_dict[data[3]]) # user_name, drive_name, drive_id, opers, status status = self.record_to_log(self.current_user_name, data[1], data[0], "进行维修", self.status_dict[data[3]]) if status: self.fixer_message.setText("查找设备成功") else: self.fixer_message.setText("找不到该设备") except: self.fixer_message.setText("找不到该设备") else: self.fixer_message.setText("请输入设备ID")
def record_to_log(self, user_name, drive_name, drive_id, opers, status): record = "user {} 操作 {} 设备ID:{} {},设备当前状态:{}".format( user_name, drive_name, drive_id, opers, status) status = StoreMysql().record_logs(drive_id, record, self.current_user_id) return status
def press_fixer_commit_btn(self): fixer_drive_ereason = self.fixer_drive_ereason.toPlainText() if fixer_drive_ereason == "": return self.fixer_message.setText("更新设备状态失败") else: ... if self.fixer_fixing_status.currentIndex() == 1: self.fixer_driver_etype_ensure.setCurrentIndex(4) current_drives_id = self.fixer_drive_id.text() current_drives_name = self.fixer_drive_name.text() current_drives_status = self.fixer_fixing_status.currentIndex() fixer_driver_etype_ensure = self.fixer_driver_etype_ensure.currentText( ) status = StoreMysql().update_drives_table(current_drives_id, fixer_driver_etype_ensure, fixer_drive_ereason, current_drives_status) if status: self.fixer_drive_status.setText( self.status_dict[self.fixer_fixing_status.currentIndex()]) self.fixer_drive_etpye.setText( self.fixer_driver_etype_ensure.currentText()) # user_name, drive_name, drive_id, opers, status self.record_to_log(self.current_user_name, current_drives_name, current_drives_id, "维修更新设备状态", "成功") self.fixer_message.setText("更新设备状态成功") else: self.record_to_log(self.current_user_name, current_drives_name, current_drives_id, "维修更新设备状态", "失败") self.fixer_message.setText("更新设备状态失败")
def change_user_role(self): username = self.change_username.text() usertype = self.change_type.currentText() if username != '': statu = StoreMysql().change_user(usertype, username) if statu: self.change_username.clear() self.loginmessage_4.setText('成功修改') self.reflash_drive_widget() else: self.change_username.clear() self.loginmessage_4.setText('修改失败') else: self.change_username.clear() self.loginmessage_4.setText('输入用户名')
def delete_user(self): username = self.delete_username.text() if username != '': status = StoreMysql().delete_user(username) if status: self.delete_username.clear() self.loginmessage_3.setText('成功删除') self.reflash_drive_widget() else: self.delete_username.clear() self.loginmessage_3.setText('删除失败') else: self.delete_username.clear() self.loginmessage_3.setText('输入用户名')
def refresh_logs_widget(self): self.data = StoreMysql().get_logs_records() self.log_widget.setRowCount(len(self.data)) for x, info in enumerate(self.data): print(x, info) for y, cell in enumerate(info): print(y, cell) if y < 7: try: item = QtWidgets.QTableWidgetItem(str(cell)) self.log_widget.setItem(x, y, item) except: pass else: pass
def press_drives_delete_btn(self): now_row = self.tableWidget.currentRow() print("当前行", now_row) drives_uuid = self.tableWidget.item(now_row, 0).text() drive_name = self.tableWidget.item(now_row, 1).text() status = StoreMysql().delete_devices_info(drives_uuid) if status: # user_name, drive_name, drive_id, opers, status self.record_to_log(self.current_user_name, drive_name, drives_uuid, "删除设备", "成功") self.ware_message.setText('删除成功') self.reflash_drive_widget() else: self.record_to_log(self.current_user_name, drive_name, drives_uuid, "尝试删除设备", "失败") self.ware_message.setText('删除失败') return True
def press_change_logs_btn(self): now_row = self.log_widget.currentRow() print("当前行", now_row) log_id = self.log_widget.item(now_row, 0).text() # ppp=self.tableWidget.item record = self.log_widget.item(now_row, 1).text() user_id = self.log_widget.item(now_row, 2).text() user_name = self.log_widget.item(now_row, 3).text() drive_name = self.log_widget.item(now_row, 4).text() drive_id = self.log_widget.item(now_row, 5).text() version = self.log_widget.item(now_row, 6).text() # 修改数据库 status = StoreMysql().update_admin_log_info(log_id, record, user_id, user_name, drive_name, drive_id, version) if status: self.ware_message.setText('成功修改') self.refresh_logs_widget() else: self.ware_message.setText('修改失败')
def press_drives_query_btn(self): self.reflash_drive_widget() name = self.drive_name.text() flag = 0 if name != '': print('查询') data = StoreMysql().get_devices_info() for x, info in enumerate(data): print(x, info) for y, cell in enumerate(info): print(y, cell) if name == cell: self.tableWidget.selectRow(x) flag = 1 break else: pass else: ... if flag: self.ware_message.setText("查找成功") else: self.ware_message.setText("查找失败")
def reflash_drive_widget(self): _translate = QtCore.QCoreApplication.translate # self.tableWidget.verticalHeader().setVisible(False) item = self.tableWidget.horizontalHeaderItem(5) # item = self.tableWidget.item(0, 0) self.data = StoreMysql().get_devices_info() self.tableWidget.setRowCount(len(self.data)) for x, info in enumerate(self.data): print(x, info) for y, cell in enumerate(info): print(y, cell) if y < 10: try: item = QtWidgets.QTableWidgetItem(str(cell)) self.tableWidget.setItem(x, y, item) # item = self.tableWidget.item(x, y) # item.setText(_translate("MainWindow",str(cell))) except: pass else: pass
def registered_user(self): username = self.resigner_name.text() password_1 = self.resigner_password_1.text() password_2 = self.resigner_password_2.text() if (username != '') and (password_1 != '') and ( password_2 != '') and password_1 == password_2: user_type = self.resign_type.currentText() pwd = self.calculate_md5(password_2) print("加密", pwd) status = StoreMysql().registered_user_to_database( username, pwd, user_type) if status: self.resigner_name.clear() self.resigner_password_1.clear() self.resigner_password_2.clear() self.loginmessage_2.setText('成功添加') else: self.resigner_name.clear() self.resigner_password_1.clear() self.resigner_password_2.clear() self.loginmessage_2.setText('添加失败') else: self.loginmessage_2.setText("错误")
def press_drives_entry_btn(self): print("添加货物") drives_uuid = self.drive_uuid.text() drive_type = self.drive_type.text() drive_product = self.drive_product.text() drive_name = self.drive_name.text() drive_version = self.drive_version.text() drive_specification = self.drive_specification.text() # TODO 后面解释的时候需要说明 ,设备的情况是根据编号进行唯一确定,不进行后期分配 # drive_number = int(self.drive_number.text()) drive_status = 1 drive_department = "company" drive_etype = "0" drive_ereason = "0" now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") status = StoreMysql().add_drives2ware( drives_uuid=drives_uuid, drive_name=drive_name, drive_type=drive_type, drive_status=drive_status, drive_version=drive_version, drive_specification=drive_specification, drive_product=drive_product, drive_department=drive_department, drive_etype=drive_etype, drive_ereason=drive_ereason, now=now) if status: # user_name, drive_name, drive_id, opers, status self.record_to_log(self.current_user_name, drive_name, drives_uuid, "采购录入", "成功") self.ware_message.setText('成功添加') self.reflash_drive_widget() else: self.ware_message.setText('添加失败')
def auto_update_user_info(self): self.user_info = StoreMysql().get_userinfo()