Lot of user management code

This commit is contained in:
2010-06-27 21:39:49 +02:00
parent e72e36f27d
commit ceaf9a836e
16 changed files with 449 additions and 70 deletions

View File

@@ -132,23 +132,45 @@ void KissCount::DeleteAccount(struct Account ac)
wxString KissCount::AddCategory(struct category category)
{
return _db->AddCategory(_user, category);
wxString id;
id = _db->AddCategory(_user, category);
category.id = id;
_user->_preferences._categories.push_back(category);
return id;
}
void KissCount::UpdateCategory(wxString oldName, struct category category)
{
wxString color;
std::vector<struct category>::iterator it;
color = _("#") ;
color += wxString::Format(_("%02X"), category.color.Red());
color += wxString::Format(_("%02X"), category.color.Green());
color += wxString::Format(_("%02X"), category.color.Blue());
_db->UpdateCategory(_user, oldName, category.name, color);
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
if (_user->_preferences._categories[i].name == oldName)
{
_user->_preferences._categories[i] = category;
break;
}
}
void KissCount::DeleteCategory(struct category category)
{
_db->DeleteCategory(_user, category);
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
if (_user->_preferences._categories[i].name == category.name)
{
_user->_preferences._categories.erase(_user->_preferences._categories.begin()+i);
break;
}
}
std::map<int, std::vector<int> > KissCount::GetAllOperations()
@@ -184,3 +206,44 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year
}
_wxUI->GenerateMonth(monthTo, yearTo);
}
void KissCount::ChangePassword(wxString password)
{
_db->ChangePassword(_user, password);
}
bool KissCount::UserExists(wxString name)
{
return _db->UserExists(name);
}
void KissCount::ChangeName(wxString name)
{
_db->ChangeName(_user, name);
_user->_name = name;
}
void KissCount::NewUser(wxString name)
{
wxDateTime curDate;
struct Account ac = {_(""), _("Account 1"), _(""), false, true};
_db->NewUser(name);
if (_user) delete _user;
_user = _db->LoadUser(name) ;
curDate.SetToCurrent();
AddAccount(ac);
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
}
void KissCount::KillMe()
{
_wxUI->KillMe();
_db->KillMe(_user);
delete _user;
_user = NULL;
_wxUI->ChangeUser();
}

View File

@@ -19,6 +19,10 @@ class KissCount
bool IsValidUser(wxString user, wxString password);
void LoadUser(wxString user);
User* GetUser();
void ChangePassword(wxString password);
bool UserExists(wxString name);
void ChangeName(wxString name);
void NewUser(wxString name);
void LoadYear(int year, bool force=false);
@@ -40,6 +44,7 @@ class KissCount
std::map<int, std::vector<int> > GetAllOperations();
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
void KillMe();
private:
wxUI* _wxUI;
Database* _db;