2010-07-10 16:34:30 +02:00
|
|
|
/*
|
2010-08-26 21:28:15 +02:00
|
|
|
Copyright 2010 Grégory Soutadé
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-10 16:34:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
|
2010-05-15 11:21:42 +02:00
|
|
|
#include <stdio.h>
|
2010-05-14 15:04:01 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <list>
|
|
|
|
#include <wx/wxsqlite3.h>
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <sha1.h>
|
|
|
|
|
2010-05-15 11:21:42 +02:00
|
|
|
#include "model.h"
|
2010-09-08 11:02:03 +02:00
|
|
|
#include "../controller/KissCount.h"
|
2010-05-15 11:21:42 +02:00
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
#define BDD_FILE "kc.bdd"
|
|
|
|
#define INIT_SCRIPT "init.sql"
|
|
|
|
|
2010-09-08 11:02:03 +02:00
|
|
|
class KissCount;
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
class Database
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
public:
|
2010-09-08 11:02:03 +02:00
|
|
|
Database(const char* filename, KissCount* kiss);
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
std::list<wxString> GetUsers();
|
|
|
|
bool IsValidUser(const wxString& user, const wxString& password);
|
2010-05-15 11:21:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
User* LoadUser(const wxString& name);
|
|
|
|
void LoadYear(User* user, int year);
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void UpdateOperation(Operation& op);
|
|
|
|
wxString AddOperation(User* user, Operation& op);
|
|
|
|
void DeleteOperation(Operation& op);
|
|
|
|
void DeleteOperations(User* user, int month, int year);
|
|
|
|
double GetAccountAmount(const wxString& id, int month, int year);
|
|
|
|
void SetAccountAmount(int month, int year, const wxString& accountId, double amount);
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString AddAccount(User* user, Account& ac);
|
|
|
|
void UpdateAccount(Account& ac);
|
2010-10-20 20:54:23 +02:00
|
|
|
void DeleteAccount(User* user, Account& ac);
|
|
|
|
void AddSharedAccount(Account& ac, const wxString& granted);
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString AddCategory(User* user, Category& category);
|
|
|
|
void UpdateCategory(Category& category);
|
|
|
|
void DeleteCategory(User* user, Category& category);
|
2010-06-22 11:35:21 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
|
|
|
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
2010-06-23 14:25:00 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void ChangePassword(User* user, const wxString& password);
|
|
|
|
bool UserExists(const wxString& name);
|
|
|
|
void ChangeName(User* user, const wxString& name);
|
|
|
|
void NewUser(const wxString& name);
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void UpdatePreference(User* user, const wxString& preference);
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
|
|
|
wxString* amountFrom, wxString* amountTo,
|
2010-08-29 09:29:34 +02:00
|
|
|
std::vector<wxString> categories, std::vector<wxString> accounts, bool wildcards);
|
2010-08-17 18:59:19 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
|
|
|
|
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
|
|
|
std::map<wxString, double>* categories);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void KillMe(User* user);
|
|
|
|
bool GetOperation(const wxString& id, Operation* op);
|
|
|
|
std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
|
2010-08-21 11:49:03 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
private:
|
2010-09-08 11:02:03 +02:00
|
|
|
KissCount* _kiss;
|
2010-08-26 21:28:15 +02:00
|
|
|
wxSQLite3Database _db;
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
void CreateDatabase();
|
|
|
|
wxString HashPassword(const wxString& password);
|
|
|
|
void LinkOrUnlinkOperation(Operation& op);
|
2010-05-14 15:04:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|