Fixing qml connection to save business with a new contact - some

database modifications
This commit is contained in:
2024-12-14 15:32:10 +01:00
parent 59e5fadd26
commit 559ad1b882
7 changed files with 54 additions and 22 deletions

View File

@@ -125,7 +125,14 @@ GridLayout
placeholderText: qsTr("TT.MM.JJJJ") placeholderText: qsTr("TT.MM.JJJJ")
validator: RegularExpressionValidator validator: RegularExpressionValidator
{ {
regularExpression: /((^|)([0-2]{1}[0-9]{1}|3[0-1]))\.((^|)([0-1]{1,2}|12))\.([0-9]{4})/ regularExpression: /((^|)([0-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
}
onTextChanged:
{
var len = birthday.length
var bd = birthday.text
if (len == 2 || len == 5) birthday.text = bd + "."
} }
} }

View File

@@ -85,7 +85,18 @@ ColumnLayout
Layout.fillHeight: true Layout.fillHeight: true
} }
Component.onCompleted: contact_model.contactIdReady.connect(onContactId) //Component.onCompleted: contact_model.contactIdReady.connect(onContactId)
Connections
{
target: contact_model
onContactIdReady:
{
var con_id = arguments[0]
business_model.addBusiness(new_business, con_id)
appLoader.source = "CustomerTable.qml"
}
}
function checkFields() function checkFields()
{ {
@@ -101,10 +112,4 @@ ColumnLayout
else else
saveBtn.enabled = true saveBtn.enabled = true
} }
function onContactId(con_id)
{
business_model.addBusiness(new_business, con_id)// bm
appLoader.source = "CustomerTable.qml"
}
} }

View File

@@ -107,6 +107,10 @@ Item {
id: customerTable id: customerTable
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
ScrollBar.vertical: ScrollBar
{
policy: customerTable.contentHeight > customerTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
}
columnSpacing: 1 columnSpacing: 1
rowSpacing: 2 rowSpacing: 2
model: business_model model: business_model
@@ -162,7 +166,7 @@ Item {
Text Text
{ {
text: model.display text: model.display == null? "": model.display
elide: Text.ElideRight elide: Text.ElideRight
width: parent.width width: parent.width
height: parent.height height: parent.height
@@ -197,7 +201,7 @@ Item {
Item Item
{ {
Layout.fillHeight: true //Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
} }
} }

View File

@@ -1,15 +1,18 @@
from .DbManager import DbManager from .DbManager import DbManager
import json import json
import mariadb import mariadb
from PySide6.QtCore import QObject, Signal
class BusinessDAO: class BusinessDAO(QObject):
newBusinessAdded = Signal()
def __init__(self): def __init__(self):
super().__init__()
self.__con = DbManager().getConnection() self.__con = DbManager().getConnection()
self.__cur = self.__con.cursor() self.__cur = self.__con.cursor()
def getBusiness(self, criterion = "Alle"): def getBusiness(self, enc_key, criterion = "Alle"):
self.__cur.callproc("getCustomerView", (criterion,)) self.__cur.callproc("getCustomerView", (enc_key, criterion,))
self.__all_cols = [desc[0] for desc in self.__cur.description] self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall(), self.__all_cols return self.__cur.fetchall(), self.__all_cols
@@ -17,6 +20,7 @@ class BusinessDAO:
try: try:
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id)) self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
self.__con.commit() self.__con.commit()
self.newBusinessAdded.emit()
except mariadb.Error as e: except mariadb.Error as e:
print(str(e)) print(str(e))

View File

@@ -2,6 +2,7 @@
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
from .BusinessDAO import BusinessDAO from .BusinessDAO import BusinessDAO
from ..PyqcrmFlags import PyqcrmFlags from ..PyqcrmFlags import PyqcrmFlags
from ..ConfigLoader import ConfigLoader
# USERS TABLE # USERS TABLE
# CUSTOMER_COLUMN_NAMES = \ # CUSTOMER_COLUMN_NAMES = \
@@ -63,14 +64,19 @@ from ..PyqcrmFlags import PyqcrmFlags
class BusinessModel(QAbstractTableModel): class BusinessModel(QAbstractTableModel):
__visible_index = {} __visible_index = {}
__col_name = "" __col_name = ""
__business_dao = None
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.__business_dao = BusinessDAO()
self.__business_dao.newBusinessAdded.connect(self.__refreshView)
self.__conf = ConfigLoader().getConfig()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__getData() self.__getData()
def __getData(self, criterion = "Alle"): def __getData(self, criterion = "Alle"):
self.beginResetModel() self.beginResetModel()
rows, self.__visible_columns = BusinessDAO().getBusiness(criterion) rows, self.__visible_columns = self.__business_dao.getBusiness(self.__key, criterion)
self.__data = rows self.__data = rows
self.endResetModel() self.endResetModel()
@@ -116,7 +122,10 @@ class BusinessModel(QAbstractTableModel):
@Slot(dict, int) @Slot(dict, int)
def addBusiness(self, business, contact_id): def addBusiness(self, business, contact_id):
BusinessDAO().addBusiness(business, contact_id) self.__business_dao.addBusiness(business, contact_id)
@Slot()
def __refreshView(self):
self.__getData() self.__getData()
@Slot(dict) @Slot(dict)

View File

@@ -5,16 +5,16 @@ import mariadb
class ContactDAO: class ContactDAO:
def __init__(self): def __init__(self):
print(f"*** File: {__file__}, __init__()") #print(f"*** File: {__file__}, __init__()")
self.__con = DbManager().getConnection() self.__con = DbManager().getConnection()
self.__cur = self.__con.cursor() self.__cur = self.__con.cursor()
def getContacts(self): def getContacts(self):
print(f"*** File: {__file__}, getContacts()") print(f"*** File: {__file__}, getContacts()")
def addContact(self, contact): def addContact(self, contact, enc_key):
try: try:
self.__cur.callproc("addContactPerson", (json.dumps(contact),)) self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
self.__con.commit() self.__con.commit()
self.__cur.callproc("getLastInsertId") self.__cur.callproc("getLastInsertId")
contact_id = self.__cur.fetchone() contact_id = self.__cur.fetchone()

View File

@@ -1,27 +1,30 @@
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal
from .ContactDAO import ContactDAO from .ContactDAO import ContactDAO
from ..ConfigLoader import ConfigLoader
import logging import logging
class ContactModel(QObject): class ContactModel(QObject):
contactIdReady = Signal(int) contactIdReady = Signal(int)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.__conf = ConfigLoader().getConfig()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
#self.logger = logging.getLogger() #self.logger = logging.getLogger()
print(f"*** File: {__file__}, __init__()") # print(f"*** File: {__file__}, __init__()")
self.__data = self.__getData() self.__data = self.__getData()
def getContacts(self): def getContacts(self):
print(f"*** File: {__file__}, getContacts()") # print(f"*** File: {__file__}, getContacts()")
logging.debug("No debug message") logging.debug("No debug message")
return self.__data return self.__data
def __getData(self): def __getData(self):
print(f"*** File: {__file__}, __getData()") # print(f"*** File: {__file__}, __getData()")
ContactDAO().getContacts() ContactDAO().getContacts()
@Slot(dict) @Slot(dict)
def addContact(self, contact): def addContact(self, contact):
i = ContactDAO().addContact(contact) i = ContactDAO().addContact(contact, self.__key)
self.contactIdReady.emit(i) self.contactIdReady.emit(i)