-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_insert.py
More file actions
302 lines (282 loc) · 11.1 KB
/
db_insert.py
File metadata and controls
302 lines (282 loc) · 11.1 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
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
import pyodbc
import table_control as tableControl
import datetime
import full_text_search as fullSearch
import random
from openpyxl import Workbook,load_workbook
import base64
import db_query as Query
class Database_insert:
def __init__(self):
self.db = pyodbc.connect(
'Driver={ODBC Driver 17 for SQL Server};'
'Server=sql.athena.domainhizmetleri.com;'
'Database=abdullah_pys;'
'UID=abdullah_pys;'
'PWD=@PassWord123;'
)
def test(self):
imlec = self.db.cursor()
imlec.execute('SELECT * FROM [abdullah_pys].[m_Student]')
kullanicilar = imlec.fetchall()
for i in kullanicilar:
print(i)
def student_insert(self,student_id,advisior_id,name,surname,mail,
phone_no,depart_id,faculty_id,clas,photo_path,password):
try:
curs = self.db.cursor()
curs.execute(
"insert into m_Student(studentID,advisorID,name,surname,mail,phoneNumber,departmentID,facultyID,class,photoPath,password) values (?, ?,?,?,?,?,?,?,?,?,?)",
str(student_id),
int(advisior_id),
str(name),
str(surname),
str(mail),
str(phone_no),
str(depart_id),
str(faculty_id),
str(clas),
str(photo_path),
str(password))
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def faculty_insert(self,faculty_id,name):
table_c = tableControl.TableControl()
if not table_c.faculty_id_control(faculty_id):
if len(name) < 50:
try:
curs = self.db.cursor()
curs.execute("insert into m_Faculty(facultyID, name) values (?, ?)", str(faculty_id), str(name))
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
else:
return "Error code : 13"
else:
return "Error code : 12"
def department_insert(self,depart_id,faculty_id,name):
table_c = tableControl.TableControl()
if not table_c.department_id_control(depart_id):
if not table_c.faculty_id_control(faculty_id):
if len(name) < 55:
try:
curs = self.db.cursor()
curs.execute("insert into m_Department(departmentID, facultyID, name) values (?, ?, ?)",
str(depart_id), str(faculty_id), str(name))
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
else:
return "Error code : 16"
else:
return "Error code : 15"
else:
return "Error code : 14"
def advisor_insert(self,name,surname,title,mail,depart_id,faculty_id,photo_path,password):
try:
curs = self.db.cursor()
curs.execute("insert into m_Advisor(name,surname,title,mail,departmentID,facultyID,photoPath,password) values (?,?,?,?,?,?,?,?)",
str(name),
str(surname),
str(title),
str(mail),
str(depart_id),
str(faculty_id),
str(photo_path),
str(password))
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def messsage_insert(self,advisor_id,student_id,status,message):
table_c = tableControl.TableControl()
date = datetime.datetime.now()
status = int(status)
if table_c.advisor_reg_control(advisor_id):
return "Error code : 26"
if table_c.student_id_control(student_id):
return "Error code : 27"
try:
curs = self.db.cursor()
curs.execute("insert into t_message(advisorID,studentID,date,status,message) values (?,?,?,?,?)",
int(advisor_id),
str(student_id),
date,
int(status),
str(message))
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def dissertation_insert(self,projenumber,pdfpath,docpath,status,desc,insertdate,updatedate):
try:
curs = self.db.cursor()
curs.execute(
"insert into t_Dissertation(projectNumber,pdfPath,docPath,status,description,insertionDate,updatedDate) values (?,?,?,?,?,?,?)",
projenumber,
pdfpath,
docpath,
status,
desc,
insertdate,
updatedate)
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def reports_insert(self,projenumber,pdfpath,docpath,status,desc,insertdate,updatedate):
try:
curs = self.db.cursor()
curs.execute(
"insert into t_reports(projectNumber,pdfPath,docPath,status,description,insertionDate,updatedDate) values (?,?,?,?,?,?,?)",
projenumber,
pdfpath,
docpath,
status,
desc,
insertdate,
updatedate)
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def plagiarism_insert(self,mainprojeid,otherprojeid,plagrismrate):
try:
curs = self.db.cursor()
curs.execute("insert into t_Plagiarism(mainProjeID,otherProjeID,plagiarismRate) values (?,?,?)",
mainprojeid,
otherprojeid,
plagrismrate)
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def semester_insert(self,startdate,enddate,name):
try:
curs = self.db.cursor()
curs.execute("insert into m_semester(startDate,endDate,name) values (?,?,?)",
startdate,
enddate,
name)
curs.commit()
return "Successful"
except Exception as e:
e = str(e)
return e
def projects_insert(self,headline,matter,cont,purpose,keyword,
metariel,method,poss,status,descr,semeterid,
studentid,insertiondate,updatedate):
try:
version = 1
deg = random.randint(1000,9999)
number = str(studentid[:8]) + str(deg)
curs = self.db.cursor()
curs.execute("insert into t_Projects(number,version,headline,matter,[content],purpose,keyword,materiel,method,possibility,status,description,semesterID,studentID,insertionDate,updatedDate) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
number,
version,
headline,
matter,
cont,
purpose,
keyword,
metariel,
method,
poss,
status,
descr,
semeterid,
studentid,
insertiondate,
updatedate)
curs.commit()
search = fullSearch.Search()
search.allin(number)
return "Successful"
except Exception as e:
e = str(e)
return e
def advisor_xlsx_add(self,rowCount):
kisiler = []
try:
wb = load_workbook("excel/advisor.xlsx")
ws = wb.active
for i in range(2,rowCount+1):
name = ws["A"+str(i)].value
surname = ws["B"+str(i)].value
title = ws["C"+str(i)].value
mail = ws["D"+str(i)].value
depart = ws["E"+str(i)].value
faculty = ws["F"+str(i)].value
photo = ws["G"+str(i)].value
passwd = ws["H"+str(i)].value
kisiler.append([name,surname,title,mail,depart,faculty,photo,passwd])
return kisiler
except Exception as e:
e = str(e)
return e
def adv_list_import(self,Rcount,base):
try:
with open("excel/advisor.xlsx", "wb") as fileOpen:
decode64 = base64.b64decode(base)
fileOpen.write(decode64)
listem = self.advisor_xlsx_add(int(Rcount))
if type(listem) == list:
for a in listem:
self.advisor_insert(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7])
return "Successful"
except Exception as e:
e = str(e)
return e
def student_xlsx_add(self,rowCount):
kisiler = []
try:
nesne = Query.Query()
advisor_count = nesne.advisorCountQuery()
advisoor_list = nesne.advisor_query()
rnd_advisor = random.randint(0,advisor_count)
rnadv = advisoor_list[rnd_advisor]["registrationID"]
wb = load_workbook("excel/student.xlsx")
ws = wb.active
for i in range(2,rowCount+1):
studentid = ws["A"+str(i)].value
name = ws["B"+str(i)].value
surname = ws["C"+str(i)].value
mail = ws["D"+str(i)].value
phone = ws["E"+str(i)].value
depart = ws["F"+str(i)].value
faculty = ws["G"+str(i)].value
clas = ws["H"+str(i)].value
photopath = ws["I"+str(i)].value
passw = ws["J"+str(i)].value
kisiler.append([studentid,rnadv,name,surname,mail,phone,depart,faculty,clas,photopath,passw])
return kisiler
except Exception as e:
e = str(e)
return e
def student_list_import(self,Rcount,base):
try:
with open("excel/student.xlsx", "wb") as fileOpen:
decode64 = base64.b64decode(base)
fileOpen.write(decode64)
listem = self.student_xlsx_add(int(Rcount))
if type(listem) == list:
for a in listem:
self.student_insert(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10])
return "Successful"
else:
return "liste değil"
except Exception as e:
e = str(e)
return e