-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nhanvien.cpp
277 lines (268 loc) · 7.67 KB
/
Nhanvien.cpp
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<stdlib.h>
#include<windows.h>
#include "Nhanvien.h"
#define N 100
using namespace std;
void InLine1(int n){
for (int i = 0; i < n; i++)
cout<<"=";
}
void TextColor1(int x)
{
HANDLE mau;
mau = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(mau,x);
}
std::ostream& operator <<(std::ostream &out ,const Nhanvien &p){
out<<p.maNV<<endl;
out<<p.name<<endl;
out<<p.chucvu<<endl;
out<<p.age<<endl;
out<<p.address<<endl;
out<<p.sdt<<endl;
return out;
}
bool check_exist(const Nhanvien &x){
Nhanvien* p=new Nhanvien[1000];
int n=getInfo(p);
for (int i=0;i<n-1;i++){
if (x.maNV==p[i].maNV) return 1;
}
return 0;
delete [] p;
}
std::istream& operator >>(std::istream &in,Nhanvien &p){
cout<<"Nhap ma nhan vien: ";getline(cin,p.maNV);
while(check_exist(p)){
cout<<"Ma nhan vien da ton tai, nhap lai: ";getline(cin,p.maNV);
}
cout<<"Nhap ten: ";getline(cin,p.name);
cout<<"Nhap tuoi: ";cin>>p.age;getchar();
cout<<"Nhap chuc vu: ";getline(cin,p.chucvu);
cout<<"Nhap dia chi: ";getline(cin,p.address);
cout<<"Nhap so dien thoai: ";getline(cin,p.sdt);
return in;
}
void Nhanvien:: setmaNV(string maNV){
this->maNV=maNV;
}
string Nhanvien:: getmaNV(){
return maNV;
}
void Nhanvien:: setChucvu(string chucvu){
this->chucvu=chucvu;
}
string Nhanvien:: getChucvu(){
return chucvu;
}
void Nhanvien:: setName(string name){
this->name=name;
}
string Nhanvien:: getName(){
return name;
}
void Nhanvien:: setAge(int age){
this->age=age;
}
int Nhanvien:: getAge(){
return age;
}
void Nhanvien:: setAddress(string address){
this->address=address;
}
string Nhanvien:: getAddress(){
return address;
}
void Nhanvien:: setSDT(string sdt){
this->sdt=sdt;
}
string Nhanvien:: getSDT(){
return sdt;
}
int getInfo(Nhanvien* p){
ifstream myFile;
myFile.open("Nhanvien/Nhanvien.txt");
if (!myFile.is_open()){
cout<<"Khong mo duoc file";
system("exit");
}
int total=0;
while (!myFile.eof()){
string line;
getline(myFile,p[total].maNV);
getline(myFile,p[total].name);
getline(myFile,p[total].chucvu);
getline(myFile,line);
stringstream geek(line);
geek>>p[total].age;
getline(myFile,p[total].address);
getline(myFile,p[total].sdt);
total++;
continue;
}
return total;
}
int check_maNV(Nhanvien *p,string ma){
int total=getInfo(p);cout<<endl;
int check=0;
for (int i=0;i<total-1;i++){
if(ma==p[i].maNV){
check=1;
}
}
return check;
}
void displaydel(Nhanvien*p,string del){
int total=getInfo(p);cout<<endl;
for (int i=0;i<total-1;i++){
if(del==p[i].maNV){
cout<<setw(10)<<left<<"MaNV";
cout<<setw(30)<<left<<"Ten";
cout<<setw(20)<<left<<"Chuc vu";
cout<<setw(10)<<left<<"Tuoi";
cout<<setw(25)<<left<<"Dia chi";
cout<<setw(15)<<left<<"So dien thoai"<<endl;
cout<<setw(10)<<left<<p[i].maNV;
cout<<setw(30)<<left<<p[i].name;
cout<<setw(20)<<left<<p[i].chucvu;
cout<<setw(10)<<left<<p[i].age;
cout<<setw(25)<<left<<p[i].address;
cout<<setw(15)<<left<<p[i].sdt<<endl;
}
}
}
void display(Nhanvien* p){
int total=getInfo(p);cout<<endl;
InLine1(47);TextColor1(11);
cout<<"Danh Sach Nhan Vien";TextColor1(7);
InLine1(48);cout<<endl;
cout<<"+----------------------------------------------------------------------------------------------------------------+\n";
cout<<setw(10)<<left<<"| MaNV";
cout<<setw(30)<<left<<"| Ho va ten";
cout<<setw(20)<<left<<"| Chuc vu";
cout<<setw(10)<<left<<"| Tuoi";
cout<<setw(25)<<left<<"| Dia chi";
cout<<setw(15)<<left<<"| So dien thoai |"<<endl;
cout<<"+----------------------------------------------------------------------------------------------------------------+\n";
for (int i=0;i<total-1;i++){
cout<<"| "<<setw(7)<<left<<p[i].maNV;
cout<<"| "<<setw(26)<<left<<p[i].name;
cout<<"| "<<setw(13)<<left<<p[i].chucvu;
cout<<"| "<<setw(6)<<left<<p[i].age;
cout<<"| "<<setw(22)<<left<<p[i].address;
cout<<"| "<<setw(14)<<left<<p[i].sdt<<"|"<<endl;
}
cout<<"+----------------------------------------------------------------------------------------------------------------+\n";
}
void Add(Nhanvien* p){
add:
string pass;
ofstream out;
out.open("Password/staff.txt",ios::app);
cout<<endl;InLine1(45);TextColor1(11);
cout<<"Them Nhan Vien";TextColor1(7);
InLine1(45);cout<<endl;
Nhanvien x;
ofstream file2;
file2.open("Nhanvien/Nhanvien.txt",ios::app);
if(!file2.is_open()) return;
cin>>x;
cout<<"Nhap mat khau cho nhan vien nay: ";cin>>pass;
out<<x.maNV<<" "<<pass<<endl;
file2<<x;
getInfo(p);
file2.close();
out.close();
TextColor1(10);cout<<"\n\t Da them thanh cong\n";TextColor1(7);
cout<<"\nBan co muon tiep tuc them nhan vien?(y/n) : ";
char t;cin>>t;getchar();
if(t=='y'){
system("cls");
goto add;
}
}
void Delete(Nhanvien *p){
DEL:
cout<<endl;InLine1(45);TextColor1(11);
cout<<"Xoa Nhan Vien";TextColor1(7);
InLine1(45);cout<<endl;
string del;
cout<<"\nNhap ma cua nhan vien ban muon xoa: ";cin>>del;
if(check_maNV(p,del)==0){
TextColor1(12); cout<<"Ma nhan vien nay khong ton tai";TextColor1(7);
cout<<"\n\nBan co muon nhap lai ma nhan vien ? (y/n) : ";
char t;cin>>t;
if(t=='y'){
system("cls");
goto DEL;
}
}
else{
cout<<"\nThong tin nhan vien muon xoa :";
displaydel(p,del);
ifstream is("Nhanvien/Nhanvien.txt");
cout<<"Ban co chac muon xoa :";
TextColor1(14);cout<<"\n\n\t -Notification-";TextColor1(7);
cout<<"\n +--------------------------------+";
cout<<"\n | 1.CO 2.KHONG |";
cout<<"\n +--------------------------------+";
char a;
cout<<"\n\nNhap lua chon : ";cin>>a;
switch (a){
case '1' :
{
ofstream out;
ifstream in;
string username,pass;
in.open("Password/staff.txt");
out.open("Password/temp.txt");
ofstream file2;
file2.open("Nhanvien/temp.txt", ofstream::out);
while(in>>username>>pass){
if(username!=del) out<<username<<" "<<pass<<endl;
}
int n=getInfo(p);
int i;
for ( i=0;i<n-1;i++){
if (del==p[i].maNV) {
break;
}
}
for(int j=0;j<n-1;j++){
if(j!=i){
file2<<p[j];
}
}
TextColor1(10);cout<<"\n\n\t Da xoa thanh cong\n";TextColor1(7);
file2.close();
is.close();
in.close();
out.close();
remove("Password/staff.txt");
rename("Password/temp.txt","Password/staff.txt");
remove("Nhanvien/Nhanvien.txt");
rename("Nhanvien/temp.txt", "Nhanvien/Nhanvien.txt");
cout<<"\nBan co muon tiep tuc xoa nhan vien (y/n) :" ;
char d;cin>>d;
if(d=='y'){
system("cls");
goto DEL;
}
break;
}
case '2':
{
cout<<"\nBan co muon tiep tuc xoa nhan vien (y/n) :" ;char d;cin>>d;
if(d=='y'){
system("cls");
goto DEL;
}
break;
}
}
}
}