1 鱼币
登录页面代码:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import qdarkstyle
import hashlib
from db.db import DB
class SignInWidget(QWidget):
is_admin_signal = pyqtSignal()
is_student_signal = pyqtSignal(str)
def __init__(self):
super(SignInWidget, self).__init__()
self.resize(900, 600)
self.setWindowTitle("图书馆管理系统")
self.setUpUI()
def setUpUI(self):
self.Vlayout = QVBoxLayout(self)
self.Hlayout1 = QHBoxLayout()
self.Hlayout2 = QHBoxLayout()
self.formlayout = QFormLayout()
self.label1 = QLabel("学号: ")
labelFont = QFont()
labelFont.setPixelSize(18)
lineEditFont = QFont()
lineEditFont.setPixelSize(16)
self.label1.setFont(labelFont)
self.lineEdit1 = QLineEdit()
self.lineEdit1.setFixedHeight(32)
self.lineEdit1.setFixedWidth(200)
self.lineEdit1.setFont(lineEditFont)
self.lineEdit1.setMaxLength(16)
self.formlayout.addRow(self.label1, self.lineEdit1)
self.label2 = QLabel("密码: ")
self.label2.setFont(labelFont)
self.lineEdit2 = QLineEdit()
self.lineEdit2.setFixedHeight(32)
self.lineEdit2.setFixedWidth(200)
self.lineEdit2.setMaxLength(16)
# 设置验证
reg = QRegExp("PB[0~9]{8}")
pValidator = QRegExpValidator(self)
pValidator.setRegExp(reg)
self.lineEdit1.setValidator(pValidator)
reg = QRegExp("[a-zA-z0-9]+$")
pValidator.setRegExp(reg)
self.lineEdit2.setValidator(pValidator)
passwordFont = QFont()
passwordFont.setPixelSize(10)
self.lineEdit2.setFont(passwordFont)
self.lineEdit2.setEchoMode(QLineEdit.Password)
self.formlayout.addRow(self.label2, self.lineEdit2)
self.signIn = QPushButton("登 录")
self.signIn.setFixedWidth(160)
self.signIn.setFixedHeight(40)
self.signIn.setFont(labelFont)
self.formlayout.addRow("", self.signIn)
self.label = QLabel("图书管理系统")
fontlabel = QFont()
fontlabel.setPixelSize(30)
self.label.setFixedWidth(200)
# self.label.setFixedHeight(80)
self.label.setFont(fontlabel)
self.Hlayout1.addWidget(self.label, Qt.AlignCenter)
self.widget1 = QWidget()
self.widget1.setLayout(self.Hlayout1)
self.widget2 = QWidget()
self.widget2.setFixedWidth(300)
self.widget2.setFixedHeight(150)
self.widget2.setLayout(self.formlayout)
self.Hlayout2.addWidget(self.widget2, Qt.AlignCenter)
self.widget = QWidget()
self.widget.setLayout(self.Hlayout2)
self.Vlayout.addWidget(self.widget1)
self.Vlayout.addWidget(self.widget, Qt.AlignTop)
self.signIn.clicked.connect(self.signInCheck)
self.lineEdit2.returnPressed.connect(self.signInCheck)
self.lineEdit1.returnPressed.connect(self.signInCheck)
def signInCheck(self):
number_Id = self.lineEdit1.text()
password = self.lineEdit2.text()
if number_Id == "" or password == "":
print(QMessageBox.warning(self, "警告", "学号和密码不可为空!", QMessageBox.Yes, QMessageBox.Yes))
return
# 打开数据库连接
db = DB()
count, res = db.query_super(table_name='user', column_name='StudentId', condition=number_Id)
print(count, res)
hash = hashlib.md5()
hash.update(password.encode(encoding='utf-8'))
if count == 0:
print(QMessageBox.information(self, "提示", "该账号不存在!", QMessageBox.Yes, QMessageBox.Yes))
else:
if number_Id == res[0][1] and hash.hexdigest() == res[0][3]:
if res[0][4] == '0':
self.is_admin_signal.emit()
else:
self.is_student_signal.emit(number_Id)
else:
print(QMessageBox.information(self, "提示", "密码错误!", QMessageBox.Yes, QMessageBox.Yes))
return
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/MainWindow_1.png"))
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
mainMindow = SignInWidget()
mainMindow.show()
sys.exit(app.exec_())
复制代码 学生主页:
管理员主页:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import qdarkstyle
from addBookDialog import addBookDialog
from dropBookDialog import dropBookDialog
from BookStorageViewer import BookStorageViewer
from UserManage import UserManage
class AdminHome(QWidget):
def __init__(self):
super().__init__()
self.setUpUI()
def setUpUI(self):
self.resize(900, 600)
self.setWindowTitle("欢迎使用图书馆管理系统")
self.layout = QHBoxLayout()
self.buttonlayout = QVBoxLayout()
self.setLayout(self.layout)
font = QFont()
font.setPixelSize(16)
self.userManageButton = QPushButton("用户管理")
self.addBookButton = QPushButton("添加书籍")
self.dropBookButton = QPushButton("淘汰书籍")
self.userManageButton.setFont(font)
self.addBookButton.setFont(font)
self.dropBookButton.setFont(font)
self.userManageButton.setFixedWidth(100)
self.userManageButton.setFixedHeight(42)
self.addBookButton.setFixedWidth(100)
self.addBookButton.setFixedHeight(42)
self.dropBookButton.setFixedWidth(100)
self.dropBookButton.setFixedHeight(42)
self.buttonlayout.addWidget(self.addBookButton)
self.buttonlayout.addWidget(self.dropBookButton)
self.buttonlayout.addWidget(self.userManageButton)
self.layout.addLayout(self.buttonlayout)
self.storageView = BookStorageViewer()
self.layout.addWidget(self.storageView)
self.addBookButton.clicked.connect(self.addBookButtonClicked)
self.dropBookButton.clicked.connect(self.dropBookButtonClicked)
self.userManageButton.clicked.connect(self.userManage)
def addBookButtonClicked(self):
addDialog = addBookDialog(self)
addDialog.add_book_success_signal.connect(self.storageView.searchButtonClicked)
addDialog.show()
addDialog.exec_()
def dropBookButtonClicked(self):
dropDialog = dropBookDialog(self)
dropDialog.drop_book_successful_signal.connect(self.storageView.searchButtonClicked)
dropDialog.show()
dropDialog.exec_()
def userManage(self):
UserDelete = UserManage(self)
UserDelete.show()
UserDelete.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/MainWindow_1.png"))
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
mainMindow = AdminHome()
mainMindow.show()
sys.exit(app.exec_())
复制代码 数据库文件:
CREATE TABLE `user` (
`id` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`StudentId` varchar(16) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`Name` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`Password` char(32) COLLATE utf8_unicode_ci NOT NULL,
`IsAdmin` bit(1) NOT NULL DEFAULT b'0',
`TimesBorrowed` int(11) NOT NULL DEFAULT '0',
`NumBorrowed` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Unique_studentID` (`StudentId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('01aa6e87-eefc-41b6-8627-f426e75cb2d1', '201725210151', 'admin', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '0');
如何在登录页面登录成功后,跳转到其它两个页面;
我来回答