-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
417 lines (384 loc) · 18.8 KB
/
project.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'project.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
# ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺
# Name: Dhanrajsinh Parmar
# Semester: Diploma - 5th Sem
# Course: Python Programming
# Department: ICT
# University: Marwadi University
# ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺
from PyQt5 import QtCore, QtGui, QtWidgets
import mysql.connector
from datetime import datetime
import sys
from PyQt5.QtGui import QIntValidator
connection = mysql.connector.connect(host="localhost", user="root", password="", database="attendance_system")
cursor = connection.cursor()
date = datetime.today()
d = date.strftime("%d_%m_%Y")
d1 = d.format(date)
class Ui_Dialog(object):
def insert(self):
if int(self.enrollmentlineEdit.text()) == 0:
try:
raise ZeroDivisionError
except:
self.errorLable.setText("Enrollment No can not be Zero ××")
self.resetedits()
else:
mySql_insert_query = """INSERT INTO mainregistry (Enrollment_No,Student_Name) VALUES (%s, %s) """
recordTuple = (int(self.enrollmentlineEdit.text()), self.snamelineEdit.text())
cursor.execute(mySql_insert_query, recordTuple)
connection.commit()
self.noticLabel.setText("Record Insert Successfully ☺ ☺")
self.resetedits()
self.reseterror()
def display(self):
if int(self.enrollmentlineEdit.text()) == 0:
try:
raise ZeroDivisionError
except:
self.errorLable.setText("Enrollment No can not be Zero ××")
self.resetedits()
else:
try:
display = "select Student_Name,%s from mainregistry where Enrollment_No = %s" % (self.cnamelineEdit.text(), int(self.enrollmentlineEdit.text()))
cursor.execute(display)
for rec in cursor:
self.displayArea.setText("Enrollment No.: {}\nDate: {}\n..{}..".format(self.enrollmentlineEdit.text(), self.cnamelineEdit.text(), rec))
self.noticLabel.setText("Records Display Successfully ☺ ☺")
self.resetedits()
except:
self.displayArea.setText("Enrollment No.: {}\nDate: {}\n..{}..".format(self.enrollmentlineEdit.text(), self.cnamelineEdit.text(), "No Records Found ¡¡¡"))
self.resetedits()
def updtstd(self):
if int(self.enrollmentlineEdit.text()) == 0:
try:
raise ZeroDivisionError
except:
self.errorLable.setText("Enrollment No can not be Zero ××")
self.resetedits()
else:
updt = "update mainregistry set Student_name = '%s' where Enrollment_No = %s;" % (self.snamelineEdit.text(), int(self.enrollmentlineEdit.text()))
cursor.execute(updt)
connection.commit()
self.noticLabel.setText("Student Name Update Successfully ☺ ☺")
self.resetedits()
self.reseterror()
def absent(self):
self.lineEdit.setText("Absent")
def present(self):
self.lineEdit.setText("Present")
def updateenrollment(self):
update = "update mainregistry set %s = '%s' where Enrollment_No = %s;" % (self.cnamelineEdit.text(), self.lineEdit.text(), int(self.enrollmentlineEdit.text()))
cursor.execute(update)
connection.commit()
self.noticLabel.setText("Attendance Update Successfully ☺ ☺")
self.resetedits()
def ctc(self):
try:
create = "ALTER TABLE mainregistry ADD %s varchar(7) NOT NULL;" % (d1)
cursor.execute(create)
connection.commit()
self.noticLabel.setText("Today's column created Successfully ☺ ☺")
except:
self.noticLabel.setText("Today's column Already created ☺ ☺")
self.resetedits()
def nxtenrollment(self):
try:
sql_select_Query = "select max(Enrollment_No) from mainregistry;"
cursor.execute(sql_select_Query)
records = cursor.fetchall()
for i in records:
res = int(''.join(map(str, i)))
res = res + 1
self.noticLabel.setText("Your Next Enrollment No. should be " + str(res))
self.enrollmentlineEdit.setText(str(res))
except:
self.noticLabel.setText("Your Next Enrollment No. should be 1")
def shwent(self):
try:
fetch = "select Enrollment_No from mainregistry;"
cursor.execute(fetch)
rec = cursor.fetchall()
st = ""
for i in rec:
st = st + "\n" + str(i[0])
self.displayArea.setText("Enrollment No" + st)
self.noticLabel.setText("Enrollment No. Displayed Successfully ☺ ☺")
except:
self.displayArea.setText("There is nothing in Enrollment Entries ¡¡¡")
self.errorLable.setText("Enrollment Entries is Null ¡¡¡")
def scfd(self):
try:
fetch = "SELECT COLUMN_NAME FROM information_schema.columns WHERE table_name='mainregistry'"
cursor.execute(fetch)
rec = cursor.fetchall()
scfd = ""
for i in rec:
scfd = scfd + "\n" + str(i)
self.displayArea.setText("Columns Are: " + scfd)
self.noticLabel.setText("Columns Displayed Successfully ☺ ☺")
except:
self.displayArea.setText("There are no Columns ¡¡¡")
self.errorLable.setText("There are no Columns ¡¡¡")
def ermntchange(self):
select = "select Enrollment_No from mainregistry;"
cursor.execute(select)
records = cursor.fetchall()
ermnt = ""
for rec in records:
ermnt = ermnt + str(rec)
if self.enrollmentlineEdit.text() in ermnt:
self.ermntchk.setText("Available in DB")
else:
self.ermntchk.setText("Not Available in DB")
def clmchange(self):
select = "SELECT COLUMN_NAME FROM information_schema.columns WHERE table_name='mainregistry'"
cursor.execute(select)
rec = cursor.fetchall()
clmn = ""
for i in rec:
clmn = clmn+str(i)
if self.cnamelineEdit.text() in clmn:
self.clmnchk.setText("Available in DB")
else:
self.clmnchk.setText("Not Available in DB")
def tchange(self):
if self.enrollmentlineEdit.text() and self.snamelineEdit.text():
self.insertButton.setEnabled(True)
self.updtstdButton.setEnabled(True)
else:
self.insertButton.setEnabled(False)
self.updtstdButton.setEnabled(False)
def achange(self):
if self.enrollmentlineEdit.text() and self.cnamelineEdit.text() and self.lineEdit.text():
self.updtermntButton.setEnabled(True)
else:
self.updtermntButton.setEnabled(False)
def bchange(self):
if self.enrollmentlineEdit.text() and self.cnamelineEdit.text():
self.displayButton.setEnabled(True)
else:
self.displayButton.setEnabled(False)
def resetedits(self):
self.enrollmentlineEdit.setText("")
self.snamelineEdit.setText("")
self.cnamelineEdit.setText("")
self.lineEdit.setText("")
self.ermntchk.setText("")
self.clmnchk.setText("")
self.displayButton.setEnabled(False)
self.insertButton.setEnabled(False)
self.updtstdButton.setEnabled(False)
self.updtermntButton.setEnabled(False)
def resetdisarea(self):
self.displayArea.setText("")
def resetnotic(self):
self.noticLabel.setText("")
def reseterror(self):
self.errorLable.setText("")
def createdby(self):
self.displayArea.setText("Name: Dhanrajsinh Parmar\nSemester: Diploma - 5th Sem\nCourse: Python Programming\nDepartment: ICT\nUniversity: Marwadi University\n☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺ ☺")
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(819, 599)
Dialog.setMinimumSize(QtCore.QSize(819, 599))
Dialog.setMaximumSize(QtCore.QSize(819, 599))
font = QtGui.QFont()
font.setPointSize(10)
Dialog.setFont(font)
self.enrollmentLable = QtWidgets.QLabel(Dialog)
self.enrollmentLable.setGeometry(QtCore.QRect(20, 50, 91, 21))
font = QtGui.QFont()
font.setPointSize(10)
self.enrollmentLable.setFont(font)
self.enrollmentLable.setObjectName("enrollmentLable")
self.snameLable = QtWidgets.QLabel(Dialog)
self.snameLable.setGeometry(QtCore.QRect(20, 90, 91, 21))
font = QtGui.QFont()
font.setPointSize(10)
self.snameLable.setFont(font)
self.snameLable.setObjectName("snameLable")
self.enrollmentlineEdit = QtWidgets.QLineEdit(Dialog)
self.enrollmentlineEdit.setEnabled(True)
self.enrollmentlineEdit.setGeometry(QtCore.QRect(120, 50, 161, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.enrollmentlineEdit.setFont(font)
self.enrollmentlineEdit.setObjectName("enrollmentlineEdit")
self.snamelineEdit = QtWidgets.QLineEdit(Dialog)
self.snamelineEdit.setGeometry(QtCore.QRect(120, 90, 161, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.snamelineEdit.setFont(font)
self.snamelineEdit.setObjectName("snamelineEdit")
self.absentButton = QtWidgets.QPushButton(Dialog)
self.absentButton.setGeometry(QtCore.QRect(420, 50, 75, 23))
font = QtGui.QFont()
font.setPointSize(10)
self.absentButton.setFont(font)
self.absentButton.setObjectName("absentButton")
self.presentButton = QtWidgets.QPushButton(Dialog)
self.presentButton.setGeometry(QtCore.QRect(520, 50, 81, 23))
font = QtGui.QFont()
font.setPointSize(10)
self.presentButton.setFont(font)
self.presentButton.setObjectName("presentButton")
self.sdetailsLabel = QtWidgets.QLabel(Dialog)
self.sdetailsLabel.setGeometry(QtCore.QRect(20, 20, 141, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.sdetailsLabel.setFont(font)
self.sdetailsLabel.setObjectName("sdetailsLabel")
self.dattendLable = QtWidgets.QLabel(Dialog)
self.dattendLable.setGeometry(QtCore.QRect(420, 20, 121, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.dattendLable.setFont(font)
self.dattendLable.setObjectName("dattendLable")
self.nxtenrollButton = QtWidgets.QPushButton(Dialog)
self.nxtenrollButton.setGeometry(QtCore.QRect(420, 130, 181, 21))
self.nxtenrollButton.setObjectName("nxtenrollButton")
self.noticLabel = QtWidgets.QLabel(Dialog)
self.noticLabel.setGeometry(QtCore.QRect(20, 270, 371, 21))
self.noticLabel.setText("")
self.noticLabel.setObjectName("noticLabel")
self.insertButton = QtWidgets.QPushButton(Dialog)
self.insertButton.setGeometry(QtCore.QRect(20, 130, 75, 23))
self.insertButton.setObjectName("insertButton")
self.displayButton = QtWidgets.QPushButton(Dialog)
self.displayButton.setGeometry(QtCore.QRect(20, 210, 75, 23))
self.displayButton.setObjectName("displayButton")
self.cnameLable = QtWidgets.QLabel(Dialog)
self.cnameLable.setGeometry(QtCore.QRect(20, 170, 91, 16))
self.cnameLable.setObjectName("cnameLable")
self.cnamelineEdit = QtWidgets.QLineEdit(Dialog)
self.cnamelineEdit.setGeometry(QtCore.QRect(120, 170, 161, 20))
self.cnamelineEdit.setObjectName("cnamelineEdit")
self.colwarnLable = QtWidgets.QLabel(Dialog)
self.colwarnLable.setGeometry(QtCore.QRect(120, 205, 251, 31))
self.colwarnLable.setObjectName("colwarnLable")
self.scrollArea = QtWidgets.QScrollArea(Dialog)
self.scrollArea.setGeometry(QtCore.QRect(219, 349, 381, 231))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 379, 229))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.displayArea = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.displayArea.setGeometry(QtCore.QRect(10, 10, 351, 201))
self.displayArea.setText("")
self.displayArea.setObjectName("displayArea")
self.scrollArea.setWidget(self.displayArea)
self.updtermntButton = QtWidgets.QPushButton(Dialog)
self.updtermntButton.setGeometry(QtCore.QRect(420, 170, 75, 23))
self.updtermntButton.setObjectName("updtermntButton")
self.closeButton = QtWidgets.QPushButton(Dialog)
self.closeButton.setGeometry(QtCore.QRect(520, 170, 81, 23))
self.closeButton.setObjectName("closeButton")
self.ctcButton = QtWidgets.QPushButton(Dialog)
self.ctcButton.setGeometry(QtCore.QRect(420, 210, 181, 23))
self.ctcButton.setObjectName("ctcButton")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(420, 90, 181, 20))
self.lineEdit.setObjectName("lineEdit")
self.updtstdButton = QtWidgets.QPushButton(Dialog)
self.updtstdButton.setGeometry(QtCore.QRect(160, 130, 75, 23))
self.updtstdButton.setObjectName("updtstdButton")
self.clearButton = QtWidgets.QPushButton(Dialog)
self.clearButton.setGeometry(QtCore.QRect(50, 310, 111, 23))
self.clearButton.setObjectName("clearButton")
self.errorLable = QtWidgets.QLabel(Dialog)
self.errorLable.setGeometry(QtCore.QRect(450, 270, 371, 21))
self.errorLable.setText("")
self.errorLable.setObjectName("errorLable")
self.errorButton = QtWidgets.QPushButton(Dialog)
self.errorButton.setGeometry(QtCore.QRect(670, 310, 111, 23))
self.errorButton.setObjectName("errorButton")
self.seeButton = QtWidgets.QPushButton(Dialog)
self.seeButton.setGeometry(QtCore.QRect(630, 50, 161, 23))
self.seeButton.setObjectName("seeButton")
self.ermntchk = QtWidgets.QLabel(Dialog)
self.ermntchk.setGeometry(QtCore.QRect(290, 50, 121, 21))
self.ermntchk.setText("")
self.ermntchk.setObjectName("ermntchk")
self.clmnchk = QtWidgets.QLabel(Dialog)
self.clmnchk.setGeometry(QtCore.QRect(290, 170, 121, 21))
self.clmnchk.setText("")
self.clmnchk.setObjectName("clmnchk")
self.scfdButton = QtWidgets.QPushButton(Dialog)
self.scfdButton.setGeometry(QtCore.QRect(630, 130, 161, 23))
self.scfdButton.setObjectName("scfdButton")
self.createdbyButton = QtWidgets.QPushButton(Dialog)
self.createdbyButton.setGeometry(QtCore.QRect(680, 470, 75, 23))
self.createdbyButton.setObjectName("createdbyButton")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(50, 470, 111, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.insertButton.clicked.connect(self.insert)
self.displayButton.clicked.connect(self.display)
self.updtermntButton.clicked.connect(self.updateenrollment)
self.absentButton.clicked.connect(self.absent)
self.presentButton.clicked.connect(self.present)
self.nxtenrollButton.clicked.connect(self.nxtenrollment)
self.ctcButton.clicked.connect(self.ctc)
self.updtstdButton.clicked.connect(self.updtstd)
self.clearButton.clicked.connect(self.resetnotic)
self.errorButton.clicked.connect(self.reseterror)
self.seeButton.clicked.connect(self.shwent)
self.scfdButton.clicked.connect(self.scfd)
self.enrollmentlineEdit.textEdited.connect(self.tchange)
self.onlyInt = QIntValidator()
self.enrollmentlineEdit.setValidator(self.onlyInt)
self.snamelineEdit.textEdited.connect(self.tchange)
self.cnamelineEdit.textEdited.connect(self.bchange)
self.lineEdit.textChanged.connect(self.achange)
self.enrollmentlineEdit.textEdited.connect(self.ermntchange)
self.cnamelineEdit.textEdited.connect(self.clmchange)
self.pushButton.clicked.connect(self.resetdisarea)
self.lineEdit.setEnabled(False)
self.insertButton.setEnabled(False)
self.updtstdButton.setEnabled(False)
self.displayButton.setEnabled(False)
self.updtermntButton.setEnabled(False)
self.createdbyButton.clicked.connect(self.createdby)
self.closeButton.clicked.connect(QtCore.QCoreApplication.instance().quit)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Attendance System"))
self.enrollmentLable.setText(_translate("Dialog", "Enrollment No.:"))
self.snameLable.setText(_translate("Dialog", "Student Name:"))
self.absentButton.setText(_translate("Dialog", "Absent"))
self.presentButton.setText(_translate("Dialog", "Present"))
self.sdetailsLabel.setText(_translate("Dialog", "Add Student Details:-"))
self.dattendLable.setText(_translate("Dialog", "Daily Attendance:-"))
self.nxtenrollButton.setText(_translate("Dialog", "What will next Enrollment?"))
self.insertButton.setText(_translate("Dialog", "Insert"))
self.displayButton.setText(_translate("Dialog", "Display"))
self.cnameLable.setText(_translate("Dialog", "Column Name :"))
self.colwarnLable.setText(_translate("Dialog", "* Column Name is in dd_mm_yyyy Format"))
self.updtermntButton.setText(_translate("Dialog", "Update"))
self.closeButton.setText(_translate("Dialog", "Close"))
self.ctcButton.setText(_translate("Dialog", "Create Today\'s Column"))
self.updtstdButton.setText(_translate("Dialog", "Update"))
self.clearButton.setText(_translate("Dialog", " Clear Message"))
self.errorButton.setText(_translate("Dialog", " Clear Error"))
self.seeButton.setText(_translate("Dialog", "Show Enrollment Entries"))
self.scfdButton.setText(_translate("Dialog", "Show Columns from DB"))
self.createdbyButton.setText(_translate("Dialog", "Created By"))
self.pushButton.setText(_translate("Dialog", "Clear Display Area"))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
As10 = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(As10)
As10.show()
sys.exit(app.exec_())