Esempio n. 1
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 854)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addProductButton = QtWidgets.QPushButton(Form)
        self.addProductButton.setObjectName("addProductButton")
        self.horizontalLayout_5.addWidget(self.addProductButton)
        self.selectProductButton = QtWidgets.QPushButton(Form)
        self.selectProductButton.setObjectName("selectProductButton")
        self.horizontalLayout_5.addWidget(self.selectProductButton)
        self.alterProductButton = QtWidgets.QPushButton(Form)
        self.alterProductButton.setObjectName("alterProductButton")
        self.horizontalLayout_5.addWidget(self.alterProductButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteProductButton = QtWidgets.QPushButton(Form)
        self.deleteProductButton.setObjectName("deleteProductButton")
        self.horizontalLayout_3.addWidget(self.deleteProductButton)
        self.documentButton = QtWidgets.QPushButton(Form)
        self.documentButton.setObjectName("documentButton")
        self.horizontalLayout_3.addWidget(self.documentButton)
        self.selectComponentButton = QtWidgets.QPushButton(Form)
        self.selectComponentButton.setObjectName("selectComponentButton")
        self.horizontalLayout_3.addWidget(self.selectComponentButton)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()
        # hsj 自动义的tableModel
        headerRow = [
            "产品编号", "产品名称", "产品代号", "批次编号", "库存数量", "接收日期", "接收人", "接收单位",
            "交付日期", "交付人", "交付单位"
        ]
        self.queryModel = MySearchTableModel("T_Product_New", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        self.comboBox.setCurrentIndex(0)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)
class InStorageWidget(MySearchWidget):
    def __init__(self):
        super().__init__()
        self.select_conditions = ["ProductID", "InNO"]

    def setupUi(self, InStorageForm):
        InStorageForm.setObjectName("InStorageForm")
        InStorageForm.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(InStorageForm)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(InStorageForm)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addInStorageButton = QtWidgets.QPushButton(InStorageForm)
        self.addInStorageButton.setObjectName("addInStorageButton")
        self.horizontalLayout_5.addWidget(self.addInStorageButton)
        self.selectInStorageInfo = QtWidgets.QPushButton(InStorageForm)
        self.selectInStorageInfo.setObjectName("selectInStorageInfo")
        self.horizontalLayout_5.addWidget(self.selectInStorageInfo)
        self.alterInStorageInfo = QtWidgets.QPushButton(InStorageForm)
        self.alterInStorageInfo.setObjectName("alterInStorageInfo")
        self.horizontalLayout_5.addWidget(self.alterInStorageInfo)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteInStorageInfo = QtWidgets.QPushButton(InStorageForm)
        self.deleteInStorageInfo.setObjectName("deleteInStorageInfo")
        self.horizontalLayout_3.addWidget(self.deleteInStorageInfo)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(InStorageForm)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(InStorageForm)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(InStorageForm)
        self.comboBox.setInsertPolicy(QtWidgets.QComboBox.InsertAtTop)
        self.comboBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.tableView = QtWidgets.QTableView(InStorageForm)
        self.tableView.setObjectName("tableView")
        self.verticalLayout.addWidget(self.tableView)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(InStorageForm)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(InStorageForm)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(InStorageForm)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(InStorageForm)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(InStorageForm)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(InStorageForm)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(InStorageForm)
        self.comboBox.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(InStorageForm)

    def retranslateUi(self, InStorageForm):
        _translate = QtCore.QCoreApplication.translate
        InStorageForm.setWindowTitle(_translate("InStorageForm", "入库管理"))
        self.label.setText(_translate("InStorageForm", "入库信息查询"))
        self.addInStorageButton.setText(_translate("InStorageForm", "新建入库信息"))
        self.selectInStorageInfo.setText(_translate("InStorageForm", "查看产品入库信息"))
        self.alterInStorageInfo.setText(_translate("InStorageForm", "修改入库信息"))
        self.deleteInStorageInfo.setText(_translate("InStorageForm", "删除入库信息"))
        self.searchButton.setText(_translate("InStorageForm", "查询"))
        self.comboBox.setItemText(0, _translate("InStorageForm", "按产品编号查询"))
        self.comboBox.setItemText(1, _translate("InStorageForm", "按入库编号查询"))
        self.label_2.setText(_translate("InStorageForm", "跳转至第"))
        self.jumpEdit.setText(_translate("InStorageForm", "1"))
        self.totalPageLabel.setText(_translate("InStorageForm", "/  " + str(self.queryModel.totalPage) + "  页"))
        self.jumpButton.setText(_translate("InStorageForm", "跳转"))
        self.previousButton.setText(_translate("InStorageForm", "上一页"))
        self.nextButton.setText(_translate("InStorageForm", "下一页"))
        # tableView数据设置
        headerRow = ["入库编号", "产品编号", "入库库房", "入库日期", "入库数量", "登记人", "出库编号"]
        self.tableView.setModel(self.queryModel)
        self.queryModel = MySearchTableModel("T_In_Detail", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        # 按钮绑定事件
        # 增加
        self.addInStorageButton.clicked.connect(lambda: self.addButtonEvent(AddInStorage()))
        # 查找
        self.searchButton.clicked.connect(self.searchButtonEvent)
        # 查看
        self.selectInStorageInfo.clicked.connect(lambda: self.selectButtonEvent(SelectINStorage()))
        # 修改
        self.alterInStorageInfo.clicked.connect(lambda: self.updateButtonEvent(AlterInStorage()))

        # 下面是无需改动的按钮
        # 删除按钮
        self.deleteInStorageInfo.clicked.connect(self.deleteButtonEvent)
        # 上一页
        self.previousButton.clicked.connect(self.preButtonEvent)
        # 下一页
        self.nextButton.clicked.connect(self.nextButtonEvent)
        # 跳转按钮
        self.jumpButton.clicked.connect(self.jumpButtonEvent)
        # 添加查询
        self.searchButton.clicked.connect(self.searchButtonEvent)

    def addButtonEvent(self, Widget):

        logger = logToFile()
        UserId = getCurrentUserId()
        tableName = self.queryModel.table
        logger.info("用户:" + str(UserId) + " 点击了添加按钮,试图在 " + " 产品入库 " + " 表中添加数据项")

        form = QDialog()
        w = Widget
        w.setupUi(form)
        form.show()
        a = form.exec_()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()
            self.updateUI()

    def selectButtonEvent(self, Widget):
        """
        hsj 根据批次中的产品编号查询产品详细信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()
        productDiglog = Widget
        form = QDialog()
        productDiglog.setupUi(form)
        productDiglog.setData(result)
        form.show()
        form.exec()

    def updateButtonEvent(self, Widget):
        """
        hsj 修改产品批次信息
        :param Widget: 要显示的窗体
        :return:
        """

        logger = logToFile()
        UserId = getCurrentUserId()
        tableName = self.queryModel.table
        result = self.queryModel.selectSingleTable()
        logger.info("用户:" + str(UserId) + " 点击了更新按钮,试图更新 " + " 产品入库 " + "表中的原数据:" + str(result))

        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()
        batchDialog = Widget
        form = QDialog()
        batchDialog.setupUi(form)
        batchDialog.updateData(result, self.queryModel)
        form.show()
        a = form.exec()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()

    def deleteButtonEvent(self):
        """
        hsj 删除批次按钮绑定事件
        :return:
        """
        logger = logToFile()
        UserId = getCurrentUserId()
        data = self.queryModel.getAllCheckedData()
        tableName = self.queryModel.table
        logger.info("用户:" + str(UserId) + " 点击了删除按钮,试图删除 " + " 产品入库 "  + " 表中的数据:" + str(data))

        # print(self.queryModel.checkList.count("Checked"))
        # 如果没有选中数据,则提示无数据
        if self.queryModel.checkList.count("Checked") == 0:
            logger.info("用户:" + str(UserId) + " 删除失败(没有选择要删除的数据)")
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!", QMessageBox.Yes, QMessageBox.Yes)
            return
        a = QMessageBox.information(QDialog(), "提示", "是否确认删除?", QMessageBox.Yes, QMessageBox.No)
        if a == QMessageBox.No:
            logger.info("用户:" + str(UserId) + " 取消了删除")
            return
        self.queryModel.deleteIn()
        self.queryModel.update()
        self.updateBottomWidget()
Esempio n. 3
0
class SelectProductWidget(MySearchWidget):
    def __init__(self):
        super(SelectProductWidget, self).__init__()
        self.select_conditions = ["ProductName", "Registerer", "BatchNO"]

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 854)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addProductButton = QtWidgets.QPushButton(Form)
        self.addProductButton.setObjectName("addProductButton")
        self.horizontalLayout_5.addWidget(self.addProductButton)
        self.selectProductButton = QtWidgets.QPushButton(Form)
        self.selectProductButton.setObjectName("selectProductButton")
        self.horizontalLayout_5.addWidget(self.selectProductButton)
        self.alterProductButton = QtWidgets.QPushButton(Form)
        self.alterProductButton.setObjectName("alterProductButton")
        self.horizontalLayout_5.addWidget(self.alterProductButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteProductButton = QtWidgets.QPushButton(Form)
        self.deleteProductButton.setObjectName("deleteProductButton")
        self.horizontalLayout_3.addWidget(self.deleteProductButton)
        self.documentButton = QtWidgets.QPushButton(Form)
        self.documentButton.setObjectName("documentButton")
        self.horizontalLayout_3.addWidget(self.documentButton)
        self.selectComponentButton = QtWidgets.QPushButton(Form)
        self.selectComponentButton.setObjectName("selectComponentButton")
        self.horizontalLayout_3.addWidget(self.selectComponentButton)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()
        # hsj 自动义的tableModel
        headerRow = [
            "产品编号", "产品名称", "产品代号", "批次编号", "库存数量", "接收日期", "接收人", "接收单位",
            "交付日期", "交付人", "交付单位"
        ]
        self.queryModel = MySearchTableModel("T_Product_New", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        self.comboBox.setCurrentIndex(0)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "产品信息创建"))
        self.addProductButton.setText(_translate("Form", "新建产品信息"))
        self.selectProductButton.setText(_translate("Form", "查看产品信息"))
        self.alterProductButton.setText(_translate("Form", "修改产品信息"))
        self.deleteProductButton.setText(_translate("Form", "删除产品信息"))
        self.documentButton.setText(_translate("Form", "查看文档"))
        self.selectComponentButton.setText(_translate("Form", "查看产品组件"))
        self.searchButton.setText(_translate("Form", "查询"))
        self.comboBox.setItemText(0, _translate("Form", "按产品名称查询"))
        self.comboBox.setItemText(1, _translate("Form", "按接收人查询"))
        self.comboBox.setItemText(2, _translate("Form", "按批次号查询"))
        self.label_2.setText(_translate("Form", "跳转至第"))
        self.jumpEdit.setText(_translate("Form", "1"))
        self.totalPageLabel.setText(
            _translate("Form", "/  " + str(self.queryModel.totalPage) + "  页"))
        self.jumpButton.setText(_translate("Form", "跳转"))
        self.previousButton.setText(_translate("Form", "上一页"))
        self.nextButton.setText(_translate("Form", "下一页"))

    def bindButton(self):
        """
        hsj 绑定按钮
        :return:
        """
        # # 删除按钮
        self.deleteProductButton.clicked.connect(self.deleteButtonEvent)
        # # 新建按钮
        self.addProductButton.clicked.connect(
            lambda: self.addButtonEvent(AddProductWidget()))
        # # 查看产品
        self.selectProductButton.clicked.connect(
            lambda: self.selectDetailButtonEvent(AddProductWidget()))
        # 修改按钮
        self.alterProductButton.clicked.connect(
            lambda: self.updateButtonEvent(AddProductWidget()))
        # 上一页
        self.previousButton.clicked.connect(self.preButtonEvent)
        # 下一页
        self.nextButton.clicked.connect(self.nextButtonEvent)
        # 跳转按钮
        self.jumpButton.clicked.connect(self.jumpButtonEvent)
        # 添加查询
        self.searchButton.clicked.connect(self.searchButtonEvent)
        self.documentButton.clicked.connect(self.selectDocumentEvent)

        # self.selectComponentButton.clicked.connect(self.selectComponentButtonEvent)
        self.selectComponentButton.clicked.connect(
            self.selectComponentButtonEventTest)

    def selectComponentButtonEventTest(self):
        a = self.isCorrect()
        if a == 0:
            return
        productID, productName = self.queryModel.getSelectedID()
        t = TreeWidget(productID, productName)
        if not t.isNone:
            t.show()
            t.exec()

    def selectDocumentEvent(self):
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()
        path = result[-1]
        import os
        if path == "选择文档" or path == "" or not os.path.isfile(path):
            QMessageBox.information(QDialog(), "提示", "文件不存在!", QMessageBox.Yes,
                                    QMessageBox.Yes)
            return
        os.startfile(path)
        # QMessageBox.information(QDialog(), "提示", "文件已打开!", QMessageBox.Yes, QMessageBox.Yes)

    def selectComponentButtonEvent(self):
        """
       hsj 搜索产品的相关组件
       :return:
       """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        select_num = self.queryModel.selectNum()
        db = openDB()
        queryModel = QSqlQueryModel()
        query = QSqlQuery()
        sql = "SELECT * FROM T_ProductComponent_New WHERE ProductID = '%s'" % (
            self.queryModel.data_list[select_num][0])
        # print(sql)
        query.exec(sql)
        if not query.next():
            QMessageBox.information(QDialog(), "提示", "该产品无其他组件!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        queryModel.setQuery(
            "SELECT * FROM T_ProductComponent_New WHERE ProductID = '%s'" %
            (self.queryModel.data_list[select_num][0]))
        headerRow = [
            "组件ID", "产品ID", "组件代号", "组件名称", "父节点ID", "组件类型", "组件数量", "寿命类型",
            "寿命", "据到期提醒", "最初维保时间", "维保间隔", "距维保提醒"
        ]
        for i in range(len(headerRow)):
            queryModel.setHeaderData(i, Qt.Horizontal, headerRow[i])
        form = QDialog()
        tableView = QTableView()
        tableView.setModel(queryModel)
        tableView.show()
        tableView.horizontalHeader().setStretchLastSection(True)
        layout = QVBoxLayout()
        layout.addWidget(tableView)
        form.setLayout(layout)
        form.showMaximized()
        form.exec()

    def deleteButtonEvent(self):
        """
        hsj 删除批次按钮绑定事件
        :return:
        """
        # print(self.queryModel.checkList.count("Checked"))
        # 如果没有选中数据,则提示无数据
        logger = logToFile()
        UserId = getCurrentUserId()
        data = self.queryModel.getAllCheckedData()
        tableName = self.queryModel.table
        logger.info("用户:" + str(UserId) + " 点击了删除按钮,试图删除 " + str(tableName) +
                    " 表中的数据:" + str(data))
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            logger.info("用户:" + str(UserId) + " 删除失败(没有选择要删除的数据)")
            return
        a = QMessageBox.information(QDialog(), "提示", "删除产品将会导致关联的数据删除,是否确认删除?",
                                    QMessageBox.Yes, QMessageBox.No)
        if a == QMessageBox.No:
            return
        logger.info("用户:" + str(UserId) + " 删除了" + str(tableName) + "中选中的数据:" +
                    str(data))

        self.queryModel.deleteProduct()
        # self.queryModel.searchRefreshPage()
        self.updateBottomWidget()
        self.queryModel.refreshPage()
        self.queryModel.update()
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addComponentButton = QtWidgets.QPushButton(Form)
        self.addComponentButton.setObjectName("addComponentButton")
        self.horizontalLayout_5.addWidget(self.addComponentButton)
        self.selectSubComponent = QtWidgets.QPushButton(Form)
        self.selectSubComponent.setObjectName("selectSubComponent")
        self.horizontalLayout_5.addWidget(self.selectSubComponent)
        self.alterComponentButton = QtWidgets.QPushButton(Form)
        self.alterComponentButton.setObjectName("alterComponentButton")
        self.horizontalLayout_5.addWidget(self.alterComponentButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteComponentButton = QtWidgets.QPushButton(Form)
        self.deleteComponentButton.setObjectName("deleteComponentButton")
        self.horizontalLayout_3.addWidget(self.deleteComponentButton)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        # self.tableView = QtWidgets.QTableView(Form)
        # self.tableView.setObjectName("tableView")
        # self.verticalLayout.addWidget(self.tableView)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()


        # hsj 自动义的tableModel
        headerRow = ["ID", "产品ID", "组件名称", "组件类型ID", "父节点ID", "排序索引", "是否寿命提醒","寿命(天)", "寿命起始日期", "据到期提醒(天)", "使用次数限制", "最多使用次数", "已使用次数", "创建人员ID", "创建时间", "修改人员ID", "修改时间", "备注"]
        self.queryModel = MySearchTableModel("T_Product_Component", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)


        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)
class KnowledgeBaseManage(MySearchWidget):
    def __init__(self):
        super(KnowledgeBaseManage, self).__init__()
        self.select_conditions = [
            "Num", "Title", "Source", "Publisher", "Rtime", "Etime",
            "Readrange"
        ]

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addBatchButton = QtWidgets.QPushButton(Form)
        self.addBatchButton.setObjectName("addBatchButton")
        self.horizontalLayout_5.addWidget(self.addBatchButton)
        self.selectProduct = QtWidgets.QPushButton(Form)
        self.selectProduct.setObjectName("selectProduct")
        self.horizontalLayout_5.addWidget(self.selectProduct)
        self.alterVBatchButton = QtWidgets.QPushButton(Form)
        self.alterVBatchButton.setObjectName("alterVBatchButton")
        self.horizontalLayout_5.addWidget(self.alterVBatchButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteBatchButton = QtWidgets.QPushButton(Form)
        self.deleteBatchButton.setObjectName("deleteBatchButton")
        self.horizontalLayout_3.addWidget(self.deleteBatchButton)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()

        #czq 借鉴hsj的tableModel
        headerRow = ["序号", "标题", "来源", "发布人", "发布时间", "过期时间", "阅读范围", "内容"]
        self.queryModel = MySearchTableModel("T_Knowladge_Base_Mangement",
                                             headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        #self.comboBox.setCurrentIndex(0)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "知识库管理"))
        self.addBatchButton.setText(_translate("Form", "新增知识"))
        self.selectProduct.setText(_translate("Form", "查看知识"))
        self.alterVBatchButton.setText(_translate("Form", "修改知识"))
        self.deleteBatchButton.setText(_translate("Form", "删除知识"))
        self.searchButton.setText(_translate("Form", "查询"))
        self.comboBox.setItemText(0, _translate("Form", "按序号查询"))
        self.comboBox.setItemText(1, _translate("Form", "按标题查询"))
        self.comboBox.setItemText(2, _translate("Form", "按来源查询"))
        self.comboBox.setItemText(3, _translate("Form", "按发布人查询"))
        self.comboBox.setItemText(4, _translate("Form", "按发布时间查询"))
        self.comboBox.setItemText(5, _translate("Form", "按过期时间查询"))
        self.comboBox.setItemText(6, _translate("Form", "按阅读范围查询"))
        self.label_2.setText(_translate("Form", "跳转至第"))
        self.jumpEdit.setText(_translate("Form", "1"))

        # 更新页码总页数 复制进去
        self.totalPageLabel.setText(
            _translate("Form", "/  " + str(self.queryModel.totalPage) + "  页"))

        self.jumpButton.setText(_translate("Form", "跳转"))
        self.previousButton.setText(_translate("Form", "上一页"))
        self.nextButton.setText(_translate("Form", "下一页"))

    def bindButton(self):
        """
         绑定按钮
        :return:
        """
        # 把需要使用的窗体传进去
        # 新建按钮
        self.addBatchButton.clicked.connect(
            lambda: self.addButtonEvent(AddKBMWidge()))
        # 查看产品
        self.selectProduct.clicked.connect(
            lambda: self.selectButtonEvent(SelectrKnowledgeBase()))
        # 修改批次
        self.alterVBatchButton.clicked.connect(
            lambda: self.updateButtonEvent(AddKBMWidge()))

        # 下面是无需改动的按钮
        # 删除按钮
        self.deleteBatchButton.clicked.connect(self.deleteButtonEvent)
        # 上一页
        self.previousButton.clicked.connect(self.preButtonEvent)
        # 下一页
        self.nextButton.clicked.connect(self.nextButtonEvent)
        # 跳转按钮
        self.jumpButton.clicked.connect(self.jumpButtonEvent)
        # 添加查询
        self.searchButton.clicked.connect(self.searchButtonEvent)

    def selectButtonEvent(self, Widget):
        """
        hsj 根据批次中的产品Id查询产品详细信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTableForeign()
        productDiglog = Widget
        form = QDialog()
        productDiglog.setupUi(form)
        productDiglog.setData(result)
        form.show()
        form.exec()
class SearchProductComponentWidget(MySearchWidget):
    def __init__(self):
        super(SearchProductComponentWidget, self).__init__()
        self.select_conditions = ["ID", "ProductNO", "parentID"]

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addComponentButton = QtWidgets.QPushButton(Form)
        self.addComponentButton.setObjectName("addComponentButton")
        self.horizontalLayout_5.addWidget(self.addComponentButton)
        self.selectSubComponent = QtWidgets.QPushButton(Form)
        self.selectSubComponent.setObjectName("selectSubComponent")
        self.horizontalLayout_5.addWidget(self.selectSubComponent)
        self.alterComponentButton = QtWidgets.QPushButton(Form)
        self.alterComponentButton.setObjectName("alterComponentButton")
        self.horizontalLayout_5.addWidget(self.alterComponentButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteComponentButton = QtWidgets.QPushButton(Form)
        self.deleteComponentButton.setObjectName("deleteComponentButton")
        self.horizontalLayout_3.addWidget(self.deleteComponentButton)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        # self.tableView = QtWidgets.QTableView(Form)
        # self.tableView.setObjectName("tableView")
        # self.verticalLayout.addWidget(self.tableView)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()


        # hsj 自动义的tableModel
        headerRow = ["ID", "产品ID", "组件名称", "组件类型ID", "父节点ID", "排序索引", "是否寿命提醒","寿命(天)", "寿命起始日期", "据到期提醒(天)", "使用次数限制", "最多使用次数", "已使用次数", "创建人员ID", "创建时间", "修改人员ID", "修改时间", "备注"]
        self.queryModel = MySearchTableModel("T_Product_Component", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)


        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "产品组件查询"))
        self.addComponentButton.setText(_translate("Form", "新建组件"))
        self.selectSubComponent.setText(_translate("Form", "查看子组件"))
        self.alterComponentButton.setText(_translate("Form", "修改组件信息"))
        self.deleteComponentButton.setText(_translate("Form", "删除组件"))
        self.searchButton.setText(_translate("Form", "查询"))
        self.comboBox.setItemText(0, _translate("Form", "按ID查询"))
        self.comboBox.setItemText(1, _translate("Form", "按产品ID查询"))
        self.comboBox.setItemText(2, _translate("Form", "按父组件查询"))
        self.label_2.setText(_translate("Form", "跳转至第"))
        self.jumpEdit.setText(_translate("Form", "1"))
        self.totalPageLabel.setText(_translate("Form", "/  " + str(self.queryModel.totalPage) + "  页"))
        self.jumpButton.setText(_translate("Form", "跳转"))
        self.previousButton.setText(_translate("Form", "上一页"))
        self.nextButton.setText(_translate("Form", "下一页"))

    def bindButton(self):
        """
        hsj 绑定按钮
        :return:
        """
        # 删除按钮
        self.deleteComponentButton.clicked.connect(self.deleteButtonEvent)
        # # 新建按钮
        self.addComponentButton.clicked.connect(lambda :self.addButtonEvent(AddComponentWidget()))
        # # 查看产品
        # self.selectProduct.clicked.connect(self.selectDetailProductButtonEvent)
        # 修改批次
        self.alterComponentButton.clicked.connect(lambda :self.updateButtonEvent(AddComponentWidget()))
        # 上一页
        self.previousButton.clicked.connect(self.preButtonEvent)
        # 下一页
        self.nextButton.clicked.connect(self.nextButtonEvent)
        # 跳转按钮
        self.jumpButton.clicked.connect(self.jumpButtonEvent)
        # 添加查询
        self.searchButton.clicked.connect(self.searchButtonEvent)

    def deleteButtonEvent(self):
        """
        hsj 删除批次按钮绑定事件
        :return:
        """
        # print(self.queryModel.checkList.count("Checked"))
        # 如果没有选中数据,则提示无数据
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!", QMessageBox.Yes, QMessageBox.Yes)
            return
        a = QMessageBox.information(QDialog(), "提示", "是否确认删除?", QMessageBox.Yes, QMessageBox.No)
        if a == QMessageBox.No:
            return
        self.queryModel.deleteCompoment()
        self.queryModel.update()
    def setupUi(self, Form):
        """自动生成UI + 表格组件"""
        Form.setObjectName("Form")
        Form.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.widget = QtWidgets.QWidget(Form)
        self.widget.setMinimumSize(QtCore.QSize(600, 0))
        self.widget.setMaximumSize(QtCore.QSize(800, 16777215))
        self.widget.setObjectName("widget")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.widget)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(self.widget)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(self.widget)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(self.widget)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addWidget(self.widget, 0, QtCore.Qt.AlignRight)

        # 中间手动代码部分 表格UI构建
        self.db = QSqlDatabase.addDatabase("QSQLITE")
        self.db.setDatabaseName("./db/ProductManagement_new.db")
        self.db.open()
        self.tableView = QTableView()
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        headerRow = [
            "ID", "组件名称", "DisplayOrder", "创建人员ID", "创建时间", "修改人员ID", "修改时间",
            "备注"
        ]
        self.queryModel = MySearchTableModel("T_Product_ComponentType",
                                             headerRow)
        # self.queryModel.setTable()
        # self.queryModel.setEditStrategy(QSqlTableModel.OnFieldChange)
        # self.queryModel.select()

        # self.queryModel.setHeaderData(0, Qt.Horizontal, "ID")
        # self.queryModel.setHeaderData(1, Qt.Horizontal, "产品ID")
        # self.queryModel.setHeaderData(2, Qt.Horizontal, "批次号")
        # self.queryModel.setHeaderData(3, Qt.Horizontal, "交付日期")
        # self.queryModel.setHeaderData(4, Qt.Horizontal, "交付人员")
        # self.queryModel.setHeaderData(5, Qt.Horizontal, "接收单位")
        # self.queryModel.setHeaderData(6, Qt.Horizontal, "接收人员")
        # self.queryModel.setHeaderData(8, Qt.Horizontal, "创建人员ID")
        # self.queryModel.setHeaderData(9, Qt.Horizontal, "创建时间")
        # self.queryModel.setHeaderData(10, Qt.Horizontal, "修改人员ID")
        # self.queryModel.setHeaderData(11, Qt.Horizontal, "修改时间")
        # self.queryModel.setHeaderData(12, Qt.Horizontal, "备注")

        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)

        # self.tableView = QtWidgets.QTableView(Form)
        # self.tableView.setObjectName("tableView")
        # self.verticalLayout.addWidget(self.tableView)
        self.widget_2 = QtWidgets.QWidget(Form)
        self.widget_2.setMaximumSize(QtCore.QSize(600, 16777215))
        self.widget_2.setObjectName("widget_2")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.widget_2)
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(self.widget_2)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(self.widget_2)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(self.widget_2)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(self.widget_2)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(self.widget_2)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(self.widget_2)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        self.verticalLayout.addWidget(self.widget_2, 0, QtCore.Qt.AlignHCenter)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
class MySearchWidget(object):
    def __init__(self):

        # 搜索关键列的列表 一般大小为3
        self.select_conditions = []
        # 在setupUi中进行重写
        self.queryModel = MySearchTableModel("T_Knowladge_Base_Mangement",
                                             ["Num"])
        self.totalPageLabel = QtWidgets.QLabel()
        self.totalPageLabel.setObjectName("totalPageLabel")

        self.jumpEdit = QtWidgets.QLineEdit()
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))

    def setupUi(self, Form):
        pass

    def retranslateUi(self, Form):
        pass

    def updateUI(self):
        """
        hsj 跳转的后更新
        :return:
        """
        self.totalPageLabel.setText("/  " + str(self.queryModel.totalPage) +
                                    "  页")
        self.jumpEdit.setText(str(self.queryModel.currentPage + 1))

    def bindButton(self):
        """
        hsj 绑定按钮
        :return:
        """
        pass

    def deleteButtonEvent(self):
        """
        hsj 删除批次按钮绑定事件
        :return:
        """
        # print(self.queryModel.checkList.count("Checked"))
        # 如果没有选中数据,则提示无数据
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            return
        a = QMessageBox.information(QDialog(), "提示", "是否确认删除?",
                                    QMessageBox.Yes, QMessageBox.No)
        if a == QMessageBox.No:
            return
        self.queryModel.delete()
        self.queryModel.update()

    def addButtonEvent(self, Widget):
        """
        hsj 新建
        :param Widget: 要显示的窗体
        :return:
        """
        form = QDialog()
        w = Widget
        w.setupUi(form)
        form.show()
        a = form.exec_()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()
            self.updateUI()

    def selectButtonEvent(self, Widget):
        """
        hsj 根据批次中的产品Id查询产品详细信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTableForeign()
        #print('re:',result)
        productDiglog = Widget
        form = QDialog()
        productDiglog.setupUi(form)
        productDiglog.setData(result)
        form.show()
        form.exec()

    def updateButtonEvent(self, Widget):
        """
        hsj 修改产品批次信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()
        batchDialog = Widget
        form = QDialog()
        batchDialog.setupUi(form)
        batchDialog.updateData(result, self.queryModel)
        form.show()
        a = form.exec()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()

    def preButtonEvent(self):
        """
        hsj 上一页按钮事件
        :return:
        """
        if self.queryModel.currentPage == 0:
            QMessageBox.information(QDialog(), "提示", "已经是第一页!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            self.queryModel.prePage()
            self.queryModel.update()
            self.updateUI()

    def nextButtonEvent(self):
        """
        hsj 下一页按钮事件
        :return:
        """
        if (self.queryModel.currentPage + 1) == self.queryModel.totalPage:
            QMessageBox.information(QDialog(), "提示", "已经是最后一页!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            self.queryModel.nextPage()
            self.queryModel.update()
            self.updateUI()

    def jumpButtonEvent(self):
        """
        hsj 跳转按钮事件
        :return:
        """
        objectPage = self.jumpEdit.text()
        if not objectPage.isdigit():
            QMessageBox.information(QDialog(), "提示", "跳转输入的不是数字,请正确填写后重试!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            objectPage = int(objectPage)
            if objectPage <= 0 or objectPage > self.queryModel.totalPage:
                QMessageBox.information(QDialog(), "提示", "跳转输入超出范围,请正确填写后重试!",
                                        QMessageBox.Yes, QMessageBox.Yes)
                return
            else:
                self.queryModel.currentPage = objectPage - 1
                self.queryModel.setCurrentData()
                self.queryModel.update()
                self.updateUI()

    def searchButtonEvent(self):
        """
        hsj 输入查询条件查询按钮事件
        :return:
        """
        content = self.searchEdit.text()
        if content == "":
            print(111)
            self.queryModel.refreshPage()
            self.queryModel.update()
        else:
            n = self.comboBox.currentIndex()
            self.queryModel.searchTable(self.select_conditions[n], content)
            self.updateUI()

    def isCorrect(self):
        """
        hsj 判断复选框是否选中一个数据
        :return:
        """
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            return 0
        elif self.queryModel.checkList.count("Checked") > 1:
            QMessageBox.warning(QDialog(), "警告", "数据过多,请选中一条后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            return 0
        else:
            return 1
class MySearchWidget(object):
    def __init__(self):

        # 搜索关键列的列表 一般大小为3
        self.select_conditions = []
        # 在setupUi中进行重写
        self.queryModel = MySearchTableModel("T_Product_New", ["ProductID"])
        self.totalPageLabel = QtWidgets.QLabel()
        self.totalPageLabel.setObjectName("totalPageLabel")

        self.jumpEdit = QtWidgets.QLineEdit()
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))

    def setupUi(self, Form):
        pass

    def retranslateUi(self, Form):
        pass

    def updateUI(self):
        """
        hsj 跳转的后更新
        :return:
        """
        self.totalPageLabel.setText("/  " + str(self.queryModel.totalPage) +
                                    "  页")
        self.jumpEdit.setText(str(self.queryModel.currentPage + 1))

    def bindButton(self):
        """
        hsj 绑定按钮
        :return:
        """
        pass

    def deleteButtonEvent(self):
        """
        hsj 删除批次按钮绑定事件
        :return:
        """
        # print(self.queryModel.checkList.count("Checked"))
        # 如果没有选中数据,则提示无数据
        logger = logToFile()
        UserId = getCurrentUserId()
        data = self.queryModel.getAllCheckedData()
        tableName = self.queryModel.table
        logger.info("用户:" + str(UserId) + " 点击了删除按钮,试图删除 " + str(tableName) +
                    " 表中的数据:" + str(data))
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            logger.info("用户:" + str(UserId) + " 删除失败(没有选择要删除的数据)")
            return
        a = QMessageBox.information(QDialog(), "提示", "是否确认删除?",
                                    QMessageBox.Yes, QMessageBox.No)
        if a == QMessageBox.No:
            logger.info("用户:" + str(UserId) + " 取消了删除")
            return
        logger.info("用户:" + str(UserId) + " 删除了" + str(tableName) + "中选中的数据:" +
                    str(data))

        self.queryModel.delete()
        self.queryModel.update()
        self.updateBottomWidget()

    def addButtonEvent(self, Widget):
        """
        hsj 新建
        :param Widget: 要显示的窗体
        :return:
        """
        # logger = logToFile()
        # UserId = getCurrentUserId()
        # tableName = self.queryModel.table
        # logger.info("用户:" + str(UserId) + " 点击了添加按钮,试图在 " + str(tableName) + " 表中添加数据项")

        form = QDialog()
        w = Widget
        w.setupUi(form)
        form.show()
        a = form.exec_()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()
            self.updateUI()

    # def selectButtonEvent(self, Widget):
    #     """
    #     hsj 根据批次中的产品Id查询产品详细信息
    #     :param Widget: 要显示的窗体
    #     :return:
    #     """
    #     # 判断复选框是否只选中一个
    #     a = self.isCorrect()
    #     if a == 0:
    #         return
    #     result = self.queryModel.selectSingleTableForeign()
    #     productDiglog = Widget
    #     form = QDialog()
    #     productDiglog.setupUi(form)
    #     productDiglog.setData(result)
    #     form.show()
    #     form.exec()

    def updateButtonEvent(self, Widget):
        """
        hsj 修改信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()

        logger = logToFile()
        UserId = getCurrentUserId()
        tableName = self.queryModel.table
        logger.info("用户:" + str(UserId) + " 点击了更新按钮,试图更新 " + str(tableName) +
                    " 表中的原数据:" + str(result))

        batchDialog = Widget
        form = QDialog()
        batchDialog.setupUi(form)
        batchDialog.updateData(result, self.queryModel)
        form.show()
        a = form.exec()

        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()

    def selectDetailButtonEvent(self, Widget):
        """
       hsj 修改产品批次信息
       :param Widget: 要显示的窗体
       :return:
       """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTable()

        batchDialog = Widget
        form = QDialog()
        batchDialog.setupUi(form)
        batchDialog.showData(result, self.queryModel)
        form.show()
        a = form.exec()
        # 如果对话框关闭,则对查询数据进行更行
        if a == 0:
            self.queryModel.refreshPage()
            self.queryModel.update()

    def preButtonEvent(self):
        """
            hsj 上一页按钮事件
            :return:
            """
        if self.queryModel.currentPage == 0:
            QMessageBox.information(QDialog(), "提示", "已经是第一页!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            self.queryModel.prePage()
            self.queryModel.update()
            self.updateUI()

    def nextButtonEvent(self):
        """
        hsj 下一页按钮事件
        :return:
        """
        if (self.queryModel.currentPage + 1) >= self.queryModel.totalPage:
            QMessageBox.information(QDialog(), "提示", "已经是最后一页!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            self.queryModel.nextPage()
            self.queryModel.update()
            self.updateUI()

    def jumpButtonEvent(self):
        """
        hsj 跳转按钮事件
        :return:
        """
        objectPage = self.jumpEdit.text()
        if not objectPage.isdigit():
            QMessageBox.information(QDialog(), "提示", "跳转输入的不是数字,请正确填写后重试!",
                                    QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            objectPage = int(objectPage)
            if objectPage <= 0 or objectPage > self.queryModel.totalPage:
                QMessageBox.information(QDialog(), "提示", "跳转输入超出范围,请正确填写后重试!",
                                        QMessageBox.Yes, QMessageBox.Yes)
                return
            else:
                self.queryModel.currentPage = objectPage - 1
                self.queryModel.setCurrentData()
                self.queryModel.update()
                self.updateUI()

    def searchButtonEvent(self):
        """
        hsj 输入查询条件查询按钮事件
        :return:
        """
        content = self.searchEdit.text()
        if content == "":
            self.queryModel.refreshPage()
            self.queryModel.update()
        else:
            n = self.comboBox.currentIndex()
            self.queryModel.searchTable(self.select_conditions[n], content)
            self.updateUI()

    def isCorrect(self):
        """
        hsj 判断复选框是否选中一个数据
        :return:
        """
        if self.queryModel.checkList.count("Checked") == 0:
            QMessageBox.warning(QDialog(), "警告", "没有数据被选中,请选中后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            return 0
        elif self.queryModel.checkList.count("Checked") > 1:
            QMessageBox.warning(QDialog(), "警告", "数据过多,请选中一条后重试!",
                                QMessageBox.Yes, QMessageBox.Yes)
            return 0
        else:
            return 1

    def updateBottomWidget(self):
        # 更新查询界面底下控件
        self.totalPageLabel.setText("/  " + str(self.queryModel.totalPage) +
                                    "  页")
        self.jumpEdit.setText(str(self.queryModel.currentPage + 1))
Esempio n. 10
0
class FaultDiagnosis(MySearchWidget):
    # 薛程耀
    def __init__(self):
        super(FaultDiagnosis, self).__init__()
        self.select_conditions = ["BatchNO", "ProductID", "ReceiveCompanyName"]

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1171, 813)
        self.verticalLayout = QtWidgets.QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.addBatchButton = QtWidgets.QPushButton(Form)
        self.addBatchButton.setObjectName("addBatchButton")
        self.horizontalLayout_5.addWidget(self.addBatchButton)
        self.alterVBatchButton = QtWidgets.QPushButton(Form)
        self.alterVBatchButton.setObjectName("alterVBatchButton")
        self.horizontalLayout_5.addWidget(self.alterVBatchButton)
        self.horizontalLayout_3.addLayout(self.horizontalLayout_5)
        self.deleteBatchButton = QtWidgets.QPushButton(Form)
        self.deleteBatchButton.setObjectName("deleteBatchButton")
        self.horizontalLayout_3.addWidget(self.deleteBatchButton)

        self.diagBatchButton = QtWidgets.QPushButton(Form)
        self.diagBatchButton.setObjectName("diagBatchButton")
        self.horizontalLayout_3.addWidget(self.diagBatchButton)

        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.searchEdit = QtWidgets.QLineEdit(Form)
        self.searchEdit.setMaximumSize(QtCore.QSize(500, 16777215))
        self.searchEdit.setObjectName("searchEdit")
        self.horizontalLayout.addWidget(self.searchEdit)
        self.searchButton = QtWidgets.QPushButton(Form)
        self.searchButton.setObjectName("searchButton")
        self.horizontalLayout.addWidget(self.searchButton)
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        self.horizontalLayout_3.addLayout(self.horizontalLayout)
        self.verticalLayout.addLayout(self.horizontalLayout_3)

        # 中间手动代码部分 表格UI构建
        self.db = openDB()
        self.tableView = QTableView()

        # hsj 自动义的tableModel
        headerRow = ["序号", "故障类型", "故障名称", "备注"]
        self.queryModel = MySearchTableModel("T_Fault_Diagnosis", headerRow)
        self.tableView.setModel(self.queryModel)
        self.header = CheckBoxHeader()
        self.tableView.setHorizontalHeader(self.header)
        self.header.clicked.connect(self.queryModel.headerClick)
        self.tableView.horizontalHeader().setStretchLastSection(True)
        self.tableView.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tableView.setModel(self.queryModel)
        self.verticalLayout.addWidget(self.tableView)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.jumpEdit = QtWidgets.QLineEdit(Form)
        self.jumpEdit.setMaximumSize(QtCore.QSize(50, 50))
        self.jumpEdit.setMaxLength(9999)
        self.jumpEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpEdit.setObjectName("jumpEdit")
        self.horizontalLayout_2.addWidget(self.jumpEdit)
        self.totalPageLabel = QtWidgets.QLabel(Form)
        self.totalPageLabel.setObjectName("totalPageLabel")
        self.horizontalLayout_2.addWidget(self.totalPageLabel)
        self.jumpButton = QtWidgets.QPushButton(Form)
        self.jumpButton.setObjectName("jumpButton")
        self.horizontalLayout_2.addWidget(self.jumpButton)
        self.previousButton = QtWidgets.QPushButton(Form)
        self.previousButton.setObjectName("previousButton")
        self.horizontalLayout_2.addWidget(self.previousButton)
        self.nextButton = QtWidgets.QPushButton(Form)
        self.nextButton.setObjectName("nextButton")
        self.horizontalLayout_2.addWidget(self.nextButton)
        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.retranslateUi(Form)
        self.bindButton()
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "故障诊断"))
        self.addBatchButton.setText(_translate("Form", "新建故障信息"))
        self.alterVBatchButton.setText(_translate("Form", "修改故障信息"))
        self.deleteBatchButton.setText(_translate("Form", "删除批次"))
        self.diagBatchButton.setText(_translate("Form", "开始诊断"))
        self.searchButton.setText(_translate("Form", "查询"))
        self.comboBox.setItemText(0, _translate("Form", "按产品名查询"))
        self.comboBox.setItemText(1, _translate("Form", "按故障类型查询"))
        self.comboBox.setItemText(2, _translate("Form", "按故障名称查询"))
        self.label_2.setText(_translate("Form", "跳转至第"))
        self.jumpEdit.setText(_translate("Form", "1"))
        self.totalPageLabel.setText(_translate("Form", "页"))
        self.jumpButton.setText(_translate("Form", "跳转"))
        self.previousButton.setText(_translate("Form", "上一页"))
        self.nextButton.setText(_translate("Form", "下一页"))

    def bindButton(self):
        """
        绑定按钮
        :return:
        """
        # 把需要使用的窗体传进去
        # 新建按钮
        self.addBatchButton.clicked.connect(
            lambda: self.addButtonEvent(AddFaultDiagnosisWidget()))
        # 查看产品
        # self.selectProduct.clicked.connect(lambda :self.selectButtonEvent(SelectSingleProductWidget()))
        # 修改批次
        self.alterVBatchButton.clicked.connect(
            lambda: self.updateButtonEvent(AddFaultDiagnosisWidget()))

        # 开始诊断
        #TODO

        # 下面是无需改动的按钮
        # 删除按钮
        self.deleteBatchButton.clicked.connect(self.deleteButtonEvent)
        # 上一页
        self.previousButton.clicked.connect(self.preButtonEvent)
        # 下一页
        self.nextButton.clicked.connect(self.nextButtonEvent)
        # 跳转按钮
        self.jumpButton.clicked.connect(self.jumpButtonEvent)
        # 添加查询
        self.searchButton.clicked.connect(self.searchButtonEvent)
        self.diagBatchButton.clicked.connect(self.judgeProcessEvent)

    def judgeProcessEvent(self):
        window = JudgeWidget()
        form = QtWidgets.QDialog()
        window.setupUi(form)
        form.exec()

    def selectButtonEvent(self, Widget):
        """
        hsj 根据批次中的产品Id查询产品详细信息
        :param Widget: 要显示的窗体
        :return:
        """
        # 判断复选框是否只选中一个
        a = self.isCorrect()
        if a == 0:
            return
        result = self.queryModel.selectSingleTableForeign()
        productDiglog = Widget
        form = QDialog()
        productDiglog.setupUi(form)
        productDiglog.setData(result)
        form.show()
        form.exec()