python实现外卖信息管理系统

时间:2021-11-21 02:06:52

本文为大家分享了python实现外卖信息管理系统的具体代码,供大家参考,具体内容如下

一、需求分析

需求分析包含如下:

1、问题描述

以外卖信息系统管理员身份登陆该系统,实现对店铺信息、派送员信息、客服人员信息、订单信息、配送信息等进行有条件查询以及信息的录入、修改、删除等功能。

2、系统功能描述

(1)信息录入:使用wxpython设计排版编写窗口界面,给出录入信息的接口,通过python语句实现与数据库的连接,从而向数据库中插入相应数据。

(2)信息修改:使用wxpython设计排版编写窗口界面,给出修改信息的接口,通过python语句实现与数据库的连接,从而修改数据库中相应数据。

(3)信息查询:在窗口界面中,通过响应的按钮触发,实现与数据库的连接查询,得到所有在线店铺信息。

(4)数据统计:在数据库中编写相应的存储过程,输入店铺名称即可select其所管理的派送员和客服人员。

3、系统功能模块图

python实现外卖信息管理系统

二、概念结构设计

系统整体的E-R模型:

python实现外卖信息管理系统

三、逻辑结构设计

本系统所用到的表结构以及其联系:

1、店铺基本信息foodshop表

python实现外卖信息管理系统

主键:shop_name

2、客服基本信息server表 python实现外卖信息管理系统

主键:server_id

外键:shopname_shop_name

参考表:shopname 参考属性:shop_name

3、派送员基本信息courier表

python实现外卖信息管理系统

主键:courier_id

外键:shopname_shop_name

参考表:shopname 参考属性:shop_name

4、学生基本信息student表

python实现外卖信息管理系统

主键:student_phone

5、订单基本信息book表

python实现外卖信息管理系统

主键:(student_phone,server_id)

外键:student_phone,参考表student,参考属性student_phone

外键:server_id,参考表server,参考属性server_id

6、配送基本信息delivery表

python实现外卖信息管理系统

主键:(student_phone,courier_id)

外键:student_phone,参考表student,参考属性student_phone

外键:courier_id,参考表courier,参考属性courier_id

四、具体实现

登陆界面:

python实现外卖信息管理系统

附上源代码:

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
# coding:utf8
 
###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
 
import wx #导入wxpyhton,pyhton自带的GUI库
#import wx.xrc
 
import pymysql #用于操作数据库
import sys
reload(sys)
sys.setdefaultencoding('utf8')
 
###########################################################################
## Class MyFrame1
###########################################################################
 
#建一个窗口类MyFrame1继承wx.Frame
class MyFrame1(wx.Frame):
 def __init__(self, parent):
 #Wx.Frame (parent, id, title, pos, size, style, name)
 wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"外卖信息管理系统", pos=wx.DefaultPosition, size=wx.Size(610, 400),
    style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
 self.Center() #居中显示
 
 # 小构件,如按钮,文本框等被放置在面板窗口。 wx.Panel类通常是被放在一个wxFrame对象中。这个类也继承自wxWindow类。
 self.m_panel1 = wx.Panel(self)
 # 标签,一行或多行的只读文本,Wx.StaticText(parent, id, label, position, size, style)
 self.m_staticText1 = wx.StaticText(self.m_panel1, wx.ID_ANY, u"关于店铺:", (20, 20))
 self.m_button1 = wx.Button(self.m_panel1, wx.ID_ANY, u"店铺信息", (130, 20), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button2 = wx.Button(self.m_panel1, wx.ID_ANY, u"店铺上架", (250, 20), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button3 = wx.Button(self.m_panel1, wx.ID_ANY, u"店铺下架", (370, 20), wx.DefaultSize,
     style=wx.BORDER_MASK)
 
 self.m_staticText2 = wx.StaticText(self.m_panel1, wx.ID_ANY, u"关于派送员:", (20, 90))
 self.m_button4 = wx.Button(self.m_panel1, wx.ID_ANY, u"派送员信息", (130, 90), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button5 = wx.Button(self.m_panel1, wx.ID_ANY, u"聘请派送员", (250, 90), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button6 = wx.Button(self.m_panel1, wx.ID_ANY, u"解雇派送员", (370, 90), wx.DefaultSize,
     style=wx.BORDER_MASK)
 
 self.m_staticText3 = wx.StaticText(self.m_panel1, wx.ID_ANY, u"关于客服人员:", (20, 160))
 self.m_button7 = wx.Button(self.m_panel1, wx.ID_ANY, u"客服人员信息", (130, 160), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button8 = wx.Button(self.m_panel1, wx.ID_ANY, u"聘请客服人员", (250, 160), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button9 = wx.Button(self.m_panel1, wx.ID_ANY, u"解雇客服人员", (370, 160), wx.DefaultSize,
     style=wx.BORDER_MASK)
 
 self.m_staticText4 = wx.StaticText(self.m_panel1, wx.ID_ANY, u"关于订单:", (20, 230))
 self.m_button10 = wx.Button(self.m_panel1, wx.ID_ANY, u"订单信息", (130, 230), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button11 = wx.Button(self.m_panel1, wx.ID_ANY, u"学生订餐", (250, 230), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button12 = wx.Button(self.m_panel1, wx.ID_ANY, u"取消订单", (370, 230), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button13 = wx.Button(self.m_panel1, wx.ID_ANY, u"修改订单", (490, 230), wx.DefaultSize,
     style=wx.BORDER_MASK)
 
 self.m_staticText5 = wx.StaticText(self.m_panel1, wx.ID_ANY, u"关于物流:", (20, 300))
 self.m_button14 = wx.Button(self.m_panel1, wx.ID_ANY, u"配送信息", (130, 300), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button15 = wx.Button(self.m_panel1, wx.ID_ANY, u"安排配送", (250, 300), wx.DefaultSize,
     style=wx.BORDER_MASK)
 self.m_button16 = wx.Button(self.m_panel1, wx.ID_ANY, u"取消配送", (370, 300), wx.DefaultSize,
     style=wx.BORDER_MASK)
 
 
 #按钮绑定对话框的弹出
 #在创建应用程序时,Bind函数可以将按钮的动作与特定的函数绑定,当按钮上有动作时,这个函数就会启动,从而处理响应的事件。
 #个Button被单击发生了EVT_BUTTON事件
 self.m_button1.Bind(wx.EVT_BUTTON, MyDialog11(None).OnClick)
 self.m_button2.Bind(wx.EVT_BUTTON, MyDialog12(None).OnClick)
 self.m_button3.Bind(wx.EVT_BUTTON, MyDialog13(None).OnClick)
 self.m_button4.Bind(wx.EVT_BUTTON, MyDialog21(None).OnClick)
 self.m_button5.Bind(wx.EVT_BUTTON, MyDialog22(None).OnClick)
 self.m_button6.Bind(wx.EVT_BUTTON, MyDialog23(None).OnClick)
 self.m_button7.Bind(wx.EVT_BUTTON, MyDialog31(None).OnClick)
 self.m_button8.Bind(wx.EVT_BUTTON, MyDialog32(None).OnClick)
 self.m_button9.Bind(wx.EVT_BUTTON, MyDialog33(None).OnClick)
 self.m_button10.Bind(wx.EVT_BUTTON, MyDialog41(None).OnClick)
 self.m_button11.Bind(wx.EVT_BUTTON, MyDialog42(None).OnClick)
 self.m_button12.Bind(wx.EVT_BUTTON, MyDialog43(None).OnClick)
 self.m_button13.Bind(wx.EVT_BUTTON, MyDialog44(None).OnClick)
 self.m_button14.Bind(wx.EVT_BUTTON, MyDialog51(None).OnClick)
 self.m_button15.Bind(wx.EVT_BUTTON, MyDialog52(None).OnClick)
 self.m_button16.Bind(wx.EVT_BUTTON, MyDialog53(None).OnClick)
 
 #设置按钮的背景颜色
 self.m_button1.SetBackgroundColour('#0a74f7')
 self.m_button1.SetForegroundColour('white')
 self.m_button2.SetBackgroundColour('#0a74f7')
 self.m_button2.SetForegroundColour('white')
 self.m_button3.SetBackgroundColour('#0a74f7')
 self.m_button3.SetForegroundColour('white')
 
 self.m_button4.SetBackgroundColour('#238E23')
 self.m_button4.SetForegroundColour('white')
 self.m_button5.SetBackgroundColour('#238E23')
 self.m_button5.SetForegroundColour('white')
 self.m_button6.SetBackgroundColour('#238E23')
 self.m_button6.SetForegroundColour('white')
 
 self.m_button7.SetBackgroundColour('#6F4242')
 self.m_button7.SetForegroundColour('white')
 self.m_button8.SetBackgroundColour('#6F4242')
 self.m_button8.SetForegroundColour('white')
 self.m_button9.SetBackgroundColour('#6F4242')
 self.m_button9.SetForegroundColour('white')
 
 self.m_button10.SetBackgroundColour('#8E6B23')
 self.m_button10.SetForegroundColour('white')
 self.m_button11.SetBackgroundColour('#8E6B23')
 self.m_button11.SetForegroundColour('white')
 self.m_button12.SetBackgroundColour('#8E6B23')
 self.m_button12.SetForegroundColour('white')
 self.m_button13.SetBackgroundColour('#8E6B23')
 self.m_button13.SetForegroundColour('white')
 
 self.m_button14.SetBackgroundColour('#545454')
 self.m_button14.SetForegroundColour('white')
 self.m_button15.SetBackgroundColour('#545454')
 self.m_button15.SetForegroundColour('white')
 self.m_button16.SetBackgroundColour('#545454')
 self.m_button16.SetForegroundColour('white')
 
 self.m_panel1.SetBackgroundColour('white') #设置面板的背景颜色
 
 
###########################################################################
## Class MyDialog11
###########################################################################
 
#一个对话框的类继承wx.Dialog
class MyDialog11(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"店铺信息", pos=wx.DefaultPosition, size=wx.Size(302, 362),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "店铺名称", (20, 20))
 wx.StaticText(self.panel, -1, "月销量", (80, 20))
 
 def OnClick(self, event):
 
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 try:
  sql = "select * from foodshop"
  cursor.execute(sql)
  rs = cursor.fetchall()
  h = 30
  for row in rs:
  h = h + 20
  shop_name = row[0]
  salenum = row[1] #注意数据库中的数据为数字 int 类型时的读取方式 id = '%d' % i[0]
  wx.StaticText(self.panel, -1, shop_name, (20, h))
  wx.StaticText(self.panel, -1, salenum, (80, h))
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 self.ShowModal()
 
 
###########################################################################
## Class MyDialog12
###########################################################################
 
class MyDialog12(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"店铺上架", pos=wx.DefaultPosition, size=wx.Size(302, 250),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入店铺名称:", (20, 20))
 # 可编辑文本框的创建使用wx.TextCtrl,默认情况下,文本框只能编辑一行文字(无论文字多长均不换行)
 self.t1 = wx.TextCtrl(self.panel, pos=(130, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入月销量:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(130, 80), size=(120, 25))
 
 
 def OnClick(self, e):
 dialog12 = MyDialog12(None)
 btn = wx.Button(parent=dialog12.panel, label="上架", pos=(20, 150), size=(100, 45), style=wx.BORDER_MASK)
 btn.Bind(wx.EVT_BUTTON, dialog12.insert)
 dialog12.ShowModal()
 
 def insert(self, event):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 shop_name = self.t1.GetValue().encode('utf8') #注意GetValue()获取的是unicode编码,
 salenum = self.t2.GetValue().encode('utf8') #你使用的#coding=utf8,那就对获取的数据.encode('utf8')重新编码
 data = (shop_name, salenum)
 
 try:
  sql = "insert into foodshop values (%s,%s)"
  cursor.execute(sql, data)
  conn.commit() #提交给后台数据库
  dial = wx.MessageDialog(None, '成功上架!', '结果', wx.YES_NO) # 创建一个带按钮的消息框, 语法是(self, 框中内容, 框标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
###########################################################################
## Class MyDialog13
###########################################################################
 
class MyDialog13(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"店铺下架", pos=wx.DefaultPosition, size=wx.Size(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "店铺名称:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(20, 50), size=(120, 25))
 
 
 def OnClick(self, e):
 dialog13 = MyDialog13(None)
 btn = wx.Button(parent=dialog13.panel, label="下架", pos=(20, 90), size=(90, 40))
 btn.Bind(wx.EVT_BUTTON, dialog13.delete)
 dialog13.ShowModal()
 
 def delete(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 shop_name = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码
 try:
  sql = "delete from foodshop where shop_name=%s"
  cursor.execute(sql, shop_name)
  conn.commit()
  dial = wx.MessageDialog(None, '成功下架!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
###########################################################################
## Class MyDialog21
###########################################################################
 
class MyDialog21(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"派送员信息", pos=wx.DefaultPosition, size=wx.Size(400, 415),
    style=wx.DEFAULT_DIALOG_STYLE)
 
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "店铺名称:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(90, 20), size=(120, 25))
 #btn = wx.Button(parent=self.panel, label="查询", pos=(240, 20), size=(70, 25))
 #btn.Bind(wx.EVT_BUTTON, self.find)
 wx.StaticText(self.panel, -1, "派送员编号", (20, 60))
 wx.StaticText(self.panel, -1, "派送员姓名", (120, 60))
 wx.StaticText(self.panel, -1, "派送员电话", (220, 60))
 
 def OnClick(self, event):
 dialog21 = MyDialog21(None)
 btn = wx.Button(parent=dialog21.panel, label="查询", pos=(240, 20), size=(70, 25))
 btn.Bind(wx.EVT_BUTTON, dialog21.find)
 dialog21.ShowModal()
 
 def find(self, event):
 '''
 if self.t1.GetValue() == '肯德基':
  wx.StaticText(self.panel, -1, '派送员编号', (20, h))
  wx.StaticText(self.panel, -1, '派送员姓名', (120, h))
 '''
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 try:
  sql = "select * from courier"
  cursor.execute(sql)
  rs = cursor.fetchall()
  h = 80
  for row in rs:
  if row[3] == self.t1.GetValue():
   h = h + 20
   courier_id = row[0]
   courier_name = row[1]
   courier_phone = row[2]
   wx.StaticText(self.panel, -1, courier_id, (20, h))
   wx.StaticText(self.panel, -1, courier_name, (120, h))
   wx.StaticText(self.panel, -1, courier_phone, (220, h))
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog22
###########################################################################
 
class MyDialog22(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"聘请派送员", pos=wx.DefaultPosition, size=wx.Size(400, 350),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入店铺名称:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(140, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入派送员编号:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(140, 80), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入派送员姓名:", (20, 140))
 self.t3 = wx.TextCtrl(self.panel, pos=(140, 140), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入派送员电话:", (20, 200))
 self.t4 = wx.TextCtrl(self.panel, pos=(140, 200), size=(120, 25))
 
 def OnClick(self, e):
 dialog22 = MyDialog22(None)
 btn = wx.Button(parent=dialog22.panel, label="聘请", pos=(20, 250), size=(100, 45))
 btn.Bind(wx.EVT_BUTTON, dialog22.insert)
 dialog22.ShowModal()
 
 def insert(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 shop_name = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码,
 courier_id = self.t2.GetValue().encode('utf8') # 你使用的#coding=utf8,那就对获取的数据.encode('utf8')
 courier_name = self.t3.GetValue().encode('utf8')
 courier_phone = self.t4.GetValue().encode('utf8')
 
 data = (courier_id, courier_name, courier_phone, shop_name)
 
 try:
  sql = "insert into courier values (%s,%s,%s,%s)"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功聘请派送员!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog23
###########################################################################
 
class MyDialog23(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"解雇派送员", pos=wx.DefaultPosition, size=wx.Size(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "派送员编号:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(20, 50), size=(120, 25))
 
 def OnClick(self, e):
 dialog23 = MyDialog23(None)
 btn = wx.Button(parent=dialog23.panel, label="解雇", pos=(20, 90), size=(90, 40))
 btn.Bind(wx.EVT_BUTTON, dialog23.delete)
 dialog23.ShowModal()
 
 def delete(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 courier_id = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码
 try:
  sql = "delete from courier where courier_id=%s"
  cursor.execute(sql, courier_id)
  conn.commit()
  dial = wx.MessageDialog(None, '成功解雇派送员!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog31
###########################################################################
 
class MyDialog31(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"客服人员信息", pos=wx.DefaultPosition, size=wx.Size(400, 401),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "店铺名称:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(90, 20), size=(120, 25))
 # btn = wx.Button(parent=self.panel, label="查询", pos=(240, 20), size=(70, 25))
 # btn.Bind(wx.EVT_BUTTON, self.find)
 wx.StaticText(self.panel, -1, "客服人员编号", (20, 60))
 wx.StaticText(self.panel, -1, "客服人员姓名", (120, 60))
 
 def OnClick(self, e):
 dialog31 = MyDialog31(None)
 btn = wx.Button(parent=dialog31.panel, label="查询", pos=(240, 20), size=(70, 25))
 btn.Bind(wx.EVT_BUTTON, dialog31.find)
 dialog31.ShowModal()
 
 def find(self, event):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 try:
  sql = "select * from server"
  cursor.execute(sql)
  rs = cursor.fetchall()
  h = 80
  for row in rs:
  if row[2] == self.t1.GetValue():
   h = h + 20
   server_id = row[0]
   server_name = row[1]
   wx.StaticText(self.panel, -1, server_id, (20, h))
   wx.StaticText(self.panel, -1, server_name, (120, h))
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog32
###########################################################################
 
class MyDialog32(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"聘请客服人员", pos=wx.DefaultPosition, size=wx.Size(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入店铺名称:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(160, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入客服人员编号:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(160, 80), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入客服人员姓名:", (20, 140))
 self.t3 = wx.TextCtrl(self.panel, pos=(160, 140), size=(120, 25))
 
 
 def OnClick(self, e):
 dialog32 = MyDialog32(None)
 btn = wx.Button(parent=dialog32.panel, label="聘请", pos=(20, 200), size=(100, 45))
 btn.Bind(wx.EVT_BUTTON, dialog32.insert)
 dialog32.ShowModal()
 
 def insert(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 shop_name = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码,
 server_id = self.t2.GetValue().encode('utf8') # 你使用的#coding=utf8,那就对获取的数据.encode('utf8')
 server_name = self.t3.GetValue().encode('utf8')
 
 data = (server_id, server_name, shop_name)
 
 try:
  sql = "insert into server values(%s,%s,%s)"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功聘请客服!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog33
###########################################################################
 
class MyDialog33(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"解雇客服人员", pos=wx.DefaultPosition, size=wx.Size(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "客服人员编号:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(20, 50), size=(120, 25))
 
 def OnClick(self, e):
 dialog33 = MyDialog33(None)
 btn = wx.Button(parent=dialog33.panel, label="解雇", pos=(20, 90), size=(90, 40))
 btn.Bind(wx.EVT_BUTTON, dialog33.delete)
 dialog33.ShowModal()
 
 def delete(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 server_id = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码
 try:
  sql = "delete from server where server_id=%s"
  cursor.execute(sql, server_id)
  conn.commit()
  dial = wx.MessageDialog(None, '成功解雇客服!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog41
###########################################################################
 
class MyDialog41(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"订单信息", pos=wx.DefaultPosition, size=wx.Size(500, 400),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "买家电话:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(90, 20), size=(120, 25))
 # btn = wx.Button(parent=self.panel, label="查询", pos=(240, 20), size=(70, 25))
 # btn.Bind(wx.EVT_BUTTON, self.find)
 wx.StaticText(self.panel, -1, "客服人员编号", (20, 60))
 wx.StaticText(self.panel, -1, "订单编号", (120, 60))
 wx.StaticText(self.panel, -1, "订单金额", (220, 60))
 wx.StaticText(self.panel, -1, "订餐方式", (320, 60))
 
 def OnClick(self, e):
 dialog41 = MyDialog41(None)
 btn = wx.Button(parent=dialog41.panel, label="查询", pos=(240, 20), size=(70, 25))
 btn.Bind(wx.EVT_BUTTON, dialog41.find)
 dialog41.ShowModal()
 
 def find(self, event):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 try:
  sql = "select * from book"
  cursor.execute(sql)
  rs = cursor.fetchall()
  h = 80
  for row in rs:
  if row[0] == self.t1.GetValue():
   h = h + 20
   server_id = row[1]
   order_id = row[2]
   order_money = row[3]
   order_way = row[4]
   wx.StaticText(self.panel, -1, server_id, (20, h))
   wx.StaticText(self.panel, -1, order_id, (120, h))
   wx.StaticText(self.panel, -1, order_money, (220, h))
   wx.StaticText(self.panel, -1, order_way, (320, h))
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog42
###########################################################################
 
class MyDialog42(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"学生订餐", pos=wx.DefaultPosition, size=wx.Size(400, 400),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入买家电话:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(150, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入客服人员编号:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(150, 80), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入订单编号:", (20, 140))
 self.t3 = wx.TextCtrl(self.panel, pos=(150, 140), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入订单金额:", (20, 200))
 self.t4 = wx.TextCtrl(self.panel, pos=(150, 200), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入订餐方式:", (20, 260))
 self.t5 = wx.TextCtrl(self.panel, pos=(150, 260), size=(120, 25))
 
 def OnClick(self, e):
 dialog42 = MyDialog42(None)
 btn = wx.Button(parent=dialog42.panel, label="订餐", pos=(20, 310), size=(100, 45))
 btn.Bind(wx.EVT_BUTTON, dialog42.insert)
 dialog42.ShowModal()
 
 def insert(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 student_phone = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码,
 server_id = self.t2.GetValue().encode('utf8') # 你使用的#coding=utf8,那就对获取的数据.encode('utf8')
 order_id = self.t3.GetValue().encode('utf8')
 order_money = self.t4.GetValue().encode('utf8')
 order_way = self.t5.GetValue().encode('utf8')
 
 data = (student_phone, server_id, order_id, order_money, order_way)
 
 try:
  sql = "insert into book values(%s,%s,%s,%s,%s)"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功订餐!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog43
###########################################################################
 
class MyDialog43(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"删除订单", pos=wx.DefaultPosition, size=wx.Size(300, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "客服人员编号:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(20, 50), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "买家电话:", (20, 90))
 self.t2 = wx.TextCtrl(self.panel, pos=(20, 120), size=(120, 25))
 
 def OnClick(self, e):
 dialog43 = MyDialog43(None)
 btn = wx.Button(parent=dialog43.panel, label="取消订单", pos=(20, 170), size=(90, 40))
 btn.Bind(wx.EVT_BUTTON, dialog43.delete)
 dialog43.ShowModal()
 
 def delete(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 server_id = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码
 student_phone = self.t2.GetValue().encode('utf8')
 data = (server_id, student_phone)
 
 try:
  sql = "delete from book where server_id=%s and student_phone=%s"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功删除订单!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog44
###########################################################################
 
class MyDialog44(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"修改订单", pos=wx.DefaultPosition, size=wx.Size(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入客服编号:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(160, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入买家电话:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(160, 80), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请更正订单金额:", (20, 140))
 self.t3 = wx.TextCtrl(self.panel, pos=(160, 140), size=(120, 25))
 
 def OnClick(self, e):
 dialog44 = MyDialog44(None)
 btn = wx.Button(parent=dialog44.panel, label="确认修改", pos=(20, 200), size=(100, 45))
 btn.Bind(wx.EVT_BUTTON, dialog44.change)
 dialog44.ShowModal()
 
 def change(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 server_id = self.t1.GetValue().encode('utf8')
 student_phone = self.t2.GetValue().encode('utf8')
 order_money = self.t3.GetValue().encode('utf8')
 data = (order_money, server_id, student_phone)
 
 try:
  sql = "update book set order_money=%s where server_id=%s and student_phone=%s"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功修改订单!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog51
###########################################################################
 
class MyDialog51(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"配送信息", pos=wx.DefaultPosition, size=wx.Size(502, 362),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "买家电话:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(90, 20), size=(120, 25))
 # btn = wx.Button(parent=self.panel, label="查询", pos=(240, 20), size=(70, 25))
 # btn.Bind(wx.EVT_BUTTON, self.find)
 wx.StaticText(self.panel, -1, "派送员编号", (20, 60))
 wx.StaticText(self.panel, -1, "预计派送时间", (120, 60))
 
 
 def OnClick(self, e):
 dialog51 = MyDialog51(None)
 btn = wx.Button(parent=dialog51.panel, label="查询", pos=(240, 20), size=(70, 25))
 btn.Bind(wx.EVT_BUTTON, dialog51.find)
 dialog51.ShowModal()
 
 def find(self, event):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 try:
  sql = "select * from delivery"
  cursor.execute(sql)
  rs = cursor.fetchall()
  h = 80
  for row in rs:
  if row[0] == self.t1.GetValue():
   h = h + 20
   courier_id = row[1]
   deliver_time = row[2]
   wx.StaticText(self.panel, -1, courier_id, (20, h))
   wx.StaticText(self.panel, -1, deliver_time, (120, h))
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog52
###########################################################################
 
class MyDialog52(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"安排配送", pos=wx.DefaultPosition, size=wx.Size(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "请输入买家电话:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(160, 20), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入派送员编号:", (20, 80))
 self.t2 = wx.TextCtrl(self.panel, pos=(160, 80), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "请输入预计派送时间:", (20, 140))
 self.t3 = wx.TextCtrl(self.panel, pos=(160, 140), size=(120, 25))
 
 def OnClick(self, e):
 dialog52 = MyDialog52(None)
 btn = wx.Button(parent=dialog52.panel, label="配送", pos=(20, 200), size=(100, 45))
 btn.Bind(wx.EVT_BUTTON, dialog52.insert)
 dialog52.ShowModal()
 
 def insert(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 student_phone = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码,
 courier_id = self.t2.GetValue().encode('utf8') # 你使用的#coding=utf8,那就对获取的数据.encode('utf8')
 deliver_time = self.t3.GetValue().encode('utf8')
 
 data = (student_phone, courier_id, deliver_time)
 
 try:
  sql = "insert into delivery values(%s,%s,%s)"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功安排派送!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
 
###########################################################################
## Class MyDialog53
###########################################################################
 
class MyDialog53(wx.Dialog):
 def __init__(self, parent):
 wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"取消配送", pos=wx.DefaultPosition, size=wx.Size(300, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 self.Center()
 self.panel = wx.Panel(self)
 self.panel.SetBackgroundColour('white')
 
 wx.StaticText(self.panel, -1, "派送员编号:", (20, 20))
 self.t1 = wx.TextCtrl(self.panel, pos=(20, 50), size=(120, 25))
 
 wx.StaticText(self.panel, -1, "买家电话:", (20, 90))
 self.t2 = wx.TextCtrl(self.panel, pos=(20, 120), size=(120, 25))
 
 def OnClick(self, e):
 dialog53 = MyDialog53(None)
 btn = wx.Button(parent=dialog53.panel, label="取消配送", pos=(20, 170), size=(90, 40))
 btn.Bind(wx.EVT_BUTTON, dialog53.delete)
 dialog53.ShowModal()
 
 def delete(self, e):
 conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = conn.cursor()
 
 courier_id = self.t1.GetValue().encode('utf8') # 注意GetValue()获取的是unicode编码
 student_phone = self.t2.GetValue().encode('utf8')
 data = (courier_id, student_phone)
 
 try:
  sql = "delete from delivery where courier_id=%s and student_phone=%s"
  cursor.execute(sql, data)
  conn.commit()
  dial = wx.MessageDialog(None, '成功取消配送!', '结果', wx.YES_NO) # 创建一个带按钮的对话框, 语法是(self, 内容, 标题, ID)
  dial.ShowModal() # 显示对话框
 except:
  conn.rollback()
 finally:
  cursor.close()
  conn.close()
 
if __name__ == "__main__":
 app = wx.App()
 MyFrame1(None).Show()
 app.MainLoop()

程序演示:

(1)店铺信息

python实现外卖信息管理系统

(2)店铺上架

python实现外卖信息管理系统

python实现外卖信息管理系统

python实现外卖信息管理系统

(3)店铺下架

python实现外卖信息管理系统

(4)派送员信息

python实现外卖信息管理系统

(5)订单信息

python实现外卖信息管理系统

(6)买家订餐

python实现外卖信息管理系统

(7)修改订单

python实现外卖信息管理系统

查看订单信息确认已经修改

 python实现外卖信息管理系统

至此python借助pymysql操作Mysql数据库的增、删、改、查功能演示完毕,剩下功能不一一截图,原理类似。

五、总结

通过本次课程设计,我对本学期所学的“数据库”和python内容有了更深一层的理解和学习。对数据库的认识不再仅仅停留在课本的理论知识上,能够更加清楚的理解其后台的操作流程。对python的应用不再局限于编写简单小程序,而是做到了与数据库进行连接,通过wxpython前台窗口,对数据库传入相应的sql语句,从而实现数据库的插入、修改、增加、删除等操作,实现sql语句的前台明了化。在设计E-R图时,采用了Navicat for mysql这一针对mysql的可视化工具,使得表与表之间的关系得以清晰的呈现,这次课程设计使我获益匪浅,在巩固与拓展知识的同时,还学会了许多工具的使用,这对以后的开发提供了宝贵的经验和基石。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/xiongwanfeng/article/details/78087174