添加逻辑
有任何一项没有填写 , 需要重新填
书籍之前已经存在 , 调用更新函数
书籍是新添加的 , 调用添加函数
【6PyQT5一起学做图书管理系统添加/删除书籍】def addBookButtonCicked(self):bookName = self.bookNameEdit.text()bookId = self.bookIdEdit.text()authName = self.authNameEdit.text()bookCategory = self.categoryComboBox.currentText()publisher = self.publisherEdit.text()publishTime = self.publishTime.text()addBookNum = self.addNumEdit.text()if (bookName == "" or bookId == "" or authName == "" or bookCategory == "" or publisher == "" or publishTime == "" or addBookNum == ""):print(QMessageBox.warning(self, "警告", "有字段为空 , 添加失败", QMessageBox.Yes, QMessageBox.Yes))returnelse:addBookNum = int(addBookNum)bookinfo=self.bookdb.querybyBookID(bookId)if (bookinfo):self.bookdb.updateBookinfo(addBookNum,bookId,addFlag=1)else:self.bookdb.addBOOK(bookName, bookId, authName, bookCategory, publisher, publishTime, addBookNum, addBookNum,0)# 插入droporinsert表timenow = time.strftime('%Y-%m-%d', time.localtime(time.time()))self.addordropdb.addinfo(bookId, timenow, addBookNum)print(QMessageBox.information(self, "提示", "添加书籍成功!", QMessageBox.Yes, QMessageBox.Yes))self.add_book_success_signal.emit()self.close()self.clearEdit()returndef clearEdit(self):self.bookNameEdit.clear()self.bookIdEdit.clear()self.authNameEdit.clear()self.addNumEdit.clear()self.publisherEdit.clear()
删除功能
删除书籍的界面和添加界面类似 , 但是在界面上稍微有一点区别 , 删除书籍时 , 需要根据来删除 , 因此z在界面上 , 除了之外 , 其他的输入框都是属性 。
删除逻辑是 , 如果当前书籍全部在书库中 , 没有被外借 , 则之前全部删除 , 如果还有外借的书籍 , 则提示删除上限(即只能删除库中现存书籍数量)
效果图
全部代码
.py
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Date: 2018-12-05 21:32:31# @Author: Jimy_Fengqi (jmps515@163.com)# @Link: https://blog.csdn.net/qiqiyingse/import sysfrom PyQt5.QtWidgets import *from PyQt5.QtGui import *from PyQt5.QtCore import *import qdarkstyleimport time#from PyQt5.QtSql import *from db.userInfoManager import BookDbManagerfrom db.userInfoManager import AddOrDropManagerimport imagesclass addBookDialog(QDialog):add_book_success_signal = pyqtSignal()def __init__(self, parent=None):super(addBookDialog, self).__init__(parent)self.setUpUI()self.setWindowModality(Qt.WindowModal)self.bookdb=BookDbManager()self.addordropdb=AddOrDropManager()self.setWindowTitle("添加书籍")def setUpUI(self):# 书名 , 书号 , 作者 , 分类 , 添加数量.出版社,出版日期# 书籍分类:哲学类、社会科学类、政治类、法律类、军事类、经济类、文化类、教育类、体育类、语言文字类、艺术类、历史类、地理类、天文学类、生物学类、医学卫生类、农业类BookCategory = ["哲学", "社会科学", "政治", "法律", "军事", "经济", "文化", "教育", "体育", "语言文字", "艺术", "历史", "地理", "天文学", "生物学", "医学卫生", "农业"]self.resize(300, 400)self.layout = QFormLayout()self.setLayout(self.layout)# Label控件self.titlelabel = QLabel("添加书籍")self.bookNameLabel = QLabel("书名:")self.bookIdLabel = QLabel("书号:")self.authNameLabel = QLabel("作者:")self.categoryLabel = QLabel("分类:")self.publisherLabel = QLabel("出 版 社:")self.publishDateLabel = QLabel("出版日期:")self.addNumLabel = QLabel("添加数量:")# button控件self.addBookButton = QPushButton("添 加")# lineEdit控件self.bookNameEdit = QLineEdit()self.bookIdEdit = QLineEdit()self.authNameEdit = QLineEdit()self.categoryComboBox = QComboBox()self.categoryComboBox.addItems(BookCategory)self.publisherEdit = QLineEdit()self.publishTime = QDateTimeEdit()self.publishTime.setDisplayFormat("yyyy-MM-dd")# self.publishDateEdit = QLineEdit()self.addNumEdit = QLineEdit()self.bookNameEdit.setMaxLength(10)self.bookIdEdit.setMaxLength(6)self.authNameEdit.setMaxLength(10)self.publisherEdit.setMaxLength(10)self.addNumEdit.setMaxLength(12)self.addNumEdit.setValidator(QIntValidator())# 添加进formlayoutself.layout.addRow("", self.titlelabel)self.layout.addRow(self.bookNameLabel, self.bookNameEdit)self.layout.addRow(self.bookIdLabel, self.bookIdEdit)self.layout.addRow(self.authNameLabel, self.authNameEdit)self.layout.addRow(self.categoryLabel, self.categoryComboBox)self.layout.addRow(self.publisherLabel, self.publisherEdit)self.layout.addRow(self.publishDateLabel, self.publishTime)self.layout.addRow(self.addNumLabel, self.addNumEdit)self.layout.addRow("", self.addBookButton)# 设置字体font = QFont()font.setPixelSize(20)self.titlelabel.setFont(font)font.setPixelSize(14)self.bookNameLabel.setFont(font)self.bookIdLabel.setFont(font)self.authNameLabel.setFont(font)self.categoryLabel.setFont(font)self.publisherLabel.setFont(font)self.publishDateLabel.setFont(font)self.addNumLabel.setFont(font)self.bookNameEdit.setFont(font)self.bookIdEdit.setFont(font)self.authNameEdit.setFont(font)self.publisherEdit.setFont(font)self.publishTime.setFont(font)self.categoryComboBox.setFont(font)self.addNumEdit.setFont(font)# button设置font.setPixelSize(16)self.addBookButton.setFont(font)self.addBookButton.setFixedHeight(32)self.addBookButton.setFixedWidth(140)# 设置间距self.titlelabel.setMargin(8)self.layout.setVerticalSpacing(10)self.addBookButton.clicked.connect(self.addBookButtonCicked)def addBookButtonCicked(self):bookName = self.bookNameEdit.text()bookId = self.bookIdEdit.text()authName = self.authNameEdit.text()bookCategory = self.categoryComboBox.currentText()publisher = self.publisherEdit.text()publishTime = self.publishTime.text()addBookNum = self.addNumEdit.text()if (bookName == "" or bookId == "" or authName == "" or bookCategory == "" or publisher == "" or publishTime == "" or addBookNum == ""):print(QMessageBox.warning(self, "警告", "有字段为空 , 添加失败", QMessageBox.Yes, QMessageBox.Yes))returnelse:addBookNum = int(addBookNum)bookinfo=self.bookdb.querybyBookID(bookId)if (bookinfo):self.bookdb.updateBookinfo(addBookNum,bookId,addFlag=1)else:self.bookdb.addBOOK(bookName, bookId, authName, bookCategory, publisher, publishTime, addBookNum, addBookNum,0)# 插入droporinsert表timenow = time.strftime('%Y-%m-%d', time.localtime(time.time()))self.addordropdb.addinfo(bookId, timenow, addBookNum)print(QMessageBox.information(self, "提示", "添加书籍成功!", QMessageBox.Yes, QMessageBox.Yes))self.add_book_success_signal.emit()self.close()self.clearEdit()returndef clearEdit(self):self.bookNameEdit.clear()self.bookIdEdit.clear()self.authNameEdit.clear()self.addNumEdit.clear()self.publisherEdit.clear()if __name__ == "__main__":app = QApplication(sys.argv)app.setWindowIcon(QIcon(":/images/MainWindow_1.png"))app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())mainMindow = addBookDialog()mainMindow.show()sys.exit(app.exec_())
- 不在一起怎么共享流量,两个手机怎么共享流量
- 贾午与韩寿是怎么冲破门第之见在一起的
- 古代皇帝家宴成年皇子是不会与妃子一起吃饭的
- 夏侯杰的女儿夏侯轻衣最后和谁在一起了
- 一起来了解一下古希腊时期王国公主克丽奥佩脱拉的生平事迹
- 徐志摩与林徽因:徐志摩为何没与林徽因在一起
- 三塔,三塔菌可以和土豆一起煮吗
- 一起学,英语和韩语可以一起学吗?
- 一起来捉妖必练,一起来捉妖怎么交易?
- 一起牛体重秤,带有牛的成语