Some Grid code moved to GridAccount

This commit is contained in:
2010-09-12 18:10:40 +02:00
parent 67d3275b28
commit 9c52ca5362
4 changed files with 89 additions and 76 deletions

View File

@@ -116,7 +116,77 @@ void GridAccount::SetWeek(int week, int line) {
}
}
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear)
void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAddOperation, bool setWeek, int month, int year)
{
std::vector<Operation>::iterator it;
User* user = _kiss->GetUser();
int curLine = 0;
_operations = operations;
_canAddOperation = canAddOperation;
_fixCosts = 1;
it = _operations->begin();
for (;it != _operations->end() && it->fix_cost; it++)
if (setWeek)
InsertOperationWithWeek(user, &(*it), ++curLine, true, it->month, it->year);
else
InsertOperation(user, &(*it), ++curLine, true, it->month, it->year);
if (canAddOperation)
InsertOperation(user, NULL, ++curLine, true, month, year);
for (; it != _operations->end(); it++)
if (setWeek)
InsertOperationWithWeek(user, &(*it), ++curLine, false, it->month, it->year);
else
InsertOperation(user, &(*it), ++curLine, false, it->month, it->year);
if (canAddOperation)
InsertOperation(user, NULL, ++curLine, false, month, year);
AutoSizeColumn(CATEGORY, false);
AutoSizeColumn(DATE, false);
AutoSizeColumn(ACCOUNT, false);
AutoSizeColumn(DELETE, false);
AutoSizeColumn(CHECKED, false);
}
void GridAccount::InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year)
{
std::vector<Operation>::iterator it;
int curLine, curWeek, week, i;
InsertOperation(user, op, line, fix, month, year);
if (fix)
_fixCosts++;
if (op && !fix)
{
for (it = _operations->begin(), curLine=1;
it->fix_cost && it != _operations->end();
it++, curLine++) ;
if (it == _operations->end()) return;
curLine++;
curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
for (i=1, it++; it != _operations->end(); it++, curLine++)
{
week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
if (week != curWeek)
{
SetWeek(i++, curLine);
curWeek = week;
}
}
}
}
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int month, int year)
{
std::vector<Operation>::iterator it;
int r, g, b;
@@ -149,18 +219,18 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
{
cat = user->GetCategory(op->category);
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
SetCellEditor(line, DATE, new CalendarEditor(op->day, month, year));
description = op->description;
UNESCAPE_CHARS(description);
SetCellValue(line, DESCRIPTION, description);
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, month+1, year));
if (op->amount < 0)
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
else
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
if (!fix)
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
SetCellValue(line, CATEGORY, cat.name);
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
@@ -186,16 +256,16 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
}
else
{
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
SetCellEditor(line, DATE, new CalendarEditor(0, month, year));
if (!fix &&
curDate.GetMonth() == curMonth &&
curDate.GetYear() == curYear)
curDate.GetMonth() == month &&
curDate.GetYear() == year)
{
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), month+1, year));
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, month, year));
}
else
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
SetCellEditor(line, DATE, new CalendarEditor(0, month, year));
if (fix)
{

View File

@@ -41,7 +41,10 @@ public:
wxPen GetColGridLinePen (int col);
wxPen GetRowGridLinePen (int row);
void SetWeek(int week, int line);
void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear);
void LoadOperations(std::vector<Operation>* operations, bool canAddOperation, bool setWeek, int month, int year);
void InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year) ;
void InsertOperation(User* user, Operation* op, int line, bool fix, int month, int year) ;
void OnCellLeftClick(wxGridEvent& evt);
@@ -50,6 +53,8 @@ public:
private:
KissCount* _kiss;
wxString* _categories, *_accounts;
std::vector<Operation>* _operations;
bool _canAddOperation;
DECLARE_EVENT_TABLE();
};