Change structures into class
This commit is contained in:
@@ -169,10 +169,10 @@ User* Database::LoadUser(wxString name)
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
User* user;
|
||||
struct account account;
|
||||
struct category category;
|
||||
Account account;
|
||||
Category category;
|
||||
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
req = wxT("SELECT * FROM user WHERE name='") + name + wxT("'");
|
||||
|
||||
@@ -259,10 +259,10 @@ void Database::LoadYear(User* user, int year)
|
||||
{
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
if (user->_operations[year] == NULL)
|
||||
user->_operations[year] = new std::map<unsigned int, std::vector<operation> >();
|
||||
user->_operations[year] = new std::map<unsigned int, std::vector<Operation> >();
|
||||
|
||||
if (!user->_accounts.size()) return;
|
||||
|
||||
@@ -282,7 +282,7 @@ void Database::LoadYear(User* user, int year)
|
||||
|
||||
while (set.NextRow())
|
||||
{
|
||||
operation op;
|
||||
Operation op;
|
||||
op.id = set.GetAsString(wxT("id"));
|
||||
op.account = set.GetAsString(wxT("account"));
|
||||
op.day = set.GetInt(wxT("day"));
|
||||
@@ -325,7 +325,7 @@ double Database::GetAccountAmount(wxString id, int month, int year)
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::UpdateOperation(struct operation op)
|
||||
void Database::UpdateOperation(Operation op)
|
||||
{
|
||||
wxString req;
|
||||
req = wxT("UPDATE operation SET ") ;
|
||||
@@ -347,7 +347,7 @@ void Database::UpdateOperation(struct operation op)
|
||||
|
||||
}
|
||||
|
||||
wxString Database::AddOperation(User* user, struct operation op)
|
||||
wxString Database::AddOperation(User* user, Operation op)
|
||||
{
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
@@ -396,7 +396,7 @@ wxString Database::AddOperation(User* user, struct operation op)
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::DeleteOperation(struct operation op)
|
||||
void Database::DeleteOperation(Operation op)
|
||||
{
|
||||
wxString req;
|
||||
req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'");
|
||||
@@ -407,7 +407,7 @@ void Database::DeleteOperation(struct operation op)
|
||||
void Database::DeleteOperations(User* user, int month, int year)
|
||||
{
|
||||
wxString req;
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
it = user->_accounts.begin();
|
||||
req = wxT("DELETE FROM account_amount WHERE account IN('") + it->id;
|
||||
@@ -470,7 +470,7 @@ void Database::SetAccountAmount(int month, int year, wxString accountId, double
|
||||
}
|
||||
}
|
||||
|
||||
wxString Database::AddAccount(User* user, struct account ac)
|
||||
wxString Database::AddAccount(User* user, Account ac)
|
||||
{
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
@@ -506,7 +506,7 @@ wxString Database::AddAccount(User* user, struct account ac)
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::UpdateAccount(struct account ac)
|
||||
void Database::UpdateAccount(Account ac)
|
||||
{
|
||||
wxString req;
|
||||
req = wxT("UPDATE account SET ") ;
|
||||
@@ -525,7 +525,7 @@ void Database::UpdateAccount(struct account ac)
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
void Database::DeleteAccount(struct account ac)
|
||||
void Database::DeleteAccount(Account ac)
|
||||
{
|
||||
wxString req;
|
||||
req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'");
|
||||
@@ -533,7 +533,7 @@ void Database::DeleteAccount(struct account ac)
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
wxString Database::AddCategory(User* user, struct category category)
|
||||
wxString Database::AddCategory(User* user, Category category)
|
||||
{
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
@@ -569,7 +569,7 @@ wxString Database::AddCategory(User* user, struct category category)
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::UpdateCategory(struct category category)
|
||||
void Database::UpdateCategory(Category category)
|
||||
{
|
||||
wxString req;
|
||||
wxString color;
|
||||
@@ -589,7 +589,7 @@ void Database::UpdateCategory(struct category category)
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
void Database::DeleteCategory(User* user, struct category category)
|
||||
void Database::DeleteCategory(User* user, Category category)
|
||||
{
|
||||
wxString req;
|
||||
|
||||
@@ -608,7 +608,7 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||
{
|
||||
wxString req;
|
||||
wxSQLite3ResultSet set, set2;
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
std::map<int, std::vector<int> > res;
|
||||
int year;
|
||||
|
||||
@@ -659,7 +659,7 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||
|
||||
void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo)
|
||||
{
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
wxString req;
|
||||
wxSQLite3ResultSet set;
|
||||
double amount;
|
||||
@@ -823,7 +823,7 @@ void Database::NewUser(wxString name)
|
||||
void Database::KillMe(User* user)
|
||||
{
|
||||
wxString req;
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
req = wxT("DELETE FROM preference WHERE user='") + user->_id + wxT("'");
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
|
||||
@@ -24,20 +24,20 @@ class Database
|
||||
User* LoadUser(wxString name);
|
||||
void LoadYear(User* user, int year);
|
||||
|
||||
void UpdateOperation(struct operation op);
|
||||
wxString AddOperation(User* user, struct operation op);
|
||||
void DeleteOperation(struct operation op);
|
||||
void UpdateOperation(Operation op);
|
||||
wxString AddOperation(User* user, Operation op);
|
||||
void DeleteOperation(Operation op);
|
||||
void DeleteOperations(User* user, int month, int year);
|
||||
double GetAccountAmount(wxString id, int month, int year);
|
||||
void SetAccountAmount(int month, int year, wxString accountId, double amount);
|
||||
|
||||
wxString AddAccount(User* user, struct account ac);
|
||||
void UpdateAccount(struct account ac);
|
||||
void DeleteAccount(struct account ac);
|
||||
wxString AddAccount(User* user, Account ac);
|
||||
void UpdateAccount(Account ac);
|
||||
void DeleteAccount(Account ac);
|
||||
|
||||
wxString AddCategory(User* user, struct category category);
|
||||
void UpdateCategory(struct category category);
|
||||
void DeleteCategory(User* user, struct category category);
|
||||
wxString AddCategory(User* user, Category category);
|
||||
void UpdateCategory(Category category);
|
||||
void DeleteCategory(User* user, Category category);
|
||||
|
||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
User::~User()
|
||||
{
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* >::iterator it;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
|
||||
|
||||
for (it = _operations.begin(); it != _operations.end(); it++)
|
||||
{
|
||||
@@ -14,10 +14,10 @@ User::~User()
|
||||
}
|
||||
}
|
||||
|
||||
struct category User::GetCategory(wxString catId)
|
||||
Category User::GetCategory(wxString catId)
|
||||
{
|
||||
struct category cat;
|
||||
std::vector<category>::iterator it;
|
||||
Category cat;
|
||||
std::vector<Category>::iterator it;
|
||||
|
||||
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||
if (it->id == catId)
|
||||
@@ -34,7 +34,7 @@ struct category User::GetCategory(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++)
|
||||
if (it->id == catId)
|
||||
return it->name;
|
||||
@@ -44,7 +44,7 @@ wxString User::GetCategoryName(wxString catId)
|
||||
|
||||
wxString User::GetCategoryId(wxString catName)
|
||||
{
|
||||
std::vector<category>::iterator it;
|
||||
std::vector<Category>::iterator it;
|
||||
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||
if (it->name == catName)
|
||||
return it->id;
|
||||
@@ -54,7 +54,7 @@ wxString User::GetCategoryId(wxString catName)
|
||||
|
||||
wxString User::GetAccountName(wxString accountId)
|
||||
{
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->id == accountId)
|
||||
return it->name;
|
||||
@@ -64,7 +64,7 @@ wxString User::GetAccountName(wxString accountId)
|
||||
|
||||
wxString User::GetAccountId(wxString accountName)
|
||||
{
|
||||
std::vector<struct account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->name == accountName)
|
||||
return it->id;
|
||||
|
||||
40
model/User.h
40
model/User.h
@@ -6,35 +6,9 @@
|
||||
#include <wx/wx.h>
|
||||
#include <wx/colour.h>
|
||||
|
||||
struct operation {
|
||||
wxString id;
|
||||
unsigned int day;
|
||||
unsigned int month;
|
||||
unsigned int year;
|
||||
double amount;
|
||||
wxString description;
|
||||
wxString category;
|
||||
bool fix_cost;
|
||||
wxString account;
|
||||
bool checked;
|
||||
} ;
|
||||
|
||||
struct account {
|
||||
wxString id;
|
||||
wxString name;
|
||||
wxString number;
|
||||
bool shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
struct category
|
||||
{
|
||||
wxString id;
|
||||
wxString parent;
|
||||
wxString name;
|
||||
wxColour color;
|
||||
wxString font;
|
||||
};
|
||||
#include "Category.h"
|
||||
#include "Account.h"
|
||||
#include "Operation.h"
|
||||
|
||||
class User
|
||||
{
|
||||
@@ -44,12 +18,12 @@ public:
|
||||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _password;
|
||||
std::vector<struct account> _accounts;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<struct operation> >* > _operations;
|
||||
std::vector<struct category> _categories;
|
||||
std::vector<Account> _accounts;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* > _operations;
|
||||
std::vector<Category> _categories;
|
||||
std::map<wxString, wxString> _preferences;
|
||||
|
||||
struct category GetCategory(wxString catId);
|
||||
Category GetCategory(wxString catId);
|
||||
wxString GetCategoryName(wxString catId);
|
||||
wxString GetCategoryId(wxString catName);
|
||||
wxString GetAccountName(wxString accountId);
|
||||
|
||||
Reference in New Issue
Block a user