From: <vo...@us...> - 2013-03-30 08:04:17
|
Revision: 3637 http://sourceforge.net/p/moneymanagerex/code/3637 Author: vomikan Date: 2013-03-30 08:04:13 +0000 (Sat, 30 Mar 2013) Log Message: ----------- eol-style = native Modified Paths: -------------- trunk/mmex/src/customreportdisplay.cpp trunk/mmex/src/customreportdisplay.h trunk/mmex/src/customreportindex.cpp trunk/mmex/src/customreportindex.h trunk/mmex/src/db/assets.cpp trunk/mmex/src/db/assets.h trunk/mmex/src/db/entry_base.cpp trunk/mmex/src/db/entry_base.h trunk/mmex/src/lua_interface.cpp trunk/mmex/src/lua_interface.h trunk/mmex/src/mmex_settings.cpp trunk/mmex/src/mmex_settings.h trunk/mmex/src/recentfiles.cpp trunk/mmex/src/recentfiles.h trunk/mmex/src/relocatecategorydialog.cpp trunk/mmex/src/relocatecategorydialog.h trunk/mmex/src/reports/budgetingperf.cpp trunk/mmex/src/reports/budgetingperf.h trunk/mmex/src/reports/incexpenses.cpp trunk/mmex/src/reports/incexpenses.h trunk/mmex/src/reports/incexpesestime.cpp trunk/mmex/src/reports/incexpesestime.h trunk/mmex/src/reports/payee.cpp trunk/mmex/src/reports/payee.h trunk/mmex/src/reports/summaryassets.cpp trunk/mmex/src/reports/summaryassets.h trunk/mmex/src/reports/summarystocks.cpp trunk/mmex/src/reports/summarystocks.h trunk/mmex/src/reports/transactions.cpp trunk/mmex/src/reports/transactions.h trunk/mmex/src/reports/trx_stats.cpp trunk/mmex/src/reports/trx_stats.h trunk/mmex/src/tests/mmex_lua_test.cpp trunk/mmex/src/tests/new_classes_test.cpp trunk/mmex/src/tests/testing_util.cpp trunk/mmex/src/tests/testing_util.h trunk/mmex/src/transactionfilterdialog.h Property Changed: ---------------- trunk/mmex/src/customreportdialog.cpp trunk/mmex/src/customreportdialog.h trunk/mmex/src/customreportdisplay.cpp trunk/mmex/src/customreportdisplay.h trunk/mmex/src/customreportindex.cpp trunk/mmex/src/customreportindex.h trunk/mmex/src/db/assets.cpp trunk/mmex/src/db/assets.h trunk/mmex/src/db/entry_base.cpp trunk/mmex/src/db/entry_base.h trunk/mmex/src/lua_interface.cpp trunk/mmex/src/lua_interface.h trunk/mmex/src/mm_Scriptable_Objects.h trunk/mmex/src/mmex_settings.cpp trunk/mmex/src/mmex_settings.h trunk/mmex/src/qif_export.cpp trunk/mmex/src/qif_export.h trunk/mmex/src/qif_import.cpp trunk/mmex/src/qif_import.h trunk/mmex/src/recentfiles.cpp trunk/mmex/src/recentfiles.h trunk/mmex/src/relocatecategorydialog.cpp trunk/mmex/src/relocatecategorydialog.h trunk/mmex/src/relocatepayeedialog.cpp trunk/mmex/src/relocatepayeedialog.h trunk/mmex/src/reports/budget.cpp trunk/mmex/src/reports/budget.h trunk/mmex/src/reports/budgetcategorysummary.cpp trunk/mmex/src/reports/budgetcategorysummary.h trunk/mmex/src/reports/budgetingperf.cpp trunk/mmex/src/reports/budgetingperf.h trunk/mmex/src/reports/cashflow.cpp trunk/mmex/src/reports/cashflow.h trunk/mmex/src/reports/categexp.cpp trunk/mmex/src/reports/categexp.h trunk/mmex/src/reports/categovertimeperf.cpp trunk/mmex/src/reports/categovertimeperf.h trunk/mmex/src/reports/incexpenses.cpp trunk/mmex/src/reports/incexpenses.h trunk/mmex/src/reports/incexpensesfinancialperiod.cpp trunk/mmex/src/reports/incexpensesfinancialperiod.h trunk/mmex/src/reports/incexpesestime.cpp trunk/mmex/src/reports/incexpesestime.h trunk/mmex/src/reports/payee.cpp trunk/mmex/src/reports/payee.h trunk/mmex/src/reports/summary.cpp trunk/mmex/src/reports/summary.h trunk/mmex/src/reports/summaryassets.cpp trunk/mmex/src/reports/summaryassets.h trunk/mmex/src/reports/summarystocks.cpp trunk/mmex/src/reports/summarystocks.h trunk/mmex/src/reports/transactions.cpp trunk/mmex/src/reports/transactions.h trunk/mmex/src/reports/trx_stats.cpp trunk/mmex/src/reports/trx_stats.h trunk/mmex/src/transactionfilterdialog.cpp trunk/mmex/src/transactionfilterdialog.h Index: trunk/mmex/src/customreportdialog.cpp =================================================================== --- trunk/mmex/src/customreportdialog.cpp 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportdialog.cpp 2013-03-30 08:04:13 UTC (rev 3637) Property changes on: trunk/mmex/src/customreportdialog.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: trunk/mmex/src/customreportdialog.h =================================================================== --- trunk/mmex/src/customreportdialog.h 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportdialog.h 2013-03-30 08:04:13 UTC (rev 3637) Property changes on: trunk/mmex/src/customreportdialog.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/mmex/src/customreportdisplay.cpp =================================================================== --- trunk/mmex/src/customreportdisplay.cpp 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportdisplay.cpp 2013-03-30 08:04:13 UTC (rev 3637) @@ -1,142 +1,142 @@ -/************************************************************************* - Copyright (C) 2011 Stefano Giorgio - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - *************************************************************************/ - -#include "customreportdisplay.h" -#include "lua_interface.h" -#include "util.h" - -mmCustomReport::mmCustomReport(wxWindow* parent, mmCoreDB* core -, const wxString& reportTitle, const wxString& sScript, const wxString& sScriptType) -: mmPrintableBase(core) -, parent_(parent) -, reportTitle_(reportTitle) -, sScript_(sScript) -, sScriptType_(sScriptType) -{} - -void mmCustomReport::DisplayReportHeader(mmHTMLBuilder& hb, const wxString reportTitle) -{ - hb.addHeader(2, reportTitle); - hb.addDateNow(); -} - -bool mmCustomReport::DisplaySQL_Results(mmHTMLBuilder& hb) -{ - hb.startCenter(); - hb.startTable(); - - int rows = 0; - bool bSelect = mmDBWrapper::IsSelect(core_->db_.get(), sScript_, rows); - if (!bSelect) - { - wxMessageDialog msgDlg(parent_, _("SQL Query will modify your Data. Proceed??"), _("Warning"), wxYES_NO|wxICON_WARNING); - if (msgDlg.ShowModal() != wxID_YES) - { - hb.endCenter(); - hb.addParaText(_("SQL query discarded by user")); - hb.endTable(); - return false; - } - } - - wxSQLite3ResultSet sqlQueryResult; - try - { - sqlQueryResult = core_->db_->ExecuteQuery(sScript_); - } - catch(const wxSQLite3Exception& e) - { - wxSafeShowMessage(wxT("Error"),e.GetMessage().c_str()); - - hb.endCenter(); - hb.addParaText(wxString::Format(_("Error: %s"), e.GetMessage().c_str())); - hb.endTable(); - return false; - } - - // Use column info to determine if data is to be right justified. - int columnCount = sqlQueryResult.GetColumnCount(); - bool *alignRight = new bool[columnCount]; - - hb.startTableRow(); - for (int index = 0; index < columnCount; index ++) - { - hb.addTableHeaderCell(sqlQueryResult.GetColumnName(index)); - alignRight[index] = (sqlQueryResult.GetColumnType(index) == WXSQLITE_INTEGER - || sqlQueryResult.GetColumnType(index) == WXSQLITE_FLOAT); - } - hb.endTableRow(); - - while (sqlQueryResult.NextRow()) - { - hb.startTableRow(); - for (int index = 0; index < columnCount; index ++) - { - wxString displayData = sqlQueryResult.GetAsString(index); - if ( sqlQueryResult.GetColumnType(index) == WXSQLITE_FLOAT ) - { - mmex::formatDoubleToCurrencyEdit(sqlQueryResult.GetDouble(index), displayData); - } - - //Right justify numeric data. - hb.addTableCell( displayData, alignRight[index]); - } - hb.endTableRow(); - } - - delete [] alignRight; - sqlQueryResult.Finalize(); - - - if (!bSelect) - hb.addHeader(2, _("Dababase updated succesfully")); - - hb.endCenter(); - hb.endTable(); - return true; -} - -void mmCustomReport::DisplayLua_Results(mmHTMLBuilder& hb) -{ - TLuaInterface lua_core; - wxString lua_result = lua_core.RunLuaCode(sScript_); - hb.addParaText(lua_result); -} - -wxString mmCustomReport::getHTMLText() -{ - mmHTMLBuilder hb; - hb.init(); - DisplayReportHeader(hb, _("Custom Report: ") + reportTitle_ ); - - if (sScriptType_ == wxT("SQL")) - { - DisplaySQL_Results(hb); - } - else if (sScriptType_ == wxT("LUA")) - { - DisplayLua_Results(hb); - } - else - { - hb.addParaText(_("Cannot execute unknown Script type")); - } - - hb.end(); - return hb.getHTMLText(); -} +/************************************************************************* + Copyright (C) 2011 Stefano Giorgio + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + *************************************************************************/ + +#include "customreportdisplay.h" +#include "lua_interface.h" +#include "util.h" + +mmCustomReport::mmCustomReport(wxWindow* parent, mmCoreDB* core +, const wxString& reportTitle, const wxString& sScript, const wxString& sScriptType) +: mmPrintableBase(core) +, parent_(parent) +, reportTitle_(reportTitle) +, sScript_(sScript) +, sScriptType_(sScriptType) +{} + +void mmCustomReport::DisplayReportHeader(mmHTMLBuilder& hb, const wxString reportTitle) +{ + hb.addHeader(2, reportTitle); + hb.addDateNow(); +} + +bool mmCustomReport::DisplaySQL_Results(mmHTMLBuilder& hb) +{ + hb.startCenter(); + hb.startTable(); + + int rows = 0; + bool bSelect = mmDBWrapper::IsSelect(core_->db_.get(), sScript_, rows); + if (!bSelect) + { + wxMessageDialog msgDlg(parent_, _("SQL Query will modify your Data. Proceed??"), _("Warning"), wxYES_NO|wxICON_WARNING); + if (msgDlg.ShowModal() != wxID_YES) + { + hb.endCenter(); + hb.addParaText(_("SQL query discarded by user")); + hb.endTable(); + return false; + } + } + + wxSQLite3ResultSet sqlQueryResult; + try + { + sqlQueryResult = core_->db_->ExecuteQuery(sScript_); + } + catch(const wxSQLite3Exception& e) + { + wxSafeShowMessage(wxT("Error"),e.GetMessage().c_str()); + + hb.endCenter(); + hb.addParaText(wxString::Format(_("Error: %s"), e.GetMessage().c_str())); + hb.endTable(); + return false; + } + + // Use column info to determine if data is to be right justified. + int columnCount = sqlQueryResult.GetColumnCount(); + bool *alignRight = new bool[columnCount]; + + hb.startTableRow(); + for (int index = 0; index < columnCount; index ++) + { + hb.addTableHeaderCell(sqlQueryResult.GetColumnName(index)); + alignRight[index] = (sqlQueryResult.GetColumnType(index) == WXSQLITE_INTEGER + || sqlQueryResult.GetColumnType(index) == WXSQLITE_FLOAT); + } + hb.endTableRow(); + + while (sqlQueryResult.NextRow()) + { + hb.startTableRow(); + for (int index = 0; index < columnCount; index ++) + { + wxString displayData = sqlQueryResult.GetAsString(index); + if ( sqlQueryResult.GetColumnType(index) == WXSQLITE_FLOAT ) + { + mmex::formatDoubleToCurrencyEdit(sqlQueryResult.GetDouble(index), displayData); + } + + //Right justify numeric data. + hb.addTableCell( displayData, alignRight[index]); + } + hb.endTableRow(); + } + + delete [] alignRight; + sqlQueryResult.Finalize(); + + + if (!bSelect) + hb.addHeader(2, _("Dababase updated succesfully")); + + hb.endCenter(); + hb.endTable(); + return true; +} + +void mmCustomReport::DisplayLua_Results(mmHTMLBuilder& hb) +{ + TLuaInterface lua_core; + wxString lua_result = lua_core.RunLuaCode(sScript_); + hb.addParaText(lua_result); +} + +wxString mmCustomReport::getHTMLText() +{ + mmHTMLBuilder hb; + hb.init(); + DisplayReportHeader(hb, _("Custom Report: ") + reportTitle_ ); + + if (sScriptType_ == wxT("SQL")) + { + DisplaySQL_Results(hb); + } + else if (sScriptType_ == wxT("LUA")) + { + DisplayLua_Results(hb); + } + else + { + hb.addParaText(_("Cannot execute unknown Script type")); + } + + hb.end(); + return hb.getHTMLText(); +} Property changes on: trunk/mmex/src/customreportdisplay.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/mmex/src/customreportdisplay.h =================================================================== --- trunk/mmex/src/customreportdisplay.h 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportdisplay.h 2013-03-30 08:04:13 UTC (rev 3637) @@ -1,46 +1,46 @@ -/************************************************************************* - Copyright (C) 2011 Stefano Giorgio - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - *************************************************************************/ -#ifndef _MM_EX_CUSTOMREPORTDISPLAY_H_ -#define _MM_EX_CUSTOMREPORTDISPLAY_H_ - -#include "reportbase.h" -#include "htmlbuilder.h" - -class mmCustomReport : public mmPrintableBase -{ -public: - mmCustomReport(wxWindow* parent, mmCoreDB* core - , const wxString& reportTitle, const wxString& sScript, const wxString& sScriptType); - - wxString getHTMLText(); - -private: - wxString reportTitle_; - wxString sScript_; - wxString sScriptType_; - wxWindow* parent_; - - void DisplayReportHeader(mmHTMLBuilder& hb, const wxString reportTitle); - - bool DisplaySQL_Results(mmHTMLBuilder& hb); - void DisplayLua_Results(mmHTMLBuilder& hb); - -}; - -#endif - +/************************************************************************* + Copyright (C) 2011 Stefano Giorgio + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + *************************************************************************/ +#ifndef _MM_EX_CUSTOMREPORTDISPLAY_H_ +#define _MM_EX_CUSTOMREPORTDISPLAY_H_ + +#include "reportbase.h" +#include "htmlbuilder.h" + +class mmCustomReport : public mmPrintableBase +{ +public: + mmCustomReport(wxWindow* parent, mmCoreDB* core + , const wxString& reportTitle, const wxString& sScript, const wxString& sScriptType); + + wxString getHTMLText(); + +private: + wxString reportTitle_; + wxString sScript_; + wxString sScriptType_; + wxWindow* parent_; + + void DisplayReportHeader(mmHTMLBuilder& hb, const wxString reportTitle); + + bool DisplaySQL_Results(mmHTMLBuilder& hb); + void DisplayLua_Results(mmHTMLBuilder& hb); + +}; + +#endif + Property changes on: trunk/mmex/src/customreportdisplay.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/mmex/src/customreportindex.cpp =================================================================== --- trunk/mmex/src/customreportindex.cpp 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportindex.cpp 2013-03-30 08:04:13 UTC (rev 3637) @@ -1,332 +1,332 @@ -/************************************************************************* - Copyright (C) 2011 Stefano Giorgio - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - *************************************************************************/ - -#include "customreportindex.h" -#include "paths.h" -#include <wx/tokenzr.h> - -//=============================================================== -// Methods for Class: customSQLReportIndex -//=============================================================== -CustomReportIndex::CustomReportIndex() -: activeReports_ (false) -, validTitle_ (false) -, reportIsSubReport_(false) -, currentReportFileIndex_(0) -{ - indexFile_ = new wxTextFile(mmex::getPathUser(mmex::CUSTOM_REPORTS)); - if (indexFile_->Exists()) - { - indexFile_ ->Open(); - activeReports_ = ReportListHasItems(); - } - else - { - if (indexFile_->Create()) - { - indexFile_->AddLine(_("Custom Reports")); - indexFile_->AddLine(wxT("")); - indexFile_->AddLine(_("Report Name[|Report Filename.sql[|SUB]]")); - indexFile_->AddLine(wxT("========================================")); - indexFile_->Write(); - indexFile_->Close(); // need to close to actually save the file contents - indexFile_->Open(); - } - } -} - -bool CustomReportIndex::HasActiveReports() -{ - return activeReports_; -} - -void CustomReportIndex::ResetReportsIndex() -{ - if (activeReports_) - { - indexFile_->GetFirstLine(); // File Heading line - indexFile_->GetNextLine(); // Blank Line - indexFile_->GetNextLine(); // Headings Line - indexFile_->GetNextLine(); // Separator line - currentReportFileIndex_ = 0; - validTitle_ = false; - reportIsSubReport_ = false; - } -} - -bool CustomReportIndex::ValidTitle() -{ - return validTitle_; -} - -bool CustomReportIndex::ReportIsSubReport() -{ - return reportIsSubReport_; -} - -wxString CustomReportIndex::NextReportTitle() -{ - validTitle_ = false; - reportIsSubReport_ = false; - - if (! indexFile_->Eof() ) - { - wxString line = indexFile_->GetNextLine().Trim(false); - if (!line.IsEmpty()) - { - currentReportFileIndex_ ++; - wxStringTokenizer tk(line, wxT("|")); - currentReportTitle_ = tk.GetNextToken(); - currentReportFileName_ = tk.GetNextToken(); - SetNewCurrentFileValues(); - - if (tk.HasMoreTokens()) - { - reportIsSubReport_ = true; - } - validTitle_ = true; - } - } - - return currentReportTitle_; -} - -wxString CustomReportIndex::CurrentReportTitle() -{ - return currentReportTitle_; -} - -wxString CustomReportIndex::CurrentReportFileName(bool withfilePath) -{ - wxString returnStr = currentReportFileName_; - if ( ! currentReportFileName_.IsEmpty() ) - { - if (withfilePath) - { - returnStr = wxString() << mmex::getPathUser(mmex::DIRECTORY) << currentReportFileName_; - } - } - return returnStr; -} - -wxString CustomReportIndex::CurrentReportFileExt() -{ - return currentReportFileExt_; -} - -wxString CustomReportIndex::CurrentReportFileType() -{ - return currentReportFileType_; -} - -wxString CustomReportIndex::ReportFileName(int index) -{ - ResetReportsIndex(); - - int currentLine = 0; - while (currentLine <= index) - { - NextReportTitle(); - currentLine ++; - } - return CurrentReportFileName(); -} - -void CustomReportIndex::LoadArrays(wxArrayString& titleArray, wxArrayString& fileNameArray, wxArrayString& subArray) -{ - ResetReportsIndex(); - NextReportTitle(); - while (ValidTitle()) - { - titleArray.Add(currentReportTitle_); - fileNameArray.Add(currentReportFileName_); - if (reportIsSubReport_) - subArray.Add(wxT("SUB")); - else - subArray.Add(wxT("NS")); - NextReportTitle(); - } -} - -wxString CustomReportIndex::UserDialogHeading() -{ - return _("Custom Reports"); -} - -void CustomReportIndex::SetNewCurrentFileValues() -{ - wxFileName fn(currentReportFileName_); - currentReportFileExt_ = fn.GetExt(); - currentReportFileExt_.MakeUpper(); - if (currentReportFileExt_ == wxT("SQL")) - currentReportFileType_ = wxT("SQL"); - else if (currentReportFileExt_ == wxT("LUA")) - currentReportFileType_ = wxT("LUA"); - else - currentReportFileType_ = wxT(""); -} - -wxString CustomReportIndex::GetUserTitleSelection(wxString description) -{ - wxArrayString reportTitles; - wxArrayString reportFileNames; - wxArrayString reportIsSub; - - LoadArrays(reportTitles, reportFileNames, reportIsSub); - - validTitle_ = false; - wxString msgStr = wxString::Format(_("Select the Custom Report %s"), description.c_str()); - wxSingleChoiceDialog reportTitleSelectionDlg(0,msgStr, UserDialogHeading(), reportTitles); - - int selectionIndex = -1; - if (reportTitleSelectionDlg.ShowModal() == wxID_OK) - { - selectionIndex = reportTitleSelectionDlg.GetSelection(); - if (selectionIndex > -1 ) - { - currentReportTitle_ = reportTitles.Item(selectionIndex); - currentReportFileName_ = reportFileNames.Item(selectionIndex); - SetNewCurrentFileValues(); - validTitle_ = true; - if ( reportIsSub.Item(selectionIndex) == wxT("SUB")) - reportIsSubReport_ = true; - else - reportIsSubReport_ = false; - } - } - else - { - selectionIndex = reportTitles.GetCount(); - } - - currentReportFileIndex_ = selectionIndex; // Add File header line Count. - - return wxString() << wxT("Custom_Report_") << selectionIndex; -} - -bool CustomReportIndex::GetSelectedTitleSelection(wxString titleIndex) -{ - long index; - wxStringTokenizer tk(titleIndex, wxT("_")); // get the 3rd token 'Custom_Report_xx' - if (tk.HasMoreTokens()) tk.GetNextToken(); else return false; - if (tk.HasMoreTokens()) tk.GetNextToken(); else return false; - wxString indexStr = tk.GetNextToken(); - indexStr.ToLong(&index); - - wxArrayString reportTitles; - wxArrayString reportFileNames; - wxArrayString reportIsSub; - LoadArrays(reportTitles, reportFileNames, reportIsSub); - - currentReportTitle_ = reportTitles.Item(index); - currentReportFileName_ = reportFileNames.Item(index); - SetNewCurrentFileValues(); - currentReportFileIndex_ = index; // Add number of header lines in file. - validTitle_ = true; - if ( reportIsSub.Item(index) == wxT("SUB")) - reportIsSubReport_ = true; - else - reportIsSubReport_ = false; - return true; -} - -void CustomReportIndex::AddReportTitle(wxString reportTitle, bool updateIndex, wxString ReportFileName, bool isSub) -{ - if (!reportTitle.IsEmpty()) - { - wxString indexLine = reportTitle; - if (!ReportFileName.IsEmpty()) - { - indexLine = indexLine << wxT("|") << ReportFileName; - reportIsSubReport_ = isSub; - if (reportIsSubReport_) - { - indexLine = indexLine << wxT("|SUB"); - } - } - - if (updateIndex) - { - indexFile_->RemoveLine(currentReportFileIndex_ + 4); - } - - indexFile_->InsertLine(indexLine, currentReportFileIndex_ + 4); - indexFile_->Write(); - indexFile_->Close(); - indexFile_->Open(); - activeReports_ = true; - } -} - -bool CustomReportIndex::ReportListHasItems() -{ - size_t lineCount = indexFile_->GetLineCount(); - return ( lineCount > 4 ); -} - -void CustomReportIndex::DeleteCurrentReportTitle(bool including_file) -{ - indexFile_->RemoveLine(currentReportFileIndex_ + 4); - indexFile_->Write(); - indexFile_->Close(); - indexFile_->Open(); - - if (including_file && wxFileExists(CurrentReportFileName())) - { - wxRemoveFile(CurrentReportFileName()); - ResetReportsIndex(); - NextReportTitle(); - } -} - -bool CustomReportIndex::GetReportFileData(wxString& reportText) -{ - bool result = false; - wxTextFile reportFile(CurrentReportFileName()); - if ( reportFile.Exists() ) - { - reportFile.Open(); - reportText << reportFile.GetFirstLine() << wxT("\n"); - - size_t currentline = 1; - while (! reportFile.Eof()) - { - reportText << reportFile.GetNextLine(); - currentline ++; - if (currentline < reportFile.GetLineCount()) - { - reportText << wxT("\n"); - } - } - - result = true; - } - else - { - wxString msg = wxString() << _("Cannot locate file: ") << CurrentReportFileName() << wxT("\n\n"); - wxMessageBox(msg,UserDialogHeading(),wxOK|wxICON_ERROR); - } - - return result; -} - -CustomReportIndex::~CustomReportIndex() -{ - delete indexFile_; -// wxMessageBox(wxT("Testing that CustomReportIndex objects are being destroyed.\nGoodby.."),wxT("CustomReportIndex Dialog Destructor...")); -} +/************************************************************************* + Copyright (C) 2011 Stefano Giorgio + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + *************************************************************************/ + +#include "customreportindex.h" +#include "paths.h" +#include <wx/tokenzr.h> + +//=============================================================== +// Methods for Class: customSQLReportIndex +//=============================================================== +CustomReportIndex::CustomReportIndex() +: activeReports_ (false) +, validTitle_ (false) +, reportIsSubReport_(false) +, currentReportFileIndex_(0) +{ + indexFile_ = new wxTextFile(mmex::getPathUser(mmex::CUSTOM_REPORTS)); + if (indexFile_->Exists()) + { + indexFile_ ->Open(); + activeReports_ = ReportListHasItems(); + } + else + { + if (indexFile_->Create()) + { + indexFile_->AddLine(_("Custom Reports")); + indexFile_->AddLine(wxT("")); + indexFile_->AddLine(_("Report Name[|Report Filename.sql[|SUB]]")); + indexFile_->AddLine(wxT("========================================")); + indexFile_->Write(); + indexFile_->Close(); // need to close to actually save the file contents + indexFile_->Open(); + } + } +} + +bool CustomReportIndex::HasActiveReports() +{ + return activeReports_; +} + +void CustomReportIndex::ResetReportsIndex() +{ + if (activeReports_) + { + indexFile_->GetFirstLine(); // File Heading line + indexFile_->GetNextLine(); // Blank Line + indexFile_->GetNextLine(); // Headings Line + indexFile_->GetNextLine(); // Separator line + currentReportFileIndex_ = 0; + validTitle_ = false; + reportIsSubReport_ = false; + } +} + +bool CustomReportIndex::ValidTitle() +{ + return validTitle_; +} + +bool CustomReportIndex::ReportIsSubReport() +{ + return reportIsSubReport_; +} + +wxString CustomReportIndex::NextReportTitle() +{ + validTitle_ = false; + reportIsSubReport_ = false; + + if (! indexFile_->Eof() ) + { + wxString line = indexFile_->GetNextLine().Trim(false); + if (!line.IsEmpty()) + { + currentReportFileIndex_ ++; + wxStringTokenizer tk(line, wxT("|")); + currentReportTitle_ = tk.GetNextToken(); + currentReportFileName_ = tk.GetNextToken(); + SetNewCurrentFileValues(); + + if (tk.HasMoreTokens()) + { + reportIsSubReport_ = true; + } + validTitle_ = true; + } + } + + return currentReportTitle_; +} + +wxString CustomReportIndex::CurrentReportTitle() +{ + return currentReportTitle_; +} + +wxString CustomReportIndex::CurrentReportFileName(bool withfilePath) +{ + wxString returnStr = currentReportFileName_; + if ( ! currentReportFileName_.IsEmpty() ) + { + if (withfilePath) + { + returnStr = wxString() << mmex::getPathUser(mmex::DIRECTORY) << currentReportFileName_; + } + } + return returnStr; +} + +wxString CustomReportIndex::CurrentReportFileExt() +{ + return currentReportFileExt_; +} + +wxString CustomReportIndex::CurrentReportFileType() +{ + return currentReportFileType_; +} + +wxString CustomReportIndex::ReportFileName(int index) +{ + ResetReportsIndex(); + + int currentLine = 0; + while (currentLine <= index) + { + NextReportTitle(); + currentLine ++; + } + return CurrentReportFileName(); +} + +void CustomReportIndex::LoadArrays(wxArrayString& titleArray, wxArrayString& fileNameArray, wxArrayString& subArray) +{ + ResetReportsIndex(); + NextReportTitle(); + while (ValidTitle()) + { + titleArray.Add(currentReportTitle_); + fileNameArray.Add(currentReportFileName_); + if (reportIsSubReport_) + subArray.Add(wxT("SUB")); + else + subArray.Add(wxT("NS")); + NextReportTitle(); + } +} + +wxString CustomReportIndex::UserDialogHeading() +{ + return _("Custom Reports"); +} + +void CustomReportIndex::SetNewCurrentFileValues() +{ + wxFileName fn(currentReportFileName_); + currentReportFileExt_ = fn.GetExt(); + currentReportFileExt_.MakeUpper(); + if (currentReportFileExt_ == wxT("SQL")) + currentReportFileType_ = wxT("SQL"); + else if (currentReportFileExt_ == wxT("LUA")) + currentReportFileType_ = wxT("LUA"); + else + currentReportFileType_ = wxT(""); +} + +wxString CustomReportIndex::GetUserTitleSelection(wxString description) +{ + wxArrayString reportTitles; + wxArrayString reportFileNames; + wxArrayString reportIsSub; + + LoadArrays(reportTitles, reportFileNames, reportIsSub); + + validTitle_ = false; + wxString msgStr = wxString::Format(_("Select the Custom Report %s"), description.c_str()); + wxSingleChoiceDialog reportTitleSelectionDlg(0,msgStr, UserDialogHeading(), reportTitles); + + int selectionIndex = -1; + if (reportTitleSelectionDlg.ShowModal() == wxID_OK) + { + selectionIndex = reportTitleSelectionDlg.GetSelection(); + if (selectionIndex > -1 ) + { + currentReportTitle_ = reportTitles.Item(selectionIndex); + currentReportFileName_ = reportFileNames.Item(selectionIndex); + SetNewCurrentFileValues(); + validTitle_ = true; + if ( reportIsSub.Item(selectionIndex) == wxT("SUB")) + reportIsSubReport_ = true; + else + reportIsSubReport_ = false; + } + } + else + { + selectionIndex = reportTitles.GetCount(); + } + + currentReportFileIndex_ = selectionIndex; // Add File header line Count. + + return wxString() << wxT("Custom_Report_") << selectionIndex; +} + +bool CustomReportIndex::GetSelectedTitleSelection(wxString titleIndex) +{ + long index; + wxStringTokenizer tk(titleIndex, wxT("_")); // get the 3rd token 'Custom_Report_xx' + if (tk.HasMoreTokens()) tk.GetNextToken(); else return false; + if (tk.HasMoreTokens()) tk.GetNextToken(); else return false; + wxString indexStr = tk.GetNextToken(); + indexStr.ToLong(&index); + + wxArrayString reportTitles; + wxArrayString reportFileNames; + wxArrayString reportIsSub; + LoadArrays(reportTitles, reportFileNames, reportIsSub); + + currentReportTitle_ = reportTitles.Item(index); + currentReportFileName_ = reportFileNames.Item(index); + SetNewCurrentFileValues(); + currentReportFileIndex_ = index; // Add number of header lines in file. + validTitle_ = true; + if ( reportIsSub.Item(index) == wxT("SUB")) + reportIsSubReport_ = true; + else + reportIsSubReport_ = false; + return true; +} + +void CustomReportIndex::AddReportTitle(wxString reportTitle, bool updateIndex, wxString ReportFileName, bool isSub) +{ + if (!reportTitle.IsEmpty()) + { + wxString indexLine = reportTitle; + if (!ReportFileName.IsEmpty()) + { + indexLine = indexLine << wxT("|") << ReportFileName; + reportIsSubReport_ = isSub; + if (reportIsSubReport_) + { + indexLine = indexLine << wxT("|SUB"); + } + } + + if (updateIndex) + { + indexFile_->RemoveLine(currentReportFileIndex_ + 4); + } + + indexFile_->InsertLine(indexLine, currentReportFileIndex_ + 4); + indexFile_->Write(); + indexFile_->Close(); + indexFile_->Open(); + activeReports_ = true; + } +} + +bool CustomReportIndex::ReportListHasItems() +{ + size_t lineCount = indexFile_->GetLineCount(); + return ( lineCount > 4 ); +} + +void CustomReportIndex::DeleteCurrentReportTitle(bool including_file) +{ + indexFile_->RemoveLine(currentReportFileIndex_ + 4); + indexFile_->Write(); + indexFile_->Close(); + indexFile_->Open(); + + if (including_file && wxFileExists(CurrentReportFileName())) + { + wxRemoveFile(CurrentReportFileName()); + ResetReportsIndex(); + NextReportTitle(); + } +} + +bool CustomReportIndex::GetReportFileData(wxString& reportText) +{ + bool result = false; + wxTextFile reportFile(CurrentReportFileName()); + if ( reportFile.Exists() ) + { + reportFile.Open(); + reportText << reportFile.GetFirstLine() << wxT("\n"); + + size_t currentline = 1; + while (! reportFile.Eof()) + { + reportText << reportFile.GetNextLine(); + currentline ++; + if (currentline < reportFile.GetLineCount()) + { + reportText << wxT("\n"); + } + } + + result = true; + } + else + { + wxString msg = wxString() << _("Cannot locate file: ") << CurrentReportFileName() << wxT("\n\n"); + wxMessageBox(msg,UserDialogHeading(),wxOK|wxICON_ERROR); + } + + return result; +} + +CustomReportIndex::~CustomReportIndex() +{ + delete indexFile_; +// wxMessageBox(wxT("Testing that CustomReportIndex objects are being destroyed.\nGoodby.."),wxT("CustomReportIndex Dialog Destructor...")); +} Property changes on: trunk/mmex/src/customreportindex.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/mmex/src/customreportindex.h =================================================================== --- trunk/mmex/src/customreportindex.h 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/customreportindex.h 2013-03-30 08:04:13 UTC (rev 3637) @@ -1,107 +1,107 @@ -/************************************************************************* - Copyright (C) 2011 Stefano Giorgio - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - *************************************************************************/ -#ifndef _MM_EX_CUSTOMREPORTINDEX_H_ -#define _MM_EX_CUSTOMREPORTINDEX_H_ - -#include "mmcoredb.h" - -//=============================================================== -// Class: CustomReportIndex -// Handles the text index file for custom reports -//=============================================================== -class CustomReportIndex -{ -public: - CustomReportIndex(); - - virtual ~CustomReportIndex(); - - /** Returns true if file is initialised and open */ - bool HasActiveReports(); - - /** Sets the index file pointer at beginning of file */ - void ResetReportsIndex(); - - /** Sets and Returns the report title. Reads one line of the index file. - Sets: validTitle_ currentReportTitle_ currentReportFileName_ reportIsSubReport_ */ - wxString NextReportTitle(); - - /** Sets and Returns the filename for the given index. */ - wxString ReportFileName(int index); - - /** Valid after calling: NextReportTitle() */ - bool ValidTitle(); - - /** Returns the report title. - Valid after calling: : NextReportTitle() or ReportFileName() */ - wxString CurrentReportTitle(); - - /** Returns true if report is a subreport title. - Valid after calling: : NextReportTitle() or ReportFileName() */ - bool ReportIsSubReport(); - - /** Returns the report filename. - Valid after calling: : NextReportTitle() or ReportFileName() */ - wxString CurrentReportFileName(bool withfilePath = true); - wxString CurrentReportFileExt(); - wxString CurrentReportFileType(); - - /** Return index of user selected report title as ID: Custom_Report_xxx. - sets: validTitle_ currentReportTitle_ currentReportFileName_ currentReportFileIndex_ */ - wxString GetUserTitleSelection(wxString description = wxT(":")); - - /** Gets the report title from the given ID: Custom_Report_xxx. - sets: currentReportTitle_ currentReportFileName_ currentReportFileIndex_ */ - bool GetSelectedTitleSelection(wxString titleIndex); - - /** Adds a new listing to the index file at the currentReportFileIndex_ - call GetUserTitleSelection() or GetSelectedTitleSelection() first. */ - void AddReportTitle(wxString reportTitle, bool updateIndex, wxString ReportFileName = wxT(""), bool isSub = false); - - /** Returns true if the report list is not empty */ - bool ReportListHasItems(); - - /** Removes the listing from the index file at location: currentReportFileIndex_ */ - void DeleteCurrentReportTitle(bool including_file); - - /** Returns the title header string for User Dialog */ - wxString UserDialogHeading(); - - /** Returns the file contents of the report file (.sql or .lua) */ - bool GetReportFileData(wxString& reportText); - - int GetCustomReportId() {return currentReportFileIndex_;} - -private: - bool activeReports_; - bool validTitle_; - bool reportIsSubReport_; - int currentReportFileIndex_; - - wxTextFile* indexFile_; - wxString currentReportTitle_; - wxString currentReportFileName_; - wxString currentReportFileExt_; - wxString currentReportFileType_; - - void SetNewCurrentFileValues(); - void LoadArrays(wxArrayString& titleArray, wxArrayString& fileNameArray, wxArrayString& subArray); -}; - -#endif - +/************************************************************************* + Copyright (C) 2011 Stefano Giorgio + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + *************************************************************************/ +#ifndef _MM_EX_CUSTOMREPORTINDEX_H_ +#define _MM_EX_CUSTOMREPORTINDEX_H_ + +#include "mmcoredb.h" + +//=============================================================== +// Class: CustomReportIndex +// Handles the text index file for custom reports +//=============================================================== +class CustomReportIndex +{ +public: + CustomReportIndex(); + + virtual ~CustomReportIndex(); + + /** Returns true if file is initialised and open */ + bool HasActiveReports(); + + /** Sets the index file pointer at beginning of file */ + void ResetReportsIndex(); + + /** Sets and Returns the report title. Reads one line of the index file. + Sets: validTitle_ currentReportTitle_ currentReportFileName_ reportIsSubReport_ */ + wxString NextReportTitle(); + + /** Sets and Returns the filename for the given index. */ + wxString ReportFileName(int index); + + /** Valid after calling: NextReportTitle() */ + bool ValidTitle(); + + /** Returns the report title. + Valid after calling: : NextReportTitle() or ReportFileName() */ + wxString CurrentReportTitle(); + + /** Returns true if report is a subreport title. + Valid after calling: : NextReportTitle() or ReportFileName() */ + bool ReportIsSubReport(); + + /** Returns the report filename. + Valid after calling: : NextReportTitle() or ReportFileName() */ + wxString CurrentReportFileName(bool withfilePath = true); + wxString CurrentReportFileExt(); + wxString CurrentReportFileType(); + + /** Return index of user selected report title as ID: Custom_Report_xxx. + sets: validTitle_ currentReportTitle_ currentReportFileName_ currentReportFileIndex_ */ + wxString GetUserTitleSelection(wxString description = wxT(":")); + + /** Gets the report title from the given ID: Custom_Report_xxx. + sets: currentReportTitle_ currentReportFileName_ currentReportFileIndex_ */ + bool GetSelectedTitleSelection(wxString titleIndex); + + /** Adds a new listing to the index file at the currentReportFileIndex_ + call GetUserTitleSelection() or GetSelectedTitleSelection() first. */ + void AddReportTitle(wxString reportTitle, bool updateIndex, wxString ReportFileName = wxT(""), bool isSub = false); + + /** Returns true if the report list is not empty */ + bool ReportListHasItems(); + + /** Removes the listing from the index file at location: currentReportFileIndex_ */ + void DeleteCurrentReportTitle(bool including_file); + + /** Returns the title header string for User Dialog */ + wxString UserDialogHeading(); + + /** Returns the file contents of the report file (.sql or .lua) */ + bool GetReportFileData(wxString& reportText); + + int GetCustomReportId() {return currentReportFileIndex_;} + +private: + bool activeReports_; + bool validTitle_; + bool reportIsSubReport_; + int currentReportFileIndex_; + + wxTextFile* indexFile_; + wxString currentReportTitle_; + wxString currentReportFileName_; + wxString currentReportFileExt_; + wxString currentReportFileType_; + + void SetNewCurrentFileValues(); + void LoadArrays(wxArrayString& titleArray, wxArrayString& fileNameArray, wxArrayString& subArray); +}; + +#endif + Property changes on: trunk/mmex/src/customreportindex.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/mmex/src/db/assets.cpp =================================================================== --- trunk/mmex/src/db/assets.cpp 2013-03-29 04:54:36 UTC (rev 3636) +++ trunk/mmex/src/db/assets.cpp 2013-03-30 08:04:13 UTC (rev 3637) @@ -1,329 +1,329 @@ -/******************************************************* - Copyright (C) 2013 Stefano Giorgio - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - ********************************************************/ - -#include "assets.h" - -/************************************************************************************ - TAssetEntry Methods - ***********************************************************************************/ -/// Constructor used when loading assets from the database -TAssetEntry::TAssetEntry(wxSQLite3ResultSet& q1) -: TEntryBase() -{ - id_ = q1.GetInt(wxT("ASSETID")); - date_ = q1.GetString(wxT("STARTDATE")); - name_ = q1.GetString(wxT("ASSETNAME")); - value_ = q1.GetDouble(wxT("VALUE")); - rate_type_ = q1.GetString(wxT("VALUECHANGE")); - notes_ = q1.GetString(wxT("NOTES")); - rate_value_ = q1.GetDouble(wxT("VALUECHANGERATE")); - type_ = q1.GetString(wxT("ASSETTYPE")); - // calculated value - display_date_ = mmGetDateForDisplay(mmGetStorageStringAsDate(date_)); -} - -/// Copy constructor using a pointer -TAssetEntry::TAssetEntry(TAssetEntry* pEntry) -: TEntryBase() -{ - date_ = pEntry->date_; - name_ = pEntry->name_; - value_ = pEntry->value_; - rate_type_ = pEntry->rate_type_; - notes_ = pEntry->notes_; - rate_value_ = pEntry->rate_value_; - type_ = pEntry->type_; -} - -void TAssetEntry::SetDatabaseValues(wxSQLite3Statement& st, int& db_index) -{ - st.Bind(++db_index, date_); // q1.GetString(wxT("STARTDATE")); - st.Bind(++db_index, name_); // q1.GetString(wxT("ASSETNAME")); - st.Bind(++db_index, value_); // q1.GetDouble(wxT("VALUE")); - st.Bind(++db_index, rate_type_); // q1.GetString(wxT("VALUECHANGE")); - st.Bind(++db_index, notes_); // q1.GetString(wxT("NOTES")); - st.Bind(++db_index, rate_value_);// q1.GetDouble(wxT("VALUECHANGERATE")); - st.Bind(++db_index, type_); // q1.GetString(wxT("ASSETTYPE")); -} - -/// Constructor for creating a new asset entry. -TAssetEntry::TAssetEntry() -: TEntryBase() -, value_(0.0) -, rate_value_(0.0) -{} - -int TAssetEntry::Add(wxSQLite3Database* db) -{ - const char INSERT_INTO_ASSETS_V1[] = - "INSERT INTO ASSETS_V1 " - "(STARTDATE, ASSETNAME, VALUE, VALUECHANGE, NOTES, VALUECHANGERATE, ASSETTYPE) " - "values (?, ?, ?, ?, ?, ?, ?)"; - - wxSQLite3Statement st = db->PrepareStatement(INSERT_INTO_ASSETS_V1); - int db_index = 0; - SetDatabaseValues(st, db_index); - FinaliseAdd(db, st); - - return id_; -} - -void TAssetEntry::Delete(wxSQLite3Database* db) -{ - DeleteEntry(db, wxT("delete from ASSETS_V1 where ASSETID = ?")); -} - -void TAssetEntry::Update(wxSQLite3Database* db) -{ - const char UPDATE_ASSETS_V1[] = - "update ASSETS_V1 set" - " STARTDATE = ?, ASSETNAME = ?, VALUE = ?, " - " VALUECHANGE = ?, NOTES = ?, VALUECHANGERATE = ?, ASSETTYPE = ? " - "where ASSETID = ?"; - try - { - wxSQLite3Statement st = db->PrepareStatement(UPDATE_ASSETS_V1); - - int db_index = 0; - SetDatabaseValues(st, db_index); - st.Bind(++db_index, id_); - - FinaliseStatement(st); - } - catch(const wxSQLite3Exception& e) - { - //wxLogDebug(wxT("TAssetEntry:Update: %s"), e.GetMessage()); - wxLogError(wxT("TAssetEntry:Update: %s"), e.GetMessage().c_str()); - } -} - -double TAssetEntry::GetAppreciatedValue(const wxDateTime& startDate, double value, double rate) -{ - double asset_value = 0.0; - wxDateTime todayDate = wxDateTime::Now(); - - if (todayDate > startDate) - { - int numYears = todayDate.GetYear() - startDate.GetYear(); - - int numMonths = todayDate.GetMonth() - startDate.GetMonth(); - int numDays = todayDate.GetDay() - startDate.GetDay(); - if ( (numMonths >= 0 ) && (numDays < 0) ) numMonths --; - if ( (numYears > 0 ) && (numMonths < 0 )) numYears -- ; - - if (numYears > 0) - { - while (numYears > 0) - { - asset_value = value + (rate * value / 100); - value = asset_value; - -- numYears; - } - } - } - - return value; -} - -double TAssetEntry::GetDepreciatedValue(const wxDateTime& startDate, double value, double rate) -{ - double asset_value = 0.0; - wxDateTime todayDate = wxDateTime::Now(); - - if (todayDate > startDate) - { - int numYears = todayDate.GetYear() - startDate.GetYear(); - if (numYears > 0) - { - while (numYears > 0) - { - asset_value = value - (rate * value / 100); - value = asset_value; - numYears --; - } - } - } - - return value; -} - -double TAssetEntry::GetValue() -{ - wxDateTime start_date = mmGetStorageStringAsDate(date_); - double asset_value = value_; - - if (rate_type_ == ASSET_RATE_DEF[APPRECIATE]) - { - asset_value = GetAppreciatedValue(start_date, value_, rate_value_); - } - - if (rate_type_ == ASSET_RATE_DEF[DEPRECIATE]) - { - asset_value = GetDepreciatedValue(start_date, value_, rate_value_); - } - - return asset_value; -} - -wxString TAssetEntry::GetValueCurrencyEditFormat(bool initial_value) -{ - wxString formatted_value; - if (initial_value) mmex::formatDoubleToCurrencyEdit(value_, formatted_value); - else mmex::formatDoubleToCurrencyEdit(GetValue(), formatted_value); - - return formatted_value; -} - -wxString TAssetEntry::DisplayDate() -{ - return mmGetDateForDisplay(mmGetStorageStringAsDate(date_)); -} - -/************************************************************************************ - TAssetList Methods - ***********************************************************************************/ -/// Constructor -TAssetList::TAssetList(boost::shared_ptr<wxSQLite3Database> db, bool load_entries) -: TListBase(db) -{ - LoadEntries(load_entries); -} - -void TAssetList::LoadEntries(bool load_entries) -{ - try - { - if (!db_->TableExists(wxT("ASSETS_V1"))) - { - const char CREATE_TABLE_ASSETS_V1[] = - "CREATE TABLE ASSETS_V1 (ASSETID integer primary key, " - "STARTDATE TEXT NOT NULL, ASSETNAME TEXT, " - "VALUE numeric, VALUECHANGE TEXT, NOTES TEXT, VALUECHANGERATE numeric, " - "ASSETTYPE TEXT)"; - - db_->ExecuteUpdate(CREATE_TABLE_ASSETS_V1); - } - - if (load_entries) - { - LoadAssetEntriesUsing(wxT("select * from assets_v1")); - } - } - catch (const wxSQLite3Exception& e) - { - //wxLogDebug(wxT("TAssetList::LoadEntries %s"), e.GetMessage()); - wxLogError(wxT("TAssetList::LoadEntries %s"), e.GetMessage().c_str()); - } -} - -void TAssetList::LoadAssetEntriesUsing(const wxString& sql_statement) -{ - entrylist_.clear(); - wxSQLite3ResultSet q1 = db_->ExecuteQuery(sql_statement); - while (q1.NextRow()) - { - boost::shared_ptr<TAssetEntry> pEntry(new TAssetEntry(q1)); - entrylist_.push_back(pEntry); - } - q1.Finalize(); -} - -int TAssetList::AddEntry(TAssetEntry* pAssetEntry) -{ - boost::shared_ptr<TAssetEntry> pEntry(pAssetEntry); - entrylist_.push_back(pEntry); - pEntry->Add(db_.get()); - - return pEntry->id_; -} - -void TAssetList::DeleteEntry(int asset_id) -{ - boost::shared_ptr<TAssetEntry> pEntry = GetEntryPtr(asset_id); - if (pEntry) - { - pEntry->Delete(db_.get()); - entrylist_.erase(entrylist_.begin() + current_index_); - } -} - -boost::shared_ptr<TAssetEntry> TAssetList::GetEntryPtr(int asset_id) -{ - boost::shared_ptr<TAssetEntry> pEntry; - size_t list_size = entrylist_.size(); - size_t index = 0; - - while (index < list_size) - { - if (entrylist_[index]->id_ == asset_id) - { - pEntry = entrylist_[index]; - current_index_ = index; - break; - } - ++ index; - } - - return pEntry; -} - -boost::shared_ptr<TAssetEntry> TAssetList::GetIndexedEntryPtr(unsigned int list_index) -{ - boost::shared_ptr<TAssetEntry> pEntry; - if (list_index < entrylist_.size()) - { - pEntry = entrylist_[list_index]; - } - - return pEntry; -} - -int TAssetList::CurrentListSize() -{ - return entrylist_.size(); -} - -double TAssetList::GetAssetBalance(bool value_today) -{ - double total_value = 0.0; - for (size_t i = 0; i < entrylist_.size(); ++i) - { - if (value_today) - total_value = total_value + entrylist_[i]->GetValue(); - else - total_value = total_value + entrylist_[i]->value_; - } - - return total_value; -} - -wxString TAssetList::GetAssetBalanceCurrencyFormat(bool value_today) -{ - wxString balance_str; - mmex::formatDoubleToCurrency(GetAssetBalance(value_today), balance_str); - - return balance_str; -} - -wxString TAssetList::GetAssetBalanceCurrencyEditFormat(bool value_today) -{ - wxString balance_str; - mmex::formatDoubleToCurrencyEdit(GetAssetBalance(value_today), balance_str); - - return balance_str; -} +/******************************************************* + Copyright (C) 2013 Stefano Giorgio + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ********************************************************/ + +#include "assets.h" + +/************************************************************************************ + TAssetEntry Methods + ***********************************************************************************/ +/// Constructor used when loading assets from the database +TAssetEntry::TAssetEntry(wxSQLite3ResultSet& q1) +: TEntryBase() +{ + id_ = q1.GetInt(wxT("ASSETID")); + date_ = q1.GetString(wxT("STARTDATE")); + name_ = q1.GetString(wxT("ASSETNAME")); + value_ = q1.GetDouble(wxT("VALUE")); + rate_type_ = q1.GetString(wxT("VALUECHANGE")); + notes_ = q1.GetString(wxT("NOTES")); + rate_value_ = q1.GetDouble(wxT("VALUECHANGERATE")); + type_ = q1.GetString(wxT("ASSETTYPE")); + // calculated value + display_date_ = mmGetDateForDisplay(mmGetStorageStringAsDate(date_)); +} + +/// Copy constructor using a pointer +TAssetEntry::TAssetEntry(TAssetEntry* pEntry) +: TEntryBase() +{ + date_ = pEntry->date_; + name_ = pEntry->name_; + value_ = pEntry->value_; + rate_type_ = pEntry->rate_type_; + notes_ = pEntry->notes_; + rate_value_ = pEntry->rate_value_; + type_ = pEntry->type_; +} + +void TAssetEntry::SetDatabaseValues(wxSQLite3Statement& st, int& db_index) +{ + st.Bind(++db_index, date_); // q1.GetString(wxT("STARTDATE")); + st.Bind(++db_index, name_); // q1.GetString(wxT("ASSETNAME")); + st.Bind(++db_index, value_); // q1.GetDouble(wxT("VALUE")); + st.Bind(++db_index, rate_type_); // q1.GetString(wxT("VALUECHANGE")); + st.Bind(++db_index, notes_); // q1.GetString(wxT("NOTES")); + st.Bind(++db_index, rate_value_);// q1.GetDouble(wxT("VALUECHANGERATE")); + st.Bind(++db_index, type_); // q1.GetString(wxT("ASSETTYPE")); +} + +/// Constructor for creating a new asset entry. +TAssetEntry::TAssetEntry() +: TEntryBase() +, value_(0.0) +, rate_value_(0.0) +{} + +int TAssetEntry::Add(wxSQLite3Database* db) +{ + const char INSERT_INTO_ASSETS_V1[] = + "INSERT INTO ASSETS_V1 " + "(STARTDATE, ASSETNAME, VALUE, VALUECHANGE, NOTES, VALUECHANGERATE, ASSETTYPE) " + "values (?, ?, ?, ?, ?, ?, ?)"; + + wxSQLite3Statement st = db->PrepareStatement(INSERT_INTO_ASSETS_V1); + int db_index = 0; + SetDatabaseValues(st, db_index); + FinaliseAdd(db, st); + + return id_; +} + +void TAssetEntry::Delete(wxSQLite3Database* db) +{ + DeleteEntry(db, wxT("delete from ASSETS_V1 where ASSETID = ?")); +} + +void TAssetEntry::Update(wxSQLite3Datab... [truncated message content] |