Fix a bug on stats (when total = 0)

Fix a bug modifying account values (infinite recursive loop)
This commit is contained in:
Grégory Soutadé 2010-08-26 19:50:32 +02:00
parent dd5f231f20
commit 4583dae912
2 changed files with 18 additions and 3 deletions

View File

@ -453,13 +453,14 @@ void AccountPanel::UpdateStats()
std::map<wxString, double>* notChecked = NULL;
curCredit = curDebit = totalCredit = totalDebit = percents = 0.0;
if (checkMode)
{
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
}
day = _calendar->GetDate().GetDay()-1;
curCredit = curDebit = totalCredit = totalDebit = 0.0;
for (i=0; i<user->GetCategoriesNumber(); i++)
_categoriesValues[i] = 0.0;
@ -515,7 +516,10 @@ void AccountPanel::UpdateStats()
for(i=0; i<user->GetCategoriesNumber()+1; i++)
{
percents = ((double) (_categoriesValues[i]*100))/totalDebit;
if (totalDebit != 0)
percents = ((double) (_categoriesValues[i]*100))/totalDebit;
else
percents = 0.0;
_statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents));
}
@ -818,12 +822,20 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
double amount;
wxString id = user->GetAccountId(_accounts[row]);
static bool inModification = false;
if (inModification) return ;
inModification = true;
_accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
_kiss->SetAccountAmount(_curMonth, _curYear, id, amount);
_accountsInitValues[id] = amount;
UpdateStats();
inModification = false;
}
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)

View File

@ -259,7 +259,10 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
{
_categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second;
percents = ((double) (categoriesIt->second*100))/total;
if (total)
percents = ((double) (categoriesIt->second*100))/total;
else
percents = 0;
value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents);
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
}