Passes re

This commit is contained in:
Grégory Soutadé 2010-07-05 18:35:12 +02:00
parent dfe81f2b03
commit 4544a5c3ad
6 changed files with 80 additions and 80 deletions

View File

@ -36,12 +36,12 @@ std::list<wxString> KissCount::GetUsers()
return _db->GetUsers(); return _db->GetUsers();
} }
bool KissCount::IsValidUser(wxString user, wxString password) bool KissCount::IsValidUser(const wxString& user, const wxString& password)
{ {
return _db->IsValidUser(user, password) ; return _db->IsValidUser(user, password) ;
} }
void KissCount::LoadUser(wxString user) void KissCount::LoadUser(const wxString& user)
{ {
if (_user) delete _user; if (_user) delete _user;
_user = _db->LoadUser(user) ; _user = _db->LoadUser(user) ;
@ -66,22 +66,22 @@ User* KissCount::GetUser()
return _user; return _user;
} }
double KissCount::GetAccountAmount(wxString id, int month, int year) double KissCount::GetAccountAmount(const wxString& id, int month, int year)
{ {
return _db->GetAccountAmount(id, month, year); return _db->GetAccountAmount(id, month, year);
} }
void KissCount::UpdateOperation(Operation op) void KissCount::UpdateOperation(Operation& op)
{ {
_db->UpdateOperation(op); _db->UpdateOperation(op);
} }
wxString KissCount::AddOperation(Operation op) wxString KissCount::AddOperation(Operation& op)
{ {
return _db->AddOperation(_user, op); return _db->AddOperation(_user, op);
} }
void KissCount::DeleteOperation(Operation op) void KissCount::DeleteOperation(Operation& op)
{ {
_db->DeleteOperation(op); _db->DeleteOperation(op);
} }
@ -99,12 +99,12 @@ void KissCount::DeleteOperations(int month, int year)
} }
} }
void KissCount::SetAccountAmount(int month, int year, wxString accountId, double amount) void KissCount::SetAccountAmount(int month, int year, const wxString& accountId, double amount)
{ {
_db->SetAccountAmount(month, year, accountId, amount); _db->SetAccountAmount(month, year, accountId, amount);
} }
wxString KissCount::AddAccount(Account ac) wxString KissCount::AddAccount(Account& ac)
{ {
ac.id = _db->AddAccount(_user, ac); ac.id = _db->AddAccount(_user, ac);
_user->_accounts.push_back(ac); _user->_accounts.push_back(ac);
@ -112,7 +112,7 @@ wxString KissCount::AddAccount(Account ac)
return ac.id; return ac.id;
} }
void KissCount::UpdateAccount(Account ac) void KissCount::UpdateAccount(Account& ac)
{ {
std::vector<Account>::iterator it; std::vector<Account>::iterator it;
int i; int i;
@ -123,7 +123,7 @@ void KissCount::UpdateAccount(Account ac)
_user->_accounts[i] = ac; _user->_accounts[i] = ac;
} }
void KissCount::DeleteAccount(Account ac) void KissCount::DeleteAccount(Account& ac)
{ {
std::vector<Account>::iterator it; std::vector<Account>::iterator it;
int i; int i;
@ -137,7 +137,7 @@ void KissCount::DeleteAccount(Account ac)
} }
} }
wxString KissCount::AddCategory(Category category) wxString KissCount::AddCategory(Category& category)
{ {
wxString id; wxString id;
id = _db->AddCategory(_user, category); id = _db->AddCategory(_user, category);
@ -148,7 +148,7 @@ wxString KissCount::AddCategory(Category category)
return id; return id;
} }
void KissCount::UpdateCategory(Category category) void KissCount::UpdateCategory(Category& category)
{ {
_db->UpdateCategory(category); _db->UpdateCategory(category);
@ -160,7 +160,7 @@ void KissCount::UpdateCategory(Category category)
} }
} }
void KissCount::DeleteCategory(Category category) void KissCount::DeleteCategory(Category& category)
{ {
_db->DeleteCategory(_user, category); _db->DeleteCategory(_user, category);
@ -206,23 +206,23 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year
_wxUI->GenerateMonth(monthTo, yearTo); _wxUI->GenerateMonth(monthTo, yearTo);
} }
void KissCount::ChangePassword(wxString password) void KissCount::ChangePassword(const wxString& password)
{ {
_db->ChangePassword(_user, password); _db->ChangePassword(_user, password);
} }
bool KissCount::UserExists(wxString name) bool KissCount::UserExists(const wxString& name)
{ {
return _db->UserExists(name); return _db->UserExists(name);
} }
void KissCount::ChangeName(wxString name) void KissCount::ChangeName(const wxString& name)
{ {
_db->ChangeName(_user, name); _db->ChangeName(_user, name);
_user->_name = name; _user->_name = name;
} }
void KissCount::NewUser(wxString name) void KissCount::NewUser(const wxString& name)
{ {
wxDateTime curDate; wxDateTime curDate;
Account ac = {wxT(""), wxT("Account 1"), wxT(""), false, true}; Account ac = {wxT(""), wxT("Account 1"), wxT(""), false, true};

View File

@ -16,30 +16,30 @@ class KissCount
~KissCount(); ~KissCount();
std::list<wxString> GetUsers(); std::list<wxString> GetUsers();
bool IsValidUser(wxString user, wxString password); bool IsValidUser(const wxString& user, const wxString& password);
void LoadUser(wxString user); void LoadUser(const wxString& user);
User* GetUser(); User* GetUser();
void ChangePassword(wxString password); void ChangePassword(const wxString& password);
bool UserExists(wxString name); bool UserExists(const wxString& name);
void ChangeName(wxString name); void ChangeName(const wxString& name);
void NewUser(wxString name); void NewUser(const wxString& name);
void LoadYear(int year, bool force=false); void LoadYear(int year, bool force=false);
wxString AddOperation(Operation op); wxString AddOperation(Operation& op);
void UpdateOperation(Operation op); void UpdateOperation(Operation& op);
void DeleteOperation(Operation op); void DeleteOperation(Operation& op);
void DeleteOperations(int month, int year); void DeleteOperations(int month, int year);
double GetAccountAmount(wxString id, int month, int year); double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(int month, int year, wxString accountId, double value); void SetAccountAmount(int month, int year, const wxString& accountId, double value);
wxString AddAccount(Account ac); wxString AddAccount(Account& ac);
void UpdateAccount(Account ac); void UpdateAccount(Account& ac);
void DeleteAccount(Account ac); void DeleteAccount(Account& ac);
wxString AddCategory(Category category); wxString AddCategory(Category& category);
void UpdateCategory(Category category); void UpdateCategory(Category& category);
void DeleteCategory(Category category); void DeleteCategory(Category& category);
std::map<int, std::vector<int> > GetAllOperations(); std::map<int, std::vector<int> > GetAllOperations();

View File

@ -113,7 +113,7 @@ void Database::CreateDatabase()
} }
wxString Database::HashPassword(wxString password) wxString Database::HashPassword(const wxString& password)
{ {
blk_SHA_CTX sha_ctx; blk_SHA_CTX sha_ctx;
unsigned char sha[20]; unsigned char sha[20];
@ -148,7 +148,7 @@ std::list<wxString> Database::GetUsers()
return res; return res;
} }
bool Database::IsValidUser(wxString user, wxString password) bool Database::IsValidUser(const wxString& user, const wxString& password)
{ {
bool res; bool res;
wxString req; wxString req;
@ -164,7 +164,7 @@ bool Database::IsValidUser(wxString user, wxString password)
return res; return res;
} }
User* Database::LoadUser(wxString name) User* Database::LoadUser(const wxString& name)
{ {
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
wxString req; wxString req;
@ -299,7 +299,7 @@ void Database::LoadYear(User* user, int year)
set.Finalize(); set.Finalize();
} }
double Database::GetAccountAmount(wxString id, int month, int year) double Database::GetAccountAmount(const wxString& id, int month, int year)
{ {
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
wxString req; wxString req;
@ -325,7 +325,7 @@ double Database::GetAccountAmount(wxString id, int month, int year)
return res; return res;
} }
void Database::UpdateOperation(Operation op) void Database::UpdateOperation(Operation& op)
{ {
wxString req; wxString req;
req = wxT("UPDATE operation SET ") ; req = wxT("UPDATE operation SET ") ;
@ -345,7 +345,7 @@ void Database::UpdateOperation(Operation op)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
wxString Database::AddOperation(User* user, Operation op) wxString Database::AddOperation(User* user, Operation& op)
{ {
wxString req, res; wxString req, res;
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
@ -394,7 +394,7 @@ wxString Database::AddOperation(User* user, Operation op)
return res; return res;
} }
void Database::DeleteOperation(Operation op) void Database::DeleteOperation(Operation& op)
{ {
wxString req; wxString req;
req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'"); req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'");
@ -438,7 +438,7 @@ void Database::DeleteOperations(User* user, int month, int year)
} }
void Database::SetAccountAmount(int month, int year, wxString accountId, double amount) void Database::SetAccountAmount(int month, int year, const wxString& accountId, double amount)
{ {
wxString req; wxString req;
req = wxT("UPDATE account_amount SET ") ; req = wxT("UPDATE account_amount SET ") ;
@ -468,7 +468,7 @@ void Database::SetAccountAmount(int month, int year, wxString accountId, double
} }
} }
wxString Database::AddAccount(User* user, Account ac) wxString Database::AddAccount(User* user, Account& ac)
{ {
wxString req, res; wxString req, res;
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
@ -504,7 +504,7 @@ wxString Database::AddAccount(User* user, Account ac)
return res; return res;
} }
void Database::UpdateAccount(Account ac) void Database::UpdateAccount(Account& ac)
{ {
wxString req; wxString req;
req = wxT("UPDATE account SET ") ; req = wxT("UPDATE account SET ") ;
@ -523,7 +523,7 @@ void Database::UpdateAccount(Account ac)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
void Database::DeleteAccount(Account ac) void Database::DeleteAccount(Account& ac)
{ {
wxString req; wxString req;
req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'"); req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'");
@ -531,7 +531,7 @@ void Database::DeleteAccount(Account ac)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
wxString Database::AddCategory(User* user, Category category) wxString Database::AddCategory(User* user, Category& category)
{ {
wxString req, res; wxString req, res;
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
@ -567,7 +567,7 @@ wxString Database::AddCategory(User* user, Category category)
return res; return res;
} }
void Database::UpdateCategory(Category category) void Database::UpdateCategory(Category& category)
{ {
wxString req; wxString req;
wxString color; wxString color;
@ -587,7 +587,7 @@ void Database::UpdateCategory(Category category)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
void Database::DeleteCategory(User* user, Category category) void Database::DeleteCategory(User* user, Category& category)
{ {
wxString req; wxString req;
@ -733,7 +733,7 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT
} }
} }
void Database::ChangePassword(User* user, wxString password) void Database::ChangePassword(User* user, const wxString& password)
{ {
wxString req; wxString req;
@ -744,7 +744,7 @@ void Database::ChangePassword(User* user, wxString password)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
bool Database::UserExists(wxString name) bool Database::UserExists(const wxString& name)
{ {
wxSQLite3ResultSet set; wxSQLite3ResultSet set;
wxString req; wxString req;
@ -764,7 +764,7 @@ bool Database::UserExists(wxString name)
return res; return res;
} }
void Database::ChangeName(User* user, wxString name) void Database::ChangeName(User* user, const wxString& name)
{ {
wxString req; wxString req;
@ -775,7 +775,7 @@ void Database::ChangeName(User* user, wxString name)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
void Database::NewUser(wxString name) void Database::NewUser(const wxString& name)
{ {
wxString req, id; wxString req, id;
wxSQLite3ResultSet set; wxSQLite3ResultSet set;

View File

@ -19,40 +19,40 @@ class Database
Database(); Database();
std::list<wxString> GetUsers(); std::list<wxString> GetUsers();
bool IsValidUser(wxString user, wxString password); bool IsValidUser(const wxString& user, const wxString& password);
User* LoadUser(wxString name); User* LoadUser(const wxString& name);
void LoadYear(User* user, int year); void LoadYear(User* user, int year);
void UpdateOperation(Operation op); void UpdateOperation(Operation& op);
wxString AddOperation(User* user, Operation op); wxString AddOperation(User* user, Operation& op);
void DeleteOperation(Operation op); void DeleteOperation(Operation& op);
void DeleteOperations(User* user, int month, int year); void DeleteOperations(User* user, int month, int year);
double GetAccountAmount(wxString id, int month, int year); double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(int month, int year, wxString accountId, double amount); void SetAccountAmount(int month, int year, const wxString& accountId, double amount);
wxString AddAccount(User* user, Account ac); wxString AddAccount(User* user, Account& ac);
void UpdateAccount(Account ac); void UpdateAccount(Account& ac);
void DeleteAccount(Account ac); void DeleteAccount(Account& ac);
wxString AddCategory(User* user, Category category); wxString AddCategory(User* user, Category& category);
void UpdateCategory(Category category); void UpdateCategory(Category& category);
void DeleteCategory(User* user, Category category); void DeleteCategory(User* user, Category& category);
std::map<int, std::vector<int> > GetAllOperations(User* user); std::map<int, std::vector<int> > GetAllOperations(User* user);
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo); void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
void ChangePassword(User* user, wxString password); void ChangePassword(User* user, const wxString& password);
bool UserExists(wxString name); bool UserExists(const wxString& name);
void ChangeName(User* user, wxString name); void ChangeName(User* user, const wxString& name);
void NewUser(wxString name); void NewUser(const wxString& name);
void KillMe(User* user); void KillMe(User* user);
private: private:
wxSQLite3Database _db; wxSQLite3Database _db;
void CreateDatabase(); void CreateDatabase();
wxString HashPassword(wxString password); wxString HashPassword(const wxString& password);
}; };
#endif #endif

View File

@ -13,7 +13,7 @@ User::~User()
} }
} }
Category User::GetCategory(wxString catId) Category User::GetCategory(wxString& catId)
{ {
Category cat; Category cat;
std::vector<Category>::iterator it; std::vector<Category>::iterator it;
@ -31,7 +31,7 @@ Category User::GetCategory(wxString catId)
return cat; return cat;
} }
wxString User::GetCategoryName(wxString catId) wxString User::GetCategoryName(wxString& catId)
{ {
std::vector<Category>::iterator it; std::vector<Category>::iterator it;
for (it=_categories.begin(); it !=_categories.end(); it++) for (it=_categories.begin(); it !=_categories.end(); it++)
@ -41,7 +41,7 @@ wxString User::GetCategoryName(wxString catId)
return _("Unknown") ; return _("Unknown") ;
} }
wxString User::GetCategoryId(wxString catName) wxString User::GetCategoryId(wxString& catName)
{ {
std::vector<Category>::iterator it; std::vector<Category>::iterator it;
for (it=_categories.begin(); it !=_categories.end(); it++) for (it=_categories.begin(); it !=_categories.end(); it++)
@ -51,7 +51,7 @@ wxString User::GetCategoryId(wxString catName)
return wxT("0") ; return wxT("0") ;
} }
wxString User::GetAccountName(wxString accountId) wxString User::GetAccountName(wxString& accountId)
{ {
std::vector<Account>::iterator it; std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++) for (it=_accounts.begin(); it !=_accounts.end(); it++)
@ -61,7 +61,7 @@ wxString User::GetAccountName(wxString accountId)
return _("Unknown") ; return _("Unknown") ;
} }
wxString User::GetAccountId(wxString accountName) wxString User::GetAccountId(wxString& accountName)
{ {
std::vector<Account>::iterator it; std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++) for (it=_accounts.begin(); it !=_accounts.end(); it++)

View File

@ -23,11 +23,11 @@ class User
std::vector<Category> _categories; std::vector<Category> _categories;
std::map<wxString, wxString> _preferences; std::map<wxString, wxString> _preferences;
Category GetCategory(wxString catId); Category GetCategory(wxString& catId);
wxString GetCategoryName(wxString catId); wxString GetCategoryName(wxString& catId);
wxString GetCategoryId(wxString catName); wxString GetCategoryId(wxString& catName);
wxString GetAccountName(wxString accountId); wxString GetAccountName(wxString& accountId);
wxString GetAccountId(wxString accountName); wxString GetAccountId(wxString& accountName);
int GetCategoriesNumber(); int GetCategoriesNumber();
int GetAccountsNumber(); int GetAccountsNumber();
int GetOperationsNumber(int month, int year); int GetOperationsNumber(int month, int year);