def save_new_unpass(self): batch, prodate, unpasstype, unpassname, unpassqty, describe, customer, new_id = \ self.new_batch.text(), self.date_produce.text(), self.new_unpasstype.currentText(), \ self.comb_new_unpassname.currentText(), self.new_unpass_qty.text(), self.new_unpass_desc.toPlainText(), \ self.comb_new_coustom.currentText(), self.new_id.text() if all([ batch, prodate, unpasstype, unpassname, unpassqty, describe, customer ]): sql = "INSERT INTO 不合格品登记 (批号,生产日期,不良品种类,不良品名称,数量Kg,不合格描述,客户,ID) " \ "VALUES ('{}','{}','{}','{}','{}','{}','{}',{})" \ "".format(batch, prodate, unpasstype, unpassname, unpassqty, describe, customer, new_id) _db = MysqlDb() with _db: try: _db.modify_db(sql) _db.modify_db("INSERT INTO 状态标记 SET ID={}".format(new_id)) self.new_id.setText(str(int(self.new_id.text()) + 1)) self.parent.set_tbl_unpass(mainwindow.TBL_UNPASS_SQL) QMessageBox.information(self, '操作提示', '插入成功') self.clear_unpass_info() msg = r'新增不合格品信息如下:\n种类:{}\n批号:{}\n客户:{}\n牌号:{}\n数量:{}Kg\n生产日期:{}\n不合格描述:{}' \ ''.format(unpasstype, batch, customer, unpassname, unpassqty, prodate, describe) wechat = SmsWechat() wechat.send_message(msg_type='text', contents=msg) except Exception as e: user_info.log2txt('登记新不合格品时发生错误:{}'.format(e)) else: QMessageBox.warning(self, '警告', '缺少必要信息,请完善后保存!')
def save_pre_info(self): try: row = self.pre_tbl_view.currentIndex().row() unpass_id = int(self.model_pre.item(row, 0).text()) part = user_info.get_value('PART') pre_information = self.txt_pre_info.toPlainText() if pre_information.replace(' ', ''): _db = MysqlDb() sql_pre_chk = "UPDATE 不合格品登记 SET {}评审=True WHERE ID={}" \ "".format(part, unpass_id) sql_pre_info = "UPDATE 状态标记 SET {}评审信息='{}' WHERE ID={}" \ "".format(part, pre_information, unpass_id) with _db: try: _db._cursor.execute(sql_pre_chk) _db._cursor.execute(sql_pre_info) eval('self.{}.setText(pre_information)' ''.format( dict( zip(FIELDS_IN_TAB2.values(), FIELDS_IN_TAB2.keys()))[part + '评审信息'])) _db._cnn.commit() QMessageBox.information(self, 'Information', '已保存!') self._load_tbl_pre_data() except Exception as e: _db._cnn.rollback() user_info.log2txt( '提交写入评审信息时出现错误<save_pre_info>:<{}>'.format(e)) QMessageBox.critical(self, 'Mistake', '系统错误未保存!') except Exception as e: user_info.log2txt('试图保存评审信息时出现错误<save_pre_info>:<{}>'.format(e)) pass
def save_pro_info(self): batch, coustomer, pro_name, pro_color, pro_date, test_date = \ self.test_batch.text(), self.comb_test_coustomer.currentText(), \ self.comb_pro_type.currentText(), self.comb_pro_color.currentText(), \ self.date_produce.text(), self.date_test.text() if all([batch, coustomer, pro_name, pro_color, pro_date, test_date]): db = MysqlDb() with db: try: sql_info = "INSERT INTO 产品信息 (批号, 客户, 产品型号, 颜色, 生产日期, 检验日期)" \ " VALUES ('{}', '{}', '{}', '{}', '{}', '{}')" \ "".format(batch, coustomer, pro_name, pro_color, pro_date, test_date) sql_performance = "INSERT INTO 常规性能 SET 批号='{}'".format(batch) db._cursor.execute(sql_info) db._cursor.execute(sql_performance) db._cnn.commit() sql_for_new = "SELECT {} FROM 常规性能 WHERE 批号='{}'" \ "".format(','.join(TEST_ITEMS), batch) # show 20 items of the same product's test result recently sql_other_same = "SELECT a.批号,IF(表面判定=TRUE,'PASS',IF(表面判定 IS NULL,NULL,'UNPASS'))," \ "IF(RoSH=TRUE,'PASS',IF(RoSH IS NULL,NULL,'UNPASS')),{} FROM 产品信息 a INNER JOIN 常规性能 b " \ "ON a.批号=b.批号 WHERE CONCAT(客户,产品型号) like '%{}%' AND a.批号<>'{}' LIMIT 20" \ "".format(','.join(TEST_ITEMS[3:]), coustomer + pro_name, batch) self.set_test_data_view('{} UNION {}'.format(sql_for_new, sql_other_same)) except Exception as e: db._cnn.rollback() QMessageBox.critical(self, '逻辑错误', '可能已存在相同的批号!') user_info.log2txt('登记新产品信息时错误:{}'.format(e)) else: QMessageBox.warning(self, '警告', '缺少必要产品信息!')
def processtrigger_follow_view(self, act): row = self.on_follow_view.currentIndex().row() if row != -1: unpass_id = int(self.model_on_follow.item(row, 0).text()) _db = MysqlDb() with _db: if act.text() == 'Close Case': sql = "UPDATE 状态标记 SET case_closed_flag=True WHERE ID={}".format( unpass_id) try: _db.modify_db(sql) self._load_on_follow_view_data() self.set_tbl_unpass(TBL_UNPASS_SQL) except Exception as e: user_info.log2txt('第三页右键更新跟踪信息状态时发生错误:{}'.format(e)) elif act.text() == '添加处置': count_rst = _db.get_rst( "SELECT COUNT(*) as _count FROM fcase_deallog WHERE ID={}" .format(unpass_id)) count = count_rst[0]['_count'] add_method_frm = AddMethod(self) add_method_frm.line_unpass_id.setText(str(unpass_id)) add_method_frm.line_deal_id.setText('{}-{}'.format( str(unpass_id), str(count + 1))) add_method_frm.show() add_method_frm.move(QCursor.pos()) elif act.text() == '刷新': self._load_on_follow_view_data()
def to_pdf(self): fields = list(FIELDS_IN_TAB3.values())[:5] info = [] row = self.on_follow_view.currentIndex().row() if row != -1: unpass_id = int(self.model_on_follow.item(row, 0).text()) _db = MysqlDb() with _db: fd = ','.join(FIELDS_IN_TAB3.values()) sql = "SELECT {} FROM 不合格品登记 a INNER JOIN 状态标记 b ON a.ID=b.ID WHERE a.ID={}" \ "".format(fd, unpass_id) pre_rst = _db.get_rst(sql) d = pre_rst[0] for k, v in d.items(): v = '' if v is None else v d[k] = str(v) for k in fields: info.append(d.pop(k)) try: write2pdf(fields, info, d) QMessageBox.information(self, '提示:', '已生成pdf文档至安装目录的output文件夹!') except Exception as e: user_info.log2txt('生成pdf文档时发生错误:{}'.format(e)) QMessageBox.information(self, '提示:', '生成pdf文档时发生错误,请查看错误日志!') else: QMessageBox.warning(self, '未选择', '请先选择项目!') pass
def save_new_pwd(self): pwd = self.line_pwd_one.text() pwd_again = self.line_pwd_again.text() if pwd == pwd_again and pwd: user_name = user_info.get_value('USERNAME') print(user_name) sql = 'UPDATE 用户 SET 密码="{}" WHERE 用户名="{}"'.format(pwd, user_name) try: db = MysqlDb() with db: db.modify_db(sql) QMessageBox.information(self, '完成提示', '密码修改成功!') except Exception as e: user_info.log2txt('更改用户密码时错误:<{}>'.format(e)) else: QMessageBox.warning(self, '错误提示', '输入有误!') self.show() # keep use this dialog when need not quit
def processtrigger_tbl_pre(self, act): row = self.pre_tbl_view.currentIndex().row() sql = '' if row != -1: unpass_id = int(self.model_pre.item(row, 0).text()) _db = MysqlDb() with _db: if act.text() == 'Start General Review': sql = "UPDATE 状态标记 SET g_m_rev=True WHERE ID={}".format( unpass_id) elif act.text() == 'Flag Review Finish': sql = "UPDATE 状态标记 SET review_finish=True WHERE ID={}".format( unpass_id) try: _db.modify_db(sql) self._load_tbl_pre_data() except Exception as e: user_info.log2txt('第二页右键更新评审信息状态时发生错误:{}'.format(e))
def show_unpass_item(self): row = self.tbl_unpass.currentIndex().row() unpass_id = int(self.model_unpass.item( row, 0).text()) # pos(row, 0) the first column try: _db = MysqlDb() with _db: fd = ','.join(list(FIELDS_IN_TAB1.values())[1:]) sql = "SELECT a.ID,{0} FROM" \ " 不合格品登记 a LEFT JOIN 状态标记 b " \ "ON a.ID=b.ID " \ "WHERE a.ID={1}".format(fd, unpass_id) _rst = _db.get_rst(sql) values = list(_rst[0].values()) fd = list(FIELDS_IN_TAB1.keys()) for i in range(len(fd)): try: v = values[i] if values[i] is not None else '' exec_str = 'self.{}.setText(str(v))'.format(fd[i]) if fd[i] == 'pre_check': exec_str = 'self.{}.setChecked(v)'.format(fd[i]) elif fd[i] == 'prodate': exec_str = 'self.{}.setText(v.strftime("%Y-%m-%d"))'.format( fd[i]) eval(exec_str) except Exception as e: user_info.log2txt( '单击显示不合格项目<ID={}>时出现错误<show_unpass_item>:<{}>'.format( unpass_id, e)) pass except Exception as e: user_info.log2txt(e) if self.person.text() != '' and self.person.text( ) != user_info.get_value('USERNAME'): self.btn_save.setEnabled(False) self.pre_check.setEnabled(False) self.btn_slparts.setEnabled(False) else: self.btn_save.setEnabled(True) self.pre_check.setEnabled(True) self.btn_slparts.setEnabled(True)
def to_excel(self): """export to *.xls file""" try: row_count = self.test_result_model.rowCount() col_count = len(self.test_result_fields) directory = QFileDialog.getExistingDirectory(self, "选择存放的位置") if directory: filename = join(directory, 'test_result.xlsx') wkb = Workbook(filename) sht = wkb.add_worksheet("test_result") sht.write_row('A1', self.test_result_fields) for r in range(row_count): for c in range(col_count): sht.write(r + 1, c, self.test_result_model.item(r, c).text()) wkb.close() QMessageBox.information(self, '完成', '文件地址:{}'.format(filename)) except Exception as e: user_info.log2txt('导出成excel时发生错误:{}'.format(e)) pass
def save_method(self): deal_id = self.line_deal_id.text() id = self.line_unpass_id.text() method = self.txt_deal_method.toPlainText() deal_qty = self.line_deal_qty.text() deal_qty = float(deal_qty) if deal_qty else 0 deal_date = self.date_deal.text() person = user_info.get_value('USERNAME') wr_time = datetime.now().__format__("%Y-%m-%d %H:%M") if deal_date and deal_qty and method: sql = "INSERT INTO fcase_deallog VALUES('{}',{},'{}','{}','{}','{}','{}')" \ "".format(deal_id, id, method, deal_qty, deal_date, person, wr_time) db = MysqlDb() with db: try: db.modify_db(sql) self.parent.show_deal_method() self.close() except Exception as e: user_info.log2txt('添加新的处理(id=<{}>)记录时<error>: {}'.format( id, e))
def processtrigger_rclick(self, act): row = self.test_data_view.currentIndex().row() if row != -1: try: db = MysqlDb() with db: batch = self.model.item(row, 0).text() if act.text() == '刷新': trans = [] for i in range(1, self.model.columnCount()): field = self.model.horizontalHeaderItem(i).text() v = self.model.item(row, i).text() if field == '表面判定' or field == 'RoSH': v = 1 if v.upper() == 'PASS' else 0 if v: field_v = "{}='{}'".format(field, v) trans.append(field_v) sql = "UPDATE 常规性能 SET {} WHERE 批号='{}'".format(','.join(trans), batch) db.modify_db(sql) QMessageBox.information(self, '提示', '操作已完成!') elif act.text() == '删除': reply = QMessageBox.question(self, 'Message', '确认删除<{}>?'.format(batch), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: sql_1 = "DELETE FROM 常规性能 WHERE 批号='{}'".format(batch) sql_2 = "DELETE FROM 产品信息 WHERE 批号='{}'".format(batch) try: db._cursor.execute(sql_1) db._cursor.execute(sql_2) db._cnn.commit() QMessageBox.information(self, '提示', '操作已完成!') except Exception as e1: db._cnn.rollback() QMessageBox.warning(self, '错误', '删除失败') user_info.log2txt('删除检测数据时发生错误:{}'.format(e1)) self.test_search() except Exception as e2: QMessageBox.warning(self, '错误', '操作失败') user_info.log2txt('更新检测数据时发生错误:{}'.format(e2))
def change_info(self): user = self.line_chg_user.text() pwd_again = self.line_chg_pwd.text() if user: db = MysqlDb() with db: sql = "SELECT 密码 FROM 用户 WHERE 用户名='{}'".format(user) try: _rst = db.get_rst(sql) if _rst: check_pwd = _rst[0]['密码'] if pwd_again == check_pwd: sql = "select 部门,邮箱,评审权限 from 用户 where 用户名='%s'" % user user_info_rst = db.get_rst(sql) _PARTS = db.get_rst('select 部门 from 部门') PART = user_info_rst[0]['部门'] EMAIL = user_info_rst[0]['邮箱'] PRIVILEGE = user_info_rst[0]['评审权限'] user_info._init() user_info.set_value('USERNAME', user) user_info.set_value('PART', PART) user_info.set_value('EMAIL', EMAIL) user_info.set_value('PRIVILEGE', PRIVILEGE) user_info.set_value('PARTS', [p['部门'] for p in _PARTS]) login_info = ' >>>当前用户:<%s> %s' % (PART, user) self.parent.setWindowTitle( self.parent.windowTitle()[:8] + login_info) self.parent.tab_changed(0) self.parent.tabWidget.setCurrentIndex(0) else: QMessageBox.warning(self, '输入错误', '密码输入错误!') self.show() else: QMessageBox.warning(self, '输入错误', '无该用户!') self.show() except Exception as e: user_info.log2txt('更换用户时发生错误:<{}>'.format(e)) else: self.show()
def processtrigger_tbl_unpass(self, act): row = self.tbl_unpass.currentIndex().row() if row != -1: unpass_id = int(self.model_unpass.item(row, 0).text()) to_parts = user_info.get_value('PARTS')[:-1] sql = '' try: _db = MysqlDb() with _db: if act.text() in to_parts: sql = "UPDATE 状态标记 SET caseto_by_QA='{}' WHERE ID={}".format( act.text(), unpass_id) elif act.text() == 'Delete': sql = 'DELETE FROM 不合格品登记 WHERE ID = %d' % unpass_id try: _db.modify_db("DELETE FROM 状态标记 WHERE ID = %d" % unpass_id) except Exception as e: user_info.log2txt(e) elif act.text() == 'Start Department Review': sql = "UPDATE 状态标记 SET b_m_rev=True WHERE ID={}".format( unpass_id) elif act.text() == '刷新': self.set_tbl_unpass(TBL_UNPASS_SQL) elif act.text() == '输入处理意见': idea_dia = IdeaDialog(self, user_info.get_value('USERNAME'), user_info.get_value('PART'), unpass_id) idea_dia.show() _db.modify_db(sql) self.fuzzy_search() except Exception as e: user_info.log2txt( '右键操作不合格清单列表<ID={}>时出现错误<processtrigger_tbl_unpass>:<{}>'. format(unpass_id, e)) pass
def tab_changed(self, index): self.txt_pre_info.setPlainText('') self.show_review_doc.clear() if index == 0: if user_info.get_value('PART') == '质量部': self.save_unpass.setVisible(True) self.show_test_win.setVisible(True) else: self.save_unpass.setVisible(False) self.show_test_win.setVisible(False) elif index == 1: # set privileges if not user_info.get_value('PRIVILEGE'): self.btn_save_pre.setEnabled(False) try: self._load_tbl_pre_data() except Exception as e: user_info.log2txt(e) self.txt_pre_info.setEnabled(False) self.btn_save_pre.clicked.connect(self.save_pre_info) elif index == 2: self._load_on_follow_view_data() self.on_follow_view.clicked.connect(self.show_deal_method) self.follow_btn_search.clicked.connect(self.search_follow_item)