Repository navigation
Expand file tree
/
Copy pathinsert_db.py
More file actions
104 lines (92 loc) · 5.17 KB
/
Copy pathinsert_db.py
File metadata and controls
104 lines (92 loc) · 5.17 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
from tkinter import *
import sqlite3
import tkinter.messagebox
conn = sqlite3.connect("E:/Database/store.db")
c = conn.cursor()
class Database:
def __init__(self, master, *args, **kwargs):
self.master = master
self.heading = Label(master, text="Sayem Digital Studio", font=("Helvetica", 20, "bold"), fg='#4F4F4F')
self.heading.place(x=0, y=0)
self.subheading = Label(master, text="Panch Gaon Golap Bajar, Araihazar, Narayanganj",
font=("Helvetica", 9, "bold"), fg='#4F4F4F')
self.subheading.place(x=0, y=35)
self.subheading = Label(master, text="Proprietor : Sayem Library", font=("Helvetica", 10, "normal"),
fg='#4F4F4F')
self.subheading.place(x=0, y=60)
self.subheading = Label(master, text="Contact : 01787325232", font=("Helvetica", 10, "normal"), fg='#4F4F4F')
self.subheading.place(x=0, y=80)
# label and entries for the window
self.name_p_l = Label(master, text="Product Name : ", font=("Helvetica", 12, "bold"), fg='#00A9A5')
self.name_p_l.place(x=0, y=150)
self.price_p_l = Label(master, text="Product Price : ", font=("Helvetica", 12, "bold"), fg='#00A9A5')
self.price_p_l.place(x=0, y=180)
self.stock_p_l = Label(master, text="Products on Stock : ", font=("Helvetica", 12, "bold"), fg='#00A9A5')
self.stock_p_l.place(x=0, y=210)
# entries for the labels
self.name_p_e = Entry(master, width=20, font=('Hevaltica 12 normal'), fg='#FF5E5B')
self.name_p_e.place(x=170, y=150)
self.price_p_e = Entry(master, width=20, font=('Hevaltica 12 normal'), fg='#FF5E5B')
self.price_p_e.place(x=170, y=180)
self.stock_p_e = Entry(master, width=20, font=('Hevaltica 12 normal'), fg='#FF5E5B')
self.stock_p_e.place(x=170, y=210)
# buttons for inserting
self.btn_add = Button(master, text="Insert", width=7, height=1, bg='green', fg='white',
font=('Hevaltica 12 bold'), command=self.items)
self.btn_add.place(x=170, y=240)
self.btn_update = Button(master, text="Update", width=7, height=1, bg='orange', fg='white',
font=('Hevaltica 12 bold'), command=self.update)
self.btn_update.place(x=260, y=240)
self.btn_delete = Button(master, text="Delete", width=7, height=1, bg='red', fg='white',
font=('Hevaltica 12 bold'), command=self.delete_record)
self.btn_delete.place(x=170, y=280)
self.btn_clear = Button(master, text="Clear", width=7, height=1, bg='Black', fg='white',
font=('Hevaltica 12 bold'), command=self.clear_all)
self.btn_clear.place(x=260, y=280)
# advertise
self.company = Label(master, text="Made by Nazibur Rahman", font=("Consolas", 10, "bold"), fg='#4F4F4F')
self.company.place(x=640, y=540)
self.company = Label(master, text="B.Sc. in Computer Science & Engineering", font=("Consolas", 10, "bold"),
fg='#4F4F4F')
self.company.place(x=520, y=560)
self.company = Label(master, text="Manarat International University, Ashulia", font=("Consolas", 10, "bold"),
fg='#4F4F4F')
self.company.place(x=508, y=580)
def items(self, *args, **kwargs):
# get from entries
self.name = self.name_p_e.get()
self.price = self.price_p_e.get()
self.stock = self.stock_p_e.get()
if self.name == '' or self.price == '' or self.stock == '':
tkinter.messagebox.showinfo("Error", "Please fill all the Entries.")
else:
sql = "INSERT INTO inventory (p_name,p_price,p_stock) VALUES(?,?,?)"
c.execute(sql, (self.name, self.price, self.stock))
conn.commit()
tkinter.messagebox.showinfo("Success", "Successfully added to database")
def clear_all(self, *args, **kwargs):
self.name_p_e.delete(0, END)
self.price_p_e.delete(0, END)
self.stock_p_e.delete(0, END)
def update(self, *args, **kwargs):
self.name = self.name_p_e.get()
self.price = self.price_p_e.get()
self.stock = self.stock_p_e.get()
if self.name == '' or self.stock == '':
tkinter.messagebox.showinfo("Error", "Insert all the field to be updated.")
else:
query = "UPDATE inventory SET p_price = ?,p_stock = ? WHERE p_name=?"
c.execute(query, (self.price, self.stock, self.name_p_e.get()))
conn.commit()
tkinter.messagebox.showinfo("Success", "Successfully Updated to database")
def delete_record(self, *args, **kwargs):
productname = str(self.name_p_e.get())
c.execute("DELETE FROM inventory WHERE p_name=?", (productname,))
conn.commit()
tkinter.messagebox.showinfo("Success", "Successfully Deleted from database")
root = Tk()
root.iconbitmap(default='logo.ico')
b = Database(root)
root.geometry("800x600+80+100")
root.title("Sayem Digital Studio Software (Point of Sale)")
root.mainloop()