void BudgetWindow::RefreshBudgetGrid(void) { fIncomeGrid.MakeEmpty(); fSpendingGrid.MakeEmpty(); CppSQLite3Query query = gDatabase.DBQuery("select category,amount,period from " "budgetlist order by category", "BudgetWindow::RefreshCategories"); while(!query.eof()) { BString cat = DeescapeIllegalCharacters(query.getStringField(0)); Fixed amount; amount.SetPremultiplied(query.getInt64Field(1)); BudgetPeriod period = (BudgetPeriod)query.getIntField(2); ReportGrid *grid = (amount.IsPositive()) ? &fIncomeGrid : &fSpendingGrid; int32 index = grid->CountItems(); grid->AddItem(); grid->SetRowTitle(index, cat.String()); Fixed f(amount.AbsoluteValue()); switch(period) { case BUDGET_QUARTERLY: { f /= 3; Fixed qamt(amount); qamt *= 4; grid->SetValue(12,index,qamt); break; } case BUDGET_ANNUALLY: { f /=12; grid->SetValue(12,index,amount); break; } default: { Fixed mamt(f); mamt *= 12; grid->SetValue(12,index,mamt); break; } } for(int32 i=0; i<12; i++) grid->SetValue(i,index,f); query.nextRow(); } }
void BudgetWindow::RefreshCategories(void) { fCategoryList->Clear(); fIncomeRow = new BRow(); fCategoryList->AddRow(fIncomeRow); fSpendingRow = new BRow(); fCategoryList->AddRow(fSpendingRow); fIncomeRow->SetField(new BStringField(TRANSLATE("Income")),0); fSpendingRow->SetField(new BStringField(TRANSLATE("Spending")),0); CppSQLite3Query query = gDatabase.DBQuery("select category,amount,period,isexpense from " "budgetlist order by category", "BudgetWindow::RefreshCategories"); float maxwidth=fCategoryList->StringWidth("Category"); while(!query.eof()) { BString cat = DeescapeIllegalCharacters(query.getStringField(0)); Fixed amount; amount.SetPremultiplied(query.getInt64Field(1)); BudgetPeriod period = (BudgetPeriod)query.getIntField(2); BRow *row = new BRow(); if(query.getIntField(3)==0) fCategoryList->AddRow(row,fIncomeRow); else fCategoryList->AddRow(row,fSpendingRow); row->SetField(new BStringField(cat.String()),0); BString amountstr; gDefaultLocale.CurrencyToString(amount.AbsoluteValue(),amountstr); amountstr.Truncate(amountstr.FindFirst(gDefaultLocale.CurrencyDecimal())); amountstr.RemoveFirst(gDefaultLocale.CurrencySymbol()); row->SetField(new BStringField(amountstr.String()),1); float tempwidth = fCategoryList->StringWidth(cat.String()); maxwidth = MAX(tempwidth,maxwidth); row->SetField(new BStringField(BudgetPeriodToString(period).String()),2); query.nextRow(); } fCategoryList->ColumnAt(0)->SetWidth(maxwidth+30); fCategoryList->ExpandOrCollapse(fIncomeRow,true); fCategoryList->ExpandOrCollapse(fSpendingRow,true); }