Ejemplo n.º 1
0
class MainWindow(QMainWindow):
    def __init__(self, user: User):
        super().__init__()
        logging.debug("MainWindow creation")
        self.ui = Ui_MainWindow(self)
        self.retranslate_ui()
        self.set_offer_ui_enabled(False)

        self.font_database = QFontDatabase()
        self.font_database.addApplicationFont(':/font-regular')
        self.font_database.addApplicationFont(':/font-medium')
        self.font_database.addApplicationFont(':/font-bold')
        self.offer_font = self.font_database.font('Montserrat', 'Regular', 7)
        logging.info(f"Loaded font for offer print: {self.offer_font.family()} {self.offer_font.styleName()}")

        self.offer = None
        self.user = user
        self.calendar = QCalendarWidget()

        self.ui.action_new.triggered.connect(self.new_offer)
        self.ui.action_open.triggered.connect(self.load_offer)
        self.ui.action_save.triggered.connect(self.save_offer)
        self.ui.action_new_number.triggered.connect(self.new_offer_symbol)
        self.ui.action_exit.triggered.connect(self.exit)

        self.ui.action_print.triggered.connect(self.print_preview)
        self.ui.action_PDF.triggered.connect(self.print_pdf)

        self.ui.action_create_merchandise.triggered.connect(self.create_merchandise)
        self.ui.action_create_customer.triggered.connect(self.create_customer)

        self.ui.action_about.triggered.connect(self.about)
        self.ui.action_about_Qt.triggered.connect(self.about_qt)

        self.ui.push_button_add_merchandise.clicked.connect(self.select_merchandise)
        self.ui.push_button_remove_row.clicked.connect(self.remove_row)
        self.ui.push_button_discount.clicked.connect(self.set_discount)
        self.ui.push_button_discount_group.clicked.connect(self.set_discount_group)

        self.ui.command_link_button_customer.clicked.connect(self.select_customer)
        self.ui.check_box_query_date.stateChanged.connect(self.inquiry_date_toggled)
        self.ui.line_edit_query_date.textChanged.connect(self.inquiry_date_text_changed)
        self.ui.push_button_query_date.clicked.connect(self.inquiry_date_button_clicked)
        self.ui.check_box_query_number.stateChanged.connect(self.inquiry_number_toggled)
        self.ui.line_edit_query_number.textChanged.connect(self.inquiry_number_changed)

        self.ui.command_link_button_delivery.clicked.connect(self.select_delivery_terms)
        self.ui.command_link_button_offer.clicked.connect(self.select_offer_terms)
        self.ui.command_link_button_billing.clicked.connect(self.select_billing_terms)
        self.ui.command_link_button_delivery_date.clicked.connect(self.select_delivery_date_terms)
        self.ui.plain_text_edit_remarks.textChanged.connect(self.update_remarks)

        # must be connected at the end or will break tests
        self.calendar.clicked.connect(self.inquiry_date_changed)

    def retranslate_ui(self) -> None:
        self.ui.menu_offer.setTitle(self.tr("Offer"))
        self.ui.menu_export.setTitle(self.tr("Export"))
        self.ui.menu_database.setTitle(self.tr("Database"))
        self.ui.menu_help.setTitle(self.tr("Help"))
        self.ui.action_new.setText(self.tr("New"))
        self.ui.action_open.setText(self.tr("Open"))
        self.ui.action_save.setText(self.tr("Save"))
        self.ui.action_exit.setText(self.tr("Exit"))
        self.ui.action_PDF.setText(self.tr("PDF"))
        self.ui.action_print.setText(self.tr("Print preview"))
        self.ui.action_create_merchandise.setText(self.tr("Create merchandise"))
        self.ui.action_create_customer.setText(self.tr("Create customer"))
        self.ui.action_about.setText(self.tr("About"))
        self.ui.action_about_Qt.setText(self.tr("About Qt"))
        self.ui.action_new_number.setText(self.tr("Set new offer symbol"))
        self.ui.push_button_add_merchandise.setText(self.tr("Add merchandise"))
        self.ui.push_button_discount.setText(self.tr("Set Discount"))
        self.ui.push_button_discount_group.setText(self.tr("Set Discount for group"))
        self.ui.push_button_remove_row.setText(self.tr("Remove row"))
        self.ui.tabWidget.setTabText(self.ui.tabWidget.indexOf(self.ui.tab), self.tr("Offer table"))
        self.ui.tabWidget.setTabText(self.ui.tabWidget.indexOf(self.ui.tab_2), self.tr("Other information"))
        self.ui.command_link_button_customer.setText(self.tr("Choose customer"))
        self.ui.grup_box_query.setTitle(self.tr("Inquiry"))
        self.ui.check_box_query_date.setText(self.tr("Inquiry date:"))
        self.ui.push_button_query_date.setText("")
        self.ui.check_box_query_number.setText(self.tr("Inquiry number:"))
        self.ui.groupBox.setTitle(self.tr("Other information"))
        self.ui.command_link_button_delivery.setText(self.tr("Shipment terms"))
        self.ui.command_link_button_delivery_date.setText(self.tr("Delivery date"))
        self.ui.command_link_button_billing.setText(self.tr("Billing terms"))
        self.ui.command_link_button_offer.setText(self.tr("Offer terms"))
        self.ui.command_link_button_remarks.setText(self.tr("Remarks"))
        self.ui.group_box_columns.setTitle(self.tr("Columns to be printed"))
        self.ui.check_box_no_column.setText(self.tr("No."))
        self.ui.check_box_code_column.setText(self.tr("Code"))
        self.ui.check_box_details_column.setText(self.tr("Specification"))
        self.ui.check_box_list_price_column.setText(self.tr("List Price"))
        self.ui.check_box_discount_column.setText(self.tr("Discount"))
        self.ui.check_box_price_column.setText(self.tr("Price"))
        self.ui.check_box_quantity_column.setText(self.tr("Quantity"))
        self.ui.check_box_total_column.setText(self.tr("Total"))

    def set_offer_ui_enabled(self, enable: bool) -> None:
        # menus
        self.ui.menu_export.setEnabled(enable)
        self.ui.action_save.setEnabled(enable)
        self.ui.action_new_number.setEnabled(enable)
        # tabs
        self.ui.tab.setEnabled(enable)
        self.ui.tab_2.setEnabled(enable)

    def update_inquiry_text(self) -> None:
        self.ui.plain_text_edit_query.setPlainText(self.offer.inquiry_text)

    @Slot()
    def new_offer(self) -> None:
        self.offer = Offer.create_empty(self.user, self)
        self.set_offer_ui_enabled(True)
        self.setWindowTitle(f"pyOffer - {self.offer.symbol}")
        self.ui.tableView.setModel(self.offer.merchandise_list)
        self.update_inquiry_text()

    @Slot()
    def new_offer_symbol(self) -> None:
        self.offer.new_symbol()
        self.setWindowTitle(f"pyOffer - {self.offer.symbol}")

    @Slot()
    def select_customer(self) -> None:
        dialog = CustomerSelectionDialog.make(self)
        if dialog.exec_() == QDialog.Accepted and dialog.chosen_customer:
            self.ui.plain_text_edit_customer.setPlainText(dialog.chosen_customer.description)
            self.offer.customer = dialog.chosen_customer

    @Slot()
    def update_remarks(self) -> None:
        self.offer.remarks = self.ui.plain_text_edit_remarks.toPlainText()

    @Slot()
    def select_delivery_terms(self) -> None:
        term_type = TermType.delivery
        dialog = TermsChooserDialog.make(term_type, self)
        if dialog.exec_() == QDialog.Accepted and dialog.chosen_item:
            self.ui.plain_text_edit_delivery.setPlainText(dialog.chosen_item.long_desc)
            self.offer.terms[term_type] = dialog.chosen_item

    @Slot()
    def select_offer_terms(self) -> None:
        term_type = TermType.offer
        dialog = TermsChooserDialog.make(term_type, self)
        if dialog.exec_() == QDialog.Accepted and dialog.chosen_item:
            self.ui.plain_text_edit_offer.setPlainText(dialog.chosen_item.long_desc)
            self.offer.terms[term_type] = dialog.chosen_item

    @Slot()
    def select_billing_terms(self) -> None:
        term_type = TermType.billing
        dialog = TermsChooserDialog.make(term_type, self)
        if dialog.exec_() == QDialog.Accepted and dialog.chosen_item:
            self.ui.plain_text_edit_billing.setPlainText(dialog.chosen_item.long_desc)
            self.offer.terms[term_type] = dialog.chosen_item

    @Slot()
    def select_delivery_date_terms(self) -> None:
        term_type = TermType.delivery_date
        dialog = TermsChooserDialog.make(term_type, self)
        if dialog.exec_() == QDialog.Accepted and dialog.chosen_item:
            self.ui.plain_text_edit_delivery_date.setPlainText(dialog.chosen_item.long_desc)
            self.offer.terms[term_type] = dialog.chosen_item

    @Slot()
    def select_merchandise(self) -> None:
        dialog = MerchandiseSelectionDialog.make(self)
        dialog.exec_()
        for item in dialog.selected.values():
            self.offer.merchandise_list.change_item_count(item)

    @Slot()
    def remove_row(self) -> None:
        index = self.ui.tableView.currentIndex()
        if index.row() < self.offer.merchandise_list.rowCount():
            self.offer.merchandise_list.removeRow(index.row())

    @Slot()
    def set_discount(self) -> None:
        dialog = DiscountDialog(self)
        dialog.line_edit_expression.textChanged.connect(self.offer.merchandise_list.select_items)
        self.offer.merchandise_list.select_items("")
        if dialog.exec_() == QDialog.Accepted:
            self.offer.merchandise_list.apply_discount(dialog.discount_value)
        else:
            self.offer.merchandise_list.select_items(None)

    @Slot()
    def set_discount_group(self) -> None:
        dialog = DiscountGroupDialog(self.offer.merchandise_list.get_discount_groups(), self)
        dialog.selectionChanged.connect(self.offer.merchandise_list.select_items)
        if dialog.exec_() == QDialog.Accepted:
            self.offer.merchandise_list.apply_discount(dialog.discount_value)
        else:
            self.offer.merchandise_list.select_items(None)

    @Slot()
    def inquiry_date_button_clicked(self) -> None:
        self.ui.check_box_query_date.setChecked(Qt.Checked)
        self.calendar.show()

    @Slot(QDate)
    def inquiry_date_changed(self, d: QDate) -> None:
        self.ui.line_edit_query_date.setText(f"{d.toPython():%d.%m.%Y}")
        self.calendar.close()

    @Slot(int)
    def inquiry_date_toggled(self, state: int) -> None:
        enabled = state == Qt.Checked
        self.ui.line_edit_query_date.setEnabled(enabled)
        if enabled:
            self.ui.line_edit_query_date.setText(f"{date.today():%d.%m.%Y}")
        else:
            self.ui.line_edit_query_date.clear()

    @Slot(str)
    def inquiry_date_text_changed(self, text: str) -> None:
        self.offer.inquiry_date = text
        self.update_inquiry_text()

    @Slot(int)
    def inquiry_number_toggled(self, state: int) -> None:
        enabled = state == Qt.Checked
        self.ui.line_edit_query_number.setEnabled(enabled)
        if not enabled:
            self.ui.line_edit_query_number.clear()

    @Slot(str)
    def inquiry_number_changed(self, text: str) -> None:
        self.offer.inquiry_number = text
        self.update_inquiry_text()

    @Slot()
    def load_offer(self) -> None:
        pass

    @Slot()
    def save_offer(self) -> None:
        pass

    @Slot()
    def exit(self) -> None:
        """Forward to QMainWindow.close, but keep here for sake of tests"""
        super().close()

    @Slot(QPrinter)
    def print(self, printer: QPrinter) -> None:
        print_options = PrintOptions(
            print_no=self.ui.check_box_no_column.isChecked(),
            print_code=self.ui.check_box_code_column.isChecked(),
            print_description=self.ui.check_box_details_column.isChecked(),
            print_list_price=self.ui.check_box_list_price_column.isChecked(),
            print_discount=self.ui.check_box_discount_column.isChecked(),
            print_price=self.ui.check_box_price_column.isChecked(),
            print_quantity=self.ui.check_box_quantity_column.isChecked(),
            print_total=self.ui.check_box_total_column.isChecked()
        )
        margin = 5
        printer.setPageSize(QPrinter.A4)
        printer.setPageMargins(margin, margin, margin, margin, QPrinter.Millimeter)
        printer.setResolution(96)

        doc = QTextDocument()
        doc.setUseDesignMetrics(True)
        doc.setDefaultFont(self.offer_font)
        doc.setHtml(self.offer.printout(print_options))
        doc.setPageSize(printer.pageRect().size())
        doc.print_(printer)

    @Slot()
    def print_preview(self) -> None:
        printer = QPrinter()
        printer.setOutputFormat(QPrinter.NativeFormat)

        dialog = QPrintPreviewDialog(printer, self)
        dialog.setWindowFlags(Qt.Window)
        dialog.paintRequested.connect(self.print)
        dialog.showMaximized()
        dialog.exec_()

    @Slot()
    def print_pdf(self) -> None:
        file_name = QFileDialog.getSaveFileName(self, self.tr("Save to .pdf"), filter=self.tr("Portable Document Format (*.pdf)"))[0]
        if not file_name:
            return

        printer = QPrinter()
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(file_name)
        self.print(printer)

    @Slot()
    def create_merchandise(self) -> None:
        dialog = CreateMerchandiseDialog.make(self)
        dialog.show()

    @Slot()
    def create_customer(self) -> None:
        dialog = CreateCustomerDialog.make(self)
        dialog.show()

    @Slot()
    def about(self) -> None:
        QMessageBox.information(self, self.tr("About pyOffer"), self.tr("pyOffer version {}\nAll rights reserved (c) Kamil Strzempowicz".format(version)))

    @Slot()
    def about_qt(self) -> None:
        """Forward to QApplication.aboutQt, but keep here for sake of tests"""
        QApplication.aboutQt()
Ejemplo n.º 2
0
class zhujiemian(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)  # 调用父类构造函数,创建窗体
        self.ui = Ui_MainWindow()  # 创建UI对象
        self.ui.setupUi(self)  # 构造UI界面
        self.setWindowTitle(bt)  # 设置窗体标题
        # open = QAction(QIcon('ICO/240.png'), '240', self)
        # self.addAction(open)  # 设置窗口LOGO
        # self.setStyleSheet("MainWindow{border-image:url(./python.jpg);}")  #
        # 设置窗口背景图片
        self.tab = {}  # 空字典

        global L
        db = self.connect_db()
        # 获取游标
        self.cur = db.cursor(pymysql.cursors.DictCursor)  # 使用字典类型输出
        # 根据” ID 字段“排序,倒叙输出 人员信息 表中的数据。备注:asc是表示升序,desc表示降序。limit 1表示输出一条记录
        sql_renyuan = "select * FROM 人员信息 WHERE 工号 = %s order by ID desc limit 1"
        rows = self.cur.execute(sql_renyuan, L[len(L) - 1])
        rows = self.cur.fetchone()
        qiye = QLabel(bt)  # 设置窗体标题
        qiye.setMinimumWidth(150)
        gonghao = QLabel("工号:%s" % L[len(L) - 1])
        gonghao.setMinimumWidth(120)
        xingming = QLabel("姓名:%s" % rows['姓名'])
        xingming.setMinimumWidth(120)
        bumen = QLabel("部门:%s" % rows['部门'])
        bumen.setMinimumWidth(120)
        zhiwei = QLabel("职位:%s" % rows['职位'])
        zhiwei.setMinimumWidth(120)

        self.ui.statusBar.addWidget(qiye)  # 加到状态栏
        self.ui.statusBar.addWidget(gonghao)
        self.ui.statusBar.addWidget(xingming)
        self.ui.statusBar.addWidget(bumen)
        self.ui.statusBar.addWidget(zhiwei)
        cur = db.cursor(pymysql.cursors.DictCursor)

        # 1.控件的上面的小tab变成透明
        # 2.选项卡部件:窗格{ 边框:1px纯灰;顶部:-1px;背景:透明;}
        # 3.突出选中的部分(改变颜色)
        # 4.设置QTabBar删除按钮图标和位置
        # 4.设置QTabBar删除按钮图标(点击前)
        # 4.设置QTabBar删除按钮图标(点击时)
        str = "QTabBar::tab{background-color:rbg(255,255,255,0);}" + \
              "QTabWidget:pane{border: 0.5px solid grey; top: -1px;background: transparent;}" + \
              "QTabBar::tab:selected{color:blue;background-color:rbg(255,255,255);} " + \
              "QTabBar::close-button{image: url(ICO/240.png);subcontrol-postion:left}" + \
              "QTabBar::close-button:hover{image:url(ICO/301.png);subcontrol-postion:left}" + \
              "QTabBar::close-button:pressed{image:url(ICO/302.png);subcontrol-postion:left}"

        self.ui.ZhuCaiDan.setStyleSheet(str)

        self.ui.ZhuCaiDan.setCurrentIndex(0)  # 显示第一个选项卡
        self.ui.ZhuCaiDan.setTabsClosable(True)  # 所有选项加上关闭按钮
        self.ui.ZhuCaiDan.tabBar().setTabButton(0, QTabBar.RightSide,
                                                None)  # 第一项去掉关闭按钮
        # self.ui.ZhuCaiDan.tabBar().setTabButton(1, QTabBar.RightSide, None)
        # # 第二项去掉关闭按钮
        u = self.ui.ZhuCaiDan.count()  # 获取选项卡数量
        # 删除多余选项卡
        while u > 0:
            self.ui.ZhuCaiDan.removeTab(u)
            u = u - 1
        self.ui.ZhuCaiDan.tabCloseRequested.connect(
            self.close_tab)  # ZhuCaiDan(页)关闭函数

        self.riqikuangxuanxiang(self.ui.ryxx_Q_riqi)
        self.riqikuangxuanxiang(self.ui.ryxx_J_riqi)

    # 窗体居中设置
    def center(self):
        deskSize = QDesktopWidget().screenGeometry()  # 获取桌面窗体参数
        windowSize = self.geometry()  # 获取窗体本身参数
        self.move((deskSize.width() - windowSize.width()) / 2,
                  (deskSize.height() - windowSize.height()) / 2)  # 居中设置

    # ZhuCaiDan(页)关闭函数;
    def close_tab(self, index):
        # currentTab = self.ui.ZhuCaiDan.currentWidget()
        currentTab = self.ui.ZhuCaiDan.widget(index)  # 获取选项卡的值

        del self.tab[currentTab.objectName()]  # 获取选项卡命名(objectName),删除对应数组
        self.ui.ZhuCaiDan.removeTab(index)  # 隐藏选项卡

    # 添加指定选项卡,显示按钮
    @Slot(bool)
    def on_actFont_ranyuanchaxun_triggered(self, clicked):
        # self.ui.actFont_ranyuanchaxun.triggered.connect(self.add_tab_renyuanxinxi)
        # # 新增选项卡(标题等同)
        self.tab['renyuanxinxi'] = [
            "部门", "组别", "职位", "工号", "姓名", "性别", "联系电话", "入职日期", "出生日期",
            "身份证号码", "地址", "待遇", "调薪日期", "离职日期", "备注"
        ]
        self.add_tab(self.ui.renyuanxinxi, '人员信息', self.tab['renyuanxinxi'],
                     self.ui.ryxx_tableWidget)

    # 添加tableWidgetn内容,查询按钮
    @Slot()
    def on_ryxx_chaxun_clicked(self):
        # self.ui.ryxx_chaxun.clicked.connect(self.chaxun_ryxx)   # 查询按钮
        text = "select * FROM 人员信息;"
        self.chaxun(self.ui.ryxx_tableWidget, text, self.tab['renyuanxinxi'])

    # 退出按钮
    @Slot()
    def on_ryxx_tuichu_clicked(self):
        index = self.ui.ZhuCaiDan.currentIndex()  # 获取当前选项卡的值
        self.ui.ZhuCaiDan.removeTab(index)  # 隐藏选项卡

    @Slot(bool)
    def on_actFont_xiangmuxinxi_triggered(self, clicked):
        # self.ui.actFont_xiangmuxinxi.triggered.connect(self.add_tab_xiangmuxingxi)
        # # 新增选项卡
        self.tab['xiangmuxinxi'] = [
            "内部编号", "客户编号", "模具等级", "业务担当", "项目担当", "设计担当", "钳工担当", "钳工组别",
            "下单日期", "首样日期", "预验日期", "复验日期", "终验日期", "要求移模日期", "实际移模日期", "出货判定",
            "备注"
        ]
        self.add_tab(self.ui.xiangmuxinxi, '项目信息', self.tab['xiangmuxinxi'],
                     self.ui.xmxx_tableWidget)

    @Slot()
    def on_xmxx_chaxun_clicked(self):
        text = "select * FROM 项目信息;"
        self.chaxun(self.ui.xmxx_tableWidget, text, self.tab['xiangmuxinxi'])

    @Slot()
    def on_xmxx_tuichu_clicked(self):
        index = self.ui.ZhuCaiDan.currentIndex()  # 获取当前选项卡的值
        self.ui.ZhuCaiDan.removeTab(index)  # 隐藏选项卡

    # 添加选项卡通用函数
    def add_tab(self, tab: QWidget, biao_ti: str, biao_tou: list,
                tableWidgetX: QTableWidgetItem):
        # self.add_tab(self.ui.xiangmuxinxi, '项目信息', headerText, self.ui.tableWidget_xm)
        while self.ui.ZhuCaiDan.indexOf(tab) < 0:
            self.ui.ZhuCaiDan.addTab(tab, biao_ti)  # 添加选项卡tab,以及标题biao_ti
            tableWidgetX.setColumnCount(len(biao_tou))  # 设置列数
            tableWidgetX.setRowCount(0)  # 设置数据区行数
            tableWidgetX.setHorizontalHeaderLabels(biao_tou)  # 设置列命名biao_tou
            tableWidgetX.setAlternatingRowColors(True)  # 交替行颜色
            selMode = QAbstractItemView.SelectRows
            tableWidgetX.setSelectionBehavior(selMode)  # 选择行为:行选择
            # selMode = QAbstractItemView.SelectItems
            # self.ui.ryxx_tableWidget.setSelectionBehavior(selMode)
            # ##选择行为:单元格选择

        w = self.ui.ZhuCaiDan.indexOf(tab)
        self.ui.ZhuCaiDan.setCurrentIndex(w)
        tableWidgetX.setSortingEnabled(False)  # 设置排序关闭

    # 添加tableWidget内容通用函数
    def chaxun(self, tableWidgetX: QTableWidgetItem, text: str,
               headerText: list):
        tableWidgetX.setSortingEnabled(False)  # 设置排序关闭
        tableWidgetX.clearContents()  # 清空表格内容
        tableWidgetX.setRowCount(0)  # 设置数据区行数
        rows = self.cur.execute(text)
        for i in range(rows):
            item = self.cur.fetchone()  # 获取一组数组
            row = tableWidgetX.rowCount()  # 获得QTableWidget表格控件的行数
            tableWidgetX.insertRow(row)  # 插入行
            for j in range(len(headerText)):
                if item[headerText[j]] is not None:
                    items = QTableWidgetItem(item[headerText[j]])
                    tableWidgetX.setItem(i, j, items)
                else:
                    pass
        tableWidgetX.resizeRowsToContents()  # 自动行高
        # tableWidgetX.resizeColumnsToContents()  # 自动列宽

        #设置表格头的伸缩模式,也就是让表格铺满整个QTableWidget控件
        self.ui.ryxx_tableWidget.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)

        str="QHeaderView::up-arrow { subcontrol-position: center right; padding-right: 1px;" \
            "image: url(ICO/ico/247.ico);}" + \
            "QHeaderView::down-arrow { subcontrol-position: center right; padding-right: 1px;" \
            "image: url(ICO/ico/248.ico);}"
        tableWidgetX.horizontalHeader().setStyleSheet(
            str)  #修改排序图标的展现方式(修改图标、位置)
        # tableWidgetX.setSortIndicatorShown(bool show)
        # connect(tableWidgetX.horizontalHeader(), SIGNAL(sectionClicked(int)),
        #         tableWidgetX, SLOT(sortByColumn(int)))  # 连接信号与槽
        # tableWidgetX.horizontalHeader().setSortIndicator(0, AscendingOrder)
        # tableWidgetX.horizontalHeader().setClickable(true)
        tableWidgetX.horizontalHeader().setSortIndicatorShown(True)  # 显示排序图标
        tableWidgetX.setSortingEnabled(True)  # 设置排序已启用
        # tableWidgetX.sortItems(2,Qt.DescendingOrder)    # Qt.AscEndingOrder升序,Qt.DescendingOrder降序

    # 数据库连接
    def connect_db(self):
        try:
            file = open('my.ini', 'r')
            global L
            while True:
                d = file.readline()
                if not d:
                    file.close()  # 关闭文件
                    break
                cc = d.split('=')[1].strip()
                L.append(cc)
            # # 建立数据库连接
            db = pymysql.connect(
                host=L[0],  # 'localhost',  # "192.168.202.1""127.0.0.1"
                port=int(L[1]),  # 3306
                user=L[2],  # 'root'
                password=L[3],  # '080420'
                db=L[4],  # 'mysql'
                charset=str(L[5]))  # 字体设置"utf8"
            return db
        except IOError:
            QMessageBox.about(self, '提示信息', '服务器链接失败')

    # 窗口关闭提示
    def closeEvent(self, event):
        result = QMessageBox.question(self, '关闭提示框', '确定要退出吗?',
                                      QMessageBox.Yes | QMessageBox.No,
                                      QMessageBox.NoButton)
        if (result == QMessageBox.Yes):
            event.accept()
        else:
            event.ignore()

    # QLineEdit日期显示
    def riqikuangxuanxiang(self, zujian: QLineEdit):
        # show_signal = pyqtSignal()  # 点击下拉框发送信号
        # zujian.curDateTime.toString('yyyy/MM/dd')
        self.show_action = QAction(self)
        self.show_action.setIcon(QIcon('ICO/png/1234864.png'))
        zujian.addAction(self.show_action, QLineEdit.TrailingPosition)
        self.show_action.triggered.connect(self.openCalendar)  # 信号和槽连接
        self.rili = QCalendarWidget(self)
        self.rili.setGridVisible(True)  # 是否显示日期之间的网格
        self.rili.setGeometry(zujian.x(), 140, 280, 200)  #日历控件位置
        self.rili.hide()  # 隐藏日期控件
        # date = self.rili.selectedDate()#获取选中日期,默认当前系统时间
        self.rili.clicked[QDate].connect(
            self.showDate)  #clicked[参数],即定义showDate是传入的参数类型设置
        # self.show_action.triggered.connect(self.showDate(date,zujian))

        # if self.rili.clicked[QDate].connect() = True:
        #     zujian.setText(date.toString("yyyy/MM/dd"))
        #     self.rili.close()  # 关闭日期控件
    def showDate(self, date):
        self.ui.ryxx_J_riqi.setText(date.toString("yyyy/MM/dd"))
        self.rili.close()  #关闭日期控件

    def openCalendar(self):
        self.rili.show()  #显示日期控件