一、前期准备:
1.安装pymssql库 2.配置好SQL Server端口(在SQL配置管理器那里配置,具体可以参考java端口配置),这个有点难哦~多去搜搜。 3.建立数据库,建立表格 4.弄一个好键盘不然敲着不舒服哈哈哈哈哈哈哈~
二、题目
三、代码如下:
"""------------------------ 餐饮管理系统 ------------------------"""
import pymssql
from tkinter
import *
def TianjiaZhuoTai(TableNumber
,TableRongliang
,TableZhuangTai
,TableWeizhi
):
tablenumber
= int(TableNumber
)
tablerongliang
= int(TableRongliang
)
tablezhuangtai
=TableZhuangTai
tableweizhi
=TableWeizhi
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= """insert into 桌台(TableNumber,TableRongliang,TableZhuangTai,TableWeizhi) values ('%d','%d','%s','%s')"""
sql
= sql
% (tablenumber
,tablerongliang
,tablezhuangtai
,tableweizhi
)
cursor
.execute
(sql
)
connect
.commit
()
cursor
.close
()
connect
.close
()
def ShanChuZhuoTai(Number
):
number
= int(Number
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
cursor
.execute
("delete from 桌台 where TableNumber ={}".format(number
))
connect
.commit
()
cursor
.close
()
connect
.close
()
def ZhuoTai():
winNew
= Toplevel
(root
)
winNew
.geometry
('580x540')
winNew
.title
('桌台管理')
lb1
= Label
(winNew
,text
= "当前桌台信息如下:")
lb1
.pack
()
lb2
= Label
(winNew
,text
= "")
lb2
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select * from 桌台"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
S
= "桌台号 桌台容量 桌台状态 所在楼层 "+'\n'
while row
:
S
= S
+ str(row
) + '\n'
row
= cursor
.fetchone
()
lb2
.config
(text
= S
)
lb8
= Label
(winNew
,text
= "请输入要添加的桌台号:")
lb8
.pack
()
entry0
= Entry
(winNew
)
entry0
.pack
()
lb4
= Label
(winNew
,text
= "请输入要添加的桌台容量:")
lb4
.pack
()
entry1
= Entry
(winNew
)
entry1
.pack
()
lb5
= Label
(winNew
,text
= "请输入添加的桌台状态:")
lb5
.pack
()
entry2
= Entry
(winNew
)
entry2
.pack
()
lb6
= Label
(winNew
,text
= "请输入添加的桌台位置:")
lb6
.pack
()
entry3
= Entry
(winNew
)
entry3
.pack
()
lb3
= Label
(winNew
,text
= "请输入需要删除的桌台号:")
lb3
.pack
()
entry4
= Entry
(winNew
)
entry4
.pack
()
btn1
= Button
(winNew
,text
= '确认添加',command
= lambda:TianjiaZhuoTai
(entry0
.get
(),entry1
.get
(),entry2
.get
(),entry3
.get
()))
btn1
.pack
()
btn2
= Button
(winNew
,text
= '确认删除',command
= lambda:ShanChuZhuoTai
(entry4
.get
()))
btn2
.pack
()
btClose
= Button
(winNew
,text
= '退出',command
= winNew
.destroy
)
btClose
.pack
()
def TianjiaCaiPing(CaiNumber
,CaiName
,FenLiang
,Price
):
cainumber
= int(CaiNumber
)
cainame
= CaiName
fenliang
= FenLiang
price
= int(Price
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= """insert into 菜品(CaiNumber,CaiName,Fenliang,Price) values ('%d','%s','%s','%d')"""
sql
= sql
% (cainumber
,cainame
,fenliang
,price
)
cursor
.execute
(sql
)
connect
.commit
()
cursor
.close
()
connect
.close
()
def ShanChuCaiPing(Number
):
number
= int(Number
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
cursor
.execute
("delete from 菜品 where CaiNumber ={}".format(number
))
connect
.commit
()
cursor
.close
()
connect
.close
()
def CaiDan():
winNew
= Toplevel
(root
)
winNew
.geometry
('590x560')
winNew
.title
('菜单管理')
lb1
= Label
(winNew
,text
= "当前菜品信息如下:")
lb1
.pack
()
lb2
= Label
(winNew
,text
= "")
lb2
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select * from 菜品"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
S
= "菜品号 菜名 份量 价格 "+'\n'
while row
:
S
= S
+ str(row
) + '\n'
row
= cursor
.fetchone
()
lb2
.config
(text
= S
)
lb3
= Label
(winNew
,text
= "请输入菜品号:")
lb3
.pack
()
entry1
= Entry
(winNew
)
entry1
.pack
()
lb4
= Label
(winNew
,text
= "请输入菜名:")
lb4
.pack
()
entry2
= Entry
(winNew
)
entry2
.pack
()
lb5
= Label
(winNew
,text
= "请输入份量:")
lb5
.pack
()
entry3
= Entry
(winNew
)
entry3
.pack
()
lb6
= Label
(winNew
,text
= "请输入价格:")
lb6
.pack
()
entry4
= Entry
(winNew
)
entry4
.pack
()
lb7
= Label
(winNew
,text
= "请输入需要删除的菜品号:")
lb7
.pack
()
entry5
= Entry
(winNew
)
entry5
.pack
()
btn1
= Button
(winNew
,text
= '确认添加',command
= lambda:TianjiaCaiPing
(entry1
.get
(),entry2
.get
(),entry3
.get
(),entry4
.get
()))
btn1
.pack
()
btn2
= Button
(winNew
,text
= '确认删除',command
= lambda:ShanChuCaiPing
(entry5
.get
()))
btn2
.pack
()
btClose
= Button
(winNew
,text
= '退出',command
= winNew
.destroy
)
btClose
.pack
()
def YingYeErJiSuan():
lb3
= Label
(winNew
,text
= "您当前订单需支付金额为:")
lb3
.pack
()
lb4
= Label
(winNew
,text
= "")
lb4
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select SUM(FinalPay) from 订单细节"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
lb4
.config
(text
= row
)
lb5
= Label
(winNew
,text
= "元")
lb5
.pack
()
connect
.commit
()
cursor
.close
()
connect
.close
()
btClose
= Button
(winNew
,text
= '点击关闭',command
= winNew
.destroy
)
btClose
.pack
()
def YingYeEr():
winNew
= Toplevel
(root
)
winNew
.geometry
('340x200')
winNew
.title
('营业额管理')
lb3
= Label
(winNew
,text
= "当前营业总额为:\n")
lb3
.pack
()
lb4
= Label
(winNew
,text
= "")
lb4
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select SUM(FinalPay) from 订单细节"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
lb4
.config
(text
= row
)
lb5
= Label
(winNew
,text
= "元\n")
lb5
.pack
()
connect
.commit
()
cursor
.close
()
connect
.close
()
btClose
= Button
(winNew
,text
= '点击关闭',command
= winNew
.destroy
)
btClose
.pack
()
def ZhangYongTai(Number
):
number
= int(Number
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
cursor
.execute
("update 桌台 set TableRongliang=TableRongliang-1 where TableNumber ={}".format(number
))
connect
.commit
()
cursor
.close
()
connect
.close
()
def KaiTai():
winNew
= Toplevel
(root
)
winNew
.geometry
('550x340')
winNew
.title
('开台管理')
lb3
= Label
(winNew
,text
= "桌台信息如下:")
lb3
.pack
()
lb2
= Label
(winNew
,text
= "")
lb2
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select * from 桌台"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
S
= "桌台号 容量 状态 位置 "+'\n'
while row
:
S
= S
+ str(row
) + '\n'
row
= cursor
.fetchone
()
lb2
.config
(text
= S
)
lb4
= Label
(winNew
,text
= "请选择相关人数的桌台号:")
lb4
.pack
()
entry1
= Entry
(winNew
)
entry1
.pack
()
btn1
= Button
(winNew
,text
= '点击确认',command
= lambda:ZhangYongTai
(entry1
.get
()))
btn1
.pack
()
cursor
.close
()
connect
.close
()
btClose
= Button
(winNew
,text
= '关闭',command
= winNew
.destroy
)
btClose
.pack
()
def DingDanXiJie(DingDanNumber
,DetailNumber
,CaiPingNumber
,ShuLiangNumber
,CaiPingPrice
):
dingdannumber
= DingDanNumber
detail
= DetailNumber
caipingnumber
= CaiPingNumber
shuliangnumber
= int(ShuLiangNumber
)
caipingprice
= int(CaiPingPrice
)
finapay
= shuliangnumber
*caipingprice
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= """insert into 订单细节(OrderNumber,OrderXijieNumber,CaipinNumber,CaipinShuliang,CaipinMoney,FinalPay) values (%s,%s,%s,%d,%d,%d)"""
sql
= sql
% (dingdannumber
,detail
,caipingnumber
,shuliangnumber
,caipingprice
,finapay
)
cursor
.execute
(sql
)
connect
.commit
()
cursor
.close
()
connect
.close
()
def ShanChuDingDanXijie(Number
,Xijienumber
):
number
= int(Number
)
xijienumber
= int(Xijienumber
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
cursor
.execute
("delete from 订单细节 where OrderNumber ={} and OrderXijieNumber = {} ".format(number
,xijienumber
))
connect
.commit
()
cursor
.close
()
connect
.close
()
def DianCan():
winNew
= Toplevel
(root
)
winNew
.geometry
('650x630')
winNew
.title
('点餐管理')
lb3
= Label
(winNew
,text
= "菜品信息如下:")
lb3
.pack
()
lb2
= Label
(winNew
,text
= "")
lb2
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select * from 菜品"
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
S
= "菜品号 菜名 份量 价格 "+'\n'
while row
:
S
= S
+ str(row
) + '\n'
row
= cursor
.fetchone
()
lb2
.config
(text
= S
)
lb8
= Label
(winNew
,text
= "请输入订单号:")
lb8
.pack
()
entry0
= Entry
(winNew
)
entry0
.pack
()
lb4
= Label
(winNew
,text
= "请输入订单细节号:")
lb4
.pack
()
entry1
= Entry
(winNew
)
entry1
.pack
()
lb5
= Label
(winNew
,text
= "请选择菜品号:")
lb5
.pack
()
entry2
= Entry
(winNew
)
entry2
.pack
()
lb6
= Label
(winNew
,text
= "请选择菜品数量:")
lb6
.pack
()
entry3
= Entry
(winNew
)
entry3
.pack
()
lb7
= Label
(winNew
,text
= "请输入菜品单价:")
lb7
.pack
()
entry4
= Entry
(winNew
)
entry4
.pack
()
btn1
= Button
(winNew
,text
= '确认添加',command
= lambda:DingDanXiJie
(entry0
.get
(),entry1
.get
(),entry2
.get
(),entry3
.get
(),entry4
.get
()))
btn1
.pack
()
btClose
= Button
(winNew
,text
= '确认取消',command
= lambda:ShanChuDingDanXijie
(entry0
.get
(),entry1
.get
()))
btClose
.pack
()
btClose
= Button
(winNew
,text
= '退出',command
= winNew
.destroy
)
btClose
.pack
()
lb7
= Label
(winNew
,text
= "(注:可重复添加,每个顾客的订单号要一样,同一个顾客每次添加的细节号不能一样\n取消已添加的菜品,需输入订单号和订单细节号)")
lb7
.pack
()
cursor
.close
()
connect
.close
()
def ShowMoney(Number
):
number
= int(Number
)
winNew
= Toplevel
(root
)
winNew
.geometry
('230x120')
winNew
.title
('订单金额')
lb3
= Label
(winNew
,text
= "您当前订单需支付金额为:")
lb3
.pack
()
lb4
= Label
(winNew
,text
= "")
lb4
.pack
()
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
sql
= "select SUM(FinalPay) from 订单细节 where OrderNumber = {}".format(number
)
cursor
.execute
(sql
)
row
= cursor
.fetchone
()
lb4
.config
(text
= row
)
lb5
= Label
(winNew
,text
= "元")
lb5
.pack
()
connect
.commit
()
cursor
.close
()
connect
.close
()
btClose
= Button
(winNew
,text
= '点击关闭',command
= winNew
.destroy
)
btClose
.pack
()
def ShiFangTai(Number
):
number
= int(Number
)
connect
= pymssql
.connect
('fuwuqiming', 'Xuuu', '12345', 'CateringManagementSystem')
cursor
= connect
.cursor
()
cursor
.execute
("update 桌台 set TableRongliang=TableRongliang+1 where TableNumber ={}".format(number
))
connect
.commit
()
cursor
.close
()
connect
.close
()
def JieZhang():
winNew
= Toplevel
(root
)
winNew
.geometry
('350x210')
winNew
.title
('查看账单')
lb8
= Label
(winNew
,text
= "请输入订单号查看账单:")
lb8
.pack
()
entry9
= Entry
(winNew
)
entry9
.pack
()
lb9
= Label
(winNew
,text
= "请输入桌台号完成消费:")
lb9
.pack
()
entry0
= Entry
(winNew
)
entry0
.pack
()
btC
= Button
(winNew
,text
= '查看账单',command
= lambda:ShowMoney
(entry9
.get
()))
btC
.pack
()
btC1
= Button
(winNew
,text
= '完成支付',command
= lambda:ShiFangTai
(entry0
.get
()))
btC1
.pack
()
btClose
= Button
(winNew
,text
= '关闭',command
= winNew
.destroy
)
btClose
.pack
()
def GengXin():
winNew
= Toplevel
(root
)
winNew
.geometry
('320x240')
winNew
.title
('关于餐饮管理系统')
lb
= Label
(winNew
,text
= "\n\n\n当前已为最新版本\n\nEMUI 6.0\n")
lb
.pack
()
btClose
= Button
(winNew
,text
= '点击关闭',command
= winNew
.destroy
)
btClose
.pack
()
root
= Tk
()
root
.geometry
('780x366')
root
.title
('餐饮管理系统')
photo
= PhotoImage
(file='D:/软件下载/美食.gif')
photoLabel
= Label
(root
,text
= "欢迎光临老八餐厅",justify
= LEFT
,image
= photo
,compound
= CENTER
,font
= ("华文行楷",30), fg
= "black")
photoLabel
.pack
()
mainmenu
= Menu
(root
)
GuanLimenu
= Menu
(mainmenu
,tearoff
=0)
mainmenu
.add_cascade
(label
= '管理员入口',menu
= GuanLimenu
)
GuanLimenu
.add_command
(label
="桌台管理",command
= ZhuoTai
)
GuanLimenu
.add_command
(label
="菜单管理",command
= CaiDan
)
GuanLimenu
.add_command
(label
="营业额管理",command
= YingYeEr
)
GuKemenu
= Menu
(mainmenu
,tearoff
=0)
mainmenu
.add_cascade
(label
= '顾客入口',menu
= GuKemenu
)
GuKemenu
.add_command
(label
="开台", command
= KaiTai
)
GuKemenu
.add_command
(label
="点餐", command
= DianCan
)
GuKemenu
.add_command
(label
="结账", command
= JieZhang
)
XiTongmenu
= Menu
(mainmenu
,tearoff
=0)
mainmenu
.add_cascade
(label
= '系统维护',menu
= XiTongmenu
)
XiTongmenu
.add_command
(label
="退出程序",command
= root
.destroy
)
XiTongmenu
.add_command
(label
="系统更新",command
= GengXin
)
root
.config
(menu
= mainmenu
)
四、运行结果
五、建立的数据库和数据库表
1、三个表,分别为 当然如果你想让你的功能更丰富你可以多加几个表,同时增加一些触发器(表之间的联系)啥的,让它看着更完善。
2、设计表
1.菜品表
2.订单细节表 注:这个不需要自己添加内容。。 3.桌台表
注:附送测试数据库的连接代码
(可以先创建一个 python文件 用来先测试一下数据库有没有连接上) 配置端口的全都选"启用”,全都选"是"就行了,配置好后重启电脑就可以使用连接代码啦~
import pymssql
def conn():
connect
= pymssql
.connect
('(local)', 'sa', '12345', 'shujukuming')
if connect
:
print("连接成功!")
return connect
if __name__
== '__main__':
conn
= conn
()
. . . .
写的不好多多指教哈哈哈哈哈~~哈哈哈
. .