-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
179 lines (167 loc) · 4.83 KB
/
database.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
import subprocess as sp
import platform
from server import db,Product,Message
if(platform.system().lower()=="windows") :
command="cls"
else:
command="clear"
def Show_Products():
Products=Product.query.all()
for prd in Products:
print(str(prd.id)+"- "+prd.titre)
print('\n')
def Add_Product():
titre=input("Product Title: ")
description=input("Product description: ")
prix=float(input("Product price: "))
image=input("Product image name: ")
specs=input("Product specs: ")
db.session.add(Product(titre=titre,description=titre,prix=prix,image=image,specs=specs))
db.session.commit()
print('\n')
def Edit_product(Id):
Products=Product.query.all()
for prd in Products:
if(prd.id==Id) :
prd.titre=input("Product Title: ")
prd.description=input("Product description: ")
prd.prix=float(input("Product price: "))
prd.image=input("Product image name: ")
prd.specs=input("Product specs: ")
db.session.commit()
return True
return False
def Delete_product(Id):
Products=Product.query.all()
for prd in Products:
if(prd.id==Id):
Product.query.filter(Product.id == Id).delete()
db.session.commit()
return True
return False
def Show_Messages():
Messages=Message.query.all()
for msg in Messages:
print(str(msg.id)+"- "+"\nName: "+msg.nom+"\nEmail: "+msg.mail+"\nDate: "+str(msg.mdate)+"\nRate: "+str(msg.rate)+"/5"+"\nMessage: "+msg.message+"\n\n")
print('\n\n')
def Delete_Message(Id):
Messages=Message.query.all()
for msg in Messages:
if(msg.id==Id):
Message.query.filter(Message.id == Id).delete()
db.session.commit()
return True
return False
def main():
sp.call(command,shell=True)
print("1)- Create DataBase\n2)- Products\n3)- Messages\n4)- Delete DataBase\n5)- Exit")
n=input()
while(n!='5') :
if(n=='1') :
db.create_all()
print("DataBase Created Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
elif(n=='2'):
sp.call(command,shell=True)
#view_products()
print("1)- View Products\n2)- Add New Product\n3)- Edit Product\n4)- Delete Product\n5)- Exit")
n1=input()
while(n1!='5') :
if(n1=='1') :
#view function
sp.call(command,shell=True)
Show_Products()
input("\nPress ENTRER !!")
sp.call(command,shell=True)
elif(n1=='2'):
#Add New Product function
Add_Product()
print("The Product Has Been Added Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
elif(n1=='3'):
#Edit Product function
Show_Products()
Id=int(input("Product ID to Edit: "))
if(Edit_product(Id)==False) :
sp.call(command,shell=True)
print("Product ID Not Found !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("The Product Has Been Edited Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
elif(n1=='4'):
#Delete Product function
sp.call(command,shell=True)
Show_Products()
Id=int(input("Product ID to Delete: "))
if(Delete_product(Id)==True) :
print("The Product Has Been Deleted Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("Product ID Not Found !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("Please Enter Your Choice Correctly !!!")
for i in range(99999999):
pass
print("1)- View Products\n2)- Add New Product\n3)- Edit Product\n4)- Delete Product\n5)- Exit")
n1=input()
sp.call(command,shell=True)
elif(n=='3'):
sp.call(command,shell=True)
print("1)- View Messages\n2)- Delete Message\n3)- Exit")
n2=input()
sp.call(command,shell=True)
while(n2!='3') :
if(n2=='1') :
Show_Messages()
input("\nPress ENTER !!")
sp.call(command,shell=True)
elif(n2=='2'):
#Delete Message function
sp.call(command,shell=True)
Show_Messages()
Id=int(input("Message ID to Delete: "))
if(Delete_Message(Id)==True) :
print("The Message Has Been Deleted Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("Message ID Not Found !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("Please Enter Your Choice Correctly !!!")
for i in range(99999999):
pass
print("1)- View Messages\n2)- Delete Message\n3)- Exit")
n2=input()
sp.call(command,shell=True)
elif(n=='4'):
db.drop_all()
print("DataBase Deleted Successfully !")
for i in range(99999999):
pass
sp.call(command,shell=True)
else:
print("Please Enter Your Choice Correctly !!!")
for i in range(99999999):
pass
sp.call(command,shell=True)
print("1)- Create DataBase\n2)- Products\n3)- Messages\n4)- Delete DataBase\n5)- Exit")
n=input()
main()