Add some verification to SearchPanel & wxID_ANY in place of -1

This commit is contained in:
Grégory Soutadé 2010-07-14 18:56:07 +02:00
parent d248b848b4
commit 5286926588
9 changed files with 96 additions and 60 deletions

View File

@ -1024,15 +1024,15 @@ std::vector<Operation>* 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);

View File

@ -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")));

View File

@ -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));

View File

@ -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);

View File

@ -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));

View File

@ -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);

View File

@ -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<wxString> categories, accounts;
wxDateTime *dateFrom=NULL, *dateTo=NULL, *dateTmp;
wxDateTime *dateFrom=NULL, *dateTo=NULL;
User* user= _kiss->GetUser();
int i;
std::vector<Operation>::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; i<user->GetCategoriesNumber(); 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; i<user->GetCategoriesNumber(); i++)
if (_category->IsChecked(i))
categories.push_back(user->_categories[i].id);
}
if (_checkAccount->IsChecked())
{
for(i=0; i<user->GetAccountsNumber(); i++)
if (_account->IsChecked(i))
accounts.push_back(user->_accounts[i].id);
}
for(i=0; i<user->GetAccountsNumber(); 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();
}

View File

@ -53,7 +53,7 @@ class SearchPanel: public wxScrolledWindow
std::vector<Operation> *_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;

View File

@ -22,7 +22,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
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);