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
|
||||
}
|
||||
|
||||
visible: bad_config? false: true
|
||||
visible: bad_config || !db_con ? false: true
|
||||
}
|
||||
|
||||
Item
|
||||
@@ -54,7 +54,11 @@ ApplicationWindow
|
||||
{
|
||||
importDialog.open()
|
||||
}
|
||||
else appLoader.source= "LoginScreen.qml"
|
||||
else
|
||||
{
|
||||
if (db_con) appLoader.source= "LoginScreen.qml"
|
||||
else appLoader.source= "NoDbConnection.qml"
|
||||
}
|
||||
}
|
||||
|
||||
Dialog
|
||||
|
||||
@@ -4,8 +4,11 @@ import json
|
||||
|
||||
|
||||
class AddressDAO:
|
||||
__cur = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
|
||||
@@ -29,6 +32,9 @@ class AddressDAO:
|
||||
print("FINISHED")#
|
||||
|
||||
def getAddressData(self, all = True, zipcode = None):
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getAddress", (all, zipcode,))
|
||||
self.__data = self.__cur.fetchall()
|
||||
return self.__data
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -2,11 +2,17 @@ from .DbManager import DbManager
|
||||
|
||||
|
||||
class BTypeDAO:
|
||||
__cur = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getBType(self):
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getBtype", (None, None, ))
|
||||
data = self.__cur.fetchall()
|
||||
return(data)
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -6,18 +6,27 @@ from PySide6.QtCore import QObject, Signal
|
||||
|
||||
class BusinessDAO(QObject):
|
||||
newBusinessAdded = Signal()
|
||||
|
||||
__cur = None
|
||||
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getBusiness(self, enc_key, criterion = "Alle"):
|
||||
if self.__cur:
|
||||
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
|
||||
else:
|
||||
return None, None
|
||||
|
||||
def addBusiness(self, data, contact_id):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
|
||||
self.__con.commit()
|
||||
self.newBusinessAdded.emit()
|
||||
|
||||
@@ -113,7 +113,7 @@ class BusinessModel(QAbstractTableModel):
|
||||
|
||||
@Slot(int)
|
||||
def onRowClicked(self, row):
|
||||
print(row)
|
||||
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, criterion):
|
||||
|
||||
@@ -7,6 +7,7 @@ class ContactDAO:
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, __init__()")
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getContacts(self):
|
||||
@@ -14,11 +15,14 @@ class ContactDAO:
|
||||
|
||||
def addContact(self, contact, enc_key):
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
|
||||
self.__con.commit()
|
||||
self.__cur.callproc("getLastInsertId")
|
||||
contact_id = self.__cur.fetchone()
|
||||
return contact_id[0]
|
||||
else:
|
||||
return None
|
||||
except mariadb.Error as e:
|
||||
print("MDB: " + str(e))
|
||||
except Exception as e:
|
||||
|
||||
@@ -7,10 +7,10 @@ class ContactModel(QObject):
|
||||
contactIdReady = Signal(int)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# print(f"*** File: {__file__}, __init__()")
|
||||
#self.logger = logging.getLogger()
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
#self.logger = logging.getLogger()
|
||||
# print(f"*** File: {__file__}, __init__()")
|
||||
self.__data = self.__getData()
|
||||
|
||||
def getContacts(self):
|
||||
|
||||
@@ -16,14 +16,17 @@ class DbManager(object):
|
||||
|
||||
|
||||
def getConnection(cls):
|
||||
#print(f"DB Manager: {cls.__dbmanager}")
|
||||
#print(f"DB Connection: {cls.__connection}")
|
||||
try:
|
||||
if not cls.__connection or not cls.__connection.ping():
|
||||
cls.__failure_notified = False
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
except mariadb.InterfaceError as e:
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||
except mariadb.Error as e:
|
||||
print(f"Connection parameters are wrong: {e}")
|
||||
print(f"File: {__file__}\n Database connection error: {e}")
|
||||
cls.__connection = None
|
||||
|
||||
return cls.__connection
|
||||
|
||||
@@ -4,15 +4,20 @@ from ..PyqcrmFlags import PyqcrmFlags
|
||||
import mariadb
|
||||
|
||||
class UserDAO:
|
||||
__cursor = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def createUser(self, username, password, info, role= PyqcrmFlags.USER):
|
||||
user_created = True
|
||||
user_created = False
|
||||
try:
|
||||
if self.__cur:
|
||||
self.__cur.callproc("createUser", (username, password, info, role))
|
||||
self.__con.commit()
|
||||
user_created = True
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
print(e.errno)
|
||||
@@ -21,8 +26,11 @@ class UserDAO:
|
||||
return user_created
|
||||
|
||||
def getUser(self, username):
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getUser", (username,))
|
||||
return self.__cur.fetchone()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ class UserManager(QObject):
|
||||
def __init__(self, user_config = None, role = None):
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
if user_config and role:
|
||||
|
||||
|
||||
6
main.py
6
main.py
@@ -28,6 +28,7 @@ from lib.DB.ContactModel import ContactModel
|
||||
# type=""
|
||||
|
||||
bad_config = False
|
||||
db_con = False
|
||||
address_model = None
|
||||
business_model = None
|
||||
business_type = None
|
||||
@@ -41,8 +42,8 @@ def initializeProgram():
|
||||
dbconf = config.getConfig()['database']
|
||||
DbManager(dbconf)
|
||||
bad_config = False
|
||||
business_model = BusinessModel()
|
||||
user = UserManager()
|
||||
business_model = BusinessModel()
|
||||
address_model = AddressModel()
|
||||
business_type = BTypeModel()
|
||||
contact_model = ContactModel()
|
||||
@@ -78,9 +79,12 @@ if __name__ == "__main__":
|
||||
config.configurationReady.connect(initializeProgram)
|
||||
else:
|
||||
initializeProgram()
|
||||
if DbManager().getConnection():
|
||||
db_con = True
|
||||
|
||||
|
||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||
engine.rootContext().setContextProperty("db_con", db_con)
|
||||
engine.rootContext().setContextProperty("config", config)
|
||||
|
||||
engine.load(qml_file)
|
||||
|
||||
Reference in New Issue
Block a user