C:\Users\MACHENIKE\PycharmProjects\untitled11\venv\Scripts\python.exe C:/Users/MACHENIKE/PycharmProjects/untitled11/venv/Online-Bookstore-Management-System-master/v1.0/Add_bookUI.py
Traceback (most recent call last):
File "C:/Users/MACHENIKE/PycharmProjects/untitled11/venv/Online-Bookstore-Management-System-master/v1.0/Add_bookUI.py", line 2, in <module>
import pymssql
ModuleNotFoundError: No module named 'pymssql'
Process finished with exit code 1
import sys
import pymssql
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import *
server = 'localhost'
user = 'SA'
password = ''
database = 'Course_Design'
class Add_bookUI(QWidget):
switch_window = pyqtSignal()
def __init__(self):
super(Add_bookUI, self).__init__()
self.initUI()
def initUI(self):
# 從資料庫中獲取資料
self.connect = pymssql.connect(server, user, password, database) # 服務器名,賬戶,密碼,資料庫名
self.cursor = self.connect.cursor()
# 標簽
self.book_name_label = QLabel("圖書名稱:")
self.author_name_label = QLabel("作者:")
self.pub_house_label = QLabel("出版社:")
self.book_kind_label = QLabel("圖書種類:")
self.price_label = QLabel("銷售價格:")
self.num_label = QLabel("購入數目:")
# 輸入框
self.book_name_e = QLineEdit()
self.author_name_e = QLineEdit()
self.pub_house_e = QLineEdit()
self.book_kind_e = QLineEdit()
self.price_e = QLineEdit()
self.num_e = QLineEdit()
self.book_name_e.editingFinished.connect(self.kind_is_ok)
self.book_name_e.editingFinished.connect(self.price_is_ok)
self.pub_house_e.editingFinished.connect(self.kind_is_ok)
self.pub_house_e.editingFinished.connect(self.price_is_ok)
self.author_name_e.editingFinished.connect(self.kind_is_ok)
self.author_name_e.editingFinished.connect(self.kind_is_ok)
# 按鈕
self.ok_btn = QPushButton("確認")
self.cancel_btn = QPushButton("取消")
self.ok_btn.clicked.connect(self.order_is_ok)
self.cancel_btn.clicked.connect(self.cancel_order)
# 布局
self.setWindowTitle("購入圖書")
self.resize(300, 400)
self.center()
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(self.book_name_label, 0, 0)
grid.addWidget(self.book_name_e, 0, 1)
grid.addWidget(self.author_name_label, 1, 0)
grid.addWidget(self.author_name_e, 1, 1)
grid.addWidget(self.pub_house_label, 2, 0)
grid.addWidget(self.pub_house_e, 2, 1)
grid.addWidget(self.book_kind_label, 3, 0)
grid.addWidget(self.book_kind_e, 3, 1)
grid.addWidget(self.price_label, 4, 0)
grid.addWidget(self.price_e, 4, 1)
grid.addWidget(self.num_label, 5, 0)
grid.addWidget(self.num_e, 5, 1)
grid.addWidget(self.cancel_btn, 6, 0)
grid.addWidget(self.ok_btn, 6, 1)
self.setLayout(grid)
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def kind_is_ok(self):
book_name = self.book_name_e.text()
author_name = self.author_name_e.text()
pub_house = self.pub_house_e.text()
sql = 'select Book_kind from Book_information where Book_name = N' + "\'" + book_name + "\' and Book_author=N\'" + author_name + "\' and Book_Publishing_house=N\'" + pub_house + "\'"
self.cursor.execute(sql)
results = self.cursor.fetchall()
if len(results) > 0:
self.book_kind_e.setText(results[0][0])
self.book_name_e.setReadOnly(True)
def price_is_ok(self):
book_name = self.book_name_e.text()
author_name = self.author_name_e.text()
pub_house = self.pub_house_e.text()
sql = 'select Book_price from Book_Information inner join Book_storage on Book_Information.Book_no = Book_storage.Book_no where Book_name = N' + "\'" + book_name + "\' and Book_author=N\'" + author_name + "\' and Book_Publishing_house=N\'" + pub_house + "\'"
print(sql)
self.cursor.execute(sql)
results = self.cursor.fetchall()
if len(results) > 0:
self.price_e.setText(str(results[0][0]))
def order_is_ok(self):
book_name = self.book_name_e.text()
author_name = self.author_name_e.text()
pub_house = self.pub_house_e.text()
book_kind = self.book_kind_e.text()
book_price = self.price_e.text()
num = self.num_e.text()
if book_name == "":
QMessageBox.critical(self, "操作失敗", "請輸入圖書名稱")
elif author_name == "":
QMessageBox.critical(self, "操作失敗", "請輸入作者名字")
elif pub_house == "":
QMessageBox.critical(self, "操作失敗", "請輸入出版社資訊")
elif book_price == "":
QMessageBox.critical(self, "操作失敗", "請輸入圖書售價")
elif book_kind == "":
QMessageBox.critical(self, "操作失敗", "請輸入圖書種類")
else:
QMessageBox.question(self, "提醒", "確定完成進貨操作確定后無法更改,確定操作?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if QMessageBox.Yes:
sql1 = 'select Book_no from Book_information where Book_name = N' + "\'" + book_name + "\' and Book_author=N\'" + author_name + "\' and Book_Publishing_house=N\'" + pub_house + "\'"
self.cursor.execute(sql1)
results = self.cursor.fetchall()
if len(results) > 0:
sql1 = 'select Book_no from Book_information where Book_name = N' + "\'" + book_name + "\' and Book_author=N\'" + author_name + "\' and Book_Publishing_house=N\'" + pub_house + "\'"
self.cursor.execute(sql1)
results = self.cursor.fetchall()
Bno = results[0][0]
sql2 = 'update Book_storage set Book_stock=Book_stock+' + num + ' where Book_no = ' + "\'" + Bno + "\'"
print(sql2)
self.cursor.execute(sql2)
self.connect.commit()
else:
sql3 = 'select top 1 Book_no from Book_Information order by Book_no desc'
self.cursor.execute(sql3)
results = self.cursor.fetchall()
print(results[0][0].split('B'))
no = int(results[0][0].split('B')[1]) + 1
Bno = "B" + str(no)
sql4 = "insert into Book_Information values (\'" + Bno + '\',N\'' + book_name + '\',N\'' + author_name + '\',N\'' + pub_house + '\',N\'' + book_kind + '\'' + ')'
sql5 = "insert into Book_storage values (" + "\'" + Bno + "\'," + str(book_price) + "," + str(
num) + ")"
print(sql4)
self.cursor.execute(sql4)
self.connect.commit()
print(sql5)
self.cursor.execute(sql5)
self.connect.commit()
# results = self.cursor.fetchall()
# print(results)
self.switch_window.emit()
def cancel_order(self):
QMessageBox.question(self, "確定取消進貨", "取消操作后回傳上一級", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if QMessageBox.Yes:
self.switch_window.emit()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Add_bookUI()
sys.exit(app.exec_())
uj5u.com熱心網友回復:
有無大佬幫忙看看呀轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/181349.html
標籤:Qt
上一篇:搭建網站,需要幾種服務器?
