From c164d563d020007d1da9f58333bfec466ae51bef Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 19 Feb 2023 20:51:37 +0700 Subject: [PATCH] Sell Item --- mm.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mm.py b/mm.py index fac078d..b49a7a4 100644 --- a/mm.py +++ b/mm.py @@ -104,8 +104,10 @@ def buy_item(item_id): VALUES (?, ?) """, (current_user_id, item_id)) + item_id = cursor.lastrowid conn.commit() cursor.close() + return item_id def mine(a,b,user_data): source_id,well_name = user_data @@ -131,6 +133,15 @@ def destroy(source_id): conn.commit() cursor.close() +def sell(item_id): + cursor = conn.cursor() + + cursor.execute("DELETE FROM inventory_item WHERE user_id = ? AND id = ?", + (current_user_id,item_id)) + + conn.commit() + cursor.close() + def sell_all(): cursor = conn.cursor() @@ -204,12 +215,19 @@ while True: break elif type(event) is tuple: if event[0] == "-UPGRADE-": - print("Upgrade") + sg.Window.Layout([[sg.Text("IT WORKED")]]) + print('asdf') + elif event[0] == "-SELL-": + id = event[1] + inv = get_inventory() + sell(id) + window[("-BUY-",inv[id][0])].update(disabled=False) + window[("-IROW-",id)].update(visible=False) elif event[0] == "-BUY-": id = event[1] - buy_item(id) + item_id = buy_item(id) window[("-BUY-",id)].update(disabled=True) - window.extend_layout(window["-COL-"], [inventory_row(id,id,0)]) + window.extend_layout(window["-COL-"], [inventory_row(item_id,id,0)]) elif event[0] == "-DESTROY-": destroy(event[1]) else: