from PyQt5.QtWidgets importQPushButton, QWidget, QHBoxLayout, QLabel, QLineEdit, QVBoxLayout, QMessageBox, QHeaderViewfrom PyQt5.QtGui importQIcon, QStandardItemModel, QStandardItemfrom PyQt5 importQtWidgetsclassMyTableGui(QWidget):def __init__(self, sender, conn):
super(MyTableGui, self).__init__()globalsender_1, con
sender_1=sender
con=conn
self.initUI()definitUI(self):
self.setWindowIcon(QIcon('shop.png'))
self.setWindowTitle('选择%s的超市表单' %sender_1.text())
self.resize(500, 100)
h_layout=QHBoxLayout(self)
btn_gys= QPushButton('供应商表单')
btn_wp= QPushButton('物品表单')
btn_ch= QPushButton('出货表单')
h_layout.addWidget(btn_gys)
h_layout.addWidget(btn_wp)
h_layout.addWidget(btn_ch)
btn_gys.clicked.connect(self.table_gys)
btn_wp.clicked.connect(self.table_wp)
btn_ch.clicked.connect(self.table_ch)deftable_gys(self):
self.deltable=Table_gys()
self.deltable.show()
self.close()deftable_wp(self):
self.deltable=Table_wp()
self.deltable.show()
self.close()deftable_ch(self):
self.deltable=Table_ch()
self.deltable.show()
self.close()classTable_gys(QWidget):def __init__(self):
super().__init__()
self.initUI()definitUI(self):
self.setWindowIcon(QIcon('shop.png'))if sender_1.text() == '删除数据':
self.setWindowTitle('删除-供应商表单')
self.resize(400, 130)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('供货编号', self)
lbl_1.move(70, 20)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
btn= QPushButton('确定', self)
btn.move(145, 70)
btn.clicked.connect(self.del_data)elif sender_1.text() == '添加数据':
self.setWindowTitle('添加-供应商表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('供货编号(必填)', self)
lbl_1.move(30, 20)
lbl_2= QLabel('供货名称', self)
lbl_2.move(70, 70)
lbl_3= QLabel('联系方式', self)
lbl_3.move(70, 120)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 65)
self.le_3=QLineEdit(self)
self.le_3.move(150, 115)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.add_data)elif sender_1.text() == '修改数据':
self.setWindowTitle('修改-供应商表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('要修改的供货编号', self)
lbl_1.move(20, 20)
lbl_2= QLabel('供货编号', self)
lbl_2.move(70, 70)
lbl_3= QLabel('供货名称', self)
lbl_3.move(70, 120)
lbl_4= QLabel('联系方式', self)
lbl_4.move(70, 170)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 65)
self.le_3=QLineEdit(self)
self.le_3.move(150, 115)
self.le_4=QLineEdit(self)
self.le_4.move(150, 165)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.update_data)elif sender_1.text() == '查找数据':
self.setWindowTitle('查找-供应商表单')
self.resize(500, 300)
self.setFixedSize(self.width(), self.height())
v_layout=QVBoxLayout(self)
h_layout=QHBoxLayout()
v_layout.addLayout(h_layout)
lbl_1= QLabel('供货编号')
self.le_1=QLineEdit()
h_layout.addWidget(lbl_1)
h_layout.addWidget(self.le_1)
btn= QPushButton('确定', self)
v_layout.addWidget(btn)
self.table_widget=QtWidgets.QTableView()
v_layout.addWidget(self.table_widget)
btn.clicked.connect(self.search_data)
self.table_widget.horizontalHeader().setStretchLastSection(True)
self.table_widget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)defdel_data(self):try:
cursor=con.cursor()
cursor.execute('''delete from supplier where supplierid='%s';''' %self.le_1.text())
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defadd_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_1.text() != '':
a_str= a_str + '\'' + self.le_1.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_2.text() != '':
a_str= a_str + '\'' + self.le_2.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_3.text() != '':
a_str= a_str + '\'' + self.le_3.text() + '\''
else:
a_str= a_str + 'null'cursor.execute('''insert into supplier values(%s);''' %a_str)
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defupdate_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_2.text() != '':
a_str= a_str + 'supplierid=' + '\'' + self.le_2.text() + '\''
if self.le_3.text() != '' or self.le_4.text() != '':
a_str= a_str + ','
if self.le_3.text() != '':
a_str= a_str + 'suppliername=' + '\'' + self.le_3.text() + '\''
if self.le_4.text() != '':
a_str= a_str + ','
if self.le_4.text() != '':
a_str= a_str + 'contact=' + '\'' + self.le_4.text() + '\''cursor.execute('''update supplier set %s where supplierid='%s';''' %(a_str, self.le_1.text()))
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defsearch_data(self):try:
cursor=con.cursor()
cursor.execute('''select * from supplier where supplierid='%s';''' %self.le_1.text())
con.commit()
data=cursor.fetchall()
model=QStandardItemModel()
model.setHorizontalHeaderLabels(['供货编号', '供货名称', '联系方式'])
cursor.close()
m=0for row indata:
n=0for item inrow:
model.setItem(m, n, QStandardItem(str(item)))
n+= 1m+= 1self.table_widget.setModel(model)except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)classTable_wp(QWidget):def __init__(self):
super().__init__()
self.initUI()definitUI(self):
self.setWindowIcon(QIcon('shop.png'))if sender_1.text() == '删除数据':
self.setWindowTitle('删除-物品表单')
self.resize(400, 130)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('物品编号', self)
lbl_1.move(70, 20)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
btn= QPushButton('确定', self)
btn.move(145, 70)
btn.clicked.connect(self.del_data)elif sender_1.text() == '添加数据':
self.setWindowTitle('添加-物品表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('物品编号(必填)', self)
lbl_1.move(30, 20)
lbl_2= QLabel('物品名称', self)
lbl_2.move(70, 70)
lbl_3= QLabel('供货编号(已有编号)', self)
lbl_3.move(10, 120)
lbl_4= QLabel('存货数量', self)
lbl_4.move(70, 170)
lbl_5= QLabel('进价', self)
lbl_5.move(70, 220)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 65)
self.le_3=QLineEdit(self)
self.le_3.move(150, 115)
self.le_4=QLineEdit(self)
self.le_4.move(150, 165)
self.le_5=QLineEdit(self)
self.le_5.move(150, 215)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.add_data)elif sender_1.text() == '修改数据':
self.setWindowTitle('修改-物品表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('要修改的物品编号', self)
lbl_1.move(20, 20)
lbl_2= QLabel('物品编号', self)
lbl_2.move(70, 60)
lbl_3= QLabel('物品名称', self)
lbl_3.move(70, 100)
lbl_4= QLabel('供货编号(已有编号)', self)
lbl_4.move(10, 140)
lbl_5= QLabel('库存数量', self)
lbl_5.move(70, 180)
lbl_6= QLabel('进价', self)
lbl_6.move(70, 220)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 55)
self.le_3=QLineEdit(self)
self.le_3.move(150, 95)
self.le_4=QLineEdit(self)
self.le_4.move(150, 135)
self.le_5=QLineEdit(self)
self.le_5.move(150, 175)
self.le_6=QLineEdit(self)
self.le_6.move(150, 215)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.update_data)elif sender_1.text() == '查找数据':
self.setWindowTitle('查找-物品表单')
self.resize(700, 300)
self.setFixedSize(self.width(), self.height())
v_layout=QVBoxLayout(self)
h_layout=QHBoxLayout()
v_layout.addLayout(h_layout)
lbl_1= QLabel('物品编号')
self.le_1=QLineEdit()
h_layout.addWidget(lbl_1)
h_layout.addWidget(self.le_1)
btn= QPushButton('确定', self)
v_layout.addWidget(btn)
self.table_widget=QtWidgets.QTableView()
v_layout.addWidget(self.table_widget)
btn.clicked.connect(self.search_data)
self.table_widget.horizontalHeader().setStretchLastSection(True)
self.table_widget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)defdel_data(self):try:
cursor=con.cursor()
cursor.execute('''delete from goods where goodsid='%s';''' %self.le_1.text())
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defadd_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_1.text() != '':
a_str= a_str + '\'' + self.le_1.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_2.text() != '':
a_str= a_str + '\'' + self.le_2.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_3.text() != '':
a_str= a_str + '\'' + self.le_3.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_4.text() != '':
a_str= a_str + self.le_4.text() + ','
else:
a_str= a_str + 'null' + ','
if self.le_5.text() != '':
a_str= a_str +self.le_5.text()else:
a_str= a_str + 'null'cursor.execute('''insert into goods values(%s);''' %a_str)
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defupdate_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_2.text() != '':
a_str= a_str + 'goodsid=' + '\'' + self.le_2.text() + '\''
if self.le_3.text() != '' or self.le_4.text() != '' or self.le_5.text() != '' or self.le_6.text() != '':
a_str= a_str + ','
if self.le_3.text() != '':
a_str= a_str + 'goodsname=' + '\'' + self.le_3.text() + '\''
if self.le_4.text() != '' or self.le_5.text() != '' or self.le_6.text() != '':
a_str= a_str + ','
if self.le_4.text() != '':
a_str= a_str + 'supplierid=' + '\'' + self.le_4.text() + '\''
if self.le_5.text() != '' or self.le_6.text() != '':
a_str= a_str + ','
if self.le_5.text() != '':
a_str= a_str + 'amount=' +self.le_5.text()if self.le_6.text() != '':
a_str= a_str + ','
if self.le_6.text() != '':
a_str= a_str + 'supplierprice=' +self.le_6.text()
cursor.execute('''update goods set %s where goodsid='%s';''' %(a_str, self.le_1.text()))
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defsearch_data(self):try:
cursor=con.cursor()
cursor.execute('''select * from goods where goodsid='%s';''' %self.le_1.text())
con.commit()
data=cursor.fetchall()
model=QStandardItemModel()
model.setHorizontalHeaderLabels(['物品编号', '物品名称', '供货编号', '存货数量', '进价'])
cursor.close()
m=0for row indata:
n=0for item inrow:
model.setItem(m, n, QStandardItem(str(item)))
n+= 1m+= 1self.table_widget.setModel(model)except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)classTable_ch(QWidget):def __init__(self):
super().__init__()
self.initUI()definitUI(self):
self.setWindowIcon(QIcon('shop.png'))if sender_1.text() == '删除数据':
self.setWindowTitle('删除-出货表单')
self.resize(400, 140)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('物品编号', self)
lbl_1.move(70, 20)
lbl_2= QLabel('销售编号', self)
lbl_2.move(70, 60)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 55)
btn= QPushButton('确定', self)
btn.move(145, 100)
btn.clicked.connect(self.del_data)elif sender_1.text() == '添加数据':
self.setWindowTitle('添加-出货表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('销售编号', self)
lbl_1.move(70, 20)
lbl_2= QLabel('物品编号(已有编号)', self)
lbl_2.move(10, 70)
lbl_3= QLabel('出货数量', self)
lbl_3.move(70, 120)
lbl_4= QLabel('售价', self)
lbl_4.move(70, 170)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_2=QLineEdit(self)
self.le_2.move(150, 65)
self.le_3=QLineEdit(self)
self.le_3.move(150, 115)
self.le_4=QLineEdit(self)
self.le_4.move(150, 165)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.add_data)elif sender_1.text() == '修改数据':
self.setWindowTitle('修改-出货表单')
self.resize(400, 300)
self.setFixedSize(self.width(), self.height())
lbl_1= QLabel('要修改的物品编号', self)
lbl_1.move(20, 20)
lbl_6= QLabel('要修改的销售编号', self)
lbl_6.move(20, 60)
lbl_2= QLabel('销售编号', self)
lbl_2.move(70, 100)
lbl_3= QLabel('物品编号(已有编号)', self)
lbl_3.move(10, 140)
lbl_4= QLabel('售出数量', self)
lbl_4.move(70, 180)
lbl_5= QLabel('售价', self)
lbl_5.move(70, 220)
self.le_1=QLineEdit(self)
self.le_1.move(150, 15)
self.le_6=QLineEdit(self)
self.le_6.move(150, 55)
self.le_2=QLineEdit(self)
self.le_2.move(150, 95)
self.le_3=QLineEdit(self)
self.le_3.move(150, 135)
self.le_4=QLineEdit(self)
self.le_4.move(150, 175)
self.le_5=QLineEdit(self)
self.le_5.move(150, 215)
btn= QPushButton('确定', self)
btn.move(145, 250)
btn.clicked.connect(self.update_data)elif sender_1.text() == '查找数据':
self.setWindowTitle('查找-出货表单')
self.resize(600, 300)
self.setFixedSize(self.width(), self.height())
v_layout=QVBoxLayout(self)
h_layout=QHBoxLayout()
v_layout.addLayout(h_layout)
lbl_1= QLabel('物品编号')
self.le_1=QLineEdit()
h_layout.addWidget(lbl_1)
h_layout.addWidget(self.le_1)
btn= QPushButton('确定', self)
v_layout.addWidget(btn)
self.table_widget=QtWidgets.QTableView()
v_layout.addWidget(self.table_widget)
btn.clicked.connect(self.search_data)
self.table_widget.horizontalHeader().setStretchLastSection(True)
self.table_widget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)defdel_data(self):try:
cursor=con.cursor()
cursor.execute('''delete from sale where goodsid='%s' and saleid='%s';''' %(self.le_1.text(), self.le_2.text()))
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defadd_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_1.text() != '':
a_str= a_str + '\'' + self.le_1.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_2.text() != '':
a_str= a_str + '\'' + self.le_2.text() + '\'' + ','
else:
a_str= a_str + 'null' + ','
if self.le_3.text() != '':
a_str= a_str + self.le_3.text() + ','
else:
a_str= a_str + 'null' + ','
if self.le_4.text() != '':
a_str= a_str +self.le_4.text()else:
a_str= a_str + 'null'cursor.execute('''insert into sale values(%s,now());''' %a_str)
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defupdate_data(self):try:
cursor=con.cursor()
a_str= ''
if self.le_2.text() != '':
a_str= a_str + 'saleid=' + '\'' + self.le_2.text() + '\''
if self.le_3.text() != '' or self.le_4.text() != '' or self.le_5.text() != '':
a_str= a_str + ','
if self.le_3.text() != '':
a_str= a_str + 'goodsid=' + '\'' + self.le_3.text() + '\''
if self.le_4.text() != '' or self.le_5.text() != '':
a_str= a_str + ','
if self.le_4.text() != '':
a_str= a_str + 'saleamount=' +self.le_4.text()if self.le_5.text() != '':
a_str= a_str + ','
if self.le_5.text() != '':
a_str= a_str + 'saleprice=' +self.le_5.text()
cursor.execute('''update sale set %s where goodsid='%s' and saleid='%s';''' %(a_str, self.le_1.text(), self.le_6.text()))
con.commit()
cursor.close()
info= QMessageBox.information(self, '系统提示', '执行成功!\n点击Ok返回主界面,点击Cancel返回上一级。',
QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok)if info ==QMessageBox.Ok:
self.close()except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)defsearch_data(self):try:
cursor=con.cursor()
cursor.execute('''select * from sale where goodsid='%s';''' %self.le_1.text())
con.commit()
data=cursor.fetchall()
model=QStandardItemModel()
model.setHorizontalHeaderLabels(['销售编号', '物品编号', '出货数量', '售价', '出售日期'])
cursor.close()
m=0for row indata:
n=0for item inrow:
model.setItem(m, n, QStandardItem(str(item)))
n+= 1m+= 1self.table_widget.setModel(model)except:
con.rollback()
QMessageBox.information(self,'系统提示', '发生错误,无法正常执行该操作,请确认信息无误后再试。',
QMessageBox.Ok, QMessageBox.Ok)