2010-05-14 15:04:01 +02:00
|
|
|
#include "KissCount.h"
|
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
KissCount::KissCount() : _user(NULL)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
|
|
|
_wxUI = new wxUI(this, _("KissCount"), wxPoint(50, 50), wxSize(1024, 768));
|
|
|
|
|
|
|
|
_wxUI->Show(true);
|
|
|
|
_wxUI->Centre();
|
|
|
|
_wxUI->Disable();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_db = new Database();
|
|
|
|
}
|
|
|
|
catch (std::string s)
|
|
|
|
{
|
|
|
|
_wxUI->Close(true);
|
|
|
|
throw s;
|
|
|
|
}
|
|
|
|
|
|
|
|
_wxUI->ChangeUser();
|
|
|
|
_wxUI->Enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
KissCount::~KissCount()
|
|
|
|
{
|
|
|
|
delete _db;
|
|
|
|
delete _wxUI;
|
2010-05-16 10:35:34 +02:00
|
|
|
if (_user) delete _user;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::list<wxString> KissCount::GetUsers()
|
|
|
|
{
|
|
|
|
return _db->GetUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KissCount::IsValidUser(wxString user, wxString password)
|
|
|
|
{
|
|
|
|
return _db->IsValidUser(user, password) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::LoadUser(wxString user)
|
|
|
|
{
|
2010-05-16 10:35:34 +02:00
|
|
|
if (_user) delete _user;
|
|
|
|
_user = _db->LoadUser(user) ;
|
2010-05-24 20:14:15 +02:00
|
|
|
if (_user)
|
|
|
|
_wxUI->LoadUser();
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-05-17 18:03:21 +02:00
|
|
|
void KissCount::LoadYear(int year, bool force)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
|
|
|
if (!force && _user->_operations[year] != NULL) return;
|
|
|
|
|
|
|
|
if (_user->_operations[year] != NULL)
|
|
|
|
{
|
|
|
|
delete _user->_operations[year];
|
|
|
|
}
|
|
|
|
|
|
|
|
_db->LoadYear(_user, year);
|
|
|
|
}
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
User* KissCount::GetUser()
|
|
|
|
{
|
|
|
|
return _user;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
|
|
|
|
double KissCount::GetAccountAmount(wxString id, int month, int year)
|
|
|
|
{
|
|
|
|
return _db->GetAccountAmount(id, month, year);
|
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
|
|
|
|
void KissCount::UpdateOperation(struct operation op)
|
|
|
|
{
|
|
|
|
_db->UpdateOperation(op);
|
|
|
|
}
|
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
wxString KissCount::AddOperation(struct operation op)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
return _db->AddOperation(_user, op);
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::DeleteOperation(struct operation op)
|
|
|
|
{
|
|
|
|
_db->DeleteOperation(op);
|
|
|
|
}
|
2010-06-12 15:59:27 +02:00
|
|
|
|
|
|
|
void KissCount::SetAccountAmount(int month, int year, wxString accountId, double amount)
|
|
|
|
{
|
|
|
|
_db->SetAccountAmount(month, year, accountId, amount);
|
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
void KissCount::AddAccount(struct Account ac)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
ac.id = _db->AddAccount(_user, ac);
|
|
|
|
_user->_accounts.push_back(ac);
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::UpdateAccount(struct Account ac)
|
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
int i;
|
|
|
|
|
2010-06-21 10:53:43 +02:00
|
|
|
_db->UpdateAccount(ac);
|
2010-06-21 13:02:02 +02:00
|
|
|
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
|
|
|
if (it->id == ac.id)
|
|
|
|
_user->_accounts[i] = ac;
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::DeleteAccount(struct Account ac)
|
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
int i;
|
|
|
|
|
2010-06-21 10:53:43 +02:00
|
|
|
_db->DeleteAccount(ac);
|
2010-06-21 13:02:02 +02:00
|
|
|
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
|
|
|
if (it->id == ac.id)
|
|
|
|
_user->_accounts.erase(_user->_accounts.begin()+i);
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
2010-06-22 11:35:21 +02:00
|
|
|
|
2010-06-22 12:29:36 +02:00
|
|
|
wxString KissCount::AddCategory(struct category category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2010-06-22 12:29:36 +02:00
|
|
|
return _db->AddCategory(_user, category);
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-06-22 12:29:36 +02:00
|
|
|
void KissCount::UpdateCategory(wxString oldName, struct category category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
|
|
|
wxString color;
|
|
|
|
color = _("#") ;
|
2010-06-22 12:29:36 +02:00
|
|
|
color += wxString::Format(_("%02X"), category.color.Red());
|
|
|
|
color += wxString::Format(_("%02X"), category.color.Green());
|
|
|
|
color += wxString::Format(_("%02X"), category.color.Blue());
|
2010-06-22 11:35:21 +02:00
|
|
|
|
2010-06-22 12:29:36 +02:00
|
|
|
_db->UpdateCategory(_user, oldName, category.name, color);
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-06-22 12:29:36 +02:00
|
|
|
void KissCount::DeleteCategory(struct category category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2010-06-22 12:29:36 +02:00
|
|
|
_db->DeleteCategory(_user, category);
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|