SoFunction
Updated on 2024-10-30

python implementation of takeaway information management system

In this article, we share the specific code of python implementation of takeaway information management system for your reference, the details are as follows

I. Needs analysis

The requirements analysis contains the following:

1. Description of the problem

Login to the system as the administrator of the takeaway information system to realize the functions of conditional query and information entry, modification and deletion of store information, dispatcher information, customer service personnel information, order information and delivery information.

2、System function description

(1) Information entry: use wxpython design and layout to write the window interface, give the interface for entering information, and realize the connection with the database through python statements, so as to insert the corresponding data into the database.

(2) Information modification: use wxpython design and layout to write the window interface, give the interface to modify the information, and realize the connection with the database through python statements, so as to modify the corresponding data in the database.

(3) Information query: In the window interface, triggered by the response button, it realizes the connection query with the database to get all the online store information.

(4) statistics: write the appropriate stored procedures in the database, enter the name of the store can select its management of the dispatcher and customer service personnel.

3、System function module diagram

II. Conceptual structural design

E-R modeling of the system as a whole:

III. Logical structure design

The table structures used in this system and their linkages:

1、Store basic information foodshop table

 

Primary key: shop_name

2、Basic customer service information server table

Primary key: server_id

Foreign key: shopname_shop_name

Reference table: shopname Reference property: shop_name

3、Dispatchers basic information courier table

 

Primary key: courier_id

Foreign key: shopname_shop_name

Reference table: shopname Reference property: shop_name

4、Basic information of studentsstudent table

 

Primary key: student_phone

5. Order basic information book form

 

Primary key: (student_phone, server_id)

Foreign key: student_phone, reference table student, reference attribute student_phone

Foreign key: server_id, reference table server, reference attribute server_id

6、Delivery of basic information delivery table

Primary key: (student_phone, courier_id)

Foreign key: student_phone, reference table student, reference attribute student_phone

Foreign key: courier_id, reference table courier, reference attribute courier_id

IV. Concrete realization

Login screen:

The source code is attached:

# coding:utf8

###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## /
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx # Import wxpyhton, pyhton's own GUI library
#import 

import pymysql # Used to manipulate databases
import sys
reload(sys)
('utf8')

###########################################################################
## Class MyFrame1
###########################################################################

# Create a window class MyFrame1 and inherit it.
class MyFrame1():
 def __init__(self, parent):
 # (parent, id, title, pos, size, style, name)
 .__init__(self, parent, id=wx.ID_ANY, title=u"Takeaway information management system", pos=, size=(610, 400),
    style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
 () # Centering

 # Small artifacts such as buttons, text boxes, etc. are placed in panel windows. Classes are usually placed in a wxFrame object. This class also inherits from the wxWindow class.
 self.m_panel1 = (self)
 # label, one or more lines of read-only text, (parent, id, label, position, size, style)
 self.m_staticText1 = (self.m_panel1, wx.ID_ANY, u"About the store:", (20, 20))
 self.m_button1 = (self.m_panel1, wx.ID_ANY, u"Store Information", (130, 20), ,
     style=wx.BORDER_MASK)
 self.m_button2 = (self.m_panel1, wx.ID_ANY, u"Store shelves", (250, 20), ,
     style=wx.BORDER_MASK)
 self.m_button3 = (self.m_panel1, wx.ID_ANY, u"Shop off the shelves.", (370, 20), ,
     style=wx.BORDER_MASK)

 self.m_staticText2 = (self.m_panel1, wx.ID_ANY, u"Regarding dispatchers:", (20, 90))
 self.m_button4 = (self.m_panel1, wx.ID_ANY, u"Dispatcher information", (130, 90), ,
     style=wx.BORDER_MASK)
 self.m_button5 = (self.m_panel1, wx.ID_ANY, u"Hire a dispatcher.", (250, 90), ,
     style=wx.BORDER_MASK)
 self.m_button6 = (self.m_panel1, wx.ID_ANY, u"Sack the delivery man.", (370, 90), ,
     style=wx.BORDER_MASK)

 self.m_staticText3 = (self.m_panel1, wx.ID_ANY, u"About Customer Service:", (20, 160))
 self.m_button7 = (self.m_panel1, wx.ID_ANY, u"Customer Service Information", (130, 160), ,
     style=wx.BORDER_MASK)
 self.m_button8 = (self.m_panel1, wx.ID_ANY, u"Hire a customer service agent.", (250, 160), ,
     style=wx.BORDER_MASK)
 self.m_button9 = (self.m_panel1, wx.ID_ANY, u"Firing of customer service agents.", (370, 160), ,
     style=wx.BORDER_MASK)

 self.m_staticText4 = (self.m_panel1, wx.ID_ANY, u"Regarding orders:", (20, 230))
 self.m_button10 = (self.m_panel1, wx.ID_ANY, u"Order Information", (130, 230), ,
     style=wx.BORDER_MASK)
 self.m_button11 = (self.m_panel1, wx.ID_ANY, u"Student Meal Ordering", (250, 230), ,
     style=wx.BORDER_MASK)
 self.m_button12 = (self.m_panel1, wx.ID_ANY, u"Cancel Order", (370, 230), ,
     style=wx.BORDER_MASK)
 self.m_button13 = (self.m_panel1, wx.ID_ANY, u"Modify Order", (490, 230), ,
     style=wx.BORDER_MASK)

 self.m_staticText5 = (self.m_panel1, wx.ID_ANY, u"On logistics:", (20, 300))
 self.m_button14 = (self.m_panel1, wx.ID_ANY, u"Distribution information", (130, 300), ,
     style=wx.BORDER_MASK)
 self.m_button15 = (self.m_panel1, wx.ID_ANY, u"Arranging for distribution", (250, 300), ,
     style=wx.BORDER_MASK)
 self.m_button16 = (self.m_panel1, wx.ID_ANY, u"Delivery canceled.", (370, 300), ,
     style=wx.BORDER_MASK)


 # Button Binding Dialog Popup
 # When creating an application, the Bind function can bind the button's action to a specific function that fires when an action is taken on the button, thus handling the response event.
 The EVT_BUTTON event occurs when the #Button is clicked.
 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)

 # Set the background color of the buttons
 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') # Set the background color of the panel


###########################################################################
## Class MyDialog11
###########################################################################

# A dialog box class inherits
class MyDialog11():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Store Information", pos=, size=(302, 362),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Store name", (20, 20))
 (, -1, "Monthly sales", (80, 20))

 def OnClick(self, event):

 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()
 try:
  sql = "select * from foodshop"
  (sql)
  rs = ()
  h = 30
  for row in rs:
  h = h + 20
  shop_name = row[0]
  salenum = row[1] # Note the way the data in the database is read when it is of type numeric int id = '%d' % i[0]
  (, -1, shop_name, (20, h))
  (, -1, salenum, (80, h))
 except:
  ()
 finally:
  ()
  ()

 ()


###########################################################################
## Class MyDialog12
###########################################################################

class MyDialog12():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Store shelves", pos=, size=(302, 250),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the name of the store:", (20, 20))
 # Creation and use of editable text boxes, which by default can only edit one line of text (no line breaks no matter how long the text is)
 self.t1 = (, pos=(130, 20), size=(120, 25))

 (, -1, "Please enter monthly sales:", (20, 80))
 self.t2 = (, pos=(130, 80), size=(120, 25))


 def OnClick(self, e):
 dialog12 = MyDialog12(None)
 btn = (parent=, label="On the shelf.", pos=(20, 150), size=(100, 45), style=wx.BORDER_MASK)
 (wx.EVT_BUTTON, )
 ()

 def insert(self, event):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 shop_name = self.().encode('utf8') # Note that GetValue() gets the unicode encoding.
 salenum = self.().encode('utf8') #You are using #coding=utf8, then re-encode the fetched data .encode('utf8')
 data = (shop_name, salenum)

 try:
  sql = "insert into foodshop values (%s,%s)"
  (sql, data)
  () # Submitted to backend database
  dial = (None, 'Successfully on the shelf!', 'Results', wx.YES_NO) # Create a message box with a button, syntax is (self, box content, box title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()

###########################################################################
## Class MyDialog13
###########################################################################

class MyDialog13():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Shop off the shelves.", pos=, size=(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Store name:", (20, 20))
 self.t1 = (, pos=(20, 50), size=(120, 25))


 def OnClick(self, e):
 dialog13 = MyDialog13(None)
 btn = (parent=, label="Off the Shelf", pos=(20, 90), size=(90, 40))
 (wx.EVT_BUTTON, )
 ()

 def delete(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 shop_name = self.().encode('utf8') # Note that GetValue() gets the unicode code.
 try:
  sql = "delete from foodshop where shop_name=%s"
  (sql, shop_name)
  ()
  dial = (None, 'Successfully off the shelf!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()

###########################################################################
## Class MyDialog21
###########################################################################

class MyDialog21():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Dispatcher information", pos=, size=(400, 415),
    style=wx.DEFAULT_DIALOG_STYLE)

 ()
  = (self)
 ('white')

 (, -1, "Store name:", (20, 20))
 self.t1 = (, pos=(90, 20), size=(120, 25))
 #btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 #(wx.EVT_BUTTON, )
 (, -1, "Dispatcher number", (20, 60))
 (, -1, "Name of dispatcher", (120, 60))
 (, -1, "Dispatcher's phone.", (220, 60))

 def OnClick(self, event):
 dialog21 = MyDialog21(None)
 btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 (wx.EVT_BUTTON, )
 ()

 def find(self, event):
 '''
 if self.() == 'KFC':
  (, -1, 'Dispatcher number', (20, h))
  (, -1, 'Name of dispatcher', (120, h))
 '''
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()
 try:
  sql = "select * from courier"
  (sql)
  rs = ()
  h = 80
  for row in rs:
  if row[3] == self.():
   h = h + 20
   courier_id = row[0]
   courier_name = row[1]
   courier_phone = row[2]
   (, -1, courier_id, (20, h))
   (, -1, courier_name, (120, h))
   (, -1, courier_phone, (220, h))
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog22
###########################################################################

class MyDialog22():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Hire a dispatcher.", pos=, size=(400, 350),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the name of the store:", (20, 20))
 self.t1 = (, pos=(140, 20), size=(120, 25))

 (, -1, "Please enter the dispatcher number:", (20, 80))
 self.t2 = (, pos=(140, 80), size=(120, 25))

 (, -1, "Please enter the name of the dispatcher:", (20, 140))
 self.t3 = (, pos=(140, 140), size=(120, 25))

 (, -1, "Please enter the dispatcher's phone number:", (20, 200))
 self.t4 = (, pos=(140, 200), size=(120, 25))

 def OnClick(self, e):
 dialog22 = MyDialog22(None)
 btn = (parent=, label="Hire.", pos=(20, 250), size=(100, 45))
 (wx.EVT_BUTTON, )
 ()

 def insert(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 shop_name = self.().encode('utf8') # Note that GetValue() gets the unicode encoding.
 courier_id = self.().encode('utf8') # You're using #coding=utf8, then .encode('utf8') on the fetched data
 courier_name = self.().encode('utf8')
 courier_phone = self.().encode('utf8')

 data = (courier_id, courier_name, courier_phone, shop_name)

 try:
  sql = "insert into courier values (%s,%s,%s,%s)"
  (sql, data)
  ()
  dial = (None, 'Successfully hired dispatchers!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog23
###########################################################################

class MyDialog23():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Sack the delivery man.", pos=, size=(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Dispatcher number:", (20, 20))
 self.t1 = (, pos=(20, 50), size=(120, 25))

 def OnClick(self, e):
 dialog23 = MyDialog23(None)
 btn = (parent=, label="Dismissal.", pos=(20, 90), size=(90, 40))
 (wx.EVT_BUTTON, )
 ()

 def delete(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 courier_id = self.().encode('utf8') # Note that GetValue() gets the unicode code.
 try:
  sql = "delete from courier where courier_id=%s"
  (sql, courier_id)
  ()
  dial = (None, 'Successfully fired the dispatcher!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog31
###########################################################################

class MyDialog31():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Customer Service Information", pos=, size=(400, 401),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Store name:", (20, 20))
 self.t1 = (, pos=(90, 20), size=(120, 25))
 # btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 # (wx.EVT_BUTTON, )
 (, -1, "Customer Service Number", (20, 60))
 (, -1, "Name of customer service agent", (120, 60))

 def OnClick(self, e):
 dialog31 = MyDialog31(None)
 btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 (wx.EVT_BUTTON, )
 ()

 def find(self, event):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()
 try:
  sql = "select * from server"
  (sql)
  rs = ()
  h = 80
  for row in rs:
  if row[2] == self.():
   h = h + 20
   server_id = row[0]
   server_name = row[1]
   (, -1, server_id, (20, h))
   (, -1, server_name, (120, h))
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog32
###########################################################################

class MyDialog32():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Hire a customer service agent.", pos=, size=(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the name of the store:", (20, 20))
 self.t1 = (, pos=(160, 20), size=(120, 25))

 (, -1, "Please enter the customer service number:", (20, 80))
 self.t2 = (, pos=(160, 80), size=(120, 25))

 (, -1, "Please enter the name of the customer service agent:", (20, 140))
 self.t3 = (, pos=(160, 140), size=(120, 25))


 def OnClick(self, e):
 dialog32 = MyDialog32(None)
 btn = (parent=, label="Hire.", pos=(20, 200), size=(100, 45))
 (wx.EVT_BUTTON, )
 ()

 def insert(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 shop_name = self.().encode('utf8') # Note that GetValue() gets the unicode encoding.
 server_id = self.().encode('utf8') # You're using #coding=utf8, then .encode('utf8') on the fetched data
 server_name = self.().encode('utf8')

 data = (server_id, server_name, shop_name)

 try:
  sql = "insert into server values(%s,%s,%s)"
  (sql, data)
  ()
  dial = (None, 'Successfully hired customer service!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog33
###########################################################################

class MyDialog33():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Firing of customer service agents.", pos=, size=(200, 200),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Customer Service Number:", (20, 20))
 self.t1 = (, pos=(20, 50), size=(120, 25))

 def OnClick(self, e):
 dialog33 = MyDialog33(None)
 btn = (parent=, label="Dismissal.", pos=(20, 90), size=(90, 40))
 (wx.EVT_BUTTON, )
 ()

 def delete(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 server_id = self.().encode('utf8') # Note that GetValue() gets the unicode code.
 try:
  sql = "delete from server where server_id=%s"
  (sql, server_id)
  ()
  dial = (None, 'Successfully fired customer service!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog41
###########################################################################

class MyDialog41():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Order Information", pos=, size=(500, 400),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Buyer's phone number:", (20, 20))
 self.t1 = (, pos=(90, 20), size=(120, 25))
 # btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 # (wx.EVT_BUTTON, )
 (, -1, "Customer Service Number", (20, 60))
 (, -1, "Order number", (120, 60))
 (, -1, "Order amount", (220, 60))
 (, -1, "Ordering Methods", (320, 60))

 def OnClick(self, e):
 dialog41 = MyDialog41(None)
 btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 (wx.EVT_BUTTON, )
 ()

 def find(self, event):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()
 try:
  sql = "select * from book"
  (sql)
  rs = ()
  h = 80
  for row in rs:
  if row[0] == self.():
   h = h + 20
   server_id = row[1]
   order_id = row[2]
   order_money = row[3]
   order_way = row[4]
   (, -1, server_id, (20, h))
   (, -1, order_id, (120, h))
   (, -1, order_money, (220, h))
   (, -1, order_way, (320, h))
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog42
###########################################################################

class MyDialog42():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Student Meal Ordering", pos=, size=(400, 400),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the buyer's phone number:", (20, 20))
 self.t1 = (, pos=(150, 20), size=(120, 25))

 (, -1, "Please enter the customer service number:", (20, 80))
 self.t2 = (, pos=(150, 80), size=(120, 25))

 (, -1, "Please enter the order number:", (20, 140))
 self.t3 = (, pos=(150, 140), size=(120, 25))

 (, -1, "Please enter the order amount:", (20, 200))
 self.t4 = (, pos=(150, 200), size=(120, 25))

 (, -1, "Please enter the ordering method:", (20, 260))
 self.t5 = (, pos=(150, 260), size=(120, 25))

 def OnClick(self, e):
 dialog42 = MyDialog42(None)
 btn = (parent=, label="Ordering.", pos=(20, 310), size=(100, 45))
 (wx.EVT_BUTTON, )
 ()

 def insert(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 student_phone = self.().encode('utf8') # Note that GetValue() gets the unicode encoding.
 server_id = self.().encode('utf8') # You're using #coding=utf8, then .encode('utf8') on the fetched data
 order_id = self.().encode('utf8')
 order_money = self.().encode('utf8')
 order_way = self.().encode('utf8')

 data = (student_phone, server_id, order_id, order_money, order_way)

 try:
  sql = "insert into book values(%s,%s,%s,%s,%s)"
  (sql, data)
  ()
  dial = (None, 'Successful order!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog43
###########################################################################

class MyDialog43():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Delete Order", pos=, size=(300, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Customer Service Number:", (20, 20))
 self.t1 = (, pos=(20, 50), size=(120, 25))

 (, -1, "Buyer's phone number:", (20, 90))
 self.t2 = (, pos=(20, 120), size=(120, 25))

 def OnClick(self, e):
 dialog43 = MyDialog43(None)
 btn = (parent=, label="Cancel Order", pos=(20, 170), size=(90, 40))
 (wx.EVT_BUTTON, )
 ()

 def delete(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 server_id = self.().encode('utf8') # Note that GetValue() gets the unicode code.
 student_phone = self.().encode('utf8')
 data = (server_id, student_phone)

 try:
  sql = "delete from book where server_id=%s and student_phone=%s"
  (sql, data)
  ()
  dial = (None, 'Order deleted successfully!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog44
###########################################################################

class MyDialog44():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Modify Order", pos=, size=(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the customer service number:", (20, 20))
 self.t1 = (, pos=(160, 20), size=(120, 25))

 (, -1, "Please enter the buyer's phone number:", (20, 80))
 self.t2 = (, pos=(160, 80), size=(120, 25))

 (, -1, "Please correct the order amount:", (20, 140))
 self.t3 = (, pos=(160, 140), size=(120, 25))

 def OnClick(self, e):
 dialog44 = MyDialog44(None)
 btn = (parent=, label="Confirmation of changes", pos=(20, 200), size=(100, 45))
 (wx.EVT_BUTTON, )
 ()

 def change(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 server_id = self.().encode('utf8')
 student_phone = self.().encode('utf8')
 order_money = self.().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"
  (sql, data)
  ()
  dial = (None, 'Successfully modified order!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog51
###########################################################################

class MyDialog51():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Distribution information", pos=, size=(502, 362),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Buyer's phone number:", (20, 20))
 self.t1 = (, pos=(90, 20), size=(120, 25))
 # btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 # (wx.EVT_BUTTON, )
 (, -1, "Dispatcher number", (20, 60))
 (, -1, "Estimated delivery time", (120, 60))


 def OnClick(self, e):
 dialog51 = MyDialog51(None)
 btn = (parent=, label="Query", pos=(240, 20), size=(70, 25))
 (wx.EVT_BUTTON, )
 ()

 def find(self, event):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()
 try:
  sql = "select * from delivery"
  (sql)
  rs = ()
  h = 80
  for row in rs:
  if row[0] == self.():
   h = h + 20
   courier_id = row[1]
   deliver_time = row[2]
   (, -1, courier_id, (20, h))
   (, -1, deliver_time, (120, h))
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog52
###########################################################################

class MyDialog52():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Arranging for distribution", pos=, size=(400, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Please enter the buyer's phone number:", (20, 20))
 self.t1 = (, pos=(160, 20), size=(120, 25))

 (, -1, "Please enter the dispatcher number:", (20, 80))
 self.t2 = (, pos=(160, 80), size=(120, 25))

 (, -1, "Please enter estimated delivery time:", (20, 140))
 self.t3 = (, pos=(160, 140), size=(120, 25))

 def OnClick(self, e):
 dialog52 = MyDialog52(None)
 btn = (parent=, label="Distribution.", pos=(20, 200), size=(100, 45))
 (wx.EVT_BUTTON, )
 ()

 def insert(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 student_phone = self.().encode('utf8') # Note that GetValue() gets the unicode encoding.
 courier_id = self.().encode('utf8') # You're using #coding=utf8, then .encode('utf8') on the fetched data
 deliver_time = self.().encode('utf8')

 data = (student_phone, courier_id, deliver_time)

 try:
  sql = "insert into delivery values(%s,%s,%s)"
  (sql, data)
  ()
  dial = (None, 'Successfully arranged for delivery!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()


###########################################################################
## Class MyDialog53
###########################################################################

class MyDialog53():
 def __init__(self, parent):
 .__init__(self, parent, id=wx.ID_ANY, title=u"Delivery canceled.", pos=, size=(300, 300),
    style=wx.DEFAULT_DIALOG_STYLE)
 ()
  = (self)
 ('white')

 (, -1, "Dispatcher number:", (20, 20))
 self.t1 = (, pos=(20, 50), size=(120, 25))

 (, -1, "Buyer's phone number:", (20, 90))
 self.t2 = (, pos=(20, 120), size=(120, 25))

 def OnClick(self, e):
 dialog53 = MyDialog53(None)
 btn = (parent=, label="Delivery canceled.", pos=(20, 170), size=(90, 40))
 (wx.EVT_BUTTON, )
 ()

 def delete(self, e):
 conn = (host='127.0.0.1', port=3306, user='root', passwd='123', db='project', charset='utf8')
 cursor = ()

 courier_id = self.().encode('utf8') # Note that GetValue() gets the unicode code.
 student_phone = self.().encode('utf8')
 data = (courier_id, student_phone)

 try:
  sql = "delete from delivery where courier_id=%s and student_phone=%s"
  (sql, data)
  ()
  dial = (None, 'Successfully canceled delivery!', 'Results', wx.YES_NO) # Create a dialog box with buttons, syntax is (self, content, title, ID)
  () # Show dialog box
 except:
  ()
 finally:
  ()
  ()

if __name__ == "__main__":
 app = ()
 MyFrame1(None).Show()
 ()

Program Demo:

(1) Store Information

(2) Store shelves

(3) Shop down

(4) Dispatcher information

(5) Order Information

(6) Ordering of food by buyers

(7) Modification of orders

Check the order information to confirm that it has been modified

 

So far python with the help of pymysql operation Mysql database add, delete, change, check the function demonstration is complete, the rest of the function is not a screenshot, the principle is similar.

V. Summary

Through this course design, I have a deeper understanding and learning of the "database" and python content learned in this semester. Knowledge of the database is no longer only in the theoretical knowledge of the textbook, can more clearly understand the background operation process. The application of python is no longer limited to writing simple small programs, but to do with the database connection, through the wxpython foreground window, the database into the corresponding sql statement, so as to achieve the database insertion, modification, increase, delete and other operations, to achieve the foreground of the sql statement clear. In designing the E-R diagram, Navicat for mysql, a visualization tool for mysql, is used, which makes the relationship between the tables to be clearly presented. This course design has benefited me a lot, while consolidating and expanding my knowledge, I also learned to use a lot of tools, which provides valuable experience and cornerstones for future development.

More study materials are available on the topic ofManagement system development》。

This is the whole content of this article.