From e2fe0c89c0fb76c7a54d6154f01046586ec366c0a32206e508ba3486440c6b02 Mon Sep 17 00:00:00 2001 From: linuxero Date: Wed, 11 Dec 2024 17:16:37 +0100 Subject: [PATCH] Finished adding a client, still the GUI need some retouches --- Gui/AddCustomer.qml | 17 ++++++++--------- lib/DB/BusinessDAO.py | 4 ++-- lib/DB/BusinessModel.py | 6 +++--- lib/DB/ContactDAO.py | 13 ++++++++----- lib/DB/ContactModel.py | 12 ++++++------ 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Gui/AddCustomer.qml b/Gui/AddCustomer.qml index c2ad4d1..a36db2b 100644 --- a/Gui/AddCustomer.qml +++ b/Gui/AddCustomer.qml @@ -7,6 +7,7 @@ import "../js/qmldict.js" as JsLib ColumnLayout { + property var new_business: null Layout.fillWidth: true Layout.fillHeight: true spacing: 15 @@ -249,7 +250,6 @@ ColumnLayout enabled: false onClicked: { - var new_business if (!checkAddContact.checked) { new_business = JsLib.addBusiness(businessGrid) @@ -258,15 +258,9 @@ ColumnLayout } else { - console.log("Contact available") - var contact_id = 0 new_business = JsLib.addBusiness(businessGrid) var new_contact = JsLib.addBusiness(addContactLayout) - // bm.setContact(new_contact, contact_id) - // bm.addBusiness(new_business, contact_id) - contact_id = contact_model.addContact(new_contact) - console.log(contact_id) - appLoader.source = "CustomerTable.qml" + contact_model.addContact(new_contact) } } @@ -278,6 +272,7 @@ ColumnLayout Layout.fillHeight: true } + Component.onCompleted: contact_model.contactIdReady.connect(onContactId) function isEmptyField() { @@ -294,5 +289,9 @@ ColumnLayout } } - + function onContactId(con_id) + { + business_model.addBusiness(new_business, con_id)// bm + appLoader.source = "CustomerTable.qml" + } } diff --git a/lib/DB/BusinessDAO.py b/lib/DB/BusinessDAO.py index 165c08f..3b0d9af 100644 --- a/lib/DB/BusinessDAO.py +++ b/lib/DB/BusinessDAO.py @@ -13,10 +13,10 @@ class BusinessDAO: self.__all_cols = [desc[0] for desc in self.__cur.description] return self.__cur.fetchall(), self.__all_cols - def addBusiness(self, data): + def addBusiness(self, data, contact_id): try: print(data) - self.__cur.callproc("addBusiness", (json.dumps(data),)) + self.__cur.callproc("addBusiness", (json.dumps(data), contact_id)) self.__con.commit() except mariadb.Error as e: diff --git a/lib/DB/BusinessModel.py b/lib/DB/BusinessModel.py index d4ebb93..77cf0ad 100644 --- a/lib/DB/BusinessModel.py +++ b/lib/DB/BusinessModel.py @@ -106,9 +106,9 @@ class BusinessModel(QAbstractTableModel): def onRowClicked(self, row): print(row) - @Slot(dict) - def addBusiness(self, business): - BusinessDAO().addBusiness(business) + @Slot(dict, int) + def addBusiness(self, business, contact_id): + BusinessDAO().addBusiness(business, contact_id) #BusinessDAO().addPlz() diff --git a/lib/DB/ContactDAO.py b/lib/DB/ContactDAO.py index 329858c..02daa19 100644 --- a/lib/DB/ContactDAO.py +++ b/lib/DB/ContactDAO.py @@ -14,12 +14,15 @@ class ContactDAO: def addContact(self, contact): try: - contact_id = self.__cur.callproc("addContactPerson", (contact, 0, )) + self.__cur.callproc("addContactPerson", (json.dumps(contact),)) self.__con.commit() - return contact_id[1] - #except mariadb.Error as e: - #print(str (e)) + self.__cur.callproc("getLastInsertId") + contact_id = self.__cur.fetchone() + print(contact_id) + return contact_id[0] + except mariadb.Error as e: + print("MDB: " + str(e)) except Exception as e: - print(str (e)) + print("PYT: " + str(e)) diff --git a/lib/DB/ContactModel.py b/lib/DB/ContactModel.py index 8d88eda..e3ffb59 100644 --- a/lib/DB/ContactModel.py +++ b/lib/DB/ContactModel.py @@ -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 import logging -import json class ContactModel(QObject): + contactIdReady = Signal(int) def __init__(self): super().__init__() #self.logger = logging.getLogger() @@ -21,8 +21,8 @@ class ContactModel(QObject): @Slot(dict) def addContact(self, contact): - addC = ContactDAO() - j = json.dumps(contact) - a = addC.addContact(j) - return a + i = ContactDAO().addContact(contact) + self.contactIdReady.emit(i) + +