Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 111.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <windows.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include <conio.h>
  8. #include <stddef.h>
  9.  
  10. #define POUND_SIGN 156
  11.  
  12. #define MAX_NUM_CITY 40
  13. #define MAX_NUM_ACC 20
  14. #define MAX_NUM_TICKETS 40
  15.  
  16. #define MAX_LEN_NAME 15
  17. #define MAX_LEN_SURNAME 20
  18. #define MAX_LEN_EMAIL 30
  19. #define MIN_LEN_PASSWORD 5
  20. #define MAX_LEN_PASSWORD 15
  21. #define MAX_LEN_ADDRESS 30
  22. #define MAX_LEN_CITY 20
  23. #define MAX_LEN_POSTCODE 8
  24. #define MAX_LEN_DATE 10
  25. #define MAX_LEN_DEPARTMENT 50
  26. #define GRADE1 8.5
  27. #define GRADE2 10
  28. #define GRADE3 13.5
  29. #define MAX_LEN_TITLE 20
  30. #define MAX_NUM_STAFF 200
  31.  
  32. #define MAX_LEN_NAMEONCARD 30
  33. #define MAX_LEN_CARDNUMBER 16
  34. #define MAX_LEN_EXPDATE 2
  35. #define MAX_LEN_SECURITYCODE 3
  36.  
  37. #define MAX_LEN_SEAT 50
  38. #define MAX_LEN_CITY 15
  39. #define MAX_LEN_DEPPTIME 10
  40. #define MAX_LEN_ARRTIME 10
  41. #define MAX_LEN_CODE 3
  42. #define MIN_PRICE (float) 1
  43. #define MAX_PRICE (float) 2000
  44.  
  45. #define START_DATE (int) 8
  46. #define END_DATE (int) 8
  47.  
  48.  
  49. int GetValidatedInteger(int min, int max);
  50. float GetValidatedFloat(float Min, float Max);
  51. char GetValidatedString(char ValidatedString[], int MinLength, int MaxLength);
  52. char GetValidatedYesNo();
  53. void Clearstdin();
  54.  
  55. void ShowMainMenuLogOut();
  56. void ShowMainMenuLogIn();
  57. void LogInMenu();
  58.  
  59. void SignUpMenu(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *LogInCheck);
  60. int Password(char TemporaryPass2[]);
  61. void PasswordStr(int HowManyInt, int HowManyChar, char TemporaryPass[]);
  62. void RandomCode(char Robot[], int HowManyChar);
  63. void SignUpText();
  64. void Email(struct CustomerAccount AllRecords[], char TemporaryEmail[], int *NumCustomerAcc, int *At, int *Dot, int *Counter);
  65.  
  66. ///// staff account functions
  67. void CreateStaffAcc(struct StaffAccount AllStaff[], int *NumStaffAcc);
  68. void AdminAccLayout(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck);
  69. void ManageStaff(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData);
  70. void ManageDestinations(struct City_Country AllCities[], int *NumOfCities);
  71. void DisplayDestinations(struct City_Country AllCities[], int *NumOfCities);
  72. void GradeMenu();
  73. void DisplayStaff(struct StaffAccount AllStaff[], int *NumStaffAcc);
  74. void DisplayStaffAll(struct StaffAccount AllStaff[], int *NumStaffAcc);
  75. void SearchRecords(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData);
  76. void SearchRecordsSurname(struct StaffAccount AllStaff[], int *NumStaffAcc);
  77. void ChoiceMenu();
  78. void UpdateRecords(struct StaffAccount AllStaff[], int *NumStaffAcc);
  79. char StaffAccDetailsUpdate();
  80. void StaffHoliday(struct StaffAccount AllStaff[], int *NumStaffAcc);
  81.  
  82. ///// external files
  83. void SaveAllRecordsToFile(struct CustomerAccount AllRecords[], int NumCustomerAcc);
  84. int ReadAllRecordsFromFile(struct CustomerAccount AllRecords[], int NumCustomerAcc);
  85.  
  86. int ReadAllStaffFromFile(struct StaffAccount AllStaff[], int NumStaffAcc);
  87. void SaveAllStaffToFile(struct StaffAccount AllStaff[], int NumStaffAcc);
  88.  
  89. int ReadAllCitiesFromFile(struct City_Country AllCities[], int NumOfCities);
  90. void SaveAllCitiesToFile(struct City_Country AllCities[], int NumOfCities);
  91.  
  92. ///// login for staff and customers
  93. void LogInCustomer(struct CustomerAccount AllRecords[], int NumCustomerAcc, int *LogInCheck, int *WhatData);
  94. void LogInStaff(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck);
  95.  
  96. ///// customer account functions
  97. void CustomerAccLayout(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *LogInCheck);
  98. void CustomerAccPersonalDeatils(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData);
  99. char CustomerAccPersonalDetailsUpdate();
  100. void CustomerAccManageAcc(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *Delete);
  101. void CustomerAccManageCard(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData);
  102. void CustomerAccAddCreditCard(struct CustomerAccount AllRecords[], int *WhatData);
  103. int NumberCheck(char ToCheck[], int CorrectSize);
  104.  
  105. ///// ticket functions
  106. void SearchFlights(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2);
  107. void Options(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2);
  108. void Payment(struct CustomerAccount AllRecords[], struct Ticket AllTickets[], int *NumOfTickets, int *WhatData);
  109.  
  110. struct CustomerAccount
  111. {
  112. char Name[MAX_LEN_NAME + 1];
  113. char Surname[MAX_LEN_SURNAME + 1];
  114. char Email[MAX_LEN_EMAIL + 1];
  115. char Password[MAX_LEN_PASSWORD + 1];
  116. char MemorablePassword[MAX_LEN_PASSWORD + 1];
  117. int Lock;
  118. int KeepLogin;
  119. int Theme;
  120. int CreditCardCheck;
  121. char NameOnCard[MAX_LEN_NAMEONCARD + 1];
  122. char CardNumber[MAX_LEN_CARDNUMBER + 1];
  123. char ExpDateMonth[MAX_LEN_EXPDATE + 1];
  124. char ExpDateYear[MAX_LEN_EXPDATE + 1];
  125. char SecurityCode[MAX_LEN_SECURITYCODE + 1];
  126. };
  127.  
  128. struct StaffAccount
  129. {
  130. char Name[MAX_LEN_NAME + 1];
  131. char Surname[MAX_LEN_SURNAME + 1];
  132. char Login[MAX_LEN_EMAIL + 1];
  133. char Password[MAX_LEN_PASSWORD + 1];
  134. char Address[MAX_LEN_ADDRESS + 1];
  135. char City[MAX_LEN_CITY + 1];
  136. char Postcode[MAX_LEN_CITY + 1];
  137. char DOB[MAX_LEN_DATE + 1];
  138. char JobTitle[MAX_LEN_TITLE + 1];
  139. char Department[MAX_LEN_DEPARTMENT + 1];
  140. float PayGrade;
  141. char StartDate[MAX_LEN_DATE + 1];
  142. int Lock;
  143. int Admin;
  144.  
  145. int Start_date[END_DATE + 1];
  146. int End_date[END_DATE + 1];
  147.  
  148. };
  149.  
  150. struct City_Country
  151. {
  152. char City[MAX_LEN_CITY + 1];
  153. char Country[MAX_LEN_CITY + 1];
  154. char AirportCode[MAX_LEN_CODE + 1];
  155. int Popularity;
  156. int Place;
  157. };
  158.  
  159. struct Ticket
  160. {
  161. char DepartureCountry[MAX_LEN_CITY + 1];
  162. char ArrivalCountry[MAX_LEN_CITY + 1];
  163. char DepartureCity[MAX_LEN_CITY + 1];
  164. char ArrivalCity[MAX_LEN_CITY + 1];
  165. char DepartureTime[MAX_LEN_DEPPTIME + 1];
  166. int DepartureDay;
  167. int DepartureMonth;
  168. int DepartureYear;
  169. int DepartureHour;
  170. int DepartureMin;
  171. float Price;
  172. int FirstClass;
  173. int BussinessClass;
  174. int ThirdClass;
  175. int NumberOfAdults;
  176. int NumberOfChildren;
  177. int NumberOfInfants;
  178. int WayBackOrNo;
  179. char Seats[MAX_LEN_SEAT + 1];
  180. int Who;
  181. };
  182.  
  183. int main()
  184. {
  185. SetConsoleTitle("Airline portal managment");
  186.  
  187. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
  188. COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
  189. c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
  190. c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
  191. SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
  192.  
  193. SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
  194. sr.Left = 0; // na zero
  195. sr.Top = 0; // na zero
  196. sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
  197. sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
  198. SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
  199.  
  200. struct City_Country AllCities[MAX_NUM_CITY];
  201. struct CustomerAccount AllRecords[MAX_NUM_ACC];
  202. struct StaffAccount AllStaff[MAX_NUM_ACC];
  203. struct Ticket AllTickets[MAX_NUM_TICKETS];
  204.  
  205. int NumOfCities = 0;
  206. int NumCustomerAcc = 0;
  207. int NumStaffAcc = 0;
  208. int NumOfTickets = 0;
  209.  
  210. int MenuChoice = 0, MenuChoice2 = 0;
  211. int LogInCheck = 0;
  212.  
  213. //SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  214. //SaveAllCitiesToFile(AllCities, NumOfCities);
  215. //SaveAllStaffToFile(AllStaff, NumStaffAcc);
  216.  
  217. NumCustomerAcc = ReadAllRecordsFromFile(AllRecords, MAX_NUM_ACC);
  218. NumStaffAcc = ReadAllStaffFromFile(AllStaff, MAX_NUM_ACC);
  219. NumOfCities = ReadAllCitiesFromFile(AllCities, MAX_NUM_CITY);
  220.  
  221. int Airport1 = -1;
  222. int Airport2 = -1;
  223.  
  224. int Counter = 0;
  225. int WhatData = 0;
  226. for (int i = 0; i < NumCustomerAcc; i++)
  227. {
  228. if (AllRecords[i].KeepLogin == 1)
  229. {
  230. LogInCheck = 1;
  231. WhatData = Counter;
  232.  
  233. switch (AllRecords[WhatData].Theme)
  234. {
  235. case 1:
  236. system("color 70");
  237. break;
  238. case 2:
  239. system("COLOR 67");
  240. break;
  241. case 3:
  242. system("color 30");
  243. break;
  244. case 4:
  245. system("color 07");
  246. break;
  247. }
  248.  
  249. }
  250. else
  251. {
  252. Counter++;
  253. }
  254. }
  255.  
  256. do
  257. {
  258. if (LogInCheck == 0) ShowMainMenuLogOut();
  259. if (LogInCheck == 1) ShowMainMenuLogIn();
  260. MenuChoice = _getch();
  261. switch (MenuChoice)
  262. {
  263. case '1':
  264. {
  265. system("cls");
  266. if (LogInCheck == 0)
  267. {
  268. LogInMenu();
  269. do
  270. {
  271. MenuChoice2 = _getch();
  272. switch (MenuChoice2)
  273. {
  274. case '1':
  275. LogInCustomer(AllRecords, NumCustomerAcc, &LogInCheck, &WhatData);
  276. break;
  277.  
  278. case '2':
  279. LogInStaff(AllStaff, AllCities, &NumStaffAcc, &NumOfCities, &WhatData, &LogInCheck);
  280. SaveAllCitiesToFile(AllCities, NumOfCities);
  281. SaveAllStaffToFile(AllStaff, NumStaffAcc);
  282. break;
  283.  
  284. case '0':
  285. system("cls");
  286. break;
  287. }
  288. } while (MenuChoice2 != '0' && MenuChoice2 != '1' && MenuChoice2 != '2');
  289. }
  290. else if (LogInCheck == 1)
  291. {
  292. AllRecords[WhatData].KeepLogin = 0;
  293. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  294. WhatData = -1;
  295. Sleep(150);
  296. LogInCheck = 0;
  297. system("color 07");
  298. system("cls");
  299. }
  300. break;
  301. }
  302. case '2':
  303. if (LogInCheck == 0)
  304. {
  305. SignUpMenu(AllRecords, &NumCustomerAcc, &LogInCheck);
  306. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  307. }
  308. else if (LogInCheck == 1)
  309. {
  310. CustomerAccLayout(AllRecords, &NumCustomerAcc, &WhatData, &LogInCheck);
  311. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  312. }
  313. break;
  314. case '3':
  315. if (LogInCheck == 1)
  316. {
  317. SearchFlights(AllCities, AllTickets, &NumOfCities, &NumOfTickets, &Airport1, &Airport2);
  318.  
  319. if (Airport1 != -1 && Airport2 != -1)
  320. {
  321. Options(AllCities, AllTickets, &NumOfCities, &NumOfTickets, &Airport1, &Airport2);
  322. Payment(AllRecords, AllTickets, &NumOfTickets, &WhatData);
  323. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  324. }
  325. }
  326. else
  327. {
  328. system("cls");
  329. printf("\n\n\n\n\n\n\n\n\n\n\n Please log in or sign up to buy tickets.");
  330. Sleep(2300);
  331. system("cls");
  332. }
  333. break;
  334. case '4':
  335. DisplayDestinations(AllCities, &NumOfCities);
  336. break;
  337. case '5':
  338. CreateStaffAcc(AllStaff, &NumStaffAcc);
  339. SaveAllStaffToFile(AllStaff, NumStaffAcc);
  340. break;
  341. case '6':
  342.  
  343. break;
  344. case '0':
  345. system("cls");
  346. printf("\n\n\n\n\n\n\n\n\n\n\n Closing the program.");
  347. Sleep(800);
  348. break;
  349. default:
  350. system("cls");
  351. break;
  352. }
  353. } while (MenuChoice != '0');
  354.  
  355. return(0);
  356. }
  357.  
  358. int GetValidatedInteger(int min, int max)
  359. {
  360. const int cTrue = 1;
  361. const int cFalse = 0;
  362. float Input = 0;
  363. int Itemread = cFalse;
  364. int Valid = cFalse;
  365.  
  366. do
  367. {
  368. Itemread = scanf_s("%f", &Input);
  369. Clearstdin();
  370.  
  371. if (Itemread == cFalse) { printf("Must be a number. (%d - %d)\n", min, max); }
  372.  
  373. else if (Input != (int)Input) { printf("Must be a intiger. (%d - %d)\n", min, max); }
  374.  
  375. else if ((Input < min) || (Input > max)) { printf("Out of range. (%d - %d)\n", min, max); }
  376.  
  377. else Valid = cTrue;
  378.  
  379. } while (Valid == cFalse);
  380.  
  381. return((int)Input);
  382. }
  383. float GetValidatedFloat(float Min, float Max)
  384. {
  385. const int cTrue = 1;
  386. const int cFalse = 0;
  387.  
  388. int ItemRead = cTrue;
  389. float Input = 0;
  390. int Valid = cFalse;
  391.  
  392. scanf_s("%f", &Input);
  393.  
  394. do
  395. {
  396. Clearstdin();
  397.  
  398. if (ItemRead == cFalse)
  399. {
  400. printf("Invalid - must be a number! Please try again.");
  401. Sleep(500);
  402. printf("\nEnter the Price (%c%1.2f - %c%1.2f): %c", POUND_SIGN, MIN_PRICE, POUND_SIGN, MAX_PRICE, POUND_SIGN);
  403. scanf_s("%f", &Input);
  404. }
  405.  
  406. else if ((Input < Min) || (Input > Max))
  407. {
  408. printf("Invalid - out-of-range! Please try again.");
  409. Sleep(500);
  410. printf("\nEnter the Price (%c%1.2f - %c%1.2f): %c", POUND_SIGN, MIN_PRICE, POUND_SIGN, MAX_PRICE, POUND_SIGN);
  411. scanf_s("%f", &Input);
  412. }
  413. else
  414. {
  415. Valid = cTrue;
  416. }
  417.  
  418. } while (Valid == cFalse);
  419.  
  420. return(Input);
  421. }
  422. char GetValidatedString(char ValidatedString[], int MinLength, int MaxLength)
  423. {
  424. const char cFalse = 0, cTrue = 1;
  425. char Success = cFalse;
  426. char YesorNo;
  427. char Input[255];
  428.  
  429. size_t InputArrayMaxLen = sizeof(Input) - 2;
  430. size_t Length;
  431.  
  432. if (MaxLength > (int)InputArrayMaxLen)
  433. {
  434. printf("\n\nRequired maximum length for called GetValidatedString() function""\ncannot exceed %d characters", (int)InputArrayMaxLen);
  435. printf("\nData not read. Please contact developer.");
  436. getchar();
  437. return(Success);
  438. }
  439. do
  440. {
  441. do
  442. {
  443. YesorNo = 'Y';
  444. Input[InputArrayMaxLen + 1] = 'z';
  445. Input[InputArrayMaxLen] = 'z';
  446. fgets(Input, sizeof(Input), stdin);
  447.  
  448.  
  449. if ((Input[InputArrayMaxLen + 1] == '\0') && (Input[InputArrayMaxLen] != '\n'))
  450. {
  451. printf("\n\nRequired maximum length for called GetValidatedString() function " "\ncannot exceed %d characters", InputArrayMaxLen);
  452. printf("\n\nDo you wish to try again (Y/N)?: ");
  453. YesorNo = GetValidatedYesNo();
  454. if (YesorNo == 'N')
  455. {
  456. printf("Data not read. Please contact developer.");
  457. getchar();
  458. return(Success);
  459. }
  460. else
  461. {
  462. printf("\nRe-enter(%d - %d characters): ", MinLength, MaxLength);
  463. }
  464. }
  465. else
  466. {
  467. YesorNo = 'N';
  468. }
  469. } while (YesorNo == 'Y');
  470.  
  471. Length = strlen(Input) - 1;
  472. Input[Length] = '\0';
  473.  
  474. if ((Length < (size_t)MinLength) || (Length >(size_t)MaxLength))
  475. {
  476. printf("\n Invalid! Please try again (Length %d-%d): ", MinLength, MaxLength);
  477. printf("\n ---> ");
  478. }
  479. else
  480. {
  481. Success = cTrue;
  482. }
  483. } while (Success == cFalse);
  484.  
  485. strcpy_s(ValidatedString, MaxLength + 1, Input);
  486. return(Success);
  487. }
  488. char GetValidatedYesNo()
  489. {
  490. char reply;
  491. do
  492. {
  493. reply = _getch();
  494. reply = toupper(reply);
  495. } while ((reply != 'Y') && (reply != 'N'));
  496.  
  497. return reply;
  498. }
  499. void Clearstdin()
  500. {
  501. char Discard[255] = "";
  502. fgets(Discard, sizeof(Discard), stdin);
  503. }
  504.  
  505. void ShowMainMenuLogOut()
  506. {
  507. printf("0.Quit 1.LogIn 2.SignUp\n");
  508. printf(" \n");
  509. printf(" Most popular destination \n");
  510. printf(" \n");
  511. printf(" \n");
  512. printf(" \n");
  513. printf(" 3. Buy tickets \n");
  514. printf(" 4. Display all destinations \n");
  515. printf(" \n");
  516. printf(" \n");
  517. printf(" \n");
  518. printf(" \n");
  519. printf(" \n");
  520. printf(" \n");
  521. printf(" \n");
  522. printf(" \n");
  523. printf(" \n");
  524. printf(" \n");
  525. printf(" \n");
  526. printf(" \n");
  527. printf(" \n");
  528. printf(" \n");
  529. printf(" \n");
  530. printf(" \n");
  531. }
  532. void ShowMainMenuLogIn()
  533. {
  534. printf("0.Quit 1.LogOut 2.Account\n");
  535. printf(" \n");
  536. printf(" Most popular destination \n");
  537. printf(" \n");
  538. printf(" \n");
  539. printf(" \n");
  540. printf(" 3. Buy tickets \n");
  541. printf(" 4. Display all destinations \n");
  542. printf(" \n");
  543. printf(" \n");
  544. printf(" \n");
  545. printf(" \n");
  546. printf(" \n");
  547. printf(" \n");
  548. printf(" \n");
  549. printf(" \n");
  550. printf(" \n");
  551. printf(" \n");
  552. printf(" \n");
  553. printf(" \n");
  554. printf(" \n");
  555. printf(" \n");
  556. printf(" \n");
  557. printf(" \n");
  558. }
  559.  
  560. void LogInMenu()
  561. {
  562. //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
  563. printf("0.Back to Main Menu \n");
  564. printf(" \n");
  565. printf(" \n");
  566. printf(" \n");
  567. printf(" \n");
  568. printf(" \n");
  569. printf(" \n");
  570. printf(" \n");
  571. printf(" 1. Log in as a customer \n");
  572. printf(" \n");
  573. printf(" \n");
  574. printf(" 2. Log in as a staff \n");
  575.  
  576. }
  577.  
  578. void SignUpMenu(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *LogInCheck)
  579. {
  580. Sleep(100);
  581. system("cls");
  582.  
  583. char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
  584. char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
  585.  
  586. printf("0.Back to Main Menu \n");
  587. SignUpText();
  588. printf(" First Name: ");
  589. GetValidatedString(AllRecords[*NumCustomerAcc].Name, 1, MAX_LEN_NAME);
  590. if (strcmp(AllRecords[*NumCustomerAcc].Name, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
  591.  
  592. printf(" Last Name: ");
  593. GetValidatedString(AllRecords[*NumCustomerAcc].Surname, 1, MAX_LEN_SURNAME);
  594. if (strcmp(AllRecords[*NumCustomerAcc].Surname, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
  595.  
  596. ///////////////////////////////////////////////////////////////////////////////Email//////////////////////////////////////////////////////////////////////////////////////////
  597. char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
  598. int Counter2 = 0;
  599. int At = 0;
  600. int Dot = 0;
  601.  
  602. do
  603. {
  604. system("cls");
  605. printf("0.Back to Main Menu \n");
  606. SignUpText();
  607. printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
  608. printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
  609. printf(" Email Address: ");
  610.  
  611. GetValidatedString(TemporaryEmail, 1, MAX_LEN_EMAIL);
  612. if (strcmp(TemporaryEmail, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
  613.  
  614. Email(AllRecords, TemporaryEmail, NumCustomerAcc, &At, &Dot, &Counter2);
  615.  
  616. } while (Counter2 != *NumCustomerAcc || At == 0 || At > 1 || Dot == 0);
  617.  
  618. strcpy_s(AllRecords[*NumCustomerAcc].Email, MAX_LEN_EMAIL, TemporaryEmail);
  619.  
  620. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  621. {
  622. TemporaryEmail[i] = NULL;
  623. }
  624.  
  625. ////////////////////////////////////////////////////////////////////////////////Password/////////////////////////////////////////////////////////////////////////////////////////
  626. system("cls");
  627. printf(" \n");
  628. SignUpText();
  629. printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
  630. printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
  631. printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
  632. printf(" \n");
  633. printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  634. printf("\n At least one number and one capital letter. \n");
  635. printf(" \n");
  636. printf(" <Password strength> ");
  637.  
  638. int Counter = 0;
  639. int Counter3 = 0;
  640. int DeleteChar = 0;
  641. int ArrayCounter = 0;
  642. int HowManyChar = 0;
  643. int HowManyInt = 0;
  644. do
  645. {
  646. char Pass[2];
  647. do
  648. {
  649. if (Counter3 > 0)
  650. {
  651. printf("\n\n You did not use either a number or a capital letter.");
  652. printf("\n Please retype your password.");
  653. Sleep(2400);
  654. system("cls");
  655. printf(" \n");
  656. SignUpText();
  657. printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
  658. printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
  659. printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
  660. printf(" \n");
  661. printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  662. printf("\n At least one number and one capital letter. \n");
  663. printf(" \n");
  664. printf(" <Password strength> ");
  665. Pass[0] = NULL;
  666.  
  667. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  668. {
  669. TemporaryPass[i] = NULL;
  670. }
  671.  
  672. HowManyChar = 0;
  673. HowManyInt = 0;
  674. ArrayCounter = 0;
  675. DeleteChar = 0;
  676. }
  677.  
  678. Pass[0] = NULL;
  679. while ((strlen(TemporaryPass) <= MAX_LEN_PASSWORD && Pass[0] != 13) || (strlen(TemporaryPass) < MIN_LEN_PASSWORD && Pass[0] == 13))
  680. {
  681.  
  682. PasswordStr(HowManyInt, HowManyChar, TemporaryPass);
  683. if (Counter3 > 0)
  684. {
  685. printf("\n\n Password: ");
  686. Counter3 = 0;
  687. }
  688. else
  689. {
  690. printf("\n\n Password: ");
  691. for (int i = 0; i < DeleteChar; i++)
  692. {
  693. printf("*");
  694. }
  695. }
  696.  
  697. Pass[0] = _getch();
  698. Pass[1] = '\0';
  699.  
  700. int ToCheck = Pass[0];
  701. if (DeleteChar > 0 && ToCheck == 8)
  702. {
  703. int ToCheck2 = TemporaryPass[ArrayCounter - 1];
  704. if (65 <= ToCheck2 && ToCheck2 <= 90) HowManyChar--;
  705. if (48 <= ToCheck2 && ToCheck2 <= 57) HowManyInt--;
  706.  
  707. DeleteChar--;
  708. TemporaryPass[ArrayCounter - 1] = NULL;
  709. ArrayCounter--;
  710. }
  711.  
  712. if (strlen(TemporaryPass) != MAX_LEN_PASSWORD)
  713. {
  714. if (Pass[0] != 13 && Pass[0] != 8)
  715. {
  716. int ToCheck = Pass[0];
  717. if (65 <= ToCheck && ToCheck <= 90) HowManyChar++;
  718. if (48 <= ToCheck && ToCheck <= 57) HowManyInt++;
  719. printf("%c", Pass[0]);
  720. Sleep(150);
  721. strcat_s(TemporaryPass, sizeof(TemporaryPass), Pass);
  722. DeleteChar++;
  723. ArrayCounter++;
  724. }
  725. }
  726.  
  727. system("cls");
  728. printf(" \n");
  729. SignUpText();
  730. printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
  731. printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
  732. printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
  733. printf(" \n");
  734. printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  735. printf("\n At least one number and one capital letter. \n");
  736. printf(" \n");
  737. printf(" <Password strength> ");
  738. }
  739. PasswordStr(HowManyInt, HowManyChar, TemporaryPass);
  740. if (HowManyChar == 0 || HowManyInt == 0) Counter3++;
  741. else Counter3 = 0;
  742.  
  743. } while (HowManyChar == 0 || HowManyInt == 0);
  744.  
  745. HowManyChar = 0;
  746. HowManyInt = 0;
  747. ArrayCounter = 0;
  748.  
  749. printf("\n\n Password: ");
  750. for (int i = 0; i < DeleteChar; i++)
  751. {
  752. printf("*");
  753. }
  754. DeleteChar = 0;
  755.  
  756. //////////////////////////////////////////////////////////////Password confirmation/////////////////////////////////////////////////////////////////////////
  757. printf("\n Confirm Password: ");
  758. Pass[0] = NULL;
  759. Password(TemporaryPass2);
  760.  
  761. if (strcmp(TemporaryPass, TemporaryPass2) != 0)
  762. {
  763. printf("\n\n Your passwords don't match.");
  764. printf("\n Please retype your password to confirm it.");
  765. Sleep(2400);
  766. system("cls");
  767. printf(" \n");
  768. SignUpText();
  769. printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
  770. printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
  771. printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
  772. printf(" \n");
  773. printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  774. printf("\n At least one number and one capital letter. \n");
  775. printf(" \n");
  776. printf(" <Password strength> ");
  777. }
  778. else
  779. {
  780. Counter++;
  781. strcpy_s(AllRecords[*NumCustomerAcc].Password, MAX_LEN_PASSWORD, TemporaryPass);
  782. }
  783.  
  784. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  785. {
  786. TemporaryPass[i] = NULL;
  787. TemporaryPass2[i] = NULL;
  788. }
  789.  
  790. } while (Counter == 0);
  791.  
  792. ///////////////////////////////////////////////////////////Choice///////////////////////////////////////////////////
  793. printf("\n\n\n 0.Cancel || 1.Next step \n");
  794. int Choice = 0;
  795. do
  796. {
  797. Choice = 0;
  798. Choice = _getch();
  799.  
  800. switch (Choice)
  801. {
  802. case '0':
  803. {
  804. AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1];
  805. Sleep(350);
  806. break;
  807. }
  808.  
  809. case '1':
  810. {
  811. system("cls");
  812. char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
  813. int StarsToDisplay = 0;
  814.  
  815. do
  816. {
  817. printf(" \n");
  818. printf(" \n");
  819. printf(" Please enter your memorable password. \n");
  820. printf(" You will need it, if you forget your main password. \n");
  821. printf("\n \n");
  822. printf("\n Memorable password must be between %d and %d characters. \n", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  823. printf("\n\n Memorable Password: ");
  824.  
  825. StarsToDisplay = 0;
  826. StarsToDisplay = Password(TemporaryPass2);
  827. strcpy_s(AllRecords[*NumCustomerAcc].MemorablePassword, MAX_LEN_PASSWORD, TemporaryPass2);
  828.  
  829.  
  830. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  831. {
  832. TemporaryPass2[i] = NULL;
  833. }
  834.  
  835. printf("\n Confirm Memorable Password: ");
  836. Password(TemporaryPass2);
  837.  
  838. if (strcmp(AllRecords[*NumCustomerAcc].MemorablePassword, TemporaryPass2) != 0)
  839. {
  840. printf("\n\n Your passwords don't match.");
  841. printf("\n Please retype your password to confirm it.");
  842. Sleep(2400);
  843. system("cls");
  844.  
  845. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  846. {
  847. TemporaryPass2[i] = NULL;
  848. }
  849.  
  850. AllRecords[0 + *NumCustomerAcc].MemorablePassword[MAX_LEN_PASSWORD + 1] = AllRecords[*NumCustomerAcc + 1].MemorablePassword[MAX_LEN_PASSWORD + 1];
  851. }
  852. } while (strcmp(AllRecords[*NumCustomerAcc].MemorablePassword, TemporaryPass2) != 0);
  853.  
  854. char UserRobot[25 + 1] = "";
  855. char Robot[15 + 1] = "";
  856.  
  857. do
  858. {
  859. for (int i = 0; i < sizeof(UserRobot); i++)
  860. {
  861. UserRobot[i] = NULL;
  862. }
  863.  
  864. for (int i = 0; i < sizeof(Robot); i++)
  865. {
  866. Robot[i] = NULL;
  867. }
  868.  
  869. RandomCode(Robot, 5);
  870.  
  871. system("cls");
  872. printf(" \n");
  873. printf(" \n");
  874. printf(" Please enter your memorable password. \n");
  875. printf(" You will need it, if you forget your main password. \n");
  876. printf("\n \n");
  877. printf("\n Memorable password must be between %d and %d characters. \n", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  878.  
  879. printf("\n\n Memorable Password: ");
  880. for (int i = 0; i < StarsToDisplay; i++)
  881. {
  882. printf("*");
  883. }
  884.  
  885. printf("\n Confirm Memorable Password: ");
  886. for (int i = 0; i < StarsToDisplay; i++)
  887. {
  888. printf("*");
  889. }
  890.  
  891. printf("\n\n\n\n : Please, re-type this security code : ");
  892. printf("\n : to confirm you are not a robot : \n");
  893. printf("\n ---> %s <---\n", Robot);
  894. printf("\n ");
  895. GetValidatedString(UserRobot, 0, 25);
  896.  
  897. } while (strcmp(UserRobot, Robot) != 0);
  898.  
  899. printf("\n\n Press ENTER to finish registration. \n");
  900.  
  901. char Finish;
  902. do
  903. {
  904. Finish = _getch();
  905. } while (Finish != 13);
  906.  
  907. for (int i = 3; i >= 0; i--)
  908. {
  909. if (i != 3) Sleep(1000);
  910. system("cls");
  911. printf("\n\n\n\n\n\n\n\n Thank You for completing your registration. \n");
  912. if (i == 3) Sleep(1500);
  913. printf("\n Now you can fully use our service. \n");
  914. if (i == 3) Sleep(1500);
  915. printf("\n Do not waste your time and find the best flights for you! \n");
  916. if (i == 3) Sleep(1500);
  917. printf("\n\n You will be redirected to a main page in a moment. \n");
  918. printf("\n %d", i);
  919. }
  920.  
  921. AllRecords[*NumCustomerAcc].Lock = 0;
  922. AllRecords[*NumCustomerAcc].KeepLogin = 0;
  923. AllRecords[*NumCustomerAcc].Theme = 0;
  924. AllRecords[*NumCustomerAcc].CreditCardCheck = 0;
  925. (*NumCustomerAcc)++;
  926. break;
  927. }
  928. }
  929. } while (Choice != '0' && Choice != '1');
  930. system("cls");
  931. }
  932. int Password(char TemporaryPass2[])
  933. {
  934. int DeleteChar = 0;
  935. int ArrayCounter = 0;
  936. char Pass[2] = "";
  937. char TemporaryArray[MAX_LEN_PASSWORD + 1] = "";
  938. while ((strlen(TemporaryArray) <= MAX_LEN_PASSWORD && Pass[0] != 13) || (strlen(TemporaryArray) < MIN_LEN_PASSWORD && Pass[0] == 13))
  939. {
  940. Pass[0] = _getch();
  941. Pass[1] = '\0';
  942.  
  943. int ToCheck = Pass[0];
  944. if (DeleteChar > 0 && ToCheck == 8)
  945. {
  946. DeleteChar--;
  947. printf("\b");
  948. printf(" ");
  949. printf("\b");
  950. TemporaryArray[ArrayCounter - 1] = NULL;
  951. ArrayCounter--;
  952. }
  953.  
  954. if (strlen(TemporaryArray) != MAX_LEN_PASSWORD)
  955. {
  956. if (Pass[0] != 13 && Pass[0] != 8)
  957. {
  958. printf("%c", Pass[0]);
  959. Sleep(150);
  960. printf("\b");
  961. printf("*");
  962. strcat_s(TemporaryArray, sizeof(TemporaryArray), Pass);
  963. DeleteChar++;
  964. ArrayCounter++;
  965. }
  966. }
  967. }
  968. strcat_s(TemporaryPass2, sizeof(TemporaryArray), TemporaryArray);
  969. return ArrayCounter;
  970. }
  971. void PasswordStr(int HowManyInt, int HowManyChar, char TemporaryPass[])
  972. {
  973. int Points = HowManyInt + HowManyChar;
  974. switch (Points)
  975. {
  976. case (0):
  977. printf("\n LOW");
  978. break;
  979. case (1):
  980. printf("\n LOW");
  981. break;
  982. case (2):
  983. printf("\n LOW");
  984. break;
  985. case (3):
  986. if (strlen(TemporaryPass) <= 5) printf("\n LOW");
  987. else printf("\n MEDIUM");
  988. break;
  989. case (4):
  990. if (strlen(TemporaryPass) <= 7) printf("\n LOW");
  991. else printf("\n MEDIUM");
  992. break;
  993. case (5):
  994. if (strlen(TemporaryPass) <= 7) printf("\n MEDIUM");
  995. else printf("\n GOOD");
  996. break;
  997. case (6):
  998. if (strlen(TemporaryPass) <= 8) printf("\n GOOD");
  999. else printf("\n VERY GOOD");
  1000. break;
  1001. case (7):
  1002. if (strlen(TemporaryPass) <= 11) printf("\n VERY GOOD");
  1003. else printf("\n EXCELLENT");
  1004. break;
  1005. default:
  1006. printf("\n EXCELLENT");
  1007. break;
  1008. }
  1009. }
  1010. void RandomCode(char Robot[], int HowManyChar)
  1011. {
  1012. srand(time(NULL));
  1013. char TemRandomCode[MAX_LEN_PASSWORD] = "";
  1014. char RandomChar[2] = "";
  1015. int RandomNumber = 0;
  1016.  
  1017. for (int i = 0; i < HowManyChar; i++)
  1018. {
  1019. RandomChar[0] = NULL;
  1020. RandomChar[1] = '\0';
  1021. RandomNumber = 0;
  1022. RandomNumber = rand() % 3;
  1023.  
  1024. switch (RandomNumber)
  1025. {
  1026. case 0:
  1027. {
  1028. RandomNumber = 0;
  1029. RandomNumber = rand() % 25 + 65;
  1030. RandomChar[0] = RandomNumber;
  1031. strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
  1032. break;
  1033. }
  1034.  
  1035. case 1:
  1036. {
  1037. RandomNumber = 0;
  1038. RandomNumber = rand() % 25 + 97;
  1039. RandomChar[0] = RandomNumber;
  1040. strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
  1041. break;
  1042. }
  1043.  
  1044. case 2:
  1045. {
  1046. RandomNumber = 0;
  1047. RandomNumber = rand() % 9 + 48;
  1048. RandomChar[0] = RandomNumber;
  1049. strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
  1050. break;
  1051. }
  1052. }
  1053. }
  1054. strcat_s(Robot, sizeof(Robot), TemRandomCode);
  1055. }
  1056. void SignUpText()
  1057. {
  1058. printf(" \n");
  1059. printf(" Buy tickets, manage your flights, \n");
  1060. printf(" get extra prices and more \n");
  1061. printf(" with your account. \n");
  1062. printf(" \n");
  1063. printf(" Start your jurney today! \n");
  1064. printf(" \n");
  1065. printf(" \n");
  1066. }
  1067. void Email(struct CustomerAccount AllRecords[], char TemporaryEmail[], int *NumCustomerAcc, int *At, int *Dot, int *Counter)
  1068. {
  1069. *Counter = 0;
  1070. *At = 0;
  1071. *Dot = 0;
  1072.  
  1073. for (int i = 1; i <= (*NumCustomerAcc); i++)
  1074. {
  1075. if (_strcmpi(TemporaryEmail, AllRecords[i - 1].Email) == 0)
  1076. {
  1077. printf("\n\n It looks like this Email Address has been already in use. \n");
  1078. printf(" Please retype your Email Address. \n");
  1079. Sleep(2400);
  1080. system("cls");
  1081. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  1082. {
  1083. TemporaryEmail[i] = NULL;
  1084. }
  1085. }
  1086. else
  1087. {
  1088. (*Counter)++;
  1089. }
  1090. }
  1091.  
  1092. for (int i = 0; i <= sizeof(TemporaryEmail); i++)
  1093. {
  1094. if (TemporaryEmail[i] == 64)
  1095. {
  1096. (*At)++;
  1097. }
  1098. else if (TemporaryEmail[i] == 46)
  1099. {
  1100. (*Dot)++;
  1101. }
  1102. }
  1103.  
  1104. if ((*At == 0 || *At > 1 || *Dot == 0) && *Counter == (*NumCustomerAcc))
  1105. {
  1106. printf("\n\n It looks like this is not an Email Address. \n");
  1107. printf(" Please retype your Email Address. \n");
  1108. Sleep(2400);
  1109. system("cls");
  1110. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  1111. {
  1112. TemporaryEmail[i] = NULL;
  1113. }
  1114. }
  1115. }
  1116.  
  1117. ///// staff account functions
  1118. void CreateStaffAcc(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1119. {
  1120. system("cls");
  1121. printf("0.Back to Main Menu\n");
  1122. printf("\n\n\n Add new employee ");
  1123. printf("\n\n\n\n First Name: ");
  1124. GetValidatedString(AllStaff[*NumStaffAcc].Name, 1, MAX_LEN_NAME);
  1125. if (strcmp(AllStaff[*NumStaffAcc].Name, "0") == 0) { system("cls"); return; }
  1126.  
  1127. printf("\n Last Name: ");
  1128. GetValidatedString(AllStaff[*NumStaffAcc].Surname, 1, MAX_LEN_NAME);
  1129. if (strcmp(AllStaff[*NumStaffAcc].Surname, "0") == 0) { system("cls"); return; }
  1130.  
  1131. printf("\n Date of birth in format 99/99/9999: ");
  1132. GetValidatedString(AllStaff[*NumStaffAcc].DOB, 1, MAX_LEN_DATE);
  1133. if (strcmp(AllStaff[*NumStaffAcc].DOB, "0") == 0) { system("cls"); return; }
  1134.  
  1135. printf("\n Home address: ");
  1136. GetValidatedString(AllStaff[*NumStaffAcc].Address, 1, MAX_LEN_ADDRESS);
  1137. if (strcmp(AllStaff[*NumStaffAcc].Address, "0") == 0) { system("cls"); return; }
  1138.  
  1139. printf("\n City: ");
  1140. GetValidatedString(AllStaff[*NumStaffAcc].City, 1, MAX_LEN_CITY);
  1141. if (strcmp(AllStaff[*NumStaffAcc].City, "0") == 0) { system("cls"); return; }
  1142.  
  1143. printf("\n Postcode: ");
  1144. GetValidatedString(AllStaff[*NumStaffAcc].Postcode, 1, MAX_LEN_POSTCODE);
  1145. if (strcmp(AllStaff[*NumStaffAcc].Postcode, "0") == 0) { system("cls"); return; }
  1146.  
  1147. printf("\n Job Title: ");
  1148. GetValidatedString(AllStaff[*NumStaffAcc].JobTitle, 1, MAX_LEN_TITLE);
  1149. if (strcmp(AllStaff[*NumStaffAcc].JobTitle, "0") == 0) { system("cls"); return; }
  1150.  
  1151. printf("\n Department: ");
  1152. GetValidatedString(AllStaff[*NumStaffAcc].Department, 1, MAX_LEN_DEPARTMENT);
  1153. if (strcmp(AllStaff[*NumStaffAcc].Department, "0") == 0) { system("cls"); return; }
  1154.  
  1155. printf("\n Start date in format 99/99/9999: ");
  1156. GetValidatedString(AllStaff[*NumStaffAcc].StartDate, 1, MAX_LEN_DATE);
  1157. if (strcmp(AllStaff[*NumStaffAcc].StartDate, "0") == 0) { system("cls"); return; }
  1158.  
  1159. printf("\n Choose pay grade from below: ");
  1160.  
  1161. int Choice = 0;
  1162.  
  1163. GradeMenu();
  1164.  
  1165. Choice = GetValidatedInteger(1, 3);
  1166.  
  1167. switch (Choice)
  1168. {
  1169. case 1:
  1170. AllStaff[*NumStaffAcc].PayGrade = GRADE1;
  1171. break;
  1172. case 2:
  1173. AllStaff[*NumStaffAcc].PayGrade = GRADE2;
  1174. break;
  1175. case 3:
  1176. AllStaff[*NumStaffAcc].PayGrade = GRADE3;
  1177. break;
  1178. }
  1179.  
  1180. printf("\n Login: ");
  1181. GetValidatedString(AllStaff[*NumStaffAcc].Login, 1, MAX_LEN_EMAIL);
  1182. if (strcmp(AllStaff[*NumStaffAcc].Login, "0") == 0) { system("cls"); return; }
  1183.  
  1184. printf("\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  1185. printf("\n\n Password: ");
  1186. char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
  1187. Password(TemporaryPass);
  1188. strcpy_s(AllStaff[*NumStaffAcc].Password, MAX_LEN_PASSWORD, TemporaryPass);
  1189.  
  1190. AllStaff[*NumStaffAcc].Lock = 0;
  1191. AllStaff[*NumStaffAcc].Admin = 1;
  1192. (*NumStaffAcc)++;
  1193.  
  1194. printf("\n\n\n\n\n\n Press Enter to finish.");
  1195. getchar();
  1196. system("cls");
  1197. }
  1198. void DisplayStaffAll(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1199. {
  1200. //this function display added records
  1201. system("cls");
  1202. if (NumStaffAcc == 0) //check if number of records is equal 0
  1203. {
  1204. printf("\n\n\n");
  1205. printf("\n\nNo records to display! Add records first!");
  1206. }
  1207. else
  1208. {
  1209. DisplayStaff(AllStaff, NumStaffAcc);
  1210. printf("\n\n\nClick ENTER to go back to menu.");
  1211.  
  1212. getchar();
  1213. }
  1214.  
  1215. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
  1216. COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
  1217. c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
  1218. c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
  1219. SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
  1220.  
  1221. SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
  1222. sr.Left = 0; // na zero
  1223. sr.Top = 0; // na zero
  1224. sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
  1225. sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
  1226. SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
  1227.  
  1228. }
  1229. void DisplayStaff(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1230. {
  1231. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
  1232. COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
  1233. c2.X = 180; // szerokoœæ na 120 szerokoœci znaków
  1234. c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
  1235. SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
  1236.  
  1237. SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
  1238. sr.Left = 0; // na zero
  1239. sr.Top = 0; // na zero
  1240. sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
  1241. sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
  1242. SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
  1243.  
  1244.  
  1245. printf("\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
  1246. printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1247. int i = 0; //counter for number of records in the for loop
  1248. for (i = 0; i < *NumStaffAcc; i++) //displaying all records (till i gain the same vaue as num of records)
  1249. {
  1250. printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
  1251. , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
  1252. }
  1253. }
  1254. void GradeMenu()
  1255. {
  1256. printf(" \n\n GRADES SYSTEM");
  1257. printf("\n 1. GRADE 1 - %c%1.2f", POUND_SIGN, GRADE1);
  1258. printf("\n 2. GRADE 2 - %c%d", POUND_SIGN, GRADE2);
  1259. printf("\n 3. GRADE 3 - %c%1.2f", POUND_SIGN, GRADE3);
  1260.  
  1261. printf("\n\n Your choice: ");
  1262.  
  1263. }
  1264.  
  1265. void SearchRecords(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData)
  1266. {
  1267.  
  1268. int ChooseMenu;
  1269.  
  1270. system("cls");
  1271.  
  1272. if (NumStaffAcc == 0)
  1273. {
  1274. printf("\n\n\n");
  1275. printf("\n\nNo employees records to display! Add employee first!");
  1276. printf("\n\nClick ENTER to continue.");
  1277. getchar();
  1278. }
  1279. else
  1280. {
  1281. ChoiceMenu();
  1282. ChooseMenu = GetValidatedInteger(1, 5); // selection in the menu, switch
  1283. system("cls");
  1284. switch (ChooseMenu)
  1285. {
  1286. case 1:
  1287. SearchRecordsSurname(AllStaff, NumStaffAcc);
  1288. getchar();
  1289. break;
  1290. case 2:
  1291. //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); start date
  1292. getchar();
  1293. break;
  1294. case 3:
  1295. //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); title
  1296. getchar();
  1297. break;
  1298. case 4:
  1299. //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); grade
  1300. getchar();
  1301. break;
  1302. case 5:
  1303. ManageStaff(AllStaff, NumStaffAcc, WhatData);
  1304. break;
  1305. }
  1306. }
  1307. }
  1308.  
  1309. void ChoiceMenu()
  1310. {
  1311. printf("\n%-5s%-20s", "1.", "Search employee by surname.");
  1312. printf("\n%-5s%-20s", "2.", "Display all employees by start date.");
  1313. printf("\n%-5s%-20s", "3.", "Display all employees by job title.");
  1314. printf("\n%-5s%-20s", "4.", "Display all employees by pay grade.");
  1315. printf("\n%-5s%-20s", "5.", "Go back to menu.");
  1316. printf("\n\nYour choice: ");
  1317. }
  1318.  
  1319. void SearchRecordsSurname(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1320. {
  1321. int MatchSurname = 0;
  1322. char CheckAnother;
  1323. int i = 0;
  1324. char Surname[MAX_LEN_SURNAME + 1];
  1325. do //do-while loop - captures the integer and store it in "i" variable.
  1326. {
  1327. MatchSurname = 0; // integer set up to make sure we will not have repeated results.
  1328. printf("\nSearch by employee's surname.");
  1329. printf("\nEnter the surname: ");
  1330.  
  1331.  
  1332. GetValidatedString(Surname, 1, MAX_LEN_SURNAME); // getting surname that program will look for from the user
  1333.  
  1334. for (i = 0; i < *NumStaffAcc; i++)
  1335. {
  1336. if (_strcmpi(Surname, AllStaff[i].Surname) == 0) //checking if searched surname exist in the records
  1337. {
  1338. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
  1339. COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
  1340. c2.X = 180; // szerokoœæ na 120 szerokoœci znaków
  1341. c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
  1342. SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
  1343.  
  1344. SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
  1345. sr.Left = 0; // na zero
  1346. sr.Top = 0; // na zero
  1347. sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
  1348. sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
  1349. SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
  1350.  
  1351. system("cls");
  1352. printf("\nEmployees with surname: %s", AllStaff[i].Surname);
  1353.  
  1354. printf("\n\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
  1355. printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1356.  
  1357. printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
  1358. , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
  1359.  
  1360. MatchSurname++; // increment matchsurname
  1361. }
  1362. }
  1363.  
  1364. if (MatchSurname == 0) // no matches
  1365. {
  1366. system("cls");
  1367. printf("\nThere is no employee with this surname in the system!");
  1368. printf("\n\nClick ENTER to continue.");
  1369. }
  1370. else //found match
  1371. {
  1372. printf("\n\nFounded %d match", MatchSurname);
  1373. }
  1374.  
  1375. printf("\n\n\n Do you want to check another record (Y/N) ?"); // adding another record
  1376. CheckAnother = GetValidatedYesNo();
  1377.  
  1378.  
  1379. } while (CheckAnother == 'Y'); // loop as many times as true, if false stop
  1380.  
  1381. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
  1382. COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
  1383. c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
  1384. c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
  1385. SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
  1386.  
  1387. SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
  1388. sr.Left = 0; // na zero
  1389. sr.Top = 0; // na zero
  1390. sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
  1391. sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
  1392. SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
  1393. }
  1394.  
  1395. char StaffAccDetailsUpdate()
  1396. {
  1397. Sleep(100);
  1398. system("cls");
  1399. printf("\n\n\n\n\n\n\n\n\n\n\n The data has been updated.");
  1400. Sleep(1500);
  1401. system("cls");
  1402. char Reply;
  1403. printf("\n\n\n\n\n\n\n\n\n\n\n Do you want to do more updates? (Y/N)");
  1404. Reply = GetValidatedYesNo();
  1405. Sleep(100);
  1406. return Reply;
  1407. }
  1408. void UpdateRecords(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1409. {
  1410. system("cls");
  1411. int RecordChoice = 0;
  1412. int MenuChoice = 0;
  1413. int i = 0;
  1414.  
  1415. printf("\n\n\n");
  1416. if (NumStaffAcc == 0)
  1417. {
  1418. printf("\n\nNo records to display! Add records first!");
  1419. printf("\n\nClick ENTER to continue.");
  1420. getchar();
  1421. }
  1422. else
  1423. {
  1424. do
  1425. {
  1426. printf("\n\n");
  1427. DisplayStaff(AllStaff, NumStaffAcc);
  1428. printf("\nProvide by number, which record you want to update and press ENTER to continue: ");
  1429. printf("\nYour choice: ");
  1430. RecordChoice = GetValidatedInteger(0, MAX_NUM_STAFF); //choosing which record you want to update
  1431. system("cls");
  1432.  
  1433.  
  1434. system("cls");
  1435. printf("0.Back to records\n");
  1436. printf("\n\n\n What do you want to change?");
  1437. printf("\n\n\n\n 1. First name\n");
  1438. printf("\n 2. Last name\n");
  1439. printf("\n 3. Date of birth\n");
  1440. printf("\n 4. Address\n");
  1441. printf("\n 5. City\n");
  1442. printf("\n 6. Postcode\n");
  1443. printf("\n 7. Job title\n");
  1444. printf("\n 8. Departhemt\n");
  1445. printf("\n 9. Start date\n");
  1446. printf("\n 10. Pay grade\n");
  1447. printf("\n 11. Login\n");
  1448. printf("\n 12. Password\n");
  1449.  
  1450. MenuChoice = GetValidatedInteger(0, 12);
  1451.  
  1452. Sleep(100);
  1453. switch (MenuChoice)
  1454. {
  1455. case 1:
  1456. {
  1457. system("cls");
  1458. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new first name?\n");
  1459. printf("\n --> ");
  1460. GetValidatedString(AllStaff[RecordChoice - 1].Name, 1, MAX_LEN_NAME);
  1461. if (StaffAccDetailsUpdate() == 'N') return;
  1462. break;
  1463. }
  1464. case 2:
  1465. {
  1466. system("cls");
  1467. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new surname?\n");
  1468. printf("\n --> ");
  1469. GetValidatedString(AllStaff[RecordChoice - 1].Surname, 1, MAX_LEN_NAME);
  1470. if (StaffAccDetailsUpdate() == 'N') return;
  1471. break;
  1472. }
  1473. case 3:
  1474. {
  1475. system("cls");
  1476. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new date of birth?\n");
  1477. printf("\n --> ");
  1478. GetValidatedString(AllStaff[RecordChoice - 1].DOB, 1, MAX_LEN_DATE);
  1479. if (StaffAccDetailsUpdate() == 'N') return;
  1480. break;
  1481. }
  1482. case 4:
  1483. {
  1484. system("cls");
  1485. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new address?\n");
  1486. printf("\n --> ");
  1487. GetValidatedString(AllStaff[RecordChoice - 1].Address, 1, MAX_LEN_ADDRESS);
  1488. if (StaffAccDetailsUpdate() == 'N') return;
  1489. break;
  1490. }
  1491. break;
  1492. case 5:
  1493. {
  1494. system("cls");
  1495. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new city?\n");
  1496. printf("\n --> ");
  1497. GetValidatedString(AllStaff[RecordChoice - 1].City, 1, MAX_LEN_CITY);
  1498. if (StaffAccDetailsUpdate() == 'N') return;
  1499. break;
  1500. }
  1501. case 6:
  1502. {
  1503. system("cls");
  1504. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new postcode\n");
  1505. printf("\n --> ");
  1506. GetValidatedString(AllStaff[RecordChoice - 1].Postcode, 1, MAX_LEN_POSTCODE);
  1507. if (StaffAccDetailsUpdate() == 'N') return;
  1508. break;
  1509. }
  1510. case 7:
  1511. {
  1512. system("cls");
  1513. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new job title\n");
  1514. printf("\n --> ");
  1515. GetValidatedString(AllStaff[RecordChoice - 1].JobTitle, 1, MAX_LEN_TITLE);
  1516. if (StaffAccDetailsUpdate() == 'N') return;
  1517. break;
  1518. }
  1519. case 8:
  1520. {
  1521. system("cls");
  1522. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new department\n");
  1523. printf("\n --> ");
  1524. GetValidatedString(AllStaff[RecordChoice - 1].Department, 1, MAX_LEN_DEPARTMENT);
  1525. if (StaffAccDetailsUpdate() == 'N') return;
  1526. break;
  1527. }
  1528. case 9:
  1529. {
  1530. system("cls");
  1531. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new start date?\n");
  1532. printf("\n --> ");
  1533. GetValidatedString(AllStaff[RecordChoice - 1].StartDate, 1, MAX_LEN_DATE);
  1534. if (StaffAccDetailsUpdate() == 'N') return;
  1535. break;
  1536. }
  1537. case 10:
  1538. {
  1539. system("cls");
  1540. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new pay grade?\n");
  1541. printf("\n --> ");
  1542. int Choice = 0;
  1543.  
  1544. GradeMenu();
  1545.  
  1546. Choice = GetValidatedInteger(1, 3);
  1547.  
  1548. switch (Choice)
  1549. {
  1550. case 1:
  1551. AllStaff[*NumStaffAcc].PayGrade = GRADE1;
  1552. break;
  1553. case 2:
  1554. AllStaff[*NumStaffAcc].PayGrade = GRADE2;
  1555. break;
  1556. case 3:
  1557. AllStaff[*NumStaffAcc].PayGrade = GRADE3;
  1558. break;
  1559. }
  1560. if (StaffAccDetailsUpdate() == 'N') return;
  1561. break;
  1562. }
  1563.  
  1564. case 11:
  1565. {
  1566. system("cls");
  1567. printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new login?\n");
  1568. printf("\n --> ");
  1569. GetValidatedString(AllStaff[RecordChoice - 1].Login, 1, MAX_LEN_EMAIL);
  1570. if (StaffAccDetailsUpdate() == 'N') return;
  1571. break;
  1572. }
  1573.  
  1574. case 12:
  1575. {
  1576. char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
  1577. system("cls");
  1578. printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  1579. printf("\n\n What is your new password?\n");
  1580. printf("\n --> ");
  1581. Password(TemporaryPass);
  1582. strcpy_s(AllStaff[RecordChoice - 1].Password, MAX_LEN_PASSWORD, TemporaryPass);
  1583. }
  1584. case 0:
  1585. system("cls");
  1586. break;
  1587. }
  1588.  
  1589. } while (MenuChoice != '0');
  1590. }
  1591. }
  1592.  
  1593. void StaffHoliday(struct StaffAccount AllStaff[], int *NumStaffAcc)
  1594. {
  1595. int i = 0;
  1596. int TableMenu;
  1597. char AddAnother ="";
  1598. char DeleteNewRecord = '\0';
  1599. int Record = 0;
  1600. system("cls");
  1601. printf("0.Back to Main Menu\n");
  1602.  
  1603. if (NumStaffAcc == 0)
  1604. {
  1605. printf("\nPlease type in a new record!");
  1606. getchar();
  1607. }
  1608.  
  1609. else
  1610. {
  1611.  
  1612. printf("\n%-5s%-20s", "1.", "Add Holiday");
  1613. printf("\n%-5s%-20s", "2.", "Display all holidays");
  1614. printf("\n%-5s%-20s", "3.", "Delete holiday");
  1615. printf("\n\n Enter your choice: ");
  1616. TableMenu = GetValidatedInteger(1, 4);
  1617. switch (TableMenu)
  1618. {
  1619. case 1:
  1620. printf("\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
  1621. printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1622. do {
  1623. for (int i = 0; i < NumStaffAcc; i++)
  1624.  
  1625. printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
  1626. , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
  1627.  
  1628.  
  1629. printf("\nChoose employee to book holiday : ");
  1630. Record = GetValidatedInteger(0, MAX_NUM_STAFF);
  1631.  
  1632. printf("\Enter the start date of the employee holiday");
  1633. GetValidatedString(AllStaff[i].Start_date, 1, START_DATE);
  1634.  
  1635. printf("\Enter the end date of the employee holiday");
  1636. GetValidatedString(AllStaff[i].End_date, 1, END_DATE);
  1637.  
  1638.  
  1639. /*if (AddAnother == 'N')
  1640. {
  1641. DisplayRecordsSelected(AllStaff, NumStaffAcc);
  1642. }*/
  1643. } while (AddAnother == 'Y');
  1644.  
  1645.  
  1646. break;
  1647. case 2:
  1648.  
  1649. if (*NumStaffAcc == 0)
  1650. {
  1651. printf("\nPlease type in a new record");
  1652. getchar();
  1653. }
  1654. else
  1655. {
  1656. printf("\n%-5s%-15s%-25s%-15s%-25s%", "NO", "FIRST NAME", "LAST NAME", "Start date", "End date");
  1657. printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1658.  
  1659. for (i = 0; i < NumStaffAcc; i++)
  1660. {
  1661. printf("\n\n%-5d%-15s%-25s%-15s%-25s%", i + 1, AllStaff[i].Name, AllStaff[i].Surname, AllStaff[i].Start_date, AllStaff[i].End_date);
  1662. }
  1663.  
  1664. getchar();
  1665. }
  1666. break;
  1667. case 3:
  1668. if (NumStaffAcc == 0)
  1669. {
  1670. printf("\nPlease type in a new record");
  1671. getchar();
  1672. }
  1673. else
  1674. {
  1675. do
  1676. {
  1677. system("cls");
  1678. printf("\n%-5s%-15s%-25s%-15s%-25s%", "NO", "FIRST NAME", "LAST NAME", "Start date", "End date");
  1679. printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
  1680.  
  1681. for (int i = 0; i <= (NumStaffAcc - 1); i++)
  1682. printf("\n\n%-5d%-15s%-25s%-15s%-25s%", i + 1, AllStaff[i].Name, AllStaff[i].Surname, AllStaff[i].Start_date, AllStaff[i].End_date);
  1683.  
  1684. printf("\nEnter the record number that you want to delete: ");
  1685. Record = GetValidatedInteger(0, MAX_NUM_STAFF);
  1686.  
  1687. AllStaff[Record - 1] = AllStaff[*NumStaffAcc - 1];
  1688. (*NumStaffAcc);
  1689.  
  1690. printf("\n Do you want to delete another record (Y/N) ?: ");
  1691. DeleteNewRecord = GetValidatedYesNo();
  1692.  
  1693. if (NumStaffAcc == 0)
  1694. {
  1695. system("cls");
  1696. printf("\nNo more records to delete");
  1697. getchar();
  1698.  
  1699. }
  1700. } while (DeleteNewRecord == 'Y' && *NumStaffAcc > 0);
  1701. }
  1702. }
  1703.  
  1704. }
  1705. }
  1706. void AdminAccLayout(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck)
  1707. {
  1708. int MenuChoice = 0;
  1709.  
  1710. do
  1711. {
  1712. system("cls");
  1713. printf(" 1.LogOut\n");
  1714. printf("\n\n\n Hello");
  1715. printf("\n\n\n\n 2. Manage destinations\n");
  1716. printf("\n 3. Manage employees details\n");
  1717. printf("\n 4. Manage customers\n");
  1718. printf("\n 5. ..............\n");
  1719. MenuChoice = _getch();
  1720. Sleep(100);
  1721. switch (MenuChoice)
  1722. {
  1723. case '1':
  1724. (*WhatData) = -1;
  1725. Sleep(150);
  1726. (*LogInCheck) = 0;
  1727. system("cls");
  1728. return;
  1729. break;
  1730. case '2':
  1731. ManageDestinations(AllCities, NumOfCities);
  1732. break;
  1733. case '3':
  1734. ManageStaff(AllStaff, NumStaffAcc, WhatData);
  1735. break;
  1736. case '4':
  1737. break;
  1738. case '5':
  1739. break;
  1740. }
  1741. } while (MenuChoice != '1');
  1742. }
  1743. void ManageStaff(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData)
  1744. {
  1745.  
  1746. int MenuChoice = 0;
  1747.  
  1748. do
  1749. {
  1750. system("cls");
  1751. printf("0.Back to account page\n");
  1752. printf("\n\n\n");
  1753. printf("\n\n\n\n 2. Add new employee\n");
  1754. printf("\n 3. Display all employees\n");
  1755. printf("\n 4. Search by\n");
  1756. printf("\n 5. Upadate employee details\n");
  1757. printf("\n 6. Probation\n");
  1758. printf("\n 7. Holidays\n");
  1759. printf("\n 8. Payroll\n");
  1760.  
  1761. MenuChoice = _getch();
  1762. Sleep(100);
  1763. switch (MenuChoice)
  1764. {
  1765. case '2':
  1766. CreateStaffAcc(AllStaff, NumStaffAcc);
  1767. break;
  1768. case '3':
  1769. DisplayStaffAll(AllStaff, NumStaffAcc);
  1770. break;
  1771. case '4':
  1772. SearchRecords(AllStaff, NumStaffAcc, WhatData);
  1773. break;
  1774. case '5':
  1775. UpdateRecords(AllStaff, NumStaffAcc);
  1776. break;
  1777. case '6':
  1778. //UpdateRecords(AllStaff, NumStaffAcc);
  1779. break;
  1780. case '7':
  1781. StaffHoliday(AllStaff, NumStaffAcc);
  1782. break;
  1783. case '8':
  1784. //UpdateRecords(AllStaff, NumStaffAcc);
  1785. break;
  1786. case '0':
  1787. system("cls");
  1788. break;
  1789. }
  1790. } while (MenuChoice != '0');
  1791. }
  1792. void ManageDestinations(struct City_Country AllCities[], int *NumOfCities)
  1793. {
  1794. int MenuChoice = 0;
  1795.  
  1796. do
  1797. {
  1798. system("cls");
  1799. printf("0.Back to account page\n\n\n\n");
  1800. printf("\n\n\n\n 2. Add new city\n");
  1801. printf("\n 3. Update city details\n");
  1802. printf("\n 4. Delete city\n");
  1803. MenuChoice = _getch();
  1804. Sleep(100);
  1805. switch (MenuChoice)
  1806. {
  1807. case '2':
  1808. system("cls");
  1809. printf("0.Back to account page\n\n\n\n");
  1810. printf(" Add new destination ");
  1811.  
  1812. printf("\n\n\n\n Name of the city: ");
  1813. GetValidatedString(AllCities[*NumOfCities].City, 1, MAX_LEN_CITY);
  1814. if (strcmp(AllCities[*NumOfCities].City, "0") == 0) { system("cls"); return; }
  1815.  
  1816. printf("\n Name of the country: ");
  1817. GetValidatedString(AllCities[*NumOfCities].Country, 1, MAX_LEN_CITY);
  1818. if (strcmp(AllCities[*NumOfCities].Country, "0") == 0) { system("cls"); return; }
  1819.  
  1820. printf("\n Airport code: ");
  1821. GetValidatedString(AllCities[*NumOfCities].AirportCode, 1, MAX_LEN_CODE);
  1822. if (strcmp(AllCities[*NumOfCities].AirportCode, "0") == 0) { system("cls"); return; }
  1823.  
  1824. printf("\n Place (1-10): ");
  1825. AllCities[*NumOfCities].Place = GetValidatedInteger(1, 10);
  1826. if (AllCities[*NumOfCities].Place == 0) { system("cls"); return; }
  1827.  
  1828. printf("\n Popularity (0-100): ");
  1829. AllCities[*NumOfCities].Popularity = GetValidatedInteger(0, 100);
  1830. if (AllCities[*NumOfCities].Popularity == 0) { system("cls"); return; }
  1831.  
  1832. printf("\n\n\n Press ENTER to go back to Main Menu.\n");
  1833. (*NumOfCities)++;
  1834. getchar();
  1835. system("cls");
  1836. break;
  1837. case '3':
  1838. {
  1839.  
  1840. int MenuChoice2 = 0;
  1841.  
  1842. do
  1843. {
  1844. system("cls");
  1845. printf("0.Back to previous page\n");
  1846. printf("\n\n\n What do you want to change?");
  1847. printf("\n\n\n\n 2. Name of the city\n");
  1848. printf("\n 3. Name of the country\n");
  1849. printf("\n 4. Airport code\n");
  1850. printf("\n 5. Place\n");
  1851. printf("\n 6. Popularity\n");
  1852. MenuChoice2 = _getch();
  1853. Sleep(100);
  1854. switch (MenuChoice2)
  1855. {
  1856. case '2':
  1857. break;
  1858. case '3':
  1859. break;
  1860. case '4':
  1861. break;
  1862. case '5':
  1863. break;
  1864. case '6':
  1865. break;
  1866. case '0':
  1867. system("cls");
  1868. break;
  1869. }
  1870. } while (MenuChoice != '0');
  1871. }
  1872. break;
  1873. case '4':
  1874. break;
  1875. case '0':
  1876. system("cls");
  1877. break;
  1878. }
  1879. } while (MenuChoice != '0');
  1880. }
  1881. void DisplayDestinations(struct City_Country AllCities[], int *NumOfCities)
  1882. {
  1883. system("cls");
  1884.  
  1885. printf("\n %-11s%-17s%-18s%-4s", "No.", "City", "Country", "IATA");
  1886. printf("\n ===== ========== ================= ======\n");
  1887.  
  1888. for (int i = 0; i < *NumOfCities; i++)
  1889. {
  1890. printf("\n %-9d%-15s%-22s%-4s\n", i+1, AllCities[i].City, AllCities[i].Country, AllCities[i].AirportCode);
  1891. }
  1892. printf("\n\n\n\n Press ENTER to go back to Main Menu.\n");
  1893. getchar();
  1894. system("cls");
  1895. }
  1896.  
  1897. ///// external files
  1898. int ReadAllRecordsFromFile(struct CustomerAccount AllRecords[], int NumCustomerAcc)
  1899. {
  1900. FILE *fp = NULL;
  1901.  
  1902. if (fopen_s(&fp, "CustomerAccount", "rb") != 0)
  1903. {
  1904. //printf("\nCannot find a file.");
  1905. return;
  1906. }
  1907.  
  1908. else
  1909. {
  1910. int Records;
  1911. Records = fread(AllRecords, sizeof(struct CustomerAccount), NumCustomerAcc, fp);
  1912. fclose(fp);
  1913. return(Records);
  1914. }
  1915. }
  1916. void SaveAllRecordsToFile(struct CustomerAccount AllRecords[], int NumCustomerAcc)
  1917. {
  1918.  
  1919. FILE *fp = NULL;
  1920.  
  1921. if (fopen_s(&fp, "CustomerAccount", "wb") != 0)
  1922. {
  1923. //printf("\nCannot find a file.");
  1924. return;
  1925. }
  1926.  
  1927. else
  1928. {
  1929. NumCustomerAcc = fwrite(AllRecords, sizeof(struct CustomerAccount), NumCustomerAcc, fp);
  1930. fclose(fp);
  1931. }
  1932.  
  1933. }
  1934.  
  1935. int ReadAllStaffFromFile(struct StaffAccount AllStaff[], int NumStaffAcc)
  1936. {
  1937. FILE *fp = NULL;
  1938.  
  1939. if (fopen_s(&fp, "StaffAccount", "rb") != 0)
  1940. {
  1941. //printf("\nCannot find a file.");
  1942. return;
  1943. }
  1944.  
  1945. else
  1946. {
  1947. int Records;
  1948. Records = fread(AllStaff, sizeof(struct StaffAccount), NumStaffAcc, fp);
  1949. fclose(fp);
  1950. return(Records);
  1951. }
  1952. }
  1953. void SaveAllStaffToFile(struct StaffAccount AllStaff[], int NumStaffAcc)
  1954. {
  1955.  
  1956. FILE *fp = NULL;
  1957.  
  1958. if (fopen_s(&fp, "StaffAccount", "wb") != 0)
  1959. {
  1960. //printf("\nCannot find a file.");
  1961. return;
  1962. }
  1963.  
  1964. else
  1965. {
  1966. NumStaffAcc = fwrite(AllStaff, sizeof(struct StaffAccount), NumStaffAcc, fp);
  1967. fclose(fp);
  1968. }
  1969.  
  1970. }
  1971.  
  1972. int ReadAllCitiesFromFile(struct City_Country AllCities[], int NumOfCities)
  1973. {
  1974. FILE *fp = NULL;
  1975.  
  1976. if (fopen_s(&fp, "Destinations", "rb") != 0)
  1977. {
  1978. //printf("\nCannot find a file.");
  1979. return;
  1980. }
  1981.  
  1982. else
  1983. {
  1984. int Records;
  1985. Records = fread(AllCities, sizeof(struct City_Country), NumOfCities, fp);
  1986. fclose(fp);
  1987. return(Records);
  1988. }
  1989. }
  1990. void SaveAllCitiesToFile(struct City_Country AllCities[], int NumOfCities)
  1991. {
  1992.  
  1993. FILE *fp = NULL;
  1994.  
  1995. if (fopen_s(&fp, "Destinations", "wb") != 0)
  1996. {
  1997. //printf("\nCannot find a file.");
  1998. return;
  1999. }
  2000.  
  2001. else
  2002. {
  2003. NumOfCities = fwrite(AllCities, sizeof(struct City_Country), NumOfCities, fp);
  2004. fclose(fp);
  2005. }
  2006.  
  2007. }
  2008.  
  2009. ///// login for customer and staff
  2010. void LogInCustomer(struct CustomerAccount AllRecords[], int NumCustomerAcc, int *LogInCheck, int *WhatData)
  2011. {
  2012. Sleep(100);
  2013. system("cls");
  2014.  
  2015. printf("0.Back to Main Menu\n");
  2016.  
  2017. //////////////////////////////////////////////////////////////////////EMAIL ADDRESS/////////////////////////////////////////////////////
  2018. printf("\n\n Email Address: ");
  2019. char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
  2020. int Counter = 1, Try = 3, Try2 = 3, RandomNumber1 = 0, RandomNumber2 = 0, RandomNumber3 = 0, StarsToDisplay = 0;
  2021. char MemPassCheck = "", First, Second, Third;
  2022.  
  2023. do
  2024. {
  2025. *WhatData = -1;
  2026. Counter = 1;
  2027. GetValidatedString(TemporaryEmail, 0, MAX_LEN_EMAIL);
  2028. if (strcmp(TemporaryEmail, "0") == 0) { system("cls"); return; }
  2029.  
  2030. if (_strcmpi(TemporaryEmail, AllRecords[0].Email) != 0) *WhatData = -1;
  2031. else *WhatData = 0;
  2032.  
  2033. for (int i = 1; i < NumCustomerAcc; i++)
  2034. {
  2035. if (_strcmpi(TemporaryEmail, AllRecords[i].Email) != 0)
  2036. {
  2037. Counter++;
  2038. }
  2039. else
  2040. {
  2041. *WhatData = Counter;
  2042. }
  2043. }
  2044.  
  2045.  
  2046. if (*WhatData == -1)
  2047. {
  2048. printf("\n\n It looks like this Email Address has not been used yet.\n");
  2049. printf(" Please retype your Email Address.\n");
  2050. Sleep(2400);
  2051. system("cls");
  2052. printf("0.Back to Main Menu\n");
  2053. printf("\n\n Email Address: ");
  2054. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  2055. {
  2056. TemporaryEmail[i] = NULL;
  2057. }
  2058. }
  2059. } while (*WhatData == -1);
  2060.  
  2061. if (AllRecords[*WhatData].Lock == 0)
  2062. {
  2063. //////////////////////////////////////////////////////////PASSWORD/////////////////////////////////////////////////////////////////////////
  2064. char Pass[2] = "";
  2065. char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
  2066. system("cls");
  2067. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2068. printf("\n\n Password: ");
  2069.  
  2070. do
  2071. {
  2072. StarsToDisplay = 0;
  2073. StarsToDisplay = Password(TemporaryPass2);
  2074.  
  2075. if (strcmp(TemporaryPass2, AllRecords[*WhatData].Password) != 0)
  2076. {
  2077. Try--; Try2--;
  2078. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  2079. {
  2080. TemporaryPass2[i] = NULL;
  2081. }
  2082. Pass[0] = NULL;
  2083. if (Try != 0) printf("\n\n Your password is incorrect. Please retype it.\n");
  2084. if (Try > 1) printf(" %d tries left.", Try);
  2085. else if (Try == 1) printf(" %d try left.", Try);
  2086. if (Try != 0) Sleep(2400);
  2087. system("cls");
  2088. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2089. printf("\n\n Password: ");
  2090. }
  2091. } while (Try != 0 && strcmp(TemporaryPass2, AllRecords[*WhatData].Password) != 0);
  2092.  
  2093. ///////////////////////////////////////////////////////////////Memorable Password///////////////////////////////////////////////////////////////////////////////////
  2094. if (Try == 0)
  2095. {
  2096. Try = 3;
  2097. int SizeOfMemPass = 0, i = 0;
  2098. srand(time(NULL));
  2099.  
  2100. while (AllRecords[*WhatData].MemorablePassword[i] != '\0')
  2101. {
  2102. SizeOfMemPass++;
  2103. i++;
  2104. }
  2105.  
  2106. if (SizeOfMemPass != 0)
  2107. {
  2108. do
  2109. {
  2110. system("cls");
  2111. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2112. printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
  2113. printf("\n Please enter three characters from your memorable password.\n");
  2114. if (Try > 1) printf("\n %d tries left.", Try);
  2115. else if (Try == 1) printf("\n %d try left.", Try);
  2116. Try--;
  2117. RandomNumber1 = rand() % SizeOfMemPass;
  2118. printf("\n\n %d.", RandomNumber1 + 1);
  2119. First = _getch();
  2120. printf("%c", First);
  2121.  
  2122. do
  2123. {
  2124. RandomNumber2 = rand() % SizeOfMemPass;
  2125.  
  2126. if (RandomNumber2 != RandomNumber1)
  2127. {
  2128. printf(" %d.", RandomNumber2 + 1);
  2129. Second = _getch();
  2130. printf("%c", Second);
  2131. }
  2132.  
  2133. } while (RandomNumber2 == RandomNumber1);
  2134.  
  2135. do
  2136. {
  2137. RandomNumber3 = rand() % SizeOfMemPass;
  2138.  
  2139. if (RandomNumber3 != RandomNumber1 && RandomNumber3 != RandomNumber2)
  2140. {
  2141. printf(" %d.", RandomNumber3 + 1);
  2142. Third = _getch();
  2143. printf("%c", Third);
  2144. Sleep(400);
  2145. }
  2146.  
  2147. } while (RandomNumber3 == RandomNumber1 || RandomNumber3 == RandomNumber2);
  2148.  
  2149. } while ((Try != 0) && (AllRecords[*WhatData].MemorablePassword[RandomNumber1] != First || AllRecords[*WhatData].MemorablePassword[RandomNumber2] != Second || AllRecords[*WhatData].MemorablePassword[RandomNumber3] != Third));
  2150. }
  2151. else Try = 0;
  2152. }
  2153. }
  2154. else
  2155. {
  2156. Try = 0;
  2157. }
  2158.  
  2159. if (Try == 0 && (AllRecords[*WhatData].MemorablePassword[RandomNumber1] != First || AllRecords[*WhatData].MemorablePassword[RandomNumber2] != Second || AllRecords[*WhatData].MemorablePassword[RandomNumber3] != Third))
  2160. {
  2161. if (AllRecords[*WhatData].Lock == 0)
  2162. {
  2163. char Code[15 + 1] = "";
  2164. RandomCode(Code, 7);
  2165.  
  2166. strcpy_s(AllRecords[*WhatData].Password, MAX_LEN_PASSWORD, Code);
  2167. AllRecords[*WhatData].Lock = 1;
  2168. for (int i = 0; i <= MAX_LEN_PASSWORD; i++)
  2169. {
  2170. AllRecords[*WhatData].MemorablePassword[i] = NULL;
  2171. }
  2172. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  2173. }
  2174.  
  2175. system("cls");
  2176. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2177. printf("\n\n\n\n\n\n Your account has been locked.");
  2178. printf("\n\n Please, write down the code which is down below.");
  2179. printf("\n Use it as a password during next loging in.");
  2180. printf("\n\n ---> %s <---\n", AllRecords[*WhatData].Password);
  2181. printf("\n\n\n\n\n\n\n\n Press ENTER to go back to Main Menu.\n");
  2182. getchar();
  2183. system("cls");
  2184. }
  2185. else
  2186. {
  2187. printf("\n\n\n 1. Keep me log in ( )\n");
  2188. printf("\n\n\n\n Press ENTER to log in.\n");
  2189. AllRecords[*WhatData].KeepLogin = 0;
  2190. Try++;
  2191. int KeepMeLogin = 0;
  2192. do
  2193. {
  2194. KeepMeLogin = 0;
  2195. KeepMeLogin = _getch();
  2196. if (KeepMeLogin == '1')
  2197. {
  2198. system("cls");
  2199. if (Try2 == 0)
  2200. {
  2201. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2202. printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
  2203. printf("\n Please enter three characters from your memorable password.\n");
  2204. if (Try > 1) printf("\n %d tries left.", Try);
  2205. else if (Try == 1) printf("\n %d try left.", Try);
  2206. else if (Try == 0) printf("\n %d try left.", Try);
  2207. printf("\n\n %d.", RandomNumber1 + 1); printf("%c", First);
  2208. printf(" %d.", RandomNumber2 + 1); printf("%c", Second);
  2209. printf(" %d.", RandomNumber3 + 1); printf("%c", Third);
  2210. }
  2211. else
  2212. {
  2213. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2214. printf("\n\n Password: ");
  2215. for (int i = 0; i < StarsToDisplay; i++)
  2216. {
  2217. printf("*");
  2218. }
  2219. }
  2220. printf("\n\n\n 1. Keep me log in (x)\n");
  2221. printf("\n\n\n\n Press ENTER to log in.\n");
  2222. AllRecords[*WhatData].KeepLogin = 1;
  2223.  
  2224. }
  2225.  
  2226. if (KeepMeLogin != 13)
  2227. {
  2228. KeepMeLogin = _getch();
  2229. if (KeepMeLogin == '1')
  2230. {
  2231. system("cls");
  2232. if (Try2 == 0)
  2233. {
  2234. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2235. printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
  2236. printf("\n Please enter three characters from your memorable password.\n");
  2237. if (Try > 1) printf("\n %d tries left.", Try);
  2238. else if (Try == 1) printf("\n %d try left.", Try);
  2239. else if (Try == 0) printf("\n %d try left.", Try);
  2240. printf("\n\n %d.", RandomNumber1 + 1); printf("%c", First);
  2241. printf(" %d.", RandomNumber2 + 1); printf("%c", Second);
  2242. printf(" %d.", RandomNumber3 + 1); printf("%c", Third);
  2243. }
  2244. else
  2245. {
  2246. printf("\n\n\n Email Address: %s", TemporaryEmail);
  2247. printf("\n\n Password: ");
  2248. for (int i = 0; i < StarsToDisplay; i++)
  2249. {
  2250. printf("*");
  2251. }
  2252. }
  2253. printf("\n\n\n 1. Keep me log in ( )\n");
  2254. printf("\n\n\n\n Press ENTER to log in.\n");
  2255. AllRecords[*WhatData].KeepLogin = 0;
  2256. }
  2257. }
  2258. } while (KeepMeLogin != 13);
  2259. SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
  2260. (*LogInCheck)++;
  2261.  
  2262. switch (AllRecords[*WhatData].Theme)
  2263. {
  2264. case 1:
  2265. system("color 70");
  2266. break;
  2267. case 2:
  2268. system("COLOR 67");
  2269. break;
  2270. case 3:
  2271. system("color 30");
  2272. break;
  2273. case 4:
  2274. system("color 07");
  2275. break;
  2276. }
  2277.  
  2278. system("cls");
  2279. }
  2280. }
  2281. void LogInStaff(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck)
  2282. {
  2283. Sleep(100);
  2284. system("cls");
  2285.  
  2286. char TemporaryLogin[MAX_LEN_EMAIL + 1] = "";
  2287. char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
  2288. int Try = 3, StarsToDisplay = 0;
  2289. int Counter = 1;
  2290.  
  2291. printf("0.Back to Main Menu\n");
  2292.  
  2293. ////////////////////////////////////////////////////////////////////// Login /////////////////////////////////////////////////////
  2294. printf("\n\n\n\n Login: ");
  2295. do
  2296. {
  2297. *WhatData = -1;
  2298. Counter = 1;
  2299. GetValidatedString(TemporaryLogin, 0, MAX_LEN_EMAIL);
  2300. if (strcmp(TemporaryLogin, "0") == 0) { system("cls"); return; }
  2301.  
  2302. if (_strcmpi(TemporaryLogin, AllStaff[0].Login) != 0) *WhatData = -1;
  2303. else *WhatData = 0;
  2304.  
  2305. for (int i = 1; i < *NumStaffAcc; i++)
  2306. {
  2307. if (_strcmpi(TemporaryLogin, AllStaff[i].Login) != 0)
  2308. {
  2309. Counter++;
  2310. }
  2311. else
  2312. {
  2313. *WhatData = Counter;
  2314. }
  2315. }
  2316.  
  2317.  
  2318. if (*WhatData == -1)
  2319. {
  2320. printf("\n\n It looks like this login has not been used yet.\n");
  2321. printf(" Please retype your login or contact your manager.\n");
  2322. Sleep(2400);
  2323. system("cls");
  2324. printf("0.Back to Main Menu\n");
  2325. printf("\n\n\n\n Login: ");
  2326. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  2327. {
  2328. TemporaryLogin[i] = NULL;
  2329. }
  2330. }
  2331. } while (*WhatData == -1);
  2332.  
  2333. if (AllStaff[*WhatData].Lock == 0)
  2334. {
  2335. //////////////////////////////////////////////////////////PASSWORD/////////////////////////////////////////////////////////////////////////
  2336. char Pass[2] = "";
  2337. system("cls");
  2338. printf("\n\n\n\n\n Login: %s", TemporaryLogin);
  2339. printf("\n\n Password: ");
  2340.  
  2341. do
  2342. {
  2343. StarsToDisplay = 0;
  2344. StarsToDisplay = Password(TemporaryPass);
  2345.  
  2346. if (strcmp(TemporaryPass, AllStaff[*WhatData].Password) != 0)
  2347. {
  2348. Try--;
  2349. for (int i = 0; i < MAX_LEN_PASSWORD; i++)
  2350. {
  2351. TemporaryPass[i] = NULL;
  2352. }
  2353. Pass[0] = NULL;
  2354. if (Try != 0) printf("\n\n Your password is incorrect. Please retype it.\n");
  2355. if (Try > 1) printf(" %d tries left.", Try);
  2356. else if (Try == 1) printf(" %d try left.", Try);
  2357. if (Try != 0) Sleep(2400);
  2358. system("cls");
  2359. printf("\n\n\n\n\n Login: %s", TemporaryLogin);
  2360. printf("\n\n Password: ");
  2361. }
  2362. } while (Try != 0 && strcmp(TemporaryPass, AllStaff[*WhatData].Password) != 0);
  2363. }
  2364. else
  2365. {
  2366. Try = 0;
  2367. }
  2368. if (Try == 0)
  2369. {
  2370. AllStaff[*WhatData].Lock = 1;
  2371. SaveAllStaffToFile(AllStaff, NumStaffAcc);
  2372. system("cls");
  2373. printf("\n\n\n\n\n Login: %s", TemporaryLogin);
  2374. printf("\n\n\n\n\n\n Your account has been locked.");
  2375. printf("\n Please contact your manager to reset your password.");
  2376. printf("\n\n\n\n\n\n\n\n Press ENTER to go back to Main Menu.\n");
  2377. getchar();
  2378. system("cls");
  2379. }
  2380. else
  2381. {
  2382. if (AllStaff[*WhatData].Admin == 1)
  2383. {
  2384. Sleep(500);
  2385. AdminAccLayout(AllStaff, AllCities, NumStaffAcc, NumOfCities, WhatData, LogInCheck);
  2386. }
  2387. //else
  2388.  
  2389. }
  2390.  
  2391. }
  2392.  
  2393. ///// customer account functions
  2394. void CustomerAccLayout(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *LogInCheck)
  2395. {
  2396. int MenuChoice = 0, Delete = 0;
  2397.  
  2398. do
  2399. {
  2400. if (Delete != 0) { system("cls"); *LogInCheck = 0; return; }
  2401. system("cls");
  2402. printf("0.Back to Main Menu 1.LogOut\n");
  2403. printf("\n\n\n Hello, %s", AllRecords[*WhatData].Name);
  2404. printf("\n\n\n\n 2. Manage your flights\n");
  2405. printf("\n 3. Change your personal details\n");
  2406. printf("\n 4. Manage credit card details\n");
  2407. printf("\n 5. Manage account\n");
  2408. MenuChoice = _getch();
  2409. Sleep(100);
  2410. switch (MenuChoice)
  2411. {
  2412. case '1':
  2413. AllRecords[*WhatData].KeepLogin = 0;
  2414. (*WhatData) = -1;
  2415. Sleep(150);
  2416. (*LogInCheck) = 0;
  2417. system("color 07");
  2418. system("cls");
  2419. return;
  2420. break;
  2421. case '2':
  2422. break;
  2423. case '3':
  2424. CustomerAccPersonalDeatils(AllRecords, NumCustomerAcc, WhatData);
  2425. break;
  2426. case '4':
  2427. CustomerAccManageCard(AllRecords, NumCustomerAcc, WhatData);
  2428. break;
  2429. case '5':
  2430. CustomerAccManageAcc(AllRecords, NumCustomerAcc, WhatData, &Delete);
  2431. break;
  2432. case '0':
  2433. system("cls");
  2434. break;
  2435. }
  2436. } while (MenuChoice != '0');
  2437. }
  2438. void CustomerAccPersonalDeatils(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData)
  2439. {
  2440. int MenuChoice = 0;
  2441. do
  2442. {
  2443. system("cls");
  2444. printf("0.Back to account page\n");
  2445. printf("\n\n\n What do you want to change?");
  2446. printf("\n\n\n\n 1. First name\n");
  2447. printf("\n 2. Last name\n");
  2448. printf("\n 3. Email address\n");
  2449. printf("\n 4. Password\n");
  2450. printf("\n 5. Memorable Password\n");
  2451.  
  2452. MenuChoice = _getch();
  2453. Sleep(100);
  2454. switch (MenuChoice)
  2455. {
  2456. case '1':
  2457. {
  2458. system("cls");
  2459. printf("\n\n\n\n\n\n\n\n\n\n\n What is your new first name?\n");
  2460. printf("\n --> ");
  2461. GetValidatedString(AllRecords[*WhatData].Name, 1, MAX_LEN_NAME);
  2462. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2463. break;
  2464. }
  2465. case '2':
  2466. {
  2467. system("cls");
  2468. printf("\n\n\n\n\n\n\n\n\n\n\n What is your new surname?\n");
  2469. printf("\n --> ");
  2470. GetValidatedString(AllRecords[*WhatData].Surname, 1, MAX_LEN_NAME);
  2471. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2472. break;
  2473. }
  2474. case '3':
  2475. {
  2476. char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
  2477. int At = 0, Dot = 0, Counter = 0;
  2478.  
  2479. do
  2480. {
  2481. system("cls");
  2482. printf("\n\n\n\n\n\n\n\n\n\n\n What is your new email address?\n");
  2483. printf("\n --> ");
  2484.  
  2485. GetValidatedString(TemporaryEmail, 1, MAX_LEN_EMAIL);
  2486.  
  2487. Email(AllRecords, TemporaryEmail, NumCustomerAcc, &At, &Dot, &Counter);
  2488.  
  2489. } while (Counter != *NumCustomerAcc || At == 0 || At > 1 || Dot == 0);
  2490.  
  2491. strcpy_s(AllRecords[*WhatData].Email, MAX_LEN_EMAIL, TemporaryEmail);
  2492.  
  2493. for (int i = 0; i < MAX_LEN_EMAIL; i++)
  2494. {
  2495. TemporaryEmail[i] = NULL;
  2496. }
  2497. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2498. break;
  2499. }
  2500. case '4':
  2501. {
  2502. char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
  2503. system("cls");
  2504. printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  2505. printf("\n\n What is your new password?\n");
  2506. printf("\n --> ");
  2507. Password(TemporaryPass);
  2508. strcpy_s(AllRecords[*WhatData].Password, MAX_LEN_PASSWORD, TemporaryPass);
  2509. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2510. }
  2511. break;
  2512. case '5':
  2513. {
  2514. char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
  2515. system("cls");
  2516. printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
  2517. printf("\n\n What is your new memorable password?\n");
  2518. printf("\n --> ");
  2519. Password(TemporaryPass2);
  2520. strcpy_s(AllRecords[*WhatData].MemorablePassword, MAX_LEN_PASSWORD, TemporaryPass2);
  2521. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2522. break;
  2523. }
  2524. case '0':
  2525. system("cls");
  2526. break;
  2527. }
  2528. } while (MenuChoice != '0');
  2529. }
  2530. char CustomerAccPersonalDetailsUpdate()
  2531. {
  2532. Sleep(100);
  2533. system("cls");
  2534. printf("\n\n\n\n\n\n\n\n\n\n\n The data has been updated.");
  2535. Sleep(1500);
  2536. system("cls");
  2537. char Reply;
  2538. printf("\n\n\n\n\n\n\n\n\n\n\n Do you want to do more updates? (Y/N)");
  2539. Reply = GetValidatedYesNo();
  2540. Sleep(100);
  2541. return Reply;
  2542. }
  2543. void CustomerAccManageAcc(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *Delete)
  2544. {
  2545. int MenuChoice = 0;
  2546. do
  2547. {
  2548. system("cls");
  2549. printf("0.Back to account page\n");
  2550. printf("\n\n\n What do you want to do?");
  2551. printf("\n\n\n\n 1. Change theme\n");
  2552. printf("\n 2. Delete account\n");
  2553.  
  2554. MenuChoice = _getch();
  2555. Sleep(100);
  2556. switch (MenuChoice)
  2557. {
  2558. case '1':
  2559. {
  2560. system("cls");
  2561. printf("0.Back to previous page\n");
  2562. printf("\n\n\n Choose your theme:");
  2563. printf("\n\n\n\n 1. Grey background\n");
  2564. printf("\n 2. Yellow background\n");
  2565. printf("\n 3. Light blue background\n");
  2566. printf("\n 4. Default\n");
  2567. int ThemeChoice = 0;
  2568. ThemeChoice = _getch();
  2569. if (ThemeChoice != '0')
  2570. {
  2571. Sleep(100);
  2572. switch (ThemeChoice)
  2573. {
  2574. case '1':
  2575. system("color 70");
  2576. AllRecords[*WhatData].Theme = 1;
  2577. break;
  2578. case '2':
  2579. system("COLOR 67");
  2580. AllRecords[*WhatData].Theme = 2;
  2581. break;
  2582. case '3':
  2583. system("color 30");
  2584. AllRecords[*WhatData].Theme = 3;
  2585. break;
  2586. case '4':
  2587. system("color 07");
  2588. AllRecords[*WhatData].Theme = 4;
  2589. break;
  2590. }
  2591. if (CustomerAccPersonalDetailsUpdate() == 'N') return;
  2592. }
  2593.  
  2594. }break;
  2595.  
  2596. case '2':
  2597. {
  2598. system("cls");
  2599. printf("\n\n\n\n\n\n\n\n\n\n\n Are you sure you want to delete the account? (Y/N)");
  2600. if (GetValidatedYesNo() == 'Y')
  2601. {
  2602. AllRecords[*WhatData] = AllRecords[*NumCustomerAcc + 1];
  2603. system("cls");
  2604. printf("\n\n\n\n\n\n\n\n\n\n\n Your account has been deleted.");
  2605. Sleep(1000);
  2606. system("cls");
  2607. printf("\n\n\n\n\n\n\n\n\n\n\n You will be redirected to main page in a moment.");
  2608. Sleep(1000);
  2609. system("cls"); (*Delete)++; (*NumCustomerAcc)--; return;
  2610. }
  2611.  
  2612. }break;
  2613. case '0':
  2614. system("cls");
  2615. break;
  2616. }
  2617. } while (MenuChoice != '0');
  2618. }
  2619. void CustomerAccManageCard(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData)
  2620. {
  2621. int MenuChoice = 0;
  2622. do
  2623. {
  2624. system("cls");
  2625. printf("0.Back to account page\n");
  2626. printf("\n\n\n What do you want to do?");
  2627. printf("\n\n\n\n 1. Show saved credit card\n");
  2628. printf("\n 2. Add new credit card\n");
  2629. printf("\n 3. Delete credit card\n");
  2630.  
  2631. MenuChoice = _getch();
  2632. Sleep(100);
  2633. switch (MenuChoice)
  2634. {
  2635. case '1':
  2636. if (AllRecords[*WhatData].CreditCardCheck == 0) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\n None saved credit card details."); Sleep(2000); }
  2637. else
  2638. {
  2639. system("cls");
  2640. printf("\n\n Your credit card details\n");
  2641. printf("\n\n\n\n\n Card holder name: %s", AllRecords[*WhatData].NameOnCard);
  2642. printf("\n\n Card number: %s", AllRecords[*WhatData].CardNumber);
  2643. printf("\n\n Card expires on: %s / %s", AllRecords[*WhatData].ExpDateMonth, AllRecords[*WhatData].ExpDateYear);
  2644. printf("\n\n Security code: %s", AllRecords[*WhatData].SecurityCode);
  2645. printf("\n\n\n\n\n\n\n Press ENTER to go back.");
  2646. getchar();
  2647. }
  2648. break;
  2649. case '2':
  2650. CustomerAccAddCreditCard(AllRecords, WhatData);
  2651. break;
  2652. case '3':
  2653. system("cls");
  2654. if (AllRecords[*WhatData].CreditCardCheck == 0) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\n None saved credit card details."); Sleep(2000); }
  2655. else
  2656. {
  2657. AllRecords[*WhatData].NameOnCard[MAX_LEN_NAMEONCARD] = AllRecords[*NumCustomerAcc + 1].NameOnCard;
  2658. AllRecords[*WhatData].CardNumber[MAX_LEN_CARDNUMBER] = AllRecords[*NumCustomerAcc + 1].CardNumber;
  2659. AllRecords[*WhatData].ExpDateMonth[MAX_LEN_EXPDATE] = AllRecords[*NumCustomerAcc + 1].ExpDateMonth;
  2660. AllRecords[*WhatData].ExpDateYear[MAX_LEN_EXPDATE] = AllRecords[*NumCustomerAcc + 1].ExpDateYear;
  2661. AllRecords[*WhatData].SecurityCode[MAX_LEN_SECURITYCODE] = AllRecords[*NumCustomerAcc + 1].SecurityCode;
  2662. AllRecords[*WhatData].CreditCardCheck = 0;
  2663. printf("\n\n\n\n\n\n\n\n\n\n\n Your credit card details has been deleted."); Sleep(2000);
  2664. }
  2665. break;
  2666. case '0':
  2667. system("cls");
  2668. break;
  2669. }
  2670. } while (MenuChoice != '0');
  2671. }
  2672. void CustomerAccAddCreditCard(struct CustomerAccount AllRecords[], int *WhatData)
  2673. {
  2674. system("cls");
  2675. printf("\n\n Please enter your credit card details to finish booking.");
  2676. printf("\n\n\n\n\n Card holder name: ");
  2677.  
  2678. ////////////////////////////////////////////////////////////////////////Name on card//////////////////////////////////////////////////////////////////////////////
  2679. char TemporaryName[MAX_LEN_NAMEONCARD + 1] = "";
  2680. GetValidatedString(TemporaryName, 1, MAX_LEN_NAMEONCARD);
  2681. if (strcmp(TemporaryName, "0") == 0) { system("cls"); return; }
  2682.  
  2683. ////////////////////////////////////////////////////////////////////////Card Number///////////////////////////////////////////////////////////////////////////////
  2684. char TemporaryCardNumber[MAX_LEN_CARDNUMBER + 1] = "";
  2685. int Control = 0;
  2686. do
  2687. {
  2688. system("cls");
  2689. printf("\n\n Please enter your credit card details to finish booking.");
  2690. printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
  2691. printf("\n\n Card number: ");
  2692. Control = 0;
  2693. GetValidatedString(TemporaryCardNumber, 1, MAX_LEN_CARDNUMBER);
  2694. if (strcmp(TemporaryCardNumber, "0") == 0) { system("cls"); return; }
  2695. Control = NumberCheck(TemporaryCardNumber, 16);
  2696. } while (Control == 0);
  2697.  
  2698. //////////////////////////////////////////////////////////////////////Card expires date/////////////////////////////////////////////////////////////////////////////
  2699. char TemporaryMonth[MAX_LEN_EXPDATE + 1] = "";
  2700. do
  2701. {
  2702. system("cls");
  2703. printf("\n\n Please enter your credit card details to finish booking.");
  2704. printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
  2705. printf("\n\n Card number: %s", TemporaryCardNumber);
  2706. printf("\n\n Card expires on: ");
  2707. Control = 0;
  2708. GetValidatedString(TemporaryMonth, 1, MAX_LEN_EXPDATE);
  2709. if (strcmp(TemporaryMonth, "0") == 0) { system("cls"); return; }
  2710. Control = NumberCheck(TemporaryMonth, 2);
  2711. } while (Control == 0);
  2712.  
  2713. char TemporaryYear[MAX_LEN_EXPDATE + 1] = "";
  2714. do
  2715. {
  2716. system("cls");
  2717. printf("\n\n Please enter your credit card details to finish booking.");
  2718. printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
  2719. printf("\n\n Card number: %s", TemporaryCardNumber);
  2720. printf("\n\n Card expires on: %s / ", TemporaryMonth);
  2721. Control = 0;
  2722. GetValidatedString(TemporaryYear, 1, MAX_LEN_EXPDATE);
  2723. if (strcmp(TemporaryYear, "0") == 0) { system("cls"); return; }
  2724. Control = NumberCheck(TemporaryYear, 2);
  2725. } while (Control == 0);
  2726.  
  2727. ///////////////////////////////////////////////////////////////////Secuirty code/////////////////////////////////////////////////////////////////////////////////////////
  2728. char TemporarySecCode[MAX_LEN_SECURITYCODE + 1] = "";
  2729. do
  2730. {
  2731. system("cls");
  2732. printf("\n\n Please enter your credit card details to finish booking.");
  2733. printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
  2734. printf("\n\n Card number: %s", TemporaryCardNumber);
  2735. printf("\n\n Card expires on: %s / %s", TemporaryMonth, TemporaryYear);
  2736. printf("\n\n Security code: ");
  2737. Control = 0;
  2738. GetValidatedString(TemporarySecCode, 1, MAX_LEN_SECURITYCODE);
  2739. if (strcmp(TemporarySecCode, "0") == 0) { system("cls"); return; }
  2740. Control = NumberCheck(TemporarySecCode, 3);
  2741. } while (Control == 0);
  2742.  
  2743. strcpy_s(AllRecords[*WhatData].NameOnCard, MAX_LEN_NAMEONCARD, TemporaryName);
  2744. strcpy_s(AllRecords[*WhatData].CardNumber, MAX_LEN_CARDNUMBER + 1, TemporaryCardNumber);
  2745. strcpy_s(AllRecords[*WhatData].ExpDateMonth, MAX_LEN_EXPDATE + 1, TemporaryMonth);
  2746. strcpy_s(AllRecords[*WhatData].ExpDateYear, MAX_LEN_EXPDATE + 1, TemporaryYear);
  2747. strcpy_s(AllRecords[*WhatData].SecurityCode, MAX_LEN_SECURITYCODE + 1, TemporarySecCode);
  2748. AllRecords[*WhatData].CreditCardCheck = 1;
  2749.  
  2750. printf("\n\n\n\n\n\n Your credit card has been saved.");
  2751. Sleep(2000);
  2752. }
  2753. int NumberCheck(char ToCheck[], int CorrectSize)
  2754. {
  2755. int Size = 0, Counter = 0, Change = 0, j = 0;
  2756.  
  2757. while (ToCheck[j] != '\0')
  2758. {
  2759. Size++;
  2760. j++;
  2761. }
  2762.  
  2763. if (Size == CorrectSize)
  2764. {
  2765. for (int i = 0; i < Size; i++)
  2766. {
  2767. Change = ToCheck[i];
  2768. if (48 <= Change && Change <= 57) Counter++;
  2769. }
  2770.  
  2771. if (Size == Counter) return 1;
  2772. else { printf("\n Incorrect data, please re-type it."); Sleep(2000); return 0; }
  2773. }
  2774. else { printf("\n Incorrect data, please re-type it."); Sleep(2000); return 0; }
  2775. }
  2776. void ManageFlights()
  2777. {
  2778. int MenuChoice = 0;
  2779.  
  2780. do
  2781. {
  2782. system("cls");
  2783. printf("0.Back to account page\n\n\n\n");
  2784. printf("\n\n\n\n 2. See bought tickets\n");
  2785. printf("\n 3. Update flight\n");
  2786. printf("\n 4. Cancel flight\n");
  2787. MenuChoice = _getch();
  2788. Sleep(100);
  2789. switch (MenuChoice)
  2790. {
  2791. case '2':
  2792. break;
  2793. case '3':
  2794. break;
  2795. case '4':
  2796. break;
  2797. case '0':
  2798. system("cls");
  2799. break;
  2800. }
  2801. } while (MenuChoice != '0');
  2802. }
  2803.  
  2804. ///// ticket functions
  2805. void SearchFlights(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2)
  2806. {
  2807. int Check = 1;
  2808. char TemporaryCity[MAX_LEN_CITY + 1] = "";
  2809. char TemporaryCity2[MAX_LEN_CITY + 1] = "";
  2810.  
  2811. do
  2812. {
  2813. Check = 1;
  2814. *Airport1 = -1;
  2815.  
  2816. system("cls");
  2817. printf("0.back to main menu\n");
  2818. printf("\n\n\n Departure from:\n");
  2819. printf("\n\n --> ");
  2820.  
  2821. GetValidatedString(TemporaryCity, 0, MAX_LEN_CITY);
  2822. if (strcmp(TemporaryCity, "0") == 0) { system("cls"); *Airport1 = -1; return; }
  2823.  
  2824. if (_strcmpi(TemporaryCity, AllCities[0].City) != 0) *Airport1 = -1;
  2825. else *Airport1 = 0;
  2826.  
  2827. for (int i = 1; i < *NumOfCities; i++)
  2828. {
  2829. if (_strcmpi(TemporaryCity, AllCities[i].City) != 0)
  2830. {
  2831. Check++;
  2832. }
  2833. else
  2834. {
  2835. *Airport1 = Check;
  2836. }
  2837. }
  2838.  
  2839. if (*Airport1 == -1)
  2840. {
  2841. printf("\n\n We do not fly from this city.");
  2842. Sleep(2000);
  2843. }
  2844. } while (*Airport1 == -1);
  2845.  
  2846. do
  2847. {
  2848. Check = 1;
  2849. *Airport2 = -1;
  2850.  
  2851. printf("\n\n\n Arrival to:\n");
  2852. printf("\n\n --> ");
  2853.  
  2854. GetValidatedString(TemporaryCity2, 0, MAX_LEN_CITY);
  2855. if (strcmp(TemporaryCity2, "0") == 0) { system("cls"); *Airport2 = -1; return; }
  2856.  
  2857. if (_strcmpi(TemporaryCity2, AllCities[0].City) != 0) *Airport2 = -1;
  2858. else *Airport2 = 0;
  2859.  
  2860. for (int i = 1; i < *NumOfCities; i++)
  2861. {
  2862. if (_strcmpi(TemporaryCity2, AllCities[i].City) != 0)
  2863. {
  2864. Check++;
  2865. }
  2866. else
  2867. {
  2868. *Airport2 = Check;
  2869. }
  2870. }
  2871.  
  2872. if (*Airport2 == -1)
  2873. {
  2874. printf("\n\n We do not fly to this city.");
  2875. Sleep(2000);
  2876. system("cls");
  2877. printf("0.back to main menu\n");
  2878. printf("\n\n\n Departure from:\n");
  2879. printf("\n\n --> %s\n", TemporaryCity);
  2880. }
  2881.  
  2882. if (_strcmpi(TemporaryCity2, TemporaryCity) == 0)
  2883. {
  2884. printf("\n\n Your departure city and arrival city are the same.");
  2885. Sleep(2300);
  2886. system("cls");
  2887. printf("0.back to main menu\n");
  2888. printf("\n\n\n Departure from:\n");
  2889. printf("\n\n --> %s\n", TemporaryCity);
  2890. *Airport2 = -1;
  2891. }
  2892. } while (*Airport2 == -1);
  2893.  
  2894. strcpy_s(AllTickets[*NumOfTickets].DepartureCity, sizeof(TemporaryCity), AllCities[*Airport1].City);
  2895. strcpy_s(AllTickets[*NumOfTickets].DepartureCountry, sizeof(TemporaryCity), AllCities[*Airport1].Country);
  2896. AllCities[*Airport1].Popularity++;
  2897.  
  2898. strcpy_s(AllTickets[*NumOfTickets].ArrivalCity, sizeof(TemporaryCity), AllCities[*Airport2].City);
  2899. strcpy_s(AllTickets[*NumOfTickets].ArrivalCountry, sizeof(TemporaryCity), AllCities[*Airport2].Country);
  2900. AllCities[*Airport2].Popularity++;
  2901.  
  2902. system("cls");
  2903. }
  2904. void Options(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2)
  2905. {
  2906. system("cls");
  2907. char Seat[40] = "";
  2908. int Price = 0, A = 0, B = 0, Adult = 0, Child = 0, Infants = 0, OneWay = 0, Way = 2;
  2909. float TicketPrice = 0, TicketPrice2 = 0, TicketPrice3 = 0, TicketPrice4 = 0, TicketChild = 0, TicketChild2 = 0, TicketChild3 = 0, TicketChild4 = 0;
  2910.  
  2911. A = AllCities[*Airport1].Place;
  2912. B = AllCities[*Airport2].Place;
  2913.  
  2914. Price = abs(A - B);
  2915.  
  2916. srand(time(NULL));
  2917.  
  2918. switch (Price)
  2919. {
  2920. case 0:
  2921. TicketPrice = rand() % 15 + 30;
  2922. TicketPrice2 = rand() % 15 + 30;
  2923. TicketPrice3 = rand() % 15 + 30;
  2924. TicketPrice4 = rand() % 15 + 30;
  2925. break;
  2926. case 1:
  2927. TicketPrice = rand() % 15 + 45;
  2928. TicketPrice2 = rand() % 15 + 45;
  2929. TicketPrice3 = rand() % 15 + 45;
  2930. TicketPrice4 = rand() % 15 + 45;
  2931. break;
  2932. case 2:
  2933. TicketPrice = rand() % 15 + 60;
  2934. TicketPrice2 = rand() % 15 + 60;
  2935. TicketPrice3 = rand() % 15 + 60;
  2936. TicketPrice4 = rand() % 15 + 60;
  2937. break;
  2938. case 3:
  2939. TicketPrice = rand() % 15 + 75;
  2940. TicketPrice2 = rand() % 15 + 75;
  2941. TicketPrice3 = rand() % 15 + 75;
  2942. TicketPrice4 = rand() % 15 + 75;
  2943. break;
  2944. case 4:
  2945. TicketPrice = rand() % 35 + 90;
  2946. TicketPrice2 = rand() % 35 + 90;
  2947. TicketPrice3 = rand() % 35 + 90;
  2948. TicketPrice4 = rand() % 35 + 90;
  2949. break;
  2950. case 5:
  2951. TicketPrice = rand() % 50 + 125;
  2952. TicketPrice2 = rand() % 50 + 125;
  2953. TicketPrice3 = rand() % 50 + 125;
  2954. TicketPrice4 = rand() % 50 + 125;
  2955. break;
  2956. case 6:
  2957. TicketPrice = rand() % 35 + 175;
  2958. TicketPrice2 = rand() % 35 + 175;
  2959. TicketPrice3 = rand() % 35 + 175;
  2960. TicketPrice4 = rand() % 35 + 175;
  2961. break;
  2962. case 7:
  2963. TicketPrice = rand() % 60 + 210;
  2964. TicketPrice2 = rand() % 60 + 210;
  2965. TicketPrice3 = rand() % 60 + 210;
  2966. TicketPrice4 = rand() % 60 + 210;
  2967. break;
  2968. case 8:
  2969. TicketPrice = rand() % 40 + 270;
  2970. TicketPrice2 = rand() % 40 + 270;
  2971. TicketPrice3 = rand() % 40 + 270;
  2972. TicketPrice4 = rand() % 40 + 270;
  2973. break;
  2974. }
  2975.  
  2976. TicketChild = TicketPrice - (TicketPrice * 25) / 100;
  2977. TicketChild2 = TicketPrice2 - (TicketPrice2 * 25) / 100;
  2978. TicketChild3 = TicketPrice3 - (TicketPrice3 * 25) / 100;
  2979. TicketChild4 = TicketPrice4 - (TicketPrice4 * 25) / 100;
  2980.  
  2981. do
  2982. {
  2983. printf("\n\n\n How many people?\n\n");
  2984. printf("\n\n Adults(16+): ");
  2985. Adult = GetValidatedInteger(0, 20);
  2986. if (Adult == 0)
  2987. {
  2988. printf("\n\n Children and infants must travel with at least one adult person.\n");
  2989. Sleep(2000);
  2990. system("cls");
  2991. }
  2992. } while (Adult == 0);
  2993.  
  2994. printf("\n Children(2-15): ");
  2995. Child = GetValidatedInteger(0, 20);
  2996.  
  2997. printf("\n Infants(<2): ");
  2998. Infants = GetValidatedInteger(0, 20);
  2999.  
  3000. printf("\n\n\n 1. ( ) One way\n");
  3001. printf("\n\n\n\n Press ENTER to see available flights.\n");
  3002.  
  3003. do
  3004. {
  3005. OneWay = 0;
  3006. OneWay = _getch();
  3007. if (OneWay == '1')
  3008. {
  3009. system("cls");
  3010. printf("\n\n\n How many people?\n\n");
  3011. printf("\n\n Adults(16+): %d\n", Adult);
  3012. printf("\n Children(2-15): %d\n", Child);
  3013. printf("\n Infants(<2): %d\n", Infants);
  3014. printf("\n\n\n 1. (x) One way\n");
  3015. printf("\n\n\n\n Press ENTER to see available flights.\n");
  3016. Way = 1;
  3017. }
  3018.  
  3019. if (OneWay != 13)
  3020. {
  3021. OneWay = _getch();
  3022. if (OneWay == '1')
  3023. {
  3024. system("cls");
  3025. printf("\n\n\n How many people?\n\n");
  3026. printf("\n\n Adults(16+): %d\n", Adult);
  3027. printf("\n Children(2-15): %d\n", Child);
  3028. printf("\n Infants(<2): %d\n", Infants);
  3029. printf("\n\n\n 1. ( ) One way\n");
  3030. printf("\n\n\n\n Press ENTER to see available flights.\n");
  3031. Way = 2;
  3032. }
  3033. }
  3034. } while (OneWay != 13);
  3035.  
  3036. system("cls");
  3037.  
  3038. struct tm newtime;
  3039. char am_pm[] = "AM";
  3040. time_t long_time;
  3041. char timebuf[26];
  3042. errno_t err;
  3043.  
  3044. // Get time as an integer.
  3045. time(&long_time);
  3046. // Convert to local time.
  3047. err = localtime_s(&newtime, &long_time);
  3048.  
  3049. if (newtime.tm_hour > 12) // Set up extension.
  3050. strcpy_s(am_pm, sizeof(am_pm), "PM");
  3051. if (newtime.tm_hour > 12) // Convert from 24-hour
  3052. newtime.tm_hour -= 12; // to 12-hour clock.
  3053. if (newtime.tm_hour == 0) // Set hour to 12 if midnight.
  3054. newtime.tm_hour = 12;
  3055.  
  3056. // Convert to an ASCII representation.
  3057. err = asctime_s(timebuf, 26, &newtime);
  3058. //printf("%.19s %D\n", timebuf, am_pm);
  3059. //printf("%.19s\n", timebuf);
  3060.  
  3061. printf("\n\n\n These are available dates for flight from %s to %s. \n\n\n", AllTickets[*NumOfTickets].DepartureCity, AllTickets[*NumOfTickets].ArrivalCity);
  3062.  
  3063. printf("\n Date Dep.time Price Adults Price Children");
  3064. printf("\n =============== ============ ================ ==================");
  3065.  
  3066. printf("\n1. %d / %d / %d 10:30 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice, POUND_SIGN, TicketChild, POUND_SIGN);
  3067.  
  3068. printf("2. %d / %d / %d 07:30 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday + 2, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice2, POUND_SIGN, TicketChild2, POUND_SIGN);
  3069.  
  3070. printf("3. %d / %d / %d 18:00 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday + 4, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice3, POUND_SIGN, TicketChild3, POUND_SIGN);
  3071.  
  3072. printf("4. %d / %d / %d 22:45 AM %1.2f%c %1.2f%c\n", newtime.tm_mday + 6, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice4, POUND_SIGN, TicketChild4, POUND_SIGN);
  3073.  
  3074. printf("\n\n Which one would you like to choose? ");
  3075.  
  3076. int Choice = 0;
  3077.  
  3078. Choice = _getch();
  3079.  
  3080. switch (Choice)
  3081. {
  3082. case '1':
  3083. AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday;
  3084. AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
  3085. AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
  3086. AllTickets[*NumOfTickets].DepartureHour = 10;
  3087. AllTickets[*NumOfTickets].DepartureMin = 30;
  3088. break;
  3089.  
  3090. case '2':
  3091. AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 2;
  3092. AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
  3093. AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
  3094. AllTickets[*NumOfTickets].DepartureHour = 07;
  3095. AllTickets[*NumOfTickets].DepartureMin = 30;
  3096. break;
  3097.  
  3098. case '3':
  3099. AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 4;
  3100. AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
  3101. AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
  3102. AllTickets[*NumOfTickets].DepartureHour = 18;
  3103. AllTickets[*NumOfTickets].DepartureMin = 00;
  3104. break;
  3105.  
  3106. case '4':
  3107. AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 6;
  3108. AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
  3109. AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
  3110. AllTickets[*NumOfTickets].DepartureHour = 22;
  3111. AllTickets[*NumOfTickets].DepartureMin = 45;
  3112. break;
  3113. }
  3114. system("cls");
  3115.  
  3116. char Yes;
  3117. int Counter = 0;
  3118.  
  3119. if (Child + Adult + Infants > 1)
  3120. {
  3121. printf("\n\n\n\n\n\n\n\n\n\n\n Would you like to book all tickets in the same class?(Y/N) ");
  3122. Yes = GetValidatedYesNo();
  3123. }
  3124.  
  3125. for (int i = 1; i <= Child + Adult + Infants; i++)
  3126. {
  3127. system("cls");
  3128. printf("\n\n\n Our airline offers three classes.\n\n");
  3129. printf("\n Which one wolud you like to choose?\n\n\n");
  3130.  
  3131. switch (Choice)
  3132. {
  3133. case '1':
  3134. printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice + (TicketPrice * 150) / 100), POUND_SIGN;
  3135. printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice + TicketPrice, POUND_SIGN);
  3136. printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice, POUND_SIGN, TicketChild, POUND_SIGN);
  3137. break;
  3138.  
  3139. case '2':
  3140. printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice2 + (TicketPrice2 * 150) / 100, POUND_SIGN);
  3141. printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice2 + TicketPrice2, POUND_SIGN);
  3142. printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice2, POUND_SIGN, TicketChild2, POUND_SIGN);
  3143. break;
  3144.  
  3145. case '3':
  3146. printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice3 + (TicketPrice3 * 150) / 100, POUND_SIGN);
  3147. printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice3 + TicketPrice3, POUND_SIGN);
  3148. printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice3, POUND_SIGN, TicketChild3, POUND_SIGN);
  3149. break;
  3150.  
  3151. case '4':
  3152. printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice4 + (TicketPrice4 * 150) / 100, POUND_SIGN);
  3153. printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice4 + TicketPrice4, POUND_SIGN);
  3154. printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice4, POUND_SIGN, TicketChild4, POUND_SIGN);
  3155. break;
  3156. }
  3157.  
  3158. int Class = 0;
  3159.  
  3160. do
  3161. {
  3162. Seat[0] = NULL;
  3163. Seat[1] = NULL;
  3164. Class = _getch();
  3165. system("cls");
  3166.  
  3167. switch (Class)
  3168. {
  3169. case '1':
  3170.  
  3171. for (int i = 1; i <= 7; i = i + 3)
  3172. {
  3173. if (i == 1)
  3174. {
  3175. printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
  3176. }
  3177. else if (i == 4)
  3178. {
  3179. printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
  3180. }
  3181. else if (i == 7)
  3182. {
  3183. printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
  3184. }
  3185. }
  3186. printf("\n Your seat: ");
  3187. GetValidatedString(Seat, 2, 39);
  3188. if (Counter == 0)
  3189. {
  3190. strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3191. }
  3192. else
  3193. {
  3194. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
  3195. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3196. }
  3197.  
  3198. if (Yes == 'Y')
  3199. AllTickets[*NumOfTickets].FirstClass = Child + Adult;
  3200. else
  3201. AllTickets[*NumOfTickets].FirstClass++;
  3202.  
  3203. Counter++;
  3204.  
  3205. break;
  3206. case '2':
  3207.  
  3208. for (int i = 1; i <= 19; i = i + 6)
  3209. {
  3210. if (i == 1)
  3211. {
  3212. printf("\n\n\n | 0%d | 0%d | | 0%d | 0%d | | 0%d | 0%d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
  3213. }
  3214. else if (i == 7)
  3215. {
  3216. printf("\n\n\n | 0%d | 0%d | | 0%d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
  3217. }
  3218. else if (i == 13)
  3219. {
  3220. printf("\n\n\n | %d | %d | | %d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
  3221. }
  3222. else if (i == 19)
  3223. {
  3224. printf("\n\n\n | %d | %d | | %d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
  3225. }
  3226. }
  3227. printf("\n Your seat: ");
  3228. GetValidatedString(Seat, 2, 39);
  3229. if (Counter == 0)
  3230. {
  3231. strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3232. }
  3233. else
  3234. {
  3235. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
  3236. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3237. }
  3238.  
  3239. if (Yes == 'Y')
  3240. AllTickets[*NumOfTickets].BussinessClass = Child + Adult;
  3241. else
  3242. AllTickets[*NumOfTickets].BussinessClass++;
  3243.  
  3244. Counter++;
  3245.  
  3246. break;
  3247. case '3':
  3248.  
  3249. for (int i = 1; i < 90; i = i + 10)
  3250. {
  3251. if (i == 1)
  3252. {
  3253. printf("\n\n\n | 0%d | 0%d | 0%d | | 0%d | 0%d | 0%d | 0%d | | 0%d | 0%d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9);
  3254. }
  3255. else
  3256. {
  3257. printf(" | %d | %d | %d | | %d | %d | %d | %d | | %d | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9);
  3258. }
  3259. }
  3260. printf("\n Your seat: ");
  3261. GetValidatedString(Seat, 2, 39);
  3262. if (Counter == 0)
  3263. {
  3264. strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3265. }
  3266. else
  3267. {
  3268. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
  3269. strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
  3270. }
  3271.  
  3272. if (Yes == 'Y')
  3273. AllTickets[*NumOfTickets].ThirdClass = Child + Adult + Infants;
  3274. else
  3275. AllTickets[*NumOfTickets].ThirdClass++;
  3276.  
  3277. Counter++;
  3278.  
  3279. break;
  3280. }
  3281. } while (Class != '1' && Class != '2' && Class != '3');
  3282.  
  3283. if (Yes == 'Y') i = Child + Adult + Infants;
  3284. }
  3285.  
  3286. switch (Choice)
  3287. {
  3288. case '1':
  3289. AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice + (TicketPrice * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice);
  3290.  
  3291. if (Child == 0)
  3292. {
  3293. AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice;
  3294. }
  3295. else
  3296. {
  3297. AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice;
  3298. AllTickets[*NumOfTickets].Price += Child * TicketChild;
  3299. }
  3300. break;
  3301.  
  3302. case '2':
  3303. AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice2 + (TicketPrice2 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice2);
  3304.  
  3305. if (Child == 0)
  3306. {
  3307. AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice2;
  3308. }
  3309. else
  3310. {
  3311. AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice2;
  3312. AllTickets[*NumOfTickets].Price += Child * TicketChild2;
  3313. }
  3314. break;
  3315.  
  3316. case '3':
  3317. AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice3 + (TicketPrice3 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice3);
  3318.  
  3319. if (Child == 0)
  3320. {
  3321. AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice3;
  3322. }
  3323. else
  3324. {
  3325. AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice3;
  3326. AllTickets[*NumOfTickets].Price += Child * TicketChild3;
  3327. }
  3328. break;
  3329.  
  3330. case '4':
  3331. AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice4 + (TicketPrice4 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice4);
  3332.  
  3333. if (Child == 0)
  3334. {
  3335. AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice4;
  3336. }
  3337. else
  3338. {
  3339. AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice4;
  3340. AllTickets[*NumOfTickets].Price += Child * TicketChild4;
  3341. }
  3342. break;
  3343. }
  3344.  
  3345. AllTickets[*NumOfTickets].NumberOfAdults = Adult;
  3346. AllTickets[*NumOfTickets].NumberOfChildren = Child;
  3347. AllTickets[*NumOfTickets].NumberOfInfants = Infants;
  3348. AllTickets[*NumOfTickets].WayBackOrNo = Way;
  3349. }
  3350. void Payment(struct CustomerAccount AllRecords[], struct Ticket AllTickets[], int *NumOfTickets, int *WhatData)
  3351. {
  3352. system("cls");
  3353.  
  3354. if (AllRecords[*WhatData].CreditCardCheck == 0)
  3355. {
  3356. CustomerAccAddCreditCard(AllRecords, WhatData);
  3357. system("cls");
  3358. }
  3359.  
  3360. for (int i = 3; i >= 0; i--)
  3361. {
  3362. if (i != 3) Sleep(1000);
  3363. system("cls");
  3364. printf("\n\n\n\n\n\n\n\n Thank You for completing your booking. \n");
  3365. if (i == 3) Sleep(1500);
  3366. printf("\n Now you can see your booking on your account. \n");
  3367. if (i == 3) Sleep(1500);
  3368. printf("\n Do not waste your time and get ready for your journey! \n");
  3369. if (i == 3) Sleep(1500);
  3370. printf("\n\n You will be redirected to a main page in a moment. \n");
  3371. printf("\n %d", i);
  3372. }
  3373.  
  3374. AllTickets[*NumOfTickets].Who = WhatData;
  3375. system("cls");
  3376. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement