Advertisement
gosuodin

ass

Jun 7th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.80 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\tNHAP 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 << setw(30) <<setfill(' ') <<"-----------------------------------------" << 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. role.push_back(Role());
  379.  
  380. role[n].user = "staff";
  381. role[n].namework = "nhanvienbanhang";
  382. break;
  383. }
  384. case 3: {
  385. int i = cus_product.size();
  386.  
  387. cus_product.push_back(Customer());
  388. cus_product[i].username = testuser;
  389.  
  390. acc_role.push_back(Account_to_role());
  391. acc_role[n].user = "khachhang";
  392. acc_role[n].chucnang = "customer";
  393.  
  394. role.push_back(Role());
  395.  
  396. role[n].user = "customer";
  397. role[n].namework = "khachhang";
  398. break;
  399. }
  400. default:
  401. break;
  402. }
  403.  
  404. int k;
  405. cout << "\t\t\t\t\t\t\t\tCAP THANH CONG! ";
  406. luufile(acc, acc_role, role);
  407. cout << "\n\t\t\t\t\t\t\t\t 1.GOBACK 2.LOGOUT " << endl;
  408. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  409. cin >> k;
  410. cin.ignore(1);
  411. switch (k) {
  412. case 1: return 1;
  413. case 2: return 0;
  414. }
  415.  
  416. }
  417. bool resetpassword(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  418. bool dk3;
  419. do {
  420. system("cls");
  421. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  422. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  423. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  424. cout << "\n\n\t\t\t\t\t\t\t\tNHAP ACCOUNT CAN RESET :";
  425. string nameacc;
  426. getline(cin, nameacc);
  427. for (int i = 0; i < acc.size(); i++) {
  428. if (nameacc == acc[i].user) {
  429. string x;
  430. cout << "\t\t\t\t\t\t\t\tNHAP NEW PASSWORD :";
  431. getline(cin, x);
  432. acc[i].password = x;
  433. cout << "\t\t\t\t\t\t\t\tSUCCESS!" << endl;
  434.  
  435.  
  436. luufile(acc, acc_role, role);
  437.  
  438.  
  439.  
  440. return 1;
  441. }
  442. }
  443. cout << "\t\t\t\t\t\t\t\t\tACCONUT KHONG TON TAI";
  444. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
  445. cout << "\n\t\t\t\t\t\t\t\ttMOI BAN NHAP SU LUA CHON(1,2 OR 3) :";
  446. int m;
  447. cin >> m;
  448. cin.ignore(1);
  449. switch (m) {
  450. case 1: dk3 = false; break;
  451. case 2: return 1;
  452. case 3: return 0;
  453. default: dk3 = false; break;
  454. }
  455.  
  456. } while (dk3 == false);
  457.  
  458. }
  459. 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) {
  460.  
  461. bool dk2;
  462. do {
  463. system("cls");
  464. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  465. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  466. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  467. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -1.CAP ACCOUNT" << setw(5) << right << "-" << endl;
  468. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -2.RESET PASSWORD" << setw(5) << right << "-" << endl;
  469. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -3.XEM THONG TIN ACCOUNT" << setw(5) << right << "-" << endl;
  470. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -4.DELETE ACCOUNT" << setw(5) << right << "-" << endl;
  471. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -5.INFORMATION LIST ACCOUNT" << setw(5) << right << "-" << endl;
  472. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -6.SEARCH INFORMATION ACCOUNT" << setw(5) << right << "-" << endl;
  473. cout << setw(35) << left << "\n\t\t\t\t\t\t\t\t -7.LOGOUT" << setw(5) << right << "-" << endl;
  474. cout << "\t\t\t\t\t\t\t\t----------------------------------------" << endl;
  475. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN :";
  476. int r;
  477. cin >> r;
  478. cin.ignore(1);
  479. switch (r) {
  480. case 1: {
  481. if (captk(acc, acc_role, role, cus_product, a, b) == false) return 0;
  482. else dk2 = true;
  483. break;
  484. }
  485. case 2: if (resetpassword(acc, acc_role, role) == true) { dk2 = true; break; }
  486. else return 0;
  487. case 3:if (information_acc_present(acc, acc_role, role, a) == true) { dk2 = true; break; }
  488. else return 0;
  489. case 4:if (delete_account(acc, acc_role, role, cus_product) == true) { dk2 = true; break; }
  490. else return 0;
  491. case 5:if (information_list_acc(acc, acc_role, role) == true) { dk2 = true; break; }
  492. else return 0;
  493. case 6:if (serch_account(acc, acc_role, role) == true) { dk2 = true; break; }
  494. else return 0;
  495. case 7: return 0;
  496. }
  497. } while (dk2 == true);
  498. return 1;
  499.  
  500. }
  501.  
  502. bool test_user(vector<Account> &acc, string testuser) {
  503.  
  504. for (int j = 0; j < acc.size(); j++) {
  505. if (testuser == acc[j].user) return 0;
  506. }
  507. return 1;
  508. }
  509. bool delete_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, vector<Customer>&cus_product) {
  510. bool dk2 = true;
  511. do {
  512. system("cls");
  513. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  514. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  515. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  516. cout << "\n\n\t\t\t\t\t\t\t\t NHAP ACCOUNT CAN DELETE :";
  517. string nameacc;
  518. getline(cin, nameacc);
  519.  
  520. if (test_user_to_delete(acc, acc_role, role, cus_product, nameacc) == true) {
  521. system("cls");
  522. cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
  523. luufile(acc, acc_role, role);
  524. int a;
  525. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  526. cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1,2 OR 3) :";
  527. cin >> a;
  528. cin.ignore(1);
  529. switch (a)
  530. {
  531. case 1: return 1;
  532. case 2: return 0;
  533. default:
  534. return 0;
  535. }
  536. }
  537. else {
  538. cout << "\t\t\t\t\t\t\t\tACCOUNT CAN DELETE KHONG TON TAI" << endl;
  539. int a;
  540. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.NHAP LAI 2.GOBACK 3.LOGOUT " << endl;
  541. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN( 1 ,2 OR 3) :";
  542. cin >> a;
  543. cin.ignore(1);
  544. switch (a)
  545. {
  546. case 1: dk2 = false; break;
  547. case 2: return 1;
  548. case 3: return 0;
  549. default:
  550. return 1;
  551. }
  552. }
  553. } while (dk2 == false);
  554.  
  555.  
  556. }
  557. bool test_user_to_delete(vector<Account> &acc, vector<Account_to_role> &acc_role,
  558. vector<Role> &role, vector<Customer>&cus_product, string testuser) {
  559. for (int i = 0; i < acc.size(); i++) {
  560. if (testuser == acc[i].user) {
  561. acc.erase(acc.begin() + i);
  562.  
  563. acc_role.erase(acc_role.begin() + i);
  564.  
  565. role.erase(role.begin() + i);
  566.  
  567. int n = cus_product.size();
  568. for (int j = 0; j < n; j++) {
  569. if (testuser == cus_product[j].username) {
  570. cus_product.erase(cus_product.begin() + j);
  571. break;
  572. }
  573. }
  574.  
  575. return 1;
  576. }
  577. }
  578.  
  579. return 0;
  580. }
  581. bool information_acc_present(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role, string a) {
  582. int i;
  583. for (i = 0; i < acc.size(); i++) {
  584. if (acc[i].user == a) break;
  585. }
  586. system("cls");
  587. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  588. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  589. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  590. cout << "\n\t\t\t\t\t\t\t\tNAME ACCOUNT :" << acc[i].user << endl;
  591. cout << "\t\t\t\t\t\t\t\tPASSWORD : " << acc[i].password << endl;
  592. cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT :" << role[i].user << endl;
  593. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  594. cout << "\n\t\t\t\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
  595. int n;
  596. cin >> n;
  597. cin.ignore(1);
  598. switch (n)
  599. {
  600. case 1: return 1;
  601. case 2: return 0;
  602. default:
  603. return 1;
  604. }
  605. return 1;
  606. }
  607. bool information_list_acc(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  608. system("cls");
  609. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  610. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  611. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  612. cout << "\n\n\t\t\t\t\t\t\t\t==========List_Account==========" << endl;
  613. cout <<"\t\t\t\t\t\t"<< setw(20) << "USER" << setw(20) << "PASSWORD" << setw(20) << "LOAI ACCOUNT" << endl;
  614. int x = acc.size();
  615. for (int i = 0; i < x; i++) {
  616. cout <<"\t\t\t\t\t\t" <<setw(20) << acc[i].user << setw(20) << acc[i].password << setw(20) << role[i].user << endl;
  617. }
  618. cout << "\n\t\t\t\t\tTONG SO ACCOUNT TRONG HET THONG :" << x << endl;
  619. cout << "\n\t\t\t\t\tLua chon: 1.QUAY LAI 2.LOGOUT " << endl;
  620. cout << "\n\t\t\t\t\tNHAP LUA CHON CUA BAN (1 OR 2) :";
  621. int n;
  622. cin >> n;
  623. cin.ignore(1);
  624. switch (n)
  625. {
  626. case 1: return 1;
  627. case 2: return 0;
  628. default:
  629. return 1;
  630. }
  631. return 1;
  632. }
  633. bool serch_account(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  634. system("cls");
  635. string a;
  636. int n = acc.size();
  637. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  638. cout << "\t\t\t\t\t\t\t\t| MENU FOR ADMIN |" << endl;
  639. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  640. cout << "\t\t\t\t\t\t\t\tNHAP VAO NAME ACCOUNT CAN TIM :";
  641. getline(cin, a);
  642. int i;
  643. for (i = 0; i < n; i++) {
  644. if (a == acc[i].user)break;
  645. }
  646. if (i < n) {
  647. system("cls");
  648. cout << "\t\t\t\t\t\t\t\tNAME ACCOUNT :" << acc[i].user << endl;
  649. cout << "\t\t\t\t\t\t\t\tPASSWORD :" << acc[i].password << endl;
  650. cout << "\t\t\t\t\t\t\t\tLOAI ACCOUNT :" << role[i].user << endl;
  651. }
  652. else cout <<"\t\t\t\t\t\t\t\t\ttKHONG TIM THAY" << endl;
  653. cout << "\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  654. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  655. int m;
  656. cin >> m;
  657. cin.ignore(1);
  658. switch (m)
  659. {
  660. case 1: return 1;
  661. case 2: return 0;
  662. default:
  663. return 1;
  664. }
  665. return 1;
  666. }
  667. void luufile(vector<Account> &acc, vector<Account_to_role> &acc_role, vector<Role> &role) {
  668. ofstream cap("luu.txt");
  669. int index = acc.size();
  670. cap << index << "\n";
  671. for (int i = 0; i < index; i++) {
  672. string x, y, z, u, v, t;
  673. x = acc[i].user;
  674. y = acc[i].password;
  675. z = acc_role[i].user;
  676. u = acc_role[i].chucnang;
  677. v = role[i].user;
  678. t = role[i].namework;
  679.  
  680. cap << x << "\n";
  681. cap << y << "\n";
  682. cap << z << "\n";
  683. cap << u << "\n";
  684. cap << v << "\n";
  685. cap << t << "\n";
  686.  
  687. }
  688. cap.close();
  689. cout << "SUCCESS!" << endl;
  690. }
  691.  
  692. ///////
  693.  
  694.  
  695. //of_storemanager
  696.  
  697. bool them_hanghoa(vector<Product>&product) {
  698. bool dk4;
  699. int price, solg;
  700. int dd1, mm1, yy1;
  701. string seri, name, nsx, hsd;
  702. system("cls");
  703. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  704. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  705. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  706. do {
  707.  
  708. cout << "\n\n\t\t\t\t\t\t\t\tNHAP VAO SERI :";
  709. getline(cin, seri);
  710. if (test_seri(seri, product) == false) {
  711.  
  712. cout << "\n\t\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
  713. cout << "\n\t\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
  714. int n;
  715. cin >> n;
  716. cin.ignore(1);
  717. switch (n)
  718. {
  719. case 1: dk4 = true; break;
  720. case 2: return 1;
  721. case 3:return 0;
  722. default:
  723. return 1;
  724. }
  725. }
  726. else {
  727. bool boolday;
  728. cout << "\t\t\t\t\t\t\t\tTEN HANG HOA :";
  729. getline(cin, name);
  730. do {
  731. do {
  732. boolday = true;
  733. cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT(dd mm yy) :";
  734. cin >> dd1 >> mm1 >> yy1;
  735. cin.ignore(1);
  736.  
  737. if (dd1 > 31 || dd1 < 1 || mm1>12 || mm1 < 1 || yy1 < 0) {
  738. cout << "\n\t\t\t\t\t\t\t\tNSX FAIL!";
  739. boolday = false;
  740. }
  741. else {
  742. ostringstream ddmmyy;
  743. ddmmyy << dd1 << "/" << mm1 << "/" << yy1;
  744.  
  745. nsx = ddmmyy.str();
  746.  
  747. }
  748. } while (boolday == false);
  749.  
  750.  
  751. /////////////////////////
  752. int dd2, mm2, yy2;
  753. do {
  754. boolday = true;
  755. cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG(dd mm yy) :";
  756. cin >> dd2 >> mm2 >> yy2;
  757. cin.ignore(1);
  758.  
  759. if (dd2 > 31 || dd2 < 1 || mm2>12 || mm2 < 1 || yy2 < 0) {
  760. cout << "\n\t\t\t\t\t\t\t\tHSD FAIL!";
  761. boolday = false;
  762. }
  763. else {
  764. ostringstream ddmmyy;
  765. ddmmyy << dd2 << "/" << mm2 << "/" << yy2;
  766.  
  767. hsd = ddmmyy.str();
  768.  
  769. }
  770. } while (boolday == false);
  771. if (test_time(dd1, dd2, mm1, mm2, yy1, yy2) == true)boolday = true;
  772. else boolday = false;
  773. } while (boolday == false);
  774.  
  775.  
  776. cout << "\t\t\t\t\t\t\t\tSO LUONG :";
  777. cin >> solg;
  778. cin.ignore(1);
  779. cout << "\t\t\t\t\t\t\t\tGIA BAN :";
  780. cin >> price;
  781. cin.ignore(1);
  782.  
  783. int i = product.size();
  784. product.push_back(Product());
  785. product[i].seri = seri;
  786. product[i].nsx = nsx;
  787. product[i].hsd = hsd;
  788. product[i].price = price;
  789. product[i].name = name;
  790. product[i].solg = solg;
  791.  
  792. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  793. savefile_product(product);
  794. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT" << endl;
  795. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  796. int n;
  797. cin >> n;
  798. cin.ignore(1);
  799. switch (n)
  800. {
  801. case 1: dk4 = true; break;
  802. case 2: return 1;
  803. case 3:return 0;
  804. default:
  805. return 1;
  806. }
  807.  
  808. }
  809. } while (dk4 == true);
  810.  
  811. }
  812. bool test_seri(string seri, vector<Product>product) {
  813. for (int i = 0; i < product.size(); i++) {
  814. if (seri == product[i].seri) {
  815. cout << "\t\t\t\t\t\t\t\tSERI SAN PHAM DA CO TRONG KHO " << endl;
  816. return 0;
  817. }
  818. }
  819. return 1;
  820. }
  821. bool forstaff(vector<Product> &product) {
  822. bool dk3 = true;
  823. do {
  824. system("cls");
  825. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  826. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  827. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  828. cout << "\n\t\t\t\t\t\t\t\t1.THEM HANG HOA " << endl;
  829. cout << "\n\t\t\t\t\t\t\t\t2.XOA HANG HOA " << endl;
  830. cout << "\n\t\t\t\t\t\t\t\t3.TIM KIEM HANG HOA" << endl;
  831. cout << "\n\t\t\t\t\t\t\t\t4.CHINH SUA HANG HOA " << endl;
  832. cout << "\n\t\t\t\t\t\t\t\t5.THONG KE" << endl;
  833. cout << "\n\t\t\t\t\t\t\t\t6.LOGOUT" << endl;
  834. cout << "\t\t\t\t\t\t\t\tMOI BAN NHAP LUA CHON :";
  835. int m;
  836. cin >> m;
  837. cin.ignore(1);
  838. switch (m) {
  839. case 1:if (them_hanghoa(product) == true)
  840. {
  841. dk3 = true; break;
  842. }
  843. else return 0;
  844. case 2:
  845. if (xoa_hanghoa(product) == true)
  846. {
  847. dk3 = true; break;
  848. }
  849. else return 0;
  850. case 3:
  851. if (find_hanghoa(product) == true)
  852. {
  853. dk3 = true; break;
  854. }
  855. else return 0;
  856. case 4:
  857. if (edit_hanghoa(product) == true)
  858. {
  859. dk3 = true; break;
  860. }
  861. else return 0;
  862. case 5:
  863. if (thongke_hanghoa(product) == true)
  864. {
  865. dk3 = true; break;
  866. }
  867. else return 0;
  868.  
  869. case 6:return 0;
  870. }
  871. } while (dk3 == true);
  872. return 0;
  873. }
  874. bool xoa_hanghoa(vector<Product>&product) {
  875. string seri;
  876. bool dk5;
  877. system("cls");
  878. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  879. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  880. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  881. do {
  882. cout << "\n\n\t\t\t\t\t\t\t\tNHAP SERI CAN XOA :";
  883. getline(cin, seri);
  884. for (int i = 0; i < product.size(); i++) {
  885. if (seri == product[i].seri) {
  886. product.erase(product.begin() + i);
  887. cout << "\t\t\t\t\t\t\t\tDELETE SUCCESS!";
  888. savefile_product(product);
  889. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  890. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 , 2 OR 3) :";
  891. int n;
  892. cin >> n;
  893. cin.ignore(1);
  894. switch (n)
  895. {
  896. case 1: dk5 = true; break;
  897. case 2: return 1;
  898. case 3:return 0;
  899. default:
  900. return 1;
  901. }
  902.  
  903. }
  904. }
  905. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  906.  
  907. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  908. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3) :";
  909. int n;
  910. cin >> n;
  911. cin.ignore(1);
  912. switch (n)
  913. {
  914. case 1: dk5 = true; break;
  915. case 2: return 1;
  916. case 3:return 0;
  917. default:
  918. return 1;
  919. }
  920. } while (dk5 == true);
  921. }
  922. bool find_hanghoa(vector<Product>&product) {
  923. bool dk6 = false;
  924. string seri;
  925. string name;
  926. system("cls");
  927. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  928. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  929. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  930. do {
  931. cout << "\t\t\t\t\t\t\t\tSERI :";
  932. getline(cin, seri);
  933. for (int i = 0; i < product.size(); i++) {
  934. if (seri == product[i].seri) {
  935. cout << "\n\t\t\t\t\t\t\t\tTHONG TIN SAN PHAM";
  936. cout << "\n\t\t\t\t\t\t\t\tSERI :" << product[i].seri << endl;
  937. cout << "\n\t\t\t\t\t\t\t\tNAME :" << product[i].name << endl;
  938. cout << "\n\t\t\t\t\t\t\t\tNGAY SAN XUAT :" << product[i].nsx << endl;
  939. cout << "\n\t\t\t\t\t\t\t\tHAN SU DUNG :" << product[i].hsd << endl;
  940. cout << "\n\t\t\t\t\t\t\t\tSO LUONG :" << product[i].solg << endl;
  941. cout << "\n\t\t\t\t\t\t\t\tPRICE :" << product[i].price << endl;
  942. cout << "\n\t\t\t\t\t\t\t\tSUCCESS ";
  943. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.Continue 2.GOBACK 3.LOGOUT " << endl;
  944. cout << "\n\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN (1 , 2 OR 3) :";
  945. int n;
  946. cin >> n;
  947. cin.ignore(1);
  948. switch (n)
  949. {
  950. case 1: dk6 = true; break;
  951. case 2: return 1;
  952. case 3:return 0;
  953. default:
  954. return 1;
  955. }
  956.  
  957. }
  958. if (dk6 == true)break;
  959. }
  960. if (dk6 == false) {
  961. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  962. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  963. cout << "\t\t\t\t\t\t\t\tSU LUA CHON CUA BAN (1,2 OR 3) :";
  964. int n;
  965. cin >> n;
  966. cin.ignore(1);
  967. switch (n)
  968. {
  969. case 1: dk6 = true; break;
  970. case 2: return 1;
  971. case 3:return 0;
  972. default:
  973. return 1;
  974. }
  975. }
  976. } while (dk6 == true);
  977.  
  978. }
  979. bool edit_hanghoa(vector<Product>&product) {
  980. bool dk = false;
  981. int price, solg;
  982. int n;
  983. string seri, name, nsx, hsd;
  984. system("cls");
  985. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  986. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  987. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  988. do {
  989. cout << "\t\t\t\t\t\t\t\tSERI :";
  990. getline(cin, seri);
  991. for (int i = 0; i < product.size(); i++) {
  992. if (seri == product[i].seri) {
  993.  
  994. cout << "\t\t\t\t\t\t\t\tSUA CAI GI: 1.SERI 2.NAME 3.NSX 4.HSX 5.SOLG 6.PRICE :" << endl;
  995. cin >> n;
  996. cin.ignore(1);
  997. product.push_back(Product());
  998. switch (n) {
  999. case 1: {
  1000. cout << "\t\t\t\t\t\t\t\tNEW SERI :";
  1001. product[i].seri = seri;
  1002. break;
  1003. }
  1004. case 2: {
  1005. cout << "\t\t\t\t\t\t\t\tNEW NAME :";
  1006. getline(cin, name);
  1007. product[i].name = name;
  1008. break;
  1009. }
  1010. case 3: {
  1011. cout << "\t\t\t\t\t\t\t\tNEW NSX :";
  1012. getline(cin, nsx);
  1013. product[i].nsx = nsx;
  1014. break;
  1015. }
  1016. case 4: {
  1017. cout << "\t\t\t\t\t\t\t\tNEW HSD :";
  1018. getline(cin, hsd);
  1019. product[i].nsx = hsd;
  1020. break;
  1021. }
  1022. case 5: {
  1023. cout << "NEW SO LUONG :";
  1024. cin >> solg;
  1025. cin.ignore(1);
  1026. product[i].solg = solg;
  1027. break;
  1028. }
  1029. case 6: {
  1030. cout << "\t\t\t\t\t\t\t\tNEW PRICE :";
  1031. cin >> price;
  1032. cin.ignore(1);
  1033. product[i].price = price;
  1034. break;
  1035. }
  1036. }
  1037. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  1038. savefile_product(product);
  1039. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  1040. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  1041. cin >> n;
  1042. cin.ignore(1);
  1043. switch (n)
  1044. {
  1045. case 1: dk = true; break;
  1046. case 2: return 1;
  1047. case 3:return 0;
  1048. default:
  1049. return 1;
  1050. }
  1051.  
  1052. }
  1053. if (dk == true)break;
  1054.  
  1055. }
  1056. if (dk == false) {
  1057. cout << "\t\t\t\t\t\t\t\tSERI FAIL";
  1058. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT " << endl;
  1059. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1,2 OR 3) :";
  1060. int n;
  1061. cin >> n;
  1062. cin.ignore(1);
  1063. switch (n)
  1064. {
  1065. case 1: {dk = true; break; }
  1066. case 2:return 1;
  1067. case 3:return 0;
  1068. default:
  1069. return 1;
  1070. }
  1071. }
  1072.  
  1073. } while (dk == true);
  1074. }
  1075. bool thongke_hanghoa(vector<Product>&product) {
  1076. int pay = 0;
  1077. system("cls");
  1078. cout << "\n\n\n\n\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  1079. cout << "\t\t\t\t\t\t\t\t| MENU FOR STOREMANAGER |" << endl;
  1080. cout << "\t\t\t\t\t\t\t\t-----------------------------------------" << endl;
  1081. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
  1082. for (int i = 0; i < product.size(); i++) {
  1083. pay = pay + product[i].price*product[i].solg;
  1084. 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;
  1085. }
  1086. cout << "\n\t\tTONG SO LUONG :" << product.size();
  1087. cout << "\n\t\t SO TIEN KHI BAN MUA :" << pay << endl;
  1088. cout << "\n\t\tLua chon: 1.GOBACK 2.LOGOUT" << endl;
  1089. cout << "\n\t\ttNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1090. int n;
  1091. cin >> n;
  1092. cin.ignore(1);
  1093. switch (n)
  1094. {
  1095. case 1:return 1;
  1096. case 2:return 0;
  1097. default:
  1098. return 1;
  1099. }
  1100. }
  1101.  
  1102.  
  1103. //// customer
  1104.  
  1105. bool for_customer(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1106. bool dk3 = true;
  1107. do {
  1108. system("cls");
  1109. int temp = cus_product.size();
  1110. cout << temp << endl;
  1111. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1112. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1113. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1114. cout << "\n\t\t\t\t\t\t\t\t1.TIM KIEM HANG HOA" << endl;
  1115. cout << "\n\t\t\t\t\t\t\t\t2.XEM GIO HANG" << endl;
  1116. cout << "\n\t\t\t\t\t\t\t\t3.LICH SU MUA" << endl;
  1117. cout << "\n\t\t\t\t\t\t\t\t4.TIM KIEM DANH SACH SAN PHAM" << endl;
  1118. cout << "\n\t\t\t\t\t\t\t\t5.LOGOUT" << endl;
  1119. int m;
  1120. cout << "\t\t\t\t\t\t\t\tMOI NHAP LUA CHON :";
  1121. cin >> m;
  1122. cin.ignore(1);
  1123. switch (m) {
  1124. case 1:if (find_to_buy(cus_product, product, a) == true)
  1125. {
  1126. dk3 = true; break;
  1127. }
  1128. else return 0;
  1129. case 2:
  1130. if (xem_giohang(cus_product, product, acc, role, a) == true)
  1131. {
  1132. dk3 = true; break;
  1133. }
  1134. else return 0;
  1135.  
  1136. case 3:
  1137. if (history_buy(cus_product, a) == true)
  1138. {
  1139. dk3 = true; break;
  1140. }
  1141. else return 0;
  1142. case 4:
  1143. if (thongke_hanghoa(product) == true)
  1144. {
  1145. dk3 = true; break;
  1146. }
  1147. else return 0;
  1148.  
  1149. case 5:return 0;
  1150. }
  1151. } while (dk3 == true);
  1152. return 0;
  1153. }
  1154.  
  1155.  
  1156. bool find_to_buy(vector<Customer>&cus_product, vector<Product>&product, string &a) {
  1157. bool dk;
  1158. string name, seri;
  1159. system("cls");
  1160. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1161. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1162. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1163. do {
  1164. int dem = 0;
  1165. cout << "\t\t\t\t\t\t\t\tSEARCH NAME :";
  1166. getline(cin, name);
  1167. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE" << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SoLg" << endl;
  1168. for (int i = 0; i < product.size(); i++) {
  1169. if (name == product[i].name) {
  1170. 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;
  1171. dem++;
  1172. }
  1173. }
  1174. if (dem > 0) {
  1175. cout << "\t\t\t\t\t\t\t\tHIEN CO :" << dem << "\t\t\t\t\t\t\t\t LOAI SAN PHAM" << endl;
  1176.  
  1177.  
  1178. int m;
  1179. cout << "\t\t\t\t\t\t\t\tLua chon: 1.MUA HANG VOI SERI 2.GOBACK 3.LOGOUT " << endl;
  1180. cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
  1181. cin >> m;
  1182. cin.ignore(1);
  1183. switch (m) {
  1184. case 1: {
  1185.  
  1186. cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN MUA :";
  1187. getline(cin, seri);
  1188.  
  1189.  
  1190. add_giohang(seri, cus_product, product, a);
  1191. cout << "\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang)! " << endl;
  1192. cout << "\t\t\t\t\t\t\t\t SU LUA CHON CUA BAN (1,2 OR 3) :";
  1193. int n;
  1194. cin >> n;
  1195. cin.ignore(1);
  1196. switch (n)
  1197. {
  1198. case 1:dk = true; break;
  1199. case 2:return 1;
  1200. case 3:return 0;
  1201. default:
  1202. return 1;
  1203. }
  1204. break;
  1205. }
  1206. case 2:return 1;
  1207. case 3:return 0;
  1208. default:return 1;
  1209. }
  1210. }
  1211. else {
  1212. cout << "\t\t\t\t\t\t\t\t KHONG TIM THAY" << endl;
  1213. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE 2.GOBACK 3.LOGOUT(Chua Xac Nhan Mua Hang) " << endl;
  1214. cout << "\n\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 ,2 OR 3 ) :";
  1215. int n;
  1216. cin >> n;
  1217. cin.ignore(1);
  1218. switch (n)
  1219. {
  1220. case 1:dk = true; break;
  1221. case 2:return 1;
  1222. case 3:return 0;
  1223. default:
  1224. return 1;
  1225. }
  1226.  
  1227. }
  1228.  
  1229. } while (dk == true);
  1230. }
  1231.  
  1232.  
  1233. void add_giohang(string seri, vector<Customer>&cus_product, vector<Product> &product, string &a) {
  1234. int temp = 0;
  1235. system("cls");
  1236. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1237. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1238. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1239. for (int n = 0; n < cus_product.size(); n++) {
  1240. if (cus_product[n].username == a) {
  1241. temp = n; break;
  1242. }
  1243. }
  1244.  
  1245. int j = cus_product[temp].giohang.size();
  1246. int k;
  1247. k = j;
  1248. for (int i = 0; i < product.size(); i++) {
  1249. if (seri == product[i].seri) {
  1250. cout << "\t\t\t\t\t\t\t\tSO LUONG :";
  1251. int solg;
  1252. cin >> solg;
  1253. cin.ignore(1);
  1254. if (solg <= product[i].solg) {
  1255. cus_product[temp].giohang.push_back(Product());
  1256. cus_product[temp].giohang[j].name = product[i].name;
  1257. cus_product[temp].giohang[j].seri = product[i].seri;
  1258. cus_product[temp].giohang[j].price = product[i].price;
  1259. cus_product[temp].giohang[j].nsx = product[i].nsx;
  1260. cus_product[temp].giohang[j].hsd = product[i].hsd;
  1261. cus_product[temp].giohang[j].solg = solg;
  1262.  
  1263. j = j + 1;
  1264. break;
  1265. }
  1266. else "\t\t\t\t\t\t\t\tSO LUONG KHONG CHO PHEP"; break;
  1267. }
  1268. }
  1269.  
  1270. if (j > k) {
  1271. cout << "\t\t\t\t\t\t\t\tSUCCESS!";
  1272. savefile_buyproduct(cus_product);
  1273. }
  1274.  
  1275. else cout << "\t\t\t\t\t\t\t\tFAIL!";
  1276. }
  1277.  
  1278.  
  1279. bool xem_giohang(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1280. bool dk = true;
  1281. int temp = 0;
  1282. system("cls");
  1283. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1284. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1285. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1286. for (int n = 0; n < cus_product.size(); n++) {
  1287. if (cus_product[n].username == a) {
  1288. temp = n; break;
  1289. }
  1290. }
  1291.  
  1292. do {
  1293. cout << setw(20) << "NAME" << setw(20) << "SERI" << setw(20) << "PRICE"
  1294. << setw(20) << "NSX" << setw(20) << "HSD" << setw(20) << "SOLG" << endl;
  1295. int pay = 0;
  1296. for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
  1297. pay = pay + cus_product[temp].giohang[i].price*cus_product[temp].giohang[i].solg;
  1298. cout << setw(20) << cus_product[temp].giohang[i].name << setw(20) << cus_product[temp].giohang[i].seri << setw(20)
  1299. << cus_product[temp].giohang[i].price << setw(20) << cus_product[temp].giohang[i].nsx
  1300. << setw(20) << cus_product[temp].giohang[i].hsd << setw(20) << cus_product[temp].giohang[i].solg << endl;
  1301. }
  1302. cout << "\n\t\t\t\t\t\t\t\tTONG LOAI HANG :" << cus_product[temp].giohang.size() << endl;
  1303. cout << "\n\t\t\t\t\t\t\t\tTHANH TIEN :" << pay;
  1304. 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;
  1305. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN(1,2,3 OR 4) :";
  1306. int n;
  1307. cin >> n;
  1308. cin.ignore(1);
  1309. switch (n)
  1310. {
  1311. case 1:
  1312. if (edit_giohang(cus_product, a) == true) {
  1313. dk = true; break;
  1314. }
  1315. else return 0;
  1316. case 2:
  1317. if (xacnhan_mua(cus_product, product, acc, role, a) == true) {
  1318. dk = true; break;
  1319. }
  1320. else return 0;
  1321. case 3:return 1;
  1322. case 4:return 0;
  1323. default:
  1324. return 1;
  1325. }
  1326. } while (dk = true);
  1327. return 1;
  1328. }
  1329.  
  1330. bool edit_giohang(vector<Customer>&cus_product, string&a) {
  1331. bool dk = false;
  1332. int temp = 0;
  1333. system("cls");
  1334. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1335. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1336. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1337. for (int n = 0; n < cus_product.size(); n++) {
  1338. if (cus_product[n].username == a) {
  1339. temp = n; break;
  1340. }
  1341. }
  1342. do {
  1343. cout << "\t\t\t\t\t\t\t\tNHAP SERI CAN XOA :" << endl;
  1344. string seri;
  1345. getline(cin, seri);
  1346. for (int i = 0; i < cus_product[temp].giohang.size(); i++) {
  1347. if (seri == cus_product[temp].giohang[i].seri) {
  1348. cus_product[temp].giohang.erase(cus_product[temp].giohang.begin() + i);
  1349. cout << "\t\t\t\t\t\t\t\tDELETE COMPLETE";
  1350.  
  1351. savefile_buyproduct(cus_product);
  1352.  
  1353. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.CONTINUE! 2.GOBACK! 3.LOGOUT" << endl;
  1354. cout << "\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1, 2 OR 3) :";
  1355. int n;
  1356. cin >> n; cin.ignore(1);
  1357. switch (n) {
  1358. case 1:dk = true; break;
  1359. case 2:return 1;
  1360. case 3:return 0;
  1361. default:
  1362. return 1;
  1363. }
  1364. break;
  1365. }
  1366. }
  1367. if (dk == false) {
  1368. cout << "\t\t\t\t\t\t\t\tSERI KHONG TON TAI " << endl;
  1369. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK! 2.LOGOUT " << endl;
  1370. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1371. int n;
  1372. cin >> n;
  1373. cin.ignore(1);
  1374. switch (n) {
  1375. case 1:return 1;
  1376. case 2:return 0;
  1377. default:
  1378. return 1;
  1379. }
  1380. }
  1381. } while (dk = true);
  1382. }
  1383.  
  1384.  
  1385. bool xacnhan_mua(vector<Customer>&cus_product, vector<Product>&product, vector<Account>&acc, vector<Role>&role, string&a) {
  1386. system("cls");
  1387. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1388. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1389. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1390. cout << "\n\t\t\t\t\t\t\t\t XAC NHAN MUA HANG";
  1391. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.XAC NHAN 2.GOBACK 3.LOGOUT" << endl;
  1392. cout << "\t\t\t\t\t\t\t\tNHAP SUA LUA CHON CUA BAN(1,2 OR 3) :";
  1393. int k;
  1394. cin >> k;
  1395. cin.ignore(1);
  1396. int temp = 0;
  1397. for (int n = 0; n < cus_product.size(); n++) {
  1398. if (cus_product[n].username == a) {
  1399. temp = n; break;
  1400. }
  1401. }
  1402. switch (k) {
  1403. case 1: {
  1404. int x = 0;
  1405. int p = cus_product[temp].cusProduct.size();
  1406. int q = cus_product[temp].giohang.size();
  1407. for (int i = p; i < p + q; i++) {
  1408.  
  1409.  
  1410. for (int j = 0; j < product.size(); j++) {
  1411. if (cus_product[temp].giohang[x].seri == product[j].seri) {
  1412. product[j].solg = product[j].solg - cus_product[temp].giohang[x].solg;
  1413. break;
  1414. }
  1415. }
  1416.  
  1417. cus_product[temp].cusProduct.push_back(Product());
  1418. cus_product[temp].cusProduct[i].name = cus_product[temp].giohang[x].name;
  1419. cus_product[temp].cusProduct[i].seri = cus_product[temp].giohang[x].seri;
  1420. cus_product[temp].cusProduct[i].price = cus_product[temp].giohang[x].price;
  1421. cus_product[temp].cusProduct[i].solg = cus_product[temp].giohang[x].solg;
  1422. cus_product[temp].cusProduct[i].nsx = cus_product[temp].giohang[x].nsx;
  1423. cus_product[temp].cusProduct[i].hsd = cus_product[temp].giohang[x].hsd;
  1424. x++;
  1425. }
  1426.  
  1427. cus_product[temp].giohang.erase(cus_product[temp].giohang.begin(), cus_product[temp].giohang.end());
  1428.  
  1429. savefile_buyproduct(cus_product);
  1430. savefile_product(product);
  1431.  
  1432. return 1;
  1433. }
  1434. case 2:return 1;
  1435. case 3:return 0;
  1436. default:
  1437. return 1;
  1438. }
  1439. }
  1440.  
  1441. bool history_buy(vector<Customer>&cus_product, string &a) {
  1442. system("cls");
  1443. cout << "\n\n\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1444. cout << "\t\t\t\t\t\t\t\t| MENU OF CUSTOMER |" << endl;
  1445. cout << "\t\t\t\t\t\t\t\t------------------------------------------------------" << endl;
  1446. int temp = 0;
  1447. for (int n = 0; n < cus_product.size(); n++) {
  1448. if (cus_product[n].username == a) {
  1449. temp = n; break;
  1450. }
  1451. }
  1452.  
  1453. cout <<setw(15) << "NAME" << setw(15) << "SERI" << setw(15) << "PRICE"
  1454. << setw(15) << "NSX" << setw(15) << "HSD" << setw(15) << "SOLG" << endl;
  1455. int pay = 0;
  1456. for (int i = 0; i < cus_product[temp].cusProduct.size(); i++) {
  1457. pay = pay + cus_product[temp].cusProduct[i].price*cus_product[temp].cusProduct[i].solg;
  1458. cout <<setw(15) << cus_product[temp].cusProduct[i].name << setw(15) << cus_product[temp].cusProduct[i].seri << setw(15)
  1459. << cus_product[temp].cusProduct[i].price << setw(15) << cus_product[temp].cusProduct[i].nsx
  1460. << setw(15) << cus_product[temp].cusProduct[i].hsd << setw(15) << cus_product[temp].cusProduct[i].solg << endl;
  1461. }
  1462. cout << "\t\t\t\t\t\t\t\tTONG LOAI HANG :" << cus_product[temp].cusProduct.size() << endl;
  1463. cout << "\t\t\t\t\t\t\t\tTHANH TIEN :" << pay;
  1464. cout << "\n\t\t\t\t\t\t\t\tLua chon: 1.GOBACK 2.LOGOUT " << endl;
  1465. cout << "\t\t\t\t\t\t\t\tNHAP SU LUA CHON CUA BAN (1 OR 2) :";
  1466. int n;
  1467. cin >> n;
  1468. cin.ignore(1);
  1469. switch (n) {
  1470. case 1: return 1;
  1471. case 2: return 0;
  1472. default:
  1473. return 1;
  1474. }
  1475. }
  1476.  
  1477. bool readfile_product(vector<Product>&product) {
  1478. ifstream readfileproduct("saveproduct.txt");
  1479. string x, y, v, t;
  1480. int z, u;
  1481. product.clear();
  1482.  
  1483. int index;
  1484. if (!readfileproduct.is_open())
  1485. {
  1486. cout << "Khong the mo file.\n";
  1487. system("pause");
  1488. return 0;
  1489. }
  1490. else {
  1491. readfileproduct >> index;
  1492. for (int i = 0; i < index; i++)
  1493. {
  1494. readfileproduct >> x;
  1495. readfileproduct >> y;
  1496. readfileproduct >> z;
  1497. readfileproduct >> u;
  1498. readfileproduct >> v;
  1499. readfileproduct >> t;
  1500.  
  1501. for (int j = 0; j < y.length(); j++) {
  1502. if (y[j] == '_')y[j] = ' ';
  1503. }
  1504. product.push_back(Product());
  1505. product[i].seri = x;
  1506. product[i].name = y;
  1507. product[i].price = z;
  1508. product[i].solg = u;
  1509. product[i].nsx = v;
  1510. product[i].hsd = t;
  1511. }
  1512. }
  1513. readfileproduct.close();
  1514.  
  1515.  
  1516. }
  1517.  
  1518. void savefile_product(vector<Product>product) {
  1519. ofstream savefile("saveproduct.txt");
  1520. int index = product.size();
  1521. savefile << index << "\n";
  1522. for (int i = 0; i < index; i++) {
  1523. int z, u;
  1524. string x, y, v, t;
  1525. x = product[i].seri;
  1526. y = product[i].name;
  1527. z = product[i].price;
  1528. u = product[i].solg;
  1529. v = product[i].nsx;
  1530. t = product[i].hsd;
  1531.  
  1532.  
  1533. for (int j = 0; j < y.length(); j++) {
  1534. if (y[j] == ' ')y[j] = '_';
  1535. }
  1536. savefile << x << " ";
  1537. savefile << y << " ";
  1538. savefile << z << " ";
  1539. savefile << u << " ";
  1540. savefile << v << " ";
  1541. savefile << t << " ";
  1542. savefile << "\n";
  1543.  
  1544. }
  1545. savefile.close();
  1546. cout << "Success!" << endl;
  1547. }
  1548.  
  1549.  
  1550.  
  1551. void savefile_buyproduct(vector<Customer>&cus_product) {
  1552. ofstream savefile1("savebuyproduct.txt");
  1553. int temp = cus_product.size();
  1554.  
  1555. savefile1 << temp << "\n";
  1556. for (int n = 0; n < temp; n++) {
  1557. savefile1 << cus_product[n].username << "\n";
  1558. }
  1559.  
  1560. for (int m = 0; m < temp; m++) {
  1561. //luu gio hang
  1562. int n1 = cus_product[m].giohang.size();
  1563. savefile1 << n1 << "\n";
  1564. for (int i = 0; i < n1; i++) {
  1565.  
  1566. int z, u;
  1567. string x, y, v, t;
  1568. x = cus_product[m].giohang[i].seri;
  1569. y = cus_product[m].giohang[i].name;
  1570. z = cus_product[m].giohang[i].price;
  1571. u = cus_product[m].giohang[i].solg;
  1572. v = cus_product[m].giohang[i].nsx;
  1573. t = cus_product[m].giohang[i].hsd;
  1574.  
  1575.  
  1576. for (int j = 0; j < y.length(); j++) {
  1577. if (y[j] == ' ')y[j] = '_';
  1578. }
  1579. savefile1 << x << " ";
  1580. savefile1 << y << " ";
  1581. savefile1 << z << " ";
  1582. savefile1 << u << " ";
  1583. savefile1 << v << " ";
  1584. savefile1 << t << " ";
  1585.  
  1586. savefile1 << "\n";
  1587. }
  1588. ///luu lich su;
  1589. int n2 = cus_product[m].cusProduct.size();
  1590. savefile1 << n2 << "\n";
  1591.  
  1592. for (int j = 0; j < n2; j++) {
  1593.  
  1594. int z, u;
  1595. string x, y, v, t;
  1596. x = cus_product[m].cusProduct[j].seri;
  1597. y = cus_product[m].cusProduct[j].name;
  1598. z = cus_product[m].cusProduct[j].price;
  1599. u = cus_product[m].cusProduct[j].solg;
  1600. v = cus_product[m].cusProduct[j].nsx;
  1601. t = cus_product[m].cusProduct[j].hsd;
  1602.  
  1603.  
  1604. for (int j = 0; j < y.length(); j++) {
  1605. if (y[j] == ' ')y[j] = '_';
  1606. }
  1607. savefile1 << x << " ";
  1608. savefile1 << y << " ";
  1609. savefile1 << z << " ";
  1610. savefile1 << u << " ";
  1611. savefile1 << v << " ";
  1612. savefile1 << t << " ";
  1613.  
  1614. savefile1 << "\n";
  1615. }
  1616.  
  1617. }
  1618. savefile1.close();
  1619. cout << "Success!" << endl;
  1620.  
  1621. }
  1622. bool readfile_buyproduct(vector<Customer>&cus_product) {
  1623. ifstream readfile2("savebuyproduct.txt");
  1624. string x, y, v, t;
  1625. int z, u;
  1626. //cus_product.clear();
  1627.  
  1628.  
  1629. if (!readfile2.is_open())
  1630. {
  1631. cout << "Khong the mo file buy .\n";
  1632. system("pause");
  1633. return 0;
  1634. }
  1635. else {
  1636. int index1;
  1637. readfile2 >> index1;
  1638. string username;
  1639. for (int n = 0; n < index1; n++) {
  1640. readfile2 >> username;
  1641. cus_product.push_back(Customer());
  1642. cus_product[n].username = username;
  1643. }
  1644. for (int m = 0; m < index1; m++) {
  1645. int index2;
  1646. readfile2 >> index2;
  1647. for (int p = 0; p < index2; p++) {
  1648.  
  1649. int z, u;
  1650. string x, y, v, t;
  1651. readfile2 >> x;
  1652. readfile2 >> y;
  1653. readfile2 >> z;
  1654. readfile2 >> u;
  1655. readfile2 >> v;
  1656. readfile2 >> t;
  1657.  
  1658. for (int j = 0; j < y.length(); j++) {
  1659. if (y[j] == '_')y[j] = ' ';
  1660. }
  1661. cus_product[m].giohang.push_back(Product());
  1662. cus_product[m].giohang[p].seri = x;
  1663. cus_product[m].giohang[p].name = y;
  1664. cus_product[m].giohang[p].price = z;
  1665. cus_product[m].giohang[p].solg = u;
  1666. cus_product[m].giohang[p].nsx = v;
  1667. cus_product[m].giohang[p].hsd = t;
  1668.  
  1669. }
  1670.  
  1671. int index3;
  1672. readfile2 >> index3;
  1673.  
  1674. for (int q = 0; q < index3; q++) {
  1675.  
  1676. int z, u;
  1677. string x, y, v, t;
  1678. readfile2 >> x;
  1679. readfile2 >> y;
  1680. readfile2 >> z;
  1681. readfile2 >> u;
  1682. readfile2 >> v;
  1683. readfile2 >> t;
  1684.  
  1685. for (int j = 0; j < y.length(); j++) {
  1686. if (y[j] == '_')y[j] = ' ';
  1687. }
  1688. cus_product[m].cusProduct.push_back(Product());
  1689. cus_product[m].cusProduct[q].seri = x;
  1690. cus_product[m].cusProduct[q].name = y;
  1691. cus_product[m].cusProduct[q].price = z;
  1692. cus_product[m].cusProduct[q].solg = u;
  1693. cus_product[m].cusProduct[q].nsx = v;
  1694. cus_product[m].cusProduct[q].hsd = t;
  1695.  
  1696. }
  1697.  
  1698.  
  1699. }
  1700.  
  1701.  
  1702. }
  1703. readfile2.close();
  1704. return 1;
  1705. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement