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