当前位置:   article > 正文

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

pip install pyside2

目录

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

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

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

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

五、制作过程  

六、主体代码

一、安装Pycharm和Anaconda              

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

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

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

“Win+R”打开cmd命令行

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

2)下载PySide2模块

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

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

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

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

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

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

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

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

2)管理员登录界面

3)用户登录界面

4)管理员选择模块界面

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

 

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

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

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

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

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

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

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

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

 

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

 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模块的环境,不然会报错!)

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

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

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

基础设计教程请看:

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

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

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

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

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

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

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

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

六、主体代码

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

ui_untitled_login_select.py(这个是图示界面ui文件通过pyuic转换而来的.py文件)
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'untitled_login_select.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_MainWindow(object):
  14. def setupUi(self, MainWindow):
  15. if not MainWindow.objectName():
  16. MainWindow.setObjectName(u"MainWindow")
  17. MainWindow.resize(800, 600)
  18. icon = QIcon()
  19. icon.addFile(u"../\u9009\u62e9.ico", QSize(), QIcon.Normal, QIcon.Off)
  20. MainWindow.setWindowIcon(icon)
  21. self.actionTlbExit = QAction(MainWindow)
  22. self.actionTlbExit.setObjectName(u"actionTlbExit")
  23. self.centralwidget = QWidget(MainWindow)
  24. self.centralwidget.setObjectName(u"centralwidget")
  25. self.layoutWidget = QWidget(self.centralwidget)
  26. self.layoutWidget.setObjectName(u"layoutWidget")
  27. self.layoutWidget.setGeometry(QRect(-1, 30, 801, 391))
  28. self.verticalLayout = QVBoxLayout(self.layoutWidget)
  29. self.verticalLayout.setObjectName(u"verticalLayout")
  30. self.verticalLayout.setContentsMargins(0, 0, 0, 0)
  31. self.horizontalLayout = QHBoxLayout()
  32. self.horizontalLayout.setObjectName(u"horizontalLayout")
  33. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  34. self.horizontalLayout.addItem(self.horizontalSpacer)
  35. self.label = QLabel(self.layoutWidget)
  36. self.label.setObjectName(u"label")
  37. font = QFont()
  38. font.setFamily(u"Agency FB")
  39. font.setPointSize(36)
  40. self.label.setFont(font)
  41. self.horizontalLayout.addWidget(self.label)
  42. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  43. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  44. self.verticalLayout.addLayout(self.horizontalLayout)
  45. self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  46. self.verticalLayout.addItem(self.verticalSpacer)
  47. self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  48. self.verticalLayout.addItem(self.verticalSpacer_2)
  49. self.horizontalLayout_2 = QHBoxLayout()
  50. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  51. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  52. self.horizontalLayout_2.addItem(self.horizontalSpacer_4)
  53. self.pButtonadministrator = QPushButton(self.layoutWidget)
  54. self.pButtonadministrator.setObjectName(u"pButtonadministrator")
  55. font1 = QFont()
  56. font1.setFamily(u"Agency FB")
  57. font1.setPointSize(24)
  58. self.pButtonadministrator.setFont(font1)
  59. self.horizontalLayout_2.addWidget(self.pButtonadministrator)
  60. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  61. self.horizontalLayout_2.addItem(self.horizontalSpacer_3)
  62. self.pButtonuser = QPushButton(self.layoutWidget)
  63. self.pButtonuser.setObjectName(u"pButtonuser")
  64. font2 = QFont()
  65. font2.setFamily(u"Agency FB")
  66. font2.setPointSize(26)
  67. self.pButtonuser.setFont(font2)
  68. self.horizontalLayout_2.addWidget(self.pButtonuser)
  69. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  70. self.horizontalLayout_2.addItem(self.horizontalSpacer_5)
  71. self.verticalLayout.addLayout(self.horizontalLayout_2)
  72. self.label_3 = QLabel(self.centralwidget)
  73. self.label_3.setObjectName(u"label_3")
  74. self.label_3.setGeometry(QRect(0, -6, 801, 531))
  75. self.label_3.setPixmap(QPixmap(u":/\u80cc\u666f\u56fe1.png"))
  76. self.label_3.setScaledContents(True)
  77. MainWindow.setCentralWidget(self.centralwidget)
  78. self.label_3.raise_()
  79. self.layoutWidget.raise_()
  80. self.menubar = QMenuBar(MainWindow)
  81. self.menubar.setObjectName(u"menubar")
  82. self.menubar.setGeometry(QRect(0, 0, 800, 26))
  83. MainWindow.setMenuBar(self.menubar)
  84. self.statusbar = QStatusBar(MainWindow)
  85. self.statusbar.setObjectName(u"statusbar")
  86. MainWindow.setStatusBar(self.statusbar)
  87. self.toolBar = QToolBar(MainWindow)
  88. self.toolBar.setObjectName(u"toolBar")
  89. MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
  90. self.toolBar.addAction(self.actionTlbExit)
  91. self.retranslateUi(MainWindow)
  92. QMetaObject.connectSlotsByName(MainWindow)
  93. # setupUi
  94. def retranslateUi(self, MainWindow):
  95. MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u767b\u5f55\u754c\u9762", None))
  96. self.actionTlbExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
  97. self.label.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
  98. self.pButtonadministrator.setText(QCoreApplication.translate("MainWindow", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
  99. self.pButtonuser.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u767b\u5f55", None))
  100. self.label_3.setText("")
  101. self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
  102. # retranslateUi

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

  1. from PySide2.QtWidgets import *
  2. from PySide2.QtCore import *
  3. from ui.ui_untitled_login_select import Ui_MainWindow
  4. from gly_login import GlyWindow as Gly
  5. from yh_login import YhWindow as Yh
  6. import os, sys
  7. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  8. class LoginWindow(QMainWindow, Ui_MainWindow):
  9. mainSingnal = Signal(str, dict)
  10. # 初始化窗体
  11. def __init__(self):
  12. # 初始化基类
  13. super(LoginWindow, self).__init__()
  14. # 初始化当前窗体及窗体中的所有控件
  15. self.setupUi(self)
  16. # 记录当前应用所在路径
  17. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  18. # 设置窗体图标
  19. app_icon = QIcon('选择.ico')
  20. self.setWindowIcon(app_icon)
  21. # 绑定信号与槽,实现按纽单击调用对应的槽函数(选择登录)
  22. # 声明子窗体(一个管理员登录,一个普通用户登录)
  23. self.gly_dl = None
  24. self.yh_dl = None
  25. self.pButtonadministrator.clicked.connect(lambda: self.gly())
  26. self.pButtonuser.clicked.connect(lambda: self.yh())
  27. # 绑定菜单栏(左上角的'退出系统'按钮)
  28. self.actionTlbExit.triggered.connect(lambda: self.Close())
  29. def gly(self):
  30. # 记录当前动作
  31. self.stuAction = 'gly_dl'
  32. # 创建子窗体
  33. self.gly_dl = Gly()
  34. # 设置该子窗体的对话框状态为“模态对话框”
  35. self.gly_dl.setModal(True)
  36. # 显示子窗体
  37. self.gly_dl.show()
  38. # # 信号与槽绑定
  39. # # 主窗体向子窗体发送数据(不能使用Lambda表达式,仅为窗体名.函数名)
  40. # self.mainSingnal.connect(self.gly_dl.handle_main_signal)
  41. # # 主窗体发射信号给子窗体
  42. # self.mainSignal.emit(self.stuAction)
  43. def yh(self):
  44. # 记录当前动作
  45. self.stuAction = 'yh_dl'
  46. # 创建子窗体()
  47. self.yh_dl = Yh()
  48. # 设置该子窗体的对话框状态为“模态对话框”
  49. self.yh_dl.setModal(True)
  50. # 显示子窗体
  51. self.yh_dl.show()
  52. # # 信号与槽绑定
  53. # # 主窗体向子窗体发送数据(不能使用Lambda表达式,仅为窗体名.函数名)
  54. # self.mainSingnal.connect(self.yh_dl.handle_main_signal)
  55. # # 主窗体发射信号给子窗体
  56. # self.mainSignal.emit(self.stuAction, None)
  57. def Close(self):
  58. reply = QMessageBox.question(self, '关闭提示', "是否要退出系统?",
  59. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  60. if reply == QMessageBox.Yes:
  61. self.close()
  62. elif reply == QMessageBox.No:
  63. return
  64. if __name__ == '__main__':
  65. app = QApplication(sys.argv)
  66. win_main = LoginWindow()
  67. win_main.show()
  68. sys.exit(app.exec_())

2)管理员登录界面

ui_untitled_gly_dl.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'untitled_gly_dl.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_Dialog(object):
  14. def setupUi(self, Dialog):
  15. if not Dialog.objectName():
  16. Dialog.setObjectName(u"Dialog")
  17. Dialog.resize(814, 461)
  18. self.layoutWidget = QWidget(Dialog)
  19. self.layoutWidget.setObjectName(u"layoutWidget")
  20. self.layoutWidget.setGeometry(QRect(0, 120, 811, 54))
  21. self.horizontalLayout_5 = QHBoxLayout(self.layoutWidget)
  22. self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
  23. self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
  24. self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  25. self.horizontalLayout_5.addItem(self.horizontalSpacer_8)
  26. self.label_Login = QLabel(self.layoutWidget)
  27. self.label_Login.setObjectName(u"label_Login")
  28. font = QFont()
  29. font.setFamily(u"Arial Black")
  30. font.setPointSize(22)
  31. font.setBold(True)
  32. font.setWeight(75)
  33. self.label_Login.setFont(font)
  34. self.horizontalLayout_5.addWidget(self.label_Login)
  35. self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  36. self.horizontalLayout_5.addItem(self.horizontalSpacer_9)
  37. self.layoutWidget_2 = QWidget(Dialog)
  38. self.layoutWidget_2.setObjectName(u"layoutWidget_2")
  39. self.layoutWidget_2.setGeometry(QRect(0, 420, 811, 33))
  40. self.horizontalLayout = QHBoxLayout(self.layoutWidget_2)
  41. self.horizontalLayout.setObjectName(u"horizontalLayout")
  42. self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
  43. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  44. self.horizontalLayout.addItem(self.horizontalSpacer)
  45. self.pButtonOk = QPushButton(self.layoutWidget_2)
  46. self.pButtonOk.setObjectName(u"pButtonOk")
  47. font1 = QFont()
  48. font1.setFamily(u"Agency FB")
  49. font1.setPointSize(10)
  50. self.pButtonOk.setFont(font1)
  51. self.horizontalLayout.addWidget(self.pButtonOk)
  52. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  53. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  54. self.pButtonCancel = QPushButton(self.layoutWidget_2)
  55. self.pButtonCancel.setObjectName(u"pButtonCancel")
  56. self.pButtonCancel.setFont(font1)
  57. self.horizontalLayout.addWidget(self.pButtonCancel)
  58. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  59. self.horizontalLayout.addItem(self.horizontalSpacer_3)
  60. self.layoutWidget_3 = QWidget(Dialog)
  61. self.layoutWidget_3.setObjectName(u"layoutWidget_3")
  62. self.layoutWidget_3.setGeometry(QRect(0, 0, 811, 75))
  63. self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_3)
  64. self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
  65. self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
  66. self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  67. self.horizontalLayout_4.addItem(self.horizontalSpacer_6)
  68. self.label = QLabel(self.layoutWidget_3)
  69. self.label.setObjectName(u"label")
  70. font2 = QFont()
  71. font2.setFamily(u"Agency FB")
  72. font2.setPointSize(36)
  73. self.label.setFont(font2)
  74. self.horizontalLayout_4.addWidget(self.label)
  75. self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  76. self.horizontalLayout_4.addItem(self.horizontalSpacer_7)
  77. self.layoutWidget_4 = QWidget(Dialog)
  78. self.layoutWidget_4.setObjectName(u"layoutWidget_4")
  79. self.layoutWidget_4.setGeometry(QRect(0, 230, 811, 98))
  80. self.horizontalLayout_6 = QHBoxLayout(self.layoutWidget_4)
  81. self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
  82. self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
  83. self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  84. self.horizontalLayout_6.addItem(self.horizontalSpacer_10)
  85. self.verticalLayout = QVBoxLayout()
  86. self.verticalLayout.setObjectName(u"verticalLayout")
  87. self.horizontalLayout_2 = QHBoxLayout()
  88. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  89. self.label_3 = QLabel(self.layoutWidget_4)
  90. self.label_3.setObjectName(u"label_3")
  91. font3 = QFont()
  92. font3.setFamily(u"Agency FB")
  93. font3.setPointSize(14)
  94. self.label_3.setFont(font3)
  95. self.horizontalLayout_2.addWidget(self.label_3)
  96. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  97. self.horizontalLayout_2.addItem(self.horizontalSpacer_4)
  98. self.lineEdit_gly_User = QLineEdit(self.layoutWidget_4)
  99. self.lineEdit_gly_User.setObjectName(u"lineEdit_gly_User")
  100. self.horizontalLayout_2.addWidget(self.lineEdit_gly_User)
  101. self.verticalLayout.addLayout(self.horizontalLayout_2)
  102. self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  103. self.verticalLayout.addItem(self.verticalSpacer)
  104. self.horizontalLayout_3 = QHBoxLayout()
  105. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  106. self.label_4 = QLabel(self.layoutWidget_4)
  107. self.label_4.setObjectName(u"label_4")
  108. self.label_4.setFont(font3)
  109. self.horizontalLayout_3.addWidget(self.label_4)
  110. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  111. self.horizontalLayout_3.addItem(self.horizontalSpacer_5)
  112. self.lineEdit_gly_Password = QLineEdit(self.layoutWidget_4)
  113. self.lineEdit_gly_Password.setObjectName(u"lineEdit_gly_Password")
  114. self.horizontalLayout_3.addWidget(self.lineEdit_gly_Password)
  115. self.verticalLayout.addLayout(self.horizontalLayout_3)
  116. self.horizontalLayout_6.addLayout(self.verticalLayout)
  117. self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  118. self.horizontalLayout_6.addItem(self.horizontalSpacer_11)
  119. self.label_5 = QLabel(Dialog)
  120. self.label_5.setObjectName(u"label_5")
  121. self.label_5.setGeometry(QRect(1, 4, 811, 461))
  122. self.label_5.setPixmap(QPixmap(u":/b2.png"))
  123. self.label_5.setScaledContents(True)
  124. self.label_5.raise_()
  125. self.layoutWidget.raise_()
  126. self.layoutWidget_2.raise_()
  127. self.layoutWidget_3.raise_()
  128. self.layoutWidget_4.raise_()
  129. self.retranslateUi(Dialog)
  130. QMetaObject.connectSlotsByName(Dialog)
  131. # setupUi
  132. def retranslateUi(self, Dialog):
  133. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
  134. self.label_Login.setText(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u767b\u5f55", None))
  135. self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
  136. self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
  137. self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
  138. self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d\uff1a", None))
  139. self.lineEdit_gly_User.setText("")
  140. self.label_4.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801\uff1a", None))
  141. self.label_5.setText("")
  142. # retranslateUi
gly_login.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. from PySide2.QtWidgets import QLineEdit, QPushButton
  5. import sqlite3
  6. import sys, os
  7. from ui.ui_untitled_gly_dl import Ui_Dialog
  8. from gly_select import GsWindow
  9. class GlyWindow (QDialog , Ui_Dialog):
  10. # 定义一个信号,从子窗体向主窗体返回信号
  11. MainSiganl = Signal(bool)
  12. # 子窗体初始化、声明信号、设置围标等
  13. #############################################################################
  14. def __init__(self):
  15. super(GlyWindow, self).__init__()
  16. self.setupUi(self)
  17. # 记录当前应用程序路径
  18. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  19. # 设置窗体图标
  20. app_icon = QIcon('登录配置.ico')
  21. self.setWindowIcon(app_icon)
  22. # 默认操作
  23. self.actionName = None
  24. # 按纽绑定
  25. self.pButtonCancel.clicked.connect(lambda: self.close())
  26. self.pButtonOk.clicked.connect(lambda: self.check_login_info())
  27. def check_login_info(self):
  28. conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
  29. c = conn.cursor()
  30. user = self.lineEdit_gly_User.text()
  31. password = self.lineEdit_gly_Password.text()
  32. sql = f"select * from all_user where user_type='管理员' and username='{user}' and password='{password}'"
  33. cursor = c.execute(sql)
  34. result = cursor.fetchone()
  35. if result is None:
  36. QMessageBox.warning(self, '警告', '用户名或密码错误或非管理员用户!')
  37. self.lineEdit_gly_Password.clear()
  38. self.lineEdit_gly_Password.setFocus()
  39. else:
  40. self.MainSiganl.emit(True)
  41. main_window = GsWindow()
  42. main_window.show()
  43. self.accept()
  44. conn.close()
  45. if __name__ == '__main__':
  46. app = QApplication(sys.argv)
  47. detail_win = GlyWindow()
  48. detail_win.show()
  49. sys.exit(app.exec_())

3)用户登录界面

ui_untitled_yh_dl.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'untitled_yh_dl.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_Dialog(object):
  14. def setupUi(self, Dialog):
  15. if not Dialog.objectName():
  16. Dialog.setObjectName(u"Dialog")
  17. Dialog.resize(813, 454)
  18. self.layoutWidget_3 = QWidget(Dialog)
  19. self.layoutWidget_3.setObjectName(u"layoutWidget_3")
  20. self.layoutWidget_3.setGeometry(QRect(0, 0, 811, 75))
  21. self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_3)
  22. self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
  23. self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
  24. self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  25. self.horizontalLayout_4.addItem(self.horizontalSpacer_6)
  26. self.label = QLabel(self.layoutWidget_3)
  27. self.label.setObjectName(u"label")
  28. font = QFont()
  29. font.setFamily(u"Agency FB")
  30. font.setPointSize(36)
  31. self.label.setFont(font)
  32. self.horizontalLayout_4.addWidget(self.label)
  33. self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  34. self.horizontalLayout_4.addItem(self.horizontalSpacer_7)
  35. self.layoutWidget = QWidget(Dialog)
  36. self.layoutWidget.setObjectName(u"layoutWidget")
  37. self.layoutWidget.setGeometry(QRect(0, 120, 811, 54))
  38. self.horizontalLayout_5 = QHBoxLayout(self.layoutWidget)
  39. self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
  40. self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
  41. self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  42. self.horizontalLayout_5.addItem(self.horizontalSpacer_8)
  43. self.label_Login = QLabel(self.layoutWidget)
  44. self.label_Login.setObjectName(u"label_Login")
  45. font1 = QFont()
  46. font1.setFamily(u"Arial Black")
  47. font1.setPointSize(22)
  48. font1.setBold(True)
  49. font1.setWeight(75)
  50. self.label_Login.setFont(font1)
  51. self.horizontalLayout_5.addWidget(self.label_Login)
  52. self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  53. self.horizontalLayout_5.addItem(self.horizontalSpacer_9)
  54. self.layoutWidget_4 = QWidget(Dialog)
  55. self.layoutWidget_4.setObjectName(u"layoutWidget_4")
  56. self.layoutWidget_4.setGeometry(QRect(0, 230, 811, 98))
  57. self.horizontalLayout_6 = QHBoxLayout(self.layoutWidget_4)
  58. self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
  59. self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
  60. self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  61. self.horizontalLayout_6.addItem(self.horizontalSpacer_10)
  62. self.verticalLayout = QVBoxLayout()
  63. self.verticalLayout.setObjectName(u"verticalLayout")
  64. self.horizontalLayout_2 = QHBoxLayout()
  65. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  66. self.label_3 = QLabel(self.layoutWidget_4)
  67. self.label_3.setObjectName(u"label_3")
  68. font2 = QFont()
  69. font2.setFamily(u"Agency FB")
  70. font2.setPointSize(14)
  71. self.label_3.setFont(font2)
  72. self.horizontalLayout_2.addWidget(self.label_3)
  73. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  74. self.horizontalLayout_2.addItem(self.horizontalSpacer_4)
  75. self.lineEdit_yh_User = QLineEdit(self.layoutWidget_4)
  76. self.lineEdit_yh_User.setObjectName(u"lineEdit_yh_User")
  77. self.horizontalLayout_2.addWidget(self.lineEdit_yh_User)
  78. self.verticalLayout.addLayout(self.horizontalLayout_2)
  79. self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  80. self.verticalLayout.addItem(self.verticalSpacer)
  81. self.horizontalLayout_3 = QHBoxLayout()
  82. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  83. self.label_4 = QLabel(self.layoutWidget_4)
  84. self.label_4.setObjectName(u"label_4")
  85. self.label_4.setFont(font2)
  86. self.horizontalLayout_3.addWidget(self.label_4)
  87. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  88. self.horizontalLayout_3.addItem(self.horizontalSpacer_5)
  89. self.lineEdit_yh_Password = QLineEdit(self.layoutWidget_4)
  90. self.lineEdit_yh_Password.setObjectName(u"lineEdit_yh_Password")
  91. self.horizontalLayout_3.addWidget(self.lineEdit_yh_Password)
  92. self.verticalLayout.addLayout(self.horizontalLayout_3)
  93. self.horizontalLayout_6.addLayout(self.verticalLayout)
  94. self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  95. self.horizontalLayout_6.addItem(self.horizontalSpacer_11)
  96. self.layoutWidget_2 = QWidget(Dialog)
  97. self.layoutWidget_2.setObjectName(u"layoutWidget_2")
  98. self.layoutWidget_2.setGeometry(QRect(0, 420, 811, 33))
  99. self.horizontalLayout = QHBoxLayout(self.layoutWidget_2)
  100. self.horizontalLayout.setObjectName(u"horizontalLayout")
  101. self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
  102. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  103. self.horizontalLayout.addItem(self.horizontalSpacer)
  104. self.pButtonOk = QPushButton(self.layoutWidget_2)
  105. self.pButtonOk.setObjectName(u"pButtonOk")
  106. font3 = QFont()
  107. font3.setFamily(u"Agency FB")
  108. font3.setPointSize(10)
  109. self.pButtonOk.setFont(font3)
  110. self.horizontalLayout.addWidget(self.pButtonOk)
  111. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  112. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  113. self.pButtonCancel = QPushButton(self.layoutWidget_2)
  114. self.pButtonCancel.setObjectName(u"pButtonCancel")
  115. self.pButtonCancel.setFont(font3)
  116. self.horizontalLayout.addWidget(self.pButtonCancel)
  117. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  118. self.horizontalLayout.addItem(self.horizontalSpacer_3)
  119. self.label_5 = QLabel(Dialog)
  120. self.label_5.setObjectName(u"label_5")
  121. self.label_5.setGeometry(QRect(1, -6, 811, 461))
  122. self.label_5.setPixmap(QPixmap(u":/b2.png"))
  123. self.label_5.setScaledContents(True)
  124. self.label_5.raise_()
  125. self.layoutWidget_3.raise_()
  126. self.layoutWidget.raise_()
  127. self.layoutWidget_4.raise_()
  128. self.layoutWidget_2.raise_()
  129. self.retranslateUi(Dialog)
  130. QMetaObject.connectSlotsByName(Dialog)
  131. # setupUi
  132. def retranslateUi(self, Dialog):
  133. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
  134. self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406\u7cfb\u7edf", None))
  135. self.label_Login.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u767b\u5f55", None))
  136. self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d\uff1a", None))
  137. self.lineEdit_yh_User.setText("")
  138. self.label_4.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801\uff1a", None))
  139. self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
  140. self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
  141. self.label_5.setText("")
  142. # retranslateUi
yh_login.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. import sqlite3
  5. import sys, os
  6. from ui.ui_untitled_yh_dl import Ui_Dialog
  7. from main import MainWindow
  8. class YhWindow(QDialog, Ui_Dialog):
  9. # 定义一个信号,从子窗体向主窗体返回信号
  10. MainSiganl = Signal(bool)
  11. UserSignal = Signal(str)
  12. #################################
  13. # 子窗体初始化、声明信号、设置围标等
  14. def __init__(self):
  15. super(YhWindow, self).__init__()
  16. self.setupUi(self)
  17. self.setWindowTitle("用户登录")
  18. # 记录当前应用程序路径
  19. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  20. # 设置窗体图标
  21. app_icon = QIcon('登录配置.ico')
  22. self.setWindowIcon(app_icon)
  23. # 默认操作
  24. self.actionName = None
  25. # 按纽绑定
  26. self.pButtonCancel.clicked.connect(lambda: self.close())
  27. self.pButtonOk.clicked.connect(lambda: self.check_login_info())
  28. self.stuAction = None
  29. self.main_win = None
  30. def check_login_info(self):
  31. conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
  32. c = conn.cursor()
  33. user = self.lineEdit_yh_User.text()
  34. password = self.lineEdit_yh_Password.text()
  35. # print(user)
  36. # print(type(user))
  37. sql = f"select * from all_user where user_type='普通用户' and username='{user}' and password='{password}'"
  38. cursor = c.execute(sql)
  39. result = cursor.fetchone()
  40. if result is None:
  41. QMessageBox.warning(self, '警告', '用户名或密码错误或为管理员用户!')
  42. self.lineEdit_yh_Password.clear()
  43. self.lineEdit_yh_Password.setFocus()
  44. else:
  45. self.MainSiganl.emit(True)
  46. self.main_win = MainWindow()
  47. self.main_win.show()
  48. self.accept()
  49. self.stuAction = user
  50. self.UserSignal.connect(self.main_win.yh_login_Signal)
  51. self.UserSignal.emit(self.stuAction)
  52. conn.close()
  53. if __name__ == '__main__':
  54. app = QApplication(sys.argv)
  55. detail_win = YhWindow()
  56. detail_win.show()
  57. sys.exit(app.exec_())

4)管理员选择模块界面

ui_gly_select.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'gly_select.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_Dialog(object):
  14. def setupUi(self, Dialog):
  15. if not Dialog.objectName():
  16. Dialog.setObjectName(u"Dialog")
  17. Dialog.resize(940, 564)
  18. self.layoutWidget = QWidget(Dialog)
  19. self.layoutWidget.setObjectName(u"layoutWidget")
  20. self.layoutWidget.setGeometry(QRect(0, 60, 941, 461))
  21. self.verticalLayout_2 = QVBoxLayout(self.layoutWidget)
  22. self.verticalLayout_2.setObjectName(u"verticalLayout_2")
  23. self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
  24. self.horizontalLayout = QHBoxLayout()
  25. self.horizontalLayout.setObjectName(u"horizontalLayout")
  26. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  27. self.horizontalLayout.addItem(self.horizontalSpacer)
  28. self.label = QLabel(self.layoutWidget)
  29. self.label.setObjectName(u"label")
  30. font = QFont()
  31. font.setFamily(u"Agency FB")
  32. font.setPointSize(24)
  33. font.setBold(True)
  34. font.setWeight(75)
  35. self.label.setFont(font)
  36. self.horizontalLayout.addWidget(self.label)
  37. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  38. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  39. self.verticalLayout_2.addLayout(self.horizontalLayout)
  40. self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)
  41. self.verticalLayout_2.addItem(self.verticalSpacer_2)
  42. self.horizontalLayout_3 = QHBoxLayout()
  43. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  44. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  45. self.horizontalLayout_3.addItem(self.horizontalSpacer_4)
  46. self.horizontalLayout_2 = QHBoxLayout()
  47. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  48. self.label_2 = QLabel(self.layoutWidget)
  49. self.label_2.setObjectName(u"label_2")
  50. font1 = QFont()
  51. font1.setFamily(u"Agency FB")
  52. font1.setPointSize(22)
  53. font1.setBold(True)
  54. font1.setWeight(75)
  55. self.label_2.setFont(font1)
  56. self.horizontalLayout_2.addWidget(self.label_2)
  57. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  58. self.horizontalLayout_2.addItem(self.horizontalSpacer_3)
  59. self.verticalLayout = QVBoxLayout()
  60. self.verticalLayout.setObjectName(u"verticalLayout")
  61. self.pButtonuser = QPushButton(self.layoutWidget)
  62. self.pButtonuser.setObjectName(u"pButtonuser")
  63. font2 = QFont()
  64. font2.setFamily(u"Bahnschrift SemiBold Condensed")
  65. font2.setPointSize(22)
  66. font2.setBold(True)
  67. font2.setWeight(75)
  68. self.pButtonuser.setFont(font2)
  69. self.verticalLayout.addWidget(self.pButtonuser)
  70. self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  71. self.verticalLayout.addItem(self.verticalSpacer)
  72. self.pButtonproject = QPushButton(self.layoutWidget)
  73. self.pButtonproject.setObjectName(u"pButtonproject")
  74. font3 = QFont()
  75. font3.setFamily(u"Bahnschrift Condensed")
  76. font3.setPointSize(24)
  77. font3.setBold(True)
  78. font3.setWeight(75)
  79. self.pButtonproject.setFont(font3)
  80. self.verticalLayout.addWidget(self.pButtonproject)
  81. self.horizontalLayout_2.addLayout(self.verticalLayout)
  82. self.horizontalLayout_3.addLayout(self.horizontalLayout_2)
  83. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  84. self.horizontalLayout_3.addItem(self.horizontalSpacer_5)
  85. self.verticalLayout_2.addLayout(self.horizontalLayout_3)
  86. self.tableWidget = QTableWidget(Dialog)
  87. self.tableWidget.setObjectName(u"tableWidget")
  88. self.tableWidget.setGeometry(QRect(0, 0, 941, 561))
  89. self.tableWidget.setStyleSheet(u"background-image: url(:/b1.png);\n"
  90. " background-size: cover;")
  91. self.tableWidget.raise_()
  92. self.layoutWidget.raise_()
  93. self.retranslateUi(Dialog)
  94. QMetaObject.connectSlotsByName(Dialog)
  95. # setupUi
  96. def retranslateUi(self, Dialog):
  97. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u64cd\u4f5c", None))
  98. self.label.setText(QCoreApplication.translate("Dialog", u"\u7ba1\u7406\u5458\u64cd\u4f5c", None))
  99. self.label_2.setText(QCoreApplication.translate("Dialog", u"\u8bf7\u9009\u62e9\uff1a", None))
  100. self.pButtonuser.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
  101. self.pButtonproject.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
  102. # retranslateUi
ui_gly_select.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. from PySide2.QtWidgets import QLineEdit, QPushButton
  5. import sqlite3
  6. import sys, os
  7. from main_body.ui_gly_select import Ui_Dialog
  8. from main import MainWindow as projectwindow
  9. from control_user import MainWindow as userwindow
  10. from PyQt5.QtWidgets import QApplication, QWidget
  11. class GsWindow(QDialog , Ui_Dialog):
  12. MainSiganl = Signal(bool)
  13. def __init__(self):
  14. super(GsWindow, self).__init__()
  15. self.setupUi(self)
  16. # 记录当前应用程序路径
  17. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  18. # 设置窗体图标
  19. app_icon = QIcon('登录配置.ico')
  20. self.setWindowIcon(app_icon)
  21. self.pButtonuser.clicked.connect(lambda: self.User())
  22. self.pButtonproject.clicked.connect(lambda: self.Project())
  23. self.setStyleSheet("background-image: url(b1.jpg);")
  24. def User(self):
  25. self.user_win = userwindow()
  26. self.user_win.show()
  27. def Project(self):
  28. self.pro_win = projectwindow()
  29. self.pro_win.show()
  30. if __name__ == '__main__':
  31. app = QApplication(sys.argv)
  32. detail_win = GsWindow()
  33. detail_win.show()
  34. sys.exit(app.exec_())

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

ui_main.py

  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'main.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_MainWindow(object):
  14. def setupUi(self, MainWindow):
  15. if not MainWindow.objectName():
  16. MainWindow.setObjectName(u"MainWindow")
  17. MainWindow.resize(1253, 840)
  18. icon = QIcon()
  19. icon.addFile(u":/\u767b\u5f55.png", QSize(), QIcon.Normal, QIcon.Off)
  20. MainWindow.setWindowIcon(icon)
  21. self.actionMenuOpen = QAction(MainWindow)
  22. self.actionMenuOpen.setObjectName(u"actionMenuOpen")
  23. self.actionMenuExit = QAction(MainWindow)
  24. self.actionMenuExit.setObjectName(u"actionMenuExit")
  25. self.actionTlbExit = QAction(MainWindow)
  26. self.actionTlbExit.setObjectName(u"actionTlbExit")
  27. self.actionTlbAdd = QAction(MainWindow)
  28. self.actionTlbAdd.setObjectName(u"actionTlbAdd")
  29. self.actionTlbChange = QAction(MainWindow)
  30. self.actionTlbChange.setObjectName(u"actionTlbChange")
  31. self.actionMenuAdd = QAction(MainWindow)
  32. self.actionMenuAdd.setObjectName(u"actionMenuAdd")
  33. self.actionMenuChange = QAction(MainWindow)
  34. self.actionMenuChange.setObjectName(u"actionMenuChange")
  35. self.actionTlbExport = QAction(MainWindow)
  36. self.actionTlbExport.setObjectName(u"actionTlbExport")
  37. self.actionTlbSelect = QAction(MainWindow)
  38. self.actionTlbSelect.setObjectName(u"actionTlbSelect")
  39. self.actionquestion = QAction(MainWindow)
  40. self.actionquestion.setObjectName(u"actionquestion")
  41. self.centralwidget = QWidget(MainWindow)
  42. self.centralwidget.setObjectName(u"centralwidget")
  43. self.layoutWidget = QWidget(self.centralwidget)
  44. self.layoutWidget.setObjectName(u"layoutWidget")
  45. self.layoutWidget.setGeometry(QRect(0, 10, 1251, 51))
  46. self.verticalLayout = QVBoxLayout(self.layoutWidget)
  47. self.verticalLayout.setObjectName(u"verticalLayout")
  48. self.verticalLayout.setContentsMargins(0, 0, 0, 0)
  49. self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  50. self.verticalLayout.addItem(self.verticalSpacer)
  51. self.horizontalLayout = QHBoxLayout()
  52. self.horizontalLayout.setObjectName(u"horizontalLayout")
  53. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  54. self.horizontalLayout.addItem(self.horizontalSpacer)
  55. self.label = QLabel(self.layoutWidget)
  56. self.label.setObjectName(u"label")
  57. font = QFont()
  58. font.setFamily(u"Agency FB")
  59. font.setPointSize(20)
  60. font.setBold(True)
  61. font.setUnderline(True)
  62. font.setWeight(75)
  63. self.label.setFont(font)
  64. self.horizontalLayout.addWidget(self.label)
  65. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  66. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  67. self.lineEditUser_Id = QLineEdit(self.layoutWidget)
  68. self.lineEditUser_Id.setObjectName(u"lineEditUser_Id")
  69. font1 = QFont()
  70. font1.setFamily(u"Agency FB")
  71. font1.setPointSize(12)
  72. font1.setBold(True)
  73. font1.setWeight(75)
  74. self.lineEditUser_Id.setFont(font1)
  75. self.horizontalLayout.addWidget(self.lineEditUser_Id)
  76. self.verticalLayout.addLayout(self.horizontalLayout)
  77. self.layoutWidget1 = QWidget(self.centralwidget)
  78. self.layoutWidget1.setObjectName(u"layoutWidget1")
  79. self.layoutWidget1.setGeometry(QRect(0, 60, 1251, 701))
  80. self.horizontalLayout_2 = QHBoxLayout(self.layoutWidget1)
  81. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  82. self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
  83. self.tableWidget = QTableWidget(self.layoutWidget1)
  84. if (self.tableWidget.columnCount() < 9):
  85. self.tableWidget.setColumnCount(9)
  86. __qtablewidgetitem = QTableWidgetItem()
  87. self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
  88. __qtablewidgetitem1 = QTableWidgetItem()
  89. self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
  90. __qtablewidgetitem2 = QTableWidgetItem()
  91. self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
  92. __qtablewidgetitem3 = QTableWidgetItem()
  93. self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
  94. __qtablewidgetitem4 = QTableWidgetItem()
  95. self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
  96. __qtablewidgetitem5 = QTableWidgetItem()
  97. self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
  98. __qtablewidgetitem6 = QTableWidgetItem()
  99. self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
  100. __qtablewidgetitem7 = QTableWidgetItem()
  101. self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
  102. __qtablewidgetitem8 = QTableWidgetItem()
  103. self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
  104. self.tableWidget.setObjectName(u"tableWidget")
  105. self.horizontalLayout_2.addWidget(self.tableWidget)
  106. self.verticalLayout_3 = QVBoxLayout()
  107. self.verticalLayout_3.setObjectName(u"verticalLayout_3")
  108. self.verticalSpacer_5 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  109. self.verticalLayout_3.addItem(self.verticalSpacer_5)
  110. self.pButtonSelect = QPushButton(self.layoutWidget1)
  111. self.pButtonSelect.setObjectName(u"pButtonSelect")
  112. self.verticalLayout_3.addWidget(self.pButtonSelect)
  113. self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  114. self.verticalLayout_3.addItem(self.verticalSpacer_8)
  115. self.verticalLayout_2 = QVBoxLayout()
  116. self.verticalLayout_2.setObjectName(u"verticalLayout_2")
  117. self.pButtonAdd = QPushButton(self.layoutWidget1)
  118. self.pButtonAdd.setObjectName(u"pButtonAdd")
  119. self.verticalLayout_2.addWidget(self.pButtonAdd)
  120. self.verticalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  121. self.verticalLayout_2.addItem(self.verticalSpacer_4)
  122. self.pButtonchange = QPushButton(self.layoutWidget1)
  123. self.pButtonchange.setObjectName(u"pButtonchange")
  124. self.verticalLayout_2.addWidget(self.pButtonchange)
  125. self.verticalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  126. self.verticalLayout_2.addItem(self.verticalSpacer_7)
  127. self.pButtonExport = QPushButton(self.layoutWidget1)
  128. self.pButtonExport.setObjectName(u"pButtonExport")
  129. self.verticalLayout_2.addWidget(self.pButtonExport)
  130. self.verticalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  131. self.verticalLayout_2.addItem(self.verticalSpacer_6)
  132. self.pButtonImport = QPushButton(self.layoutWidget1)
  133. self.pButtonImport.setObjectName(u"pButtonImport")
  134. self.verticalLayout_2.addWidget(self.pButtonImport)
  135. self.verticalSpacer_3 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  136. self.verticalLayout_2.addItem(self.verticalSpacer_3)
  137. self.pButtonshow = QPushButton(self.layoutWidget1)
  138. self.pButtonshow.setObjectName(u"pButtonshow")
  139. self.verticalLayout_2.addWidget(self.pButtonshow)
  140. self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  141. self.verticalLayout_2.addItem(self.verticalSpacer_2)
  142. self.pButtonExit = QPushButton(self.layoutWidget1)
  143. self.pButtonExit.setObjectName(u"pButtonExit")
  144. self.verticalLayout_2.addWidget(self.pButtonExit)
  145. self.verticalLayout_3.addLayout(self.verticalLayout_2)
  146. self.horizontalLayout_2.addLayout(self.verticalLayout_3)
  147. MainWindow.setCentralWidget(self.centralwidget)
  148. self.menubar = QMenuBar(MainWindow)
  149. self.menubar.setObjectName(u"menubar")
  150. self.menubar.setGeometry(QRect(0, 0, 1253, 26))
  151. self.menuFile = QMenu(self.menubar)
  152. self.menuFile.setObjectName(u"menuFile")
  153. self.menuAdd = QMenu(self.menubar)
  154. self.menuAdd.setObjectName(u"menuAdd")
  155. self.menuEdit = QMenu(self.menubar)
  156. self.menuEdit.setObjectName(u"menuEdit")
  157. self.menuHelp = QMenu(self.menubar)
  158. self.menuHelp.setObjectName(u"menuHelp")
  159. MainWindow.setMenuBar(self.menubar)
  160. self.statusbar = QStatusBar(MainWindow)
  161. self.statusbar.setObjectName(u"statusbar")
  162. MainWindow.setStatusBar(self.statusbar)
  163. self.toolBar = QToolBar(MainWindow)
  164. self.toolBar.setObjectName(u"toolBar")
  165. MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
  166. self.menubar.addAction(self.menuFile.menuAction())
  167. self.menubar.addAction(self.menuAdd.menuAction())
  168. self.menubar.addAction(self.menuEdit.menuAction())
  169. self.menubar.addAction(self.menuHelp.menuAction())
  170. self.menuFile.addAction(self.actionMenuOpen)
  171. self.menuFile.addAction(self.actionMenuExit)
  172. self.menuEdit.addAction(self.actionMenuAdd)
  173. self.menuEdit.addAction(self.actionMenuChange)
  174. self.menuHelp.addAction(self.actionquestion)
  175. self.toolBar.addAction(self.actionTlbExit)
  176. self.toolBar.addAction(self.actionTlbAdd)
  177. self.toolBar.addAction(self.actionTlbChange)
  178. self.toolBar.addAction(self.actionTlbExport)
  179. self.toolBar.addAction(self.actionTlbSelect)
  180. self.retranslateUi(MainWindow)
  181. QMetaObject.connectSlotsByName(MainWindow)
  182. # setupUi
  183. def retranslateUi(self, MainWindow):
  184. MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u4e00\u89c8", None))
  185. self.actionMenuOpen.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None))
  186. self.actionMenuExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa", None))
  187. self.actionTlbExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
  188. self.actionTlbAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
  189. self.actionTlbChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
  190. self.actionMenuAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
  191. self.actionMenuChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
  192. self.actionTlbExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa\u9879\u76ee", None))
  193. self.actionTlbSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u9879\u76ee", None))
  194. self.actionquestion.setText(QCoreApplication.translate("MainWindow", u"\u51fa\u73b0\u9519\u8bef\uff1f", None))
  195. self.label.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u8fdb\u5ea6\u7ba1\u7406", None))
  196. ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
  197. ___qtablewidgetitem.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7f16\u53f7", None));
  198. ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
  199. ___qtablewidgetitem1.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7c7b\u578b", None));
  200. ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
  201. ___qtablewidgetitem2.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u540d\u79f0", None));
  202. ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
  203. ___qtablewidgetitem3.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u65e5\u671f", None));
  204. ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
  205. ___qtablewidgetitem4.setText(QCoreApplication.translate("MainWindow", u"\u7ed3\u675f\u65e5\u671f", None));
  206. ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
  207. ___qtablewidgetitem5.setText(QCoreApplication.translate("MainWindow", u"\u5b8c\u6210\u8fdb\u5ea6", None));
  208. ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
  209. ___qtablewidgetitem6.setText(QCoreApplication.translate("MainWindow", u"\u8d1f\u8d23\u4eba", None));
  210. ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
  211. ___qtablewidgetitem7.setText(QCoreApplication.translate("MainWindow", u"\u9879\u76ee\u7ea7\u522b", None));
  212. ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
  213. ___qtablewidgetitem8.setText(QCoreApplication.translate("MainWindow", u"\u5907\u6ce8", None));
  214. self.pButtonSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u9879\u76ee", None))
  215. self.pButtonAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u9879\u76ee", None))
  216. self.pButtonchange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u9879\u76ee", None))
  217. self.pButtonExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa\u9879\u76ee", None))
  218. self.pButtonImport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165\u9879\u76ee", None))
  219. self.pButtonshow.setText(QCoreApplication.translate("MainWindow", u"\u663e\u793a\u9879\u76ee\u53ca\u6570\u636e", None))
  220. self.pButtonExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
  221. self.menuFile.setTitle(QCoreApplication.translate("MainWindow", u"\u6587\u4ef6", None))
  222. self.menuAdd.setTitle("")
  223. self.menuEdit.setTitle(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91", None))
  224. self.menuHelp.setTitle(QCoreApplication.translate("MainWindow", u"\u5e2e\u52a9", None))
  225. self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
  226. # retranslateUi

main.py

  1. from PySide2.QtWidgets import QApplication
  2. from PySide2.QtWidgets import QMainWindow
  3. from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
  4. from PySide2.QtWidgets import QAbstractItemView, QLineEdit, QPushButton
  5. import sys, os
  6. from main_body.ui_main import Ui_MainWindow as MainWin
  7. from PySide2.QtWidgets import QHeaderView
  8. import sqlite3
  9. from PySide2.QtWidgets import QFileDialog, QMessageBox, QMenu
  10. import chardet, csv
  11. from PySide2.QtCore import Signal, Qt
  12. from gl import DetailWindow as DetailWind
  13. from search import DetailWindow as Searchwind
  14. from tkinter import *
  15. from tkinter import messagebox
  16. from question import DetailWindow as qwind
  17. from control_user import MainWindow as conwind
  18. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  19. class MainWindow(QMainWindow, MainWin):
  20. mainSignal = Signal(str, dict)
  21. def __init__(self):
  22. super(MainWindow, self).__init__()
  23. self.setupUi(self)
  24. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  25. # 设置窗体图标
  26. app_icon = QIcon('项目新.ico')
  27. self.setWindowIcon(app_icon)
  28. self.pButtonExit.clicked.connect(lambda: self.Close())
  29. self.pButtonshow.clicked.connect(lambda: self.Show())
  30. self.pButtonImport.clicked.connect(lambda: self.Import())
  31. self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
  32. self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
  33. self.gl_win = None
  34. self.pButtonAdd.clicked.connect(lambda: self.Project_Add())
  35. self.pButtonchange.clicked.connect(lambda: self.Project_Change())
  36. self.pButtonExport.clicked.connect(lambda: self.Export())
  37. self.pButtonSelect.clicked.connect(lambda: self.Select())
  38. self.stuAction = None
  39. self.YhName = None
  40. self.actionTlbExit.triggered.connect(lambda: self.Close())
  41. self.actionTlbAdd.triggered.connect(lambda: self.Project_Add())
  42. self.actionTlbChange.triggered.connect(lambda: self.Project_Change())
  43. self.actionTlbExport.triggered.connect(lambda: self.Export())
  44. self.actionTlbSelect.triggered.connect(lambda: self.Select())
  45. # self.tableWidget.setSelectionBehavior(
  46. # QAbstractItemView.SelectRows # 行选
  47. # )
  48. # self.tableWidget.setSelectionMode(
  49. # QAbstractItemView.SingleSelection # 单选
  50. # )
  51. self.actionMenuExit.triggered.connect(lambda: self.Close())
  52. self.actionMenuOpen.triggered.connect(lambda: self.Import())
  53. self.actionMenuAdd.triggered.connect(lambda: self.Project_Add())
  54. self.actionMenuChange.triggered.connect(lambda: self.Project_Change())
  55. self.actionquestion.triggered.connect(lambda: self.question())
  56. # self.Show()
  57. # self.pButtonshow.setVisible(False)
  58. self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
  59. self.tableWidget.customContextMenuRequested.connect(self.menu_pop)
  60. ########################################################################################################################
  61. # 显示all_projects的数据
  62. def Show(self, actionGl=False):
  63. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  64. try:
  65. if actionGl == True:
  66. while self.tableWidget.rowCount() > 0:
  67. self.tableWidget.removeRow(0)
  68. self.tableWidget.setRowCount(0)
  69. conn = sqlite3.connect(db_file)
  70. cur = conn.cursor()
  71. sql = '''
  72. select Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
  73. from project
  74. '''
  75. cur.execute(sql)
  76. stu = cur.fetchone()
  77. row_index = 0
  78. while stu:
  79. self.tableWidget.insertRow(row_index)
  80. for colIdx, data in enumerate(stu):
  81. TblItem = QTableWidgetItem(str(data))
  82. self.tableWidget.setItem(row_index, colIdx, TblItem)
  83. stu = cur.fetchone()
  84. row_index = row_index + 1
  85. self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  86. except Exception as e:
  87. print(e)
  88. finally:
  89. cur.close()
  90. conn.close()
  91. cur = None
  92. conn = None
  93. ########################################################################################################################
  94. # 导入all_Projects的数据
  95. def Import(self):
  96. # 选择要导入的CSV文件
  97. csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')
  98. if not csv_file:
  99. return
  100. # 获取导入数据库路径
  101. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  102. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  103. if not db_file:
  104. return
  105. try:
  106. # 连接数据库并创建表格
  107. conn = sqlite3.connect(db_file)
  108. cur = conn.cursor()
  109. # cur.execute(
  110. # 'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')
  111. # 读取CSV文件并插入数据
  112. with open(csv_file, 'r') as f:
  113. reader = csv.reader(f)
  114. for row in reader:
  115. cur.execute(
  116. 'INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM project WHERE Id = ?)',
  117. (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[0]))
  118. conn.commit()
  119. QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
  120. except Exception as e:
  121. conn.rollback()
  122. QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
  123. finally:
  124. cur.close()
  125. conn.close()
  126. # opened_file = QFileDialog().getOpenFileName(
  127. # parent=self,
  128. # caption='选择要导入的文件',
  129. # dir=self.cur_dir,
  130. # filter='CSV文件(*.csv);;文本文件(*.txt)'
  131. # )
  132. # if len(opened_file[0]) > 0:
  133. # db_file = os.path.join(self.cur_dir, './data/all_projects.db')
  134. # try:
  135. # conn = sqlite3.connect(db_file)
  136. # cur = conn.cursor()
  137. # sql = '''
  138. # INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark)
  139. # VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  140. # '''
  141. # data = open(opened_file[0], mode='rb').read()
  142. # encoding = chardet.detect(data).get('encoding')
  143. # with open(opened_file[0], mode='r', encoding=encoding) as f:
  144. # csv_reader = csv.DictReader(f)
  145. # rows = []
  146. # for row in csv_reader:
  147. # rows.append((row['项目编号'], row['项目类型'], row['项目名称'],
  148. # row['开始日期'], row['结束日期'], row['完成进度'], row['负责人'],
  149. # row['项目级别'], row['备注']))
  150. # cur.executemany(sql, rows)
  151. # conn.commit()
  152. # QMessageBox.information(self, '消息', '导入成功!')
  153. #self.db2screen()
  154. # except Exception as e:
  155. # conn.rollback()
  156. # QMessageBox.critical(self, '错误', '导入失败!' + str(e))
  157. # finally:
  158. # cur.close()
  159. # conn.close()
  160. # cur = None
  161. # conn = None
  162. ########################################################################################################################
  163. # 添加项目
  164. def Project_Add(self):
  165. self.stuAction = 'Add'
  166. self.gl_win = DetailWind()
  167. self.gl_win.setModal(True)
  168. self.gl_win.show()
  169. self.mainSignal.connect(self.gl_win.handle_main_signal)
  170. self.mainSignal.emit(self.stuAction, None)
  171. self.gl_win.detailSiganl.connect(self.Show)
  172. ########################################################################################################################
  173. # 修改项目
  174. def Project_Change(self):
  175. self.stuAction = 'Change'
  176. selected_ranges = self.tableWidget.selectedRanges()
  177. if len(selected_ranges) > 1 or len(selected_ranges) == 0:
  178. QMessageBox.warning(self, '警告', '请选择一行')
  179. return
  180. self.gl_win = DetailWind()
  181. self.gl_win.setModal(True)
  182. self.gl_win.show()
  183. self.mainSignal.connect(self.gl_win.handle_main_signal)
  184. stu = {}
  185. current_row = self.tableWidget.currentRow()
  186. for c in range(self.tableWidget.columnCount()):
  187. item_data = self.tableWidget.item(current_row, c).text()
  188. item_name = self.tableWidget.horizontalHeaderItem(c).text()
  189. stu[item_name] = item_data
  190. self.mainSignal.emit(self.stuAction, stu)
  191. self.gl_win.detailSiganl.connect(self.Show)
  192. ########################################################################################################################
  193. # 右键菜单
  194. def menu_pop(self, pos):
  195. row = self.tableWidget.currentRow()
  196. stu = {}
  197. for col in range(self.tableWidget.columnCount()):
  198. col_name = self.tableWidget.horizontalHeaderItem(col).text()
  199. col_value = self.tableWidget.item(row, col).text()
  200. stu[col_name] = col_value
  201. menu = QMenu()
  202. actionAdd = menu.addAction(u'添加')
  203. actionEdit = menu.addAction(u'编辑')
  204. actionDel = menu.addAction(u'删除')
  205. actionName = menu.exec_(self.tableWidget.mapToGlobal(pos))
  206. if actionName == actionAdd:
  207. self.Project_Add()
  208. elif actionName == actionEdit:
  209. self.Project_Change()
  210. elif actionName == actionDel:
  211. stu_People = stu['负责人']
  212. stu_No = stu['项目编号']
  213. answer = QMessageBox.question(
  214. self,
  215. '确认删除',
  216. '是否删除{}行的项目'.format(row+1, stu_People),
  217. QMessageBox.Yes | QMessageBox.No
  218. )
  219. if answer == QMessageBox.No:
  220. return
  221. self.tableWidget.removeRow(row)
  222. self.del_from_db(stu_No)
  223. ########################################################################################################################
  224. # 右键菜单中的删除键所使用的功能
  225. def del_from_db(self, stu_No):
  226. conn, cur = None, None
  227. try:
  228. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  229. conn = sqlite3.connect(db_file)
  230. cur = conn.cursor()
  231. sql = '''
  232. delete from project where Id = '{}'
  233. '''.format(stu_No)
  234. cur.execute(sql)
  235. conn.commit()
  236. QMessageBox.information(
  237. self,
  238. '删除成功',
  239. '成功删除项目:{}!'.format(stu_No),
  240. QMessageBox.Ok
  241. )
  242. except Exception as e:
  243. conn.rollback()
  244. QMessageBox.critical(
  245. self,
  246. '删除失败!',
  247. str(e),
  248. QMessageBox.Ok
  249. )
  250. finally:
  251. cur.close()
  252. conn.close()
  253. cur = None
  254. conn = None
  255. ########################################################################################################################
  256. # 退出系统
  257. def Close(self):
  258. reply = QMessageBox.question(self,'关闭提示',"是否要退出界面?",
  259. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  260. if reply == QMessageBox.Yes:
  261. self.close()
  262. elif reply == QMessageBox.No:
  263. return
  264. ########################################################################################################################
  265. # 导出项目
  266. def Export(self):
  267. # 选择要导出的数据库文件
  268. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  269. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  270. if not db_file:
  271. return
  272. # 获取导出路径
  273. csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')
  274. if not csv_file:
  275. return
  276. try:
  277. # 连接数据库并查询数据
  278. conn = sqlite3.connect(db_file)
  279. cur = conn.cursor()
  280. cur.execute('SELECT * FROM project')
  281. data = cur.fetchall()
  282. # 将数据写入CSV文件
  283. with open(csv_file, 'w', newline='') as f:
  284. writer = csv.writer(f)
  285. writer.writerow([i[0] for i in cur.description]) # 写入表头
  286. for row in data:
  287. writer.writerow(row)
  288. QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
  289. except Exception as e:
  290. QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
  291. finally:
  292. cur.close()
  293. conn.close()
  294. ########################################################################################################################
  295. # 搜索项目
  296. def Select(self):
  297. self.se_win = Searchwind()
  298. self.se_win.setModal(True)
  299. self.se_win.show()
  300. # def Select(self):
  301. # e = 0
  302. # root = Tk()
  303. # root.title("查询项目")
  304. # Label(root, text='输入项目编号:').grid(row=0, column=0)
  305. # e1 = Entry(root)
  306. # e1.grid(row=0, column=1, padx=10, pady=5)
  307. #
  308. # def showData(e):
  309. # dept = str(e1.get())
  310. # db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  311. # conn = sqlite3.connect(db_file)
  312. # cur = conn.cursor()
  313. # sql = '''
  314. # select Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
  315. # from project
  316. # where Id = ?
  317. # '''
  318. # cur.execute(sql, (dept,))
  319. # data = cur.fetchone()
  320. # if data:
  321. # messagebox.showinfo("查询结果", "{}".format(data))
  322. # else:
  323. # messagebox.showwarning("查询结果", "未查询到相关信息")
  324. #
  325. # cur.close()
  326. # conn.close()
  327. #
  328. # bTnOk = Button(text='查询')
  329. # bTnOk.grid(row=3, column=1)
  330. # bTnOk.bind("<Button-1>", showData)
  331. # mainloop()
  332. ########################################################################################################################
  333. def question(self):
  334. self.que_win = qwind()
  335. self.que_win.setModal(True)
  336. self.que_win.show()
  337. ########################################################################################################################
  338. def yh_login_Signal(self, yhActionName:str):
  339. self.YhName = yhActionName
  340. self.lineEditUser_Id.setText('欢迎!'+ self.YhName)
  341. # print(self.YhName)
  342. # print(type(self.YhName))
  343. conn = sqlite3.connect(os.path.join(self.cur_dir, './data/user_password.db'))
  344. c = conn.cursor()
  345. sql_add = f"select add_right from all_user where username='{self.YhName}'"
  346. sql_change = f"select change_right from all_user where username='{self.YhName}'"
  347. sql_import = f"select import_right from all_user where username='{self.YhName}'"
  348. sql_export = f"select export_right from all_user where username='{self.YhName}'"
  349. cursor_add = c.execute(sql_add)
  350. result_add = cursor_add.fetchone() # 返回元组,取第一个值
  351. # print(result_add[0])
  352. # print(type(result_add[0]))
  353. cursor_change = c.execute(sql_change)
  354. result_change = cursor_change.fetchone()
  355. cursor_import = c.execute(sql_import)
  356. result_import = cursor_import.fetchone()
  357. cursor_export = c.execute(sql_export)
  358. result_export = cursor_export.fetchone()
  359. if result_add[0] == 'F':
  360. self.pButtonAdd.setVisible(False)
  361. else:
  362. self.pButtonAdd.setVisible(True)
  363. if result_change[0] == 'F':
  364. self.pButtonchange.setVisible(False)
  365. else:
  366. self.pButtonchange.setVisible(True)
  367. if result_import[0] == 'F':
  368. self.pButtonImport.setVisible(False)
  369. else:
  370. self.pButtonImport.setVisible(True)
  371. if result_export[0] == 'F':
  372. self.pButtonAdd.setVisible(False)
  373. else:
  374. self.pButtonAdd.setVisible(True)
  375. if __name__ == '__main__':
  376. app = QApplication(sys.argv)
  377. win_main = MainWindow()
  378. win_main.show()
  379. sys.exit(app.exec_())

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

ui_control_user.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'control_user.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. class Ui_MainWindow(object):
  13. def setupUi(self, MainWindow):
  14. if not MainWindow.objectName():
  15. MainWindow.setObjectName(u"MainWindow")
  16. MainWindow.resize(1242, 687)
  17. self.actionTlbAdd = QAction(MainWindow)
  18. self.actionTlbAdd.setObjectName(u"actionTlbAdd")
  19. self.actionTlbChange = QAction(MainWindow)
  20. self.actionTlbChange.setObjectName(u"actionTlbChange")
  21. self.actionTlbSearch = QAction(MainWindow)
  22. self.actionTlbSearch.setObjectName(u"actionTlbSearch")
  23. self.actionMenuopen = QAction(MainWindow)
  24. self.actionMenuopen.setObjectName(u"actionMenuopen")
  25. self.actionMenuexport = QAction(MainWindow)
  26. self.actionMenuexport.setObjectName(u"actionMenuexport")
  27. self.actionMenuExport = QAction(MainWindow)
  28. self.actionMenuExport.setObjectName(u"actionMenuExport")
  29. self.centralwidget = QWidget(MainWindow)
  30. self.centralwidget.setObjectName(u"centralwidget")
  31. self.layoutWidget = QWidget(self.centralwidget)
  32. self.layoutWidget.setObjectName(u"layoutWidget")
  33. self.layoutWidget.setGeometry(QRect(0, 0, 1241, 611))
  34. self.verticalLayout_4 = QVBoxLayout(self.layoutWidget)
  35. self.verticalLayout_4.setObjectName(u"verticalLayout_4")
  36. self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
  37. self.horizontalLayout = QHBoxLayout()
  38. self.horizontalLayout.setObjectName(u"horizontalLayout")
  39. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  40. self.horizontalLayout.addItem(self.horizontalSpacer)
  41. self.label = QLabel(self.layoutWidget)
  42. self.label.setObjectName(u"label")
  43. font = QFont()
  44. font.setFamily(u"Agency FB")
  45. font.setPointSize(26)
  46. font.setBold(True)
  47. font.setWeight(75)
  48. self.label.setFont(font)
  49. self.horizontalLayout.addWidget(self.label)
  50. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  51. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  52. self.verticalLayout_4.addLayout(self.horizontalLayout)
  53. self.verticalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  54. self.verticalLayout_4.addItem(self.verticalSpacer_5)
  55. self.horizontalLayout_2 = QHBoxLayout()
  56. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  57. self.tableWidget = QTableWidget(self.layoutWidget)
  58. if (self.tableWidget.columnCount() < 9):
  59. self.tableWidget.setColumnCount(9)
  60. __qtablewidgetitem = QTableWidgetItem()
  61. self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
  62. __qtablewidgetitem1 = QTableWidgetItem()
  63. self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
  64. __qtablewidgetitem2 = QTableWidgetItem()
  65. self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
  66. __qtablewidgetitem3 = QTableWidgetItem()
  67. self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
  68. __qtablewidgetitem4 = QTableWidgetItem()
  69. self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
  70. __qtablewidgetitem5 = QTableWidgetItem()
  71. self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
  72. __qtablewidgetitem6 = QTableWidgetItem()
  73. self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
  74. __qtablewidgetitem7 = QTableWidgetItem()
  75. self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
  76. __qtablewidgetitem8 = QTableWidgetItem()
  77. self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
  78. self.tableWidget.setObjectName(u"tableWidget")
  79. self.horizontalLayout_2.addWidget(self.tableWidget)
  80. self.verticalLayout_3 = QVBoxLayout()
  81. self.verticalLayout_3.setObjectName(u"verticalLayout_3")
  82. self.verticalSpacer_4 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  83. self.verticalLayout_3.addItem(self.verticalSpacer_4)
  84. self.pButtonSelect = QPushButton(self.layoutWidget)
  85. self.pButtonSelect.setObjectName(u"pButtonSelect")
  86. self.verticalLayout_3.addWidget(self.pButtonSelect)
  87. self.verticalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  88. self.verticalLayout_3.addItem(self.verticalSpacer_6)
  89. self.verticalLayout_2 = QVBoxLayout()
  90. self.verticalLayout_2.setObjectName(u"verticalLayout_2")
  91. self.verticalLayout = QVBoxLayout()
  92. self.verticalLayout.setObjectName(u"verticalLayout")
  93. self.pButtonDisplay = QPushButton(self.layoutWidget)
  94. self.pButtonDisplay.setObjectName(u"pButtonDisplay")
  95. self.verticalLayout.addWidget(self.pButtonDisplay)
  96. self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  97. self.verticalLayout.addItem(self.verticalSpacer)
  98. self.pButtonChange = QPushButton(self.layoutWidget)
  99. self.pButtonChange.setObjectName(u"pButtonChange")
  100. self.verticalLayout.addWidget(self.pButtonChange)
  101. self.verticalLayout_2.addLayout(self.verticalLayout)
  102. self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  103. self.verticalLayout_2.addItem(self.verticalSpacer_2)
  104. self.pButtonAdd = QPushButton(self.layoutWidget)
  105. self.pButtonAdd.setObjectName(u"pButtonAdd")
  106. self.verticalLayout_2.addWidget(self.pButtonAdd)
  107. self.verticalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  108. self.verticalLayout_2.addItem(self.verticalSpacer_7)
  109. self.pButtonImport = QPushButton(self.layoutWidget)
  110. self.pButtonImport.setObjectName(u"pButtonImport")
  111. self.verticalLayout_2.addWidget(self.pButtonImport)
  112. self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed)
  113. self.verticalLayout_2.addItem(self.verticalSpacer_8)
  114. self.pButtonExit = QPushButton(self.layoutWidget)
  115. self.pButtonExit.setObjectName(u"pButtonExit")
  116. self.verticalLayout_2.addWidget(self.pButtonExit)
  117. self.verticalLayout_3.addLayout(self.verticalLayout_2)
  118. self.horizontalLayout_2.addLayout(self.verticalLayout_3)
  119. self.verticalLayout_4.addLayout(self.horizontalLayout_2)
  120. MainWindow.setCentralWidget(self.centralwidget)
  121. self.menubar = QMenuBar(MainWindow)
  122. self.menubar.setObjectName(u"menubar")
  123. self.menubar.setGeometry(QRect(0, 0, 1242, 26))
  124. self.menufile = QMenu(self.menubar)
  125. self.menufile.setObjectName(u"menufile")
  126. self.menuhelp = QMenu(self.menubar)
  127. self.menuhelp.setObjectName(u"menuhelp")
  128. MainWindow.setMenuBar(self.menubar)
  129. self.statusbar = QStatusBar(MainWindow)
  130. self.statusbar.setObjectName(u"statusbar")
  131. MainWindow.setStatusBar(self.statusbar)
  132. self.toolBar = QToolBar(MainWindow)
  133. self.toolBar.setObjectName(u"toolBar")
  134. MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
  135. self.menubar.addAction(self.menufile.menuAction())
  136. self.menubar.addAction(self.menuhelp.menuAction())
  137. self.menufile.addAction(self.actionMenuopen)
  138. self.menufile.addAction(self.actionMenuExport)
  139. self.toolBar.addAction(self.actionTlbAdd)
  140. self.toolBar.addAction(self.actionTlbChange)
  141. self.toolBar.addAction(self.actionTlbSearch)
  142. self.retranslateUi(MainWindow)
  143. QMetaObject.connectSlotsByName(MainWindow)
  144. # setupUi
  145. def retranslateUi(self, MainWindow):
  146. MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7ba1\u7406", None))
  147. self.actionTlbAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0", None))
  148. self.actionTlbChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539", None))
  149. self.actionTlbSearch.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22", None))
  150. self.actionMenuopen.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None))
  151. self.actionMenuexport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None))
  152. self.actionMenuExport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None))
  153. self.label.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7ba1\u7406", None))
  154. ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
  155. ___qtablewidgetitem.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u7c7b\u578b", None));
  156. ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
  157. ___qtablewidgetitem1.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u540d", None));
  158. ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
  159. ___qtablewidgetitem2.setText(QCoreApplication.translate("MainWindow", u"\u7528\u6237\u5bc6\u7801", None));
  160. ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
  161. ___qtablewidgetitem3.setText(QCoreApplication.translate("MainWindow", u"\u767b\u5f55\u6b21\u6570", None));
  162. ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
  163. ___qtablewidgetitem4.setText(QCoreApplication.translate("MainWindow", u"\u4e0a\u4e00\u6b21\u767b\u5f55\u65f6\u95f4", None));
  164. ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
  165. ___qtablewidgetitem5.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0", None));
  166. ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
  167. ___qtablewidgetitem6.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539", None));
  168. ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
  169. ___qtablewidgetitem7.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165", None));
  170. ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
  171. ___qtablewidgetitem8.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u51fa", None));
  172. self.pButtonSelect.setText(QCoreApplication.translate("MainWindow", u"\u641c\u7d22\u7528\u6237", None))
  173. self.pButtonDisplay.setText(QCoreApplication.translate("MainWindow", u"\u663e\u793a\u7528\u6237", None))
  174. self.pButtonChange.setText(QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u7528\u6237", None))
  175. self.pButtonAdd.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u7528\u6237", None))
  176. self.pButtonImport.setText(QCoreApplication.translate("MainWindow", u"\u5bfc\u5165\u7528\u6237", None))
  177. self.pButtonExit.setText(QCoreApplication.translate("MainWindow", u"\u9000\u51fa\u7cfb\u7edf", None))
  178. self.menufile.setTitle(QCoreApplication.translate("MainWindow", u"\u6587\u4ef6", None))
  179. self.menuhelp.setTitle(QCoreApplication.translate("MainWindow", u"\u5e2e\u52a9", None))
  180. self.toolBar.setWindowTitle(QCoreApplication.translate("MainWindow", u"toolBar", None))
  181. # retranslateUi
control_user.py
  1. from PySide2.QtWidgets import QApplication
  2. from PySide2.QtWidgets import QMainWindow
  3. from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
  4. from PySide2.QtWidgets import QAbstractItemView, QLineEdit, QPushButton
  5. import sys, os
  6. from PySide2.QtWidgets import QHeaderView
  7. import sqlite3
  8. from PySide2.QtWidgets import QFileDialog, QMessageBox, QMenu
  9. import chardet, csv
  10. from PySide2.QtCore import Signal, Qt
  11. from tkinter import *
  12. from tkinter import messagebox
  13. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  14. from main_body.ui_control_user import Ui_MainWindow
  15. from control_gl import DetailWindow as DetailWind
  16. class MainWindow(QMainWindow, Ui_MainWindow):
  17. mainSignal = Signal(str, dict)
  18. def __init__(self):
  19. super(MainWindow, self).__init__()
  20. self.setupUi(self)
  21. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  22. # 设置窗体图标
  23. app_icon = QIcon('项目新.ico')
  24. self.setWindowIcon(app_icon)
  25. self.pButtonExit.clicked.connect(lambda: self.Close())
  26. self.pButtonDisplay.clicked.connect(lambda: self.Show())
  27. self.user_win = None
  28. self.pButtonAdd.clicked.connect(lambda: self.User_Add())
  29. self.pButtonChange.clicked.connect(lambda: self.User_Change())
  30. self.pButtonSelect.clicked.connect(lambda: self.Select())
  31. self.pButtonImport.clicked.connect(lambda: self.Import())
  32. self.stuAction = None
  33. self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
  34. self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
  35. self.actionTlbSearch.triggered.connect(lambda: self.Select())
  36. self.actionMenuopen.triggered.connect(lambda: self.Import())
  37. self.actionMenuExport.triggered.connect(lambda: self.Export())
  38. self.actionTlbAdd.triggered.connect(lambda: self.User_Add())
  39. self.actionTlbChange.triggered.connect(lambda: self.User_Change())
  40. # 右键菜单
  41. self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
  42. self.tableWidget.customContextMenuRequested.connect(self.menu_pop)
  43. def Show(self, actionGl=False):
  44. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  45. try:
  46. if actionGl == True:
  47. while self.tableWidget.rowCount() > 0:
  48. self.tableWidget.removeRow(0)
  49. self.tableWidget.setRowCount(0)
  50. conn = sqlite3.connect(db_file)
  51. cur = conn.cursor()
  52. sql = '''
  53. select *
  54. from all_user
  55. '''
  56. cur.execute(sql)
  57. stu = cur.fetchone()
  58. row_index = 0
  59. while stu:
  60. self.tableWidget.insertRow(row_index)
  61. for colIdx, data in enumerate(stu):
  62. TblItem = QTableWidgetItem(str(data))
  63. self.tableWidget.setItem(row_index, colIdx, TblItem)
  64. stu = cur.fetchone()
  65. row_index = row_index + 1
  66. self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  67. except Exception as e:
  68. print(e)
  69. finally:
  70. cur.close()
  71. conn.close()
  72. cur = None
  73. conn = None
  74. # 添加用户
  75. def User_Add(self):
  76. self.stuAction = 'Add'
  77. self.gl_win = DetailWind()
  78. self.gl_win.setModal(True)
  79. self.gl_win.show()
  80. self.mainSignal.connect(self.gl_win.handle_main_signal)
  81. self.mainSignal.emit(self.stuAction, None)
  82. self.gl_win.detailSiganl.connect(self.Show)
  83. # 修改用户
  84. def User_Change(self):
  85. self.stuAction = 'Change'
  86. selected_ranges = self.tableWidget.selectedRanges()
  87. if len(selected_ranges) > 1 or len(selected_ranges) == 0:
  88. QMessageBox.warning(self, '警告', '请选择一行')
  89. return
  90. self.gl_win = DetailWind()
  91. self.gl_win.setModal(True)
  92. self.gl_win.show()
  93. self.mainSignal.connect(self.gl_win.handle_main_signal)
  94. stu = {}
  95. current_row = self.tableWidget.currentRow()
  96. for c in range(self.tableWidget.columnCount()):
  97. item_data = self.tableWidget.item(current_row, c).text()
  98. item_name = self.tableWidget.horizontalHeaderItem(c).text()
  99. stu[item_name] = item_data
  100. self.mainSignal.emit(self.stuAction, stu)
  101. self.gl_win.detailSiganl.connect(self.Show)
  102. # 退出系统
  103. def Close(self):
  104. reply = QMessageBox.question(self,'关闭提示',"是否要退出界面?",
  105. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  106. if reply == QMessageBox.Yes:
  107. self.close()
  108. elif reply == QMessageBox.No:
  109. return
  110. def Select(self):
  111. e = 0
  112. root = Tk()
  113. root.title("查询项目")
  114. Label(root, text='输入项目编号:').grid(row=0, column=0)
  115. e1 = Entry(root)
  116. e1.grid(row=0, column=1, padx=10, pady=5)
  117. def showData(e):
  118. dept = str(e1.get())
  119. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  120. conn = sqlite3.connect(db_file)
  121. cur = conn.cursor()
  122. sql = '''
  123. select user_type,username,password,login_times,last_login,add_right,change_right,
  124. import_right,export_right
  125. from all_user
  126. where username = ?
  127. '''
  128. cur.execute(sql, (dept,))
  129. data = cur.fetchone()
  130. if data:
  131. messagebox.showinfo("查询结果", "用户类型{},用户名{},用户密码{}\n登录次数{},上一次登录时间{}\n添加权限{},修改权限{},导入权限{},导出权限{}".format(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8]))
  132. else:
  133. messagebox.showwarning("查询结果", "未查询到相关信息")
  134. cur.close()
  135. conn.close()
  136. bTnOk = Button(text='查询')
  137. bTnOk.grid(row=3, column=1)
  138. bTnOk.bind("<Button-1>", showData)
  139. mainloop()
  140. def Import(self):
  141. # 选择要导入的CSV文件
  142. csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')
  143. if not csv_file:
  144. return
  145. # 获取导入数据库路径
  146. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  147. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  148. if not db_file:
  149. return
  150. try:
  151. # 连接数据库并创建表格
  152. conn = sqlite3.connect(db_file)
  153. cur = conn.cursor()
  154. # cur.execute(
  155. # 'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')
  156. # 读取CSV文件并插入数据
  157. with open(csv_file, 'r') as f:
  158. reader = csv.reader(f)
  159. for row in reader:
  160. cur.execute(
  161. 'INSERT INTO all_user (user_type,username,password,login_times,last_login) SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM all_user WHERE username = ?)',
  162. (row[0], row[1], row[2], row[3], row[4], row[0]))
  163. conn.commit()
  164. QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
  165. except Exception as e:
  166. conn.rollback()
  167. QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
  168. finally:
  169. cur.close()
  170. conn.close()
  171. def Export(self):
  172. # 选择要导出的数据库文件
  173. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  174. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  175. if not db_file:
  176. return
  177. # 获取导出路径
  178. csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')
  179. if not csv_file:
  180. return
  181. try:
  182. # 连接数据库并查询数据
  183. conn = sqlite3.connect(db_file)
  184. cur = conn.cursor()
  185. cur.execute('SELECT * FROM all_user')
  186. data = cur.fetchall()
  187. # 将数据写入CSV文件
  188. with open(csv_file, 'w', newline='') as f:
  189. writer = csv.writer(f)
  190. writer.writerow([i[0] for i in cur.description]) # 写入表头
  191. for row in data:
  192. writer.writerow(row)
  193. QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
  194. except Exception as e:
  195. QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
  196. finally:
  197. cur.close()
  198. conn.close()
  199. def menu_pop(self, pos):
  200. row = self.tableWidget.currentRow()
  201. stu = {}
  202. for col in range(self.tableWidget.columnCount()):
  203. col_name = self.tableWidget.horizontalHeaderItem(col).text()
  204. col_value = self.tableWidget.item(row, col).text()
  205. stu[col_name] = col_value
  206. menu = QMenu()
  207. actionAdd = menu.addAction(u'添加')
  208. actionEdit = menu.addAction(u'编辑')
  209. actionDel = menu.addAction(u'删除')
  210. actionName = menu.exec_(self.tableWidget.mapToGlobal(pos))
  211. if actionName == actionAdd:
  212. self.User_Add()
  213. elif actionName == actionEdit:
  214. self.User_Change()
  215. elif actionName == actionDel:
  216. stu_People = stu['用户名']
  217. stu_No = stu['用户密码']
  218. answer = QMessageBox.question(
  219. self,
  220. '确认删除',
  221. '是否删除{}行的项目'.format(row+1, stu_People),
  222. QMessageBox.Yes | QMessageBox.No
  223. )
  224. if answer == QMessageBox.No:
  225. return
  226. self.tableWidget.removeRow(row)
  227. self.del_from_db(stu_No)
  228. def del_from_db(self, stu_No):
  229. conn, cur = None, None
  230. try:
  231. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  232. conn = sqlite3.connect(db_file)
  233. cur = conn.cursor()
  234. sql = '''
  235. delete from all_user where password = '{}'
  236. '''.format(stu_No)
  237. cur.execute(sql)
  238. conn.commit()
  239. QMessageBox.information(
  240. self,
  241. '删除成功',
  242. '成功删除项目:{}!'.format(stu_No),
  243. QMessageBox.Ok
  244. )
  245. except Exception as e:
  246. conn.rollback()
  247. QMessageBox.critical(
  248. self,
  249. '删除失败!',
  250. str(e),
  251. QMessageBox.Ok
  252. )
  253. finally:
  254. cur.close()
  255. conn.close()
  256. cur = None
  257. conn = None
  258. if __name__ == '__main__':
  259. app = QApplication(sys.argv)
  260. win_main = MainWindow()
  261. win_main.show()
  262. sys.exit(app.exec_())

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

ui_gl.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'gl.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. import picture_rc
  13. class Ui_Dialog(object):
  14. def setupUi(self, Dialog):
  15. if not Dialog.objectName():
  16. Dialog.setObjectName(u"Dialog")
  17. Dialog.resize(892, 787)
  18. icon = QIcon()
  19. icon.addFile(u"C:/Users/17844/Desktop/Python\u5927\u4f5c\u4e1a/\u9879\u76ee.ico", QSize(), QIcon.Normal, QIcon.Off)
  20. Dialog.setWindowIcon(icon)
  21. self.layoutWidget = QWidget(Dialog)
  22. self.layoutWidget.setObjectName(u"layoutWidget")
  23. self.layoutWidget.setGeometry(QRect(1, 1, 891, 785))
  24. self.verticalLayout_10 = QVBoxLayout(self.layoutWidget)
  25. self.verticalLayout_10.setObjectName(u"verticalLayout_10")
  26. self.verticalLayout_10.setContentsMargins(0, 0, 0, 0)
  27. self.verticalLayout_9 = QVBoxLayout()
  28. self.verticalLayout_9.setObjectName(u"verticalLayout_9")
  29. self.horizontalLayout_13 = QHBoxLayout()
  30. self.horizontalLayout_13.setObjectName(u"horizontalLayout_13")
  31. self.horizontalSpacer_16 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  32. self.horizontalLayout_13.addItem(self.horizontalSpacer_16)
  33. self.label_Big_Title = QLabel(self.layoutWidget)
  34. self.label_Big_Title.setObjectName(u"label_Big_Title")
  35. font = QFont()
  36. font.setFamily(u"Agency FB")
  37. font.setPointSize(14)
  38. font.setBold(True)
  39. font.setWeight(75)
  40. self.label_Big_Title.setFont(font)
  41. self.horizontalLayout_13.addWidget(self.label_Big_Title)
  42. self.horizontalSpacer_17 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  43. self.horizontalLayout_13.addItem(self.horizontalSpacer_17)
  44. self.verticalLayout_9.addLayout(self.horizontalLayout_13)
  45. self.verticalSpacer_9 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  46. self.verticalLayout_9.addItem(self.verticalSpacer_9)
  47. self.horizontalLayout_14 = QHBoxLayout()
  48. self.horizontalLayout_14.setObjectName(u"horizontalLayout_14")
  49. self.horizontalSpacer_18 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  50. self.horizontalLayout_14.addItem(self.horizontalSpacer_18)
  51. self.verticalLayout_8 = QVBoxLayout()
  52. self.verticalLayout_8.setObjectName(u"verticalLayout_8")
  53. self.verticalLayout_7 = QVBoxLayout()
  54. self.verticalLayout_7.setObjectName(u"verticalLayout_7")
  55. self.verticalLayout = QVBoxLayout()
  56. self.verticalLayout.setObjectName(u"verticalLayout")
  57. self.horizontalLayout_3 = QHBoxLayout()
  58. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  59. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  60. self.horizontalLayout_3.addItem(self.horizontalSpacer_5)
  61. self.horizontalLayout = QHBoxLayout()
  62. self.horizontalLayout.setObjectName(u"horizontalLayout")
  63. self.label_2 = QLabel(self.layoutWidget)
  64. self.label_2.setObjectName(u"label_2")
  65. font1 = QFont()
  66. font1.setFamily(u"Agency FB")
  67. font1.setPointSize(10)
  68. self.label_2.setFont(font1)
  69. self.horizontalLayout.addWidget(self.label_2)
  70. self.horizontalSpacer = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  71. self.horizontalLayout.addItem(self.horizontalSpacer)
  72. self.lineEdit_No = QLineEdit(self.layoutWidget)
  73. self.lineEdit_No.setObjectName(u"lineEdit_No")
  74. self.horizontalLayout.addWidget(self.lineEdit_No)
  75. self.horizontalLayout_3.addLayout(self.horizontalLayout)
  76. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  77. self.horizontalLayout_3.addItem(self.horizontalSpacer_3)
  78. self.horizontalLayout_2 = QHBoxLayout()
  79. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  80. self.label_3 = QLabel(self.layoutWidget)
  81. self.label_3.setObjectName(u"label_3")
  82. self.label_3.setFont(font1)
  83. self.horizontalLayout_2.addWidget(self.label_3)
  84. self.horizontalSpacer_2 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  85. self.horizontalLayout_2.addItem(self.horizontalSpacer_2)
  86. self.lineEdit_Type = QLineEdit(self.layoutWidget)
  87. self.lineEdit_Type.setObjectName(u"lineEdit_Type")
  88. self.horizontalLayout_2.addWidget(self.lineEdit_Type)
  89. self.horizontalLayout_3.addLayout(self.horizontalLayout_2)
  90. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  91. self.horizontalLayout_3.addItem(self.horizontalSpacer_4)
  92. self.verticalLayout.addLayout(self.horizontalLayout_3)
  93. self.verticalSpacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  94. self.verticalLayout.addItem(self.verticalSpacer)
  95. self.horizontalLayout_4 = QHBoxLayout()
  96. self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
  97. self.label_4 = QLabel(self.layoutWidget)
  98. self.label_4.setObjectName(u"label_4")
  99. self.horizontalLayout_4.addWidget(self.label_4)
  100. self.horizontalSpacer_6 = QSpacerItem(5, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  101. self.horizontalLayout_4.addItem(self.horizontalSpacer_6)
  102. self.lineEdit_Name = QLineEdit(self.layoutWidget)
  103. self.lineEdit_Name.setObjectName(u"lineEdit_Name")
  104. self.lineEdit_Name.setEnabled(True)
  105. self.horizontalLayout_4.addWidget(self.lineEdit_Name)
  106. self.verticalLayout.addLayout(self.horizontalLayout_4)
  107. self.verticalLayout_7.addLayout(self.verticalLayout)
  108. self.verticalSpacer_7 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  109. self.verticalLayout_7.addItem(self.verticalSpacer_7)
  110. self.horizontalLayout_12 = QHBoxLayout()
  111. self.horizontalLayout_12.setObjectName(u"horizontalLayout_12")
  112. self.verticalLayout_5 = QVBoxLayout()
  113. self.verticalLayout_5.setObjectName(u"verticalLayout_5")
  114. self.verticalLayout_3 = QVBoxLayout()
  115. self.verticalLayout_3.setObjectName(u"verticalLayout_3")
  116. self.verticalLayout_2 = QVBoxLayout()
  117. self.verticalLayout_2.setObjectName(u"verticalLayout_2")
  118. self.horizontalLayout_11 = QHBoxLayout()
  119. self.horizontalLayout_11.setObjectName(u"horizontalLayout_11")
  120. self.label_5 = QLabel(self.layoutWidget)
  121. self.label_5.setObjectName(u"label_5")
  122. self.horizontalLayout_11.addWidget(self.label_5)
  123. self.horizontalSpacer_13 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  124. self.horizontalLayout_11.addItem(self.horizontalSpacer_13)
  125. self.lineEdit_Start = QLineEdit(self.layoutWidget)
  126. self.lineEdit_Start.setObjectName(u"lineEdit_Start")
  127. self.horizontalLayout_11.addWidget(self.lineEdit_Start)
  128. self.verticalLayout_2.addLayout(self.horizontalLayout_11)
  129. self.verticalSpacer_2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  130. self.verticalLayout_2.addItem(self.verticalSpacer_2)
  131. self.horizontalLayout_10 = QHBoxLayout()
  132. self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
  133. self.label_6 = QLabel(self.layoutWidget)
  134. self.label_6.setObjectName(u"label_6")
  135. self.horizontalLayout_10.addWidget(self.label_6)
  136. self.horizontalSpacer_12 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  137. self.horizontalLayout_10.addItem(self.horizontalSpacer_12)
  138. self.lineEdit_End = QLineEdit(self.layoutWidget)
  139. self.lineEdit_End.setObjectName(u"lineEdit_End")
  140. self.horizontalLayout_10.addWidget(self.lineEdit_End)
  141. self.verticalLayout_2.addLayout(self.horizontalLayout_10)
  142. self.verticalLayout_3.addLayout(self.verticalLayout_2)
  143. self.verticalSpacer_3 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  144. self.verticalLayout_3.addItem(self.verticalSpacer_3)
  145. self.horizontalLayout_5 = QHBoxLayout()
  146. self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
  147. self.label_13 = QLabel(self.layoutWidget)
  148. self.label_13.setObjectName(u"label_13")
  149. self.horizontalLayout_5.addWidget(self.label_13)
  150. self.horizontalSpacer_11 = QSpacerItem(13, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  151. self.horizontalLayout_5.addItem(self.horizontalSpacer_11)
  152. self.lineEdit_Completion_Progress = QLineEdit(self.layoutWidget)
  153. self.lineEdit_Completion_Progress.setObjectName(u"lineEdit_Completion_Progress")
  154. self.horizontalLayout_5.addWidget(self.lineEdit_Completion_Progress)
  155. self.verticalLayout_3.addLayout(self.horizontalLayout_5)
  156. self.verticalLayout_5.addLayout(self.verticalLayout_3)
  157. self.verticalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  158. self.verticalLayout_5.addItem(self.verticalSpacer_5)
  159. self.verticalLayout_4 = QVBoxLayout()
  160. self.verticalLayout_4.setObjectName(u"verticalLayout_4")
  161. self.horizontalLayout_8 = QHBoxLayout()
  162. self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
  163. self.label_9 = QLabel(self.layoutWidget)
  164. self.label_9.setObjectName(u"label_9")
  165. self.horizontalLayout_8.addWidget(self.label_9)
  166. self.horizontalSpacer_10 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  167. self.horizontalLayout_8.addItem(self.horizontalSpacer_10)
  168. self.lineEdit_People = QLineEdit(self.layoutWidget)
  169. self.lineEdit_People.setObjectName(u"lineEdit_People")
  170. self.horizontalLayout_8.addWidget(self.lineEdit_People)
  171. self.verticalLayout_4.addLayout(self.horizontalLayout_8)
  172. self.verticalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  173. self.verticalLayout_4.addItem(self.verticalSpacer_4)
  174. self.horizontalLayout_7 = QHBoxLayout()
  175. self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
  176. self.label_10 = QLabel(self.layoutWidget)
  177. self.label_10.setObjectName(u"label_10")
  178. self.horizontalLayout_7.addWidget(self.label_10)
  179. self.horizontalSpacer_9 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  180. self.horizontalLayout_7.addItem(self.horizontalSpacer_9)
  181. self.lineEdit_Money = QLineEdit(self.layoutWidget)
  182. self.lineEdit_Money.setObjectName(u"lineEdit_Money")
  183. self.horizontalLayout_7.addWidget(self.lineEdit_Money)
  184. self.verticalLayout_4.addLayout(self.horizontalLayout_7)
  185. self.verticalLayout_5.addLayout(self.verticalLayout_4)
  186. self.horizontalLayout_12.addLayout(self.verticalLayout_5)
  187. self.horizontalSpacer_15 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  188. self.horizontalLayout_12.addItem(self.horizontalSpacer_15)
  189. self.verticalLayout_6 = QVBoxLayout()
  190. self.verticalLayout_6.setObjectName(u"verticalLayout_6")
  191. self.horizontalLayout_9 = QHBoxLayout()
  192. self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
  193. self.label_12 = QLabel(self.layoutWidget)
  194. self.label_12.setObjectName(u"label_12")
  195. self.horizontalLayout_9.addWidget(self.label_12)
  196. self.horizontalSpacer_7 = QSpacerItem(13, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  197. self.horizontalLayout_9.addItem(self.horizontalSpacer_7)
  198. self.textEdit_Label = QTextEdit(self.layoutWidget)
  199. self.textEdit_Label.setObjectName(u"textEdit_Label")
  200. self.horizontalLayout_9.addWidget(self.textEdit_Label)
  201. self.verticalLayout_6.addLayout(self.horizontalLayout_9)
  202. self.verticalSpacer_6 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
  203. self.verticalLayout_6.addItem(self.verticalSpacer_6)
  204. self.horizontalLayout_6 = QHBoxLayout()
  205. self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
  206. self.label_8 = QLabel(self.layoutWidget)
  207. self.label_8.setObjectName(u"label_8")
  208. self.horizontalLayout_6.addWidget(self.label_8)
  209. self.horizontalSpacer_8 = QSpacerItem(5, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  210. self.horizontalLayout_6.addItem(self.horizontalSpacer_8)
  211. self.lineEdit_level = QLineEdit(self.layoutWidget)
  212. self.lineEdit_level.setObjectName(u"lineEdit_level")
  213. self.horizontalLayout_6.addWidget(self.lineEdit_level)
  214. self.verticalLayout_6.addLayout(self.horizontalLayout_6)
  215. self.horizontalLayout_12.addLayout(self.verticalLayout_6)
  216. self.verticalLayout_7.addLayout(self.horizontalLayout_12)
  217. self.verticalLayout_8.addLayout(self.verticalLayout_7)
  218. self.verticalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)
  219. self.verticalLayout_8.addItem(self.verticalSpacer_8)
  220. self.gridLayout = QGridLayout()
  221. self.gridLayout.setObjectName(u"gridLayout")
  222. self.label_11 = QLabel(self.layoutWidget)
  223. self.label_11.setObjectName(u"label_11")
  224. self.gridLayout.addWidget(self.label_11, 0, 0, 1, 1)
  225. self.horizontalSpacer_14 = QSpacerItem(40, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
  226. self.gridLayout.addItem(self.horizontalSpacer_14, 1, 0, 1, 1)
  227. self.textEdit_Notes = QTextEdit(self.layoutWidget)
  228. self.textEdit_Notes.setObjectName(u"textEdit_Notes")
  229. self.gridLayout.addWidget(self.textEdit_Notes, 1, 1, 1, 1)
  230. self.verticalLayout_8.addLayout(self.gridLayout)
  231. self.horizontalLayout_14.addLayout(self.verticalLayout_8)
  232. self.horizontalSpacer_19 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  233. self.horizontalLayout_14.addItem(self.horizontalSpacer_19)
  234. self.verticalLayout_9.addLayout(self.horizontalLayout_14)
  235. self.verticalLayout_10.addLayout(self.verticalLayout_9)
  236. self.verticalSpacer_10 = QSpacerItem(20, 5, QSizePolicy.Minimum, QSizePolicy.Expanding)
  237. self.verticalLayout_10.addItem(self.verticalSpacer_10)
  238. self.horizontalLayout_15 = QHBoxLayout()
  239. self.horizontalLayout_15.setObjectName(u"horizontalLayout_15")
  240. self.horizontalSpacer_20 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  241. self.horizontalLayout_15.addItem(self.horizontalSpacer_20)
  242. self.pButtonOk = QPushButton(self.layoutWidget)
  243. self.pButtonOk.setObjectName(u"pButtonOk")
  244. font2 = QFont()
  245. font2.setFamily(u"Agency FB")
  246. font2.setPointSize(12)
  247. font2.setBold(False)
  248. font2.setWeight(50)
  249. self.pButtonOk.setFont(font2)
  250. self.horizontalLayout_15.addWidget(self.pButtonOk)
  251. self.horizontalSpacer_21 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  252. self.horizontalLayout_15.addItem(self.horizontalSpacer_21)
  253. self.pButtonCancel = QPushButton(self.layoutWidget)
  254. self.pButtonCancel.setObjectName(u"pButtonCancel")
  255. font3 = QFont()
  256. font3.setFamily(u"Agency FB")
  257. font3.setPointSize(12)
  258. self.pButtonCancel.setFont(font3)
  259. self.horizontalLayout_15.addWidget(self.pButtonCancel)
  260. self.horizontalSpacer_22 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  261. self.horizontalLayout_15.addItem(self.horizontalSpacer_22)
  262. self.verticalLayout_10.addLayout(self.horizontalLayout_15)
  263. self.label = QLabel(Dialog)
  264. self.label.setObjectName(u"label")
  265. self.label.setGeometry(QRect(1, 4, 891, 781))
  266. self.label.setPixmap(QPixmap(u":/\u80cc\u666f\u56fe1.png"))
  267. self.label.raise_()
  268. self.layoutWidget.raise_()
  269. self.retranslateUi(Dialog)
  270. QMetaObject.connectSlotsByName(Dialog)
  271. # setupUi
  272. def retranslateUi(self, Dialog):
  273. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
  274. self.label_Big_Title.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ba1\u7406", None))
  275. self.label_2.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7f16\u53f7\uff1a", None))
  276. self.label_3.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7c7b\u578b\uff1a", None))
  277. self.label_4.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u540d\u79f0\uff1a", None))
  278. self.label_5.setText(QCoreApplication.translate("Dialog", u"\u5f00\u59cb\u65e5\u671f\uff1a", None))
  279. self.label_6.setText(QCoreApplication.translate("Dialog", u"\u7ed3\u675f\u65e5\u671f\uff1a", None))
  280. self.label_13.setText(QCoreApplication.translate("Dialog", u"\u5b8c\u6210\u8fdb\u5ea6\uff1a", None))
  281. self.label_9.setText(QCoreApplication.translate("Dialog", u"\u8d1f\u8d23\u4eba\uff1a", None))
  282. self.label_10.setText(QCoreApplication.translate("Dialog", u"\u9884\u7b97\u91d1\u989d\uff1a", None))
  283. self.label_12.setText(QCoreApplication.translate("Dialog", u"\u6807\u7b7e\uff1a", None))
  284. self.label_8.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ea7\u522b\uff1a", None))
  285. self.label_11.setText(QCoreApplication.translate("Dialog", u"\u5907\u6ce8\uff1a", None))
  286. self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
  287. self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
  288. self.label.setText("")
  289. # retranslateUi
gl.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. import sys, os, sqlite3
  5. from main_body.ui_gl import Ui_Dialog
  6. from PySide2.QtGui import QIcon
  7. class DetailWindow(QDialog, Ui_Dialog):
  8. detailSiganl = Signal(bool)
  9. def __init__(self):
  10. super(DetailWindow, self).__init__()
  11. self.setupUi(self)
  12. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  13. # self.setWindowFlags(
  14. # Qt.WindowMinMaxButtonsHint |
  15. # Qt.MSWindowsFixedSizeDialogHint
  16. # )
  17. self.actionName = None
  18. self.pButtonOk.clicked.connect(lambda: self.save2db())
  19. self.pButtonCancel.clicked.connect(lambda: self.close())
  20. # 设置窗体图标
  21. app_icon = QIcon('修改.ico')
  22. self.setWindowIcon(app_icon)
  23. def handle_main_signal(self, mainActionName:str, stu:dict):
  24. self.actionName = mainActionName
  25. if self.actionName == 'Add':
  26. self.label_Big_Title.setText('项目添加')
  27. self.pButtonOk.setText('添加')
  28. self.lineEdit_No.setText('')
  29. self.lineEdit_Type.setText('')
  30. self.lineEdit_Name.setText('')
  31. self.lineEdit_Start.setText('')
  32. self.lineEdit_End.setText('')
  33. self.lineEdit_Completion_Progress.setText('')
  34. self.lineEdit_People.setText('')
  35. self.lineEdit_level.setText('')
  36. self.textEdit_Notes.setText('')
  37. elif self.actionName == 'Change' and stu is not None:
  38. self.label_Big_Title.setText('项目修改')
  39. self.pButtonOk.setText('修改')
  40. self.lineEdit_No.setText(stu['项目编号'])
  41. self.lineEdit_Type.setText(stu['项目类型'])
  42. self.lineEdit_Name.setText(stu['项目名称'])
  43. self.lineEdit_Start.setText(stu['开始日期'])
  44. self.lineEdit_End.setText(stu['结束日期'])
  45. self.lineEdit_Completion_Progress.setText(str(stu['完成进度']))
  46. self.lineEdit_People.setText(stu['负责人'])
  47. self.lineEdit_level.setText(stu['项目级别'])
  48. self.textEdit_Notes.setText(stu['备注'])
  49. def save2db(self):
  50. _Id = self.lineEdit_No.text().strip()
  51. _Type = self.lineEdit_Type.text().strip()
  52. _Name = self.lineEdit_Name.text().strip()
  53. _Start = self.lineEdit_Start.text().strip()
  54. _End = self.lineEdit_End.text().strip()
  55. _Progress = self.lineEdit_Completion_Progress.text().strip()
  56. _People = self.lineEdit_People.text().strip()
  57. _Level = self.lineEdit_level.text().strip()
  58. _Note = self.textEdit_Notes.toPlainText().strip()
  59. if self.actionName == 'Add':
  60. try:
  61. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  62. conn = sqlite3.connect(db_file)
  63. cur = conn.cursor()
  64. sql = """
  65. INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark)
  66. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  67. """
  68. stu = (_Id, _Type, _Name, _Start, _End, _Progress, _People, _Level, _Note)
  69. cur.execute(sql, stu)
  70. conn.commit()
  71. QMessageBox.information(self, '添加', '添加成功!')
  72. self.detailSiganl.emit(True)
  73. except Exception as e:
  74. conn.rollback()
  75. QMessageBox.critical(self, '错误', '添加失败!' + str(e))
  76. self.detailSiganl.emit(False)
  77. finally:
  78. self.close()
  79. cur.close()
  80. conn.close()
  81. cur = None
  82. conn = None
  83. elif self.actionName == 'Change':
  84. try:
  85. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  86. conn = sqlite3.connect(db_file)
  87. cur = conn.cursor()
  88. sql = """
  89. update project set Type='{0}',Name='{1}',Start_date='{2}',End_date='{3}',
  90. Progress={4},Manager='{5}',Level='{6}',Remark='{7}' where Id='{8}'
  91. """.format(_Type, _Name, _Start, _End, _Progress, _People, _Level, _Note, _Id)
  92. cur.execute(sql)
  93. conn.commit()
  94. QMessageBox.information(self, '修改', '修改成功!')
  95. self.detailSiganl.emit(True)
  96. except Exception as e:
  97. conn.rollback()
  98. QMessageBox.critical(self, '错误', '修改失败!' + str(e))
  99. self.detailSiganl.emit(False)
  100. finally:
  101. self.close()
  102. cur.close()
  103. conn.close()
  104. cur = None
  105. conn = None
  106. if __name__ == '__main__':
  107. app = QApplication(sys.argv)
  108. win_main = DetailWindow()
  109. win_main.show()
  110. sys.exit(app.exec_())

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

代码同上一个界面

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

ui_search.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'search.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. class Ui_Dialog(object):
  13. def setupUi(self, Dialog):
  14. if not Dialog.objectName():
  15. Dialog.setObjectName(u"Dialog")
  16. Dialog.resize(1172, 733)
  17. self.layoutWidget = QWidget(Dialog)
  18. self.layoutWidget.setObjectName(u"layoutWidget")
  19. self.layoutWidget.setGeometry(QRect(1, 1, 1171, 731))
  20. self.verticalLayout = QVBoxLayout(self.layoutWidget)
  21. self.verticalLayout.setObjectName(u"verticalLayout")
  22. self.verticalLayout.setContentsMargins(0, 0, 0, 0)
  23. self.horizontalLayout = QHBoxLayout()
  24. self.horizontalLayout.setObjectName(u"horizontalLayout")
  25. self.pButtonShow = QPushButton(self.layoutWidget)
  26. self.pButtonShow.setObjectName(u"pButtonShow")
  27. self.horizontalLayout.addWidget(self.pButtonShow)
  28. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  29. self.horizontalLayout.addItem(self.horizontalSpacer)
  30. self.label = QLabel(self.layoutWidget)
  31. self.label.setObjectName(u"label")
  32. font = QFont()
  33. font.setFamily(u"Agency FB")
  34. font.setPointSize(22)
  35. font.setBold(True)
  36. font.setWeight(75)
  37. self.label.setFont(font)
  38. self.horizontalLayout.addWidget(self.label)
  39. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  40. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  41. self.verticalLayout.addLayout(self.horizontalLayout)
  42. self.verticalSpacer = QSpacerItem(20, 13, QSizePolicy.Minimum, QSizePolicy.Fixed)
  43. self.verticalLayout.addItem(self.verticalSpacer)
  44. self.horizontalLayout_4 = QHBoxLayout()
  45. self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
  46. self.label_2 = QLabel(self.layoutWidget)
  47. self.label_2.setObjectName(u"label_2")
  48. font1 = QFont()
  49. font1.setFamily(u"Agency FB")
  50. font1.setPointSize(10)
  51. font1.setBold(True)
  52. font1.setWeight(75)
  53. self.label_2.setFont(font1)
  54. self.horizontalLayout_4.addWidget(self.label_2)
  55. self.horizontalSpacer_3 = QSpacerItem(13, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  56. self.horizontalLayout_4.addItem(self.horizontalSpacer_3)
  57. self.lineEditsearch = QLineEdit(self.layoutWidget)
  58. self.lineEditsearch.setObjectName(u"lineEditsearch")
  59. self.horizontalLayout_4.addWidget(self.lineEditsearch)
  60. self.horizontalSpacer_4 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  61. self.horizontalLayout_4.addItem(self.horizontalSpacer_4)
  62. self.pButtonSearch = QPushButton(self.layoutWidget)
  63. self.pButtonSearch.setObjectName(u"pButtonSearch")
  64. self.horizontalLayout_4.addWidget(self.pButtonSearch)
  65. self.horizontalSpacer_8 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  66. self.horizontalLayout_4.addItem(self.horizontalSpacer_8)
  67. self.horizontalLayout_2 = QHBoxLayout()
  68. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  69. self.label_3 = QLabel(self.layoutWidget)
  70. self.label_3.setObjectName(u"label_3")
  71. self.horizontalLayout_2.addWidget(self.label_3)
  72. self.horizontalSpacer_5 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  73. self.horizontalLayout_2.addItem(self.horizontalSpacer_5)
  74. self.comboBox_Type = QComboBox(self.layoutWidget)
  75. self.comboBox_Type.addItem("")
  76. self.comboBox_Type.addItem("")
  77. self.comboBox_Type.addItem("")
  78. self.comboBox_Type.addItem("")
  79. self.comboBox_Type.addItem("")
  80. self.comboBox_Type.addItem("")
  81. self.comboBox_Type.addItem("")
  82. self.comboBox_Type.addItem("")
  83. self.comboBox_Type.addItem("")
  84. self.comboBox_Type.addItem("")
  85. self.comboBox_Type.addItem("")
  86. self.comboBox_Type.addItem("")
  87. self.comboBox_Type.addItem("")
  88. self.comboBox_Type.addItem("")
  89. self.comboBox_Type.addItem("")
  90. self.comboBox_Type.setObjectName(u"comboBox_Type")
  91. self.horizontalLayout_2.addWidget(self.comboBox_Type)
  92. self.horizontalLayout_4.addLayout(self.horizontalLayout_2)
  93. self.horizontalSpacer_7 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  94. self.horizontalLayout_4.addItem(self.horizontalSpacer_7)
  95. self.horizontalLayout_3 = QHBoxLayout()
  96. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  97. self.label_4 = QLabel(self.layoutWidget)
  98. self.label_4.setObjectName(u"label_4")
  99. self.horizontalLayout_3.addWidget(self.label_4)
  100. self.horizontalSpacer_6 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  101. self.horizontalLayout_3.addItem(self.horizontalSpacer_6)
  102. self.comboBox_Level = QComboBox(self.layoutWidget)
  103. self.comboBox_Level.addItem("")
  104. self.comboBox_Level.addItem("")
  105. self.comboBox_Level.addItem("")
  106. self.comboBox_Level.addItem("")
  107. self.comboBox_Level.addItem("")
  108. self.comboBox_Level.setObjectName(u"comboBox_Level")
  109. self.horizontalLayout_3.addWidget(self.comboBox_Level)
  110. self.horizontalLayout_4.addLayout(self.horizontalLayout_3)
  111. self.verticalLayout.addLayout(self.horizontalLayout_4)
  112. self.verticalSpacer_2 = QSpacerItem(20, 13, QSizePolicy.Minimum, QSizePolicy.Fixed)
  113. self.verticalLayout.addItem(self.verticalSpacer_2)
  114. self.tableWidget = QTableWidget(self.layoutWidget)
  115. if (self.tableWidget.columnCount() < 9):
  116. self.tableWidget.setColumnCount(9)
  117. __qtablewidgetitem = QTableWidgetItem()
  118. self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem)
  119. __qtablewidgetitem1 = QTableWidgetItem()
  120. self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)
  121. __qtablewidgetitem2 = QTableWidgetItem()
  122. self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2)
  123. __qtablewidgetitem3 = QTableWidgetItem()
  124. self.tableWidget.setHorizontalHeaderItem(3, __qtablewidgetitem3)
  125. __qtablewidgetitem4 = QTableWidgetItem()
  126. self.tableWidget.setHorizontalHeaderItem(4, __qtablewidgetitem4)
  127. __qtablewidgetitem5 = QTableWidgetItem()
  128. self.tableWidget.setHorizontalHeaderItem(5, __qtablewidgetitem5)
  129. __qtablewidgetitem6 = QTableWidgetItem()
  130. self.tableWidget.setHorizontalHeaderItem(6, __qtablewidgetitem6)
  131. __qtablewidgetitem7 = QTableWidgetItem()
  132. self.tableWidget.setHorizontalHeaderItem(7, __qtablewidgetitem7)
  133. __qtablewidgetitem8 = QTableWidgetItem()
  134. self.tableWidget.setHorizontalHeaderItem(8, __qtablewidgetitem8)
  135. self.tableWidget.setObjectName(u"tableWidget")
  136. self.verticalLayout.addWidget(self.tableWidget)
  137. self.retranslateUi(Dialog)
  138. QMetaObject.connectSlotsByName(Dialog)
  139. # setupUi
  140. def retranslateUi(self, Dialog):
  141. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u67e5\u8be2", None))
  142. self.pButtonShow.setText(QCoreApplication.translate("Dialog", u"\u663e\u793a\u9879\u76ee", None))
  143. self.label.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u67e5\u8be2", None))
  144. self.label_2.setText(QCoreApplication.translate("Dialog", u"\u8bf7\u8f93\u5165\u5173\u952e\u5b57\uff1a", None))
  145. self.pButtonSearch.setText(QCoreApplication.translate("Dialog", u"\u641c\u7d22", None))
  146. #if QT_CONFIG(shortcut)
  147. self.pButtonSearch.setShortcut(QCoreApplication.translate("Dialog", u"Return", None))
  148. #endif // QT_CONFIG(shortcut)
  149. self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7c7b\u578b", None))
  150. self.comboBox_Type.setItemText(0, QCoreApplication.translate("Dialog", u"\u6280\u672f\u7814\u53d1", None))
  151. self.comboBox_Type.setItemText(1, QCoreApplication.translate("Dialog", u"\u5e02\u573a\u8425\u9500", None))
  152. self.comboBox_Type.setItemText(2, QCoreApplication.translate("Dialog", u"\u751f\u4ea7\u5236\u9020", None))
  153. self.comboBox_Type.setItemText(3, QCoreApplication.translate("Dialog", u"\u4eba\u529b\u8d44\u6e90", None))
  154. self.comboBox_Type.setItemText(4, QCoreApplication.translate("Dialog", u"\u8d22\u52a1\u7ba1\u7406", None))
  155. self.comboBox_Type.setItemText(5, QCoreApplication.translate("Dialog", u"\u8f6f\u4ef6\u5f00\u53d1", None))
  156. self.comboBox_Type.setItemText(6, QCoreApplication.translate("Dialog", u"\u7f51\u7edc\u8fd0\u7ef4", None))
  157. self.comboBox_Type.setItemText(7, QCoreApplication.translate("Dialog", u"\u54a8\u8be2\u670d\u52a1", None))
  158. self.comboBox_Type.setItemText(8, QCoreApplication.translate("Dialog", u"\u5e02\u573a\u8c03\u7814", None))
  159. self.comboBox_Type.setItemText(9, QCoreApplication.translate("Dialog", u"\u57f9\u8bad\u670d\u52a1", None))
  160. self.comboBox_Type.setItemText(10, QCoreApplication.translate("Dialog", u"\u6d3b\u52a8\u7b56\u5212", None))
  161. self.comboBox_Type.setItemText(11, QCoreApplication.translate("Dialog", u"\u7269\u6d41\u914d\u9001", None))
  162. self.comboBox_Type.setItemText(12, QCoreApplication.translate("Dialog", u"\u8d22\u52a1\u5ba1\u8ba1", None))
  163. self.comboBox_Type.setItemText(13, QCoreApplication.translate("Dialog", u"\u73af\u5883\u76d1\u6d4b", None))
  164. self.comboBox_Type.setItemText(14, QCoreApplication.translate("Dialog", u"\u6cd5\u5f8b\u54a8\u8be2", None))
  165. self.comboBox_Type.setCurrentText(QCoreApplication.translate("Dialog", u"\u6280\u672f\u7814\u53d1", None))
  166. self.label_4.setText(QCoreApplication.translate("Dialog", u"\u7ea7\u522b", None))
  167. self.comboBox_Level.setItemText(0, QCoreApplication.translate("Dialog", u"A", None))
  168. self.comboBox_Level.setItemText(1, QCoreApplication.translate("Dialog", u"B", None))
  169. self.comboBox_Level.setItemText(2, QCoreApplication.translate("Dialog", u"C", None))
  170. self.comboBox_Level.setItemText(3, QCoreApplication.translate("Dialog", u"D", None))
  171. self.comboBox_Level.setItemText(4, QCoreApplication.translate("Dialog", u"E", None))
  172. ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0)
  173. ___qtablewidgetitem.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7f16\u53f7", None));
  174. ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1)
  175. ___qtablewidgetitem1.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7c7b\u578b", None));
  176. ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2)
  177. ___qtablewidgetitem2.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u540d\u79f0", None));
  178. ___qtablewidgetitem3 = self.tableWidget.horizontalHeaderItem(3)
  179. ___qtablewidgetitem3.setText(QCoreApplication.translate("Dialog", u"\u5f00\u59cb\u65e5\u671f", None));
  180. ___qtablewidgetitem4 = self.tableWidget.horizontalHeaderItem(4)
  181. ___qtablewidgetitem4.setText(QCoreApplication.translate("Dialog", u"\u7ed3\u675f\u65e5\u671f", None));
  182. ___qtablewidgetitem5 = self.tableWidget.horizontalHeaderItem(5)
  183. ___qtablewidgetitem5.setText(QCoreApplication.translate("Dialog", u"\u5b8c\u6210\u8fdb\u5ea6", None));
  184. ___qtablewidgetitem6 = self.tableWidget.horizontalHeaderItem(6)
  185. ___qtablewidgetitem6.setText(QCoreApplication.translate("Dialog", u"\u8d1f\u8d23\u4eba", None));
  186. ___qtablewidgetitem7 = self.tableWidget.horizontalHeaderItem(7)
  187. ___qtablewidgetitem7.setText(QCoreApplication.translate("Dialog", u"\u9879\u76ee\u7ea7\u522b", None));
  188. ___qtablewidgetitem8 = self.tableWidget.horizontalHeaderItem(8)
  189. ___qtablewidgetitem8.setText(QCoreApplication.translate("Dialog", u"\u5907\u6ce8", None));
  190. # retranslateUi
search.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
  5. from PySide2.QtWidgets import QHeaderView
  6. import sys, os, sqlite3
  7. from PySide2.QtGui import QIcon
  8. from main_body.ui_search import Ui_Dialog
  9. class DetailWindow(QDialog, Ui_Dialog):
  10. detailSiganl = Signal(bool)
  11. def __init__(self):
  12. super(DetailWindow, self).__init__()
  13. self.setupUi(self)
  14. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  15. # 设置窗体图标
  16. app_icon = QIcon('选择.ico')
  17. self.setWindowIcon(app_icon)
  18. # self.setWindowFlags(
  19. # Qt.WindowMinMaxButtonsHint |
  20. # Qt.MSWindowsFixedSizeDialogHint
  21. # )
  22. self.actionName = None
  23. self.pButtonShow.clicked.connect(lambda: self.Show())
  24. self.pButtonSearch.clicked.connect(lambda: self.Search())
  25. self.comboBox_Type.currentIndexChanged.connect(lambda: self.Select())
  26. self.comboBox_Level.currentIndexChanged.connect(lambda: self.Select())
  27. self.lineEditsearch.setText('') # 初始化搜索框
  28. # self.Show()
  29. ########################################################################################################################
  30. # 关键字搜索
  31. def Search(self):
  32. _info = self.lineEditsearch.text().strip()
  33. try:
  34. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  35. conn = sqlite3.connect(db_file)
  36. cur = conn.cursor()
  37. sql = '''
  38. select Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
  39. from project
  40. WHERE Id || Type || Name || Start_date || End_date || Progress || Manager || Level || Remark
  41. LIKE ? ;
  42. '''
  43. stu = ('%' + _info + '%',)
  44. cur.execute(sql, stu)
  45. conn.commit()
  46. self.tableWidget.clearContents() # 清空表格内容
  47. self.tableWidget.setRowCount(0) # 清空表格行数
  48. row_index = 0
  49. while True: # 使用True代替stu,因为查询结果为None时stu值为False,不能作为循环条件
  50. stu = cur.fetchone()
  51. if stu is None: # 如果查询结果为None,退出循环
  52. break
  53. self.tableWidget.insertRow(row_index)
  54. for col_index, data in enumerate(stu):
  55. TblItem = QTableWidgetItem(str(data))
  56. self.tableWidget.setItem(row_index, col_index, TblItem)
  57. row_index += 1
  58. self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  59. except Exception as e:
  60. conn.rollback()
  61. finally:
  62. cur.close()
  63. conn.close()
  64. cur = None
  65. conn = None
  66. ########################################################################################################################
  67. # 下拉框搜索
  68. def Select(self):
  69. current_type = self.comboBox_Type.currentText()
  70. current_level = self.comboBox_Level.currentText()
  71. try:
  72. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  73. conn = sqlite3.connect(db_file)
  74. cur = conn.cursor()
  75. sql = '''
  76. select Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
  77. from project
  78. WHERE Type = ? AND Level = ?
  79. '''
  80. stu = (current_type, current_level)
  81. cur.execute(sql, stu)
  82. conn.commit()
  83. self.tableWidget.clearContents() # 清空表格内容
  84. self.tableWidget.setRowCount(0) # 清空表格行数
  85. row_index = 0
  86. while True: # 使用True代替stu,因为查询结果为None时stu值为False,不能作为循环条件
  87. stu = cur.fetchone()
  88. if stu is None: # 如果查询结果为None,退出循环
  89. break
  90. self.tableWidget.insertRow(row_index)
  91. for col_index, data in enumerate(stu):
  92. TblItem = QTableWidgetItem(str(data))
  93. self.tableWidget.setItem(row_index, col_index, TblItem)
  94. row_index += 1
  95. self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  96. except Exception as e:
  97. conn.rollback()
  98. finally:
  99. cur.close()
  100. conn.close()
  101. cur = None
  102. conn = None
  103. ########################################################################################################################
  104. # 显示项目
  105. def Show(self, actionGl=False):
  106. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  107. try:
  108. if actionGl == True:
  109. while self.tableWidget.rowCount() > 0:
  110. self.tableWidget.removeRow(0)
  111. self.tableWidget.setRowCount(0)
  112. conn = sqlite3.connect(db_file)
  113. cur = conn.cursor()
  114. sql = '''
  115. select Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark
  116. from project
  117. '''
  118. cur.execute(sql)
  119. stu = cur.fetchone()
  120. row_index = 0
  121. while stu:
  122. self.tableWidget.insertRow(row_index)
  123. for colIdx, data in enumerate(stu):
  124. TblItem = QTableWidgetItem(str(data))
  125. self.tableWidget.setItem(row_index, colIdx, TblItem)
  126. stu = cur.fetchone()
  127. row_index = row_index + 1
  128. self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  129. except Exception as e:
  130. print(e)
  131. finally:
  132. cur.close()
  133. conn.close()
  134. cur = None
  135. conn = None
  136. ########################################################################################################################
  137. if __name__ == '__main__':
  138. app = QApplication(sys.argv)
  139. win_main = DetailWindow()
  140. win_main.show()
  141. sys.exit(app.exec_())

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

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

  1. def Import(self):
  2. # 选择要导入的CSV文件
  3. csv_file, _ = QFileDialog.getOpenFileName(None, '选择 CSV 文件', '', 'CSV 文件(*.csv)')
  4. if not csv_file:
  5. return
  6. # 获取导入数据库路径
  7. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  8. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  9. if not db_file:
  10. return
  11. try:
  12. # 连接数据库并创建表格
  13. conn = sqlite3.connect(db_file)
  14. cur = conn.cursor()
  15. # cur.execute(
  16. # 'CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)')
  17. # 读取CSV文件并插入数据
  18. with open(csv_file, 'r') as f:
  19. reader = csv.reader(f)
  20. for row in reader:
  21. cur.execute(
  22. 'INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM project WHERE Id = ?)',
  23. (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[0]))
  24. conn.commit()
  25. QMessageBox.information(None, '导入成功', '数据已成功导入到SQLite数据库中!')
  26. except Exception as e:
  27. conn.rollback()
  28. QMessageBox.warning(None, '导入失败', '导入过程中发生错误:{}'.format(str(e)))
  29. finally:
  30. cur.close()
  31. conn.close()
  32. # opened_file = QFileDialog().getOpenFileName(
  33. # parent=self,
  34. # caption='选择要导入的文件',
  35. # dir=self.cur_dir,
  36. # filter='CSV文件(*.csv);;文本文件(*.txt)'
  37. # )
  38. # if len(opened_file[0]) > 0:
  39. # db_file = os.path.join(self.cur_dir, './data/all_projects.db')
  40. # try:
  41. # conn = sqlite3.connect(db_file)
  42. # cur = conn.cursor()
  43. # sql = '''
  44. # INSERT INTO project (Id, Type, Name, Start_date, End_date, Progress, Manager, Level, Remark)
  45. # VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  46. # '''
  47. # data = open(opened_file[0], mode='rb').read()
  48. # encoding = chardet.detect(data).get('encoding')
  49. # with open(opened_file[0], mode='r', encoding=encoding) as f:
  50. # csv_reader = csv.DictReader(f)
  51. # rows = []
  52. # for row in csv_reader:
  53. # rows.append((row['项目编号'], row['项目类型'], row['项目名称'],
  54. # row['开始日期'], row['结束日期'], row['完成进度'], row['负责人'],
  55. # row['项目级别'], row['备注']))
  56. # cur.executemany(sql, rows)
  57. # conn.commit()
  58. # QMessageBox.information(self, '消息', '导入成功!')
  59. #self.db2screen()
  60. # except Exception as e:
  61. # conn.rollback()
  62. # QMessageBox.critical(self, '错误', '导入失败!' + str(e))
  63. # finally:
  64. # cur.close()
  65. # conn.close()
  66. # cur = None
  67. # conn = None

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

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

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

  1. def Export(self):
  2. # 选择要导出的数据库文件
  3. # db_file, _ = QFileDialog.getOpenFileName(None, '选择数据库文件', '', 'SQLite 数据库(*.db *.sqlite)')
  4. db_file = os.path.join(self.cur_dir, './data/my_All_Projects.db')
  5. if not db_file:
  6. return
  7. # 获取导出路径
  8. csv_file, _ = QFileDialog.getSaveFileName(None, '保存 CSV 文件', '', 'CSV 文件(*.csv)')
  9. if not csv_file:
  10. return
  11. try:
  12. # 连接数据库并查询数据
  13. conn = sqlite3.connect(db_file)
  14. cur = conn.cursor()
  15. cur.execute('SELECT * FROM project')
  16. data = cur.fetchall()
  17. # 将数据写入CSV文件
  18. with open(csv_file, 'w', newline='') as f:
  19. writer = csv.writer(f)
  20. writer.writerow([i[0] for i in cur.description]) # 写入表头
  21. for row in data:
  22. writer.writerow(row)
  23. QMessageBox.information(None, '导出成功', '数据已成功导出到CSV文件中!')
  24. except Exception as e:
  25. QMessageBox.warning(None, '导出失败', '导出过程中发生错误:{}'.format(str(e)))
  26. finally:
  27. cur.close()
  28. conn.close()

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

ui_control_gl.py
  1. # -*- coding: utf-8 -*-
  2. ################################################################################
  3. ## Form generated from reading UI file 'control_gl.ui'
  4. ##
  5. ## Created by: Qt User Interface Compiler version 5.15.2
  6. ##
  7. ## WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ################################################################################
  9. from PySide2.QtCore import *
  10. from PySide2.QtGui import *
  11. from PySide2.QtWidgets import *
  12. class Ui_Dialog(object):
  13. def setupUi(self, Dialog):
  14. if not Dialog.objectName():
  15. Dialog.setObjectName(u"Dialog")
  16. Dialog.resize(928, 602)
  17. self.layoutWidget = QWidget(Dialog)
  18. self.layoutWidget.setObjectName(u"layoutWidget")
  19. self.layoutWidget.setGeometry(QRect(30, 40, 831, 341))
  20. self.verticalLayout_3 = QVBoxLayout(self.layoutWidget)
  21. self.verticalLayout_3.setObjectName(u"verticalLayout_3")
  22. self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
  23. self.horizontalLayout = QHBoxLayout()
  24. self.horizontalLayout.setObjectName(u"horizontalLayout")
  25. self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  26. self.horizontalLayout.addItem(self.horizontalSpacer)
  27. self.label_big_title = QLabel(self.layoutWidget)
  28. self.label_big_title.setObjectName(u"label_big_title")
  29. font = QFont()
  30. font.setFamily(u"Agency FB")
  31. font.setPointSize(24)
  32. font.setBold(True)
  33. font.setWeight(75)
  34. self.label_big_title.setFont(font)
  35. self.horizontalLayout.addWidget(self.label_big_title)
  36. self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  37. self.horizontalLayout.addItem(self.horizontalSpacer_2)
  38. self.verticalLayout_3.addLayout(self.horizontalLayout)
  39. self.verticalSpacer_3 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)
  40. self.verticalLayout_3.addItem(self.verticalSpacer_3)
  41. self.verticalLayout_2 = QVBoxLayout()
  42. self.verticalLayout_2.setObjectName(u"verticalLayout_2")
  43. self.horizontalLayout_9 = QHBoxLayout()
  44. self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
  45. self.horizontalSpacer_10 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  46. self.horizontalLayout_9.addItem(self.horizontalSpacer_10)
  47. self.horizontalLayout_2 = QHBoxLayout()
  48. self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
  49. self.label_2 = QLabel(self.layoutWidget)
  50. self.label_2.setObjectName(u"label_2")
  51. self.horizontalLayout_2.addWidget(self.label_2)
  52. self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  53. self.horizontalLayout_2.addItem(self.horizontalSpacer_3)
  54. self.user_type = QLineEdit(self.layoutWidget)
  55. self.user_type.setObjectName(u"user_type")
  56. self.horizontalLayout_2.addWidget(self.user_type)
  57. self.horizontalLayout_9.addLayout(self.horizontalLayout_2)
  58. self.horizontalSpacer_11 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  59. self.horizontalLayout_9.addItem(self.horizontalSpacer_11)
  60. self.verticalLayout_2.addLayout(self.horizontalLayout_9)
  61. self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)
  62. self.verticalLayout_2.addItem(self.verticalSpacer_2)
  63. self.verticalLayout = QVBoxLayout()
  64. self.verticalLayout.setObjectName(u"verticalLayout")
  65. self.horizontalLayout_8 = QHBoxLayout()
  66. self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
  67. self.horizontalLayout_3 = QHBoxLayout()
  68. self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
  69. self.label_3 = QLabel(self.layoutWidget)
  70. self.label_3.setObjectName(u"label_3")
  71. self.horizontalLayout_3.addWidget(self.label_3)
  72. self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  73. self.horizontalLayout_3.addItem(self.horizontalSpacer_4)
  74. self.user_name = QLineEdit(self.layoutWidget)
  75. self.user_name.setObjectName(u"user_name")
  76. self.horizontalLayout_3.addWidget(self.user_name)
  77. self.horizontalLayout_8.addLayout(self.horizontalLayout_3)
  78. self.horizontalSpacer_9 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  79. self.horizontalLayout_8.addItem(self.horizontalSpacer_9)
  80. self.horizontalLayout_4 = QHBoxLayout()
  81. self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
  82. self.label_4 = QLabel(self.layoutWidget)
  83. self.label_4.setObjectName(u"label_4")
  84. self.horizontalLayout_4.addWidget(self.label_4)
  85. self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  86. self.horizontalLayout_4.addItem(self.horizontalSpacer_5)
  87. self.user_password = QLineEdit(self.layoutWidget)
  88. self.user_password.setObjectName(u"user_password")
  89. self.horizontalLayout_4.addWidget(self.user_password)
  90. self.horizontalLayout_8.addLayout(self.horizontalLayout_4)
  91. self.verticalLayout.addLayout(self.horizontalLayout_8)
  92. self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Fixed)
  93. self.verticalLayout.addItem(self.verticalSpacer)
  94. self.horizontalLayout_7 = QHBoxLayout()
  95. self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
  96. self.horizontalLayout_5 = QHBoxLayout()
  97. self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
  98. self.label_5 = QLabel(self.layoutWidget)
  99. self.label_5.setObjectName(u"label_5")
  100. self.horizontalLayout_5.addWidget(self.label_5)
  101. self.horizontalSpacer_6 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  102. self.horizontalLayout_5.addItem(self.horizontalSpacer_6)
  103. self.user_times = QLineEdit(self.layoutWidget)
  104. self.user_times.setObjectName(u"user_times")
  105. self.horizontalLayout_5.addWidget(self.user_times)
  106. self.horizontalLayout_7.addLayout(self.horizontalLayout_5)
  107. self.horizontalSpacer_8 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  108. self.horizontalLayout_7.addItem(self.horizontalSpacer_8)
  109. self.horizontalLayout_6 = QHBoxLayout()
  110. self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
  111. self.label_6 = QLabel(self.layoutWidget)
  112. self.label_6.setObjectName(u"label_6")
  113. self.horizontalLayout_6.addWidget(self.label_6)
  114. self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  115. self.horizontalLayout_6.addItem(self.horizontalSpacer_7)
  116. self.user_last_time = QLineEdit(self.layoutWidget)
  117. self.user_last_time.setObjectName(u"user_last_time")
  118. self.horizontalLayout_6.addWidget(self.user_last_time)
  119. self.horizontalLayout_7.addLayout(self.horizontalLayout_6)
  120. self.verticalLayout.addLayout(self.horizontalLayout_7)
  121. self.verticalLayout_2.addLayout(self.verticalLayout)
  122. self.verticalLayout_3.addLayout(self.verticalLayout_2)
  123. self.layoutWidget1 = QWidget(Dialog)
  124. self.layoutWidget1.setObjectName(u"layoutWidget1")
  125. self.layoutWidget1.setGeometry(QRect(150, 500, 601, 30))
  126. self.horizontalLayout_10 = QHBoxLayout(self.layoutWidget1)
  127. self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
  128. self.horizontalLayout_10.setContentsMargins(0, 0, 0, 0)
  129. self.horizontalSpacer_13 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  130. self.horizontalLayout_10.addItem(self.horizontalSpacer_13)
  131. self.pButtonOk = QPushButton(self.layoutWidget1)
  132. self.pButtonOk.setObjectName(u"pButtonOk")
  133. self.horizontalLayout_10.addWidget(self.pButtonOk)
  134. self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  135. self.horizontalLayout_10.addItem(self.horizontalSpacer_12)
  136. self.pButtonCancel = QPushButton(self.layoutWidget1)
  137. self.pButtonCancel.setObjectName(u"pButtonCancel")
  138. self.horizontalLayout_10.addWidget(self.pButtonCancel)
  139. self.horizontalSpacer_14 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  140. self.horizontalLayout_10.addItem(self.horizontalSpacer_14)
  141. self.widget = QWidget(Dialog)
  142. self.widget.setObjectName(u"widget")
  143. self.widget.setGeometry(QRect(170, 430, 671, 22))
  144. self.horizontalLayout_11 = QHBoxLayout(self.widget)
  145. self.horizontalLayout_11.setObjectName(u"horizontalLayout_11")
  146. self.horizontalLayout_11.setContentsMargins(0, 0, 0, 0)
  147. self.checkBoxAdd = QCheckBox(self.widget)
  148. self.checkBoxAdd.setObjectName(u"checkBoxAdd")
  149. self.horizontalLayout_11.addWidget(self.checkBoxAdd)
  150. self.horizontalSpacer_15 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  151. self.horizontalLayout_11.addItem(self.horizontalSpacer_15)
  152. self.checkBoxChange = QCheckBox(self.widget)
  153. self.checkBoxChange.setObjectName(u"checkBoxChange")
  154. self.horizontalLayout_11.addWidget(self.checkBoxChange)
  155. self.horizontalSpacer_16 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  156. self.horizontalLayout_11.addItem(self.horizontalSpacer_16)
  157. self.checkBoxDelete = QCheckBox(self.widget)
  158. self.checkBoxDelete.setObjectName(u"checkBoxDelete")
  159. self.horizontalLayout_11.addWidget(self.checkBoxDelete)
  160. self.horizontalSpacer_17 = QSpacerItem(20, 20, QSizePolicy.Fixed, QSizePolicy.Minimum)
  161. self.horizontalLayout_11.addItem(self.horizontalSpacer_17)
  162. self.checkBoxImport = QCheckBox(self.widget)
  163. self.checkBoxImport.setObjectName(u"checkBoxImport")
  164. self.horizontalLayout_11.addWidget(self.checkBoxImport)
  165. self.retranslateUi(Dialog)
  166. QMetaObject.connectSlotsByName(Dialog)
  167. # setupUi
  168. def retranslateUi(self, Dialog):
  169. Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
  170. self.label_big_title.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7ba1\u7406", None))
  171. self.label_2.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u7c7b\u578b", None))
  172. self.label_3.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u540d", None))
  173. self.label_4.setText(QCoreApplication.translate("Dialog", u"\u7528\u6237\u5bc6\u7801", None))
  174. self.label_5.setText(QCoreApplication.translate("Dialog", u"\u767b\u5f55\u6b21\u6570", None))
  175. self.label_6.setText(QCoreApplication.translate("Dialog", u"\u4e0a\u6b21\u767b\u5f55\u65f6\u95f4", None))
  176. self.pButtonOk.setText(QCoreApplication.translate("Dialog", u"\u786e\u5b9a", None))
  177. self.pButtonCancel.setText(QCoreApplication.translate("Dialog", u"\u53d6\u6d88", None))
  178. self.checkBoxAdd.setText(QCoreApplication.translate("Dialog", u"\u6dfb\u52a0", None))
  179. self.checkBoxChange.setText(QCoreApplication.translate("Dialog", u"\u4fee\u6539", None))
  180. self.checkBoxDelete.setText(QCoreApplication.translate("Dialog", u"\u5220\u9664", None))
  181. self.checkBoxImport.setText(QCoreApplication.translate("Dialog", u"\u5bfc\u5165", None))
  182. # retranslateUi
control_gl.py
  1. from PySide2.QtWidgets import QApplication, QDialog, QMessageBox
  2. from PySide2.QtCore import Signal # 信号
  3. from PySide2.QtGui import Qt, QIcon # 图标、窗体设置
  4. import sys, os, sqlite3
  5. from main_body.ui_control_gl import Ui_Dialog
  6. from PySide2.QtGui import QIcon
  7. class DetailWindow(QDialog, Ui_Dialog):
  8. detailSiganl = Signal(bool)
  9. def __init__(self):
  10. super(DetailWindow, self).__init__()
  11. self.setupUi(self)
  12. self.cur_dir = os.path.dirname(os.path.abspath(__file__))
  13. # self.setWindowFlags(
  14. # Qt.WindowMinMaxButtonsHint |
  15. # Qt.MSWindowsFixedSizeDialogHint
  16. # )
  17. self.actionName = None
  18. self.pButtonOk.clicked.connect(lambda: self.save2db())
  19. self.pButtonCancel.clicked.connect(lambda: self.close())
  20. # 设置窗体图标
  21. app_icon = QIcon('修改.ico')
  22. self.setWindowIcon(app_icon)
  23. def handle_main_signal(self, mainActionName: str, stu: dict):
  24. self.actionName = mainActionName
  25. if self.actionName == 'Add':
  26. self.label_big_title.setText("用户添加")
  27. self.pButtonOk.setText('添加')
  28. self.user_type.setText('')
  29. self.user_name.setText('')
  30. self.user_password.setText('')
  31. self.user_times.setText('')
  32. self.user_last_time.setText('')
  33. self.checkBoxAdd.setChecked(True)
  34. self.checkBoxChange.setChecked(True)
  35. self.checkBoxDelete.setChecked(True)
  36. self.checkBoxImport.setChecked(True)
  37. elif self.actionName == 'Change' and stu is not None:
  38. self.label_big_title.setText('用户修改')
  39. self.pButtonOk.setText('修改')
  40. self.user_type.setText(stu['用户类型'])
  41. self.user_name.setText(stu['用户名'])
  42. self.user_password.setText(stu['用户密码'])
  43. self.user_times.setText(stu['登录次数'])
  44. self.user_last_time.setText(stu['上一次登录时间'])
  45. if stu['添加'] == 'T':
  46. self.checkBoxAdd.setChecked(True)
  47. else:
  48. self.checkBoxAdd.setChecked(True)
  49. if stu['添加'] == 'T':
  50. self.checkBoxChange.setChecked(True)
  51. else:
  52. self.checkBoxChange.setChecked(True)
  53. if stu['添加'] == 'T':
  54. self.checkBoxDelete.setChecked(True)
  55. else:
  56. self.checkBoxDelete.setChecked(True)
  57. if stu['添加'] == 'T':
  58. self.checkBoxImport.setChecked(True)
  59. else:
  60. self.checkBoxImport.setChecked(True)
  61. def save2db(self):
  62. _type = self.user_type.text().strip()
  63. _name = self.user_name.text().strip()
  64. _password = self.user_password.text().strip()
  65. _times = self.user_times.text().strip()
  66. _last = self.user_last_time.text().strip()
  67. if self.checkBoxAdd.isChecked():
  68. _add = 'T'
  69. else:
  70. _add = 'F'
  71. if self.checkBoxChange.isChecked():
  72. _change = 'T'
  73. else:
  74. _change = 'F'
  75. if self.checkBoxDelete.isChecked():
  76. _delete = 'T'
  77. else:
  78. _delete = 'F'
  79. if self.checkBoxImport.isChecked():
  80. _import = 'T'
  81. else:
  82. _import = 'F'
  83. if self.actionName == 'Add':
  84. try:
  85. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  86. conn = sqlite3.connect(db_file)
  87. cur = conn.cursor()
  88. sql = """
  89. INSERT INTO all_user (user_type,username,password,login_times,last_login,add_right,change_right,
  90. import_right,export_right)
  91. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  92. """
  93. stu = (_type, _name, _password, _times, _last, _add, _change, _import,_delete )
  94. cur.execute(sql, stu)
  95. conn.commit()
  96. QMessageBox.information(self, '添加', '添加成功!')
  97. self.detailSiganl.emit(True)
  98. except Exception as e:
  99. conn.rollback()
  100. QMessageBox.critical(self, '错误', '添加失败!' + str(e))
  101. print(e)
  102. self.detailSiganl.emit(False)
  103. finally:
  104. self.close()
  105. cur.close()
  106. conn.close()
  107. cur = None
  108. conn = None
  109. elif self.actionName == 'Change':
  110. try:
  111. db_file = os.path.join(self.cur_dir, './data/user_password.db')
  112. conn = sqlite3.connect(db_file)
  113. cur = conn.cursor()
  114. sql = """
  115. update all_user set user_type='{0}',password='{1}',login_times='{2}', last_login='{3}',add_right='{4}',
  116. change_right='{5}',import_right='{6}',export_right='{7}'
  117. where username='{8}'
  118. """.format(_type, _password, _times, _last, _add, _change, _import,_delete, _name)
  119. cur.execute(sql)
  120. conn.commit()
  121. QMessageBox.information(self, '修改', '修改成功!')
  122. self.detailSiganl.emit(True)
  123. except Exception as e:
  124. conn.rollback()
  125. QMessageBox.critical(self, '错误', '修改失败!' + str(e))
  126. print(e)
  127. self.detailSiganl.emit(False)
  128. finally:
  129. self.close()
  130. cur.close()
  131. conn.close()
  132. cur = None
  133. conn = None
  134. if __name__ == '__main__':
  135. app = QApplication(sys.argv)
  136. win_main = DetailWindow()
  137. win_main.show()
  138. sys.exit(app.exec_())

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

 

同上一界面代码

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/371287
推荐阅读
相关标签
  

闽ICP备14008679号