# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'UITest4.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
import os
import threading
import time
import traceback
# from sqlite3 import IntegrityError
import webbrowser

from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QColor, QBrush, QCursor, QFont, QIcon
from PyQt5.QtWidgets import QFileDialog, QMenu, QInputDialog, QLineEdit

import updateDB
import xlsxOpenpyxl
import quarryDB
import constants
import insertDB
import deleteDB
import sqlite3DB
from shutil import copyfile

class Ui_MainWindow(object):


    db_file = ''        #当前数据库名称

    content = []        #content存储浏览页的数据 其中数据两两一组，每两个list元素中，前者为单板名，后者为数据库中查询该单板名返回的条目数据
    revise_content = [] #content 同理 存的是修订页的数据

    copy = []       # 备份搜索结果 在update的时候会用到
    copy_logs = []      # 备份修订页搜索结果 在update的时候会用到

    #函数命名前有它的功能介绍
    #其中几个比较重要的组件有：
    #各种页面切换的父窗口: self.stackedWidget_1

    #浏览键：self.pushButton_1 --------> page_5
        #下拉栏：comboBox
        #浏览展示窗口：tabWidget
    #管理键：self.pushButton_4 -----> page_4
        #单板列表：self.treeWidget
        #待编辑条目：self.tableWidget_3
        #检索结果：self.tableWidget_4
        #日志：self.listWidget
    #修订键：self.pushButton_5 ---------> page
        #修订页下拉栏：self.comboBox_2
        #修订记录：self.tableWidget_6
        #修订记录提交窗口：self.tableWidget_5
    #单板信息：self.pushButton_edit -------> page_6
        #单板信息：self.tableWiget_V8
        #待编辑单板信息：self.tableWidget_v8Input


    def setupUi(self, MainWindow):          #此函数用来初始化组件

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1142, 782)
        MainWindow.setWindowIcon(QIcon('icon.ico'))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
        self.verticalLayout.setObjectName("verticalLayout")
        self.pushButton_1 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_1.setMinimumSize(QtCore.QSize(100, 40))
        self.pushButton_1.setObjectName("pushButton_1")
        self.verticalLayout.addWidget(self.pushButton_1)
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setMinimumSize(QtCore.QSize(100, 40))
        self.pushButton_4.setObjectName("pushButton_4")
        self.verticalLayout.addWidget(self.pushButton_4)
        #修订键
        self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_5.setMinimumSize(QtCore.QSize(100, 40))
        self.pushButton_5.setObjectName("pushButton_5")
        self.verticalLayout.addWidget(self.pushButton_5)

        #编辑单板
        self.pushButton_edit = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_edit.setMinimumSize(QtCore.QSize(100, 40))
        self.pushButton_edit.setObjectName("pushButton_edit")
        self.verticalLayout.addWidget(self.pushButton_edit)
        self.white = QtWidgets.QWidget(self.centralwidget)
        self.white.setObjectName("white")
        self.verticalLayout.addWidget(self.white)
        self.horizontalLayout.addLayout(self.verticalLayout)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.VLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.horizontalLayout.addWidget(self.line)
        self.stackedWidget_1 = QtWidgets.QStackedWidget(self.centralwidget)
        self.stackedWidget_1.setObjectName("stackedWidget_1")
        self.page_6 = QtWidgets.QWidget()
        self.page_6.setObjectName("编辑单板")
        self.verticalLayout_v8 = QtWidgets.QVBoxLayout(self.page_6)
        self.verticalLayout_v8.setObjectName("verticalLayout_v8")
        self.verticalLayout_v8show = QtWidgets.QVBoxLayout()
        self.verticalLayout_v8show.setObjectName("verticalLayout_v8show")
        self.label_13 = QtWidgets.QLabel(self.page_6)
        self.label_13.setObjectName("label_13")
        self.verticalLayout_v8show.addWidget(self.label_13)
        self.horizontalLayout_v8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_v8.setObjectName("horizontalLayout_v8")
        self.tableWidget_v8 = QtWidgets.QTableWidget(self.page_6)
        self.tableWidget_v8.setObjectName("tableWidget_v8")
        self.tableWidget_v8.setColumnCount(14)
        self.tableWidget_v8.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(3, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(4, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(5, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(6, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(7, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(8, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(9, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(10, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(11, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(12, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8.setHorizontalHeaderItem(13, item)
        self.tableWidget_v8.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        self.tableWidget_v8.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)

        self.horizontalLayout_v8.addWidget(self.tableWidget_v8)
        self.verticalLayout_19 = QtWidgets.QVBoxLayout()
        self.verticalLayout_19.setObjectName("verticalLayout_19")
        self.pushButton_32 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_32.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_32.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_32.setObjectName("pushButton_32")
        self.verticalLayout_19.addWidget(self.pushButton_32)
        self.pushButton_31 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_31.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_31.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_31.setObjectName("pushButton_31")
        self.verticalLayout_19.addWidget(self.pushButton_31)
        self.pushButton_33 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_33.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_33.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_33.setObjectName("pushButton_33")
        self.verticalLayout_19.addWidget(self.pushButton_33)

        self.pushButton_34 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_34.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_34.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_34.setObjectName("pushButton_34")
        self.verticalLayout_19.addWidget(self.pushButton_34)
        self.pushButton_34.hide()

        self.pushButton_35 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_35.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_35.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_35.setObjectName("pushButton_35")
        self.verticalLayout_19.addWidget(self.pushButton_35)
        self.pushButton_35.hide()

        self.horizontalLayout_v8.addLayout(self.verticalLayout_19)
        self.verticalLayout_v8show.addLayout(self.horizontalLayout_v8)
        self.verticalLayout_v8.addLayout(self.verticalLayout_v8show)
        self.verticalLayout_v8input = QtWidgets.QVBoxLayout()
        self.verticalLayout_v8input.setObjectName("verticalLayout_v8input")
        self.label_14 = QtWidgets.QLabel(self.page_6)
        self.label_14.setObjectName("label_14")
        self.verticalLayout_v8input.addWidget(self.label_14)
        self.horizontalLayout_v8input = QtWidgets.QHBoxLayout()
        self.horizontalLayout_v8input.setObjectName("horizontalLayout_v8input")
        self.verticalLayout_20 = QtWidgets.QVBoxLayout()
        self.verticalLayout_20.setObjectName("verticalLayout_20")
        self.tableWidget_v8Input = QtWidgets.QTableWidget(self.page_6)
        self.tableWidget_v8Input.setObjectName("tableWidget_v8Input")
        self.tableWidget_v8Input.setColumnCount(14)
        self.tableWidget_v8Input.setRowCount(1)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(3, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(4, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(5, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(6, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(7, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(8, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(9, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(10, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(11, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(12, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_v8Input.setHorizontalHeaderItem(13, item)

        self.tableWidget_v8Input.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        self.tableWidget_v8Input.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)

        self.verticalLayout_20.addWidget(self.tableWidget_v8Input)
        self.horizontalLayout_v8input.addLayout(self.verticalLayout_20)
        self.pushButton_30 = QtWidgets.QPushButton(self.page_6)
        self.pushButton_30.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_30.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_30.setObjectName("pushButton_30")
        self.horizontalLayout_v8input.addWidget(self.pushButton_30)
        self.verticalLayout_v8input.addLayout(self.horizontalLayout_v8input)
        self.verticalLayout_v8.addLayout(self.verticalLayout_v8input)
        self.verticalLayout_v8.setStretch(0, 12)
        self.verticalLayout_v8.setStretch(1, 2)

        self.stackedWidget_1.addWidget(self.page_6)

        self.page_3 = QtWidgets.QWidget()
        self.page_3.setObjectName("page_3")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.page_3)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.formLayout = QtWidgets.QFormLayout()
        self.formLayout.setObjectName("formLayout")
        self.label_2 = QtWidgets.QLabel(self.page_3)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_2)
        self.checkBox = QtWidgets.QCheckBox(self.page_3)
        self.checkBox.setObjectName("checkBox")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.checkBox)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2)
        self.checkBox_2 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_2.setObjectName("checkBox_2")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.checkBox_2)
        self.lineEdit_3 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_3.setText("")
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_3)
        self.checkBox_3 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_3.setObjectName("checkBox_3")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.checkBox_3)
        self.lineEdit = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit.setObjectName("lineEdit")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit)
        self.checkBox_4 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_4.setObjectName("checkBox_4")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.checkBox_4)
        self.lineEdit_4 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4)
        self.checkBox_5 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_5.setObjectName("checkBox_5")
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.checkBox_5)
        self.lineEdit_5 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.lineEdit_5)
        self.checkBox_6 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_6.setObjectName("checkBox_6")
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.checkBox_6)
        self.lineEdit_6 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.lineEdit_6)
        self.checkBox_8 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_8.setObjectName("checkBox_8")
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.checkBox_8)
        self.lineEdit_7 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.lineEdit_7)
        self.checkBox_7 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_7.setObjectName("checkBox_7")
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.checkBox_7)
        self.lineEdit_8 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_8.setObjectName("lineEdit_8")
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.lineEdit_8)
        self.checkBox_21 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_21.setObjectName("checkBox_21")
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.checkBox_21)
        self.lineEdit_9 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_9.setObjectName("lineEdit_9")
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.lineEdit_9)
        self.checkBox_9 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_9.setObjectName("checkBox_9")
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.checkBox_9)
        self.lineEdit_10 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_10.setObjectName("lineEdit_10")
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.lineEdit_10)
        self.checkBox_22 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_22.setObjectName("checkBox_22")
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.checkBox_22)
        self.lineEdit_11 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_11.setObjectName("lineEdit_11")
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.lineEdit_11)
        self.checkBox_10 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_10.setObjectName("checkBox_10")
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.checkBox_10)
        self.lineEdit_12 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_12.setObjectName("lineEdit_12")
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.lineEdit_12)
        self.checkBox_24 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_24.setObjectName("checkBox_24")
        self.formLayout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.checkBox_24)
        self.lineEdit_13 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_13.setObjectName("lineEdit_13")
        self.formLayout.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.lineEdit_13)
        self.checkBox_12 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_12.setObjectName("checkBox_12")
        self.formLayout.setWidget(14, QtWidgets.QFormLayout.LabelRole, self.checkBox_12)
        self.lineEdit_14 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_14.setObjectName("lineEdit_14")
        self.formLayout.setWidget(14, QtWidgets.QFormLayout.FieldRole, self.lineEdit_14)
        self.checkBox_23 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_23.setObjectName("checkBox_23")
        self.formLayout.setWidget(15, QtWidgets.QFormLayout.LabelRole, self.checkBox_23)
        self.lineEdit_15 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_15.setObjectName("lineEdit_15")
        self.formLayout.setWidget(15, QtWidgets.QFormLayout.FieldRole, self.lineEdit_15)
        self.checkBox_11 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_11.setObjectName("checkBox_11")
        self.formLayout.setWidget(16, QtWidgets.QFormLayout.LabelRole, self.checkBox_11)
        self.lineEdit_16 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_16.setObjectName("lineEdit_16")
        self.formLayout.setWidget(16, QtWidgets.QFormLayout.FieldRole, self.lineEdit_16)
        self.checkBox_17 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_17.setObjectName("checkBox_17")
        self.formLayout.setWidget(17, QtWidgets.QFormLayout.LabelRole, self.checkBox_17)
        self.lineEdit_17 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_17.setObjectName("lineEdit_17")
        self.formLayout.setWidget(17, QtWidgets.QFormLayout.FieldRole, self.lineEdit_17)
        self.checkBox_18 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_18.setObjectName("checkBox_18")
        self.formLayout.setWidget(18, QtWidgets.QFormLayout.LabelRole, self.checkBox_18)
        self.lineEdit_18 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_18.setObjectName("lineEdit_18")
        self.formLayout.setWidget(18, QtWidgets.QFormLayout.FieldRole, self.lineEdit_18)
        self.checkBox_20 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_20.setObjectName("checkBox_20")
        self.formLayout.setWidget(19, QtWidgets.QFormLayout.LabelRole, self.checkBox_20)
        self.lineEdit_19 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_19.setObjectName("lineEdit_19")
        self.formLayout.setWidget(19, QtWidgets.QFormLayout.FieldRole, self.lineEdit_19)
        self.checkBox_19 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_19.setObjectName("checkBox_19")
        self.formLayout.setWidget(20, QtWidgets.QFormLayout.LabelRole, self.checkBox_19)
        self.lineEdit_20 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_20.setObjectName("lineEdit_20")
        self.formLayout.setWidget(20, QtWidgets.QFormLayout.FieldRole, self.lineEdit_20)
        self.checkBox_13 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_13.setObjectName("checkBox_13")
        self.formLayout.setWidget(21, QtWidgets.QFormLayout.LabelRole, self.checkBox_13)
        self.lineEdit_21 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_21.setObjectName("lineEdit_21")
        self.formLayout.setWidget(21, QtWidgets.QFormLayout.FieldRole, self.lineEdit_21)
        self.checkBox_14 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_14.setObjectName("checkBox_14")
        self.formLayout.setWidget(22, QtWidgets.QFormLayout.LabelRole, self.checkBox_14)
        self.lineEdit_22 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_22.setObjectName("lineEdit_22")
        self.formLayout.setWidget(22, QtWidgets.QFormLayout.FieldRole, self.lineEdit_22)
        self.checkBox_15 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_15.setObjectName("checkBox_15")
        self.formLayout.setWidget(23, QtWidgets.QFormLayout.LabelRole, self.checkBox_15)
        self.lineEdit_23 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_23.setObjectName("lineEdit_23")
        self.formLayout.setWidget(23, QtWidgets.QFormLayout.FieldRole, self.lineEdit_23)
        self.checkBox_16 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_16.setObjectName("checkBox_16")
        self.formLayout.setWidget(24, QtWidgets.QFormLayout.LabelRole, self.checkBox_16)
        self.lineEdit_24 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_24.setObjectName("lineEdit_24")
        self.formLayout.setWidget(24, QtWidgets.QFormLayout.FieldRole, self.lineEdit_24)
        self.checkBox_25 = QtWidgets.QCheckBox(self.page_3)
        self.checkBox_25.setObjectName("checkBox_25")
        self.formLayout.setWidget(25, QtWidgets.QFormLayout.LabelRole, self.checkBox_25)
        self.lineEdit_25 = QtWidgets.QLineEdit(self.page_3)
        self.lineEdit_25.setObjectName("lineEdit_25")
        self.formLayout.setWidget(25, QtWidgets.QFormLayout.FieldRole, self.lineEdit_25)
        self.buttonBox = QtWidgets.QDialogButtonBox(self.page_3)
        self.buttonBox.setMaximumSize(QtCore.QSize(220, 25))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Apply|QtWidgets.QDialogButtonBox.Reset)
        self.buttonBox.setObjectName("buttonBox")
        self.formLayout.setWidget(26, QtWidgets.QFormLayout.FieldRole, self.buttonBox)
        self.verticalLayout_2.addLayout(self.formLayout)
        self.horizontalLayout_2.addLayout(self.verticalLayout_2)
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.label = QtWidgets.QLabel(self.page_3)
        self.label.setObjectName("label")
        self.verticalLayout_3.addWidget(self.label)
        self.tableWidget_2 = QtWidgets.QTableWidget(self.page_3)

        self.tableWidget_2.setObjectName("tableWidget_2")
        self.tableWidget_2.setColumnCount(0)
        self.tableWidget_2.setRowCount(0)
        self.verticalLayout_3.addWidget(self.tableWidget_2)
        self.pushButton_10 = QtWidgets.QPushButton(self.page_3)
        self.pushButton_10.setMinimumSize(QtCore.QSize(100, 0))
        self.pushButton_10.setMaximumSize(QtCore.QSize(100, 25))
        self.pushButton_10.setObjectName("pushButton_10")
        self.verticalLayout_3.addWidget(self.pushButton_10, 0, QtCore.Qt.AlignRight)
        self.horizontalLayout_2.addLayout(self.verticalLayout_3)
        self.stackedWidget_1.addWidget(self.page_3)
        self.page_5 = QtWidgets.QWidget()
        self.page_5.setObjectName("page_5")
        self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.page_5)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.label_3 = QtWidgets.QLabel(self.page_5)
        self.label_3.setObjectName("label_3")
        self.horizontallayout_6 = QtWidgets.QVBoxLayout(self.page_5)
        self.horizontallayout_6.setObjectName("horizontallayout_6")

        self.verticalLayout_5.addWidget(self.label_3)
        self.verticalLayout_5.addLayout(self.horizontallayout_6)
        self.comboBox = QtWidgets.QComboBox(self.page_5)
        self.comboBox.setMaximumSize(QtCore.QSize(200, 16777215))
        self.comboBox.setObjectName("comboBox")


        self.label_4 = QtWidgets.QLabel(self.page_5)
        self.label_4.setObjectName("label_4")
        self.verticalLayout_5.addWidget(self.label_4)
        self.tabWidget = QtWidgets.QTabWidget(self.page_5)
        self.tabWidget.setTabPosition(QtWidgets.QTabWidget.South)
        self.tabWidget.setObjectName("tabWidget")

        #导出excel 键 浏览页面

        self.verticalLayout_5.addWidget(self.tabWidget)
        self.pushButton_12 = QtWidgets.QPushButton(self.page_5)
        self.pushButton_12.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_12.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_12.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_12.setObjectName("pushButton_12")

        self.pushButton_save_form = QtWidgets.QPushButton(self.page_5)
        self.pushButton_save_form.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_save_form.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_save_form.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_save_form.setObjectName("pushButton_12")

        #导入excel 浏览界面
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.pushButton_20 = QtWidgets.QPushButton(self.page_5)
        self.pushButton_20.setObjectName("pushButton_20")
        self.pushButton_20.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_20.setMinimumSize(QtCore.QSize(100, 30))



        self.pushButton_21 = QtWidgets.QPushButton(self.page_5)
        self.pushButton_21.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_21.setMinimumSize(QtCore.QSize(100, 30))

        self.pushButton_21.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_21.setObjectName("退出预览")
        self.pushButton_21.hide()

        self.pushButton_22 = QtWidgets.QPushButton(self.page_5)
        self.pushButton_22.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_22.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_22.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_22.setObjectName("保存")
        self.pushButton_22.hide()

        self.horizontalLayout_9.addWidget(self.pushButton_20, 1, QtCore.Qt.AlignRight)
        self.horizontalLayout_9.addWidget(self.pushButton_12)
        self.horizontalLayout_9.addWidget(self.pushButton_save_form)
        self.horizontalLayout_9.addWidget(self.pushButton_21, 1, QtCore.Qt.AlignLeft)
        self.horizontalLayout_9.addWidget(self.pushButton_22)

        self.verticalLayout_5.addLayout(self.horizontalLayout_9)

        self.stackedWidget_1.addWidget(self.page_5)



        #修订页
        self.page = QtWidgets.QWidget()
        self.page.setObjectName("page")
        self.stackedWidget_1.addWidget(self.page)

        self.verticalLayout_18 = QtWidgets.QVBoxLayout(self.page)
        self.verticalLayout_18.setObjectName("verticalLayout_18")
        self.verticalLayout_15 = QtWidgets.QVBoxLayout()
        self.verticalLayout_15.setObjectName("verticalLayout_15")
        self.label_6 = QtWidgets.QLabel(self.page)
        self.label_6.setObjectName("label_6")
        self.verticalLayout_15.addWidget(self.label_6)
        self.comboBox_2 = QtWidgets.QComboBox(self.page)
        self.comboBox_2.setMaximumSize(QtCore.QSize(200, 16777215))
        self.comboBox_2.setObjectName("comboBox_2")
        self.verticalLayout_15.addWidget(self.comboBox_2)
        self.verticalLayout_18.addLayout(self.verticalLayout_15)
        self.verticalLayout_16 = QtWidgets.QVBoxLayout()
        self.verticalLayout_16.setObjectName("verticalLayout_16")
        self.label_7 = QtWidgets.QLabel(self.page)
        self.label_7.setObjectName("label_7")
        self.verticalLayout_16.addWidget(self.label_7)
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.tableWidget_6 = QtWidgets.QTableWidget(self.page)
        self.tableWidget_6.setObjectName("tableWidget_6")
        self.horizontalLayout_6.addWidget(self.tableWidget_6)

        self.verticalLayout_14 = QtWidgets.QVBoxLayout()
        self.verticalLayout_14.setObjectName("verticalLayout_14")
        self.pushButton_14 = QtWidgets.QPushButton(self.page)
        self.pushButton_14.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_14.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_14.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_14.setObjectName("pushButton_14")
        self.verticalLayout_14.addWidget(self.pushButton_14)
        self.pushButton_17 = QtWidgets.QPushButton(self.page)
        self.pushButton_17.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_17.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_17.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_17.setObjectName("pushButton_17")
        self.verticalLayout_14.addWidget(self.pushButton_17)

        self.horizontalLayout_6.addLayout(self.verticalLayout_14)
        self.verticalLayout_16.addLayout(self.horizontalLayout_6)
        self.verticalLayout_18.addLayout(self.verticalLayout_16)
        self.verticalLayout_17 = QtWidgets.QVBoxLayout()
        self.verticalLayout_17.setObjectName("verticalLayout_17")
        self.label_8 = QtWidgets.QLabel(self.page)
        self.label_8.setObjectName("label_8")
        self.verticalLayout_17.addWidget(self.label_8)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")

        #修订提交
        self.tableWidget_5 = QtWidgets.QTableWidget(self.page)
        self.tableWidget_5.setObjectName("tableWidget_5")
        self.tableWidget_5.setColumnCount(len(constants.head_name_logs) - 1) #时间不用写
        self.tableWidget_5.setRowCount(1)
        self.tableWidget_5.setHorizontalHeaderLabels(constants.head_name_logs_input)
        self.tableWidget_5.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        self.tableWidget_5.horizontalHeader().setSectionResizeMode(0,QHeaderView.ResizeToContents)
        self.tableWidget_5.horizontalHeader().setSectionResizeMode(1,QHeaderView.Stretch)
        self.tableWidget_5.horizontalHeader().setSectionResizeMode(2,QHeaderView.Stretch)
        self.tableWidget_5.horizontalHeader().setSectionResizeMode(3,QHeaderView.Stretch)
        self.tableWidget_5.horizontalHeader().setSectionResizeMode(4,QHeaderView.ResizeToContents)

        # self.tableWidget_5.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.horizontalLayout_7.addWidget(self.tableWidget_5)

        self.pushButton_15 = QtWidgets.QPushButton(self.page)
        self.pushButton_15.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_15.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_15.setObjectName("pushButton_15")
        self.horizontalLayout_7.addWidget(self.pushButton_15)
        self.verticalLayout_17.addLayout(self.horizontalLayout_7)
        self.verticalLayout_18.addLayout(self.verticalLayout_17)
        self.verticalLayout_18.setStretch(0, 1)
        self.verticalLayout_18.setStretch(1, 11)
        self.verticalLayout_18.setStretch(2, 4)
        self.stackedWidget_1.addWidget(self.page)

        #浏览刷新建

        self.pushButton_13 = QtWidgets.QPushButton(self.page_5)
        self.pushButton_13.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_13.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.pushButton_13.setObjectName("pushButton_13")
        self.horizontallayout_6.addWidget(self.comboBox)
        self.horizontallayout_6.addWidget(self.pushButton_13)
        self.verticalLayout_5.addLayout(self.horizontallayout_6)


        #CURD 页layout

        self.page_4 = QtWidgets.QWidget()
        self.page_4.setObjectName("page_4")

        self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.page_4)

        self.verticalLayout_13.setObjectName("verticalLayout_13")

        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")

        #单板 框布局
        self.verticalLayout_7 = QtWidgets.QVBoxLayout()
        self.verticalLayout_7.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        self.verticalLayout_7.setObjectName("verticalLayout_7")

        self.label_31 = QtWidgets.QLabel(self.page_4)
        self.label_31.setMinimumSize(QtCore.QSize(0, 17))
        self.label_31.setMaximumSize(QtCore.QSize(300, 17))
        self.label_31.setObjectName("label_31")
        self.verticalLayout_7.addWidget(self.label_31)
        self.treeWidget = QtWidgets.QTreeWidget(self.page_4)
        self.treeWidget.setObjectName("treeWidget")

        self.verticalLayout_7.addWidget(self.treeWidget)


        self.horizontalLayout_5.addLayout(self.verticalLayout_7)

        self.verticalLayout_8 = QtWidgets.QVBoxLayout()
        self.verticalLayout_8.setObjectName("verticalLayout_8")
        self.label_33 = QtWidgets.QLabel(self.page_4)
        self.label_33.setMinimumSize(QtCore.QSize(0, 17))
        self.label_33.setMaximumSize(QtCore.QSize(16777215, 17))
        self.label_33.setObjectName("label_33")
        self.verticalLayout_8.addWidget(self.label_33)
        self.listWidget = QtWidgets.QListWidget(self.page_4)
        self.listWidget.setMinimumSize(QtCore.QSize(560, 0))
        self.listWidget.setObjectName("listWidget")

        self.verticalLayout_8.addWidget(self.listWidget)

        self.horizontalLayout_5.addLayout(self.verticalLayout_8)

        self.pushButton_11 = QtWidgets.QPushButton(self.page_4)
        self.pushButton_11.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_11.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_11.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_11.setObjectName("pushButton_11")

        self.verticalLayout_13.addLayout(self.horizontalLayout_5)

        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.verticalLayout_9 = QtWidgets.QVBoxLayout()
        self.verticalLayout_9.setObjectName("verticalLayout_9")
        self.label_32 = QtWidgets.QLabel(self.page_4)
        self.label_32.setObjectName("label_32")
        self.verticalLayout_9.addWidget(self.label_32)

        # 初始化提交界面的table
        self.tableWidget_3 = QtWidgets.QTableWidget(self.page_4)
        self.tableWidget_3.setObjectName("tableWidget_3")
        self.tableWidget_3.setColumnCount(len(constants.head_name_cn))
        self.tableWidget_3.setRowCount(1)
        self.tableWidget_3.setHorizontalHeaderLabels(constants.head_name_cn)
        self.tableWidget_3.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        self.verticalLayout_7.addWidget(self.tableWidget_3)

        self.verticalLayout_9.addWidget(self.tableWidget_3)
        self.horizontalLayout_3.addLayout(self.verticalLayout_9)
        self.verticalLayout_11 = QtWidgets.QVBoxLayout()
        self.verticalLayout_11.setObjectName("verticalLayout_11")

#搜索键
        self.pushButton_6 = QtWidgets.QPushButton(self.page_4)
        self.pushButton_6.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_6.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_6.setObjectName("pushButton_6")
        self.verticalLayout_11.addWidget(self.pushButton_6)
#提交键
        self.pushButton = QtWidgets.QPushButton(self.page_4)
        self.pushButton.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout_11.addWidget(self.pushButton)

        self.horizontalLayout_3.addLayout(self.verticalLayout_11)

        self.verticalLayout_13.addLayout(self.horizontalLayout_3)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.verticalLayout_10 = QtWidgets.QVBoxLayout()
        self.verticalLayout_10.setObjectName("verticalLayout_10")
        self.label_5 = QtWidgets.QLabel(self.page_4)
        self.label_5.setObjectName("label_5")
        self.verticalLayout_10.addWidget(self.label_5)

        #搜索结果layout
        self.tableWidget_4 = QtWidgets.QTableWidget(self.page_4)

        self.tableWidget_4.setObjectName("tableWidget_4")
        self.tableWidget_4.setColumnCount(0)
        self.tableWidget_4.setRowCount(0)
        self.tableWidget_4.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)


        self.verticalLayout_10.addWidget(self.tableWidget_4)

        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.widget = QtWidgets.QWidget(self.page_4)
        self.widget.setObjectName("widget")
        self.horizontalLayout_4.addWidget(self.widget)

        self.horizontalLayout_4.addLayout(self.verticalLayout_10)
        self.verticalLayout_12 = QtWidgets.QVBoxLayout()
        self.verticalLayout_12.setSizeConstraint(QtWidgets.QLayout.SetMaximumSize)
        self.verticalLayout_12.setSpacing(6)
        self.verticalLayout_12.setObjectName("verticalLayout_12")
        self.pushButton_9 = QtWidgets.QPushButton(self.page_4)
        self.pushButton_9.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_9.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_9.setObjectName("pushButton_9")
        self.verticalLayout_12.addWidget(self.pushButton_9)
        self.pushButton_8 = QtWidgets.QPushButton(self.page_4)
        self.pushButton_8.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_8.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_8.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.pushButton_8.setAutoFillBackground(True)
        self.pushButton_8.setObjectName("pushButton_8")
        self.verticalLayout_12.addWidget(self.pushButton_8)
        self.pushButton_7 = QtWidgets.QPushButton(self.page_4)
        self.pushButton_7.setMinimumSize(QtCore.QSize(100, 30))
        self.pushButton_7.setMaximumSize(QtCore.QSize(100, 30))
        self.pushButton_7.setObjectName("pushButton_7")
        self.verticalLayout_12.addWidget(self.pushButton_7)
        self.horizontalLayout_4.addLayout(self.verticalLayout_12)

        self.verticalLayout_13.addLayout(self.horizontalLayout_4)

        self.stackedWidget_1.addWidget(self.page_4)
        self.horizontalLayout.addWidget(self.stackedWidget_1)

        self.verticalLayout_4.addLayout(self.horizontalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1142, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)

        self.menu = self.menubar.addMenu("打开")

        self.action_open_db = self.menu.addAction('选择数据库')
        self.action_open_db.triggered.connect(self.open_db)

        self.menu2 = self.menubar.addMenu("备份")
        self.action_save_db = self.menu2.addAction('备份当前数据库')
        self.action_save_db.triggered.connect(self.save_db)

        self.menu3 = self.menubar.addMenu("帮助")
        self.action_helper = self.menu3.addAction("使用说明")
        self.action_helper.triggered.connect(self.open_helper)

        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.stackedWidget_1.setCurrentIndex(2)
        self.comboBox.setCurrentIndex(-1)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.verticalLayout_11.addWidget(self.pushButton_11)


    # 注册信号槽

        # treewidget
        self.treeWidget.itemChanged.connect(self.check_item)

        # 监听切换页面按钮
        self.pushButton_1.clicked.connect(self.show_page)
        # self.pushButton_2.clicked.connect(self.show_page)
        # self.pushButton_3.clicked.connect(self.show_page)
        self.pushButton_4.clicked.connect(self.show_page)
        self.pushButton_5.clicked.connect(self.show_page)
        self.pushButton_edit.clicked.connect(self.show_page)



        self.selected_hardware = []


        #编辑单板
        self.stackedWidget_1.addWidget(self.page_6)


        # 添加提交键监听

        self.pushButton.clicked.connect(self.double_check_submit)

        #搜索键监听
        self.pushButton_6.clicked.connect(self.search)

        #设置CURD界面比例layout

        self.verticalLayout_13.setStretch(0, 4)
        self.verticalLayout_13.setStretch(1, 2)
        self.verticalLayout_13.setStretch(2, 10)

        #注册删除按钮
        self.pushButton_8.clicked.connect(self.double_check_delete)

        #修订删除按钮
        self.pushButton_17.clicked.connect(self.double_check_delete_revise)

        #注册更新键
        self.pushButton_9.clicked.connect(self.double_check_update)

        #注册curd页导出键
        self.pushButton_7.clicked.connect(self.search_to_excel)

        #注册浏览页按版本导出键
        self.pushButton_12.clicked.connect(self.browse_to_excel)

        #浏览页全部导出形态表
        self.pushButton_save_form.clicked.connect(self.form_to_excel)

        #注册清空检索条件键
        self.pushButton_11.clicked.connect(self.clear_search)

        #注册浏览刷新
        self.pushButton_13.clicked.connect(self.refresh_browse)

        #注册修订确认
        self.pushButton_15.clicked.connect(self.double_check_revise)

        # 修订保存键
        self.pushButton_14.clicked.connect(self.update_revise)

        #从excel导入
        self.pushButton_20.clicked.connect(self.open_excel)
        #退出预览
        self.pushButton_21.clicked.connect(self.close_browse)

        self.pushButton_22.clicked.connect(self.double_check_overwrite)
        #删除菜单
        self.tableWidget_4.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableWidget_4.customContextMenuRequested.connect(self.showDeleteMenu)

        self.deleteMenu = QMenu(self.tableWidget_4)
        self.deleteAction = self.deleteMenu.addAction('删除此条目')
        self.deleteAction.triggered.connect(self.double_check_delete)

        #添加单板菜单
        self.treeWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.treeWidget.customContextMenuRequested.connect(self.showContextMenu)

        self.contextMenu = QMenu(self.treeWidget)
        self.actionA = self.contextMenu.addAction('新建形态表')
        self.actionB = self.contextMenu.addAction('新建空单板')
        self.second = self.contextMenu.addMenu('新建继承单板')
        self.actionC = self.contextMenu.addAction('删除')


        self.actionA.triggered.connect(self.menu_newForm)
        self.actionB.triggered.connect(self.menu_newHardware)
        self.actionC.triggered.connect(self.menu_delete)



        #单板信息
        self.pushButton_30.clicked.connect(self.double_check_insert_hardware_info)

        #单板信息删除
        self.pushButton_32.clicked.connect(self.double_check_delete_hardware_info)
        #到处到excel hardware info
        self.pushButton_33.clicked.connect(self.hardware_info_to_excel)
        #
        self.pushButton_31.clicked.connect(self.excel_to_hardware_info)

        #覆盖单板信息
        self.pushButton_34.clicked.connect(self.double_check_save_hardware_info)

        #推出预览单板信息
        self.pushButton_35.clicked.connect(self.close_hardware_info)


    #初始化单板列表右键菜单（新增单板）
    def init_menu(self):
        try:
            self.second.clear()
            form = self.get_all_form_name()
            for i in form:
                self.submenu = self.second.addMenu(i)
                self.submenu.setTitle(i)
                table = self.get_table_from_form(i)
                for j in table:
                    self.action = self.submenu.addAction(j)
                    self.action.setText(j)
                    self.action.triggered.connect(self.menu_decHardware)
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '初始化继承单板菜单失败：'+ str(e))
            traceback.print_exc()
    #新建继承单板
    def menu_decHardware(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            select_hardware = self.stackedWidget_1.sender().text()
            print(select_hardware)
            formname = self.stackedWidget_1.sender().parent().title()
            tablename, ok = QInputDialog.getText(self.treeWidget, "新建继承单板", "命名新的单板:", QLineEdit.Normal,
                                                 "")
            if ok == True:
                tablename.strip()
                print(tablename)
                if tablename == None or tablename == '' or tablename.isspace == True:
                    raise Exception('单板名称不可为空')
                else:

                    form_list = list(quarryDB.quarry_form_store(self.db_file))
                    for formname in form_list:
                        formname = list(formname)

                        table_list = list(quarryDB.quarry_form(formname[0], self.db_file))




                        for i in table_list:
                            if i == tablename:
                                QMessageBox.warning(self.stackedWidget_1,'提示','单板名重复')
                                raise Exception('该单板已存在')
                    # 二次确认插入
                    A = QMessageBox.question(self.stackedWidget_1, '确认', '确定新建继承自'+ select_hardware + '的单板：' + tablename + ' ？',
                                             QMessageBox.Yes | QMessageBox.No)
                    if A == QMessageBox.Yes:
                        # 将单板注册到form里
                        insertDB.insert_hardware(formname[0], tablename,self.db_file)
                        # 创建一个存储新的单板的form表 和logs

                        sqlite3DB.copy_table(select_hardware, tablename,self.db_file)
                        QMessageBox.warning(self.stackedWidget_1, '提示', '新建成功')
                        self.upload_logs('新建单板:' + tablename)
                        self.refresh_tree()
                        self.init_menu()
                        A = QMessageBox.question(self.stackedWidget_1, '确认', '新建成功，是否立即录入单板信息？',
                                                 QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
                        if A == QMessageBox.Yes:
                            self.redirect_to_hardware_info(formname, tablename)
                        else:
                            print('cancel')
                    else:
                        print('取消创建')
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '新建继承单板失败：' + str(e))
            traceback.print_exc()
            self.upload_logs(str(e))
            try:
                if str(e) == '复制失败':
                    deleteDB.delete_table_from_form(formname, tablename, self.db_file)
            except Exception:
                traceback.print_exc()
                print('清理失败')





    #初始化UI上的文字
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "资源表管理"))
        self.pushButton_1.setText(_translate("MainWindow", "浏览"))
        self.pushButton_4.setText(_translate("MainWindow", "管理"))
        self.pushButton_5.setText(_translate("MainWindow", "修订"))
        self.label_2.setText(_translate("MainWindow", "检索条件："))
        self.checkBox.setText(_translate("MainWindow", "业务名称"))
        self.checkBox_2.setText(_translate("MainWindow", "位宽（bit）"))
        self.checkBox_3.setText(_translate("MainWindow", "条数（K）"))
        self.checkBox_4.setText(_translate("MainWindow", "TID位宽"))
        self.checkBox_5.setText(_translate("MainWindow", "TID值"))
        self.checkBox_6.setText(_translate("MainWindow", "SubTid位宽"))
        self.checkBox_8.setText(_translate("MainWindow", "subTid值"))
        self.checkBox_7.setText(_translate("MainWindow", "存储位置"))
        self.checkBox_21.setText(_translate("MainWindow", "算法表ID"))
        self.checkBox_9.setText(_translate("MainWindow", "算法表规格（K）"))
        self.checkBox_22.setText(_translate("MainWindow", "动作表ID"))
        self.checkBox_10.setText(_translate("MainWindow", "测试规格（K）"))
        self.checkBox_24.setText(_translate("MainWindow", "单多播"))
        self.checkBox_12.setText(_translate("MainWindow", "index/data"))
        self.checkBox_23.setText(_translate("MainWindow", "TCAM起始地址"))
        self.checkBox_11.setText(_translate("MainWindow", "TBLM_ID"))
        self.checkBox_17.setText(_translate("MainWindow", "落地部门"))
        self.checkBox_18.setText(_translate("MainWindow", "落地负责人"))
        self.checkBox_20.setText(_translate("MainWindow", "落地情况确认"))
        self.checkBox_19.setText(_translate("MainWindow", "备注"))
        self.checkBox_13.setText(_translate("MainWindow", "server type位宽"))
        self.checkBox_14.setText(_translate("MainWindow", "server type值"))
        self.checkBox_15.setText(_translate("MainWindow", "单板名称"))
        self.checkBox_16.setText(_translate("MainWindow", "CheckBox"))
        self.checkBox_25.setText(_translate("MainWindow", "CheckBox"))
        self.pushButton_12.setText(_translate("MainWindow", "按版本导出"))
        self.pushButton_save_form.setText(_translate("MainWindow", "按形态表导出"))
        self.pushButton_20.setText(_translate("MainWindow", "从Excel导入"))
        self.pushButton_21.setText(_translate("MainWindow", "退出预览"))
        self.pushButton_22.setText(_translate("MainWindow", "保存并覆盖"))
        self.label.setText(_translate("MainWindow", "检索结果："))
        self.pushButton_10.setText(_translate("MainWindow", "导出到Excel"))
        self.label_3.setText(_translate("MainWindow", "形态表："))
        self.label_4.setText(_translate("MainWindow", "当前形态："))

        self.label_31.setText(_translate("MainWindow", "选择要检索的单板"))
        self.treeWidget.headerItem().setText(0, _translate("MainWindow", "形态表"))
        __sortingEnabled = self.treeWidget.isSortingEnabled()
        self.treeWidget.setSortingEnabled(False)

        self.treeWidget.setSortingEnabled(__sortingEnabled)
        self.label_33.setText(_translate("MainWindow", "日志："))
        self.pushButton_11.setText(_translate("MainWindow", "清空"))
        self.label_32.setText(_translate("MainWindow", "待编辑条目："))
        self.pushButton_6.setText(_translate("MainWindow", "搜索"))
        self.pushButton.setText(_translate("MainWindow", "提交"))
        self.label_5.setText(_translate("MainWindow", "检索结果："))
        self.pushButton_9.setText(_translate("MainWindow", "保存更改"))
        self.pushButton_8.setText(_translate("MainWindow", "删除选中条目"))
        self.pushButton_7.setText(_translate("MainWindow", "导出到excel"))
        self.pushButton_13.setText(_translate("MainWindow", "刷新"))

        #修订页
        self.label_6.setText(_translate("MainWindow", "形态表："))
        self.label_7.setText(_translate("MainWindow", "修订记录："))
        self.pushButton_14.setText(_translate("MainWindow", "保存更改"))
        self.pushButton_17.setText(_translate("MainWindow", "删除选择记录"))

        self.pushButton_15.setText(_translate("MainWindow", "提交"))
        self.label_8.setText(_translate("MainWindow", "请输入修订内容："))

        #编辑单板页
        self.pushButton_edit.setText(_translate("MainWindow","单板信息"))

        self.label_13.setText(_translate("MainWindow", "V8算法组支持单板："))
        item = self.tableWidget_v8.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "接口板名称"))
        item = self.tableWidget_v8.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "所落版本"))
        item = self.tableWidget_v8.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "所属产品形态"))
        item = self.tableWidget_v8.horizontalHeaderItem(3)
        item.setText(_translate("MainWindow", "算法芯片"))
        item = self.tableWidget_v8.horizontalHeaderItem(4)
        item.setText(_translate("MainWindow", "TCAM型号"))
        item = self.tableWidget_v8.horizontalHeaderItem(5)
        item.setText(_translate("MainWindow", "对应算法"))
        item = self.tableWidget_v8.horizontalHeaderItem(6)
        item.setText(_translate("MainWindow", "算法引擎个数"))
        item = self.tableWidget_v8.horizontalHeaderItem(7)
        item.setText(_translate("MainWindow", "算法是否放从核及多核形态"))
        item = self.tableWidget_v8.horizontalHeaderItem(8)
        item.setText(_translate("MainWindow", "从核上表类型"))
        item = self.tableWidget_v8.horizontalHeaderItem(9)
        item.setText(_translate("MainWindow", "CPU类型"))
        item = self.tableWidget_v8.horizontalHeaderItem(10)
        item.setText(_translate("MainWindow", "makefile编so"))
        item = self.tableWidget_v8.horizontalHeaderItem(11)
        item.setText(_translate("MainWindow", "cmake编so"))
        item = self.tableWidget_v8.horizontalHeaderItem(12)
        item.setText(_translate("MainWindow", "ko编译命令"))
        item = self.tableWidget_v8.horizontalHeaderItem(13)
        item.setText(_translate("MainWindow", "备注"))
        self.pushButton_32.setText(_translate("MainWindow", "删除选中条目"))

        self.pushButton_31.setText(_translate("MainWindow", "从excel导入"))
        self.pushButton_33.setText(_translate("MainWindow", "导出到excel"))
        self.pushButton_34.setText(_translate("MainWindow", "覆盖单板信息"))
        self.pushButton_35.setText(_translate("MainWindow", "退出预览"))
        self.label_14.setText(_translate("MainWindow", "添加单板信息："))
        item = self.tableWidget_v8Input.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "接口板名称"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "所落版本"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "所属产品形态"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(3)
        item.setText(_translate("MainWindow", "算法芯片"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(4)
        item.setText(_translate("MainWindow", "TCAM型号"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(5)
        item.setText(_translate("MainWindow", "对应算法"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(6)
        item.setText(_translate("MainWindow", "算法引擎个数"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(7)
        item.setText(_translate("MainWindow", "算法是否放从核及多核形态"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(8)
        item.setText(_translate("MainWindow", "从核上表类型"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(9)
        item.setText(_translate("MainWindow", "CPU类型"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(10)
        item.setText(_translate("MainWindow", "makefile编so"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(11)
        item.setText(_translate("MainWindow", "cmake编so"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(12)
        item.setText(_translate("MainWindow", "ko编译指令"))
        item = self.tableWidget_v8Input.horizontalHeaderItem(13)
        item.setText(_translate("MainWindow", "备注"))
        self.pushButton_30.setText(_translate("MainWindow", "提交"))

        table_style = 'font-size: 16px'
        button_style = 'font-size: 14px'
        combobox_style = 'font-size: 14px'
        label_style = 'font-size: 15px'
        font = QFont("Microsoft YaHei")


        self.tabWidget.setStyleSheet(table_style)
        self.tableWidget_3.setStyleSheet(table_style)
        self.tableWidget_4.setStyleSheet(table_style)
        self.tableWidget_5.setStyleSheet(table_style)
        self.tableWidget_6.setStyleSheet(table_style)
        self.tableWidget_v8.setStyleSheet(table_style)
        self.tableWidget_v8Input.setStyleSheet(table_style)

        self.tabWidget.setFont(font)
        self.tableWidget_3.setFont(font)
        self.tableWidget_4.setFont(font)
        self.tableWidget_5.setFont(font)
        self.tableWidget_6.setFont(font)
        self.tableWidget_v8.setFont(font)
        self.tableWidget_v8Input.setFont(font)


        self.pushButton.setStyleSheet(button_style)
        self.pushButton_1.setStyleSheet(button_style)
        self.pushButton_11.setStyleSheet(button_style)
        self.pushButton_22.setStyleSheet(button_style)
        self.pushButton_21.setStyleSheet(button_style)
        self.pushButton_20.setStyleSheet(button_style)
        self.pushButton_12.setStyleSheet(button_style)
        self.pushButton_32.setStyleSheet(button_style)
        self.pushButton_34.setStyleSheet(button_style)
        self.pushButton_33.setStyleSheet(button_style)
        self.pushButton_35.setStyleSheet(button_style)
        self.pushButton_31.setStyleSheet(button_style)
        self.pushButton_13.setStyleSheet(button_style)
        self.pushButton_4.setStyleSheet(button_style)
        self.pushButton_34.setStyleSheet(button_style)
        self.pushButton_14.setStyleSheet(button_style)
        self.pushButton_35.setStyleSheet(button_style)
        self.pushButton_5.setStyleSheet(button_style)
        self.pushButton_15.setStyleSheet(button_style)
        self.pushButton_6.setStyleSheet(button_style)
        self.pushButton_7.setStyleSheet(button_style)
        self.pushButton_17.setStyleSheet(button_style)
        self.pushButton_8.setStyleSheet(button_style)
        self.pushButton_9.setStyleSheet(button_style)
        self.pushButton_10.setStyleSheet(button_style)
        self.pushButton_edit.setStyleSheet(button_style)
        self.pushButton_save_form.setStyleSheet(button_style)

        self.pushButton_save_form.setFont(font)
        self.pushButton.setFont(font)
        self.pushButton_1.setFont(font)
        self.pushButton_11.setFont(font)
        self.pushButton_22.setFont(font)
        self.pushButton_21.setFont(font)
        self.pushButton_20.setFont(font)
        self.pushButton_12.setFont(font)
        self.pushButton_32.setFont(font)
        self.pushButton_34.setFont(font)
        self.pushButton_33.setFont(font)
        self.pushButton_35.setFont(font)
        self.pushButton_31.setFont(font)
        self.pushButton_13.setFont(font)
        self.pushButton_4.setFont(font)
        self.pushButton_34.setFont(font)
        self.pushButton_14.setFont(font)
        self.pushButton_35.setFont(font)
        self.pushButton_5.setFont(font)
        self.pushButton_15.setFont(font)
        self.pushButton_6.setFont(font)
        self.pushButton_7.setFont(font)
        self.pushButton_17.setFont(font)
        self.pushButton_8.setFont(font)
        self.pushButton_9.setFont(font)
        self.pushButton_10.setFont(font)
        self.pushButton_edit.setFont(font)

        self.comboBox.setStyleSheet(combobox_style)
        self.comboBox_2.setStyleSheet(combobox_style)

        self.comboBox.setFont(font)
        self.comboBox_2.setFont(font)

        self.treeWidget.setStyleSheet(combobox_style)
        self.treeWidget.setFont(font)

        self.label.setStyleSheet(combobox_style)
        self.label_14.setStyleSheet(combobox_style)
        self.label_13.setStyleSheet(combobox_style)
        self.label_31.setStyleSheet(combobox_style)
        self.label_2.setStyleSheet(combobox_style)
        self.label_32.setStyleSheet(combobox_style)
        self.label_3.setStyleSheet(combobox_style)
        self.label_33.setStyleSheet(combobox_style)
        self.label_4.setStyleSheet(combobox_style)
        self.label_5.setStyleSheet(combobox_style)
        self.label_6.setStyleSheet(combobox_style)
        self.label_7.setStyleSheet(combobox_style)
        self.label_8.setStyleSheet(combobox_style)


        self.label.setFont(font)
        self.label_14.setFont(font)
        self.label_13.setFont(font)
        self.label_31.setFont(font)
        self.label_2.setFont(font)
        self.label_32.setFont(font)
        self.label_3.setFont(font)
        self.label_33.setFont(font)
        self.label_4.setFont(font)
        self.label_5.setFont(font)
        self.label_6.setFont(font)
        self.label_7.setFont(font)
        self.label_8.setFont(font)

        self.menubar.setFont(font)
        self.menubar.setStyleSheet(button_style)






    #点击右侧四个按钮进行页面切换
    def show_page(self):
        dic = {
            "pushButton_1": 1,
            # "pushButton_2": 0,
            # "pushButton_3": 2,
            "pushButton_4": 3,
            "pushButton_5": 2,
            "pushButton_edit": 4
        }
        index = dic[self.stackedWidget_1.sender().objectName()]
        self.stackedWidget_1.setCurrentIndex(index)

        # 根据checkbox解锁text输入




    #当浏览页中的下拉单选中条目变化时运行，显示该形态表信息
    def select_from_resources(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            resource = self.comboBox.currentText()
            cur = quarryDB.quarry_form(resource,self.db_file)

            resource_list = []
            for i in cur:
                i = list(i)
                resource_list.append(i[0])

             # 获得一串 tablename

            #初始化tab
            self.tabWidget.clear()
            self.content = []
            self.revise_content = []

            #查询修订表
            revise_results = quarryDB.quarry_logs(resource,self.db_file)
            self.revise_tab(resource + '修订记录', revise_results)
            self.revise_content.append(resource + "修订记录")
            self.revise_content.append(revise_results)

            #########################multi thread###############
            thread = []

            for i in resource_list:

                results = quarryDB.quarry_all(i,self.db_file)  # 查询一个table返回所有搜索结果
                #在这里初始化窗口等
                print(results)
                tab = QtWidgets.QWidget()
                # tab.setObjectName("tab")
                # 设置成垂直排列
                verticalLayout_6 = QtWidgets.QVBoxLayout(tab)
                # verticalLayout_6.setObjectName("verticalLayout_6")
                # 把table放到tab里
                tableWidget = QtWidgets.QTableWidget()
                # tableWidget.setObjectName("tableWidget")
                # verticalLayout_6.addWidget(tableWidget)


                t1 = threading.Thread(target=self.browse_form, args=(i, results, tab, tableWidget, verticalLayout_6))
                print(t1)
                thread.append(t1)
                print('当前线程池')
                print(thread)
                self.content.append([i])
                self.content.append(list(results))
            for t in thread:
                # t.setDaemon(True)
                t.start()

            for t in thread:
                t.join()

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            # QMessageBox.warning(self.stackedWidget_1, '提示', '错误：'+ str(e))
            traceback.print_exc()

    #生成修订表tab
    def revise_tab(self, tablename, results):
        # 初始化一个tab页

        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        # 设置成垂直排列
        self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.tab)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        # 把table放到tab里
        self.tableWidget = QtWidgets.QTableWidget(self.tab)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(0)
        self.tableWidget.setRowCount(0)
        self.verticalLayout_6.addWidget(self.tableWidget)
        self.tabWidget.addTab(self.tab, "")
        _translate = QtCore.QCoreApplication.translate

        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", tablename))

        # # 贴到table上
        if results != None and len(results) != 0 and len(results[0]) - 1 > 0:
            self.tableWidget.setRowCount(len(results))
            self.tableWidget.setColumnCount(len(results[0]))
            for i in range(len(results)):
                for j in range(len(results[0])):

                    self.tableWidget.setItem(i, j, QTableWidgetItem(results[i][j]))
            self.tableWidget.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
            self.tableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
            self.tableWidget.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeToContents)
            self.tableWidget.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
            self.tableWidget.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
            self.tableWidget.horizontalHeader().setSectionResizeMode(4, QHeaderView.Stretch)
            self.tableWidget.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)

        headName = constants.head_name_logs
        self.tableWidget.setHorizontalHeaderLabels(headName)

    #在 select_form_resources 中被多线程调用 用来填充数据到tableWidget来显示
    def browse_form(self, tablename, results, tab, tableWidget, verticalLayout_6):
        try:
            print('lokkkkkkk')
            print(results)

            verticalLayout_6.addWidget(tableWidget)
            self.tabWidget.addTab(tab, "")
            _translate = QtCore.QCoreApplication.translate
            self.tabWidget.setTabText(self.tabWidget.indexOf(tab), _translate("MainWindow", tablename))
            tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
            # # 贴到table上
            if results != None and len(results) != 0 and len(results[0]) - 1 > 0:
                tableWidget.setRowCount(len(results))
                tableWidget.setColumnCount(len(results[0]) - 1)
                for i in range(len(results)):
                    for j in range(len(results[0])):
                        if j != 0:
                            tableWidget.setItem(i, j - 1 , QTableWidgetItem(results[i][j]))
                self.rander_table_background_browse(tableWidget)
            #常量表头
            headName = constants.head_name_cn
            tableWidget.setHorizontalHeaderLabels(headName)

        except Exception:
            traceback.print_exc()

    def browse_form2(self, tablename, results, tab, tableWidget, verticalLayout_6):
        try:


            verticalLayout_6.addWidget(tableWidget)
            self.tabWidget.addTab(tab, "")
            _translate = QtCore.QCoreApplication.translate
            self.tabWidget.setTabText(self.tabWidget.indexOf(tab), _translate("MainWindow", tablename))
            tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
            # # 贴到table上
            if results != None and len(results) != 0 and len(results[0]) - 1 > 0:
                tableWidget.setRowCount(len(results))
                tableWidget.setColumnCount(len(results[0]))
                for i in range(len(results)):
                    for j in range(len(results[0])):

                        tableWidget.setItem(i, j , QTableWidgetItem(results[i][j]))
                self.rander_table_background_browse(tableWidget)
            #常量表头
            headName = constants.head_name_cn
            tableWidget.setHorizontalHeaderLabels(headName)

        except Exception:
            traceback.print_exc()

    #单板列表父子勾选逻辑
    def check_item(self,item,col):
        #勾选逻辑
        if item.checkState(col) == QtCore.Qt.Checked:
            for i in range(item.childCount()):
                if(item.child(i).checkState(col) == QtCore.Qt.Unchecked):
                    item.child(i).setCheckState(col,QtCore.Qt.Checked)
            flag = [0]

            if item.parent() != None:
                for i in range(item.parent().childCount()):

                    if item.parent().child(i).checkState(col) == QtCore.Qt.Unchecked:
                        flag[0] = 1

            if flag[0] == 0 and item.parent() != None and item.parent().checkState(col) == QtCore.Qt.Unchecked :


                item.parent().setCheckState(col,QtCore.Qt.Checked)
        #取消勾选逻辑 用到2个flag
        else:
            flag1 = [0]
            flag2 = True
            if item.parent() != None and item.parent().checkState(col) == QtCore.Qt.Checked:
                item.parent().setCheckState(col,QtCore.Qt.Unchecked)
            for i in range(item.childCount()):
                if item.child(i).checkState(col) == QtCore.Qt.Checked:
                    flag1[0] = 1
                flag2 = flag2 and item.child(i).checkState(col) == QtCore.Qt.Checked
            if flag1[0] == 0 or flag2:
                for i in range(item.childCount()):
                    item.child(i).setCheckState(col,QtCore.Qt.Unchecked)
        #收集check的单板

        hardware = []
        for i in range(self.treeWidget.topLevelItemCount()):
            for j in range(self.treeWidget.topLevelItem(i).childCount()):
                if(self.treeWidget.topLevelItem(i).child(j).checkState(col) == QtCore.Qt.Checked):
                    hardware.append(self.treeWidget.topLevelItem(i).child(j).text(col))
        self.selected_hardware  = hardware

    #增加单板列表中的父节点， 也就是形态表
    def add_root(self, name):
        _translate = QtCore.QCoreApplication.translate

        item_0 = QtWidgets.QTreeWidgetItem(self.treeWidget)
        item_0.setCheckState(0, QtCore.Qt.Unchecked)
        self.treeWidget.topLevelItem(self.treeWidget.topLevelItemCount() - 1).setText(0, _translate("MainWindow", name))

        return item_0
    #增加单板列表中的子节点， 也就是单板
    def add_child(self, name, index, root):
        _translate = QtCore.QCoreApplication.translate
        item_1 = QtWidgets.QTreeWidgetItem(root)
        item_1.setCheckState(0, QtCore.Qt.Unchecked)
        self.treeWidget.topLevelItem(self.treeWidget.topLevelItemCount() - 1).child(index).setText(0, _translate("MainWindow", name))
    #弹窗确认提交插入条目
    def double_check_submit(self):
        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定插入该条目？', QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.submit_form()
        else:
            print('cancel')
    #提交查找/插入条件表单
    def submit_form(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            #检测是否为全空
            emptyflag = 1
            #表单
            form = []
            #存储本次查询sql
            sql_store = []
            for i in range(len(constants.head_name_cn)):

                if self.tableWidget_3.item(0,i) != None and self.tableWidget_3.item(0,i).text() != '' and self.tableWidget_3.item(0,i).text().isspace() == False:
                    text = self.tableWidget_3.item(0,i).text().strip()

                    # print(text)

                    form.append(text)
                    emptyflag = 0
                else:
                    form.append('')
            if emptyflag == 1:
                A = QMessageBox.warning(self.stackedWidget_1, '提示', '插入信息不可全空')
                return


            logs_1 = []
            logs_2 = []
            logs_3 = []
            logs_version = []
            logs_algoId = []
            for i in self.selected_hardware:
                #检查输入条件的格式
                #版本号大写处理
                if form[1] != None or len(form[1]) != 0:
                    form[1] = form[1].upper()
                    self.tableWidget_3.item(0, 1).setText(form[1])
                form[0] = form[0].upper()
                self.tableWidget_3.item(0,0).setText(form[0])

                #检查算法表id和subtid、位宽、条数是数字

                if not(self.is_number(form[4])):
                    raise Exception('算法表ID格式错误')
                if not(self.is_number(form[5])):
                    raise Exception('SubTid格式错误')
                if not(self.is_number(form[6])):
                    raise Exception('位宽格式错误')
                if not(self.is_number(form[7])):
                    raise Exception('条数格式错误')
                if len(form[0]) != 11:
                    QMessageBox.warning(self.stackedWidget_1, '提示', '建议版本号命名格式为 "V***R***C**" ')



                sql = insertDB.insert_db(i, form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7],
                                   form[8], form[9], form[10]
                                   , form[11], form[12], form[13], form[14], form[15], form[16], form[17], form[18],
                                   form[19], form[20], form[21], form[22],form[23],form[24],form[25],form[26],form[27],form[28],form[29],form[30],form[31])
                sql_store.append(sql)
                #记录日志
                logs_1.append(form[0])
                logs_2.append(form[3])
                logs_3.append(i)
                logs_version.append(form[0])
                logs_algoId.append(form[4])
                # self.upload_logs('向 ' + i + '中 ' + form[0] + ' 插入 ' + form[1] + ' 成功')
            insertDB.excecute_sql(sql_store, self.db_file)
            for i in range(len(logs_1)):
                self.upload_logs('成功向 ' + logs_3[i] + '插入版本号为：'+ logs_version[i] + '; 业务名为：' + logs_2[i] + '; 算法表ID为：' + logs_algoId[i] + ' 的条目')
            self.search()
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            if str(e).find('name') != -1:
                texts = '业务名重复'
            else :
                texts = str(e)
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', texts)

            self.upload_logs('插入失败 ,' + texts  )
    #判断输入是否为数字
    def is_number(self, s):
        try:
            float(s)
            return True
        except ValueError:
            pass

        try:
            import unicodedata
            unicodedata.numeric(s)
            return True
        except (TypeError, ValueError):
            pass

        return False
    #根据输入搜索数据库
    def search(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            #初始化table
            self.tableWidget_4.clearContents()
            self.tableWidget_4.setRowCount(0)
            #初始化备份
            self.copy = []

            form = []
            for i in range(len(constants.head_name_cn)):
                if self.tableWidget_3.item(0,i) != None and self.tableWidget_3.item(0,i) != '' and self.tableWidget_3.item(0,i).text().isspace() == False:
                    text = self.tableWidget_3.item(0,i).text().strip()
                    # print(text)
                    emptyflag = 0
                    form.append(text)

                else:
                    form.append('None')




            for i in self.selected_hardware:

                results = quarryDB.quarry_search(i, form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7],
                                   form[8], form[9], form[10]
                                   , form[11], form[12], form[13], form[14], form[15], form[16], form[17], form[18],
                                   form[19], form[20], form[21],form[22], form[23],form[24],form[25],form[26],form[27],form[28],form[29],form[30],form[31], self.db_file)
                print(results)
                self.show_search_results(results,i)

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            QMessageBox.warning(self.stackedWidget_1, '提示', '搜索失败：'+str(e))
            traceback.print_exc()
            print('search error')
            self.upload_logs("搜索失败")
    #显示搜索结果
    def show_search_results(self, results,tablename):
        try:
            if results != None and results != '' and len(results) != 0:
                preRow = self.tableWidget_4.rowCount()
                self.tableWidget_4.setRowCount(preRow + len(results))
                self.tableWidget_4.setColumnCount(len(results[0]))
                # 表头
                self.tableWidget_4.setHorizontalHeaderLabels(constants.head_name_search)
                for i in range(len(results)):
                    row = []
                    for j in range(len(results[0])):

                        if j != 0:
                            row.append(results[i][j])
                        self.tableWidget_4.setItem(i + preRow, j, QTableWidgetItem(results[i][j]))
                        if j == 0:
                            row.append(tablename)
                            self.tableWidget_4.setItem(i + preRow, j, QTableWidgetItem(tablename))
                    #拿到当前搜索备份
                    self.copy.append(row)


                # 搜索结果框自适应

                self.tableWidget_4.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)


                self.rander_table_background(self.tableWidget_4)


        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '显示搜索结果失败：'+ str(e))

            print("results is empty")
            traceback.print_exc()
    #修订页显示当前形态表的修订表格
    def select_from_logs(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            resource = self.comboBox_2.currentText()



            self.tableWidget_6.clear()
            self.tableWidget_6.setRowCount(0)
            self.tableWidget_6.setColumnCount(0)
            self.copy_logs = []

                # print(i)

            results = quarryDB.quarry_logs(resource, self.db_file)  # 查询一个table返回所有搜索结果

            if results != None and len(results) != 0:
                self.tableWidget_6.setRowCount(len(results))
                self.tableWidget_6.setColumnCount(len(results[0]))
                headName = constants.head_name_logs
                self.tableWidget_6.setHorizontalHeaderLabels(headName)

                for i in range(len(results)):
                    row = []
                    for j in range(len(results[0])):
                        self.tableWidget_6.setItem(i, j, QTableWidgetItem(results[i][j]))
                        row.append(results[i][j])
                    self.copy_logs.append(row)

                self.tableWidget_6.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeToContents)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(4, QHeaderView.Stretch)
                self.tableWidget_6.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)


            else:
                print("is empty")

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '修订错误：'+str(e))
            traceback.print_exc()
    #搜索结果染色
    def rander_table_background(self, table):
        for i in range(table.rowCount()):
            if table.item(i,5).text().isdigit():
                num = int(table.item(i,5).text()) + 3

                table.item(i,5).setBackground(QBrush(QColor(num*144%255,num*250%255, num * 199 % 255)))

            if table.item(i,6).text().isdigit():
                num = int(table.item(i, 6).text()) + 3
                table.item(i, 6).setBackground(QBrush(QColor(num * 144 % 255, num * 250 % 255, num * 199 % 255)))
    #浏览结果染色
    def rander_table_background_browse(self, table):
        for i in range(table.rowCount()):
            if table.item(i,4).text().isdigit():
                num = int(table.item(i,4).text()) + 3
                

                table.item(i,4).setBackground(QBrush(QColor(num*144%255,num*250%255, num * 199 % 255)))

            if table.item(i,5).text().isdigit():
                num = int(table.item(i, 5).text()) + 3
                table.item(i, 5).setBackground(QBrush(QColor(num*144%255,num*250%255, num * 199 % 255)))
    #删除条目
    def delete(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            form = []
            llog = ''
            for i in range(self.tableWidget_4.rowCount()):
                if self.tableWidget_4.item(i,0).isSelected():
                    for j in range(self.tableWidget_4.columnCount()):
                        form.append(self.tableWidget_4.item(i,j).text().strip())
            if len(form) != 0:
                llog = deleteDB.delete( form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7],
                                   form[8], form[9], form[10]
                                   , form[11], form[12], form[13], form[14], form[15], form[16], form[17], form[18],
                                   form[19], form[20],form[21],form[22],form[23],form[24],form[25],form[26],form[27],form[28],form[29],form[30],form[31],form[32],self.db_file)


                self.search()
            else:
                print('no item selected')
            if llog != '':
                self.upload_logs(llog)
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '删除失败：' + str(e))
            self.upload_logs("删除 " + form[0] + '中的' + form[4] + '失败')
            print('delete error')
    #弹出确认框确认删除
    def double_check_delete(self):
        if self.tableWidget_4.currentItem() == None:
            QMessageBox.warning(self.stackedWidget_1,'提示','尚未选择条目')
            return
        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定删除该条目？', QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.delete()
        else:
            print('cancel')
    #弹出框确认更新
    def double_check_update(self):
        A = QMessageBox.question(self.stackedWidget_1, '确认', '确认更新？', QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.update()
        else:
            print('cancel')
    #原子更新搜索结果框内的条目
    def update(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            llog = ''
            sql_store = []
            lists = []
            upload_log = ''
            for i in range(self.tableWidget_4.rowCount()):
                form = []

                for j in range(self.tableWidget_4.columnCount()):
                    if self.tableWidget_4.item(i,j) != None and self.tableWidget_4.item(i,j).text() != '' and self.tableWidget_4.item(i,j).text().isspace() == False:

                        form.append(self.tableWidget_4.item(i,j).text().strip())
                    else:
                        QMessageBox.warning(self.stackedWidget_1,'提示','更改条目不可为空！')
                        return


                if len(form) != 0:


                    llog = updateDB.update_db( form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7],
                                       form[8], form[9], form[10]
                                       , form[11], form[12], form[13], form[14], form[15], form[16], form[17], form[18],
                                       form[19], form[20],form[21],form[22],form[23],form[24],form[25],form[26],form[27],form[28],form[29],form[30],form[31],form[32], i, self.copy)

                #lists 里面包含log信息和待执行sql

                if llog != None and len(llog) != 0:
                    lists = list(llog)
                    sql_store.append(lists[1])
                    upload_log += lists[0]
            updateDB.sql_excecute(sql_store,self.db_file)

            if upload_log != None and upload_log != '' :
                self.upload_logs(upload_log)
            self.search()
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
            traceback.print_exc()


        except Exception as e:

            QMessageBox.warning(self.stackedWidget_1, '提示', '更新失败:' + str(e))

            traceback.print_exc()
            self.search()
    #搜索结果导出到excel
    def search_to_excel(self):
        try:
            if self.tableWidget_4.rowCount() == None or self.tableWidget_4.rowCount() == 0:
                QMessageBox.warning(self.stackedWidget_1,'提示','搜索结果为空')
                return

            fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "", '' ,".xlsx")

            fileName = list(fileName)


            if fileName[0].find('.xlsx') != -1:
                dir = fileName[0]
            else :

                dir = fileName[0] + fileName[1]
            result = []


            for i in range(self.tableWidget_4.rowCount()):
                row = []
                for j in range(self.tableWidget_4.columnCount()):
                    row.append(self.tableWidget_4.item(i,j).text())
                result.append(row)
            result.insert(0, constants.head_name_search)
            xlsxOpenpyxl.write_excel_xlsx(dir,'sheet1',result)
            QMessageBox.about(self.stackedWidget_1,'提示','导出成功')
            self.upload_logs('导出搜索结果成功')
        except Exception as e:
            traceback.print_exc()
            QMessageBox.about(self.stackedWidget_1,'提示','导出失败:' + str(e))
    #按照版本名导出
    def browse_to_excel(self):
        try:

            if self.tabWidget.tabText(0) == None or self.tabWidget.tabText(0) == '' :
                QMessageBox.warning(self.stackedWidget_1,'提示','请先选择形态表')
                return


            version, ok = QInputDialog.getText(self.stackedWidget_1, "导出版本", "请输入想要导出的版本号:\n\n"
                                                                             "默认导出最新版本"
                                                                         , QLineEdit.Normal, "")

            if ok == True:
                version_list = []

                version_list1 = version.split()
                for i in version_list1:
                    if i.isspace() == True :
                        continue
                    if i == '':
                        continue
                    version_list.append(i.strip())
                print(version_list)
            else :

                return
            if(version_list != None and len(version_list) != 0):

                fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "", version_list[0] + "_NSE资源划分_" + self.comboBox.currentText() , ".xlsx")
            else :
                fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "",
                                                        "NSE资源划分_" + self.comboBox.currentText(), ".xlsx")
            fileName = list(fileName)
            if fileName[0] == None or fileName[0] == '':
                return
            if fileName[0].find('.xlsx') != -1:
                dir = fileName[0]
            else:
                dir = fileName[0] + fileName[1]
            sheetname = ''
            xlsxOpenpyxl.helper(dir)
            self.revise_to_excel(dir)
            for i in range(len(self.content)):
                dict = {}
                onesheet = []
                if len(self.content[i]) == 1 and i % 2 == 0:
                    sheetname = self.content[i][0]
                    #这里得到了一个sheet名字
                    #添加一个sheet页
                    xlsxOpenpyxl.add_sheet(dir,sheetname)
                elif len(self.content[i]) >= 1:
                    for j in self.content[i]:
                        row = list(j)
                        del[row[0]]
                        #如果版本号等于要求的版本号 并且表里不存在这条 直接加进来
                        print(len(version_list))
                        if(len(version_list) == 0) :
                            version_list.append('zzzzzzzzzzz')
                        if row[0] == version_list[0] and (dict.get(row[3],'notFound') == 'notFound'):
                            print("进来了@@@@！！！！！！！！！！！！！！")
                            dict[row[3]] = row
                        elif row[0] < version_list[0] and (row[1] == None or row[1] == 'None' or row[1] >= version_list[0]) and (dict.get(row[3],'notFound')== 'notFound') :
                            dict[row[3]] = row
                        #如果 set里已经存在了一个相同的业务名 需要比较当前版本号和 dict里的大小 而且 最大不能超过要求的版本号
                        elif (dict.get(row[3],'notFound') != 'notFound'):
                            version_in_dict = dict[row[3]][0]
                            version_current = row[0]
                            if (version_current > version_in_dict) and (version_current <= version_list[0]) :
                                dict[row[3]] = row
                    #遍历dict 把条目加到one sheet里
                    for key in dict.keys():
                        onesheet.append(dict[key])
                    onesheet.insert(0, constants.head_name_cn)
                    print('sheet内容')
                    print(onesheet)
                    xlsxOpenpyxl.add_content_to_sheet(dir,sheetname,onesheet, 1)
            xlsxOpenpyxl.cur_head(dir)
            self.upload_logs('导出版本号为')
            QMessageBox.about(self.stackedWidget_1,'提示','导出成功')
        except Exception as e:
            traceback.print_exc()
            print("browse_to_excel error")
            QMessageBox.about(self.stackedWidget_1, '提示', '导出失败' + str(e))
    #导出形态表所有版本
    def form_to_excel(self):
        try:

            if self.tabWidget.tabText(0) == None or self.tabWidget.tabText(0) == '' :
                QMessageBox.warning(self.stackedWidget_1,'提示','请先选择形态表')
                return



            fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "", "NSE资源划分_" + self.comboBox.currentText() , ".xlsx")
            # print(fileName)
            fileName = list(fileName)
            if fileName[0] == None or fileName[0] == '':
                return
            if fileName[0].find('.xlsx') != -1:
                dir = fileName[0]
            else:

                dir = fileName[0] + fileName[1]

            sheetname = ''
            xlsxOpenpyxl.helper(dir)
            self.revise_to_excel(dir)

            for i in range(len(self.content)):
                dict = {}
                onesheet = []
                if len(self.content[i]) == 1 and i % 2 == 0:
                    sheetname = self.content[i][0]
                    #这里得到了一个sheet名字
                    #添加一个sheet页
                    xlsxOpenpyxl.add_sheet(dir,sheetname)
                elif len(self.content[i]) >= 1:
                    # row = list(self.content[i][0])
                    # del[row[0]]

                    for j in self.content[i]:
                        row = list(j)
                        del[row[0]]
                        onesheet.append(row)
                    onesheet.insert(0, constants.head_name_cn)
                    xlsxOpenpyxl.add_content_to_sheet(dir,sheetname,onesheet, 1)
            xlsxOpenpyxl.cur_head(dir)
            QMessageBox.about(self.stackedWidget_1,'提示','导出成功')
        except Exception as e:
            traceback.print_exc()
            print("browse_to_excel error")
            QMessageBox.about(self.stackedWidget_1, '提示', '导出失败' + str(e))
    #导出修订记录
    def revise_to_excel(self, dir):
        sheetname = self.revise_content[0]
        xlsxOpenpyxl.add_sheet(dir, sheetname)
        onesheet = []
        for i in self.revise_content[1]:
            onesheet.append(list(i))
        onesheet.insert(0,constants.head_name_logs)
        xlsxOpenpyxl.add_content_to_sheet(dir, sheetname, onesheet, 0)
    #清空搜索
    def clear_search(self):
        self.tableWidget_3.clearContents()
    #上传日志
    def upload_logs(self, log):
        log = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '  ' + log
        self.listWidget.addItem(log)
        self.statusbar.clearMessage()
        self.statusbar.showMessage('最近一次修改 ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        log_file = open('修改日志.txt',mode = 'a')
        log_file.write(log + '\n')
        log_file.close()
    #弹出框确认
    def double_check_revise(self):

        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确认记录该修订？',
                                     QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.revise_form()
            self.select_from_logs()
        else:
            print('cancel')
    #插入修订记录
    def revise_form(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            form = []
            for i in range(len(constants.head_name_logs_input)):
                if self.tableWidget_5.item(0, i) != None:
                    text = self.tableWidget_5.item(0, i).text().strip()
                    # print(text)

                    form.append(text)

                else:
                    form.append('None')
            tablename = self.comboBox_2.currentText()
            form.insert(0, time.strftime("%Y-%m-%d", time.localtime()))

            insertDB.insert_logs(tablename, form[0], form[1], form[2], form[3], form[4], form[5], self.db_file)

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '插入修订记录失败：'+ str(e))
            traceback.print_exc()
            print('submit_log error')

        # 备份搜索结果 用来进行更新
    #更新整张表
    def update_revise(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            for i in range(self.tableWidget_6.rowCount()):
                form = []
                for j in range(self.tableWidget_6.columnCount()):
                    form.append(self.tableWidget_6.item(i,j).text().strip())
                if len(form) != 0:
                    print(self.copy_logs)
                    updateDB.update_revise_db( self.comboBox_2.currentText(), form[0], form[1], form[2], form[3], form[4], form[5], i, self.copy_logs,self.db_file)

                #更改成功后 备份变成当前

            self.select_from_logs()
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '更新修订失败：' + str(e))
            print('update error')
    #弹出框确认删除修订记录
    def double_check_delete_revise(self):
        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定删除词条修订？',
                                 QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.delete_revise()
        else:
            print('cancel')
    #删除修订记录
    def delete_revise(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            form = []
            for i in range(self.tableWidget_6.rowCount()):
                if self.tableWidget_6.item(i,0).isSelected():
                    for j in range(self.tableWidget_6.columnCount()):
                        form.append(self.tableWidget_6.item(i,j).text().strip())
            if len(form) != 0:
                deleteDB.delete_revise( self.comboBox_2.currentText(),form[0], form[1], form[2], form[3], form[4], form[5],self.db_file)


                self.select_from_logs()
            else:
                print('no item selected')
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            QMessageBox.warning(self.stackedWidget_1, '提示', '删除修订条目失败：' + str(e))
            traceback.print_exc()
            print('delete error')

    browse_store = []
    #从excel导入形态表，进入预览，显示在浏览页上
    def open_excel(self):
        _translate = QtCore.QCoreApplication.translate
        try:
            #清空tab
            fileName = QFileDialog.getOpenFileName(self.stackedWidget_1,'','',"(*.xls *.xlsx)")
            fileName = list(fileName)
            if fileName[0] == None or len(fileName[0]) == 0:
                return
            self.tabWidget.clear()
            #lists结构 lists 里第一行数据是sheet页名字  sheet页第一个是修订后面是单板 [[一个sheet页[一行数据]]]
            self.browse_store = xlsxOpenpyxl.read_excel_xlsx(fileName[0])
            print(self.browse_store)
            self.revise_tab(self.browse_store[0][0], self.browse_store[1])


            thread = []

            for i in range(len(self.browse_store[0])):
                if i == 0 :
                    continue

                tab = QtWidgets.QWidget()
                tab.setObjectName("tab")
                # 设置成垂直排列
                verticalLayout_6 = QtWidgets.QVBoxLayout(tab)
                verticalLayout_6.setObjectName("verticalLayout_6")
                # 把table放到tab里
                tableWidget = QtWidgets.QTableWidget(tab)
                tableWidget.setObjectName("tableWidget")
                tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)


                t1 = threading.Thread(target=self.browse_form2, args=(self.browse_store[0][i], self.browse_store[i + 1], tab, tableWidget, verticalLayout_6))
                thread.append(t1)

            for t in thread:
                t.setDaemon(True)
                t.start()

            for t in thread:
                t.join()


            self.label_4.setText(_translate("MainWindow", "预览：" + fileName[0]))
            self.pushButton_20.hide()
            self.pushButton_12.hide()
            self.pushButton_13.hide()
            self.pushButton_save_form.hide()
            self.comboBox.hide()
            self.label_3.hide()
            self.pushButton_21.show()
            self.pushButton_22.show()
            QMessageBox.about(self.stackedWidget_1,'提示','导入成功')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '打开文件失败：' + str(e))
            traceback.print_exc()
            self.comboBox.setcurrentText()
    #退出预览
    def close_browse(self):
        _translate = QtCore.QCoreApplication.translate
        self.pushButton_21.hide()
        self.pushButton_22.hide()
        self.pushButton_20.show()
        self.pushButton_12.show()
        self.pushButton_save_form.show()
        self.pushButton_13.show()
        self.comboBox.show()
        self.label_3.show()
        self.label_4.setText(_translate("MainWindow", "当前形态"))
        self.tabWidget.clear()
    #先判断形态表已经存在
    def save_browse(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            excelName = self.tabWidget.tabText(0).replace('修订记录','').strip()
            flag = 1
            droptable = []
            oldname = []
            newname = []
            hardware = self.get_table_from_form(excelName)
            rootlist = quarryDB.quarry_form_store(self.db_file)
            rootlist = list(rootlist)
            rootlist.insert(0,"形态表")

            resources_list = []
            for i in rootlist:
                if i == '形态表':
                    resources_list.append(i)
                else:
                    i = list(i)
                    resources_list.append(i[0])

            #判断这个excel中的形态表是否存在
            for i in resources_list:

                if excelName == i:
                    flag = 0
            for i in range(self.tabWidget.count()):
                if i == 0:
                    if '修订记录' not in self.tabWidget.tabText(0):
                        QMessageBox.about(self.stackedWidget_1, '提示', 'excel格式错误，缺少修订记录' )
                    else:
                        continue

                if self.tabWidget.tabText(i) not in hardware:
                    QMessageBox.about(self.stackedWidget_1, '提示', 'Excel存在未注册单板：'+self.tabWidget.tabText(i))
                    return
            droplog = ''
            if flag == 0:
                #先建表 成功后再删表 然后
                for i in range(self.tabWidget.count()):
                    sqls = []
                    if i == 0:
                        print(self.browse_store)
                        sqlite3DB.create_log(excelName + '_tmp',self.db_file)
                        for j in self.browse_store[1]:
                            insertDB.insert_logs(excelName+'_tmp', j[0],j[1],j[2],j[3],j[4],j[5], self.db_file)


                        droplog = excelName+'_logs'

                        oldname.append(excelName+'_tmp_logs')
                        newname.append(excelName+'_logs')
                    else:
                        #从db调出单板列表
                        hardware = self.get_table_from_form(excelName)
                        for j in hardware:
                            if j == self.tabWidget.tabText(i):
                                sqlite3DB.create_table(self.tabWidget.tabText(i) + '_tmp',self.db_file)





                        for j in self.browse_store[i + 1]:

                            sql = insertDB.insert_db(self.tabWidget.tabText(i)+'_tmp', j[0],j[1],j[2],j[3],j[4],j[5],j[6]
                                                   ,j[7],j[8],j[9],j[10],j[11],j[12],j[13],j[14],j[15],j[16],j[17],
                                                   j[18],j[19],j[20],j[21],j[22],j[23],j[24],j[25],j[26],j[27],j[28],j[29],j[30],j[31])
                            sqls.append(sql)
                        insertDB.excecute_sql(sqls, self.db_file)

                        oldname.append(self.tabWidget.tabText(i)+'_tmp')
                        newname.append(self.tabWidget.tabText(i))

                #等所有新表都更新后  删掉旧表
                droptable = self.get_table_from_form(excelName)
                droptable.insert(0,droplog)
                for i in range(len(droptable)):
                    sqlite3DB.drop_table(droptable[i], self.db_file)
                for i in range(len(oldname)):
                    sqlite3DB.rename_table(oldname[i], newname[i], self.db_file)


                QMessageBox.about(self.stackedWidget_1, '提示', '覆盖成功')
                self.close_browse()
                self.upload_logs("覆盖 " + excelName + " 成功")
                self.upload_logs("——————————————————————————————————————————————————————")



            else:
                QMessageBox.warning(self.stackedWidget_1,'提示','该形态表尚不存在，请先注册后添加')
                return



        except IndexError as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1,'提示','Excel格式错误')

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')

        except Exception as e:
            traceback.print_exc()
            error= str(e)
            QMessageBox.warning(self.stackedWidget_1, '提示', '保存失败：'+str(e))

        finally:
            sqlite3DB.delete_tmp(self.db_file)
            self.close_browse()
    #弹窗确认覆盖
    def double_check_overwrite(self):

        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定覆盖该形态表？',
                                 QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            #先备份数据库和全表excel
            self.auto_save_db()
            self.save_browse()

        else:
            print('cancel')
    # 单板列表右键菜单
    def showContextMenu(self):
        self.contextMenu.exec_(QCursor.pos())
    #搜索结果框右键删除菜单
    def showDeleteMenu(self):
        self.deleteMenu.exec_(QCursor.pos())
    #新建形态表
    def menu_newForm(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            # 第三个参数表示显示类型，可选，有正常（QLineEdit.Normal）、密碼（ QLineEdit. Password）、不显示（ QLineEdit. NoEcho）三种情况
            formname, ok = QInputDialog.getText(self.treeWidget, "新建形态表", "命名新的形态表:", QLineEdit.Normal, "")
            if ok == True:
                formname.strip()

                if formname == None or formname == '' or formname.isspace == True:
                    raise Exception('形态表不可为空')
                else:
                    form_list = list(quarryDB.quarry_form_store(self.db_file))
                    print(form_list)
                    for i in form_list:
                        if i == formname:
                            raise Exception('形态表已存在')
                    #二次确认插入
                    A = QMessageBox.question(self.stackedWidget_1, '确认', '确定新建形态表：'+formname+' ？',
                                             QMessageBox.Yes | QMessageBox.No)
                    if A == QMessageBox.Yes:
                        #注册到form store里
                        insertDB.insert_form(formname, self.db_file)
                        #创建一个存储新的单板的form表
                        sqlite3DB.create_form(formname, self.db_file)
                        sqlite3DB.create_log(formname, self.db_file)
                        QMessageBox.warning(self.stackedWidget_1, '提示', '形态表 ' + formname + ' 新建成功')
                        self.upload_logs('新建形态表:' + formname)
                        self.refresh_tree()
                        self.init_menu()
                    else:
                        print('取消创建')

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            A = QMessageBox.warning(self.stackedWidget_1, '提示', '新建失败,' + str(e))

            self.upload_logs('新建失败，' + str(e))
    #新建新单板
    def menu_newHardware(self):

        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            #获得被点击的条目
            if self.treeWidget.currentItem().parent() == None:
                formname = self.treeWidget.currentItem().text(0)
            else:
                formname = self.treeWidget.currentItem().parent().text(0)

            # 第三个参数表示显示类型，可选，有正常（QLineEdit.Normal）、密碼（ QLineEdit. Password）、不显示（ QLineEdit. NoEcho）三种情况
            tablename, ok = QInputDialog.getText(self.treeWidget, "新建单板", "在" + formname + "中命名新的单板:", QLineEdit.Normal, "")
            if ok == True:
                tablename.strip()
                print(tablename)
                if tablename == None or tablename == '' or tablename.isspace == True:
                    raise Exception('单板名称不可为空')
                else:
                    form_list = list(quarryDB.quarry_form_store(self.db_file))
                    for formname in form_list:
                        formname = list(formname)

                        table_list = list(quarryDB.quarry_form(formname[0],self.db_file))

                        for i in table_list:
                            i = list(i)



                            if i[0] == tablename:
                                raise Exception('该单板已存在')
                    # 二次确认插入
                    A = QMessageBox.question(self.stackedWidget_1, '确认', '确定新建单板：' + tablename + ' ？',
                                             QMessageBox.Yes | QMessageBox.No)
                    if A == QMessageBox.Yes:
                        # 将单板注册到form里
                        insertDB.insert_hardware(formname[0], tablename, self.db_file)
                        # 创建一个存储新的单板的form表 和logs
                        sqlite3DB.create_table(tablename, self.db_file)




                        self.upload_logs('新建单板:' + tablename)
                        self.refresh_tree()
                        self.init_menu()

                        A = QMessageBox.question(self.stackedWidget_1, '确认', '新建成功，是否立即录入单板信息？',
                                                 QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
                        if A == QMessageBox.Yes:
                            self.redirect_to_hardware_info(formname, tablename)
                        else:
                            print('cancel')


                    else:
                        print('取消创建')

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            A = QMessageBox.warning(self.stackedWidget_1, '提示', '新建失败,' + str(e))

            self.upload_logs('新建失败，' + str(e))
    #新建单板后跳转到单板信息
    def redirect_to_hardware_info(self, formname, tablename):
        self.pushButton_edit.click()

        print(self.tableWidget_v8Input.item(0,2))
        self.tableWidget_v8Input.setItem(0,2, QTableWidgetItem(formname))
        self.tableWidget_v8Input.setItem(0,0, QTableWidgetItem(tablename))
    #刷新单板列表
    def refresh_tree(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            self.treeWidget.clear()
            rootlist = quarryDB.quarry_form_store(self.db_file)
            rootlist = list(rootlist)

            for i in range(len(rootlist)):

                cur = list(rootlist[i])
                root = self.add_root(cur[0])
                print(root)
                # 从constants初始化tree 下拉表单的子表（单板）
                childlist = quarryDB.quarry_form(root.text(0), self.db_file)
                childlist = list(childlist)

                for j in range(len(childlist)):
                    tmp = list(childlist[j])
                    self.add_child(tmp[0], j, root)
            resources_list = []
            for i in rootlist:

                i = list(i)
                resources_list.append(i[0])


            self.comboBox_2.clear()
            self.comboBox_2.addItems(resources_list)
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            QMessageBox.warning(self.stackedWidget_1, '提示', '刷新单板列表失败：' + str(e))
            traceback.print_exc()
    #删除单板或者形态表
    def menu_delete(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            form = self.treeWidget.currentItem()
            if form.parent() != None:
                #警告
                A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确认删除单板' + form.text(0)+'？',
                                         QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
                if A == QMessageBox.Yes:
                    deleteDB.delete_table_from_form(form.parent().text(0), form.text(0),self.db_file)
                    self.upload_logs('成功删除单板 '+form.text(0))
                    self.refresh_tree()
                    self.init_menu()
                else:
                    print('cancel')
                    return
            #父节点
            elif form.parent() == None and form.childCount() != 0:
                QMessageBox.warning(self.stackedWidget_1,'警告','无法删除，' + form.text(0) +'形态表尚存在单板')
                return
            else:
                # 警告
                A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确认删除形态表' + form.text(0) + '？',
                                         QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
                if A == QMessageBox.Yes:
                    deleteDB.delete_form_from_formstore(form.text(0), self.db_file)
                    self.upload_logs('成功删除单板 ' + form.text(0))
                    self.refresh_tree()
                else:
                    print('cancel')
                    return
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '删除失败：' + str(e))
            self.upload_logs(e)
    #通过形态表名获得单板list
    def get_table_from_form(self,formname):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            cur = quarryDB.quarry_form(formname, self.db_file)

            resource_list = []
            for i in cur:
                i = list(i)
                resource_list.append(i[0])
            return resource_list
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '获取单板列表失败：'+ str(e))
            traceback.print_exc()

    #返回所有形态表名 初始化tree窗口
    def tree_init(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            rootlist = quarryDB.quarry_form_store(self.db_file)
            rootlist = list(rootlist)

            for i in range(len(rootlist)):
                cur = list(rootlist[i])
                root = self.add_root(cur[0])
                print(root)

                childlist = quarryDB.quarry_form(root.text(0), self.db_file)
                childlist = list(childlist)

                for j in range(len(childlist)):
                    tmp = list(childlist[j])
                    self.add_child(tmp[0], j, root)
            resources_list = []
            for i in rootlist:
                i = list(i)
                resources_list.append(i[0])
            return resources_list
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '初始化单板列表失败：'+ str(e))
            traceback.print_exc()
    #拿到所有形态表的名字
    def get_all_form_name(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            rootlist = quarryDB.quarry_form_store(self.db_file)
            rootlist = list(rootlist)
            resources_list = []
            for i in rootlist:
                i = list(i)
                resources_list.append(i[0])
            return resources_list
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :

            traceback.print_exc()
    #浏览表刷新键
    def refresh_browse(self):
        try:
            num = self.comboBox.currentIndex()
            print('进入num')
            self.comboBox.clear()
            print('清空box')
            self.comboBox.addItems(self.get_all_form_name())
            print('添加橡木')
            self.comboBox.setCurrentIndex(num)
            print('设置index')
        except Exception as e:

            traceback.print_exc()
    #查询单板信息表
    def quarry_hardware_info(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            result = quarryDB.quarry_hardware_info(self.db_file)

            # 贴到table上
            self.tableWidget_v8.setRowCount(len(result))
            self.tableWidget_v8.setColumnCount(len(result[0]))
            # 表头
            for i in range(len(result)):
                for j in range(len(result[0])):
                    self.tableWidget_v8.setItem(i, j, QTableWidgetItem(result[i][j]))
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '查询单板信息失败：'+ str(e))
            traceback.print_exc()
    #弹出窗确认插入单板信息
    def double_check_insert_hardware_info(self):
        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定插入该单板信息？', QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.insert_hardware_info()
        else:
            print('cancel')
    #插入单板信息
    def insert_hardware_info(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            emptyflag = 0
            form = []
            for i in range(self.tableWidget_v8Input.columnCount()):
                if self.tableWidget_v8Input.item(0, i) != None and self.tableWidget_v8Input.item(0,i).text() != '' and self.tableWidget_v8Input.item(0,i).text().isspace() == False:
                    text = self.tableWidget_v8Input.item(0, i).text().strip()
                    # print(text)
                    emptyflag = 1
                    form.append(text)

                else:
                    form.append('N/A')
            if emptyflag == 0:
                QMessageBox.warning(self.stackedWidget_1,'提示','输入不可全空')
                return



            insertDB.insert_hardware_info(form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7], form[8], form[9],form[10],form[11],form[12],form[13], self.db_file)

            self.quarry_hardware_info()
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '插入单板信息失败：' + str(e))
            print('submit_hardware_info error')
    #弹出框确认删除单板信息
    def double_check_delete_hardware_info(self):

        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定删除该条目？',
                                 QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.delete_hardware_info()
        else:
            print('cancel')
    #删除单板信息
    def delete_hardware_info(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            form = []
            llog = ''
            for i in range(self.tableWidget_v8.rowCount()):
                if self.tableWidget_v8.item(i,0).isSelected():
                    for j in range(self.tableWidget_v8.columnCount()):
                        form.append(self.tableWidget_v8.item(i,j).text().strip())
            if len(form) != 0:
                llog = deleteDB.delete_hardware_info( form[0], form[1], form[2], form[3], form[4], form[5], form[6], form[7],
                                   form[8], form[9], form[10]
                                   , form[11], form[12], form[13],self.db_file)


                self.quarry_hardware_info()
            else:
                QMessageBox.warning(self.stackedWidget_1,'提示','没有选中条目')
                print('no item selected')
            if llog != '':
                self.upload_logs(llog)
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e :
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '删除单板信息失败：' + str(e))
            print('delete error')
    #导出单板信息
    def hardware_info_to_excel(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "", "V8算法组支持单板", ".xlsx")
            # print(fileName)
            fileName = list(fileName)
            if fileName[0] == None or fileName[0] == '':
                return
            if fileName[0].find('.xlsx') != -1:
                dir = fileName[0]
            else:

                dir = fileName[0] + fileName[1]


            xlsxOpenpyxl.helper(dir)
            hardware_info = quarryDB.quarry_hardware_info(self.db_file)

            xlsxOpenpyxl.add_sheet(dir, '单板信息')
            onesheet = []
            for i in hardware_info:
                onesheet.append(list(i))
            onesheet.insert(0, constants.head_name_hardware_info)
            xlsxOpenpyxl.cur_head(dir)
            xlsxOpenpyxl.add_content_to_sheet(dir, '单板信息', onesheet, 2)
            QMessageBox.about(self.stackedWidget_1,'提示','导出成功')
        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '导出错误：'+ str(e))

            print("browse_to_excel error")

    hardware_info_excel_name = ''
    #从excel 导入单板信息
    def excel_to_hardware_info(self):
        _translate = QtCore.QCoreApplication.translate
        try:
            #清空tab


            fileName = QFileDialog.getOpenFileName(self.stackedWidget_1,'','',"*.xlsx")
            fileName = list(fileName)

            if fileName[0] == None or len(fileName[0]) == 0:
                return
            self.tableWidget_v8.clear()
            self.hardware_info_excel_name = fileName[0]
            #lists结构 lists 里第一行数据是sheet页名字  sheet页第一个是修订后面是单板 [[一个sheet页[一行数据]]]
            hardware_info = xlsxOpenpyxl.read_excel_xlsx(fileName[0])
            print(hardware_info)
            for i in range(len(hardware_info[1])):



                if hardware_info[1] != None and len(hardware_info[1]) != 0 :
                    self.tableWidget_v8.setRowCount(len(hardware_info[1]))
                    self.tableWidget_v8.setColumnCount(len(hardware_info[1][0]))
                    for i in range(len(hardware_info[1])):
                        for j in range(len(hardware_info[1][0])):
                            cur = hardware_info[1]
                            self.tableWidget_v8.setItem(i, j, QTableWidgetItem(cur[i][j]))


            headName = constants.head_name_hardware_info
            self.tableWidget_v8.setHorizontalHeaderLabels(headName)

            self.tableWidget_v8Input.hide()
            self.pushButton_30.hide()
            self.pushButton_31.hide()
            self.pushButton_32.hide()
            self.pushButton_33.hide()
            self.pushButton_34.show()
            self.pushButton_35.show()
            self.label_14.hide()
            self.label_13.setText('预览单板信息：' + fileName[0])








        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '导入失败：'+ str(e))
            traceback.print_exc()
            self.comboBox.setcurrentText()
    #退出预览
    def close_hardware_info(self):
        self.tableWidget_v8Input.show()
        self.pushButton_30.show()
        self.pushButton_31.show()
        self.pushButton_32.show()
        self.pushButton_33.show()
        self.pushButton_34.hide()
        self.pushButton_35.hide()
        self.label_14.show()
        self.label_13.setText('V8算法组支持单板：')
        self.quarry_hardware_info()
    #弹出框确认覆盖
    def double_check_save_hardware_info(self):
        A = QMessageBox.question(self.stackedWidget_1, '确认', '是否确定覆盖单板信息？', QMessageBox.Yes | QMessageBox.No)  # 创建一个二次确认框
        if A == QMessageBox.Yes:
            self.auto_save_db()
            self.save_hardware_info()
        else:
            print('cancel')
    #覆盖单板信息
    def save_hardware_info(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException
            if self.hardware_info_excel_name != None and self.hardware_info_excel_name != '':
                hardware_info = xlsxOpenpyxl.read_excel_xlsx(self.hardware_info_excel_name)
                #先建表
                sqlite3DB.create_hardware_info(self.db_file)

                for i in hardware_info[1]:
                    insertDB.insert_hardware_info_tmp(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10],i[11],i[12],i[13], self.db_file)
                sqlite3DB.drop_table('hardware_info', self.db_file)
                sqlite3DB.rename_table('hardware_info_tmp','hardware_info',self.db_file)

                QMessageBox.warning(self.stackedWidget_1,'提示','覆盖成功')

        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '覆盖失败：'+str(e))
            traceback.print_exc()
            try:
                sqlite3DB.drop_table('hardware_info_tmp', self.db_file)
            except Exception:
                traceback.print_exc()
    # 打开db
    def open_db(self):
        try:

            fileName = QFileDialog.getOpenFileName(self.stackedWidget_1, '', '', "*.db")
            fileName = list(fileName)
            if fileName[0] == None or len(fileName[0]) == 0:
                return
            self.db_file = fileName[0]
            print(self.db_file)

            self.comboBox.clear()
            self.comboBox_2.clear()
            self.treeWidget.clear()
            resources_list = self.tree_init()
            self.quarry_hardware_info()
            # 批量插入表下拉资源单监听
            self.comboBox.addItems(resources_list)
            self.comboBox.currentIndexChanged.connect(self.select_from_resources)
            self.selected_hardware = []
            #修订页下拉资源单
            self.comboBox_2.addItems(resources_list)
            self.comboBox_2.currentTextChanged.connect(self.select_from_logs)
            self.init_menu()
        except Exception as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '打开数据库失败：' + str(e))
            traceback.print_exc()
    #备份db
    def save_db(self):
        try:
            if self.db_file == None or self.db_file == '':
                raise noDBException

            dir = ''
            fileName = QFileDialog.getSaveFileName(self.stackedWidget_1, "", "", ".db")

            fileName = list(fileName)
            if fileName[0] == None or len(fileName[0]) == 0:
                return


            if fileName[0].find('.db') != -1:
                dir = fileName[0]
            else:

                dir = fileName[0] + fileName[1]

            copyfile(self.db_file, dir)

        except IOError as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '备份失败，数据库可能已锁:' + str(e) )
            traceback.print_exc()


        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')

        except Exception as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '备份失败：' + str(e))
    #自动备份
    def auto_save_db(self):
        try:

            b = os.getcwd() + '\\auto_save_db\\'
            if not os.path.exists(b):
                os.makedirs(b)
            file = b + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) +'.db'

            print(file)


            copyfile(self.db_file, file)

        except IOError as e:
            QMessageBox.warning(self.stackedWidget_1, '提示', '备份失败:' + str(e))
            traceback.print_exc()


        except noDBException:
            QMessageBox.warning(self.stackedWidget_1, '提示', '请先选择数据库')

        except Exception as e:
            traceback.print_exc()
            QMessageBox.warning(self.stackedWidget_1, '提示', '备份失败：' + str(e))

    def open_helper(self):
        try:
            webbrowser.open("说明.docx")
        except Exception:
            traceback.print_exc()




class noDBException(Exception):

    def __init__(self):
        print('没有打开db')
    def __str__(self):
        print("没有打开db")



#必须加入的
import sys
sys.setrecursionlimit(1000000)

from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QMessageBox, QHeaderView

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(mainWindow)
    mainWindow.show()
    sys.exit(app.exec_())