From 224e1e6d997732eb5a92c0b773c5ec44bf9728e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 30 Jun 2010 21:57:35 +0200 Subject: [PATCH] Fix float bug && account update stats bug --- model/Database.cpp | 22 ++++++++++++++++------ view/AccountPanel.cpp | 9 +++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/model/Database.cpp b/model/Database.cpp index 2e7528c..2fed959 100644 --- a/model/Database.cpp +++ b/model/Database.cpp @@ -42,6 +42,16 @@ #define EXECUTE_SQL_UPDATE(req, return_value) EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, {}, {}) +static inline wxString DoubleToString(double d) +{ + wxString res; + + res = wxString::Format(_("%.2lf"), d); + res.Replace(_(","), _(".")); + + return res; +} + Database::Database() { std::ifstream bdd_file; @@ -323,7 +333,7 @@ void Database::UpdateOperation(struct operation op) req += _(", year='") + wxString::Format(_("%d"), op.year) + _("'"); req += _(", month='") + wxString::Format(_("%d"), op.month) + _("'"); req += _(", day='") + wxString::Format(_("%d"), op.day) + _("'"); - req += _(", amount='") + wxString::Format(_("%.2lf"), op.amount) + _("'"); + req += _(", amount='") + DoubleToString(op.amount) + _("'"); req += _(", description=\"") + op.description + _("\""); req += _(", category='") + op.category + _("'"); if (op.checked) @@ -348,7 +358,7 @@ wxString Database::AddOperation(User* user, struct operation op) req += _(", '") + wxString::Format(_("%d"), op.year) + _("'"); req += _(", '") + wxString::Format(_("%d"), op.month) + _("'"); req += _(", '") + wxString::Format(_("%d"), op.day) + _("'"); - req += _(", '") + wxString::Format(_("%.2lf"), op.amount) + _("'"); + req += _(", '") + DoubleToString(op.amount) + _("'"); req += _(", \"") + op.description + _("\""); req += _(", '") + op.category + _("'"); if (op.fix_cost) @@ -365,7 +375,7 @@ wxString Database::AddOperation(User* user, struct operation op) req += _(" AND year='") + wxString::Format(_("%d"), op.year) + _("'"); req += _(" AND month='") + wxString::Format(_("%d"), op.month) + _("'"); req += _(" AND day='") + wxString::Format(_("%d"), op.day) + _("'"); - req += _(" AND amount='") + wxString::Format(_("%.2lf"), op.amount) + _("'"); + req += _(" AND amount='") + DoubleToString(op.amount) + _("'"); req += _(" AND description=\"") + op.description + _("\""); req += _(" AND category='") + op.category + _("'"); if (op.fix_cost) @@ -433,8 +443,8 @@ void Database::SetAccountAmount(int month, int year, wxString accountId, double { wxString req; req = _("UPDATE account_amount SET ") ; - req += _("amount='") + wxString::Format(_("%.2lf"), amount) + _("'"); - req += _(" WHERE id='") + accountId + _("'"); + req += _("amount='") + DoubleToString(amount) + _("'"); + req += _(" WHERE account='") + accountId + _("'"); req += _(" AND year='") + wxString::Format(_("%d"), year) + _("'"); req += _(" AND month='") + wxString::Format(_("%d"), month) + _("'"); @@ -705,7 +715,7 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT req += it->id + _("'"); req += _(" ,'") + wxString::Format(_("%d"), yearTo) + _("'"); req += _(" ,'") + wxString::Format(_("%d"), monthTo) + _("'"); - req += _(" ,'") + wxString::Format(_("%.2lf"), amount) + _("'"); + req += _(" ,'") + DoubleToString(amount) + _("'"); req += _(")"); EXECUTE_SQL_UPDATE(req, ); diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 770f3f0..1e2fd70 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -806,9 +806,14 @@ void AccountPanel::OnAccountModified(wxGridEvent& event) User* user = _kiss->GetUser(); int row = event.GetRow(); double amount; + wxString id = user->GetAccountId(_accounts[row]); - _accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount); - _kiss->SetAccountAmount(_curMonth, _curYear, user->GetAccountId(_accounts[row]), amount); + _accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount); + + _kiss->SetAccountAmount(_curMonth, _curYear, id, amount); + _accountsInitValues[id] = amount; + + UpdateStats(); } void AccountPanel::OnTreeRightClick(wxTreeEvent& event)