Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 61.06 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. from tkinter import messagebox, StringVar
  4. from functools import partial
  5. from sqlalchemy import create_engine
  6. from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, select, Date, update
  7. metadata = MetaData()
  8.  
  9. engine = create_engine('sqlite:///sql_database:', echo=True)
  10. conn = engine.connect()
  11.  
  12. btnCRUDROW = 1
  13. ACCOUNTROW = 2
  14. PASSWORDROW = 3
  15. btnLOGINROW = 4
  16.  
  17.  
  18.  
  19. user_Info = {'admin':'pass01', 'manage':'pass02'}
  20. product_data = []
  21. class product:
  22.     def __init__(self, name, price, effectivedate, origin):
  23.         self.name = name
  24.         self.price = price
  25.         self.effectivedate = effectivedate
  26.         self.origin = origin
  27.  
  28.     def create(self):
  29.         pass
  30.     def edit(self, name, stock, price, purchase, effectivedate, origin, returns):
  31.         self.name = name
  32.         self.stock = stock
  33.         self.price = price
  34.         self.purchase = purchase
  35.         self.effectivedate = effectivedate
  36.         self.origin = origin
  37.         self.returns = returns
  38.     def remove(self):
  39.         pass
  40.  
  41.  
  42. product_table = Table(
  43.     'product_table', metadata,
  44.     Column('id', Integer, primary_key=True),
  45.     Column('name', String),
  46.     # Column('stock', String),
  47.     Column('price', Integer),
  48.     Column('effectivedate', String),
  49.     Column('origin', String),
  50.     # Column('returns', String),
  51. )
  52.  
  53. purchase_table = Table(
  54.     'purchase_table', metadata,
  55.     Column('id', Integer, primary_key=True),
  56.     Column('product_id', None, ForeignKey('product_table.id')),
  57.     Column('time', String),
  58.     Column('count', Integer),
  59.     Column('Manufacturers', String),
  60.  
  61. )
  62.  
  63. stock_table = Table(
  64.     'stock_table', metadata,
  65.     Column('id', Integer, primary_key=True),
  66.     Column('product_id', None, ForeignKey('product_table.id')),
  67.     Column('count', Integer)
  68. )
  69.  
  70. returns_table = Table(
  71.     'returns_table', metadata,
  72.     Column('id', Integer, primary_key=True),
  73.     Column('product_id', None, ForeignKey('product_table.id')),
  74.     Column('time', String),
  75.     Column('count', Integer),
  76.     Column('money', String),
  77.     Column('Manufacturers', String)
  78. )
  79.  
  80. employee_table = Table(
  81.     'employee_table', metadata,
  82.     Column('id', Integer, primary_key=True),
  83.     Column('part_id', None, ForeignKey('part_table.id')),
  84.     Column('branch_id', None, ForeignKey('branch_table.id')),
  85.     Column('name', String),
  86.     Column('gender', Integer)
  87. )
  88.  
  89. part_table = Table(
  90.     'part_table', metadata,
  91.     Column('id', Integer, primary_key=True),
  92.     Column('name', String),
  93.     Column('number', Integer),
  94. )
  95.  
  96. branch_table = Table(
  97.     'branch_table', metadata,
  98.     Column('id', Integer, primary_key=True),
  99.     Column('name', String),
  100.     Column('address', String),
  101.     Column('phone', Integer)
  102. )
  103. leave_table = Table(
  104.     'leave_table', metadata,
  105.     Column('id', Integer, primary_key=True),
  106.     Column('employee_id', None, ForeignKey('employee_table.id')),
  107.     Column('kind', String),
  108.     Column('date', String)
  109. )
  110. attendance_table = Table(
  111.     'attendance_table', metadata,
  112.     Column('id', Integer, primary_key=True),
  113.     Column('employee_id', None, ForeignKey('employee_table.id')),
  114.     Column('kind', String),
  115.     Column('date', String)
  116. )
  117.  
  118. metadata.create_all(engine)
  119.  
  120. def open_main_window(old_page):
  121.     # btn pixel
  122.     X_PIXEL01 = 0
  123.     X_PIXEL02 = 80
  124.     X_PIXEL03 = 160
  125.     Y_PIXEL01 = 20
  126.     Y_PIXEL02 = 50
  127.     Y_PIXEL03 = 80
  128.     global G_user_name
  129.  
  130.     old_page.destroy()
  131.     win_main = tk.Tk()
  132.     win_main.title("main page")
  133.     win_main.geometry('300x200')
  134.     label_Lusername = tk.Label(win_main, text="User Name:").place(x=0,y=0)
  135.     label_username = tk.Label(win_main,text=G_user_name).place(x=80, y=0)
  136.     btn_open_page01 = tk.Button(win_main, text='products', command= lambda:select_product_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL01)
  137.     btn_open_page02 = tk.Button(win_main, text='purchase', command=lambda: select_purchase_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL01)
  138.     btn_open_page03 = tk.Button(win_main, text='stock', command=lambda: select_stock_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL01)
  139.     btn_open_page04 = tk.Button(win_main, text='returns', command=lambda: select_returns_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL02)
  140.     btn_open_page05 = tk.Button(win_main, text='employee', command=lambda: select_employee_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL02)
  141.     btn_open_page06 = tk.Button(win_main, text='part', command=lambda: select_part_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL02)
  142.     btn_open_page07 = tk.Button(win_main, text='branch', command=lambda: select_branch_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL03)
  143.     btn_open_page08 = tk.Button(win_main, text='leave', command=lambda: select_leave_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL03)
  144.     btn_open_page09 = tk.Button(win_main, text='attendance', command=lambda: select_attendance_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL03)
  145.  
  146. # def open_page01_window(old_page):
  147. #     LABEL_YPIXEL = 20
  148. #     NAME_XPIXEL = 0
  149. #     STOCK_XPIXEL = 80
  150. #     PRICE_XPIXEL = 160
  151. #     PURCHASE_XPIXEL = 240
  152. #     EFFECT_XPIXEL = 350
  153. #     ORIGIN_XPIXEL = 430
  154. #     RETURNS_XPIXEL = 500
  155. #     line = 0
  156. #     global product_data
  157. #     old_page.destroy()
  158. #     win_products = tk.Tk()
  159. #     win_products.title("page01")
  160. #     win_products.geometry('600x400')
  161. #
  162. #     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  163. #     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  164. #     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  165. #     label_Lstock = tk.Label(win_products, text="Stock").place(x=STOCK_XPIXEL, y=LABEL_YPIXEL)
  166. #     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  167. #     label_Lpurchase = tk.Label(win_products, text="Purchase").place(x=PURCHASE_XPIXEL, y=LABEL_YPIXEL)
  168. #     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  169. #     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  170. #     label_Lreturns = tk.Label(win_products, text="Returns").place(x=RETURNS_XPIXEL, y=LABEL_YPIXEL)
  171. #     btn_new_object = tk.Button(win_products, text='Insert', command=lambda: Product_insert_window(win_products)).pack(
  172. #         side="bottom")
  173. #     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(
  174. #         side="bottom")
  175. #
  176. #     selectsql_product = select([product_table])
  177. #     result = conn.execute(selectsql_product)
  178. #
  179. #     for row in result:
  180. #
  181. #         # print('row:', row)
  182. #         label_prd_name = tk.Label(win_products, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  183. #         label_prd_stock = tk.Label(win_products, text=row[2]).place(x=STOCK_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  184. #         label_prd_price = tk.Label(win_products, text=row[3]).place(x=PRICE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  185. #         label_prd_purchase = tk.Label(win_products, text=row[4]).place(x=PURCHASE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  186. #         label_prd_effectivedate = tk.Label(win_products, text=row[4]).place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  187. #         label_prd_origin = tk.Label(win_products, text=row[5]).place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  188. #         label_prd_returns = tk.Label(win_products, text=row[6]).place(x=RETURNS_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  189. #
  190. #         line+=1
  191.  
  192.  
  193. def select_product_window(old_page):
  194.     LABEL_YPIXEL = 20
  195.     NAME_XPIXEL = 0
  196.     PRICE_XPIXEL = 130
  197.     EFFECT_XPIXEL = 280
  198.     ORIGIN_XPIXEL = 350
  199.     EDIT_XPIXEL = 480
  200.     REMOVE_XPIXEL = 530
  201.     line = 0
  202.     global product_data
  203.     old_page.destroy()
  204.     win_products = tk.Tk()
  205.     win_products.title("product")
  206.     win_products.geometry('600x400')
  207.  
  208.     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  209.     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  210.     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  211.     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  212.     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  213.     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  214.     btn_new_object = tk.Button(win_products, text='Insert', command=lambda: Product_insert_window(win_products)).pack(
  215.         side="bottom")
  216.     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(
  217.         side="bottom")
  218.  
  219.     selectsql_product = select([product_table])
  220.     result = conn.execute(selectsql_product)
  221.  
  222.     for row in result:
  223.         label_prd_name = tk.Label(win_products, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  224.         label_prd_price = tk.Label(win_products, text=row[2]).place(x=PRICE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  225.         label_prd_effectivedate = tk.Label(win_products, text=row[3]).place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  226.         label_prd_origin = tk.Label(win_products, text=row[4]).place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  227.         btn_edit_prd = tk.Button(win_products, text='edit', command=partial(edit_product_window, win_products, row[0]))\
  228.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  229.         btn_delete_prd = tk.Button(win_products, text='delete', command=partial(delete_product, win_products, row[0])) \
  230.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  231.         line+=1
  232.  
  233. def Product_insert_window(old_page):
  234.     old_page.destroy()
  235.     win_products_insert = tk.Tk()
  236.     win_products_insert.title("Insert product")
  237.     win_products_insert.geometry('450x300')
  238.  
  239.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  240.     entry_name = tk.Entry(win_products_insert)
  241.     entry_name.grid(column=1, row=0)
  242.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=1)
  243.     entry_price = tk.Entry(win_products_insert)
  244.     entry_price.grid(column=1, row=1)
  245.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=2)
  246.     entry_effectivedate = tk.Entry(win_products_insert)
  247.     entry_effectivedate.grid(column=1, row=2)
  248.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=3)
  249.     entry_origin = tk.Entry(win_products_insert)
  250.     entry_origin.grid(column=1, row=3)
  251.     btn_insert = tk.Button(win_products_insert, text="insert", command= lambda:insert_product(win_products_insert,
  252.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get())).place(x=200, y=250)
  253.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:select_product_window(win_products_insert))\
  254.         .place(x=300, y=250)
  255.  
  256. def edit_product_window(old_page, input_id):
  257.     print('id:', input_id)
  258.     old_page.destroy()
  259.     win_products_insert = tk.Tk()
  260.     win_products_insert.title("Edit product")
  261.     win_products_insert.geometry('450x300')
  262.  
  263.     selectsql_product = select([product_table]).\
  264.         where(product_table.c.id == input_id)
  265.     result = conn.execute(selectsql_product)
  266.     print('result:', result)
  267.  
  268.     string_name = StringVar()
  269.     string_price = StringVar()
  270.     string_effectivedate = StringVar()
  271.     string_origin = StringVar()
  272.  
  273.     for row in result:
  274.         string_name.set(row[1])
  275.         string_price.set(row[2])
  276.         string_effectivedate.set(row[3])
  277.         string_origin.set(row[4])
  278.  
  279.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  280.     entry_name = tk.Entry(win_products_insert, textvariable = string_name)
  281.     entry_name.grid(column=1, row=0)
  282.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=1)
  283.     entry_price = tk.Entry(win_products_insert, textvariable = string_price)
  284.     entry_price.grid(column=1, row=1)
  285.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=2)
  286.     entry_effectivedate = tk.Entry(win_products_insert, textvariable = string_effectivedate)
  287.     entry_effectivedate.grid(column=1, row=2)
  288.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=3)
  289.     entry_origin = tk.Entry(win_products_insert, textvariable = string_origin)
  290.     entry_origin.grid(column=1, row=3)
  291.  
  292.  
  293.     btn_edit = tk.Button(win_products_insert, text="insert", command= lambda:edit_product(win_products_insert,
  294.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get(), input_id)).place(x=200, y=250)
  295.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:select_product_window(win_products_insert))\
  296.         .place(x=300, y=250)
  297.  
  298. def insert_product(old_page, name, price, effect, origin):
  299.     global product_data
  300.     test_product = product(name, price, effect, origin)
  301.  
  302.     selectsql_product = select([product_table])
  303.     result = conn.execute(selectsql_product)
  304.     print (result)
  305.     id = 1
  306.     for row in result:
  307.         if  not row[0] < id:
  308.             id = row[0]+1
  309.     ins = product_table.insert().values(
  310.         id= id,
  311.         name = test_product.name,
  312.         price = test_product.price,
  313.         effectivedate = test_product.effectivedate,
  314.         origin = test_product.origin)
  315.     conn.execute(ins)
  316.     select_product_window(old_page)
  317.  
  318. def edit_product(old_page, name, price, effect, origin, input_id):
  319.     editsql_product = product_table.update().where(product_table.c.id == input_id).values(
  320.         name = name,
  321.         price = price,
  322.         effectivedate = effect,
  323.         origin = origin
  324.     )
  325.     conn.execute(editsql_product)
  326.     select_product_window(old_page)
  327.  
  328. def delete_product(old_page, input_id):
  329.     deletesql_product = product_table.delete().where(product_table.c.id == input_id)
  330.     conn.execute(deletesql_product)
  331.     select_product_window(old_page)
  332.  
  333.  
  334. # employee
  335. def select_employee_window(old_page):
  336.     LABEL_YPIXEL = 20
  337.     NAME_XPIXEL = 0
  338.     GENDER_XPIXEL = 130
  339.     EDIT_XPIXEL = 480
  340.     REMOVE_XPIXEL = 530
  341.     line = 0
  342.     global product_data
  343.     old_page.destroy()
  344.     win_employee = tk.Tk()
  345.     win_employee.title("employee")
  346.     win_employee.geometry('600x400')
  347.  
  348.     label_Lusername = tk.Label(win_employee, text="User Name:").place(x=0, y=0)
  349.     label_username = tk.Label(win_employee, text=G_user_name).place(x=80, y=0)
  350.     label_Lname = tk.Label(win_employee, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  351.     label_Lprice = tk.Label(win_employee, text="gender").place(x=GENDER_XPIXEL, y=LABEL_YPIXEL)
  352.  
  353.     btn_new_object = tk.Button(win_employee, text='Insert', command=lambda:employee_insert_window(win_employee)).pack(
  354.         side="bottom")
  355.     btn_open_main = tk.Button(win_employee, text='return', command=lambda:open_main_window(win_employee)).pack(
  356.         side="bottom")
  357.  
  358.     selectsql_employee = select([employee_table])
  359.     result = conn.execute(selectsql_employee)
  360.  
  361.     for row in result:
  362.         tk.Label(win_employee, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  363.         tk.Label(win_employee, text=row[2]).place(x=GENDER_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  364.         tk.Button(win_employee, text='edit', command=partial(edit_employee_window, win_employee, row[0]))\
  365.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  366.         tk.Button(win_employee, text='delete', command=partial(delete_employee, win_employee, row[0])) \
  367.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  368.         line+=1
  369.  
  370. def employee_insert_window(old_page):
  371.     old_page.destroy()
  372.     win_products_insert = tk.Tk()
  373.     win_products_insert.title("Insert product")
  374.     win_products_insert.geometry('450x300')
  375.  
  376.     tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  377.     entry_name = tk.Entry(win_products_insert)
  378.     entry_name.grid(column=1, row=0)
  379.     tk.Label(win_products_insert, text="gender").grid(column=0, row=1)
  380.     entry_gender = tk.Entry(win_products_insert)
  381.     entry_gender.grid(column=1, row=1)
  382.     tk.Button(win_products_insert, text="insert", command= lambda:insert_employee(win_products_insert,
  383.         entry_name.get(), entry_gender.get())).place(x=200, y=250)
  384.     tk.Button(win_products_insert, text="return", command= lambda:select_employee_window(win_products_insert))\
  385.         .place(x=300, y=250)
  386.  
  387. def edit_employee_window(old_page, input_id):
  388.     old_page.destroy()
  389.     win_employee_insert = tk.Tk()
  390.     win_employee_insert.title("Edit product")
  391.     win_employee_insert.geometry('450x300')
  392.  
  393.     selectsql_employee = select([employee_table]).\
  394.         where(employee_table.c.id == input_id)
  395.     result = conn.execute(selectsql_employee)
  396.  
  397.     string_name = StringVar()
  398.     string_gender = StringVar()
  399.  
  400.     for row in result:
  401.         string_name.set(row[1])
  402.         string_gender.set(row[2])
  403.  
  404.     tk.Label(win_employee_insert, text="Name").grid(column=0, row=0)
  405.     entry_name = tk.Entry(win_employee_insert, textvariable = string_name)
  406.     entry_name.grid(column=1, row=0)
  407.     tk.Label(win_employee_insert, text="price").grid(column=0, row=1)
  408.     entry_price = tk.Entry(win_employee_insert, textvariable = string_gender)
  409.     entry_price.grid(column=1, row=1)
  410.  
  411.  
  412.     tk.Button(win_employee_insert, text="insert", command= lambda:edit_product(win_employee_insert,
  413.         entry_name.get(), entry_price.get(), input_id)).place(x=200, y=250)
  414.     tk.Button(win_employee_insert, text="return", command= lambda:select_employee_window(win_employee_insert))\
  415.         .place(x=300, y=250)
  416.  
  417. def insert_employee(old_page, name, gender):
  418.  
  419.     selectsql_employee = select([employee_table])
  420.     result = conn.execute(selectsql_employee)
  421.     id = 1
  422.     for row in result:
  423.         if  not row[0] < id:
  424.             id = row[0]+1
  425.     ins = employee_table.insert().values(
  426.         id= id,
  427.         name = name,
  428.         gender = gender)
  429.     conn.execute(ins)
  430.     select_employee_window(old_page)
  431.  
  432. def edit_employee(old_page, name, gender, input_id):
  433.     editsql_employee = employee_table.update().where(employee_table.c.id == input_id).values(
  434.         name = name,
  435.         gender = gender
  436.     )
  437.     conn.execute(editsql_employee)
  438.     select_employee_window(old_page)
  439.  
  440. def delete_employee(old_page, input_id):
  441.     deletesql_employee = employee_table.delete().where(employee_table.c.id == input_id)
  442.     conn.execute(deletesql_employee)
  443.     select_employee_window(old_page)
  444.  
  445. # part
  446. def select_part_window(old_page):
  447.     LABEL_YPIXEL = 20
  448.     NAME_XPIXEL = 0
  449.     NUMBER_XPIXEL = 130
  450.     EDIT_XPIXEL = 480
  451.     REMOVE_XPIXEL = 530
  452.     line = 0
  453.     old_page.destroy()
  454.     win_part = tk.Tk()
  455.     win_part.title("part")
  456.     win_part.geometry('600x400')
  457.  
  458.     tk.Label(win_part, text="User Name:").place(x=0, y=0)
  459.     tk.Label(win_part, text=G_user_name).place(x=80, y=0)
  460.     tk.Label(win_part, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  461.     tk.Label(win_part, text="number").place(x=NUMBER_XPIXEL, y=LABEL_YPIXEL)
  462.     tk.Button(win_part, text='Insert', command=lambda: part_insert_window(win_part)).pack(
  463.         side="bottom")
  464.     tk.Button(win_part, text='return', command=lambda:open_main_window(win_part)).pack(
  465.         side="bottom")
  466.  
  467.     selectsql_part = select([part_table])
  468.     result = conn.execute(selectsql_part)
  469.  
  470.     for row in result:
  471.         tk.Label(win_part, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  472.         tk.Label(win_part, text=row[2]).place(x=NUMBER_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  473.         tk.Button(win_part, text='edit', command=partial(edit_part_window, win_part, row[0]))\
  474.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  475.         tk.Button(win_part, text='delete', command=partial(delete_part, win_part, row[0])) \
  476.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  477.         line+=1
  478.  
  479. def part_insert_window(old_page):
  480.     old_page.destroy()
  481.     win_part_insert = tk.Tk()
  482.     win_part_insert.title("Insert part")
  483.     win_part_insert.geometry('450x300')
  484.  
  485.     tk.Label(win_part_insert, text="Name").grid(column=0, row=0)
  486.     entry_name = tk.Entry(win_part_insert)
  487.     entry_name.grid(column=1, row=0)
  488.     tk.Label(win_part_insert, text="number").grid(column=0, row=1)
  489.     entry_number = tk.Entry(win_part_insert)
  490.     entry_number.grid(column=1, row=1)
  491.     tk.Button(win_part_insert, text="insert", command= lambda:insert_part(win_part_insert,entry_name.get(),
  492.                                                                              entry_number.get())).place(x=200, y=250)
  493.     tk.Button(win_part_insert, text="return", command= lambda:select_part_window(win_part_insert)).place(x=300, y=250)
  494.  
  495. def edit_part_window(old_page, input_id):
  496.     old_page.destroy()
  497.     win_part_insert = tk.Tk()
  498.     win_part_insert.title("Edit product")
  499.     win_part_insert.geometry('450x300')
  500.  
  501.     selectsql_part = select([part_table]).\
  502.         where(part_table.c.id == input_id)
  503.     result = conn.execute(selectsql_part)
  504.  
  505.     string_name = StringVar()
  506.     string_number = StringVar()
  507.  
  508.     for row in result:
  509.         string_name.set(row[1])
  510.         string_number.set(row[2])
  511.  
  512.     label_Lname = tk.Label(win_part_insert, text="Name").grid(column=0, row=0)
  513.     entry_name = tk.Entry(win_part_insert, textvariable = string_name)
  514.     entry_name.grid(column=1, row=0)
  515.     label_Lprice = tk.Label(win_part_insert, text="price").grid(column=0, row=2)
  516.     entry_number = tk.Entry(win_part_insert, textvariable = string_number)
  517.     entry_number.grid(column=1, row=2)
  518.  
  519.     btn_edit = tk.Button(win_part_insert, text="insert", command= lambda:edit_part(win_part_insert,
  520.         entry_name.get(), entry_number.get(), input_id)).place(x=200, y=250)
  521.     btn_return = tk.Button(win_part_insert, text="return", command= lambda:select_part_window(win_part_insert))\
  522.         .place(x=300, y=250)
  523.  
  524. def insert_part(old_page, name, number):
  525.  
  526.     selectsql_part = select([part_table])
  527.     result = conn.execute(selectsql_part)
  528.     id = 1
  529.     for row in result:
  530.         if  not row[0] < id:
  531.             id = row[0]+1
  532.     ins = part_table.insert().values(
  533.         id= id,
  534.         name = name,
  535.         number = number)
  536.     conn.execute(ins)
  537.     select_part_window(old_page)
  538.  
  539. def edit_part(old_page, name, number, input_id):
  540.     editsql_product = part_table.update().where(part_table.c.id == input_id).values(
  541.         name = name,
  542.         number = number
  543.     )
  544.     conn.execute(editsql_product)
  545.     select_part_window(old_page)
  546.  
  547. def delete_part(old_page, input_id):
  548.     deletesql_part = part_table.delete().where(part_table.c.id == input_id)
  549.     conn.execute(deletesql_part)
  550.     select_part_window(old_page)
  551. # branch
  552. def select_branch_window(old_page):
  553.     LABEL_YPIXEL = 20
  554.     NAME_XPIXEL = 0
  555.     PRICE_XPIXEL = 130
  556.     EFFECT_XPIXEL = 280
  557.     ORIGIN_XPIXEL = 350
  558.     EDIT_XPIXEL = 480
  559.     REMOVE_XPIXEL = 530
  560.     line = 0
  561.     global product_data
  562.     old_page.destroy()
  563.     win_products = tk.Tk()
  564.     win_products.title("product")
  565.     win_products.geometry('600x400')
  566.  
  567.     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  568.     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  569.     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  570.     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  571.     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  572.     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  573.     btn_new_object = tk.Button(win_products, text='Insert', command=lambda: Product_insert_window(win_products)).pack(
  574.         side="bottom")
  575.     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(
  576.         side="bottom")
  577.  
  578.     selectsql_product = select([product_table])
  579.     result = conn.execute(selectsql_product)
  580.  
  581.     for row in result:
  582.         label_prd_name = tk.Label(win_products, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  583.         label_prd_price = tk.Label(win_products, text=row[2]).place(x=PRICE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  584.         label_prd_effectivedate = tk.Label(win_products, text=row[3]).place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  585.         label_prd_origin = tk.Label(win_products, text=row[4]).place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  586.         btn_edit_prd = tk.Button(win_products, text='edit', command=partial(edit_product_window, win_products, row[0]))\
  587.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  588.         btn_delete_prd = tk.Button(win_products, text='delete', command=partial(delete_product, win_products, row[0])) \
  589.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  590.         line+=1
  591.  
  592. def branch_insert_window(old_page):
  593.     old_page.destroy()
  594.     win_products_insert = tk.Tk()
  595.     win_products_insert.title("Insert product")
  596.     win_products_insert.geometry('450x300')
  597.  
  598.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  599.     entry_name = tk.Entry(win_products_insert)
  600.     entry_name.grid(column=1, row=0)
  601.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  602.     # entry_stock = tk.Entry(win_products_insert)
  603.     # entry_stock.grid(column=1, row=1)
  604.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  605.     entry_price = tk.Entry(win_products_insert)
  606.     entry_price.grid(column=1, row=2)
  607.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  608.     # entry_purchase = tk.Entry(win_products_insert)
  609.     # entry_purchase.grid(column=1, row=3)
  610.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  611.     entry_effectivedate = tk.Entry(win_products_insert)
  612.     entry_effectivedate.grid(column=1, row=4)
  613.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  614.     entry_origin = tk.Entry(win_products_insert)
  615.     entry_origin.grid(column=1, row=5)
  616.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  617.     # entry_returns = tk.Entry(win_products_insert)
  618.     # entry_returns.grid(column=1, row=6)
  619.     btn_insert = tk.Button(win_products_insert, text="insert", command= lambda:insert_product(win_products_insert,
  620.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get())).place(x=200, y=250)
  621.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  622.         .place(x=300, y=250)
  623.  
  624. def edit_branch_window(old_page, input_id):
  625.     print('id:', input_id)
  626.     old_page.destroy()
  627.     win_products_insert = tk.Tk()
  628.     win_products_insert.title("Edit product")
  629.     win_products_insert.geometry('450x300')
  630.  
  631.     selectsql_product = select([product_table]).\
  632.         where(product_table.c.id == input_id)
  633.     result = conn.execute(selectsql_product)
  634.     print('result:', result)
  635.     purchase_product_id = select([purchase_table]). \
  636.         where(purchase_table.c.product_id == input_id)
  637.     selectsql_purchase_result = conn.execute(selectsql_product)
  638.  
  639.     string_name = StringVar()
  640.     string_price = StringVar()
  641.     string_effectivedate = StringVar()
  642.     string_origin = StringVar()
  643.  
  644.     for row in result:
  645.         string_name.set(row[1])
  646.         string_price.set(row[2])
  647.         string_effectivedate.set(row[3])
  648.         string_origin.set(row[4])
  649.  
  650.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  651.     entry_name = tk.Entry(win_products_insert, textvariable = string_name)
  652.     entry_name.grid(column=1, row=0)
  653.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  654.     # entry_stock = tk.Entry(win_products_insert, textvariable = string_stock)
  655.     # entry_stock.grid(column=1, row=1)
  656.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  657.     entry_price = tk.Entry(win_products_insert, textvariable = string_price)
  658.     entry_price.grid(column=1, row=2)
  659.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  660.     # entry_purchase = tk.Entry(win_products_insert, textvariable = string_purchase)
  661.     # entry_purchase.grid(column=1, row=3)
  662.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  663.     entry_effectivedate = tk.Entry(win_products_insert, textvariable = string_effectivedate)
  664.     entry_effectivedate.grid(column=1, row=4)
  665.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  666.     entry_origin = tk.Entry(win_products_insert, textvariable = string_origin)
  667.     entry_origin.grid(column=1, row=5)
  668.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  669.     # entry_returns = tk.Entry(win_products_insert, textvariable = string_returns)
  670.     # entry_returns.grid(column=1, row=6)
  671.  
  672.     btn_edit = tk.Button(win_products_insert, text="insert", command= lambda:edit_product(win_products_insert,
  673.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get(), input_id)).place(x=200, y=250)
  674.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  675.         .place(x=300, y=250)
  676.  
  677. def insert_branch(old_page, name, price, effect, origin):
  678.     global product_data
  679.     test_product = product(name, price, effect, origin)
  680.  
  681.     selectsql_product = select([product_table])
  682.     result = conn.execute(selectsql_product)
  683.     print (result)
  684.     id = 1
  685.     for row in result:
  686.         if  not row[0] < id:
  687.             id = row[0]+1
  688.     ins = product_table.insert().values(
  689.         id= id,
  690.         name = test_product.name,
  691.         price = test_product.price,
  692.         effectivedate = test_product.effectivedate,
  693.         origin = test_product.origin)
  694.     conn.execute(ins)
  695.     selcet_product_window(old_page)
  696.  
  697. def edit_branch(old_page, name, price, effect, origin, input_id):
  698.     editsql_product = product_table.update().where(product_table.c.id == input_id).values(
  699.         name = name,
  700.         price = price,
  701.         effectivedate = effect,
  702.         origin = origin
  703.     )
  704.     conn.execute(editsql_product)
  705.     selcet_product_window(old_page)
  706.  
  707. def delete_branch(old_page, input_id):
  708.     deletesql_product = product_table.delete().where(product_table.c.id == input_id)
  709.     conn.execute(deletesql_product)
  710.     selcet_product_window(old_page)
  711. # leave
  712. def select_leave_window(old_page):
  713.     LABEL_YPIXEL = 20
  714.     NAME_XPIXEL = 0
  715.     PRICE_XPIXEL = 130
  716.     EFFECT_XPIXEL = 280
  717.     ORIGIN_XPIXEL = 350
  718.     EDIT_XPIXEL = 480
  719.     REMOVE_XPIXEL = 530
  720.     line = 0
  721.     global product_data
  722.     old_page.destroy()
  723.     win_products = tk.Tk()
  724.     win_products.title("product")
  725.     win_products.geometry('600x400')
  726.  
  727.     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  728.     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  729.     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  730.     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  731.     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  732.     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  733.     btn_new_object = tk.Button(win_products, text='Insert', command=lambda: Product_insert_window(win_products)).pack(
  734.         side="bottom")
  735.     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(
  736.         side="bottom")
  737.  
  738.     selectsql_product = select([product_table])
  739.     result = conn.execute(selectsql_product)
  740.  
  741.     for row in result:
  742.         label_prd_name = tk.Label(win_products, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  743.         label_prd_price = tk.Label(win_products, text=row[2]).place(x=PRICE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  744.         label_prd_effectivedate = tk.Label(win_products, text=row[3]).place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  745.         label_prd_origin = tk.Label(win_products, text=row[4]).place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  746.         btn_edit_prd = tk.Button(win_products, text='edit', command=partial(edit_product_window, win_products, row[0]))\
  747.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  748.         btn_delete_prd = tk.Button(win_products, text='delete', command=partial(delete_product, win_products, row[0])) \
  749.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  750.         line+=1
  751.  
  752. def leave_insert_window(old_page):
  753.     old_page.destroy()
  754.     win_products_insert = tk.Tk()
  755.     win_products_insert.title("Insert product")
  756.     win_products_insert.geometry('450x300')
  757.  
  758.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  759.     entry_name = tk.Entry(win_products_insert)
  760.     entry_name.grid(column=1, row=0)
  761.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  762.     # entry_stock = tk.Entry(win_products_insert)
  763.     # entry_stock.grid(column=1, row=1)
  764.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  765.     entry_price = tk.Entry(win_products_insert)
  766.     entry_price.grid(column=1, row=2)
  767.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  768.     # entry_purchase = tk.Entry(win_products_insert)
  769.     # entry_purchase.grid(column=1, row=3)
  770.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  771.     entry_effectivedate = tk.Entry(win_products_insert)
  772.     entry_effectivedate.grid(column=1, row=4)
  773.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  774.     entry_origin = tk.Entry(win_products_insert)
  775.     entry_origin.grid(column=1, row=5)
  776.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  777.     # entry_returns = tk.Entry(win_products_insert)
  778.     # entry_returns.grid(column=1, row=6)
  779.     btn_insert = tk.Button(win_products_insert, text="insert", command= lambda:insert_product(win_products_insert,
  780.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get())).place(x=200, y=250)
  781.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  782.         .place(x=300, y=250)
  783.  
  784. def edit_leave_window(old_page, input_id):
  785.     print('id:', input_id)
  786.     old_page.destroy()
  787.     win_products_insert = tk.Tk()
  788.     win_products_insert.title("Edit product")
  789.     win_products_insert.geometry('450x300')
  790.  
  791.     selectsql_product = select([product_table]).\
  792.         where(product_table.c.id == input_id)
  793.     result = conn.execute(selectsql_product)
  794.     print('result:', result)
  795.     purchase_product_id = select([purchase_table]). \
  796.         where(purchase_table.c.product_id == input_id)
  797.     selectsql_purchase_result = conn.execute(selectsql_product)
  798.  
  799.     string_name = StringVar()
  800.     string_price = StringVar()
  801.     string_effectivedate = StringVar()
  802.     string_origin = StringVar()
  803.  
  804.     for row in result:
  805.         string_name.set(row[1])
  806.         string_price.set(row[2])
  807.         string_effectivedate.set(row[3])
  808.         string_origin.set(row[4])
  809.  
  810.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  811.     entry_name = tk.Entry(win_products_insert, textvariable = string_name)
  812.     entry_name.grid(column=1, row=0)
  813.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  814.     # entry_stock = tk.Entry(win_products_insert, textvariable = string_stock)
  815.     # entry_stock.grid(column=1, row=1)
  816.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  817.     entry_price = tk.Entry(win_products_insert, textvariable = string_price)
  818.     entry_price.grid(column=1, row=2)
  819.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  820.     # entry_purchase = tk.Entry(win_products_insert, textvariable = string_purchase)
  821.     # entry_purchase.grid(column=1, row=3)
  822.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  823.     entry_effectivedate = tk.Entry(win_products_insert, textvariable = string_effectivedate)
  824.     entry_effectivedate.grid(column=1, row=4)
  825.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  826.     entry_origin = tk.Entry(win_products_insert, textvariable = string_origin)
  827.     entry_origin.grid(column=1, row=5)
  828.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  829.     # entry_returns = tk.Entry(win_products_insert, textvariable = string_returns)
  830.     # entry_returns.grid(column=1, row=6)
  831.  
  832.     btn_edit = tk.Button(win_products_insert, text="insert", command= lambda:edit_product(win_products_insert,
  833.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get(), input_id)).place(x=200, y=250)
  834.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  835.         .place(x=300, y=250)
  836.  
  837. def insert_leave(old_page, name, price, effect, origin):
  838.     global product_data
  839.     test_product = product(name, price, effect, origin)
  840.  
  841.     selectsql_product = select([product_table])
  842.     result = conn.execute(selectsql_product)
  843.     print (result)
  844.     id = 1
  845.     for row in result:
  846.         if  not row[0] < id:
  847.             id = row[0]+1
  848.     ins = product_table.insert().values(
  849.         id= id,
  850.         name = test_product.name,
  851.         price = test_product.price,
  852.         effectivedate = test_product.effectivedate,
  853.         origin = test_product.origin)
  854.     conn.execute(ins)
  855.     selcet_product_window(old_page)
  856.  
  857. def edit_leave(old_page, name, price, effect, origin, input_id):
  858.     editsql_product = product_table.update().where(product_table.c.id == input_id).values(
  859.         name = name,
  860.         price = price,
  861.         effectivedate = effect,
  862.         origin = origin
  863.     )
  864.     conn.execute(editsql_product)
  865.     selcet_product_window(old_page)
  866.  
  867. def delete_leave(old_page, input_id):
  868.     deletesql_product = product_table.delete().where(product_table.c.id == input_id)
  869.     conn.execute(deletesql_product)
  870.     selcet_product_window(old_page)
  871. # attendance
  872. def select_attendance_window(old_page):
  873.     LABEL_YPIXEL = 20
  874.     NAME_XPIXEL = 0
  875.     PRICE_XPIXEL = 130
  876.     EFFECT_XPIXEL = 280
  877.     ORIGIN_XPIXEL = 350
  878.     EDIT_XPIXEL = 480
  879.     REMOVE_XPIXEL = 530
  880.     line = 0
  881.     global product_data
  882.     old_page.destroy()
  883.     win_products = tk.Tk()
  884.     win_products.title("product")
  885.     win_products.geometry('600x400')
  886.  
  887.     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  888.     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  889.     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  890.     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  891.     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  892.     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  893.     btn_new_object = tk.Button(win_products, text='Insert', command=lambda: Product_insert_window(win_products)).pack(
  894.         side="bottom")
  895.     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(
  896.         side="bottom")
  897.  
  898.     selectsql_product = select([product_table])
  899.     result = conn.execute(selectsql_product)
  900.  
  901.     for row in result:
  902.         label_prd_name = tk.Label(win_products, text=row[1]).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  903.         label_prd_price = tk.Label(win_products, text=row[2]).place(x=PRICE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  904.         label_prd_effectivedate = tk.Label(win_products, text=row[3]).place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  905.         label_prd_origin = tk.Label(win_products, text=row[4]).place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  906.         btn_edit_prd = tk.Button(win_products, text='edit', command=partial(edit_product_window, win_products, row[0]))\
  907.             .place(x=EDIT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  908.         btn_delete_prd = tk.Button(win_products, text='delete', command=partial(delete_product, win_products, row[0])) \
  909.             .place(x=REMOVE_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  910.         line+=1
  911.  
  912. def attendance_insert_window(old_page):
  913.     old_page.destroy()
  914.     win_products_insert = tk.Tk()
  915.     win_products_insert.title("Insert product")
  916.     win_products_insert.geometry('450x300')
  917.  
  918.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  919.     entry_name = tk.Entry(win_products_insert)
  920.     entry_name.grid(column=1, row=0)
  921.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  922.     # entry_stock = tk.Entry(win_products_insert)
  923.     # entry_stock.grid(column=1, row=1)
  924.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  925.     entry_price = tk.Entry(win_products_insert)
  926.     entry_price.grid(column=1, row=2)
  927.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  928.     # entry_purchase = tk.Entry(win_products_insert)
  929.     # entry_purchase.grid(column=1, row=3)
  930.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  931.     entry_effectivedate = tk.Entry(win_products_insert)
  932.     entry_effectivedate.grid(column=1, row=4)
  933.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  934.     entry_origin = tk.Entry(win_products_insert)
  935.     entry_origin.grid(column=1, row=5)
  936.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  937.     # entry_returns = tk.Entry(win_products_insert)
  938.     # entry_returns.grid(column=1, row=6)
  939.     btn_insert = tk.Button(win_products_insert, text="insert", command= lambda:insert_product(win_products_insert,
  940.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get())).place(x=200, y=250)
  941.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  942.         .place(x=300, y=250)
  943.  
  944. def edit_attendance_window(old_page, input_id):
  945.     print('id:', input_id)
  946.     old_page.destroy()
  947.     win_products_insert = tk.Tk()
  948.     win_products_insert.title("Edit product")
  949.     win_products_insert.geometry('450x300')
  950.  
  951.     selectsql_product = select([product_table]).\
  952.         where(product_table.c.id == input_id)
  953.     result = conn.execute(selectsql_product)
  954.     print('result:', result)
  955.     purchase_product_id = select([purchase_table]). \
  956.         where(purchase_table.c.product_id == input_id)
  957.     selectsql_purchase_result = conn.execute(selectsql_product)
  958.  
  959.     string_name = StringVar()
  960.     string_price = StringVar()
  961.     string_effectivedate = StringVar()
  962.     string_origin = StringVar()
  963.  
  964.     for row in result:
  965.         string_name.set(row[1])
  966.         string_price.set(row[2])
  967.         string_effectivedate.set(row[3])
  968.         string_origin.set(row[4])
  969.  
  970.     label_Lname = tk.Label(win_products_insert, text="Name").grid(column=0, row=0)
  971.     entry_name = tk.Entry(win_products_insert, textvariable = string_name)
  972.     entry_name.grid(column=1, row=0)
  973.     # label_Lstock = tk.Label(win_products_insert, text="stock").grid(column=0, row=1)
  974.     # entry_stock = tk.Entry(win_products_insert, textvariable = string_stock)
  975.     # entry_stock.grid(column=1, row=1)
  976.     label_Lprice = tk.Label(win_products_insert, text="price").grid(column=0, row=2)
  977.     entry_price = tk.Entry(win_products_insert, textvariable = string_price)
  978.     entry_price.grid(column=1, row=2)
  979.     # label_Lpurchase = tk.Label(win_products_insert, text="purchase").grid(column=0, row=3)
  980.     # entry_purchase = tk.Entry(win_products_insert, textvariable = string_purchase)
  981.     # entry_purchase.grid(column=1, row=3)
  982.     label_Leffectivedate = tk.Label(win_products_insert, text="effectivedate").grid(column=0, row=4)
  983.     entry_effectivedate = tk.Entry(win_products_insert, textvariable = string_effectivedate)
  984.     entry_effectivedate.grid(column=1, row=4)
  985.     label_Lorigin = tk.Label(win_products_insert, text="origin").grid(column=0, row=5)
  986.     entry_origin = tk.Entry(win_products_insert, textvariable = string_origin)
  987.     entry_origin.grid(column=1, row=5)
  988.     # label_Lreturns = tk.Label(win_products_insert, text="returns").grid(column=0, row=6)
  989.     # entry_returns = tk.Entry(win_products_insert, textvariable = string_returns)
  990.     # entry_returns.grid(column=1, row=6)
  991.  
  992.     btn_edit = tk.Button(win_products_insert, text="insert", command= lambda:edit_product(win_products_insert,
  993.         entry_name.get(), entry_price.get(), entry_effectivedate.get(), entry_origin.get(), input_id)).place(x=200, y=250)
  994.     btn_return = tk.Button(win_products_insert, text="return", command= lambda:selcet_product_window(win_products_insert))\
  995.         .place(x=300, y=250)
  996.  
  997. def insert_attendance(old_page, name, price, effect, origin):
  998.     global product_data
  999.     test_product = product(name, price, effect, origin)
  1000.  
  1001.     selectsql_product = select([product_table])
  1002.     result = conn.execute(selectsql_product)
  1003.     print (result)
  1004.     id = 1
  1005.     for row in result:
  1006.         if  not row[0] < id:
  1007.             id = row[0]+1
  1008.     ins = product_table.insert().values(
  1009.         id= id,
  1010.         name = test_product.name,
  1011.         price = test_product.price,
  1012.         effectivedate = test_product.effectivedate,
  1013.         origin = test_product.origin)
  1014.     conn.execute(ins)
  1015.     selcet_product_window(old_page)
  1016.  
  1017. def edit_attendance(old_page, name, price, effect, origin, input_id):
  1018.     editsql_product = product_table.update().where(product_table.c.id == input_id).values(
  1019.         name = name,
  1020.         price = price,
  1021.         effectivedate = effect,
  1022.         origin = origin
  1023.     )
  1024.     conn.execute(editsql_product)
  1025.     selcet_product_window(old_page)
  1026.  
  1027. def delete_attendance(old_page, input_id):
  1028.     deletesql_product = product_table.delete().where(product_table.c.id == input_id)
  1029.     conn.execute(deletesql_product)
  1030.     selcet_product_window(old_page)
  1031. #
  1032.  
  1033. def select_purchase_window(old_page):
  1034.     LABEL_YPIXEL = 20
  1035.     PRODUCT_XPIXEL = 0
  1036.     TIME_XPIXEL = 80
  1037.     COUNT_XPIXEL = 160
  1038.     MANUFACTURES_XPIXEL = 240
  1039.     EDIT_XPIXEL = 480
  1040.     DELETE_XPIXEL = 530
  1041.     line = 0
  1042.  
  1043.     old_page.destroy()
  1044.     win_purchase = tk.Tk()
  1045.     win_purchase.title("purchase")
  1046.     win_purchase.geometry('600x400')
  1047.  
  1048.     label_Lusername = tk.Label(win_purchase, text="User Name:").place(x=0, y=0)
  1049.     label_username = tk.Label(win_purchase, text=G_user_name).place(x=80, y=0)
  1050.     label_Lproduct = tk.Label(win_purchase, text="Product").place(x=PRODUCT_XPIXEL, y=LABEL_YPIXEL)
  1051.     label_Ltime = tk.Label(win_purchase, text="Time").place(x=TIME_XPIXEL, y=LABEL_YPIXEL)
  1052.     label_Lcount = tk.Label(win_purchase, text="Count").place(x=COUNT_XPIXEL, y=LABEL_YPIXEL)
  1053.     label_Lmanafacture = tk.Label(win_purchase, text="Manufactures").place(x=MANUFACTURES_XPIXEL, y=LABEL_YPIXEL)
  1054.     btn_new_object = tk.Button(win_purchase, text='Insert', command=lambda: purchase_insert_window(win_purchase)).pack(
  1055.         side="bottom")
  1056.     btn_open_main = tk.Button(win_purchase, text='return', command=lambda:open_main_window(win_purchase)).pack(
  1057.         side="bottom")
  1058.  
  1059.     selectsql_purchase = select([purchase_table])
  1060.     result = conn.execute(selectsql_purchase)
  1061.  
  1062.     for row in result:
  1063.         selectsql_product_by_product_id = select([product_table]).where(product_table.c.id == row[1])
  1064.         result_product_name = conn.execute(selectsql_product_by_product_id)
  1065.         product_name = ''
  1066.         for name in result_product_name:
  1067.             product_name = name[1]
  1068.  
  1069.         label_pur_name = tk.Label(win_purchase, text=product_name).place(x=PRODUCT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1070.         label_pur_stock = tk.Label(win_purchase, text=row[2]).place(x=TIME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1071.         label_pur_price = tk.Label(win_purchase, text=row[3]).place(x=COUNT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1072.         label_pur_purchase = tk.Label(win_purchase, text=row[4]).place(x=MANUFACTURES_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1073.  
  1074.         btn_delete_pur = tk.Button(win_purchase, text='delete', command=partial(delete_purchase, win_purchase, row[0])) \
  1075.             .place(x=DELETE_XPIXEL, y=LABEL_YPIXEL + (line + 1) * 30)
  1076.         line+=1
  1077.  
  1078. def purchase_insert_window(old_page):
  1079.     old_page.destroy()
  1080.     win_purchase_insert = tk.Tk()
  1081.     win_purchase_insert.title("Insert product")
  1082.     win_purchase_insert.geometry('450x300')
  1083.  
  1084.     label_Lname = tk.Label(win_purchase_insert, text="Product").grid(column=0, row=0)
  1085.     entry_name = tk.Entry(win_purchase_insert)
  1086.     entry_name.grid(column=1, row=0)
  1087.     label_Lstock = tk.Label(win_purchase_insert, text="Time").grid(column=0, row=1)
  1088.     entry_stock = tk.Entry(win_purchase_insert)
  1089.     entry_stock.grid(column=1, row=1)
  1090.     label_Lprice = tk.Label(win_purchase_insert, text="Count").grid(column=0, row=2)
  1091.     entry_price = tk.Entry(win_purchase_insert)
  1092.     entry_price.grid(column=1, row=2)
  1093.     label_Lpurchase = tk.Label(win_purchase_insert, text="Manufactures").grid(column=0, row=3)
  1094.     entry_purchase = tk.Entry(win_purchase_insert)
  1095.     entry_purchase.grid(column=1, row=3)
  1096.  
  1097.     btn_insert = tk.Button(win_purchase_insert, text="insert", command= lambda:insert_purchase(win_purchase_insert,
  1098.         entry_name.get(), entry_stock.get(), entry_price.get(), entry_purchase.get())).place(x=200, y=250)
  1099.     btn_return = tk.Button(win_purchase_insert, text="return", command= lambda:select_purchase_window(win_purchase_insert))\
  1100.         .place(x=300, y=250)
  1101.  
  1102. def insert_purchase(old_page, product, time, count, manufactures):
  1103.     print('\nproduct:', product)
  1104.     selectsql_purchase = select([purchase_table])
  1105.     result = conn.execute(selectsql_purchase)
  1106.  
  1107.     product_id = 0
  1108.     selectsql_product_by_product_id = select([product_table]).where(product_table.c.name == product)
  1109.     result_product_id = conn.execute(selectsql_product_by_product_id)
  1110.     for row in result_product_id:
  1111.         product_id = row[0]
  1112.  
  1113.     id = 0
  1114.     for row in result:
  1115.         if not row[0] < id:
  1116.             id = row[0] + 1
  1117.  
  1118.     if product_id:
  1119.         ins = purchase_table.insert().values(
  1120.             id= id,
  1121.             product_id = product_id,
  1122.             time= time,
  1123.             count = count,
  1124.             Manufacturers = manufactures
  1125.             )
  1126.         conn.execute(ins)
  1127.  
  1128.         edit_stock(product_id, count, 1)
  1129.     else:
  1130.         messagebox.showerror(message='Error, the product is not exist, try again.')
  1131.         pass
  1132.     select_purchase_window(old_page)
  1133.  
  1134. def delete_purchase(old_page, input_id):
  1135.     selectsql_purchase = purchase_table.select().where(purchase_table.c.id == input_id)
  1136.     result_purchase = conn.execute(selectsql_purchase)
  1137.  
  1138.     purchase_product_id = 0
  1139.     purchase_count = 0
  1140.     for row in result_purchase:
  1141.         purchase_product_id = row[1]
  1142.         purchase_count = row[3]
  1143.         print('purchase_product_id:',purchase_product_id)
  1144.         print('purchase_count:', purchase_count)
  1145.     edit_stock(purchase_product_id, purchase_count, 0)
  1146.  
  1147.     deletesql_purchase = purchase_table.delete().where(purchase_table.c.id == input_id)
  1148.     conn.execute(deletesql_purchase)
  1149.     select_purchase_window(old_page)
  1150.  
  1151.  
  1152. def select_stock_window(old_page):
  1153.     LABEL_YPIXEL = 20
  1154.     NAME_XPIXEL = 0
  1155.     STOCK_XPIXEL = 100
  1156.  
  1157.     line = 0
  1158.     global product_data
  1159.     old_page.destroy()
  1160.     win_stock = tk.Tk()
  1161.     win_stock.title("stock")
  1162.     win_stock.geometry('600x400')
  1163.  
  1164.     label_Lusername = tk.Label(win_stock, text="User Name:").place(x=0, y=0)
  1165.     label_username = tk.Label(win_stock, text=G_user_name).place(x=80, y=0)
  1166.     label_Lproductname = tk.Label(win_stock, text="Product").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  1167.     label_Lcount = tk.Label(win_stock, text="Count").place(x=STOCK_XPIXEL, y=LABEL_YPIXEL)
  1168.  
  1169.     btn_open_main = tk.Button(win_stock, text='return', command=lambda:open_main_window(win_stock)).pack(
  1170.         side="bottom")
  1171.  
  1172.     selectsql_stock = select([stock_table])
  1173.     result = conn.execute(selectsql_stock)
  1174.  
  1175.     for row in result:
  1176.         product_id = row[1]
  1177.         product_name = ''
  1178.         selectsql_name_by_product_id = select([product_table]).where(product_table.c.id == product_id)
  1179.         result_product_id = conn.execute(selectsql_name_by_product_id)
  1180.         for id in result_product_id:
  1181.             product_name = id[1]
  1182.         label_stk_name = tk.Label(win_stock, text=product_name).place(x=NAME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1183.         label_stk_count = tk.Label(win_stock, text=row[2]).place(x=STOCK_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1184.  
  1185.         line+=1
  1186.  
  1187. def edit_stock(product_id, count, add):
  1188.     # print('\nedit stock\n')
  1189.     if add:
  1190.         # print('\nadd \n')
  1191.         product_exist = 0
  1192.         selectsql_stock_table = select([stock_table])
  1193.         result_stock_table = conn.execute(selectsql_stock_table)
  1194.         id = 0
  1195.         pre_count = 0
  1196.         for row in result_stock_table:
  1197.             if product_id == row[1]:
  1198.                 product_exist = 1
  1199.                 pre_count = row[2]
  1200.             if not row[0] < id:
  1201.                 id = row[0] + 1
  1202.  
  1203.         if product_exist:
  1204.             upd = stock_table.update().where(stock_table.c.product_id == product_id).values(
  1205.                 count= int(pre_count)+int(count)
  1206.             )
  1207.             conn.execute(upd)
  1208.         else:
  1209.             ins = stock_table.insert().values(
  1210.                 product_id=product_id,
  1211.                 count=count
  1212.             )
  1213.             conn.execute(ins)
  1214.     else:
  1215.         selectsql_stock_table = select([stock_table])
  1216.         result_stock_table = conn.execute(selectsql_stock_table)
  1217.         pre_count = 0
  1218.         for row in result_stock_table:
  1219.             if product_id == row[1]:
  1220.                 pre_count = row[2]
  1221.         upd = stock_table.update().where(stock_table.c.product_id == product_id).values(
  1222.             count=int(pre_count) - int(count)
  1223.         )
  1224.         conn.execute(upd)
  1225.         pass
  1226.  
  1227.  
  1228. def select_returns_window(old_page):
  1229.     LABEL_YPIXEL = 20
  1230.     PRODUCT_XPIXEL = 0
  1231.     TIME_XPIXEL = 80
  1232.     COUNT_XPIXEL = 160
  1233.     MONEY_XPIXEL = 240
  1234.     MANUFACTURES_XPIXEL = 300
  1235.  
  1236.     DELETE_XPIXEL = 530
  1237.     line = 0
  1238.  
  1239.     old_page.destroy()
  1240.     win_returns = tk.Tk()
  1241.     win_returns.title("returns")
  1242.     win_returns.geometry('600x400')
  1243.  
  1244.     label_Lusername = tk.Label(win_returns, text="User Name:").place(x=0, y=0)
  1245.     label_username = tk.Label(win_returns, text=G_user_name).place(x=80, y=0)
  1246.     label_Lproduct = tk.Label(win_returns, text="Product").place(x=PRODUCT_XPIXEL, y=LABEL_YPIXEL)
  1247.     label_Ltime = tk.Label(win_returns, text="Time").place(x=TIME_XPIXEL, y=LABEL_YPIXEL)
  1248.     label_Lcount = tk.Label(win_returns, text="Count").place(x=COUNT_XPIXEL, y=LABEL_YPIXEL)
  1249.     label_Lmoney = tk.Label(win_returns, text="Money").place(x=MONEY_XPIXEL, y=LABEL_YPIXEL)
  1250.     label_Lmanafacture = tk.Label(win_returns, text="Manufactures").place(x=MANUFACTURES_XPIXEL, y=LABEL_YPIXEL)
  1251.     btn_new_object = tk.Button(win_returns, text='Insert', command=lambda: returns_insert_window(win_returns)).pack(
  1252.         side="bottom")
  1253.     btn_open_main = tk.Button(win_returns, text='return', command=lambda:open_main_window(win_returns)).pack(
  1254.         side="bottom")
  1255.  
  1256.     selectsql_returns = select([returns_table])
  1257.     result = conn.execute(selectsql_returns)
  1258.  
  1259.     for row in result:
  1260.         selectsql_product_by_product_id = select([product_table]).where(product_table.c.id == row[1])
  1261.         result_product_name = conn.execute(selectsql_product_by_product_id)
  1262.         product_name = ''
  1263.         for name in result_product_name:
  1264.             product_name = name[1]
  1265.  
  1266.         label_pur_name = tk.Label(win_returns, text=product_name).place(x=PRODUCT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1267.         label_pur_stock = tk.Label(win_returns, text=row[2]).place(x=TIME_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1268.         label_pur_price = tk.Label(win_returns, text=row[3]).place(x=COUNT_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1269.         label_pur_purchase = tk.Label(win_returns, text=row[4]).place(x=MONEY_XPIXEL, y=LABEL_YPIXEL+(line+1)*30)
  1270.         label_pur_manafacture  = tk.Label(win_returns, text=row[4]).place(x=MANUFACTURES_XPIXEL, y=LABEL_YPIXEL+(line+1) * 30)
  1271.         btn_delete_pur = tk.Button(win_returns, text='delete', command=partial(delete_returns, win_returns, row[0])) \
  1272.             .place(x=DELETE_XPIXEL, y=LABEL_YPIXEL + (line + 1) * 30)
  1273.         line+=1
  1274.  
  1275. def returns_insert_window(old_page):
  1276.     old_page.destroy()
  1277.     win_returns_insert = tk.Tk()
  1278.     win_returns_insert.title("Insert returns")
  1279.     win_returns_insert.geometry('450x300')
  1280.  
  1281.     label_Lname = tk.Label(win_returns_insert, text="Product").grid(column=0, row=0)
  1282.     entry_name = tk.Entry(win_returns_insert)
  1283.     entry_name.grid(column=1, row=0)
  1284.     label_Lstock = tk.Label(win_returns_insert, text="Time").grid(column=0, row=1)
  1285.     entry_stock = tk.Entry(win_returns_insert)
  1286.     entry_stock.grid(column=1, row=1)
  1287.     label_Lprice = tk.Label(win_returns_insert, text="Count").grid(column=0, row=2)
  1288.     entry_price = tk.Entry(win_returns_insert)
  1289.     entry_price.grid(column=1, row=2)
  1290.     label_Lpurchase = tk.Label(win_returns_insert, text="Manufactures").grid(column=0, row=3)
  1291.     entry_purchase = tk.Entry(win_returns_insert)
  1292.     entry_purchase.grid(column=1, row=3)
  1293.  
  1294.     btn_insert = tk.Button(win_returns_insert, text="insert", command= lambda:insert_returns(win_returns_insert,
  1295.         entry_name.get(), entry_stock.get(), entry_price.get(), entry_purchase.get())).place(x=200, y=250)
  1296.     btn_return = tk.Button(win_returns_insert, text="return", command= lambda:select_returns_window(win_returns_insert))\
  1297.         .place(x=300, y=250)
  1298.  
  1299. def insert_returns(old_page, product, time, count, manufactures):
  1300.     print('\nproduct:', product)
  1301.     selectsql_returns = select([returns_table])
  1302.     result = conn.execute(selectsql_returns)
  1303.  
  1304.     product_id = 0
  1305.     product_price = 0
  1306.     stock_count = 0
  1307.     selectsql_product_by_product_name = select([product_table]).where(product_table.c.name == product)
  1308.     result_product_id = conn.execute(selectsql_product_by_product_name)
  1309.     for row in result_product_id:
  1310.         product_id = row[0]
  1311.         product_price = row[2]
  1312.     selectsql_stock_by_product_id = select([stock_table]).where(stock_table.c.product_id == product_id)
  1313.     result_stock = conn.execute(selectsql_stock_by_product_id)
  1314.     for row in result_stock:
  1315.         stock_count = row[2]
  1316.     id = 0
  1317.     for row in result:
  1318.         if not row[0] < id:
  1319.             id = row[0] + 1
  1320.  
  1321.     if product_id:
  1322.         if int(stock_count) > int(count):
  1323.             ins = returns_table.insert().values(
  1324.                 id= id,
  1325.                 product_id = product_id,
  1326.                 time= time,
  1327.                 count = count,
  1328.                 money = (int(product_price) * int(count)),
  1329.                 Manufacturers = manufactures
  1330.                 )
  1331.             conn.execute(ins)
  1332.  
  1333.             edit_stock(product_id, count, 0)
  1334.         else:
  1335.             messagebox.showerror(message='Error, the stock count is not enough, try again.')
  1336.     else:
  1337.         messagebox.showerror(message='Error, the product is not exist, try again.')
  1338.         pass
  1339.     select_returns_window(old_page)
  1340.  
  1341. def delete_returns(old_page, input_id):
  1342.     selectsql_returns = returns_table.select().where(returns_table.c.id == input_id)
  1343.     result_returns = conn.execute(selectsql_returns)
  1344.  
  1345.     returns_product_id = 0
  1346.     returns_count = 0
  1347.     for row in result_returns:
  1348.         returns_product_id = row[1]
  1349.         returns_count = -row[3]
  1350.  
  1351.     edit_stock(returns_product_id, returns_count, 0)
  1352.     deletesql_returns = returns_table.delete().where(returns_table.c.id == input_id)
  1353.     conn.execute(deletesql_returns)
  1354.     select_returns_window(old_page)
  1355.  
  1356.  
  1357.  
  1358.  
  1359. def usr_login(usr_name, usr_pwd):
  1360.     global win_login
  1361.     global G_user_name
  1362.  
  1363.     if usr_name in user_Info:
  1364.         if usr_pwd == user_Info[usr_name]:
  1365.             G_user_name = usr_name
  1366.             messagebox.showinfo(title='Welcome', message='How are you?' + usr_name)
  1367.             open_main_window(win_login)
  1368.         else:
  1369.             messagebox.showerror(message='Error, your password is wrong, try again.')
  1370.     else:
  1371.         messagebox.askyesno('Welcome','You have not sign up yet. Sign up today?')
  1372.  
  1373. def login_frame():
  1374.     global var_account
  1375.     global var_password
  1376.     global win_login
  1377.     win_login = tk.Tk()
  1378.     win_login.title("Log in")
  1379.     var_account = tk.StringVar()
  1380.     var_password = tk.StringVar()
  1381.  
  1382.     label=tk.Label(win_login, text="Log in!")
  1383.     label_account=tk.Label(win_login, text="account")
  1384.     label_password=tk.Label(win_login, text="password")
  1385.     entry_account=tk.Entry(win_login)
  1386.     entry_password=tk.Entry(win_login, show='*')
  1387.     btn_login=tk.Button(win_login, text="Log in", command=lambda :usr_login(entry_account.get(), entry_password.get()))
  1388.     label.grid(column=0,row=0)
  1389.  
  1390.  
  1391.     label_account.grid(column=0,row =ACCOUNTROW)
  1392.     entry_account.grid(column=1,row =ACCOUNTROW)
  1393.     label_password.grid(column=0,row =PASSWORDROW)
  1394.     entry_password.grid(column=1,row =PASSWORDROW)
  1395.     btn_login.grid(row = btnLOGINROW)
  1396.  
  1397.     win_login.mainloop()
  1398.  
  1399. login_frame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement