2022年 11月 4日

python实现商品进销存管理系统

python实现商品进销存管理系统,基于python,MySQL,tkinter

  1. import pymysql #导入数据库模块
  2. import tkinter #导入相关的窗体模块
  3. import os #利用os模块可以方便定义完整路径
  4. import tkinter.messagebox#实现提示框的组件
  5. import tkinter.simpledialog#简单对话框
  6. from wordcloud import WordCloud
  7. import matplotlib.pyplot as plt
  8. import threading
  9. import pandas as pd #对数据进行访问
  10. import sys #与操作系统交互
  11. def get_resources_path(relative_path):#利用此函数实现资源路径的定位
  12. if getattr(sys,"frozen",False):
  13. base_path=sys._MEIPASS #获取临时资源
  14. else:
  15. base_path=os.path.abspath(".") #获取当前路径
  16. return os.path.join(base_path,relative_path) #获得绝对路径
  17. LOGO_PATH=get_resources_path(os.path.join("resources",'shop_logo.ico')) #'resources'+os.sep + 'shop_logo.ico'#logo文件路径
  18. IMAGES_PATH=get_resources_path(os.path.join("resources",'background.png'))#'resources' +os.sep+ 'background.png'#图像文件路径
  19. Warehouse_PATH=get_resources_path(os.path.join("resources",'店铺.png'))#'resources' +os.sep+ '店铺.png'#图像文件路径
  20. COMMODITY_DELETE_PATH=get_resources_path(os.path.join("resources",'店铺修改背景图.png'))#'resources' +os.sep+ '店铺修改背景图.png'#图像文件路径
  21. WORDCLOUD_PATH='词云图.png'
  22. EXCEL_COMMODITY=get_resources_path(os.path.join("resources",'商品数据.xlsx'))#'resources'+ os.sep + '商品数据.xlsx'#商品数据的路径
  23. EXCEL_STORE=get_resources_path(os.path.join("resources",'店铺.xlsx'))#'resources'+ os.sep + '店铺.xlsx'#店铺数据的路径
  24. EXCEL_WAREHOUSE=get_resources_path(os.path.join("resources",'库房.xlsx'))#'resources'+ os.sep + '库房.xlsx'#库房数据的路径
  25. EXCEL_CUSTOMER=get_resources_path(os.path.join("resources",'顾客数据.xlsx'))#'resources'+ os.sep + '顾客数据.xlsx'#顾客数据的路径
  26. class MainForm: #定义窗体类,父类
  27. def __init__(self):#构造窗体
  28. self.root=tkinter.Tk()#创建一个窗体
  29. self.root.title("露露小卖店")#设置标题
  30. self.root.iconbitmap(LOGO_PATH)#设置logo资源
  31. self.root.geometry('680x500+150+50')#初始化窗口大小
  32. self.root.resizable(False,False) #固定窗口大小
  33. def worcloud_s(self,text): #生产词云图片
  34. wc= WordCloud(
  35. collocations=False,
  36. font_path=r"C:/Windows/Fonts/simfang.ttf",
  37. background_color="black",
  38. width=600,
  39. height=300,
  40. max_words=50).generate(text)
  41. wc.to_image()
  42. wc.to_file("词云图.png")
  43. class The_login(MainForm): #登录窗口
  44. def __init__(self):
  45. super().__init__()
  46. photo = tkinter.PhotoImage(file=IMAGES_PATH) # 设置图像资源
  47. tkinter.Label(self.root, image=photo,width=680,height=500).place(x=0,y=0)
  48. tkinter.Label(self.root, text="用户名", font=("黑体", 20)).place(x=150,y=200)
  49. self.entry1 = tkinter.Entry(self.root,font=("黑体", 20))
  50. self.entry1.place(x=300,y=200)
  51. tkinter.Label(self.root, text="密码", font=("黑体", 20)).place(x=150,y=250)
  52. self.entry2 = tkinter.Entry(self.root,font=("黑体", 20),show="*")
  53. self.entry2.place(x=300,y=250)
  54. tkinter.Button(self.root, text="店铺登录",command=self.bidui, width=15, font=("微软雅黑", 10)).place(x=150,y=300)
  55. tkinter.Button(self.root, text="退出", command=self.root.quit, width=15, font=("微软雅黑", 10)).place(x=450, y=300)
  56. tkinter.Button(self.root, text="导入店铺信息", command=self.store_in, width=10, font=("微软雅黑", 10)).place(x=550, y=450)
  57. tkinter.Button(self.root, text="店铺注册", command=self.Registered, width=10, font=("微软雅黑", 10)).place(x=0, y=450)
  58. self.root1=self.root.mainloop()
  59. #对用户账号,密码进行查询,比对
  60. def bidui(self):
  61. global global_id
  62. def find_store():#查找店铺账号和密码数据
  63. cursor=conn.cursor()
  64. sql='select * from store where store_id="%s" and store_password="%s"'%(self.entry1.get(),self.entry2.get())
  65. cursor.execute(sql)
  66. conn.commit()
  67. cursor.close()
  68. return cursor.fetchone()
  69. try :
  70. if bool(find_store())==1:
  71. print("登录成功")
  72. global_id=self.entry1.get()
  73. self.root.destroy()
  74. The_store()
  75. else:
  76. labell = tkinter.Label(self.root, text='登陆失败!', font=("黑体", 10)) ##
  77. labell.place(x=300, y=0)
  78. except:
  79. pass
  80. def store_in(self):
  81. def remove_store_all(): # 清除店铺中的数据表数据
  82. cursor = conn.cursor() # 创建游标
  83. cursor.execute('delete from store')
  84. conn.commit() # 提交
  85. cursor.close() # 关闭游标
  86. def store_Add(): # 向店铺的表中导入数据
  87. cursor = conn.cursor() # 创建游标
  88. for co in range(len(df["店铺账号"])-1):
  89. print(co)
  90. try:
  91. sql = 'insert into store values (%s,%s,%s,%s,%s,%s,%s);' # 添加数据
  92. cursor.execute(sql,(
  93. df["店铺账号"][co],
  94. df["店铺密码"][co],
  95. df["店铺名称"][co],
  96. df["店铺地址"][co],
  97. df["店铺电话"][co],
  98. df["店主"][co],
  99. df["盈亏"][co])) # 执行添加数据
  100. conn.commit() # 提交
  101. except:
  102. print(df["店铺名称"][co])
  103. cursor.close() # 关闭游
  104. df = pd.read_excel(EXCEL_STORE)
  105. remove_store_all()
  106. store_Add()
  107. #——————————————————————-——————————店铺注册------------------------------
  108. def Registered(self): #店铺注册信息
  109. def remove_prompt(): # 清空提示信息
  110. Entry_prompt.delete(0.0, tkinter.END)
  111. Entry_prompt.update()
  112. Entry_prompt.insert(tkinter.INSERT,"———————————店铺注册——————————")
  113. def store_add():#添加店铺信息
  114. if Entry_user.get()=='': #用户名不能为空
  115. remove_prompt()
  116. Entry_prompt.insert(tkinter.INSERT, "用户名输入为空\n")
  117. elif Entry_password.get()=='': #密码不能为空
  118. remove_prompt()
  119. Entry_prompt.insert(tkinter.INSERT, "密码输入为空\n")
  120. elif Entry_name.get() == '': # 名称不能为空
  121. remove_prompt()
  122. Entry_prompt.insert(tkinter.INSERT, "店铺名称输入为空\n")
  123. elif Entry_address.get() == '': # 地址不能为空
  124. remove_prompt()
  125. Entry_prompt.insert(tkinter.INSERT, "店铺地址输入为空\n")
  126. elif Entry_phon.get() == '': # 电话不能为空
  127. remove_prompt()
  128. Entry_prompt.insert(tkinter.INSERT, "店铺电话输入为空\n")
  129. elif Entry_master.get() == '': # 店主不能为空
  130. remove_prompt()
  131. Entry_prompt.insert(tkinter.INSERT, "店主输入为空\n")
  132. else:
  133. remove_prompt()
  134. cursor = conn.cursor() # 创建游标
  135. try:
  136. sql = 'insert into store values (%s,%s,%s,%s,%s,%s,%s);' # 添加数据
  137. cursor.execute(sql, (
  138. Entry_user.get(), #账号
  139. Entry_password.get(),#密码
  140. Entry_name.get(),#名称
  141. Entry_address.get(),#地址
  142. Entry_phon.get(),#电话
  143. Entry_master.get(),#店主
  144. 0 )#盈亏
  145. ) # 执行添加数据
  146. conn.commit() # 提交
  147. cursor.execute('select * from store where store_id="%s";'%(Entry_user.get()))
  148. conn.commit()
  149. Entry_prompt.insert(tkinter.INSERT, "店铺注册成功\n")
  150. Entry_prompt.insert(tkinter.INSERT, cursor.fetchall())
  151. except:
  152. Entry_prompt.insert(tkinter.INSERT, "店铺账号已存在,请从新输入:\n")
  153. cursor.close() # 关闭游
  154. root=tkinter.Toplevel() #创建一个附属窗口
  155. root.title("露露小卖店") #标题
  156. root.iconbitmap(LOGO_PATH) # 设置logo资源
  157. root.geometry('380x400+150+50') # 初始化窗口大小
  158. root.resizable(False, False) # 固定窗口大小
  159. tkinter.Button(root,text="确认添加",command=store_add,font=("微软雅黑", 10)).place(x=30,y=360)
  160. tkinter.Button(root, text="退出", command=root.destroy, font=("微软雅黑", 10)).place(x=320, y=360)
  161. #店铺账号 店铺密码 店铺名称 店铺地址 店铺电话 店主
  162. tkinter.Label(root,text="店铺账号",font=("微软雅黑", 10)).place(x=60,y=120)
  163. tkinter.Label(root, text="店铺密码", font=("微软雅黑", 10)).place(x=60, y=160)
  164. tkinter.Label(root, text="店铺名称", font=("微软雅黑", 10)).place(x=60, y=200)
  165. tkinter.Label(root, text="店铺地址", font=("微软雅黑", 10)).place(x=60, y=240)
  166. tkinter.Label(root, text="店铺电话", font=("微软雅黑", 10)).place(x=60, y=280)
  167. tkinter.Label(root, text="店 主", font=("微软雅黑", 10)).place(x=60, y=320)
  168. Entry_prompt = tkinter.Text(root, width=44,height=5,font=("微软雅黑", 10))
  169. Entry_prompt.place(x=12, y=10)
  170. Entry_user=tkinter.Entry(root,font=("微软雅黑", 10))
  171. Entry_user.place(x=120,y=120)
  172. Entry_password = tkinter.Entry(root, font=("微软雅黑", 10))
  173. Entry_password.place(x=120, y=160)
  174. Entry_name = tkinter.Entry(root, font=("微软雅黑", 10))
  175. Entry_name.place(x=120, y=200)
  176. Entry_address = tkinter.Entry(root, font=("微软雅黑", 10))
  177. Entry_address.place(x=120, y=240)
  178. Entry_phon = tkinter.Entry(root, font=("微软雅黑", 10))
  179. Entry_phon.place(x=120, y=280)
  180. Entry_master = tkinter.Entry(root, font=("微软雅黑", 10))
  181. Entry_master.place(x=120, y=320)
  182. remove_prompt()
  183. class The_store(MainForm):#主页面设置
  184. def __init__(self):
  185. super().__init__()
  186. self.Label=tkinter.Label(self.root,text="欢迎光临露露小卖店",bg='#233233',width=32,height=10,
  187. fg='#ffffff',font=("黑体",30))
  188. self.Label.place(x=20,y=0)
  189. self.button1 = tkinter.Button(self.root, text="初始化", command=self.Ininia, height=3, width=10).place(x=0,y=430)
  190. self.button2 = tkinter.Button(self.root, text="商品", command=self.Commodity_switch, height=3, width=10).place(x=150,y=430)
  191. self.button3 = tkinter.Button(self.root, text="店铺", command=self.Shop_switch, height=3, width=10).place(x=300,y=430)
  192. self.button4 = tkinter.Button(self.root, text="库房", command=self.Warehouse_switch, height=3, width=10).place(x=450,y=430)
  193. self.button1 = tkinter.Button(self.root, text="退出", command=quit, height=3, width=10).place(x=600,y=430)
  194. self.root.mainloop()
  195. def Commodity_switch(self): #商品
  196. self.root.destroy() #关闭主界面
  197. Commodity_From() #进入商品界面
  198. def Shop_switch(self): #店铺
  199. self.root.destroy() # 关闭主界面
  200. Shop_From()
  201. def Warehouse_switch(self): #库房
  202. self.root.destroy() # 关闭主界面
  203. Warehouse()
  204. def Ininia(self): #具体初始化
  205. self.Label.place_forget()
  206. text=tkinter.Text(self.root,width=80,height=20,font=('微软雅黑', 10))
  207. scroll = tkinter.Scrollbar()
  208. scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  209. text.place(x=20, y=20)
  210. scroll.config(command=text.yview)
  211. text.config(yscrollcommand=scroll.set)
  212. text.insert(tkinter.INSERT,"----------数据加载开始---------\n")
  213. INn=Initialize()
  214. def After_xx():
  215. for i in INn.Accord():
  216. text.insert(tkinter.INSERT,i)
  217. text.insert(tkinter.INSERT, '\n')
  218. text.insert(tkinter.END,"数据加载完毕")
  219. self.root.after(100,After_xx())
  220. class Initialize: #对数据库进行初始化
  221. def __init__(self):
  222. self.df_commodity=pd.read_excel(EXCEL_COMMODITY)
  223. self.df_warehouse = pd.read_excel(EXCEL_WAREHOUSE)
  224. self.df_customer = pd.read_excel(EXCEL_CUSTOMER)
  225. self.remove_all()
  226. self.all_refresh()
  227. def remove_all(self): #清除数据表数据
  228. cursor = conn.cursor() #创建游标
  229. cursor.execute('delete from commodity;') #清除商品数据
  230. cursor.execute('delete from warehouse;') #清除库房信息
  231. cursor.execute('delete from customer') #清除顾客信息
  232. conn.commit() #提交
  233. cursor.close() #关闭游标
  234. def all_refresh(self):
  235. def commodity_Add():#向商品commodity的表中导入数据'DW-1201090311','其它蔬菜',4,2,20210101,'2年',1,8
  236. global global_id
  237. cursor = conn.cursor() #创建游标
  238. for co in range(len(self.df_commodity["商品编码"])):
  239. try:
  240. sql = 'insert into commodity values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'#添加数据
  241. cursor.execute(sql, (
  242. self.df_commodity["商品编码"][co],
  243. self.df_commodity["商品名称"][co],
  244. self.df_commodity["商品售价"][co],
  245. self.df_commodity["商品进价"][co],
  246. self.df_commodity["生产日期"][co],
  247. self.df_commodity["保质期"][co],
  248. self.df_commodity["商品规格"][co],
  249. self.df_commodity["销售数量"][co],
  250. global_id,
  251. self.df_commodity["库房编号"][co],
  252. None)
  253. ) # 执行添加数据
  254. except:
  255. print(self.df_commodity["商品编码"][co])
  256. conn.commit() # 提交
  257. cursor.close() # 关闭游标
  258. def warehouse_Add():#向库房的表中导入数据'DW-1201090311','其它蔬菜',4,2,20210101,'2年',1,8
  259. global global_id
  260. cursor = conn.cursor() #创建游标
  261. for co in range(len(self.df_warehouse["库房编号"])):
  262. try:
  263. sql = 'insert into warehouse values (%s,%s,%s,%s,%s,%s,%s);'#添加数据
  264. cursor.execute(sql, (
  265. self.df_warehouse["库房编号"][co],
  266. self.df_warehouse["库房密码"][co],
  267. self.df_warehouse["库房名称"][co],
  268. self.df_warehouse["库房地址"][co],
  269. self.df_warehouse["库房电话"][co],
  270. self.df_warehouse["库房管理人"][co],
  271. global_id )
  272. ) # 执行添加数据
  273. except:
  274. print(self.df_warehouse["库房编号"][co])
  275. conn.commit() # 提交
  276. cursor.close() # 关闭游标
  277. def customer_Add():#向顾客的表中导入数据
  278. global global_id
  279. def go_shopping(): #查看购物情况
  280. sql=' select sum(commodity_amount) from commodity GROUP BY customer_id;'
  281. cursor.execute(sql)
  282. conn.commit()
  283. return cursor.fetchall()
  284. cursor = conn.cursor() # 创建游标
  285. for co in range(len(self.df_customer["用户账号"])):
  286. try:
  287. sql = 'insert into customer values (%s,%s,%s,%s,%s,%s);'#添加数据
  288. cursor.execute(sql, (
  289. self.df_customer["用户账号"][co],
  290. self.df_customer["密码"][co],
  291. self.df_customer["用户名"][co],
  292. self.df_customer["电话"][co],
  293. go_shopping(),
  294. global_id )
  295. ) # 执行添加数据
  296. except:
  297. print(self.df_customer["用户账号"][co])
  298. conn.commit() # 提交
  299. cursor.close() # 关闭游标
  300. commodity_Add()
  301. warehouse_Add()
  302. customer_Add()
  303. def Accord(self):
  304. cursor = conn.cursor() #创建游标
  305. a=[]
  306. for co1 in range(len(self.df_commodity["商品编码"])):
  307. try:
  308. sql='select * from commodity where commodity_id="%s"'%(self.df_commodity["商品编码"][co1])
  309. cursor.execute(sql)
  310. a.append(cursor.fetchall()) #结果导出
  311. except:
  312. continue
  313. for co2 in range(len(self.df_warehouse["库房编号"])):
  314. try:
  315. sql='select * from warehouse where warehouse_id="%s"'%(self.df_warehouse["库房编号"][co2])
  316. cursor.execute(sql)
  317. a.append(cursor.fetchall()) #结果导出
  318. except:
  319. continue
  320. for co in range(len(self.df_customer["用户账号"])):
  321. try:
  322. sql='select * from customer where customer_id="%s"'%(self.df_customer["用户账号"][co])
  323. cursor.execute(sql)
  324. a.append(cursor.fetchall()) #结果导出
  325. except:
  326. continue
  327. conn.commit() #提交
  328. cursor.close() #关闭游标
  329. return a
  330. class Commodity_From(MainForm): #商品界面设置
  331. def __init__(self):
  332. super().__init__()
  333. self.Commodity_select_photo()
  334. photo_word = tkinter.PhotoImage(file=WORDCLOUD_PATH)
  335. tkinter.Label(self.root, image=photo_word, width=600, height=400).place(x=30, y=0)
  336. tkinter.Label(self.root,text="------------你的年度销量---------",font=("微软雅黑", 20)).place(x=100,y=0)
  337. self.button1 = tkinter.Button(self.root, text="增加", command=self.Commodity_add_s, height=3, width=10).place(x=0, y=430)
  338. self.button2 = tkinter.Button(self.root, text="删除", command=self.Commodity_drop_s, height=3, width=10).place(x=150, y=430)
  339. self.button3 = tkinter.Button(self.root, text="修改", command=self.Commodity_delente_s, height=3, width=10).place(x=300, y=430)
  340. self.button4 = tkinter.Button(self.root, text="查询", command=self.Commodity_select_s, height=3, width=10).place(x=450, y=430)
  341. self.button1 = tkinter.Button(self.root, text="返回", command=self.The_store_power, height=3, width=10).place(x=600, y=430)
  342. self.root.mainloop()
  343. def Commodity_add_s(self):# 进入增加界面
  344. self.root.destroy() # 关闭商品界面
  345. Commodity_add() #进入增加界面
  346. def Commodity_drop_s(self):#进入删除界面
  347. self.root.destroy()
  348. Commodity_drop()
  349. def Commodity_delente_s(self): #进去修改界面
  350. self.root.destroy()
  351. Commodity_delente()
  352. def Commodity_select_s(self): #进入查询界面
  353. self.root.destroy()
  354. Commodity_select()
  355. def The_store_power(self): #进入主界面
  356. self.root.destroy()
  357. The_store()
  358. def Commodity_select_photo(self):#查询所有的商品信息commodity_name
  359. global global_id
  360. a=[]
  361. cursor=conn.cursor()
  362. sql='select commodity_name from commodity where store_id="%s"'%(global_id)
  363. cursor.execute(sql)
  364. conn.commit()
  365. cursor.close()
  366. for i in cursor.fetchall():
  367. a.append(i[0])
  368. self.worcloud_s(str(a)) #生成图片
  369. class Commodity_add(MainForm):# 商品类,,增删除,改,查
  370. def __init__(self):
  371. super().__init__()
  372. tkinter.Label(self.root,text="增加商品信息",font=("微软雅黑", 20)).place(x=260,y=0)
  373. tkinter.Label(self.root, text="商品编码", font=("微软雅黑", 10)).place(x=0,y=200)
  374. self.entryss1 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  375. self.entryss1.place(x=60,y=200)
  376. tkinter.Label(self.root, text="商品名称", font=("微软雅黑", 10)).place(x=200,y=200)
  377. self.entryss2 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  378. self.entryss2.place(x=260,y=200)
  379. self.Text_1 = tkinter.Text(self.root, height=6, width=80,font=("微软雅黑", 10)) #输出标注框
  380. self.Text_1.place(x=20,y=50)
  381. tkinter.Label(self.root, text="商品售价", font=("微软雅黑", 10)).place(x=0,y=270)
  382. self.entryss3 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  383. self.entryss3.place(x=60,y=270)
  384. tkinter.Label(self.root, text="商品进价", font=("微软雅黑", 10)).place(x=0,y=350)
  385. self.entryss4 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  386. self.entryss4.place(x=60,y=350)
  387. tkinter.Label(self.root, text="生产日期", font=("微软雅黑", 10)).place(x=200,y=270)
  388. self.entryss5 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  389. self.entryss5.place(x=260,y=270)
  390. tkinter.Label(self.root, text="保质期", font=("微软雅黑", 10)).place(x=200,y=350)
  391. self.entryss6 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  392. self.entryss6.place(x=260,y=350)
  393. tkinter.Label(self.root, text="商品规格", font=("微软雅黑", 10)).place(x=400,y=270)
  394. self.entryss7 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  395. self.entryss7.place(x=460,y=270)
  396. tkinter.Label(self.root, text="销售数量", font=("微软雅黑", 10)).place(x=400,y=350)
  397. self.entryss8 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  398. self.entryss8.place(x=460,y=350)
  399. tkinter.Label(self.root, text="仓库编号", font=("微软雅黑", 10)).place(x=400, y=200)
  400. self.entryss9 = tkinter.Entry(self.root, font=("微软雅黑", 10))
  401. self.entryss9.place(x=460, y=200)
  402. tkinter.Button(self.root,text="确认添加",command=self.add_s,font=("微软雅黑", 15)).place(x=200,y=420)
  403. tkinter.Button(self.root, text="取消 ", command=self.add_Cancel, font=("微软雅黑",15)).place(x=400,y=420)
  404. tkinter.Button(self.root, text="返回主菜单", command=self.The_store_1, font=("微软雅黑", 15)).place(x=0, y=450)
  405. tkinter.Button(self.root, text="返回 ", command=self.Commodity_From_1, font=("微软雅黑", 15)).place(x=600, y=450)
  406. self.root.mainloop()
  407. def The_store_1(self):#返回主菜单
  408. self.root.destroy()
  409. The_store()
  410. def Commodity_From_1(self): #返回商品菜单
  411. self.root.destroy()
  412. Commodity_From()
  413. def drop_Text_1(self):#清除显示信息
  414. self.Text_1.delete(0.0, tkinter.END)
  415. self.Text_1.update()
  416. def add_s(self): #处理增加
  417. global global_id
  418. cursor = conn.cursor() # 创建sql游标
  419. if self.entryss1.get() =='':
  420. self.drop_Text_1()
  421. self.Text_1.insert(tkinter.INSERT,"你的商品编码输入为空")
  422. elif self.entryss2.get() =='':
  423. self.drop_Text_1()
  424. self.Text_1.insert(tkinter.INSERT,"你的商品名称输入为空")
  425. elif self.entryss3.get() == '':
  426. self.drop_Text_1()
  427. self.Text_1.insert(tkinter.INSERT, "你的商品售价输入为空")
  428. elif self.entryss4.get() == '':
  429. self.drop_Text_1()
  430. self.Text_1.insert(tkinter.INSERT, "你的商品进价输入为空")
  431. elif self.entryss5.get() == '':
  432. self.drop_Text_1()
  433. self.Text_1.insert(tkinter.INSERT, "你的生产日期输入为空")
  434. elif self.entryss6.get() == '':
  435. self.drop_Text_1()
  436. self.Text_1.insert(tkinter.INSERT, "你的保质期输入为空")
  437. elif self.entryss7.get() == '':
  438. self.drop_Text_1()
  439. self.Text_1.insert(tkinter.INSERT, "你的商品规格输入为空")
  440. elif self.entryss8.get() == '':
  441. self.drop_Text_1()
  442. self.Text_1.insert(tkinter.INSERT, "你的销售数量输入为空")
  443. elif self.entryss9.get() == '':
  444. self.drop_Text_1()
  445. self.Text_1.insert(tkinter.INSERT, "你的仓库编号输入为空")
  446. else:
  447. try:
  448. sql = "insert into commodity values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" # 添加数据
  449. cursor.execute(sql,(
  450. self.entryss1.get(), #商品编号
  451. self.entryss2.get(), #商品名称
  452. self.entryss3.get(), #商品售价
  453. self.entryss4.get(), #商品进价
  454. self.entryss5.get(), #生产日期
  455. self.entryss6.get(), #保质期
  456. self.entryss7.get(), #商品规格
  457. self.entryss8.get(), #销售数量
  458. global_id, #店铺编号
  459. self.entryss9.get(), #库房编号
  460. None #顾客编号为空
  461. ))
  462. conn.commit() #提交
  463. cursor.execute('select * from commodity where commodity_id="%s"' % (self.entryss1.get()))
  464. conn.commit()
  465. cursor.close() #关闭游标
  466. self.drop_Text_1()
  467. self.Text_1.insert(tkinter.INSERT, "数据添加成功")
  468. self.Text_1.insert(tkinter.INSERT,cursor.fetchall())
  469. except:
  470. try:
  471. sql = 'select * from commodity where commodity_id="%s"' % (self.entryss1.get())
  472. cursor.execute(sql)
  473. conn.commit()
  474. self.drop_Text_1()
  475. self.Text_1.insert(tkinter.INSERT, "数据存在:")
  476. self.Text_1.insert(tkinter.INSERT, cursor.fetchall())
  477. cursor.close()
  478. except:
  479. self.drop_Text_1()
  480. self.Text_1.insert(tkinter.INSERT, "商品数据不符合类型,从新添加:")
  481. def add_Cancel(self): #取消输入的信息
  482. self.entryss1.delete(0, tkinter.END)
  483. self.entryss2.delete(0, tkinter.END)
  484. self.entryss3.delete(0, tkinter.END)
  485. self.entryss4.delete(0, tkinter.END)
  486. self.entryss5.delete(0, tkinter.END)
  487. self.entryss6.delete(0, tkinter.END)
  488. self.entryss7.delete(0, tkinter.END)
  489. self.entryss8.delete(0, tkinter.END)
  490. self.entryss9.delete(0, tkinter.END)
  491. self.Text_1.delete(0.0, tkinter.END)
  492. self.entryss1.update()
  493. self.entryss2.update()
  494. self.entryss3.update()
  495. self.entryss4.update()
  496. self.entryss5.update()
  497. self.entryss6.update()
  498. self.entryss7.update()
  499. self.entryss8.update()
  500. self.entryss9.update()
  501. self.Text_1.update()
  502. self.Text_1.insert(tkinter.INSERT,"请选择其他")
  503. #————————————————————————————店铺————————————————————————————————,
  504. class Commodity_drop(MainForm): #删除界面
  505. def __init__(self):
  506. super().__init__()
  507. self.Textw = tkinter.Text(self.root, height=18, width=80, font=("微软雅黑", 10))
  508. self.Textw.place(x=15, y=0)
  509. tkinter.Label(self.root,text="输入需要删除的商品编号或商品名称",font=("微软雅黑", 20)).place(x=100,y=350)
  510. self.Entry_1=tkinter.Entry(self.root,font=("微软雅黑", 20))
  511. self.Entry_1.place(x=20,y=400)
  512. tkinter.Button(self.root,text="查询",command=self.commodity_select_drop,font=("微软雅黑", 10)).place(x=380,y=400)
  513. tkinter.Button(self.root, text="返回", command=self.commodity_return, font=("微软雅黑", 10)).place(x=600, y=450)
  514. tkinter.Button(self.root, text="确定清除", command=self.commodity_confirm, font=("微软雅黑", 10)).place(x=450, y=400)
  515. tkinter.Button(self.root, text="取消清除", command=self.commodity_confirm, font=("微软雅黑", 10)).place(x=550, y=400)
  516. self.commodity_refersh() #显示提示页面
  517. self.commodity_select() #显示所有的商品信息
  518. self.root.mainloop()
  519. def commodity_return(self): #返回商品菜单
  520. self.root.destroy()
  521. Commodity_From()
  522. def commodity_confirm(self): #提示确认查询
  523. self.commodity_refersh()
  524. self.Textw.insert(tkinter.INSERT,"请先查询\n")
  525. self.commodity_select()
  526. def commodity_refersh(self): #刷新界面
  527. self.Textw.delete(0.0,tkinter.END)
  528. self.Textw.update()
  529. self.Textw.insert(tkinter.INSERT,
  530. "----------------------------------请输入你要删除的商品编号,或商品名称----------------------------------\n")
  531. def commodity_select(self): #查询所有的商品
  532. cursor = conn.cursor() # 创建sql游标
  533. sql = 'select * from commodity ' # 查询所有商品的信息
  534. cursor.execute(sql)
  535. self.Textw.insert(tkinter.INSERT, "你的商品信息为:\n")
  536. for fetchone in cursor.fetchall():
  537. self.Textw.insert(tkinter.INSERT, fetchone)
  538. self.Textw.insert(tkinter.INSERT, '\n')
  539. #——————————————————————————————————————————————————————删除页面————————————————————————————————————————————————————
  540. def commodity_select_drop(self): #查询需要删除的商品信息
  541. if self.Entry_1.get() == '':
  542. self.commodity_refersh()
  543. self.Textw.insert(tkinter.INSERT, "你的输入为空:\n")
  544. self.commodity_select()
  545. else:
  546. try:
  547. def selecte_id_look():
  548. cursor = conn.cursor() # 创建sql游标
  549. sql1 = 'select * from commodity where commodity_id="%s"' % (self.Entry_1.get()) # 查询需要删除的信息
  550. cursor.execute(sql1)
  551. conn.commit() # 提交
  552. cursor.close() # 关闭游标
  553. self.commodity_refersh()
  554. self.Textw.insert(tkinter.INSERT, "你输入的的商品编号查询的信息为:\n")
  555. return cursor.fetchall()
  556. def selecte_name_look():
  557. cursor = conn.cursor() # 创建sql游标
  558. sql2 = 'select * from commodity where commodity_name="%s"' % (self.Entry_1.get()) # 查询需要删除的信息
  559. cursor.execute(sql2)
  560. conn.commit() # 提交
  561. cursor.close() # 关闭游标
  562. self.commodity_refersh()
  563. self.Textw.insert(tkinter.INSERT, "你输入的的商品名称查询的信息为:\n")
  564. return cursor.fetchall()
  565. def button_id():
  566. tkinter.Button(self.root, text="确定清除", command=delete_id,
  567. font=("微软雅黑", 10)).place(x=450, y=400)
  568. tkinter.Button(self.root, text="取消清除", command=self.commodity_select, font=("微软雅黑", 10)).place(
  569. x=550, y=400)
  570. def button_name():
  571. tkinter.Button(self.root, text="确定清除", command=delete_name,
  572. font=("微软雅黑", 10)).place(x=450, y=400)
  573. tkinter.Button(self.root, text="取消清除", command=self.commodity_select, font=("微软雅黑", 10)).place(
  574. x=550, y=400)
  575. def delete_id():
  576. cursor = conn.cursor() # 创建sql游标
  577. sql = 'delete from commodity where commodity_id="%s"' % (self.Entry_1.get())
  578. cursor.execute(sql)
  579. conn.commit() # 提交
  580. cursor.close() # 关闭游标
  581. self.Textw.insert(tkinter.INSERT, "数据删除成功\n")
  582. def delete_name():
  583. cursor = conn.cursor() # 创建sql游标
  584. sql = 'delete from commodity where commodity_name="%s"' % (self.Entry_1.get())
  585. cursor.execute(sql)
  586. conn.commit() # 提交
  587. cursor.close() # 关闭游标
  588. self.Textw.insert(tkinter.INSERT, "数据删除成功\n")
  589. if bool(selecte_id_look())==True:
  590. for fetchone in selecte_id_look():
  591. self.Textw.insert(tkinter.INSERT, fetchone)
  592. self.Textw.insert(tkinter.INSERT, '\n')
  593. button_id()
  594. elif bool(selecte_name_look())==True:
  595. for fetchone in selecte_name_look():
  596. self.Textw.insert(tkinter.INSERT, fetchone)
  597. self.Textw.insert(tkinter.INSERT, '\n')
  598. button_name()
  599. else:
  600. self.commodity_refersh()
  601. self.Textw.insert(tkinter.INSERT, "你输入的的商品信息错误或没有此商品:\n")
  602. except:
  603. self.Textw.insert(tkinter.INSERT, "程序运行故障:\n")
  604. #_____________________________________修改页面————————————————————————————————————————————————————————————
  605. class Commodity_delente(MainForm): #修改
  606. def __init__(self):
  607. super().__init__()
  608. photo=tkinter.PhotoImage(file=COMMODITY_DELETE_PATH)
  609. tkinter.Label(self.root, image=photo, width=680, height=500).place(x=0, y=0)
  610. tkinter.Label(self.root,text="修改商品信息",font=("黑体",20)).place(x=250,y=0)
  611. tkinter.Label(self.root, text="所有商品信息", font=("微软雅黑", 10)).place(x=110, y=30)
  612. self.Text_select=tkinter.Text(self.root,width=40,height=13,font=("微软雅黑", 10)) #显示所有商品信息
  613. self.Text_select.place(x=10,y=50)
  614. tkinter.Label(self.root, text="修改商品信息", font=("微软雅黑", 10)).place(x=110, y=300) #显示查询和修改的商品信息
  615. self.Text_delete = tkinter.Text(self.root, width=40, height=8,font=("微软雅黑", 10))
  616. self.Text_delete.place(x=10, y=320)
  617. tkinter.Label(self.root, text="查询商品信息", font=("微软雅黑", 10)).place(x=500, y=30)
  618. tkinter.Label(self.root, text="输入商品编号:", font=("微软雅黑", 10)).place(x=350, y=50)
  619. self.Entry_id = tkinter.Entry(self.root,font=("微软雅黑", 10)) #输入商品编号
  620. self.Entry_id.place(x=450, y=50)
  621. tkinter.Button(self.root, text="查询",command=self.select_id_commodity, font=("微软雅黑", 7)).place(x=630, y=50)
  622. tkinter.Label(self.root, text="修改商品内容:", font=("微软雅黑", 10)).place(x=350, y=100)
  623. self.Entry_update = tkinter.Entry(self.root, font=("微软雅黑", 10)) #输入修改的商品信息
  624. self.Entry_update.place(x=450, y=100)
  625. tkinter.Button(self.root,text="商品名称",command=self.update_name,font=("微软雅黑",10)).place(x=450,y=150)
  626. tkinter.Button(self.root, text="商品售价", command=self.update_price, font=("微软雅黑", 10)).place(x=550, y=150)
  627. tkinter.Button(self.root, text="商品进价", command=self.update_pur_price, font=("微软雅黑", 10)).place(x=450, y=200)
  628. tkinter.Button(self.root, text="生产日期", command=self.update_production, font=("微软雅黑", 10)).place(x=550, y=200)
  629. tkinter.Button(self.root, text="保质期", command=self.update_life, font=("微软雅黑", 10)).place(x=450, y=250)
  630. tkinter.Button(self.root, text="商品规格", command=self.update_speci, font=("微软雅黑", 10)).place(x=550, y=250)
  631. tkinter.Button(self.root,text="库房编号",command=self.warehouse_id,font=("微软雅黑",10)).place(x=450,y=300)
  632. tkinter.Button(self.root, text="返回", command=self.commodity_return, font=("微软雅黑", 10)).place(x=600, y=450)
  633. self.selecte_Text_query() #跟新并查询商品信息
  634. self.root.mainloop()
  635. def commodity_return(self): #返回商品菜单
  636. self.root.destroy()
  637. Commodity_From()
  638. def selecte_Text_query(self): # 更新并查询商品信息
  639. self.Text_select.delete(0.0, tkinter.END)
  640. self.Text_select.update()
  641. try:
  642. cursor=conn.cursor()
  643. sql='select * from commodity '
  644. cursor.execute(sql)
  645. conn.commit()
  646. cursor.close()
  647. for i in cursor.fetchall():
  648. self.Text_select.insert(tkinter.INSERT,i)
  649. self.Text_select.insert(tkinter.INSERT,'\n')
  650. except:
  651. pass
  652. def delete_Text_query(self): #跟新输出显示框的信息
  653. self.Text_delete.delete(0.0,tkinter.END)
  654. self.Text_delete.update()
  655. self.Text_delete.insert(tkinter.INSERT,"你查询到的商品为:\n")
  656. def select_id_commodity(self): #根据id查询信息
  657. def commodity_select_id(): #查询商品信息
  658. def select_id():
  659. cursor = conn.cursor() # 创建sql游标
  660. sql = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  661. cursor.execute(sql)
  662. conn.commit() # 提交
  663. cursor.close() # 关闭游标
  664. return cursor.fetchall()
  665. if bool(select_id())==True:
  666. for i in select_id():
  667. self.Text_delete.insert(tkinter.INSERT, i)
  668. self.Text_delete.insert(tkinter.INSERT,'\n')
  669. else:
  670. self.Text_delete.insert(tkinter.INSERT,"没有该商品信息:\n")
  671. if self.Entry_id.get()=='':
  672. self.delete_Text_query()
  673. self.Text_delete.insert(tkinter.INSERT,"你的输入为空:\n请从新输入;\n")
  674. else:
  675. commodity_select_id()
  676. def update_name(self):
  677. self.delete_Text_query()
  678. try:
  679. cursor=conn.cursor()
  680. sql='update commodity set commodity_name="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  681. cursor.execute(sql)
  682. conn.commit()
  683. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  684. cursor.execute(sql2)
  685. conn.commit()
  686. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  687. cursor.close()
  688. self.Text_delete.insert(tkinter.INSERT, "\n你的商品名称修改成功;\n")
  689. except:
  690. pass
  691. def update_price(self):
  692. self.delete_Text_query()
  693. try:
  694. cursor=conn.cursor()
  695. sql='update commodity set commodity_price="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  696. cursor.execute(sql)
  697. conn.commit()
  698. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  699. cursor.execute(sql2)
  700. conn.commit()
  701. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  702. cursor.close()
  703. self.Text_delete.insert(tkinter.INSERT, "\n你的商品售价修改成功;\n")
  704. except:
  705. pass
  706. def update_pur_price(self):
  707. self.delete_Text_query()
  708. try:
  709. cursor=conn.cursor()
  710. sql='update commodity set commodity_pur_price="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  711. cursor.execute(sql)
  712. conn.commit()
  713. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  714. cursor.execute(sql2)
  715. conn.commit()
  716. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  717. cursor.close()
  718. self.Text_delete.insert(tkinter.INSERT, "\n你的商品进价修改成功;\n")
  719. except:
  720. pass
  721. def update_production(self):
  722. self.delete_Text_query()
  723. try:
  724. cursor=conn.cursor()
  725. sql='update commodity set commodity_production="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  726. cursor.execute(sql)
  727. conn.commit()
  728. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  729. cursor.execute(sql2)
  730. conn.commit()
  731. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  732. cursor.close()
  733. self.Text_delete.insert(tkinter.INSERT, "\n你的生产日期修改成功;\n")
  734. except:
  735. pass
  736. def update_life(self):
  737. self.delete_Text_query()
  738. try:
  739. cursor=conn.cursor()
  740. sql='update commodity set commodity_life="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  741. cursor.execute(sql)
  742. conn.commit()
  743. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  744. cursor.execute(sql2)
  745. conn.commit()
  746. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  747. cursor.close()
  748. self.Text_delete.insert(tkinter.INSERT, "\n你的保质期修改成功;\n")
  749. except:
  750. pass
  751. def update_speci(self):
  752. self.delete_Text_query()
  753. try:
  754. cursor=conn.cursor()
  755. sql='update commodity set commodity_speci="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  756. cursor.execute(sql)
  757. conn.commit()
  758. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  759. cursor.execute(sql2)
  760. conn.commit()
  761. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  762. cursor.close()
  763. self.Text_delete.insert(tkinter.INSERT, "\n你的商品规格修改成功;\n")
  764. except:
  765. pass
  766. def warehouse_id(self):
  767. self.delete_Text_query()
  768. try:
  769. cursor=conn.cursor()
  770. sql='update commodity set warehouse_id="%s" where commodity_id="%s"'%(self.Entry_update.get(),self.Entry_id.get())
  771. cursor.execute(sql)
  772. conn.commit()
  773. sql2 = 'select * from commodity where commodity_id="%s"' % (self.Entry_id.get())
  774. cursor.execute(sql2)
  775. conn.commit()
  776. self.Text_delete.insert(tkinter.INSERT,cursor.fetchall())
  777. cursor.close()
  778. self.Text_delete.insert(tkinter.INSERT, "\n你的库房修改成功;\n")
  779. except:
  780. pass
  781. class Commodity_select(MainForm) : #查询
  782. def __init__(self):
  783. super().__init__()
  784. tkinter.Label(self.root, text="查询商品信息", font=("黑体", 20)).place(x=250, y=0)
  785. tkinter.Label(self.root, text="所有商品信息", font=("微软雅黑", 10)).place(x=110, y=30)
  786. self.Text_select = tkinter.Text(self.root, width=40, height=13, font=("微软雅黑", 10)) # 显示所有商品信息
  787. self.Text_select.place(x=10, y=50)
  788. tkinter.Label(self.root, text="查询商品信息", font=("微软雅黑", 10)).place(x=500, y=30)
  789. #商品编号
  790. tkinter.Label(self.root, text="输入商品编号查询:", font=("微软雅黑", 10)).place(x=350, y=50)
  791. self.Entry_id = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 输入商品编号
  792. self.Entry_id.place(x=450, y=50)
  793. tkinter.Button(self.root, text="查询",command=self.selecte_id_commodity ,font=("微软雅黑", 7)).place(x=630, y=50)
  794. tkinter.Label(self.root, text="所有商品编号信息", font=("微软雅黑", 10)).place(x=100, y=300) # 显示查询和修改的商品信息
  795. self.Text_id = tkinter.Text(self.root, width=30, height=8, font=("微软雅黑", 10))
  796. self.Text_id.place(x=10, y=320)
  797. # 商品名称
  798. tkinter.Label(self.root, text="输入商品名称查询:", font=("微软雅黑", 10)).place(x=350, y=100)
  799. self.Entry_name = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 输入修改的商品信息
  800. self.Entry_name.place(x=450, y=100)
  801. tkinter.Button(self.root, text="查询",command=self.selecte_name_commodity, font=("微软雅黑", 7)).place(x=630, y=100)
  802. tkinter.Label(self.root, text="所有商品名称信息", font=("微软雅黑", 10)).place(x=300, y=300) # 显示查询和修改的商品信息
  803. self.Text_name = tkinter.Text(self.root, width=30, height=8, font=("微软雅黑", 10))
  804. self.Text_name.place(x=210, y=320)
  805. #商品库房名称
  806. tkinter.Label(self.root, text="输入库房名称查询:", font=("微软雅黑", 10)).place(x=350, y=150)
  807. self.Entry_warehouse = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 输入修改的商品信息
  808. self.Entry_warehouse.place(x=450, y=150)
  809. tkinter.Button(self.root, text="查询",command=self.selecte_warehouse_commodity, font=("微软雅黑", 7)).place(x=630, y=150)
  810. tkinter.Label(self.root, text="库房所有商品信息", font=("微软雅黑", 10)).place(x=500, y=300) # 显示查询和修改的商品信息
  811. self.Text_warehouse = tkinter.Text(self.root, width=30, height=8, font=("微软雅黑", 10))
  812. self.Text_warehouse.place(x=410, y=320)
  813. tkinter.Button(self.root, text="返回", command=self.commodity_return, font=("微软雅黑", 10)).place(x=600, y=450)
  814. self.selecte_Text_query() # 跟新并查询商品信息
  815. self.root.mainloop()
  816. def commodity_return(self): #返回商品界面
  817. self.root.destroy()
  818. Commodity_From()
  819. def selecte_Text_query(self): # 更新并查询商品信息
  820. self.Text_select.delete(0.0, tkinter.END)
  821. self.Text_select.update()
  822. try:
  823. cursor = conn.cursor()
  824. sql = 'select * from commodity '
  825. cursor.execute(sql)
  826. conn.commit()
  827. cursor.close()
  828. for i in cursor.fetchall():
  829. self.Text_select.insert(tkinter.INSERT, i)
  830. self.Text_select.insert(tkinter.INSERT, '\n')
  831. except:
  832. pass
  833. def selecte_id_commodity(self): #根据商品id查询商品信息
  834. def text_id_query(): #清空text里面的信息
  835. self.Text_id.delete(0.0,tkinter.END)
  836. self.Text_id.update()
  837. if self.Entry_warehouse.get()=='':
  838. text_id_query()
  839. self.Text_id.insert(tkinter.INSERT,"你输入的库房账号为空\n")
  840. else:
  841. text_id_query()
  842. def select_id():
  843. cursor=conn.cursor()
  844. sql='select * from commodity where warehouse_id="%s"'%(self.Entry_warehouse.get())
  845. cursor.execute(sql)
  846. conn.commit()
  847. cursor.close()
  848. return cursor.fetchall()
  849. if bool(select_id())==True:
  850. for i in select_id():
  851. self.Text_id.insert(tkinter.INSERT,i)
  852. self.Text_id.insert(tkinter.INSERT,'\n')
  853. else:
  854. self.Text_id.insert(tkinter.INSERT,"你输入的商品不在店铺\n")
  855. def selecte_name_commodity(self): #根据商品name查询商品信息
  856. def text_name_query(): #清空text里面的信息
  857. self.Text_name.delete(0.0,tkinter.END)
  858. self.Text_name.update()
  859. if self.Entry_name.get()=='':
  860. text_name_query()
  861. self.Text_name.insert(tkinter.INSERT,"你输入的商品名称为空\n")
  862. else:
  863. text_name_query()
  864. def select_name():
  865. cursor=conn.cursor()
  866. sql='select * from commodity where commodity_name="%s"'%(self.Entry_name.get())
  867. cursor.execute(sql)
  868. conn.commit()
  869. cursor.close()
  870. return cursor.fetchall()
  871. if bool(select_name())==True:
  872. for i in select_name():
  873. self.Text_name.insert(tkinter.INSERT,i)
  874. self.Text_name.insert(tkinter.INSERT,'\n')
  875. else:
  876. self.Text_name.insert(tkinter.INSERT,"你输入的商品名称查询不在店铺\n")
  877. def selecte_warehouse_commodity(self): #根据商品id查询商品信息
  878. def text_warehouse_query(): #清空text里面的信息
  879. self.Text_warehouse.delete(0.0,tkinter.END)
  880. self.Text_warehouse.update()
  881. if self.Entry_warehouse.get()=='':
  882. text_warehouse_query()
  883. self.Text_warehouse.insert(tkinter.INSERT,"你输入的库房为空\n")
  884. else:
  885. text_warehouse_query()
  886. def select_warehouse():
  887. cursor=conn.cursor()
  888. sql='select * from commodity where commodity_id="%s"'%(self.Entry_id.get())
  889. cursor.execute(sql)
  890. conn.commit()
  891. cursor.close()
  892. return cursor.fetchall()
  893. if bool(select_warehouse())==True:
  894. for i in select_warehouse():
  895. self.Text_warehouse.insert(tkinter.INSERT,i)
  896. self.Text_warehouse.insert(tkinter.INSERT,'\n')
  897. else:
  898. self.Text_warehouse.insert(tkinter.INSERT,"你输入的库房查询不在店铺\n")
  899. class Shop_From(MainForm): #店铺界面设置,店铺可以查询,修改,导出仓库信息全部商品
  900. def __init__(self):
  901. super().__init__()
  902. self.button1 = tkinter.Button(self.root, text="顾客", command=self.Customer, height=3, width=10).place(x=0, y=430)
  903. self.button2 = tkinter.Button(self.root, text="商品", command=self.Commodiyt_from_1, height=3, width=10).place(x=150, y=430)
  904. self.button3 = tkinter.Button(self.root, text="库房", command=self.Warehouse_1, height=3, width=10).place(x=300, y=430)
  905. self.button4 = tkinter.Button(self.root, text="导入导出", command=self.export_1, height=3, width=10).place(x=450, y=430)
  906. self.button1 = tkinter.Button(self.root, text="返回", command=self.The_store_1, height=3, width=10).place(x=600, y=430)
  907. self.root.mainloop()
  908. def Commodiyt_from_1(self):#进入商品界面
  909. self.root.destroy()
  910. Commodity_From()
  911. def The_store_1(self):#进入主界面
  912. self.root.destroy()
  913. The_store()
  914. def Warehouse_1(self): # 进入库房界面
  915. self.root.destroy()
  916. Warehouse()
  917. def export_1(self):#进入导出界面
  918. self.root.destroy()
  919. Shop_export()
  920. def Customer(self):# 顾客管理
  921. def remove_Text_purint(): #清空Customer_Text_purint数据
  922. Customer_Text_purint.delete(0.0, tkinter.END)
  923. Customer_Text_purint.update()
  924. def import_user(): #导出所有用户信息到Customer_Text中
  925. cursor = conn.cursor()
  926. sql = 'select * from customer'
  927. cursor.execute(sql)
  928. Customer_Text.delete(0.0, tkinter.END)
  929. Customer_Text.update()
  930. Customer_Text.insert(tkinter.INSERT, '你的所有商品信息\n')
  931. for x in cursor.fetchall():
  932. Customer_Text.insert(tkinter.INSERT,x)
  933. Customer_Text.insert(tkinter.INSERT, '\n')
  934. conn.commit()
  935. cursor.close()
  936. def query_user():# 查询用户信息
  937. cursor=conn.cursor()
  938. sql='select * from customer where customer_id="%s" and customer_password="%s"'%(Customer_Entry_user.get(),Customer_Entry_password.get())
  939. cursor.execute(sql)
  940. conn.commit()
  941. cursor.close()
  942. return cursor.fetchall()
  943. #....................修改用户名.........................
  944. def delete_user():# 修改用户信息
  945. def delete_user_od() : #修改
  946. cursor = conn.cursor()
  947. sql='update customer set customer_name="%s" where customer_id="%s"'%(Customer_Entry_name.get(),Customer_Entry_user.get())
  948. cursor.execute(sql)
  949. conn.commit()
  950. cursor.close()
  951. if Customer_Entry_user.get()=='':
  952. remove_Text_purint()
  953. Customer_Text_purint.insert(tkinter.INSERT, "用户名输入为空\n")
  954. elif Customer_Entry_password.get()=='':
  955. remove_Text_purint()
  956. Customer_Text_purint.insert(tkinter.INSERT, "密码输入为空\n")
  957. else:
  958. try:
  959. remove_Text_purint() #清空
  960. Customer_Text_purint.insert(tkinter.INSERT,'你原用户信息\n') # 提示信息
  961. Customer_Text_purint.insert(tkinter.INSERT, query_user()) #查询
  962. Customer_Text_purint.insert(tkinter.INSERT, "\n你修改后用户信息\n") # 查询
  963. delete_user_od() #进行修改
  964. Customer_Text_purint.insert(tkinter.INSERT, query_user()) # 在查询
  965. except:
  966. remove_Text_purint()
  967. Customer_Text_purint.insert(tkinter.INSERT, "用户修改失败\n")
  968. # ....................修改密码.........................
  969. def delete_password():#修改密码
  970. def delete_user_od() : #对密码修改
  971. cursor = conn.cursor()
  972. sql='update customer set customer_password="%s" where customer_id="%s"'%(Customer_Entry_password.get(),Customer_Entry_user.get())
  973. cursor.execute(sql)
  974. conn.commit()
  975. cursor.close()
  976. def query_user(): # 查询用户信息
  977. cursor = conn.cursor()
  978. sql = 'select * from customer where customer_id="%s"'% (
  979. Customer_Entry_user.get())
  980. cursor.execute(sql)
  981. conn.commit()
  982. cursor.close()
  983. return cursor.fetchall()
  984. if Customer_Entry_user.get()=='':
  985. remove_Text_purint()
  986. Customer_Text_purint.insert(tkinter.INSERT, "用户名输入为空\n")
  987. elif Customer_Entry_password.get()=='':
  988. remove_Text_purint()
  989. Customer_Text_purint.insert(tkinter.INSERT, "密码输入为空\n")
  990. else:
  991. try:
  992. remove_Text_purint() #清空
  993. Customer_Text_purint.insert(tkinter.INSERT,'你原用户信息\n') # 提示信息
  994. Customer_Text_purint.insert(tkinter.INSERT, query_user()) #查询
  995. Customer_Text_purint.insert(tkinter.INSERT, "\n你修改后的用户信息\n") # 查询
  996. delete_user_od() #进行修改
  997. Customer_Text_purint.insert(tkinter.INSERT, query_user()) # 在查询
  998. except:
  999. remove_Text_purint()
  1000. Customer_Text_purint.insert(tkinter.INSERT, "用户修改失败\n")
  1001. # ....................增加用户.........................
  1002. def add_user(): #增加用户
  1003. def delete_user_add() : #增加修改
  1004. cursor = conn.cursor()
  1005. sql='insert into customer values(%s,%s,%s,0)'%(Customer_Entry_user.get(),Customer_Entry_name.get(),Customer_Entry_password.get())
  1006. cursor.execute(sql)
  1007. conn.commit()
  1008. cursor.close()
  1009. def query_user(): # 查询用户信息
  1010. cursor = conn.cursor()
  1011. sql = 'select * from customer where customer_id="%s"'% (
  1012. Customer_Entry_user.get())
  1013. cursor.execute(sql)
  1014. conn.commit()
  1015. cursor.close()
  1016. return cursor.fetchall()
  1017. if Customer_Entry_user.get()=='':
  1018. remove_Text_purint()
  1019. Customer_Text_purint.insert(tkinter.INSERT, "用户名输入为空\n")
  1020. elif Customer_Entry_password.get()=='':
  1021. remove_Text_purint()
  1022. Customer_Text_purint.insert(tkinter.INSERT, "密码输入为空\n")
  1023. else:
  1024. try:
  1025. remove_Text_purint() #清空
  1026. Customer_Text_purint.insert(tkinter.INSERT, "你增加的用户信息\n") # 查询
  1027. delete_user_add() #进行修改
  1028. Customer_Text_purint.insert(tkinter.INSERT, query_user()) # 在查询
  1029. except:
  1030. remove_Text_purint()
  1031. Customer_Text_purint.insert(tkinter.INSERT, "用户已存在,用户添加失败\n")
  1032. Customer_Text_purint.insert(tkinter.INSERT, query_user()) # 在查询
  1033. # ....................删除用户.........................
  1034. def drop_user(): #删除用户
  1035. def delete_user_drop() : #删除修改
  1036. cursor = conn.cursor()
  1037. sql='delete from customer where customer_id="%s" and customer_password="%s"'%(Customer_Entry_user.get(),Customer_Entry_password.get())
  1038. cursor.execute(sql)
  1039. conn.commit()
  1040. cursor.close()
  1041. def query_user(): # 查询用户信息
  1042. cursor = conn.cursor()
  1043. sql = 'select * from customer where customer_id="%s"'% (
  1044. Customer_Entry_user.get())
  1045. cursor.execute(sql)
  1046. conn.commit()
  1047. cursor.close()
  1048. return cursor.fetchall()
  1049. if Customer_Entry_user.get()=='':
  1050. remove_Text_purint()
  1051. Customer_Text_purint.insert(tkinter.INSERT, "用户名输入为空\n")
  1052. elif Customer_Entry_password.get()=='':
  1053. remove_Text_purint()
  1054. Customer_Text_purint.insert(tkinter.INSERT, "密码输入为空\n")
  1055. else:
  1056. try:
  1057. remove_Text_purint() #清空
  1058. Customer_Text_purint.insert(tkinter.INSERT, "你删除的用户信息\n") # 查询
  1059. delete_user_drop() #删除
  1060. Customer_Text_purint.insert(tkinter.INSERT, query_user()) # 在查询
  1061. except:
  1062. remove_Text_purint()
  1063. Customer_Text_purint.insert(tkinter.INSERT, "用户输入不对,用户删除失败\n")
  1064. tkinter.Label(self.root, text="顾客信息", font=("黑体", 20)).place(x=260, y=0)
  1065. Customer_Text=tkinter.Text(self.root,width=50,height=20,font=("微软雅黑",10))
  1066. Customer_Text.place(x=0,y=30)
  1067. import_user()
  1068. tkinter.Label(self.root, text="用户信息修改", font=("黑体", 10)).place(x=500, y=10)
  1069. tkinter.Label(self.root, text="用户账号", font=("黑体", 10)).place(x=420, y=50)
  1070. tkinter.Label(self.root, text="密 码", font=("黑体", 10)).place(x=420, y=100)
  1071. tkinter.Label(self.root, text="用 户 名", font=("黑体", 10)).place(x=420, y=150)
  1072. tkinter.Label(self.root, text="电 话", font=("黑体", 10)).place(x=420, y=200)
  1073. Customer_Entry_user = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 显示框
  1074. Customer_Entry_user.place(x=500,y=50)
  1075. Customer_Entry_password = tkinter.Entry(self.root, font=("微软雅黑", 10),show='*') # 显示框
  1076. Customer_Entry_password.place(x=500,y=100)
  1077. Customer_Entry_name = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 显示框
  1078. Customer_Entry_name.place(x=500, y=150)
  1079. Customer_Entry_phon = tkinter.Entry(self.root, font=("微软雅黑", 10)) # 显示框
  1080. Customer_Entry_phon.place(x=500, y=200)
  1081. tkinter.Button(self.root,text="修改用户信息",command=delete_user,font=('微软雅黑',10)).place(x=420,y=250)
  1082. tkinter.Button(self.root, text="修改密码", command=delete_password, font=('微软雅黑', 10)).place(x=420, y=300)
  1083. tkinter.Button(self.root, text="添加用户", command=add_user, font=('微软雅黑', 10)).place(x=560, y=250)
  1084. tkinter.Button(self.root, text="删除用户", command='1111', font=('微软雅黑', 10)).place(x=560, y=300)
  1085. Customer_Text_purint=tkinter.Text(self.root,width=30,height=3,font=("微软雅黑",10))
  1086. Customer_Text_purint.place(x=420, y=350)
  1087. Customer_Text_purint.insert(tkinter.INSERT,"输入正确的账号密码可以修改用户名\n输入正确的账号可以修改密码\n"
  1088. "输入没有的账号,用户名,密码可以添加账号\n输入正确的账号,密码可以删除账号")
  1089. class Shop_export(MainForm):#导入导出
  1090. def __init__(self):
  1091. super().__init__()
  1092. tkinter.Label(self.root, text="导入导出顾客商品信息", font=("黑体", 20)).place(x=200, y=0)
  1093. self.prompt=tkinter.Text(self.root,width=55,height=5,font=("微软雅黑",15))
  1094. self.prompt.place(x=10,y=50)
  1095. #————————————————导入————————————————————————
  1096. tkinter.Label(self.root,text="输入导入的绝对地址:",font=("微软雅黑",15)).place(x=70,y=200)
  1097. self.leading_in=tkinter.Entry(self.root,font=("黑体",15))
  1098. self.leading_in.place(x=50,y=250)
  1099. tkinter.Button(self.root, text="导入顾客", command=self.leading_in_customer,font=("微软雅黑",15)).place(x=100, y=300)
  1100. tkinter.Button(self.root, text="导入商品", command=self.leading_in_commodity, font=("微软雅黑",15)).place(
  1101. x=100, y=350)
  1102. #————————————————导出————————————————
  1103. tkinter.Label(self.root, text="输入导出的绝对地址:", font=("微软雅黑", 15)).place(x=420, y=200)
  1104. self.leading_out = tkinter.Entry(self.root, font=("黑体", 15))
  1105. self.leading_out.place(x=400, y=250)
  1106. tkinter.Button(self.root, text="导出顾客", command=self.leading_out_customer, font=("微软雅黑",15)).place(x=450, y=300)
  1107. tkinter.Button(self.root, text="导出商品", command=self.leading_out_commodity,font=("微软雅黑",15)).place(
  1108. x=450, y=350)
  1109. tkinter.Button(self.root, text="查看顾客", command=self.look_customer, font=("微软雅黑", 15)).place(x=0, y=430)
  1110. tkinter.Button(self.root, text="查看商品", command=self.look_commodity, font=("微软雅黑", 15)).place(x=300, y=430)
  1111. tkinter.Button(self.root, text="返回商品", command=self.The_store_1,font=("微软雅黑",15)).place(x=600,y=430)
  1112. self.root.mainloop()
  1113. def The_store_1(self): #返回商品
  1114. self.root.destroy()
  1115. The_store()
  1116. def clean_prompt(self): #清除提示框
  1117. self.prompt.delete(0.0,tkinter.END)
  1118. self.prompt.update()
  1119. def look_customer(self): #查看顾客
  1120. cursor=conn.cursor()
  1121. cursor.execute("select * from customer")
  1122. conn.commit()
  1123. cursor.close()
  1124. self.clean_prompt()
  1125. for i in cursor.fetchall():
  1126. self.prompt.insert(tkinter.INSERT,i)
  1127. def look_commodity(self): #查看商品
  1128. cursor=conn.cursor()
  1129. cursor.execute("select * from commodity")
  1130. conn.commit()
  1131. cursor.close()
  1132. self.clean_prompt()
  1133. for i in cursor.fetchall():
  1134. self.prompt.insert(tkinter.INSERT,i)
  1135. def leading_in_customer(self): #导入顾客信息
  1136. global global_id
  1137. self.clean_prompt()
  1138. address=self.leading_in.get()
  1139. df_customer=pd.read_excel(address)
  1140. def go_shopping(): # 查看购物情况
  1141. sql = ' select sum(commodity_amount) from commodity GROUP BY customer_id;'
  1142. cursor.execute(sql)
  1143. conn.commit()
  1144. return cursor.fetchone()
  1145. cursor = conn.cursor() # 创建游标
  1146. try:
  1147. for co in range(len(df_customer["用户账号"])):
  1148. try:
  1149. sql = 'insert into customer values (%s,%s,%s,%s,%s,%s);' # 添加数据
  1150. cursor.execute(sql, (
  1151. df_customer["用户账号"][co],
  1152. df_customer["密码"][co],
  1153. df_customer["用户名"][co],
  1154. df_customer["电话"][co],
  1155. go_shopping(),
  1156. global_id)
  1157. ) # 执行添加数据
  1158. conn.commit() # 提交
  1159. except:
  1160. self.prompt.insert(tkinter.INSERT,"你的用户账号已导入\n")
  1161. self.prompt.insert(tkinter.INSERT,df_customer["用户账号"][co])
  1162. self.prompt.insert(tkinter.INSERT, "\n")
  1163. except:
  1164. self.prompt.insert(tkinter.INSERT, "错误:你导入的信息不符合导入格式\n")
  1165. cursor.close() # 关闭游标
  1166. def leading_in_commodity(self): #导入顾客信息
  1167. global global_id
  1168. self.clean_prompt()
  1169. address = self.leading_in.get()
  1170. df_commodity = pd.read_excel(address)
  1171. cursor = conn.cursor() # 创建游标
  1172. try:
  1173. for co in range(len(df_commodity["商品编码"])):
  1174. try:
  1175. sql = 'insert into commodity values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);' # 添加数据
  1176. cursor.execute(sql, (
  1177. df_commodity["商品编码"][co],
  1178. df_commodity["商品名称"][co],
  1179. df_commodity["商品售价"][co],
  1180. df_commodity["商品进价"][co],
  1181. df_commodity["生产日期"][co],
  1182. df_commodity["保质期"][co],
  1183. df_commodity["商品规格"][co],
  1184. df_commodity["销售数量"][co],
  1185. global_id,
  1186. df_commodity["库房编号"][co],
  1187. df_commodity["顾客编号"][co])
  1188. ) # 执行添加数据
  1189. conn.commit() # 提交
  1190. except:
  1191. self.prompt.insert(tkinter.INSERT, "你的商品账号已导入\n")
  1192. self.prompt.insert(tkinter.INSERT, df_commodity["商品编码"][co])
  1193. self.prompt.insert(tkinter.INSERT, "\n")
  1194. except:
  1195. self.prompt.insert(tkinter.INSERT, "错误:你导入的信息不符合导入格式\n")
  1196. cursor.close() # 关闭游标
  1197. def leading_out_customer(self): #导出顾客
  1198. def select_():
  1199. cursor = conn.cursor()
  1200. cursor.execute("select * from customer")
  1201. conn.commit()
  1202. cursor.close()
  1203. return cursor.fetchall()
  1204. b=['顾客帐号','顾客密码','顾客名称','顾客电话','消费情况','店铺帐号']
  1205. c=self.leading_out.get()
  1206. df=pd.DataFrame(select_(),columns=b)
  1207. try:
  1208. df.to_excel(c,index=0)
  1209. except:
  1210. self.prompt.insert(tkinter.INSERT,"地址格式错误:")
  1211. def leading_out_commodity(self): #导出顾客
  1212. def select_commoidty():
  1213. cursor = conn.cursor()
  1214. cursor.execute("select * from commodity")
  1215. conn.commit()
  1216. cursor.close()
  1217. return cursor.fetchall()
  1218. b=['商品编号','商品名称','商品售价','商品进价','生产日期','保质期','商品规格','销售数量','店铺编号','库房编号','顾客编号']
  1219. c=self.leading_out.get()
  1220. df=pd.DataFrame(select_commoidty(),columns=b)
  1221. try:
  1222. df.to_excel(c,index=0)
  1223. except:
  1224. self.prompt.insert(tkinter.INSERT,"地址格式错误:")
  1225. class Warehouse(MainForm):#库房
  1226. def __init__(self):
  1227. super().__init__()
  1228. tkinter.Label(self.root, text="库房", font=("黑体", 20)).place(x=300, y=0)
  1229. #库房统计查询
  1230. tkinter.Button(self.root, text="库存情况", command=self.Warehouse_situation, height=3, width=10).place(x=0, y=430)
  1231. tkinter.Button(self.root, text="库存导出", command=self.leading_out_warehouse, height=3, width=10).place(x=300, y=430)
  1232. tkinter.Button(self.root, text="返回菜单", command=self.The_store_1, height=3, width=10).place(x=600, y=430)
  1233. self.root.mainloop()
  1234. def The_store_1(self): #返回菜单
  1235. self.root.destroy()
  1236. The_store()
  1237. def Warehouse_situation(self): #库存情况
  1238. tkinter.Label(self.root, text="店铺帐号:", font=("微软雅黑", 15)).place(x=100,y=200)
  1239. self.entry_warehouse = tkinter.Entry(self.root, font=("微软雅黑", 15))
  1240. self.entry_warehouse.place(x=250, y=200)
  1241. tkinter.Label(self.root, text="店铺密码:", font=("微软雅黑", 15)).place(x=100, y=250)
  1242. self.entry_password = tkinter.Entry(self.root, font=("微软雅黑", 15))
  1243. self.entry_password.place(x=250, y=250)
  1244. tkinter.Button(self.root, text="查询", command=self.Warehouse_confirm,font=("微软雅黑", 10)).place(x=600, y=200)
  1245. self.Text_warehouse=tkinter.Text(self.root,width=80,height=7,font=("微软雅黑", 10))
  1246. self.Text_warehouse.place(x=12,y=30)
  1247. tkinter.Label(self.root, text="导出地址:", font=("微软雅黑", 15)).place(x=100, y=300)
  1248. self.leading_warehouse_Entry = tkinter.Entry(self.root, font=("微软雅黑", 15))
  1249. self.leading_warehouse_Entry.place(x=250, y=300)
  1250. def remove_Text_warehouse(self):
  1251. self.Text_warehouse.delete(0.0,tkinter.END)
  1252. self.Text_warehouse.update()
  1253. def Warehouse_confirm(self): #执行查询结果
  1254. self.remove_Text_warehouse()
  1255. def selecte_warehouse():
  1256. try:
  1257. cursor = conn.cursor()
  1258. sql=' select commodity_name,count(*),warehouse_id from commodity GROUP BY commodity_name having ' \
  1259. 'warehouse_id=(select warehouse_id from warehouse where warehouse_id="%s"' \
  1260. ' and warehouse_password="%s")'%(self.entry_warehouse.get(),self.entry_password.get())
  1261. cursor.execute(sql)
  1262. conn.commit()
  1263. cursor.close()
  1264. self.remove_Text_warehouse()
  1265. return cursor.fetchall()
  1266. except:
  1267. pass
  1268. if bool(selecte_warehouse())==True:
  1269. self.Text_warehouse.insert(tkinter.INSERT, "商品名称,库存,库房号:\n")
  1270. for i in selecte_warehouse():
  1271. self.Text_warehouse.insert(tkinter.INSERT,i)
  1272. self.Text_warehouse.insert(tkinter.INSERT,'\n')
  1273. else:
  1274. self.Text_warehouse.insert(tkinter.INSERT,"库房账号,或密码输入不对\n")
  1275. def leading_out_warehouse(self): #导出库存
  1276. self.remove_Text_warehouse()
  1277. try:
  1278. def selecte_warehouse():
  1279. cursor = conn.cursor()
  1280. sql = 'select commodity_name,count(*),warehouse_id from commodity group by commodity_name having warehouse_id="%s"'%(self.entry_warehouse.get())
  1281. cursor.execute(sql)
  1282. conn.commit()
  1283. cursor.close()
  1284. return cursor.fetchall()
  1285. if bool(selecte_warehouse())==True:
  1286. df=pd.DataFrame(selecte_warehouse(),columns=["商品名称","剩余数量","库房名称"])
  1287. df.to_excel(self.leading_warehouse_Entry.get(),index=0)
  1288. self.Text_warehouse.insert(tkinter.INSERT, "库存导出成功\n")
  1289. else:self.Text_warehouse.insert(tkinter.INSERT,"请先查库存\n")
  1290. except:
  1291. self.Text_warehouse.insert(tkinter.INSERT,"程序运行错误:\n")
  1292. if __name__=="__main__":
  1293. conn=pymysql.connect( #连接MySQL
  1294. host='localhost', #本地服务器
  1295. port=3306, #服务器端口
  1296. user='root', #用户名
  1297. password='123456',
  1298. db='cpsim',
  1299. charset='utf8'
  1300. )
  1301. global_id = 0
  1302. The_login()
  1303. conn.close()