├── .idea ├── dictionaries │ └── zyh.xml ├── sqldialects.xml └── vcs.xml ├── README.md ├── UI image ├── code ├── DatabaseCourseDesign.py └── pyqt │ └── bookshop │ ├── 1.jpg │ ├── BookShopSystem.py │ ├── Insert_delreader.py │ ├── Insert_delreader.ui │ ├── Insert_return.py │ ├── Insert_return.ui │ ├── Insertbook.py │ ├── Insertdel.py │ ├── Insertdel.ui │ ├── Insertpurchase.py │ ├── Insertpurchase.ui │ ├── Insertsell.py │ ├── Insertsell.ui │ ├── LoginUI.py │ ├── LoginUI.ui │ ├── admin.txt │ ├── admin_window.py │ ├── admin_window.ui │ ├── deleteEmployee.py │ ├── deleteEmployee.ui │ ├── deletebook.ui │ ├── employee.txt │ ├── getBookInfo.ui │ ├── insert_addreader.py │ ├── insert_addreader.ui │ ├── insert_employee.py │ ├── insert_employee.ui │ ├── searchbook.py │ ├── searchbook.ui │ ├── searchborrowAndreturn.py │ ├── searchborrowAndreturn.ui │ ├── searchreader.py │ ├── searchreader.ui │ ├── tableDefinition.txt │ ├── user_window.py │ ├── user_window_test.py │ ├── user_window_test_1.py │ ├── user_window_test_2.py │ └── user_window_test_2.ui └── 书店管理系统开发文档.md /.idea/dictionaries/zyh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ndarray 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/sqldialects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Database_courseDesign 2 | bookshop system 3 | ## settings 4 | pycharm2020、MySQL、PyqtDesigner、python3.8 5 | ## attention 6 | 1.databasecoursedesign是没有UI界面的书店管理系统,可直接下载运行,当然前提是有相关数据库 7 | 8 | ~~2.路径pyqt/bookshop是有UI界面的书店管理系统,暂时还在开发中(2020/7/11)~~ 9 | 2.UI界面完成设计(2020/7/19) 10 | 3.后续完善和异常处理就要看心情了 11 | 12 | 13 | lastupdate 2020/12/14 14 | 在csdn上有很多小伙伴跟我进行了一些讨论,也指出了我代码中的一些不足之处,都进行了修改 15 | 现在再回头看看发现自己写的代码~~惨不忍睹~~,没有一点规范和良好的命名规范,这也导致了一些小伙伴的苦恼 16 | 17 | 18 | 首先是程序运行:从LoginUI.py运行,然后输入用户名和密码并且选择相应的操作来进行 19 | 管理员还是一般用户的操作,然后登陆到界面进行操作。 20 | 21 | 常见bug及修复 22 | 1. 无法运行程序 23 | 解决:程序目录下要有相应的用户存储文件,分别为admin.txt和user.txt 24 | 25 | 2. 进行用户操作(像查询书籍等等)就卡死 26 | 解决:在pycharm中(目前只有pycharm出现此问题)配置数据库连接,先进行连接再运行程序 27 | 28 | 3. 无法对书籍进行操作 29 | 解决:在ER设计时,可以想象有个全国图书库里面放着所有正版书籍,书店里面也许没有一些书,但是有的书籍必须在图书库里面可以 30 | 索引到,所以**想进行书籍操作(特别是购入书籍)就必须确保要操作的书籍在图书库中,也就是说要先进行添加书籍信息这个按钮的操作** 31 | 32 | 4. **必须要修改的部分** 33 | ```python 34 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 35 | user='root') 36 | ``` 37 | 要将其中参数改为自己数据库参数,这里当初没有进行工具类的创建,现在知道了也懒得搞了 38 | 39 | 40 | -------------------------------------------------------------------------------- /UI image: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /code/DatabaseCourseDesign.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:UTF-8 _*_ 2 | # 开发人员:zyh 3 | # 开发时间:2020/6/13 20:30 4 | # 文件名:DatabaseCourseDesign.py 5 | # 开发工具:PyCharm 6 | import datetime 7 | from pymysql import * 8 | import json 9 | 10 | 11 | class BasicSqlOperation(object): 12 | def __init__(self): 13 | # 打开数据库连接 14 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 15 | user='root') 16 | # 创建游标对象 17 | self.cursor = self.db.cursor() 18 | sql = "use bookshopmanagement" 19 | self.cursor.execute(sql) 20 | 21 | def showAllTables(self): 22 | sql = "show tables" 23 | try: 24 | # 执行数据库操作 25 | self.cursor.execute(sql) 26 | # 处理结果 27 | data = self.cursor.fetchall() 28 | for i in data: 29 | print(i) 30 | except Exception as err: 31 | print("SQL执行错误,原因:", err) 32 | 33 | def execute_sql(self, sql): 34 | try: 35 | # 执行数据库操作 36 | self.cursor.execute(sql) 37 | # 事务提交 38 | self.db.commit() 39 | except Exception as err: 40 | # 事务回滚 41 | self.db.rollback() 42 | print("SQL执行错误,原因:", err) 43 | 44 | def FindAll(self): 45 | # 实例变量 46 | table_name = input("table name") 47 | # 定义SQL语句 48 | sql = "select * from %s" % table_name 49 | try: 50 | # 执行数据库操作 51 | self.cursor.execute(sql) 52 | # 处理结果 53 | data = self.cursor.fetchall() 54 | for i in data: 55 | print(i) 56 | except Exception as err: 57 | print("SQL执行错误,原因:", err) 58 | 59 | def Insert_purchase(self): 60 | # 实例变量 61 | isbn = input("isbn") 62 | price = int(input("price")) 63 | purchase_num = int(input("num")) 64 | # 定义SQL语句 65 | sql = "insert into purchasebook(isbn, price, purchasenum) values('%s','%d','%d')" % \ 66 | (isbn, price, purchase_num) 67 | self.execute_sql(sql) 68 | 69 | def Insert_reader(self): 70 | reader_id = int(input("readerid")) 71 | reader_name = input("name") 72 | sex = input("sex (男 or 女)") 73 | age = int(input("age")) 74 | tel = input("tel") 75 | sql = "insert into reader(readerid, readername, sex, age, tel) values('%d','%s','%s','%d','%s')" % ( 76 | reader_id, reader_name, sex, age, tel) 77 | self.execute_sql(sql) 78 | 79 | def Insert_book(self): 80 | # 实例变量 81 | ISBN = input("ISBN:") 82 | bookname = input("bookname") 83 | author = input("author") 84 | price = int(input("proce")) 85 | # 定义SQL语句 86 | sql = "insert into book(ISBN, bookname, author, price) values('%s','%s','%s','%d')" % ( 87 | ISBN, bookname, author, price) 88 | self.execute_sql(sql) 89 | 90 | def Insert_borrow(self): 91 | # 实例变量 92 | borrow_time = datetime.datetime.now().strftime("%Y-%m-%d") 93 | reader_id = input("readerId") 94 | ISBN = input("ISBN:") 95 | # 定义SQL语句 96 | sql = "insert into borrow(BorrowTime, ReaderID, ISBN) values('%s','%s','%s')" % ( 97 | borrow_time, reader_id, ISBN) 98 | self.execute_sql(sql) 99 | 100 | def Insert_collectionofbook(self): 101 | # 实例变量 102 | isbn = input("isbn") 103 | total_num = int(input("totalnum")) 104 | # 定义SQL语句 105 | sql = "insert into collectionofbook(ISBN, totalnum) values('%s','%d')" % ( 106 | isbn, total_num) 107 | self.execute_sql(sql) 108 | 109 | def Insert_return(self): 110 | # 实例变量 111 | return_time = datetime.datetime.now().strftime("%Y-%m-%d") 112 | reader_id = input("reader_id") 113 | isbn = input("isbn") 114 | # 定义SQL语句 115 | sql = "insert into returnofbook(returntime, readerid, isbn) values('%s', '%s','%s')" % ( 116 | return_time, reader_id, isbn) 117 | self.execute_sql(sql) 118 | 119 | def Insert_sell(self): 120 | # 实例变量 121 | isbn = input("isbn") 122 | already_sold = int(input("alreadysold")) 123 | price = int(input("price")) 124 | # 定义SQL语句 125 | sql = "insert into sell(isbn, price, AlreadySold) values('%s','%d','%d')" % \ 126 | (isbn, price, already_sold) 127 | self.execute_sql(sql) 128 | 129 | def del_reader(self): 130 | reader_id = int(input("reader_id")) 131 | sql = "delete from reader where readerid = " + str(reader_id) 132 | self.execute_sql(sql) 133 | 134 | # 用析构函数实现数据库关闭 135 | def __del__(self): 136 | # 关闭数据库连接 137 | self.db.close() 138 | 139 | 140 | class SqlOperation(BasicSqlOperation): 141 | def __init__(self): 142 | super().__init__() 143 | 144 | def drop_table(self): 145 | table_name = input("tablename") 146 | sql = "drop table " + table_name 147 | self.execute_sql(sql) 148 | 149 | def Insert_employee(self): 150 | # 实例变量 151 | employee_id = int(input("employeeID")) 152 | employee_name = input("name") 153 | employee_sex = input("sex (男 or 女)") 154 | employee_age = int(input("age")) 155 | employee_tel = input("tel") 156 | employee_salary = int(input("salary")) 157 | # 定义SQL语句 158 | sql = "insert into employee(employeeid, employname, employsex, employage, employtel, salary) " \ 159 | "values('%d','%s','%s','%d','%s','%d')" % \ 160 | (employee_id, employee_name, employee_sex, employee_age, employee_tel, employee_salary) 161 | self.execute_sql(sql) 162 | 163 | # 定义删除表数据函数 164 | def Del(self): 165 | # 实例变量 166 | table_name = input("table_name") 167 | # 定义SQL语句 168 | sql = "drop table table " + table_name 169 | self.execute_sql(sql) 170 | 171 | # 定义修改表数据函数 172 | def Update_empolyee(self): 173 | employee_id = int(input("employeeID")) 174 | employee_name = input("name") 175 | employee_sex = input("sex (男 or 女)") 176 | employee_age = int(input("age")) 177 | employee_tel = input("tel") 178 | employee_salary = int(input("salary")) 179 | sql = "update employee set EmployTEL=%s,Salary=%d where EmployeeID = %d" % \ 180 | (employee_tel, employee_salary, employee_id) 181 | self.execute_sql(sql) 182 | 183 | def del_employee(self): 184 | employeeid = int(input("employeeid")) 185 | sql = "delete from employee where employeeid = " + str(employeeid) 186 | self.execute_sql(sql) 187 | 188 | 189 | def login(bookshop_admin, bookshop_employee): 190 | user_id = input("user_id") 191 | user_password = input("password") 192 | if user_id in bookshop_admin.keys(): 193 | if bookshop_admin[user_id] == user_password: 194 | return sql_execute(1) 195 | 196 | elif user_id in bookshop_employee.keys(): 197 | if bookshop_employee[user_id] == user_password: 198 | return sql_execute(2) 199 | 200 | else: 201 | print("no such account") 202 | return 0 203 | 204 | 205 | def addUser(bookshop_admin, bookshop_employee): 206 | choice = int(input("admin 1 employee 2")) 207 | if choice is 1: 208 | id = input("id") 209 | password = input("password") 210 | 211 | bookshop_admin[id] = password 212 | 213 | else: 214 | print(bookshop_employee) 215 | id = input("id") 216 | password = input("password") 217 | bookshop_employee[id] = password 218 | print(bookshop_employee) 219 | 220 | 221 | def delUser(bookshop_admin, bookshop_empolee): 222 | choice = int(input("admin 1 employee 2")) 223 | if choice is 1: 224 | id = input("id") 225 | del bookshop_admin[id] 226 | else: 227 | id = input("id") 228 | del bookshop_empolee[id] 229 | 230 | 231 | def sql_execute(priority): 232 | if priority is 1: 233 | print("admin login in success") 234 | return 1 235 | else: 236 | print("employee login in success") 237 | return 2 238 | 239 | 240 | def function_choice_employee(): 241 | continue_flag = True 242 | employee = BasicSqlOperation() 243 | while continue_flag: 244 | print("查看所有列表 1") 245 | print("查看某个表信息 2") 246 | print("添加读者 3") 247 | print("删除读者 4") 248 | print("添加借阅 5") 249 | print("添加还书 6") 250 | print("购入书籍 7") 251 | print("卖出书籍 8") 252 | print("添加新出版书籍 9") 253 | choice = int(input("enter your choice")) 254 | if choice is 1: 255 | employee.showAllTables() 256 | elif choice is 2: 257 | employee.FindAll(input("table name")) 258 | elif choice is 3: 259 | employee.Insert_reader() 260 | elif choice is 4: 261 | employee.del_reader() 262 | elif choice is 5: 263 | employee.Insert_borrow() 264 | elif choice is 6: 265 | employee.Insert_return() 266 | elif choice is 7: 267 | employee.Insert_purchase() 268 | elif choice is 8: 269 | employee.Insert_sell() 270 | elif choice is 9: 271 | employee.Insert_book() 272 | else: 273 | print("error") 274 | 275 | continue_flag = input("continue? True or False") 276 | 277 | 278 | def function_choice_admin(bookshop_admin, bookshop_employee): 279 | continue_flag = 1 280 | admin = SqlOperation() 281 | while continue_flag is 1: 282 | print("查看所有列表 1") 283 | print("查看某个表信息 2") 284 | print("添加读者 3") 285 | print("删除读者 4") 286 | print("添加借阅 5") 287 | print("添加还书 6") 288 | print("添加雇员 7") 289 | print("删除雇员 8") 290 | print("购入书籍 9") 291 | print("卖出书籍 10") 292 | print("增加操作用户 11") 293 | print("删除操作用户 12") 294 | print("修改员工信息 13") 295 | print("添加新出版信息 14") 296 | 297 | choice = int(input("enter your choice")) 298 | if choice is 1: 299 | admin.showAllTables() 300 | elif choice is 2: 301 | admin.FindAll() 302 | elif choice is 3: 303 | admin.Insert_reader() 304 | elif choice is 4: 305 | admin.del_reader() 306 | elif choice is 5: 307 | admin.Insert_borrow() 308 | elif choice is 6: 309 | admin.Insert_return() 310 | elif choice is 9: 311 | admin.Insert_purchase() 312 | elif choice is 10: 313 | admin.Insert_sell() 314 | elif choice is 8: 315 | admin.del_employee() 316 | elif choice is 7: 317 | admin.Insert_employee() 318 | elif choice is 11: 319 | addUser(bookshop_admin, bookshop_employee) 320 | elif choice is 12: 321 | delUser(bookshop_admin, bookshop_employee) 322 | elif choice is 13: 323 | admin.Update_empolyee() 324 | elif choice is 14: 325 | admin.Insert_book() 326 | else: 327 | print("error") 328 | 329 | continue_flag = int(input("continue? 1 continue or 0 end")) 330 | 331 | 332 | def main(): 333 | """read the id and password from txt which is saved in json""" 334 | file_name_1 = r"admin.txt" 335 | file_name_2 = r"employee.txt" 336 | 337 | with open(file_name_1, "r") as f: 338 | js = f.read() 339 | bookshop_admin = json.loads(js) 340 | f.close() 341 | 342 | with open(file_name_2, "r") as f: 343 | js = f.read() 344 | bookshop_employee = json.loads(js) 345 | f.close() 346 | # print(bookshop_employee) 347 | """login() function will return the priority admin user is 1, employee user is 2 and no such account is 0""" 348 | priority = login(bookshop_admin, bookshop_employee) 349 | if priority is 1: 350 | function_choice_admin(bookshop_admin, bookshop_employee) 351 | elif priority is 2: 352 | function_choice_employee() 353 | elif priority is 0: 354 | print("log in failed") 355 | 356 | jsOBJ = json.dumps(bookshop_admin) 357 | with open(file_name_1, "w") as f: 358 | f.write(jsOBJ) 359 | f.close() 360 | 361 | jsOBJ = json.dumps(bookshop_employee) 362 | with open(file_name_2, "w") as f: 363 | f.write(jsOBJ) 364 | f.close() 365 | 366 | 367 | if __name__ == '__main__': 368 | main() 369 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyhsna/Database_courseDesign/cc2b53f697d31697aec939b978895c920e24cac8/code/pyqt/bookshop/1.jpg -------------------------------------------------------------------------------- /code/pyqt/bookshop/BookShopSystem.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:UTF-8 _*_ 2 | # 开发人员:zyh 3 | # 开发时间:2020/7/4 22:37 4 | # 文件名:BookShopSystem.py 5 | # 开发工具: 6 | 7 | from LoginUI import * 8 | from LoginUI import userWindow 9 | from user_window import User_MainWindow 10 | import sys 11 | 12 | from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget 13 | 14 | class Login(QMainWindow): 15 | def __init__(self): 16 | QMainWindow.__init__(self) 17 | self.UI = Ui_MainWindow() 18 | user = userWindow() 19 | self.UI.setupUi(self) 20 | 21 | 22 | if __name__ == '__main__': 23 | app = QApplication(sys.argv) 24 | mainWindow = Login() 25 | mainWindow.show() 26 | sys.exit(app.exec_()) 27 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insert_delreader.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | 5 | from PyQt5 import QtCore, QtGui, QtWidgets 6 | from pymysql import * 7 | 8 | class Ui_delreader(object): 9 | def execute_sql(self, sql): 10 | try: 11 | # 执行数据库操作 12 | self.cursor.execute(sql) 13 | # 事务提交 14 | self.db.commit() 15 | except Exception as err: 16 | # 事务回滚 17 | print("hello err") 18 | self.db.rollback() 19 | print("SQL执行错误,原因:", err) 20 | 21 | def setupUi(self, Form): 22 | Form.setObjectName("Form") 23 | Form.resize(565, 351) 24 | self.pushButton_2 = QtWidgets.QPushButton(Form) 25 | self.pushButton_2.setGeometry(QtCore.QRect(130, 220, 93, 28)) 26 | self.pushButton_2.setObjectName("pushButton_2") 27 | self.pushButton_3 = QtWidgets.QPushButton(Form) 28 | self.pushButton_3.setGeometry(QtCore.QRect(350, 220, 93, 28)) 29 | self.pushButton_3.setObjectName("pushButton_3") 30 | self.widget = QtWidgets.QWidget(Form) 31 | self.widget.setGeometry(QtCore.QRect(120, 110, 341, 30)) 32 | self.widget.setObjectName("widget") 33 | self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget) 34 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 35 | self.horizontalLayout.setObjectName("horizontalLayout") 36 | self.label = QtWidgets.QLabel(self.widget) 37 | self.label.setObjectName("label") 38 | self.horizontalLayout.addWidget(self.label) 39 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 40 | self.lineEdit.setObjectName("lineEdit") 41 | self.horizontalLayout.addWidget(self.lineEdit) 42 | self.pushButton = QtWidgets.QPushButton(self.widget) 43 | self.pushButton.setObjectName("pushButton") 44 | self.horizontalLayout.addWidget(self.pushButton) 45 | 46 | self.statusbar = QtWidgets.QStatusBar(Form) 47 | self.statusbar.setObjectName("statusbar") 48 | Form.setStatusBar(self.statusbar) 49 | 50 | self.retranslateUi(Form) 51 | self.pushButton.clicked.connect(self.lineEdit.clear) 52 | self.pushButton_3.clicked.connect(Form.close) 53 | QtCore.QMetaObject.connectSlotsByName(Form) 54 | 55 | self.pushButton_2.clicked.connect(lambda: self.delreader()) 56 | def retranslateUi(self, Form): 57 | _translate = QtCore.QCoreApplication.translate 58 | Form.setWindowTitle(_translate("Form", "删除读者")) 59 | self.pushButton_2.setText(_translate("Form", "确认")) 60 | self.pushButton_3.setText(_translate("Form", "退出")) 61 | self.label.setText(_translate("Form", "借阅证ID")) 62 | self.pushButton.setText(_translate("Form", "清空")) 63 | 64 | def delreader(self): 65 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 66 | user='root') 67 | # 创建游标对象 68 | self.cursor = self.db.cursor() 69 | 70 | sql = "use bookshopmanagement" 71 | self.cursor.execute(sql) 72 | 73 | sql = "SELECT * FROM reader" 74 | self.cursor.execute(sql) 75 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 76 | data = self.cursor.fetchall() 77 | original_row = len(data) 78 | id = self.lineEdit.text() 79 | sql = "delete from reader where ReaderID = '%d' " % int(id) 80 | self.execute_sql(sql) 81 | sql = "SELECT * FROM reader" 82 | 83 | self.cursor.execute(sql) 84 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 85 | new_data = self.cursor.fetchall() 86 | new_row = len(new_data) 87 | if new_row == original_row-1: 88 | self.statusbar.showMessage("删除成功,请返回刷新", 2000) 89 | else: 90 | self.statusbar.showMessage("删除失败,请返回刷新", 2000) -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insert_delreader.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 565 10 | 351 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 130 20 | 220 21 | 93 22 | 28 23 | 24 | 25 | 26 | 确认 27 | 28 | 29 | 30 | 31 | 32 | 350 33 | 220 34 | 93 35 | 28 36 | 37 | 38 | 39 | 退出 40 | 41 | 42 | 43 | 44 | 45 | 120 46 | 110 47 | 341 48 | 30 49 | 50 | 51 | 52 | 53 | 54 | 55 | 借阅证ID 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 清空 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | pushButton 76 | clicked() 77 | lineEdit 78 | clear() 79 | 80 | 81 | 401 82 | 119 83 | 84 | 85 | 337 86 | 123 87 | 88 | 89 | 90 | 91 | pushButton_3 92 | clicked() 93 | Form 94 | close() 95 | 96 | 97 | 402 98 | 233 99 | 100 | 101 | 557 102 | 276 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insert_return.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'Insert_return.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | import datetime 10 | import sys 11 | 12 | from PyQt5 import QtCore, QtGui, QtWidgets 13 | from PyQt5.QtWidgets import QApplication 14 | from pymysql import * 15 | 16 | 17 | class Ui_InsertReturnAndBorrow(object): 18 | def execute_sql(self, sql): 19 | try: 20 | # 执行数据库操作 21 | self.cursor.execute(sql) 22 | # 事务提交 23 | self.db.commit() 24 | except Exception as err: 25 | # 事务回滚 26 | self.db.rollback() 27 | print("SQL执行错误,原因:", err) 28 | 29 | def setupUi(self, Form): 30 | self.priority = 0 31 | Form.setObjectName("Form") 32 | Form.resize(593, 409) 33 | self.pushButton = QtWidgets.QPushButton(Form) 34 | self.pushButton.setGeometry(QtCore.QRect(450, 100, 93, 28)) 35 | self.pushButton.setObjectName("pushButton") 36 | self.pushButton_2 = QtWidgets.QPushButton(Form) 37 | self.pushButton_2.setGeometry(QtCore.QRect(100, 300, 93, 28)) 38 | self.pushButton_2.setObjectName("pushButton_2") 39 | self.pushButton_3 = QtWidgets.QPushButton(Form) 40 | self.pushButton_3.setGeometry(QtCore.QRect(310, 300, 93, 28)) 41 | self.pushButton_3.setObjectName("pushButton_3") 42 | self.radioButton = QtWidgets.QRadioButton(Form) 43 | self.radioButton.setGeometry(QtCore.QRect(110, 250, 115, 19)) 44 | self.radioButton.setObjectName("radioButton") 45 | self.radioButton_2 = QtWidgets.QRadioButton(Form) 46 | self.radioButton_2.setGeometry(QtCore.QRect(310, 250, 115, 19)) 47 | self.radioButton_2.setObjectName("radioButton_2") 48 | self.widget = QtWidgets.QWidget(Form) 49 | self.widget.setGeometry(QtCore.QRect(100, 70, 291, 151)) 50 | self.widget.setObjectName("widget") 51 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 52 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 53 | self.gridLayout.setObjectName("gridLayout") 54 | self.return_2 = QtWidgets.QLabel(self.widget) 55 | self.return_2.setObjectName("return_2") 56 | self.gridLayout.addWidget(self.return_2, 0, 0, 1, 1) 57 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 58 | self.lineEdit.setObjectName("lineEdit") 59 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 60 | self.label_2 = QtWidgets.QLabel(self.widget) 61 | self.label_2.setObjectName("label_2") 62 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 63 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 64 | self.lineEdit_2.setObjectName("lineEdit_2") 65 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 66 | self.statusbar = QtWidgets.QStatusBar(Form) 67 | self.statusbar.setObjectName("statusbar") 68 | Form.setStatusBar(self.statusbar) 69 | 70 | 71 | 72 | 73 | self.retranslateUi(Form) 74 | self.pushButton.clicked.connect(self.lineEdit.clear) 75 | self.pushButton.clicked.connect(self.lineEdit_2.clear) 76 | self.pushButton_3.clicked.connect(Form.close) 77 | QtCore.QMetaObject.connectSlotsByName(Form) 78 | self.radioButton.clicked.connect(lambda:self.Choose_borrow()) 79 | self.radioButton_2.clicked.connect(lambda: self.Choose_return()) 80 | self.pushButton_2.clicked.connect(lambda: self.insert_borrowAndReturn()) 81 | 82 | 83 | def retranslateUi(self, Form): 84 | _translate = QtCore.QCoreApplication.translate 85 | Form.setWindowTitle(_translate("Form", "Form")) 86 | self.pushButton.setText(_translate("Form", "清空")) 87 | self.pushButton_2.setText(_translate("Form", "确认")) 88 | self.pushButton_3.setText(_translate("Form", "退出")) 89 | self.radioButton.setText(_translate("Form", "借书")) 90 | self.radioButton_2.setText(_translate("Form", "还书")) 91 | self.return_2.setText(_translate("Form", "借阅证ID")) 92 | self.label_2.setText(_translate("Form", "ISBN")) 93 | 94 | 95 | def insert_borrowAndReturn(self): 96 | borrow_time = datetime.datetime.now().strftime("%Y-%m-%d") 97 | reader_id = self.lineEdit.text() 98 | ISBN = self.lineEdit_2.text() 99 | # 定义SQL语句 100 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 101 | user='root') 102 | # 创建游标对象 103 | self.cursor = self.db.cursor() 104 | sql = "use bookshopmanagement" 105 | self.cursor.execute(sql) 106 | if self.priority is 0: 107 | self.statusbar.showMessage("请选择操作", 2000) 108 | print("capzuo") 109 | elif self.priority is 1: 110 | 111 | sql = "insert into borrow(BorrowTime, ReaderID, ISBN) values('%s','%d','%s')" % ( 112 | borrow_time, int(reader_id), ISBN) 113 | self.execute_sql(sql) 114 | else: 115 | return_time = datetime.datetime.now().strftime("%Y-%m-%d") 116 | # 定义SQL语句 117 | sql = "insert into returnofbook(returntime, readerid, isbn) values('%s', '%s','%s')" % ( 118 | return_time, int(reader_id), ISBN) 119 | self.execute_sql(sql) 120 | 121 | 122 | def Choose_borrow(self): 123 | self.priority = 1 # 借书 124 | self.statusbar.showMessage("借书", 2000) 125 | def Choose_return(self): 126 | self.priority = 2 # 还书 127 | self.statusbar.showMessage("还书", 2000) 128 | 129 | if __name__ == '__main__': 130 | # db = QtSql.QSqlDatabase.addDatabase('QMYSQL') 131 | # db.setPort(3306) 132 | # db.setHostName('localhost') 133 | # db.setDatabaseName('bookshopmanagement') 134 | # db.setUserName('root') 135 | # db.setPassword('zyh20000205') 136 | 137 | # print(db.open()) 138 | 139 | app = QApplication(sys.argv) 140 | mainWindow = QtWidgets.QMainWindow() 141 | test_ui = Ui_InsertReturnAndBorrow() 142 | test_ui.setupUi(mainWindow) 143 | mainWindow.show() 144 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insert_return.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 593 10 | 409 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 450 20 | 100 21 | 93 22 | 28 23 | 24 | 25 | 26 | 清空 27 | 28 | 29 | 30 | 31 | 32 | 100 33 | 300 34 | 93 35 | 28 36 | 37 | 38 | 39 | 确认 40 | 41 | 42 | 43 | 44 | 45 | 310 46 | 300 47 | 93 48 | 28 49 | 50 | 51 | 52 | 退出 53 | 54 | 55 | 56 | 57 | 58 | 110 59 | 250 60 | 115 61 | 19 62 | 63 | 64 | 65 | 借书 66 | 67 | 68 | 69 | 70 | 71 | 310 72 | 250 73 | 115 74 | 19 75 | 76 | 77 | 78 | 还书 79 | 80 | 81 | 82 | 83 | 84 | 100 85 | 70 86 | 291 87 | 151 88 | 89 | 90 | 91 | 92 | 93 | 94 | 借阅证ID 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | ISBN 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | pushButton 118 | clicked() 119 | lineEdit 120 | clear() 121 | 122 | 123 | 454 124 | 109 125 | 126 | 127 | 318 128 | 113 129 | 130 | 131 | 132 | 133 | pushButton 134 | clicked() 135 | lineEdit_2 136 | clear() 137 | 138 | 139 | 534 140 | 115 141 | 142 | 143 | 381 144 | 180 145 | 146 | 147 | 148 | 149 | pushButton_3 150 | clicked() 151 | Form 152 | close() 153 | 154 | 155 | 396 156 | 288 157 | 158 | 159 | 501 160 | 259 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertbook.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from pymysql import * 5 | from PyQt5 import QtCore, QtGui, QtWidgets 6 | from PyQt5.QtWidgets import QApplication 7 | 8 | 9 | class Ui_InputBookinfo(object): 10 | def execute_sql(self, sql): 11 | try: 12 | # 执行数据库操作 13 | self.cursor.execute(sql) 14 | # 事务提交 15 | self.db.commit() 16 | except Exception as err: 17 | # 事务回滚 18 | self.db.rollback() 19 | print("SQL执行错误,原因:", err) 20 | 21 | def setupUi(self, InputBookinfo): 22 | InputBookinfo.setObjectName("InputBookinfo") 23 | InputBookinfo.resize(516, 326) 24 | self.pushButton_2 = QtWidgets.QPushButton(InputBookinfo) 25 | self.pushButton_2.setGeometry(QtCore.QRect(400, 64, 81, 31)) 26 | self.pushButton_2.setObjectName("pushButton_2") 27 | self.widget = QtWidgets.QWidget(InputBookinfo) 28 | self.widget.setGeometry(QtCore.QRect(80, 230, 301, 31)) 29 | self.widget.setObjectName("widget") 30 | self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget) 31 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 32 | self.horizontalLayout.setObjectName("horizontalLayout") 33 | self.pushButton = QtWidgets.QPushButton(self.widget) 34 | self.pushButton.setObjectName("pushButton") 35 | self.horizontalLayout.addWidget(self.pushButton) 36 | self.pushButton_3 = QtWidgets.QPushButton(self.widget) 37 | self.pushButton_3.setObjectName("pushButton_3") 38 | self.horizontalLayout.addWidget(self.pushButton_3) 39 | self.widget1 = QtWidgets.QWidget(InputBookinfo) 40 | self.widget1.setGeometry(QtCore.QRect(90, 60, 291, 151)) 41 | self.widget1.setObjectName("widget1") 42 | self.gridLayout = QtWidgets.QGridLayout(self.widget1) 43 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 44 | self.gridLayout.setObjectName("gridLayout") 45 | self.label = QtWidgets.QLabel(self.widget1) 46 | self.label.setObjectName("label") 47 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 48 | self.lineEdit = QtWidgets.QLineEdit(self.widget1) 49 | self.lineEdit.setObjectName("lineEdit") 50 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 51 | self.label_2 = QtWidgets.QLabel(self.widget1) 52 | self.label_2.setObjectName("label_2") 53 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 54 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget1) 55 | self.lineEdit_2.setObjectName("lineEdit_2") 56 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 57 | self.label_3 = QtWidgets.QLabel(self.widget1) 58 | self.label_3.setObjectName("label_3") 59 | self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) 60 | self.lineEdit_3 = QtWidgets.QLineEdit(self.widget1) 61 | self.lineEdit_3.setObjectName("lineEdit_3") 62 | self.gridLayout.addWidget(self.lineEdit_3, 2, 1, 1, 1) 63 | self.label_4 = QtWidgets.QLabel(self.widget1) 64 | self.label_4.setObjectName("label_4") 65 | self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1) 66 | self.lineEdit_4 = QtWidgets.QLineEdit(self.widget1) 67 | self.lineEdit_4.setObjectName("lineEdit_4") 68 | self.gridLayout.addWidget(self.lineEdit_4, 3, 1, 1, 1) 69 | 70 | self.statusbar = QtWidgets.QStatusBar(InputBookinfo) 71 | self.statusbar.setObjectName("statusbar") 72 | InputBookinfo.setStatusBar(self.statusbar) 73 | 74 | self.retranslateUi(InputBookinfo) 75 | self.pushButton_2.clicked.connect(self.lineEdit_4.clear) 76 | self.pushButton_2.clicked.connect(self.lineEdit_3.clear) 77 | self.pushButton_2.clicked.connect(self.lineEdit_2.clear) 78 | self.pushButton_2.clicked.connect(self.lineEdit.clear) 79 | self.pushButton_3.clicked.connect(InputBookinfo.close) 80 | QtCore.QMetaObject.connectSlotsByName(InputBookinfo) 81 | 82 | self.pushButton.clicked.connect(lambda: self.get_book_info()) 83 | 84 | def retranslateUi(self, InputBookinfo): 85 | _translate = QtCore.QCoreApplication.translate 86 | InputBookinfo.setWindowTitle(_translate("InputBookinfo", "添加书籍信息")) 87 | self.pushButton_2.setText(_translate("InputBookinfo", "清空")) 88 | self.pushButton.setText(_translate("InputBookinfo", "确认")) 89 | self.pushButton_3.setText(_translate("InputBookinfo", "退出")) 90 | self.label.setText(_translate("InputBookinfo", "输入ISBN")) 91 | self.label_2.setText(_translate("InputBookinfo", "书名")) 92 | self.label_3.setText(_translate("InputBookinfo", "作者")) 93 | self.label_4.setText(_translate("InputBookinfo", "价格")) 94 | 95 | def get_book_info(self): 96 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 97 | user='root') 98 | # 创建游标对象 99 | self.cursor = self.db.cursor() 100 | sql = "use bookshopmanagement" 101 | self.cursor.execute(sql) 102 | ISBN = self.lineEdit.text() # 获取文本框内容 103 | bookName = self.lineEdit_2.text() 104 | author = self.lineEdit_3.text() # 获取文本框内容 105 | price = self.lineEdit_4.text() 106 | sql = "SELECT * FROM book" 107 | self.cursor.execute(sql) 108 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 109 | data = self.cursor.fetchall() 110 | original_row = len(data) 111 | # 定义SQL语句 112 | try: 113 | sql = "insert into book(ISBN, bookname, author, price) values('%s','%s','%s','%d')" % ( 114 | ISBN, bookName, author, int(price)) 115 | self.execute_sql(sql) 116 | except Exception as err: 117 | print("错误原因 " + err) 118 | sql = "SELECT * FROM book" 119 | self.cursor.execute(sql) 120 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 121 | data = self.cursor.fetchall() 122 | changed_row = len(data) 123 | if changed_row == original_row+1: 124 | self.statusbar.showMessage("插入成功,请返回刷新", 2000) 125 | else: 126 | self.statusbar.showMessage("插入失败,请重试", 2000) 127 | self.cursor.close() 128 | 129 | 130 | if __name__ == '__main__': 131 | # db = QtSql.QSqlDatabase.addDatabase('QMYSQL') 132 | # db.setPort(3306) 133 | # db.setHostName('localhost') 134 | # db.setDatabaseName('bookshopmanagement') 135 | # db.setUserName('root') 136 | # db.setPassword('zyh20000205') 137 | 138 | # print(db.open()) 139 | 140 | app = QApplication(sys.argv) 141 | mainWindow = QtWidgets.QMainWindow() 142 | test_ui = Ui_InputBookinfo() 143 | test_ui.setupUi(mainWindow) 144 | mainWindow.show() 145 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertdel.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | from PyQt5 import QtCore, QtGui, QtWidgets 5 | from pymysql import * 6 | 7 | class Ui_delbook(object): 8 | def execute_sql(self, sql): 9 | try: 10 | # 执行数据库操作 11 | self.cursor.execute(sql) 12 | # 事务提交 13 | self.db.commit() 14 | except Exception as err: 15 | # 事务回滚 16 | self.db.rollback() 17 | print("SQL执行错误,原因:", err) 18 | 19 | def setupUi(self, delbook): 20 | delbook.setObjectName("delbook") 21 | delbook.resize(515, 336) 22 | self.pushButton_2 = QtWidgets.QPushButton(delbook) 23 | self.pushButton_2.setGeometry(QtCore.QRect(110, 230, 93, 28)) 24 | self.pushButton_2.setObjectName("pushButton_2") 25 | self.pushButton_3 = QtWidgets.QPushButton(delbook) 26 | self.pushButton_3.setGeometry(QtCore.QRect(320, 230, 93, 28)) 27 | self.pushButton_3.setObjectName("pushButton_3") 28 | self.widget = QtWidgets.QWidget(delbook) 29 | self.widget.setGeometry(QtCore.QRect(80, 140, 352, 30)) 30 | self.widget.setObjectName("widget") 31 | self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget) 32 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 33 | self.horizontalLayout.setObjectName("horizontalLayout") 34 | self.label = QtWidgets.QLabel(self.widget) 35 | self.label.setObjectName("label") 36 | self.horizontalLayout.addWidget(self.label) 37 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 38 | self.lineEdit.setObjectName("lineEdit") 39 | self.horizontalLayout.addWidget(self.lineEdit) 40 | self.pushButton = QtWidgets.QPushButton(self.widget) 41 | self.pushButton.setObjectName("pushButton") 42 | self.horizontalLayout.addWidget(self.pushButton) 43 | 44 | self.retranslateUi(delbook) 45 | self.pushButton.clicked.connect(self.lineEdit.clear) 46 | self.pushButton_3.clicked.connect(delbook.close) 47 | QtCore.QMetaObject.connectSlotsByName(delbook) 48 | self.pushButton_2.clicked.connect(lambda: self.insert_del()) 49 | 50 | def retranslateUi(self, delbook): 51 | _translate = QtCore.QCoreApplication.translate 52 | delbook.setWindowTitle(_translate("delbook", "删除书籍")) 53 | self.pushButton_2.setText(_translate("delbook", "确认")) 54 | self.pushButton_3.setText(_translate("delbook", "退出")) 55 | self.label.setText(_translate("delbook", "ISBN")) 56 | self.pushButton.setText(_translate("delbook", "清空")) 57 | 58 | def insert_del(self): 59 | isbn = self.lineEdit.text() 60 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 61 | user='root') 62 | # 创建游标对象 63 | self.cursor = self.db.cursor() 64 | sql = "use bookshopmanagement" 65 | self.cursor.execute(sql) 66 | sql = "delete from book where ISBN = '%s' " % (isbn) 67 | self.execute_sql(sql) 68 | self.cursor.connection.commit() 69 | self.db.close() 70 | 71 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertdel.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | delbook 4 | 5 | 6 | 7 | 0 8 | 0 9 | 515 10 | 336 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 110 20 | 230 21 | 93 22 | 28 23 | 24 | 25 | 26 | 确认 27 | 28 | 29 | 30 | 31 | 32 | 320 33 | 230 34 | 93 35 | 28 36 | 37 | 38 | 39 | 退出 40 | 41 | 42 | 43 | 44 | 45 | 80 46 | 140 47 | 352 48 | 30 49 | 50 | 51 | 52 | 53 | 54 | 55 | ISBN 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 清空 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | pushButton 76 | clicked() 77 | lineEdit 78 | clear() 79 | 80 | 81 | 393 82 | 153 83 | 84 | 85 | 293 86 | 153 87 | 88 | 89 | 90 | 91 | pushButton_3 92 | clicked() 93 | delbook 94 | close() 95 | 96 | 97 | 355 98 | 243 99 | 100 | 101 | 254 102 | 202 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertpurchase.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | 5 | from PyQt5 import QtCore, QtGui, QtWidgets 6 | from PyQt5.QtWidgets import QApplication 7 | from pymysql import * 8 | 9 | class Ui_insertpurchase(object): 10 | 11 | def execute_sql(self, sql): 12 | try: 13 | # 执行数据库操作 14 | self.cursor.execute(sql) 15 | # 事务提交 16 | self.db.commit() 17 | except Exception as err: 18 | # 事务回滚 19 | self.db.rollback() 20 | print("SQL执行错误,原因:", err) 21 | 22 | def setupUi(self, insertpurchase): 23 | insertpurchase.setObjectName("insertpurchase") 24 | insertpurchase.resize(589, 447) 25 | self.pushButton = QtWidgets.QPushButton(insertpurchase) 26 | self.pushButton.setGeometry(QtCore.QRect(460, 140, 93, 28)) 27 | self.pushButton.setObjectName("pushButton") 28 | self.pushButton_2 = QtWidgets.QPushButton(insertpurchase) 29 | self.pushButton_2.setGeometry(QtCore.QRect(120, 360, 93, 28)) 30 | self.pushButton_2.setObjectName("pushButton_2") 31 | self.pushButton_3 = QtWidgets.QPushButton(insertpurchase) 32 | self.pushButton_3.setGeometry(QtCore.QRect(380, 360, 93, 28)) 33 | self.pushButton_3.setObjectName("pushButton_3") 34 | self.widget = QtWidgets.QWidget(insertpurchase) 35 | self.widget.setGeometry(QtCore.QRect(100, 120, 311, 171)) 36 | self.widget.setObjectName("widget") 37 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 38 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 39 | self.gridLayout.setObjectName("gridLayout") 40 | self.label = QtWidgets.QLabel(self.widget) 41 | self.label.setObjectName("label") 42 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 43 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 44 | self.lineEdit.setObjectName("lineEdit") 45 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 46 | self.label_2 = QtWidgets.QLabel(self.widget) 47 | self.label_2.setObjectName("label_2") 48 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 49 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 50 | self.lineEdit_2.setObjectName("lineEdit_2") 51 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 52 | self.label_3 = QtWidgets.QLabel(self.widget) 53 | self.label_3.setObjectName("label_3") 54 | self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) 55 | self.lineEdit_3 = QtWidgets.QLineEdit(self.widget) 56 | self.lineEdit_3.setObjectName("lineEdit_3") 57 | self.gridLayout.addWidget(self.lineEdit_3, 2, 1, 1, 1) 58 | 59 | self.retranslateUi(insertpurchase) 60 | self.pushButton.clicked.connect(self.lineEdit.clear) 61 | self.pushButton.clicked.connect(self.lineEdit_2.clear) 62 | self.pushButton.clicked.connect(self.lineEdit_3.clear) 63 | self.pushButton_3.clicked.connect(insertpurchase.close) 64 | QtCore.QMetaObject.connectSlotsByName(insertpurchase) 65 | 66 | self.pushButton_2.clicked.connect(lambda: self.insert_purchase()) 67 | 68 | def retranslateUi(self, insertpurchase): 69 | _translate = QtCore.QCoreApplication.translate 70 | insertpurchase.setWindowTitle(_translate("insertpurchase", "购入书籍")) 71 | self.pushButton.setText(_translate("insertpurchase", "清空")) 72 | self.pushButton_2.setText(_translate("insertpurchase", "确认")) 73 | self.pushButton_3.setText(_translate("insertpurchase", "退出")) 74 | self.label.setText(_translate("insertpurchase", "ISBN")) 75 | self.label_2.setText(_translate("insertpurchase", "购买数量")) 76 | self.label_3.setText(_translate("insertpurchase", "价格")) 77 | 78 | def insert_purchase(self): 79 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 80 | user='root') 81 | # 创建游标对象 82 | self.cursor = self.db.cursor() 83 | sql = "use bookshopmanagement" 84 | self.cursor.execute(sql) 85 | 86 | isbn = self.lineEdit.text() 87 | price = self.lineEdit_2.text() 88 | purchase_num = self.lineEdit_3.text() 89 | # 定义SQL语句 90 | print(isbn,price,purchase_num) 91 | sql = "insert into purchasebook(isbn, price, purchasenum) values('%s','%d','%d')" % \ 92 | (isbn, int(price), int(purchase_num)) 93 | self.execute_sql(sql) 94 | self.cursor.close() 95 | 96 | if __name__ == '__main__': 97 | # db = QtSql.QSqlDatabase.addDatabase('QMYSQL') 98 | # db.setPort(3306) 99 | # db.setHostName('localhost') 100 | # db.setDatabaseName('bookshopmanagement') 101 | # db.setUserName('root') 102 | # db.setPassword('zyh20000205') 103 | 104 | # print(db.open()) 105 | 106 | app = QApplication(sys.argv) 107 | mainWindow = QtWidgets.QMainWindow() 108 | test_ui = Ui_insertpurchase() 109 | test_ui.setupUi(mainWindow) 110 | mainWindow.show() 111 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertpurchase.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | insertpurchase 4 | 5 | 6 | 7 | 0 8 | 0 9 | 589 10 | 447 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 460 20 | 140 21 | 93 22 | 28 23 | 24 | 25 | 26 | 清空 27 | 28 | 29 | 30 | 31 | 32 | 120 33 | 360 34 | 93 35 | 28 36 | 37 | 38 | 39 | 确认 40 | 41 | 42 | 43 | 44 | 45 | 380 46 | 360 47 | 93 48 | 28 49 | 50 | 51 | 52 | 退出 53 | 54 | 55 | 56 | 57 | 58 | 100 59 | 120 60 | 311 61 | 171 62 | 63 | 64 | 65 | 66 | 67 | 68 | ISBN 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 购买数量 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 价格 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | pushButton 102 | clicked() 103 | lineEdit 104 | clear() 105 | 106 | 107 | 486 108 | 151 109 | 110 | 111 | 402 112 | 153 113 | 114 | 115 | 116 | 117 | pushButton 118 | clicked() 119 | lineEdit_2 120 | clear() 121 | 122 | 123 | 499 124 | 155 125 | 126 | 127 | 398 128 | 214 129 | 130 | 131 | 132 | 133 | pushButton 134 | clicked() 135 | lineEdit_3 136 | clear() 137 | 138 | 139 | 534 140 | 158 141 | 142 | 143 | 380 144 | 256 145 | 146 | 147 | 148 | 149 | pushButton_3 150 | clicked() 151 | insertpurchase 152 | close() 153 | 154 | 155 | 429 156 | 376 157 | 158 | 159 | 405 160 | 429 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertsell.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | from PyQt5 import QtCore, QtGui, QtWidgets 5 | from pymysql import * 6 | 7 | 8 | class Ui_Insertsell(object): 9 | def execute_sql(self, sql): 10 | try: 11 | # 执行数据库操作 12 | self.cursor.execute(sql) 13 | # 事务提交 14 | self.db.commit() 15 | except Exception as err: 16 | # 事务回滚 17 | self.db.rollback() 18 | print("SQL执行错误,原因:", err) 19 | 20 | def setupUi(self, Insertsell): 21 | Insertsell.setObjectName("Insertsell") 22 | Insertsell.resize(605, 362) 23 | self.pushButton = QtWidgets.QPushButton(Insertsell) 24 | self.pushButton.setGeometry(QtCore.QRect(460, 110, 93, 28)) 25 | self.pushButton.setObjectName("pushButton") 26 | self.pushButton_2 = QtWidgets.QPushButton(Insertsell) 27 | self.pushButton_2.setGeometry(QtCore.QRect(130, 270, 93, 28)) 28 | self.pushButton_2.setObjectName("pushButton_2") 29 | self.pushButton_3 = QtWidgets.QPushButton(Insertsell) 30 | self.pushButton_3.setGeometry(QtCore.QRect(310, 270, 93, 28)) 31 | self.pushButton_3.setObjectName("pushButton_3") 32 | self.widget = QtWidgets.QWidget(Insertsell) 33 | self.widget.setGeometry(QtCore.QRect(120, 100, 281, 121)) 34 | self.widget.setObjectName("widget") 35 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 36 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 37 | self.gridLayout.setObjectName("gridLayout") 38 | self.label = QtWidgets.QLabel(self.widget) 39 | self.label.setObjectName("label") 40 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 41 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 42 | self.lineEdit.setObjectName("lineEdit") 43 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 44 | self.label_2 = QtWidgets.QLabel(self.widget) 45 | self.label_2.setObjectName("label_2") 46 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 47 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 48 | self.lineEdit_2.setObjectName("lineEdit_2") 49 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 50 | self.label_3 = QtWidgets.QLabel(self.widget) 51 | self.label_3.setObjectName("label_3") 52 | self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) 53 | self.lineEdit_3 = QtWidgets.QLineEdit(self.widget) 54 | self.lineEdit_3.setObjectName("lineEdit_3") 55 | self.gridLayout.addWidget(self.lineEdit_3, 2, 1, 1, 1) 56 | 57 | self.retranslateUi(Insertsell) 58 | self.pushButton.clicked.connect(self.lineEdit.clear) 59 | self.pushButton.clicked.connect(self.lineEdit_2.clear) 60 | self.pushButton.clicked.connect(self.lineEdit_3.clear) 61 | self.pushButton_3.clicked.connect(Insertsell.close) 62 | QtCore.QMetaObject.connectSlotsByName(Insertsell) 63 | 64 | self.pushButton_2.clicked.connect(lambda: self.insertsell()) 65 | 66 | def retranslateUi(self, Insertsell): 67 | _translate = QtCore.QCoreApplication.translate 68 | Insertsell.setWindowTitle(_translate("Insertsell", "卖出书籍")) 69 | self.pushButton.setText(_translate("Insertsell", "清空")) 70 | self.pushButton_2.setText(_translate("Insertsell", "确认")) 71 | self.pushButton_3.setText(_translate("Insertsell", "退出")) 72 | self.label.setText(_translate("Insertsell", "ISBN")) 73 | self.label_2.setText(_translate("Insertsell", "价格")) 74 | self.label_3.setText(_translate("Insertsell", "数量")) 75 | 76 | def insertsell(self): 77 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 78 | user='root') 79 | # 创建游标对象 80 | self.cursor = self.db.cursor() 81 | sql = "use bookshopmanagement" 82 | self.cursor.execute(sql) 83 | 84 | isbn = self.lineEdit.text() 85 | price = self.lineEdit_2.text() 86 | sell_num = self.lineEdit_3.text() 87 | # 定义SQL语句 88 | print(isbn, price, sell_num) 89 | sql = "insert into sell(isbn, price, AlreadySold) values('%s','%d','%d')" % \ 90 | (isbn, int(price), int(sell_num)) 91 | self.execute_sql(sql) 92 | self.cursor.close() -------------------------------------------------------------------------------- /code/pyqt/bookshop/Insertsell.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Insertsell 4 | 5 | 6 | 7 | 0 8 | 0 9 | 605 10 | 362 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 460 20 | 110 21 | 93 22 | 28 23 | 24 | 25 | 26 | 清空 27 | 28 | 29 | 30 | 31 | 32 | 130 33 | 270 34 | 93 35 | 28 36 | 37 | 38 | 39 | 确认 40 | 41 | 42 | 43 | 44 | 45 | 310 46 | 270 47 | 93 48 | 28 49 | 50 | 51 | 52 | 退出 53 | 54 | 55 | 56 | 57 | 58 | 120 59 | 100 60 | 281 61 | 121 62 | 63 | 64 | 65 | 66 | 67 | 68 | ISBN 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 价格 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 数量 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | pushButton 102 | clicked() 103 | lineEdit 104 | clear() 105 | 106 | 107 | 498 108 | 125 109 | 110 | 111 | 353 112 | 118 113 | 114 | 115 | 116 | 117 | pushButton 118 | clicked() 119 | lineEdit_2 120 | clear() 121 | 122 | 123 | 506 124 | 129 125 | 126 | 127 | 386 128 | 163 129 | 130 | 131 | 132 | 133 | pushButton 134 | clicked() 135 | lineEdit_3 136 | clear() 137 | 138 | 139 | 538 140 | 135 141 | 142 | 143 | 349 144 | 198 145 | 146 | 147 | 148 | 149 | pushButton_3 150 | clicked() 151 | Insertsell 152 | close() 153 | 154 | 155 | 351 156 | 283 157 | 158 | 159 | 494 160 | 314 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/LoginUI.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'LoginUI.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | import sys 11 | from PyQt5 import QtCore, QtGui, QtWidgets 12 | from PyQt5.QtWidgets import * 13 | import json 14 | 15 | from user_window_test_2 import * 16 | from admin_window import * 17 | 18 | class Ui_MainWindow(QtWidgets.QMainWindow): 19 | # def __init__(self, user_ui): 20 | def __init__(self): 21 | super(Ui_MainWindow, self).__init__() 22 | # self.user_ui = user_ui 23 | 24 | def setupUi(self, MainWindow): 25 | MainWindow.setObjectName("MainWindow") 26 | MainWindow.resize(800, 450) 27 | 28 | # 设置背景框,不建议 29 | # MainWindow.setStyleSheet("background-image:url(1.jpg)") 30 | 31 | self.priority_flag = 2 # 登录用户等级 32 | self.centralwidget = QtWidgets.QWidget(MainWindow) 33 | self.centralwidget.setObjectName("centralwidget") 34 | self.layoutWidget = QtWidgets.QWidget(self.centralwidget) 35 | self.layoutWidget.setGeometry(QtCore.QRect(270, 150, 231, 133)) 36 | self.layoutWidget.setObjectName("layoutWidget") 37 | self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.layoutWidget) 38 | self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) 39 | self.verticalLayout_3.setObjectName("verticalLayout_3") 40 | self.horizontalLayout = QtWidgets.QHBoxLayout() 41 | self.horizontalLayout.setObjectName("horizontalLayout") 42 | self.verticalLayout_2 = QtWidgets.QVBoxLayout() 43 | self.verticalLayout_2.setObjectName("verticalLayout_2") 44 | self.label = QtWidgets.QLabel(self.layoutWidget) 45 | self.label.setObjectName("label") 46 | self.verticalLayout_2.addWidget(self.label) 47 | self.label_2 = QtWidgets.QLabel(self.layoutWidget) 48 | self.label_2.setObjectName("label_2") 49 | self.verticalLayout_2.addWidget(self.label_2) 50 | self.horizontalLayout.addLayout(self.verticalLayout_2) 51 | self.verticalLayout = QtWidgets.QVBoxLayout() 52 | self.verticalLayout.setObjectName("verticalLayout") 53 | self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget) 54 | self.lineEdit.setObjectName("lineEdit") 55 | self.verticalLayout.addWidget(self.lineEdit) 56 | self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget) 57 | self.lineEdit_2.setObjectName("lineEdit_2") 58 | self.verticalLayout.addWidget(self.lineEdit_2) 59 | self.lineEdit_2.setEchoMode(QLineEdit.Password) 60 | self.horizontalLayout.addLayout(self.verticalLayout) 61 | self.verticalLayout_3.addLayout(self.horizontalLayout) 62 | self.gridLayout = QtWidgets.QGridLayout() 63 | self.gridLayout.setObjectName("gridLayout") 64 | self.pushButton = QtWidgets.QPushButton(self.layoutWidget) 65 | self.pushButton.setObjectName("pushButton") 66 | self.gridLayout.addWidget(self.pushButton, 1, 0, 1, 1) 67 | self.pushButton_2 = QtWidgets.QPushButton(self.layoutWidget) 68 | self.pushButton_2.setObjectName("pushButton_2") 69 | self.gridLayout.addWidget(self.pushButton_2, 1, 1, 1, 1) 70 | self.radioButton = QtWidgets.QRadioButton(self.layoutWidget) 71 | self.radioButton.setObjectName("radioButton") 72 | self.gridLayout.addWidget(self.radioButton, 0, 0, 1, 1) 73 | self.radioButton_2 = QtWidgets.QRadioButton(self.layoutWidget) 74 | self.radioButton_2.setObjectName("radioButton_2") 75 | self.gridLayout.addWidget(self.radioButton_2, 0, 1, 1, 1) 76 | self.verticalLayout_3.addLayout(self.gridLayout) 77 | self.label_3 = QtWidgets.QLabel(self.centralwidget) 78 | self.label_3.setGeometry(QtCore.QRect(340, 70, 151, 61)) 79 | self.label_3.setTextFormat(QtCore.Qt.AutoText) 80 | self.label_3.setObjectName("label_3") 81 | self.label_4 = QtWidgets.QLabel(self.centralwidget) 82 | self.label_4.setGeometry(QtCore.QRect(630, 520, 211, 16)) 83 | self.label_4.setObjectName("label_4") 84 | MainWindow.setCentralWidget(self.centralwidget) 85 | self.menubar = QtWidgets.QMenuBar(MainWindow) 86 | self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26)) 87 | self.menubar.setObjectName("menubar") 88 | MainWindow.setMenuBar(self.menubar) 89 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 90 | self.statusbar.setObjectName("statusbar") 91 | MainWindow.setStatusBar(self.statusbar) 92 | 93 | self.retranslateUi(MainWindow) 94 | self.pushButton_2.clicked.connect(MainWindow.close) 95 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 96 | self.pushButton.clicked.connect(lambda: self.check_user(MainWindow)) # 绑定信号槽 97 | self.statusbar.showMessage("欢迎使用书店管理系统 developed by zyhsna", 5000) # 状态栏显示信息 98 | self.radioButton.clicked.connect(lambda: self.admin_login()) # 绑定 99 | self.radioButton_2.clicked.connect(lambda: self.user_login()) 100 | self.pushButton.setShortcut('enter') # 绑定到小键盘enter,无小键盘未测试 101 | 102 | def retranslateUi(self, MainWindow): 103 | _translate = QtCore.QCoreApplication.translate 104 | MainWindow.setWindowTitle(_translate("MainWindow", "书店管理系统")) 105 | self.label.setText(_translate("MainWindow", "用户名")) 106 | self.label_2.setText(_translate("MainWindow", "密码")) 107 | self.pushButton.setText(_translate("MainWindow", "登录")) 108 | self.pushButton_2.setText(_translate("MainWindow", "退出")) 109 | self.radioButton.setText(_translate("MainWindow", "管理员")) 110 | self.radioButton_2.setText(_translate("MainWindow", "普通用户")) 111 | self.label_3.setText(_translate("MainWindow", "书店管理系统")) 112 | self.label_4.setText(_translate("MainWindow", "Developed by zyhsna")) 113 | 114 | def check_user(self, MainWindow): 115 | """判断账号是否存在及正确,从json中读取用户信息,如果正确那么便打开界面并且会关闭登录界面""" 116 | #user_ui = User_MainWindow() 117 | account = self.lineEdit.text() # 获取文本框内容 118 | password = self.lineEdit_2.text() 119 | print(account) 120 | print("youxianji"+str(self.priority_flag)) 121 | 122 | file_name_1 = r"admin.txt" 123 | file_name_2 = r"employee.txt" 124 | with open(file_name_1, "r") as f: 125 | js = f.read() 126 | bookshop_admin = json.loads(js) 127 | f.close() 128 | print(bookshop_admin) 129 | with open(file_name_2, "r") as f: 130 | js = f.read() 131 | bookshop_employee = json.loads(js) 132 | 133 | if self.priority_flag is 0: 134 | if account in bookshop_admin.keys(): 135 | if bookshop_admin[account] == password: 136 | self.statusbar.showMessage("管理员登录成功", 2000) 137 | admin.show() 138 | MainWindow.close() 139 | elif len(password) is 0: 140 | self.statusbar.showMessage("请输入密码", 2000) 141 | else: 142 | self.statusbar.showMessage("密码错误", 2000) 143 | elif len(account) is 0: 144 | self.statusbar.showMessage("请输入账号", 2000) 145 | else: 146 | self.statusbar.showMessage("没有该账户名", 2000) 147 | 148 | elif self.priority_flag is 1: 149 | if account in bookshop_employee.keys(): 150 | if bookshop_employee[account] == password: 151 | self.statusbar.showMessage("用户登录成功", 2000) 152 | user.show() 153 | MainWindow.close() 154 | elif len(password) is 0: 155 | self.statusbar.showMessage("请输入密码", 2000) 156 | else: 157 | self.statusbar.showMessage("密码错误", 2000) 158 | elif len(account) is 0: 159 | self.statusbar.showMessage("请输入账号", 2000) 160 | else: 161 | self.statusbar.showMessage("没有该账户名", 2000) 162 | 163 | else: 164 | self.statusbar.showMessage("请选择登录用户级别", 2000) 165 | 166 | # 改变用户登录等级 167 | def admin_login(self): 168 | print("admin choosed") 169 | self.priority_flag = 0 170 | 171 | def user_login(self): 172 | print("employee chosed") 173 | self.priority_flag = 1 174 | 175 | 176 | class login_window(QMainWindow): 177 | def __init__(self): 178 | QMainWindow.__init__(self) 179 | self.UI = Ui_MainWindow() 180 | self.UI.setupUi(self) 181 | 182 | 183 | class userWindow(QMainWindow): 184 | def __init__(self): 185 | QMainWindow.__init__(self) 186 | self.UI = Ui_user_window_test2() 187 | self.UI.setupUi(self) 188 | 189 | class adminWindow(QMainWindow): 190 | def __init__(self): 191 | QMainWindow.__init__(self) 192 | self.UI = Ui_adminWindow() 193 | self.UI.setupUi(self) 194 | 195 | 196 | if __name__ == '__main__': 197 | app = QApplication(sys.argv) 198 | login = login_window() 199 | user = userWindow() 200 | admin = adminWindow() 201 | login.show() 202 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/LoginUI.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 270 21 | 150 22 | 231 23 | 133 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 用户名 35 | 36 | 37 | 38 | 39 | 40 | 41 | 密码 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 登录 65 | 66 | 67 | 68 | 69 | 70 | 71 | 退出 72 | 73 | 74 | 75 | 76 | 77 | 78 | 管理员 79 | 80 | 81 | 82 | 83 | 84 | 85 | 普通用户 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 340 97 | 70 98 | 151 99 | 61 100 | 101 | 102 | 103 | 书店管理系统 104 | 105 | 106 | Qt::AutoText 107 | 108 | 109 | 110 | 111 | 112 | 630 113 | 520 114 | 211 115 | 16 116 | 117 | 118 | 119 | Developed by zyhsna 120 | 121 | 122 | 123 | 124 | 125 | 126 | 0 127 | 0 128 | 800 129 | 26 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | pushButton_2 139 | clicked() 140 | MainWindow 141 | close() 142 | 143 | 144 | 422 145 | 319 146 | 147 | 148 | 432 149 | 412 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/admin.txt: -------------------------------------------------------------------------------- 1 | {"1": "zyh", "2": "zyh"} -------------------------------------------------------------------------------- /code/pyqt/bookshop/admin_window.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'admin_window.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | import json 10 | import sys 11 | from pymysql import * 12 | from PyQt5 import QtCore, QtGui, QtWidgets, QtSql 13 | from PyQt5.QtWidgets import QMainWindow, QApplication 14 | from insert_employee import * 15 | from deleteEmployee import * 16 | 17 | 18 | class Ui_adminWindow(object): 19 | def setupUi(self, MainWindow): 20 | MainWindow.setObjectName("MainWindow") 21 | MainWindow.resize(988, 533) 22 | self.centralwidget = QtWidgets.QWidget(MainWindow) 23 | self.centralwidget.setObjectName("centralwidget") 24 | self.operator_2 = QtWidgets.QFrame(self.centralwidget) 25 | self.operator_2.setGeometry(QtCore.QRect(240, 40, 591, 331)) 26 | self.operator_2.setFrameShape(QtWidgets.QFrame.StyledPanel) 27 | self.operator_2.setFrameShadow(QtWidgets.QFrame.Raised) 28 | self.operator_2.setObjectName("operator_2") 29 | self.pushButton_3 = QtWidgets.QPushButton(self.operator_2) 30 | self.pushButton_3.setGeometry(QtCore.QRect(430, 60, 93, 28)) 31 | self.pushButton_3.setObjectName("pushButton_3") 32 | self.pushButton_5 = QtWidgets.QPushButton(self.operator_2) 33 | self.pushButton_5.setGeometry(QtCore.QRect(430, 110, 93, 28)) 34 | self.pushButton_5.setObjectName("pushButton_5") 35 | self.radioButton = QtWidgets.QRadioButton(self.operator_2) 36 | self.radioButton.setGeometry(QtCore.QRect(130, 230, 115, 19)) 37 | self.radioButton.setObjectName("radioButton") 38 | self.radioButton_2 = QtWidgets.QRadioButton(self.operator_2) 39 | self.radioButton_2.setGeometry(QtCore.QRect(310, 230, 115, 19)) 40 | self.radioButton_2.setObjectName("radioButton_2") 41 | self.widget = QtWidgets.QWidget(self.operator_2) 42 | self.widget.setGeometry(QtCore.QRect(80, 50, 291, 91)) 43 | self.widget.setObjectName("widget") 44 | self.gridLayout_2 = QtWidgets.QGridLayout(self.widget) 45 | self.gridLayout_2.setContentsMargins(0, 0, 0, 0) 46 | self.gridLayout_2.setObjectName("gridLayout_2") 47 | self.label = QtWidgets.QLabel(self.widget) 48 | self.label.setObjectName("label") 49 | self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1) 50 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 51 | self.lineEdit.setObjectName("lineEdit") 52 | self.gridLayout_2.addWidget(self.lineEdit, 0, 1, 1, 1) 53 | self.label_2 = QtWidgets.QLabel(self.widget) 54 | self.label_2.setObjectName("label_2") 55 | self.gridLayout_2.addWidget(self.label_2, 1, 0, 1, 1) 56 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 57 | self.lineEdit_2.setText("") 58 | self.lineEdit_2.setObjectName("lineEdit_2") 59 | self.gridLayout_2.addWidget(self.lineEdit_2, 1, 1, 1, 1) 60 | self.emoloyee = QtWidgets.QFrame(self.centralwidget) 61 | self.emoloyee.setGeometry(QtCore.QRect(244, 37, 611, 361)) 62 | self.emoloyee.setFrameShape(QtWidgets.QFrame.StyledPanel) 63 | self.emoloyee.setFrameShadow(QtWidgets.QFrame.Raised) 64 | self.emoloyee.setObjectName("emoloyee") 65 | self.pushButton_4 = QtWidgets.QPushButton(self.emoloyee) 66 | self.pushButton_4.setGeometry(QtCore.QRect(470, 20, 93, 28)) 67 | self.pushButton_4.setObjectName("pushButton_4") 68 | self.pushButton_6 = QtWidgets.QPushButton(self.emoloyee) 69 | self.pushButton_6.setGeometry(QtCore.QRect(470, 70, 93, 28)) 70 | self.pushButton_6.setObjectName("pushButton_6") 71 | # self.pushButton_7 = QtWidgets.QPushButton(self.emoloyee) 72 | # self.pushButton_7.setGeometry(QtCore.QRect(470, 120, 93, 28)) 73 | # self.pushButton_7.setObjectName("pushButton_7") 74 | # self.pushButton_8 = QtWidgets.QPushButton(self.emoloyee) 75 | # self.pushButton_8.setGeometry(QtCore.QRect(470, 170, 93, 28)) 76 | # self.pushButton_8.setObjectName("pushButton_8") 77 | self.tableView = QtWidgets.QTableView(self.emoloyee) 78 | self.tableView.setGeometry(QtCore.QRect(20, 20, 441, 301)) 79 | self.tableView.setObjectName("tableView") 80 | self.widget1 = QtWidgets.QWidget(self.centralwidget) 81 | self.widget1.setGeometry(QtCore.QRect(90, 60, 101, 65)) 82 | self.widget1.setObjectName("widget1") 83 | self.gridLayout = QtWidgets.QGridLayout(self.widget1) 84 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 85 | self.gridLayout.setObjectName("gridLayout") 86 | self.add_operator = QtWidgets.QPushButton(self.widget1) 87 | self.add_operator.setObjectName("add_operator") 88 | self.gridLayout.addWidget(self.add_operator, 0, 0, 1, 1) 89 | self.showEmployeeInfo = QtWidgets.QPushButton(self.widget1) 90 | self.showEmployeeInfo.setObjectName("showEmployeeInfo") 91 | self.gridLayout.addWidget(self.showEmployeeInfo, 1, 0, 1, 1) 92 | MainWindow.setCentralWidget(self.centralwidget) 93 | self.menubar = QtWidgets.QMenuBar(MainWindow) 94 | self.menubar.setGeometry(QtCore.QRect(0, 0, 988, 26)) 95 | self.menubar.setObjectName("menubar") 96 | MainWindow.setMenuBar(self.menubar) 97 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 98 | self.statusbar.setObjectName("statusbar") 99 | MainWindow.setStatusBar(self.statusbar) 100 | self.emoloyee.setVisible(False) 101 | self.retranslateUi(MainWindow) 102 | self.add_operator.clicked.connect(self.operator_2.show) 103 | self.add_operator.clicked.connect(self.emoloyee.hide) 104 | self.showEmployeeInfo.clicked.connect(self.operator_2.hide) 105 | self.showEmployeeInfo.clicked.connect(self.emoloyee.show) 106 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 107 | self.priority = 0 108 | childwindow_insertEmployee = child_insertEmployee() 109 | childwindow_delEmployee = child_delEmployee() 110 | 111 | self.radioButton.clicked.connect(lambda: self.choose_admin()) 112 | self.radioButton_2.clicked.connect(lambda: self.choose_employee()) 113 | self.pushButton_3.clicked.connect(lambda: self.add_operator_method()) 114 | self.pushButton_5.clicked.connect(lambda:self.del_operator()) 115 | self.showEmployeeInfo.clicked.connect(lambda:self.get_empolyee_info()) 116 | self.pushButton_4.clicked.connect(lambda:childwindow_insertEmployee.show()) 117 | self.pushButton_6.clicked.connect(lambda: childwindow_delEmployee.show()) 118 | 119 | def retranslateUi(self, MainWindow): 120 | _translate = QtCore.QCoreApplication.translate 121 | MainWindow.setWindowTitle(_translate("MainWindow", "管理员")) 122 | self.pushButton_3.setText(_translate("MainWindow", "添加人员")) 123 | self.pushButton_5.setText(_translate("MainWindow", "删除人员")) 124 | self.radioButton.setText(_translate("MainWindow", "管理员")) 125 | self.radioButton_2.setText(_translate("MainWindow", "一般用户")) 126 | self.label.setText(_translate("MainWindow", "用户名")) 127 | self.label_2.setText(_translate("MainWindow", "密码")) 128 | self.pushButton_4.setText(_translate("MainWindow", "添加雇员")) 129 | self.pushButton_6.setText(_translate("MainWindow", "删除雇员")) 130 | # self.pushButton_7.setText(_translate("MainWindow", "查找雇员")) 131 | # self.pushButton_8.setText(_translate("MainWindow", "修改信息")) 132 | self.add_operator.setText(_translate("MainWindow", "查看操作人员")) 133 | self.showEmployeeInfo.setText(_translate("MainWindow", "查看雇员信息")) 134 | 135 | def add_operator_method(self): 136 | if self.priority is 0: 137 | self.statusbar.showMessage("请选择用户级别") 138 | elif self.priority is 1: 139 | print(1) 140 | self.addOperator_admin() 141 | elif self.priority is 2: 142 | self.addOperator_employee() 143 | 144 | def del_operator(self): 145 | if self.priority is 0: 146 | self.statusbar.showMessage("请选择用户级别") 147 | elif self.priority is 1: 148 | self.delOperator_admin() 149 | elif self.priority is 2: 150 | self.delOperator_employee() 151 | 152 | 153 | def addOperator_admin(self): 154 | file_name_1 = r"admin.txt" 155 | with open(file_name_1, "r") as f: 156 | js = f.read() 157 | admin = json.loads(js) 158 | f.close() 159 | id = self.lineEdit.text() 160 | pwd = self.lineEdit_2.text() 161 | if id in admin.keys(): 162 | self.statusbar.showMessage("该账号名已被使用", 2000) 163 | else: 164 | admin[id] = pwd 165 | 166 | self.statusbar.showMessage("添加成功!",2000) 167 | jsOBJ = json.dumps(admin) 168 | with open(file_name_1, "w") as f: 169 | f.write(jsOBJ) 170 | f.close() 171 | 172 | def addOperator_employee(self): 173 | file_name_2 = r"employee.txt" 174 | with open(file_name_2, "r") as f: 175 | js = f.read() 176 | employee = json.loads(js) 177 | f.close() 178 | id = self.lineEdit.text() 179 | pwd = self.lineEdit_2.text() 180 | if id in employee.keys(): 181 | self.statusbar.showMessage("该账号名已被使用", 2000) 182 | else: 183 | employee[id] = pwd 184 | self.statusbar.showMessage("添加成功!", 2000) 185 | jsOBJ = json.dumps(employee) 186 | with open(file_name_2, "w") as f: 187 | f.write(jsOBJ) 188 | f.close() 189 | 190 | def delOperator_admin(self): 191 | file_name_1 = r"admin.txt" 192 | with open(file_name_1, "r") as f: 193 | js = f.read() 194 | admin = json.loads(js) 195 | f.close() 196 | id = self.lineEdit.text() 197 | if id not in admin.keys(): 198 | self.statusbar.showMessage("未发现该账号名", 2000) 199 | else: 200 | del admin[id] 201 | self.statusbar.showMessage("删除成功!", 2000) 202 | jsOBJ = json.dumps(admin) 203 | with open(file_name_1, "w") as f: 204 | f.write(jsOBJ) 205 | f.close() 206 | 207 | 208 | def delOperator_employee(self): 209 | file_name_2 = r"employee.txt" 210 | with open(file_name_2, "r") as f: 211 | js = f.read() 212 | employee = json.loads(js) 213 | f.close() 214 | id = self.lineEdit.text() 215 | pwd = self.lineEdit_2.text() 216 | if id in employee.keys(): 217 | self.statusbar.showMessage("未发现该账号名", 2000) 218 | else: 219 | del employee[id] 220 | self.statusbar.showMessage("删除成功!", 2000) 221 | jsOBJ = json.dumps(employee) 222 | with open(file_name_2, "w") as f: 223 | f.write(jsOBJ) 224 | f.close() 225 | 226 | def get_empolyee_info(self): 227 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 228 | user='root') 229 | # 创建游标对象 230 | self.cursor = self.db.cursor() 231 | sql = "use bookshopmanagement" 232 | self.cursor.execute(sql) 233 | sql = "select * from employee;" 234 | self.cursor.execute(sql) 235 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 236 | data = self.cursor.fetchall() 237 | print(data) 238 | self.model = QtSql.QSqlTableModel() 239 | self.tableView.setModel(self.model) 240 | row = len(data) 241 | model = QtGui.QStandardItemModel(row, len(data[0])) 242 | col = len(data[0]) 243 | for i in range(row): 244 | for j in range(len(data[0])): 245 | if j is 1 or j is 2 or j is 4: 246 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 247 | elif j is 0 or j is 3 or j is 5: 248 | if data[i][j] is None: 249 | model.setItem(i, j, QtGui.QStandardItem(str(0))) 250 | else: 251 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 252 | self.cursor.close() 253 | model.setHorizontalHeaderLabels(['雇员编号', '姓名', '性别', '年龄', '电话', '工资']) 254 | self.tableView.setModel(model) 255 | 256 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 257 | 258 | def choose_admin(self): 259 | self.priority = 1 260 | 261 | def choose_employee(self): 262 | self.priority = 2 263 | 264 | 265 | class parentWindow_admin(QMainWindow): 266 | def __init__(self): 267 | QMainWindow.__init__(self) 268 | self.UI = Ui_adminWindow() 269 | self.UI.setupUi(self) 270 | 271 | class child_insertEmployee(QMainWindow): 272 | def __init__(self): 273 | QMainWindow.__init__(self) 274 | self.UI = Ui_insert_employee() 275 | self.UI.setupUi(self) 276 | 277 | class child_delEmployee(QMainWindow): 278 | def __init__(self): 279 | QMainWindow.__init__(self) 280 | self.UI = Ui_Form() 281 | self.UI.setupUi(self) 282 | 283 | if __name__ == '__main__': 284 | app = QApplication(sys.argv) 285 | window = parentWindow_admin() 286 | window.show() 287 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/admin_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 988 10 | 533 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 240 21 | 40 22 | 591 23 | 331 24 | 25 | 26 | 27 | QFrame::StyledPanel 28 | 29 | 30 | QFrame::Raised 31 | 32 | 33 | 34 | 35 | 430 36 | 60 37 | 93 38 | 28 39 | 40 | 41 | 42 | 添加人员 43 | 44 | 45 | 46 | 47 | 48 | 430 49 | 110 50 | 93 51 | 28 52 | 53 | 54 | 55 | 删除人员 56 | 57 | 58 | 59 | 60 | 61 | 130 62 | 230 63 | 115 64 | 19 65 | 66 | 67 | 68 | 管理员 69 | 70 | 71 | 72 | 73 | 74 | 310 75 | 230 76 | 115 77 | 19 78 | 79 | 80 | 81 | 一般用户 82 | 83 | 84 | 85 | 86 | 87 | 80 88 | 50 89 | 291 90 | 91 91 | 92 | 93 | 94 | 95 | 96 | 97 | 用户名 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 密码 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 244 125 | 37 126 | 611 127 | 361 128 | 129 | 130 | 131 | QFrame::StyledPanel 132 | 133 | 134 | QFrame::Raised 135 | 136 | 137 | 138 | 139 | 470 140 | 20 141 | 93 142 | 28 143 | 144 | 145 | 146 | 添加雇员 147 | 148 | 149 | 150 | 151 | 152 | 470 153 | 70 154 | 93 155 | 28 156 | 157 | 158 | 159 | 删除雇员 160 | 161 | 162 | 163 | 164 | 165 | 470 166 | 120 167 | 93 168 | 28 169 | 170 | 171 | 172 | 查找雇员 173 | 174 | 175 | 176 | 177 | 178 | 470 179 | 170 180 | 93 181 | 28 182 | 183 | 184 | 185 | 修改信息 186 | 187 | 188 | 189 | 190 | 191 | 20 192 | 20 193 | 441 194 | 301 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 90 203 | 60 204 | 101 205 | 65 206 | 207 | 208 | 209 | 210 | 211 | 212 | 查看操作人员 213 | 214 | 215 | 216 | 217 | 218 | 219 | 查看雇员信息 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 0 230 | 0 231 | 988 232 | 26 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | add_operator 242 | clicked() 243 | operator_2 244 | show() 245 | 246 | 247 | 149 248 | 107 249 | 250 | 251 | 354 252 | 153 253 | 254 | 255 | 256 | 257 | add_operator 258 | clicked() 259 | emoloyee 260 | hide() 261 | 262 | 263 | 114 264 | 99 265 | 266 | 267 | 320 268 | 500 269 | 270 | 271 | 272 | 273 | showEmployeeInfo 274 | clicked() 275 | operator_2 276 | hide() 277 | 278 | 279 | 130 280 | 135 281 | 282 | 283 | 250 284 | 265 285 | 286 | 287 | 288 | 289 | showEmployeeInfo 290 | clicked() 291 | emoloyee 292 | show() 293 | 294 | 295 | 103 296 | 140 297 | 298 | 299 | 272 300 | 577 301 | 302 | 303 | 304 | 305 | 306 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/deleteEmployee.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'deleteEmployee.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | 11 | from PyQt5 import QtCore, QtGui, QtWidgets 12 | from pymysql import * 13 | 14 | 15 | class Ui_Form(object): 16 | def execute_sql(self, sql): 17 | try: 18 | # 执行数据库操作 19 | self.cursor.execute(sql) 20 | # 事务提交 21 | self.db.commit() 22 | except Exception as err: 23 | # 事务回滚 24 | print("hello err") 25 | self.db.rollback() 26 | print("SQL执行错误,原因:", err) 27 | 28 | def setupUi(self, Form): 29 | Form.setObjectName("Form") 30 | Form.resize(422, 269) 31 | self.label = QtWidgets.QLabel(Form) 32 | self.label.setGeometry(QtCore.QRect(90, 70, 61, 16)) 33 | self.label.setObjectName("label") 34 | self.pushButton = QtWidgets.QPushButton(Form) 35 | self.pushButton.setGeometry(QtCore.QRect(90, 150, 93, 28)) 36 | self.pushButton.setObjectName("pushButton") 37 | self.lineEdit = QtWidgets.QLineEdit(Form) 38 | self.lineEdit.setGeometry(QtCore.QRect(170, 70, 161, 21)) 39 | self.lineEdit.setObjectName("lineEdit") 40 | self.pushButton_2 = QtWidgets.QPushButton(Form) 41 | self.pushButton_2.setGeometry(QtCore.QRect(250, 150, 93, 28)) 42 | self.pushButton_2.setObjectName("pushButton_2") 43 | 44 | self.retranslateUi(Form) 45 | QtCore.QMetaObject.connectSlotsByName(Form) 46 | self.statusbar = QtWidgets.QStatusBar(Form) 47 | self.statusbar.setObjectName("statusbar") 48 | Form.setStatusBar(self.statusbar) 49 | self.pushButton.clicked.connect(lambda:self.delEmployee()) 50 | self.pushButton_2.clicked.connect(Form.close) 51 | 52 | def retranslateUi(self, Form): 53 | _translate = QtCore.QCoreApplication.translate 54 | Form.setWindowTitle(_translate("Form", "删除员工")) 55 | self.label.setText(_translate("Form", "员工编号")) 56 | self.pushButton.setText(_translate("Form", "确认")) 57 | self.pushButton_2.setText(_translate("Form", "退出")) 58 | 59 | def delEmployee(self): 60 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 61 | user='root') 62 | # 创建游标对象 63 | self.cursor = self.db.cursor() 64 | 65 | sql = "use bookshopmanagement;" 66 | self.cursor.execute(sql) 67 | if len(self.lineEdit.text()) is 0: 68 | self.statusbar.showMessage("请输入编号", 1500) 69 | else: 70 | sql = "select * from employee" 71 | self.cursor.execute(sql) 72 | data = self.cursor.fetchall() 73 | row = len(data) 74 | num = self.lineEdit.text() 75 | sql = "delete from employee where employeeId = %d ;" % int(num) 76 | self.execute_sql(sql) 77 | sql = "select * from employee" 78 | self.execute_sql(sql) 79 | data = self.cursor.fetchall() 80 | changed_row = len(data) 81 | if changed_row == row - 1: 82 | self.statusbar.showMessage("删除成功,请返回刷新", 1500) 83 | else: 84 | self.statusbar.showMessage("删除失败", 1500) 85 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/deleteEmployee.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 422 10 | 269 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 90 20 | 70 21 | 61 22 | 16 23 | 24 | 25 | 26 | 员工编号 27 | 28 | 29 | 30 | 31 | 32 | 90 33 | 150 34 | 93 35 | 28 36 | 37 | 38 | 39 | 确认 40 | 41 | 42 | 43 | 44 | 45 | 170 46 | 70 47 | 161 48 | 21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 250 56 | 150 57 | 93 58 | 28 59 | 60 | 61 | 62 | 退出 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/deletebook.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 462 10 | 329 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 50 20 | 80 21 | 261 22 | 121 23 | 24 | 25 | 26 | 27 | 28 | 29 | TextLabel 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | TextLabel 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | TextLabel 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/employee.txt: -------------------------------------------------------------------------------- 1 | {"2": "zyh"} -------------------------------------------------------------------------------- /code/pyqt/bookshop/getBookInfo.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InputBookinfo 4 | 5 | 6 | 7 | 0 8 | 0 9 | 516 10 | 326 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 400 20 | 64 21 | 81 22 | 31 23 | 24 | 25 | 26 | 清空 27 | 28 | 29 | 30 | 31 | 32 | 80 33 | 230 34 | 301 35 | 31 36 | 37 | 38 | 39 | 40 | 41 | 42 | 确认 43 | 44 | 45 | 46 | 47 | 48 | 49 | 退出 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 90 59 | 60 60 | 291 61 | 151 62 | 63 | 64 | 65 | 66 | 67 | 68 | 输入ISBN 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 书名 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 作者 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 价格 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | pushButton_2 112 | clicked() 113 | lineEdit_4 114 | clear() 115 | 116 | 117 | 453 118 | 80 119 | 120 | 121 | 346 122 | 197 123 | 124 | 125 | 126 | 127 | pushButton_2 128 | clicked() 129 | lineEdit_3 130 | clear() 131 | 132 | 133 | 480 134 | 72 135 | 136 | 137 | 342 138 | 141 139 | 140 | 141 | 142 | 143 | pushButton_2 144 | clicked() 145 | lineEdit_2 146 | clear() 147 | 148 | 149 | 475 150 | 75 151 | 152 | 153 | 334 154 | 116 155 | 156 | 157 | 158 | 159 | pushButton_2 160 | clicked() 161 | lineEdit 162 | clear() 163 | 164 | 165 | 425 166 | 73 167 | 168 | 169 | 342 170 | 69 171 | 172 | 173 | 174 | 175 | pushButton_3 176 | clicked() 177 | InputBookinfo 178 | close() 179 | 180 | 181 | 270 182 | 248 183 | 184 | 185 | 388 186 | 289 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/insert_addreader.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | from PyQt5 import QtCore, QtGui, QtWidgets 5 | from pymysql import * 6 | 7 | 8 | class Ui_addreader(object): 9 | def execute_sql(self, sql): 10 | try: 11 | # 执行数据库操作 12 | self.cursor.execute(sql) 13 | # 事务提交 14 | self.db.commit() 15 | except Exception as err: 16 | # 事务回滚 17 | print("hello err") 18 | self.db.rollback() 19 | print("SQL执行错误,原因:", err) 20 | 21 | def setupUi(self, Form): 22 | Form.setObjectName("Form") 23 | Form.resize(701, 431) 24 | self.pushButton = QtWidgets.QPushButton(Form) 25 | self.pushButton.setGeometry(QtCore.QRect(540, 70, 93, 28)) 26 | self.pushButton.setObjectName("pushButton") 27 | self.pushButton_2 = QtWidgets.QPushButton(Form) 28 | self.pushButton_2.setGeometry(QtCore.QRect(160, 320, 93, 28)) 29 | self.pushButton_2.setObjectName("pushButton_2") 30 | self.pushButton_3 = QtWidgets.QPushButton(Form) 31 | self.pushButton_3.setGeometry(QtCore.QRect(370, 320, 93, 28)) 32 | self.pushButton_3.setObjectName("pushButton_3") 33 | self.widget = QtWidgets.QWidget(Form) 34 | self.widget.setGeometry(QtCore.QRect(160, 70, 311, 191)) 35 | self.widget.setObjectName("widget") 36 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 37 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 38 | self.gridLayout.setObjectName("gridLayout") 39 | self.label = QtWidgets.QLabel(self.widget) 40 | self.label.setObjectName("label") 41 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 42 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 43 | self.lineEdit.setObjectName("lineEdit") 44 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 45 | self.label_2 = QtWidgets.QLabel(self.widget) 46 | self.label_2.setObjectName("label_2") 47 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 48 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 49 | self.lineEdit_2.setObjectName("lineEdit_2") 50 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 51 | self.label_3 = QtWidgets.QLabel(self.widget) 52 | self.label_3.setObjectName("label_3") 53 | self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) 54 | self.lineEdit_3 = QtWidgets.QLineEdit(self.widget) 55 | self.lineEdit_3.setObjectName("lineEdit_3") 56 | self.gridLayout.addWidget(self.lineEdit_3, 2, 1, 1, 1) 57 | self.label_4 = QtWidgets.QLabel(self.widget) 58 | self.label_4.setObjectName("label_4") 59 | self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1) 60 | self.lineEdit_4 = QtWidgets.QLineEdit(self.widget) 61 | self.lineEdit_4.setObjectName("lineEdit_4") 62 | self.gridLayout.addWidget(self.lineEdit_4, 3, 1, 1, 1) 63 | self.label_5 = QtWidgets.QLabel(self.widget) 64 | self.label_5.setObjectName("label_5") 65 | self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1) 66 | self.lineEdit_5 = QtWidgets.QLineEdit(self.widget) 67 | self.lineEdit_5.setText("") 68 | self.lineEdit_5.setObjectName("lineEdit_5") 69 | self.gridLayout.addWidget(self.lineEdit_5, 4, 1, 1, 1) 70 | 71 | self.statusbar = QtWidgets.QStatusBar(Form) 72 | self.statusbar.setObjectName("statusbar") 73 | Form.setStatusBar(self.statusbar) 74 | 75 | self.retranslateUi(Form) 76 | self.pushButton.clicked.connect(self.lineEdit.clear) 77 | self.pushButton.clicked.connect(self.lineEdit_2.clear) 78 | self.pushButton.clicked.connect(self.lineEdit_3.clear) 79 | self.pushButton.clicked.connect(self.lineEdit_4.clear) 80 | self.pushButton.clicked.connect(self.lineEdit_5.clear) 81 | self.pushButton_3.clicked.connect(Form.close) 82 | QtCore.QMetaObject.connectSlotsByName(Form) 83 | 84 | self.pushButton_2.clicked.connect(lambda: self.insertreader()) 85 | 86 | def retranslateUi(self, Form): 87 | _translate = QtCore.QCoreApplication.translate 88 | Form.setWindowTitle(_translate("Form", "Form")) 89 | self.pushButton.setText(_translate("Form", "清空")) 90 | self.pushButton_2.setText(_translate("Form", "确认")) 91 | self.pushButton_3.setText(_translate("Form", "退出")) 92 | self.label.setText(_translate("Form", "借阅证ID")) 93 | self.label_2.setText(_translate("Form", "姓名")) 94 | self.label_3.setText(_translate("Form", "性别")) 95 | self.label_4.setText(_translate("Form", "年龄")) 96 | self.label_5.setText(_translate("Form", "电话")) 97 | 98 | def insertreader(self): 99 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 100 | user='root') 101 | # 创建游标对象 102 | self.cursor = self.db.cursor() 103 | sql = "use bookshopmanagement" 104 | self.cursor.execute(sql) 105 | 106 | sql = "SELECT * FROM reader" 107 | self.cursor.execute(sql) 108 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 109 | data = self.cursor.fetchall() 110 | original_row = len(data) 111 | 112 | id = self.lineEdit.text() 113 | name = self.lineEdit_2.text() 114 | sex = self.lineEdit_3.text() 115 | age = self.lineEdit_4.text() 116 | tel = self.lineEdit_5.text() 117 | print(id,name,sex,age,tel) 118 | sql ="insert into reader(readerid, readername, sex, age, tel) values ('%d','%s','%s','%d','%s')" % \ 119 | (int(id),name,sex,int(age),tel) 120 | self.cursor.execute(sql) 121 | sql = "SELECT * FROM reader" 122 | self.cursor.execute(sql) 123 | self.cursor.connection.commit() 124 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 125 | new_data = self.cursor.fetchall() 126 | print(new_data) 127 | new_row = len(new_data) 128 | if new_row == original_row + 1: 129 | self.statusbar.showMessage("插入成功,请返回刷新", 2000) 130 | else: 131 | self.statusbar.showMessage("插入失败,请重试", 2000) 132 | self.cursor.close() 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/insert_addreader.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 701 10 | 431 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 540 20 | 70 21 | 93 22 | 28 23 | 24 | 25 | 26 | 清空 27 | 28 | 29 | 30 | 31 | 32 | 160 33 | 320 34 | 93 35 | 28 36 | 37 | 38 | 39 | 确认 40 | 41 | 42 | 43 | 44 | 45 | 370 46 | 320 47 | 93 48 | 28 49 | 50 | 51 | 52 | 退出 53 | 54 | 55 | 56 | 57 | 58 | 160 59 | 70 60 | 311 61 | 191 62 | 63 | 64 | 65 | 66 | 67 | 68 | 借阅证ID 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 姓名 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 性别 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 年龄 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 电话 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | pushButton 126 | clicked() 127 | lineEdit 128 | clear() 129 | 130 | 131 | 568 132 | 84 133 | 134 | 135 | 455 136 | 87 137 | 138 | 139 | 140 | 141 | pushButton 142 | clicked() 143 | lineEdit_2 144 | clear() 145 | 146 | 147 | 628 148 | 86 149 | 150 | 151 | 420 152 | 132 153 | 154 | 155 | 156 | 157 | pushButton 158 | clicked() 159 | lineEdit_3 160 | clear() 161 | 162 | 163 | 584 164 | 76 165 | 166 | 167 | 443 168 | 158 169 | 170 | 171 | 172 | 173 | pushButton 174 | clicked() 175 | lineEdit_4 176 | clear() 177 | 178 | 179 | 568 180 | 80 181 | 182 | 183 | 459 184 | 200 185 | 186 | 187 | 188 | 189 | pushButton 190 | clicked() 191 | lineEdit_5 192 | clear() 193 | 194 | 195 | 556 196 | 77 197 | 198 | 199 | 442 200 | 245 201 | 202 | 203 | 204 | 205 | pushButton_3 206 | clicked() 207 | Form 208 | close() 209 | 210 | 211 | 398 212 | 332 213 | 214 | 215 | 662 216 | 326 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/insert_employee.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from pymysql import * 5 | from PyQt5 import QtCore, QtGui, QtWidgets 6 | from PyQt5.QtWidgets import QApplication 7 | 8 | 9 | class Ui_insert_employee(object): 10 | def execute_sql(self, sql): 11 | try: 12 | # 执行数据库操作 13 | self.cursor.execute(sql) 14 | # 事务提交 15 | self.db.commit() 16 | except Exception as err: 17 | # 事务回滚 18 | print("hello err") 19 | self.db.rollback() 20 | print("SQL执行错误,原因:", err) 21 | 22 | def setupUi(self, insert_employee): 23 | insert_employee.setObjectName("insert_employee") 24 | insert_employee.resize(781, 523) 25 | self.pushButton = QtWidgets.QPushButton(insert_employee) 26 | self.pushButton.setGeometry(QtCore.QRect(540, 80, 93, 28)) 27 | self.pushButton.setObjectName("pushButton") 28 | self.pushButton_2 = QtWidgets.QPushButton(insert_employee) 29 | self.pushButton_2.setGeometry(QtCore.QRect(540, 150, 93, 28)) 30 | self.pushButton_2.setObjectName("pushButton_2") 31 | self.pushButton_3 = QtWidgets.QPushButton(insert_employee) 32 | self.pushButton_3.setGeometry(QtCore.QRect(540, 220, 93, 28)) 33 | self.pushButton_3.setObjectName("pushButton_3") 34 | self.widget = QtWidgets.QWidget(insert_employee) 35 | self.widget.setGeometry(QtCore.QRect(120, 70, 331, 221)) 36 | self.widget.setObjectName("widget") 37 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 38 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 39 | self.gridLayout.setObjectName("gridLayout") 40 | self.label_4 = QtWidgets.QLabel(self.widget) 41 | self.label_4.setObjectName("label_4") 42 | self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1) 43 | self.label_6 = QtWidgets.QLabel(self.widget) 44 | self.label_6.setObjectName("label_6") 45 | self.gridLayout.addWidget(self.label_6, 5, 0, 1, 1) 46 | self.label = QtWidgets.QLabel(self.widget) 47 | self.label.setObjectName("label") 48 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 49 | self.label_3 = QtWidgets.QLabel(self.widget) 50 | self.label_3.setObjectName("label_3") 51 | self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) 52 | self.label_5 = QtWidgets.QLabel(self.widget) 53 | self.label_5.setObjectName("label_5") 54 | self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1) 55 | self.label_2 = QtWidgets.QLabel(self.widget) 56 | self.label_2.setObjectName("label_2") 57 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 58 | self.radioButton = QtWidgets.QRadioButton(self.widget) 59 | self.radioButton.setObjectName("radioButton") 60 | self.gridLayout.addWidget(self.radioButton, 2, 1, 1, 1) 61 | self.radioButton_2 = QtWidgets.QRadioButton(self.widget) 62 | self.radioButton_2.setObjectName("radioButton_2") 63 | self.gridLayout.addWidget(self.radioButton_2, 2, 2, 1, 1) 64 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 65 | self.lineEdit_2.setObjectName("lineEdit_2") 66 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 2) 67 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 68 | self.lineEdit.setObjectName("lineEdit") 69 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 2) 70 | self.lineEdit_4 = QtWidgets.QLineEdit(self.widget) 71 | self.lineEdit_4.setObjectName("lineEdit_4") 72 | self.gridLayout.addWidget(self.lineEdit_4, 3, 1, 1, 2) 73 | self.lineEdit_5 = QtWidgets.QLineEdit(self.widget) 74 | self.lineEdit_5.setObjectName("lineEdit_5") 75 | self.gridLayout.addWidget(self.lineEdit_5, 4, 1, 1, 2) 76 | self.lineEdit_6 = QtWidgets.QLineEdit(self.widget) 77 | self.lineEdit_6.setObjectName("lineEdit_6") 78 | self.gridLayout.addWidget(self.lineEdit_6, 5, 1, 1, 2) 79 | 80 | self.statusbar = QtWidgets.QStatusBar(insert_employee) 81 | self.statusbar.setObjectName("statusbar") 82 | insert_employee.setStatusBar(self.statusbar) 83 | 84 | self.sex = None 85 | self.radioButton.clicked.connect(lambda: self.chooseSex_male()) 86 | self.radioButton_2.clicked.connect(lambda: self.chooseSex_female()) 87 | self.retranslateUi(insert_employee) 88 | self.pushButton_2.clicked.connect(self.lineEdit.clear) 89 | self.pushButton_2.clicked.connect(self.lineEdit_2.clear) 90 | self.pushButton_2.clicked.connect(self.lineEdit_4.clear) 91 | self.pushButton_2.clicked.connect(self.lineEdit_5.clear) 92 | self.pushButton_2.clicked.connect(self.lineEdit_6.clear) 93 | self.pushButton_3.clicked.connect(insert_employee.close) 94 | QtCore.QMetaObject.connectSlotsByName(insert_employee) 95 | 96 | self.pushButton.clicked.connect(lambda: self.insertEmployee()) 97 | 98 | def retranslateUi(self, insert_employee): 99 | _translate = QtCore.QCoreApplication.translate 100 | insert_employee.setWindowTitle(_translate("insert_employee", "Form")) 101 | self.pushButton.setText(_translate("insert_employee", "确认")) 102 | self.pushButton_2.setText(_translate("insert_employee", "清空")) 103 | self.pushButton_3.setText(_translate("insert_employee", "退出")) 104 | self.label_4.setText(_translate("insert_employee", "年龄")) 105 | self.label_6.setText(_translate("insert_employee", "工资")) 106 | self.label.setText(_translate("insert_employee", "雇员ID")) 107 | self.label_3.setText(_translate("insert_employee", "性别")) 108 | self.label_5.setText(_translate("insert_employee", "电话")) 109 | self.label_2.setText(_translate("insert_employee", "姓名")) 110 | self.radioButton.setText(_translate("insert_employee", "男")) 111 | self.radioButton_2.setText(_translate("insert_employee", "女")) 112 | 113 | 114 | def chooseSex_male(self): 115 | self.sex = "男" 116 | 117 | def chooseSex_female(self): 118 | self.sex = "女" 119 | 120 | def insertEmployee(self): 121 | id = self.lineEdit.text() 122 | name = self.lineEdit_2.text() 123 | if self.sex is None: 124 | self.statusbar.showMessage("请选择性别", 2000) 125 | else: 126 | salary = self.lineEdit_6.text() 127 | tel = self.lineEdit_5.text() 128 | age = self.lineEdit_4.text() 129 | print(id, name, self.sex, salary, tel, age) 130 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 131 | user='root') 132 | # 创建游标对象 133 | self.cursor = self.db.cursor() 134 | 135 | sql = "use bookshopmanagement" 136 | self.cursor.execute(sql) 137 | sql = "select * from employee" 138 | self.execute_sql(sql) 139 | data = self.cursor.fetchall() 140 | original_row = len(data) 141 | sql = "insert into employee VALUES (" \ 142 | " '%d','%s','%s','%d','%s','%d') " %(int(id), name, self.sex, int(age), tel, int(salary)) 143 | self.execute_sql(sql) 144 | sql = "select * from employee" 145 | self.execute_sql(sql) 146 | data = self.cursor.fetchall() 147 | changed_row = len(data) 148 | if changed_row == original_row+1: 149 | self.statusbar.showMessage("增加成功", 2000) 150 | else: 151 | self.statusbar.showMessage("增加失败",2000) 152 | 153 | 154 | 155 | if __name__ == '__main__': 156 | # db = QtSql.QSqlDatabase.addDatabase('QMYSQL') 157 | # db.setPort(3306) 158 | # db.setHostName('localhost') 159 | # db.setDatabaseName('bookshopmanagement') 160 | # db.setUserName('root') 161 | # db.setPassword('zyh20000205') 162 | 163 | # print(db.open()) 164 | 165 | app = QApplication(sys.argv) 166 | mainWindow = QtWidgets.QMainWindow() 167 | test_ui = Ui_insert_employee() 168 | test_ui.setupUi(mainWindow) 169 | mainWindow.show() 170 | sys.exit(app.exec_()) 171 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/insert_employee.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | insert_employee 4 | 5 | 6 | 7 | 0 8 | 0 9 | 781 10 | 523 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 540 20 | 80 21 | 93 22 | 28 23 | 24 | 25 | 26 | 确认 27 | 28 | 29 | 30 | 31 | 32 | 540 33 | 150 34 | 93 35 | 28 36 | 37 | 38 | 39 | 清空 40 | 41 | 42 | 43 | 44 | 45 | 540 46 | 220 47 | 93 48 | 28 49 | 50 | 51 | 52 | 退出 53 | 54 | 55 | 56 | 57 | 58 | 120 59 | 70 60 | 331 61 | 221 62 | 63 | 64 | 65 | 66 | 67 | 68 | 年龄 69 | 70 | 71 | 72 | 73 | 74 | 75 | 工资 76 | 77 | 78 | 79 | 80 | 81 | 82 | 雇员ID 83 | 84 | 85 | 86 | 87 | 88 | 89 | 性别 90 | 91 | 92 | 93 | 94 | 95 | 96 | 电话 97 | 98 | 99 | 100 | 101 | 102 | 103 | 姓名 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | pushButton_2 143 | clicked() 144 | lineEdit 145 | clear() 146 | 147 | 148 | 595 149 | 165 150 | 151 | 152 | 373 153 | 90 154 | 155 | 156 | 157 | 158 | pushButton_2 159 | clicked() 160 | lineEdit_2 161 | clear() 162 | 163 | 164 | 574 165 | 157 166 | 167 | 168 | 425 169 | 126 170 | 171 | 172 | 173 | 174 | pushButton_2 175 | clicked() 176 | lineEdit_4 177 | clear() 178 | 179 | 180 | 551 181 | 165 182 | 183 | 184 | 411 185 | 196 186 | 187 | 188 | 189 | 190 | pushButton_2 191 | clicked() 192 | lineEdit_5 193 | clear() 194 | 195 | 196 | 621 197 | 165 198 | 199 | 200 | 444 201 | 224 202 | 203 | 204 | 205 | 206 | pushButton_2 207 | clicked() 208 | lineEdit_6 209 | clear() 210 | 211 | 212 | 608 213 | 163 214 | 215 | 216 | 382 217 | 264 218 | 219 | 220 | 221 | 222 | pushButton_3 223 | clicked() 224 | insert_employee 225 | close() 226 | 227 | 228 | 552 229 | 234 230 | 231 | 232 | 569 233 | 338 234 | 235 | 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchbook.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | 5 | from PyQt5 import QtCore, QtGui, QtWidgets,QtSql 6 | from PyQt5.QtWidgets import QApplication 7 | from pymysql import * 8 | 9 | class Ui_searchbook(object): 10 | def execute_sql(self, sql): 11 | try: 12 | # 执行数据库操作 13 | self.cursor.execute(sql) 14 | # 事务提交 15 | self.db.commit() 16 | except Exception as err: 17 | # 事务回滚 18 | self.db.rollback() 19 | print("SQL执行错误,原因:", err) 20 | 21 | def setupUi(self, Form): 22 | Form.setObjectName("Form") 23 | Form.resize(726, 491) 24 | self.pushButton = QtWidgets.QPushButton(Form) 25 | self.pushButton.setGeometry(QtCore.QRect(510, 70, 93, 21)) 26 | self.pushButton.setObjectName("pushButton") 27 | self.pushButton_2 = QtWidgets.QPushButton(Form) 28 | self.pushButton_2.setGeometry(QtCore.QRect(510, 140, 93, 28)) 29 | self.pushButton_2.setObjectName("pushButton_2") 30 | self.tableView = QtWidgets.QTableView(Form) 31 | self.tableView.setGeometry(QtCore.QRect(110, 210, 491, 211)) 32 | self.tableView.setObjectName("tableView") 33 | self.widget = QtWidgets.QWidget(Form) 34 | self.widget.setGeometry(QtCore.QRect(110, 60, 341, 111)) 35 | self.widget.setObjectName("widget") 36 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 37 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 38 | self.gridLayout.setObjectName("gridLayout") 39 | self.label = QtWidgets.QLabel(self.widget) 40 | self.label.setObjectName("label") 41 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 42 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 43 | self.lineEdit.setObjectName("lineEdit") 44 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 45 | self.label_2 = QtWidgets.QLabel(self.widget) 46 | self.label_2.setObjectName("label_2") 47 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 48 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 49 | self.lineEdit_2.setObjectName("lineEdit_2") 50 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 51 | self.statusbar = QtWidgets.QStatusBar(Form) 52 | self.statusbar.setObjectName("statusbar") 53 | Form.setStatusBar(self.statusbar) 54 | self.retranslateUi(Form) 55 | self.pushButton_2.clicked.connect(Form.close) 56 | QtCore.QMetaObject.connectSlotsByName(Form) 57 | 58 | self.pushButton.clicked.connect(lambda: self.searchbook()) 59 | def retranslateUi(self, Form): 60 | _translate = QtCore.QCoreApplication.translate 61 | Form.setWindowTitle(_translate("Form", "搜索书籍")) 62 | self.pushButton.setText(_translate("Form", "确认")) 63 | self.pushButton_2.setText(_translate("Form", "退出")) 64 | self.label.setText(_translate("Form", "ISBN")) 65 | self.label_2.setText(_translate("Form", "作者")) 66 | 67 | def searchbook(self): 68 | isbn = self.lineEdit.text() 69 | author = self.lineEdit_2.text() 70 | self.model = QtSql.QSqlTableModel() 71 | self.tableView.setModel(self.model) 72 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 73 | user='root') 74 | # 创建游标对象 75 | self.cursor = self.db.cursor() 76 | sql = "use bookshopmanagement" 77 | self.cursor.execute(sql) 78 | while True: 79 | if len(isbn) is 0 and len(author) is not 0: 80 | sql = "select book.ISBN,BookName,Author,Price,TotalNum " \ 81 | "from book left join collectionofbook c on book.ISBN = c.ISBN where author = '%s' " % author 82 | break 83 | elif len(isbn) is not 0 and len(author) is 0: 84 | sql = "select book.ISBN,BookName,Author,Price,TotalNum " \ 85 | " from book left join collectionofbook c on book.ISBN = c.ISBN where book.ISBN = '%s' " % isbn 86 | break 87 | elif len(isbn) is not 0 and len(author) is not 0: 88 | sql = "select book.ISBN,BookName,Author,Price,TotalNum " \ 89 | " from book left join collectionofbook c on book.ISBN = c.ISBN " \ 90 | "where book.ISBN = '%s' and author = '%s' " % (isbn, author) 91 | self.statusbar.showMessage("请输入信息", 2000) 92 | 93 | # 定义SQL语句 94 | print(isbn, author) 95 | self.execute_sql(sql) 96 | data = self.cursor.fetchall() 97 | row = len(data) 98 | print(row) 99 | if row is not 0: 100 | model = QtGui.QStandardItemModel(row, len(data[0])) 101 | col = len(data[0]) 102 | for i in range(row): 103 | for j in range(len(data[0])): 104 | if j is not 3 and j is not 4: 105 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 106 | else: 107 | if data[i][j] is None: 108 | model.setItem(i, j, QtGui.QStandardItem(str(0))) 109 | else: 110 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 111 | self.cursor.close() 112 | model.setHorizontalHeaderLabels(['ISBN', "书名", "作者", "定价", "存货"]) 113 | self.tableView.setModel(model) 114 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 115 | 116 | 117 | if __name__ == '__main__': 118 | app = QApplication(sys.argv) 119 | mainWindow = QtWidgets.QMainWindow() 120 | test_ui = Ui_searchbook() 121 | test_ui.setupUi(mainWindow) 122 | mainWindow.show() 123 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchbook.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 726 10 | 491 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 510 20 | 70 21 | 93 22 | 21 23 | 24 | 25 | 26 | 确认 27 | 28 | 29 | 30 | 31 | 32 | 510 33 | 140 34 | 93 35 | 28 36 | 37 | 38 | 39 | 退出 40 | 41 | 42 | 43 | 44 | 45 | 110 46 | 210 47 | 491 48 | 211 49 | 50 | 51 | 52 | 53 | 54 | 55 | 110 56 | 60 57 | 341 58 | 111 59 | 60 | 61 | 62 | 63 | 64 | 65 | ISBN 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 作者 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | pushButton_2 89 | clicked() 90 | Form 91 | close() 92 | 93 | 94 | 535 95 | 151 96 | 97 | 98 | 703 99 | 182 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchborrowAndreturn.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'searchborrowAndreturn.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | import sys 10 | 11 | from PyQt5.QtWidgets import QApplication 12 | from pymysql import * 13 | from PyQt5 import QtCore, QtGui, QtWidgets, QtSql 14 | 15 | 16 | class Ui_searchBorrowInfo(object): 17 | def setupUi(self, Form): 18 | Form.setObjectName("Form") 19 | Form.resize(801, 577) 20 | self.searchborrow = QtWidgets.QTableView(Form) 21 | self.searchborrow.setGeometry(QtCore.QRect(80, 230, 531, 271)) 22 | self.searchborrow.setObjectName("searchborrow") 23 | self.radioButton = QtWidgets.QRadioButton(Form) 24 | self.radioButton.setGeometry(QtCore.QRect(140, 170, 115, 19)) 25 | self.radioButton.setObjectName("radioButton") 26 | self.radioButton_2 = QtWidgets.QRadioButton(Form) 27 | self.radioButton_2.setGeometry(QtCore.QRect(350, 170, 115, 19)) 28 | self.radioButton_2.setObjectName("radioButton_2") 29 | self.widget = QtWidgets.QWidget(Form) 30 | self.widget.setGeometry(QtCore.QRect(100, 30, 491, 91)) 31 | self.widget.setObjectName("widget") 32 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 33 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 34 | self.gridLayout.setObjectName("gridLayout") 35 | self.label_2 = QtWidgets.QLabel(self.widget) 36 | self.label_2.setObjectName("label_2") 37 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 38 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 39 | self.lineEdit_2.setObjectName("lineEdit_2") 40 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 41 | self.label = QtWidgets.QLabel(self.widget) 42 | self.label.setObjectName("label") 43 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 44 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 45 | self.lineEdit.setObjectName("lineEdit") 46 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 47 | self.widget1 = QtWidgets.QWidget(Form) 48 | self.widget1.setGeometry(QtCore.QRect(630, 30, 111, 141)) 49 | self.widget1.setObjectName("widget1") 50 | self.verticalLayout = QtWidgets.QVBoxLayout(self.widget1) 51 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 52 | self.verticalLayout.setObjectName("verticalLayout") 53 | self.pushButton_2 = QtWidgets.QPushButton(self.widget1) 54 | self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 55 | self.pushButton_2.setObjectName("pushButton_2") 56 | self.verticalLayout.addWidget(self.pushButton_2) 57 | self.pushButton = QtWidgets.QPushButton(self.widget1) 58 | self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 59 | self.pushButton.setObjectName("pushButton") 60 | self.verticalLayout.addWidget(self.pushButton) 61 | self.pushButton_3 = QtWidgets.QPushButton(self.widget1) 62 | self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 63 | self.pushButton_3.setObjectName("pushButton_3") 64 | self.verticalLayout.addWidget(self.pushButton_3) 65 | 66 | self.retranslateUi(Form) 67 | self.pushButton.clicked.connect(self.lineEdit_2.clear) 68 | self.pushButton.clicked.connect(self.lineEdit.clear) 69 | self.pushButton_3.clicked.connect(Form.close) 70 | QtCore.QMetaObject.connectSlotsByName(Form) 71 | 72 | self.statusbar = QtWidgets.QStatusBar(Form) 73 | self.statusbar.setObjectName("statusbar") 74 | Form.setStatusBar(self.statusbar) 75 | self.priority = 0 76 | self.radioButton.clicked.connect(lambda: self.borrow_choosed()) 77 | self.radioButton_2.clicked.connect(lambda: self.return_choosed()) 78 | self.pushButton_2.clicked.connect(lambda: self.getInfo()) 79 | 80 | def retranslateUi(self, Form): 81 | _translate = QtCore.QCoreApplication.translate 82 | Form.setWindowTitle(_translate("Form", "搜索借阅信息")) 83 | self.radioButton.setText(_translate("Form", "查询借阅")) 84 | self.radioButton_2.setText(_translate("Form", "查询还书")) 85 | self.label_2.setText(_translate("Form", "借阅证ID")) 86 | self.label.setText(_translate("Form", "ISBN")) 87 | self.pushButton_2.setText(_translate("Form", "确认")) 88 | self.pushButton.setText(_translate("Form", "清空")) 89 | self.pushButton_3.setText(_translate("Form", "退出")) 90 | 91 | def getInfo(self): 92 | if self.priority is 0: 93 | self.statusbar.showMessage("请选择查询信息") 94 | elif self.priority is 1: 95 | self.searchBorrowInfo() 96 | # self.pushButton_2.clicked.connect(lambda: self.searchBorrowInfo()) 97 | elif self.priority is 2: 98 | self.searchReturnInfo() 99 | 100 | def searchBorrowInfo(self): 101 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 102 | user='root') 103 | # 创建游标对象 104 | self.cursor = self.db.cursor() 105 | sql = "use bookshopmanagement" 106 | self.cursor.execute(sql) 107 | ISBN = self.lineEdit.text() 108 | print(ISBN) 109 | readerID = self.lineEdit_2.text() 110 | flag = False 111 | if len(ISBN) is 0 and len(readerID) is 0: 112 | self.statusbar.showMessage("请输入信息") 113 | elif len(ISBN) is not 0 and len(readerID) is 0: 114 | sql = "select * from borrow where isbn = '%s' " % ISBN 115 | flag = True 116 | elif len(ISBN) is 0 and len(readerID) is not 0: 117 | sql = "select * from borrow where readerid = '%d' " % int(readerID) 118 | flag = True 119 | elif len(ISBN) is not 0 and len(readerID) is not 0: 120 | sql = "select * from borrow where read ='%d' and isbn = '%s' " %(int(readerID), ISBN) 121 | flag = True 122 | if flag: 123 | self.cursor.execute(sql) 124 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 125 | data = self.cursor.fetchall() 126 | print(data) 127 | self.model = QtSql.QSqlTableModel() 128 | self.searchborrow.setModel(self.model) 129 | row = len(data) 130 | model = QtGui.QStandardItemModel(row, len(data[0])) 131 | col = len(data[0]) 132 | for i in range(row): 133 | for j in range(len(data[0])): 134 | if j is 3: 135 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 136 | elif j is 1: 137 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 138 | elif j is 0 or j is 2: 139 | if data[i][j] is None: 140 | model.setItem(i, j, QtGui.QStandardItem(str(0))) 141 | else: 142 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 143 | self.cursor.close() 144 | model.setHorizontalHeaderLabels(['借书编号', '借阅时间', '借阅证ID', 'ISBN']) 145 | self.searchborrow.setModel(model) 146 | 147 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 148 | 149 | def searchReturnInfo(self): 150 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 151 | user='root') 152 | # 创建游标对象 153 | self.cursor = self.db.cursor() 154 | sql = "use bookshopmanagement" 155 | self.cursor.execute(sql) 156 | ISBN = self.lineEdit.text() 157 | print(ISBN) 158 | readerID = self.lineEdit_2.text() 159 | flag = False 160 | if len(ISBN) is 0 and len(readerID) is 0: 161 | self.statusbar.showMessage("请输入信息") 162 | elif len(ISBN) is not 0 and len(readerID) is 0: 163 | sql = "select * from returnofbook where isbn = '%s' " % ISBN 164 | flag = True 165 | elif len(ISBN) is 0 and len(readerID) is not 0: 166 | sql = "select * from returnofbook where readerid = '%d' " % int(readerID) 167 | flag = True 168 | elif len(ISBN) is not 0 and len(readerID) is not 0: 169 | sql = "select * from returnofbook where read ='%d' and isbn = '%s' " % (int(readerID), ISBN) 170 | flag = True 171 | if flag: 172 | self.cursor.execute(sql) 173 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 174 | data = self.cursor.fetchall() 175 | print(data) 176 | self.model = QtSql.QSqlTableModel() 177 | self.searchborrow.setModel(self.model) 178 | row = len(data) 179 | model = QtGui.QStandardItemModel(row, len(data[0])) 180 | col = len(data[0]) 181 | for i in range(row): 182 | for j in range(len(data[0])): 183 | if j is 3: 184 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 185 | elif j is 1: 186 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 187 | elif j is 0 or j is 2: 188 | if data[i][j] is None: 189 | model.setItem(i, j, QtGui.QStandardItem(str(0))) 190 | else: 191 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 192 | self.cursor.close() 193 | model.setHorizontalHeaderLabels(['还书编号', '还书时间', '借阅证ID', 'ISBN']) 194 | self.searchborrow.setModel(model) 195 | 196 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 197 | 198 | def borrow_choosed(self): 199 | self.priority = 1 200 | 201 | def return_choosed(self): 202 | self.priority = 2 203 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchborrowAndreturn.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 801 10 | 577 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 80 20 | 230 21 | 531 22 | 271 23 | 24 | 25 | 26 | 27 | 28 | 29 | 140 30 | 170 31 | 115 32 | 19 33 | 34 | 35 | 36 | 查询借阅 37 | 38 | 39 | 40 | 41 | 42 | 350 43 | 170 44 | 115 45 | 19 46 | 47 | 48 | 49 | 查询还书 50 | 51 | 52 | 53 | 54 | 55 | 100 56 | 30 57 | 491 58 | 91 59 | 60 | 61 | 62 | 63 | 64 | 65 | 借阅证ID 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ISBN 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 630 88 | 30 89 | 111 90 | 141 91 | 92 | 93 | 94 | 95 | 96 | 97 | PointingHandCursor 98 | 99 | 100 | 确认 101 | 102 | 103 | 104 | 105 | 106 | 107 | PointingHandCursor 108 | 109 | 110 | 清空 111 | 112 | 113 | 114 | 115 | 116 | 117 | PointingHandCursor 118 | 119 | 120 | 退出 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | pushButton 131 | clicked() 132 | lineEdit_2 133 | clear() 134 | 135 | 136 | 676 137 | 103 138 | 139 | 140 | 564 141 | 88 142 | 143 | 144 | 145 | 146 | pushButton 147 | clicked() 148 | lineEdit 149 | clear() 150 | 151 | 152 | 687 153 | 109 154 | 155 | 156 | 564 157 | 49 158 | 159 | 160 | 161 | 162 | pushButton_3 163 | clicked() 164 | Form 165 | close() 166 | 167 | 168 | 644 169 | 153 170 | 171 | 172 | 672 173 | 307 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchreader.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'searchreader.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | import sys 11 | 12 | from PyQt5 import QtCore, QtGui, QtWidgets,QtSql 13 | from PyQt5.QtWidgets import QApplication, QMainWindow 14 | from pymysql import * 15 | 16 | class Ui_searchreader(object): 17 | def execute_sql(self, sql): 18 | try: 19 | # 执行数据库操作 20 | self.cursor.execute(sql) 21 | # 事务提交 22 | self.db.commit() 23 | except Exception as err: 24 | # 事务回滚 25 | print("hello err") 26 | self.db.rollback() 27 | print("SQL执行错误,原因:", err) 28 | 29 | def setupUi(self, searchreader): 30 | searchreader.setObjectName("searchreader") 31 | searchreader.resize(671, 533) 32 | self.pushButton = QtWidgets.QPushButton(searchreader) 33 | self.pushButton.setGeometry(QtCore.QRect(480, 59, 93, 28)) 34 | self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 35 | self.pushButton.setObjectName("pushButton") 36 | self.pushButton_2 = QtWidgets.QPushButton(searchreader) 37 | self.pushButton_2.setGeometry(QtCore.QRect(480, 129, 93, 28)) 38 | self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 39 | self.pushButton_2.setObjectName("pushButton_2") 40 | self.tableView = QtWidgets.QTableView(searchreader) 41 | self.tableView.setGeometry(QtCore.QRect(110, 230, 461, 201)) 42 | self.tableView.setObjectName("tableView") 43 | self.widget = QtWidgets.QWidget(searchreader) 44 | self.widget.setGeometry(QtCore.QRect(110, 40, 271, 141)) 45 | self.widget.setObjectName("widget") 46 | self.gridLayout = QtWidgets.QGridLayout(self.widget) 47 | self.gridLayout.setContentsMargins(0, 0, 0, 0) 48 | self.gridLayout.setObjectName("gridLayout") 49 | self.label = QtWidgets.QLabel(self.widget) 50 | self.label.setObjectName("label") 51 | self.gridLayout.addWidget(self.label, 0, 0, 1, 1) 52 | self.lineEdit = QtWidgets.QLineEdit(self.widget) 53 | self.lineEdit.setObjectName("lineEdit") 54 | self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) 55 | self.label_2 = QtWidgets.QLabel(self.widget) 56 | self.label_2.setObjectName("label_2") 57 | self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) 58 | self.lineEdit_2 = QtWidgets.QLineEdit(self.widget) 59 | self.lineEdit_2.setObjectName("lineEdit_2") 60 | self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) 61 | self.statusbar = QtWidgets.QStatusBar(searchreader) 62 | self.statusbar.setObjectName("statusbar") 63 | searchreader.setStatusBar(self.statusbar) 64 | self.retranslateUi(searchreader) 65 | self.pushButton_2.clicked.connect(searchreader.close) 66 | QtCore.QMetaObject.connectSlotsByName(searchreader) 67 | 68 | self.pushButton.clicked.connect(lambda: self.search_reader()) 69 | 70 | def retranslateUi(self, searchreader): 71 | _translate = QtCore.QCoreApplication.translate 72 | searchreader.setWindowTitle(_translate("searchreader", "Form")) 73 | self.pushButton.setText(_translate("searchreader", "确认")) 74 | self.pushButton_2.setText(_translate("searchreader", "退出")) 75 | self.label.setText(_translate("searchreader", "借阅证ID")) 76 | self.label_2.setText(_translate("searchreader", "电话")) 77 | 78 | def search_reader(self): 79 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 80 | user='root') 81 | # 创建游标对象 82 | self.cursor = self.db.cursor() 83 | 84 | sql = "use bookshopmanagement" 85 | self.cursor.execute(sql) 86 | self.model = QtSql.QSqlTableModel() 87 | self.tableView.setModel(self.model) 88 | readerid = self.lineEdit.text() 89 | tel = self.lineEdit_2.text() 90 | print(readerid,tel) 91 | flag = False 92 | while True: 93 | if len(readerid) is 0 and len(tel) is not 0: 94 | sql = "select * from reader where TEL like '%s';" % ("%"+tel+"%") 95 | flag = True 96 | break 97 | elif len(readerid) is not 0 and len(tel) is 0: 98 | sql = "select * from reader where readerid = '%d';" % int(readerid) 99 | flag = True 100 | break 101 | else: 102 | self.statusbar.showMessage("请输入id或者手机号", 3000) 103 | break 104 | if flag: 105 | print(sql) 106 | self.execute_sql(sql) 107 | data = self.cursor.fetchall() 108 | row = len(data) 109 | print(row) 110 | if row is not 0: 111 | model = QtGui.QStandardItemModel(row, len(data[0])) 112 | col = len(data[0]) 113 | for i in range(row): 114 | for j in range(len(data[0])): 115 | if j is not 0 and j is not 3: 116 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 117 | else: 118 | if data[i][j] is None: 119 | model.setItem(i, j, QtGui.QStandardItem(str(0))) 120 | else: 121 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 122 | self.cursor.close() 123 | model.setHorizontalHeaderLabels(['借阅证ID', '姓名', '性别', '年龄', '电话']) 124 | self.tableView.setModel(model) 125 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 126 | else: 127 | self.statusbar.showMessage("请输入信息") 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/searchreader.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | searchreader 4 | 5 | 6 | 7 | 0 8 | 0 9 | 671 10 | 533 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 480 20 | 59 21 | 93 22 | 28 23 | 24 | 25 | 26 | PointingHandCursor 27 | 28 | 29 | 确认 30 | 31 | 32 | 33 | 34 | 35 | 480 36 | 129 37 | 93 38 | 28 39 | 40 | 41 | 42 | PointingHandCursor 43 | 44 | 45 | 退出 46 | 47 | 48 | 49 | 50 | 51 | 110 52 | 230 53 | 461 54 | 201 55 | 56 | 57 | 58 | 59 | 60 | 61 | 110 62 | 40 63 | 271 64 | 141 65 | 66 | 67 | 68 | 69 | 70 | 71 | 借阅证ID 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 电话 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | pushButton_2 95 | clicked() 96 | searchreader 97 | close() 98 | 99 | 100 | 522 101 | 157 102 | 103 | 104 | 627 105 | 231 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/tableDefinition.txt: -------------------------------------------------------------------------------- 1 | 2 | create database BookshopManagemen; 3 | use BookshopManagement; 4 | 5 | create table Reader( 6 | ReaderID int, 7 | ReaderName varchar(10) default '张三', 8 | Sex varchar(1), 9 | Age int default 18, 10 | TEL varchar(12) default NULL, 11 | primary key (ReaderID), 12 | unique (ReaderID), 13 | CHECK ( Sex='男' or Sex='女') 14 | ); 15 | 16 | create table Book( 17 | ISBN varchar(20), 18 | BookName varchar(20) not null , 19 | Author varchar(20) default ' ', 20 | Price int , 21 | primary key (ISBN), 22 | unique (ISBN), 23 | check ( Price>0 ) 24 | ); 25 | 26 | create table CollectionOfBook( 27 | ISBN varchar(20), 28 | TotalNum int default 0, 29 | foreign key (ISBN) 30 | references Book(ISBN) 31 | ); 32 | 33 | alter table collectionofbook add constraint check(TotalNum>=0); 34 | drop table borrow; 35 | 36 | 37 | create table Borrow( 38 | borrowID int primary key auto_increment, 39 | BorrowTime DATE , 40 | ReaderID int, 41 | ISBN varchar(20), 42 | foreign key (ReaderID) 43 | references Reader(ReaderID), 44 | foreign key (ISBN) 45 | references collectionofbook(ISBN) 46 | ); 47 | drop table sell; 48 | create table Sell( 49 | sell_id int auto_increment primary key , 50 | ISBN varchar(20), 51 | AlreadySold int, 52 | price int check ( price>=0 ), 53 | FOREIGN KEY (ISBN) 54 | references Book(ISBN) 55 | ); 56 | 57 | create table PurchaseBook( 58 | PurchaseID int primary key auto_increment, 59 | ISBN varchar(20) , 60 | Price int, 61 | PurchaseNum int, 62 | foreign key (ISBN) 63 | references Book(ISBN) 64 | ); 65 | 66 | CREATE table Employee( 67 | EmployeeID int primary key , 68 | EmployName varchar(20), 69 | EmploySex varchar(1), 70 | EmployAge int, 71 | EmployTEL varchar(20), 72 | Salary int, 73 | check ( EmploySex ='男' or EmploySex = '女') 74 | ); 75 | 76 | drop table returnofbook; 77 | create table ReturnOfBook( 78 | returnID int primary key auto_increment, 79 | ReturnTime DATE, 80 | ReaderID int, 81 | ISBN varchar(20), 82 | foreign key (ReaderID) 83 | references Reader(ReaderID), 84 | foreign key (ISBN) 85 | references collectionofbook(ISBN) 86 | ); 87 | 88 | insert into reader(readerid, readername, sex, age, tel) values ( 89 | 1,'zyh','男',20,'19825300946' 90 | ); 91 | 92 | insert into book(ISBN, BookName, Author, Price) values ( 93 | '151515-4654-545','数据库系统概论','王珊',50 94 | ); 95 | insert into collectionofbook(isbn, totalnum) 96 | drop trigger increaseNumberOfBooks; 97 | 98 | create trigger increaseNumberOfBooks after insert on purchasebook 99 | for each row 100 | begin 101 | if not exists(select 1 from collectionofbook where NEW.ISBN in(select ISBN from collectionofbook)) then 102 | begin 103 | insert into CollectionOfBook(ISBN, TotalNum) VALUE (NEW.ISBN,NEW.PurchaseNum); 104 | end; 105 | else 106 | begin 107 | update CollectionOfBook set TotalNum = TotalNum+NEW.PurchaseNum 108 | where CollectionOfBook.ISBN = NEW.ISBN; 109 | end; 110 | end if; 111 | end; 112 | select version(); 113 | 114 | 115 | drop trigger decreaseNumberOfBooks; 116 | create trigger decreaseNumberOfBooks after insert on sell 117 | for each row 118 | begin 119 | update CollectionOfBook set TotalNum = TotalNum-NEW.AlreadySold 120 | where CollectionOfBook.ISBN = NEW.ISBN; 121 | end; 122 | 123 | create trigger borrowBook before insert on borrow 124 | for each row 125 | begin 126 | if (select TotalNum from collectionofbook where CollectionOfBook.ISBN 127 | = NEW.ISBN 128 | ) -1 >=0 then 129 | update collectionofbook set TotalNum = TotalNum-1 where CollectionOfBook.ISBN 130 | = NEW.ISBN; 131 | end if; 132 | end; 133 | 134 | insert into borrow(borrowtime, readerid, isbn) VALUES ('2020-6-23','1','1'); 135 | 136 | 137 | create trigger ReturnBook before insert on returnofbook 138 | for each row 139 | begin 140 | update collectionofbook set TotalNum = TotalNum+1 where CollectionOfBook.ISBN 141 | = NEW.ISBN; 142 | end; 143 | 144 | insert into returnofbook(returntime, readerid, isbn) values ('2020-6-23','1','1'); -------------------------------------------------------------------------------- /code/pyqt/bookshop/user_window.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'user_window.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | 11 | from PyQt5 import QtCore, QtGui, QtWidgets 12 | from PyQt5.QtWidgets import * 13 | 14 | 15 | class User_MainWindow(QtWidgets.QMainWindow): 16 | # def __init__(self): 17 | # super(User_MainWindow, self).__init__() 18 | # self.setupUi(self) 19 | # self.retranslateUi(self) 20 | 21 | def setupUi(self, MainWindow): 22 | MainWindow.setObjectName("MainWindow") 23 | MainWindow.resize(800, 600) 24 | self.centralwidget = QtWidgets.QWidget(MainWindow) 25 | self.centralwidget.setObjectName("centralwidget") 26 | self.label = QtWidgets.QLabel(self.centralwidget) 27 | self.label.setGeometry(QtCore.QRect(400, 190, 141, 61)) 28 | self.label.setObjectName("label") 29 | MainWindow.setCentralWidget(self.centralwidget) 30 | self.menubar = QtWidgets.QMenuBar(MainWindow) 31 | self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26)) 32 | self.menubar.setObjectName("menubar") 33 | MainWindow.setMenuBar(self.menubar) 34 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 35 | self.statusbar.setObjectName("statusbar") 36 | MainWindow.setStatusBar(self.statusbar) 37 | 38 | self.retranslateUi(MainWindow) 39 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 40 | 41 | def retranslateUi(self, MainWindow): 42 | _translate = QtCore.QCoreApplication.translate 43 | MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) 44 | self.label.setText(_translate("MainWindow", "主窗口调用test")) 45 | -------------------------------------------------------------------------------- /code/pyqt/bookshop/user_window_test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'user_window_test.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | from pymysql import * 11 | from PyQt5 import QtCore, QtGui, QtWidgets, QtSql 12 | from PyQt5.QtWidgets import QApplication,QInputDialog, QLineEdit, QMainWindow, QWidget 13 | import sys 14 | from Insertbook import * 15 | from Insertpurchase import * 16 | from Insertsell import * 17 | from Insertdel import * 18 | 19 | 20 | class Ui_userWindow(object): 21 | def __init__(self): 22 | super().__init__() 23 | # self.InsertBook = InsertBook 24 | 25 | 26 | def setupUi(self, MainWindow): 27 | MainWindow.setObjectName("MainWindow") 28 | MainWindow.resize(977, 542) 29 | self.centralwidget = QtWidgets.QWidget(MainWindow) 30 | self.centralwidget.setObjectName("centralwidget") 31 | self.book = QtWidgets.QWidget(self.centralwidget) 32 | self.book.setEnabled(True) 33 | self.book.setGeometry(QtCore.QRect(190, 40, 701, 411)) 34 | self.book.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 35 | self.book.setObjectName("book") 36 | 37 | self.label = QtWidgets.QLabel(self.book) 38 | self.label.setEnabled(False) 39 | self.label.setGeometry(QtCore.QRect(270, 10, 91, 20)) 40 | self.label.setObjectName("label") 41 | self.layoutWidget = QtWidgets.QWidget(self.book) 42 | self.layoutWidget.setGeometry(QtCore.QRect(580, 20, 101, 371)) 43 | self.layoutWidget.setObjectName("layoutWidget") 44 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.layoutWidget) 45 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 46 | self.verticalLayout_2.setObjectName("verticalLayout_2") 47 | self.add_book = QtWidgets.QPushButton(self.layoutWidget) 48 | self.add_book.setObjectName("add_book") 49 | self.verticalLayout_2.addWidget(self.add_book) 50 | self.del_book = QtWidgets.QPushButton(self.layoutWidget) 51 | self.del_book.setObjectName("del_book") 52 | self.verticalLayout_2.addWidget(self.del_book) 53 | self.purchasebook = QtWidgets.QPushButton(self.layoutWidget) 54 | self.purchasebook.setObjectName("purchasebook") 55 | self.verticalLayout_2.addWidget(self.purchasebook) 56 | self.sellbook = QtWidgets.QPushButton(self.layoutWidget) 57 | self.sellbook.setObjectName("sellbook") 58 | self.verticalLayout_2.addWidget(self.sellbook) 59 | self.search_book = QtWidgets.QPushButton(self.layoutWidget) 60 | self.search_book.setObjectName("search_book") 61 | self.verticalLayout_2.addWidget(self.search_book) 62 | self.table_info = QtWidgets.QTableView(self.book) 63 | self.table_info.setGeometry(QtCore.QRect(30, 40, 521, 351)) 64 | self.table_info.setObjectName("table_info") 65 | self.layoutWidget1 = QtWidgets.QWidget(self.centralwidget) 66 | self.layoutWidget1.setGeometry(QtCore.QRect(50, 40, 111, 411)) 67 | self.layoutWidget1.setObjectName("layoutWidget1") 68 | self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget1) 69 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 70 | self.verticalLayout.setObjectName("verticalLayout") 71 | self.see_book_info = QtWidgets.QPushButton(self.layoutWidget1) 72 | self.see_book_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 73 | self.see_book_info.setObjectName("see_book_info") 74 | self.verticalLayout.addWidget(self.see_book_info) 75 | self.see_reader_info = QtWidgets.QPushButton(self.layoutWidget1) 76 | self.see_reader_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 77 | self.see_reader_info.setObjectName("see_reader_info") 78 | self.verticalLayout.addWidget(self.see_reader_info) 79 | self.see_borrow_info = QtWidgets.QPushButton(self.layoutWidget1) 80 | self.see_borrow_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 81 | self.see_borrow_info.setObjectName("see_borrow_info") 82 | self.verticalLayout.addWidget(self.see_borrow_info) 83 | self.exit = QtWidgets.QPushButton(self.layoutWidget1) 84 | self.exit.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 85 | self.exit.setObjectName("exit") 86 | self.verticalLayout.addWidget(self.exit) 87 | MainWindow.setCentralWidget(self.centralwidget) 88 | self.menubar = QtWidgets.QMenuBar(MainWindow) 89 | self.menubar.setGeometry(QtCore.QRect(0, 0, 977, 26)) 90 | self.menubar.setObjectName("menubar") 91 | MainWindow.setMenuBar(self.menubar) 92 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 93 | self.statusbar.setObjectName("statusbar") 94 | MainWindow.setStatusBar(self.statusbar) 95 | 96 | # 登录成功提示 97 | 98 | 99 | self.retranslateUi(MainWindow) 100 | self.exit.clicked.connect(MainWindow.close) 101 | self.see_book_info.clicked.connect(self.book.show) 102 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 103 | 104 | self.see_book_info.clicked.connect(lambda: self.get_book_info()) 105 | 106 | 107 | 108 | """下面这段代码是用来弹出各种功能的pushbutton的界面,并绑定到对应的槽上面""" 109 | childwindow_addbook = child_addbok() 110 | childwindow_insertpurchase = child_purchase_book() 111 | childwindow_insertsell = child_sellbook() 112 | childwindow_insertdel = child_delbook() 113 | 114 | self.add_book.clicked.connect(lambda: childwindow_addbook.show()) 115 | self.purchasebook.clicked.connect(lambda: childwindow_insertpurchase.show()) 116 | self.sellbook.clicked.connect(lambda: childwindow_insertsell.show()) 117 | self.del_book.clicked.connect(lambda: childwindow_insertdel.show()) 118 | 119 | def retranslateUi(self, MainWindow): 120 | _translate = QtCore.QCoreApplication.translate 121 | MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) 122 | self.label.setText(_translate("MainWindow", "书籍信息查看")) 123 | self.add_book.setText(_translate("MainWindow", "添加书籍")) 124 | self.del_book.setText(_translate("MainWindow", "删除书籍")) 125 | self.purchasebook.setText(_translate("MainWindow", "购入书籍")) 126 | self.sellbook.setText(_translate("MainWindow", "卖出书籍")) 127 | self.search_book.setText(_translate("MainWindow", "搜索书籍")) 128 | self.see_book_info.setText(_translate("MainWindow", "查看书籍信息")) 129 | self.see_reader_info.setText(_translate("MainWindow", "查看读者信息")) 130 | self.see_borrow_info.setText(_translate("MainWindow", "查看借阅信息")) 131 | self.exit.setText(_translate("MainWindow", "退出")) 132 | self.statusbar.showMessage("用户登录成功", 2000) 133 | 134 | def get_book_info(self): 135 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 136 | user='root') 137 | print(123) 138 | # 创建游标对象 139 | self.cursor = self.db.cursor() 140 | sql = "use bookshopmanagement" 141 | self.cursor.execute(sql) 142 | self.model = QtSql.QSqlTableModel() 143 | self.table_info.setModel(self.model) 144 | sql = "SELECT * FROM book" 145 | self.cursor.execute(sql) 146 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 147 | data = self.cursor.fetchall() 148 | print(data) 149 | sql = " select ISBN,TotalNum from collectionofbook;" 150 | self.cursor.execute(sql) 151 | booknum_data = self.cursor.fetchall() 152 | print(booknum_data) 153 | print(54) 154 | # 打印测试 155 | row = len(data) 156 | col = len(data[0]) 157 | flag = False 158 | currentLocation = 0 159 | MergedList = [[] for x in range(row)] 160 | for i in range(row): 161 | for j in range(len(booknum_data)): 162 | if booknum_data[j][0] == data[i][0]: 163 | flag = True 164 | currentLocation = j 165 | break 166 | if flag is True: 167 | for x in range(col): 168 | MergedList[i].append(data[i][x]) 169 | MergedList[i].append(booknum_data[currentLocation][1]) 170 | else: 171 | for x in range(col): 172 | MergedList[i].append(data[i][x]) 173 | MergedList[i].append(0) 174 | flag = False 175 | print(MergedList) 176 | 177 | 178 | model = QtGui.QStandardItemModel(row, len(MergedList[0])) 179 | # for i in range(row): 180 | # for j in range(col+1): 181 | # if j is not 3: 182 | # model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 183 | # else: 184 | # model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 185 | # print(data[i][j]) 186 | 187 | for i in range(row): 188 | for j in range(len(MergedList[0])): 189 | if j is not 3 and j is not 4: 190 | model.setItem(i, j, QtGui.QStandardItem(MergedList[i][j])) 191 | else: 192 | model.setItem(i, j, QtGui.QStandardItem(str(MergedList[i][j]))) 193 | 194 | model.setHorizontalHeaderLabels(['ISBN', "书名", "作者", "定价", "存货"]) 195 | self.table_info.setModel(model) 196 | self.statusbar.showMessage("查询成功!总共查询到"+str(row)+"条数据", 2000) 197 | 198 | 199 | 200 | class parentWindow(QMainWindow): 201 | def __init__(self): 202 | QMainWindow.__init__(self) 203 | self.UI = Ui_userWindow() 204 | self.UI.setupUi(self) 205 | 206 | 207 | class child_addbok(QWidget): 208 | def __init__(self): 209 | QWidget.__init__(self) 210 | self.UI = Ui_InputBookinfo() 211 | self.UI.setupUi(self) 212 | 213 | class child_purchase_book(QWidget): 214 | def __init__(self): 215 | QWidget.__init__(self) 216 | self.UI = Ui_insertpurchase() 217 | self.UI.setupUi(self) 218 | 219 | 220 | class child_sellbook(QWidget): 221 | def __init__(self): 222 | QWidget.__init__(self) 223 | self.UI = Ui_Insertsell() 224 | self.UI.setupUi(self) 225 | 226 | class child_delbook(QWidget): 227 | def __init__(self): 228 | QWidget.__init__(self) 229 | self.UI = Ui_delbook() 230 | self.UI.setupUi(self) 231 | 232 | 233 | if __name__ == '__main__': 234 | app = QApplication(sys.argv) 235 | window = parentWindow() 236 | childwindow = child_addbok() 237 | window.UI.add_book.clicked.connect(lambda: childwindow.show()) 238 | 239 | window.show() 240 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/user_window_test_1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'user_window_test_1.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.15.0 6 | # 7 | # WARNING: Any manual changes made to this file will be lost when pyuic5 is 8 | # run again. Do not edit this file unless you know what you are doing. 9 | 10 | 11 | from PyQt5 import QtCore, QtGui, QtWidgets 12 | 13 | 14 | from pymysql import * 15 | from PyQt5 import QtCore, QtGui, QtWidgets, QtSql 16 | from PyQt5.QtWidgets import QApplication,QInputDialog, QLineEdit, QMainWindow, QWidget 17 | import sys 18 | from Insertbook import * 19 | from Insertpurchase import * 20 | from Insertsell import * 21 | from Insertdel import * 22 | from searchbook import * 23 | from insert_addreader import * 24 | 25 | 26 | class Ui_user_window_test_1(object): 27 | def setupUi(self, MainWindow): 28 | MainWindow.setObjectName("MainWindow") 29 | MainWindow.resize(1000, 600) 30 | self.centralwidget = QtWidgets.QWidget(MainWindow) 31 | self.centralwidget.setObjectName("centralwidget") 32 | self.layoutWidget = QtWidgets.QWidget(self.centralwidget) 33 | self.layoutWidget.setGeometry(QtCore.QRect(50, 40, 111, 411)) 34 | self.layoutWidget.setObjectName("layoutWidget") 35 | self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget) 36 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 37 | self.verticalLayout.setObjectName("verticalLayout") 38 | self.see_book_info = QtWidgets.QPushButton(self.layoutWidget) 39 | self.see_book_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 40 | self.see_book_info.setObjectName("see_book_info") 41 | self.verticalLayout.addWidget(self.see_book_info) 42 | self.see_reader_info = QtWidgets.QPushButton(self.layoutWidget) 43 | self.see_reader_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 44 | self.see_reader_info.setObjectName("see_reader_info") 45 | self.verticalLayout.addWidget(self.see_reader_info) 46 | self.see_borrow_info = QtWidgets.QPushButton(self.layoutWidget) 47 | self.see_borrow_info.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 48 | self.see_borrow_info.setObjectName("see_borrow_info") 49 | self.verticalLayout.addWidget(self.see_borrow_info) 50 | self.exit = QtWidgets.QPushButton(self.layoutWidget) 51 | self.exit.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 52 | self.exit.setObjectName("exit") 53 | self.verticalLayout.addWidget(self.exit) 54 | self.borrow = QtWidgets.QFrame(self.centralwidget) 55 | self.borrow.setGeometry(QtCore.QRect(210, 50, 701, 411)) 56 | self.borrow.setFrameShape(QtWidgets.QFrame.StyledPanel) 57 | self.borrow.setFrameShadow(QtWidgets.QFrame.Raised) 58 | self.borrow.setObjectName("borrow") 59 | self.pushButton_3 = QtWidgets.QPushButton(self.borrow) 60 | self.pushButton_3.setGeometry(QtCore.QRect(570, 60, 93, 28)) 61 | self.pushButton_3.setObjectName("pushButton_3") 62 | self.pushButton_6 = QtWidgets.QPushButton(self.borrow) 63 | self.pushButton_6.setGeometry(QtCore.QRect(570, 130, 93, 28)) 64 | self.pushButton_6.setObjectName("pushButton_6") 65 | self.pushButton_7 = QtWidgets.QPushButton(self.borrow) 66 | self.pushButton_7.setGeometry(QtCore.QRect(570, 210, 91, 31)) 67 | self.pushButton_7.setObjectName("pushButton_7") 68 | self.borrow_info = QtWidgets.QTableView(self.borrow) 69 | self.borrow_info.setGeometry(QtCore.QRect(50, 40, 481, 341)) 70 | self.borrow_info.setObjectName("borrow_info") 71 | self.book = QtWidgets.QWidget(self.centralwidget) 72 | self.book.setEnabled(True) 73 | self.book.setGeometry(QtCore.QRect(211, 45, 700, 411)) 74 | self.book.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) 75 | self.book.setObjectName("book") 76 | self.label = QtWidgets.QLabel(self.book) 77 | self.label.setEnabled(False) 78 | self.label.setGeometry(QtCore.QRect(270, 10, 91, 20)) 79 | self.label.setObjectName("label") 80 | self.layoutWidget1 = QtWidgets.QWidget(self.book) 81 | self.layoutWidget1.setGeometry(QtCore.QRect(580, 20, 101, 371)) 82 | self.layoutWidget1.setObjectName("layoutWidget1") 83 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.layoutWidget1) 84 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 85 | self.verticalLayout_2.setObjectName("verticalLayout_2") 86 | self.pushButton = QtWidgets.QPushButton(self.layoutWidget1) 87 | self.pushButton.setObjectName("pushButton") 88 | self.verticalLayout_2.addWidget(self.pushButton) 89 | self.del_book = QtWidgets.QPushButton(self.layoutWidget1) 90 | self.del_book.setObjectName("del_book") 91 | self.verticalLayout_2.addWidget(self.del_book) 92 | self.purchasebook = QtWidgets.QPushButton(self.layoutWidget1) 93 | self.purchasebook.setObjectName("purchasebook") 94 | self.verticalLayout_2.addWidget(self.purchasebook) 95 | self.sellbook = QtWidgets.QPushButton(self.layoutWidget1) 96 | self.sellbook.setEnabled(True) 97 | self.sellbook.setObjectName("sellbook") 98 | self.verticalLayout_2.addWidget(self.sellbook) 99 | self.search_book = QtWidgets.QPushButton(self.layoutWidget1) 100 | self.search_book.setObjectName("search_book") 101 | self.verticalLayout_2.addWidget(self.search_book) 102 | self.book_info = QtWidgets.QTableView(self.book) 103 | self.book_info.setGeometry(QtCore.QRect(30, 40, 531, 351)) 104 | self.book_info.setObjectName("book_info") 105 | self.reader = QtWidgets.QFrame(self.centralwidget) 106 | self.reader.setGeometry(QtCore.QRect(206, 45, 761, 411)) 107 | self.reader.setFrameShape(QtWidgets.QFrame.StyledPanel) 108 | self.reader.setFrameShadow(QtWidgets.QFrame.Raised) 109 | self.reader.setObjectName("reader") 110 | self.pushButton_2 = QtWidgets.QPushButton(self.reader) 111 | self.pushButton_2.setGeometry(QtCore.QRect(610, 50, 93, 28)) 112 | self.pushButton_2.setObjectName("pushButton_2") 113 | self.pushButton_4 = QtWidgets.QPushButton(self.reader) 114 | self.pushButton_4.setGeometry(QtCore.QRect(610, 140, 93, 28)) 115 | self.pushButton_4.setObjectName("pushButton_4") 116 | self.pushButton_5 = QtWidgets.QPushButton(self.reader) 117 | self.pushButton_5.setGeometry(QtCore.QRect(610, 240, 93, 28)) 118 | self.pushButton_5.setObjectName("pushButton_5") 119 | self.readerInfo = QtWidgets.QTableView(self.reader) 120 | self.readerInfo.setGeometry(QtCore.QRect(20, 50, 541, 311)) 121 | self.readerInfo.setObjectName("readerInfo") 122 | self.label_2 = QtWidgets.QLabel(self.reader) 123 | self.label_2.setGeometry(QtCore.QRect(260, 20, 71, 16)) 124 | self.label_2.setObjectName("label_2") 125 | MainWindow.setCentralWidget(self.centralwidget) 126 | self.menubar = QtWidgets.QMenuBar(MainWindow) 127 | self.menubar.setGeometry(QtCore.QRect(0, 0, 1315, 26)) 128 | self.menubar.setObjectName("menubar") 129 | MainWindow.setMenuBar(self.menubar) 130 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 131 | self.statusbar.setObjectName("statusbar") 132 | MainWindow.setStatusBar(self.statusbar) 133 | self.reader.setVisible(False) 134 | self.borrow.setVisible(False) 135 | self.retranslateUi(MainWindow) 136 | self.exit.clicked.connect(MainWindow.close) 137 | self.see_book_info.clicked.connect(self.book.show) 138 | self.see_book_info.clicked.connect(self.reader.hide) 139 | self.see_book_info.clicked.connect(self.borrow.hide) 140 | self.see_reader_info.clicked.connect(self.reader.show) 141 | self.see_reader_info.clicked.connect(self.borrow.hide) 142 | self.see_borrow_info.clicked.connect(self.borrow.show) 143 | self.see_borrow_info.clicked.connect(self.reader.hide) 144 | self.see_borrow_info.clicked.connect(self.book.hide) 145 | self.see_reader_info.clicked.connect(self.book.hide) 146 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 147 | 148 | 149 | self.see_book_info.clicked.connect(lambda: self.get_book_info()) 150 | self.see_reader_info.clicked.connect(lambda: self.get_reader_info()) 151 | 152 | 153 | """下面这段代码是用来弹出各种功能的pushbutton的界面,并绑定到对应的槽上面""" 154 | childwindow_addbook = child_addbok() 155 | childwindow_insertpurchase = child_purchase_book() 156 | childwindow_insertsell = child_sellbook() 157 | childwindow_insertdel = child_delbook() 158 | childwindow_searchbook = child_searchbook() 159 | childwindow_addreader = child_addreader() 160 | self.pushButton.clicked.connect(lambda: childwindow_addbook.show()) 161 | self.purchasebook.clicked.connect(lambda: childwindow_insertpurchase.show()) 162 | self.sellbook.clicked.connect(lambda: childwindow_insertsell.show()) 163 | self.del_book.clicked.connect(lambda: childwindow_insertdel.show()) 164 | self.search_book.clicked.connect(lambda: childwindow_searchbook.show()) 165 | self.pushButton_2.clicked.connect(lambda: childwindow_addreader.show()) 166 | 167 | 168 | def retranslateUi(self, MainWindow): 169 | _translate = QtCore.QCoreApplication.translate 170 | MainWindow.setWindowTitle(_translate("MainWindow", "书店管理系统")) 171 | self.see_book_info.setText(_translate("MainWindow", "查看书籍信息")) 172 | self.see_reader_info.setText(_translate("MainWindow", "查看读者信息")) 173 | self.see_borrow_info.setText(_translate("MainWindow", "查看借阅信息")) 174 | self.exit.setText(_translate("MainWindow", "退出")) 175 | self.pushButton_3.setText(_translate("MainWindow", "借书")) 176 | self.pushButton_6.setText(_translate("MainWindow", "还书")) 177 | self.pushButton_7.setText(_translate("MainWindow", "搜索借阅")) 178 | self.label.setText(_translate("MainWindow", "书籍信息查看")) 179 | self.pushButton.setText(_translate("MainWindow", "添加书籍信息")) 180 | self.del_book.setText(_translate("MainWindow", "删除书籍")) 181 | self.purchasebook.setText(_translate("MainWindow", "购入书籍")) 182 | self.sellbook.setText(_translate("MainWindow", "卖出书籍")) 183 | self.search_book.setText(_translate("MainWindow", "搜索书籍")) 184 | self.pushButton_2.setText(_translate("MainWindow", "添加读者")) 185 | self.pushButton_4.setText(_translate("MainWindow", "删除读者")) 186 | self.pushButton_5.setText(_translate("MainWindow", "搜索读者")) 187 | self.label_2.setText(_translate("MainWindow", "读者信息")) 188 | 189 | 190 | def get_book_info(self): 191 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 192 | user='root') 193 | # 创建游标对象 194 | self.cursor = self.db.cursor() 195 | sql = "use bookshopmanagement" 196 | self.cursor.execute(sql) 197 | self.model = QtSql.QSqlTableModel() 198 | self.book_info.setModel(self.model) 199 | sql = "SELECT * FROM book" 200 | self.cursor.execute(sql) 201 | # 获取查询到的数据, 是以二维元组的形式存储的, 所以读取需要使用 data[i][j] 下标定位 202 | data = self.cursor.fetchall() 203 | print(data) 204 | sql = " select ISBN,TotalNum from collectionofbook;" 205 | self.cursor.execute(sql) 206 | booknum_data = self.cursor.fetchall() 207 | print(booknum_data) 208 | print(54) 209 | # 打印测试 210 | row = len(data) 211 | col = len(data[0]) 212 | flag = False 213 | currentLocation = 0 214 | MergedList = [[] for x in range(row)] 215 | for i in range(row): 216 | for j in range(len(booknum_data)): 217 | if booknum_data[j][0] == data[i][0]: 218 | flag = True 219 | currentLocation = j 220 | break 221 | if flag is True: 222 | for x in range(col): 223 | MergedList[i].append(data[i][x]) 224 | MergedList[i].append(booknum_data[currentLocation][1]) 225 | else: 226 | for x in range(col): 227 | MergedList[i].append(data[i][x]) 228 | MergedList[i].append(0) 229 | flag = False 230 | print(MergedList) 231 | 232 | model = QtGui.QStandardItemModel(row, len(MergedList[0])) 233 | 234 | for i in range(row): 235 | for j in range(len(MergedList[0])): 236 | if j is not 3 and j is not 4: 237 | model.setItem(i, j, QtGui.QStandardItem(MergedList[i][j])) 238 | else: 239 | model.setItem(i, j, QtGui.QStandardItem(str(MergedList[i][j]))) 240 | 241 | model.setHorizontalHeaderLabels(['ISBN', "书名", "作者", "定价", "存货"]) 242 | self.book_info.setModel(model) 243 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条数据", 2000) 244 | 245 | 246 | def get_reader_info(self): 247 | self.db = connect(host='localhost', port=3306, charset='utf8', database='MySQL', password='zyh20000205', 248 | user='root') 249 | # 创建游标对象 250 | self.cursor = self.db.cursor() 251 | self.model_1 = QtSql.QSqlTableModel() 252 | self.readerInfo.setModel(self.model_1) 253 | sql = "use bookshopmanagement" 254 | self.cursor.execute(sql) 255 | sql = "select * from reader" 256 | self.cursor.execute(sql) 257 | data = self.cursor.fetchall() 258 | row = len(data) 259 | col = len(data[0]) 260 | print(data) 261 | model = QtGui.QStandardItemModel(row, col) 262 | for i in range(row): 263 | for j in range(col): 264 | if j is not 0 and j is not 3: 265 | model.setItem(i, j, QtGui.QStandardItem(data[i][j])) 266 | else: 267 | model.setItem(i, j, QtGui.QStandardItem(str(data[i][j]))) 268 | model.setHorizontalHeaderLabels(['借阅证ID', "姓名", "性别", "年龄", "电话"]) 269 | self.readerInfo.setModel(model) 270 | self.statusbar.showMessage("查询成功!总共查询到" + str(row) + "条借阅人信息", 2000) 271 | 272 | 273 | class parentWindow(QMainWindow): 274 | def __init__(self): 275 | QMainWindow.__init__(self) 276 | self.UI = Ui_user_window_test_1() 277 | self.UI.setupUi(self) 278 | 279 | 280 | class child_addbok(QMainWindow): 281 | def __init__(self): 282 | QMainWindow.__init__(self) 283 | self.UI = Ui_InputBookinfo() 284 | self.UI.setupUi(self) 285 | 286 | class child_purchase_book(QWidget): 287 | def __init__(self): 288 | QWidget.__init__(self) 289 | self.UI = Ui_insertpurchase() 290 | self.UI.setupUi(self) 291 | 292 | 293 | class child_sellbook(QWidget): 294 | def __init__(self): 295 | QWidget.__init__(self) 296 | self.UI = Ui_Insertsell() 297 | self.UI.setupUi(self) 298 | 299 | class child_delbook(QWidget): 300 | def __init__(self): 301 | QWidget.__init__(self) 302 | self.UI = Ui_delbook() 303 | self.UI.setupUi(self) 304 | 305 | class child_searchbook(QMainWindow): 306 | def __init__(self): 307 | QMainWindow.__init__(self) 308 | self.UI = Ui_searchbook() 309 | self.UI.setupUi(self) 310 | 311 | class child_addreader(QMainWindow): 312 | def __init__(self): 313 | QMainWindow.__init__(self) 314 | self.UI = Ui_addreader() 315 | self.UI.setupUi(self) 316 | 317 | 318 | if __name__ == '__main__': 319 | app = QApplication(sys.argv) 320 | window = parentWindow() 321 | childwindow = child_addbok() 322 | 323 | 324 | window.show() 325 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /code/pyqt/bookshop/user_window_test_2.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1315 10 | 859 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 50 21 | 40 22 | 111 23 | 411 24 | 25 | 26 | 27 | 28 | 29 | 30 | PointingHandCursor 31 | 32 | 33 | 查看书籍信息 34 | 35 | 36 | 37 | 38 | 39 | 40 | PointingHandCursor 41 | 42 | 43 | 查看读者信息 44 | 45 | 46 | 47 | 48 | 49 | 50 | PointingHandCursor 51 | 52 | 53 | 查看借阅信息 54 | 55 | 56 | 57 | 58 | 59 | 60 | PointingHandCursor 61 | 62 | 63 | 退出 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 210 73 | 40 74 | 701 75 | 411 76 | 77 | 78 | 79 | QFrame::StyledPanel 80 | 81 | 82 | QFrame::Raised 83 | 84 | 85 | 86 | 87 | 570 88 | 60 89 | 93 90 | 28 91 | 92 | 93 | 94 | 借书 95 | 96 | 97 | 98 | 99 | 100 | 570 101 | 130 102 | 93 103 | 28 104 | 105 | 106 | 107 | 还书 108 | 109 | 110 | 111 | 112 | 113 | 570 114 | 210 115 | 91 116 | 31 117 | 118 | 119 | 120 | 搜索借书 121 | 122 | 123 | 124 | 125 | 126 | 50 127 | 40 128 | 481 129 | 311 130 | 131 | 132 | 133 | 134 | 135 | 136 | 570 137 | 280 138 | 93 139 | 28 140 | 141 | 142 | 143 | 搜索还书 144 | 145 | 146 | 147 | 148 | 149 | 250 150 | 10 151 | 72 152 | 15 153 | 154 | 155 | 156 | 借阅信息 157 | 158 | 159 | 160 | 161 | 162 | 180 163 | 370 164 | 115 165 | 19 166 | 167 | 168 | 169 | 查看借书 170 | 171 | 172 | 173 | 174 | 175 | 330 176 | 370 177 | 115 178 | 19 179 | 180 | 181 | 182 | 查看还书 183 | 184 | 185 | 186 | 187 | 188 | true 189 | 190 | 191 | 192 | 198 193 | 40 194 | 700 195 | 411 196 | 197 | 198 | 199 | PointingHandCursor 200 | 201 | 202 | 203 | false 204 | 205 | 206 | 207 | 270 208 | 10 209 | 91 210 | 20 211 | 212 | 213 | 214 | 书籍信息查看 215 | 216 | 217 | 218 | 219 | 220 | 580 221 | 20 222 | 101 223 | 371 224 | 225 | 226 | 227 | 228 | 229 | 230 | 添加书籍信息 231 | 232 | 233 | 234 | 235 | 236 | 237 | 删除书籍 238 | 239 | 240 | 241 | 242 | 243 | 244 | 购入书籍 245 | 246 | 247 | 248 | 249 | 250 | 251 | true 252 | 253 | 254 | 卖出书籍 255 | 256 | 257 | 258 | 259 | 260 | 261 | 搜索书籍 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 30 271 | 40 272 | 531 273 | 351 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 190 282 | 40 283 | 761 284 | 411 285 | 286 | 287 | 288 | QFrame::StyledPanel 289 | 290 | 291 | QFrame::Raised 292 | 293 | 294 | 295 | 296 | 610 297 | 50 298 | 93 299 | 28 300 | 301 | 302 | 303 | 添加读者 304 | 305 | 306 | 307 | 308 | 309 | 610 310 | 140 311 | 93 312 | 28 313 | 314 | 315 | 316 | 删除读者 317 | 318 | 319 | 320 | 321 | 322 | 610 323 | 240 324 | 93 325 | 28 326 | 327 | 328 | 329 | 搜索读者 330 | 331 | 332 | 333 | 334 | 335 | 20 336 | 50 337 | 541 338 | 311 339 | 340 | 341 | 342 | 343 | 344 | 345 | 260 346 | 20 347 | 71 348 | 16 349 | 350 | 351 | 352 | 读者信息 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 0 361 | 0 362 | 1315 363 | 26 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | exit 373 | clicked() 374 | MainWindow 375 | close() 376 | 377 | 378 | 121 379 | 410 380 | 381 | 382 | 155 383 | 376 384 | 385 | 386 | 387 | 388 | see_book_info 389 | clicked() 390 | book 391 | show() 392 | 393 | 394 | 134 395 | 139 396 | 397 | 398 | 18 399 | 690 400 | 401 | 402 | 403 | 404 | see_book_info 405 | clicked() 406 | reader 407 | hide() 408 | 409 | 410 | 79 411 | 130 412 | 413 | 414 | 524 415 | 936 416 | 417 | 418 | 419 | 420 | see_book_info 421 | clicked() 422 | borrow 423 | hide() 424 | 425 | 426 | 67 427 | 139 428 | 429 | 430 | 505 431 | 486 432 | 433 | 434 | 435 | 436 | see_reader_info 437 | clicked() 438 | reader 439 | show() 440 | 441 | 442 | 118 443 | 225 444 | 445 | 446 | 490 447 | 936 448 | 449 | 450 | 451 | 452 | see_reader_info 453 | clicked() 454 | borrow 455 | hide() 456 | 457 | 458 | 80 459 | 232 460 | 461 | 462 | 524 463 | 486 464 | 465 | 466 | 467 | 468 | see_borrow_info 469 | clicked() 470 | borrow 471 | show() 472 | 473 | 474 | 138 475 | 314 476 | 477 | 478 | 566 479 | 486 480 | 481 | 482 | 483 | 484 | see_borrow_info 485 | clicked() 486 | reader 487 | hide() 488 | 489 | 490 | 90 491 | 315 492 | 493 | 494 | 584 495 | 936 496 | 497 | 498 | 499 | 500 | see_borrow_info 501 | clicked() 502 | book 503 | hide() 504 | 505 | 506 | 87 507 | 318 508 | 509 | 510 | -30 511 | 787 512 | 513 | 514 | 515 | 516 | see_reader_info 517 | clicked() 518 | book 519 | hide() 520 | 521 | 522 | 64 523 | 228 524 | 525 | 526 | -30 527 | 835 528 | 529 | 530 | 531 | 532 | 533 | -------------------------------------------------------------------------------- /书店管理系统开发文档.md: -------------------------------------------------------------------------------- 1 | # 书店管理系统开发文档 2 | 3 | ## 2020-7-4 4 | 5 | 1.完成基础代码框架(未完成**GUI**编程) 6 | 7 | 2.完成GUI框架结构梳理 8 | 9 | 3.完成MySQL数据库相关表的搭建及数据定义 10 | 11 | 4.完成相关系统基础测试 12 | 13 | ## 2020-7-5 14 | 15 | 1.完成登录界面的GUI设置 16 | 17 | 2.完成登录界面管理员和普通用户的设置和切换 18 | 19 | 3.添加输入密码的回显模式 20 | 21 | ## 2020-7-6 22 | 23 | 1.完成登录界面和主界面的切换以及显示 24 | 25 | 2.完成一般用户界面的设计 26 | 27 | 3.完成部分MySQL数据库可视化操作对象 28 | 29 | ## 2020-7-7、2020-7-8 30 | 31 | 1.参加互联网+省赛选拔比赛,开发搁置 32 | 33 | ## 2020-7-9 34 | 35 | 1.完成添加书籍信息和购入书籍的窗口弹出设置 36 | 37 | 2.完成通过弹出窗口输入信息对MySQL数据库的操作 38 | 39 | 3.完成登录界面跳转至相应级别用户界面并能弹出相应的pushbutton操作界面 40 | 41 | ## 2020-7-10 42 | 43 | 回家以及摸鱼 44 | 45 | ## 2020-7-11 46 | 47 | 1.完成collectionofbook和book表的联合显示(PS:一个是自己想偷懒,一个是一开始表没设计好) 48 | 49 | 2.将code上传到了GitHub 50 | 51 | ## 2020-7-12 52 | 53 | 1.完成了查看书籍信息选项的所有操作,包括:搜索书籍、添加书籍、删除书籍、购书、卖书 54 | 55 | 2.完成了在同一个页面跳转其他选项的操作 56 | 57 | ## 2020-7-13 58 | 59 | 1.完成了查看读者信息以及增删读者的窗口操作 60 | 61 | 2.对相关表的定义做出了修改(增加级联删除)、以防出现由于外键约束而无法删除的情况 62 | 63 | ## 2020-7-14~15 64 | 65 | 做学校暑期实践 66 | 67 | ## 2020-7-16 68 | 69 | 1.完成借阅和还书的窗口操作 70 | 71 | ## 2020-7-17 72 | 73 | 暑期项目实践答辩 74 | 75 | ## 2020-7-18 76 | 77 | 1.完成借阅和还书的查询,所有一般用户的操作完成!✿✿ヽ(°▽°)ノ✿ 78 | 79 | 2.设计出管理员的系统 80 | 81 | 3.尽量今天全部结束 82 | 83 | ~~自己摸鱼的本事也是一流,就这么个小项目,拖了将近十几天~~ 84 | 85 | ## 2020-7-19 86 | 87 | 1.完成了了管理员所有功能,项目基本框架已经搭建完了,终于告了一段落,后续会进行一些小的修补工作 --------------------------------------------------------------------------------