forked from harsh725/Student_Management_system-FLASK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
257 lines (212 loc) · 7.83 KB
/
backend.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
# FOREGIN KEY, triger , cascade
import sqlite3
def studentData():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS student(usn TEXT PRIMARY KEY,
name TEXT,
mobileno TEXT,
address TEXT,
email TEXT)""")
con.commit()
con.close()
studentData()
def addstdrec(usn,name,mobileno,address,email):
con=sqlite3.connect("student.db")
cur=con.cursor()
# print("testtttt========",type(usn),type(name),type(mobileno),type(address),type(email))
cur.execute("""INSERT INTO student VALUES (:usn,:name,:mobileno,:address,:email)""",{'usn':usn,'name':name,'mobileno':mobileno,'address':address,'email':email})
# print("000000000000000000000000000")
con.commit()
con.close()
def viewdatastud():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("SELECT * FROM student")
rows=cur.fetchall()
con.close()
return rows
# addstdrec("1CR18CS","harsh","875814979","india","[email protected]")
# print(viewdatastud(),"------------------")
def deletestdrec(usn):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""PRAGMA foreign_keys = ON""")
con.commit()
cur.execute("DELETE FROM student WHERE usn=:usn",{'usn':usn})
con.commit()
con.close()
def updatestddata(usn,name,mobileno,address,email):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("UPDATE student SET name=:name,mobileno=:mobileno,address=:address,email=:email WHERE usn=:usn",{'name':name,'mobileno':mobileno,'address':address,'email':email,'usn' : usn})
con.commit()
con.close()
# print(viewdatastud())
def moderatordata():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS moderator(usr TEXT PRIMARY KEY,
namem TEXT,
password TEXT,
emailm TEXT,
contactno TEXT)""")
con.commit()
con.close()
moderatordata()
def addmoderator(idm,namem,password,emailm,contactno):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""INSERT INTO moderator VALUES (:usr,:namem,:password,:emailm,:contactno)""",{'usr':idm,'namem':namem,'password':password,'emailm':emailm,'contactno':contactno})
con.commit()
con.close()
# addmoderator(69,"harsh","hd","[email protected]",111)
# addmoderator(2,"gsgg","kl","[email protected]",21)
def viewmoderator():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("SELECT * FROM moderator")
rows=cur.fetchall()
con.close()
return rows
# print(viewmoderator())
def deleterecmoderator(idm):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("DELETE FROM moderator WHERE usr=:idm",{'idm':idm})
con.commit()
con.close()
def updaterecmoderator(idm,namem,password,emailm,contactno):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("UPDATE moderator SET namem=:namem,password=:password,emailm=:emailm,contactno=:contactno WHERE idm=:idm",{'namem':namem,'password':password,'emailm':emailm,'contactno':contactno,'idm':idm})
con.commit()
con.close()
# print(viewmoderator())
def feedata():
con=sqlite3.connect("student.db")
cur=con.cursor()
con.execute("""PRAGMA foreign_keys = ON""")
cur.execute("""CREATE TABLE IF NOT EXISTS fee(usn TEXT,
amount TEXT,
status TEXT,
payment_date TEXT,
penalty TEXT,
foreign key (usn) references student(usn) ON DELETE CASCADE)""")
con.commit()
con.close()
feedata()
def addfeedetails(usn,amount,status,payment_date,penalty):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute(""" INSERT INTO fee VALUES(:usn,:amount,:status,:payment_date,:penalty) """, {'usn':usn,'amount':amount,'status':status,'payment_date':payment_date,'penalty':penalty} )
con.commit()
con.close()
# addfeedetails("1CR18CS","50000","PAID","25-JULY","NHI LAGI")
def viewfeedetails():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("SELECT * FROM fee")
rows=cur.fetchall()
con.close()
return rows
# print(viewfeedetails())
def deletefeerec(usn):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("DELETE FROM fee WHERE usn=:usn",{'usn':usn})
con.commit()
con.close()
def updatefeerec(usn,amount,status,date,penalty):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("UPDATE fee SET amount=:amount,status=:status,date=:date,penalty=:penalty WHERE usn=:usn",{'amount':amount,'status':status,'date':date,'penalty':penalty,'usn':usn})
con.commit()
con.close()
def subjectdata():
con=sqlite3.connect("student.db")
cur=con.cursor()
con.execute("""PRAGMA foreign_keys = ON""")
cur.execute("""CREATE TABLE IF NOT EXISTS subject(usn TEXT PRIMARY KEY,
sub1 TEXT,
sub2 TEXT,
sub3 TEXT,
backlogs TEXT,
foreign key (usn) references student(usn) ON DELETE CASCADE)""")
con.commit()
con.close()
subjectdata()
def addsubject(usn,sub1,sub2,sub3,backlogs):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""INSERT INTO subject VALUES (:usn,:sub1,:sub2,:sub3,:backlogs)""",{'usn':usn,'sub1':sub1,'sub2':sub2,'sub3':sub3,'backlogs':backlogs})
con.commit()
con.close()
def viewsubject():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("SELECT * FROM subject")
rows=cur.fetchall()
con.close()
return rows
def deletesubjectrec(usn):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("DELETE FROM subject WHERE usn=:usn",{'usn':usn})
con.commit()
con.close()
def updaterecsubject(usn,sub1,sub2,sub3,backlogs):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("UPDATE subject SET sub1=:sub1,sub2=:sub2,sub3=:sub3,backlogs=:backlogs WHERE usn=:usn",{'sub1':sub1,'sub2':sub2,'sub3':sub3,'backlogs':backlogs,'usn':usn})
con.commit()
con.close()
def performancedata():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""PRAGMA foreign_keys = ON""")
cur.execute("""CREATE TABLE IF NOT EXISTS performance(usn TEXT PRIMARY KEY,
iat1 INTEGER,
iat2 INTEGER,
iat3 INTEGER,
AVG INTEGER,
external INTEGER,
total INTEGER,
foreign key (usn) references student(usn) ON DELETE CASCADE)""")
con.commit()
con.close()
performancedata()
def trigger():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""CREATE TRIGGER IF NOT EXISTS calculate AFTER INSERT ON performance
BEGIN
UPDATE performance
set AVG=(new.iat1+new.iat2+new.iat3)/3 where new.usn=usn;
UPDATE performance
set total=(new.AVG/3)+new.external where new.usn=usn;
-- where usn=new.usn
END""")
con.commit()
con.close()
trigger()
def addmark(usn,iat1,iat2,iat3,ex,avg,total):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("""INSERT INTO performance VALUES(:usn,:iat1,:iat2,:iat3,:AVG,:external,:total)""",{'usn':usn,'iat1':iat1,'iat2':iat2,'iat3':iat3,'external':ex,'AVG':avg,'total':total})
con.commit()
con.close()
def check_marks():
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("SELECT * FROM performance")
rows=cur.fetchall()
con.close()
return rows
def updatemark(usn,iat1,iat2,iat3,ex,avg,total):
con=sqlite3.connect("student.db")
cur=con.cursor()
cur.execute("DELETE FROM performance WHERE usn=:usn",{'usn':usn})
con.commit()
con.close()
addmark(usn,iat1,iat2,iat3,ex,avg,total)