Finished adding a client, still the GUI need some retouches

This commit is contained in:
2024-12-11 17:16:37 +01:00
parent 9a8be0409a
commit e2fe0c89c0
5 changed files with 27 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ import "../js/qmldict.js" as JsLib
ColumnLayout ColumnLayout
{ {
property var new_business: null
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
spacing: 15 spacing: 15
@@ -249,7 +250,6 @@ ColumnLayout
enabled: false enabled: false
onClicked: onClicked:
{ {
var new_business
if (!checkAddContact.checked) if (!checkAddContact.checked)
{ {
new_business = JsLib.addBusiness(businessGrid) new_business = JsLib.addBusiness(businessGrid)
@@ -258,15 +258,9 @@ ColumnLayout
} }
else else
{ {
console.log("Contact available")
var contact_id = 0
new_business = JsLib.addBusiness(businessGrid) new_business = JsLib.addBusiness(businessGrid)
var new_contact = JsLib.addBusiness(addContactLayout) var new_contact = JsLib.addBusiness(addContactLayout)
// bm.setContact(new_contact, contact_id) contact_model.addContact(new_contact)
// bm.addBusiness(new_business, contact_id)
contact_id = contact_model.addContact(new_contact)
console.log(contact_id)
appLoader.source = "CustomerTable.qml"
} }
} }
@@ -278,6 +272,7 @@ ColumnLayout
Layout.fillHeight: true Layout.fillHeight: true
} }
Component.onCompleted: contact_model.contactIdReady.connect(onContactId)
function isEmptyField() function isEmptyField()
{ {
@@ -294,5 +289,9 @@ ColumnLayout
} }
} }
function onContactId(con_id)
{
business_model.addBusiness(new_business, con_id)// bm
appLoader.source = "CustomerTable.qml"
}
} }

View File

@@ -13,10 +13,10 @@ class BusinessDAO:
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
def addBusiness(self, data): def addBusiness(self, data, contact_id):
try: try:
print(data) print(data)
self.__cur.callproc("addBusiness", (json.dumps(data),)) self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
self.__con.commit() self.__con.commit()
except mariadb.Error as e: except mariadb.Error as e:

View File

@@ -106,9 +106,9 @@ class BusinessModel(QAbstractTableModel):
def onRowClicked(self, row): def onRowClicked(self, row):
print(row) print(row)
@Slot(dict) @Slot(dict, int)
def addBusiness(self, business): def addBusiness(self, business, contact_id):
BusinessDAO().addBusiness(business) BusinessDAO().addBusiness(business, contact_id)
#BusinessDAO().addPlz() #BusinessDAO().addPlz()

View File

@@ -14,12 +14,15 @@ class ContactDAO:
def addContact(self, contact): def addContact(self, contact):
try: try:
contact_id = self.__cur.callproc("addContactPerson", (contact, 0, )) self.__cur.callproc("addContactPerson", (json.dumps(contact),))
self.__con.commit() self.__con.commit()
return contact_id[1] self.__cur.callproc("getLastInsertId")
#except mariadb.Error as e: contact_id = self.__cur.fetchone()
#print(str (e)) print(contact_id)
return contact_id[0]
except mariadb.Error as e:
print("MDB: " + str(e))
except Exception as e: except Exception as e:
print(str (e)) print("PYT: " + str(e))

View File

@@ -1,9 +1,9 @@
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal
from .ContactDAO import ContactDAO from .ContactDAO import ContactDAO
import logging import logging
import json
class ContactModel(QObject): class ContactModel(QObject):
contactIdReady = Signal(int)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
#self.logger = logging.getLogger() #self.logger = logging.getLogger()
@@ -21,8 +21,8 @@ class ContactModel(QObject):
@Slot(dict) @Slot(dict)
def addContact(self, contact): def addContact(self, contact):
addC = ContactDAO() i = ContactDAO().addContact(contact)
j = json.dumps(contact) self.contactIdReady.emit(i)
a = addC.addContact(j)
return a