Employee/Applicant GUI and DB

This commit is contained in:
2025-02-14 12:05:45 +01:00
parent 80bd2c9be2
commit 5ff4749247
10 changed files with 199 additions and 52 deletions

View File

@@ -105,7 +105,7 @@ class BusinessModel(QAbstractTableModel):
def columnCount(self, parent= QModelIndex()):
return len(self.__visible_columns) - 1
def data(self, index, role= Qt.DisplayRole):
def data(self, index, role = Qt.DisplayRole):
if role == Qt.DisplayRole:
row = self.__data[index.row()]
return row[index.column() + 1]
@@ -132,6 +132,7 @@ class BusinessModel(QAbstractTableModel):
@Slot(int)
def onRowClicked(self, row):
#print(self.__data)
#print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
if not self.__business_dict['business'] or self.__data[row][0] != self.__business_dict['business']['id']:
self.__business = self.__business_dao.getOneBusiness(self.__data[row][0], self.__key)

View File

@@ -17,16 +17,10 @@ class EmployeeDAO(QObject):
if self.__con:
self.__cur = self.__con.cursor()
def getEmployees(self, enc_key, criterion = "Alle", appli_emp = 0, processed = False):
'''
appli_emp:
0 = applicants and employees
1 = applicants only
2 = employees only
'''
def getEmployees(self, enc_key, criterion = "Alle", processed = False, fired = False):
try:
if self.__cur:
self.__cur.callproc("getEmployeesView", (appli_emp, processed, criterion, enc_key, ))
self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, enc_key, ))
self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall(), self.__all_cols
else:
@@ -45,10 +39,10 @@ class EmployeeDAO(QObject):
except mariadb.Error as e:
print(str(e))
def addEmployee(self, data, enc_key, employee = False):
def addEmployee(self, data, enc_key, applicant = True):
try:
if self.__cur:
self.__cur.callproc("addApplicant", (json.dumps(data), employee, enc_key,))
self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,))
self.__con.commit()
self.newEmployeeAdded.emit()

View File

@@ -21,21 +21,22 @@ class EmployeeModel(QAbstractTableModel):
self.__getData()
@Slot(dict, bool)
def addEmployee(self, new_employee, employee = False):
print(new_employee)
self.__employee_dao.addEmployee(new_employee, self.__key, employee)
def addEmployee(self, new_employee, applicant = True):
new_employee['worklicense'] = int(new_employee['worklicense'])
new_employee['residencetype'] = int(new_employee['residencetype'])
self.__employee_dao.addEmployee(new_employee, self.__key, applicant)
@Slot(str)
def viewCriterion(self, criterion):
self.__getData(criterion)
def viewCriterion(self, criterion, processed = False, fired = False):
self.__getData(criterion, processed, fired)
@Slot()
def __refreshView(self):
self.__getData()
def __getData(self, criterion = "Alle", processed = False):
def __getData(self, criterion = "Alle", processed = False, fired = False):
self.beginResetModel()
rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, 0, processed)
rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, processed, fired)
self.__data = rows
self.endResetModel()
@@ -45,14 +46,32 @@ class EmployeeModel(QAbstractTableModel):
def columnCount(self, parent= QModelIndex()):
return len(self.__visible_columns) - 2
@Slot(str, bool, bool)
def viewCriterion(self, criterion, processed, fired):
self.__getData(criterion, processed, fired)
def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole:
row = self.__data[index.row()]
return row[index.column() + 2]
tr = row[index.column() + 2] #if type(row[index.column() + 2]) is str else str(row[index.column() + 2], "utf-8")
#print(f"Data: {tr}")
# return row[index.column() + 2]
return tr
return None
def headerData(self, section, orientation, role= Qt.DisplayRole):
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
def headerData(self, section, orientation, role = Qt.DisplayRole):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
self.__col_name = self.__visible_columns[section + 2]
return self.__col_name
return super().headerData(section, orientation, role)
@Slot(int)
def onRowClicked(self, row):
#print(self.__data)
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
#if not self.__employee_dict['employee'] or self.__data[row][0] != self.__employee_dict['employee']['id']:
#self.__employee = self.__employee_dao.getEmployee(self.__data[row][0], self.__key)
#print(self.__business)
#self.__getEmployeeInfo()
# self.__getContactInfo()
# print(self.__business_dict)