Generate & delete month/year OK

This commit is contained in:
2010-06-24 21:02:42 +02:00
parent 271b3ef1e7
commit e72e36f27d
6 changed files with 133 additions and 11 deletions

View File

@@ -16,6 +16,7 @@
}\
catch (wxSQLite3Exception e)\
{\
std::cerr << req.mb_str() << "\n" ;\
std::cerr << e.GetMessage().mb_str() << "\n" ;\
code_if_fail; \
return return_value;\
@@ -30,6 +31,7 @@
}\
catch (wxSQLite3Exception e)\
{\
std::cerr << req.mb_str() << "\n" ;\
std::cerr << e.GetMessage().mb_str() << "\n" ;\
code_if_fail; \
return return_value;\
@@ -103,11 +105,12 @@ void Database::CreateDatabase()
std::list<wxString> Database::GetUsers()
{
std::list<wxString> res;
wxString req;
// Check whether value exists in table
wxSQLite3ResultSet set ;
EXECUTE_SQL_QUERY(_("SELECT name FROM user ORDER BY name"), set, res);
req = _("SELECT name FROM user ORDER BY name");
EXECUTE_SQL_QUERY(req, set, res);
while (set.NextRow())
{
@@ -382,6 +385,41 @@ void Database::DeleteOperation(struct operation op)
EXECUTE_SQL_UPDATE(req, );
}
void Database::DeleteOperations(User* user, int month, int year)
{
wxString req;
std::vector<Account>::iterator it;
it = user->_accounts.begin();
req = _("DELETE FROM account_amount WHERE account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("')");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
if (month != -1)
req += _(" AND month='") + wxString::Format(_("%d"), month) + _("'");
EXECUTE_SQL_UPDATE(req, );
it = user->_accounts.begin();
req = _("DELETE FROM operation WHERE account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("')");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
if (month != -1)
req += _(" AND month='") + wxString::Format(_("%d"), month) + _("'");
EXECUTE_SQL_UPDATE(req, );
}
void Database::SetAccountAmount(int month, int year, wxString accountId, double amount)
{
wxString req;
@@ -542,6 +580,7 @@ void Database::UpdateCategory(User* user, wxString oldName, wxString name, wxStr
void Database::DeleteCategory(User* user, struct category category)
{
wxString req;
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
req += _(" AND type='category'");
req += _(" AND name='name'");

View File

@@ -27,6 +27,7 @@ class Database
void UpdateOperation(struct operation op);
wxString AddOperation(User* user, struct operation op);
void DeleteOperation(struct 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);