added BusinessDAO

This commit is contained in:
2024-12-04 16:56:20 +01:00
parent 6e91637792
commit 50720596c6
11 changed files with 303 additions and 34668 deletions

15
lib/DB/BusinessDAO.py Normal file
View File

@@ -0,0 +1,15 @@
from .DbManager import DbManager
class BusinessDAO:
def __init__(self):
self.__con = DbManager().getConnection()
self.__cur = self.__con.cursor()
def getBusiness(self):
self.__cur.callproc("getCustomerView")
self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall(), self.__all_cols
def addBusiness(self):
pass

View File

@@ -1,45 +1,74 @@
# This Python file uses the following encoding: utf-8
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot
from .BusinessDAO import BusinessDAO
# USERS TABLE
# CUSTOMER_COLUMN_NAMES = \
# {
# "userid": "Identification",
# "username": "Benutzername",
# "password": "Passwort",
# "enabled": "Aktiv",
# "roleid": "Rolle",
# "gecos": "Information"
# }
#
# CUSTOMER_COLUMN_INDEX = \
# {
# "userid": 0,
# "username": 1,
# "password": 2,
# "enabled": 3,
# "roleid": 4,
# "gecos": 5
# }
#######################################
CUSTOMER_COLUMN_NAMES = \
{
"userid": "Identification",
"username": "Benutzername",
"password": "Passwort",
"enabled": "Aktiv",
"roleid": "Rolle",
"gecos": "Information"
}
# COLS = \
# {
# "businessid": "Kundennummer",
# "company": "Firma",
# "street": "Straße",
# "postcodeid": "PLZ",
# "phone": "Telefon",
# "mobilephone": "Mobil",
# "email": "E-Mail",
# "homepage": "Homepage",
# "director": "Geschäftsführer",
# "contactpersonid": "Ansprechpartner",
# "info": "Info",
# "btid": "Typ",
# }
# COLS_INDEX = \
# {
# "businessid": 0,
# "company": 1,
# "street": 2,
# "postcodeid": 3,
# "phone": 4,
# "mobilephone": 5,
# "email": 6,
# "homepage": 7,
# "director": 8,
# "contactpersonid": 9,
# "info": 10,
# "btid": 11,
# }
CUSTOMER_COLUMN_INDEX = \
{
"userid": 0,
"username": 1,
"password": 2,
"enabled": 3,
"roleid": 4,
"gecos": 5
}
class BusinessModel(QAbstractTableModel):
__visible_index = {}
__col_name = ""
def __init__(self, con, cols):
def __init__(self):
super().__init__()
self.__con = con
self.__visible_columns = cols
self.__data = self.__getData()
for col in cols:
self.__visible_index[col] = CUSTOMER_COLUMN_INDEX[col]
def __getData(self):
cursor = self.__con.cursor()
cursor.execute("SELECT * FROM users")
self.__all_cols = [desc[0] for desc in cursor.description]
#print(self.__all_cols)
rows = cursor.fetchall()
rows, self.__visible_columns = BusinessDAO().getBusiness()
return rows
def rowCount(self, parent= QModelIndex()):
@@ -51,29 +80,35 @@ class BusinessModel(QAbstractTableModel):
def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole:
row = self.__data[index.row()]
self.__col_name = self.__visible_columns[index.column()]
col_index = self.__visible_index[self.__col_name]
return row[col_index]
return row[index.column()]
return None
def headerData(self, section, orientation, role= Qt.DisplayRole):
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
self.__col_name = self.__visible_columns[section]
return CUSTOMER_COLUMN_NAMES.get(self.__col_name, self.__col_name)
return self.__col_name
return super().headerData(section, orientation, role)
@Slot(dict)
def setVisibleColumns(self, cols):
self.__visible_columns.clear()
self.__visible_index.clear()
for col, val in cols.items():
self.__visible_index[val] = CUSTOMER_COLUMN_INDEX[cols[col]]
self.__visible_columns.append(cols[col])
# self.headerDataChanged.emit()
# self.dataChanged.emit()
self.layoutChanged.emit()
########################NOT READY#################################
# @Slot(dict)
# def setVisibleColumns(self, cols):
# self.__visible_columns.clear()
# self.__visible_index.clear()
# for col, val in cols.items():
# self.__visible_index[val] = COLS_INDEX[cols[col]]
# self.__visible_columns.append(cols[col])
# # self.headerDataChanged.emit()
# # self.dataChanged.emit()
# self.layoutChanged.emit()
#################################################################
@Slot(int)
def onRowClicked(self, row):
print(row)
@Slot(dict)
def addBusiness(self, business):
pass