-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncomeFile.cpp
More file actions
85 lines (69 loc) · 2.31 KB
/
IncomeFile.cpp
File metadata and controls
85 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "IncomeFile.h"
#include "Markup.h"
#include "ItemManager.h"
#include "SupportMethods.h"
void IncomeFile :: addIncomeToFile(Income income) {
string amount = SupportMethods :: convertFloatToString (income.getIncomeAmount());
CMarkup xml;
string fileNameWithIncomes = getFileName();
bool fileExists = xml.Load(fileNameWithIncomes);
if (!fileExists) {
xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
xml.AddElem(fileNameWithIncomes);
}
xml.FindElem();
xml.IntoElem();
xml.AddElem("Income");
xml.IntoElem();
xml.AddElem( "IncomeId", income.getIncomeId());
xml.AddElem( "UserId", income.getUserId() );
xml.AddElem( "Date", income.getIncomeDate() );
xml.AddElem( "Item", income.getIncomeName() );
xml.AddElem( "Amount", amount );
xml.OutOfElem();
xml.OutOfElem();
xml.Save(fileNameWithIncomes);
lastIncomeId++;
}
vector <Income> IncomeFile :: getIncomeFromFile(int ID_LOGGED_USER) {
int userId = 0;
Income income;
vector <Income> incomes;
CMarkup xml;
string fileNameWithIncomes = getFileName();
if (!xml.Load(fileNameWithIncomes)) {
cout << "Error: Cant load XML file." << endl;
}
if (xml.Load(fileNameWithIncomes)) {
xml.FindElem();
xml.IntoElem();
while ( xml.FindElem("Income")) {
xml.IntoElem();
xml.FindElem("IncomeId");
lastIncomeId = atoi(xml.GetData().c_str());
xml.FindElem("UserId");
userId = atoi(xml.GetData().c_str());
if (userId != ID_LOGGED_USER) {
xml.OutOfElem();
continue;
}
income.setupUserId(userId);
income.setupIncomeId(lastIncomeId);
xml.FindElem("Date");
string incomeDate = xml.GetData();
income.setupStringDate(incomeDate);
xml.FindElem("Item");
string incomeName = xml.GetData();
income.setupIncomeName(incomeName);
xml.FindElem("Amount");
float incomeAmount = atoi(xml.GetData().c_str());
income.setupIncomeAmount(incomeAmount);
xml.OutOfElem();
incomes.push_back(income);
}
}
return incomes;
}
int IncomeFile :: getLastIncomeId() {
return lastIncomeId;
}