Add operation control on SearchPanel
This commit is contained in:
parent
d9359b2f98
commit
de0e7fa1d9
|
@ -75,6 +75,7 @@ void KissCount::LoadYear(int year, bool force)
|
||||||
if (_user->_operations[year] != NULL)
|
if (_user->_operations[year] != NULL)
|
||||||
{
|
{
|
||||||
delete _user->_operations[year];
|
delete _user->_operations[year];
|
||||||
|
_user->_operations[year] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_db->LoadYear(_user, year);
|
_db->LoadYear(_user, year);
|
||||||
|
|
|
@ -23,9 +23,10 @@ enum {SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
||||||
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
||||||
EVT_SHOW(SearchPanel::OnShow)
|
|
||||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
||||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
||||||
|
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
|
||||||
|
EVT_SHOW(SearchPanel::OnShow)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||||
|
@ -235,3 +236,129 @@ void SearchPanel::OnCalendarToChange(wxCalendarEvent& event)
|
||||||
{
|
{
|
||||||
_checkDateTo->SetValue(true);
|
_checkDateTo->SetValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 != wxT(""))
|
||||||
|
{
|
||||||
|
new_op.description = value;
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _grid->GetCellValue(event.GetRow(), DATE);
|
||||||
|
if (value != wxT(""))
|
||||||
|
{
|
||||||
|
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 != wxT(""))
|
||||||
|
{
|
||||||
|
value.ToDouble(&new_op.amount);
|
||||||
|
new_op.amount *= -1.0;
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
||||||
|
if (value != wxT(""))
|
||||||
|
{
|
||||||
|
value.ToDouble(&new_op.amount);
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
||||||
|
if (value != wxT(""))
|
||||||
|
{
|
||||||
|
new_op.category = user->GetCategoryId(value);
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
||||||
|
if (value != wxT(""))
|
||||||
|
{
|
||||||
|
new_op.account = user->GetAccountId(value);
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
||||||
|
if (value != wxT("") && 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).color;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class SearchPanel: public wxScrolledWindow
|
||||||
~SearchPanel();
|
~SearchPanel();
|
||||||
|
|
||||||
void OnButtonSearch(wxCommandEvent& event);
|
void OnButtonSearch(wxCommandEvent& event);
|
||||||
|
void OnOperationModified(wxGridEvent& event);
|
||||||
void OnShow(wxShowEvent& event);
|
void OnShow(wxShowEvent& event);
|
||||||
void OnCalendarFromChange(wxCalendarEvent& event);
|
void OnCalendarFromChange(wxCalendarEvent& event);
|
||||||
void OnCalendarToChange(wxCalendarEvent& event);
|
void OnCalendarToChange(wxCalendarEvent& event);
|
||||||
|
|
|
@ -195,7 +195,10 @@ void wxUI::ShowPanel(wxPanel* panel)
|
||||||
|
|
||||||
_accountPanel = new AccountPanel(_kiss, this);
|
_accountPanel = new AccountPanel(_kiss, this);
|
||||||
if (year != -1)
|
if (year != -1)
|
||||||
_accountPanel->ShowMonth(month, year);
|
{
|
||||||
|
_kiss->LoadYear(year, true);
|
||||||
|
_accountPanel->ShowMonth(month, year);
|
||||||
|
}
|
||||||
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
||||||
_searchPanel = new SearchPanel(_kiss, this);
|
_searchPanel = new SearchPanel(_kiss, this);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user