Some modification where not commited previously ???
This commit is contained in:
@@ -19,30 +19,21 @@
|
||||
|
||||
#include "AccountPanel.h"
|
||||
|
||||
enum {DESCRIPTION_ID=1, SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID,
|
||||
enum {SEARCH_ID=1, GRID_ID,
|
||||
CHANGE_ACCOUNT_ID, CHANGE_CATEGORY_ID, RENAME_ID};
|
||||
|
||||
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
||||
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
||||
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
|
||||
EVT_BUTTON(CHANGE_ACCOUNT_ID, SearchPanel::OnButtonChangeAccount)
|
||||
EVT_BUTTON(CHANGE_CATEGORY_ID, SearchPanel::OnButtonChangeCategory)
|
||||
EVT_BUTTON(RENAME_ID, SearchPanel::OnButtonRename)
|
||||
EVT_SHOW(SearchPanel::OnShow)
|
||||
EVT_TEXT_ENTER(DESCRIPTION_ID, SearchPanel::OnEnter)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
#define UNESCAPE_CHARS(s) { \
|
||||
s.Replace(wxT("\\\""), wxT("\""), true); \
|
||||
s.Replace(wxT("\\\'"), wxT("\'"), true); \
|
||||
}
|
||||
|
||||
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(NULL)
|
||||
{
|
||||
DEFAULT_FONT(font);
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
wxDateTime firstOfMonth;
|
||||
@@ -53,72 +44,13 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
SetSizer(vbox);
|
||||
|
||||
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
|
||||
_checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to"));
|
||||
|
||||
_checkDateFrom->SetValue(wxT("1"));
|
||||
_checkDateTo->SetValue(wxT("1"));
|
||||
|
||||
wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 10);
|
||||
|
||||
firstOfMonth.SetToCurrent();
|
||||
firstOfMonth.SetDay(1);
|
||||
_calendarFrom = new wxCalendarCtrl(this, CALENDAR_FROM_ID, firstOfMonth, wxDefaultPosition, wxDefaultSize,
|
||||
wxCAL_MONDAY_FIRST);
|
||||
_calendarTo = new wxCalendarCtrl(this, CALENDAR_TO_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
||||
wxCAL_MONDAY_FIRST);
|
||||
|
||||
|
||||
_description = new wxTextCtrl(this, DESCRIPTION_ID);
|
||||
_description->SetWindowStyle(_description->GetWindowStyle() | wxTE_PROCESS_ENTER);
|
||||
wxSize size = _description->GetSize();
|
||||
size.SetWidth(size.GetWidth()*2);
|
||||
_description->SetMinSize(size);
|
||||
_amountFrom = new wxTextCtrl(this, wxID_ANY);
|
||||
_amountTo = new wxTextCtrl(this, wxID_ANY);
|
||||
|
||||
_category = new wxCheckListBox(this, wxID_ANY);
|
||||
_category->Append(_("Unknown"));
|
||||
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
||||
_category->Append(wxGetTranslation(categoryIt->name));
|
||||
|
||||
wxString stypes[] = {_("Fix"), _("Non fix"), _("Checked"), _("Not checked")};
|
||||
_optype = new wxCheckListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, stypes);
|
||||
|
||||
_account = new wxCheckListBox(this, wxID_ANY);
|
||||
_account->Append(_("Unknown"));
|
||||
for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
|
||||
_account->Append(accountIt->name);
|
||||
|
||||
_searchButton = new wxButton(this, SEARCH_ID, _("Search"));
|
||||
|
||||
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* labelOperations = new wxStaticText(this, wxID_ANY, _("Operations"));
|
||||
wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account"));
|
||||
_banner = new SearchBanner(kiss, this, this, OnEnter);
|
||||
|
||||
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(labelAmountFrom, wxGBPosition(0, 3));
|
||||
gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3));
|
||||
gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4));
|
||||
gridBagSizer->Add(_amountTo, wxGBPosition(1, 4));
|
||||
gridBagSizer->Add(labelCategory, wxGBPosition(0, 5));
|
||||
gridBagSizer->Add(_category, wxGBPosition(1, 5));
|
||||
gridBagSizer->Add(labelOperations, wxGBPosition(0, 6));
|
||||
gridBagSizer->Add(_optype, wxGBPosition(1, 6));
|
||||
gridBagSizer->Add(labelAccount, wxGBPosition(0, 7));
|
||||
gridBagSizer->Add(_account, wxGBPosition(1, 7));
|
||||
gridBagSizer->Add(_searchButton, wxGBPosition(2, 0));
|
||||
|
||||
vbox->Add(gridBagSizer, 0, wxGROW|wxALL, 5);
|
||||
vbox->Add(_banner, 0, wxGROW|wxALL, 5);
|
||||
vbox->Add(_searchButton, 0, wxALL, 5);
|
||||
|
||||
_grid = new GridAccount(_kiss, this, GRID_ID, false, false, true);
|
||||
|
||||
@@ -145,7 +77,6 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
|
||||
SearchPanel::~SearchPanel()
|
||||
{
|
||||
if (_operations) delete _operations;
|
||||
}
|
||||
|
||||
KissPanel* SearchPanel::CreatePanel()
|
||||
@@ -166,111 +97,18 @@ wxString SearchPanel::GetToolTip()
|
||||
return _("Search");
|
||||
}
|
||||
|
||||
void SearchPanel::Search()
|
||||
void SearchPanel::OnEnter(void* caller, wxCommandEvent& event)
|
||||
{
|
||||
wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL;
|
||||
std::vector<wxString> categories, accounts;
|
||||
wxDateTime *dateFrom=NULL, *dateTo=NULL;
|
||||
User* user= _kiss->GetUser();
|
||||
int i, types=0;
|
||||
std::vector<Operation>::iterator it;
|
||||
double af, at;
|
||||
SearchPanel* _this = (SearchPanel*) caller;
|
||||
|
||||
if (_calendarFrom->GetDate() > _calendarTo->GetDate())
|
||||
{
|
||||
wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_amountFrom->GetLineText(0).Length())
|
||||
{
|
||||
amountFrom = new wxString;
|
||||
*amountFrom = _amountFrom->GetLineText(0);
|
||||
if (!amountFrom->ToDouble(&af))
|
||||
{
|
||||
wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK);
|
||||
delete amountFrom;
|
||||
return;
|
||||
}
|
||||
|
||||
if (af < 0) af *= -1;
|
||||
}
|
||||
|
||||
if (_amountTo->GetLineText(0).Length())
|
||||
{
|
||||
amountTo = new wxString;
|
||||
*amountTo = _amountTo->GetLineText(0);
|
||||
if (!amountTo->ToDouble(&at))
|
||||
{
|
||||
wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK);
|
||||
delete amountFrom;
|
||||
delete amountTo;
|
||||
return;
|
||||
}
|
||||
|
||||
if (at < 0) at *= -1;
|
||||
}
|
||||
|
||||
if (amountFrom && amountTo && af > at)
|
||||
{
|
||||
wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK);
|
||||
delete amountFrom;
|
||||
delete amountTo;
|
||||
return;
|
||||
}
|
||||
|
||||
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
||||
|
||||
if (_description->GetLineText(0).Length())
|
||||
{
|
||||
description = new wxString;
|
||||
*description = _description->GetLineText(0);
|
||||
}
|
||||
|
||||
if (_checkDateFrom->IsChecked())
|
||||
{
|
||||
dateFrom = new wxDateTime;
|
||||
*dateFrom = _calendarFrom->GetDate();
|
||||
}
|
||||
|
||||
if (_checkDateTo->IsChecked())
|
||||
{
|
||||
dateTo = new wxDateTime;
|
||||
*dateTo = _calendarTo->GetDate();
|
||||
}
|
||||
|
||||
if (dateFrom && dateTo && *dateFrom > *dateTo)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||
if (_category->IsChecked(i))
|
||||
categories.push_back((i) ? user->_categories[i-1].id : wxT("0"));
|
||||
|
||||
types |= (_optype->IsChecked(0)) ? FIX_OP : 0;
|
||||
types |= (_optype->IsChecked(1)) ? NON_FIX_OP : 0;
|
||||
types |= (_optype->IsChecked(2)) ? CHECKED_OP : 0;
|
||||
types |= (_optype->IsChecked(3)) ? NOT_CHECKED_OP : 0;
|
||||
|
||||
for(i=0; i<user->GetAccountsNumber(); i++)
|
||||
if (_account->IsChecked(i))
|
||||
accounts.push_back((i) ? user->_accounts[i-1].id : wxT("0"));
|
||||
|
||||
if (_operations)
|
||||
delete _operations;
|
||||
|
||||
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
|
||||
}
|
||||
|
||||
void SearchPanel::OnEnter(wxCommandEvent& event)
|
||||
{
|
||||
OnButtonSearch(event);
|
||||
_this->OnButtonSearch(event);
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
{
|
||||
Search();
|
||||
_operations = _banner->Search();
|
||||
|
||||
if (!_operations) return;
|
||||
|
||||
if (_operations->size() > 1)
|
||||
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
||||
@@ -416,16 +254,6 @@ void SearchPanel::OnShow(wxShowEvent& event)
|
||||
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search"));
|
||||
}
|
||||
|
||||
void SearchPanel::OnCalendarFromChange(wxCalendarEvent& event)
|
||||
{
|
||||
_checkDateFrom->SetValue(true);
|
||||
}
|
||||
|
||||
void SearchPanel::OnCalendarToChange(wxCalendarEvent& event)
|
||||
{
|
||||
_checkDateTo->SetValue(true);
|
||||
}
|
||||
|
||||
void SearchPanel::OnOperationModified(wxGridEvent& event)
|
||||
{
|
||||
_wxUI->NeedReload();
|
||||
|
||||
Reference in New Issue
Block a user