Fix Account loading bug

This commit is contained in:
Grégory Soutadé 2010-07-03 11:03:36 +02:00
parent 4c3f2cc209
commit c237b9f057
3 changed files with 22 additions and 10 deletions

View File

@ -207,13 +207,15 @@ User* Database::LoadUser(wxString name)
if (!user->_accounts.empty())
{
it = user->_accounts.begin();
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id;
req = _("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("') ORDER BY year ASC");
req += _("')");
req += _(" OR user='") + user->_id + _("'");
req += _(" ORDER BY year ASC");
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
@ -265,13 +267,14 @@ void Database::LoadYear(User* user, int year)
if (!user->_accounts.size()) return;
it = user->_accounts.begin();
req = _("SELECT * FROM operation WHERE account IN('") + it->id;
req = _("SELECT * FROM operation WHERE (account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("')");
req += _("')");
req += _(" OR user='") + user->_id + _("')");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
req += _(" ORDER BY fix_cost DESC, year,month,day ASC");
@ -421,13 +424,14 @@ void Database::DeleteOperations(User* user, int month, int year)
EXECUTE_SQL_UPDATE(req, );
it = user->_accounts.begin();
req = _("DELETE FROM operation WHERE account IN('") + it->id;
req = _("DELETE FROM operation WHERE (account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("')");
req += _(" OR user='") + user->_id + _("')");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
if (month != -1)
req += _(" AND month='") + wxString::Format(_("%d"), month) + _("'");
@ -611,13 +615,15 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
if (!user->_accounts.empty())
{
it = user->_accounts.begin();
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id;
req = _("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("') ORDER BY year ASC");
req += _("')");
req += _(" OR user='") + user->_id + _("'");
req += _(" ORDER BY year ASC");
EXECUTE_SQL_QUERY(req, set, res);
@ -626,13 +632,14 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
year = set.GetInt(_("year"));
it = user->_accounts.begin();
req = _("SELECT DISTINCT month FROM account_amount WHERE account IN('") + it->id;
req = _("SELECT DISTINCT month FROM operation WHERE (account IN('") + it->id;
it++;
for (;it != user->_accounts.end(); it++)
{
req += _("', '") + it->id ;
}
req += _("')");
req += _(" OR user='") + user->_id + _("')");
req += _(" AND year='") + set.GetAsString(_("year")) + _("'");
req += _(" ORDER BY month ASC");
@ -810,6 +817,9 @@ void Database::NewUser(wxString name)
return ;
}
/*
Shared accounts not currently supported
*/
void Database::KillMe(User* user)
{
wxString req;
@ -839,6 +849,7 @@ void Database::KillMe(User* user)
req += _("', '") + it->id ;
}
req += _("')");
req += _(" OR user='") + user->_id + _("')");
EXECUTE_SQL_UPDATE(req, );
}

View File

@ -952,7 +952,7 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
if (ops.size() == 1 && ops[year].size() == 1)
{
wxMessageBox(_("It must be at least one month"), _("Error"), wxICON_ERROR | wxOK);
wxMessageBox(_("It must be at least one month !"), _("Error"), wxICON_ERROR | wxOK);
return;
}

View File

@ -248,7 +248,8 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
{
if (user->_accounts.size() == 1)
{
wxMessageBox(_("It must be at least one account"), _("Error"), wxICON_ERROR | wxOK);
wxMessageBox(_("It must be at least one account !"), _("Error"), wxICON_ERROR | wxOK);
_accountsGrid->SetCellValue(row, col, _("0"));
return;
}
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+new_account.name, _("KissCount"), wxYES_NO);