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")
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
}
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()
{
@@ -101,10 +112,4 @@ ColumnLayout
else
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
Layout.fillHeight: true
Layout.fillWidth: true
ScrollBar.vertical: ScrollBar
{
policy: customerTable.contentHeight > customerTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
}
columnSpacing: 1
rowSpacing: 2
model: business_model
@@ -162,7 +166,7 @@ Item {
Text
{
text: model.display
text: model.display == null? "": model.display
elide: Text.ElideRight
width: parent.width
height: parent.height
@@ -197,7 +201,7 @@ Item {
Item
{
Layout.fillHeight: true
//Layout.fillHeight: true
Layout.fillWidth: true
}
}

View File

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

View File

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

View File

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

View File

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