使用wxPython开发订单管理系统-订单输入页面

该代码实现了一个使用wxPython库创建的GUI应用程序,用于输入订单信息。界面包括客户、调度单号、线路、车型等字段,以及进仓费、停车费等其他费用的输入框。用户可以选择从预定义的列表中选取数据,如税率、车辆型号等。此外,还包含了数据导入、查询和保存功能。
摘要由CSDN通过智能技术生成

主要涉及知识:
wx.StaticBox,wx.BoxSizer,wx.StaticBoxSizer,wx.StaticText,wx.TextCtrl,wx.Choice,wx.Button,wx.MessageBox
代码:

import wx
import time
import sqlite3
import datetime
import cal
import query
from sqloperation import  create_db,insert_db
info_fields="ID INTEGER PRIMARY KEY AUTOINCREMENT, 日期 DATE,客户 TEXT,调度单号 TEXT, 线路 TEXT, 车型 TEXT ,书号 TEXT, 车辆信息 TEXT,\
                              驾驶员 TEXT,调度 TEXT,税前运费 REAL default 0, 含税运费 REAL default 0,税前其它 REAL default 0,含税其它费用 REAL default 0, \
                              运费客户计 REAL default 0 ,运费来源文件 TEXT ,其它费用客户计 REAL default 0,\
                              其它费用来源文件 TEXT, 费用差异 REAL ,是否结案 TEXT default False,关联 REAL default 0 ,\
                              进仓费 REAL default 0,停车费 REAL default 0,换托盘 REAL default 0,买标签 REAL default 0 ,送货费 REAL default 0 ,\
                              压车费 REAL default 0 ,垫付费用  REAL default 0,给司机费用  REAL default 0"

def open_file(file):
    with open(file,"r",encoding="utf-8") as f:
        return f.readlines()
    
line=open_file(".//constant//路线.txt")
tax_rate=open_file(".//constant//税率.txt")
truck=open_file(".//constant//车辆型号.txt")
truckid=open_file(".//constant//车牌.txt")
driver=open_file(".//constant//司机.txt")
coordinator=open_file(".//constant//调度员.txt")
customer=open_file(".//constant//客户.txt")

class MyFrame(wx.Frame):
    
    def __init__(self,user,parent,id=-1):
          self.user=user
          wx.Frame.__init__ (self,parent,id,title="订单信息输入_"+self.user,pos=(300,50),size=(800,650))#,name='frame') #如果是顶级窗口,这个值是None,id=-1自动生成 ,name框架内的文字
          self.locale = wx.Locale(wx.LANGUAGE_CHINESE_SIMPLIFIED)
          self.panel=wx.Panel(self)   #panel 实例

          icon = wx.Icon('smart.ico')
          self.SetIcon(icon)          

          box2 = wx.StaticBox(self.panel, -1, "其它费用备注",)
          bsizer2 = wx.StaticBoxSizer(box2, wx.VERTICAL)
          
          bsubh=wx.BoxSizer(wx.HORIZONTAL)          
          self.other_l1= wx.StaticText(self.panel, -1,"关联",style=wx.TE_RIGHT)
          self.other_l2 = wx.StaticText(self.panel, -1, "进仓费",style=wx.TE_RIGHT)
          self.other_l3 = wx.StaticText(self.panel, -1, "停车费",style=wx.TE_RIGHT)
          self.other_l4 = wx.StaticText(self.panel, -1, "换托盘",style=wx.TE_RIGHT)
          self.other_t1=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t2=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t3=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t4=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t1.SetValue('0')
          self.other_t2.SetValue('0')          
          self.other_t3.SetValue('0')
          self.other_t4.SetValue('0')
          
          bsubh.Add(self.other_l1, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_t1, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_l2, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_t2, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_l3, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_t3, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_l4, 1, wx.EXPAND|wx.ALL, 5)
          bsubh.Add(self.other_t4, 1, wx.EXPAND|wx.ALL, 5)



          bsubh1=wx.BoxSizer(wx.HORIZONTAL)
          
          self.other_l5 = wx.StaticText(self.panel, -1,"买标签",style=wx.TE_RIGHT)
          self.other_l6= wx.StaticText(self.panel, -1, "送货费",style=wx.TE_RIGHT)
          self.other_l7= wx.StaticText(self.panel, -1, "压车费",style=wx.TE_RIGHT)
          self.other_l8 = wx.StaticText(self.panel, -1, "垫付费用",style=wx.TE_RIGHT)
          self.other_t5=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t6=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t7=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t8=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.other_t5.SetValue('0')          
          self.other_t6.SetValue('0')          
          self.other_t7.SetValue('0')
          self.other_t8.SetValue('0')


          bsubh1.Add(self.other_l5, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_t5, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_l6, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_t6, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_l7, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_t7, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_l8, 1, wx.EXPAND|wx.ALL, 5)
          bsubh1.Add(self.other_t8, 1, wx.EXPAND|wx.ALL, 5)
          
          bsizer2.Add(bsubh, 1, wx.EXPAND|wx.LEFT, 10) 
          bsizer2.Add(bsubh1, 1, wx.EXPAND|wx.LEFT, 10)

          
          self.bt_confirm=wx.Button(self.panel,label="确定")  #创建按钮
          self.bt_confirm.Bind(wx.EVT_BUTTON,self.OnclickSubmit)          
       
      

          self.bt_input=wx.Button(self.panel,label="数据导入")
          bitmap=wx.Bitmap("pic//input.png")
          self.bt_input.SetBitmap(bitmap)   
          self.bt_input.Bind(wx.EVT_BUTTON,self.Onclickfoward)       
          self.bt_query=wx.Button(self.panel,label="数据查询")
          bitmap=wx.Bitmap("pic//check.png")
          self.bt_query.SetBitmap(bitmap)   
          self.bt_query.Bind(wx.EVT_BUTTON,self.OnclickQuery)  
          


          self.label_customer=wx.StaticText( self.panel,label="客户:")
          self.text_customer=wx.Choice(self.panel, -1, choices=customer) #相当于tkinter的Entry          
          self.text_customer.SetSelection(1)
          
          self.label_order=wx.StaticText( self.panel,label="订单:")
          self.text_order=wx.TextCtrl( self.panel,style=wx.TE_LEFT)  
          self.text_order.SetToolTip("请输入15位订单号")  

          self.label_line=wx.StaticText( self.panel,label="线路:")
          self.text_line=wx.Choice(self.panel, -1, choices=line)
          self.text_line.SetSelection(0)
          
          self.label_truck=wx.StaticText( self.panel,label="车型:")
          self.text_truck=wx.Choice(self.panel, -1, choices=truck)
          self.text_truck.SetSelection(0)          

          self.label_truck_id=wx.StaticText( self.panel,label="车牌:")
          self.text_truck_id=wx.Choice(self.panel, -1, choices=truckid)
          self.text_truck_id.SetSelection(0)          


          
          self.label_cer=wx.StaticText( self.panel,label="证书书号:")
          self.text_cer=wx.TextCtrl( self.panel,style=wx.TE_LEFT)

          self.label_driver=wx.StaticText( self.panel,label="驾驶员:")
          self.text_driver=wx.Choice(self.panel, -1, choices=driver)
          self.text_driver.SetSelection(1)
          
          self.label_coordinator=wx.StaticText( self.panel,label="调度:")
          self.text_coordinator=wx.Choice(self.panel, -1, choices=coordinator)
          self.text_coordinator.SetSelection(0)
          
          self.label_freight=wx.StaticText( self.panel,label="运费:")
          self.text_freight=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.text_freight.SetValue('0')
          self.label_taxrate=wx.StaticText( self.panel,label="税率:")


          self.text_taxrate=wx.Choice(self.panel, -1, choices=tax_rate)
          self.text_taxrate.SetSelection(1)
          self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.text_taxrate) 
                 

          self.label_others=wx.StaticText( self.panel,label="其它费用:")
          self.text_others=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.text_others.SetValue('0')
          self.label_othertax=wx.StaticText( self.panel,label="其它费用税率:")

          self.text_othertax=wx.Choice(self.panel, -1, choices=tax_rate)
          self.text_othertax.SetSelection(0)
          self.Bind(wx.EVT_CHOICE, self.EvtOther,self.text_othertax)

          self.label_todriver=wx.StaticText( self.panel,label="给司机费用:")
          self.text_todriver=wx.TextCtrl( self.panel,style=wx.TE_LEFT)
          self.text_todriver.SetValue('0')
          
          
          hsizer_0=wx.BoxSizer(wx.HORIZONTAL)#控件横向排列
          hsizer_0.Add(self.label_customer,proportion=0,flag=wx.ALL,border=5)  #hsizer_user横向第一行
          hsizer_0.Add(self.text_customer,proportion=1,flag=wx.ALL,border=5)  #proportion=0表示不变,proportion=1两倍宽度
          
          hsizer_1=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_1.Add(self.label_order,proportion=0,flag=wx.ALL,border=5)  
          hsizer_1.Add(self.text_order,proportion=1,flag=wx.ALL,border=5)  

          hsizer_2=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_2.Add(self.label_line,proportion=0,flag=wx.ALL,border=5)  
          hsizer_2.Add(self.text_line,proportion=1,flag=wx.ALL,border=5)  
          
          hsizer_3=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_3.Add(self.label_truck,proportion=0,flag=wx.ALL,border=5)  
          hsizer_3.Add(self.text_truck,proportion=1,flag=wx.ALL,border=5)  

          hsizer_3_add=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_3_add.Add(self.label_truck_id,proportion=0,flag=wx.ALL,border=5)  
          hsizer_3_add.Add(self.text_truck_id,proportion=1,flag=wx.ALL,border=5)  



          hsizer_4=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_4.Add(self.label_cer,proportion=0,flag=wx.ALL,border=5)
          hsizer_4.Add(self.text_cer,proportion=1,flag=wx.ALL,border=5)   


          hsizer_5=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_5.Add(self.label_driver,proportion=0,flag=wx.ALL,border=5)
          hsizer_5.Add(self.text_driver,proportion=1,flag=wx.ALL,border=5)


          hsizer_6=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_6.Add(self.label_coordinator,proportion=0,flag=wx.ALL,border=5)
          hsizer_6.Add(self.text_coordinator,proportion=1,flag=wx.ALL,border=5)


          hsizer_7=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_7.Add(self.label_freight,proportion=0,flag=wx.ALL,border=5)
          hsizer_7.Add(self.text_freight,proportion=1,flag=wx.ALL,border=5)
          hsizer_7.Add(self.label_taxrate,proportion=0,flag=wx.ALL,border=5)
          hsizer_7.Add(self.text_taxrate,proportion=1,flag=wx.ALL,border=5)


          hsizer_8=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_8.Add(self.label_others,proportion=0,flag=wx.ALL,border=5)
          hsizer_8.Add(self.text_others,proportion=1,flag=wx.ALL,border=5)
          hsizer_8.Add(self.label_othertax,proportion=0,flag=wx.ALL,border=5)
          hsizer_8.Add(self.text_othertax,proportion=1,flag=wx.ALL,border=5)


          hsizer_9=wx.BoxSizer(wx.HORIZONTAL)
          hsizer_9.Add(self.label_todriver,proportion=0,flag=wx.ALL,border=5)
          hsizer_9.Add(self.text_todriver,proportion=1,flag=wx.ALL,border=5)


          hsizer_button=wx.BoxSizer(wx.HORIZONTAL)   
          hsizer_button.Add(self.bt_query,proportion=0,flag=wx.ALIGN_RIGHT,border=5)
          hsizer_button.Add(self.bt_input,proportion=0,flag=wx.ALIGN_LEFT,border=5)  #|wx.LEFT|wx.RIGHT
          
          
    
          hx=wx.BoxSizer(wx.HORIZONTAL)
          hx.Add(self.bt_confirm,proportion=1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=0)

          vsizer_all=wx.BoxSizer(wx.VERTICAL)
          vsizer_all.Add(hsizer_0,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_1,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_2,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_3,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_3_add,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_4,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_5,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_6,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_7,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_8,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(bsizer2, proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(hsizer_9,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=45)
          vsizer_all.Add(self.bt_confirm,proportion=0, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=45)
     
          vsizer_all.AddSpacer(30)

          vsizer_all.Add(hsizer_button,proportion=0,flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT,border=45)

 
          self.panel.SetSizer(vsizer_all)
          
          
    def EvtChoice(self, evt):
           '''cb = evt.GetEventObject()
           data = cb.GetClientData(evt.GetSelection())
           print("data",data )'''
           print(self.text_taxrate.GetSelection())

    def EvtOther(self, evt):
           '''cb = evt.GetEventObject()
           data = cb.GetClientData(evt.GetSelection())
           print("data",data )'''
           print(self.text_othertax.GetSelection())


    def EvtComboBox(self, evt):
           cb = evt.GetEventObject()
           data = cb.GetClientData(evt.GetSelection())
           data1=cb.GetValue()
           print("data",data1 )
   
          
    def OnclickSubmit(self,event):                
          try:
              customer_selected=customer[self.text_customer.GetSelection()].strip()
              line_selected=line[self.text_line.GetSelection()].strip()
              if customer and line_selected:
                  order=self.text_order.GetValue()
                  truck_selected=truck[self.text_truck.GetSelection()].strip()
                  certification=self.text_cer.GetValue()
                  truck_id_selected=truckid[self.text_truck_id.GetSelection()].strip()   #strip()消除换行符
                  driver_selected=driver[self.text_driver.GetSelection()].strip()
                  coordinator_selected=coordinator[self.text_coordinator.GetSelection()].strip()
                  freight_tax=tax_rate[self.text_taxrate.GetSelection()].strip()
                  other_tax=tax_rate[self.text_othertax.GetSelection()].strip()

                  
                  other1=self.other_t1.GetValue()
                  other2=self.other_t2.GetValue()
                  other3=self.other_t3.GetValue()
                  other4=self.other_t4.GetValue()
                  other5=self.other_t5.GetValue()
                  other6=self.other_t6.GetValue()
                  other7=self.other_t7.GetValue()
                  other8=self.other_t8.GetValue()

                  freight=self.text_freight.GetValue()                
                  freight_with_tax='{0:.2f}'.format(float(freight)*(1+float(freight_tax[:-1])/100)) #将百分比文本转换成数字
                  #print(" freight_with_tax", freight_with_tax)
                  
                  others=self.text_others.GetValue()                  
                  other_with_tax='{0:.2f}'.format(float(others)*(1+float(other_tax[:-1])/100))
                  #print("other_with_tax",other_with_tax)

                  todrivers=self.text_todriver.GetValue()

                  today=(datetime.datetime.now()).strftime("%Y-%m-%d")   #日期格式转换
                  
                  #print(order,line_selected,truck_selected,certification,driver_selected,coordinator_selected,  freight_with_tax,other_with_tax)
                  table_name="费用明细"
                  fields= "日期,客户,调度单号, 线路 , 车型  ,依赖书号, 车辆信息 ,驾驶员 ,调度, 税前运费, 含税运费 ,税前其它,含税其它费用,关联,进仓费,停车费,换托盘,买标签,送货费,压车费,垫付费用,给司机费用"
                  values=str(tuple([today,customer_selected,order,line_selected,truck_selected,certification,truck_id_selected,driver_selected,\
                                    coordinator_selected, float(freight),freight_with_tax,others,other_with_tax,other1,other2,other3,other4,other5,other6,other7,other8,todrivers]))
                  
                  msg=wx.MessageBox("确认保存如下数据"+values, "保存数据",wx.YES_NO) # | wx.CANCEL
                         
                  if msg== wx.YES:
                      create_db("费用明细",info_fields)
                      insert_db("费用明细",fields,values)
                      message='数据已保存'
                      wx.MessageBox(message)
                                    
                  else:
                      message='数据未保存'
                      wx.MessageBox(message)
              else:
                  wx.MessageBox("请输入客户和线路")

          except Exception as e:
               wx.MessageBox(str(e))
    
    def Onclickfoward(self,event):
          self.panel.Parent.Hide()
          frame=cal.MyCal("usertest",parent=None,id=-1)  #导入新窗体
          frame.Show()

    def  OnclickQuery(self,event):
          self.panel.Parent.Hide()
          frame=query.MyFrame("usertest",parent=None)  #导入新窗体
          frame.Show()
      
if __name__=="__main__":
    app=wx.App()     
    frame=MyFrame("usertst",parent=None)
    frame.Show()
    app.MainLoop()

在这里插入图片描述

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值