-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.h
More file actions
70 lines (60 loc) · 2.1 KB
/
Copy pathdatabase.h
File metadata and controls
70 lines (60 loc) · 2.1 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef DATABASE_H
#define DATABASE_H
#include <QtSql>
class DataBase
{
public:
enum EScoreFlags
{
eNone = 0,
eIncoming = 0x01, // Доходы - зарплаты, планируемые доходы и т.д.
eSpending = 0x02, // Расходы
eActive = 0x04, // Активы - наличные, карты и пр.
ePassive = 0x08, // Пассивы - кредиты, долги и пр.
};
struct SScore
{
SScore() : id(-1), parent_id(-1), flags(eNone) {}
QString name;
qint64 id;
qint64 parent_id;
quint64 flags;
std::list<SScore> child;
QDate added;
QDate removed;
};
struct STransaction
{
STransaction() : score_id(-1), id(-1) {}
QString desc;
qint64 score_id;
qint64 id;
QString balance;
QDate date;
};
DataBase();
SScore scores();
bool setScore(const SScore& score, bool replace = false);
bool setScore(const QString& name, qint64 parent_id = -1, quint64 flags = eNone, const std::list<SScore>& childs = std::list<SScore>(), bool replace = false);
bool renameScore(const QString& old_name, const QString& new_name);
bool removeScore(qint64 id);
std::list<STransaction> transacts(int year = -1, int month = -1, qint64 score_id = -1);
bool setTransaction(const STransaction& tr, bool replace = false);
bool setTransaction(const QDate& date, qint64 score_id, QString balance = QString(), QString desc = QString(), bool replace = false);
bool removeTransaction(qint64 id);
bool removeTransaction(const QDate& date, qint64 score_id);
bool moveTransaction(const QDate& old_date, qint64 old_score_id, const QDate& new_date, qint64 new_score_id);
static DataBase& inst()
{
static DataBase d;
return d;
}
private:
bool _recRemoveScore(qint64 id);
void _init();
void _createTables(const QString& connection);
void _clearMemoryCache();
QStringList _dbDump();
void _memory_cache();
};
#endif // DATABASE_H