-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncomesFile.cpp
More file actions
79 lines (69 loc) · 2.23 KB
/
IncomesFile.cpp
File metadata and controls
79 lines (69 loc) · 2.23 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
#include "IncomesFile.h"
vector <Income> IncomesFile::loadIncomesOfLoggedInUserFromXmlFile(int loggedInUserId) {
CMarkup xml;
Income income;
vector <Income> incomes;
if (!xml.Load(getFilename())) {
xml.SetDoc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
xml.AddElem("IncomesFile");
xml.Save(getFilename());
}
xml.FindElem("IncomesFile");
xml.IntoElem();
while (xml.FindElem("Income")) {
xml.IntoElem();
xml.FindElem("UserId");
if (atoi(xml.GetData().c_str())!=loggedInUserId)
xml.OutOfElem();
else {
income.setUserId(atoi(xml.GetData().c_str()));
xml.FindElem("TransactionId");
income.setTransactionId(atoi(xml.GetData().c_str()));
xml.FindElem("Date");
income.setDate(AuxiliaryMethods::convertDateToIntWithoutDashes(xml.GetData()));
xml.FindElem("Item");
income.setItem(xml.GetData());
xml.FindElem("Value");
income.setValue(xml.GetData());
incomes.push_back(income);
xml.OutOfElem();
}
}
return incomes;
}
void IncomesFile::writeIncomeToXmlFile(Income income) {
CMarkup xml;
if (!xml.Load(getFilename())) {
cout << "Blad odczytu pliku!";
} else {
xml.FindElem("IncomesFile");
xml.IntoElem();
xml.AddElem("Income");
xml.IntoElem();
xml.AddElem("UserId",income.getUserId());
xml.AddElem("TransactionId",income.getTransactionId());
xml.AddElem("Date",income.getDate());
xml.AddElem("Item",income.getItem());
xml.AddElem("Value",income.getValue());
xml.OutOfElem();
xml.OutOfElem();
xml.Save(getFilename());
}
}
int IncomesFile::getLastTransactionId() {
CMarkup xml;
int lastTransactionId = 0;
if (!xml.Load(getFilename())) {
cout << "Blad odczytu pliku!";
} else {
xml.FindElem("IncomesFile");
xml.IntoElem();
while (xml.FindElem("Income")) {
xml.IntoElem();
xml.FindElem("TransactionId");
lastTransactionId = atoi(xml.GetData().c_str());
xml.OutOfElem();
}
}
return lastTransactionId;
}