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

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

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();
}