From 52869265886067b5be2a88b33de8590ddad13ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 14 Jul 2010 18:56:07 +0200 Subject: [PATCH] Add some verification to SearchPanel & wxID_ANY in place of -1 --- src/model/Database.cpp | 12 ++-- src/view/AccountPanel.cpp | 2 +- src/view/GenerateDialog.cpp | 6 +- src/view/GridAccount.cpp | 4 +- src/view/PasswordDialog.cpp | 8 +-- src/view/PreferencesPanel.cpp | 10 ++-- src/view/SearchPanel.cpp | 110 ++++++++++++++++++++++------------ src/view/SearchPanel.h | 2 +- src/view/wxUI.cpp | 2 +- 9 files changed, 96 insertions(+), 60 deletions(-) diff --git a/src/model/Database.cpp b/src/model/Database.cpp index f93a4dc..4a9d5f7 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1024,15 +1024,15 @@ std::vector* Database::Search(User* user, wxString* description, wxDa op.checked = set.GetBool(wxT("checked")); if (dateFrom && - op.month == dateFrom->GetMonth() && - op.year == dateFrom->GetYear() && - op.day < dateFrom->GetDay()-1) + (int)op.month == dateFrom->GetMonth() && + (int)op.year == dateFrom->GetYear() && + (int)op.day < dateFrom->GetDay()-1) continue; if (dateTo && - op.month == dateTo->GetMonth() && - op.year == dateTo->GetYear() && - op.day > dateTo->GetDay()-1) + (int)op.month == dateTo->GetMonth() && + (int)op.year == dateTo->GetYear() && + (int)op.day > dateTo->GetDay()-1) continue; res->push_back(op); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index bffa20f..ea41bda 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -117,7 +117,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(* _accountsGrid->AutoSizeColumns(true); - _statsGrid = new wxGrid(this, -1); + _statsGrid = new wxGrid(this, wxID_ANY); chart = new wxChartPanel(this); chart->SetChart(new Chart(_pie, _("Cost repartition"))); diff --git a/src/view/GenerateDialog.cpp b/src/view/GenerateDialog.cpp index 2392f3f..28bf025 100644 --- a/src/view/GenerateDialog.cpp +++ b/src/view/GenerateDialog.cpp @@ -28,7 +28,7 @@ EVT_CHOICE(YEAR_FROM_ID, GenerateDialog::OnYearFromChange) EVT_CHOICE(YEAR_TO_ID, GenerateDialog::OnYearToChange) END_EVENT_TABLE() -GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), -1, _("Generate month")), _kiss(kiss), _wxUI(parent) +GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), wxID_ANY, _("Generate month")), _kiss(kiss), _wxUI(parent) { wxGridBagSizer *gridBagSizer; wxStaticText* label; @@ -42,14 +42,14 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea gridBagSizer = new wxGridBagSizer(4, 5); - label = new wxStaticText(this, -1, _("From ")); + label = new wxStaticText(this, wxID_ANY, _("From ")); gridBagSizer->Add(label, wxGBPosition(0, 0)); _yearFrom = new wxChoice(this, YEAR_FROM_ID); gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1)); _monthFrom = new wxChoice(this, MONTH_FROM_ID); gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2)); - label = new wxStaticText(this, -1, _("To ")); + label = new wxStaticText(this, wxID_ANY, _("To ")); gridBagSizer->Add(label, wxGBPosition(1, 0)); _yearTo = new wxChoice(this, YEAR_TO_ID); gridBagSizer->Add(_yearTo, wxGBPosition(1, 1)); diff --git a/src/view/GridAccount.cpp b/src/view/GridAccount.cpp index 8f4037b..7c5eb85 100644 --- a/src/view/GridAccount.cpp +++ b/src/view/GridAccount.cpp @@ -111,8 +111,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, InsertRows(line, 1); - SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2)); - SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2)); + SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2)); + SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2)); wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false); SetCellEditor(line, ACCOUNT, accountEditor); wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false); diff --git a/src/view/PasswordDialog.cpp b/src/view/PasswordDialog.cpp index da3069a..88b570a 100644 --- a/src/view/PasswordDialog.cpp +++ b/src/view/PasswordDialog.cpp @@ -26,24 +26,24 @@ EVT_BUTTON(BUTTON_OK_ID, PasswordDialog::OnOK) EVT_BUTTON(BUTTON_CANCEL_ID, PasswordDialog::OnCancel) END_EVENT_TABLE() -PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Change password")), _kiss(kiss), _wxUI(parent) +PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), wxID_ANY, _("Change password")), _kiss(kiss), _wxUI(parent) { wxGridBagSizer *gridBagSizer; wxStaticText* label; gridBagSizer = new wxGridBagSizer(5, 3); - label = new wxStaticText(this, -1, _("Old password ")); + label = new wxStaticText(this, wxID_ANY, _("Old password ")); gridBagSizer->Add(label, wxGBPosition(0, 0)); _oldPassword = new wxTextCtrl(this, OLD_PASSWORD_ID); gridBagSizer->Add(_oldPassword, wxGBPosition(0, 1)); - label = new wxStaticText(this, -1, _("New password ")); + label = new wxStaticText(this, wxID_ANY, _("New password ")); gridBagSizer->Add(label, wxGBPosition(1, 0)); _newPassword = new wxTextCtrl(this, NEW_PASSWORD_ID); gridBagSizer->Add(_newPassword, wxGBPosition(1, 1)); - label = new wxStaticText(this, -1, _("Confirm password ")); + label = new wxStaticText(this, wxID_ANY, _("Confirm password ")); gridBagSizer->Add(label, wxGBPosition(2, 0)); _confirmPassword = new wxTextCtrl(this, CONFIRM_PASSWORD_ID); gridBagSizer->Add(_confirmPassword, wxGBPosition(2, 1)); diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index 3aa6c69..ea42b04 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -47,10 +47,10 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p SetSizer(vbox); - staticUser = new wxStaticBox(this, -1, _("User")); - staticAccount = new wxStaticBox(this, -1, _("Accounts")); - staticCategories = new wxStaticBox(this, -1, _("Categories")); - staticLanguage = new wxStaticBox(this, -1, _("Language")); + staticUser = new wxStaticBox(this, wxID_ANY, _("User")); + staticAccount = new wxStaticBox(this, wxID_ANY, _("Accounts")); + staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories")); + staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language")); // User staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL); @@ -58,7 +58,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p gridBagSizer = new wxGridBagSizer(10, 10); staticBoxSizer->Add(gridBagSizer); - label = new wxStaticText(this, -1, _("Name")); + label = new wxStaticText(this, wxID_ANY, _("Name")); gridBagSizer->Add(label, wxGBPosition(0, 0)); _name = new wxTextCtrl(this, NAME_ID, user->_name); diff --git a/src/view/SearchPanel.cpp b/src/view/SearchPanel.cpp index 63f8734..5463b9b 100644 --- a/src/view/SearchPanel.cpp +++ b/src/view/SearchPanel.cpp @@ -42,13 +42,8 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*pa SetSizer(vbox); - _checkDescription = new wxCheckBox(this, wxID_ANY, _("Description")); _checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from")); _checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to")); - _checkAmountFrom = new wxCheckBox(this, wxID_ANY, _("Amount from")); - _checkAmountTo = new wxCheckBox(this, wxID_ANY, _("Amount to")); - _checkCategory = new wxCheckBox(this, wxID_ANY, _("Category")); - _checkAccount = new wxCheckBox(this, wxID_ANY, _("Account")); wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 9); @@ -74,19 +69,25 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*pa _searchButton = new wxButton(this, SEARCH_ID, _("Search")); - gridBagSizer->Add(_checkDescription, wxGBPosition(0, 0)); + wxStaticText* labelDescription = new wxStaticText(this, wxID_ANY, _("Description")); + wxStaticText* labelAmountFrom = new wxStaticText(this, wxID_ANY, _("Amount from")); + wxStaticText* labelAmountTo = new wxStaticText(this, wxID_ANY, _("Amount to")); + wxStaticText* labelCategory = new wxStaticText(this, wxID_ANY, _("Category")); + wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account")); + + gridBagSizer->Add(labelDescription, wxGBPosition(0, 0)); gridBagSizer->Add(_description, wxGBPosition(1, 0)); gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1)); gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1)); gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2)); gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2)); - gridBagSizer->Add(_checkAmountFrom, wxGBPosition(0, 3)); + gridBagSizer->Add(labelAmountFrom, wxGBPosition(0, 3)); gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3)); - gridBagSizer->Add(_checkAmountTo, wxGBPosition(0, 4)); + gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4)); gridBagSizer->Add(_amountTo, wxGBPosition(1, 4)); - gridBagSizer->Add(_checkCategory, wxGBPosition(0, 5)); + gridBagSizer->Add(labelCategory, wxGBPosition(0, 5)); gridBagSizer->Add(_category, wxGBPosition(1, 5)); - gridBagSizer->Add(_checkAccount, wxGBPosition(0, 6)); + gridBagSizer->Add(labelAccount, wxGBPosition(0, 6)); gridBagSizer->Add(_account, wxGBPosition(1, 6)); gridBagSizer->Add(_searchButton, wxGBPosition(2, 0)); @@ -114,14 +115,54 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event) { wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL; std::vector categories, accounts; - wxDateTime *dateFrom=NULL, *dateTo=NULL, *dateTmp; + wxDateTime *dateFrom=NULL, *dateTo=NULL; User* user= _kiss->GetUser(); int i; std::vector::iterator it; + double af, at; + + if (_calendarFrom->GetDate() > _calendarTo->GetDate()) + { + wxMessageBox(_("Invalide date range"), _("Error"), wxICON_ERROR | wxOK); + return; + } + + if (_amountFrom->GetLineText(0) != wxT("")) + { + amountFrom = new wxString; + *amountFrom = _amountFrom->GetLineText(0); + if (!amountFrom->ToDouble(&af)) + { + wxMessageBox(_("Invalide amount from"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + return; + } + } + + if (_amountTo->GetLineText(0) != wxT("")) + { + amountTo = new wxString; + *amountTo = _amountTo->GetLineText(0); + if (!amountTo->ToDouble(&at)) + { + wxMessageBox(_("Invalide amount to"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + delete amountTo; + return; + } + } + + if (amountFrom && amountTo && af > at) + { + wxMessageBox(_("Invalide amount range"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + delete amountTo; + return; + } _grid->DeleteRows(1, _grid->GetNumberRows()-1); - if (_checkDescription->IsChecked()) + if (_description->GetLineText(0) != wxT("")) { description = new wxString; *description = _description->GetLineText(0); @@ -144,42 +185,37 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event) ; } - if (_checkAmountFrom->IsChecked()) - { - amountFrom = new wxString; - *amountFrom = _amountFrom->GetLineText(0); - } + for(i=0; iGetCategoriesNumber(); i++) + if (_category->IsChecked(i)) + categories.push_back(user->_categories[i].id); - if (_checkAmountTo->IsChecked()) - { - amountTo = new wxString; - *amountTo = _amountTo->GetLineText(0); - } - - if (_checkCategory->IsChecked()) - { - for(i=0; iGetCategoriesNumber(); i++) - if (_category->IsChecked(i)) - categories.push_back(user->_categories[i].id); - } - - if (_checkAccount->IsChecked()) - { - for(i=0; iGetAccountsNumber(); i++) - if (_account->IsChecked(i)) - accounts.push_back(user->_accounts[i].id); - } + for(i=0; iGetAccountsNumber(); i++) + if (_account->IsChecked(i)) + accounts.push_back(user->_accounts[i].id); if (_operations) delete _operations; _operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); - + + if (_operations->size() > 1) + wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + else if (_operations->size() == 1) + wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + else + wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++) { _grid->InsertOperation(user, &(*it), i, false, 0, 0); } + _grid->AutoSizeColumn(CATEGORY, false); + _grid->AutoSizeColumn(DATE, false); + _grid->AutoSizeColumn(ACCOUNT, false); + _grid->AutoSizeColumn(DELETE, false); + _grid->AutoSizeColumn(CHECKED, false); + _wxUI->Layout(); } diff --git a/src/view/SearchPanel.h b/src/view/SearchPanel.h index 766a472..4da55ff 100644 --- a/src/view/SearchPanel.h +++ b/src/view/SearchPanel.h @@ -53,7 +53,7 @@ class SearchPanel: public wxScrolledWindow std::vector *_operations; wxCalendarCtrl* _calendarFrom, *_calendarTo; GridAccount *_grid; - wxCheckBox *_checkDescription, *_checkDateFrom, *_checkDateTo, *_checkAmountFrom, *_checkAmountTo, *_checkCategory, *_checkAccount; + wxCheckBox *_checkDateFrom, *_checkDateTo; wxTextCtrl* _description, *_amountFrom, *_amountTo; wxCheckListBox* _category, *_account; wxButton* _searchButton; diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index 5909caa..4fc1982 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -22,7 +22,7 @@ along with KissCount. If not, see . wxString months[12] ; wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _searchPanel(NULL), _preferencesPanel(NULL), + : wxFrame(NULL, wxID_ANY, title, pos, size), _kiss(kiss), _accountPanel(NULL), _searchPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL), _locale(NULL), _needReload(false) { _hbox = new wxBoxSizer(wxVERTICAL);