-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.py
320 lines (242 loc) · 10.9 KB
/
main.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
317
318
319
320
import streamlit as st
import pandas as pd
from PIL import Image
#from drug_db import *
import random
## SQL DATABASE CODE
import sqlite3
conn = sqlite3.connect("drug_data.db",check_same_thread=False)
c = conn.cursor()
def cust_create_table():
c.execute('''CREATE TABLE IF NOT EXISTS Customers(
C_Name VARCHAR(50) NOT NULL,
C_Password VARCHAR(50) NOT NULL,
C_Email VARCHAR(50) PRIMARY KEY NOT NULL,
C_State VARCHAR(50) NOT NULL,
C_Number VARCHAR(50) NOT NULL
)''')
print('Customer Table create Successfully')
def customer_add_data(Cname,Cpass, Cemail, Cstate,Cnumber):
c.execute('''INSERT INTO Customers (C_Name,C_Password,C_Email, C_State, C_Number) VALUES(?,?,?,?,?)''', (Cname,Cpass, Cemail, Cstate,Cnumber))
conn.commit()
def customer_view_all_data():
c.execute('SELECT * FROM Customers')
customer_data = c.fetchall()
return customer_data
def customer_update(Cemail,Cnumber):
c.execute(''' UPDATE Customers SET C_Number = ? WHERE C_Email = ?''', (Cnumber,Cemail,))
conn.commit()
print("Updating")
def customer_delete(Cemail):
c.execute(''' DELETE FROM Customers WHERE C_Email = ?''', (Cemail,))
conn.commit()
def drug_update(Duse, Did):
c.execute(''' UPDATE Drugs SET D_Use = ? WHERE D_id = ?''', (Duse,Did))
conn.commit()
def drug_delete(Did):
c.execute(''' DELETE FROM Drugs WHERE D_id = ?''', (Did,))
conn.commit()
def drug_create_table():
c.execute('''CREATE TABLE IF NOT EXISTS Drugs(
D_Name VARCHAR(50) NOT NULL,
D_ExpDate DATE NOT NULL,
D_Use VARCHAR(50) NOT NULL,
D_Qty INT NOT NULL,
D_id INT PRIMARY KEY NOT NULL)
''')
print('DRUG Table create Successfully')
def drug_add_data(Dname, Dexpdate, Duse, Dqty, Did):
c.execute('''INSERT INTO Drugs (D_Name, D_Expdate, D_Use, D_Qty, D_id) VALUES(?,?,?,?,?)''', (Dname, Dexpdate, Duse, Dqty, Did))
conn.commit()
def drug_view_all_data():
c.execute('SELECT * FROM Drugs')
drug_data = c.fetchall()
return drug_data
def order_create_table():
c.execute('''
CREATE TABLE IF NOT EXISTS Orders(
O_Name VARCHAR(100) NOT NULL,
O_Items VARCHAR(100) NOT NULL,
O_Qty VARCHAR(100) NOT NULL,
O_id VARCHAR(100) PRIMARY KEY NOT NULL)
''')
def order_delete(Oid):
c.execute(''' DELETE FROM Orders WHERE O_id = ?''', (Oid,))
def order_add_data(O_Name,O_Items,O_Qty,O_id):
c.execute('''INSERT INTO Orders (O_Name, O_Items,O_Qty, O_id) VALUES(?,?,?,?)''',
(O_Name,O_Items,O_Qty,O_id))
conn.commit()
def order_view_data(customername):
c.execute('SELECT * FROM ORDERS Where O_Name == ?',(customername,))
order_data = c.fetchall()
return order_data
def order_view_all_data():
c.execute('SELECT * FROM ORDERS')
order_all_data = c.fetchall()
return order_all_data
#__________________________________________________________________________________
def admin():
st.title("Pharmacy Database Dashboard")
menu = ["Drugs", "Customers", "Orders", "About"]
choice = st.sidebar.selectbox("Menu", menu)
## DRUGS
if choice == "Drugs":
menu = ["Add", "View", "Update", "Delete"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "Add":
st.subheader("Add Drugs")
col1, col2 = st.columns(2)
with col1:
drug_name = st.text_area("Enter the Drug Name")
drug_expiry = st.date_input("Expiry Date of Drug (YYYY-MM-DD)")
drug_mainuse = st.text_area("When to Use")
with col2:
drug_quantity = st.text_area("Enter the quantity")
drug_id = st.text_area("Enter the Drug id (example:#D1)")
if st.button("Add Drug"):
drug_add_data(drug_name,drug_expiry,drug_mainuse,drug_quantity,drug_id)
st.success("Successfully Added Data")
if choice == "View":
st.subheader("Drug Details")
drug_result = drug_view_all_data()
#st.write(drug_result)
with st.expander("View All Drug Data"):
drug_clean_df = pd.DataFrame(drug_result, columns=["Name", "Expiry Date", "Use", "Quantity", "ID"])
st.dataframe(drug_clean_df)
with st.expander("View Drug Quantity"):
drug_name_quantity_df = drug_clean_df[['Name','Quantity']]
#drug_name_quantity_df = drug_name_quantity_df.reset_index()
st.dataframe(drug_name_quantity_df)
if choice == 'Update':
st.subheader("Update Drug Details")
d_id = st.text_area("Drug ID")
d_use = st.text_area("Drug Use")
if st.button(label='Update'):
drug_update(d_use,d_id)
if choice == 'Delete':
st.subheader("Delete Drugs")
did = st.text_area("Drug ID")
if st.button(label="Delete"):
drug_delete(did)
## CUSTOMERS
elif choice == "Customers":
menu = ["View", "Update", "Delete"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "View":
st.subheader("Customer Details")
cust_result = customer_view_all_data()
#st.write(cust_result)
with st.expander("View All Customer Data"):
cust_clean_df = pd.DataFrame(cust_result, columns=["Name", "Password","Email-ID" ,"Area", "Number"])
st.dataframe(cust_clean_df)
if choice == 'Update':
st.subheader("Update Customer Details")
cust_email = st.text_area("Email")
cust_number = st.text_area("Phone Number")
if st.button(label='Update'):
customer_update(cust_email,cust_number)
if choice == 'Delete':
st.subheader("Delete Customer")
cust_email = st.text_area("Email")
if st.button(label="Delete"):
customer_delete(cust_email)
elif choice == "Orders":
menu = ["View"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "View":
st.subheader("Order Details")
order_result = order_view_all_data()
#st.write(cust_result)
with st.expander("View All Order Data"):
order_clean_df = pd.DataFrame(order_result, columns=["Name", "Items","Qty" ,"ID"])
st.dataframe(order_clean_df)
elif choice == "About":
st.subheader("DBMS Mini Project")
st.subheader("By Aditi (226), Anweasha (235) & Vijay (239)")
def getauthenicate(username, password):
#print("Auth")
c.execute('SELECT C_Password FROM Customers WHERE C_Name = ?', (username,))
cust_password = c.fetchall()
#print(cust_password[0][0], "Outside password")
#print(password, "Parameter password")
if cust_password[0][0] == password:
#print("Inside password")
return True
else:
return False
###################################################################
def customer(username, password):
if getauthenicate(username, password):
print("In Customer")
st.title("Welcome to Pharmacy Store")
st.subheader("Your Order Details")
order_result = order_view_data(username)
# st.write(cust_result)
with st.expander("View All Order Data"):
order_clean_df = pd.DataFrame(order_result, columns=["Name", "Items", "Qty", "ID"])
st.dataframe(order_clean_df)
drug_result = drug_view_all_data()
print(drug_result)
st.subheader("Drug: "+drug_result[0][0])
img = Image.open('images/dolo650.jpg')
st.image(img, width=100, caption="Rs. 15/-")
dolo650 = st.slider(label="Quantity",min_value=0, max_value=5, key= 1)
st.info("When to USE: " + str(drug_result[0][2]))
st.subheader("Drug: " + drug_result[1][0])
img = Image.open('images/strepsils.JPG')
st.image(img, width=100 , caption="Rs. 10/-")
strepsils = st.slider(label="Quantity",min_value=0, max_value=5, key= 2)
st.info("When to USE: " + str(drug_result[1][2]))
st.subheader("Drug: " + drug_result[2][0])
img = Image.open('images/vicks.JPG')
st.image(img, width=100, caption="Rs. 65/-")
vicks = st.slider(label="Quantity",min_value=0, max_value=5, key=3)
st.info("When to USE: " + str(drug_result[2][2]))
if st.button(label="Buy now"):
O_items = ""
if int(dolo650) > 0:
O_items += "Dolo-650,"
if int(strepsils) > 0:
O_items += "Strepsils,"
if int(vicks) > 0:
O_items += "Vicks"
O_Qty = str(dolo650)+str(',') + str(strepsils) + str(",") + str(vicks)
O_id = username + "#O" + str(random.randint(0,1000000))
#order_add_data(O_Name, O_Items,O_Qty, O_id):
order_add_data(username, O_items, O_Qty, O_id)
if __name__ == '__main__':
drug_create_table()
cust_create_table()
order_create_table()
menu = ["Login", "SignUp","Admin"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "Login":
username = st.sidebar.text_input("User Name")
password = st.sidebar.text_input("Password", type='password')
if st.sidebar.checkbox(label="Login"):
customer(username, password)
elif choice == "SignUp":
st.subheader("Create New Account")
cust_name = st.text_input("Name")
cust_password = st.text_input("Password", type='password', key=1000)
cust_password1 = st.text_input("Confirm Password", type='password', key=1001)
col1, col2, col3 = st.columns(3)
with col1:
cust_email = st.text_area("Email ID")
with col2:
cust_area = st.text_area("State")
with col3:
cust_number = st.text_area("Phone Number")
if st.button("Signup"):
if (cust_password == cust_password1):
customer_add_data(cust_name,cust_password,cust_email, cust_area, cust_number,)
st.success("Account Created!")
st.info("Go to Login Menu to login")
else:
st.warning('Password dont match')
elif choice == "Admin":
username = st.sidebar.text_input("User Name")
password = st.sidebar.text_input("Password", type='password')
# if st.sidebar.button("Login"):
if username == 'admin' and password == 'admin':
admin()