-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContact.cpp
More file actions
108 lines (91 loc) · 2 KB
/
Contact.cpp
File metadata and controls
108 lines (91 loc) · 2 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
#include "stdafx.h"
#include "Contact.h"
extern vector<Person*> contact_item;
extern string errorMsg;
Contact::Contact()
{
MainFunctionsNum = 5;
refresh();
}
Contact::~Contact()
{
int freei = contact_item.size();
for (int i = 0; i<freei; ++i){
delete(contact_item.at(i));
}
}
MainStrategy* Contact::setMainStrategy(int num){
switch (num){
case 1:
return new MainNewMenu();
case 2:
return new MainDelMenu();
case 3:
return new MainMdfMenu();
case 4:
return new MainVewMenu();
case 5:
return NULL;
}
return NULL;
}
void Contact::removeMainStrategy(MainStrategy* p){
delete p;
}
void Contact::welcome() const{
int n = 0;
system("cls");
cout<<"\n\n\n----------Welcome to the Address Book System.--------\n\n";
cout<<"-----now LOADING address book...";
n = refresh();
Sleep(800);
if (n > 0){
cout<<"\t"<<n<<" contact(s) have been imported.\n";
}
else if (n == -1){
cout<<"\tFolder contact does not exist!.Please retry later!\n";
getch();
exit(0);
}
else{
cout<<"\t"<<"no contact has been imported.\n";
}
Sleep(50);
cout<<" Login...";
Sleep(300);
cout<<" Successful!";
Sleep(40);
}
int Contact::refresh() const{
string info_check;
contact_item.clear();
long hFile = 0;
struct _finddata_t fileinfo;
const char* cp = ".\\contact\\*";
const char* dir = ".\\contact";
int freei = contact_item.size();
for (int i = 0; i<freei; ++i){
delete(contact_item.at(i));
}
if ((hFile = _findfirst(cp, &fileinfo)) != -1){
do{
if (!(fileinfo.attrib & _A_SUBDIR)){
string path = ".\\contact\\";
path += fileinfo.name;
Person *temp_p = new Person;
FILE* fp = fopen(path.c_str(), "rb");
fread(temp_p, sizeof(*temp_p), 1, fp);
fclose(fp);
info_check = temp_p->name;
info_check += ".ctt";
if (info_check == fileinfo.name)
contact_item.push_back(temp_p);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
else{
if (!CreateDirectory(dir, NULL)) return -1;
}
return contact_item.size();
}