项目进度管理系统----Python下Pyside2模块(大一课设)

目录

一、安装Pycharm和Anaconda(这里我用的是Pycharm,Vscode也一样适用)

二、在相应的conda环境中下载Pyside2模块

三、在编译器中添加对应的Pyside2外部工具 

四、项目进度管理系统介绍

五、制作过程  

六、主体代码

代码组成有点乱,想要的私信我,有问题也可以问我,本人大一,会的不太多,但是我遇到的问题有不会的可以问问,看到会回复。

一、安装Pycharm和Anaconda              

如何搭建Python开发环境_netexsy的博客-CSDN博客

二、在相应的conda环境中下载Pyside2模块

1)先切换到对应的虚拟环境      

“Win+R”打开cmd命令行

项目进度管理系统----Python下Pyside2模块(大一课设)_第1张图片

输入“conda activate  环境名” 切换环境

项目进度管理系统----Python下Pyside2模块(大一课设)_第2张图片

2)下载PySide2模块

pip install pyside2 -i https://pypi.douban.com/simple

三、在编译器中添加对应的Pyside2外部工具

1)打开 PyCharm--->文件--->设置--->工具--->外部工具

2)添加外部工具(Program需要使用个人电脑下的模块中的exe文件,复制自己的路径即可,Working Directory和Arguments直接照抄就行)

New QtForm(命名)
    1)Program - D:\Develop\Python\Anaconda3\envs\Qt\Scripts\pyside2-designer.exe  (找到自己电脑目录下的pyside2-designer.exe,此处为示例)
    2)Working Directory - $FileDir$
Edit QtForm(命名)
    1)Program - D:\Develop\Python\Anaconda3\envs\Qt\Scripts\pyside2-designer.exe   (找到自己电脑下的pyside2-designer.exe,此处为示例)
    2)Arguments - $FileDir$\$FileName$
    3)Working Directory - $FileDir$
PyUIC(命名)
    1)Program - D:\Develop\Python\Anaconda3\envs\Qt\Scripts\pyside2-uic.exe    (找到自己电脑下的pyside2-uic.exe ,此处为示例)
    2)Arguments - $FileName$ -o ui_$FileNameWithoutExtension$.py
    3)Working Directory - $FileDir$

四、项目进度管理系统介绍

项目进度管理系统----Python下Pyside2模块(大一课设)_第3张图片

设计项目进度管理系统界面(个人自主设计)

1)管理员登录/用户登录

项目进度管理系统----Python下Pyside2模块(大一课设)_第4张图片

2)管理员登录界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第5张图片

3)用户登录界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第6张图片

4)管理员选择模块界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第7张图片

5)管理员主界面----项目管理

 项目进度管理系统----Python下Pyside2模块(大一课设)_第8张图片

 6)管理员主界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第9张图片

7)添加界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第10张图片

8) 修改界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第11张图片

9) 搜索界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第12张图片

 10)导入界面----项目管理/用户界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第13张图片

11) 导出界面----项目管理/用户界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第14张图片

12)添加界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第15张图片

13)添加界面----用户管理

 项目进度管理系统----Python下Pyside2模块(大一课设)_第16张图片

14)搜索界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第17张图片

项目进度管理系统----Python下Pyside2模块(大一课设)_第18张图片

 6.数据库的使用(MySql)

推荐使用SQLiteStudio或Navicat。  

7.表的使用

表1my_All_Project表(项目表)

序号

字段名

类型

长度

默认值

说明

1

Id

Varchar

10

NULL

2

Type

Varchar

20

NULL

3

Name

Varchar

50

NULL

4

Start_date

date

1

NULL

5

End_date

date

1

NULL

6

Progress

int

1

NULL 

7

Manager

Varchar

20

NULL

8

Level

char(1)

1

NULL

9

Remark

Varchar

100

NULL

                                     

表2 user表(用户表)

序号

字段名

类型

长度

默认值

说明

1

user_type

Varchar

20

NULL

2

username

Varchar

40

NULL

3

password

Varchar

100

NULL

4

login_times

int

1

NULL

5

last_login

date

Timestamp

NULL

 五、制作过程

1.打开PyCharm,新建一个项目。(注意环境要使用安装了PySide2模块的环境,不然会报错!)

项目进度管理系统----Python下Pyside2模块(大一课设)_第19张图片

2.在项目中新建一个目录,取名为“ui”(名字自己取)--->鼠标移到目录上--->鼠标右键点击目录--->External Tools--->New QtForm

项目进度管理系统----Python下Pyside2模块(大一课设)_第20张图片

3. 弹出一个程序“Qt Designer”(第一次可能要等10秒钟,后面就不用了。)

项目进度管理系统----Python下Pyside2模块(大一课设)_第21张图片

 4.刚开始做窗体界面使用“Main Window”就可以了,子窗体比较推荐用Dialog,我们可以利用Qt Designer设计系统的各种界面。

基础设计教程请看:

利用PySide2模块以及Qt设计师(Qt-Designer)设计简易的系统窗体_netexsy的博客-CSDN博客

利用Qt设计师可以很快设计出上述界面,但是要注意的是,单独一个界面中的每个部件都要取号名字,不能重复,不然写python代码时会有冲突!

5.设计完界面后保存取名字退出并编译(每个界面名字也要不一样,要能够记住!)

右键点击ui文件,选择“External Tool”里面的“pyuic”工具,这个工具能够将我们刚刚设计好的图形化界面转化为后缀为.py的python代码,方便我们调用。(ui文件不能被编译器识别,但是转换成python代码后就可以了!)

项目进度管理系统----Python下Pyside2模块(大一课设)_第22张图片

下面会有对应的.py文件自动生成,下面的.py文件才能被我们调用。

项目进度管理系统----Python下Pyside2模块(大一课设)_第23张图片

6.在ui目录以外的地方新建一个.py文件(不能和那些ui文件在一个目录下面,不然可能会报错)

设计了几个界面就要新建几个.py文件,这个.py文件是我们自己新建的,和pyuic工具生成的.py文件不是一个东西。

接下来我们进入最重要的代码部分

六、主体代码

 1)管理员登录/用户登录

项目进度管理系统----Python下Pyside2模块(大一课设)_第24张图片

ui_untitled_login_select.py(这个是图示界面ui文件通过pyuic转换而来的.py文件)
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'untitled_login_select.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        icon = QIcon()
        icon.addFile(u"../\u9009\u62e9.ico", QSize(), QIcon.Normal, QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.actionTlbExit = QAction(MainWindow)
        self.actionTlbExit.setObjectName(u"actionTlbExit")
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.layoutWidget = QWidget(self.centralwidget)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(-1, 30, 801, 391))
        self.verticalLayout = QVBoxLayout(self.layoutWidget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label = QLabel(self.layoutWidget)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(36)
        self.label.setFont(font)

        self.horizontalLayout.addWidget(self.label)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)


        self.verticalLayout.addLayout(self.horizontalLayout)

        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer_2)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_4)

        self.pButtonadministrator = QPushButton(self.layoutWidget)
        self.pButtonadministrator.setObjectName(u"pButtonadministrator")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(24)
        self.pButtonadministrator.setFont(font1)

        self.horizontalLayout_2.addWidget(self.pButtonadministrator)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_3)

        self.pButtonuser = QPushButton(self.layoutWidget)
        self.pButtonuser.setObjectName(u"pButtonuser")
        font2 = QFont()
        font2.setFamily(u"Agency FB")
        font2.setPointSize(26)
        self.pButtonuser.setFont(font2)

        self.horizontalLayout_2.addWidget(self.pButtonuser)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_5)


        self.verticalLayout.addLayout(self.horizontalLayout_2)

        self.label_3 = QLabel(self.centralwidget)
        self.label_3.setObjectName(u"label_3")
        self.label_3.setGeometry(QRect(0, -6, 801, 531))
        self.label_3.setPixmap(QPixmap(u":/\u80cc\u666f\u56fe1.png"))
        self.label_3.setScaledContents(True)
        MainWindow.setCentralWidget(self.centralwidget)
        self.label_3.raise_()
        self.layoutWidget.raise_()
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QToolBar(MainWindow)
        self.toolBar.setObjectName(u"toolBar")
        MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)

        self.toolBar.addAction(self.actionTlbExit)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u767b\u5f55\u754c\u9762", None))
        self.actionTlbExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
        self.pButtonadministrator.setText(QCoreApplication.translate("MainWindow", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
        self.pButtonuser.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u767b\u5f55", None))
        self.label_3.setText("")
        self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
    # retranslateUi

dljm.py(这个是我们在ui文件之外的目录新建的.py文件)

from PySide2.QtWidgets import *
from PySide2.QtCore import *
from ui.ui_untitled_login_select import Ui_MainWindow
from gly_login import GlyWindow as Gly
from yh_login import YhWindow as Yh
import os, sys
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置



class LoginWindow(QMainWindow, Ui_MainWindow):
    mainSingnal = Signal(str, dict)
    # 初始化窗体
    def __init__(self):
        # 初始化基类
        super(LoginWindow, self).__init__()
        # 初始化当前窗体及窗体中的所有控件
        self.setupUi(self)
        # 记录当前应用所在路径
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # 设置窗体图标
        app_icon = QIcon('选择.ico')
        self.setWindowIcon(app_icon)

        # 绑定信号与槽,实现按纽单击调用对应的槽函数(选择登录)
        # 声明子窗体(一个管理员登录,一个普通用户登录)
        self.gly_dl = None
        self.yh_dl = None
        self.pButtonadministrator.clicked.connect(lambda: self.gly())
        self.pButtonuser.clicked.connect(lambda: self.yh())

        # 绑定菜单栏(左上角的'退出系统'按钮)
        self.actionTlbExit.triggered.connect(lambda: self.Close())


    def gly(self):
        # 记录当前动作
        self.stuAction = 'gly_dl'
        # 创建子窗体
        self.gly_dl = Gly()
        # 设置该子窗体的对话框状态为“模态对话框”
        self.gly_dl.setModal(True)
        # 显示子窗体
        self.gly_dl.show()
        # # 信号与槽绑定
        # # 主窗体向子窗体发送数据(不能使用Lambda表达式,仅为窗体名.函数名)
        # self.mainSingnal.connect(self.gly_dl.handle_main_signal)
        # # 主窗体发射信号给子窗体
        # self.mainSignal.emit(self.stuAction)

    def yh(self):
        # 记录当前动作
        self.stuAction = 'yh_dl'
        # 创建子窗体()
        self.yh_dl = Yh()
        # 设置该子窗体的对话框状态为“模态对话框”
        self.yh_dl.setModal(True)
        # 显示子窗体
        self.yh_dl.show()
        # # 信号与槽绑定
        # # 主窗体向子窗体发送数据(不能使用Lambda表达式,仅为窗体名.函数名)
        # self.mainSingnal.connect(self.yh_dl.handle_main_signal)
        # # 主窗体发射信号给子窗体
        # self.mainSignal.emit(self.stuAction, None)

    def Close(self):
        reply = QMessageBox.question(self, '关闭提示', "是否要退出系统?",
                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.close()
        elif reply == QMessageBox.No:
            return

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = LoginWindow()
    win_main.show()
    sys.exit(app.exec_())

2)管理员登录界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第25张图片

ui_untitled_gly_dl.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'untitled_gly_dl.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(814, 461)
        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(0, 120, 811, 54))
        self.horizontalLayout_5 = QHBoxLayout(self.layoutWidget)
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_8)

        self.label_Login = QLabel(self.layoutWidget)
        self.label_Login.setObjectName(u"label_Login")
        font = QFont()
        font.setFamily(u"Arial Black")
        font.setPointSize(22)
        font.setBold(True)
        font.setWeight(75)
        self.label_Login.setFont(font)

        self.horizontalLayout_5.addWidget(self.label_Login)

        self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_9)

        self.layoutWidget_2 = QWidget(Dialog)
        self.layoutWidget_2.setObjectName(u"layoutWidget_2")
        self.layoutWidget_2.setGeometry(QRect(0, 420, 811, 33))
        self.horizontalLayout = QHBoxLayout(self.layoutWidget_2)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.pButtonOk = QPushButton(self.layoutWidget_2)
        self.pButtonOk.setObjectName(u"pButtonOk")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(10)
        self.pButtonOk.setFont(font1)

        self.horizontalLayout.addWidget(self.pButtonOk)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)

        self.pButtonCancel = QPushButton(self.layoutWidget_2)
        self.pButtonCancel.setObjectName(u"pButtonCancel")
        self.pButtonCancel.setFont(font1)

        self.horizontalLayout.addWidget(self.pButtonCancel)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_3)

        self.layoutWidget_3 = QWidget(Dialog)
        self.layoutWidget_3.setObjectName(u"layoutWidget_3")
        self.layoutWidget_3.setGeometry(QRect(0, 0, 811, 75))
        self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_3)
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_6)

        self.label = QLabel(self.layoutWidget_3)
        self.label.setObjectName(u"label")
        font2 = QFont()
        font2.setFamily(u"Agency FB")
        font2.setPointSize(36)
        self.label.setFont(font2)

        self.horizontalLayout_4.addWidget(self.label)

        self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_7)

        self.layoutWidget_4 = QWidget(Dialog)
        self.layoutWidget_4.setObjectName(u"layoutWidget_4")
        self.layoutWidget_4.setGeometry(QRect(0, 230, 811, 98))
        self.horizontalLayout_6 = QHBoxLayout(self.layoutWidget_4)
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_10)

        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_3 = QLabel(self.layoutWidget_4)
        self.label_3.setObjectName(u"label_3")
        font3 = QFont()
        font3.setFamily(u"Agency FB")
        font3.setPointSize(14)
        self.label_3.setFont(font3)

        self.horizontalLayout_2.addWidget(self.label_3)

        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_4)

        self.lineEdit_gly_User = QLineEdit(self.layoutWidget_4)
        self.lineEdit_gly_User.setObjectName(u"lineEdit_gly_User")

        self.horizontalLayout_2.addWidget(self.lineEdit_gly_User)


        self.verticalLayout.addLayout(self.horizontalLayout_2)

        self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_4 = QLabel(self.layoutWidget_4)
        self.label_4.setObjectName(u"label_4")
        self.label_4.setFont(font3)

        self.horizontalLayout_3.addWidget(self.label_4)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_5)

        self.lineEdit_gly_Password = QLineEdit(self.layoutWidget_4)
        self.lineEdit_gly_Password.setObjectName(u"lineEdit_gly_Password")

        self.horizontalLayout_3.addWidget(self.lineEdit_gly_Password)


        self.verticalLayout.addLayout(self.horizontalLayout_3)


        self.horizontalLayout_6.addLayout(self.verticalLayout)

        self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_11)

        self.label_5 = QLabel(Dialog)
        self.label_5.setObjectName(u"label_5")
        self.label_5.setGeometry(QRect(1, 4, 811, 461))
        self.label_5.setPixmap(QPixmap(u":/b2.png"))
        self.label_5.setScaledContents(True)
        self.label_5.raise_()
        self.layoutWidget.raise_()
        self.layoutWidget_2.raise_()
        self.layoutWidget_3.raise_()
        self.layoutWidget_4.raise_()

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
        self.label_Login.setText(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
        self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
        self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
        self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d\uff1a", None))
        self.lineEdit_gly_User.setText("")
        self.label_4.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801\uff1a", None))
        self.label_5.setText("")
    # retranslateUi

gly_login.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
from PySide2.QtWidgets import QLineEdit, QPushButton
import sqlite3
import sys, os
from ui.ui_untitled_gly_dl import Ui_Dialog
from gly_select import GsWindow

class GlyWindow  (QDialog , Ui_Dialog):
    # 定义一个信号,从子窗体向主窗体返回信号
    MainSiganl = Signal(bool)
    # 子窗体初始化、声明信号、设置围标等
#############################################################################
    def __init__(self):
        super(GlyWindow, self).__init__()
        self.setupUi(self)
        # 记录当前应用程序路径
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))
        # 设置窗体图标
        app_icon = QIcon('登录配置.ico')
        self.setWindowIcon(app_icon)

        # 默认操作
        self.actionName = None
        # 按纽绑定
        self.pButtonCancel.clicked.connect(lambda: self.close())
        self.pButtonOk.clicked.connect(lambda: self.check_login_info())


    def check_login_info(self):
        conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
        c = conn.cursor()

        user = self.lineEdit_gly_User.text()
        password = self.lineEdit_gly_Password.text()

        sql = f"select * from all_user where user_type='管理员' and  username='{user}' and password='{password}'"
        cursor = c.execute(sql)
        result = cursor.fetchone()

        if result is None:
            QMessageBox.warning(self, '警告', '用户名或密码错误或非管理员用户!')
            self.lineEdit_gly_Password.clear()
            self.lineEdit_gly_Password.setFocus()
        else:
            self.MainSiganl.emit(True)
            main_window = GsWindow()
            main_window.show()
            self.accept()
        conn.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    detail_win = GlyWindow()
    detail_win.show()
    sys.exit(app.exec_())

3)用户登录界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第26张图片

ui_untitled_yh_dl.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'untitled_yh_dl.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(813, 454)
        self.layoutWidget_3 = QWidget(Dialog)
        self.layoutWidget_3.setObjectName(u"layoutWidget_3")
        self.layoutWidget_3.setGeometry(QRect(0, 0, 811, 75))
        self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_3)
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_6)

        self.label = QLabel(self.layoutWidget_3)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(36)
        self.label.setFont(font)

        self.horizontalLayout_4.addWidget(self.label)

        self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_7)

        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(0, 120, 811, 54))
        self.horizontalLayout_5 = QHBoxLayout(self.layoutWidget)
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_8)

        self.label_Login = QLabel(self.layoutWidget)
        self.label_Login.setObjectName(u"label_Login")
        font1 = QFont()
        font1.setFamily(u"Arial Black")
        font1.setPointSize(22)
        font1.setBold(True)
        font1.setWeight(75)
        self.label_Login.setFont(font1)

        self.horizontalLayout_5.addWidget(self.label_Login)

        self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_9)

        self.layoutWidget_4 = QWidget(Dialog)
        self.layoutWidget_4.setObjectName(u"layoutWidget_4")
        self.layoutWidget_4.setGeometry(QRect(0, 230, 811, 98))
        self.horizontalLayout_6 = QHBoxLayout(self.layoutWidget_4)
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_10)

        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_3 = QLabel(self.layoutWidget_4)
        self.label_3.setObjectName(u"label_3")
        font2 = QFont()
        font2.setFamily(u"Agency FB")
        font2.setPointSize(14)
        self.label_3.setFont(font2)

        self.horizontalLayout_2.addWidget(self.label_3)

        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_4)

        self.lineEdit_yh_User = QLineEdit(self.layoutWidget_4)
        self.lineEdit_yh_User.setObjectName(u"lineEdit_yh_User")

        self.horizontalLayout_2.addWidget(self.lineEdit_yh_User)


        self.verticalLayout.addLayout(self.horizontalLayout_2)

        self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_4 = QLabel(self.layoutWidget_4)
        self.label_4.setObjectName(u"label_4")
        self.label_4.setFont(font2)

        self.horizontalLayout_3.addWidget(self.label_4)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_5)

        self.lineEdit_yh_Password = QLineEdit(self.layoutWidget_4)
        self.lineEdit_yh_Password.setObjectName(u"lineEdit_yh_Password")

        self.horizontalLayout_3.addWidget(self.lineEdit_yh_Password)


        self.verticalLayout.addLayout(self.horizontalLayout_3)


        self.horizontalLayout_6.addLayout(self.verticalLayout)

        self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_11)

        self.layoutWidget_2 = QWidget(Dialog)
        self.layoutWidget_2.setObjectName(u"layoutWidget_2")
        self.layoutWidget_2.setGeometry(QRect(0, 420, 811, 33))
        self.horizontalLayout = QHBoxLayout(self.layoutWidget_2)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.pButtonOk = QPushButton(self.layoutWidget_2)
        self.pButtonOk.setObjectName(u"pButtonOk")
        font3 = QFont()
        font3.setFamily(u"Agency FB")
        font3.setPointSize(10)
        self.pButtonOk.setFont(font3)

        self.horizontalLayout.addWidget(self.pButtonOk)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)

        self.pButtonCancel = QPushButton(self.layoutWidget_2)
        self.pButtonCancel.setObjectName(u"pButtonCancel")
        self.pButtonCancel.setFont(font3)

        self.horizontalLayout.addWidget(self.pButtonCancel)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_3)

        self.label_5 = QLabel(Dialog)
        self.label_5.setObjectName(u"label_5")
        self.label_5.setGeometry(QRect(1, -6, 811, 461))
        self.label_5.setPixmap(QPixmap(u":/b2.png"))
        self.label_5.setScaledContents(True)
        self.label_5.raise_()
        self.layoutWidget_3.raise_()
        self.layoutWidget.raise_()
        self.layoutWidget_4.raise_()
        self.layoutWidget_2.raise_()

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
        self.label_Login.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u767b\u5f55", None))
        self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d\uff1a", None))
        self.lineEdit_yh_User.setText("")
        self.label_4.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801\uff1a", None))
        self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
        self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
        self.label_5.setText("")
    # retranslateUi

yh_login.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
import sqlite3
import sys, os
from ui.ui_untitled_yh_dl import Ui_Dialog
from main import MainWindow


class YhWindow(QDialog, Ui_Dialog):
    # 定义一个信号,从子窗体向主窗体返回信号
    MainSiganl = Signal(bool)
    UserSignal = Signal(str)
    #################################
    # 子窗体初始化、声明信号、设置围标等
    def __init__(self):
        super(YhWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("用户登录")
        # 记录当前应用程序路径
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))
        # 设置窗体图标
        app_icon = QIcon('登录配置.ico')
        self.setWindowIcon(app_icon)

        # 默认操作
        self.actionName = None
        # 按纽绑定
        self.pButtonCancel.clicked.connect(lambda: self.close())
        self.pButtonOk.clicked.connect(lambda: self.check_login_info())

        self.stuAction = None

        self.main_win = None


    def check_login_info(self):
        conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
        c = conn.cursor()

        user = self.lineEdit_yh_User.text()
        password = self.lineEdit_yh_Password.text()



        # print(user)
        # print(type(user))
        sql = f"select * from all_user where user_type='普通用户' and  username='{user}' and password='{password}'"
        cursor = c.execute(sql)
        result = cursor.fetchone()

        if result is None:
            QMessageBox.warning(self, '警告', '用户名或密码错误或为管理员用户!')
            self.lineEdit_yh_Password.clear()
            self.lineEdit_yh_Password.setFocus()
        else:
            self.MainSiganl.emit(True)
            self.main_win = MainWindow()
            self.main_win.show()
            self.accept()

            self.stuAction = user
            self.UserSignal.connect(self.main_win.yh_login_Signal)
            self.UserSignal.emit(self.stuAction)

        conn.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    detail_win = YhWindow()
    detail_win.show()
    sys.exit(app.exec_())

4)管理员选择模块界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第27张图片

ui_gly_select.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'gly_select.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(940, 564)
        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(0, 60, 941, 461))
        self.verticalLayout_2 = QVBoxLayout(self.layoutWidget)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label = QLabel(self.layoutWidget)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(24)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)

        self.horizontalLayout.addWidget(self.label)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)


        self.verticalLayout_2.addLayout(self.horizontalLayout)

        self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_4)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_2 = QLabel(self.layoutWidget)
        self.label_2.setObjectName(u"label_2")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(22)
        font1.setBold(True)
        font1.setWeight(75)
        self.label_2.setFont(font1)

        self.horizontalLayout_2.addWidget(self.label_2)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_3)

        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.pButtonuser = QPushButton(self.layoutWidget)
        self.pButtonuser.setObjectName(u"pButtonuser")
        font2 = QFont()
        font2.setFamily(u"Bahnschrift SemiBold Condensed")
        font2.setPointSize(22)
        font2.setBold(True)
        font2.setWeight(75)
        self.pButtonuser.setFont(font2)

        self.verticalLayout.addWidget(self.pButtonuser)

        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.pButtonproject = QPushButton(self.layoutWidget)
        self.pButtonproject.setObjectName(u"pButtonproject")
        font3 = QFont()
        font3.setFamily(u"Bahnschrift Condensed")
        font3.setPointSize(24)
        font3.setBold(True)
        font3.setWeight(75)
        self.pButtonproject.setFont(font3)

        self.verticalLayout.addWidget(self.pButtonproject)


        self.horizontalLayout_2.addLayout(self.verticalLayout)


        self.horizontalLayout_3.addLayout(self.horizontalLayout_2)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_5)


        self.verticalLayout_2.addLayout(self.horizontalLayout_3)

        self.tableWidget = QTableWidget(Dialog)
        self.tableWidget.setObjectName(u"tableWidget")
        self.tableWidget.setGeometry(QRect(0, 0, 941, 561))
        self.tableWidget.setStyleSheet(u"background-image: url(:/b1.png);\n"
" background-size: cover;")
        self.tableWidget.raise_()
        self.layoutWidget.raise_()

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u64cd\u4f5c", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u64cd\u4f5c", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"\u8bf7\u9009\u62e9\uff1a", None))
        self.pButtonuser.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
        self.pButtonproject.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
    # retranslateUi

ui_gly_select.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
from PySide2.QtWidgets import QLineEdit, QPushButton
import sqlite3
import sys, os
from main_body.ui_gly_select import Ui_Dialog
from main import MainWindow as projectwindow
from control_user import MainWindow as userwindow

from PyQt5.QtWidgets import QApplication, QWidget

class GsWindow(QDialog , Ui_Dialog):
    MainSiganl = Signal(bool)

    def __init__(self):
        super(GsWindow, self).__init__()
        self.setupUi(self)
        # 记录当前应用程序路径
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))
        # 设置窗体图标
        app_icon = QIcon('登录配置.ico')
        self.setWindowIcon(app_icon)

        self.pButtonuser.clicked.connect(lambda: self.User())
        self.pButtonproject.clicked.connect(lambda: self.Project())

        self.setStyleSheet("background-image: url(b1.jpg);")

    def User(self):
        self.user_win = userwindow()
        self.user_win.show()

    def Project(self):
        self.pro_win = projectwindow()
        self.pro_win.show()





if __name__ == '__main__':
    app = QApplication(sys.argv)
    detail_win = GsWindow()
    detail_win.show()
    sys.exit(app.exec_())

5)管理员主界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第28张图片

ui_main.py

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

################################################################################
## Form generated from reading UI file 'main.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(1253, 840)
        icon = QIcon()
        icon.addFile(u":/\u767b\u5f55.png", QSize(), QIcon.Normal, QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.actionMenuOpen = QAction(MainWindow)
        self.actionMenuOpen.setObjectName(u"actionMenuOpen")
        self.actionMenuExit = QAction(MainWindow)
        self.actionMenuExit.setObjectName(u"actionMenuExit")
        self.actionTlbExit = QAction(MainWindow)
        self.actionTlbExit.setObjectName(u"actionTlbExit")
        self.actionTlbAdd = QAction(MainWindow)
        self.actionTlbAdd.setObjectName(u"actionTlbAdd")
        self.actionTlbChange = QAction(MainWindow)
        self.actionTlbChange.setObjectName(u"actionTlbChange")
        self.actionMenuAdd = QAction(MainWindow)
        self.actionMenuAdd.setObjectName(u"actionMenuAdd")
        self.actionMenuChange = QAction(MainWindow)
        self.actionMenuChange.setObjectName(u"actionMenuChange")
        self.actionTlbExport = QAction(MainWindow)
        self.actionTlbExport.setObjectName(u"actionTlbExport")
        self.actionTlbSelect = QAction(MainWindow)
        self.actionTlbSelect.setObjectName(u"actionTlbSelect")
        self.actionquestion = QAction(MainWindow)
        self.actionquestion.setObjectName(u"actionquestion")
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.layoutWidget = QWidget(self.centralwidget)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(0, 10, 1251, 51))
        self.verticalLayout = QVBoxLayout(self.layoutWidget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label = QLabel(self.layoutWidget)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(20)
        font.setBold(True)
        font.setUnderline(True)
        font.setWeight(75)
        self.label.setFont(font)

        self.horizontalLayout.addWidget(self.label)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)

        self.lineEditUser_Id = QLineEdit(self.layoutWidget)
        self.lineEditUser_Id.setObjectName(u"lineEditUser_Id")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(12)
        font1.setBold(True)
        font1.setWeight(75)
        self.lineEditUser_Id.setFont(font1)

        self.horizontalLayout.addWidget(self.lineEditUser_Id)


        self.verticalLayout.addLayout(self.horizontalLayout)

        self.layoutWidget1 = QWidget(self.centralwidget)
        self.layoutWidget1.setObjectName(u"layoutWidget1")
        self.layoutWidget1.setGeometry(QRect(0, 60, 1251, 701))
        self.horizontalLayout_2 = QHBoxLayout(self.layoutWidget1)
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.tableWidget = QTableWidget(self.layoutWidget1)
        if (self.tableWidget.columnCount() < 9):
            self.tableWidget.setColumnCount(9)
        __qtablewidgetitem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
        __qtablewidgetitem1 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
        __qtablewidgetitem2 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
        __qtablewidgetitem3 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
        __qtablewidgetitem4 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
        __qtablewidgetitem5 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
        __qtablewidgetitem6 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
        __qtablewidgetitem7 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
        __qtablewidgetitem8 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
        self.tableWidget.setObjectName(u"tableWidget")

        self.horizontalLayout_2.addWidget(self.tableWidget)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalSpacer_5 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_3.addItem(self.verticalSpacer_5)

        self.pButtonSelect = QPushButton(self.layoutWidget1)
        self.pButtonSelect.setObjectName(u"pButtonSelect")

        self.verticalLayout_3.addWidget(self.pButtonSelect)

        self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_3.addItem(self.verticalSpacer_8)

        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.pButtonAdd = QPushButton(self.layoutWidget1)
        self.pButtonAdd.setObjectName(u"pButtonAdd")

        self.verticalLayout_2.addWidget(self.pButtonAdd)

        self.verticalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_4)

        self.pButtonchange = QPushButton(self.layoutWidget1)
        self.pButtonchange.setObjectName(u"pButtonchange")

        self.verticalLayout_2.addWidget(self.pButtonchange)

        self.verticalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_7)

        self.pButtonExport = QPushButton(self.layoutWidget1)
        self.pButtonExport.setObjectName(u"pButtonExport")

        self.verticalLayout_2.addWidget(self.pButtonExport)

        self.verticalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_6)

        self.pButtonImport = QPushButton(self.layoutWidget1)
        self.pButtonImport.setObjectName(u"pButtonImport")

        self.verticalLayout_2.addWidget(self.pButtonImport)

        self.verticalSpacer_3 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_3)

        self.pButtonshow = QPushButton(self.layoutWidget1)
        self.pButtonshow.setObjectName(u"pButtonshow")

        self.verticalLayout_2.addWidget(self.pButtonshow)

        self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.pButtonExit = QPushButton(self.layoutWidget1)
        self.pButtonExit.setObjectName(u"pButtonExit")

        self.verticalLayout_2.addWidget(self.pButtonExit)


        self.verticalLayout_3.addLayout(self.verticalLayout_2)


        self.horizontalLayout_2.addLayout(self.verticalLayout_3)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 1253, 26))
        self.menuFile = QMenu(self.menubar)
        self.menuFile.setObjectName(u"menuFile")
        self.menuAdd = QMenu(self.menubar)
        self.menuAdd.setObjectName(u"menuAdd")
        self.menuEdit = QMenu(self.menubar)
        self.menuEdit.setObjectName(u"menuEdit")
        self.menuHelp = QMenu(self.menubar)
        self.menuHelp.setObjectName(u"menuHelp")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QToolBar(MainWindow)
        self.toolBar.setObjectName(u"toolBar")
        MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)

        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuAdd.menuAction())
        self.menubar.addAction(self.menuEdit.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.menuFile.addAction(self.actionMenuOpen)
        self.menuFile.addAction(self.actionMenuExit)
        self.menuEdit.addAction(self.actionMenuAdd)
        self.menuEdit.addAction(self.actionMenuChange)
        self.menuHelp.addAction(self.actionquestion)
        self.toolBar.addAction(self.actionTlbExit)
        self.toolBar.addAction(self.actionTlbAdd)
        self.toolBar.addAction(self.actionTlbChange)
        self.toolBar.addAction(self.actionTlbExport)
        self.toolBar.addAction(self.actionTlbSelect)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u4e00\u89c8", None))
        self.actionMenuOpen.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None))
        self.actionMenuExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa", None))
        self.actionTlbExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
        self.actionTlbAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
        self.actionTlbChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
        self.actionMenuAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
        self.actionMenuChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
        self.actionTlbExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa\u9879\u76ee", None))
        self.actionTlbSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u9879\u76ee", None))
        self.actionquestion.setText(QCoreApplication.translate("MainWindow", u"\u51fa\u73b0\u9519\u8bef\uff1f", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406", None))
        ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
        ___qtablewidgetitem.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7f16\u53f7", None));
        ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
        ___qtablewidgetitem1.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7c7b\u578b", None));
        ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
        ___qtablewidgetitem2.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u540d\u79f0", None));
        ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
        ___qtablewidgetitem3.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u65e5\u671f", None));
        ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
        ___qtablewidgetitem4.setText(QCoreApplication.translate("MainWindow", u"\u7ed3\u675f\u65e5\u671f", None));
        ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
        ___qtablewidgetitem5.setText(QCoreApplication.translate("MainWindow", u"\u5b8c\u6210\u8fdb\u5ea6", None));
        ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
        ___qtablewidgetitem6.setText(QCoreApplication.translate("MainWindow", u"\u8d1f\u8d23\u4eba", None));
        ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
        ___qtablewidgetitem7.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7ea7\u522b", None));
        ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
        ___qtablewidgetitem8.setText(QCoreApplication.translate("MainWindow", u"\u5907\u6ce8", None));
        self.pButtonSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u9879\u76ee", None))
        self.pButtonAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
        self.pButtonchange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
        self.pButtonExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa\u9879\u76ee", None))
        self.pButtonImport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165\u9879\u76ee", None))
        self.pButtonshow.setText(QCoreApplication.translate("MainWindow", u"\u663e\u793a\u9879\u76ee\u53ca\u6570\u636e", None))
        self.pButtonExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
        self.menuFile.setTitle(QCoreApplication.translate("MainWindow", u"\u6587\u4ef6", None))
        self.menuAdd.setTitle("")
        self.menuEdit.setTitle(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91", None))
        self.menuHelp.setTitle(QCoreApplication.translate("MainWindow", u"\u5e2e\u52a9", None))
        self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
    # retranslateUi

main.py

from PySide2.QtWidgets import QApplication
from PySide2.QtWidgets import QMainWindow
from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
from PySide2.QtWidgets import QAbstractItemView, QLineEdit, QPushButton
import sys, os
from main_body.ui_main import Ui_MainWindow as MainWin

from PySide2.QtWidgets import QHeaderView
import sqlite3

from PySide2.QtWidgets import QFileDialog, QMessageBox, QMenu
import chardet, csv

from PySide2.QtCore import Signal, Qt
from gl import DetailWindow as DetailWind

from search import DetailWindow as Searchwind

from tkinter import *
from tkinter import messagebox

from question import DetailWindow  as qwind

from control_user import MainWindow as conwind

from PySide2.QtGui import Qt, QIcon # 图标、窗体设置


class MainWindow(QMainWindow, MainWin):
    mainSignal = Signal(str, dict)
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # 设置窗体图标
        app_icon = QIcon('项目新.ico')
        self.setWindowIcon(app_icon)

        self.pButtonExit.clicked.connect(lambda: self.Close())
        self.pButtonshow.clicked.connect(lambda: self.Show())
        self.pButtonImport.clicked.connect(lambda: self.Import())

        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)

        self.gl_win = None
        self.pButtonAdd.clicked.connect(lambda: self.Project_Add())
        self.pButtonchange.clicked.connect(lambda: self.Project_Change())
        self.pButtonExport.clicked.connect(lambda: self.Export())
        self.pButtonSelect.clicked.connect(lambda: self.Select())

        self.stuAction = None
        self.YhName = None

        self.actionTlbExit.triggered.connect(lambda: self.Close())
        self.actionTlbAdd.triggered.connect(lambda: self.Project_Add())
        self.actionTlbChange.triggered.connect(lambda: self.Project_Change())
        self.actionTlbExport.triggered.connect(lambda: self.Export())
        self.actionTlbSelect.triggered.connect(lambda: self.Select())
        # self.tableWidget.setSelectionBehavior(
        #     QAbstractItemView.SelectRows  # 行选
        # )
        # self.tableWidget.setSelectionMode(
        #     QAbstractItemView.SingleSelection  # 单选
        # )


        self.actionMenuExit.triggered.connect(lambda: self.Close())
        self.actionMenuOpen.triggered.connect(lambda: self.Import())
        self.actionMenuAdd.triggered.connect(lambda: self.Project_Add())
        self.actionMenuChange.triggered.connect(lambda: self.Project_Change())
        self.actionquestion.triggered.connect(lambda: self.question())

        # self.Show()
        # self.pButtonshow.setVisible(False)

        self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.tableWidget.customContextMenuRequested.connect(self.menu_pop)

########################################################################################################################
# 显示all_projects的数据
    def Show(self, actionGl=False):
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
        try:
            if actionGl == True:
                while self.tableWidget.rowCount() > 0:
                    self.tableWidget.removeRow(0)
                self.tableWidget.setRowCount(0)
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                   select  Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
                   from project
                  '''
            cur.execute(sql)
            stu = cur.fetchone()
            row_index = 0
            while stu:
                self.tableWidget.insertRow(row_index)
                for colIdx, data in enumerate(stu):
                    TblItem = QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_index, colIdx, TblItem)
                stu = cur.fetchone()
                row_index = row_index + 1
            self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        except Exception as e:
            print(e)
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None
########################################################################################################################
# 导入all_Projects的数据
    def Import(self):
        # 选择要导入的CSV文件
        csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        # 获取导入数据库路径
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')

        if not db_file:
            return

        try:
            # 连接数据库并创建表格
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            # cur.execute(
            #     'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')

            # 读取CSV文件并插入数据
            with open(csv_file, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    cur.execute(
                        'INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM project WHERE Id = ?)',
                        (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[0]))

            conn.commit()
            QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
        except Exception as e:
            conn.rollback()
            QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()

            # opened_file = QFileDialog().getOpenFileName(
        #     parent=self,
        #     caption='选择要导入的文件',
        #     dir=self.cur_dir,
        #     filter='CSV文件(*.csv);;文本文件(*.txt)'
        # )
        # if len(opened_file[0]) > 0:
        #     db_file = os.path.join(self.cur_dir, './data/all_projects.db')
        #     try:
        #         conn = sqlite3.connect(db_file)
        #         cur = conn.cursor()
        #         sql = '''
        #               INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark)
        #               VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
        #               '''
        #         data = open(opened_file[0], mode='rb').read()
        #         encoding = chardet.detect(data).get('encoding')
        #         with open(opened_file[0], mode='r', encoding=encoding) as f:
        #             csv_reader = csv.DictReader(f)
        #             rows = []
        #             for row in csv_reader:
        #                 rows.append((row['项目编号'], row['项目类型'], row['项目名称'],
        #                 row['开始日期'], row['结束日期'], row['完成进度'], row['负责人'],
        #                 row['项目级别'], row['备注']))
        #             cur.executemany(sql, rows)
        #         conn.commit()
        #         QMessageBox.information(self, '消息', '导入成功!')

                #self.db2screen()

            # except Exception as e:
            #     conn.rollback()
            #     QMessageBox.critical(self, '错误', '导入失败!' + str(e))
            # finally:
            #     cur.close()
            #     conn.close()
            #     cur = None
            #     conn = None
########################################################################################################################
# 添加项目
    def Project_Add(self):
        self.stuAction = 'Add'
        self.gl_win = DetailWind()
        self.gl_win.setModal(True)
        self.gl_win.show()
        self.mainSignal.connect(self.gl_win.handle_main_signal)
        self.mainSignal.emit(self.stuAction, None)
        self.gl_win.detailSiganl.connect(self.Show)
########################################################################################################################
# 修改项目
    def Project_Change(self):
        self.stuAction = 'Change'
        selected_ranges = self.tableWidget.selectedRanges()

        if len(selected_ranges) > 1 or len(selected_ranges) == 0:
            QMessageBox.warning(self, '警告', '请选择一行')
            return

        self.gl_win = DetailWind()
        self.gl_win.setModal(True)
        self.gl_win.show()
        self.mainSignal.connect(self.gl_win.handle_main_signal)

        stu = {}
        current_row = self.tableWidget.currentRow()
        for c in range(self.tableWidget.columnCount()):
            item_data = self.tableWidget.item(current_row, c).text()
            item_name = self.tableWidget.horizontalHeaderItem(c).text()
            stu[item_name] = item_data

        self.mainSignal.emit(self.stuAction, stu)
        self.gl_win.detailSiganl.connect(self.Show)
########################################################################################################################
# 右键菜单
    def menu_pop(self, pos):
        row = self.tableWidget.currentRow()
        stu = {}
        for col in range(self.tableWidget.columnCount()):
            col_name = self.tableWidget.horizontalHeaderItem(col).text()
            col_value = self.tableWidget.item(row, col).text()
            stu[col_name] = col_value

        menu = QMenu()
        actionAdd = menu.addAction(u'添加')
        actionEdit = menu.addAction(u'编辑')
        actionDel = menu.addAction(u'删除')

        actionName = menu.exec_(self.tableWidget.mapToGlobal(pos))
        if actionName == actionAdd:
            self.Project_Add()
        elif actionName == actionEdit:
            self.Project_Change()
        elif actionName == actionDel:
            stu_People = stu['负责人']
            stu_No = stu['项目编号']
            answer = QMessageBox.question(
                self,
                '确认删除',
                '是否删除{}行的项目'.format(row+1, stu_People),
                QMessageBox.Yes | QMessageBox.No
            )
            if answer == QMessageBox.No:
                return
            self.tableWidget.removeRow(row)
            self.del_from_db(stu_No)
########################################################################################################################
# 右键菜单中的删除键所使用的功能
    def del_from_db(self, stu_No):
        conn, cur = None, None
        try:
            db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                    delete from project where Id = '{}'
                  '''.format(stu_No)
            cur.execute(sql)
            conn.commit()
            QMessageBox.information(
                self,
                '删除成功',
                '成功删除项目:{}!'.format(stu_No),
                QMessageBox.Ok
            )
        except Exception as e:
            conn.rollback()
            QMessageBox.critical(
                self,
                '删除失败!',
                str(e),
                QMessageBox.Ok
            )
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None
########################################################################################################################
# 退出系统
    def Close(self):
        reply = QMessageBox.question(self,'关闭提示',"是否要退出界面?",
                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.close()
        elif reply == QMessageBox.No:
            return
########################################################################################################################
# 导出项目
    def Export(self):
        # 选择要导出的数据库文件
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')

        if not db_file:
            return

        # 获取导出路径
        csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        try:
            # 连接数据库并查询数据
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            cur.execute('SELECT * FROM project')
            data = cur.fetchall()

            # 将数据写入CSV文件
            with open(csv_file, 'w', newline='') as f:
                writer = csv.writer(f)
                writer.writerow([i[0] for i in cur.description])  # 写入表头
                for row in data:
                    writer.writerow(row)

            QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
        except Exception as e:
            QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()
########################################################################################################################
# 搜索项目
    def Select(self):
        self.se_win = Searchwind()
        self.se_win.setModal(True)
        self.se_win.show()
#     def Select(self):
#         e = 0
#         root = Tk()
#         root.title("查询项目")
#         Label(root, text='输入项目编号:').grid(row=0, column=0)
#         e1 = Entry(root)
#         e1.grid(row=0, column=1, padx=10, pady=5)
#
#         def showData(e):
#             dept = str(e1.get())
#             db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
#             conn = sqlite3.connect(db_file)
#             cur = conn.cursor()
#             sql = '''
#                     select  Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
#                     from project
#                     where Id = ?
#                   '''
#             cur.execute(sql, (dept,))
#             data = cur.fetchone()
#             if data:
#                 messagebox.showinfo("查询结果", "{}".format(data))
#             else:
#                 messagebox.showwarning("查询结果", "未查询到相关信息")
#
#             cur.close()
#             conn.close()
#
#         bTnOk = Button(text='查询')
#         bTnOk.grid(row=3, column=1)
#         bTnOk.bind("", showData)
#         mainloop()
########################################################################################################################
    def question(self):
        self.que_win = qwind()
        self.que_win.setModal(True)
        self.que_win.show()
########################################################################################################################
    def yh_login_Signal(self, yhActionName:str):
        self.YhName = yhActionName
        self.lineEditUser_Id.setText('欢迎!'+ self.YhName)
        # print(self.YhName)
        # print(type(self.YhName))
        conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
        c = conn.cursor()

        sql_add = f"select add_right from all_user where username='{self.YhName}'"
        sql_change = f"select change_right from all_user where username='{self.YhName}'"
        sql_import = f"select import_right from all_user where username='{self.YhName}'"
        sql_export = f"select export_right from all_user where username='{self.YhName}'"
        cursor_add = c.execute(sql_add)
        result_add = cursor_add.fetchone()                 # 返回元组,取第一个值
        # print(result_add[0])
        # print(type(result_add[0]))

        cursor_change = c.execute(sql_change)
        result_change = cursor_change.fetchone()

        cursor_import = c.execute(sql_import)
        result_import = cursor_import.fetchone()

        cursor_export = c.execute(sql_export)
        result_export = cursor_export.fetchone()

        if result_add[0] == 'F':
            self.pButtonAdd.setVisible(False)
        else:
            self.pButtonAdd.setVisible(True)

        if result_change[0] == 'F':
            self.pButtonchange.setVisible(False)
        else:
            self.pButtonchange.setVisible(True)

        if result_import[0] == 'F':
            self.pButtonImport.setVisible(False)
        else:
            self.pButtonImport.setVisible(True)

        if result_export[0] == 'F':
            self.pButtonAdd.setVisible(False)
        else:
            self.pButtonAdd.setVisible(True)







if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = MainWindow()
    win_main.show()
    sys.exit(app.exec_())

 6)管理员主界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第29张图片

ui_control_user.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'control_user.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(1242, 687)
        self.actionTlbAdd = QAction(MainWindow)
        self.actionTlbAdd.setObjectName(u"actionTlbAdd")
        self.actionTlbChange = QAction(MainWindow)
        self.actionTlbChange.setObjectName(u"actionTlbChange")
        self.actionTlbSearch = QAction(MainWindow)
        self.actionTlbSearch.setObjectName(u"actionTlbSearch")
        self.actionMenuopen = QAction(MainWindow)
        self.actionMenuopen.setObjectName(u"actionMenuopen")
        self.actionMenuexport = QAction(MainWindow)
        self.actionMenuexport.setObjectName(u"actionMenuexport")
        self.actionMenuExport = QAction(MainWindow)
        self.actionMenuExport.setObjectName(u"actionMenuExport")
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.layoutWidget = QWidget(self.centralwidget)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(0, 0, 1241, 611))
        self.verticalLayout_4 = QVBoxLayout(self.layoutWidget)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label = QLabel(self.layoutWidget)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(26)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)

        self.horizontalLayout.addWidget(self.label)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)


        self.verticalLayout_4.addLayout(self.horizontalLayout)

        self.verticalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_4.addItem(self.verticalSpacer_5)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.tableWidget = QTableWidget(self.layoutWidget)
        if (self.tableWidget.columnCount() < 9):
            self.tableWidget.setColumnCount(9)
        __qtablewidgetitem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
        __qtablewidgetitem1 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
        __qtablewidgetitem2 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
        __qtablewidgetitem3 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
        __qtablewidgetitem4 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
        __qtablewidgetitem5 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
        __qtablewidgetitem6 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
        __qtablewidgetitem7 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
        __qtablewidgetitem8 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
        self.tableWidget.setObjectName(u"tableWidget")

        self.horizontalLayout_2.addWidget(self.tableWidget)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalSpacer_4 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_3.addItem(self.verticalSpacer_4)

        self.pButtonSelect = QPushButton(self.layoutWidget)
        self.pButtonSelect.setObjectName(u"pButtonSelect")

        self.verticalLayout_3.addWidget(self.pButtonSelect)

        self.verticalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_3.addItem(self.verticalSpacer_6)

        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.pButtonDisplay = QPushButton(self.layoutWidget)
        self.pButtonDisplay.setObjectName(u"pButtonDisplay")

        self.verticalLayout.addWidget(self.pButtonDisplay)

        self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.pButtonChange = QPushButton(self.layoutWidget)
        self.pButtonChange.setObjectName(u"pButtonChange")

        self.verticalLayout.addWidget(self.pButtonChange)


        self.verticalLayout_2.addLayout(self.verticalLayout)

        self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.pButtonAdd = QPushButton(self.layoutWidget)
        self.pButtonAdd.setObjectName(u"pButtonAdd")

        self.verticalLayout_2.addWidget(self.pButtonAdd)

        self.verticalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_7)

        self.pButtonImport = QPushButton(self.layoutWidget)
        self.pButtonImport.setObjectName(u"pButtonImport")

        self.verticalLayout_2.addWidget(self.pButtonImport)

        self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_8)

        self.pButtonExit = QPushButton(self.layoutWidget)
        self.pButtonExit.setObjectName(u"pButtonExit")

        self.verticalLayout_2.addWidget(self.pButtonExit)


        self.verticalLayout_3.addLayout(self.verticalLayout_2)


        self.horizontalLayout_2.addLayout(self.verticalLayout_3)


        self.verticalLayout_4.addLayout(self.horizontalLayout_2)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 1242, 26))
        self.menufile = QMenu(self.menubar)
        self.menufile.setObjectName(u"menufile")
        self.menuhelp = QMenu(self.menubar)
        self.menuhelp.setObjectName(u"menuhelp")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolBar = QToolBar(MainWindow)
        self.toolBar.setObjectName(u"toolBar")
        MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)

        self.menubar.addAction(self.menufile.menuAction())
        self.menubar.addAction(self.menuhelp.menuAction())
        self.menufile.addAction(self.actionMenuopen)
        self.menufile.addAction(self.actionMenuExport)
        self.toolBar.addAction(self.actionTlbAdd)
        self.toolBar.addAction(self.actionTlbChange)
        self.toolBar.addAction(self.actionTlbSearch)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7ba1\u7406", None))
        self.actionTlbAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0", None))
        self.actionTlbChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539", None))
        self.actionTlbSearch.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22", None))
        self.actionMenuopen.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None))
        self.actionMenuexport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None))
        self.actionMenuExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7ba1\u7406", None))
        ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
        ___qtablewidgetitem.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7c7b\u578b", None));
        ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
        ___qtablewidgetitem1.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u540d", None));
        ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
        ___qtablewidgetitem2.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u5bc6\u7801", None));
        ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
        ___qtablewidgetitem3.setText(QCoreApplication.translate("MainWindow", u"\u767b\u5f55\u6b21\u6570", None));
        ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
        ___qtablewidgetitem4.setText(QCoreApplication.translate("MainWindow", u"\u4e0a\u4e00\u6b21\u767b\u5f55\u65f6\u95f4", None));
        ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
        ___qtablewidgetitem5.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0", None));
        ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
        ___qtablewidgetitem6.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539", None));
        ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
        ___qtablewidgetitem7.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165", None));
        ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
        ___qtablewidgetitem8.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None));
        self.pButtonSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u7528\u6237", None))
        self.pButtonDisplay.setText(QCoreApplication.translate("MainWindow", u"\u663e\u793a\u7528\u6237", None))
        self.pButtonChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u7528\u6237", None))
        self.pButtonAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u7528\u6237", None))
        self.pButtonImport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165\u7528\u6237", None))
        self.pButtonExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
        self.menufile.setTitle(QCoreApplication.translate("MainWindow", u"\u6587\u4ef6", None))
        self.menuhelp.setTitle(QCoreApplication.translate("MainWindow", u"\u5e2e\u52a9", None))
        self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
    # retranslateUi

control_user.py
from PySide2.QtWidgets import QApplication
from PySide2.QtWidgets import QMainWindow
from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
from PySide2.QtWidgets import QAbstractItemView, QLineEdit, QPushButton
import sys, os
from PySide2.QtWidgets import QHeaderView
import sqlite3
from PySide2.QtWidgets import QFileDialog, QMessageBox, QMenu
import chardet, csv
from PySide2.QtCore import Signal, Qt
from tkinter import *
from tkinter import messagebox
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
from main_body.ui_control_user import Ui_MainWindow
from control_gl import DetailWindow as DetailWind

class MainWindow(QMainWindow, Ui_MainWindow):
    mainSignal = Signal(str, dict)
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # 设置窗体图标
        app_icon = QIcon('项目新.ico')
        self.setWindowIcon(app_icon)

        self.pButtonExit.clicked.connect(lambda: self.Close())
        self.pButtonDisplay.clicked.connect(lambda: self.Show())

        self.user_win = None
        self.pButtonAdd.clicked.connect(lambda: self.User_Add())
        self.pButtonChange.clicked.connect(lambda: self.User_Change())
        self.pButtonSelect.clicked.connect(lambda: self.Select())
        self.pButtonImport.clicked.connect(lambda: self.Import())

        self.stuAction = None

        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)

        self.actionTlbSearch.triggered.connect(lambda: self.Select())
        self.actionMenuopen.triggered.connect(lambda: self.Import())
        self.actionMenuExport.triggered.connect(lambda: self.Export())
        self.actionTlbAdd.triggered.connect(lambda: self.User_Add())
        self.actionTlbChange.triggered.connect(lambda: self.User_Change())
        # 右键菜单
        self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.tableWidget.customContextMenuRequested.connect(self.menu_pop)

    def Show(self, actionGl=False):
        db_file = os.path.join(self.cur_dir, './data/user_password.db')
        try:
            if actionGl == True:
                while self.tableWidget.rowCount() > 0:
                    self.tableWidget.removeRow(0)
                self.tableWidget.setRowCount(0)
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                   select  *
                   from all_user
                  '''
            cur.execute(sql)
            stu = cur.fetchone()
            row_index = 0
            while stu:
                self.tableWidget.insertRow(row_index)
                for colIdx, data in enumerate(stu):
                    TblItem = QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_index, colIdx, TblItem)
                stu = cur.fetchone()
                row_index = row_index + 1
            self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        except Exception as e:
            print(e)
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None

# 添加用户
    def User_Add(self):
        self.stuAction = 'Add'
        self.gl_win = DetailWind()
        self.gl_win.setModal(True)
        self.gl_win.show()
        self.mainSignal.connect(self.gl_win.handle_main_signal)
        self.mainSignal.emit(self.stuAction, None)
        self.gl_win.detailSiganl.connect(self.Show)


# 修改用户
    def User_Change(self):
        self.stuAction = 'Change'
        selected_ranges = self.tableWidget.selectedRanges()

        if len(selected_ranges) > 1 or len(selected_ranges) == 0:
            QMessageBox.warning(self, '警告', '请选择一行')
            return

        self.gl_win = DetailWind()
        self.gl_win.setModal(True)
        self.gl_win.show()
        self.mainSignal.connect(self.gl_win.handle_main_signal)

        stu = {}
        current_row = self.tableWidget.currentRow()
        for c in range(self.tableWidget.columnCount()):
            item_data = self.tableWidget.item(current_row, c).text()
            item_name = self.tableWidget.horizontalHeaderItem(c).text()
            stu[item_name] = item_data

        self.mainSignal.emit(self.stuAction, stu)
        self.gl_win.detailSiganl.connect(self.Show)


# 退出系统
    def Close(self):
        reply = QMessageBox.question(self,'关闭提示',"是否要退出界面?",
                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.close()
        elif reply == QMessageBox.No:
            return

    def Select(self):
        e = 0
        root = Tk()
        root.title("查询项目")
        Label(root, text='输入项目编号:').grid(row=0, column=0)
        e1 = Entry(root)
        e1.grid(row=0, column=1, padx=10, pady=5)

        def showData(e):
            dept = str(e1.get())
            db_file = os.path.join(self.cur_dir, './data/user_password.db')
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                    select  user_type,username,password,login_times,last_login,add_right,change_right,
                    import_right,export_right
                    from all_user
                    where username = ?
                  '''
            cur.execute(sql, (dept,))
            data = cur.fetchone()
            if data:
                messagebox.showinfo("查询结果", "用户类型{},用户名{},用户密码{}\n登录次数{},上一次登录时间{}\n添加权限{},修改权限{},导入权限{},导出权限{}".format(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8]))
            else:
                messagebox.showwarning("查询结果", "未查询到相关信息")

            cur.close()
            conn.close()

        bTnOk = Button(text='查询')
        bTnOk.grid(row=3, column=1)
        bTnOk.bind("", showData)
        mainloop()


    def Import(self):
        # 选择要导入的CSV文件
        csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        # 获取导入数据库路径
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/user_password.db')

        if not db_file:
            return

        try:
            # 连接数据库并创建表格
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            # cur.execute(
            #     'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')

            # 读取CSV文件并插入数据
            with open(csv_file, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    cur.execute(
                        'INSERT INTO all_user (user_type,username,password,login_times,last_login) SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM all_user WHERE username = ?)',
                        (row[0], row[1], row[2], row[3], row[4], row[0]))

            conn.commit()
            QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
        except Exception as e:
            conn.rollback()
            QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()

    def Export(self):
        # 选择要导出的数据库文件
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/user_password.db')

        if not db_file:
            return

        # 获取导出路径
        csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        try:
            # 连接数据库并查询数据
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            cur.execute('SELECT * FROM all_user')
            data = cur.fetchall()

            # 将数据写入CSV文件
            with open(csv_file, 'w', newline='') as f:
                writer = csv.writer(f)
                writer.writerow([i[0] for i in cur.description])  # 写入表头
                for row in data:
                    writer.writerow(row)

            QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
        except Exception as e:
            QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()


    def menu_pop(self, pos):
        row = self.tableWidget.currentRow()
        stu = {}
        for col in range(self.tableWidget.columnCount()):
            col_name = self.tableWidget.horizontalHeaderItem(col).text()
            col_value = self.tableWidget.item(row, col).text()
            stu[col_name] = col_value

        menu = QMenu()
        actionAdd = menu.addAction(u'添加')
        actionEdit = menu.addAction(u'编辑')
        actionDel = menu.addAction(u'删除')

        actionName = menu.exec_(self.tableWidget.mapToGlobal(pos))
        if actionName == actionAdd:
            self.User_Add()
        elif actionName == actionEdit:
            self.User_Change()
        elif actionName == actionDel:
            stu_People = stu['用户名']
            stu_No = stu['用户密码']
            answer = QMessageBox.question(
                self,
                '确认删除',
                '是否删除{}行的项目'.format(row+1, stu_People),
                QMessageBox.Yes | QMessageBox.No
            )
            if answer == QMessageBox.No:
                return
            self.tableWidget.removeRow(row)
            self.del_from_db(stu_No)


    def del_from_db(self, stu_No):
        conn, cur = None, None
        try:
            db_file = os.path.join(self.cur_dir, './data/user_password.db')
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                    delete from all_user where password = '{}'
                  '''.format(stu_No)
            cur.execute(sql)
            conn.commit()
            QMessageBox.information(
                self,
                '删除成功',
                '成功删除项目:{}!'.format(stu_No),
                QMessageBox.Ok
            )
        except Exception as e:
            conn.rollback()
            QMessageBox.critical(
                self,
                '删除失败!',
                str(e),
                QMessageBox.Ok
            )
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = MainWindow()
    win_main.show()
    sys.exit(app.exec_())

7)添加界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第30张图片

ui_gl.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'gl.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

import picture_rc

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(892, 787)
        icon = QIcon()
        icon.addFile(u"C:/Users/17844/Desktop/Python\u5927\u4f5c\u4e1a/\u9879\u76ee.ico", QSize(), QIcon.Normal, QIcon.Off)
        Dialog.setWindowIcon(icon)
        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(1, 1, 891, 785))
        self.verticalLayout_10 = QVBoxLayout(self.layoutWidget)
        self.verticalLayout_10.setObjectName(u"verticalLayout_10")
        self.verticalLayout_10.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_9 = QVBoxLayout()
        self.verticalLayout_9.setObjectName(u"verticalLayout_9")
        self.horizontalLayout_13 = QHBoxLayout()
        self.horizontalLayout_13.setObjectName(u"horizontalLayout_13")
        self.horizontalSpacer_16 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_13.addItem(self.horizontalSpacer_16)

        self.label_Big_Title = QLabel(self.layoutWidget)
        self.label_Big_Title.setObjectName(u"label_Big_Title")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.label_Big_Title.setFont(font)

        self.horizontalLayout_13.addWidget(self.label_Big_Title)

        self.horizontalSpacer_17 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_13.addItem(self.horizontalSpacer_17)


        self.verticalLayout_9.addLayout(self.horizontalLayout_13)

        self.verticalSpacer_9 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.verticalLayout_9.addItem(self.verticalSpacer_9)

        self.horizontalLayout_14 = QHBoxLayout()
        self.horizontalLayout_14.setObjectName(u"horizontalLayout_14")
        self.horizontalSpacer_18 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_14.addItem(self.horizontalSpacer_18)

        self.verticalLayout_8 = QVBoxLayout()
        self.verticalLayout_8.setObjectName(u"verticalLayout_8")
        self.verticalLayout_7 = QVBoxLayout()
        self.verticalLayout_7.setObjectName(u"verticalLayout_7")
        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_5)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.label_2 = QLabel(self.layoutWidget)
        self.label_2.setObjectName(u"label_2")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(10)
        self.label_2.setFont(font1)

        self.horizontalLayout.addWidget(self.label_2)

        self.horizontalSpacer = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.lineEdit_No = QLineEdit(self.layoutWidget)
        self.lineEdit_No.setObjectName(u"lineEdit_No")

        self.horizontalLayout.addWidget(self.lineEdit_No)


        self.horizontalLayout_3.addLayout(self.horizontalLayout)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_3)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_3 = QLabel(self.layoutWidget)
        self.label_3.setObjectName(u"label_3")
        self.label_3.setFont(font1)

        self.horizontalLayout_2.addWidget(self.label_3)

        self.horizontalSpacer_2 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_2)

        self.lineEdit_Type = QLineEdit(self.layoutWidget)
        self.lineEdit_Type.setObjectName(u"lineEdit_Type")

        self.horizontalLayout_2.addWidget(self.lineEdit_Type)


        self.horizontalLayout_3.addLayout(self.horizontalLayout_2)

        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_4)


        self.verticalLayout.addLayout(self.horizontalLayout_3)

        self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout_4 = QHBoxLayout()
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.label_4 = QLabel(self.layoutWidget)
        self.label_4.setObjectName(u"label_4")

        self.horizontalLayout_4.addWidget(self.label_4)

        self.horizontalSpacer_6 = QSpacerItem(5, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_6)

        self.lineEdit_Name = QLineEdit(self.layoutWidget)
        self.lineEdit_Name.setObjectName(u"lineEdit_Name")
        self.lineEdit_Name.setEnabled(True)

        self.horizontalLayout_4.addWidget(self.lineEdit_Name)


        self.verticalLayout.addLayout(self.horizontalLayout_4)


        self.verticalLayout_7.addLayout(self.verticalLayout)

        self.verticalSpacer_7 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_7.addItem(self.verticalSpacer_7)

        self.horizontalLayout_12 = QHBoxLayout()
        self.horizontalLayout_12.setObjectName(u"horizontalLayout_12")
        self.verticalLayout_5 = QVBoxLayout()
        self.verticalLayout_5.setObjectName(u"verticalLayout_5")
        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.horizontalLayout_11 = QHBoxLayout()
        self.horizontalLayout_11.setObjectName(u"horizontalLayout_11")
        self.label_5 = QLabel(self.layoutWidget)
        self.label_5.setObjectName(u"label_5")

        self.horizontalLayout_11.addWidget(self.label_5)

        self.horizontalSpacer_13 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_11.addItem(self.horizontalSpacer_13)

        self.lineEdit_Start = QLineEdit(self.layoutWidget)
        self.lineEdit_Start.setObjectName(u"lineEdit_Start")

        self.horizontalLayout_11.addWidget(self.lineEdit_Start)


        self.verticalLayout_2.addLayout(self.horizontalLayout_11)

        self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.horizontalLayout_10 = QHBoxLayout()
        self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
        self.label_6 = QLabel(self.layoutWidget)
        self.label_6.setObjectName(u"label_6")

        self.horizontalLayout_10.addWidget(self.label_6)

        self.horizontalSpacer_12 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_10.addItem(self.horizontalSpacer_12)

        self.lineEdit_End = QLineEdit(self.layoutWidget)
        self.lineEdit_End.setObjectName(u"lineEdit_End")

        self.horizontalLayout_10.addWidget(self.lineEdit_End)


        self.verticalLayout_2.addLayout(self.horizontalLayout_10)


        self.verticalLayout_3.addLayout(self.verticalLayout_2)

        self.verticalSpacer_3 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_3.addItem(self.verticalSpacer_3)

        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.label_13 = QLabel(self.layoutWidget)
        self.label_13.setObjectName(u"label_13")

        self.horizontalLayout_5.addWidget(self.label_13)

        self.horizontalSpacer_11 = QSpacerItem(13, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_11)

        self.lineEdit_Completion_Progress = QLineEdit(self.layoutWidget)
        self.lineEdit_Completion_Progress.setObjectName(u"lineEdit_Completion_Progress")

        self.horizontalLayout_5.addWidget(self.lineEdit_Completion_Progress)


        self.verticalLayout_3.addLayout(self.horizontalLayout_5)


        self.verticalLayout_5.addLayout(self.verticalLayout_3)

        self.verticalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_5.addItem(self.verticalSpacer_5)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.horizontalLayout_8 = QHBoxLayout()
        self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
        self.label_9 = QLabel(self.layoutWidget)
        self.label_9.setObjectName(u"label_9")

        self.horizontalLayout_8.addWidget(self.label_9)

        self.horizontalSpacer_10 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_8.addItem(self.horizontalSpacer_10)

        self.lineEdit_People = QLineEdit(self.layoutWidget)
        self.lineEdit_People.setObjectName(u"lineEdit_People")

        self.horizontalLayout_8.addWidget(self.lineEdit_People)


        self.verticalLayout_4.addLayout(self.horizontalLayout_8)

        self.verticalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_4.addItem(self.verticalSpacer_4)

        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.label_10 = QLabel(self.layoutWidget)
        self.label_10.setObjectName(u"label_10")

        self.horizontalLayout_7.addWidget(self.label_10)

        self.horizontalSpacer_9 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_7.addItem(self.horizontalSpacer_9)

        self.lineEdit_Money = QLineEdit(self.layoutWidget)
        self.lineEdit_Money.setObjectName(u"lineEdit_Money")

        self.horizontalLayout_7.addWidget(self.lineEdit_Money)


        self.verticalLayout_4.addLayout(self.horizontalLayout_7)


        self.verticalLayout_5.addLayout(self.verticalLayout_4)


        self.horizontalLayout_12.addLayout(self.verticalLayout_5)

        self.horizontalSpacer_15 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_12.addItem(self.horizontalSpacer_15)

        self.verticalLayout_6 = QVBoxLayout()
        self.verticalLayout_6.setObjectName(u"verticalLayout_6")
        self.horizontalLayout_9 = QHBoxLayout()
        self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
        self.label_12 = QLabel(self.layoutWidget)
        self.label_12.setObjectName(u"label_12")

        self.horizontalLayout_9.addWidget(self.label_12)

        self.horizontalSpacer_7 = QSpacerItem(13, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_9.addItem(self.horizontalSpacer_7)

        self.textEdit_Label = QTextEdit(self.layoutWidget)
        self.textEdit_Label.setObjectName(u"textEdit_Label")

        self.horizontalLayout_9.addWidget(self.textEdit_Label)


        self.verticalLayout_6.addLayout(self.horizontalLayout_9)

        self.verticalSpacer_6 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_6.addItem(self.verticalSpacer_6)

        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.label_8 = QLabel(self.layoutWidget)
        self.label_8.setObjectName(u"label_8")

        self.horizontalLayout_6.addWidget(self.label_8)

        self.horizontalSpacer_8 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_8)

        self.lineEdit_level = QLineEdit(self.layoutWidget)
        self.lineEdit_level.setObjectName(u"lineEdit_level")

        self.horizontalLayout_6.addWidget(self.lineEdit_level)


        self.verticalLayout_6.addLayout(self.horizontalLayout_6)


        self.horizontalLayout_12.addLayout(self.verticalLayout_6)


        self.verticalLayout_7.addLayout(self.horizontalLayout_12)


        self.verticalLayout_8.addLayout(self.verticalLayout_7)

        self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_8.addItem(self.verticalSpacer_8)

        self.gridLayout = QGridLayout()
        self.gridLayout.setObjectName(u"gridLayout")
        self.label_11 = QLabel(self.layoutWidget)
        self.label_11.setObjectName(u"label_11")

        self.gridLayout.addWidget(self.label_11, 0, 0, 1, 1)

        self.horizontalSpacer_14 = QSpacerItem(40, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.gridLayout.addItem(self.horizontalSpacer_14, 1, 0, 1, 1)

        self.textEdit_Notes = QTextEdit(self.layoutWidget)
        self.textEdit_Notes.setObjectName(u"textEdit_Notes")

        self.gridLayout.addWidget(self.textEdit_Notes, 1, 1, 1, 1)


        self.verticalLayout_8.addLayout(self.gridLayout)


        self.horizontalLayout_14.addLayout(self.verticalLayout_8)

        self.horizontalSpacer_19 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_14.addItem(self.horizontalSpacer_19)


        self.verticalLayout_9.addLayout(self.horizontalLayout_14)


        self.verticalLayout_10.addLayout(self.verticalLayout_9)

        self.verticalSpacer_10 = QSpacerItem(20, 5, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.verticalLayout_10.addItem(self.verticalSpacer_10)

        self.horizontalLayout_15 = QHBoxLayout()
        self.horizontalLayout_15.setObjectName(u"horizontalLayout_15")
        self.horizontalSpacer_20 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_15.addItem(self.horizontalSpacer_20)

        self.pButtonOk = QPushButton(self.layoutWidget)
        self.pButtonOk.setObjectName(u"pButtonOk")
        font2 = QFont()
        font2.setFamily(u"Agency FB")
        font2.setPointSize(12)
        font2.setBold(False)
        font2.setWeight(50)
        self.pButtonOk.setFont(font2)

        self.horizontalLayout_15.addWidget(self.pButtonOk)

        self.horizontalSpacer_21 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_15.addItem(self.horizontalSpacer_21)

        self.pButtonCancel = QPushButton(self.layoutWidget)
        self.pButtonCancel.setObjectName(u"pButtonCancel")
        font3 = QFont()
        font3.setFamily(u"Agency FB")
        font3.setPointSize(12)
        self.pButtonCancel.setFont(font3)

        self.horizontalLayout_15.addWidget(self.pButtonCancel)

        self.horizontalSpacer_22 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_15.addItem(self.horizontalSpacer_22)


        self.verticalLayout_10.addLayout(self.horizontalLayout_15)

        self.label = QLabel(Dialog)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(1, 4, 891, 781))
        self.label.setPixmap(QPixmap(u":/\u80cc\u666f\u56fe1.png"))
        self.label.raise_()
        self.layoutWidget.raise_()

        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
        self.label_Big_Title.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7f16\u53f7\uff1a", None))
        self.label_3.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7c7b\u578b\uff1a", None))
        self.label_4.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u540d\u79f0\uff1a", None))
        self.label_5.setText(QCoreApplication.translate("Dialog", u"\u5f00\u59cb\u65e5\u671f\uff1a", None))
        self.label_6.setText(QCoreApplication.translate("Dialog", u"\u7ed3\u675f\u65e5\u671f\uff1a", None))
        self.label_13.setText(QCoreApplication.translate("Dialog", u"\u5b8c\u6210\u8fdb\u5ea6\uff1a", None))
        self.label_9.setText(QCoreApplication.translate("Dialog", u"\u8d1f\u8d23\u4eba\uff1a", None))
        self.label_10.setText(QCoreApplication.translate("Dialog", u"\u9884\u7b97\u91d1\u989d\uff1a", None))
        self.label_12.setText(QCoreApplication.translate("Dialog", u"\u6807\u7b7e\uff1a", None))
        self.label_8.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ea7\u522b\uff1a", None))
        self.label_11.setText(QCoreApplication.translate("Dialog", u"\u5907\u6ce8\uff1a", None))
        self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
        self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
        self.label.setText("")
    # retranslateUi

gl.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
import sys, os, sqlite3
from main_body.ui_gl import Ui_Dialog
from PySide2.QtGui import QIcon

class DetailWindow(QDialog, Ui_Dialog):
    detailSiganl = Signal(bool)

    def __init__(self):
        super(DetailWindow, self).__init__()
        self.setupUi(self)
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # self.setWindowFlags(
        #     Qt.WindowMinMaxButtonsHint |
        #     Qt.MSWindowsFixedSizeDialogHint
        # )

        self.actionName = None

        self.pButtonOk.clicked.connect(lambda: self.save2db())
        self.pButtonCancel.clicked.connect(lambda: self.close())

        # 设置窗体图标
        app_icon = QIcon('修改.ico')
        self.setWindowIcon(app_icon)


    def handle_main_signal(self, mainActionName:str, stu:dict):
        self.actionName = mainActionName
        if self.actionName == 'Add':
            self.label_Big_Title.setText('项目添加')
            self.pButtonOk.setText('添加')
            self.lineEdit_No.setText('')
            self.lineEdit_Type.setText('')
            self.lineEdit_Name.setText('')
            self.lineEdit_Start.setText('')
            self.lineEdit_End.setText('')
            self.lineEdit_Completion_Progress.setText('')
            self.lineEdit_People.setText('')
            self.lineEdit_level.setText('')
            self.textEdit_Notes.setText('')

        elif self.actionName == 'Change' and stu is not None:
            self.label_Big_Title.setText('项目修改')
            self.pButtonOk.setText('修改')
            self.lineEdit_No.setText(stu['项目编号'])
            self.lineEdit_Type.setText(stu['项目类型'])
            self.lineEdit_Name.setText(stu['项目名称'])
            self.lineEdit_Start.setText(stu['开始日期'])
            self.lineEdit_End.setText(stu['结束日期'])
            self.lineEdit_Completion_Progress.setText(str(stu['完成进度']))
            self.lineEdit_People.setText(stu['负责人'])
            self.lineEdit_level.setText(stu['项目级别'])
            self.textEdit_Notes.setText(stu['备注'])






    def save2db(self):
        _Id = self.lineEdit_No.text().strip()
        _Type = self.lineEdit_Type.text().strip()
        _Name = self.lineEdit_Name.text().strip()
        _Start = self.lineEdit_Start.text().strip()
        _End = self.lineEdit_End.text().strip()
        _Progress = self.lineEdit_Completion_Progress.text().strip()
        _People = self.lineEdit_People.text().strip()
        _Level = self.lineEdit_level.text().strip()
        _Note = self.textEdit_Notes.toPlainText().strip()

        if self.actionName == 'Add':
            try:
                db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
                conn = sqlite3.connect(db_file)
                cur = conn.cursor()
                sql = """
                      INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark) 
                      VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
                      """
                stu = (_Id, _Type, _Name, _Start, _End, _Progress, _People, _Level, _Note)
                cur.execute(sql, stu)
                conn.commit()
                QMessageBox.information(self, '添加', '添加成功!')
                self.detailSiganl.emit(True)
            except Exception as e:
                conn.rollback()
                QMessageBox.critical(self, '错误', '添加失败!' + str(e))
                self.detailSiganl.emit(False)
            finally:
                self.close()
                cur.close()
                conn.close()
                cur = None
                conn = None

        elif self.actionName == 'Change':
            try:
                db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
                conn = sqlite3.connect(db_file)
                cur = conn.cursor()
                sql = """
                      update project set Type='{0}',Name='{1}',Start_date='{2}',End_date='{3}',
                      Progress={4},Manager='{5}',Level='{6}',Remark='{7}' where Id='{8}'
                      """.format(_Type, _Name, _Start, _End, _Progress, _People, _Level, _Note, _Id)
                cur.execute(sql)
                conn.commit()
                QMessageBox.information(self, '修改', '修改成功!')
                self.detailSiganl.emit(True)
            except Exception as e:
                conn.rollback()
                QMessageBox.critical(self, '错误', '修改失败!' + str(e))
                self.detailSiganl.emit(False)
            finally:
                self.close()
                cur.close()
                conn.close()
                cur = None
                conn = None





if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = DetailWindow()
    win_main.show()
    sys.exit(app.exec_())

8) 修改界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第31张图片

代码同上一个界面

9) 搜索界面----项目管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第32张图片

ui_search.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'search.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(1172, 733)
        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(1, 1, 1171, 731))
        self.verticalLayout = QVBoxLayout(self.layoutWidget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.pButtonShow = QPushButton(self.layoutWidget)
        self.pButtonShow.setObjectName(u"pButtonShow")

        self.horizontalLayout.addWidget(self.pButtonShow)

        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label = QLabel(self.layoutWidget)
        self.label.setObjectName(u"label")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(22)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)

        self.horizontalLayout.addWidget(self.label)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)


        self.verticalLayout.addLayout(self.horizontalLayout)

        self.verticalSpacer = QSpacerItem(20, 13, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout_4 = QHBoxLayout()
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.label_2 = QLabel(self.layoutWidget)
        self.label_2.setObjectName(u"label_2")
        font1 = QFont()
        font1.setFamily(u"Agency FB")
        font1.setPointSize(10)
        font1.setBold(True)
        font1.setWeight(75)
        self.label_2.setFont(font1)

        self.horizontalLayout_4.addWidget(self.label_2)

        self.horizontalSpacer_3 = QSpacerItem(13, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_3)

        self.lineEditsearch = QLineEdit(self.layoutWidget)
        self.lineEditsearch.setObjectName(u"lineEditsearch")

        self.horizontalLayout_4.addWidget(self.lineEditsearch)

        self.horizontalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_4)

        self.pButtonSearch = QPushButton(self.layoutWidget)
        self.pButtonSearch.setObjectName(u"pButtonSearch")

        self.horizontalLayout_4.addWidget(self.pButtonSearch)

        self.horizontalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_8)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_3 = QLabel(self.layoutWidget)
        self.label_3.setObjectName(u"label_3")

        self.horizontalLayout_2.addWidget(self.label_3)

        self.horizontalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_5)

        self.comboBox_Type = QComboBox(self.layoutWidget)
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.addItem("")
        self.comboBox_Type.setObjectName(u"comboBox_Type")

        self.horizontalLayout_2.addWidget(self.comboBox_Type)


        self.horizontalLayout_4.addLayout(self.horizontalLayout_2)

        self.horizontalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_7)

        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_4 = QLabel(self.layoutWidget)
        self.label_4.setObjectName(u"label_4")

        self.horizontalLayout_3.addWidget(self.label_4)

        self.horizontalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_6)

        self.comboBox_Level = QComboBox(self.layoutWidget)
        self.comboBox_Level.addItem("")
        self.comboBox_Level.addItem("")
        self.comboBox_Level.addItem("")
        self.comboBox_Level.addItem("")
        self.comboBox_Level.addItem("")
        self.comboBox_Level.setObjectName(u"comboBox_Level")

        self.horizontalLayout_3.addWidget(self.comboBox_Level)


        self.horizontalLayout_4.addLayout(self.horizontalLayout_3)


        self.verticalLayout.addLayout(self.horizontalLayout_4)

        self.verticalSpacer_2 = QSpacerItem(20, 13, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout.addItem(self.verticalSpacer_2)

        self.tableWidget = QTableWidget(self.layoutWidget)
        if (self.tableWidget.columnCount() < 9):
            self.tableWidget.setColumnCount(9)
        __qtablewidgetitem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
        __qtablewidgetitem1 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
        __qtablewidgetitem2 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
        __qtablewidgetitem3 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
        __qtablewidgetitem4 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
        __qtablewidgetitem5 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
        __qtablewidgetitem6 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
        __qtablewidgetitem7 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
        __qtablewidgetitem8 = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
        self.tableWidget.setObjectName(u"tableWidget")

        self.verticalLayout.addWidget(self.tableWidget)


        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u67e5\u8be2", None))
        self.pButtonShow.setText(QCoreApplication.translate("Dialog", u"\u663e\u793a\u9879\u76ee", None))
        self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u67e5\u8be2", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"\u8bf7\u8f93\u5165\u5173\u952e\u5b57\uff1a", None))
        self.pButtonSearch.setText(QCoreApplication.translate("Dialog", u"\u641c\u7d22", None))
#if QT_CONFIG(shortcut)
        self.pButtonSearch.setShortcut(QCoreApplication.translate("Dialog", u"Return", None))
#endif // QT_CONFIG(shortcut)
        self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7c7b\u578b", None))
        self.comboBox_Type.setItemText(0, QCoreApplication.translate("Dialog", u"\u6280\u672f\u7814\u53d1", None))
        self.comboBox_Type.setItemText(1, QCoreApplication.translate("Dialog", u"\u5e02\u573a\u8425\u9500", None))
        self.comboBox_Type.setItemText(2, QCoreApplication.translate("Dialog", u"\u751f\u4ea7\u5236\u9020", None))
        self.comboBox_Type.setItemText(3, QCoreApplication.translate("Dialog", u"\u4eba\u529b\u8d44\u6e90", None))
        self.comboBox_Type.setItemText(4, QCoreApplication.translate("Dialog", u"\u8d22\u52a1\u7ba1\u7406", None))
        self.comboBox_Type.setItemText(5, QCoreApplication.translate("Dialog", u"\u8f6f\u4ef6\u5f00\u53d1", None))
        self.comboBox_Type.setItemText(6, QCoreApplication.translate("Dialog", u"\u7f51\u7edc\u8fd0\u7ef4", None))
        self.comboBox_Type.setItemText(7, QCoreApplication.translate("Dialog", u"\u54a8\u8be2\u670d\u52a1", None))
        self.comboBox_Type.setItemText(8, QCoreApplication.translate("Dialog", u"\u5e02\u573a\u8c03\u7814", None))
        self.comboBox_Type.setItemText(9, QCoreApplication.translate("Dialog", u"\u57f9\u8bad\u670d\u52a1", None))
        self.comboBox_Type.setItemText(10, QCoreApplication.translate("Dialog", u"\u6d3b\u52a8\u7b56\u5212", None))
        self.comboBox_Type.setItemText(11, QCoreApplication.translate("Dialog", u"\u7269\u6d41\u914d\u9001", None))
        self.comboBox_Type.setItemText(12, QCoreApplication.translate("Dialog", u"\u8d22\u52a1\u5ba1\u8ba1", None))
        self.comboBox_Type.setItemText(13, QCoreApplication.translate("Dialog", u"\u73af\u5883\u76d1\u6d4b", None))
        self.comboBox_Type.setItemText(14, QCoreApplication.translate("Dialog", u"\u6cd5\u5f8b\u54a8\u8be2", None))

        self.comboBox_Type.setCurrentText(QCoreApplication.translate("Dialog", u"\u6280\u672f\u7814\u53d1", None))
        self.label_4.setText(QCoreApplication.translate("Dialog", u"\u7ea7\u522b", None))
        self.comboBox_Level.setItemText(0, QCoreApplication.translate("Dialog", u"A", None))
        self.comboBox_Level.setItemText(1, QCoreApplication.translate("Dialog", u"B", None))
        self.comboBox_Level.setItemText(2, QCoreApplication.translate("Dialog", u"C", None))
        self.comboBox_Level.setItemText(3, QCoreApplication.translate("Dialog", u"D", None))
        self.comboBox_Level.setItemText(4, QCoreApplication.translate("Dialog", u"E", None))

        ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
        ___qtablewidgetitem.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7f16\u53f7", None));
        ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
        ___qtablewidgetitem1.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7c7b\u578b", None));
        ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
        ___qtablewidgetitem2.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u540d\u79f0", None));
        ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
        ___qtablewidgetitem3.setText(QCoreApplication.translate("Dialog", u"\u5f00\u59cb\u65e5\u671f", None));
        ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
        ___qtablewidgetitem4.setText(QCoreApplication.translate("Dialog", u"\u7ed3\u675f\u65e5\u671f", None));
        ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
        ___qtablewidgetitem5.setText(QCoreApplication.translate("Dialog", u"\u5b8c\u6210\u8fdb\u5ea6", None));
        ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
        ___qtablewidgetitem6.setText(QCoreApplication.translate("Dialog", u"\u8d1f\u8d23\u4eba", None));
        ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
        ___qtablewidgetitem7.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ea7\u522b", None));
        ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
        ___qtablewidgetitem8.setText(QCoreApplication.translate("Dialog", u"\u5907\u6ce8", None));
    # retranslateUi

search.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
from PySide2.QtWidgets import QHeaderView
import sys, os, sqlite3
from PySide2.QtGui import QIcon
from main_body.ui_search import Ui_Dialog

class DetailWindow(QDialog, Ui_Dialog):
    detailSiganl = Signal(bool)

    def __init__(self):
        super(DetailWindow, self).__init__()
        self.setupUi(self)
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # 设置窗体图标
        app_icon = QIcon('选择.ico')
        self.setWindowIcon(app_icon)
        # self.setWindowFlags(
        #     Qt.WindowMinMaxButtonsHint |
        #     Qt.MSWindowsFixedSizeDialogHint
        # )

        self.actionName = None
        self.pButtonShow.clicked.connect(lambda: self.Show())
        self.pButtonSearch.clicked.connect(lambda: self.Search())
        self.comboBox_Type.currentIndexChanged.connect(lambda: self.Select())
        self.comboBox_Level.currentIndexChanged.connect(lambda: self.Select())

        self.lineEditsearch.setText('')           # 初始化搜索框
        # self.Show()
########################################################################################################################
# 关键字搜索
    def Search(self):
        _info = self.lineEditsearch.text().strip()
        try:
            db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                  select  Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark 
                  from project 
                 WHERE Id || Type || Name || Start_date || End_date || Progress || Manager || Level || Remark
                    LIKE ? ;
                  '''
            stu = ('%' + _info + '%',)
            cur.execute(sql, stu)
            conn.commit()

            self.tableWidget.clearContents()  # 清空表格内容
            self.tableWidget.setRowCount(0)  # 清空表格行数

            row_index = 0
            while True:  # 使用True代替stu,因为查询结果为None时stu值为False,不能作为循环条件
                stu = cur.fetchone()
                if stu is None:  # 如果查询结果为None,退出循环
                    break
                self.tableWidget.insertRow(row_index)
                for col_index, data in enumerate(stu):
                    TblItem = QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_index, col_index, TblItem)
                row_index += 1
            self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        except Exception as e:
            conn.rollback()
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None
########################################################################################################################
# 下拉框搜索
    def Select(self):
        current_type = self.comboBox_Type.currentText()
        current_level = self.comboBox_Level.currentText()
        try:
            db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()

            sql = '''
                  select  Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark 
                    from project 
                  WHERE Type = ?  AND Level = ?
                  '''
            stu = (current_type, current_level)
            cur.execute(sql, stu)
            conn.commit()

            self.tableWidget.clearContents()  # 清空表格内容
            self.tableWidget.setRowCount(0)  # 清空表格行数

            row_index = 0
            while True:  # 使用True代替stu,因为查询结果为None时stu值为False,不能作为循环条件
                stu = cur.fetchone()
                if stu is None:  # 如果查询结果为None,退出循环
                    break
                self.tableWidget.insertRow(row_index)
                for col_index, data in enumerate(stu):
                    TblItem = QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_index, col_index, TblItem)
                row_index += 1
            self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        except Exception as e:
            conn.rollback()

        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None
########################################################################################################################
# 显示项目
    def Show(self, actionGl=False):
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
        try:
            if actionGl == True:
                while self.tableWidget.rowCount() > 0:
                    self.tableWidget.removeRow(0)
                self.tableWidget.setRowCount(0)
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            sql = '''
                   select  Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
                   from project
                  '''
            cur.execute(sql)
            stu = cur.fetchone()
            row_index = 0
            while stu:
                self.tableWidget.insertRow(row_index)
                for colIdx, data in enumerate(stu):
                    TblItem = QTableWidgetItem(str(data))
                    self.tableWidget.setItem(row_index, colIdx, TblItem)
                stu = cur.fetchone()
                row_index = row_index + 1
            self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        except Exception as e:
            print(e)
        finally:
            cur.close()
            conn.close()
            cur = None
            conn = None
########################################################################################################################
if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = DetailWindow()
    win_main.show()
    sys.exit(app.exec_())

 10)导入界面----项目管理/用户界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第33张图片

导入界面为代码书写,添加到对应的类里面

 def Import(self):
        # 选择要导入的CSV文件
        csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        # 获取导入数据库路径
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')

        if not db_file:
            return

        try:
            # 连接数据库并创建表格
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            # cur.execute(
            #     'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')

            # 读取CSV文件并插入数据
            with open(csv_file, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    cur.execute(
                        'INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM project WHERE Id = ?)',
                        (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[0]))

            conn.commit()
            QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
        except Exception as e:
            conn.rollback()
            QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()

            # opened_file = QFileDialog().getOpenFileName(
        #     parent=self,
        #     caption='选择要导入的文件',
        #     dir=self.cur_dir,
        #     filter='CSV文件(*.csv);;文本文件(*.txt)'
        # )
        # if len(opened_file[0]) > 0:
        #     db_file = os.path.join(self.cur_dir, './data/all_projects.db')
        #     try:
        #         conn = sqlite3.connect(db_file)
        #         cur = conn.cursor()
        #         sql = '''
        #               INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark)
        #               VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
        #               '''
        #         data = open(opened_file[0], mode='rb').read()
        #         encoding = chardet.detect(data).get('encoding')
        #         with open(opened_file[0], mode='r', encoding=encoding) as f:
        #             csv_reader = csv.DictReader(f)
        #             rows = []
        #             for row in csv_reader:
        #                 rows.append((row['项目编号'], row['项目类型'], row['项目名称'],
        #                 row['开始日期'], row['结束日期'], row['完成进度'], row['负责人'],
        #                 row['项目级别'], row['备注']))
        #             cur.executemany(sql, rows)
        #         conn.commit()
        #         QMessageBox.information(self, '消息', '导入成功!')

                #self.db2screen()

            # except Exception as e:
            #     conn.rollback()
            #     QMessageBox.critical(self, '错误', '导入失败!' + str(e))
            # finally:
            #     cur.close()
            #     conn.close()
            #     cur = None
            #     conn = None

导出界面为代码书写,添加到对应的类里面

11) 导出界面----项目管理/用户界面

项目进度管理系统----Python下Pyside2模块(大一课设)_第34张图片

导出界面为代码书写,添加到对应的类里面

    def Export(self):
        # 选择要导出的数据库文件
        # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
        db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')

        if not db_file:
            return

        # 获取导出路径
        csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')

        if not csv_file:
            return

        try:
            # 连接数据库并查询数据
            conn = sqlite3.connect(db_file)
            cur = conn.cursor()
            cur.execute('SELECT * FROM project')
            data = cur.fetchall()

            # 将数据写入CSV文件
            with open(csv_file, 'w', newline='') as f:
                writer = csv.writer(f)
                writer.writerow([i[0] for i in cur.description])  # 写入表头
                for row in data:
                    writer.writerow(row)

            QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
        except Exception as e:
            QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
        finally:
            cur.close()
            conn.close()

12)添加界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第35张图片

ui_control_gl.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'control_gl.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        if not Dialog.objectName():
            Dialog.setObjectName(u"Dialog")
        Dialog.resize(928, 602)
        self.layoutWidget = QWidget(Dialog)
        self.layoutWidget.setObjectName(u"layoutWidget")
        self.layoutWidget.setGeometry(QRect(30, 40, 831, 341))
        self.verticalLayout_3 = QVBoxLayout(self.layoutWidget)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.label_big_title = QLabel(self.layoutWidget)
        self.label_big_title.setObjectName(u"label_big_title")
        font = QFont()
        font.setFamily(u"Agency FB")
        font.setPointSize(24)
        font.setBold(True)
        font.setWeight(75)
        self.label_big_title.setFont(font)

        self.horizontalLayout.addWidget(self.label_big_title)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer_2)


        self.verticalLayout_3.addLayout(self.horizontalLayout)

        self.verticalSpacer_3 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_3.addItem(self.verticalSpacer_3)

        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.horizontalLayout_9 = QHBoxLayout()
        self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
        self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_9.addItem(self.horizontalSpacer_10)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.label_2 = QLabel(self.layoutWidget)
        self.label_2.setObjectName(u"label_2")

        self.horizontalLayout_2.addWidget(self.label_2)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_3)

        self.user_type = QLineEdit(self.layoutWidget)
        self.user_type.setObjectName(u"user_type")

        self.horizontalLayout_2.addWidget(self.user_type)


        self.horizontalLayout_9.addLayout(self.horizontalLayout_2)

        self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_9.addItem(self.horizontalSpacer_11)


        self.verticalLayout_2.addLayout(self.horizontalLayout_9)

        self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_8 = QHBoxLayout()
        self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_3 = QLabel(self.layoutWidget)
        self.label_3.setObjectName(u"label_3")

        self.horizontalLayout_3.addWidget(self.label_3)

        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer_4)

        self.user_name = QLineEdit(self.layoutWidget)
        self.user_name.setObjectName(u"user_name")

        self.horizontalLayout_3.addWidget(self.user_name)


        self.horizontalLayout_8.addLayout(self.horizontalLayout_3)

        self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_8.addItem(self.horizontalSpacer_9)

        self.horizontalLayout_4 = QHBoxLayout()
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.label_4 = QLabel(self.layoutWidget)
        self.label_4.setObjectName(u"label_4")

        self.horizontalLayout_4.addWidget(self.label_4)

        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_5)

        self.user_password = QLineEdit(self.layoutWidget)
        self.user_password.setObjectName(u"user_password")

        self.horizontalLayout_4.addWidget(self.user_password)


        self.horizontalLayout_8.addLayout(self.horizontalLayout_4)


        self.verticalLayout.addLayout(self.horizontalLayout_8)

        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)

        self.verticalLayout.addItem(self.verticalSpacer)

        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.label_5 = QLabel(self.layoutWidget)
        self.label_5.setObjectName(u"label_5")

        self.horizontalLayout_5.addWidget(self.label_5)

        self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_6)

        self.user_times = QLineEdit(self.layoutWidget)
        self.user_times.setObjectName(u"user_times")

        self.horizontalLayout_5.addWidget(self.user_times)


        self.horizontalLayout_7.addLayout(self.horizontalLayout_5)

        self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_7.addItem(self.horizontalSpacer_8)

        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.label_6 = QLabel(self.layoutWidget)
        self.label_6.setObjectName(u"label_6")

        self.horizontalLayout_6.addWidget(self.label_6)

        self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_6.addItem(self.horizontalSpacer_7)

        self.user_last_time = QLineEdit(self.layoutWidget)
        self.user_last_time.setObjectName(u"user_last_time")

        self.horizontalLayout_6.addWidget(self.user_last_time)


        self.horizontalLayout_7.addLayout(self.horizontalLayout_6)


        self.verticalLayout.addLayout(self.horizontalLayout_7)


        self.verticalLayout_2.addLayout(self.verticalLayout)


        self.verticalLayout_3.addLayout(self.verticalLayout_2)

        self.layoutWidget1 = QWidget(Dialog)
        self.layoutWidget1.setObjectName(u"layoutWidget1")
        self.layoutWidget1.setGeometry(QRect(150, 500, 601, 30))
        self.horizontalLayout_10 = QHBoxLayout(self.layoutWidget1)
        self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
        self.horizontalLayout_10.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer_13 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_10.addItem(self.horizontalSpacer_13)

        self.pButtonOk = QPushButton(self.layoutWidget1)
        self.pButtonOk.setObjectName(u"pButtonOk")

        self.horizontalLayout_10.addWidget(self.pButtonOk)

        self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_10.addItem(self.horizontalSpacer_12)

        self.pButtonCancel = QPushButton(self.layoutWidget1)
        self.pButtonCancel.setObjectName(u"pButtonCancel")

        self.horizontalLayout_10.addWidget(self.pButtonCancel)

        self.horizontalSpacer_14 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_10.addItem(self.horizontalSpacer_14)

        self.widget = QWidget(Dialog)
        self.widget.setObjectName(u"widget")
        self.widget.setGeometry(QRect(170, 430, 671, 22))
        self.horizontalLayout_11 = QHBoxLayout(self.widget)
        self.horizontalLayout_11.setObjectName(u"horizontalLayout_11")
        self.horizontalLayout_11.setContentsMargins(0, 0, 0, 0)
        self.checkBoxAdd = QCheckBox(self.widget)
        self.checkBoxAdd.setObjectName(u"checkBoxAdd")

        self.horizontalLayout_11.addWidget(self.checkBoxAdd)

        self.horizontalSpacer_15 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_11.addItem(self.horizontalSpacer_15)

        self.checkBoxChange = QCheckBox(self.widget)
        self.checkBoxChange.setObjectName(u"checkBoxChange")

        self.horizontalLayout_11.addWidget(self.checkBoxChange)

        self.horizontalSpacer_16 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_11.addItem(self.horizontalSpacer_16)

        self.checkBoxDelete = QCheckBox(self.widget)
        self.checkBoxDelete.setObjectName(u"checkBoxDelete")

        self.horizontalLayout_11.addWidget(self.checkBoxDelete)

        self.horizontalSpacer_17 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)

        self.horizontalLayout_11.addItem(self.horizontalSpacer_17)

        self.checkBoxImport = QCheckBox(self.widget)
        self.checkBoxImport.setObjectName(u"checkBoxImport")

        self.horizontalLayout_11.addWidget(self.checkBoxImport)


        self.retranslateUi(Dialog)

        QMetaObject.connectSlotsByName(Dialog)
    # setupUi

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
        self.label_big_title.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
        self.label_2.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7c7b\u578b", None))
        self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d", None))
        self.label_4.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u5bc6\u7801", None))
        self.label_5.setText(QCoreApplication.translate("Dialog", u"\u767b\u5f55\u6b21\u6570", None))
        self.label_6.setText(QCoreApplication.translate("Dialog", u"\u4e0a\u6b21\u767b\u5f55\u65f6\u95f4", None))
        self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
        self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
        self.checkBoxAdd.setText(QCoreApplication.translate("Dialog", u"\u6dfb\u52a0", None))
        self.checkBoxChange.setText(QCoreApplication.translate("Dialog", u"\u4fee\u6539", None))
        self.checkBoxDelete.setText(QCoreApplication.translate("Dialog", u"\u5220\u9664", None))
        self.checkBoxImport.setText(QCoreApplication.translate("Dialog", u"\u5bfc\u5165", None))
    # retranslateUi

control_gl.py
from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
from PySide2.QtCore import Signal # 信号
from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
import sys, os, sqlite3
from main_body.ui_control_gl import Ui_Dialog
from PySide2.QtGui import QIcon

class DetailWindow(QDialog, Ui_Dialog):
    detailSiganl = Signal(bool)

    def __init__(self):
        super(DetailWindow, self).__init__()
        self.setupUi(self)
        self.cur_dir = os.path.dirname(os.path.abspath(__file__))

        # self.setWindowFlags(
        #     Qt.WindowMinMaxButtonsHint |
        #     Qt.MSWindowsFixedSizeDialogHint
        # )

        self.actionName = None

        self.pButtonOk.clicked.connect(lambda: self.save2db())
        self.pButtonCancel.clicked.connect(lambda: self.close())


        # 设置窗体图标
        app_icon = QIcon('修改.ico')
        self.setWindowIcon(app_icon)

    def handle_main_signal(self, mainActionName: str, stu: dict):
        self.actionName = mainActionName
        if self.actionName == 'Add':
            self.label_big_title.setText("用户添加")
            self.pButtonOk.setText('添加')
            self.user_type.setText('')
            self.user_name.setText('')
            self.user_password.setText('')
            self.user_times.setText('')
            self.user_last_time.setText('')
            self.checkBoxAdd.setChecked(True)
            self.checkBoxChange.setChecked(True)
            self.checkBoxDelete.setChecked(True)
            self.checkBoxImport.setChecked(True)


        elif self.actionName == 'Change' and stu is not None:
            self.label_big_title.setText('用户修改')
            self.pButtonOk.setText('修改')
            self.user_type.setText(stu['用户类型'])
            self.user_name.setText(stu['用户名'])
            self.user_password.setText(stu['用户密码'])
            self.user_times.setText(stu['登录次数'])
            self.user_last_time.setText(stu['上一次登录时间'])
            if stu['添加'] == 'T':
                self.checkBoxAdd.setChecked(True)
            else:
                self.checkBoxAdd.setChecked(True)
            if stu['添加'] == 'T':
                self.checkBoxChange.setChecked(True)
            else:
                self.checkBoxChange.setChecked(True)
            if stu['添加'] == 'T':
                self.checkBoxDelete.setChecked(True)
            else:
                self.checkBoxDelete.setChecked(True)
            if stu['添加'] == 'T':
                self.checkBoxImport.setChecked(True)
            else:
                self.checkBoxImport.setChecked(True)


    def save2db(self):
        _type = self.user_type.text().strip()
        _name = self.user_name.text().strip()
        _password = self.user_password.text().strip()
        _times = self.user_times.text().strip()
        _last = self.user_last_time.text().strip()
        if self.checkBoxAdd.isChecked():
            _add = 'T'
        else:
            _add = 'F'
        if self.checkBoxChange.isChecked():
            _change = 'T'
        else:
            _change = 'F'
        if self.checkBoxDelete.isChecked():
            _delete = 'T'
        else:
            _delete = 'F'
        if self.checkBoxImport.isChecked():
            _import = 'T'
        else:
            _import = 'F'

        if self.actionName == 'Add':
            try:
                db_file = os.path.join(self.cur_dir, './data/user_password.db')
                conn = sqlite3.connect(db_file)
                cur = conn.cursor()
                sql = """
                      INSERT INTO all_user (user_type,username,password,login_times,last_login,add_right,change_right,
                    import_right,export_right) 
                      VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
                      """
                stu = (_type, _name, _password, _times, _last, _add, _change, _import,_delete )
                cur.execute(sql, stu)
                conn.commit()
                QMessageBox.information(self, '添加', '添加成功!')
                self.detailSiganl.emit(True)
            except Exception as e:
                conn.rollback()
                QMessageBox.critical(self, '错误', '添加失败!' + str(e))
                print(e)
                self.detailSiganl.emit(False)
            finally:
                self.close()
                cur.close()
                conn.close()
                cur = None
                conn = None

        elif self.actionName == 'Change':
            try:
                db_file = os.path.join(self.cur_dir, './data/user_password.db')
                conn = sqlite3.connect(db_file)
                cur = conn.cursor()
                sql = """
                      update all_user set user_type='{0}',password='{1}',login_times='{2}', last_login='{3}',add_right='{4}',
                      change_right='{5}',import_right='{6}',export_right='{7}'
                     where username='{8}'
                      """.format(_type, _password, _times, _last, _add, _change, _import,_delete, _name)
                cur.execute(sql)
                conn.commit()
                QMessageBox.information(self, '修改', '修改成功!')
                self.detailSiganl.emit(True)
            except Exception as e:
                conn.rollback()
                QMessageBox.critical(self, '错误', '修改失败!' + str(e))
                print(e)
                self.detailSiganl.emit(False)
            finally:
                self.close()
                cur.close()
                conn.close()
                cur = None
                conn = None


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win_main = DetailWindow()
    win_main.show()
    sys.exit(app.exec_())

13)修改界面----用户管理

 项目进度管理系统----Python下Pyside2模块(大一课设)_第36张图片

同上一界面代码

14)搜索界面----用户管理

项目进度管理系统----Python下Pyside2模块(大一课设)_第37张图片

项目进度管理系统----Python下Pyside2模块(大一课设)_第38张图片

该部分代码使用了tkinter模块,可以不用的!

代码组成有点乱,想要的私信!

你可能感兴趣的:(python,开发语言)