Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<iomanip>
- #include<string>
- #include <fstream>
- #include<sstream>
- using namespace std;
- struct Account {
- string user;
- string password;
- };
- struct Role {
- string user;
- string namework;
- };
- struct Account_to_role {
- string user;
- string chucnang;
- };
- struct Product {
- string seri = "";
- string name = "";
- string nsx = "";
- string hsd = "";
- int solg = 0;
- int price = 0;
- };
- struct Customer {
- string username;
- vector <Product> cusProduct;
- vector <Product> giohang;
- };
- bool readfile_buyproduct(vector<Customer>&cus_product);
- void savefile_buyproduct(vector<Customer>&cus_product);
- bool readfile_product(vector<Product>&product);
- void savefile_product(vector<Product>product);
- bool history_buy(vector<Customer>&cus_product, string &a);
- bool xacnhan_mua(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
- bool edit_giohang(vector<Customer>&cus_product, string&a);
- bool xem_giohang(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
- bool for_customer(vector<Customer> &cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
- void add_giohang(string seri, vector<Customer>&cus_product, vector<Product> &product, string&a);
- bool find_to_buy(vector<Customer>&cus_product, vector<Product>&product, string&a);
- bool thongke_hanghoa(vector<Product>&product);
- bool edit_hanghoa(vector<Product>&product);
- bool find_hanghoa(vector<Product>&product);
- bool xoa_hanghoa(vector<Product>&product);
- bool test_seri(string temp, vector<Product>product);
- bool them_hanghoa(vector<Product>&product);
- bool forstaff(vector<Product> &product);
- bool docfile_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
- void luufile(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
- bool test_account_to_login(vector<Account> &acc, vector<Role> &role, string &a, string &b, string &c);
- bool logintk(vector<Account> &acc, vector<Account_to_role>&acc_role, vector<Role> &role,
- vector<Customer>&cus_product, vector<Product>&product, string &a, string &b, string &c);
- void allocation(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product);
- bool captk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b);
- bool resetpassword(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
- bool for_admin(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string &b, string &c);
- bool phanvungtk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, vector<Product>&product, string &a, string &b, string &c);
- bool forstaff(vector<Product> &product);
- bool test_user(vector<Account> &acc, string testuser);
- bool test_user_to_delete(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string testuser);
- bool delete_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product);
- bool information_acc_present(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, string a);
- bool information_list_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
- bool serch_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
- bool test_time(int dd1, int dd2, int mm1, int mm2, int yy1, int yy2) {
- if (yy2 < yy1 || (yy2 == yy1&&mm2 < mm1) || (yy2 == yy1&&mm2 == mm1 && (dd2<dd1 || dd2 == dd1)))return 0;
- else return 1;
- }
- bool signup_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b) {
- _flushall;
- system("cls");
- cout << "\t\t\t\t\t\t\t\t\n\n\NHAP USER: ";
- string testuser;
- getline(cin, testuser);
- if (test_user(acc, testuser) == false) {
- cout << "\t\t\t\t\t\t\t\tACCOUNT DA TON TAI";
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: return 1;
- case 2: return 0;
- default: return 1;
- }
- }
- int n = acc.size();
- acc.push_back(Account());
- acc[n].user = testuser;
- _flushall;
- cout << "\t\t\t\t\t\t\t\tCAP PASSWORD ";
- string pass1;
- getline(cin, pass1);
- acc[n].password = pass1;
- _flushall;
- int i = cus_product.size();
- cus_product.push_back(Customer());
- cus_product[i].username = testuser;
- acc_role.push_back(Account_to_role());
- acc_role[n].user = "khachhang";
- acc_role[n].chucnang = "customer";
- role.push_back(Role());
- role[n].user = "customer";
- role[n].namework = "khachhang";
- int k;
- cout << "\t\t\t\t\t\t\t\t\nCAP THANH CONG! ";
- luufile(acc, acc_role, role);
- }
- int main() {
- bool dk;
- vector<Customer> cus_product;
- //sysadmin;
- vector<Account> acc;
- vector<Role> role;
- vector<Account_to_role> acc_role;
- allocation(acc, acc_role, role, cus_product);
- string a, b, c;
- //storemanager
- vector<Product> product;
- //customer
- cout << "\n\n\t\t\t\t\t\t\t\t--------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| CHAO MUNG BAN DEN VOI HE THONG BAN HANG ONLINE |" << endl;
- cout << "\t\t\t\t\t\t\t\t--------------------------------------------------" << endl;
- //vector<Customer> cus_product;
- cout << "\n\n\n\t\t\t\t \t \t1. LOGIN 2.SIGN UP" << endl;
- cout << "\n\t\t\t\t\t MOI BAN NHAP SU LUA CHON(1 OR 2 ) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1:break;
- case 2:signup_acc(acc, acc_role, role, cus_product, a, b);
- default:
- break;
- }
- do {
- do {
- dk = logintk(acc, acc_role, role, cus_product, product, a, b, c);
- } while (dk == false);
- dk = phanvungtk(acc, acc_role, role, cus_product, product, a, b, c);
- } while (dk == false);
- system("pause");
- return 0;
- }
- bool phanvungtk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, vector<Product>&product, string &a, string &b, string &c) {
- system("cls");
- cout << c << endl;
- if (c == "storemanager") {
- return for_admin(acc, acc_role, role, cus_product, a, b, c);
- }
- else if (c == "staff") {
- return forstaff(product);
- }
- else {
- return for_customer(cus_product, product, acc, role, a);
- }
- return 1;
- }
- bool test_account_to_login(vector<Account> &acc, vector<Role> &role, string &a, string &b, string &c) {
- for (int j = 0; j < acc.size(); j++) {
- if (a == acc[j].user && b == acc[j].password) {
- c = role[j].user;
- return 1;
- }
- }
- return 0;
- }
- bool logintk(vector<Account> &acc, vector<Account_to_role>&acc_role,
- vector<Role> &role, vector<Customer>&cus_product, vector<Product>&product
- , string &a, string &b, string &c) {
- /*docfile_account(acc, acc_role, role);
- readfile_product(product);
- readfile_buyproduct(cus_product);*/
- system("cls");
- cout << "\n\n\n\t\t\t\t\t\t\t\t LOGIN WITH YOUR ACCOUNT " << endl;
- cout << "\n\n\n\n\n\n\t\t\t NHAP USER :";
- getline(cin, a);
- cout << "\t\t\tNHAP PASSWORD :";
- getline(cin, b);
- return test_account_to_login(acc, role, a, b, c);
- }
- bool docfile_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
- ifstream ACCount("luu.txt");
- string x, y, z, u, v, t;
- acc.clear();
- acc_role.clear();
- role.clear();
- int index;
- if (!ACCount.is_open())
- {
- cout << "\t\t\t\t\t\t\t\tKHONG THE MO FILE.\n";
- system("pause");
- return 0;
- }
- else {
- ACCount >> index;
- for (int i = 0; i < index; i++)
- {
- ACCount >> x;
- ACCount >> y;
- ACCount >> z;
- ACCount >> u;
- ACCount >> v;
- ACCount >> t;
- acc.push_back(Account());
- acc[i].user = x;
- acc[i].password = y;
- acc_role.push_back(Account_to_role());
- acc_role[i].user = z;
- acc_role[i].chucnang = u;
- role.push_back(Role());
- role[i].user = v;
- role[i].namework = t;
- }
- }
- ACCount.close();
- }
- void allocation(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product) {
- acc.push_back(Account());
- acc[0].password = "28051997";
- acc[0].user = "huynhhai";
- acc.push_back(Account());
- acc[1].user = "staff";
- acc[1].password = "12345";
- acc.push_back(Account());
- acc[2].user = "customer";
- acc[2].password = "12345";
- cus_product.push_back(Customer());
- cus_product[0].username = "customer";
- acc_role.push_back(Account_to_role());
- acc_role[0].user = "quantrivien";
- acc_role[0].chucnang = "storemanager";
- acc_role.push_back(Account_to_role());
- acc_role[1].user = "nhanvien";
- acc_role[1].chucnang = "storemanager";
- acc_role.push_back(Account_to_role());
- acc_role[2].user = "khachhang";
- acc_role[2].chucnang = "customer";
- role.push_back(Role());
- role[0].user = "storemanager";
- role[0].namework = "quanlinhanvien";
- role.push_back(Role());
- role[1].user = "staff";
- role[1].namework = "nhanvienbanhang";
- role.push_back(Role());
- role[2].user = "customer";
- role[2].namework = "khachhang";
- }
- bool captk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b) {
- _flushall;
- system("cls");
- cout << setw(30) <<setfill(' ') <<"-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\n\t\t\t\t\t\t\t\tNHAP USER :";
- string testuser;
- getline(cin, testuser);
- if (test_user(acc, testuser) == false) {
- cout << "\t\t\t\t\t\t\t\tACCOUNT DA TON TAI";
- cout << "\t\t\t\t\t\t\t Lua chon: 1.NHAP LAI 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\t NHAP SU LUA CHON CUA BAN (1,2 OR 3 ) :";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: return 1;
- case 2: return 0;
- default: return 1;
- }
- }
- int n = acc.size();
- acc.push_back(Account());
- acc[n].user = testuser;
- _flushall;
- cout << "\t\t\t\t\t\t\t\tCAP PASSWORD :";
- string pass1;
- getline(cin, pass1);
- acc[n].password = pass1;
- _flushall;
- cout << "\n\t\t\t\t\t\t\t\t CHON LOAI TAI KHOAN: 1.ADMIN 2.NHAN VIEN 3.KHACH HANG " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
- int z;
- cin >> z;
- cin.ignore(1);
- switch (z) {
- case 1: {
- acc_role.push_back(Account_to_role());
- acc_role[n].chucnang = "storemanager";
- acc_role[n].user = "nhanvien";
- role.push_back(Role());
- role[n].user = "storemanager";
- role[n].namework = "quanlinhanvien";
- break;
- }
- case 2: {
- acc_role.push_back(Account_to_role());
- acc_role[n].user = "nhanvien";
- acc_role[n].chucnang = "storemanager";
- role.push_back(Role());
- role[n].user = "staff";
- role[n].namework = "nhanvienbanhang";
- break;
- }
- case 3: {
- int i = cus_product.size();
- cus_product.push_back(Customer());
- cus_product[i].username = testuser;
- acc_role.push_back(Account_to_role());
- acc_role[n].user = "khachhang";
- acc_role[n].chucnang = "customer";
- role.push_back(Role());
- role[n].user = "customer";
- role[n].namework = "khachhang";
- break;
- }
- default:
- break;
- }
- int k;
- cout << "\t\t\t\t\t\t\t\tCAP THANH CONG! ";
- luufile(acc, acc_role, role);
- cout << "\n\t\t\t\t\t\t\t\t 1.GOBACK 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- cin >> k;
- cin.ignore(1);
- switch (k) {
- case 1: return 1;
- case 2: return 0;
- }
- }
- bool resetpassword(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
- bool dk3;
- do {
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\n\t\t\t\t\t\t\t\tNHAP ACCOUNT CAN RESET :";
- string nameacc;
- getline(cin, nameacc);
- for (int i = 0; i < acc.size(); i++) {
- if (nameacc == acc[i].user) {
- string x;
- cout << "\t\t\t\t\t\t\t\tNHAP NEW PASSWORD :";
- getline(cin, x);
- acc[i].password = x;
- cout << "\t\t\t\t\t\t\t\tSUCCESS!" << endl;
- luufile(acc, acc_role, role);
- return 1;
- }
- }
- cout << "\t\t\t\t\t\t\t\t\tACCONUT KHONG TON TAI";
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\ttMOI BAN NHAP SU LUA CHON(1,2 OR 3) :";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: dk3 = false; break;
- case 2: return 1;
- case 3: return 0;
- default: dk3 = false; break;
- }
- } while (dk3 == false);
- }
- bool for_admin(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string &b, string &c) {
- bool dk2;
- do {
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -1.CAP ACCOUNT" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -2.RESET PASSWORD" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -3.XEM THONG TIN ACCOUNT" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -4.DELETE ACCOUNT" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -5.INFORMATION LIST ACCOUNT" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -6.SEARCH INFORMATION ACCOUNT" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -7.LOGOUT" << setw(5) << right << "-" << endl;
- cout << "\t\t\t\t\t\t\t\t----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN :";
- int r;
- cin >> r;
- cin.ignore(1);
- switch (r) {
- case 1: {
- if (captk(acc, acc_role, role, cus_product, a, b) == false) return 0;
- else dk2 = true;
- break;
- }
- case 2: if (resetpassword(acc, acc_role, role) == true) { dk2 = true; break; }
- else return 0;
- case 3:if (information_acc_present(acc, acc_role, role, a) == true) { dk2 = true; break; }
- else return 0;
- case 4:if (delete_account(acc, acc_role, role, cus_product) == true) { dk2 = true; break; }
- else return 0;
- case 5:if (information_list_acc(acc, acc_role, role) == true) { dk2 = true; break; }
- else return 0;
- case 6:if (serch_account(acc, acc_role, role) == true) { dk2 = true; break; }
- else return 0;
- case 7: return 0;
- }
- } while (dk2 == true);
- return 1;
- }
- bool test_user(vector<Account> &acc, string testuser) {
- for (int j = 0; j < acc.size(); j++) {
- if (testuser == acc[j].user) return 0;
- }
- return 1;
- }
- bool delete_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product) {
- bool dk2 = true;
- do {
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\n\t\t\t\t\t\t\t\t NHAP ACCOUNT CAN DELETE :";
- string nameacc;
- getline(cin, nameacc);
- if (test_user_to_delete(acc, acc_role, role, cus_product, nameacc) == true) {
- system("cls");
- cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
- luufile(acc, acc_role, role);
- int a;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1,2 OR 3) :";
- cin >> a;
- cin.ignore(1);
- switch (a)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 0;
- }
- }
- else {
- cout << "\t\t\t\t\t\t\t\tACCOUNT CAN DELETE KHONG TON TAI" << endl;
- int a;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN( 1 ,2 OR 3) :";
- cin >> a;
- cin.ignore(1);
- switch (a)
- {
- case 1: dk2 = false; break;
- case 2: return 1;
- case 3: return 0;
- default:
- return 1;
- }
- }
- } while (dk2 == false);
- }
- bool test_user_to_delete(vector<Account> &acc, vector<Account_to_role> &acc_role,
- vector<Role> &role, vector<Customer>&cus_product, string testuser) {
- for (int i = 0; i < acc.size(); i++) {
- if (testuser == acc[i].user) {
- acc.erase(acc.begin() + i);
- acc_role.erase(acc_role.begin() + i);
- role.erase(role.begin() + i);
- int n = cus_product.size();
- for (int j = 0; j < n; j++) {
- if (testuser == cus_product[j].username) {
- cus_product.erase(cus_product.begin() + j);
- break;
- }
- }
- return 1;
- }
- }
- return 0;
- }
- bool information_acc_present(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, string a) {
- int i;
- for (i = 0; i < acc.size(); i++) {
- if (acc[i].user == a) break;
- }
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\t\t\t\t\t\t\t\tNAME ACCOUNT :" << acc[i].user << endl;
- cout << "\t\t\t\t\t\t\t\tPASSWORD : " << acc[i].password << endl;
- cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT :" << role[i].user << endl;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- return 1;
- }
- bool information_list_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\n\t\t\t\t\t\t\t\t==========List_Account==========" << endl;
- cout <<"\t\t\t\t\t\t"<< setw(20) << "USER" << setw(20) << "PASSWORD" << setw(20) << "LOAI ACCOUNT" << endl;
- int x = acc.size();
- for (int i = 0; i < x; i++) {
- cout <<"\t\t\t\t\t\t" <<setw(20) << acc[i].user << setw(20) << acc[i].password << setw(20) << role[i].user << endl;
- }
- cout << "\n\t\t\t\t\tTONG SO ACCOUNT TRONG HET THONG :" << x << endl;
- cout << "\n\t\t\t\t\tLua chon: 1.QUAY LAI 2.LOGOUT " << endl;
- cout << "\n\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- return 1;
- }
- bool serch_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
- system("cls");
- string a;
- int n = acc.size();
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP VAO NAME ACCOUNT CAN TIM :";
- getline(cin, a);
- int i;
- for (i = 0; i < n; i++) {
- if (a == acc[i].user)break;
- }
- if (i < n) {
- system("cls");
- cout << "\t\t\t\t\t\t\t\tNAME ACCOUNT :" << acc[i].user << endl;
- cout << "\t\t\t\t\t\t\t\tPASSWORD :" << acc[i].password << endl;
- cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT :" << role[i].user << endl;
- }
- else cout <<"\t\t\t\t\t\t\t\t\ttKHONG TIM THAY" << endl;
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- return 1;
- }
- void luufile(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
- ofstream cap("luu.txt");
- int index = acc.size();
- cap << index << "\n";
- for (int i = 0; i < index; i++) {
- string x, y, z, u, v, t;
- x = acc[i].user;
- y = acc[i].password;
- z = acc_role[i].user;
- u = acc_role[i].chucnang;
- v = role[i].user;
- t = role[i].namework;
- cap << x << "\n";
- cap << y << "\n";
- cap << z << "\n";
- cap << u << "\n";
- cap << v << "\n";
- cap << t << "\n";
- }
- cap.close();
- cout << "SUCCESS!" << endl;
- }
- ///////
- //of_storemanager
- bool them_hanghoa(vector<Product>&product) {
- bool dk4;
- int price, solg;
- int dd1, mm1, yy1;
- string seri, name, nsx, hsd;
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- do {
- cout << "\n\n\t\t\t\t\t\t\t\tNHAP VAO SERI :";
- getline(cin, seri);
- if (test_seri(seri, product) == false) {
- cout << "\n\t\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
- cout << "\n\t\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk4 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- else {
- bool boolday;
- cout << "\t\t\t\t\t\t\t\tTEN HANG HOA :";
- getline(cin, name);
- do {
- do {
- boolday = true;
- cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT(dd mm yy) :";
- cin >> dd1 >> mm1 >> yy1;
- cin.ignore(1);
- if (dd1 > 31 || dd1 < 1 || mm1>12 || mm1 < 1 || yy1 < 0) {
- cout << "\n\t\t\t\t\t\t\t\tNSX FAIL!";
- boolday = false;
- }
- else {
- ostringstream ddmmyy;
- ddmmyy << dd1 << "/" << mm1 << "/" << yy1;
- nsx = ddmmyy.str();
- }
- } while (boolday == false);
- /////////////////////////
- int dd2, mm2, yy2;
- do {
- boolday = true;
- cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG(dd mm yy) :";
- cin >> dd2 >> mm2 >> yy2;
- cin.ignore(1);
- if (dd2 > 31 || dd2 < 1 || mm2>12 || mm2 < 1 || yy2 < 0) {
- cout << "\n\t\t\t\t\t\t\t\tHSD FAIL!";
- boolday = false;
- }
- else {
- ostringstream ddmmyy;
- ddmmyy << dd2 << "/" << mm2 << "/" << yy2;
- hsd = ddmmyy.str();
- }
- } while (boolday == false);
- if (test_time(dd1, dd2, mm1, mm2, yy1, yy2) == true)boolday = true;
- else boolday = false;
- } while (boolday == false);
- cout << "\t\t\t\t\t\t\t\tSO LUONG :";
- cin >> solg;
- cin.ignore(1);
- cout << "\t\t\t\t\t\t\t\tGIA BAN :";
- cin >> price;
- cin.ignore(1);
- int i = product.size();
- product.push_back(Product());
- product[i].seri = seri;
- product[i].nsx = nsx;
- product[i].hsd = hsd;
- product[i].price = price;
- product[i].name = name;
- product[i].solg = solg;
- cout << "\t\t\t\t\t\t\t\tSUCCESS!";
- savefile_product(product);
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk4 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- } while (dk4 == true);
- }
- bool test_seri(string seri, vector<Product>product) {
- for (int i = 0; i < product.size(); i++) {
- if (seri == product[i].seri) {
- cout << "\t\t\t\t\t\t\t\tSERI SAN PHAM DA CO TRONG KHO " << endl;
- return 0;
- }
- }
- return 1;
- }
- bool forstaff(vector<Product> &product) {
- bool dk3 = true;
- do {
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\n\t\t\t\t\t\t\t\t1.THEM HANG HOA " << endl;
- cout << "\n\t\t\t\t\t\t\t\t2.XOA HANG HOA " << endl;
- cout << "\n\t\t\t\t\t\t\t\t3.TIM KIEM HANG HOA" << endl;
- cout << "\n\t\t\t\t\t\t\t\t4.CHINH SUA HANG HOA " << endl;
- cout << "\n\t\t\t\t\t\t\t\t5.THONG KE" << endl;
- cout << "\n\t\t\t\t\t\t\t\t6.LOGOUT" << endl;
- cout << "\t\t\t\t\t\t\t\tMOI BAN NHAP LUA CHON :";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1:if (them_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 2:
- if (xoa_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 3:
- if (find_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 4:
- if (edit_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 5:
- if (thongke_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 6:return 0;
- }
- } while (dk3 == true);
- return 0;
- }
- bool xoa_hanghoa(vector<Product>&product) {
- string seri;
- bool dk5;
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- do {
- cout << "\n\n\t\t\t\t\t\t\t\tNHAP SERI CAN XOA :";
- getline(cin, seri);
- for (int i = 0; i < product.size(); i++) {
- if (seri == product[i].seri) {
- product.erase(product.begin() + i);
- cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
- savefile_product(product);
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 , 2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk5 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- }
- cout << "\t\t\t\t\t\t\t\tSERI FAIL";
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk5 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- } while (dk5 == true);
- }
- bool find_hanghoa(vector<Product>&product) {
- bool dk6 = false;
- string seri;
- string name;
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- do {
- cout << "\t\t\t\t\t\t\t\tSERI :";
- getline(cin, seri);
- for (int i = 0; i < product.size(); i++) {
- if (seri == product[i].seri) {
- cout << "\n\t\t\t\t\t\t\t\tTHONG TIN SAN PHAM";
- cout << "\n\t\t\t\t\t\t\t\tSERI :" << product[i].seri << endl;
- cout << "\n\t\t\t\t\t\t\t\tNAME :" << product[i].name << endl;
- cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT :" << product[i].nsx << endl;
- cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG :" << product[i].hsd << endl;
- cout << "\n\t\t\t\t\t\t\t\tSO LUONG :" << product[i].solg << endl;
- cout << "\n\t\t\t\t\t\t\t\tPRICE :" << product[i].price << endl;
- cout << "\n\t\t\t\t\t\t\t\tSUCCESS ";
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.Continue 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN (1 , 2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk6 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- if (dk6 == true)break;
- }
- if (dk6 == false) {
- cout << "\t\t\t\t\t\t\t\tSERI FAIL";
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tSU LUA CHON CUA BAN (1,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk6 = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- } while (dk6 == true);
- }
- bool edit_hanghoa(vector<Product>&product) {
- bool dk = false;
- int price, solg;
- int n;
- string seri, name, nsx, hsd;
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- do {
- cout << "\t\t\t\t\t\t\t\tSERI :";
- getline(cin, seri);
- for (int i = 0; i < product.size(); i++) {
- if (seri == product[i].seri) {
- cout << "\t\t\t\t\t\t\t\tSUA CAI GI: 1.SERI 2.NAME 3.NSX 4.HSX 5.SOLG 6.PRICE :" << endl;
- cin >> n;
- cin.ignore(1);
- product.push_back(Product());
- switch (n) {
- case 1: {
- cout << "\t\t\t\t\t\t\t\tNEW SERI :";
- product[i].seri = seri;
- break;
- }
- case 2: {
- cout << "\t\t\t\t\t\t\t\tNEW NAME :";
- getline(cin, name);
- product[i].name = name;
- break;
- }
- case 3: {
- cout << "\t\t\t\t\t\t\t\tNEW NSX :";
- getline(cin, nsx);
- product[i].nsx = nsx;
- break;
- }
- case 4: {
- cout << "\t\t\t\t\t\t\t\tNEW HSD :";
- getline(cin, hsd);
- product[i].nsx = hsd;
- break;
- }
- case 5: {
- cout << "NEW SO LUONG :";
- cin >> solg;
- cin.ignore(1);
- product[i].solg = solg;
- break;
- }
- case 6: {
- cout << "\t\t\t\t\t\t\t\tNEW PRICE :";
- cin >> price;
- cin.ignore(1);
- product[i].price = price;
- break;
- }
- }
- cout << "\t\t\t\t\t\t\t\tSUCCESS!";
- savefile_product(product);
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: dk = true; break;
- case 2: return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- if (dk == true)break;
- }
- if (dk == false) {
- cout << "\t\t\t\t\t\t\t\tSERI FAIL";
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: {dk = true; break; }
- case 2:return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- } while (dk == true);
- }
- bool thongke_hanghoa(vector<Product>&product) {
- int pay = 0;
- system("cls");
- cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
- cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
- cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
- for (int i = 0; i < product.size(); i++) {
- pay = pay + product[i].price*product[i].solg;
- cout << setw(20) << product[i].name << setw(20) << product[i].seri << setw(20) << product[i].price << setw(20) << product[i].nsx << setw(20) << product[i].hsd << setw(20) << product[i].solg << endl;
- }
- cout << "\n\t\tTONG SO LUONG :" << product.size();
- cout << "\n\t\t SO TIEN KHI BAN MUA :" << pay << endl;
- cout << "\n\t\tLua chon: 1.GOBACK 2.LOGOUT" << endl;
- cout << "\n\t\ttNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1:return 1;
- case 2:return 0;
- default:
- return 1;
- }
- }
- //// customer
- bool for_customer(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
- bool dk3 = true;
- do {
- system("cls");
- int temp = cus_product.size();
- cout << temp << endl;
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\n\t\t\t\t\t\t\t\t1.TIM KIEM HANG HOA" << endl;
- cout << "\n\t\t\t\t\t\t\t\t2.XEM GIO HANG" << endl;
- cout << "\n\t\t\t\t\t\t\t\t3.LICH SU MUA" << endl;
- cout << "\n\t\t\t\t\t\t\t\t4.TIM KIEM DANH SACH SAN PHAM" << endl;
- cout << "\n\t\t\t\t\t\t\t\t5.LOGOUT" << endl;
- int m;
- cout << "\t\t\t\t\t\t\t\tMOI NHAP LUA CHON :";
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1:if (find_to_buy(cus_product, product, a) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 2:
- if (xem_giohang(cus_product, product, acc, role, a) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 3:
- if (history_buy(cus_product, a) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 4:
- if (thongke_hanghoa(product) == true)
- {
- dk3 = true; break;
- }
- else return 0;
- case 5:return 0;
- }
- } while (dk3 == true);
- return 0;
- }
- bool find_to_buy(vector<Customer>&cus_product, vector<Product>&product, string &a) {
- bool dk;
- string name, seri;
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- do {
- int dem = 0;
- cout << "\t\t\t\t\t\t\t\tSEARCH NAME :";
- getline(cin, name);
- cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SoLg" << endl;
- for (int i = 0; i < product.size(); i++) {
- if (name == product[i].name) {
- cout << setw(20) << product[i].name << setw(20) << product[i].seri << setw(20) << product[i].price << setw(20) << product[i].nsx << setw(20) << product[i].hsd << setw(20) << product[i].solg << endl;
- dem++;
- }
- }
- if (dem > 0) {
- cout << "\t\t\t\t\t\t\t\tHIEN CO :" << dem << "\t\t\t\t\t\t\t\t LOAI SAN PHAM" << endl;
- int m;
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.MUA HANG VOI SERI 2.GOBACK 3.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: {
- cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN MUA :";
- getline(cin, seri);
- add_giohang(seri, cus_product, product, a);
- cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang)! " << endl;
- cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1:dk = true; break;
- case 2:return 1;
- case 3:return 0;
- default:
- return 1;
- }
- break;
- }
- case 2:return 1;
- case 3:return 0;
- default:return 1;
- }
- }
- else {
- cout << "\t\t\t\t\t\t\t\t KHONG TIM THAY" << endl;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang) " << endl;
- cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3 ) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1:dk = true; break;
- case 2:return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- } while (dk == true);
- }
- void add_giohang(string seri, vector<Customer>&cus_product, vector<Product> &product, string &a) {
- int temp = 0;
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- for (int n = 0; n < cus_product.size(); n++) {
- if (cus_product[n].username == a) {
- temp = n; break;
- }
- }
- int j = cus_product[temp].giohang.size();
- int k;
- k = j;
- for (int i = 0; i < product.size(); i++) {
- if (seri == product[i].seri) {
- cout << "\t\t\t\t\t\t\t\tSO LUONG :";
- int solg;
- cin >> solg;
- cin.ignore(1);
- if (solg <= product[i].solg) {
- cus_product[temp].giohang.push_back(Product());
- cus_product[temp].giohang[j].name = product[i].name;
- cus_product[temp].giohang[j].seri = product[i].seri;
- cus_product[temp].giohang[j].price = product[i].price;
- cus_product[temp].giohang[j].nsx = product[i].nsx;
- cus_product[temp].giohang[j].hsd = product[i].hsd;
- cus_product[temp].giohang[j].solg = solg;
- j = j + 1;
- break;
- }
- else "\t\t\t\t\t\t\t\tSO LUONG KHONG CHO PHEP"; break;
- }
- }
- if (j > k) {
- cout << "\t\t\t\t\t\t\t\tSUCCESS!";
- savefile_buyproduct(cus_product);
- }
- else cout << "\t\t\t\t\t\t\t\tFAIL!";
- }
- bool xem_giohang(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
- bool dk = true;
- int temp = 0;
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- for (int n = 0; n < cus_product.size(); n++) {
- if (cus_product[n].username == a) {
- temp = n; break;
- }
- }
- do {
- cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE"
- << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
- int pay = 0;
- for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
- pay = pay + cus_product[temp].giohang[i].price*cus_product[temp].giohang[i].solg;
- cout << setw(20) << cus_product[temp].giohang[i].name << setw(20) << cus_product[temp].giohang[i].seri << setw(20)
- << cus_product[temp].giohang[i].price << setw(20) << cus_product[temp].giohang[i].nsx
- << setw(20) << cus_product[temp].giohang[i].hsd << setw(20) << cus_product[temp].giohang[i].solg << endl;
- }
- cout << "\n\t\t\t\t\t\t\t\tTONG LOAI HANG :" << cus_product[temp].giohang.size() << endl;
- cout << "\n\t\t\t\t\t\t\t\tTHANH TIEN :" << pay;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CHINH SUA GIO HANG 2.XAC NHAN MUA HANG 3.GOBACK 4.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN(1,2,3 OR 4) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1:
- if (edit_giohang(cus_product, a) == true) {
- dk = true; break;
- }
- else return 0;
- case 2:
- if (xacnhan_mua(cus_product, product, acc, role, a) == true) {
- dk = true; break;
- }
- else return 0;
- case 3:return 1;
- case 4:return 0;
- default:
- return 1;
- }
- } while (dk = true);
- return 1;
- }
- bool edit_giohang(vector<Customer>&cus_product, string&a) {
- bool dk = false;
- int temp = 0;
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- for (int n = 0; n < cus_product.size(); n++) {
- if (cus_product[n].username == a) {
- temp = n; break;
- }
- }
- do {
- cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN XOA :" << endl;
- string seri;
- getline(cin, seri);
- for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
- if (seri == cus_product[temp].giohang[i].seri) {
- cus_product[temp].giohang.erase(cus_product[temp].giohang.begin() + i);
- cout << "\t\t\t\t\t\t\t\tDELETE COMPLETE";
- savefile_buyproduct(cus_product);
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE! 2.GOBACK! 3.LOGOUT" << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1, 2 OR 3) :";
- int n;
- cin >> n; cin.ignore(1);
- switch (n) {
- case 1:dk = true; break;
- case 2:return 1;
- case 3:return 0;
- default:
- return 1;
- }
- break;
- }
- }
- if (dk == false) {
- cout << "\t\t\t\t\t\t\t\tSERI KHONG TON TAI " << endl;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK! 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n) {
- case 1:return 1;
- case 2:return 0;
- default:
- return 1;
- }
- }
- } while (dk = true);
- }
- bool xacnhan_mua(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\n\t\t\t\t\t\t\t\t XAC NHAN MUA HANG";
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.XAC NHAN 2.GOBACK 3.LOGOUT" << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1,2 OR 3) :";
- int k;
- cin >> k;
- cin.ignore(1);
- int temp = 0;
- for (int n = 0; n < cus_product.size(); n++) {
- if (cus_product[n].username == a) {
- temp = n; break;
- }
- }
- switch (k) {
- case 1: {
- int x = 0;
- int p = cus_product[temp].cusProduct.size();
- int q = cus_product[temp].giohang.size();
- for (int i = p; i < p + q; i++) {
- for (int j = 0; j < product.size(); j++) {
- if (cus_product[temp].giohang[x].seri == product[j].seri) {
- product[j].solg = product[j].solg - cus_product[temp].giohang[x].solg;
- break;
- }
- }
- cus_product[temp].cusProduct.push_back(Product());
- cus_product[temp].cusProduct[i].name = cus_product[temp].giohang[x].name;
- cus_product[temp].cusProduct[i].seri = cus_product[temp].giohang[x].seri;
- cus_product[temp].cusProduct[i].price = cus_product[temp].giohang[x].price;
- cus_product[temp].cusProduct[i].solg = cus_product[temp].giohang[x].solg;
- cus_product[temp].cusProduct[i].nsx = cus_product[temp].giohang[x].nsx;
- cus_product[temp].cusProduct[i].hsd = cus_product[temp].giohang[x].hsd;
- x++;
- }
- cus_product[temp].giohang.erase(cus_product[temp].giohang.begin(), cus_product[temp].giohang.end());
- savefile_buyproduct(cus_product);
- savefile_product(product);
- return 1;
- }
- case 2:return 1;
- case 3:return 0;
- default:
- return 1;
- }
- }
- bool history_buy(vector<Customer>&cus_product, string &a) {
- system("cls");
- cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
- cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
- int temp = 0;
- for (int n = 0; n < cus_product.size(); n++) {
- if (cus_product[n].username == a) {
- temp = n; break;
- }
- }
- cout <<setw(15) << "NAME" << setw(15) << "SERI" << setw(15) << "PRICE"
- << setw(15) << "NSX" << setw(15) << "HSD" << setw(15) << "SOLG" << endl;
- int pay = 0;
- for (int i = 0; i < cus_product[temp].cusProduct.size(); i++) {
- pay = pay + cus_product[temp].cusProduct[i].price*cus_product[temp].cusProduct[i].solg;
- cout <<setw(15) << cus_product[temp].cusProduct[i].name << setw(15) << cus_product[temp].cusProduct[i].seri << setw(15)
- << cus_product[temp].cusProduct[i].price << setw(15) << cus_product[temp].cusProduct[i].nsx
- << setw(15) << cus_product[temp].cusProduct[i].hsd << setw(15) << cus_product[temp].cusProduct[i].solg << endl;
- }
- cout << "\t\t\t\t\t\t\t\tTONG LOAI HANG :" << cus_product[temp].cusProduct.size() << endl;
- cout << "\t\t\t\t\t\t\t\tTHANH TIEN :" << pay;
- cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
- cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n) {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- }
- bool readfile_product(vector<Product>&product) {
- ifstream readfileproduct("saveproduct.txt");
- string x, y, v, t;
- int z, u;
- product.clear();
- int index;
- if (!readfileproduct.is_open())
- {
- cout << "Khong the mo file.\n";
- system("pause");
- return 0;
- }
- else {
- readfileproduct >> index;
- for (int i = 0; i < index; i++)
- {
- readfileproduct >> x;
- readfileproduct >> y;
- readfileproduct >> z;
- readfileproduct >> u;
- readfileproduct >> v;
- readfileproduct >> t;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == '_')y[j] = ' ';
- }
- product.push_back(Product());
- product[i].seri = x;
- product[i].name = y;
- product[i].price = z;
- product[i].solg = u;
- product[i].nsx = v;
- product[i].hsd = t;
- }
- }
- readfileproduct.close();
- }
- void savefile_product(vector<Product>product) {
- ofstream savefile("saveproduct.txt");
- int index = product.size();
- savefile << index << "\n";
- for (int i = 0; i < index; i++) {
- int z, u;
- string x, y, v, t;
- x = product[i].seri;
- y = product[i].name;
- z = product[i].price;
- u = product[i].solg;
- v = product[i].nsx;
- t = product[i].hsd;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == ' ')y[j] = '_';
- }
- savefile << x << " ";
- savefile << y << " ";
- savefile << z << " ";
- savefile << u << " ";
- savefile << v << " ";
- savefile << t << " ";
- savefile << "\n";
- }
- savefile.close();
- cout << "Success!" << endl;
- }
- void savefile_buyproduct(vector<Customer>&cus_product) {
- ofstream savefile1("savebuyproduct.txt");
- int temp = cus_product.size();
- savefile1 << temp << "\n";
- for (int n = 0; n < temp; n++) {
- savefile1 << cus_product[n].username << "\n";
- }
- for (int m = 0; m < temp; m++) {
- //luu gio hang
- int n1 = cus_product[m].giohang.size();
- savefile1 << n1 << "\n";
- for (int i = 0; i < n1; i++) {
- int z, u;
- string x, y, v, t;
- x = cus_product[m].giohang[i].seri;
- y = cus_product[m].giohang[i].name;
- z = cus_product[m].giohang[i].price;
- u = cus_product[m].giohang[i].solg;
- v = cus_product[m].giohang[i].nsx;
- t = cus_product[m].giohang[i].hsd;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == ' ')y[j] = '_';
- }
- savefile1 << x << " ";
- savefile1 << y << " ";
- savefile1 << z << " ";
- savefile1 << u << " ";
- savefile1 << v << " ";
- savefile1 << t << " ";
- savefile1 << "\n";
- }
- ///luu lich su;
- int n2 = cus_product[m].cusProduct.size();
- savefile1 << n2 << "\n";
- for (int j = 0; j < n2; j++) {
- int z, u;
- string x, y, v, t;
- x = cus_product[m].cusProduct[j].seri;
- y = cus_product[m].cusProduct[j].name;
- z = cus_product[m].cusProduct[j].price;
- u = cus_product[m].cusProduct[j].solg;
- v = cus_product[m].cusProduct[j].nsx;
- t = cus_product[m].cusProduct[j].hsd;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == ' ')y[j] = '_';
- }
- savefile1 << x << " ";
- savefile1 << y << " ";
- savefile1 << z << " ";
- savefile1 << u << " ";
- savefile1 << v << " ";
- savefile1 << t << " ";
- savefile1 << "\n";
- }
- }
- savefile1.close();
- cout << "Success!" << endl;
- }
- bool readfile_buyproduct(vector<Customer>&cus_product) {
- ifstream readfile2("savebuyproduct.txt");
- string x, y, v, t;
- int z, u;
- //cus_product.clear();
- if (!readfile2.is_open())
- {
- cout << "Khong the mo file buy .\n";
- system("pause");
- return 0;
- }
- else {
- int index1;
- readfile2 >> index1;
- string username;
- for (int n = 0; n < index1; n++) {
- readfile2 >> username;
- cus_product.push_back(Customer());
- cus_product[n].username = username;
- }
- for (int m = 0; m < index1; m++) {
- int index2;
- readfile2 >> index2;
- for (int p = 0; p < index2; p++) {
- int z, u;
- string x, y, v, t;
- readfile2 >> x;
- readfile2 >> y;
- readfile2 >> z;
- readfile2 >> u;
- readfile2 >> v;
- readfile2 >> t;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == '_')y[j] = ' ';
- }
- cus_product[m].giohang.push_back(Product());
- cus_product[m].giohang[p].seri = x;
- cus_product[m].giohang[p].name = y;
- cus_product[m].giohang[p].price = z;
- cus_product[m].giohang[p].solg = u;
- cus_product[m].giohang[p].nsx = v;
- cus_product[m].giohang[p].hsd = t;
- }
- int index3;
- readfile2 >> index3;
- for (int q = 0; q < index3; q++) {
- int z, u;
- string x, y, v, t;
- readfile2 >> x;
- readfile2 >> y;
- readfile2 >> z;
- readfile2 >> u;
- readfile2 >> v;
- readfile2 >> t;
- for (int j = 0; j < y.length(); j++) {
- if (y[j] == '_')y[j] = ' ';
- }
- cus_product[m].cusProduct.push_back(Product());
- cus_product[m].cusProduct[q].seri = x;
- cus_product[m].cusProduct[q].name = y;
- cus_product[m].cusProduct[q].price = z;
- cus_product[m].cusProduct[q].solg = u;
- cus_product[m].cusProduct[q].nsx = v;
- cus_product[m].cusProduct[q].hsd = t;
- }
- }
- }
- readfile2.close();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement