-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMuonTra.cpp
More file actions
170 lines (163 loc) · 3.88 KB
/
MuonTra.cpp
File metadata and controls
170 lines (163 loc) · 3.88 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "stdafx.h"
#include "MuonTra.h"
//bool MuonTra::checkMaSach(string masach) {
// int dem;
// for (int i = 0;i < vListSach.size();i++) {
// if (masach == vListSach[i].getMasach())
// dem = i;
// else
// {
// cout << "ma sach ko co!"<<endl;
// return false;
// }
// }
// if (vListSach[dem].getSoluong() <= 0) {
// cout << "Sach da het trong thu vien!!!" << endl;
// return false;
// }
// return true;
//}
void MuonTra::chuyenFileListSachToVector(string diachifile) {
fstream f;
string n;
f.open(diachifile, ios::in);
if (f.fail() == true)
{
cout << "File not exit!!!" << endl;
}
else
{
while (f.eof() != true)
{
getline(f, n);
Sach Sach(n);
vListSach.push_back(n);
}
}
f.close();
}
//void MuonTra::chuyenFileListSachToVector(string diachifile) {
// fstream f;
// string n;
// f.open(diachifile, ios::in);
// if (f.fail() == true)
// {
// cout << "File not exit!!!" << endl;
// }
// else
// {
// while (f.eof() != true)
// {
// getline(f, n);
// DocGia DocGia(n);
// vListDocGia.push_back(n);
// }
// }
// f.close();
//}
bool MuonTra::checkMaDocGia(string madocgia) {
/*int dem;
for (int i = 0;i < vListDocGia.size();i++) {
if (madocgia == vListDocGia[i].getMaDocGia())
dem = i;
else
{
cout << "Can Tao Moi Doc gia truoc khi muon sach! " << endl;
return false;
}
}*/
return true;
}
PhieuMuonTra MuonTra::get(int i)
{
return vListMuon[i];
}
int MuonTra::size()
{
return vListMuon.size();
}
bool MuonTra::checkNgay(Date ngaymuon, Date ngaytra) {
if (ngaytra.getYear() < ngaymuon.getYear()) {
cout << "Ngay tra khong duoc sau hon ngay muon!" << endl;
return false;
}
else {
if (ngaytra.getMonth() < ngaymuon.getMonth()) {
cout << "Ngay tra khong duoc sau hon ngay muon!" << endl;
return false;
}
else {
if (ngaytra.getDay() < ngaymuon.getDay()) {
cout << "Ngay tra khong duoc sau hon ngay muon!" << endl;
return false;
}
}
}
return true;
}
//void MuonTra::lapPhieuMuon() {
// cin.ignore();
// string madocgia,masach, sophieu, ngaymuon, ngaytra;
//
// cout << "Nhap so phieu: ";getline(cin, sophieu);
// cout << "Nhap ma doc gia:";getline(cin, madocgia);
// cout << "Nhap Ma Sach: ";getline(cin, masach);
// cout << "Nhap ngay muuon: ";getline(cin, ngaymuon);
// cout << "Nhap ngay tra ";getline(cin, ngaytra);
//
// if (checkMaDocGia(madocgia) == true && checkMaSach(masach) == true&&checkNgay(ngaymuon,ngaytra)==true) {
// cout << "Dang ki muon sach thanh cong " << endl;
// string s= madocgia+ masach+ sophieu+ ngaymuon+ ngaytra;
// vListMuon.push_back(s);
// }
//}
void MuonTra::xuatFileListMuonTra(string diachifile) {
fstream f;
string s;
f.open(diachifile, ios::out);
for (int i = 0;i < vListMuon.size();i++) {
PhieuMuonTra object(vListMuon[i],s);
f<<s<<endl;
}
f.close();
}
bool MuonTra::checkNgayHetHan(Date ngaytra, Date ngayhethan) {
if (ngaytra.getYear() < ngayhethan.getYear()) {
return false;
}
else {
if (ngaytra.getMonth() < ngayhethan.getMonth()) {
return false;
}
else {
if (ngaytra.getDay() < ngayhethan.getDay()) {
return false;
}
}
}
return true;
}
void MuonTra::xuatFileMuonSachQuaHan(string ngayhethan, string diachifile) {
fstream f;
string s;
f.open(diachifile, ios::out);
for (int i = 0;i < vListMuon.size();i++) {
if (checkNgay(vListMuon[i].getNgayTra(), ngayhethan) == true) {
PhieuMuonTra object(vListMuon[i], s);
f << s << endl;
}
}
f.close();
}
void MuonTra::xoaPhieu(int idx) {
for (int i = idx;i < vListMuon.size()-1;i++) {
vListMuon[idx] = vListMuon[idx + 1];
}
vListMuon.pop_back();
}
void MuonTra::hanhDongTraSach(string nhapmasophieucantra) {
for (int i = 0;i < vListMuon.size();i++) {
if (vListMuon[i].getSoPhieu() == nhapmasophieucantra)
xoaPhieu(i);
}
}