Added start blocke on no database connection available
This commit is contained in:
74
Gui/NoDbConnection.qml
Normal file
74
Gui/NoDbConnection.qml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
color: "slateblue"
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
id: info
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
color: "slateblue"
|
||||||
|
implicitHeight: 55
|
||||||
|
implicitWidth: parent.width / 4
|
||||||
|
y: parent.height / 4
|
||||||
|
Text
|
||||||
|
{
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: qsTr("Keine Verbindung zur Datenbank!")
|
||||||
|
color: "moccasin"
|
||||||
|
font.bold: true
|
||||||
|
font.pixelSize: 45
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
id: nostart
|
||||||
|
anchors.top: info.bottom
|
||||||
|
color: "slateblue"
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
implicitHeight: 55
|
||||||
|
implicitWidth: parent.width / 4
|
||||||
|
Text
|
||||||
|
{
|
||||||
|
text: qsTr("Programm kann nicht starten..")
|
||||||
|
color: "moccasin"
|
||||||
|
anchors.centerIn: parent
|
||||||
|
font.bold: true
|
||||||
|
font.pixelSize: 45
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
anchors.top: nostart.bottom
|
||||||
|
anchors.topMargin: 25
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
color: "slateblue"
|
||||||
|
implicitHeight: 55
|
||||||
|
implicitWidth: parent.width / 4
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
width: parent.width
|
||||||
|
height: 75
|
||||||
|
Text
|
||||||
|
{
|
||||||
|
text: qsTr("Beenden")
|
||||||
|
color: "moccasin"
|
||||||
|
anchors.centerIn: parent
|
||||||
|
font.bold: true
|
||||||
|
font.pixelSize: 45
|
||||||
|
}
|
||||||
|
anchors.centerIn: parent
|
||||||
|
background: Rectangle
|
||||||
|
{
|
||||||
|
color: "dodgerblue"
|
||||||
|
radius: 50
|
||||||
|
}
|
||||||
|
onClicked: Qt.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ ApplicationWindow
|
|||||||
leftMargin: 9
|
leftMargin: 9
|
||||||
}
|
}
|
||||||
|
|
||||||
visible: bad_config? false: true
|
visible: bad_config || !db_con ? false: true
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
Item
|
||||||
@@ -54,7 +54,11 @@ ApplicationWindow
|
|||||||
{
|
{
|
||||||
importDialog.open()
|
importDialog.open()
|
||||||
}
|
}
|
||||||
else appLoader.source= "LoginScreen.qml"
|
else
|
||||||
|
{
|
||||||
|
if (db_con) appLoader.source= "LoginScreen.qml"
|
||||||
|
else appLoader.source= "NoDbConnection.qml"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog
|
Dialog
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import json
|
|||||||
|
|
||||||
|
|
||||||
class AddressDAO:
|
class AddressDAO:
|
||||||
|
__cur = None
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
#print(f"*** File: {__file__}, init()")
|
||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +32,9 @@ class AddressDAO:
|
|||||||
print("FINISHED")#
|
print("FINISHED")#
|
||||||
|
|
||||||
def getAddressData(self, all = True, zipcode = None):
|
def getAddressData(self, all = True, zipcode = None):
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("getAddress", (all, zipcode,))
|
self.__cur.callproc("getAddress", (all, zipcode,))
|
||||||
self.__data = self.__cur.fetchall()
|
self.__data = self.__cur.fetchall()
|
||||||
return self.__data
|
return self.__data
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|||||||
@@ -2,11 +2,17 @@ from .DbManager import DbManager
|
|||||||
|
|
||||||
|
|
||||||
class BTypeDAO:
|
class BTypeDAO:
|
||||||
|
__cur = None
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
#print(f"*** File: {__file__}, init()")
|
||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
def getBType(self):
|
def getBType(self):
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("getBtype", (None, None, ))
|
self.__cur.callproc("getBtype", (None, None, ))
|
||||||
data = self.__cur.fetchall()
|
data = self.__cur.fetchall()
|
||||||
return(data)
|
return(data)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|||||||
@@ -6,18 +6,27 @@ from PySide6.QtCore import QObject, Signal
|
|||||||
|
|
||||||
class BusinessDAO(QObject):
|
class BusinessDAO(QObject):
|
||||||
newBusinessAdded = Signal()
|
newBusinessAdded = Signal()
|
||||||
|
|
||||||
|
__cur = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
#print(f"*** File: {__file__}, init()")
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
def getBusiness(self, enc_key, criterion = "Alle"):
|
def getBusiness(self, enc_key, criterion = "Alle"):
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("getCustomerView", (enc_key, 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
|
||||||
|
else:
|
||||||
|
return None, None
|
||||||
|
|
||||||
def addBusiness(self, data, contact_id):
|
def addBusiness(self, data, contact_id):
|
||||||
try:
|
try:
|
||||||
|
if self.__cur:
|
||||||
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()
|
self.newBusinessAdded.emit()
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class BusinessModel(QAbstractTableModel):
|
|||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onRowClicked(self, row):
|
def onRowClicked(self, row):
|
||||||
print(row)
|
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
|
||||||
|
|
||||||
@Slot(str)
|
@Slot(str)
|
||||||
def viewCriterion(self, criterion):
|
def viewCriterion(self, criterion):
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
def getContacts(self):
|
def getContacts(self):
|
||||||
@@ -14,11 +15,14 @@ class ContactDAO:
|
|||||||
|
|
||||||
def addContact(self, contact, enc_key):
|
def addContact(self, contact, enc_key):
|
||||||
try:
|
try:
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("addContactPerson", (enc_key, 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()
|
||||||
return contact_id[0]
|
return contact_id[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print("MDB: " + str(e))
|
print("MDB: " + str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ class ContactModel(QObject):
|
|||||||
contactIdReady = Signal(int)
|
contactIdReady = Signal(int)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
# print(f"*** File: {__file__}, __init__()")
|
||||||
|
#self.logger = logging.getLogger()
|
||||||
self.__conf = ConfigLoader().getConfig()
|
self.__conf = ConfigLoader().getConfig()
|
||||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||||
#self.logger = logging.getLogger()
|
|
||||||
# print(f"*** File: {__file__}, __init__()")
|
|
||||||
self.__data = self.__getData()
|
self.__data = self.__getData()
|
||||||
|
|
||||||
def getContacts(self):
|
def getContacts(self):
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ class DbManager(object):
|
|||||||
|
|
||||||
|
|
||||||
def getConnection(cls):
|
def getConnection(cls):
|
||||||
|
#print(f"DB Manager: {cls.__dbmanager}")
|
||||||
|
#print(f"DB Connection: {cls.__connection}")
|
||||||
try:
|
try:
|
||||||
if not cls.__connection or not cls.__connection.ping():
|
if not cls.__connection or not cls.__connection.ping():
|
||||||
|
cls.__failure_notified = False
|
||||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||||
except mariadb.InterfaceError as e:
|
except mariadb.InterfaceError as e:
|
||||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print(f"Connection parameters are wrong: {e}")
|
print(f"File: {__file__}\n Database connection error: {e}")
|
||||||
cls.__connection = None
|
cls.__connection = None
|
||||||
|
|
||||||
return cls.__connection
|
return cls.__connection
|
||||||
|
|||||||
@@ -4,15 +4,20 @@ from ..PyqcrmFlags import PyqcrmFlags
|
|||||||
import mariadb
|
import mariadb
|
||||||
|
|
||||||
class UserDAO:
|
class UserDAO:
|
||||||
|
__cursor = None
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
#print(f"*** File: {__file__}, init()")
|
||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
def createUser(self, username, password, info, role= PyqcrmFlags.USER):
|
def createUser(self, username, password, info, role= PyqcrmFlags.USER):
|
||||||
user_created = True
|
user_created = False
|
||||||
try:
|
try:
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("createUser", (username, password, info, role))
|
self.__cur.callproc("createUser", (username, password, info, role))
|
||||||
self.__con.commit()
|
self.__con.commit()
|
||||||
|
user_created = True
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
print(e.errno)
|
print(e.errno)
|
||||||
@@ -21,8 +26,11 @@ class UserDAO:
|
|||||||
return user_created
|
return user_created
|
||||||
|
|
||||||
def getUser(self, username):
|
def getUser(self, username):
|
||||||
|
if self.__cur:
|
||||||
self.__cur.callproc("getUser", (username,))
|
self.__cur.callproc("getUser", (username,))
|
||||||
return self.__cur.fetchone()
|
return self.__cur.fetchone()
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class UserManager(QObject):
|
|||||||
def __init__(self, user_config = None, role = None):
|
def __init__(self, user_config = None, role = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
|
if self.__con:
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
if user_config and role:
|
if user_config and role:
|
||||||
|
|
||||||
|
|||||||
6
main.py
6
main.py
@@ -28,6 +28,7 @@ from lib.DB.ContactModel import ContactModel
|
|||||||
# type=""
|
# type=""
|
||||||
|
|
||||||
bad_config = False
|
bad_config = False
|
||||||
|
db_con = False
|
||||||
address_model = None
|
address_model = None
|
||||||
business_model = None
|
business_model = None
|
||||||
business_type = None
|
business_type = None
|
||||||
@@ -41,8 +42,8 @@ def initializeProgram():
|
|||||||
dbconf = config.getConfig()['database']
|
dbconf = config.getConfig()['database']
|
||||||
DbManager(dbconf)
|
DbManager(dbconf)
|
||||||
bad_config = False
|
bad_config = False
|
||||||
business_model = BusinessModel()
|
|
||||||
user = UserManager()
|
user = UserManager()
|
||||||
|
business_model = BusinessModel()
|
||||||
address_model = AddressModel()
|
address_model = AddressModel()
|
||||||
business_type = BTypeModel()
|
business_type = BTypeModel()
|
||||||
contact_model = ContactModel()
|
contact_model = ContactModel()
|
||||||
@@ -78,9 +79,12 @@ if __name__ == "__main__":
|
|||||||
config.configurationReady.connect(initializeProgram)
|
config.configurationReady.connect(initializeProgram)
|
||||||
else:
|
else:
|
||||||
initializeProgram()
|
initializeProgram()
|
||||||
|
if DbManager().getConnection():
|
||||||
|
db_con = True
|
||||||
|
|
||||||
|
|
||||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||||
|
engine.rootContext().setContextProperty("db_con", db_con)
|
||||||
engine.rootContext().setContextProperty("config", config)
|
engine.rootContext().setContextProperty("config", config)
|
||||||
|
|
||||||
engine.load(qml_file)
|
engine.load(qml_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user