forked from LalitkumarDeshmukh/Inventory-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.py
131 lines (108 loc) · 5.52 KB
/
category.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
from tkinter import*
from PIL import Image,ImageTk #pip install pillow
from tkinter import ttk,messagebox
import sqlite3
class categoryClass:
def __init__(self,root):
self.root=root
self.root.geometry("1100x500+220+130")
self.root.title("Inventory Management System")
self.root.config(bg="white")
self.root.focus_force()
#=====variable===
self.var_cat_id=StringVar()
self.var_name=StringVar()
#=======title===
lbl_title=Label(self.root,text="Manage Product Category",font=("goudy old style",30),bg="#184a45",fg="white",bd=3,relief=RIDGE).pack(side=TOP,fill=X,padx=10,pady=20)
lbl_name=Label(self.root,text="Enter Category Name",font=("goudy old style",30),bg="white").place(x=50,y=100)
txt_name=Entry(self.root,textvariable=self.var_name,font=("goudy old style",25),bg="lightyellow").place(x=50,y=170,width=300)
btn_add=Button(self.root,text="ADD",command=self.add,font=("goudy old style",15),bg="#4caf50",fg="white",cursor="hand2").place(x=360,y=170,width=150,height=30)
btn_delete=Button(self.root,text="DELETE",command=self.delete,font=("goudy old style",15),bg="red",fg="white",cursor="hand2").place(x=520,y=170,width=150,height=30)
#category details======
cat_frame=Frame(self.root,bd=3,relief=RIDGE)
cat_frame.place(x=700,y=100,width=380,height=100)
scrolly=Scrollbar(cat_frame,orient=VERTICAL)
scrollx=Scrollbar(cat_frame,orient=HORIZONTAL)
self.category_table=ttk.Treeview(cat_frame,columns=("cid","name"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.category_table.xview)
scrolly.config(command=self.category_table.yview)
self.category_table.heading("cid",text="C ID")
self.category_table.heading("name",text="Name")
self.category_table["show"]="headings"
self.category_table.column("cid",width=90)
self.category_table.column("name",width=100)
self.category_table.pack(fill=BOTH,expand=1)
self.category_table.bind("<ButtonRelease-1>",self.get_data)
#==images==
self.im1=Image.open("images/cat.jpg")
self.im1=self.im1.resize((500,250),Image.ANTIALIAS)
self.im1=ImageTk.PhotoImage(self.im1)
self.lbl_im1=Label(self.root,image=self.im1,bd=2,relief=RAISED)
self.lbl_im1.place(x=50,y=220)
self.im2=Image.open("images/cat2.jpg")
self.im2=self.im2.resize((500,250),Image.ANTIALIAS)
self.im2=ImageTk.PhotoImage(self.im2)
self.lbl_im2=Label(self.root,image=self.im2,bd=2,relief=RAISED)
self.lbl_im2.place(x=580,y=220)
self.show()
#=============functions=================
def add(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_name.get()=="":
messagebox.showerror("Error","Category name should be required",parent=self.root)
else:
cur.execute("Select * from category where name=?",(self.var_name.get(),))
row=cur.fetchone()
if row!=None:
messagebox.showerror("Error","Category already present, try different",parent=self.root)
else:
cur.execute("Insert into Category (name) values(?)",(self.var_name.get(),))
con.commit()
messagebox.showinfo("Success","Category 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 category")
rows=cur.fetchall()
self.category_table.delete(*self.category_table.get_children())
for row in rows:
self.category_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.category_table.focus()
content=(self.category_table.item(f))
row=content['values']
# print(row)
self.var_cat_id.set(row[0]),
self.var_name.set(row[1]),
def delete(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_cat_id.get()=="":
messagebox.showerror("Error","please select category from the list",parent=self.root)
else:
cur.execute("Select * from category where cid=?",(self.var_cat_id.get(),))
row=cur.fetchone()
if row==None:
messagebox.showerror("Error","Error, please try again",parent=self.root)
else:
op=messagebox.askyesno("Confirm","Do you really want to delete?",parent=self.root)
if op==True:
cur.execute("delete from category where cid=?",(self.var_cat_id.get(),))
con.commit()
messagebox.showinfo("Delete","category Deleted Successfully",parent=self.root)
self.show()
self.var_cat_id.set("")
self.var_name.set("")
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)