{
QStringList tables = db.tables();
QSqlQuery q;
- if (!tables.contains (this->tabNameCustomers, Qt::CaseSensitivity::CaseInsensitive) ) {
+ if (!tables.contains (this->tabNameCustomers,
+ Qt::CaseSensitivity::CaseInsensitive) ) {
if (!q.exec (this->sqlCreateCustomerTable) ) return q.lastError();
}
- if (!tables.contains (this->tabNameServices, Qt::CaseSensitivity::CaseInsensitive) ) {
+ if (!tables.contains (this->tabNameServices,
+ Qt::CaseSensitivity::CaseInsensitive) ) {
if (!q.exec (this->sqlCreateServicesTable) ) return q.lastError();
}
- if (!tables.contains (this->tabNameOrders, Qt::CaseSensitivity::CaseInsensitive) ) {
+ if (!tables.contains (this->tabNameOrders,
+ Qt::CaseSensitivity::CaseInsensitive) ) {
if (!q.exec (this->sqlCreateOrdersTable) ) return q.lastError();
}
- if (!tables.contains (this->tabNameOrderitems, Qt::CaseSensitivity::CaseInsensitive) ) {
+ if (!tables.contains (this->tabNameOrderitems,
+ Qt::CaseSensitivity::CaseInsensitive) ) {
if (!q.exec (this->sqlCreateOrderItemsTable) ) return q.lastError();
}
- if (!tables.contains (this->tabNameInvoices, Qt::CaseSensitivity::CaseInsensitive) ) {
+ if (!tables.contains (this->tabNameInvoices,
+ Qt::CaseSensitivity::CaseInsensitive) ) {
if (!q.exec (this->sqlCreateInvoiceTable) ) return q.lastError();
}
void DbConn::addService (const QString& name, const int& cost) const
{
QSqlQuery q;
- if (!q.prepare (this->sqlAddService) ) qCCritical (dbase) << "error while preparing: " << q.lastError();
+ if (!q.prepare (this->sqlAddService) )
+ qCCritical (dbase) << "error while preparing: " << q.lastError();
q.addBindValue (name );
q.addBindValue (cost );
if (!q.exec() ) qCCritical (dbase) << "error: " << q.lastError();
qCDebug (dbase) << "added new service " << name << ", costing " << cost;
}
}
-void DbConn::addCustomer (const QString& name, const QString& street, const QString& number,
- const QString& city, const uint8_t& zip) const
+void DbConn::addCustomer (const QString& name,
+ const QString& street, const QString& number,
+ const QString& city, const int& zip) const
{
QSqlQuery q;
- if (!q.prepare (this->sqlAddCustomer) ) qCCritical (dbase) << "error while preparing: " << q.lastError();
+ if (!q.prepare (this->sqlAddCustomer) )
+ qCCritical (dbase) << "error while preparing: " << q.lastError();
q.addBindValue (name );
q.addBindValue (street);
- q.addBindValue (number );
+ q.addBindValue (number);
q.addBindValue (city);
q.addBindValue (zip );
if (!q.exec() ) qCCritical (dbase) << "error: " << q.lastError();
<< street << " " << number << ", " << zip << " " << city;
}
}
-void DbConn::addOrder (const int& customerID, const QDate& date, const QList<int>& items) const
+void DbConn::addOrder (const int& customerID, const QDate& date,
+ const QList<int>& items) const
{
QSqlQuery q;
- if (!q.prepare (this->sqlAddOrder) ) qCCritical (dbase) << "error while preparing: " << q.lastError();
+ if (!q.prepare (this->sqlAddOrder) )
+ qCCritical (dbase) << "error while preparing: " << q.lastError();
q.addBindValue (customerID );
q.addBindValue (date );
else emit ordersChanged();
QVariant orderID = q.lastInsertId();
q.clear();
- if (!q.prepare (this->sqlAddOrderItem) ) qCCritical (dbase) << "error while preparing: " << q.lastError();
+ if (!q.prepare (this->sqlAddOrderItem) )
+ qCCritical (dbase) << "error while preparing: " << q.lastError();
QList<QVariant> orderIDList;
for (int i = 0; i < items.length(); i++) {
void DbConn::addInvoice (const QDate& date, const int& orderID) const
{
QSqlQuery q;
- if (!q.prepare (this->sqlAddInvoice) ) qCCritical (dbase) << "error while preparing: " << q.lastError();
+ if (!q.prepare (this->sqlAddInvoice) )
+ qCCritical (dbase) << "error while preparing: " << q.lastError();
q.addBindValue (date );
q.addBindValue (orderID );
if (!q.exec() ) qCCritical (dbase) << "error: " << q.lastError();
Q_OBJECT
QSqlDatabase db;
QSqlError initDB() const;
- const QLatin1String tabNameCustomers {"customers"};
+
+public:
+ explicit DbConn (QObject* parent = nullptr);
+
+signals:
+ void servicesChanged() const;
+ void customersChanged() const;
+ void ordersChanged() const;
+ void orderitemsChanged() const;
+ void invoicesChanged() const;
+
+public slots:
+ void addService (const QString& name, const int& cost) const;
+ void addCustomer (const QString& name,
+ const QString& street, const QString& number,
+ const QString& city, const int& zip) const;
+ void addOrder (const int& customerID, const QDate& date,
+ const QList<int>& items) const;
+ void addInvoice (const QDate& date, const int& OrderID) const;
+
+private:
+
+ const QLatin1String tabNameCustomers
+ {"customers"
+ };
const QLatin1String tabNameOrders {"orders"};
const QLatin1String tabNameOrderitems {"orderitems"};
const QLatin1String tabNameInvoices{"invoices"};
"id integer primary key autoincrement,"
"name text not null,"
"street text,"
- "number text"
+ "number text,"
"city text,"
"zip integer"
")"
" customers "
"(name, street, number, city, zip)"
" values "
- "(?,?,?,?,?)"
+ "(?, ?, ?, ?, ?)"
};
const QLatin1String sqlCreateServicesTable {
"create table services("
" values "
"(?,?)"
};
-public:
- explicit DbConn (QObject* parent = nullptr);
-
-signals:
- void servicesChanged() const;
- void customersChanged() const;
- void ordersChanged() const;
- void orderitemsChanged() const;
- void invoicesChanged() const;
-
-public slots:
- void addService (const QString& name, const int& cost) const;
- void addCustomer (const QString& name, const QString& street, const QString& number,
- const QString& city, const uint8_t& zip) const;
- void addOrder (const int& customerID, const QDate& date, const QList<int>& items) const;
- void addInvoice (const QDate& date, const int& OrderID) const;
};
#endif // DBCONN_H