-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
138 lines (128 loc) · 3.25 KB
/
main.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
#include "log.h"
#include "book.h"
#include "user.h"
#include "staff.h"
#include "admin.h"
#include "library.h"
#include "customer.h"
#include "password.h"
#include "store.h"
#include "storelist.h"
#include "md5.h"
Log rec;
Storelist storelist;
Store store;
Library lib;
Password pwd;
string account;
string book_address;
string cash_address;
string book_log_address;
string cash_log_address;
MD5 md5;
Admin admin;
int user_index;
int storeNum = 0; // number of the store
int Login(string username, string password) // Get user's status
{
for (size_t i = 0; i < lib.UserArray.size(); i++ )
if (username == lib.UserArray[i].GetUsername() && password == lib.UserArray[i].GetPassword()) // If find username and password in User.txt
{
user_index = i;
return lib.UserArray[i].GetStatus(); // Return user's status
}
return 0;
}
void Welcome() // Welcome interface
{
lib.LoadUser(); // Load User.txt
storelist.LoadStoreList();
int status = 0, time = 0, choice;
while(1)
{
while(1)
{
system("cls");
cout << "Welcome to Book Works Management System!" << endl;
cout << "1. Sign Up (Only for customer)" << endl;
cout << "2. Sign In" << endl;
cin >> choice;
if (choice == 1 || choice == 2) break;
cout << "Please input 1 or 2!" << endl;
Sleep(3000);
}
if (choice == 1)
{
system("cls");
admin.AddCustomer();
continue;
}
else if (choice == 2)
{
system("cls");
cout << "Please login" << endl;
while (status == 0)
{
cout << "Username: " << endl;
cin >> account; // Input username
cout << "Password: " << endl;
pwd.InputPassword(); // Input password without showing what you input
md5.reset();
md5.update(pwd.GetPassword());
status = Login(account, md5.toString()); // Get user's status
if (status < 1 || status > 3)
{
time++; // Try how many times
if (time < 3) cout << "Your username or password is incorrected, please try again." << endl;
else if (time < 4) cout << "Incorrected 3 times, this is the last chance." << endl;
else
{
cout << "Please contact the admin to reset your password!" << endl; // fail four times, force to exit
Sleep(1500);
return;
}
Sleep(1500);
}
else // Choose Book store, Choose interface depend on status
{
system("cls");
for (size_t i = 0; i < storelist.StoreArray.size(); i++)
cout << i + 1 << ". " << storelist.StoreArray[i].GetName() << " | Address: " << storelist.StoreArray[i].GetAddress() << endl;
cout << endl;
cout << "Please input the number of the bookstore that you want to visit:" << endl;
cin >> storeNum;
while(storeNum != 1 && storeNum != 2 && storeNum != 3)
{
cout << "Please input number between 1 and 3!" << endl;
cin >> storeNum;
}
storelist.LoadLib(storeNum);
if (status == 1)
{
Admin person;
person.Interface();
}
else if (status == 2)
{
Staff person;
person.Interface();
}
else if (status == 3)
{
Customer person;
person.Interface();
}
break;
}
system("cls");
cout << "Welcome to Book Works Management System!" << endl;
cout << "Please login" << endl;
}
}
break;
}
}
int main(void)
{
Welcome(); // Welcome interface
}