Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.31 KB | None | 0 0
  1. #include "Menus.h"
  2.  
  3.  
  4. void clientMenu(Company & comp, vector<Client>::iterator it) {
  5.  
  6. clearScreen();
  7.  
  8. string option_str;
  9. int option_int;
  10.  
  11. // dados para efetuar reserva
  12. string location;
  13. string date;
  14. Date initial_date;
  15. Date final_date;
  16. Accomodation* acc;
  17. Reservation res;
  18. int id, pos;
  19. vector<Reservation> reservations_tmp;
  20.  
  21.  
  22. cout << TAB_BIG << "|| " << it->getUsername() << " ||" << endl << endl;
  23. cout << TAB << "1 - Efetuar Reserva" << endl;
  24. cout << TAB << "2 - Ver Reservas" << endl;
  25. cout << TAB << "3 - Cancelar Reservas" << endl;
  26. cout << TAB << "4 - Informações de Conta" << endl;
  27. cout << TAB << "5 - Sair" << endl;
  28.  
  29. cout << endl << TAB << "Opção: ";
  30.  
  31. getline(cin, option_str);
  32.  
  33. option_int = stoi(option_str);
  34.  
  35. if (option_int < 1 || option_int >5) throw WrongOption(1, 5);
  36.  
  37. switch (option_int) {
  38. case 1:
  39. clearScreen();
  40.  
  41. cout << TAB_BIG << "|| Eftuar Reserva ||" << endl << endl;
  42.  
  43. cout << TAB << "Local: ";
  44. getline(cin, location);
  45. if (cin.eof()) throw InvalidInput();
  46.  
  47. cout << TAB << "Data Inicial: ";
  48. getline(cin, date);
  49. if (!initial_date.getDate(date)) throw InvalidDate();
  50.  
  51. cout << TAB << "Data Final: ";
  52. getline(cin, date);
  53. if (!final_date.getDate(date)) throw InvalidDate();
  54.  
  55. acc = comp.displayOffers(location, initial_date, final_date);
  56. if (acc == NULL) break;
  57.  
  58.  
  59. res.setAccomodation(acc);
  60. res.setCheckIN(initial_date);
  61. res.setCheckOUT(final_date);
  62. res.setID();
  63.  
  64. it->addReservation(res);
  65.  
  66. clearScreen();
  67.  
  68. cout << TAB_BIG << "|| Reserva ||" << endl << endl;
  69. cout << res;
  70. //cout da reserva
  71.  
  72. cout << endl << TAB << "A sua reserva foi criada com sucesso." << endl;
  73. cout << TAB << "Prima qualquer tecla para voltar ao Menu Cliente." << endl << endl;
  74.  
  75. pauseScreen();
  76.  
  77. clientMenu(comp, it);
  78. break;
  79. case 2:
  80. it->showReservations();
  81. break;
  82.  
  83. case 3:
  84. it->showReservations();
  85. id = comp.cancelReservation();
  86. if (id == 0) break;
  87.  
  88. reservations_tmp = it->getReservations();
  89. res.setID(id);
  90. pos = sequentialSearch<Reservation>(reservations_tmp, res);
  91.  
  92. it->deleteReservation(pos);
  93.  
  94. break;
  95. case 4:
  96. clearScreen();
  97. cout << TAB_BIG << "|| Informações de Conta ||" << endl << endl;
  98. cout << TAB << "Nome: " << it->getName() << endl;
  99. cout << TAB << "Nome de Utilizador: " << it->getUsername() << endl;
  100. cout << TAB << "Pontos: " << it->getPoints() << endl << endl;
  101.  
  102. break;
  103. case 5:
  104. //exit(1);
  105. start(comp);
  106. break;
  107. }
  108.  
  109. cout << TAB << "Prima qualquer tecla para voltar ao Menu Cliente." << endl << endl;
  110.  
  111. pauseScreen();
  112.  
  113. clientMenu(comp, it);
  114.  
  115.  
  116. }
  117.  
  118. void logIn(Company &comp, char user) {
  119. clearScreen();
  120.  
  121. string username;
  122. string password;
  123. vector<Suplier>::iterator its;
  124. vector<Client>::iterator itc;
  125.  
  126. cout << TAB_BIG << "|| Entrar ||" << endl << endl;
  127.  
  128. cout << TAB << "Username: ";
  129.  
  130. getline(cin, username);
  131. if (cin.eof()) throw InvalidInput();
  132.  
  133.  
  134. cout << TAB << "Password: ";
  135.  
  136. getline(cin, password);
  137. if (cin.eof()) throw InvalidInput();
  138.  
  139. if (user == 's') {
  140. its = comp.verifyLogInSup(username, password);
  141. suplierMenu(comp, its);
  142. }
  143. else {
  144. itc = comp.verifyLogInCli(username, password);
  145. clientMenu(comp, itc);
  146. }
  147.  
  148.  
  149. cout << TAB << "Prima qualquer tecla para voltar ao Menu Inicial." << endl << endl;
  150.  
  151. pauseScreen();
  152.  
  153. start(comp);
  154.  
  155. }
  156.  
  157.  
  158.  
  159. void mainMenu(Company & comp, char user) {
  160. clearScreen();
  161.  
  162. string option_str;
  163. unsInt option_int;
  164.  
  165. if(user== 's') cout << TAB_BIG << "|| Menu Fornecedor ||" << endl << endl;
  166. else cout << TAB_BIG << "|| Menu Cliente ||" << endl << endl;
  167. cout << TAB << "1 - Registar" << endl;
  168. cout << TAB << "2 - Entrar" << endl;
  169. cout << TAB << "3 - Voltar ao Menu Inicial" << endl;
  170.  
  171. cout << endl << TAB << "Opção: ";
  172.  
  173. getline(cin, option_str);
  174.  
  175. option_int = stoi(option_str);
  176.  
  177. if (option_int < 1 || option_int >3) throw WrongOption(1, 3);
  178.  
  179.  
  180. switch (option_int) {
  181. case 1:
  182. if(user== 's') comp.registerSuplier();
  183. else comp.registerClient();
  184.  
  185. pauseScreen();
  186. mainMenu(comp,user);
  187. break;
  188. case 2:
  189. if (user == 's') logIn(comp, 's');
  190. else logIn(comp, 'c');
  191. break;
  192. case 3:
  193. start(comp);
  194. }
  195.  
  196. }
  197.  
  198. void suplierMenu(Company & comp, vector<Suplier>::iterator it){
  199.  
  200. clearScreen();
  201.  
  202. string option_str;
  203. int option_int;
  204. string add;
  205.  
  206.  
  207. cout << TAB_BIG << "|| " << it->getUsername() << " ||" << endl << endl;
  208. cout << TAB << "1 - Ver Alojamentos" << endl;
  209. cout << TAB << "2 - Adicionar Alojamento" << endl;
  210. cout << TAB << "3 - Informações de Conta" << endl;
  211. cout << TAB << "4 - Ver Reservas" << endl; // a implementar
  212. cout << TAB << "5 - Sair" << endl;
  213.  
  214. cout << endl << TAB << "Opção: ";
  215.  
  216. getline(cin, option_str);
  217.  
  218. option_int = stoi(option_str);
  219.  
  220. if (option_int < 1 || option_int >5) throw WrongOption(1, 5);
  221.  
  222. switch (option_int) {
  223. case 1:
  224. it->showAccomodations();
  225. break;
  226.  
  227. case 2:
  228. add = "s";
  229. while (add == "s") {
  230. it->addAccomodation();
  231.  
  232. cout << endl << TAB << "Adicionar Alojamento (s/n)? ";
  233. getline(cin, add);
  234.  
  235. }
  236.  
  237. if (add != "n") throw InvalidInput();
  238.  
  239.  
  240. clearScreen();
  241. cout << TAB << "Os seus alojamentos foram atualizados com sucesso!" << endl;
  242. break;
  243.  
  244. case 3:
  245. clearScreen();
  246. cout << TAB_BIG << "|| Informações de Conta ||" << endl << endl;
  247. cout << TAB << "Nome: " << it->getName() << endl;
  248. cout << TAB << "Nome de Utilizador: " << it->getUsername() << endl;
  249. cout << TAB << "NIF: " << it->getNIF() << endl;
  250. cout << TAB << "Morada: " << it->getAdress() << endl << endl;
  251.  
  252. break;
  253.  
  254. case 4:
  255. it->showReservations();
  256. break;
  257. case 5:
  258. //exit(1);
  259. start(comp);
  260. break;
  261. }
  262.  
  263. cout << TAB << "Prima qualquer tecla para voltar ao Menu Fornecedor." << endl << endl;
  264.  
  265. pauseScreen();
  266.  
  267. suplierMenu(comp, it);
  268.  
  269. }
  270.  
  271. void guestMenu(Company & comp) {
  272. string option_str;
  273. unsInt option_int;
  274.  
  275. // dados para efetuar reserva
  276. string location;
  277. string date;
  278. Date initial_date;
  279. Date final_date;
  280. Accomodation* acc;
  281. Reservation res;
  282.  
  283. clearScreen();
  284.  
  285. cout << TAB_BIG << "|| Menu ||" << endl << endl;
  286. cout << TAB << "1 - Efetuar Reserva" << endl;
  287. cout << TAB << "2 - Cancelar Reserva" << endl;
  288. cout << TAB << "3 - Ver Reserva" << endl;
  289. cout << TAB << "4 - Voltar ao Menu Inicial" << endl;
  290.  
  291. cout << endl << TAB << "Opção: ";
  292.  
  293. getline(cin, option_str);
  294.  
  295. option_int = stoi(option_str);
  296.  
  297. if (option_int < 1 || option_int >4) throw WrongOption(1, 4);
  298.  
  299. clearScreen();
  300.  
  301. switch(option_int) {
  302. case 1:
  303.  
  304. cout << TAB_BIG << "|| Eftuar Reserva ||" << endl << endl;
  305.  
  306. cout << TAB << "Local: ";
  307. getline(cin, location);
  308. if (cin.eof()) throw InvalidInput();
  309.  
  310. cout << TAB << "Data Inicial: ";
  311. getline(cin, date);
  312. if (!initial_date.getDate(date)) throw InvalidDate();
  313.  
  314. cout << TAB << "Data Final: ";
  315. getline(cin, date);
  316. if (!final_date.getDate(date)) throw InvalidDate();
  317.  
  318. acc = comp.displayOffers(location, initial_date, final_date);
  319. if (acc == NULL) break;
  320.  
  321. res.setAccomodation(acc);
  322. res.setCheckIN(initial_date);
  323. res.setCheckOUT(final_date);
  324. res.setID();
  325.  
  326.  
  327. clearScreen();
  328.  
  329. cout << TAB_BIG << "|| Reserva ||" << endl << endl;
  330. cout << res;
  331.  
  332.  
  333. cout << endl << TAB << "A sua reserva foi criada com sucesso." << endl;
  334. cout << endl << TAB << "É importante que guarde o id da sua reserva para poder fazer alterações futuras." << endl;
  335.  
  336. break;
  337. case 2:
  338. comp.cancelReservation();
  339. break;
  340. case 3:
  341. comp.showReservation();
  342. break;
  343. case 4:
  344. start(comp);
  345. }
  346. cout << TAB << "Prima qualquer tecla para voltar ao Menu." << endl << endl;
  347.  
  348. pauseScreen();
  349.  
  350. guestMenu(comp);
  351.  
  352.  
  353. }
  354.  
  355.  
  356. void start(Company & comp) {
  357. string option_str;
  358. unsInt option_int;
  359.  
  360. clearScreen();
  361.  
  362. cout << TAB_BIG << "|| Menu Inicial ||" << endl << endl;
  363. cout << TAB << "1 - Menu Fornecedor" << endl;
  364. cout << TAB << "2 - Menu Cliente" << endl;
  365. cout << TAB << "3 - Entrar como Visitante" << endl;
  366. cout << TAB << "4 - Sair" << endl;
  367.  
  368. cout << endl << TAB<< "Opção: ";
  369.  
  370. getline(cin, option_str);
  371.  
  372. option_int = stoi(option_str);
  373.  
  374. if (option_int < 1 || option_int >4) throw WrongOption(1, 4);
  375.  
  376.  
  377.  
  378. switch (option_int){
  379. case 1:
  380. mainMenu(comp,'s');
  381. break;
  382. case 2:
  383. mainMenu(comp, 'c');
  384. break;
  385. case 3:
  386. guestMenu(comp);
  387. break;
  388. case 4:
  389. comp.saveChanges();
  390. exit(1);
  391. }
  392.  
  393.  
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement