1
/***************************************************************
3
* Purpose: Core Code for OpenMoneyBox Application Class
4
* Author: Igor Calì (igor.cali0@gmail.com)
6
* Copyright: Igor Calì (igor.cali0@gmail.com)
8
**************************************************************/
10
#ifndef OMB33CORE_CPP_INCLUDED
11
#define OMB33CORE_CPP_INCLUDED
13
#ifdef _OMB_USE_CIPHER
16
#ifndef __OMBCONVERT_BIN__
17
#include "ui/password.h"
18
#endif // __OMBCONVERT_BIN__
19
#include "wxsqlite3.h"
20
#endif // _OMB_USE_CIPHER
22
#include <wx/filename.h>
23
#include <wx/textfile.h>
25
#ifndef __OMBCONVERT_BIN__
29
#include "productversion.h"
30
#include "omb33core.h"
32
#ifdef __OPENMONEYBOX_EXE__
33
#include "openmoneybox/ui/main_wx.h"
37
extern wxLanguage Lan;
40
#ifdef __OPENMONEYBOX_EXE__
41
extern "C" ombMainFrame *frame;
42
#endif // __OPENMONEYBOX_EXE__
45
extern wxString cs_information;
46
extern wxString cs_funds;
47
extern wxString cs_credits;
48
extern wxString cs_debts;
49
extern wxString cs_loans;
50
extern wxString cs_borrows;
51
//extern wxString cs_shoplist;
52
extern wxString cs_transactions;
53
extern wxString cs_categories;
54
extern wxString cs_funds_master;
55
extern wxString cs_credits_master;
56
extern wxString cs_debts_master;
57
extern wxString cs_loans_master;
58
extern wxString cs_borrows_master;
59
extern wxString cs_categories_master;
61
#if (! wxCHECK_VERSION(3, 0, 0) )
62
extern wxLanguage Lan;
65
#ifdef _OMB_USE_CIPHER
66
extern bool TableExists(const wxString& tableName, const wxString& databaseName, sqlite3 *m_db);
67
extern int ExecuteUpdate(sqlite3 *m_db, const char* sql/*, bool saveRC = false*/);
68
extern wxSQLite3Table GetTable(sqlite3 *m_db, const char* sql);
69
#endif // _OMB_USE_CIPHER
71
#ifndef __OMBCONVERT_BIN__
72
TData_v32::TData_v32(wxGauge *ProgressBar):TData(ProgressBar){
74
TData_v32::TData_v32(void){
75
#endif // __OMBCONVERT_BIN__
77
#ifdef _OMB_USE_CIPHER
78
IsEncrypted = IsEncrypted_master = false;
79
#endif // _OMB_USE_CIPHER
81
Credits = new TVal_v32[MAX_CREDITS];
82
Debts = new TVal_v32[MAX_DEBTS];
83
Lent = new TObj_v32[MAX_LENT];
84
Borrowed = new TObj_v32[MAX_BORROWED];
85
Lines = new TLine_v32[MAX_LINES];
90
void TData_v32::Initialize(bool Creating){
91
// Report initialization
92
Lines[0].IsDate=false;
93
Lines[0].Date=wxInvalidDateTime;
94
Lines[0].Time=wxInvalidDateTime;
96
Lines[0].Value=wxEmptyString;
97
Lines[0].Reason=wxEmptyString;
98
Lines[0].CategoryIndex = -1;
99
Lines[0].ContactIndex = -1;
102
void TData_v32::ParseDatabase(void){
105
#ifdef _OMB_USE_CIPHER
107
int Rows, id, i; // Rows: number of rows in the query table
108
// id: id of table item
109
long ind, // ind: category index of transaction
110
contact_in; // contact_in: contact index of transaction or object
115
wxString str, reason;
116
wxDateTime date, time;
117
wxSQLite3Table Table;
120
if(TableExists(L"Funds", wxEmptyString, database)){
121
Table = GetTable(database, "select * from Funds order by name;");
124
Rows = Table.GetRowCount();
125
for (i = 0; i < Rows; i++){
127
id = Table.GetInt(0, 0);
128
str = Table.GetString(1, wxEmptyString);
129
val = Table.GetDouble(2, 0);
130
if(AddValue(tvFou, id, str, val)){
136
wxString Sql = L"select data from Information where id = " +
137
wxString::Format(L"%d", dbMeta_default_fund) +
139
Table = GetTable(database, Sql.c_str());
141
Table = GetTable(database, L"select data from Information where id = " +
142
wxString::Format(L"%d", dbMeta_default_fund) +
144
#endif // __OPENSUSE__
146
FileData.DefFund = Table.GetString(0, wxEmptyString);
149
if(TableExists(L"Credits", wxEmptyString, database)){
150
Table = GetTable(database, "select * from Credits order by name;");
153
Rows = Table.GetRowCount();
154
for (i = 0; i < Rows; i++){
156
id = Table.GetInt(0, 0);
157
str = Table.GetString(1, wxEmptyString);
158
val = Table.GetDouble(2, 0);
159
contact_in = Table.GetInt(3, -1);
160
if(AddValue(tvCre, id, str, val, contact_in)){
162
Tot_Credits += val;}}}
165
if(TableExists(L"Debts", wxEmptyString, database)){
166
Table = GetTable(database, "select * from Debts order by name;");
169
Rows = Table.GetRowCount();
170
for (i = 0; i < Rows; i++){
172
id = Table.GetInt(0, 0);
173
str = Table.GetString(1, wxEmptyString);
174
val = Table.GetDouble(2, 0);
175
contact_in = Table.GetInt(3, -1);
176
if(AddValue(tvDeb, id, str, val, contact_in)){
181
if(TableExists(L"Loans", wxEmptyString, database)){
182
Table = GetTable(database, "select * from Loans order by name;");
184
Rows = Table.GetRowCount();
185
for (i = 0; i < Rows; i++){
187
id = Table.GetInt(0, 0);
188
str = Table.GetString(1, wxEmptyString);
189
reason = Table.GetString(2, wxEmptyString);
190
ind = Table.GetInt(3, 0);
191
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
192
else date = wxDateTime((time_t) ind);
193
contact_in = Table.GetInt(4, -1);
194
if(AddObject(toPre, id, str, reason, date, contact_in)) NLen++;}}
197
if(TableExists(L"Borrows", wxEmptyString, database)){
198
Table = GetTable(database, "select * from Borrows order by name;");
200
Rows = Table.GetRowCount();
201
for (i = 0; i < Rows; i++){
203
id = Table.GetInt(0, 0);
204
str = Table.GetString(1, wxEmptyString);
205
reason = Table.GetString(2, wxEmptyString);
206
ind = Table.GetInt(3, 0);
207
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
208
else date = wxDateTime((time_t) ind);
209
contact_in = Table.GetInt(4, -1);
210
if(AddObject(toInP, id, str, reason, date, contact_in)) NBor++;}}
213
Table = /*database->*/GetTable(database, "select * from Categories order by name;");
215
Rows = Table.GetRowCount();
216
for (i = 0; i < Rows; i++){
218
id = Table.GetInt(0, 0);
219
str = Table.GetString(1, wxEmptyString);
220
is_date = Table.GetInt(2, 0);
221
if(is_date)AddCategory(id, str);}
224
wxDateTime LastDate = wxDateTime(1, wxDateTime::Jan, 1970);
225
Table = /*database->*/GetTable(database, "select * from Transactions order by date;");
227
Rows = Table.GetRowCount();
229
for (i = 0; i < Rows; i++){
231
id = Table.GetInt(0, 0);
232
is_date = Table.GetInt(1, 0);
233
date = wxDateTime((time_t) Table.GetInt(2, 0));
234
if(date.IsLaterThan(LastDate)) LastDate = date;
235
time = wxDateTime((time_t) Table.GetInt(3, 0));
236
type = (TOpType) Table.GetInt(4, 0);
237
str = Table.GetString(5, wxEmptyString);
238
reason = Table.GetString(6, wxEmptyString);
239
ind = Table.GetInt(7, 0);
241
contact_in = Table.GetInt(8, -1);
243
#if (wxCHECK_VERSION(3, 0, 0) )
248
if(AddDate(id, date, val)) NLin++;}
250
#if (wxCHECK_VERSION(3, 0, 0) )
251
Table.GetAsString(9).ToCDouble(&lat);
252
Table.GetAsString(10).ToCDouble(&lon);
254
Table.GetAsString(9).ToDouble(&lat);
255
Table.GetAsString(10).ToDouble(&lon);
258
#if (wxCHECK_VERSION(3, 0, 0) )
263
str = FormDigits(val);}
264
if(AddOper(id, date, time, type, str, reason, ind, contact_in, true, lat, lon)) NLin++;}}}
265
else LastDate = wxDateTime::Today();
267
FileData.Year = LastDate.GetYear();
268
// Following code is a workaround for GetMonth() bug in Linux
269
// http://forums.wxwidgets.org/viewtopic.php?t=25154&highlight=getmonth
272
temp = LastDate.Format("%m", wxDateTime::Local).c_str();
274
temp = LastDate.Format(L"%m", wxDateTime::Local).c_str();
276
temp.ToLong(&FileData.Month, 10);
280
// Read shopping list
281
if(TableExists(L"Shoplist", wxEmptyString, database)){
282
Table = GetTable(database, "select * from Shoplist order by item collate nocase;");
284
Rows = Table.GetRowCount();
285
for (i = 0; i < Rows; i++){
287
id = Table.GetInt(0, 0);
288
str = Table.GetString(1, wxEmptyString);
289
ind = Table.GetInt(2, 0);
290
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
291
else date = wxDateTime((time_t) ind);
292
if(AddShopItem(id, str, date)) NSho++;}}
295
int Rows, id, i; // Rows: number of rows in the query table
296
// id: id of table item
297
long ind, // ind: category index of transaction
298
contact_in; // contact_in: contact index of transaction or object
303
wxString str, reason;
304
wxDateTime date, time;
305
wxSQLite3Table Table;
308
if(database->TableExists(L"Funds")){
309
Table = database->GetTable("select * from Funds order by name;");
312
Rows = Table.GetRowCount();
313
for (i = 0; i < Rows; i++){
315
id = Table.GetInt(0, 0);
316
str = Table.GetString(1, wxEmptyString);
317
val = Table.GetDouble(2, 0);
318
if(AddValue(tvFou, id, str, val)){
323
Table = database->GetTable(L"select data from Information where id = " +
324
wxString::Format(L"%d", dbMeta_default_fund) +
327
FileData.DefFund = Table.GetString(0, wxEmptyString);
330
if(database->TableExists(L"Credits")){
331
Table = database->GetTable("select * from Credits order by name;");
334
Rows = Table.GetRowCount();
335
for (i = 0; i < Rows; i++){
337
id = Table.GetInt(0, 0);
338
str = Table.GetString(1, wxEmptyString);
339
val = Table.GetDouble(2, 0);
340
contact_in = Table.GetInt(3, -1);
341
if(AddValue(tvCre, id, str, val, contact_in)){
343
Tot_Credits += val;}}}
346
if(database->TableExists(L"Debts")){
347
Table = database->GetTable("select * from Debts order by name;");
350
Rows = Table.GetRowCount();
351
for (i = 0; i < Rows; i++){
353
id = Table.GetInt(0, 0);
354
str = Table.GetString(1, wxEmptyString);
355
val = Table.GetDouble(2, 0);
356
contact_in = Table.GetInt(3, -1);
357
if(AddValue(tvDeb, id, str, val, contact_in)){
362
if(database->TableExists(L"Loans")){
363
Table = database->GetTable("select * from Loans order by name;");
365
Rows = Table.GetRowCount();
366
for (i = 0; i < Rows; i++){
368
id = Table.GetInt(0, 0);
369
str = Table.GetString(1, wxEmptyString);
370
reason = Table.GetString(2, wxEmptyString);
371
ind = Table.GetInt(3, 0);
372
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
373
else date = wxDateTime((time_t) ind);
374
contact_in = Table.GetInt(4, -1);
375
if(AddObject(toPre, id, str, reason, date, contact_in)) NLen++;}}
378
if(database->TableExists(L"Borrows")){
379
Table = database->GetTable("select * from Borrows order by name;");
381
Rows = Table.GetRowCount();
382
for (i = 0; i < Rows; i++){
384
id = Table.GetInt(0, 0);
385
str = Table.GetString(1, wxEmptyString);
386
reason = Table.GetString(2, wxEmptyString);
387
ind = Table.GetInt(3, 0);
388
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
389
else date = wxDateTime((time_t) ind);
390
contact_in = Table.GetInt(4, -1);
391
if(AddObject(toInP, id, str, reason, date, contact_in)) NBor++;}}
394
Table = database->GetTable("select * from Categories order by name;");
396
Rows = Table.GetRowCount();
397
for (i = 0; i < Rows; i++){
399
id = Table.GetInt(0, 0);
400
str = Table.GetString(1, wxEmptyString);
401
is_date = Table.GetInt(2, 0);
402
if(is_date)AddCategory(id, str);}
405
wxDateTime LastDate = wxDateTime(1, wxDateTime::Jan, 1970);
406
Table = database->GetTable("select * from Transactions order by date;");
408
Rows = Table.GetRowCount();
410
for (i = 0; i < Rows; i++){
412
id = Table.GetInt(0, 0);
413
is_date = Table.GetInt(1, 0);
414
date = wxDateTime((time_t) Table.GetInt(2, 0));
415
if(date.IsLaterThan(LastDate)) LastDate = date;
416
time = wxDateTime((time_t) Table.GetInt(3, 0));
417
type = (TOpType) Table.GetInt(4, 0);
418
str = Table.GetString(5, wxEmptyString);
419
reason = Table.GetString(6, wxEmptyString);
420
ind = Table.GetInt(7, 0);
422
contact_in = Table.GetInt(8, -1);
424
#if (wxCHECK_VERSION(3, 0, 0) )
429
if(AddDate(id, date, val)) NLin++;}
431
#if (wxCHECK_VERSION(3, 0, 0) )
432
Table.GetAsString(9).ToCDouble(&lat);
433
Table.GetAsString(10).ToCDouble(&lon);
435
Table.GetAsString(9).ToDouble(&lat);
436
Table.GetAsString(10).ToDouble(&lon);
439
#if (wxCHECK_VERSION(3, 0, 0) )
444
str = FormDigits(val);}
445
if(AddOper(id, date, time, type, str, reason, ind, contact_in, true, lat, lon)) NLin++;}}}
446
else LastDate = wxDateTime::Today();
448
FileData.Year = LastDate.GetYear();
449
// Following code is a workaround for GetMonth() bug in Linux
450
// http://forums.wxwidgets.org/viewtopic.php?t=25154&highlight=getmonth
453
temp = LastDate.Format("%m", wxDateTime::Local).c_str();
455
temp = LastDate.Format(L"%m", wxDateTime::Local).c_str();
457
temp.ToLong(&FileData.Month, 10);
461
// Read shopping list
462
if(database->TableExists(L"Shoplist")){
463
Table = database->GetTable("select * from Shoplist order by item collate nocase;");
465
Rows = Table.GetRowCount();
466
for (i = 0; i < Rows; i++){
468
id = Table.GetInt(0, 0);
469
str = Table.GetString(1, wxEmptyString);
470
ind = Table.GetInt(2, 0);
471
if(ind == -1) date = wxDateTime::Today().Add(wxDateSpan(100, 0, 0, 0));
472
else date = wxDateTime((time_t) ind);
473
if(AddShopItem(id, str, date)) NSho++;}}
474
#endif // _OMB_USE_CIPHER
479
bool TData_v32::AddOper(int id, wxDateTime D, wxDateTime O, TOpType T, wxString V, wxString M, long N, long c_index,
480
bool hasLocation, double lat, double lon){
481
if(T==toNULL||V.IsEmpty()||M.IsEmpty()) return false;
482
//wxString Tot=FormDigits(Tot_Funds);
486
Lines[NLin].IsDate = false;
487
Lines[NLin].Date = D;
488
Lines[NLin].Time = O;
489
Lines[NLin].Type = T;
490
Lines[NLin].Value = V;
491
Lines[NLin].Reason = M;
492
Lines[NLin].CategoryIndex = N;
493
Lines[NLin].ContactIndex = c_index;
494
Lines[NLin].Latitude = lat;
495
Lines[NLin].Longitude = lon;
499
if(T > 8) V = DoubleQuote(V);
501
// Necessry to make sure the operation is appended to other entries of same day
502
D.Set(D.GetDay(), D.GetMonth(), D.GetYear(), O.GetHour(), O.GetMinute());
507
AddDate(-1, D, Tot_Funds);
509
else for(int i = NLin - 1; i >= 0; i--)if(IsDate(i)){
510
if( Lines[i].Date.IsSameDate(D)){
513
if (! found) AddDate(-1, D, Tot_Funds);
516
lat = ombInvalidLatitude;
517
lon = ombInvalidLongitude;
520
#ifdef _OMB_USE_CIPHER
521
wxString Sql = L"insert into Transactions values (NULL, 0, " +
522
wxString::Format(L"%d", (int) D.GetTicks()) +
524
wxString::Format(L"%d", (int) O.GetTicks()) +
526
wxString::Format(L"%d", T) +
532
wxString::Format(L"%ld", N) +
535
wxString::Format(L"%ld", c_index) +
538
#if( wxCHECK_VERSION(3,0,0) )
539
ombFromCDouble(lat) +
544
#if( wxCHECK_VERSION(3,0,0) )
545
ombFromCDouble(lon) +
551
ExecuteUpdate(database, Sql.c_str()/*, false*/);
553
database->ExecuteUpdate(L"insert into Transactions values (NULL, 0, " +
554
wxString::Format(L"%d", (int) D.GetTicks()) +
556
wxString::Format(L"%d", (int) O.GetTicks()) +
558
wxString::Format(L"%d", T) +
564
wxString::Format(L"%ld", N) +
567
wxString::Format(L"%ld", c_index) +
570
#if( wxCHECK_VERSION(3,0,0) )
571
ombFromCDouble(lat) +
576
#if( wxCHECK_VERSION(3,0,0) )
577
ombFromCDouble(lon) +
583
#endif // _OMB_USE_CIPHER
585
FileData.Modified=true;
591
bool TData_v32::AddDate(int id, wxDateTime D, double T){
592
if(!D.IsValid())return false;
595
D.ResetTime(); // New dates are with time set to midnight
597
#ifdef __OPENMONEYBOX_EXE__
600
M = Day.GetMonth() + 1;
601
if((A != FileData.Year) || (M != FileData.Month)){
602
//#ifdef __OPENMONEYBOX_EXE__
604
wxCommandEvent evt(wxEVT_NULL,0);
605
frame->TextConvClick(evt);}
606
//#endif // __OPENMONEYBOX_EXE__
607
wxString Path=::wxPathOnly(FileData.FileName);
609
wxString month=::wxString::Format("%02d",FileData.Month);
611
#if(wxCHECK_VERSION(3,0,0))
612
wxString month=::wxString::Format(L"%02d",int(FileData.Month));
614
wxString month=::wxString::Format(L"%02d",FileData.Month);
617
wxString File = GetDocPrefix();
620
File+=::wxString::Format("%d",FileData.Year);
622
File+=::wxString::Format(L"%d",FileData.Year);
624
File += L"-" + month + L".omb";
625
FileData.Modified = true;
627
//#ifdef __OPENMONEYBOX_EXE__
628
wxString master = Get_MasterDB();
629
wxString trailname = ::wxString::Format(L"_%d_%02d", FileData.Year, int(FileData.Month));
631
bool has_cat = Prepare_MasterDB(master, trailname);
633
#ifdef _OMB_USE_CIPHER
634
sqlite3_exec(database, "RELEASE rollback;", NULL, NULL, NULL);
637
sqlite3_open((Path + L"/" + File).c_str(), &pBk);
638
sqlite3_backup *pBackup;
639
pBackup = sqlite3_backup_init(pBk, "main", database, "main");
641
(void)sqlite3_backup_step(pBackup, -1);
642
(void)sqlite3_backup_finish(pBackup);
645
database->ReleaseSavepoint(L"rollback");
646
database->Backup(Path + L"/" + File);
647
#endif // _OMB_USE_CIPHER
649
Archive_inMaster(master, trailname, ! has_cat);
651
#ifdef _OMB_USE_CIPHER
652
ExecuteUpdate(database, "DELETE FROM Transactions");
653
ExecuteUpdate(database, "VACUUM");
654
ExecuteUpdate(database, "SAVEPOINT rollback;");
656
database->ExecuteUpdate("DELETE FROM Transactions");
658
database->Savepoint(L"rollback");
659
#endif // _OMB_USE_CIPHER
661
//#endif // __OPENMONEYBOX_EXE__
663
//CategoryDB->Sort(false);
666
FileData.Month = int (D.GetMonth()) + 1;
667
FileData.Year = D.GetYear();}
668
#endif // __OPENMONEYBOX_EXE__
670
else // Robustness code to avoid creation of duplicate date entries
671
for(int i = NLin - 1; i >= 0; i--)if(IsDate(i))
672
if(Lines[i].Date == D)
673
#ifndef __OMBCONVERT_BIN__
677
#endif // __OMBCONVERT_BIN__
681
Lines[NLin].IsDate = true;
682
Lines[NLin].Date = D;
683
Lines[NLin].Time = wxInvalidDateTime;
684
Lines[NLin].Type = toNULL;
685
Lines[NLin].Value = FormDigits(T);
686
Lines[NLin].Reason = wxEmptyString;
687
Lines[NLin].CategoryIndex = -1;
688
Lines[NLin].ContactIndex = -1;
689
Lines[NLin].Latitude = ombInvalidLatitude;
690
Lines[NLin].Longitude = ombInvalidLongitude;
693
#ifdef _OMB_USE_CIPHER
696
wxString Sql = L"insert into Transactions values (NULL, 1, " +
697
wxString::Format(L"%d", (int) D.GetTicks()) +
699
#if( wxCHECK_VERSION(3,0,0) )
705
wxString::Format(L"%d", (int) ombInvalidLatitude) +
707
wxString::Format(L"%d", (int) ombInvalidLongitude) +
709
ExecuteUpdate(database, Sql.c_str());
712
ExecuteUpdate(database, L"insert into Transactions values (NULL, 1, " +
713
wxString::Format(L"%d", (int) D.GetTicks()) +
715
#if( wxCHECK_VERSION(3,0,0) )
721
wxString::Format(L"%d", (int) ombInvalidLatitude) +
723
wxString::Format(L"%d", (int) ombInvalidLongitude) +
725
#endif // __OPENSUSE__
727
database->ExecuteUpdate(L"insert into Transactions values (NULL, 1, " +
728
wxString::Format(L"%d", (int) D.GetTicks()) +
730
#if( wxCHECK_VERSION(3,0,0) )
736
wxString::Format(L"%d", (int) ombInvalidLatitude) +
738
wxString::Format(L"%d", (int) ombInvalidLongitude) +
740
#endif // _OMB_USE_CIPHER
742
FileData.Modified=true;
745
bool TData_v32::FindContact(long contact_id){
746
bool contact_exists = false;
747
#ifdef _OMB_USE_CIPHER
748
bool table_existed = TableExists(L"Contacts", wxEmptyString, database);
750
bool table_existed = database->TableExists(L"Contacts");
751
#endif // _OMB_USE_CIPHER
753
wxSQLite3Table ContactsTable;
754
#ifdef _OMB_USE_CIPHER
756
wxString Sql = L"select status from Contacts where mobile_id = " +
757
wxString::Format(L"%ld", contact_id) +
759
ContactsTable = GetTable(database, Sql.c_str());
761
ContactsTable = GetTable(database, L"select status from Contacts where mobile_id = " +
762
wxString::Format(L"%ld", contact_id) +
764
#endif // __OPENSUSE__
766
ContactsTable = database->GetTable(L"select status from Contacts where mobile_id = " +
767
wxString::Format(L"%ld", contact_id) +
769
#endif // _OMB_USE_CIPHER
770
ContactsTable.SetRow(0);
772
contact_exists = (ContactsTable.GetInt(0) > 0);
775
return contact_exists;
778
bool TData_v32::IsDate(int R){
779
return Lines[R].IsDate;
782
bool TData_v32::OpenDatabase(wxString File){
784
bool file_exist = ::wxFileExists(File);
787
#ifdef _OMB_USE_CIPHER
788
#ifdef __OMBCONVERT_BIN__
789
wxString pwd = wxEmptyString;
791
wxString pwd = GetKey();
792
wxString pwd_archive = GetKey(true);
793
#endif // __OMBCONVERT_BIN__
794
#endif // _OMB_USE_CIPHER
796
#ifndef __OMBCONVERT_BIN__
798
#ifdef _OMB_USE_CIPHER
799
if(! CheckAndPromptForConversion(File, false, pwd)){
801
if(! CheckAndPromptForConversion(File, false)){
802
#endif // _OMB_USE_CIPHER
806
wxString ArchiveName = Get_MasterDB();
807
bool master_exist = ::wxFileExists(ArchiveName);
810
#ifdef _OMB_USE_CIPHER
811
if(! CheckAndPromptForConversion(ArchiveName, true, pwd_archive)){
813
if(! CheckAndPromptForConversion(ArchiveName, true)){
814
#endif // _OMB_USE_CIPHER
817
#endif // __OMBCONVERT_BIN__
819
#ifdef __OPENMONEYBOX_EXE__
820
wxLogMessage(L"Opening database...");
821
#endif // __OPENMONEYBOX_EXE__
823
#ifdef _OMB_USE_CIPHER
827
IsEncrypted = IsEncryptedDB(File, pwd, wxEmptyString, true);
828
#ifndef __OMBCONVERT_BIN__
829
if(master_exist) IsEncrypted_master = IsEncryptedDB(ArchiveName, pwd_archive, wxEmptyString, true);
830
#endif // __OMBCONVERT_BIN__
833
sqlite3_open(File.c_str(), &database);
835
sqlite3_open(File, &database);
836
#endif // __OPENSUSE__
844
sqlite3_key(database, pwd.c_str(), pwd.length());
846
sqlite3_key(database, pwd, pwd.length());
847
#endif // __OPENSUSE__
848
int rc = sqlite3_exec(database, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL);
855
#ifndef __OMBCONVERT_BIN__
856
PasswordPrompt(database, false);
857
#endif // __OMBCONVERT_BIN__
871
if(result == 1) break;
875
database->Open(File, wxEmptyString, WXSQLITE_OPEN_READWRITE | WXSQLITE_OPEN_CREATE );
876
#endif // _OMB_USE_CIPHER
878
#ifdef __OPENMONEYBOX_EXE__
879
wxLogMessage(L"Database loaded.");
880
#endif // __OPENMONEYBOX_EXE__
883
FileData.FileName = File;
884
::wxFileName::SplitPath(File, NULL, NULL, &Name, NULL, wxPATH_NATIVE);
885
FileData.FileView = Name;
887
#ifndef __OMBCONVERT_BIN__
888
// Check if present Android backup to be archived in master db
890
wxSQLite3Table Table;
891
#ifdef _OMB_USE_CIPHER
895
Sql = L"select data from Information where id = " +
896
wxString::Format(L"%d", dbMeta_mobile_export) +
898
Table = GetTable(database, Sql.c_str());
900
Table = GetTable(database, L"select data from Information where id = " +
901
wxString::Format(L"%d", dbMeta_mobile_export) +
903
#endif // __OPENSUSE__
905
Table = database->GetTable(L"select data from Information where id = " +
906
wxString::Format(L"%d", dbMeta_mobile_export) +
908
#endif // _OMB_USE_CIPHER
910
wxString archive = Table.GetString(0, wxEmptyString);
912
if(! archive.IsEmpty()){
913
wxString Path, backup_file;
914
::wxFileName::SplitPath(File, &Path, NULL, NULL, wxPATH_NATIVE);
917
backup_file = Path + L"/_" + archive;
918
#elif defined ( __WXMSW__ )
919
backup_file = Path + "\\_" + archive;
922
if(::wxFileExists(backup_file)){
923
wxString master = Get_MasterDB();
924
wxString trailname = L"_" + archive;
925
bool has_cat = Prepare_MasterDB(master, trailname);
927
#if ( wxCHECK_VERSION(3, 0, 0) )
928
#ifdef _OMB_USE_CIPHER
931
Sql = wxString::Format(L"ATTACH DATABASE '%s' AS ext KEY '%s';", backup_file, pwd);
932
ExecuteUpdate(database, Sql.c_str());
934
ExecuteUpdate(database, wxString::Format(L"ATTACH DATABASE '%s' AS ext KEY '%s';", backup_file, pwd));
935
#endif // __OPENSUSE__
937
// Archive data in master database from external archive
938
Sql = L"INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM ext.Transactions;";
939
ExecuteUpdate(database, Sql.c_str());
941
Sql = wxString::Format(L"INSERT INTO master.Funds%s SELECT * FROM ext.Funds%s;", trailname, trailname);
942
ExecuteUpdate(database, Sql.c_str());
943
Sql = wxString::Format(L"INSERT INTO master.Credits%s SELECT * FROM ext.Credits%s;", trailname, trailname);
944
ExecuteUpdate(database, Sql.c_str());
945
Sql = wxString::Format(L"INSERT INTO master.Debts%s SELECT * FROM ext.Debts%s;", trailname, trailname);
946
ExecuteUpdate(database, Sql.c_str());
947
Sql = wxString::Format(L"INSERT INTO master.Loans%s SELECT * FROM ext.Loans%s;", trailname, trailname);
948
ExecuteUpdate(database, Sql.c_str());
949
Sql = wxString::Format(L"INSERT INTO master.Borrows%s SELECT * FROM ext.Borrows%s;", trailname, trailname);
950
ExecuteUpdate(database, Sql.c_str());
952
ExecuteUpdate(database, wxString::Format(L"INSERT INTO master.Funds%s SELECT * FROM ext.Funds%s;", trailname, trailname));
953
ExecuteUpdate(database, wxString::Format(L"INSERT INTO master.Credits%s SELECT * FROM ext.Credits%s;", trailname, trailname));
954
ExecuteUpdate(database, wxString::Format(L"INSERT INTO master.Debts%s SELECT * FROM ext.Debts%s;", trailname, trailname));
955
ExecuteUpdate(database, wxString::Format(L"INSERT INTO master.Loans%s SELECT * FROM ext.Loans%s;", trailname, trailname));
956
ExecuteUpdate(database, wxString::Format(L"INSERT INTO master.Borrows%s SELECT * FROM ext.Borrows%s;", trailname, trailname));
957
#endif // __OPENSUSE__
959
database->ExecuteUpdate(wxString::Format(L"ATTACH DATABASE '%s' AS master;", master));
960
database->ExecuteUpdate(wxString::Format(L"ATTACH DATABASE '%s' AS ext;", backup_file));
962
// Archive data in master database from external archive
963
database->ExecuteUpdate(L"INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM ext.Transactions;");
964
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Funds%s SELECT * FROM ext.Funds%s;", trailname, trailname));
965
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Credits%s SELECT * FROM ext.Credits%s;", trailname, trailname));
966
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Debts%s SELECT * FROM ext.Debts%s;", trailname, trailname));
967
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Loans%s SELECT * FROM ext.Loans%s;", trailname, trailname));
968
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Borrows%s SELECT * FROM ext.Borrows%s;", trailname, trailname));
969
#endif // _OMB_USE_CIPHER
971
database->ExecuteUpdate(wxString::Format(L"ATTACH DATABASE '%s' AS master;", master.c_str()));
972
database->ExecuteUpdate(wxString::Format(L"ATTACH DATABASE '%s' AS ext;", backup_file.c_str()));
974
// Archive data in master database from external archive
975
database->ExecuteUpdate(L"INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM ext.Transactions;");
976
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Funds%s SELECT * FROM ext.Funds%s;", trailname.c_str(), trailname.c_str()));
977
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Credits%s SELECT * FROM ext.Credits%s;", trailname.c_str(), trailname.c_str()));
978
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Debts%s SELECT * FROM ext.Debts%s;", trailname.c_str(), trailname.c_str()));
979
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Loans%s SELECT * FROM ext.Loans%s;", trailname.c_str(), trailname.c_str()));
980
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Borrows%s SELECT * FROM ext.Borrows%s;", trailname.c_str(), trailname.c_str()));
983
#ifdef _OMB_USE_CIPHER
985
Sql = L"INSERT INTO master.Categories SELECT * FROM ext.Categories;";
986
ExecuteUpdate(database, Sql.c_str()/*, false*/);
988
Sql = L"DETACH DATABASE 'master';";
989
ExecuteUpdate(database, Sql.c_str()/*, false*/);
990
Sql = L"DETACH DATABASE 'ext';";
991
ExecuteUpdate(database, Sql.c_str());
994
Sql = L"update Information set data = \"\" where id = " +
995
wxString::Format(L"%d", dbMeta_mobile_export) +
997
ExecuteUpdate(database, Sql.c_str());
999
ExecuteUpdate(database, L"update Information set data = \"\" where id = " +
1000
wxString::Format(L"%d", dbMeta_mobile_export) +
1002
#endif // __OPENSUSE__
1004
if(! has_cat) database->ExecuteUpdate(L"INSERT INTO master.Categories SELECT * FROM ext.Categories;");
1006
database->ExecuteUpdate(L"DETACH DATABASE 'master';");
1007
database->ExecuteUpdate(L"DETACH DATABASE 'ext';");
1009
database->ExecuteUpdate(L"update Information set data = \"\" where id = " +
1010
wxString::Format(L"%d", dbMeta_mobile_export) +
1012
#endif // _OMB_USE_CIPHER
1014
::wxRemoveFile(backup_file);
1017
#endif // __OMBCONVERT_BIN__
1020
#ifdef _OMB_USE_CIPHER
1024
wxString Sql = L"pragma user_version = " +
1025
::wxString::Format(L"%d", dbVersion) +
1027
ExecuteUpdate(database, Sql.c_str());
1030
ExecuteUpdate(database, L"pragma user_version = " +
1031
::wxString::Format(L"%d", dbVersion) +
1033
#endif // __OPENSUSE__
1034
// Set restore savepoint
1035
ExecuteUpdate(database, "SAVEPOINT rollback;");
1038
else database->ExecuteUpdate(L"pragma user_version = " +
1039
::wxString::Format(L"%d", dbVersion) +
1042
// Set restore savepoint
1043
database->Savepoint(L"rollback");
1044
#endif // _OMB_USE_CIPHER
1046
#ifdef __OPENMONEYBOX_EXE__
1047
wxLogMessage(L"Rollback savepoint set in database");
1048
#endif // __OPENMONEYBOX_EXE__
1050
#if wxCHECK_VERSION(3, 0, 0)
1051
// Write file metadata
1055
metadata += wxGetLinuxDistributionInfo().Description;
1056
#elif defined ( __WXMSW__)
1057
metadata += wxGetOsDescription();
1059
,etadata += L"unknown";
1061
metadata += L"\n\n";
1062
#ifndef __OMBCONVERT_BIN__
1063
metadata += wxGetLibraryVersionInfo().ToString();
1065
metadata += _("Converted with ombconvert");
1066
#endif // __OMBCONVERT_BIN__
1067
#endif // wxCHECK_VERSION
1069
#ifdef _OMB_USE_CIPHER
1070
if(! TableExists(L"Information", wxEmptyString, database)){
1072
ExecuteUpdate(database, cs_information.c_str());
1074
ExecuteUpdate(database, cs_information);
1075
#endif // __OPENSUSE__
1077
#if wxCHECK_VERSION(3, 0, 0)
1079
wxString Sql = L"insert into Information values (" +
1080
wxString::Format(L"%d", dbMeta_application_info) +
1084
ExecuteUpdate(database, Sql.c_str());
1086
ExecuteUpdate(database, L"insert into Information values (" +
1087
wxString::Format(L"%d", dbMeta_application_info) +
1091
#endif // __OPENSUSE__
1092
#endif // wxCHECK_VERSION
1095
Sql = L"insert into Information values (" +
1096
wxString::Format(L"%d", dbMeta_default_fund) +
1098
ExecuteUpdate(database, Sql.c_str());
1099
Sql = L"insert into Information values (" +
1100
wxString::Format(L"%d", dbMeta_mobile_export) +
1102
ExecuteUpdate(database, Sql.c_str());
1104
ExecuteUpdate(database, L"insert into Information values (" +
1105
wxString::Format(L"%d", dbMeta_default_fund) +
1107
ExecuteUpdate(database, L"insert into Information values (" +
1108
wxString::Format(L"%d", dbMeta_mobile_export) +
1110
#endif // __OPENSUSE__
1112
#if wxCHECK_VERSION(3, 0, 0)
1116
wxString Sql = L"update Information set data = \"" +
1119
wxString::Format(L"%d", dbMeta_application_info) +
1121
ExecuteUpdate(database, Sql.c_str());
1124
ExecuteUpdate(database, L"update Information set data = \"" +
1127
wxString::Format(L"%d", dbMeta_application_info) +
1129
#endif // __OPENSUSE__
1130
#endif // wxCHECK_VERSION
1132
if(! database->TableExists(L"Information")){
1133
database->ExecuteUpdate(cs_information);
1135
#if wxCHECK_VERSION(3, 0, 0)
1136
database->ExecuteUpdate(L"insert into Information values (" +
1137
wxString::Format(L"%d", dbMeta_application_info) +
1141
#endif // wxCHECK_VERSION
1142
database->ExecuteUpdate(L"insert into Information values (" +
1143
wxString::Format(L"%d", dbMeta_default_fund) +
1145
database->ExecuteUpdate(L"insert into Information values (" +
1146
wxString::Format(L"%d", dbMeta_mobile_export) +
1149
#if wxCHECK_VERSION(3, 0, 0)
1150
else database->ExecuteUpdate(L"update Information set data = \"" +
1153
wxString::Format(L"%d", dbMeta_application_info) +
1155
#endif // wxCHECK_VERSION
1156
#endif // _OMB_USE_CIPHER
1158
// Set currency when if not present (added later in dbVersion 31)
1159
wxSQLite3Table currencyTable;
1160
#ifdef _OMB_USE_CIPHER
1162
wxString Sql = L"select data from Information where id = " +
1163
wxString::Format(L"%d", dbMeta_currency) +
1165
currencyTable = GetTable(database, Sql.c_str());
1167
currencyTable = GetTable(database, L"select data from Information where id = " +
1168
wxString::Format(L"%d", dbMeta_currency) +
1170
#endif // __OPENSUSE__
1172
currencyTable = database->GetTable(L"select data from Information where id = " +
1173
wxString::Format(L"%d", dbMeta_currency) +
1175
#endif // _OMB_USE_CIPHER
1176
if(currencyTable.GetRowCount() == 0){
1177
wxString curr = GetCurrencySymbol();
1178
#ifdef _OMB_USE_CIPHER
1180
Sql = L"insert into Information values (" +
1181
wxString::Format(L"%d", dbMeta_currency) +
1185
ExecuteUpdate(database, Sql.c_str());
1187
ExecuteUpdate(database, L"insert into Information values (" +
1188
wxString::Format(L"%d", dbMeta_currency) +
1192
#endif // __OPENSUSE__
1194
database->ExecuteUpdate(L"insert into Information values (" +
1195
wxString::Format(L"%d", dbMeta_currency) +
1199
#endif // _OMB_USE_CIPHER
1202
#ifdef __OPENMONEYBOX_EXE__
1203
wxLogMessage(L"Database metadata updated");
1204
#endif // __OPENMONEYBOX_EXE__
1206
#ifdef _OMB_USE_CIPHER
1208
// Transaction table init
1209
if(! TableExists(L"Transactions", wxEmptyString, database)) ExecuteUpdate(database, cs_transactions.c_str());
1211
// Category table init
1212
if(! TableExists(L"Categories", wxEmptyString, database)) ExecuteUpdate(database, cs_categories.c_str());
1214
// Transaction table init
1215
if(! TableExists(L"Transactions", wxEmptyString, database)) ExecuteUpdate(database, cs_transactions);
1217
// Category table init
1218
if(! TableExists(L"Categories", wxEmptyString, database)) ExecuteUpdate(database, cs_categories);
1219
#endif // __OPENSUSE__
1221
// Transaction table init
1222
if(! database->TableExists(L"Transactions")) database->ExecuteUpdate(cs_transactions);
1224
// Category table init
1225
if(! database->TableExists(L"Categories")) database->ExecuteUpdate(cs_categories);
1226
#endif // _OMB_USE_CIPHER
1229
FileData.Modified = false;
1233
bool TData_v32::AddObject(TObjType T, int id, wxString N, wxString O, wxDateTime D, long c_index){
1234
if(N.IsEmpty() || O.IsEmpty())return false;
1235
if (D == invalidDate) return false;
1239
O = DoubleQuote(O);}
1245
Lent[NLen].Name = N;
1246
Lent[NLen].Object = O;
1247
Lent[NLen].Alarm = D;
1248
Lent[NLen].ContactIndex = c_index;
1251
#ifdef _OMB_USE_CIPHER
1253
if(! TableExists(L"Loans", wxEmptyString, database)) ExecuteUpdate(database, cs_loans.c_str());
1254
wxString Sql = L"insert into Loans values (NULL, '" +
1259
wxString::Format(L"%d", (int) D.GetTicks()) +
1262
wxString::Format(L"%ld", c_index) +
1265
ExecuteUpdate(database, Sql.c_str());
1267
if(! TableExists(L"Loans", wxEmptyString, database)) ExecuteUpdate(database, cs_loans);
1268
ExecuteUpdate(database, L"insert into Loans values (NULL, '" +
1273
wxString::Format(L"%d", (int) D.GetTicks()) +
1276
wxString::Format(L"%ld", c_index) +
1279
#endif // __OPENSUSE__
1281
if(! database->TableExists(L"Loans")) database->ExecuteUpdate(cs_loans);
1282
database->ExecuteUpdate(L"insert into Loans values (NULL, '" +
1287
wxString::Format(L"%d", (int) D.GetTicks()) +
1290
wxString::Format(L"%ld", c_index) +
1293
#endif // _OMB_USE_CIPHER
1298
Borrowed[NBor].Id = id;
1299
Borrowed[NBor].Name = N;
1300
Borrowed[NBor].Object = O;
1301
Borrowed[NBor].Alarm = D;
1302
Borrowed[NBor].ContactIndex = c_index;
1305
#ifdef _OMB_USE_CIPHER
1307
if(! TableExists(L"Borrows", wxEmptyString, database)) ExecuteUpdate(database, cs_borrows.c_str());
1308
wxString Sql = L"insert into Borrows values (NULL, '" +
1313
wxString::Format(L"%d", (int) D.GetTicks()) +
1316
wxString::Format(L"%ld", c_index) +
1319
ExecuteUpdate(database, Sql.c_str());
1321
if(! TableExists(L"Borrows", wxEmptyString, database)) ExecuteUpdate(database, cs_borrows);
1322
ExecuteUpdate(database, L"insert into Borrows values (NULL, '" +
1327
wxString::Format(L"%d", (int) D.GetTicks()) +
1330
wxString::Format(L"%ld", c_index) +
1333
#endif // __OPENSUSE__
1335
if(! database->TableExists(L"Borrows")) database->ExecuteUpdate(cs_borrows);
1336
database->ExecuteUpdate(L"insert into Borrows values (NULL, '" +
1341
wxString::Format(L"%d", (int) D.GetTicks()) +
1344
wxString::Format(L"%ld", c_index) +
1347
#endif // _OMB_USE_CIPHER
1351
FileData.Modified = true;
1355
bool TData_v32::AddValue(TTypeVal T, int id, wxString N, double V, long c_index){
1357
if(N.IsEmpty() || V == 0) return false;
1365
#if( wxCHECK_VERSION(3,0,0) )
1366
curstr = ::wxString::FromCDouble(V, 2);
1368
curstr = FormDigits(V);
1373
for(x = 0; x < NFun; x++)if(Funds[x].Name == N){
1378
Funds[NFun].Id = id;
1379
Funds[NFun].Name = N;
1380
Funds[NFun].Value = V;}
1382
#ifdef _OMB_USE_CIPHER
1384
if(! TableExists(L"Funds", wxEmptyString, database)) ExecuteUpdate(database, cs_funds.c_str());
1385
wxString Sql = L"insert into Funds values (NULL, '" +
1390
ExecuteUpdate(database, Sql.c_str());
1392
if(! TableExists(L"Funds", wxEmptyString, database)) ExecuteUpdate(database, cs_funds);
1393
ExecuteUpdate(database, L"insert into Funds values (NULL, '" +
1398
#endif // __OPENSUSE__
1400
if(! database->TableExists(L"Funds")) database->ExecuteUpdate(cs_funds);
1402
database->ExecuteUpdate(L"insert into Funds values (NULL, '" +
1407
#endif // _OMB_USE_CIPHER
1412
for(x = 0; x < NCre; x++) if(Credits[x].Name == N){
1413
Credits[x].Value += V;
1414
ChangeFundValue(tvCre, Credits[x].Id, Credits[x].Value);
1419
Credits[NCre].Id = id;
1420
Credits[NCre].Name = N;
1421
Credits[NCre].Value = V;
1422
Credits[NCre].ContactIndex = c_index;
1425
#ifdef _OMB_USE_CIPHER
1427
if(! TableExists(L"Credits", wxEmptyString, database)) ExecuteUpdate(database, cs_credits.c_str());
1428
wxString Sql = L"insert into Credits values (NULL, '" +
1434
wxString::Format(L"%ld", c_index) +
1437
ExecuteUpdate(database, Sql.c_str());
1439
if(! TableExists(L"Credits", wxEmptyString, database)) ExecuteUpdate(database, cs_credits);
1440
ExecuteUpdate(database, L"insert into Credits values (NULL, '" +
1446
wxString::Format(L"%ld", c_index) +
1449
#endif // __OPENSUSE__
1451
if(! database->TableExists(L"Credits")) database->ExecuteUpdate(cs_credits);
1453
database->ExecuteUpdate(L"insert into Credits values (NULL, '" +
1459
wxString::Format(L"%ld", c_index) +
1462
#endif // _OMB_USE_CIPHER
1467
for(x = 0; x < NDeb; x++) if(Debts[x].Name == N){
1468
Debts[x].Value += V;
1469
ChangeFundValue(tvDeb, Debts[x].Id, Debts[x].Value);
1474
Debts[NDeb].Id = id;
1475
Debts[NDeb].Name = N;
1476
Debts[NDeb].Value = V;
1477
Debts[NDeb].ContactIndex = c_index;
1480
#ifdef _OMB_USE_CIPHER
1482
if(! TableExists(L"Debts", wxEmptyString, database)) ExecuteUpdate(database, cs_debts.c_str());
1483
wxString Sql = L"insert into Debts values (NULL, '" +
1489
wxString::Format(L"%ld", c_index) +
1492
ExecuteUpdate(database, Sql.c_str());
1494
if(! TableExists(L"Debts", wxEmptyString, database)) ExecuteUpdate(database, cs_debts);
1495
ExecuteUpdate(database, L"insert into Debts values (NULL, '" +
1501
wxString::Format(L"%ld", c_index) +
1504
#endif // __OPENSUSE__
1506
if(! database->TableExists(L"Debts")) database->ExecuteUpdate(cs_debts);
1507
database->ExecuteUpdate(L"insert into Debts values (NULL, '" +
1513
wxString::Format(L"%ld", c_index) +
1516
#endif // _OMB_USE_CIPHER
1525
FileData.Modified=true;}
1529
void TData_v32::CleanMaster(void){
1530
// TODO (igor#1#): To be implemented: ...
1531
// - clean empty Credits tables
1532
// - clean empty Debts tables
1533
// - clean empty Loans tables
1534
// - clean empty Borros tables
1540
bool TData_v32::ChangeFundValue(TTypeVal type, int id, double V){
1553
table = wxEmptyString;}
1555
#if (wxCHECK_VERSION(3, 0, 0) )
1556
wxString curstr = ::wxString::FromCDouble(V, 2);
1558
wxString curstr = ::wxString::Format(L"%f", V);
1560
#ifndef __OMBCONVERT_BIN__
1562
case wxLANGUAGE_ITALIAN:
1563
SubstLocaleDecimalSeparator(curstr, ',');
1569
SubstLocaleDecimalSeparator(curstr, ',');
1570
#endif // __OMBCONVERT_BIN__
1572
#endif // wxCHECK_VERSION
1574
#ifdef _OMB_USE_CIPHER
1576
wxString Sql = L"update " + table + L" set value = " +
1579
wxString::Format(L"%d", id) +
1581
ExecuteUpdate(database, Sql.c_str());
1583
ExecuteUpdate(database, L"update " + table + L" set value = " +
1586
wxString::Format(L"%d", id) +
1588
#endif // __OPENSUSE__
1590
database->ExecuteUpdate(L"update " + table + L" set value = " +
1593
wxString::Format(L"%d", id) +
1595
#endif // _OMB_USE_CIPHER
1598
FileData.Modified=true;
1601
#ifndef __OMBCONVERT_BIN__
1602
void TData_v32::XMLExport(wxString F1, wxString F2){
1603
bool FirstDate=false; // set when first date is inserted
1604
wxString App; // line to append
1605
double cur; // value storage
1606
//wxArrayString RemarkTokens;
1608
wxString dir = wxDirSelector(_("Select a folder"),GetBilDocPath());
1609
if(dir.IsEmpty())return;
1610
::wxBeginBusyCursor(wxHOURGLASS_CURSOR);
1613
dir = dir + L"\\" + GetDocPrefix() + L"_" + ::wxString::Format("%d", FileData.Year) + L"-"
1614
+ ::wxString::Format("%02d", FileData.Month);
1616
dir = dir + L"/" + GetDocPrefix() + L"_" + ::wxString::Format(L"%d", FileData.Year);
1617
#if(wxCHECK_VERSION(3,0,0))
1618
dir = dir + L"-" + ::wxString::Format(L"%02d", int(FileData.Month));
1620
dir = dir + L"-" + ::wxString::Format(L"%02d", FileData.Month);
1623
if(!wxDirExists(dir))if(!wxMkdir(dir,0777))return;
1624
// xsl template copy
1626
wxString xsltempl=GetInstallationPath()+L"\\data";
1628
wxString xsltempl=GetDataDir();
1631
wxLanguage Lan=FindLang();
1634
case wxLANGUAGE_ITALIAN:
1638
xsltempl+=L"\\it\\";
1645
xsltempl+=L"\\en\\";
1648
xsltempl += L"ombexport.xsl";
1649
wxCopyFile(xsltempl, dir + L"/ombexport.xsl");
1650
// xml document creation
1651
wxString xmlfile = dir + L"/" + GetDocPrefix() + L".xml";
1652
wxTextFile *file = new wxTextFile(xmlfile);
1654
file->AddLine(L"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
1656
file->AddLine(L"<!--File Created By OpenMoneyBox 3.3 on " + wxDateTime::Today().Format(L"%d/%m/%Y") + L" " + wxDateTime::Now().Format(L"%H:%M") + L"-->");
1658
file->AddLine(L"<!--File Created By OpenMoneyBox 3.3 on " + wxDateTime::Today().Format(L"%d/%02m/%Y") + L" "+wxDateTime::Now().Format(L"%H:%M") + L"-->");
1660
file->AddLine(L"<?xml-stylesheet type=\"text/xsl\" href=\"ombexport.xsl\"?>");
1661
file->AddLine(L"<groups><headers>");
1662
wxString Header=_("Monthly report of");
1664
file->AddLine(L"<title heading=\""+Header+L" \" month=\""+IntToMonth(FileData.Month)+L" "+::wxString::Format("%d",FileData.Year)+L"\" />");
1666
file->AddLine(L"<title heading=\""+Header+L" \" month=\""+IntToMonth(FileData.Month)+L" "+::wxString::Format(L"%d",FileData.Year)+L"\" />");
1668
file->AddLine(L"</headers><days>");
1670
for(int i = 0; i < NLin; i++){
1673
if(!FirstDate)FirstDate=true;
1674
else file->AddLine(L"</day>");
1675
App+=L"<day date=\"";
1677
App+=Lines[i].Date.Format("%a %d/%m/%Y",wxDateTime::Local);
1679
App+=Lines[i].Date.Format(L"%a %d/%m/%Y",wxDateTime::Local);
1681
App+=L"\" total=\"";
1682
Lines[i].Value.ToDouble(&cur);
1683
App+=FormDigits(cur);
1685
file->AddLine(App);}
1687
App+=L"<item time=\"";
1689
App+=Lines[i].Time.Format("%H:%M",wxDateTime::Local);
1691
App+=Lines[i].Time.Format(L"%H:%M",wxDateTime::Local);
1694
switch(Lines[i].Type){
1740
App += L"\" value=\"";
1741
if(Lines[i].Type < 9){
1742
Lines[i].Value.ToDouble(&cur);
1743
App += FormDigits(cur);}
1745
if(Lines[i].Value.Find(L"\"") != wxNOT_FOUND){
1746
wxString vals = Lines[i].Value;
1747
vals.Replace(L"\"", L"[OMB_ESCAPEQUOTES]", true); // intermediate string to be processed by SubstSpecialChars
1750
else App += Lines[i].Value;
1753
App += L"\" reason=\"";
1755
if(Lines[i].Reason.Find(L"\"") != wxNOT_FOUND){
1756
wxString reas = Lines[i].Reason;
1757
reas.Replace(L"\"", L"[OMB_ESCAPEQUOTES]", true); // intermediate string to be processed by SubstSpecialChars
1760
else App+=Lines[i].Reason;
1762
App+=L"\" category=\"";
1763
App=SubstSpecialChars(App);
1765
if(Lines[i].CategoryIndex != -1)
1766
for(int j = 0; j < NCat; j++)if(Categories[j].Id == Lines[i].CategoryIndex){
1767
file->AddLine(Categories[j].Name);
1769
file->AddLine(L"\"/>");}}
1771
file->AddLine(L"</day></days></groups>");
1772
file->Write(wxTextFileType_Unix,wxConvUTF8);
1776
// Logo picture copy
1778
xsltempl=GetDataDir()+L"logo.png";
1780
xsltempl=GetInstallationPath()+L"\\data\\logo.png";
1782
wxCopyFile(xsltempl,dir+L"/logo.png");
1784
wxCopyFile(F1, dir+L"/chart1.png");
1785
wxCopyFile(F2, dir+L"/chart2.png");
1786
::wxEndBusyCursor();}
1787
#endif // __OMBCONVERT_BIN__
1789
#ifndef __OMBCONVERT_BIN__
1790
void TData_v32::Archive_inMaster(wxString master, wxString trailname, bool archive_categories){
1791
// master: database to attach and archive data in
1792
// trailname: suffix for tables
1793
// archive_categories: true to archive also categories
1795
#if(wxCHECK_VERSION(3, 0, 0))
1796
#ifdef _OMB_USE_CIPHER
1799
// Archive data in master database
1800
ExecuteUpdate(database, "INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM Transactions;");
1802
wxString Sql = wxString::Format("INSERT INTO master.Funds%s SELECT * FROM Funds;", trailname);
1803
ExecuteUpdate(database, Sql.c_str());
1804
Sql = wxString::Format("INSERT INTO master.Credits%s SELECT * FROM Credits;", trailname);
1805
ExecuteUpdate(database, Sql.c_str());
1806
Sql = wxString::Format("INSERT INTO master.Debts%s SELECT * FROM Debts;", trailname);
1807
ExecuteUpdate(database, Sql.c_str());
1808
Sql = wxString::Format("INSERT INTO master.Loans%s SELECT * FROM Loans;", trailname);
1809
ExecuteUpdate(database, Sql.c_str());
1810
Sql = wxString::Format("INSERT INTO master.Borrows%s SELECT * FROM Borrows;", trailname);
1811
ExecuteUpdate(database, Sql.c_str());
1813
ExecuteUpdate(database, wxString::Format("INSERT INTO master.Funds%s SELECT * FROM Funds;", trailname));
1814
ExecuteUpdate(database, wxString::Format("INSERT INTO master.Credits%s SELECT * FROM Credits;", trailname));
1815
ExecuteUpdate(database, wxString::Format("INSERT INTO master.Debts%s SELECT * FROM Debts;", trailname));
1816
ExecuteUpdate(database, wxString::Format("INSERT INTO master.Loans%s SELECT * FROM Loans;", trailname));
1817
ExecuteUpdate(database, wxString::Format("INSERT INTO master.Borrows%s SELECT * FROM Borrows;", trailname));
1818
#endif // __OPENSUSE__
1820
database->ExecuteUpdate(wxString::Format("ATTACH DATABASE '%s' AS master;", master));
1822
// Archive data in master database
1823
database->ExecuteUpdate("INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM Transactions;");
1824
database->ExecuteUpdate(wxString::Format("INSERT INTO master.Funds%s SELECT * FROM Funds;", trailname));
1825
database->ExecuteUpdate(wxString::Format("INSERT INTO master.Credits%s SELECT * FROM Credits;", trailname));
1826
database->ExecuteUpdate(wxString::Format("INSERT INTO master.Debts%s SELECT * FROM Debts;", trailname));
1827
database->ExecuteUpdate(wxString::Format("INSERT INTO master.Loans%s SELECT * FROM Loans;", trailname));
1828
database->ExecuteUpdate(wxString::Format("INSERT INTO master.Borrows%s SELECT * FROM Borrows;", trailname));
1829
#endif // _OMB_USE_CIPHER
1831
database->ExecuteUpdate(wxString::Format(L"ATTACH DATABASE '%s' AS master;", master.c_str()));
1833
// Archive data in master database
1834
database->ExecuteUpdate("INSERT INTO master.Transactions (isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude) SELECT isdate, date, time, type, value, reason, cat_index, contact_index, latitude, longitude FROM Transactions;");
1835
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Funds%s SELECT * FROM Funds;", trailname.c_str()));
1836
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Credits%s SELECT * FROM Credits;", trailname.c_str()));
1837
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Debts%s SELECT * FROM Debts;", trailname.c_str()));
1838
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Loans%s SELECT * FROM Loans;", trailname.c_str()));
1839
database->ExecuteUpdate(wxString::Format(L"INSERT INTO master.Borrows%s SELECT * FROM Borrows;", trailname.c_str()));
1840
#endif // wxCHECK_VERSION
1842
#ifdef _OMB_USE_CIPHER
1843
if(archive_categories) ExecuteUpdate(database, "INSERT INTO master.Categories SELECT * FROM Categories;");
1844
ExecuteUpdate(database, "DETACH DATABASE 'master';");
1846
if(archive_categories) database->ExecuteUpdate("INSERT INTO master.Categories SELECT * FROM Categories;");
1847
database->ExecuteUpdate("DETACH DATABASE 'master';");
1848
#endif // _OMB_USE_CIPHER
1850
#endif // __OMBCONVERT_BIN__
1852
#ifndef __OMBCONVERT_BIN__
1853
bool TData_v32::Prepare_MasterDB(wxString dbPath, wxString trailname){
1854
// master: database to attach and archive data in
1855
// trailname: suffix for tables
1857
bool file_exist = ::wxFileExists(dbPath);
1859
#ifdef _OMB_USE_CIPHER
1860
wxString pwd_archive = GetKey(true);
1864
sqlite3_open(dbPath.c_str(), &db);
1865
sqlite3_key(db, pwd_archive.c_str(), pwd_archive.length());
1867
sqlite3_open(dbPath, &db);
1868
sqlite3_key(db, pwd_archive, pwd_archive.length());
1869
#endif // __OPENSUSE__
1871
int rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL);
1878
PasswordPrompt(db, true);
1885
wxSQLite3Database *db = new wxSQLite3Database();
1886
db->Open(dbPath, wxEmptyString, WXSQLITE_OPEN_READWRITE | WXSQLITE_OPEN_CREATE );
1887
#endif // _OMB_USE_CIPHER
1889
#ifdef _OMB_USE_CIPHER
1892
wxString Sql = L"pragma user_version = " +
1893
::wxString::Format(L"%d", dbVersion) +
1895
ExecuteUpdate(db, Sql.c_str());
1898
if(! file_exist) ExecuteUpdate(db, L"pragma user_version = " +
1899
::wxString::Format(L"%d", dbVersion) +
1901
#endif // __OPENSUSE__
1903
if(! file_exist) db->ExecuteUpdate(L"pragma user_version = " +
1904
::wxString::Format(L"%d", dbVersion) +
1906
#endif // _OMB_USE_CIPHER
1909
#if wxCHECK_VERSION(3, 0, 0)
1910
// Write file metadata
1913
metadata += wxGetLinuxDistributionInfo().Description;
1914
#elif defined ( __WXMSW__)
1915
metadata += wxGetOsDescription();
1917
,etadata += L"unknown";
1919
metadata += L"\n\n";
1920
#ifndef __OMBCONVERT_BIN__
1921
metadata += wxGetLibraryVersionInfo().ToString();
1923
metadata += _("Converted with ombconvert");
1924
#endif // __OMBCONVERT_BIN__
1926
metadata = L"wxWidgets 2.8.0";
1927
#endif // wxCHECK_VERSION
1929
#ifdef _OMB_USE_CIPHER
1930
if(! TableExists(L"Information", "master", db)){
1932
ExecuteUpdate(db, cs_information.c_str());
1933
wxString Sql = L"insert into Information values (" +
1934
wxString::Format(L"%d", dbMeta_application_info) +
1938
ExecuteUpdate(db, Sql.c_str());
1940
ExecuteUpdate(db, cs_information);
1941
ExecuteUpdate(db, L"insert into Information values (" +
1942
wxString::Format(L"%d", dbMeta_application_info) +
1946
#endif // __OPENSUSE__
1951
wxString Sql = L"update Information set data = \"" +
1954
wxString::Format(L"%d", dbMeta_application_info) +
1956
ExecuteUpdate(db, Sql.c_str());
1959
ExecuteUpdate(db, L"update Information set data = \"" +
1962
wxString::Format(L"%d", dbMeta_application_info) +
1964
#endif // __OPENSUSE__
1966
if(! db->TableExists(L"Information")){
1967
db->ExecuteUpdate(cs_information);
1968
db->ExecuteUpdate(L"insert into Information values (" +
1969
wxString::Format(L"%d", dbMeta_application_info) +
1974
else db->ExecuteUpdate(L"update Information set data = \"" +
1977
wxString::Format(L"%d", dbMeta_application_info) +
1979
#endif // _OMB_USE_CIPHER
1981
#ifdef _OMB_USE_CIPHER
1983
// Transaction table init
1984
if(! TableExists(L"Transactions", "master", db)) ExecuteUpdate(db, cs_transactions.c_str());
1986
// Transaction table init
1987
if(! TableExists(L"Transactions", "master", db)) ExecuteUpdate(db, cs_transactions);
1988
#endif // __OPENSUSE__
1990
// Transaction table init
1991
if(! db->TableExists(L"Transactions")) db->ExecuteUpdate(cs_transactions);
1992
#endif // _OMB_USE_CIPHER
1994
#ifdef _OMB_USE_CIPHER
1995
// Category table init
1996
bool master_had_categories = TableExists(L"Categories", "master", db);
1998
// Category table init
1999
bool master_had_categories = db->TableExists(L"Categories");
2000
#endif // _OMB_USE_CIPHER
2002
if(master_had_categories){
2003
#if(wxCHECK_VERSION(3, 0, 0))
2004
#ifdef _OMB_USE_CIPHER
2005
if(! TableExists("Categories" + trailname, "master", db))
2008
wxString Sql = wxString::Format(cs_categories_master, trailname);
2009
ExecuteUpdate(db, Sql.c_str());
2012
ExecuteUpdate(db, wxString::Format(cs_categories_master, trailname));
2013
#endif // __OPENSUSE__
2015
if(! db->TableExists("Categories" + trailname)) db->ExecuteUpdate(wxString::Format(cs_categories_master, trailname));
2016
#endif // _OMB_USE_CIPHER
2018
if(! db->TableExists(L"Categories" + trailname)) db->ExecuteUpdate(wxString::Format(cs_categories_master, trailname.c_str()));
2019
#endif // wxCHECK_VERSION
2021
#ifdef _OMB_USE_CIPHER
2023
else ExecuteUpdate(db, cs_categories.c_str());
2025
else ExecuteUpdate(db, cs_categories);
2026
#endif // __OPENSUSE__
2028
else db->ExecuteUpdate(cs_categories);
2029
#endif // _OMB_USE_CIPHER
2031
#if(wxCHECK_VERSION(3, 0, 0))
2032
#ifdef _OMB_USE_CIPHER
2035
if(! TableExists("Funds" + trailname, "master", db)){
2036
Sql = wxString::Format(cs_funds_master, trailname);
2037
ExecuteUpdate(db, Sql.c_str());
2039
if(! TableExists("Credits" + trailname, "master", db)){
2040
Sql = wxString::Format(cs_credits_master, trailname);
2041
ExecuteUpdate(db, Sql.c_str());
2043
if(! TableExists("Debts" + trailname, "master", db)){
2044
Sql = wxString::Format(cs_debts_master, trailname);
2045
ExecuteUpdate(db, Sql.c_str());
2047
if(! TableExists("Loans" + trailname, "master", db)){
2048
Sql = wxString::Format(cs_loans_master, trailname);
2049
ExecuteUpdate(db, Sql.c_str());
2051
if(! TableExists("Borrows" + trailname, "master", db)){
2052
Sql = wxString::Format(cs_borrows_master, trailname);
2053
ExecuteUpdate(db, Sql.c_str());
2056
if(! TableExists("Funds" + trailname, "master", db)) ExecuteUpdate(db, wxString::Format(cs_funds_master, trailname));
2057
if(! TableExists("Credits" + trailname, "master", db)) ExecuteUpdate(db, wxString::Format(cs_credits_master, trailname));
2058
if(! TableExists("Debts" + trailname, "master", db)) ExecuteUpdate(db, wxString::Format(cs_debts_master, trailname));
2059
if(! TableExists("Loans" + trailname, "master", db)) ExecuteUpdate(db, wxString::Format(cs_loans_master, trailname));
2060
if(! TableExists("Borrows" + trailname, "master", db)) ExecuteUpdate(db, wxString::Format(cs_borrows_master, trailname));
2061
#endif // __OPENSUSE__
2063
if(! db->TableExists("Funds" + trailname)) db->ExecuteUpdate(wxString::Format(cs_funds_master, trailname));
2064
if(! db->TableExists("Credits" + trailname)) db->ExecuteUpdate(wxString::Format(cs_credits_master, trailname));
2065
if(! db->TableExists("Debts" + trailname)) db->ExecuteUpdate(wxString::Format(cs_debts_master, trailname));
2066
if(! db->TableExists("Loans" + trailname)) db->ExecuteUpdate(wxString::Format(cs_loans_master, trailname));
2067
if(! db->TableExists("Borrows" + trailname)) db->ExecuteUpdate(wxString::Format(cs_borrows_master, trailname));
2068
#endif // _OMB_USE_CIPHER
2070
if(! db->TableExists(L"Funds" + trailname)) db->ExecuteUpdate(wxString::Format(cs_funds_master, trailname.c_str()));
2071
if(! db->TableExists(L"Credits" + trailname)) db->ExecuteUpdate(wxString::Format(cs_credits_master, trailname.c_str()));
2072
if(! db->TableExists(L"Debts" + trailname)) db->ExecuteUpdate(wxString::Format(cs_debts_master, trailname.c_str()));
2073
if(! db->TableExists(L"Loans" + trailname)) db->ExecuteUpdate(wxString::Format(cs_loans_master, trailname.c_str()));
2074
if(! db->TableExists(L"Borrows" + trailname)) db->ExecuteUpdate(wxString::Format(cs_borrows_master, trailname.c_str()));
2075
#endif // wxCHECK_VERSION
2077
#ifdef _OMB_USE_CIPHER
2081
#endif // _OMB_USE_CIPHER
2083
return master_had_categories;
2085
#endif // __OMBCONVERT_BIN__
2087
#ifndef __OMBCONVERT_BIN__
2088
void TData_v32::XMLExport_archive(wxString F1, wxString F2, wxDateTime date){
2089
bool FirstDate=false; // set when first date is inserted
2090
wxString App; // line to append
2091
double cur; // value storage
2093
wxString dir = wxDirSelector(_("Select a folder"),GetBilDocPath());
2094
if(dir.IsEmpty())return;
2095
::wxBeginBusyCursor(wxHOURGLASS_CURSOR);
2098
dir = dir + L"\\" + GetDocPrefix() + L"_" + date.Format(L"%Y-%m");
2100
dir = dir + L"/" + GetDocPrefix() + L"_" + date.Format(L"%Y-%m");
2102
if(!wxDirExists(dir))if(!wxMkdir(dir,0777))return;
2103
// xsl template copy
2105
wxString xsltempl=GetInstallationPath()+L"\\data";
2107
wxString xsltempl=GetDataDir();
2110
wxLanguage Lan=FindLang();
2113
case wxLANGUAGE_ITALIAN:
2117
xsltempl+=L"\\it\\";
2124
xsltempl+=L"\\en\\";
2127
xsltempl += L"ombexport.xsl";
2128
wxCopyFile(xsltempl, dir + L"/ombexport.xsl");
2129
// xml document creation
2130
wxString xmlfile = dir + L"/" + GetDocPrefix() + L".xml";
2131
wxTextFile *file=new wxTextFile(xmlfile);
2133
file->AddLine(L"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
2135
file->AddLine(L"<!--File Created By OpenMoneyBox 3.3 on " + wxDateTime::Today().Format(L"%d/%m/%Y") + L" " + wxDateTime::Now().Format(L"%H:%M") + L"-->");
2137
file->AddLine(L"<!--File Created By OpenMoneyBox 3.3 on " + wxDateTime::Today().Format(L"%d/%02m/%Y") + L" " + wxDateTime::Now().Format(L"%H:%M") + L"-->");
2139
file->AddLine(L"<?xml-stylesheet type=\"text/xsl\" href=\"ombexport.xsl\"?>");
2140
file->AddLine(L"<groups><headers>");
2141
wxString Header=_("Monthly report of");
2143
file->AddLine(L"<title heading=\""+Header+L" \" month=\""+IntToMonth(FileData.Month)+L" "+::wxString::Format("%d",FileData.Year)+L"\" />");
2145
file->AddLine(L"<title heading=\"" + Header + L" \" month=\"" + IntToMonth(/*FileData.Month*/date.GetMonth() + 1) + L" " +
2146
::wxString::Format(L"%d", /*FileData.Year*/date.GetYear()) + L"\" />");
2148
file->AddLine(L"</headers><days>");
2150
int min_date, max_date;
2151
wxDateTime min_datetime, max_datetime, d_date, time;
2152
wxSQLite3Table transaction_table;
2153
wxString value_string, reas;
2155
min_datetime = date;
2156
min_datetime.SetDay(1);
2157
min_datetime.SetHour(0);
2158
min_datetime.SetMinute(0);
2159
min_datetime.SetSecond(0);
2160
min_datetime.SetMillisecond(0);
2161
min_date = min_datetime.GetTicks();
2163
max_datetime = date;
2164
max_datetime.SetToLastMonthDay(max_datetime.GetMonth(), max_datetime.GetYear());
2165
max_datetime.SetHour(23);
2166
max_datetime.SetMinute(59);
2167
max_datetime.SetSecond(59);
2168
max_datetime.SetMillisecond(999);
2169
max_date = max_datetime.GetTicks();
2171
#ifdef _OMB_USE_CIPHER
2173
wxString Sql = ::wxString::Format(L"SELECT * FROM master.Transactions WHERE date >= %d and date <= %d;", min_date, max_date);
2174
transaction_table = GetTable(database, Sql.c_str());
2176
transaction_table = GetTable(database, ::wxString::Format(L"SELECT * FROM master.Transactions WHERE date >= %d and date <= %d;", min_date, max_date));
2177
#endif // __OPENSUSE__
2179
transaction_table = database->GetTable(::wxString::Format(L"SELECT * FROM master.Transactions WHERE date >= %d and date <= %d;", min_date, max_date));
2180
#endif // _OMB_USE_CIPHER
2183
for(int i = 0; i < transaction_table.GetRowCount(); i++){
2184
transaction_table.SetRow(i);
2185
App = wxEmptyString;
2186
if(transaction_table.GetInt(L"isdate", false)){
2187
if(! FirstDate) FirstDate = true;
2188
else file->AddLine(L"</day>");
2189
App += L"<day date=\"";
2190
d_date = wxDateTime((time_t) transaction_table.GetInt(2, 0));
2192
App += d_date.Format("%a %d/%m/%Y", wxDateTime::Local);
2194
App += d_date.Format(L"%a %d/%m/%Y", wxDateTime::Local);
2196
App += L"\" total=\"";
2197
value_string = transaction_table.GetString(5, wxEmptyString);
2198
#if( wxCHECK_VERSION(3,0,0) )
2199
value_string.ToCDouble(&cur);
2201
value_string.ToDouble(&cur);
2203
App += FormDigits(cur);
2205
file->AddLine(App);}
2207
App+=L"<item time=\"";
2209
App+=Lines[i].Time.Format("%H:%M",wxDateTime::Local);
2211
time = wxDateTime((time_t) transaction_table.GetInt(3, 0));
2212
App += time.Format(L"%H:%M",wxDateTime::Local);
2214
App += L"\" type=\"";
2215
switch(transaction_table.GetInt(4, 0)){
2261
App += L"\" value=\"";
2262
value_string = transaction_table.GetString(5, wxEmptyString);
2263
if(transaction_table.GetInt(4, 0) < 9){
2264
#if( wxCHECK_VERSION(3,0,0) )
2265
value_string.ToCDouble(&cur);
2267
value_string.ToDouble(&cur);
2269
App += FormDigits(cur);}
2270
else App += value_string;
2271
App += L"\" reason=\"";
2273
reas = transaction_table.GetString(6, wxEmptyString);
2274
if(reas.Find(L"\"") != wxNOT_FOUND)
2275
reas.Replace(L"\"", L"[OMB_ESCAPEQUOTES]", true); // intermediate string to be processed by SubstSpecialChars
2278
App += L"\" category=\"";
2279
App = SubstSpecialChars(App);
2281
if(transaction_table.GetInt(7, 0) != -1)
2282
for(int j = 0; j < NCat; j++)if(Categories[j].Id == transaction_table.GetInt(7, 0)){
2283
file->AddLine(Categories[j].Name);
2285
file->AddLine(L"\"/>");}}
2287
file->AddLine(L"</day></days></groups>");
2288
file->Write(wxTextFileType_Unix,wxConvUTF8);
2292
// Logo picture copy
2294
xsltempl=GetDataDir()+L"logo.png";
2296
xsltempl=GetInstallationPath()+L"\\data\\logo.png";
2298
wxCopyFile(xsltempl,dir+L"/logo.png");
2300
wxCopyFile(F1, dir+L"/chart1.png");
2301
wxCopyFile(F2, dir+L"/chart2.png");
2302
::wxEndBusyCursor();}
2303
#endif // __OMBCONVERT_BIN__
2305
bool TData_v32::UpdateMatters(TOpType T){
2309
MattersBuffer->Clear();
2310
for(i = 0; i < NLin; i++)if(Lines[i].Type == T){
2312
for(j = 0; j < MattersBuffer->Count();j ++)if(MattersBuffer->Item(j).CmpNoCase(Lines[i].Reason) == 0){
2315
if(! Ex)MattersBuffer->Add(Lines[i].Reason);}
2316
MattersBuffer->Sort();
2319
void TData_v32::ChangeTransactionCategory(int id, int new_index){
2320
#ifdef _OMB_USE_CIPHER
2321
wxString Sql = L"update Transactions set cat_index = " +
2322
wxString::Format(L"%d", new_index) +
2324
wxString::Format(L"%d", id) +
2326
ExecuteUpdate(database, Sql.c_str()/*, false*/);
2328
database->ExecuteUpdate(L"update Transactions set cat_index = " +
2329
wxString::Format(L"%d", new_index) +
2331
wxString::Format(L"%d", id) +
2333
#endif // _OMB_USE_CIPHER
2337
#ifdef _OMB_USE_CIPHER
2338
#ifndef __OMBCONVERT_BIN__
2339
bool TData_v32::PasswordPrompt(sqlite3 *db, bool Archive = false){
2340
int Response, rc, return_value = false;
2343
TPassF *PassF = new TPassF(wxTheApp->GetTopWindow());
2346
PassF->PassLab->SetLabel(_("Insert the archive password:"));
2349
Response = PassF->ShowModal();}
2350
while(Response == wxID_RETRY);
2354
Key = PassF->Pass->GetValue();
2355
if(SetKey(Key, Archive)){
2357
sqlite3_key(db, Key.c_str(), Key.length());
2359
sqlite3_key(db, Key, Key.length());
2360
#endif // __OPENSUSE__
2361
rc = sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL);
2362
if (rc == SQLITE_OK)
2363
return_value = true;
2368
//Error(5, wxEmptyString); // This condition should never happen
2369
return_value = false;
2372
return return_value;
2374
#endif // __OMBCONVERT_BIN__
2375
#endif // _OMB_USE_CIPHER
2377
#ifndef __OMBCONVERT_BIN__
2378
#ifdef _OMB_USE_CIPHER
2379
void TData_v32::ModPass(void){
2383
TPassF *PassF = new TPassF(wxTheApp->GetTopWindow());
2384
PassF->Pass2->Show(true);
2385
PassF->ConfirmLab->Show(true);
2387
Response = PassF->ShowModal();}
2388
while(Response == wxID_RETRY);
2390
wxString ArchiveName = Get_MasterDB();
2395
// Change main database password
2396
Key = PassF->Pass->GetValue();
2399
if(sqlite3_rekey(database, Key.c_str(), Key.length()) == SQLITE_OK)
2401
if(sqlite3_rekey(database, Key, Key.length()) == SQLITE_OK)
2402
#endif // __OPENSUSE__
2406
sqlite3_close(database);
2407
IsEncrypted = IsEncryptedDB(FileData.FileName, Key);
2409
if(sqlite3_open(FileData.FileName.c_str(), &database) == SQLITE_OK){
2410
sqlite3_key(database, Key.c_str(), Key.length());
2412
if(sqlite3_open(FileData.FileName, &database) == SQLITE_OK){
2413
sqlite3_key(database, Key, Key.length());
2414
#endif // __OPENSUSE__
2415
if(sqlite3_exec(database, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK)
2420
// change archive password
2425
sqlite3_open(ArchiveName.c_str(), &Master);
2426
sqlite3_key(Master, Key.c_str(), Key.length());
2428
sqlite3_open(ArchiveName, &Master);
2429
sqlite3_key(Master, Key, Key.length());
2430
#endif // __OPENSUSE__
2432
Key = PassF->Pass->GetValue();
2433
if(IsEncrypted_master){
2435
if(sqlite3_rekey(Master, Key.c_str(), Key.length()) == SQLITE_OK)
2437
if(sqlite3_rekey(Master, Key, Key.length()) == SQLITE_OK)
2438
#endif // __OPENSUSE__
2442
sqlite3_close(Master);
2443
IsEncrypted_master = IsEncryptedDB(ArchiveName, Key);
2445
if(sqlite3_open(ArchiveName.c_str(), &Master) == SQLITE_OK){
2446
sqlite3_key(Master, Key.c_str(), Key.length());
2448
if(sqlite3_open(ArchiveName, &Master) == SQLITE_OK){
2449
sqlite3_key(Master, Key, Key.length());
2450
#endif // __OPENSUSE__
2451
if(sqlite3_exec(Master, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK)
2461
Error(5,wxEmptyString); // This condition should never happen
2465
#endif // _OMB_USE_CIPHER
2466
#endif // __OMBCONVERT_BIN__
2468
#ifndef __OMBCONVERT_BIN__
2469
#ifdef _OMB_USE_CIPHER
2470
bool TData_v32::AttachMaster(void){
2471
wxString ArchiveName = Get_MasterDB();
2473
if(::wxFileExists(ArchiveName)){
2474
wxString pwd_archive = GetKey(true);
2475
if(! CheckAndPromptForConversion(ArchiveName, true, pwd_archive))
2484
if(IsEncrypted_master){
2487
if(sqlite3_open(ArchiveName.c_str(), &Master) != SQLITE_OK) return false;
2488
sqlite3_key(Master, pwd_archive.c_str(), pwd_archive.length());
2490
if(sqlite3_open(ArchiveName, &Master) != SQLITE_OK) return false;
2491
sqlite3_key(Master, pwd_archive, pwd_archive.length());
2492
#endif // __OPENSUSE__
2493
int rc = sqlite3_exec(Master, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL);
2500
#ifndef __OMBCONVERT_BIN__
2501
PasswordPrompt(database, true);
2502
pwd_archive = GetKey(true);
2503
#endif // __OMBCONVERT_BIN__
2516
if(result == 1) break;
2521
wxString Sql = wxString::Format(L"ATTACH DATABASE '%s' AS master KEY '%s';", ArchiveName, pwd_archive);
2522
ExecuteUpdate(database, Sql.c_str());
2524
ExecuteUpdate(database, wxString::Format(L"ATTACH DATABASE '%s' AS master KEY '%s';", ArchiveName, pwd_archive));
2525
#endif // __OPENSUSE__
2531
#endif // _OMB_USE_CIPHER
2532
#endif // __OMBCONVERT_BIN__
2534
#endif // OMB33CORE_CPP_INCLUDED