From ac5c26bc4f304cb70371aac5206dc99008d78679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 23 Jun 2010 14:25:00 +0200 Subject: [PATCH] Month generation in progress --- controller/KissCount.cpp | 5 ++++ controller/KissCount.h | 1 + model/Database.cpp | 50 ++++++++++++++++++++++++++++++++++++ model/Database.h | 2 ++ view/AccountPanel.cpp | 53 ++++++++++++++++++++++++++++++++++++++- view/AccountPanel.h | 2 ++ view/PreferencesPanel.cpp | 10 ++++++-- view/UsersDialog.cpp | 2 +- view/wxUI.h | 1 + 9 files changed, 122 insertions(+), 4 deletions(-) diff --git a/controller/KissCount.cpp b/controller/KissCount.cpp index 97880ef..8ce843f 100644 --- a/controller/KissCount.cpp +++ b/controller/KissCount.cpp @@ -137,3 +137,8 @@ void KissCount::DeleteCategory(struct category category) { _db->DeleteCategory(_user, category); } + +std::map > KissCount::GetAllOperations() +{ + return _db->GetAllOperations(_user); +} diff --git a/controller/KissCount.h b/controller/KissCount.h index 2480f38..dd059a8 100644 --- a/controller/KissCount.h +++ b/controller/KissCount.h @@ -36,6 +36,7 @@ class KissCount void UpdateCategory(wxString oldName, struct category category); void DeleteCategory(struct category category); + std::map > GetAllOperations(); private: wxUI* _wxUI; Database* _db; diff --git a/model/Database.cpp b/model/Database.cpp index e450da9..b4e2e8b 100644 --- a/model/Database.cpp +++ b/model/Database.cpp @@ -555,3 +555,53 @@ void Database::DeleteCategory(User* user, struct category category) EXECUTE_SQL_UPDATE(req, ); } + +std::map > Database::GetAllOperations(User* user) +{ + wxString req; + wxSQLite3ResultSet set, set2; + std::vector::iterator it; + std::map > res; + int year; + + if (!user->_accounts.empty()) + { + it = user->_accounts.begin(); + req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) + { + req += _("', '") + it->id ; + } + req += _("') ORDER BY year ASC"); + + EXECUTE_SQL_QUERY(req, set, res); + + while (set.NextRow()) + { + year = set.GetInt(_("year")); + + it = user->_accounts.begin(); + req = _("SELECT DISTINCT month FROM account_amount WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) + { + req += _("', '") + it->id ; + } + req += _("')"); + req += _(" AND year='") + set.GetAsString(_("year")) + _("'"); + req += _(" ORDER BY month ASC"); + + EXECUTE_SQL_QUERY(req, set2, res); + + while (set2.NextRow()) + { + res[year].push_back(set2.GetInt(_("month"))); + } + set2.Finalize(); + } + set.Finalize(); + } + + return res; +} diff --git a/model/Database.h b/model/Database.h index fcf1727..e6e2c6f 100644 --- a/model/Database.h +++ b/model/Database.h @@ -38,6 +38,8 @@ class Database void UpdateCategory(User* user, wxString oldName, wxString name, wxString color); void DeleteCategory(User* user, struct category category); + std::map > GetAllOperations(User* user); + private: wxSQLite3Database _db; diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 5a635f3..e66792f 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -3,7 +3,7 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS}; enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS}; enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS}; -enum {CALENDAR_TREE_ID=10, OPS_GRID_ID, ACCOUNTS_GRID_ID}; +enum {CALENDAR_TREE_ID=10, OPS_GRID_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID}; static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _(""), _("")}; @@ -13,6 +13,8 @@ BEGIN_EVENT_TABLE(AccountPanel, wxPanel) EVT_TREE_ITEM_RIGHT_CLICK(CALENDAR_TREE_ID, AccountPanel::OnTreeRightClick) EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange) EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange) + EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate) + EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete) END_EVENT_TABLE() AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT) @@ -781,6 +783,14 @@ void AccountPanel::OnAccountModified(wxGridEvent& event) void AccountPanel::OnTreeRightClick(wxTreeEvent& event) { // ShowMonth(2010,4); + wxMenu menu(0); + + menu.Append(MENU_GENERATE_ID, _("Generate month")); + menu.AppendSeparator(); + if (_tree.GetCount() > 1) + menu.Append(MENU_DELETE_ID, _("Delete")); + + PopupMenu(&menu, event.GetPoint()); } void AccountPanel::OnTreeChange(wxTreeEvent& event) @@ -842,3 +852,44 @@ void AccountPanel::OnTreeChange(wxTreeEvent& event) inModification = false; } + +void AccountPanel::OnMenuGenerate(wxCommandEvent& event) +{ + wxString monthString; + int month, year, i; + + month = year = -1; + + monthString = _tree.GetItemText(_tree.GetSelection()); + for (i=0; i<12; i++) + if (monthString == months[i]) + { + month = i; + break; + } + + if (month == -1) + { + year = wxAtoi(monthString); + + // Error + if (year == 0) + return; + } + else + { + year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(_tree.GetSelection()))); + + // Error + if (year == 0) + return; + } + + GenerateDialog g(_kiss, _wxUI, month, year); + g.ShowModal(); +} + +void AccountPanel::OnMenuDelete(wxCommandEvent& event) +{ + +} diff --git a/view/AccountPanel.h b/view/AccountPanel.h index 0846cbd..f81e320 100644 --- a/view/AccountPanel.h +++ b/view/AccountPanel.h @@ -41,6 +41,8 @@ public: void OnAccountModified(wxGridEvent& event); void OnTreeRightClick(wxTreeEvent& event); void OnTreeChange(wxTreeEvent& event); + void OnMenuGenerate(wxCommandEvent& event); + void OnMenuDelete(wxCommandEvent& event); private: KissCount* _kiss; diff --git a/view/PreferencesPanel.cpp b/view/PreferencesPanel.cpp index 1073bd8..aaf1bc2 100644 --- a/view/PreferencesPanel.cpp +++ b/view/PreferencesPanel.cpp @@ -268,8 +268,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) if (user->GetAccountId(new_account.name) != _("0")) { - wxMessageDialog dialog(_wxUI, _("Account ")+new_account.name+_(" already exists"), _("Error"), wxOK); - dialog.ShowModal(); + wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); inModification = false; return ; } @@ -363,6 +362,13 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) return ; } + if (user->GetCategoryId(new_cat.name) != _("0")) + { + wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + inModification = false; + return ; + } + _kiss->AddCategory(new_cat); _categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, false); _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); diff --git a/view/UsersDialog.cpp b/view/UsersDialog.cpp index 5e59c4e..b078f09 100644 --- a/view/UsersDialog.cpp +++ b/view/UsersDialog.cpp @@ -44,11 +44,11 @@ UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), - vbox->Add(-1, 40); vbox->Add(hbox1, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10); - Center(); SetSizer(vbox); _users->SetFocus(); Layout(); + Center(); } void UsersDialog::OnOK(wxCommandEvent& event) diff --git a/view/wxUI.h b/view/wxUI.h index 34b4fba..6f8161c 100644 --- a/view/wxUI.h +++ b/view/wxUI.h @@ -6,6 +6,7 @@ #include "ButtonPanel.h" #include "PreferencesPanel.h" #include "UsersDialog.h" +#include "GenerateDialog.h" #include class KissCount;