Advertisement
Guest User

Untitled

a guest
May 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PyCon 18.78 KB | None | 0 0
  1. '''Here is what I would like for this order form to be able to do.  I want information to be held in a data base so when
  2. a customer orders through out the year when I punch in their last name their particulars come up such as address phone
  3. number and email if they are a repeat customer.
  4.  
  5. For the order form section of the form I want drop down boxes for product for size of picture  then a drop down box for
  6. Individual or Team quantity of the order the cost of the product and for it automatically total for that line of order
  7. and also at the bottom of the order to keep a running total if they order multiple products.  So I guess you will need
  8. up to 5 lines of potential product ordering for different products.  As an example the customer might order an 8 x 10
  9. Individual, 8 Wallets, and a memory mate.  So for each one want drop down box description to pop up quantity and of
  10. course total for each product with a gross total at the bottom of the form.
  11.  
  12. I would like for this information to be contained in the database for each customer with the date of each order.
  13.  
  14. COMPLETE: Payment method.  Please have a drop down of Still Owe, Check ( and a box pop up for check number) Cash, MC, VISA, DISC,
  15. AMEX .
  16.  
  17. I think that is all I can think of right now.  Any neat things you can do with your knowledge would be great as well.
  18. If you can create my logo at the top of the form I can send you the logo.
  19.  
  20. tag_bind
  21. events
  22. bind
  23. TreeviewSelect
  24. selection
  25. '''
  26.  
  27. import tkinter as tk
  28. from tkinter import messagebox
  29. from tkinter import ttk
  30. import sqlite3
  31. import datetime
  32.  
  33. #connect to databas file
  34. fileName = 'Enter the name of the database you want to create or load'
  35. db = sqlite3.connect('example2.db')
  36. cursor = db.cursor()
  37. #constants for prices
  38. MEMORY_MATE_PRICE = 10
  39. MEMORY_MATE_8X10_PRICE = 8
  40. MEMORY_MATE_5X7_PRICE = 6
  41. MEMORY_MATE_4X6_PRICE = 4
  42. MEMORY_MATE_3X5_PRICE = 3
  43. UNCUT_WALLETS = 7
  44. KEY_CHAIN = 7
  45. MOUSE_PAD = 15
  46. FLEXIBLE_MAGNET = 8
  47.  
  48.  
  49. #stack type process for the pages, when you want to go to one raise it to the top
  50. class PhotoProjectApp(tk.Tk):
  51.     def __init__(self, *args, **kwargs):
  52.         tk.Tk.__init__(self,*args,**kwargs)
  53.         #icon and name of application
  54.         #tk.Tk.iconbitmap(self, default='PhotoProjectIco.ico')
  55.         tk.Tk.wm_title(self, "Troy's Photography")
  56.         #set up the container whhich is the Frame(window)
  57.         container = tk.Frame(self)
  58.         #pack the window and give weights to the row and columns
  59.         container.pack(side='top', fill='both', expand= True)
  60.         container.grid_rowconfigure(0, weight=1)
  61.         container.grid_columnconfigure(0, weight=1)
  62.         #dicitonary to hold the pages
  63.         self.frames = {}
  64.  
  65.         #check to see if the table name already exists in the database
  66.         cursor.execute("SELECT count(*) FROM sqlite_master WHERE name='testUsers' and type='table'")
  67.         check = cursor.fetchall()
  68.         #if it doesnt exist then create one but if it does then do nothing
  69.         if check[0][0] == 0:
  70.  
  71.             cursor.execute('''
  72.               CREATE TABLE testUsers(id INTEGER PRIMARY KEY, firstName TEXT,
  73.                                 lastName TEXT, phone TEXT, email TEXT UNIQUE,
  74.                                 address TEXT, dated TEXT, payment TEXT)
  75.  
  76.           ''')
  77.  
  78.         #for to iterate through the pages and put int the stack
  79.         for F in (StartPage, CustomerEntryPage, searchForCustomerPage, updateDatabase):
  80.  
  81.             frame = F(container, self)
  82.  
  83.             self.frames[F] = frame
  84.  
  85.             frame.grid(row=0, column=0, sticky='nsew')
  86.  
  87.         self.show_frame(StartPage)
  88.  
  89.  
  90.     def show_frame(self, cont):
  91.         frame = self.frames[cont]
  92.         frame.tkraise()
  93.  
  94. #starting home page
  95. class StartPage(tk.Frame):
  96.     def __init__(self, parent, controller):
  97.         tk.Frame.__init__(self, parent)
  98.         label = tk.Label(self, text='Start Page')
  99.         label.pack()
  100.         self.frame = None
  101.         #button to get to CustomerEntryPage
  102.         customerPageButton = ttk.Button(self, text='Customer Entry', command=lambda: controller.show_frame(CustomerEntryPage))
  103.         customerPageButton.pack()
  104.         #button to get to searchForCustomerPage
  105.         searchForCustomerButton = ttk.Button(self, text='Search For Customer', command=lambda: controller.show_frame(searchForCustomerPage))
  106.         searchForCustomerButton.pack()
  107.  
  108. #CustomerEntryPage
  109. class CustomerEntryPage(tk.Frame):
  110.     def __init__(self, parent, controller):
  111.         tk.Frame.__init__(self, parent)
  112.         #labels for customer info
  113.         self.firstName = tk.Label(self, text='First Name')
  114.         self.firstName.grid(row=0, sticky='e')
  115.         self.lastName = tk.Label(self, text='Last Name')
  116.         self.lastName.grid(row=1, sticky='e')
  117.         self.address = tk.Label(self, text='Address')
  118.         self.address.grid(row=2, sticky='e')
  119.         self.phone = tk.Label(self, text='Phone Number')
  120.         self.phone.grid(row=3, sticky='e')
  121.         self.email = tk.Label(self, text='Email')
  122.         self.email.grid(row=4, sticky='e')
  123.  
  124.         #entry boxes for customer info
  125.         self.firstName_entry = ttk.Entry(self)
  126.         self.firstName_entry.grid(row=0, column=1)
  127.         self.lastName_entry = ttk.Entry(self)
  128.         self.lastName_entry.grid(row=1, column=1)
  129.         self.address_entry = ttk.Entry(self)
  130.         self.address_entry.grid(row=2, column=1)
  131.         self.phone_entry = ttk.Entry(self)
  132.         self.phone_entry.grid(row=3, column=1)
  133.         self.email_entry = ttk.Entry(self)
  134.         self.email_entry.grid(row=4, column=1)
  135.  
  136.         startPageButton = ttk.Button(self, text='Home', command=lambda: controller.show_frame(StartPage))
  137.         startPageButton.grid(row=6, column=0)
  138.  
  139.         submitButton = ttk.Button(self, text='Submit', command=self.orderFormEntry)
  140.         submitButton.grid(row=6, column=1)
  141.  
  142.         quitButton = ttk.Button(self, text='Quit', command=quit)
  143.         quitButton.grid(row=7, column=0)
  144.  
  145.         #label and entry box
  146.         self.memoryMateLabel=ttk.Label(self, text='Memory Mate Quantity')
  147.         self.memoryMateLabel.grid(row=0, column=9)
  148.         self.memoryMate_entry = ttk.Entry(self)
  149.         self.memoryMate_entry.grid(row=0, column=10)
  150.         self.memoryMate_entry.insert('end', '0')
  151.         self.memoryMateQ = self.memoryMate_entry.get()
  152.  
  153.         #labaels for quantities
  154.         self.uncutWallet = tk.Label(self, text='Uncut Wallet quantity')
  155.         self.uncutWallet.grid(row=1, column=9, sticky='e')
  156.         self.keyChain = tk.Label(self, text='Key Chain quantity')
  157.         self.keyChain.grid(row=2, column=9, sticky='e')
  158.         self.mousePad = tk.Label(self, text='Mouse Pad quantity')
  159.         self.mousePad.grid(row=3, column=9, sticky='e')
  160.         self.flexibleMagnet = tk.Label(self, text='Flexible Magnet quantity')
  161.         self.flexibleMagnet.grid(row=4, column=9, sticky='e')
  162.         self.eightLabel = tk.Label(self, text='8x10 quantity')
  163.         self.eightLabel.grid(row=6, column=9, sticky='e')
  164.         self.fiveLabel = tk.Label(self, text='5x7 quantity')
  165.         self.fiveLabel.grid(row=7, column=9, sticky='e')
  166.         self.fourLabel = tk.Label(self, text='4x6 quantity')
  167.         self.fourLabel.grid(row=8, column=9, sticky='e')
  168.         self.threeLabel = tk.Label(self, text='3.5x5 quantity')
  169.         self.threeLabel.grid(row=9, column=9, sticky='e')
  170.  
  171.  
  172.         self.uncutWallet_entry = ttk.Entry(self)
  173.         self.uncutWallet_entry.grid(row=1, column=10)
  174.         self.uncutWallet_entry.insert('end', '0')
  175.         self.uncutWalletQ = self.uncutWallet_entry.get()
  176.  
  177.         self.keyChain_entry = ttk.Entry(self)
  178.         self.keyChain_entry.grid(row=2, column=10)
  179.         self.keyChain_entry.insert('end', '0')
  180.         self.keyChainQ = self.keyChain_entry.get()
  181.  
  182.         self.mousePad_entry = ttk.Entry(self)
  183.         self.mousePad_entry.grid(row=3, column=10)
  184.         self.mousePad_entry.insert('end', '0')
  185.         self.mousePadQ = self.mousePad_entry.get()
  186.  
  187.         self.flexibleMagnet_entry = ttk.Entry(self)
  188.         self.flexibleMagnet_entry.grid(row=4, column=10)
  189.         self.flexibleMagnet_entry.insert('end', '0')
  190.         self.flexibleMagnetQ = self.flexibleMagnet_entry.get()
  191.  
  192.         self.eight_entry = ttk.Entry(self)
  193.         self.eight_entry.grid(row=6, column=10)
  194.         self.eight_entry.insert('end', '0')
  195.         self.eight_entryQ = self.eight_entry.get()
  196.  
  197.         self.five_entry = ttk.Entry(self)
  198.         self.five_entry.grid(row=7, column=10)
  199.         self.five_entry.insert('end', '0')
  200.         self.five_entryQ = self.five_entry.get()
  201.  
  202.         self.four_entry = ttk.Entry(self)
  203.         self.four_entry.grid(row=8, column=10)
  204.         self.four_entry.insert('end', '0')
  205.         self.four_entryQ = self.four_entry.get()
  206.  
  207.         self.three_entry = ttk.Entry(self)
  208.         self.three_entry.grid(row=9, column=10)
  209.         self.three_entry.insert('end', '0')
  210.         self.three_entryQ = self.three_entry.get()
  211.  
  212.         paymentMethodList = ['Payment Method', 'Still Owe', 'Check', 'Cash', 'MC', 'VISA', 'DISC', 'AMEX']
  213.         self.payment = tk.StringVar()
  214.         self.payment.set(self)
  215.         paymentOption = ttk.OptionMenu(self, self.payment, *paymentMethodList)
  216.         paymentOption.grid(row=0, column=20, padx=100)
  217.  
  218.         self.totalLabel = ttk.Label(self, text='Total: $0')
  219.         self.totalLabel.grid(row=10, column=11)
  220.  
  221.         self.keyChainLabel = ttk.Label(self, text=' $0')
  222.         self.keyChainLabel.grid(row=2, column=11)
  223.  
  224.         self.uncutLabel = ttk.Label(self, text=' $0')
  225.         self.uncutLabel.grid(row=1, column=11)
  226.  
  227.         self.memoryMateLabel = ttk.Label(self, text=' $0')
  228.         self.memoryMateLabel.grid(row=0, column=11)
  229.  
  230.         self.mousePadLabel = ttk.Label(self, text=' $0')
  231.         self.mousePadLabel.grid(row=3, column=11)
  232.  
  233.         self.flexibleMagnetLabel = ttk.Label(self, text=' $0')
  234.         self.flexibleMagnetLabel.grid(row=4, column=11)
  235.  
  236.         self.fiveLabelTotal = ttk.Label(self, text='$0')
  237.         self.fiveLabelTotal.grid(row=7, column=11)
  238.  
  239.         self.fourLabelTotal = ttk.Label(self, text='$0')
  240.         self.fourLabelTotal.grid(row=8, column=11)
  241.  
  242.         self.eightLabelTotal = ttk.Label(self, text='$0')
  243.         self.eightLabelTotal.grid(row=6, column=11)
  244.  
  245.         self.threeLabelTotal = ttk.Label(self, text='$0')
  246.         self.threeLabelTotal.grid(row=9, column=11)
  247.  
  248.         #count to update for check number box
  249.         self.count = 0
  250.  
  251.         self.after(500, self.updateTotalPrice)
  252.  
  253.  
  254.     def updateTotalPrice(self):
  255.         total = 0
  256.         self.memoryMateT = self.memoryMate_entry.get()
  257.         self.uncutWalletT = self.uncutWallet_entry.get()
  258.         self.keyChainT = self.keyChain_entry.get()
  259.         self.mousePadT = self.mousePad_entry.get()
  260.         self.flexibleMagnetT = self.flexibleMagnet_entry.get()
  261.  
  262.  
  263.         try:
  264.             uncutWalletInt = int(self.uncutWalletT)
  265.             memoryMateInt = int(self.memoryMateT)
  266.             keyChainInt = int(self.keyChainT)
  267.             mousePadInt = int(self.mousePadT)
  268.             flexibleMagnetInt = int(self.flexibleMagnetT)
  269.  
  270.         except ValueError:
  271.             uncutWalletInt = 0
  272.             memoryMateInt = 0
  273.             keyChainInt = 0
  274.             mousePadInt = 0
  275.             flexibleMagnetInt = 0
  276.             self.errorLabel = ttk.Label(self, text='If no quantity must have 0 for quantity')
  277.             self.errorLabel.grid(row=6, column=12)
  278.  
  279.         uncutWalletTotal = uncutWalletInt*UNCUT_WALLETS
  280.         keyChainTotal = keyChainInt*KEY_CHAIN
  281.         mousePadTotal = mousePadInt*MOUSE_PAD
  282.         flexibleMagnetTotal = flexibleMagnetInt*FLEXIBLE_MAGNET
  283.         memoryMateTotal = memoryMateInt*MEMORY_MATE_PRICE
  284.  
  285.         self.total = (memoryMateTotal+uncutWalletTotal+keyChainTotal+mousePadTotal+flexibleMagnetTotal)
  286.  
  287.  
  288.         #self.uncutWalltetTotalLabel = ttk.Label(self, text='%s' % uncutWalletTotal)
  289.         #self.uncutWalltetTotalLabel.grid(row=1, column=11)
  290.  
  291.         #self.totalLabel = ttk.Label(self, text='Total: $%s' % total)
  292.         #self.totalLabel.grid(row=5, column=11)
  293.         self.totalLabel.configure(text='Total: $%s' % total)
  294.         self.memoryMateLabel.configure(text=' $%s' % memoryMateTotal)
  295.         self.uncutLabel.configure(text=' $%s' % uncutWalletTotal)
  296.         self.keyChainLabel.configure(text=' $%s' % keyChainTotal)
  297.         self.mousePadLabel.configure(text=' $%s' % mousePadTotal)
  298.         self.flexibleMagnetLabel.configure(text=' $%s' % flexibleMagnetTotal)
  299.  
  300.         try:
  301.             if self.errorLabel.winfo_exists() == 1:
  302.                 self.errorLabel.grid_forget()
  303.  
  304.         except AttributeError:
  305.             self.errorLabel = 0
  306.         check = self.payment.get()
  307.  
  308.         if check != 'Check':
  309.             self.count = 0
  310.  
  311.         if check == 'Check' and self.count == 0:
  312.             checkNumW = tk.Toplevel()
  313.             checkNumLabel = tk.Label(checkNumW, text='Check # ')
  314.             checkNumLabel.grid(row=0, column=1)
  315.             checkNum_entry = ttk.Entry(checkNumW)
  316.             checkNum_entry.grid(row=0, column=2)
  317.             self.checkNum = checkNum_entry.get()
  318.             self.count = self.count + 1
  319.             print(self.checkNum)
  320.  
  321.  
  322.  
  323.         self.after(500, self.updateTotalPrice)
  324.  
  325.     def orderFormEntry(self):
  326.         self.firstName1 = self.firstName_entry.get()
  327.         self.lastName1 = self.lastName_entry.get()
  328.         phone1 = self.phone_entry.get()
  329.         email1 = self.email_entry.get()
  330.         address1 = self.address_entry.get()
  331.         today = '%s/%s/%s' % (date.month, date.day, date.year)
  332.         paymentType = self.payment.get()
  333.  
  334.         self.uncutWalletQuantity = self.uncutWallet_entry.get()
  335.         self.memoryMateQuantity = self.memoryMate_entry.get()
  336.         self.keyChainQuantity = self.keyChain_entry.get()
  337.         self.mousePadQuantity = self.mousePad_entry.get()
  338.         self.flexibleMagnetQuantity = self.flexibleMagnet_entry.get()
  339.         self.Quantity8x10 = self.eight_entry.get()
  340.         self.Quantity5x7 = self.five_entry.get()
  341.         self.Quantity4x6 = self.four_entry.get()
  342.         self.Quantity3x5 = self.three_entry.get()
  343.  
  344.         cursor.execute('''INSERT INTO testUsers(firstName, lastName, phone, email, address, dated, payment)
  345.                       VALUES (?,?,?,?,?,?,?)''', (self.firstName1, self.lastName1, phone1, email1, address1, today, paymentType))
  346.         db.commit()
  347.  
  348.         self.orderFormDatabase()
  349.  
  350.     def orderFormDatabase(self):
  351.  
  352.  
  353.         cursor.execute("SELECT count(*) FROM sqlite_master WHERE name='orderInfo' and type='table'")
  354.         check = cursor.fetchall()
  355.         if check[0][0] == 0:
  356.             cursor.execute('''
  357.              CREATE TABLE orderInfo(id INTEGER PRIMARY KEY, MemoryMate INTEGER, eight INTEGER,
  358.                                    five INTEGER, four INTEGER, three INTEGER, uncutWallet INTEGER,
  359.                                    keyChain INTEGER, mousePad INTEGER, flexibleMagnet INTEGER)
  360.  
  361.              ''')
  362.  
  363.         cursor.execute('''INSERT INTO orderInfo(firstName, lastName, uncutWallet, orderTotal, memoryMate, keyChain, mousePad, flexibleMagnet, eight, five, four, three)
  364.                      VALUES (?,?,?,?,?,?,?,?,?,?,?,?)''', (self.firstName1, self.lastName1, self.total, self.uncutWalletQuantity, self.memoryMateQuantity, self.keyChainQuantity,self.mousePadQuantity,
  365.                                                       self.flexibleMagnetQuantity, self.Quantity8x10, self.Quantity5x7, self.Quantity4x6, self.Quantity3x5))
  366.         db.commit()
  367.         cursor.execute('''SELECT * FROM orderInfo''')
  368.         self.row = cursor.fetchall()
  369.  
  370.     def takeToOrderTable(self, event):
  371.         newTop = tk.Toplevel()
  372.         newTop.title('Database of Customers')
  373.         headings = ['First Name', 'Last Name', 'Phone', 'Email', 'Address', 'Date Ordered', 'Payment']
  374.         self.tree = ttk.Treeview(newTop, columns=headings, selectmode='extended')
  375.         self.tree.pack()
  376.         self.tree.heading('#0', text='Order History')
  377.         cursor.execute("SELECT * FROM testUsers")
  378.         row = cursor.fetchall()
  379.  
  380.         for i in headings:
  381.             self.tree.heading(i, text=i)
  382.  
  383.         for i in row:
  384.             self.tree.insert('', 'end', '', values=(i[1:8]))
  385.         customerCount = ttk.Label(newTop, text='Customers: %s' % len(row))
  386.         customerCount.pack()
  387.  
  388.  
  389.  
  390. class searchForCustomerPage(tk.Frame):
  391.     def __init__(self, parent, controller):
  392.         tk.Frame.__init__(self, parent)
  393.  
  394.         find = tk.Label(self, text='Customers Last Name')
  395.         find.grid(row=0, column=0)
  396.  
  397.         self.find_entry = tk.Entry(self)
  398.         self.find_entry.grid(row=0, column=1)
  399.  
  400.         searchSubmitButton = ttk.Button(self, text='Search', command=lambda: self.searchForCustomer())
  401.         searchSubmitButton.grid(row=1, column=0)
  402.  
  403.         startPageButton = ttk.Button(self, text='Home', command=lambda: controller.show_frame(StartPage))
  404.         startPageButton.grid(row=6, column=1)
  405.  
  406.         tableButton = ttk.Button(self, text='show table', command=lambda: self.displayCustomers())
  407.         tableButton.grid(row=10, column=10)
  408.  
  409.  
  410.     def searchForCustomer(self):
  411.         found = self.find_entry.get()
  412.         try:
  413.  
  414.             cursor.execute("SELECT * FROM testUsers WHERE lastName = ?", (found,))
  415.             row = cursor.fetchall()
  416.             for col in row:
  417.                 dataList=[col[1], col[2], col[3], col[4], col[5], col[6]]
  418.                 tk.messagebox.showinfo(title='Customer Info', message='Name: %s %s \n Phone: %s \n Email: %s \n Address: %s \n Date Ordered: %s' % (
  419.                                                                     dataList[0], dataList[1], dataList[2], dataList[3], dataList[4], dataList[5]))
  420.  
  421.         except sqlite3.Error:
  422.             tk.messagebox.showinfo(title='Not Found', message='That person is not in the Database')
  423.  
  424.  
  425.     def displayCustomers(self):
  426.         top = tk.Toplevel()
  427.         top.title('Database of Customers')
  428.         headings = ['First Name', 'Last Name', 'Phone', 'Email', 'Address', 'Date Ordered', 'Payment']
  429.         self.tree = ttk.Treeview(top, columns=headings, selectmode='extended')
  430.         self.tree.pack()
  431.         self.tree.heading('#0', text='Order History')
  432.         cursor.execute("SELECT * FROM testUsers")
  433.         row = cursor.fetchall()
  434.  
  435.         for i in headings:
  436.             self.tree.heading(i, text=i)
  437.  
  438.         for i in row:
  439.             self.tree.insert('', 'end', '', values=(i[1:8]))
  440.         customerCount = ttk.Label(top, text='Customers: %s' % len(row))
  441.         customerCount.pack()
  442.  
  443.  
  444. #If when putting customer into db they already exist have pop up message letting user know they are already in the db and
  445. #ask if they want to update the users information/product order information
  446.  
  447. class updateDatabase(tk.Frame):
  448.     def __init__(self, parent, controller):
  449.         tk.Frame.__init__(self, parent)
  450.  
  451.  
  452. app = PhotoProjectApp()
  453. app.geometry('1280x720')
  454. date = datetime.date.today()
  455. app.mainloop()
  456. db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement