Accounts events caught

This commit is contained in:
Grégory Soutadé 2010-06-12 15:59:27 +02:00
parent 8d2d985e2e
commit c353c02d5b
7 changed files with 33 additions and 3 deletions

View File

@ -83,3 +83,8 @@ void KissCount::DeleteOperation(struct operation op)
{
_db->DeleteOperation(op);
}
void KissCount::SetAccountAmount(int month, int year, wxString accountId, double amount)
{
_db->SetAccountAmount(month, year, accountId, amount);
}

View File

@ -24,6 +24,7 @@ class KissCount
void UpdateOperation(struct operation op);
void AddOperation(struct operation op);
void DeleteOperation(struct operation op);
void SetAccountAmount(int month, int year, wxString accountId, double value);
private:
wxUI* _wxUI;

View File

@ -318,3 +318,15 @@ void Database::DeleteOperation(struct operation op)
EXECUTE_SQL_UPDATE(req, );
}
void Database::SetAccountAmount(int month, int year, wxString accountId, double amount)
{
wxString req;
req = _("UPDATE account_amount SET ") ;
req += _("amount='") + wxString::Format(_("%.2lf"), amount) + _("'");
req += _(" WHERE id='") + accountId + _("'");
req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'");
req += _(" AND month='") + wxString::Format(_("%d"), month) + _("'");
EXECUTE_SQL_UPDATE(req, );
}

View File

@ -28,6 +28,7 @@ class Database
void UpdateOperation(struct operation op);
void AddOperation(User* user, struct operation op);
void DeleteOperation(struct operation op);
void SetAccountAmount(int month, int year, wxString accountId, double amount);
private:
wxSQLite3Database _db;

View File

@ -4,6 +4,7 @@ static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, AccountPanel::OnAccountModified)
END_EVENT_TABLE()
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID)
@ -329,7 +330,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
}
else
{
_grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear));
_grid->SetCellEditor(line, DATE, new CalendarEditor(1, _curMonth, _curYear));
}
}
@ -601,3 +602,13 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
inModification = false ;
}
void AccountPanel::OnAccountModified(wxGridEvent& event)
{
User* user = _kiss->GetUser();
int row = event.GetRow();
double amount;
_accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
_kiss->SetAccountAmount(_curMonth, _curYear, user->GetAccountId(_accounts[row]), amount);
}

View File

@ -40,6 +40,7 @@ public:
void ShowMonth(int year, int month);
void OnOperationModified(wxGridEvent& event);
void OnAccountModified(wxGridEvent& event);
private:
KissCount* _kiss;

View File

@ -22,14 +22,13 @@ void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
wxGridCellEditor* CalendarEditor::Clone() const
{
std::cout << "Cloned\n" ;
return new CalendarEditor(_day, _month, _year);
}
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
_parent = parent;
_calendar->Create(parent, id, wxDateTime(_day, _month, _year));
_calendar->Create(_parent, id, wxDateTime(_day, _month, _year));
_calendar->EnableHolidayDisplay(false);
_calendar->EnableMonthChange(false);
_calendar->EnableYearChange(false);