当前位置:   article > 正文

数据库课程设计:物流信息管理系统(PyCharm+MySQL)_物流管理数据库实训

物流管理数据库实训

目录

1.创建数据库表

2.ER图

3.实现功能简述

4.部分功能页面展示

 5.python代码 

6.不足说明


1.创建数据库表

系统主要的处理对象有:订单信息、寄件人信息、收件人信息、配送员信息。具体数据类型设置如下:

寄件人表:姓名、身份证号、地址、性别、电话号码。

收件人表:姓名、身份证号、地址、性别、电话号码。

配送员表:姓名、工号、身份证号、性别、电话号码。

订单表:订单编号、运输时间、物流站、快递员、寄件人、收件人、商品、价格。

2.ER图

3.实现功能简述

该系统主要分为两个模块,分别面对管理员及游客这两类应用人员,管理员具有对数据进行增删查改操作的最高权限;游客仅被赋予了查询订单权限,不可以对数据进行增删改操作。

管理员进入正式操作窗口之前需要进行身份验证,当且仅当输入已有账号及对应密码后(此处需要提前在库中添加一个管理员表(manger),表中有账户名称和账户密码两个元素)才能进入实际操作页面,游客只需点击首页游客登录按钮即可进入查询页面进行查询操作。

该系统利用python代码实现,总共分为八个部分,分别是系统开始首页面、管理员登录页面、管理员注册页面、管理员信息选择操作页面、人员信息操作选择页面、收件人/寄件人/配送员信息操作页面、订单信息操作页面以及游客订单查询页面。

本系统页面显示主要由tkinter库完成,系统页面的背景插入主要由PIL库实现,PyCharm连接MySQL Workbench实现数据库sql语句的应用及对数据的相关管理工作。

4.部分功能页面展示

首页:

 管理员登录页面:

 管理员注册页面:

 收件人/寄件人/配送员信息操作页面,三个页面结构相同,以下只展示第一个页面:

 订单信息操作页面:

 游客操作页面:

 5.python代码 

  1. import pymysql
  2. from tkinter import *
  3. from tkinter.messagebox import *
  4. from tkinter import ttk
  5. import tkinter as tk
  6. import tkinter.font as tkFont
  7. from PIL import Image,ImageTk
  8. def delButton(tree):
  9. x = tree.get_children()
  10. for item in x:
  11. tree.delete(item)
  12. def back(root):
  13. root.destroy()
  14. StartPage()
  15. image1=None
  16. img1=None
  17. #(1)物流信息管理系统
  18. def StartPage():
  19. global image1
  20. global img1
  21. root=tk.Tk()
  22. root.title('物流信息管理系统')
  23. root.geometry('490x650+500+100')
  24. root['background']='white'
  25. image1 = Image.open('1.png')
  26. img1 = ImageTk.PhotoImage(image1)
  27. Label(root,image=img1).pack()#place(relx=0,rely=0)
  28. Button(root, text="管理员登录", font=tkFont.Font(size=16), command=lambda: Login(root), width=25,
  29. height=2, fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.21,rely=0.45)
  30. Button(root, text="游客登录", font=tkFont.Font(size=16), command=lambda:GuestPage(root), width=25,
  31. height=2, fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.21,rely=0.6)
  32. Button(root, text='退出系统', height=2, font=tkFont.Font(size=16), width=25, command=root.destroy,
  33. fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.21,rely=0.75)
  34. root.mainloop()
  35. image2=None
  36. img2=None
  37. #(2)管理员登录页面
  38. def Login(root):
  39. global image2
  40. global img2
  41. root.destroy()
  42. root= tk.Tk()
  43. root.title('管理员登录页面')
  44. root.geometry('1200x700+200+50')
  45. root['background']='white'
  46. image2 = Image.open('6.png')
  47. img2 = ImageTk.PhotoImage(image2)
  48. Label(root,image=img2).pack()
  49. Label(root, text='账号:',font=("楷体", 15),bg='white').place(relx=0.4,rely=0.35)
  50. Label(root, text='密码:',font=("楷体", 15),bg='white').place(relx=0.4,rely=0.45)
  51. username=StringVar()
  52. pwd=StringVar()
  53. entry_username=Entry(root,textvariable=username, show=None)
  54. entry_username.place(relx=0.45, rely=0.35, relwidth=0.2,relheight=0.039)
  55. entry_pwd = Entry(root, textvariable=pwd, show='*')
  56. entry_pwd.place(relx=0.45, rely=0.45, relwidth=0.2,relheight=0.039)
  57. Button(root, text="登录", width=15, font=tkFont.Font(size=15), command=lambda:sign_in(root, entry_username, entry_pwd),fg='black', activebackground='black', activeforeground='white').place(relx=0.47,rely=0.57)
  58. Button(root, text="注册", width=15, font=tkFont.Font(size=15),command=lambda:register_Page(root),fg='black',activebackground='black', activeforeground='white').place(relx=0.47,rely=0.65)
  59. root.protocol('WM_DELETE_WINDOW', lambda:back(root))
  60. root.mainloop()
  61. #(2.1)
  62. def sign_in(root, entry_username, entry_pwd):
  63. db = pymysql.connect(host="localhost", user="root",\
  64. password="root", db="fu_logistics", port=3306)
  65. cur = db.cursor()
  66. sql="select * from manger where username='%s'"%(entry_username.get())
  67. try:
  68. cur.execute(sql)
  69. result = cur.fetchone()
  70. mima=result[1]
  71. except:
  72. showinfo(title='提示', message='账号/密码错误!')
  73. cur.close()
  74. db.close()
  75. if mima==entry_pwd.get():
  76. MangerChoosePage(root)
  77. else:
  78. showinfo(title='提示', message='账号/密码错误!')
  79. image8=None
  80. img8=None
  81. #(3)管理员注册页面
  82. def register_Page(root):
  83. global image8
  84. global img8
  85. root.destroy()
  86. root=Tk()
  87. root.title('管理员注册页面')
  88. root.geometry('1200x700+200+50')
  89. root['background']='white'
  90. image8 = Image.open('7.png')
  91. img8 = ImageTk.PhotoImage(image8)
  92. Label(root,image=img8).pack()
  93. Label(root, text='输入账号:',font=("楷体", 15),bg='white').place(relx=0.4,rely=0.35)
  94. Label(root, text='输入密码:',font=("楷体", 15),bg='white').place(relx=0.4,rely=0.45)
  95. Label(root, text='确认密码:',font=("楷体", 15),bg='white').place(relx=0.4,rely=0.55)
  96. username=StringVar()
  97. pwd=StringVar()
  98. sure_pwd=StringVar()
  99. entry_username=Entry(root,textvariable=username, show=None)
  100. entry_username.place(relx=0.495, rely=0.35, relwidth=0.2,relheight=0.039)
  101. entry_pwd = Entry(root, textvariable=pwd, show='*')
  102. entry_pwd.place(relx=0.495, rely=0.45, relwidth=0.2,relheight=0.039)
  103. entry_sure_pwd = Entry(root, textvariable=sure_pwd, show='*')
  104. entry_sure_pwd.place(relx=0.495, rely=0.55, relwidth=0.2,relheight=0.039)
  105. Button(root, text="注册", width=15, font=tkFont.Font(size=15),command=lambda:register(root,entry_username,entry_pwd,entry_sure_pwd),fg='black',activebackground='black', activeforeground='white').place(relx=0.47,rely=0.65)
  106. Button(root, text="退出", width=15, font=tkFont.Font(size=15),command=lambda:Login(root),fg='black',activebackground='black', activeforeground='white').place(relx=0.47,rely=0.75)
  107. root.protocol('WM_DELETE_WINDOW', lambda:Login(root))
  108. root.mainloop()
  109. #(3.1)
  110. def register(root,entry_username,entry_pwd,entry_sure_pwd):
  111. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  112. cur = db.cursor()
  113. sql="insert into manger values('%s','%s')"% (entry_username.get(),entry_pwd.get())
  114. cur.execute("select * from manger where username='%s'"%(entry_username.get()))
  115. result = cur.fetchall()
  116. if result:
  117. showinfo('提示','该账号已存在,请重新输入!')
  118. else:
  119. if len(entry_pwd.get())==6:
  120. if entry_sure_pwd.get()==entry_pwd.get():
  121. cur.execute(sql)
  122. db.commit()
  123. showinfo('提示','注册成功!')
  124. Login(root)
  125. else:
  126. showinfo('提示','两次输入密码不相同,请重新输入!')
  127. else:
  128. showinfo("提示","请输入六位数密码!")
  129. cur.close()
  130. db.close()
  131. image3 = None
  132. img3 = None
  133. # (4)管理员信息选择操作页面
  134. def MangerChoosePage(root):
  135. global image3
  136. global img3
  137. root.destroy()
  138. root = Tk()
  139. root.title('管理员信息选择操作页面')
  140. root.geometry('600x750+500+40') # ('950x700')
  141. root['background'] = 'white'
  142. image3 = Image.open('8.png')
  143. img3 = ImageTk.PhotoImage(image3)
  144. Label(root, image=img3).pack()
  145. Button(root, text="人员信息操作", font=tkFont.Font(size=16), command=lambda: Manger_user_Page(root), width=25,
  146. height=2, fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.22,
  147. rely=0.3)
  148. Button(root, text="订单信息操作", font=tkFont.Font(size=16), command=lambda: MangerPage(root), width=25,
  149. height=2, fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.22,
  150. rely=0.5)
  151. Button(root, text='退出', height=2, font=tkFont.Font(size=16), width=25, command=lambda: back(root),
  152. fg='black', bg='gainsboro', activebackground='black', activeforeground='white').place(relx=0.22, rely=0.7)
  153. root.protocol('WM_DELETE_WINDOW', lambda: back(root))
  154. root.mainloop()
  155. image4=None
  156. img4=None
  157. #(5)人员信息操作页面
  158. def Manger_user_Page(root):
  159. global image4
  160. global img4
  161. root.destroy()
  162. root = Tk()
  163. root.geometry('565x600+500+80')
  164. root.title('人员信息操作页面')
  165. root['background']='white'
  166. image4 = Image.open('4.png')
  167. img4 = ImageTk.PhotoImage(image4)
  168. Label(root,image=img4).pack()
  169. Button(root, text="收件人信息操作",activebackground='gainsboro',font=('楷体',15), command=lambda: Uers_infor_Page(root=root,table='recipient')).place(relx=0.27, rely=0.4, width=250)
  170. Button(root, text="寄件人信息操作",activebackground='gainsboro',font=('楷体',15), command=lambda: Uers_infor_Page(root=root,table='sender')).place(relx=0.27, rely=0.52, width=250)
  171. Button(root, text="配送员信息操作", activebackground='gainsboro',font=('楷体',15), command=lambda: Uers_infor_Page(root=root,table='distributor')).place(relx=0.27, rely=0.64, width=250)
  172. Button(root, text="退出", activebackground='gainsboro',font=('楷体',15), command=lambda:MangerChoosePage(root)).place(relx=0.27, rely=0.76, width=250)
  173. root.protocol('WM_DELETE_WINDOW', lambda:MangerChoosePage(root))
  174. root.mainloop()
  175. image6=None
  176. img6=None
  177. #(6)收件人、寄件人、配送员信息操作页面
  178. def Uers_infor_Page(root,table):
  179. global image6
  180. global img6
  181. root.destroy()
  182. root=Tk()
  183. root.geometry('900x700+300+50')
  184. if table=='recipient':
  185. Title='收件人'+'信息操作页面'
  186. temp1='身份证号'
  187. temp2='地址'
  188. elif table=='distributor':
  189. Title='配送员'+'信息操作页面'
  190. temp1= '工号'
  191. temp2='身份证号'
  192. else:
  193. Title='寄件人'+'信息操作页面'
  194. temp1= '身份证号'
  195. temp2='地址'
  196. root.title(Title)
  197. root['background']='floralwhite'
  198. image6 = Image.open('3.jpeg')
  199. img6 = ImageTk.PhotoImage(image6)
  200. Label(root,text=Title,compound='bottom',image=img6,font=('楷体',30),fg='blue',bg='floralwhite').pack()
  201. Label(root, text="姓名:").place(relx=0.02, rely=0.08, relwidth=0.1)
  202. Label(root, text=temp1+':').place(relx=0.5, rely=0.08, relwidth=0.1)
  203. Label(root, text=temp2+':').place(relx=0.02, rely=0.14, relwidth=0.1)
  204. Label(root, text="性别:").place(relx=0.5, rely=0.14, relwidth=0.1)
  205. Label(root, text="电话号码:").place(relx=0.02, rely=0.2, relwidth=0.1)
  206. name = StringVar()
  207. ID = StringVar()
  208. address = StringVar()
  209. sex = StringVar()
  210. phonenumber = StringVar()
  211. entry_name = Entry(root, textvariable=name )
  212. entry_name.place(relx=0.12, rely=0.08, relwidth=0.3, height=25)
  213. entry_ID = Entry(root, textvariable=ID)
  214. entry_ID.place(relx=0.6, rely=0.08, relwidth=0.3, height=25)
  215. entry_address = Entry(root, textvariable=address)
  216. entry_address.place(relx=0.12, rely=0.14, relwidth=0.3, height=25)
  217. entry_sex = Entry(root, textvariable=sex)
  218. entry_sex.place(relx=0.6, rely=0.14, relwidth=0.3, height=25)
  219. entry_phonenumber = Entry(root, textvariable=phonenumber)
  220. entry_phonenumber.place(relx=0.12, rely=0.2, relwidth=0.3, height=25)
  221. list1=[entry_name,entry_ID,entry_address,entry_sex,entry_phonenumber]
  222. Tree1 = ttk.Treeview(root, show='headings',column=('name','ID','address','sex','phonenumber'))
  223. Tree1.column('name', width=50, anchor="center")
  224. Tree1.column('ID', width=70, anchor="center")
  225. Tree1.column('address', width=40, anchor="center")
  226. Tree1.column('sex', width=70, anchor="center")
  227. Tree1.column('phonenumber', width=70, anchor="center")
  228. # 表格标题设置
  229. Tree1.heading('name', text='姓名')
  230. Tree1.heading('ID', text=temp1)
  231. Tree1.heading('address', text=temp2)
  232. Tree1.heading('sex', text='性别')
  233. Tree1.heading('phonenumber', text='电话号码')
  234. Tree1.place(relx=0.01,rely=0.5, relwidth=0.98)
  235. def treeviewClick(event):
  236. item = Tree1.selection()[0]
  237. item_text = Tree1.item(item, "values")
  238. entry_name.delete(0, 'end')
  239. entry_ID.delete(0, 'end')
  240. entry_address.delete(0, 'end')
  241. entry_sex.delete(0, 'end')
  242. entry_phonenumber.delete(0, 'end')
  243. entry_name.insert(0, item_text[0])
  244. entry_ID.insert(0, item_text[1])
  245. entry_address.insert(0, item_text[2])
  246. entry_sex.insert(0, item_text[3])
  247. entry_phonenumber.insert(0, item_text[4])
  248. Button(root, text="显示所有人员信息", command=lambda: showAll_user_Info(tree=Tree1,table=table)).place(relx=0.12, rely=0.3, width=120)
  249. Button(root, text="增加人员信息", command=lambda: append_user_Info(tree=Tree1, list=list1,table=table)).place(relx=0.32, rely=0.3,width=120)
  250. Button(root, text="删除人员信息", command=lambda: delete_user_Info(tree=Tree1,table=table)).place(relx=0.52, rely=0.3, width=120)
  251. Button(root, text="更改人员信息", command=lambda: update_user_Info(tree=Tree1, list=list1,table=table)).place(relx=0.72, rely=0.3,width=120)
  252. Button(root, text="根据姓名查找", command=lambda: find_use_Info(tree=Tree1,table=table,entry=entry_name,flag='name')).place(relx=0.02, rely=0.38,width=135)
  253. Button(root, text="根据"+temp1+"查找", command=lambda: find_use_Info(tree=Tree1,table=table,entry=entry_ID,flag='ID')).place(relx=0.22, rely=0.38,width=135)
  254. Button(root, text="根据"+temp2+"查找", command=lambda: find_use_Info(tree=Tree1,table=table,entry=entry_address,flag='address')).place(relx=0.42, rely=0.38,width=135)
  255. Button(root, text="根据性别查找", command=lambda: find_use_Info(tree=Tree1,table=table,entry=entry_sex,flag='sex')).place(relx=0.62, rely=0.38,width=135)
  256. Button(root, text="根据电话号码查找", command=lambda: find_use_Info(tree=Tree1,table=table,entry=entry_phonenumber,flag="phonenumber")).place(relx=0.82, rely=0.38,width=135)
  257. Tree1.bind('<ButtonRelease-1>', treeviewClick)
  258. root.protocol('WM_DELETE_WINDOW', lambda:Manger_user_Page(root))
  259. root.mainloop()
  260. #(6.1)
  261. def showAll_user_Info(tree,table):
  262. delButton(tree)
  263. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  264. cur = db.cursor() #用db操作游标
  265. if table=='recipient':
  266. sql="select * from recipient"
  267. elif table=='sender':
  268. sql="select * from sender"
  269. else:
  270. sql="select * from distributor"
  271. cur.execute(sql) # 执行sql语句
  272. #fetchone()返回一条记录(元组),没有结果则返回none
  273. #fetchall()返回所有元组,构成一个二维元组
  274. results = cur.fetchall()
  275. for item in results:
  276. tree.insert('', "end", values=item)
  277. cur.close()
  278. db.close() # 关闭连接
  279. #(6.2)
  280. def append_user_Info(tree,list,table):
  281. delButton(tree)
  282. list2 = []
  283. for i in range(len(list)):
  284. if list[i].get() == '':
  285. showerror(title='提示', message='输入不能为空!')
  286. return
  287. else:
  288. list2.append(list[i].get())
  289. x = tree.get_children()
  290. for item in x:
  291. tree.delete(item)
  292. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  293. cur = db.cursor()
  294. try:
  295. if table == 'recipient':
  296. sql1 = "insert into recipient values('%s','%s','%s','%s','%s')"% (list2[0], list2[1], list2[2], list2[3], list2[4])
  297. elif table == 'sender':
  298. sql1 = "insert into sender values('%s','%s','%s','%s','%s')"% (list2[0], list2[1], list2[2], list2[3], list2[4])
  299. else:
  300. sql1 = "insert into distributor values('%s','%s','%s','%s','%s')"% (list2[0], list2[1], list2[2], list2[3], list2[4])
  301. cur.execute(sql1)
  302. db.commit()
  303. if table == 'recipient':
  304. sql = "select * from recipient"
  305. elif table == 'sender':
  306. sql = "select * from sender"
  307. else:
  308. sql = "select * from distributor"
  309. cur.execute(sql)
  310. results = cur.fetchall()
  311. for item in results:
  312. tree.insert('', "end", values=item)
  313. showinfo(title='提示', message='添加/更改成功!')
  314. except:
  315. showinfo(title='提示', message='该人员/编号已存在!')
  316. return
  317. cur.close()
  318. db.close()
  319. #(6.3)
  320. def delete_user_Info(tree,table):
  321. if not tree.selection():
  322. showerror(title='提示', message='请选择一条信息!')
  323. return
  324. res=askyesno('提示','是否确认删除?')
  325. if res==True:
  326. for item in tree.selection():
  327. selectedItem = tree.selection()[0]
  328. no1 = tree.item(selectedItem, 'values')[1]
  329. tree.delete(item)
  330. if table == 'recipient':
  331. sql = "delete from recipient where RID = '%s' " % no1
  332. elif table == 'sender':
  333. sql = "delete from sender where SID = '%s' " % no1
  334. else:
  335. sql = "delete from distributor where Dnum = '%s' " % no1
  336. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  337. cur = db.cursor()
  338. cur.execute(sql)
  339. db.commit()
  340. cur.close()
  341. db.close()
  342. showinfo(title='提示', message='删除成功!')
  343. #(6.4)
  344. def update_user_Info(tree, list,table):
  345. if not tree.selection():
  346. showerror(title='提示', message='请选择一条信息!')
  347. return
  348. else:
  349. res=askyesno("提示","是否确认更新数据?")
  350. if res==True:
  351. for item in tree.selection():
  352. selectedItem = tree.selection()[0]
  353. no1 = tree.item(selectedItem, 'values')[1]
  354. tree.delete(item)
  355. if table == 'recipient':
  356. sql = "delete from recipient where RID = '%s' " % no1
  357. elif table == 'sender':
  358. sql = "delete from sender where SID = '%s' " % no1
  359. else:
  360. sql = "delete from distributor where Dnum = '%s' " % no1
  361. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  362. cur = db.cursor()
  363. cur.execute(sql)
  364. db.commit()
  365. cur.close()
  366. db.close()
  367. append_user_Info(tree, list,table)
  368. return
  369. #(6.5)
  370. def find_sql_line(table,flag,entry):
  371. if table=='recipient':
  372. if flag=='name':
  373. sql = "select * from recipient where Rname = '%s'"%(entry.get())
  374. elif flag=='ID':
  375. sql = "select * from recipient where RID = '%s'"%(entry.get())
  376. elif flag=='address':
  377. sql = "select * from recipient where Raddress = '%s'"%(entry.get())
  378. elif flag=='sex':
  379. sql = "select * from recipient where Rsex = '%s'"%(entry.get())
  380. else:
  381. sql = "select * from recipient where Rphonenumber = '%s'"%(entry.get())
  382. elif table=='sender':
  383. if flag=='name':
  384. sql = "select * from sender where Sname = '%s'"%(entry.get())
  385. elif flag=='ID':
  386. sql = "select * from sender where SID = '%s'"%(entry.get())
  387. elif flag=='address':
  388. sql = "select * from sender where Saddress = '%s'"%(entry.get())
  389. elif flag=='sex':
  390. sql = "select * from sender where Ssex = '%s'"%(entry.get())
  391. else:
  392. sql = "select * from sender where Sphonenumber = '%s'"%(entry.get())
  393. else:
  394. if flag=='name':
  395. sql = "select * from distributor where Dname = '%s'"%(entry.get())
  396. elif flag=='ID':
  397. sql = "select * from distributor where Dnum = '%s'"%(entry.get())
  398. elif flag=='address':
  399. sql = "select * from distributor where DID = '%s'"%(entry.get())
  400. elif flag=='sex':
  401. sql = "select * from distributor where Dsex = '%s'"%(entry.get())
  402. else:
  403. sql = "select * from distributor where Dphonenumber = '%s'"%(entry.get())
  404. return sql
  405. #(6.6)
  406. def find_use_Info(tree,table,entry,flag):
  407. delButton(tree)
  408. db = pymysql.connect(host="localhost", user="root", password="root", db="fu_logistics", port=3306)
  409. cur = db.cursor()
  410. sql=find_sql_line(table=table,flag=flag,entry=entry)
  411. cur.execute(sql)
  412. results = cur.fetchall()
  413. if results:
  414. for item in results:
  415. tree.insert('', "end", values=item)
  416. else:
  417. showinfo(title='提示', message='无该信息!')
  418. cur.close()
  419. db.close()
  420. image7=None
  421. img7=None
  422. #(7)订单信息操作页面
  423. def MangerPage(root1):
  424. global image7
  425. global img7
  426. root1.destroy()
  427. root1 = Tk()
  428. root1.geometry('1000x700+300+50')
  429. root1.title('订单信息操作页面')
  430. root1['background']='floralwhite'
  431. image7 = Image.open('2.jpeg')
  432. img7 = ImageTk.PhotoImage(image7)
  433. Label(root1, text='订单信息操作页面',bg='floralwhite', fg='blue', font=('楷体', 20),compound='bottom',image=img7).pack()
  434. Label(root1, text="订单编号:",font=('楷体', 13)).place(relx=0.5, rely=0.07, relwidth=0.1)
  435. Label(root1, text="运输时间:",font=('楷体', 13)).place(relx=0.5, rely=0.12, relwidth=0.1)
  436. Label(root1, text="物流站:",font=('楷体', 13)).place(relx=0.5, rely=0.17, relwidth=0.1)
  437. Label(root1, text="快递员:",font=('楷体', 13)).place(relx=0.5, rely=0.22, relwidth=0.1)
  438. Label(root1, text="寄件人:",font=('楷体', 13)).place(relx=0.5, rely=0.27, relwidth=0.1)
  439. Label(root1, text="收件人:",font=('楷体', 13)).place(relx=0.5, rely=0.32, relwidth=0.1)
  440. Label(root1, text="商品:",font=('楷体', 13)).place(relx=0.5, rely=0.37, relwidth=0.1)
  441. Label(root1, text="价格:",font=('楷体', 13)).place(relx=0.5, rely=0.42, relwidth=0.1)
  442. Onum = StringVar()
  443. Odelivery_time = StringVar()
  444. Olog_station = StringVar()
  445. Odistributor = StringVar()
  446. Osender = StringVar()
  447. Orecipient = StringVar()
  448. Ogoods = StringVar()
  449. Oprice = StringVar()
  450. entry_Onum = Entry(root1, textvariable=Onum)
  451. entry_Onum.place(relx=0.6, rely=0.07, relwidth=0.3, height=25)
  452. entry_Odelivery_time = Entry(root1, textvariable=Odelivery_time)
  453. entry_Odelivery_time.place(relx=0.6, rely=0.12, relwidth=0.3, height=25)
  454. entry_Olog_station = Entry(root1, textvariable=Olog_station)
  455. entry_Olog_station.place(relx=0.6, rely=0.17, relwidth=0.3, height=25)
  456. entry_Odistributor = Entry(root1, textvariable=Odistributor)
  457. entry_Odistributor.place(relx=0.6, rely=0.22, relwidth=0.3, height=25)
  458. entry_Osender = Entry(root1, textvariable=Osender)
  459. entry_Osender.place(relx=0.6, rely=0.27, relwidth=0.3, height=25)
  460. entry_Orecipient = Entry(root1, textvariable=Orecipient)
  461. entry_Orecipient.place(relx=0.6, rely=0.32, relwidth=0.3, height=25)
  462. entry_Ogoods = Entry(root1, textvariable=Ogoods)
  463. entry_Ogoods.place(relx=0.6, rely=0.37, relwidth=0.3, height=25)
  464. entry_Oprice = Entry(root1, textvariable=Oprice)
  465. entry_Oprice.place(relx=0.6, rely=0.42, relwidth=0.3, height=25)
  466. list1 = [entry_Onum, entry_Odelivery_time, entry_Olog_station, entry_Odistributor, entry_Osender, entry_Orecipient,entry_Ogoods, entry_Oprice]
  467. Tree1 = ttk.Treeview(root1, show='headings',
  468. column=('Onum', 'Odelivery_time', 'Olog_station', 'Odistributor', 'Osender', 'Orecipient', 'Ogoods', 'Oprice'))
  469. Tree1.column('Onum', width=50, anchor="center")
  470. Tree1.column('Odelivery_time', width=70, anchor="center")
  471. Tree1.column('Olog_station', width=40, anchor="center")
  472. Tree1.column('Odistributor', width=70, anchor="center")
  473. Tree1.column('Osender', width=70, anchor="center")
  474. Tree1.column('Orecipient', width=70, anchor="center")
  475. Tree1.column('Ogoods', width=70, anchor="center")
  476. Tree1.column('Oprice', width=40, anchor="center")
  477. Tree1.heading('Onum', text='订单编号')
  478. Tree1.heading('Odelivery_time', text='运输时间')
  479. Tree1.heading('Olog_station', text='物流站')
  480. Tree1.heading('Odistributor', text='快递员')
  481. Tree1.heading('Osender', text='寄件人')
  482. Tree1.heading('Orecipient', text='收件人')
  483. Tree1.heading('Ogoods', text='商品')
  484. Tree1.heading('Oprice', text='价格')
  485. Tree1.place(rely=0.5, relwidth=1)
  486. Button(root1, text="根据编号查找",activebackground='gray',font=('楷体',13), command=lambda:findInfo(check=1, tree=Tree1, list=list1) ).place(relx=0.15, rely=0.17, width=150)
  487. Button(root1, text="查询所有订单",activebackground='gray',font=('楷体',13), command=lambda: showAllInfo(tree=Tree1)).place(relx=0.15, rely=0.10, width=150)
  488. Button(root1, text="增加订单", activebackground='gray',font=('楷体',13), command=lambda: appendInfo(tree=Tree1, list=list1)).place(relx=0.15, rely=0.24, width=150)
  489. Button(root1, text="删除订单", activebackground='gray',font=('楷体',13), command=lambda: deleteInfo(tree=Tree1)).place(relx=0.15, rely=0.31, width=150)
  490. Button(root1, text="更改订单信息", activebackground='gray',font=('楷体',13), command=lambda: updateInfo(tree=Tree1, list=list1)).place(relx=0.15, rely=0.38, width=150)
  491. def treeviewClick(event):
  492. item = Tree1.selection()[0]
  493. item_text = Tree1.item(item, "values")
  494. entry_Onum.delete(0, 'end')
  495. entry_Odelivery_time.delete(0, 'end')
  496. entry_Olog_station.delete(0, 'end')
  497. entry_Odistributor.delete(0, 'end')
  498. entry_Osender.delete(0, 'end')
  499. entry_Orecipient.delete(0, 'end')
  500. entry_Ogoods.delete(0, 'end')
  501. entry_Oprice.delete(0, 'end')
  502. entry_Onum.insert(0, item_text[0])
  503. entry_Odelivery_time.insert(0, item_text[1])
  504. entry_Olog_station.insert(0, item_text[2])
  505. entry_Odistributor.insert(0, item_text[3])
  506. entry_Osender.insert(0, item_text[4])
  507. entry_Orecipient.insert(0, item_text[5])
  508. entry_Ogoods.insert(0, item_text[6])
  509. entry_Oprice.insert(0, item_text[7])
  510. Tree1.bind('<ButtonRelease-1>', treeviewClick)
  511. root1.protocol('WM_DELETE_WINDOW', lambda:MangerChoosePage(root1))
  512. root1.mainloop()
  513. #(7.1)
  514. def showAllInfo(tree):
  515. delButton(tree)
  516. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  517. cur = db.cursor() #用db操作游标
  518. cur.execute("select * from orders")
  519. results = cur.fetchall()
  520. for item in results:
  521. tree.insert('', "end", values=item)
  522. cur.close()
  523. db.close() # 关闭连接
  524. #(7.2)
  525. def appendInfo(tree,list):
  526. delButton(tree)
  527. list2 = []
  528. for i in range(len(list)):
  529. if list[i].get() == '':
  530. showerror(title='提示', message='输入不能为空!')
  531. return
  532. else:
  533. list2.append(list[i].get())
  534. x = tree.get_children()
  535. for item in x:
  536. tree.delete(item)
  537. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  538. cur = db.cursor()
  539. try:
  540. cur.execute("insert into orders values('%s','%s','%s','%s','%s','%s','%s','%s')" % (list2[0], list2[1], list2[2], list2[3], list2[4], list2[5], list2[6], list2[7]))
  541. db.commit()#对数据进行修改、删除、插入时最好都commit一下,跟在execute()后面
  542. cur.execute("select * from orders")
  543. results = cur.fetchall()
  544. for item in results:
  545. tree.insert('', "end", values=item)
  546. showinfo(title='提示', message='添加/更新成功!')
  547. except:
  548. showinfo(title='提示', message='该编号已存在!')
  549. return
  550. cur.close()
  551. db.close()
  552. #(7.3)
  553. def deleteInfo(tree):
  554. if not tree.selection():
  555. showerror(title='提示', message='请选择一条信息!')
  556. return
  557. res = askyesno('提示!', '是否确认删除?')
  558. if res == True:
  559. for item in tree.selection():
  560. selectedItem = tree.selection()[0]
  561. no1 = tree.item(selectedItem, 'values')[0]
  562. tree.delete(item)
  563. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  564. cur = db.cursor()
  565. cur.execute("delete from orders where Onum = '%s'" % no1)
  566. db.commit()
  567. cur.close()
  568. db.close()
  569. showinfo(title='提示', message='删除成功!')
  570. #(7.4)
  571. def updateInfo(tree, list):
  572. if not tree.selection():
  573. showerror(title='提示', message='请选择一条信息!')
  574. return
  575. else:
  576. res=askyesno("提示!","是否确认更新数据?")
  577. if res==True:
  578. for item in tree.selection():
  579. selectedItem = tree.selection()[0]
  580. no1 = tree.item(selectedItem, 'values')[0]
  581. tree.delete(item)
  582. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  583. cur = db.cursor()
  584. cur.execute("delete from orders where Onum = '%s'" % no1)
  585. db.commit()
  586. cur.close()
  587. db.close()
  588. appendInfo(tree, list)
  589. return
  590. #(7.5)
  591. def findInfo(check, tree, list):
  592. if check:
  593. delButton(tree)
  594. db = pymysql.connect(host="localhost", user="root",password="root", db="fu_logistics", port=3306)
  595. cur = db.cursor()
  596. cur.execute("select * from orders where Onum = '%s'" % list[0].get()) # 执行sql语句
  597. results = cur.fetchall()
  598. if results:
  599. for item in results:
  600. tree.insert('', "end", values=item)
  601. else:
  602. showinfo(title='提示', message='无该订单编号!')
  603. cur.close()
  604. db.close()
  605. image5=None
  606. img5=None
  607. #(8)游客订单信息查询页面
  608. def GuestPage(root):
  609. global image5
  610. global img5
  611. root.destroy()
  612. root=Tk()
  613. root.title('游客订单信息查询页面')
  614. root.geometry('850x730+300+50')
  615. root['background']='white'
  616. image5 = Image.open('5.png')
  617. img5 = ImageTk.PhotoImage(image5)
  618. Label(root,text='游客订单信息查询页面',compound='bottom',image=img5,bg='floralwhite',fg='blue',font=('楷体',20)).pack(side=TOP, fill='x')
  619. Label(root,text='订单编号:',font=('楷体',13)).place(relx=0.07,rely=0.15,relwidth=0.15)
  620. Label(root, text='收件人姓名:',font=('楷体',13)).place(relx=0.07, rely=0.25, relwidth=0.15)
  621. Label(root, text='寄件人姓名:',font=('楷体',13)).place(relx=0.07, rely=0.35, relwidth=0.15)
  622. Label(root, text='配送时间:',font=('楷体',13)).place(relx=0.07, rely=0.45, relwidth=0.15)
  623. Onum=StringVar()
  624. Rname=StringVar()
  625. Sname=StringVar()
  626. Odeliver_time=StringVar()
  627. entry_Onum = Entry(root, textvariable=Onum)
  628. entry_Onum.place(relx=0.2, rely=0.15, relwidth=0.3, height=25)
  629. entry_Rname = Entry(root, textvariable=Rname)
  630. entry_Rname.place(relx=0.2, rely=0.25, relwidth=0.3, height=25)
  631. entry_Sname = Entry(root, textvariable=Sname)
  632. entry_Sname.place(relx=0.2, rely=0.35, relwidth=0.3, height=25)
  633. entry_Odeliver_time = Entry(root, textvariable=Odeliver_time)
  634. entry_Odeliver_time.place(relx=0.2, rely=0.45, relwidth=0.3, height=25)
  635. Tree1 = ttk.Treeview(root, show='headings',column=('Onum', \
  636. 'Odelivery_time', 'Olog_station', 'Odistributor', 'Osender', 'Orecipient', 'Ogoods','Oprice'))
  637. Tree1.column('Onum', width=50, anchor="center")
  638. Tree1.column('Odelivery_time', width=80, anchor="center")
  639. Tree1.column('Olog_station', width=40, anchor="center")
  640. Tree1.column('Odistributor', width=70, anchor="center")
  641. Tree1.column('Osender', width=70, anchor="center")
  642. Tree1.column('Orecipient', width=70, anchor="center")
  643. Tree1.column('Ogoods', width=70, anchor="center")
  644. Tree1.column('Oprice', width=40, anchor="center")
  645. # 表格标题设置
  646. Tree1.heading('Onum', text='订单编号')
  647. Tree1.heading('Odelivery_time', text='运输时间')
  648. Tree1.heading('Olog_station', text='物流站')
  649. Tree1.heading('Odistributor', text='快递员')
  650. Tree1.heading('Osender', text='寄件人')
  651. Tree1.heading('Orecipient', text='收件人')
  652. Tree1.heading('Ogoods', text='商品')
  653. Tree1.heading('Oprice', text='价格')
  654. Tree1.place(rely=0.6, relwidth=1)
  655. Button(root, text="按编号查询",bg='gainsboro',fg='black',activebackground='grey',font=('楷体',13), command=lambda:Find_infor_num(Tree1,entry_Onum)).place(relx=0.65, rely=0.15, width=150)
  656. Button(root, text="按姓名查询",bg='gainsboro',fg='black', activebackground='grey',font=('楷体',13), command=lambda:Find_infor_name(Tree1,entry_Rname,entry_Sname)).place(relx=0.65, rely=0.3, width=150)
  657. Button(root, text="按时间查询",bg='gainsboro',fg='black', activebackground='grey',font=('楷体',13), command=lambda:Find_infor_time(Tree1,entry_Odeliver_time)).place(relx=0.65, rely=0.45, width=150)
  658. root.protocol('WM_DELETE_WINDOW', lambda:back(root))
  659. root.mainloop()
  660. #(8.1)
  661. def Find_infor_num(Tree1,Name):
  662. delButton(Tree1)
  663. db = pymysql.connect(host="localhost", user="root", password="root", db="fu_logistics", port=3306)
  664. cur = db.cursor()
  665. cur.execute("select * from orders where Onum = '%s'" % Name.get())
  666. results = cur.fetchall() # 获取查询的所有记录
  667. if results:
  668. for item in results:
  669. Tree1.insert('', "end", values=item)
  670. else:
  671. showinfo(title='提示', message='无该订单编号!')
  672. cur.close()
  673. db.close()
  674. #(8.2)
  675. def Find_infor_name(Tree1,Name1,Name2):
  676. delButton(Tree1)
  677. db = pymysql.connect(host="localhost", user="root", password="root", db="fu_logistics", port=3306)
  678. cur = db.cursor()
  679. if Name1.get():
  680. cur.execute("select * from orders where Orecipient = '%s'" % Name1.get())
  681. results = cur.fetchall()
  682. if not results:
  683. showinfo(title='提示', message='无该收件人!')
  684. else:
  685. for item in results:
  686. Tree1.insert('', "end", values=item)
  687. if Name2.get():
  688. cur.execute("select * from orders where Osender = '%s'" % Name2.get())
  689. results = cur.fetchall()
  690. if not results:
  691. showinfo(title='提示', message='无该寄件人!')
  692. else:
  693. for item in results:
  694. Tree1.insert('', "end", values=item)
  695. cur.close()
  696. db.close()
  697. #(8.3)
  698. def Find_infor_time(Tree1,time):
  699. delButton(Tree1)
  700. db = pymysql.connect(host="localhost", user="root", password="root", db="fu_logistics", port=3306)
  701. cur = db.cursor()
  702. ch='%'+time.get()+'%'
  703. cur.execute("select * from orders where Odelivery_time like '%s'" % ch)
  704. results = cur.fetchall()
  705. if results:
  706. for item in results:
  707. Tree1.insert('', "end", values=item)
  708. else:
  709. showinfo(title='提示', message='无该配送日期!')
  710. cur.close()
  711. db.close()
  712. if __name__=='__main__':
  713. StartPage()

6.不足说明

1.本数据库在创建时,没有添加外码,因此表间数据不具有对应关系,数据插入时不受外码影响。

2.部分代码是根据已创建的数据库结构来对应编写,延展性不强。

3.对部分插入数据无完整语句限制,部分不按实际规则填写的数据也会被写入数据库。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/524924
推荐阅读
相关标签
  

闽ICP备14008679号