forked from LalitkumarDeshmukh/Inventory-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.py
316 lines (261 loc) · 14 KB
/
product.py
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
from tkinter import*
from PIL import Image,ImageTk #pip install pillow
from tkinter import ttk,messagebox
import sqlite3
class productClass:
def __init__(self,root):
self.cat_list=[]
self.sup_list=[]
self.root=root
self.root.geometry("1100x500+220+130")
self.root.title("Inventory Management System")
self.root.config(bg="white")
self.root.focus_force()
############################
self.var_searchby=StringVar()
self.var_searchtxt=StringVar()
self.var_pid=StringVar()
self.var_cat=StringVar()
self.var_sup=StringVar()
self.cat_list=[]
self.cat_list=[]
self.fetch_cat_sup()
self.var_name=StringVar()
self.var_price=StringVar()
self.var_qty=StringVar()
self.var_status=StringVar()
product_Frame=Frame(self.root,bd=3,relief=RIDGE,bg="white")
product_Frame.place(x=10,y=10,width=450,height=480)
#################TITLE##########
title=Label(product_Frame,text=" Manage Product Details",font=("goudy old style",15),bg="#0f4d7d",fg="white").pack(side=TOP,fill=X)
########COLUMN1#########
lbl_category=Label(product_Frame,text="Category",font=("goudy old style",15),bg="white").place(x=30,y=60,)
lbl_supplier=Label(product_Frame,text="Supplier",font=("goudy old style",15),bg="white").place(x=30,y=110)
lbl_product_name=Label(product_Frame,text="Name",font=("goudy old style",15),bg="white").place(x=30,y=160)
lbl_price=Label(product_Frame,text="Price",font=("goudy old style",15),bg="white").place(x=30,y=210)
lbl_qty=Label(product_Frame,text="Quantity",font=("goudy old style",15),bg="white").place(x=30,y=260)
lbl_status=Label(product_Frame,text="Status",font=("goudy old style",15),bg="white").place(x=30,y=310)
#======COLUMN2====
cmb_cat=ttk.Combobox(product_Frame,textvariable=self.var_cat,values=self.cat_list,state='readonly',justify=CENTER,font=("goudy old style",15))
cmb_cat.place(x=150,y=60,width=200)
cmb_cat.current(0)
cmb_sup=ttk.Combobox(product_Frame,textvariable=self.var_sup,values=self.sup_list,state='readonly',justify=CENTER,font=("goudy old style",15))
cmb_sup.place(x=150,y=110,width=200)
cmb_sup.current(0)
txt_name=Entry(product_Frame,textvariable=self.var_name,font=("goudy old style",15),bg='lightyellow').place(x=150,y=160,width=200)
txt_price=Entry(product_Frame,textvariable=self.var_price,font=("goudy old style",15),bg='lightyellow').place(x=150,y=210,width=200)
txt_qty=Entry(product_Frame,textvariable=self.var_qty,font=("goudy old style",15),bg='lightyellow').place(x=150,y=260,width=200)
cmb_status=ttk.Combobox(product_Frame,textvariable=self.var_status,values=("Active","Inactive"),state='readonly',justify=CENTER,font=("goudy old style",15))
cmb_status.place(x=150,y=310,width=200)
cmb_status.current(0)
#===buttons===
btn_add=Button(product_Frame,text="Save",command=self.add,font=("goudy old style",15),bg="#2196f3",fg="white",cursor="hand2").place(x=10,y=400,width=100,height=40)
btn_update=Button(product_Frame,text="Update",command=self.update,font=("goudy old style",15),bg="#4caf50",fg="white",cursor="hand2").place(x=120,y=400,width=100,height=40)
btn_delete=Button(product_Frame,text="Delete",command=self.delete,font=("goudy old style",15),bg="#f44336",fg="white",cursor="hand2").place(x=230,y=400,width=100,height=40)
btn_clear=Button(product_Frame,text="Clear",command=self.clear,font=("goudy old style",15),bg="#607d8b",fg="white",cursor="hand2").place(x=340,y=400,width=100,height=40)
#========searchframe===========
SearchFrame=LabelFrame(self.root,text="Search Employee",font=("goudy old style",12,"bold"),bd=2,relief=RIDGE,bg="white")
SearchFrame.place(x=480,y=10,width=600,height=80)
txt_search=Entry(SearchFrame,textvariable=self.var_searchtxt,font=("goudy old style",15),bg="lightyellow").place(x=200,y=10)
btn_search=Button(SearchFrame,text="Search",command=self.search,font=("goudy old style",15),bg="#4caf50",fg="white",cursor="hand2").place(x=410,y=9,width=150,height=30)
#======options====
cmb_search=ttk.Combobox(SearchFrame,textvariable=self.var_searchby,values=("Select","Category","Supplier","Name",),state='readonly',justify=CENTER,font=("goudy old style",15))
cmb_search.place(x=10,y=10,width=180)
cmb_search.current(0)
#product details======
p_frame=Frame(self.root,bd=3,relief=RIDGE)
p_frame.place(x=480,y=100,width=600,height=390)
scrolly=Scrollbar(p_frame,orient=VERTICAL)
scrollx=Scrollbar(p_frame,orient=HORIZONTAL)
self.product_table=ttk.Treeview(p_frame,columns=("pid","Supplier","Category","name","qty","price","status"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.product_table.xview)
scrolly.config(command=self.product_table.yview)
self.product_table.heading("pid",text="P ID")
self.product_table.heading("Category",text="Category")
self.product_table.heading("Supplier",text="Supplier name")
self.product_table.heading("name",text="Name")
self.product_table.heading("qty",text="Qty")
self.product_table.heading("price",text="price")
self.product_table.heading("status",text="Status")
self.product_table["show"]="headings"
self.product_table.column("pid",width=90)
self.product_table.column("Category",width=100)
self.product_table.column("Supplier",width=100)
self.product_table.column("name",width=100)
self.product_table.column("qty",width=100)
self.product_table.column("price",width=100)
self.product_table.column("status",width=100)
self.product_table.pack(fill=BOTH,expand=1)
self.product_table.bind("<ButtonRelease-1>",self.get_data)
self.show()
#===============================================================================================
def fetch_cat_sup(self):
self.cat_list.append("Empty")
self.sup_list.append("Empty")
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
cur.execute("Select name from category")
cat=cur.fetchall()
if len(cat)>0:
del self.cat_list[:]
self.cat_list.append("Select")
for i in cat:
self.cat_list.append(i[0])
cur.execute("Select name from supplier")
sup=cur.fetchall()
if len(sup)>0:
del self.sup_list[:]
self.sup_list.append("Select")
for i in sup:
self.sup_list.append(i[0])
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def add(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
cur.execute("Select * from category")
if self.var_cat.get()=="Select" or self.var_cat.get()=="Empty" or self.var_sup.get()=="Select" or self.var_name.get()=="":
messagebox.showerror("Error","All fields are required ",parent=self.root)
else:
cur.execute("Select * from product where name=?",(self.var_name.get(),))
row=cur.fetchone()
if row!=None:
messagebox.showerror("Product already available, try different",parent=self.root)
else:
cur.execute("Insert into product (Category,Supplier,name,qty,price,status) values(?,?,?,?,?,?)",(
self.var_cat.get(),
self.var_sup.get(),
self.var_name.get(),
self.var_qty.get(),
self.var_price.get(),
self.var_status.get(),
))
con.commit()
messagebox.showinfo("Success","Product Added Successfully",parent=self.root)
self.show()
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def show(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
cur.execute("select * from product")
rows=cur.fetchall()
self.product_table.delete(*self.product_table.get_children())
for row in rows:
self.product_table.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def get_data(self,ev):
f=self.product_table.focus()
content=(self.product_table.item(f))
row=content['values']
self.var_pid.set(row[0])
self.var_cat.set(row[2])
self.var_sup.set(row[1])
self.var_name.set(row[3])
self.var_qty.set(row[4])
self.var_price.set(row[5])
self.var_status.set(row[6])
def update(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_pid.get()=="":
messagebox.showerror("Error","Please select product from list",parent=self.root)
else:
cur.execute("Select * from product where pid=?",(self.var_emp_id.get(),))
row=cur.fetchone()
if row==None:
messagebox.showerror("Error","Invalid Product",parent=self.root)
else:
cur.execute("Update product set Category=?,Supplier=?,name=?,price=?,qty=?,status=? where pid=?",(
self.var_cat.get(),
self.var_sup.get(),
self.var_name.get(),
self.var_qty.get(),
self.var_price.get(),
self.var_status.get(),
self.var_pid.get()
))
con.commit()
messagebox.showinfo("Success","Product Updated Successfully",parent=self.root)
self.show()
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def show(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
cur.execute("select * from employee")
rows=cur.fetchall()
self.product_table.delete(*self.product_table.get_children())
for row in rows:
self.product_table.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def delete(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_pid.get()=="":
messagebox.showerror("Error","Select product from the list",parent=self.root)
else:
cur.execute("Select * from product where pid=?",(self.var_pid.get(),))
row=cur.fetchone()
if row==None:
messagebox.showerror("Error","Invalid Product",parent=self.root)
else:
op=messagebox.askyesno("Confirm","Do you really want to delete?",parent=self.root)
if op==True:
cur.execute("delete from product where pid=?",(self.var_pid.get(),))
con.commit()
messagebox.showinfo("Delete","Product Deleted Successfully",parent=self.root)
self.clear()
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def clear(self):
self.var_cat.set("Select")
self.var_sup.set("Select")
self.var_name.set("")
self.var_qty.set("")
self.var_price.set("")
self.var_status.set("Active")
self.var_pid.set("")
self.var_searchtxt.set("")
self.var_searchby.set("Select")
self.show()
def search(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_searchby.get()=="Select":
messagebox.showerror("Error","Select Search By option",parent=self.root)
elif self.var_searchtxt.get()=="":
messagebox.showerror("Error","Select input should be required",parent=self.root)
else:
searchby=StringVar()
if self.var_searchby.get()=="Name":
searchby.set("name")
elif self.var_searchby.get()=="Category":
searchby.set("Category")
else:
searchby.set("Supplier")
cur.execute("select * from product where "+str(searchby.get())+"= '"+str(self.var_searchtxt.get())+"'")
rows=cur.fetchall()
if len(rows)!=0:
self.product_table.delete(*self.product_table.get_children())
for row in rows:
self.product_table.insert('',END,values=row)
else:
messagebox.showerror("Error","No record found!!!",parent=self.root)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
if __name__=="__main__":
root=Tk()
obj=productClass(root)
root.mainloop()