-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
276 lines (201 loc) · 7.97 KB
/
main.py
File metadata and controls
276 lines (201 loc) · 7.97 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
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
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from database import DataBase
from market import page
import sqlite3
conn = sqlite3.connect("market.db")
c = conn.cursor()
class page1(page):
def submit1(self, instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
# try:
self.table.remove_widget(self.num_input)
self.table.remove_widget(self.submit)
c.execute(f"select id from names where name = '{self.name2}' and account_id = {id1}")
id = c.fetchall()
id = id[0][0]
c.execute(f"insert into salary (names_id,amount) values ({id},{self.num_input.text})")
conn.commit()
popupWindow = Popup(title="Information", content=Label(text="your money has been successfully added"),
size_hint=(None, None), size=(400, 400))
popupWindow.open()
# except:
# popupWindow = Popup(title="Error", content=Label(text="must be a number"), size_hint=(None, None), size=(400, 400))
# popupWindow.open()
def window1(self):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
names_list2 = []
self.c.execute(f"select name from names where account_id = {id1}")
names_db = self.c.fetchall()
for name in names_db:
names_list2.append(name[0])
firstGrid = GridLayout(cols = 1)
if len(names_list2) == 0:
pass
else:
for name in names_list2:
firstGrid.add_widget(Label(text = name))
btn = Button(text = "want to continue in this table")
btn.bind(on_press = self.start)
firstGrid.add_widget(btn)
popupWindow = Popup(title="Question", content= firstGrid, size_hint=(None,None),size=(400,400))
popupWindow.open()
def delete1(self,instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
self.clear_widgets()
self.inside1.clear_widgets()
self.add_widget(self.inside4)
db.delete(id1)
def logout_btn1(self,instance):
sm.current = "login"
self.clear_widgets()
self.inside1.clear_widgets()
self.add_widget(self.inside4)
def start(self,instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
if instance.text == "continue to the previous":
if len(db.chec(id1)) == 0:
popupWindow = Popup(title="Error", content= Label(text = "you don't have a previus table"), size_hint=(None,None),size=(400,400))
popupWindow.open()
else:
self.inside1.clear_widgets()
self.names_list = []
db.start(self.names_list,id1)
self.demo()
else:
db.delete(id1)
db.start(self.names_list,id1)
self.demo()
def chec(self,instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
if self.inpuut1.text in db.chec(id1):
self.demo1()
else:
show = GridLayout(cols = 1)
only = Button(text = "you cannot write onother name")
show.add_widget(only)
for name in db.chec(id1):
show.add_widget(Label(text = name))
popupWindow = Popup(title="Error", content= show, size_hint=(None,None),size=(400,400))
popupWindow.open()
only.bind(on_press = popupWindow.dismiss)
def view1(self,instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
self.demo2(db.view1(self.name2,id1))
def finish_all1(self,instance):
current_user = db.get_user(MainWindow.current)
id1 = current_user[-1]
pop_finish = GridLayout(cols = 1)
for tupl in db.finish_all1(id1):
if tupl[1] < 0:
tupl1 = str(tupl[1])
pop_finish.add_widget(Label(text =f"{str(tupl[0])} should pay {tupl1[1:]}" ))
else:
pop_finish.add_widget(Label(text =f"{str(tupl[0])} should recive {str(tupl[1])}" ))
for tupl in db.finish_all(id1):
# pop_finish.add_widget(Label(text = ))
pop_finish.add_widget(Label(text =f"{str(tupl[0])} should pay {tupl[1]}" ))
pop_finish.add_widget(Label(text = "do you want to continue",font_size = 20))
popinside = GridLayout(cols = 2)
no1 = Button(text = "no")
yes1 = Button(text = "yes")
no1.bind(on_press = self.delete1)
popinside.add_widget(yes1)
popinside.add_widget(no1)
pop_finish.add_widget(popinside)
popupWindow = Popup(title = "thank you for using our app",content=pop_finish,size_hint=(None,None),size=(400,400))
popupWindow.open()
yes1.bind(on_press = popupWindow.dismiss)
no1.bind(on_press = popupWindow.dismiss)
class CreateAccountWindow(Screen):
namee = ObjectProperty(None)
email = ObjectProperty(None)
password = ObjectProperty(None)
def submit(self):
if self.namee.text != "" and self.email.text != "" and self.email.text.count("@") == 1 and self.email.text.count(".") > 0:
if self.password != "":
db.add_user(self.email.text, self.password.text, self.namee.text)
MainWindow.current = self.email.text
sm.current = "market"
self.reset()
else:
invalidForm()
else:
invalidForm()
def login(self):
self.reset()
sm.current = "login"
def reset(self):
self.email.text = ""
self.password.text = ""
self.namee.text = ""
class LoginWindow(Screen):
email = ObjectProperty(None)
password = ObjectProperty(None)
def loginBtn(self):
if db.validate(self.email.text, self.password.text):
MainWindow.current = self.email.text
self.reset()
sm.current = "market"
else:
invalidLogin()
def createBtn(self):
self.reset()
sm.current = "create"
def reset(self):
self.email.text = ""
self.password.text = ""
class MainWindow(Screen):
n = ObjectProperty(None)
created = ObjectProperty(None)
email = ObjectProperty(None)
current = ""
def logOut(self):
sm.current = "login"
def on_enter(self, *args):
password, name, created = db.get_user(self.current)
self.n.text = "Account Name: " + name
self.email.text = "Email: " + self.current
self.created.text = "Created On: " + created
class WindowManager(ScreenManager):
pass
def sucsess():
pop = Popup(title='Confirmation',
content=Label(text='your Email has benn successfully added'),
size_hint=(None, None), size=(400, 400))
pop.open()
def invalidLogin():
pop = Popup(title='Invalid Login',
content=Label(text='Invalid username or password.'),
size_hint=(None, None), size=(400, 400))
pop.open()
def invalidForm():
pop = Popup(title='Invalid Form',
content=Label(text='Please fill in all inputs with valid information.'),
size_hint=(None, None), size=(400, 400))
pop.open()
kv = Builder.load_file("my.kv")
sm = WindowManager()
if __name__ == "__main__":
db = DataBase("market.db")
screens = [LoginWindow(name="login"), CreateAccountWindow(name="create"),MainWindow(name="main"),page1(name="market")]
for screen in screens:
sm.add_widget(screen)
sm.current = "login"
class MyMainApp(App):
def build(self):
return sm
if __name__ == "__main__":
MyMainApp().run()