Move grid management code into GridAccount

This commit is contained in:
2010-09-12 19:19:16 +02:00
parent 9c52ca5362
commit 85e7b0c186
4 changed files with 281 additions and 387 deletions

View File

@@ -247,127 +247,5 @@ void SearchPanel::OnCalendarToChange(wxCalendarEvent& event)
void SearchPanel::OnOperationModified(wxGridEvent& event)
{
User* user = _kiss->GetUser();
int row = event.GetRow()-1;
int col = event.GetCol();
Operation new_op, cur_op;
int op_complete = 6;
wxString value ;
wxDateTime date;
static bool inModification = false ;
wxColour color ;
unsigned char r, g, b;
// Avoid recursives calls
if (inModification) return;
inModification = true ;
if (event.GetCol() == DEBIT)
_grid->SetCellValue(event.GetRow(), CREDIT, wxT(""));
else if (event.GetCol() == CREDIT)
_grid->SetCellValue(event.GetRow(), DEBIT, wxT(""));
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
if (value.Length())
{
new_op.description = value;
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), DATE);
if (value.Length())
{
date.ParseFormat(value, wxT("%d/%m/%Y"));
new_op.day = date.GetDay()-1;
new_op.month = date.GetMonth();
new_op.year = date.GetYear();
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), DEBIT);
if (value.Length())
{
value.ToDouble(&new_op.amount);
new_op.amount *= -1.0;
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), CREDIT);
if (value.Length())
{
value.ToDouble(&new_op.amount);
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
if (value.Length())
{
new_op.category = user->GetCategoryId(value);
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
if (value.Length())
{
new_op.account = user->GetAccountId(value);
op_complete--;
}
value = _grid->GetCellValue(event.GetRow(), CHECKED);
if (value.Length() && value != wxT("0"))
new_op.checked = true;
else
new_op.checked = false;
op_complete--;
if (col == CHECKED || col == CATEGORY)
{
color = user->GetCategory(new_op.category).backcolor;
if (new_op.checked)
{
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
color.Set(r, g, b, color.Alpha());
}
SET_ROW_COLOR(event.GetRow(), color);
}
if (col == DELETE)
{
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
{
_grid->SetCellValue(event.GetRow(), event.GetCol(), wxT("0"));
_wxUI->NeedReload();
inModification = false;
return;
}
}
// Modify an operation
cur_op = (*_operations)[row] ;
new_op.id = cur_op.id;
new_op.fix_cost = false;
new_op.transfert = cur_op.transfert;
if (col == DELETE)
{
_grid->DeleteRows(event.GetRow(), 1);
_kiss->DeleteOperation(cur_op);
_operations->erase(_operations->begin()+row);
_wxUI->NeedReload();
inModification = false ;
return ;
}
(*_operations)[row] = new_op;
_kiss->UpdateOperation(new_op);
_wxUI->NeedReload();
inModification = false ;
}