wip
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
#include "Account.h"
|
||||
|
||||
|
||||
Account::~Account()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef ACCOUNT_H
|
||||
#define ACCOUNT_H
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <wx/wx.h>
|
||||
|
||||
class Account
|
||||
{
|
||||
public:
|
||||
~Account();
|
||||
|
||||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _number;
|
||||
int _amount;
|
||||
bool _shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -131,8 +131,8 @@ User* Database::LoadUser(wxString name)
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
User* user;
|
||||
Account* account;
|
||||
std::list<Account*>::iterator it;
|
||||
struct Account account;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
|
||||
req = _("SELECT * FROM user WHERE name='") + name + _("'");
|
||||
|
||||
@@ -155,25 +155,23 @@ User* Database::LoadUser(wxString name)
|
||||
|
||||
while (set.NextRow())
|
||||
{
|
||||
account = new Account();
|
||||
account->_id = set.GetAsString(_("id"));
|
||||
account->_name = set.GetAsString(_("name"));
|
||||
account->_number = set.GetAsString(_("number"));
|
||||
account->_amount = set.GetInt(_("amount"));
|
||||
account->_shared = set.GetBool(_("shared"));
|
||||
account->_default = set.GetBool(_("default_account"));
|
||||
user->_accounts.push_back(account);
|
||||
account.id = set.GetAsString(_("id"));
|
||||
account.name = set.GetAsString(_("name"));
|
||||
account.number = set.GetAsString(_("number"));
|
||||
account.shared = set.GetBool(_("shared"));
|
||||
account._default = set.GetBool(_("default_account"));
|
||||
user->_accounts[account.id] = account;
|
||||
}
|
||||
set.Finalize();
|
||||
|
||||
if (!user->_accounts.empty())
|
||||
{
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT DISTINCT year FROM operation WHERE account IN('") + (*it)->_id;
|
||||
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->first;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + (*it)->_id ;
|
||||
req += _("', '") + it->first ;
|
||||
}
|
||||
req += _("') ORDER BY year ASC");
|
||||
|
||||
@@ -186,6 +184,14 @@ User* Database::LoadUser(wxString name)
|
||||
set.Finalize();
|
||||
}
|
||||
|
||||
req = _("SELECT id, value FROM preference WHERE type='category' AND name='name' AND user='") + user->_id + _("' ORDER BY value ASC");
|
||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||
|
||||
while (set.NextRow())
|
||||
user->_preferences._categories[set.GetAsString(_("id"))] = set.GetAsString(_("value"));
|
||||
|
||||
set.Finalize();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -193,17 +199,17 @@ void Database::LoadYear(User* user, int year)
|
||||
{
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
std::list<Account*>::iterator it;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
|
||||
if (user->_operations[year] == NULL)
|
||||
user->_operations[year] = new std::map<unsigned int, std::list<operation> >();
|
||||
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + (*it)->_id;
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + it->first;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + (*it)->_id ;
|
||||
req += _("', '") + it->first ;
|
||||
}
|
||||
req += _("') ORDER BY fix_cost DESC, year,month,day ASC");
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Preferences
|
||||
{
|
||||
public:
|
||||
std::map<wxString, wxColour> _colors;
|
||||
std::list<wxString> _categories;
|
||||
std::map<wxString, wxString> _categories;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,12 +5,6 @@ User::~User()
|
||||
{
|
||||
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* >::iterator it;
|
||||
|
||||
while (!_accounts.empty())
|
||||
{
|
||||
delete _accounts.front();
|
||||
_accounts.pop_front();
|
||||
}
|
||||
|
||||
for (it = _operations.begin(); it != _operations.end(); it++)
|
||||
{
|
||||
if (_operations[it->first])
|
||||
@@ -19,3 +13,17 @@ User::~User()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString User::GetCategoryName(wxString catId)
|
||||
{
|
||||
if (_preferences._categories.find(catId) == _preferences._categories.end())
|
||||
return _("Unknown") ;
|
||||
return _preferences._categories[catId];
|
||||
}
|
||||
|
||||
wxString User::GetAccountName(wxString accountId)
|
||||
{
|
||||
if (_accounts.find(accountId) == _accounts.end())
|
||||
return _("Unknown") ;
|
||||
return _accounts[accountId].name;
|
||||
}
|
||||
|
||||
17
model/User.h
17
model/User.h
@@ -2,8 +2,7 @@
|
||||
#define USER_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "Account.h"
|
||||
#include <wx/wx.h>
|
||||
#include "Preferences.h"
|
||||
|
||||
struct operation {
|
||||
@@ -18,6 +17,15 @@ struct operation {
|
||||
wxString account;
|
||||
} ;
|
||||
|
||||
struct Account {
|
||||
wxString id;
|
||||
wxString name;
|
||||
wxString number;
|
||||
int amount;
|
||||
bool shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
class User
|
||||
{
|
||||
public:
|
||||
@@ -26,9 +34,12 @@ public:
|
||||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _password;
|
||||
std::list<Account*> _accounts;
|
||||
std::map<wxString, Account> _accounts;
|
||||
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* > _operations;
|
||||
Preferences _preferences;
|
||||
|
||||
wxString GetCategoryName(wxString catId);
|
||||
wxString GetAccountName(wxString accountId);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define MODEL_H
|
||||
|
||||
#include "User.h"
|
||||
#include "Account.h"
|
||||
#include "Preferences.h"
|
||||
#include "Database.h"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user