Exemplo n.º 1
0
 def parts_need(self):
     check_list = self.groupBox.findChildren(QCheckBox)
     parts = ','.join(
         [check.objectName() for check in check_list if check.isChecked()])
     unpass_id = self.parent.ID.text()
     if unpass_id:
         db = MysqlDb()
         with db:
             sql = "update 状态标记 set part_need_review='{}' where ID={}".format(
                 parts, unpass_id)
             db.modify_db(sql)
         self.parent.parts.setText(parts)
Exemplo n.º 2
0
 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, '警告', '缺少必要产品信息!')
Exemplo n.º 3
0
    def __init__(self, parent, username, department, deal_id):
        super().__init__(parent)
        self.ctl_name_zh = {
            'txt_tec_part': '技术部',
            'txt_pro_part': '工艺部',
            'txt_qc_part': '质量部',
            'txt_tec_support': '技术支持部'
        }
        self.username = username
        self.department = department
        self.deal_id = deal_id
        self.parent = parent
        self.setupUi(self)
        self.ctl = self.findChild(
            QTextEdit,
            dict(zip(self.ctl_name_zh.values(),
                     self.ctl_name_zh.keys()))[self.department])
        db = MysqlDb()
        with db:
            sql = 'SELECT {} FROM 不合格品登记 WHERE ID={}'.format(
                ','.join([part + '意见' for part in self.ctl_name_zh.values()]),
                deal_id)
            flag_sql = 'SELECT 责任自审 FROM 不合格品登记 WHERE ID=%d' % deal_id
            rst = db.get_rst(sql)
            flag_rst = db.get_rst(flag_sql)
        for i in range(len(rst[0])):
            eval('self.%s.setPlainText(list(rst[0].values())[i])' %
                 list(self.ctl_name_zh.keys())[i])

        start_type_idea_flag = flag_rst[0]['责任自审']  # if 责任自审未完成 then 不能输入处理意见
        if not start_type_idea_flag:
            self.setWindowTitle(self.windowTitle() +
                                '>>>当前不合格品处理尚未完成分析、预防及改善办法提交')
        for ctl in self.findChildren(QTextEdit):
            if self.ctl_name_zh[
                    ctl.objectName()] == department and start_type_idea_flag:
                ctl.setReadOnly(False)
            else:
                if not start_type_idea_flag:
                    self.btn_deal_method.setEnabled(False)
                    self.btn_sign_name.setEnabled(False)
                    self.btn_save_idea.setEnabled(False)
                ctl.setReadOnly(True)
        self.btn_save_idea.clicked.connect(self.save_idea)
        self.btn_sign_name.clicked.connect(self.sign)
        self.btn_deal_method.clicked.connect(self.add_methods)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 def __init__(self, parent):
     super().__init__(parent)
     self.setupUi(self)
     db = MysqlDb()
     with db:
         self.rst = db.get_rst("SELECT DISTINCT 客户,产品型号 FROM 产品信息")
         count_rst = db.get_rst("SELECT MAX(ID) AS above_id FROM 不合格品登记")
         count = count_rst[0]['above_id']
     self.new_id.setText(str(count + 1))
     self.comb_new_coustom.addItems(set(r['客户'] for r in self.rst))
     self.comb_new_coustom.setCurrentIndex(-1)
     self.comb_new_coustom.currentTextChanged.connect(
         self.set_unpassname_items)
     self.new_unpasstype.addItems(('制程不合格', '退货不合格', '来料不合格'))
     self.parent = parent
     self.date_produce.setDate(QDate.currentDate())
     self.new_unpass_qty.setValidator(QDoubleValidator())
     self.btn_clear.clicked.connect(self.clear_unpass_info)
     self.btn_save_new_unpass.clicked.connect(self.save_new_unpass)
Exemplo n.º 6
0
 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))
Exemplo n.º 7
0
    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, '警告', '缺少必要信息,请完善后保存!')
Exemplo n.º 8
0
 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))
Exemplo n.º 9
0
 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()
Exemplo n.º 10
0
    def save_idea(self):
        from mainwindow import FIELDS_IN_TAB3
        contents = self.ctl.toPlainText().strip()
        if contents != '':
            db = MysqlDb()
            with db:
                sql = "UPDATE 不合格品登记 SET {}意见='{}' WHERE ID={}".format(
                    self.department, contents, self.deal_id)
                db.modify_db(sql)

                # start write PDF
                fields = list(FIELDS_IN_TAB3.values())[:5]
                info = []
                fd = ','.join(FIELDS_IN_TAB3.values())
                sql = "SELECT {} FROM 不合格品登记 a INNER JOIN 状态标记 b ON a.ID=b.ID WHERE a.ID={}" \
                      "".format(fd, self.deal_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))
            write2pdf(fields, info, d)  # write PDF out to output/file_name.pdf

            # start use wechat send message
            batch, _, pro_name, _, _ = info
            filename = pro_name + '-' + batch + '.pdf'
            wechat = SmsWechat()
            wechat.send_message(msg_type='text',
                                contents='{} {}更新不良品评审单(批号:{})了,请查看PDF!'
                                ''.format(self.department, self.username,
                                          batch))
            wechat.send_message(msg_type='file',
                                file_obj=open('output/{}'.format(filename),
                                              'rb'))

            self.parent.fuzzy_search()
            QMessageBox.information(self, 'Update success', '本次更新完成!')
Exemplo n.º 11
0
    def __init__(self, parent):
        super().__init__(parent)
        self.setupUi(self)
        self.parent = parent
        self.date_produce.setDate(QDate.currentDate())
        self.date_test.setDate(QDate.currentDate())
        self.btn_test_clear.clicked.connect(self.clear_pro_info)
        self.btn_test_tounpass.clicked.connect(self.to_unpass)
        self.btn_search_need_modi.clicked.connect(self.test_search)
        self.test_data_view.setContextMenuPolicy(Qt.CustomContextMenu)
        self.test_data_view.customContextMenuRequested.connect(self.rclick_test_data_view)

        self.test_data_view.setSelectionMode(QTableView.SingleSelection)
        self.test_data_view.setStyleSheet(
            "selection-color: rgb(255, 0, 127);\nselection-background-color: rgb(85, 255, 127);")

        db = MysqlDb()
        with db:
            self.rst = db.get_rst("SELECT DISTINCT 客户,产品型号,颜色 FROM 产品信息")
        self.comb_test_coustomer.addItems(set(r['客户'] for r in self.rst))
        self.comb_test_coustomer.setCurrentIndex(-1)
        self.comb_test_coustomer.currentTextChanged.connect(self.set_pro_type_items)
        self.comb_pro_type.currentTextChanged.connect(self.set_pro_color_items)
        self.btn_test_save.clicked.connect(self.save_pro_info)
Exemplo n.º 12
0
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'part_need_review.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QCheckBox, QPushButton, QDialog
from getdb import MysqlDb

db = MysqlDb()
with db:
    rst = db.get_rst('SELECT 部门 from 部门')
PARTS = [p['部门'] for p in rst]
PARTS.remove('总经办')


class Ui_parts_need_review(object):
    def setupUi(self, parts_need_review):
        parts_need_review.setObjectName("parts_need_review")
        parts_need_review.resize(200, 304)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icons/user.ico"), QtGui.QIcon.Normal,
                       QtGui.QIcon.Off)
        parts_need_review.setWindowIcon(icon)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(parts_need_review)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.groupBox = QtWidgets.QGroupBox(parts_need_review)
        self.groupBox.setObjectName("groupBox")