From 963e2181aefc1982fb7a5c9db57d82fff6de0e3e Mon Sep 17 00:00:00 2001 From: Chang Yi Chen Date: Tue, 21 Sep 2021 16:21:06 +0800 Subject: [PATCH] edit --- app.py | 3 ++- customerItem.py | 27 +++++++++++---------------- data.py | 6 +++--- product_data.py | 36 ------------------------------------ products.db | Bin 8192 -> 12288 bytes test.py | 4 ++-- 6 files changed, 18 insertions(+), 58 deletions(-) delete mode 100644 product_data.py diff --git a/app.py b/app.py index 122aeca..5e53836 100644 --- a/app.py +++ b/app.py @@ -15,7 +15,8 @@ class App(Tk): def __init__(self): Tk.__init__(self) self._frame = None - self.switch_frame(Past_Purchase_Page) + #self.switch_frame(Past_Purchase_Page) + self.switch_frame(customerItem_Page) def switch_frame(self, frame_class): new_frame = frame_class(self) diff --git a/customerItem.py b/customerItem.py index edc8232..ed10972 100644 --- a/customerItem.py +++ b/customerItem.py @@ -8,20 +8,15 @@ class customerItem_Page(Frame): def __init__(self, master): Frame.__init__(self, master) self.master = master - - def show(): - conn = sqlite3.connect('products.db') + getProducts() - c = conn.cursor() - - c.execute(''' - SELECT * FROM products - ''', ['']) - - for product in c.fetchall(): - print(product) - - conn.commit() - conn.close() - - filter_btn = Button(self, text="FILTER", command = show) \ No newline at end of file + def getProducts(): + my_conn = sqlite3.connect('products.db') + r_set=my_conn.execute('''SELECT * from products'''); + i=0 # row value inside the loop + for product in r_set: + for j in range(len(product)): + e = Entry(self, width=10, fg='blue') + e.grid(row=i, column=j) + e.insert(END, product[j]) + i=i+1 \ No newline at end of file diff --git a/data.py b/data.py index f879bc7..ed5ef15 100644 --- a/data.py +++ b/data.py @@ -23,11 +23,11 @@ INSERT INTO products VALUES (?,?,?,?,?,?) ''', [row['Category'], - row['Cost ($)'], + row['Cost'], row['Model'], - row['Price ($)'], + row['Price'], row['ProductID'], - row['Warranty (months)']] + row['Warranty']] ) # cursor.execute(''' diff --git a/product_data.py b/product_data.py deleted file mode 100644 index b902ba2..0000000 --- a/product_data.py +++ /dev/null @@ -1,36 +0,0 @@ -import sqlite3 -import sqlite3 -import json - -with open('products.json') as f: - data = json.load(f) - -conn = sqlite3.connect('products.db') - -cursor = conn.cursor() - -cursor.execute(''' -CREATE TABLE items ( - Category TEXT, - Cost INTEGER, - Model TEXT, - Price INTEGER, - ProductID INTEGER, - Warranty INTEGER); -''') - -for row in data: - cursor.execute(''' - INSERT INTO items VALUES (?,?,?,?,?,?) - ''', - [row['Category'], - row['Cost'], - row['Model'], - row['Price'], - row['ProductID'], - row['Warranty']] - ) - -conn.commit() - -conn.close() \ No newline at end of file diff --git a/products.db b/products.db index 7ea8f4f7eaa54b25b90614c999f18fce66648602..0250929b4c9fbff6459a613afb7383a5d6d11199 100644 GIT binary patch literal 12288 zcmeI#zi-n(6bJA-JBeG1>M=C9Rh87M=W-TB97yUwF#U&dlTNr#~nRd$te z&h7}o7&Fu`)yRXZn?hcwtFA8#gWcLWouRMHpgBf!^yab+=tBSk5P$##AOHafKmY;| zfB*#krNG%Tx136azq~2Ky+QmuO`@Zo%<`*IZ~L{t7eVcA(---yxNZv-^-#tKNqQmz z|4Fbso=P$))RyMB+)ko+Fwt(M{a!rLZ;fBq*c`19t#)I(*4`Bl{N3^X$6=a=hw?-; z9tQqBzkOrHC^_{CXZ^z{KF(eY)S12;9?4`>ck}P-y7`?x*H3BB88s~0Vf2yS(Q7)V zS2R#10s;_#00bZa0SG_<0uX=z1Rwx`zY8o_mcy3};?1P@EQ>nBFqQX{VeGQE8&}FD z)pYoerq>Dg-u5GJ-vFL))H~K=K=@WgR_o_rd00Izz00bZa0SG_<0uX=z h1R(JL3lvS_8= literal 8192 zcmeI#O-jQ+7zW^(^d}nBabX)up-guQA~fB)u-2%BsI?8~Ha2N3HVz~sSfq=Bx9}F8 z!kyRf7*0Z}1wjwsJ0vstzIT$qvzz{38F3x2tWV=5P$##AOHafKmY;|fWUtcm~T+sG)+2xlHScEP)F}D zPA9G1vs$j;GH@5+lJ?_N$9t)1j-uCp#-AMBmIvKRKuLRDfw00Izz00bZa0SG_<0uX=z z1R(H>KvmaGTGuFb#NaOW`=J-fQxOIY@}{qqiYhc|7FvC87&K=^qg43OwjK*cDZkvV yCA%Ab-l*pE3auv}8INvdT>JjTac;%bR9N{6%jq6#Un`br8mwk-ZKXlOGCl#d#9q(< diff --git a/test.py b/test.py index 46ed74f..5c0a8d6 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,6 @@ import sqlite3 -connection = sqlite3.connect('items.db') +connection = sqlite3.connect('products.db') cursor = connection.cursor() -cursor.execute('SELECT * FROM products WHERE ItemID < 1005') +cursor.execute('SELECT * FROM products') print(cursor.fetchall()) \ No newline at end of file