项目功能
本系统将人员分为三类,分别是学生,教师,管理员。 其中管理员可创建学生和老师的基本信息并为其开通使用系统权限,可维护学生修课名称信息,可维护老师授课名称及班级信息,可修改管理员密码;学生能查看个人的详细信息,修改个人密码;老师能查看个人详细信息;可维护授课班级学生的成绩信息;修改个人密码。 学校人员信息包含学生和老师两类,学生基本信息有学号、姓名、性别、专业、班级、年龄、入学时间,详细信息还包括修课名称及成绩;老师基本信息有工号、姓名、性别、专业、入职时间、职称,详细信息还包括授课名称及班级。
项目运用技术
GUI方面是使用了Pyside2模块,数据库部分是SQLite3模块。
主要代码
main.py
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication, QMessageBox
import admin
import student
import teacher
from lib.share import SI
import Info
import sqlite3
class login_win:
def adm(self):
self.ui.user_text.setPlaceholderText("admin")
self.ui.username.setText("用户名")
def teacher(self):
self.ui.user_text.setPlaceholderText("请输入工号")
self.ui.username.setText("工 号")
def student(self):
self.ui.user_text.setPlaceholderText("请输入学号")
self.ui.username.setText("学 号")
def login(self):
username = self.ui.user_text.text().strip()
passwd = self.ui.pwd_text.text().strip()
if self.ui.radioButton.isChecked():
if username == Info.admin.ID and passwd == Info.admin.Password:
QMessageBox.about(self.ui, "登陆成功", '管理员登录成功')
SI.admin_win = admin.admin_win()
SI.admin_win.ui.show()
self.ui.user_text.setText("")
self.ui.pwd_text.setText("")
self.ui.hide()
else:
QMessageBox.information(self.ui, '错误', '用户名或密码错误')
elif self.ui.radioButton_2.isChecked():
if username in Info.teacher.ID and passwd == c.execute(f"select Password from teacher where ID = '{username}';").fetchone()[0]:
QMessageBox.about(self.ui, "登陆成功", '教师登录成功')
SI.teacher_win = teacher.teacher_win()
SI.teacher_win.ui.lineEdit_2.setText(username)
class_id = \
c.execute(f"select CLASS_ID from teaching where ID='{username}';").fetchone()[
0]
classes = c.execute(f"select CLASSES from teaching where CLASS_ID='{class_id}';").fetchone()[0]
SI.teacher_win.ui.lineEdit.setText(
c.execute(f"select CLASS_NAME from class where CLASS_ID='{class_id}';").fetchone()[0])
SI.teacher_win.ui.plainTextEdit.setPlainText(classes)
SI.teacher_win.ui.show()
self.ui.user_text.setText("")
self.ui.pwd_text.setText("")
self.ui.hide()
else:
QMessageBox.information(self.ui, '错误', '工号或密码错误')
elif self.ui.radioButton_3.isChecked():
stu_id = username
if username in Info.student.ID and passwd == c.execute(f"select Password from student where ID = '{username}';").fetchone()[0]:
QMessageBox.about(self.ui, "登陆成功", '学生登录成功')
SI.student_win = student.student_win()
class_names = ""
SI.student_win.ui.lineEdit_2.setText(username)
class_nums = c.execute(f"select CLASS_ID from grade where STU_ID= '{stu_id}' ;").fetchall()
for class_num in class_nums:
class_name = \
c.execute(f"select CLASS_NAME from class where CLASS_ID= '{class_num[0]}' ;").fetchone()[0]
class_score = c.execute(
f"select SCORE from grade where CLASS_ID= '{class_num[0]}'and STU_ID='{stu_id}' ;").fetchone()[
0]
end = class_name + ":" + class_score
class_names = class_names + class_name + ";"
SI.student_win.ui.plainTextEdit.appendPlainText(end)
SI.student_win.ui.lineEdit.setText(class_names)
SI.student_win.ui.show()
self.ui.user_text.setText("")
self.ui.pwd_text.setText("")
self.ui.hide()
else:
QMessageBox.information(self.ui, '错误', '学号或密码错误')
def out(self):
choice = QMessageBox.question(self.ui, "退出", "确认退出系统吗?")
if choice == QMessageBox.Yes:
conn.commit()
conn.close()
exit()
elif choice == QMessageBox.No:
pass
def username(self):
user = self.ui.user_text.text().strip()
return user
def __init__(self):
self.ui = QUiLoader().load('ui/main.ui')
self.ui.login.clicked.connect(self.login)
self.ui.exit.clicked.connect(self.out)
self.ui.radioButton.clicked.connect(self.adm)
self.ui.radioButton_2.clicked.connect(self.teacher)
self.ui.radioButton_3.clicked.connect(self.student)
self.ui.pwd_text.returnPressed.connect(self.login)
if __name__ == '__main__':
conn = sqlite3.connect("schoolManager.db")
c = conn.cursor()
app = QApplication([])
SI.login_win = login_win()
SI.login_win.ui.show()
app.exec_()
数据库格式 schoolManager.db
写在最后
因为其他页面的代码比较多,我就以文件的形式放在最后。这个系统肯定还存在着许多BUG,目前还未进行完善,并且存在着过多的代码冗余,代码之路还有待进步,欢迎各位大佬指正。
文件链接
下载地址
|