Move code grid into GridAccount

Clear and focus to password textctrl when typing invalid password at login
This commit is contained in:
Grégory Soutadé 2010-09-13 19:19:11 +02:00
parent 85e7b0c186
commit 4a90f93130
3 changed files with 96 additions and 63 deletions

View File

@ -86,6 +86,8 @@ void UsersDialog::OnOK(wxCommandEvent& event)
if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0))) if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0)))
{ {
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK); wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK);
_password->Clear();
_password->SetFocus();
} }
else else
{ {

View File

@ -110,6 +110,11 @@ wxPen GridAccount::GetRowGridLinePen (int row) {
return GetCellBackgroundColour(row, 0); return GetCellBackgroundColour(row, 0);
} }
void GridAccount::ResetWeeks()
{
_week1 = _week2 = _week3 = _week4 = 0;
}
void GridAccount::SetWeek(int week, int line) { void GridAccount::SetWeek(int week, int line) {
switch (week) { switch (week) {
case 1: _week1 = line; break; case 1: _week1 = line; break;
@ -130,7 +135,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAdd
_curMonth = month; _curMonth = month;
_curYear = year; _curYear = year;
_displayedOperations.clear(); _displayedOperations.clear();
_displayedOperations.insert(_displayedOperations.begin()+0, NULL); _displayedOperations.push_back(NULL); // Header
_fixCosts = 1; _fixCosts = 1;
it = _operations->begin(); it = _operations->begin();
@ -162,7 +167,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAdd
void GridAccount::InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year) void GridAccount::InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year)
{ {
std::vector<Operation>::iterator it; std::vector<Operation*>::iterator it;
int curLine, curWeek, week, i; int curLine, curWeek, week, i;
InsertOperation(user, op, line, fix, month, year); InsertOperation(user, op, line, fix, month, year);
@ -172,17 +177,23 @@ void GridAccount::InsertOperationWithWeek(User* user, Operation* op, int line, b
if (op && !fix) if (op && !fix)
{ {
for (it = _operations->begin(), curLine=1; for (it = _displayedOperations.begin(), curLine=0;
it->fix_cost && it != _operations->end(); it != _displayedOperations.end();
it++, curLine++) ; 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 (*it && !(*it)->fix_cost) break;
}
if (it == _displayedOperations.end()) return;
ResetWeeks();
curWeek = wxDateTime((*it)->day+1, (wxDateTime::Month)(*it)->month, (*it)->year).GetWeekOfMonth();
it++;
for (i=1; it != _displayedOperations.end(); it++, curLine++)
{
if (!*it) continue;
week = wxDateTime((*it)->day+1, (wxDateTime::Month)(*it)->month, (*it)->year).GetWeekOfMonth();
if (week != curWeek) if (week != curWeek)
{ {
SetWeek(i++, curLine); SetWeek(i++, curLine);
@ -204,9 +215,11 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
curDate.SetToCurrent(); curDate.SetToCurrent();
// // First is header
// if (op)
_displayedOperations.insert(_displayedOperations.begin()+line, op); _displayedOperations.insert(_displayedOperations.begin()+line, op);
if (!op && !user->_accounts.size()) return; if (!user->_accounts.size()) return;
InsertRows(line, 1); InsertRows(line, 1);
@ -329,10 +342,22 @@ void GridAccount::OnCellLeftClick(wxGridEvent& evt)
evt.Skip(); evt.Skip();
} }
void GridAccount::DeleteOperation(const Operation& op)
{
std::vector<Operation>::iterator it;
for (it=_operations->begin(); it!=_operations->end(); it++)
if (it->id == op.id)
{
_operations->erase(it);
break;
}
}
void GridAccount::OnOperationModified(wxGridEvent& event) void GridAccount::OnOperationModified(wxGridEvent& event)
{ {
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
int row = event.GetRow()-1; int row = event.GetRow();
int col = event.GetCol(); int col = event.GetCol();
Operation new_op, cur_op, op_tmp; Operation new_op, cur_op, op_tmp;
int op_complete = 6, i; int op_complete = 6, i;
@ -348,19 +373,19 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
inModification = true ; inModification = true ;
if (event.GetCol() == DEBIT) if (col == DEBIT)
SetCellValue(event.GetRow(), CREDIT, wxT("")); SetCellValue(row, CREDIT, wxT(""));
else if (event.GetCol() == CREDIT) else if (col == CREDIT)
SetCellValue(event.GetRow(), DEBIT, wxT("")); SetCellValue(row, DEBIT, wxT(""));
value = GetCellValue(event.GetRow(), DESCRIPTION); value = GetCellValue(row, DESCRIPTION);
if (value.Length()) if (value.Length())
{ {
new_op.description = value; new_op.description = value;
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), DATE); value = GetCellValue(row, DATE);
if (value.Length()) if (value.Length())
{ {
date.ParseFormat(value, wxT("%d/%m/%Y")); date.ParseFormat(value, wxT("%d/%m/%Y"));
@ -370,7 +395,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), DEBIT); value = GetCellValue(row, DEBIT);
if (value.Length()) if (value.Length())
{ {
value.ToDouble(&new_op.amount); value.ToDouble(&new_op.amount);
@ -378,44 +403,44 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), CREDIT); value = GetCellValue(row, CREDIT);
if (value.Length()) if (value.Length())
{ {
value.ToDouble(&new_op.amount); value.ToDouble(&new_op.amount);
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), CATEGORY); value = GetCellValue(row, CATEGORY);
if (value.Length()) if (value.Length())
{ {
new_op.category = user->GetCategoryId(value); new_op.category = user->GetCategoryId(value);
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), ACCOUNT); value = GetCellValue(row, ACCOUNT);
if (value.Length()) if (value.Length())
{ {
new_op.account = user->GetAccountId(value); new_op.account = user->GetAccountId(value);
op_complete--; op_complete--;
} }
value = GetCellValue(event.GetRow(), CHECKED); value = GetCellValue(row, CHECKED);
if (value.Length() && value != wxT("0")) if (value.Length() && value != wxT("0"))
new_op.checked = true; new_op.checked = true;
else else
new_op.checked = false; new_op.checked = false;
op_complete--; op_complete--;
if (event.GetCol() == DESCRIPTION && if (col == DESCRIPTION &&
(!GetCellValue(event.GetRow(), CATEGORY).Length() || (!GetCellValue(row, CATEGORY).Length() ||
!GetCellValue(event.GetRow(), ACCOUNT).Length())) !GetCellValue(row, ACCOUNT).Length()))
{ {
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear)) if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear))
{ {
new_op.category = op_tmp.category; new_op.category = op_tmp.category;
new_op.account = op_tmp.account; new_op.account = op_tmp.account;
SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category)); SetCellValue(row, CATEGORY, user->GetCategoryName(new_op.category));
SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account)); SetCellValue(row, ACCOUNT, user->GetAccountName(new_op.account));
op_complete -= 2; op_complete -= 2;
} }
} }
@ -432,8 +457,8 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
color.Set(r, g, b, color.Alpha()); color.Set(r, g, b, color.Alpha());
} }
SET_ROW_COLOR(event.GetRow(), color, user->GetCategory(new_op.category).forecolor); SET_ROW_COLOR(row, color, user->GetCategory(new_op.category).forecolor);
SET_ROW_FONT(event.GetRow(), user->GetCategoryFont(new_op.category)); SET_ROW_FONT(row, user->GetCategoryFont(new_op.category));
} }
if (col == DELETE) if (col == DELETE)
@ -441,7 +466,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
wxMessageDialog dialog(this, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO); wxMessageDialog dialog(this, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO) if (dialog.ShowModal() == wxID_NO)
{ {
SetCellValue(event.GetRow(), event.GetCol(), wxT("0")); SetCellValue(row, col, wxT("0"));
inModification = false; inModification = false;
return; return;
} }
@ -450,13 +475,14 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
// Modify a fix operation // Modify a fix operation
if (row < _fixCosts) if (row < _fixCosts)
{ {
cur_op = (*_operations)[row] ; cur_op = *(_displayedOperations)[row] ;
if (col == DELETE) if (col == DELETE)
{ {
DeleteRows(event.GetRow(), 1); DeleteRows(row, 1);
_operations->erase(_operations->begin()+row); DeleteOperation(cur_op);
_kiss->DeleteOperation(cur_op); _kiss->DeleteOperation(cur_op);
_displayedOperations.erase(_displayedOperations.begin()+row);
_fixCosts = _fixCosts--; _fixCosts = _fixCosts--;
inModification = false ; inModification = false ;
event.Skip(); event.Skip();
@ -470,15 +496,16 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
if (cur_op.day != new_op.day) if (cur_op.day != new_op.day)
{ {
need_insertion = true; need_insertion = true;
DeleteRows(event.GetRow(), 1); DeleteRows(row, 1);
_operations->erase(_operations->begin()+row); DeleteOperation(cur_op);
_displayedOperations.erase(_displayedOperations.begin()+row);
_fixCosts--; _fixCosts--;
_kiss->UpdateOperation(new_op); _kiss->UpdateOperation(new_op);
} }
else else
{ {
_kiss->UpdateOperation(new_op); _kiss->UpdateOperation(new_op);
(*_operations)[row] = new_op; *(_displayedOperations)[row] = new_op;
} }
fix_op = true; fix_op = true;
@ -497,7 +524,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
for(i=0; i<NUMBER_COLS_OPS; i++) for(i=0; i<NUMBER_COLS_OPS; i++)
{ {
if (i == CATEGORY) continue; if (i == CATEGORY) continue;
SetCellValue(event.GetRow(), i, wxT("")); SetCellValue(row, i, wxT(""));
} }
DEFAULT_FONT(font); DEFAULT_FONT(font);
@ -508,18 +535,18 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
new_op.id = _kiss->AddOperation(new_op); new_op.id = _kiss->AddOperation(new_op);
} }
// Modify an operation // Modify an operation
else if (row <= user->GetOperationsNumber(_curMonth, _curYear)) else if (row < (int)(_displayedOperations.size()-1))
{ {
row--; cur_op = *(_displayedOperations)[row] ;
cur_op = (*_operations)[row] ;
new_op.id = cur_op.id; new_op.id = cur_op.id;
new_op.fix_cost = false; new_op.fix_cost = false;
new_op.transfert = cur_op.transfert; new_op.transfert = cur_op.transfert;
if (col == DELETE) if (col == DELETE)
{ {
DeleteRows(event.GetRow(), 1); DeleteRows(row, 1);
_operations->erase(_operations->begin()+row); DeleteOperation(cur_op);
_displayedOperations.erase(_displayedOperations.begin()+row);
_kiss->DeleteOperation(cur_op); _kiss->DeleteOperation(cur_op);
inModification = false ; inModification = false ;
event.Skip(); event.Skip();
@ -529,20 +556,20 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
if (cur_op.day != new_op.day) if (cur_op.day != new_op.day)
{ {
need_insertion = true; need_insertion = true;
DeleteRows(event.GetRow(), 1); DeleteRows(row, 1);
_operations->erase(_operations->begin()+row); DeleteOperation(cur_op);
_displayedOperations.erase(_displayedOperations.begin()+row);
_kiss->UpdateOperation(new_op); _kiss->UpdateOperation(new_op);
} }
else else
{ {
_kiss->UpdateOperation(new_op); _kiss->UpdateOperation(new_op);
(*_operations)[row] = new_op; *(_displayedOperations)[row] = new_op;
} }
} }
// Add an operation // Add an operation
else else
{ {
row--;
if (op_complete) { if (op_complete) {
inModification = false ; inModification = false ;
return ; return ;
@ -553,41 +580,42 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
for(i=0; i<NUMBER_COLS_OPS; i++) for(i=0; i<NUMBER_COLS_OPS; i++)
{ {
SetCellValue(event.GetRow(), i, wxT("")); SetCellValue(row, i, wxT(""));
} }
DEFAULT_FONT(font); DEFAULT_FONT(font);
SET_ROW_COLOR(event.GetRow(), OWN_GREEN, *wxBLACK); SET_ROW_COLOR(row, OWN_GREEN, *wxBLACK);
SET_ROW_FONT(event.GetRow(), font); SET_ROW_FONT(row, font);
new_op.id = _kiss->AddOperation(new_op); new_op.id = _kiss->AddOperation(new_op);
} }
if (need_insertion) if (need_insertion)
{ {
for(i=0; i<(int)_operations->size(); i++) for(i=0; i<(int)_displayedOperations.size(); i++)
{ {
if ((*_operations)[i].fix_cost && !fix_op) continue; if (_displayedOperations[i] == NULL) continue;
if (!(*_operations)[i].fix_cost && fix_op) break; if ((_displayedOperations)[i]->fix_cost && !fix_op) continue;
if (!(_displayedOperations)[i]->fix_cost && fix_op) break;
if (user->_preferences[wxT("operation_order")] == wxT("ASC")) if (user->_preferences[wxT("operation_order")] == wxT("ASC"))
{ {
if ((*_operations)[i].day > new_op.day) if ((_displayedOperations)[i]->day > new_op.day)
break; break;
} }
else else
{ {
if ((*_operations)[i].day < new_op.day) if ((_displayedOperations)[i]->day < new_op.day)
break; break;
} }
} }
_operations->insert(_operations->begin()+i ,new_op); if (i == (int)_displayedOperations.size()) i--;
i++; // For header _operations->push_back(new_op);
if (!fix_op) i++;
InsertOperationWithWeek(user, &new_op, i, fix_op, _curMonth, _curYear); InsertOperationWithWeek(user, &((*_operations)[_operations->size()-1]), i, fix_op, _curMonth, _curYear);
if (fix_op) if (fix_op)
_fixCosts = _fixCosts+1; _fixCosts = _fixCosts+1;
} }

View File

@ -40,7 +40,6 @@ public:
wxPen GetColGridLinePen (int col); wxPen GetColGridLinePen (int col);
wxPen GetRowGridLinePen (int row); wxPen GetRowGridLinePen (int row);
void SetWeek(int week, int line);
void LoadOperations(std::vector<Operation>* operations, bool canAddOperation, bool setWeek, int month, int year); 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 InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year) ;
@ -59,6 +58,10 @@ private:
int _curMonth, _curYear; int _curMonth, _curYear;
std::vector<Operation*> _displayedOperations; std::vector<Operation*> _displayedOperations;
void SetWeek(int week, int line);
void ResetWeeks();
void DeleteOperation(const Operation& op);
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
}; };
#endif #endif