-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattendance.py
More file actions
177 lines (143 loc) · 6.87 KB
/
attendance.py
File metadata and controls
177 lines (143 loc) · 6.87 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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '.\Attendance.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# 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.
import mysql.connector
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def __init__(self):
self.listValues = None
self.studentId = None
def setupUi(self, Dialog, listValues, studentId):
Dialog.setObjectName("Dialog")
Dialog.resize(368, 196)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 150, 301, 31))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.formLayoutWidget = QtWidgets.QWidget(Dialog)
self.formLayoutWidget.setGeometry(QtCore.QRect(20, 20, 311, 131))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.lblStudentId = QtWidgets.QLabel(self.formLayoutWidget)
self.lblStudentId.setObjectName("lblStudentId")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.lblStudentId)
self.lblFirstName = QtWidgets.QLabel(self.formLayoutWidget)
self.lblFirstName.setObjectName("lblFirstName")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.lblFirstName)
self.lblLastName = QtWidgets.QLabel(self.formLayoutWidget)
self.lblLastName.setObjectName("lblLastName")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.lblLastName)
self.lblStatus = QtWidgets.QLabel(self.formLayoutWidget)
self.lblStatus.setObjectName("lblStatus")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.lblStatus)
self.cmbStudentId = QtWidgets.QComboBox(self.formLayoutWidget)
self.cmbStudentId.setObjectName("cmbStudentId")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.cmbStudentId)
self.txtFirstName = QtWidgets.QLineEdit(self.formLayoutWidget)
self.txtFirstName.setObjectName("txtFirstName")
self.txtFirstName.setEnabled(False)
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.txtFirstName)
self.txtLastName = QtWidgets.QLineEdit(self.formLayoutWidget)
self.txtLastName.setObjectName("txtLastName")
self.txtLastName.setEnabled(False)
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.txtLastName)
self.cmbStatus = QtWidgets.QComboBox(self.formLayoutWidget)
self.cmbStatus.setObjectName("cmbStatus")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.cmbStatus)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Dialog)
# Update UI here
self.listValues = listValues
self.studentId = studentId
self.initialSetup()
self.connect_signals()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.lblStudentId.setText(_translate("Dialog", "Student ID:"))
self.lblFirstName.setText(_translate("Dialog", "First Name: "))
self.lblLastName.setText(_translate("Dialog", "Last Name: "))
self.lblStatus.setText(_translate("Dialog", "Status: "))
def connect_signals(self):
self.cmbStudentId.currentIndexChanged.connect(self.refresh)
##################### End UI Generation ###################
#############################################################
# #
# Events #
# #
#############################################################
def initialSetup(self):
self.setupComboBoxStatus()
self.setupComboBoxStudentID()
self.setupDatabase()
self.setValues()
def setupComboBoxStatus(self):
self.cmbStatus.clear()
self.cmbStatus.addItem("Present")
self.cmbStatus.addItem("Absent")
def setupComboBoxStudentID(self):
self.cmbStudentId.clear()
for id in self.studentId:
self.cmbStudentId.addItem(str(id))
def setupTextStudentName(self, firstName, lastName):
self.txtFirstName.clear()
self.txtLastName.clear()
self.txtFirstName.setText(firstName)
self.txtLastName.setText(lastName)
def setValues(self):
if self.listValues == None:
return
self.cmbStudentId.setCurrentText(self.listValues[0])
self.cmbStatus.setCurrentText(self.listValues[1])
def getValues(self):
listResult = []
listResult.append(self.cmbStudentId.currentText())
listResult.append(self.cmbStatus.currentText())
return listResult
##################### End Events ###################
#############################################################
# #
# Database #
# #
#############################################################
def setupDatabase(self):
self.connect()
self.refresh()
def connect(self):
self.cnx = mysql.connector.connect(user="root",
password="222488842dahy",
host="127.0.0.1",
database="mydb")
def refresh(self):
# Create a cursor object to execute queries
cursor = self.cnx.cursor()
studentId = self.cmbStudentId.currentText()
# Execute a query to retrieve data
query = "Select student_first_name, student_last_name " \
"from student " \
"where student_id = " + studentId
if studentId == "":
return
cursor.execute(query)
# Fetch all the rows returned by the query
name = cursor.fetchall()[0]
self.setupTextStudentName(name[0], name[1])
# Close the cursor and the database connection
cursor.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog, None, [])
Dialog.show()
sys.exit(app.exec_())