-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_to_db.py
120 lines (90 loc) · 4.42 KB
/
add_to_db.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
#import all the modules
from tkinter import *
import sqlite3
import tkinter.messagebox
connect=sqlite3.connect("storedb.db")
c=connect.cursor()
result=c.execute("SELECT Max(id) from inventory")
for r in result:
id=r[0]
class Database:
def __init__(self,master,*args,**kwargs):
self.master=master
self.heading=Label(master,text="Add to databse",font=('arial 40 bold'),fg='steelblue')
self.heading.place(x=400,y=0)
#lables for the window
self.name_l=Label(master,text="Enter Product Name",font=('arial 18 bold'))
self.name_l.place(x=0,y=70)
self.stock_l=Label(master,text="Enter Stocks",font=('arial 18 bold'))
self.stock_l.place(x=0,y=120)
self.cp_l = Label(master, text="Enter Cost Price ", font=('arial 18 bold'))
self.cp_l.place(x=0, y=170)
self.sp_l = Label(master, text="Enter Selling Price", font=('arial 18 bold'))
self.sp_l.place(x=0, y=220)
self.vendor_l = Label(master, text="Enter Dealer Name", font=('arial 18 bold'))
self.vendor_l.place(x=0, y=270)
self.vendor_phone_l = Label(master, text="Enter Dealer Phone Number", font=('arial 18 bold'))
self.vendor_phone_l.place(x=0, y=320)
self.id_l = Label(master, text="Enter ID", font=('arial 18 bold'))
self.id_l.place(x=0, y=370)
#enteries for window
self.name_e=Entry(master,width=25,font=('arial 18 bold'))
self.name_e.place(x=380,y=70)
self.stock_e = Entry(master, width=25, font=('arial 18 bold'))
self.stock_e.place(x=380, y=120)
self.cp_e = Entry(master, width=25, font=('arial 18 bold'))
self.cp_e.place(x=380, y=170)
self.sp_e = Entry(master, width=25, font=('arial 18 bold'))
self.sp_e.place(x=380, y=220)
self.vendor_e = Entry(master, width=25, font=('arial 18 bold'))
self.vendor_e.place(x=380, y=270)
self.vendor_phone_e = Entry(master, width=25, font=('arial 18 bold'))
self.vendor_phone_e.place(x=380, y=320)
self.id_e=Entry(master,width=25,font=('arial 18 bold'))
self.id_e.place(x=380,y=370)
#button to add to the database
self.btn_add=Button(master,text='Add to Database',width=25,height=2,bg='steelblue',fg='white',command=self.get_items)
self.btn_add.place(x=520,y=420)
self.btn_clear=Button(master,text="Clear All Fields",width=18,height=2,bg='lightgreen',fg='white',command=self.clear_all)
self.btn_clear.place(x=350,y=420)
#text box for the log
self.tbBox=Text(master,width=60,height=18)
self.tbBox.place(x=750,y=70)
self.master.bind('<Return>', self.get_items)
self.master.bind('<Up>', self.clear_all)
def get_items(self, *args, **kwargs):
# get from entries
self.name = self.name_e.get()
self.stock = self.stock_e.get()
self.cp = self.cp_e.get()
self.sp = self.sp_e.get()
self.vendor = self.vendor_e.get()
self.vendor_phone = self.vendor_phone_e.get()
# dynamic entries
self.totalcp = float(self.cp) * float(self.stock)
self.totalsp = float(self.sp) * float(self.stock)
self.assumed_profit = float(self.totalsp - self.totalcp)
if self.name == '' or self.stock == '' or self.cp == '' or self.sp == '':
tkinter.messagebox.showinfo("Error", "Please Fill all the entries.")
else:
sql = "INSERT INTO inventory (name, stock, cp, sp, totalcp, totalsp, assumed_profit, vendor, vendor_phoneno ) VALUES(?,?,?,?,?,?,?,?,?)"
c.execute(sql, (
self.name, self.stock, self.cp, self.sp, self.totalcp, self.totalsp, self.assumed_profit, self.vendor,
self.vendor_phone))
conn.commit()
# textbox insert
self.tbBox.insert(END, "\n\nInseted " + str(self.name) + " into the database with code " + str(self.id_e.get()))
tkinter.messagebox.showinfo("Success", "Successfully added to the database")
def clear_all(self, *args, **kwargs):
num = id + 1
self.name_e.delete(0, END)
self.stock_e.delete(0, END)
self.cp_e.delete(0, END)
self.sp_e.delete(0, END)
self.vendor_e.delete(0, END)
self.vendor_phone_e.delete(0, END)
root=Tk()
b=Database(root)
root.geometry("1366x768+0+0")
root.title("Shopify")
root.mainloop()