Move grid management code into GridAccount
This commit is contained in:
parent
9c52ca5362
commit
85e7b0c186
|
@ -519,269 +519,7 @@ void AccountPanel::UpdateStats()
|
|||
|
||||
void AccountPanel::OnOperationModified(wxGridEvent& event)
|
||||
{
|
||||
User* user = _kiss->GetUser();
|
||||
int row = event.GetRow()-1;
|
||||
int col = event.GetCol();
|
||||
Operation new_op, cur_op, op_tmp;
|
||||
int op_complete = 6, i;
|
||||
wxString value ;
|
||||
wxDateTime date;
|
||||
bool need_insertion = false, fix_op=false;
|
||||
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 (event.GetCol() == DESCRIPTION &&
|
||||
(!_grid->GetCellValue(event.GetRow(), CATEGORY).Length() ||
|
||||
!_grid->GetCellValue(event.GetRow(), ACCOUNT).Length()))
|
||||
{
|
||||
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear))
|
||||
{
|
||||
new_op.category = op_tmp.category;
|
||||
new_op.account = op_tmp.account;
|
||||
_grid->SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category));
|
||||
_grid->SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account));
|
||||
op_complete -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
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, user->GetCategory(new_op.category).forecolor);
|
||||
SET_ROW_FONT(event.GetRow(), user->GetCategoryFont(new_op.category));
|
||||
}
|
||||
|
||||
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"));
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Modify a fix operation
|
||||
if (row < _fixCosts)
|
||||
{
|
||||
cur_op = (*_curOperations)[row] ;
|
||||
|
||||
if (col == DELETE)
|
||||
{
|
||||
_grid->DeleteRows(event.GetRow(), 1);
|
||||
_curOperations->erase(_curOperations->begin()+row);
|
||||
_kiss->DeleteOperation(cur_op);
|
||||
_grid->_fixCosts = _fixCosts--;
|
||||
UpdateStats();
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
|
||||
new_op.id = cur_op.id;
|
||||
new_op.fix_cost = true;
|
||||
new_op.transfert = cur_op.transfert;
|
||||
|
||||
if (cur_op.day != new_op.day)
|
||||
{
|
||||
need_insertion = true;
|
||||
_grid->DeleteRows(event.GetRow(), 1);
|
||||
_curOperations->erase(_curOperations->begin()+row);
|
||||
_fixCosts--;
|
||||
_kiss->UpdateOperation(new_op);
|
||||
}
|
||||
else
|
||||
{
|
||||
_kiss->UpdateOperation(new_op);
|
||||
(*_curOperations)[row] = new_op;
|
||||
}
|
||||
|
||||
fix_op = true;
|
||||
}
|
||||
// Add a fixCost
|
||||
else if (row == _fixCosts)
|
||||
{
|
||||
if (op_complete) {
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
need_insertion = true;
|
||||
fix_op = true;
|
||||
new_op.fix_cost = true;
|
||||
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
if (i == CATEGORY) continue;
|
||||
_grid->SetCellValue(event.GetRow(), i, wxT(""));
|
||||
}
|
||||
|
||||
DEFAULT_FONT(font);
|
||||
|
||||
SET_ROW_COLOR(row, OWN_GREEN, *wxBLACK);
|
||||
SET_ROW_FONT(row, font);
|
||||
|
||||
new_op.id = _kiss->AddOperation(new_op);
|
||||
}
|
||||
// Modify an operation
|
||||
else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
|
||||
{
|
||||
row--;
|
||||
cur_op = (*_curOperations)[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);
|
||||
_curOperations->erase(_curOperations->begin()+row);
|
||||
_kiss->DeleteOperation(cur_op);
|
||||
UpdateStats();
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
|
||||
if (cur_op.day != new_op.day)
|
||||
{
|
||||
need_insertion = true;
|
||||
_grid->DeleteRows(event.GetRow(), 1);
|
||||
_curOperations->erase(_curOperations->begin()+row);
|
||||
_kiss->UpdateOperation(new_op);
|
||||
}
|
||||
else
|
||||
{
|
||||
_kiss->UpdateOperation(new_op);
|
||||
(*_curOperations)[row] = new_op;
|
||||
}
|
||||
}
|
||||
// Add an operation
|
||||
else
|
||||
{
|
||||
row--;
|
||||
if (op_complete) {
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
need_insertion = true;
|
||||
fix_op = false;
|
||||
new_op.fix_cost = false;
|
||||
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
_grid->SetCellValue(event.GetRow(), i, wxT(""));
|
||||
}
|
||||
|
||||
DEFAULT_FONT(font);
|
||||
|
||||
SET_ROW_COLOR(event.GetRow(), OWN_GREEN, *wxBLACK);
|
||||
SET_ROW_FONT(event.GetRow(), font);
|
||||
|
||||
new_op.id = _kiss->AddOperation(new_op);
|
||||
}
|
||||
|
||||
if (need_insertion)
|
||||
{
|
||||
for(i=0; i<(int)_curOperations->size(); i++)
|
||||
{
|
||||
if ((*_curOperations)[i].fix_cost && !fix_op) continue;
|
||||
if (!(*_curOperations)[i].fix_cost && fix_op) break;
|
||||
if (user->_preferences[wxT("operation_order")] == wxT("ASC"))
|
||||
{
|
||||
if ((*_curOperations)[i].day > new_op.day)
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*_curOperations)[i].day < new_op.day)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_curOperations->insert(_curOperations->begin()+i ,new_op);
|
||||
|
||||
i++; // For header
|
||||
if (!fix_op) i++;
|
||||
_grid->InsertOperationWithWeek(user, &new_op, i, fix_op, _curMonth, _curYear);
|
||||
if (fix_op)
|
||||
_grid->_fixCosts = _fixCosts+1;
|
||||
}
|
||||
|
||||
UpdateStats();
|
||||
inModification = false ;
|
||||
}
|
||||
|
||||
void AccountPanel::OnAccountModified(wxGridEvent& event)
|
||||
|
|
|
@ -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 ;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,10 @@ BEGIN_EVENT_TABLE(GridAccount, wxGrid)
|
|||
EVT_GRID_CELL_LEFT_CLICK(GridAccount::OnCellLeftClick )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id),
|
||||
_fixCosts(0), _week1(0), _week2(0), _week3(0), _week4(0), _kiss(kiss)
|
||||
enum {GRID_ID};
|
||||
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id), _fixCosts(0), _week1(0),
|
||||
_week2(0), _week3(0), _week4(0), _kiss(kiss),
|
||||
_curMonth(0), _curYear(0)
|
||||
{
|
||||
wxBitmap deleteBitmap(wxT(DELETE_ICON));
|
||||
wxBitmap checkedBitmap(wxT(CHECKED_ICON));
|
||||
|
@ -85,6 +87,7 @@ GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxG
|
|||
_categories[i] = categoryIt->name ;
|
||||
}
|
||||
|
||||
Connect(id, wxEVT_GRID_CELL_CHANGE, wxGridEventHandler(GridAccount::OnOperationModified), NULL, this);
|
||||
}
|
||||
|
||||
GridAccount::~GridAccount()
|
||||
|
@ -124,7 +127,10 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAdd
|
|||
|
||||
_operations = operations;
|
||||
_canAddOperation = canAddOperation;
|
||||
|
||||
_curMonth = month;
|
||||
_curYear = year;
|
||||
_displayedOperations.clear();
|
||||
_displayedOperations.insert(_displayedOperations.begin()+0, NULL);
|
||||
_fixCosts = 1;
|
||||
|
||||
it = _operations->begin();
|
||||
|
@ -198,6 +204,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
|||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
_displayedOperations.insert(_displayedOperations.begin()+line, op);
|
||||
|
||||
if (!op && !user->_accounts.size()) return;
|
||||
|
||||
InsertRows(line, 1);
|
||||
|
@ -320,3 +328,270 @@ void GridAccount::OnCellLeftClick(wxGridEvent& evt)
|
|||
pEditor->DecRef();
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void GridAccount::OnOperationModified(wxGridEvent& event)
|
||||
{
|
||||
User* user = _kiss->GetUser();
|
||||
int row = event.GetRow()-1;
|
||||
int col = event.GetCol();
|
||||
Operation new_op, cur_op, op_tmp;
|
||||
int op_complete = 6, i;
|
||||
wxString value ;
|
||||
wxDateTime date;
|
||||
bool need_insertion = false, fix_op=false;
|
||||
static bool inModification = false ;
|
||||
wxColour color ;
|
||||
unsigned char r, g, b;
|
||||
|
||||
// Avoid recursives calls
|
||||
if (inModification) return;
|
||||
|
||||
inModification = true ;
|
||||
|
||||
if (event.GetCol() == DEBIT)
|
||||
SetCellValue(event.GetRow(), CREDIT, wxT(""));
|
||||
else if (event.GetCol() == CREDIT)
|
||||
SetCellValue(event.GetRow(), DEBIT, wxT(""));
|
||||
|
||||
value = GetCellValue(event.GetRow(), DESCRIPTION);
|
||||
if (value.Length())
|
||||
{
|
||||
new_op.description = value;
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
value = 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 = GetCellValue(event.GetRow(), DEBIT);
|
||||
if (value.Length())
|
||||
{
|
||||
value.ToDouble(&new_op.amount);
|
||||
new_op.amount *= -1.0;
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
value = GetCellValue(event.GetRow(), CREDIT);
|
||||
if (value.Length())
|
||||
{
|
||||
value.ToDouble(&new_op.amount);
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
value = GetCellValue(event.GetRow(), CATEGORY);
|
||||
if (value.Length())
|
||||
{
|
||||
new_op.category = user->GetCategoryId(value);
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
value = GetCellValue(event.GetRow(), ACCOUNT);
|
||||
if (value.Length())
|
||||
{
|
||||
new_op.account = user->GetAccountId(value);
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
value = GetCellValue(event.GetRow(), CHECKED);
|
||||
if (value.Length() && value != wxT("0"))
|
||||
new_op.checked = true;
|
||||
else
|
||||
new_op.checked = false;
|
||||
op_complete--;
|
||||
|
||||
if (event.GetCol() == DESCRIPTION &&
|
||||
(!GetCellValue(event.GetRow(), CATEGORY).Length() ||
|
||||
!GetCellValue(event.GetRow(), ACCOUNT).Length()))
|
||||
{
|
||||
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear))
|
||||
{
|
||||
new_op.category = op_tmp.category;
|
||||
new_op.account = op_tmp.account;
|
||||
SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category));
|
||||
SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account));
|
||||
op_complete -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
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, user->GetCategory(new_op.category).forecolor);
|
||||
SET_ROW_FONT(event.GetRow(), user->GetCategoryFont(new_op.category));
|
||||
}
|
||||
|
||||
if (col == DELETE)
|
||||
{
|
||||
wxMessageDialog dialog(this, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
{
|
||||
SetCellValue(event.GetRow(), event.GetCol(), wxT("0"));
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Modify a fix operation
|
||||
if (row < _fixCosts)
|
||||
{
|
||||
cur_op = (*_operations)[row] ;
|
||||
|
||||
if (col == DELETE)
|
||||
{
|
||||
DeleteRows(event.GetRow(), 1);
|
||||
_operations->erase(_operations->begin()+row);
|
||||
_kiss->DeleteOperation(cur_op);
|
||||
_fixCosts = _fixCosts--;
|
||||
inModification = false ;
|
||||
event.Skip();
|
||||
return ;
|
||||
}
|
||||
|
||||
new_op.id = cur_op.id;
|
||||
new_op.fix_cost = true;
|
||||
new_op.transfert = cur_op.transfert;
|
||||
|
||||
if (cur_op.day != new_op.day)
|
||||
{
|
||||
need_insertion = true;
|
||||
DeleteRows(event.GetRow(), 1);
|
||||
_operations->erase(_operations->begin()+row);
|
||||
_fixCosts--;
|
||||
_kiss->UpdateOperation(new_op);
|
||||
}
|
||||
else
|
||||
{
|
||||
_kiss->UpdateOperation(new_op);
|
||||
(*_operations)[row] = new_op;
|
||||
}
|
||||
|
||||
fix_op = true;
|
||||
}
|
||||
// Add a fixCost
|
||||
else if (row == _fixCosts)
|
||||
{
|
||||
if (op_complete) {
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
need_insertion = true;
|
||||
fix_op = true;
|
||||
new_op.fix_cost = true;
|
||||
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
if (i == CATEGORY) continue;
|
||||
SetCellValue(event.GetRow(), i, wxT(""));
|
||||
}
|
||||
|
||||
DEFAULT_FONT(font);
|
||||
|
||||
SET_ROW_COLOR(row, OWN_GREEN, *wxBLACK);
|
||||
SET_ROW_FONT(row, font);
|
||||
|
||||
new_op.id = _kiss->AddOperation(new_op);
|
||||
}
|
||||
// Modify an operation
|
||||
else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
|
||||
{
|
||||
row--;
|
||||
cur_op = (*_operations)[row] ;
|
||||
new_op.id = cur_op.id;
|
||||
new_op.fix_cost = false;
|
||||
new_op.transfert = cur_op.transfert;
|
||||
|
||||
if (col == DELETE)
|
||||
{
|
||||
DeleteRows(event.GetRow(), 1);
|
||||
_operations->erase(_operations->begin()+row);
|
||||
_kiss->DeleteOperation(cur_op);
|
||||
inModification = false ;
|
||||
event.Skip();
|
||||
return ;
|
||||
}
|
||||
|
||||
if (cur_op.day != new_op.day)
|
||||
{
|
||||
need_insertion = true;
|
||||
DeleteRows(event.GetRow(), 1);
|
||||
_operations->erase(_operations->begin()+row);
|
||||
_kiss->UpdateOperation(new_op);
|
||||
}
|
||||
else
|
||||
{
|
||||
_kiss->UpdateOperation(new_op);
|
||||
(*_operations)[row] = new_op;
|
||||
}
|
||||
}
|
||||
// Add an operation
|
||||
else
|
||||
{
|
||||
row--;
|
||||
if (op_complete) {
|
||||
inModification = false ;
|
||||
return ;
|
||||
}
|
||||
need_insertion = true;
|
||||
fix_op = false;
|
||||
new_op.fix_cost = false;
|
||||
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
SetCellValue(event.GetRow(), i, wxT(""));
|
||||
}
|
||||
|
||||
DEFAULT_FONT(font);
|
||||
|
||||
SET_ROW_COLOR(event.GetRow(), OWN_GREEN, *wxBLACK);
|
||||
SET_ROW_FONT(event.GetRow(), font);
|
||||
|
||||
new_op.id = _kiss->AddOperation(new_op);
|
||||
}
|
||||
|
||||
if (need_insertion)
|
||||
{
|
||||
for(i=0; i<(int)_operations->size(); i++)
|
||||
{
|
||||
if ((*_operations)[i].fix_cost && !fix_op) continue;
|
||||
if (!(*_operations)[i].fix_cost && fix_op) break;
|
||||
if (user->_preferences[wxT("operation_order")] == wxT("ASC"))
|
||||
{
|
||||
if ((*_operations)[i].day > new_op.day)
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*_operations)[i].day < new_op.day)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_operations->insert(_operations->begin()+i ,new_op);
|
||||
|
||||
i++; // For header
|
||||
if (!fix_op) i++;
|
||||
InsertOperationWithWeek(user, &new_op, i, fix_op, _curMonth, _curYear);
|
||||
if (fix_op)
|
||||
_fixCosts = _fixCosts+1;
|
||||
}
|
||||
|
||||
inModification = false ;
|
||||
event.Skip();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
void InsertOperation(User* user, Operation* op, int line, bool fix, int month, int year) ;
|
||||
|
||||
void OnCellLeftClick(wxGridEvent& evt);
|
||||
void OnOperationModified(wxGridEvent& event);
|
||||
|
||||
int _fixCosts;
|
||||
int _week1, _week2, _week3, _week4;
|
||||
|
@ -55,6 +56,8 @@ private:
|
|||
wxString* _categories, *_accounts;
|
||||
std::vector<Operation>* _operations;
|
||||
bool _canAddOperation;
|
||||
int _curMonth, _curYear;
|
||||
std::vector<Operation*> _displayedOperations;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user