-
Notifications
You must be signed in to change notification settings - Fork 0
/
income.cpp
55 lines (46 loc) · 1.13 KB
/
income.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Income.h"
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
Income::Income(const QDate &date, const QString &title, double amount, const QString &description)
{
m_date = date;
m_title = title;
m_amount = amount;
m_description = description;
}
bool Income::addToDatabase(QSqlDatabase &db)
{
if (!db.isOpen()) {
qDebug() << "Database is not open";
return false;
}
QSqlQuery query;
query.prepare("INSERT INTO incomes (date, title, amount, description) "
"VALUES (:date, :title, :amount, :description)");
query.bindValue(":date", m_date);
query.bindValue(":title", m_title);
query.bindValue(":amount", m_amount);
query.bindValue(":description", m_description);
if (!query.exec()) {
qDebug() << "Error adding income to database:" << query.lastError();
return false;
}
return true;
}
QDate Income::getDate() const
{
return m_date;
}
QString Income::getTitle() const
{
return m_title;
}
double Income::getAmount() const
{
return m_amount;
}
QString Income::getDescription() const
{
return m_description;
}