query.exec_(sql) if (not query.next()): print(QMessageBox.warning(self, "警告", "原密码输入错误,请重新输入", QMessageBox.Yes, QMessageBox.Yes)) self.oldPasswordEdit.clear() return # 密码与确认密码不同 if(password!=confirmPassword): print(QMessageBox.warning(self,"警告","两次输入密码不同,请确认输入",QMessageBox.Yes,QMessageBox.Yes)) self.passwordEdit.clear() self.confirmPasswordEdit.clear() return # 修改密码 hl = hashlib.md5() hl.update(password.encode(encoding='utf-8')) md5password = hl.hexdigest() sql="UPDATE User SET Password='******' WHERE StudentName='%s'"%(md5password,studentId) query.exec_(sql) db.commit() QMessageBox.information(self,"提醒","修改密码成功,请登录系统!",QMessageBox.Yes,QMessageBox.Yes) self.close() return if __name__ == "__main__": app = QApplication(sys.argv) app.setWindowIcon(QIcon(res_path("images/zi.ico"))) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) mainMindow = changePasswordDialog() mainMindow.show() sys.exit(app.exec_())
def setUpUI(self): self.layout = QVBoxLayout() self.Hlayout1 = QHBoxLayout() self.Hlayout2 = QHBoxLayout() # Hlayout1控件的初始化 self.searchEdit = QLineEdit() self.searchEdit.setFixedHeight(32) font = QFont() font.setPixelSize(15) self.searchEdit.setFont(font) self.searchButton = QPushButton("查询") self.searchButton.setFixedHeight(32) self.searchButton.setFont(font) self.searchButton.setIcon(QIcon(QPixmap(res_path("images/search.png")))) self.condisionComboBox = QComboBox() searchCondision = ['按品牌查询', '按设备查询', '按型号查询','按备注查询'] # , '按入库时间查询', '按修改时间查询' self.condisionComboBox.setFixedHeight(32) self.condisionComboBox.setFont(font) self.condisionComboBox.addItems(searchCondision) self.Hlayout1.addWidget(self.searchEdit) self.Hlayout1.addWidget(self.searchButton) self.Hlayout1.addWidget(self.condisionComboBox) # Hlayout2初始化 self.jumpToLabel = QLabel("跳转到第") self.pageEdit = QLineEdit() self.pageEdit.setFixedWidth(30) s = "/" + str(self.totalPage) + "页" self.pageLabel = QLabel(s) self.jumpToButton = QPushButton("跳转") self.prevButton = QPushButton("前一页") self.prevButton.setFixedWidth(60) self.backButton = QPushButton("后一页") self.backButton.setFixedWidth(60) Hlayout = QHBoxLayout() Hlayout.addWidget(self.jumpToLabel) Hlayout.addWidget(self.pageEdit) Hlayout.addWidget(self.pageLabel) Hlayout.addWidget(self.jumpToButton) Hlayout.addWidget(self.prevButton) Hlayout.addWidget(self.backButton) widget = QWidget() widget.setLayout(Hlayout) widget.setFixedWidth(500) self.Hlayout2.addWidget(widget) # tableView # 序号,书名,书号,作者,分类,出版社,出版时间,库存,剩余可借 self.db = QSqlDatabase.addDatabase("QSQLITE") self.db.setDatabaseName('./db/AssetsManagement.db') self.db.open() self.tableView = QTableView() self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.queryModel = QSqlQueryModel() self.searchButtonClicked() self.tableView.setModel(self.queryModel) self.queryModel.setHeaderData(0, Qt.Horizontal, "序号") self.queryModel.setHeaderData(1, Qt.Horizontal, "品牌") self.queryModel.setHeaderData(2, Qt.Horizontal, "设备") self.queryModel.setHeaderData(3, Qt.Horizontal, "型号") self.queryModel.setHeaderData(4, Qt.Horizontal, "数量") self.queryModel.setHeaderData(5, Qt.Horizontal, "单位") self.queryModel.setHeaderData(6, Qt.Horizontal, "备注") self.queryModel.setHeaderData(7, Qt.Horizontal, "入库时间") self.queryModel.setHeaderData(8, Qt.Horizontal, "修改时间") # self.queryModel.setHeaderData(8, Qt.Horizontal, "总借阅次数") self.layout.addLayout(self.Hlayout1) self.layout.addWidget(self.tableView) self.layout.addLayout(self.Hlayout2) self.setLayout(self.layout) self.searchButton.clicked.connect(self.searchButtonClicked) self.prevButton.clicked.connect(self.prevButtonClicked) self.backButton.clicked.connect(self.backButtonClicked) self.jumpToButton.clicked.connect(self.jumpToButtonClicked) self.searchEdit.returnPressed.connect(self.searchButtonClicked)