-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderFIle.cpp
More file actions
104 lines (90 loc) · 2.7 KB
/
orderFIle.cpp
File metadata and controls
104 lines (90 loc) · 2.7 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "orderFile.h"
//构造函数
OrderFile::OrderFile() {
ifstream ifs;
ifs.open(ORDER_FILE, ios::in);
string date;
string interval;
string stuId;
string stuName;
string roomId;
string status;
this->m_size = 0;
while (ifs >> date && ifs >> interval && ifs >> stuId && ifs >> stuName
&& ifs >> roomId && ifs >> status)
{
string key;
string value;
map<string, string> m;
int pos = date.find(":");
if (pos != -1) {
key = date.substr(0, pos);
value = date.substr(pos + 1, date.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
pos = interval.find(":");
if (pos != -1) {
key = interval.substr(0, pos);
value = interval.substr(pos + 1, interval.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
pos = stuId.find(":");
if (pos != -1) {
key = stuId.substr(0, pos);
value = stuId.substr(pos + 1, stuId.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
pos = stuName.find(":");
if (pos != -1) {
key = stuName.substr(0, pos);
value = stuName.substr(pos + 1, stuName.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
pos = roomId.find(":");
if (pos != -1) {
key = roomId.substr(0, pos);
value = roomId.substr(pos + 1, roomId.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
pos = status.find(":");
if (pos != -1) {
key = status.substr(0, pos);
value = status.substr(pos + 1, status.size() - pos - 1);
m.insert(make_pair(key, value));
//cout << key << " " << value << endl;
}
this->m_orderData.insert(make_pair(this->m_size, m));
this->m_size++;
}
ifs.close();
/*map<int, map<string, string> >::iterator it;
for (it = m_orderData.begin(); it != m_orderData.end(); it++) {
cout << "预约序号为: " << it->first << " 详细预约信息如下: " << endl;
map<string, string>::iterator mit;
for (mit = it->second.begin(); mit != it->second.end(); mit++) {
cout << " key = " << mit->first << " value = " << mit->second << " ";
}
cout << endl;
}*/
}
//更新预约记录
void OrderFile::updateOrder() {
if (this->m_size == 0) {
return;
}
ofstream ofs(ORDER_FILE, ios::out | ios::trunc);
for (int i = 0; i < this->m_size; i++) {
ofs << "date:" << this->m_orderData[i]["date"] << " ";
ofs << "interval:" << this->m_orderData[i]["interval"] << " ";
ofs << "stuId:" << this->m_orderData[i]["stuId"] << " ";
ofs << "stuName:" << this->m_orderData[i]["stuName"] << " ";
ofs << "roomId:" << this->m_orderData[i]["roomId"] << " ";
ofs << "status:" << this->m_orderData[i]["status"] << endl;
}
ofs.close();
}