-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataBaseConnection.py
More file actions
96 lines (85 loc) · 2.58 KB
/
dataBaseConnection.py
File metadata and controls
96 lines (85 loc) · 2.58 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
import sqlite3 as sql
# Connection For Database
def connectDatabase():
conn = sql.connect("Cafe.db")
cursor = conn.cursor()
return conn, cursor
# Show Coffee Ingredients
def getCoffeeIngredients():
conn, cursor = connectDatabase()
cursor.execute("""SELECT * FROM Coffees""")
coffees = cursor.fetchall()
print("\nCoffee Menu And Ingredients")
conn.close()
return coffees
# Create Table For Daily and Weekly Revenue
def createTable():
conn, cursor = connectDatabase()
cursor.execute("""CREATE TABLE IF NOT EXISTS Daily(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
CoffeeName TEXT,
CoffeePrice INTEGER
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS WEEKLY(
DAY INTEGER,
REVENUE INTEGER
)""")
conn.commit()
conn.close()
# Add Daily sale
def insertDaily(result):
conn, cursor = connectDatabase()
cursor.execute(f"""INSERT INTO Daily (CoffeePrice) VALUES ({result})""")
conn.commit()
conn.close()
# Show Daily Datas
def getDailyDatas():
conn, cursor = connectDatabase()
cursor.execute("SELECT * FROM Daily")
datas = cursor.fetchall()
conn.close()
return datas
# Daily Table Delete
def dropDaily():
conn, cursor = connectDatabase()
try:
cursor.execute("""DROP TABLE Daily""")
conn.commit()
except:
print("Please Sale the Coffee")
finally:
conn.close()
# Insert Daily Sales For Weekly
def insertDailyRevenue(datas, dailyRevenue,day):
try:
conn, cursor = connectDatabase()
for data in datas:
dailyRevenue += data[2]
dailyRevenue = dailyRevenue/2
cursor.execute("""INSERT INTO WEEKLY (DAY,REVENUE) VALUES (?,?) """ , (day, dailyRevenue))
conn.commit()
conn.close()
except:
print("Please Choice Daily Revenue")
# Get Weekly Revenue
def getWeeklyRevenue():
try:
TotalRevenue = 0
conn, cursor = connectDatabase()
cursor.execute("""SELECT * FROM WEEKLY WHERE REVENUE""")
weeklyRevenue = cursor.fetchall()
for data in weeklyRevenue:
TotalRevenue += data[1]
print(f"""
_ _ _ _ _ _ _ _ _ _ _ _
|
|
| TOTAL WEEKLY REVENUE : {TotalRevenue}
|
|_ _ _ _ _ _ _ _ _ _ _ _
""")
cursor.execute("""DROP TABLE WEEKLY""")
conn.commit()
conn.close()
except:
print("Please Choice Daily Revenue")