2010-07-14 16:22:02 +02:00
|
|
|
/*
|
2011-02-13 19:30:12 +01:00
|
|
|
Copyright 2010-2011 Grégory Soutadé
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-14 16:22:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AccountPanel.h"
|
|
|
|
|
2011-02-13 19:30:12 +01:00
|
|
|
enum {SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID,
|
|
|
|
CHANGE_ACCOUNT_ID, CHANGE_CATEGORY_ID, RENAME_ID};
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
|
|
|
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
2010-07-16 18:38:13 +02:00
|
|
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
|
|
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
2010-07-16 19:28:36 +02:00
|
|
|
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
|
2011-02-13 19:30:12 +01:00
|
|
|
EVT_BUTTON(CHANGE_ACCOUNT_ID, SearchPanel::OnButtonChangeAccount)
|
|
|
|
EVT_BUTTON(CHANGE_CATEGORY_ID, SearchPanel::OnButtonChangeCategory)
|
|
|
|
EVT_BUTTON(RENAME_ID, SearchPanel::OnButtonRename)
|
2010-07-16 19:28:36 +02:00
|
|
|
EVT_SHOW(SearchPanel::OnShow)
|
2010-07-14 16:22:02 +02:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-09-05 12:08:48 +02:00
|
|
|
#define UNESCAPE_CHARS(s) { \
|
|
|
|
s.Replace(wxT("\\\""), wxT("\""), true); \
|
|
|
|
s.Replace(wxT("\\\'"), wxT("\'"), true); \
|
|
|
|
}
|
|
|
|
|
2010-12-15 19:13:16 +01:00
|
|
|
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(NULL)
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
DEFAULT_FONT(font);
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
std::vector<Account>::iterator accountIt;
|
|
|
|
std::vector<Category>::iterator categoryIt;
|
|
|
|
wxDateTime firstOfMonth;
|
2010-09-22 21:02:29 +02:00
|
|
|
wxRect rect = wxDisplay().GetGeometry();
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
2011-02-13 19:30:12 +01:00
|
|
|
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
SetSizer(vbox);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
|
|
|
|
_checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to"));
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom->SetValue(wxT("1"));
|
|
|
|
_checkDateTo->SetValue(wxT("1"));
|
2010-07-27 22:31:56 +02:00
|
|
|
|
2010-10-30 20:52:53 +02:00
|
|
|
wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 10);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
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);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_description = new wxTextCtrl(this, wxID_ANY);
|
|
|
|
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);
|
2011-02-09 21:36:29 +01:00
|
|
|
_category->Append(_("Unknown"));
|
2010-08-26 21:28:15 +02:00
|
|
|
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
2011-02-20 14:22:31 +01:00
|
|
|
_category->Append(wxGetTranslation(categoryIt->name));
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
wxString stypes[] = {_("Fix"), _("Non fix"), _("Checked"), _("Not checked")};
|
|
|
|
_optype = new wxCheckListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, stypes);
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_account = new wxCheckListBox(this, wxID_ANY);
|
2011-02-09 21:36:29 +01:00
|
|
|
_account->Append(_("Unknown"));
|
2010-08-26 21:28:15 +02:00
|
|
|
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"));
|
2010-12-02 19:20:04 +01:00
|
|
|
wxStaticText* labelOperations = new wxStaticText(this, wxID_ANY, _("Operations"));
|
2010-08-26 21:28:15 +02:00
|
|
|
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(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));
|
2010-12-02 19:20:04 +01:00
|
|
|
gridBagSizer->Add(labelOperations, wxGBPosition(0, 6));
|
2010-12-01 20:30:34 +01:00
|
|
|
gridBagSizer->Add(_optype, wxGBPosition(1, 6));
|
2010-10-30 20:52:53 +02:00
|
|
|
gridBagSizer->Add(labelAccount, wxGBPosition(0, 7));
|
|
|
|
gridBagSizer->Add(_account, wxGBPosition(1, 7));
|
2010-08-26 21:28:15 +02:00
|
|
|
gridBagSizer->Add(_searchButton, wxGBPosition(2, 0));
|
|
|
|
|
2010-12-11 09:51:44 +01:00
|
|
|
vbox->Add(gridBagSizer, 0, wxGROW|wxALL, 5);
|
2010-08-26 21:28:15 +02:00
|
|
|
|
2011-03-13 19:22:17 +01:00
|
|
|
_grid = new GridAccount(_kiss, this, GRID_ID, false, false, true);
|
2010-08-26 21:28:15 +02:00
|
|
|
|
2011-02-13 19:30:12 +01:00
|
|
|
hbox->Add(_grid, 0, wxGROW|wxALL, 5);
|
|
|
|
|
|
|
|
_changeAccountButton = new wxButton(this, CHANGE_ACCOUNT_ID, _("Change account"));
|
|
|
|
_changeCategoryButton = new wxButton(this, CHANGE_CATEGORY_ID, _("Change category"));
|
|
|
|
_renameButton = new wxButton(this, RENAME_ID, _("Rename"));
|
|
|
|
|
|
|
|
vbox2->Add(_changeAccountButton, wxALL, 15);
|
|
|
|
vbox2->Add(_changeCategoryButton, wxALL, 15);
|
|
|
|
vbox2->Add(_renameButton, wxALL, 15);
|
|
|
|
|
|
|
|
hbox->Add(vbox2, 0, wxALL, 15);
|
|
|
|
|
|
|
|
vbox->Add(hbox, 0, wxGROW|wxALL, 5);
|
2010-08-26 21:28:15 +02:00
|
|
|
|
|
|
|
Fit();
|
|
|
|
|
2010-12-11 09:51:44 +01:00
|
|
|
SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
|
2011-01-29 12:02:49 +01:00
|
|
|
SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
|
2010-08-26 21:28:15 +02:00
|
|
|
SetScrollbars(10, 10, 100/10, 100/10);
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchPanel::~SearchPanel()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_operations) delete _operations;
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-12-15 19:13:16 +01:00
|
|
|
KissPanel* SearchPanel::CreatePanel()
|
|
|
|
{
|
|
|
|
return new SearchPanel(_kiss, _wxUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBitmapButton* SearchPanel::GetButton(int id)
|
|
|
|
{
|
|
|
|
if (!_KissButton)
|
2011-02-05 21:02:03 +01:00
|
|
|
_KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(SEARCH_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128));
|
2010-12-15 19:13:16 +01:00
|
|
|
|
|
|
|
return _KissButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString SearchPanel::GetToolTip()
|
|
|
|
{
|
|
|
|
return _("Search");
|
|
|
|
}
|
|
|
|
|
2011-02-13 19:30:12 +01:00
|
|
|
void SearchPanel::Search()
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL;
|
|
|
|
std::vector<wxString> categories, accounts;
|
|
|
|
wxDateTime *dateFrom=NULL, *dateTo=NULL;
|
|
|
|
User* user= _kiss->GetUser();
|
2010-12-01 20:30:34 +01:00
|
|
|
int i, types=0;
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
double af, at;
|
|
|
|
|
|
|
|
if (_calendarFrom->GetDate() > _calendarTo->GetDate())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_amountFrom->GetLineText(0).Length())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
amountFrom = new wxString;
|
|
|
|
*amountFrom = _amountFrom->GetLineText(0);
|
|
|
|
if (!amountFrom->ToDouble(&af))
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-26 21:03:22 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (af < 0) af *= -1;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_amountTo->GetLineText(0).Length())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
amountTo = new wxString;
|
|
|
|
*amountTo = _amountTo->GetLineText(0);
|
|
|
|
if (!amountTo->ToDouble(&at))
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
delete amountTo;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-26 21:03:22 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (at < 0) at *= -1;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (amountFrom && amountTo && af > at)
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
delete amountTo;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_description->GetLineText(0).Length())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
description = new wxString;
|
|
|
|
*description = _description->GetLineText(0);
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_checkDateFrom->IsChecked())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
dateFrom = new wxDateTime;
|
|
|
|
*dateFrom = _calendarFrom->GetDate();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_checkDateTo->IsChecked())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
dateTo = new wxDateTime;
|
|
|
|
*dateTo = _calendarTo->GetDate();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (dateFrom && dateTo && *dateFrom > *dateTo)
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
;
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for(i=0; i<user->GetCategoriesNumber(); i++)
|
|
|
|
if (_category->IsChecked(i))
|
2011-02-10 20:04:33 +01:00
|
|
|
categories.push_back((i) ? user->_categories[i-1].id : wxT("0"));
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
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;
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for(i=0; i<user->GetAccountsNumber(); i++)
|
|
|
|
if (_account->IsChecked(i))
|
2011-02-10 20:04:33 +01:00
|
|
|
accounts.push_back((i) ? user->_accounts[i-1].id : wxT("0"));
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_operations)
|
|
|
|
delete _operations;
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
|
2011-02-13 19:30:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
Search();
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
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
|
2010-07-17 12:33:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
|
|
|
return;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2011-03-13 19:22:17 +01:00
|
|
|
_grid->LoadOperations(_operations, 0, 0);
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->Layout();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2011-02-13 19:30:12 +01:00
|
|
|
static void ChangeAccount(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
wxString* account = (wxString*) params[0];
|
|
|
|
|
|
|
|
op->account = *account;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonChangeAccount(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int i, a;
|
|
|
|
std::vector<int> rows;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
wxString *accounts = new wxString[user->GetAccountsNumber()+1];
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
wxString account;
|
|
|
|
void * params[] = {&account};
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
accounts[0] = _("None");
|
|
|
|
a = 0;
|
|
|
|
for(i=0; i < user->GetAccountsNumber(); i++)
|
|
|
|
accounts[++a] = user->_accounts[i].name;
|
|
|
|
|
|
|
|
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new account"), wxT("KissCount"), user->GetAccountsNumber()+1, accounts);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_CANCEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
a = dialog.GetSelection();
|
|
|
|
account = (a) ? user->_accounts[a-1].id : wxT("0");
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, ChangeAccount, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeCategory(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
wxString* category = (wxString*) params[0];
|
|
|
|
bool* fix = (bool*) params[1];
|
|
|
|
|
|
|
|
op->category = *category;
|
|
|
|
op->fix_cost = * fix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonChangeCategory(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int i, a;
|
|
|
|
std::vector<int> rows;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
wxString *categories = new wxString[user->GetCategoriesNumber()+1];
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
wxString category;
|
|
|
|
bool fix;
|
|
|
|
void * params[] = {&category, &fix};
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
categories[0] = _("None");
|
|
|
|
a = 0;
|
|
|
|
for(i=0; i < user->GetCategoriesNumber(); i++)
|
|
|
|
categories[++a] = user->_categories[i].name;
|
|
|
|
|
|
|
|
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new category"), wxT("KissCount"), user->GetCategoriesNumber()+1, categories);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() == wxID_CANCEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
a = dialog.GetSelection();
|
|
|
|
|
|
|
|
if (a)
|
|
|
|
{
|
|
|
|
category = user->_categories[a-1].id ;
|
|
|
|
fix = user->_categories[a-1].fix_cost;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
category = wxT("0");
|
|
|
|
fix = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, ChangeCategory, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeName(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
wxString* description = (wxString*) params[0];
|
|
|
|
|
|
|
|
op->description = *description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonRename(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
std::vector<int> rows;
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
wxString category;
|
|
|
|
wxString description;
|
|
|
|
void * params[] = {&description};
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
wxTextEntryDialog u(this, wxT(""), _("Enter a new description"));
|
|
|
|
|
|
|
|
if (u.ShowModal() == wxID_CANCEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
description = u.GetValue();
|
|
|
|
|
|
|
|
if (!description.size()) return;
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, ChangeName, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
2010-07-14 16:22:02 +02:00
|
|
|
void SearchPanel::OnShow(wxShowEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search"));
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 18:38:13 +02:00
|
|
|
void SearchPanel::OnCalendarFromChange(wxCalendarEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom->SetValue(true);
|
2010-07-16 18:38:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnCalendarToChange(wxCalendarEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateTo->SetValue(true);
|
2010-07-16 18:38:13 +02:00
|
|
|
}
|
2010-07-16 19:28:36 +02:00
|
|
|
|
|
|
|
void SearchPanel::OnOperationModified(wxGridEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->NeedReload();
|
2010-07-16 19:28:36 +02:00
|
|
|
}
|