-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.h
116 lines (97 loc) · 3.34 KB
/
database.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef DATABASE_H
#define DATABASE_H
#include <QObject>
#include <QSql>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlDatabase>
#include <QFile>
#include <QDate>
#include <QDebug>
#include <ctime>
#define DATABASE_HOSTNAME "UsersDataBase"
#define DATABASE_NAME "users.sql"
#define TABLE "Users"
#define TABLE_LOGIN "Login"
#define TABLE_PSSWD "Password"
#define DATABASE_HOSTNAME_WEATHER "WeatherDataBase"
#define DATABASE_WEATHER_NAME "weather.sql"
#define TABLE_WEATHER "Weather"
#define TABLE_WEEKDAY "Weekday"
#define TABLE_DATE "Date_"
#define TABLE_MONTH "Month"
#define TABLE_LABEL "Label"
#define TABLE_TEMPERATURE "Temperature"
class DataBase : public QObject
{
Q_OBJECT
public:
explicit DataBase(QObject *parent = 0);
virtual ~DataBase();
bool createMainTable();
void connectToDataBase();
bool insertIntoMainTable(const QVariantList &data);
bool insertIntoMainTableWithID(const QVariantList &data);
bool insertIntoMainTableWithKnownID(const QVariantList &data, int ID);
bool checkingForRecord(QString login);
bool checkingForID(int ID);
bool comparisonMethodIDWithLogin(int ID, QString login);
void deleteUserByID(int ID);
void deleteUserByLogin(QString login);
void deleteUserByIDAndLogin(int ID, QString login);
QString checkingForRecordReturningPsswd(QString login);
int checkUsersDataBaseCountOfRecords();
bool checkingForIDInWeatherDB(int ID);
bool checkingForWeekdayInWeatherDB(QString weekday);
bool insertIntoWeatherTable(const QVariantList &data);
bool insertIntoWeatherTableWithID(const QVariantList &data, int ID);
bool insertIntoWeatherTableWithKnownID(const QVariantList &data, int ID);
bool openWeatherDataBase();
bool createWeatherTable();
bool restoreWeatherDataBase();
void connectToWeatherDataBase();
void deleteWeatherRecordByID(int ID);
void deleteAllWeatherRecords();
void modifyWeatherRecordWithID(const QVariantList &data, int ID);
int checkWeatherDataBaseCountOfRecords();
int checkWeatherDataBaseCountOfWeekdayRecords(QString weekday);
void backupDataFromWeatherDB();
void undoMethod();
void searchByID(int ID);
void searchByWeekday(QString weekday);
void searchByDate(QString date);
void searchByMonth(QString month);
void closeDataBase();
void closeWeatherDataBase();
void setSaved(QVariantList savedData);
QVariantList getSaved();
private:
QSqlDatabase db;
QSqlDatabase weather_db;
private:
bool openDataBase();
bool restoreDataBase();
};
class DataBaseReadMethods : public DataBase{
Q_OBJECT
public:
explicit DataBaseReadMethods(QObject *parent = 0);
virtual ~DataBaseReadMethods();
QVariantList readDataFromWeatherSqlFileToQVariantList();
QVariantList readDataFromUsersSqlFileToQVariantList();
QVariantList readWeekdayFromWeatherSqlFileToQVariantList(QString weekday);
QVariantList readDateFromWeatherSqlFileToQVariantList(QString date);
QVariantList readMonthFromWeatherSqlFileToQVariantList(QString month);
};
class SortMethods : public DataBaseReadMethods{
Q_OBJECT
public:
explicit SortMethods(QObject *parent = 0);
virtual ~SortMethods();
void sortingByWeekday();
void sortingByDate();
void sortingByMonth();
void sortingByGeneralCharacteristics();
void sortingByTemperature();
};
#endif // DATABASE_H