Repository navigation
Expand file tree
/
Copy pathinventorySystem.py
More file actions
398 lines (315 loc) · 15.3 KB
/
Copy pathinventorySystem.py
File metadata and controls
398 lines (315 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# MAIN FILE (inventorySystem.py)
import tkinter as tk
from tkinter import ttk, messagebox
from tkinter import *
from PIL import ImageTk,Image
import database
# Initialize main tkinter window
w=Tk()
w.title('Login')
w.configure(bg='#ff4f5a')
w.resizable(False, False)
# Center the window on the screen
window_width = 925
window_height = 500
screen_width = w.winfo_screenwidth()
screen_height = w.winfo_screenheight()
x_position = (screen_width - window_width) // 2
y_position = (screen_height - window_height) // 2
w.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")
# Function to handle sign-in process
def signin():
# Create sign-in window
signin_win=Frame(w,width=925,height=500,bg='white')
signin_win.place(x=0,y=0)
f1=Frame(signin_win,width=350,height=350,bg='white')
f1.place(x=480,y=100)
# Load and display image
global img1
img1 = ImageTk.PhotoImage(Image.open(r"C:\Users\Luis Cortez\Documents\PYTHON DEFENSE\img.png"))
Label(signin_win,image=img1,border=0,bg='white').place(x=70,y=76)
# Sign-in label
l2=Label(signin_win,text="Inventory Sign in",fg='#ff4f5a',bg='white')
l2.config(font=('Microsoft YaHei UI Light',18, 'bold'))
l2.place(x=550,y=80)
# Username entry
e1 =Entry(f1,width=45,fg='black',border=0,bg='white')
e1_label = Label(f1,text="Username:", bg='white')
e1.config(font=('Microsoft YaHei UI Light',11, ))
e1_label.config(font=('Microsoft YaHei UI Light',11))
e1.place(x=120,y=60)
e1_label.place(x=40,y=58)
Frame(f1,width=198,height=1,bg='black').place(x=115,y=87)
#------------------------------------------------------
# Password entry
e2 =Entry(f1,width=21,fg='black',border=0,bg='white',show='*')
e2_label = Label(f1,text="Password:", bg='white')
e2.config(font=('Microsoft YaHei UI Light',11, ))
e2_label.config(font=('Microsoft YaHei UI Light',11))
e2.place(x=120,y=130)
e2_label.place(x=40,y=128)
Frame(f1,width=198,height=1,bg='black').place(x=115,y=157)
def signin_cmd():
# Hardcoded username and password
username = "admin"
password = "admin123"
if e1.get() == username and e2.get() == password:
# This show success message and proceed to inventory application
messagebox.showinfo(title="Login Success", message="You successfully logged in.")
w.destroy()
inventory_app = tk.Tk()
InventorySystemGUI(inventory_app)
inventory_app.mainloop()
else:
# Show error message for invalid login
messagebox.showerror(title="Error", message="Invalid login.")
#------------------------------------------------------
# Sign-in button
Button(f1,width=38,pady=7,text='Sign in',bg='#ff4f5a',fg='white',border=0,command=signin_cmd).place(x=45,y=204)
# Call the signin function to display the login screen
signin()
# Create database table if not exists
database.create_table()
# Class for Inventory System GUI
class InventorySystemGUI:
def __init__(self, root):
# Initialize root window
self.root = root
self.root.title("Inventory System")
self.root.protocol("WM_DELETE_WINDOW", self.on_closing) # Bind on_closing to the closing event
# Center the window on the screen
window_width = 800
window_height = 450 # Adjust this as needed
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_position = (screen_width - window_width) // 2
y_position = (screen_height - window_height) // 2
root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")
root.resizable(False, False)
title_frame = tk.Frame(root, bg='#CCCCCC')
title_frame.pack(fill='x', pady=10)
title_label = tk.Label(root, text="Inventory Management System", font=("Arial", 22))
title_label.pack(expand=True)
# Search gui
search_frame = tk.Frame(root)
search_frame.pack(pady=15, padx=10)
product_name_label = tk.Label(search_frame, text="Product Name:")
product_name_label.grid(row=0, column=0, padx=(0, 5))
self.product_name_entry = tk.Entry(search_frame, width=15)
self.product_name_entry.grid(row=0, column=1, padx=(0, 5))
item_no_label = tk.Label(search_frame, text="Item No.:")
item_no_label.grid(row=0, column=2, padx=(0, 5))
self.item_no_entry = tk.Entry(search_frame, width=15)
self.item_no_entry.grid(row=0, column=3, padx=(0, 5))
category_label = tk.Label(search_frame, text="Category:")
category_label.grid(row=0, column=4, padx=(0, 5))
self.category_var = tk.StringVar()
category_options = ["All","BTS", "BLACKPINK", "EXO", "BGYO", "BINI", "HORI7ON", "TWICE", "ITZY"]
self.category_dropdown = ttk.Combobox(search_frame, textvariable=self.category_var, values=category_options, state="readonly")
self.category_dropdown.grid(row=0, column=5, padx=(0, 5))
self.category_var.set("All")
search_button = tk.Button(search_frame, text="Search", command=self.search_product)
search_button.grid(row=0, column=6)
show_all_button = tk.Button(search_frame, text="Show All Records", command=self.show_all_records)
show_all_button.grid(row=0, column=7, padx=(10, 0))
# Table headings
columns = ("Item No.", "Product Name", "Category", "Quantity", "Price")
self.tree = ttk.Treeview(root, columns=columns, show="headings", height=10)
style = ttk.Style(root)
style.theme_use("clam")
for col in columns:
self.tree.heading(col, text=col)
self.tree.column(col, width=125, anchor=tk.CENTER)
self.tree.pack(pady=20)
# Bottom buttons
button_frame = tk.Frame(root)
button_frame.pack(pady=10)
add_button = tk.Button(button_frame, text="Add", command=self.show_add_item_window)
add_button.grid(row=0, column=0, padx=10, pady=10)
remove_button = tk.Button(button_frame, text="Remove", command=self.remove_product)
remove_button.grid(row=0, column=1, padx=10, pady=10)
edit_button = tk.Button(button_frame, text="Edit", command=self.edit_product)
edit_button.grid(row=0, column=2, padx=10)
self.show_all_records()
# Method to search for products
def search_product(self):
search_text = self.product_name_entry.get()
item_no_search = self.item_no_entry.get()
category_search = self.category_var.get()
filtered_items = database.search_items(search_text, item_no_search, category_search)
for item in self.tree.get_children():
self.tree.delete(item)
for item in filtered_items:
self.tree.insert("", "end", values=item)
if not filtered_items:
messagebox.showinfo("Search Results", "No matching items found.")
# Method to display all records
def show_all_records(self):
all_items = database.show_all_records()
for item in self.tree.get_children():
self.tree.delete(item)
for item in all_items:
self.tree.insert("", "end", values=item)
# Method to add a new item
def add_item(self, item_data):
database.add_item(item_data)
self.show_all_records()
# Method to display the window for adding a new item
def show_add_item_window(self):
add_item_window = AddItemWindow(self.root, self.add_item)
# Method to remove a product
def remove_product(self):
selected_items = self.tree.selection()
if not selected_items:
messagebox.showerror("Error", "Please select a product to remove.")
return
confirmation = messagebox.askyesno("Confirmation", "Are you sure you want to remove the selected item?")
if confirmation:
for selected_item in selected_items:
item_data = self.tree.item(selected_item)['values']
database.remove_product(item_data[0])
self.tree.delete(selected_item)
else:
return
# Method to edit a product
def edit_product(self):
selected_items = self.tree.selection()
if not selected_items:
messagebox.showerror("Error", "Please select a product to edit.")
return
for selected_item in selected_items:
item_data = self.tree.item(selected_item)['values']
edit_window = EditItemWindow(self.root, item_data, self.update_item)
# Method to update a product
def update_item(self, item_no, new_item_data):
database.update_item(item_no, new_item_data)
selected_item = self.tree.selection()[0]
self.tree.item(selected_item, values=new_item_data)
# Method to handle window closing event
def on_closing(self):
confirmation = messagebox.askokcancel("Quit", "Are you sure you want to quit the program?")
if confirmation:
self.root.destroy()
# Class for adding a new item window
class AddItemWindow:
def __init__(self, root, add_func):
self.root = root
self.add_func = add_func
self.top = tk.Toplevel(root)
self.top.title("Add Item")
# Center the window on the screen
window_width = 250
window_height = 170 # Adjust this as needed
screen_width = self.top.winfo_screenwidth()
screen_height = self.top.winfo_screenheight()
x_position = (screen_width - window_width) // 2
y_position = (screen_height - window_height) // 2
self.top.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")
self.top.resizable(False, False)
product_name_label = tk.Label(self.top, text="Product Name:")
product_name_label.grid(row=0, column=0, padx=5, pady=5)
self.product_name_entry = tk.Entry(self.top)
self.product_name_entry.grid(row=0, column=1, padx=5, pady=5)
category_label = tk.Label(self.top, text="Category:")
category_label.grid(row=1, column=0, padx=5, pady=5)
self.category_var = tk.StringVar()
category_options = ["BTS", "BLACKPINK", "EXO", "BGYO", "BINI", "HORI7ON", "TWICE", "ITZY"]
self.category_dropdown = ttk.Combobox(self.top, textvariable=self.category_var, values=category_options, state="readonly")
self.category_dropdown.grid(row=1, column=1, padx=5, pady=5)
quantity_label = tk.Label(self.top, text="Quantity:")
quantity_label.grid(row=2, column=0, padx=5, pady=5)
self.quantity_entry = tk.Entry(self.top)
self.quantity_entry.grid(row=2, column=1, padx=5, pady=5)
price_label = tk.Label(self.top, text="Price:")
price_label.grid(row=3, column=0, padx=5, pady=5)
self.price_entry = tk.Entry(self.top)
self.price_entry.grid(row=3, column=1, padx=5, pady=5)
add_button = tk.Button(self.top, text="Add", command=self.add_item)
add_button.grid(row=4, column=0, columnspan=2, padx=5, pady=5)
# Method to add a new item
def add_item(self):
product_name = self.product_name_entry.get()
category = self.category_var.get()
quantity = self.quantity_entry.get()
price = self.price_entry.get()
if not all([product_name, category, quantity, price]):
messagebox.showerror("Error", "Please fill all fields.")
return
if not quantity.isdigit():
messagebox.showerror("Error", "Quantity must be a valid integer.")
return
try:
price = float(price)
except ValueError:
messagebox.showerror("Error", "Price must be a valid number.")
return
self.add_func((product_name, category, int(quantity), price))
self.top.destroy()
# Class for editing an item window
class EditItemWindow:
def __init__(self, root, item_data, update_func):
self.root = root
self.update_func = update_func
self.item_data = item_data
self.top = tk.Toplevel(root)
self.top.title("Edit Item")
# Center the window on the screen
window_width = 250
window_height = 193 # Adjust this as needed
screen_width = self.top.winfo_screenwidth()
screen_height = self.top.winfo_screenheight()
x_position = (screen_width - window_width) // 2
y_position = (screen_height - window_height) // 2
self.top.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")
self.top.resizable(False, False)
# Labels and entries for item information
item_no_label = tk.Label(self.top, text="Item No.:")
item_no_label.grid(row=0, column=0, padx=5, pady=5)
self.item_no_entry = tk.Entry(self.top, state='readonly')
self.item_no_entry.grid(row=0, column=1, padx=5, pady=5)
self.item_no_entry.insert(0, item_data[0])
product_name_label = tk.Label(self.top, text="Product Name:")
product_name_label.grid(row=1, column=0, padx=5, pady=5)
self.product_name_entry = tk.Entry(self.top)
self.product_name_entry.grid(row=1, column=1, padx=5, pady=5)
self.product_name_entry.insert(0, item_data[1])
category_label = tk.Label(self.top, text="Category:")
category_label.grid(row=2, column=0, padx=5, pady=5)
self.category_var = tk.StringVar()
category_options = ["BTS", "BLACKPINK", "EXO", "BGYO", "BINI", "HORI7ON", "TWICE", "ITZY"]
self.category_dropdown = ttk.Combobox(self.top, textvariable=self.category_var, values=category_options, state="readonly")
self.category_dropdown.grid(row=2, column=1, padx=5, pady=5)
self.category_var.set(item_data[2])
quantity_label = tk.Label(self.top, text="Quantity:")
quantity_label.grid(row=3, column=0, padx=5, pady=5)
self.quantity_entry = tk.Entry(self.top)
self.quantity_entry.grid(row=3, column=1, padx=5, pady=5)
self.quantity_entry.insert(0, item_data[3])
price_label = tk.Label(self.top, text="Price:")
price_label.grid(row=4, column=0, padx=5, pady=5)
self.price_entry = tk.Entry(self.top)
self.price_entry.grid(row=4, column=1, padx=5, pady=5)
self.price_entry.insert(0, item_data[4])
update_button = tk.Button(self.top, text="Update", command=self.update_item)
update_button.grid(row=5, column=0, columnspan=2, padx=5, pady=5)
# Method to update an item
def update_item(self):
product_name = self.product_name_entry.get()
category = self.category_var.get()
quantity = self.quantity_entry.get()
price = self.price_entry.get()
if not all([product_name, category, quantity, price]):
messagebox.showerror("Error", "Please fill all fields.")
return
if not quantity.isdigit():
messagebox.showerror("Error", "Quantity must be a valid integer.")
return
try:
price = float(price)
except ValueError:
messagebox.showerror("Error", "Price must be a valid number.")
return
new_item_data = (self.item_data[0], product_name, category, int(quantity), price)
self.update_func(self.item_data[0], new_item_data) # Pass both item_no and new_item_data to the update_func
self.top.destroy()
w.mainloop()