Some optimizations on empty wxString comparison and on Search (Database)
This commit is contained in:
parent
3802460429
commit
d12e00c6fb
|
@ -1030,6 +1030,23 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
|
||||||
std::vector<wxString>::iterator it;
|
std::vector<wxString>::iterator it;
|
||||||
std::vector<Account>::iterator accountIt;
|
std::vector<Account>::iterator accountIt;
|
||||||
std::vector<Operation>* res = new std::vector<Operation>;
|
std::vector<Operation>* res = new std::vector<Operation>;
|
||||||
|
|
||||||
|
wxString dayFrom, monthFrom, yearFrom;
|
||||||
|
wxString dayTo, monthTo, yearTo;
|
||||||
|
|
||||||
|
if (dateFrom)
|
||||||
|
{
|
||||||
|
dayFrom = wxString::Format(wxT("%d"), dateFrom->GetDay()-1);
|
||||||
|
monthFrom = wxString::Format(wxT("%d"), dateFrom->GetMonth());
|
||||||
|
yearFrom = wxString::Format(wxT("%d"), dateFrom->GetYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateTo)
|
||||||
|
{
|
||||||
|
dayTo = wxString::Format(wxT("%d"), dateTo->GetDay()-1);
|
||||||
|
monthTo = wxString::Format(wxT("%d"), dateTo->GetMonth());
|
||||||
|
yearTo = wxString::Format(wxT("%d"), dateTo->GetYear());
|
||||||
|
}
|
||||||
|
|
||||||
req = wxT("SELECT * from operation WHERE ");
|
req = wxT("SELECT * from operation WHERE ");
|
||||||
|
|
||||||
|
@ -1043,9 +1060,8 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
|
||||||
{
|
{
|
||||||
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
|
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
|
||||||
req += wxT("(");
|
req += wxT("(");
|
||||||
req += wxT(" year >= '") + wxString::Format(wxT("%d"), dateFrom->GetYear()) + wxT("'");
|
req += wxT("year >= ") + yearFrom ;
|
||||||
//req += wxT(" AND month >= '") + wxString::Format(wxT("%d"), dateFrom->GetMonth()) + wxT("'");
|
req += wxT(" AND (month > '") + monthFrom + wxT("' OR (month == '") + monthFrom + wxT("' AND day >= '") + dayFrom + wxT("'))");
|
||||||
// req += wxT(" AND day >= '") + wxString::Format(wxT("%d"), dateFrom->GetDay()) + wxT("'");
|
|
||||||
req += wxT(")");
|
req += wxT(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1053,9 +1069,8 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
|
||||||
{
|
{
|
||||||
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
|
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
|
||||||
req += wxT("(");
|
req += wxT("(");
|
||||||
req += wxT(" year <= '") + wxString::Format(wxT("%d"), dateTo->GetYear()) + wxT("'");
|
req += wxT("year <= ") + yearTo ;
|
||||||
//req += wxT(" AND month <= '") + wxString::Format(wxT("%d"), dateTo->GetMonth()) + wxT("'");
|
req += wxT(" AND (month < '") + monthTo + wxT("' OR (month == '") + monthTo + wxT("' AND day <= '") + dayTo + wxT("'))");
|
||||||
// req += wxT(" AND day <= '") + wxString::Format(wxT("%d"), dateTo->GetDay()) + wxT("'");
|
|
||||||
req += wxT(")");
|
req += wxT(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,19 +1149,6 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
|
||||||
op.category = set.GetAsString(wxT("category"));
|
op.category = set.GetAsString(wxT("category"));
|
||||||
op.fix_cost = set.GetBool(wxT("fix_cost"));
|
op.fix_cost = set.GetBool(wxT("fix_cost"));
|
||||||
op.checked = set.GetBool(wxT("checked"));
|
op.checked = set.GetBool(wxT("checked"));
|
||||||
|
|
||||||
if (dateFrom &&
|
|
||||||
(int)op.year == dateFrom->GetYear() &&
|
|
||||||
(int)op.month <= dateFrom->GetMonth() &&
|
|
||||||
(int)op.day < dateFrom->GetDay()-1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (dateTo &&
|
|
||||||
(int)op.year == dateTo->GetYear() &&
|
|
||||||
(int)op.month >= dateTo->GetMonth() &&
|
|
||||||
(int)op.day > dateTo->GetDay()-1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
res->push_back(op);
|
res->push_back(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ wxLanguage User::GetLanguage()
|
||||||
wxString res = _preferences[wxT("language")];
|
wxString res = _preferences[wxT("language")];
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (res == wxT(""))
|
if (!res.Length())
|
||||||
return wxLANGUAGE_ENGLISH ;
|
return wxLANGUAGE_ENGLISH ;
|
||||||
|
|
||||||
res.ToLong(&val);
|
res.ToLong(&val);
|
||||||
|
|
|
@ -536,14 +536,14 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
||||||
_grid->SetCellValue(event.GetRow(), DEBIT, wxT(""));
|
_grid->SetCellValue(event.GetRow(), DEBIT, wxT(""));
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
|
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.description = value;
|
new_op.description = value;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DATE);
|
value = _grid->GetCellValue(event.GetRow(), DATE);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
date.ParseFormat(value, wxT("%d/%m/%Y"));
|
date.ParseFormat(value, wxT("%d/%m/%Y"));
|
||||||
new_op.day = date.GetDay()-1;
|
new_op.day = date.GetDay()-1;
|
||||||
|
@ -553,7 +553,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DEBIT);
|
value = _grid->GetCellValue(event.GetRow(), DEBIT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
new_op.amount *= -1.0;
|
new_op.amount *= -1.0;
|
||||||
|
@ -561,36 +561,36 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.category = user->GetCategoryId(value);
|
new_op.category = user->GetCategoryId(value);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.account = user->GetAccountId(value);
|
new_op.account = user->GetAccountId(value);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
||||||
if (value != wxT("") && value != wxT("0"))
|
if (value.Length() && value != wxT("0"))
|
||||||
new_op.checked = true;
|
new_op.checked = true;
|
||||||
else
|
else
|
||||||
new_op.checked = false;
|
new_op.checked = false;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
|
|
||||||
if (event.GetCol() == DESCRIPTION &&
|
if (event.GetCol() == DESCRIPTION &&
|
||||||
_grid->GetCellValue(event.GetRow(), CATEGORY) == wxT("") &&
|
(!_grid->GetCellValue(event.GetRow(), CATEGORY).Length() ||
|
||||||
_grid->GetCellValue(event.GetRow(), ACCOUNT) == wxT(""))
|
!_grid->GetCellValue(event.GetRow(), ACCOUNT).Length()))
|
||||||
{
|
{
|
||||||
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear))
|
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear))
|
||||||
{
|
{
|
||||||
|
|
|
@ -146,7 +146,7 @@ void GenerateDialog::OnYearFromChange(wxCommandEvent& event)
|
||||||
|
|
||||||
_monthFrom->Clear();
|
_monthFrom->Clear();
|
||||||
|
|
||||||
if (years == wxT(""))
|
if (!years.Length())
|
||||||
{
|
{
|
||||||
_monthFrom->Append(wxT(""));
|
_monthFrom->Append(wxT(""));
|
||||||
return;
|
return;
|
||||||
|
@ -193,7 +193,7 @@ void GenerateDialog::OnOK(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
int monthFrom, yearFrom, monthTo, yearTo, i;
|
int monthFrom, yearFrom, monthTo, yearTo, i;
|
||||||
|
|
||||||
if (_yearFrom->GetString(_yearFrom->GetCurrentSelection()) == wxT(""))
|
if (!_yearFrom->GetString(_yearFrom->GetCurrentSelection()).Length())
|
||||||
{
|
{
|
||||||
monthFrom = -1;
|
monthFrom = -1;
|
||||||
yearFrom = -1;
|
yearFrom = -1;
|
||||||
|
|
|
@ -277,27 +277,27 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
|
||||||
inModification = true;
|
inModification = true;
|
||||||
|
|
||||||
value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME);
|
value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_account.name = value;
|
new_account.name = value;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER);
|
value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_account.number = value;
|
new_account.number = value;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED);
|
value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED);
|
||||||
if (value != wxT("") && value != wxT("0"))
|
if (value.Length() && value != wxT("0"))
|
||||||
new_account.shared = true;
|
new_account.shared = true;
|
||||||
else
|
else
|
||||||
new_account.shared = false;
|
new_account.shared = false;
|
||||||
|
|
||||||
value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT);
|
value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT);
|
||||||
if (value != wxT("") && value != wxT("0"))
|
if (value.Length() && value != wxT("0"))
|
||||||
new_account._default = true;
|
new_account._default = true;
|
||||||
else
|
else
|
||||||
new_account._default = false;
|
new_account._default = false;
|
||||||
|
@ -430,7 +430,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||||
inModification = true;
|
inModification = true;
|
||||||
|
|
||||||
value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
|
value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_cat.name = value;
|
new_cat.name = value;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
|
|
|
@ -135,7 +135,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_amountFrom->GetLineText(0) != wxT(""))
|
if (_amountFrom->GetLineText(0).Length())
|
||||||
{
|
{
|
||||||
amountFrom = new wxString;
|
amountFrom = new wxString;
|
||||||
*amountFrom = _amountFrom->GetLineText(0);
|
*amountFrom = _amountFrom->GetLineText(0);
|
||||||
|
@ -149,7 +149,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||||
if (af < 0) af *= -1;
|
if (af < 0) af *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_amountTo->GetLineText(0) != wxT(""))
|
if (_amountTo->GetLineText(0).Length())
|
||||||
{
|
{
|
||||||
amountTo = new wxString;
|
amountTo = new wxString;
|
||||||
*amountTo = _amountTo->GetLineText(0);
|
*amountTo = _amountTo->GetLineText(0);
|
||||||
|
@ -174,7 +174,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||||
|
|
||||||
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
||||||
|
|
||||||
if (_description->GetLineText(0) != wxT(""))
|
if (_description->GetLineText(0).Length())
|
||||||
{
|
{
|
||||||
description = new wxString;
|
description = new wxString;
|
||||||
*description = _description->GetLineText(0);
|
*description = _description->GetLineText(0);
|
||||||
|
@ -273,14 +273,14 @@ void SearchPanel::OnOperationModified(wxGridEvent& event)
|
||||||
_grid->SetCellValue(event.GetRow(), DEBIT, wxT(""));
|
_grid->SetCellValue(event.GetRow(), DEBIT, wxT(""));
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
|
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.description = value;
|
new_op.description = value;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DATE);
|
value = _grid->GetCellValue(event.GetRow(), DATE);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
date.ParseFormat(value, wxT("%d/%m/%Y"));
|
date.ParseFormat(value, wxT("%d/%m/%Y"));
|
||||||
new_op.day = date.GetDay()-1;
|
new_op.day = date.GetDay()-1;
|
||||||
|
@ -290,7 +290,7 @@ void SearchPanel::OnOperationModified(wxGridEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), DEBIT);
|
value = _grid->GetCellValue(event.GetRow(), DEBIT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
new_op.amount *= -1.0;
|
new_op.amount *= -1.0;
|
||||||
|
@ -298,28 +298,28 @@ void SearchPanel::OnOperationModified(wxGridEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.category = user->GetCategoryId(value);
|
new_op.category = user->GetCategoryId(value);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
||||||
if (value != wxT(""))
|
if (value.Length())
|
||||||
{
|
{
|
||||||
new_op.account = user->GetAccountId(value);
|
new_op.account = user->GetAccountId(value);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
||||||
if (value != wxT("") && value != wxT("0"))
|
if (value.Length() && value != wxT("0"))
|
||||||
new_op.checked = true;
|
new_op.checked = true;
|
||||||
else
|
else
|
||||||
new_op.checked = false;
|
new_op.checked = false;
|
||||||
|
|
|
@ -168,7 +168,7 @@ void wxUI::LoadUser()
|
||||||
if (_statsPanel)
|
if (_statsPanel)
|
||||||
delete _statsPanel;
|
delete _statsPanel;
|
||||||
|
|
||||||
if (user->_preferences[wxT("language")] != wxT(""))
|
if (user->_preferences[wxT("language")].Length())
|
||||||
SetLanguage(user->GetLanguage());
|
SetLanguage(user->GetLanguage());
|
||||||
|
|
||||||
_accountPanel = new AccountPanel(_kiss, this);
|
_accountPanel = new AccountPanel(_kiss, this);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user