Advertisement
Guest User

ass

a guest
Jun 7th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<iomanip>
  4. #include<string>
  5. #include <fstream>
  6. #include<sstream>
  7. using namespace std;
  8.  
  9. struct Account {
  10. string user;
  11. string password;
  12. };
  13. struct Role {
  14. string user;
  15. string namework;
  16. };
  17. struct Account_to_role {
  18. string user;
  19. string chucnang;
  20. };
  21.  
  22.  
  23. struct Product {
  24. string seri = "";
  25. string name = "";
  26. string nsx = "";
  27. string hsd = "";
  28. int solg = 0;
  29. int price = 0;
  30.  
  31. };
  32.  
  33. struct Customer {
  34.  
  35. string username;
  36.  
  37. vector <Product> cusProduct;
  38. vector <Product> giohang;
  39.  
  40. };
  41.  
  42. bool readfile_buyproduct(vector<Customer>&cus_product);
  43. void savefile_buyproduct(vector<Customer>&cus_product);
  44. bool readfile_product(vector<Product>&product);
  45. void savefile_product(vector<Product>product);
  46.  
  47. bool history_buy(vector<Customer>&cus_product, string &a);
  48. bool xacnhan_mua(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
  49. bool edit_giohang(vector<Customer>&cus_product, string&a);
  50. bool xem_giohang(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
  51. bool for_customer(vector<Customer> &cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a);
  52. void add_giohang(string seri, vector<Customer>&cus_product, vector<Product> &product, string&a);
  53. bool find_to_buy(vector<Customer>&cus_product, vector<Product>&product, string&a);
  54.  
  55.  
  56.  
  57.  
  58. bool thongke_hanghoa(vector<Product>&product);
  59. bool edit_hanghoa(vector<Product>&product);
  60. bool find_hanghoa(vector<Product>&product);
  61. bool xoa_hanghoa(vector<Product>&product);
  62. bool test_seri(string temp, vector<Product>product);
  63. bool them_hanghoa(vector<Product>&product);
  64. bool forstaff(vector<Product> &product);
  65.  
  66.  
  67.  
  68.  
  69. bool docfile_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
  70. void luufile(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
  71. bool test_account_to_login(vector<Account> &acc, vector<Role> &role, string &a, string &b, string &c);
  72. bool logintk(vector<Account> &acc, vector<Account_to_role>&acc_role, vector<Role> &role,
  73. vector<Customer>&cus_product, vector<Product>&product, string &a, string &b, string &c);
  74. void allocation(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product);
  75. bool captk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b);
  76. bool resetpassword(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
  77. 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);
  78. 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);
  79. bool forstaff(vector<Product> &product);
  80. bool test_user(vector<Account> &acc, string testuser);
  81. bool test_user_to_delete(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string testuser);
  82. bool delete_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product);
  83. bool information_acc_present(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, string a);
  84. bool information_list_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
  85. bool serch_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role);
  86.  
  87.  
  88. bool test_time(int dd1, int dd2, int mm1, int mm2, int yy1, int yy2) {
  89. if (yy2 < yy1 || (yy2 == yy1&&mm2 < mm1) || (yy2 == yy1&&mm2 == mm1 && (dd2<dd1 || dd2 == dd1)))return 0;
  90. else return 1;
  91.  
  92. }
  93. bool signup_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b) {
  94. _flushall;
  95. system("cls");
  96. cout << "\t\t\t\t\t\t\t\t\n\n\NHAP USER: ";
  97. string testuser;
  98. getline(cin, testuser);
  99.  
  100. if (test_user(acc, testuser) == false) {
  101. cout << "\t\t\t\t\t\t\t\tACCOUNT DA TON TAI";
  102. cout << "\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.LOGOUT " << endl;
  103. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  104. int m;
  105. cin >> m;
  106. cin.ignore(1);
  107. switch (m) {
  108. case 1: return 1;
  109. case 2: return 0;
  110. default: return 1;
  111. }
  112. }
  113.  
  114. int n = acc.size();
  115. acc.push_back(Account());
  116. acc[n].user = testuser;
  117.  
  118. _flushall;
  119. cout << "\t\t\t\t\t\t\t\tCAP PASSWORD ";
  120. string pass1;
  121. getline(cin, pass1);
  122.  
  123. acc[n].password = pass1;
  124. _flushall;
  125.  
  126.  
  127. int i = cus_product.size();
  128.  
  129. cus_product.push_back(Customer());
  130. cus_product[i].username = testuser;
  131.  
  132. acc_role.push_back(Account_to_role());
  133. acc_role[n].user = "khachhang";
  134. acc_role[n].chucnang = "customer";
  135.  
  136. role.push_back(Role());
  137.  
  138. role[n].user = "customer";
  139. role[n].namework = "khachhang";
  140.  
  141.  
  142.  
  143.  
  144. int k;
  145. cout << "\t\t\t\t\t\t\t\t\nCAP THANH CONG! ";
  146. luufile(acc, acc_role, role);
  147. }
  148. int main() {
  149. bool dk;
  150. vector<Customer> cus_product;
  151. //sysadmin;
  152. vector<Account> acc;
  153. vector<Role> role;
  154. vector<Account_to_role> acc_role;
  155. allocation(acc, acc_role, role, cus_product);
  156. string a, b, c;
  157.  
  158. //storemanager
  159. vector<Product> product;
  160. //customer
  161. cout << "\n\n\t\t\t\t\t\t\t\t--------------------------------------------------" << endl;
  162. cout << "\t\t\t\t\t\t\t\t| CHAO MUNG BAN DEN VOI HE THONG BAN HANG ONLINE |" << endl;
  163. cout << "\t\t\t\t\t\t\t\t--------------------------------------------------" << endl;
  164. //vector<Customer> cus_product;
  165. cout << "\n\n\n \t\t\t\t \t \t1. LOGIN 2.SIGN UP" << endl;
  166. cout << "\n\t\t\t\t\t MOI BAN NHAP SU LUA CHON(1 OR 2 )";
  167. int n;
  168. cin >> n;
  169. cin.ignore(1);
  170. switch (n)
  171. {
  172. case 1:break;
  173. case 2:signup_acc(acc, acc_role, role, cus_product, a, b);
  174. default:
  175. break;
  176. }
  177.  
  178. do {
  179. do {
  180. dk = logintk(acc, acc_role, role, cus_product, product, a, b, c);
  181. } while (dk == false);
  182.  
  183. dk = phanvungtk(acc, acc_role, role, cus_product, product, a, b, c);
  184. } while (dk == false);
  185. system("pause");
  186. return 0;
  187. }
  188. 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) {
  189. system("cls");
  190. cout << c << endl;
  191.  
  192. if (c == "storemanager") {
  193.  
  194. return for_admin(acc, acc_role, role, cus_product, a, b, c);
  195. }
  196. else if (c == "staff") {
  197.  
  198. return forstaff(product);
  199. }
  200. else {
  201.  
  202. return for_customer(cus_product, product, acc, role, a);
  203. }
  204. return 1;
  205. }
  206. bool test_account_to_login(vector<Account> &acc, vector<Role> &role, string &a, string &b, string &c) {
  207. for (int j = 0; j < acc.size(); j++) {
  208. if (a == acc[j].user && b == acc[j].password) {
  209. c = role[j].user;
  210.  
  211. return 1;
  212. }
  213. }
  214. return 0;
  215. }
  216. bool logintk(vector<Account> &acc, vector<Account_to_role>&acc_role,
  217. vector<Role> &role, vector<Customer>&cus_product, vector<Product>&product
  218. , string &a, string &b, string &c) {
  219.  
  220. /*docfile_account(acc, acc_role, role);
  221. readfile_product(product);
  222. readfile_buyproduct(cus_product);*/
  223. system("cls");
  224. cout << "\n\n\n\t\t\t\t\t\t\t\t LOGIN WITH YOUR ACCOUNT " << endl;
  225. cout << "\n\n\n\n\n\n\t\t\t NHAP USER : ";
  226. getline(cin, a);
  227. cout << "\t\t\t NHAP PASSWORD : ";
  228. getline(cin, b);
  229. return test_account_to_login(acc, role, a, b, c);
  230. }
  231. bool docfile_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  232. ifstream ACCount("luu.txt");
  233. string x, y, z, u, v, t;
  234. acc.clear();
  235. acc_role.clear();
  236. role.clear();
  237. int index;
  238. if (!ACCount.is_open())
  239. {
  240. cout << "\t\t\t\t\t\t\t\tKHONG THE MO FILE.\n";
  241. system("pause");
  242. return 0;
  243. }
  244. else {
  245. ACCount >> index;
  246. for (int i = 0; i < index; i++)
  247. {
  248. ACCount >> x;
  249. ACCount >> y;
  250. ACCount >> z;
  251. ACCount >> u;
  252. ACCount >> v;
  253. ACCount >> t;
  254. acc.push_back(Account());
  255. acc[i].user = x;
  256. acc[i].password = y;
  257. acc_role.push_back(Account_to_role());
  258. acc_role[i].user = z;
  259. acc_role[i].chucnang = u;
  260. role.push_back(Role());
  261. role[i].user = v;
  262. role[i].namework = t;
  263. }
  264. }
  265. ACCount.close();
  266.  
  267. }
  268. void allocation(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product) {
  269.  
  270. acc.push_back(Account());
  271.  
  272. acc[0].password = "28051997";
  273. acc[0].user = "huynhhai";
  274.  
  275. acc.push_back(Account());
  276.  
  277.  
  278. acc[1].user = "staff";
  279. acc[1].password = "12345";
  280.  
  281. acc.push_back(Account());
  282.  
  283.  
  284. acc[2].user = "customer";
  285. acc[2].password = "12345";
  286.  
  287. cus_product.push_back(Customer());
  288. cus_product[0].username = "customer";
  289.  
  290.  
  291. acc_role.push_back(Account_to_role());
  292.  
  293. acc_role[0].user = "quantrivien";
  294. acc_role[0].chucnang = "storemanager";
  295.  
  296. acc_role.push_back(Account_to_role());
  297.  
  298.  
  299. acc_role[1].user = "nhanvien";
  300. acc_role[1].chucnang = "storemanager";
  301.  
  302. acc_role.push_back(Account_to_role());
  303.  
  304. acc_role[2].user = "khachhang";
  305. acc_role[2].chucnang = "customer";
  306.  
  307. role.push_back(Role());
  308. role[0].user = "storemanager";
  309. role[0].namework = "quanlinhanvien";
  310.  
  311. role.push_back(Role());
  312.  
  313. role[1].user = "staff";
  314. role[1].namework = "nhanvienbanhang";
  315.  
  316. role.push_back(Role());
  317.  
  318. role[2].user = "customer";
  319. role[2].namework = "khachhang";
  320. }
  321. bool captk(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product, string &a, string&b) {
  322. _flushall;
  323. system("cls");
  324. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  325. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  326. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  327. cout << "\n\n\t\t\t\t\t\t\t\tNHAP USER: ";
  328. string testuser;
  329. getline(cin, testuser);
  330.  
  331. if (test_user(acc, testuser) == false) {
  332. cout << "\t\t\t\t\t\t\t\tACCOUNT DA TON TAI";
  333. cout << " \t\t\t\t\t\t\t Lua chon: 1.NHAP LAI 2.LOGOUT " << endl;
  334. cout << " \t\t\t\t\t\t\t\t NHAP SU LUA CHON CUA BAN (1,2 OR 3 ) :";
  335. int m;
  336. cin >> m;
  337. cin.ignore(1);
  338. switch (m) {
  339. case 1: return 1;
  340. case 2: return 0;
  341. default: return 1;
  342. }
  343. }
  344.  
  345. int n = acc.size();
  346. acc.push_back(Account());
  347. acc[n].user = testuser;
  348.  
  349. _flushall;
  350. cout << "\t\t\t\t\t\t\t\tCAP PASSWORD : ";
  351. string pass1;
  352. getline(cin, pass1);
  353.  
  354. acc[n].password = pass1;
  355. _flushall;
  356. cout << " \n \t\t\t\t\t\t\t\t CHON LOAI TAI KHOAN: 1.ADMIN 2.NHAN VIEN 3.KHACH HANG " << endl;
  357. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  358. int z;
  359. cin >> z;
  360. cin.ignore(1);
  361.  
  362. switch (z) {
  363. case 1: {
  364. acc_role.push_back(Account_to_role());
  365. acc_role[n].chucnang = "storemanager";
  366. acc_role[n].user = "nhanvien";
  367.  
  368. role.push_back(Role());
  369. role[n].user = "storemanager";
  370. role[n].namework = "quanlinhanvien";
  371. break;
  372. }
  373. case 2: {
  374. acc_role.push_back(Account_to_role());
  375.  
  376. acc_role[n].user = "nhanvien";
  377. acc_role[n].chucnang = "storemanager";
  378. //
  379. role.push_back(Role());
  380.  
  381. role[n].user = "staff";
  382. role[n].namework = "nhanvienbanhang";
  383. break;
  384. }
  385. case 3: {
  386. int i = cus_product.size();
  387.  
  388. cus_product.push_back(Customer());
  389. cus_product[i].username = testuser;
  390.  
  391. acc_role.push_back(Account_to_role());
  392. acc_role[n].user = "khachhang";
  393. acc_role[n].chucnang = "customer";
  394.  
  395. role.push_back(Role());
  396.  
  397. role[n].user = "customer";
  398. role[n].namework = "khachhang";
  399. break;
  400. }
  401. default:
  402. break;
  403. }
  404.  
  405. int k;
  406. cout << "\t\t\t\t\t\t\t\tCAP THANH CONG! ";
  407. luufile(acc, acc_role, role);
  408. cout << "\n\t\t\t\t\t\t\t\t 1.GOBACK 2.LOGOUT " << endl;
  409. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2)";
  410. cin >> k;
  411. cin.ignore(1);
  412. switch (k) {
  413. case 1: return 1;
  414. case 2: return 0;
  415. }
  416.  
  417. }
  418. bool resetpassword(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  419. bool dk3;
  420. do {
  421. system("cls");
  422. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  423. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  424. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  425. cout << "\n\n\t\t\t\t\t\t\t\tNHAP ACCOUNT CAN RESET: ";
  426. string nameacc;
  427. getline(cin, nameacc);
  428. for (int i = 0; i < acc.size(); i++) {
  429. if (nameacc == acc[i].user) {
  430. string x;
  431. cout << "\t\t\t\t\t\t\t\tNHAP NEW PASSWORD: ";
  432. getline(cin, x);
  433. acc[i].password = x;
  434. cout << "\t\t\t\t\t\t\t\tSUCCESS!" << endl;
  435.  
  436.  
  437. luufile(acc, acc_role, role);
  438.  
  439.  
  440.  
  441. return 1;
  442. }
  443. }
  444. cout << "\t\t\t\t\t\t\t\t\tACCONUT KHONG TON TAI";
  445. cout << "\n\t\t\t\t\t\t\t\t chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
  446. cout << "\n\t\t\t\t\t\t\t\ttMOI BAN NHAP SU LUA CHON(1,2 OR 3)";
  447. int m;
  448. cin >> m;
  449. cin.ignore(1);
  450. switch (m) {
  451. case 1: dk3 = false; break;
  452. case 2: return 1;
  453. case 3: return 0;
  454. default: dk3 = false; break;
  455. }
  456.  
  457. } while (dk3 == false);
  458.  
  459. }
  460. 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) {
  461.  
  462. bool dk2;
  463. do {
  464. system("cls");
  465. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  466. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  467. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  468. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -1.CAP ACCOUNT" << setw(5) << right << "-" << endl;
  469. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -2.RESET PASSWORD" << setw(5) << right << "-" << endl;
  470. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -3.XEM THONG TIN ACCOUNT" << setw(5) << right << "-" << endl;
  471. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -4.DELETE ACCOUNT" << setw(5) << right << "-" << endl;
  472. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -5.INFORMATION LIST ACCOUNT" << setw(5) << right << "-" << endl;
  473. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -6.SEARCH INFORMATION ACCOUNT" << setw(5) << right << "-" << endl;
  474. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -7.LOGOUT" << setw(5) << right << "-" << endl;
  475. cout << "\t\t\t\t\t\t\t\t----------------------------------------" << endl;
  476. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN :";
  477. int r;
  478. cin >> r;
  479. cin.ignore(1);
  480. switch (r) {
  481. case 1: {
  482. if (captk(acc, acc_role, role, cus_product, a, b) == false) return 0;
  483. else dk2 = true;
  484. break;
  485. }
  486. case 2: if (resetpassword(acc, acc_role, role) == true) { dk2 = true; break; }
  487. else return 0;
  488. case 3:if (information_acc_present(acc, acc_role, role, a) == true) { dk2 = true; break; }
  489. else return 0;
  490. case 4:if (delete_account(acc, acc_role, role, cus_product) == true) { dk2 = true; break; }
  491. else return 0;
  492. case 5:if (information_list_acc(acc, acc_role, role) == true) { dk2 = true; break; }
  493. else return 0;
  494. case 6:if (serch_account(acc, acc_role, role) == true) { dk2 = true; break; }
  495. else return 0;
  496. case 7: return 0;
  497. }
  498. } while (dk2 == true);
  499. return 1;
  500.  
  501. }
  502.  
  503. bool test_user(vector<Account> &acc, string testuser) {
  504.  
  505. for (int j = 0; j < acc.size(); j++) {
  506. if (testuser == acc[j].user) return 0;
  507. }
  508. return 1;
  509. }
  510. bool delete_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product) {
  511. bool dk2 = true;
  512. do {
  513. system("cls");
  514. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  515. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  516. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  517. cout << "\n\n\t\t\t\t\t\t\t\t NHAP ACCOUNT CAN DELETE : ";
  518. string nameacc;
  519. getline(cin, nameacc);
  520.  
  521. if (test_user_to_delete(acc, acc_role, role, cus_product, nameacc) == true) {
  522. system("cls");
  523. cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
  524. luufile(acc, acc_role, role);
  525. int a;
  526. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  527. cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1,2 OR 3) :";
  528. cin >> a;
  529. cin.ignore(1);
  530. switch (a)
  531. {
  532. case 1: return 1;
  533. case 2: return 0;
  534. default:
  535. return 0;
  536. }
  537. }
  538. else {
  539. cout << "\t\t\t\t\t\t\t\tACCOUNT CAN DELETE KHONG TON TAI" << endl;
  540. int a;
  541. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
  542. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN( 1 ,2 OR 3) :";
  543. cin >> a;
  544. cin.ignore(1);
  545. switch (a)
  546. {
  547. case 1: dk2 = false; break;
  548. case 2: return 1;
  549. case 3: return 0;
  550. default:
  551. return 1;
  552. }
  553. }
  554. } while (dk2 == false);
  555.  
  556.  
  557. }
  558. bool test_user_to_delete(vector<Account> &acc, vector<Account_to_role> &acc_role,
  559. vector<Role> &role, vector<Customer>&cus_product, string testuser) {
  560. for (int i = 0; i < acc.size(); i++) {
  561. if (testuser == acc[i].user) {
  562. acc.erase(acc.begin() + i);
  563.  
  564. acc_role.erase(acc_role.begin() + i);
  565.  
  566. role.erase(role.begin() + i);
  567.  
  568. int n = cus_product.size();
  569. for (int j = 0; j < n; j++) {
  570. if (testuser == cus_product[j].username) {
  571. cus_product.erase(cus_product.begin() + j);
  572. break;
  573. }
  574. }
  575.  
  576. return 1;
  577. }
  578. }
  579.  
  580. return 0;
  581. }
  582. bool information_acc_present(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, string a) {
  583. int i;
  584. for (i = 0; i < acc.size(); i++) {
  585. if (acc[i].user == a) break;
  586. }
  587. system("cls");
  588. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  589. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  590. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  591. cout << "\n\t\t\t\t\t\t\t\tNAME ACCOUNT : " << acc[i].user << endl;
  592. cout << "\t\t\t\t\t\t\t\tPASSWORD : " << acc[i].password << endl;
  593. cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT : " << role[i].user << endl;
  594. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  595. cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
  596. int n;
  597. cin >> n;
  598. cin.ignore(1);
  599. switch (n)
  600. {
  601. case 1: return 1;
  602. case 2: return 0;
  603. default:
  604. return 1;
  605. }
  606. return 1;
  607. }
  608. bool information_list_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  609. system("cls");
  610. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  611. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  612. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  613. cout << "\n\n\t\t\t\t\t\t\t\t==========List_Account==========" << endl;
  614. cout <<"\t\t\t\t\t\t\t\t"<< setw(20) << "USER" << setw(20) << "PASSWORD" << setw(20) << "LOAI ACCOUNT" << endl;
  615. int x = acc.size();
  616. for (int i = 0; i < x; i++) {
  617. cout <<"\t\t\t\t\t\t\t\t" <<setw(20) << acc[i].user << setw(20) << acc[i].password << setw(20) << role[i].user << endl;
  618. }
  619. cout << "\n\t\t\t\t\t\t\t\t TONG SO ACCOUNT TRONG HET THONG: " << x << endl;
  620. cout << "\n\t\t\t\t\t\t\t\t Lua chon: 1.QUAY LAI 2.LOGOUT " << endl;
  621. cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
  622. int n;
  623. cin >> n;
  624. cin.ignore(1);
  625. switch (n)
  626. {
  627. case 1: return 1;
  628. case 2: return 0;
  629. default:
  630. return 1;
  631. }
  632. return 1;
  633. }
  634. bool serch_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  635. system("cls");
  636. string a;
  637. int n = acc.size();
  638. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  639. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  640. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  641. cout << "\t\t\t\t\t\t\t\tNHAP VAO NAME ACCOUNT CAN TIM : ";
  642. getline(cin, a);
  643. int i;
  644. for (i = 0; i < n; i++) {
  645. if (a == acc[i].user)break;
  646. }
  647. if (i < n) {
  648. system("cls");
  649. cout << "\t\t\t\t\t\t\t\tNAME ACCOUNT : " << acc[i].user << endl;
  650. cout << "\t\t\t\t\t\t\t\tPASSWORD : " << acc[i].password << endl;
  651. cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT : " << role[i].user << endl;
  652. }
  653. else cout <<"\t\t\t\t\t\t\t\t\ttKHONG TIM THAY" << endl;
  654. cout << "\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  655. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  656. int m;
  657. cin >> m;
  658. cin.ignore(1);
  659. switch (m)
  660. {
  661. case 1: return 1;
  662. case 2: return 0;
  663. default:
  664. return 1;
  665. }
  666. return 1;
  667. }
  668. void luufile(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  669. ofstream cap("luu.txt");
  670. int index = acc.size();
  671. cap << index << "\n";
  672. for (int i = 0; i < index; i++) {
  673. string x, y, z, u, v, t;
  674. x = acc[i].user;
  675. y = acc[i].password;
  676. z = acc_role[i].user;
  677. u = acc_role[i].chucnang;
  678. v = role[i].user;
  679. t = role[i].namework;
  680.  
  681. cap << x << "\n";
  682. cap << y << "\n";
  683. cap << z << "\n";
  684. cap << u << "\n";
  685. cap << v << "\n";
  686. cap << t << "\n";
  687.  
  688. }
  689. cap.close();
  690. cout << "Success!" << endl;
  691. }
  692.  
  693. ///////
  694.  
  695.  
  696. //of_storemanager
  697.  
  698. bool them_hanghoa(vector<Product>&product) {
  699. bool dk4;
  700. int price, solg;
  701. int dd1, mm1, yy1;
  702. string seri, name, nsx, hsd;
  703. system("cls");
  704. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  705. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  706. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  707. do {
  708.  
  709. cout << "\n\n\t\t\t\t\t\t\t\tNHAP VAO SERI";
  710. getline(cin, seri);
  711. if (test_seri(seri, product) == false) {
  712.  
  713. cout << "\n\t\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
  714. cout << "\n\t\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
  715. int n;
  716. cin >> n;
  717. cin.ignore(1);
  718. switch (n)
  719. {
  720. case 1: dk4 = true; break;
  721. case 2: return 1;
  722. case 3:return 0;
  723. default:
  724. return 1;
  725. }
  726. }
  727. else {
  728. bool boolday;
  729. cout << "\n\t\t\t\t\t\t\t\tTEN HANG HOA :";
  730. getline(cin, name);
  731. do {
  732. do {
  733. boolday = true;
  734. cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT(dd mm yy) : ";
  735. cin >> dd1 >> mm1 >> yy1;
  736. cin.ignore(1);
  737.  
  738. if (dd1 > 31 || dd1 < 1 || mm1>12 || mm1 < 1 || yy1 < 0) {
  739. cout <<"\n\t\t\t\t\t\t\t\tNSX FAIL!";
  740. boolday = false;
  741. }
  742. else {
  743. ostringstream ddmmyy;
  744. ddmmyy << dd1 << "/" << mm1 << "/" << yy1;
  745.  
  746. nsx = ddmmyy.str();
  747.  
  748. }
  749. } while (boolday == false);
  750.  
  751.  
  752. /////////////////////////
  753. int dd2, mm2, yy2;
  754. do {
  755. boolday = true;
  756. cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG(dd mm yy) : ";
  757. cin >> dd2 >> mm2 >> yy2;
  758. cin.ignore(1);
  759.  
  760. if (dd2 > 31 || dd2 < 1 || mm2>12 || mm2 < 1 || yy2 < 0) {
  761. cout << "\n\t\t\t\t\t\t\t\tHSD FAIL!";
  762. boolday = false;
  763. }
  764. else {
  765. ostringstream ddmmyy;
  766. ddmmyy << dd2 << "/" << mm2 << "/" << yy2;
  767.  
  768. hsd = ddmmyy.str();
  769.  
  770. }
  771. } while (boolday == false);
  772. if (test_time(dd1, dd2, mm1, mm2, yy1, yy2) == true)boolday = true;
  773. else boolday = false;
  774. } while (boolday == false);
  775.  
  776.  
  777. cout << "\n\t\t\t\t\t\t\t\tSO LUONG :";
  778. cin >> solg;
  779. cin.ignore(1);
  780. cout << "\n\t\t\t\t\t\t\t\tGIA BAN : ";
  781. cin >> price;
  782. cin.ignore(1);
  783.  
  784. int i = product.size();
  785. product.push_back(Product());
  786. product[i].seri = seri;
  787. product[i].nsx = nsx;
  788. product[i].hsd = hsd;
  789. product[i].price = price;
  790. product[i].name = name;
  791. product[i].solg = solg;
  792.  
  793. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  794. savefile_product(product);
  795. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
  796. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  797. int n;
  798. cin >> n;
  799. cin.ignore(1);
  800. switch (n)
  801. {
  802. case 1: dk4 = true; break;
  803. case 2: return 1;
  804. case 3:return 0;
  805. default:
  806. return 1;
  807. }
  808.  
  809. }
  810. } while (dk4 == true);
  811.  
  812. }
  813. bool test_seri(string seri, vector<Product>product) {
  814. for (int i = 0; i < product.size(); i++) {
  815. if (seri == product[i].seri) {
  816. cout << "\t\t\t\t\t\t\t\tSERI SAN PHAM DA CO TRONG KHO " << endl;
  817. return 0;
  818. }
  819. }
  820. return 1;
  821. }
  822. bool forstaff(vector<Product> &product) {
  823. bool dk3 = true;
  824. do {
  825. system("cls");
  826. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  827. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  828. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  829. cout << "\n\t\t\t\t\t\t\t\t1.THEM HANG HOA " << endl;
  830. cout << "\n\t\t\t\t\t\t\t\t2.XOA HANG HOA " << endl;
  831. cout << "\n\t\t\t\t\t\t\t\t3.TIM KIEM HANG HOA" << endl;
  832. cout << "\n\t\t\t\t\t\t\t\t4.CHINH SUA HANG HOA " << endl;
  833. cout << "\n\t\t\t\t\t\t\t\t5.THONG KE" << endl;
  834. cout << "\n\t\t\t\t\t\t\t\t6.LOGOUT" << endl;
  835. cout << "\t\t\t\t\t\t\t\t MOI BAN NHAP LUA CHON ";
  836. int m;
  837. cin >> m;
  838. cin.ignore(1);
  839. switch (m) {
  840. case 1:if (them_hanghoa(product) == true)
  841. {
  842. dk3 = true; break;
  843. }
  844. else return 0;
  845. case 2:
  846. if (xoa_hanghoa(product) == true)
  847. {
  848. dk3 = true; break;
  849. }
  850. else return 0;
  851. case 3:
  852. if (find_hanghoa(product) == true)
  853. {
  854. dk3 = true; break;
  855. }
  856. else return 0;
  857. case 4:
  858. if (edit_hanghoa(product) == true)
  859. {
  860. dk3 = true; break;
  861. }
  862. else return 0;
  863. case 5:
  864. if (thongke_hanghoa(product) == true)
  865. {
  866. dk3 = true; break;
  867. }
  868. else return 0;
  869.  
  870. case 6:return 0;
  871. }
  872. } while (dk3 == true);
  873. return 0;
  874. }
  875. bool xoa_hanghoa(vector<Product>&product) {
  876. string seri;
  877. bool dk5;
  878. system("cls");
  879. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  880. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  881. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  882. do {
  883. cout << "\n\n\t\t\t\t\t\t\t\tNHAP SERI CAN XOA";
  884. getline(cin, seri);
  885. for (int i = 0; i < product.size(); i++) {
  886. if (seri == product[i].seri) {
  887. product.erase(product.begin() + i);
  888. cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
  889. savefile_product(product);
  890. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  891. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 , 2 OR 3) :";
  892. int n;
  893. cin >> n;
  894. cin.ignore(1);
  895. switch (n)
  896. {
  897. case 1: dk5 = true; break;
  898. case 2: return 1;
  899. case 3:return 0;
  900. default:
  901. return 1;
  902. }
  903.  
  904. }
  905. }
  906. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  907.  
  908. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  909. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
  910. int n;
  911. cin >> n;
  912. cin.ignore(1);
  913. switch (n)
  914. {
  915. case 1: dk5 = true; break;
  916. case 2: return 1;
  917. case 3:return 0;
  918. default:
  919. return 1;
  920. }
  921. } while (dk5 == true);
  922. }
  923. bool find_hanghoa(vector<Product>&product) {
  924. bool dk6 = false;
  925. string seri;
  926. string name;
  927. system("cls");
  928. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  929. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  930. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  931. do {
  932. cout << "\t\t\t\t\t\t\t\tSERI: ";
  933. getline(cin, seri);
  934. for (int i = 0; i < product.size(); i++) {
  935. if (seri == product[i].seri) {
  936. cout << "\n\t\t\t\t\t\t\t\tTHONG TIN SAN PHAM";
  937. cout << "\n\t\t\t\t\t\t\t\tSERI : " << product[i].seri << endl;
  938. cout << "\n\t\t\t\t\t\t\t\tNAME : " << product[i].name << endl;
  939. cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT : " << product[i].nsx << endl;
  940. cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG : " << product[i].hsd << endl;
  941. cout << "\n\t\t\t\t\t\t\t\tSO LUONG : " << product[i].solg << endl;
  942. cout << "\n\t\t\t\t\t\t\t\tPRICE : " << product[i].price << endl;
  943. cout << "\n\t\t\t\t\t\t\t\tSUCCESS ";
  944. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.Continue 2.GOBACK 3.LOGOUT " << endl;
  945. cout << "\n\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN (1 , 2 OR 3) :";
  946. int n;
  947. cin >> n;
  948. cin.ignore(1);
  949. switch (n)
  950. {
  951. case 1: dk6 = true; break;
  952. case 2: return 1;
  953. case 3:return 0;
  954. default:
  955. return 1;
  956. }
  957.  
  958. }
  959. if (dk6 == true)break;
  960. }
  961. if (dk6 == false) {
  962. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  963. cout << "\t\t\t\t\t\t\t\t chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  964. cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
  965. int n;
  966. cin >> n;
  967. cin.ignore(1);
  968. switch (n)
  969. {
  970. case 1: dk6 = true; break;
  971. case 2: return 1;
  972. case 3:return 0;
  973. default:
  974. return 1;
  975. }
  976. }
  977. } while (dk6 == true);
  978.  
  979. }
  980. bool edit_hanghoa(vector<Product>&product) {
  981. bool dk = false;
  982. int price, solg;
  983. int n;
  984. string seri, name, nsx, hsd;
  985. system("cls");
  986. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  987. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  988. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  989. do {
  990. cout << "\t\t\t\t\t\t\t\tSERI: ";
  991. getline(cin, seri);
  992. for (int i = 0; i < product.size(); i++) {
  993. if (seri == product[i].seri) {
  994.  
  995. cout << "\t\t\t\t\t\t\t\tSUA CAI GI: 1.SERI 2.NAME 3.NSX 4.HSX 5.SOLG 6.PRICE :" << endl;
  996. cin >> n;
  997. cin.ignore(1);
  998. product.push_back(Product());
  999. switch (n) {
  1000. case 1: {
  1001. cout << "\t\t\t\t\t\t\t\tNEW SERI : ";
  1002. product[i].seri = seri;
  1003. break;
  1004. }
  1005. case 2: {
  1006. cout << "\t\t\t\t\t\t\t\tNEW NAME : ";
  1007. getline(cin, name);
  1008. product[i].name = name;
  1009. break;
  1010. }
  1011. case 3: {
  1012. cout << "\t\t\t\t\t\t\t\tNEW NSX: ";
  1013. getline(cin, nsx);
  1014. product[i].nsx = nsx;
  1015. break;
  1016. }
  1017. case 4: {
  1018. cout << "\t\t\t\t\t\t\t\tNEW HSD: ";
  1019. getline(cin, hsd);
  1020. product[i].nsx = hsd;
  1021. break;
  1022. }
  1023. case 5: {
  1024. cout << "NEW SO LUONG: ";
  1025. cin >> solg;
  1026. cin.ignore(1);
  1027. product[i].solg = solg;
  1028. break;
  1029. }
  1030. case 6: {
  1031. cout << "\t\t\t\t\t\t\t\tNEW PRICE:";
  1032. cin >> price;
  1033. cin.ignore(1);
  1034. product[i].price = price;
  1035. break;
  1036. }
  1037. }
  1038. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  1039. savefile_product(product);
  1040. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  1041. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  1042. cin >> n;
  1043. cin.ignore(1);
  1044. switch (n)
  1045. {
  1046. case 1: dk = true; break;
  1047. case 2: return 1;
  1048. case 3:return 0;
  1049. default:
  1050. return 1;
  1051. }
  1052.  
  1053. }
  1054. if (dk == true)break;
  1055.  
  1056. }
  1057. if (dk == false) {
  1058. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  1059. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  1060. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  1061. int n;
  1062. cin >> n;
  1063. cin.ignore(1);
  1064. switch (n)
  1065. {
  1066. case 1: {dk = true; break; }
  1067. case 2:return 1;
  1068. case 3:return 0;
  1069. default:
  1070. return 1;
  1071. }
  1072. }
  1073.  
  1074. } while (dk == true);
  1075. }
  1076. bool thongke_hanghoa(vector<Product>&product) {
  1077. int pay = 0;
  1078. system("cls");
  1079. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  1080. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  1081. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  1082. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
  1083. for (int i = 0; i < product.size(); i++) {
  1084. pay = pay + product[i].price*product[i].solg;
  1085. 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;
  1086. }
  1087. cout << "\n\t\tTONG SO LUONG: " << product.size();
  1088. cout << "\n\t\tSO TIEN KHI BAN MUA : " << pay << endl;
  1089. cout << "\n\t\tLua chon: 1.GOBACK 2.LOGOUT" << endl;
  1090. cout << "\n\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1091. int n;
  1092. cin >> n;
  1093. cin.ignore(1);
  1094. switch (n)
  1095. {
  1096. case 1:return 1;
  1097. case 2:return 0;
  1098. default:
  1099. return 1;
  1100. }
  1101. }
  1102.  
  1103.  
  1104. //// customer
  1105.  
  1106. bool for_customer(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1107. bool dk3 = true;
  1108. do {
  1109. system("cls");
  1110. int temp = cus_product.size();
  1111. cout << temp << endl;
  1112. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1113. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1114. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1115. cout << "\n\t\t\t\t\t\t\t\t1.TIM KIEM HANG HOA" << endl;
  1116. cout << "\n\t\t\t\t\t\t\t\t2.XEM GIO HANG" << endl;
  1117. cout << "\n\t\t\t\t\t\t\t\t3.LICH SU MUA" << endl;
  1118. cout << "\n\t\t\t\t\t\t\t\t4.TIM KIEM DANH SACH SAN PHAM" << endl;
  1119. cout << "\n\t\t\t\t\t\t\t\t5.LOGOUT" << endl;
  1120. int m;
  1121. cout << "\t\t\t\t\t\t\t\tMOI NHAP LUA CHON : ";
  1122. cin >> m;
  1123. cin.ignore(1);
  1124. switch (m) {
  1125. case 1:if (find_to_buy(cus_product, product, a) == true)
  1126. {
  1127. dk3 = true; break;
  1128. }
  1129. else return 0;
  1130. case 2:
  1131. if (xem_giohang(cus_product, product, acc, role, a) == true)
  1132. {
  1133. dk3 = true; break;
  1134. }
  1135. else return 0;
  1136.  
  1137. case 3:
  1138. if (history_buy(cus_product, a) == true)
  1139. {
  1140. dk3 = true; break;
  1141. }
  1142. else return 0;
  1143. case 4:
  1144. if (thongke_hanghoa(product) == true)
  1145. {
  1146. dk3 = true; break;
  1147. }
  1148. else return 0;
  1149.  
  1150. case 5:return 0;
  1151. }
  1152. } while (dk3 == true);
  1153. return 0;
  1154. }
  1155.  
  1156.  
  1157. bool find_to_buy(vector<Customer>&cus_product, vector<Product>&product, string &a) {
  1158. bool dk;
  1159. string name, seri;
  1160. system("cls");
  1161. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1162. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1163. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1164. do {
  1165. int dem = 0;
  1166. cout << "\t\t\t\t\t\t\t\tSEARCH NAME : ";
  1167. getline(cin, name);
  1168. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SoLg" << endl;
  1169. for (int i = 0; i < product.size(); i++) {
  1170. if (name == product[i].name) {
  1171. 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;
  1172. dem++;
  1173. }
  1174. }
  1175. if (dem > 0) {
  1176. cout << "\t\t\t\t\t\t\t\tHIEN CO " << dem << "\t\t\t\t\t\t\t\t LOAI SAN PHAM" << endl;
  1177.  
  1178.  
  1179. int m;
  1180. cout << "\t\t\t\t\t\t\t\tLua chon: 1.MUA HANG VOI SERI 2.GOBACK 3.LOGOUT " << endl;
  1181. cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
  1182. cin >> m;
  1183. cin.ignore(1);
  1184. switch (m) {
  1185. case 1: {
  1186.  
  1187. cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN MUA : ";
  1188. getline(cin, seri);
  1189.  
  1190.  
  1191. add_giohang(seri, cus_product, product, a);
  1192. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang)! " << endl;
  1193. cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
  1194. int n;
  1195. cin >> n;
  1196. cin.ignore(1);
  1197. switch (n)
  1198. {
  1199. case 1:dk = true; break;
  1200. case 2:return 1;
  1201. case 3:return 0;
  1202. default:
  1203. return 1;
  1204. }
  1205. break;
  1206. }
  1207. case 2:return 1;
  1208. case 3:return 0;
  1209. default:return 1;
  1210. }
  1211. }
  1212. else {
  1213. cout << "\t\t\t\t\t\t\t\t KHONG TIM THAY" << endl;
  1214. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang) " << endl;
  1215. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3 )";
  1216. int n;
  1217. cin >> n;
  1218. cin.ignore(1);
  1219. switch (n)
  1220. {
  1221. case 1:dk = true; break;
  1222. case 2:return 1;
  1223. case 3:return 0;
  1224. default:
  1225. return 1;
  1226. }
  1227.  
  1228. }
  1229.  
  1230. } while (dk == true);
  1231. }
  1232.  
  1233.  
  1234. void add_giohang(string seri, vector<Customer>&cus_product, vector<Product> &product, string &a) {
  1235. int temp = 0;
  1236. system("cls");
  1237. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1238. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1239. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1240. for (int n = 0; n < cus_product.size(); n++) {
  1241. if (cus_product[n].username == a) {
  1242. temp = n; break;
  1243. }
  1244. }
  1245.  
  1246. int j = cus_product[temp].giohang.size();
  1247. int k;
  1248. k = j;
  1249. for (int i = 0; i < product.size(); i++) {
  1250. if (seri == product[i].seri) {
  1251. cout << "\t\t\t\t\t\t\t\tSO LUONG : ";
  1252. int solg;
  1253. cin >> solg;
  1254. cin.ignore(1);
  1255. if (solg <= product[i].solg) {
  1256. cus_product[temp].giohang.push_back(Product());
  1257. cus_product[temp].giohang[j].name = product[i].name;
  1258. cus_product[temp].giohang[j].seri = product[i].seri;
  1259. cus_product[temp].giohang[j].price = product[i].price;
  1260. cus_product[temp].giohang[j].nsx = product[i].nsx;
  1261. cus_product[temp].giohang[j].hsd = product[i].hsd;
  1262. cus_product[temp].giohang[j].solg = solg;
  1263.  
  1264. j = j + 1;
  1265. break;
  1266. }
  1267. else "\t\t\t\t\t\t\t\tSO LUONG KHONG CHO PHEP"; break;
  1268. }
  1269. }
  1270.  
  1271. if (j > k) {
  1272. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  1273. savefile_buyproduct(cus_product);
  1274. }
  1275.  
  1276. else cout << "\t\t\t\t\t\t\t\tFAIL!";
  1277. }
  1278.  
  1279.  
  1280. bool xem_giohang(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1281. bool dk = true;
  1282. int temp = 0;
  1283. system("cls");
  1284. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1285. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1286. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1287. for (int n = 0; n < cus_product.size(); n++) {
  1288. if (cus_product[n].username == a) {
  1289. temp = n; break;
  1290. }
  1291. }
  1292.  
  1293. do {
  1294. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE"
  1295. << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
  1296. int pay = 0;
  1297. for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
  1298. pay = pay + cus_product[temp].giohang[i].price*cus_product[temp].giohang[i].solg;
  1299. cout << setw(20) << cus_product[temp].giohang[i].name << setw(20) << cus_product[temp].giohang[i].seri << setw(20)
  1300. << cus_product[temp].giohang[i].price << setw(20) << cus_product[temp].giohang[i].nsx
  1301. << setw(20) << cus_product[temp].giohang[i].hsd << setw(20) << cus_product[temp].giohang[i].solg << endl;
  1302. }
  1303. cout << "\n\t\t\t\t\t\t\t\tTong Loai Hang: " << cus_product[temp].giohang.size() << endl;
  1304. cout << "\n\t\t\t\t\t\t\t\tThanh Tien: " << pay;
  1305. 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;
  1306. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN(1,2,3 OR 4)";
  1307. int n;
  1308. cin >> n;
  1309. cin.ignore(1);
  1310. switch (n)
  1311. {
  1312. case 1:
  1313. if (edit_giohang(cus_product, a) == true) {
  1314. dk = true; break;
  1315. }
  1316. else return 0;
  1317. case 2:
  1318. if (xacnhan_mua(cus_product, product, acc, role, a) == true) {
  1319. dk = true; break;
  1320. }
  1321. else return 0;
  1322. case 3:return 1;
  1323. case 4:return 0;
  1324. default:
  1325. return 1;
  1326. }
  1327. } while (dk = true);
  1328. return 1;
  1329. }
  1330.  
  1331. bool edit_giohang(vector<Customer>&cus_product, string&a) {
  1332. bool dk = false;
  1333. int temp = 0;
  1334. system("cls");
  1335. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1336. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1337. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1338. for (int n = 0; n < cus_product.size(); n++) {
  1339. if (cus_product[n].username == a) {
  1340. temp = n; break;
  1341. }
  1342. }
  1343. do {
  1344. cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN XOA :" << endl;
  1345. string seri;
  1346. getline(cin, seri);
  1347. for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
  1348. if (seri == cus_product[temp].giohang[i].seri) {
  1349. cus_product[temp].giohang.erase(cus_product[temp].giohang.begin() + i);
  1350. cout << "\t\t\t\t\t\t\t\tDELETE COMPLETE";
  1351.  
  1352. savefile_buyproduct(cus_product);
  1353.  
  1354. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE! 2.GOBACK! 3.LOGOUT" << endl;
  1355. cout << "\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1, 2 OR 3)";
  1356. int n;
  1357. cin >> n; cin.ignore(1);
  1358. switch (n) {
  1359. case 1:dk = true; break;
  1360. case 2:return 1;
  1361. case 3:return 0;
  1362. default:
  1363. return 1;
  1364. }
  1365. break;
  1366. }
  1367. }
  1368. if (dk == false) {
  1369. cout << "\t\t\t\t\t\t\t\tSERI KHONG TON TAI " << endl;
  1370. cout << "\t\t\t\t\t\t\t\tLua chon: 1.GOBACK! 2.LOGOUT " << endl;
  1371. cout << "NHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1372. int n;
  1373. cin >> n;
  1374. cin.ignore(1);
  1375. switch (n) {
  1376. case 1:return 1;
  1377. case 2:return 0;
  1378. default:
  1379. return 1;
  1380. }
  1381. }
  1382. } while (dk = true);
  1383. }
  1384.  
  1385.  
  1386. bool xacnhan_mua(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1387. system("cls");
  1388. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1389. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1390. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1391. cout << "\n\t\t\t\t\t\t\t\t XAC NHAN MUA HANG";
  1392. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.XAC NHAN 2.GOBACK 3.LOGOUT" << endl;
  1393. cout << "\n\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1,2 OR 3) :";
  1394. int k;
  1395. cin >> k;
  1396. cin.ignore(1);
  1397. int temp = 0;
  1398. for (int n = 0; n < cus_product.size(); n++) {
  1399. if (cus_product[n].username == a) {
  1400. temp = n; break;
  1401. }
  1402. }
  1403. switch (k) {
  1404. case 1: {
  1405. int x = 0;
  1406. int p = cus_product[temp].cusProduct.size();
  1407. int q = cus_product[temp].giohang.size();
  1408. for (int i = p; i < p + q; i++) {
  1409.  
  1410.  
  1411. for (int j = 0; j < product.size(); j++) {
  1412. if (cus_product[temp].giohang[x].seri == product[j].seri) {
  1413. product[j].solg = product[j].solg - cus_product[temp].giohang[x].solg;
  1414. break;
  1415. }
  1416. }
  1417.  
  1418. cus_product[temp].cusProduct.push_back(Product());
  1419. cus_product[temp].cusProduct[i].name = cus_product[temp].giohang[x].name;
  1420. cus_product[temp].cusProduct[i].seri = cus_product[temp].giohang[x].seri;
  1421. cus_product[temp].cusProduct[i].price = cus_product[temp].giohang[x].price;
  1422. cus_product[temp].cusProduct[i].solg = cus_product[temp].giohang[x].solg;
  1423. cus_product[temp].cusProduct[i].nsx = cus_product[temp].giohang[x].nsx;
  1424. cus_product[temp].cusProduct[i].hsd = cus_product[temp].giohang[x].hsd;
  1425. x++;
  1426. }
  1427.  
  1428. cus_product[temp].giohang.erase(cus_product[temp].giohang.begin(), cus_product[temp].giohang.end());
  1429.  
  1430. savefile_buyproduct(cus_product);
  1431. savefile_product(product);
  1432.  
  1433. return 1;
  1434. }
  1435. case 2:return 1;
  1436. case 3:return 0;
  1437. default:
  1438. return 1;
  1439. }
  1440. }
  1441.  
  1442. bool history_buy(vector<Customer>&cus_product, string &a) {
  1443. system("cls");
  1444. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1445. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1446. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1447. int temp = 0;
  1448. for (int n = 0; n < cus_product.size(); n++) {
  1449. if (cus_product[n].username == a) {
  1450. temp = n; break;
  1451. }
  1452. }
  1453.  
  1454. cout <<setw(15) << "NAME" << setw(15) << "SERI" << setw(15) << "PRICE"
  1455. << setw(15) << "NSX" << setw(15) << "HSD" << setw(15) << "SOLG" << endl;
  1456. int pay = 0;
  1457. for (int i = 0; i < cus_product[temp].cusProduct.size(); i++) {
  1458. pay = pay + cus_product[temp].cusProduct[i].price*cus_product[temp].cusProduct[i].solg;
  1459. cout <<setw(15) << cus_product[temp].cusProduct[i].name << setw(15) << cus_product[temp].cusProduct[i].seri << setw(15)
  1460. << cus_product[temp].cusProduct[i].price << setw(15) << cus_product[temp].cusProduct[i].nsx
  1461. << setw(15) << cus_product[temp].cusProduct[i].hsd << setw(15) << cus_product[temp].cusProduct[i].solg << endl;
  1462. }
  1463. cout << "\t\t\t\t\t\t\t\tTONG LOAI HANG: " << cus_product[temp].cusProduct.size() << endl;
  1464. cout << "\t\t\t\t\t\t\t\tTHANH TIEN: " << pay;
  1465. cout << "\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  1466. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1467. int n;
  1468. cin >> n;
  1469. cin.ignore(1);
  1470. switch (n) {
  1471. case 1: return 1;
  1472. case 2: return 0;
  1473. default:
  1474. return 1;
  1475. }
  1476. }
  1477.  
  1478. bool readfile_product(vector<Product>&product) {
  1479. ifstream readfileproduct("saveproduct.txt");
  1480. string x, y, v, t;
  1481. int z, u;
  1482. product.clear();
  1483.  
  1484. int index;
  1485. if (!readfileproduct.is_open())
  1486. {
  1487. cout << "Khong the mo file.\n";
  1488. system("pause");
  1489. return 0;
  1490. }
  1491. else {
  1492. readfileproduct >> index;
  1493. for (int i = 0; i < index; i++)
  1494. {
  1495. readfileproduct >> x;
  1496. readfileproduct >> y;
  1497. readfileproduct >> z;
  1498. readfileproduct >> u;
  1499. readfileproduct >> v;
  1500. readfileproduct >> t;
  1501.  
  1502. for (int j = 0; j < y.length(); j++) {
  1503. if (y[j] == '_')y[j] = ' ';
  1504. }
  1505. product.push_back(Product());
  1506. product[i].seri = x;
  1507. product[i].name = y;
  1508. product[i].price = z;
  1509. product[i].solg = u;
  1510. product[i].nsx = v;
  1511. product[i].hsd = t;
  1512. }
  1513. }
  1514. readfileproduct.close();
  1515.  
  1516.  
  1517. }
  1518.  
  1519. void savefile_product(vector<Product>product) {
  1520. ofstream savefile("saveproduct.txt");
  1521. int index = product.size();
  1522. savefile << index << "\n";
  1523. for (int i = 0; i < index; i++) {
  1524. int z, u;
  1525. string x, y, v, t;
  1526. x = product[i].seri;
  1527. y = product[i].name;
  1528. z = product[i].price;
  1529. u = product[i].solg;
  1530. v = product[i].nsx;
  1531. t = product[i].hsd;
  1532.  
  1533.  
  1534. for (int j = 0; j < y.length(); j++) {
  1535. if (y[j] == ' ')y[j] = '_';
  1536. }
  1537. savefile << x << " ";
  1538. savefile << y << " ";
  1539. savefile << z << " ";
  1540. savefile << u << " ";
  1541. savefile << v << " ";
  1542. savefile << t << " ";
  1543. savefile << "\n";
  1544.  
  1545. }
  1546. savefile.close();
  1547. cout << "Success!" << endl;
  1548. }
  1549.  
  1550.  
  1551.  
  1552. void savefile_buyproduct(vector<Customer>&cus_product) {
  1553. ofstream savefile1("savebuyproduct.txt");
  1554. int temp = cus_product.size();
  1555.  
  1556. savefile1 << temp << "\n";
  1557. for (int n = 0; n < temp; n++) {
  1558. savefile1 << cus_product[n].username << "\n";
  1559. }
  1560.  
  1561. for (int m = 0; m < temp; m++) {
  1562. //luu gio hang
  1563. int n1 = cus_product[m].giohang.size();
  1564. savefile1 << n1 << "\n";
  1565. for (int i = 0; i < n1; i++) {
  1566.  
  1567. int z, u;
  1568. string x, y, v, t;
  1569. x = cus_product[m].giohang[i].seri;
  1570. y = cus_product[m].giohang[i].name;
  1571. z = cus_product[m].giohang[i].price;
  1572. u = cus_product[m].giohang[i].solg;
  1573. v = cus_product[m].giohang[i].nsx;
  1574. t = cus_product[m].giohang[i].hsd;
  1575.  
  1576.  
  1577. for (int j = 0; j < y.length(); j++) {
  1578. if (y[j] == ' ')y[j] = '_';
  1579. }
  1580. savefile1 << x << " ";
  1581. savefile1 << y << " ";
  1582. savefile1 << z << " ";
  1583. savefile1 << u << " ";
  1584. savefile1 << v << " ";
  1585. savefile1 << t << " ";
  1586.  
  1587. savefile1 << "\n";
  1588. }
  1589. ///luu lich su;
  1590. int n2 = cus_product[m].cusProduct.size();
  1591. savefile1 << n2 << "\n";
  1592.  
  1593. for (int j = 0; j < n2; j++) {
  1594.  
  1595. int z, u;
  1596. string x, y, v, t;
  1597. x = cus_product[m].cusProduct[j].seri;
  1598. y = cus_product[m].cusProduct[j].name;
  1599. z = cus_product[m].cusProduct[j].price;
  1600. u = cus_product[m].cusProduct[j].solg;
  1601. v = cus_product[m].cusProduct[j].nsx;
  1602. t = cus_product[m].cusProduct[j].hsd;
  1603.  
  1604.  
  1605. for (int j = 0; j < y.length(); j++) {
  1606. if (y[j] == ' ')y[j] = '_';
  1607. }
  1608. savefile1 << x << " ";
  1609. savefile1 << y << " ";
  1610. savefile1 << z << " ";
  1611. savefile1 << u << " ";
  1612. savefile1 << v << " ";
  1613. savefile1 << t << " ";
  1614.  
  1615. savefile1 << "\n";
  1616. }
  1617.  
  1618. }
  1619. savefile1.close();
  1620. cout << "Success!" << endl;
  1621.  
  1622. }
  1623. bool readfile_buyproduct(vector<Customer>&cus_product) {
  1624. ifstream readfile2("savebuyproduct.txt");
  1625. string x, y, v, t;
  1626. int z, u;
  1627. //cus_product.clear();
  1628.  
  1629.  
  1630. if (!readfile2.is_open())
  1631. {
  1632. cout << "Khong the mo file buy .\n";
  1633. system("pause");
  1634. return 0;
  1635. }
  1636. else {
  1637. int index1;
  1638. readfile2 >> index1;
  1639. string username;
  1640. for (int n = 0; n < index1; n++) {
  1641. readfile2 >> username;
  1642. cus_product.push_back(Customer());
  1643. cus_product[n].username = username;
  1644. }
  1645. for (int m = 0; m < index1; m++) {
  1646. int index2;
  1647. readfile2 >> index2;
  1648. for (int p = 0; p < index2; p++) {
  1649.  
  1650. int z, u;
  1651. string x, y, v, t;
  1652. readfile2 >> x;
  1653. readfile2 >> y;
  1654. readfile2 >> z;
  1655. readfile2 >> u;
  1656. readfile2 >> v;
  1657. readfile2 >> t;
  1658.  
  1659. for (int j = 0; j < y.length(); j++) {
  1660. if (y[j] == '_')y[j] = ' ';
  1661. }
  1662. cus_product[m].giohang.push_back(Product());
  1663. cus_product[m].giohang[p].seri = x;
  1664. cus_product[m].giohang[p].name = y;
  1665. cus_product[m].giohang[p].price = z;
  1666. cus_product[m].giohang[p].solg = u;
  1667. cus_product[m].giohang[p].nsx = v;
  1668. cus_product[m].giohang[p].hsd = t;
  1669.  
  1670. }
  1671.  
  1672. int index3;
  1673. readfile2 >> index3;
  1674.  
  1675. for (int q = 0; q < index3; q++) {
  1676.  
  1677. int z, u;
  1678. string x, y, v, t;
  1679. readfile2 >> x;
  1680. readfile2 >> y;
  1681. readfile2 >> z;
  1682. readfile2 >> u;
  1683. readfile2 >> v;
  1684. readfile2 >> t;
  1685.  
  1686. for (int j = 0; j < y.length(); j++) {
  1687. if (y[j] == '_')y[j] = ' ';
  1688. }
  1689. cus_product[m].cusProduct.push_back(Product());
  1690. cus_product[m].cusProduct[q].seri = x;
  1691. cus_product[m].cusProduct[q].name = y;
  1692. cus_product[m].cusProduct[q].price = z;
  1693. cus_product[m].cusProduct[q].solg = u;
  1694. cus_product[m].cusProduct[q].nsx = v;
  1695. cus_product[m].cusProduct[q].hsd = t;
  1696.  
  1697. }
  1698.  
  1699.  
  1700. }
  1701.  
  1702.  
  1703. }
  1704. readfile2.close();
  1705. return 1;
  1706. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement