Commit e0fd525a by krmaet

Update main.c

parent 773a1a9e
Showing with 83 additions and 39 deletions
...@@ -19,7 +19,8 @@ int main() ...@@ -19,7 +19,8 @@ int main()
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
refresh(); refresh();
int row,col, ch, option, position; int row,col, ch, option;
int position = 2;
int menuOption = -1; int menuOption = -1;
int seatmap[ROWS][COLUMNS]= {0}; int seatmap[ROWS][COLUMNS]= {0};
int ticketCount = 0; int ticketCount = 0;
...@@ -57,45 +58,64 @@ int main() ...@@ -57,45 +58,64 @@ int main()
//Ask for password //Ask for password
mvwprintw(my_win, 2, 1, "Password:"); mvwprintw(my_win, 2, 1, "Password:");
wscanw(my_win, "%s", password); wscanw(my_win, "%s", password);
wrefresh(my_win);
//~ delwin(my_win);
// SIIA LÄHEB SQL KASUTAJA KONTROLL // SIIA LÄHEB SQL KASUTAJA KONTROLL
position = CheckUser(con, username, password); position = CheckUser(con, username, password);
//~ mvwprintw(my_win, 3, 1, "Wrong username or password!");
//~ if (strcmp(username, "admin") == 0) if (position == -1)
{
refresh();
my_win = create_newwin(5, 40, 1, col / 2 - 40/2);
mvwprintw(my_win, 1, 1, "Wrong username or password!");
mvwprintw(my_win, 2, 1, "Press any key to start again!");
wgetch(my_win);
goto start;
}
if (position == ADMIN) if (position == ADMIN)
{ {
snprintf(buffer, STR_MAX, "Logged in as admin"); snprintf(buffer, STR_MAX, "Logged in as admin");
while (1) while (1)
{ {
admin_menu: ; admin_menu: ;
option = NONE;
option = optionMenu(adminOptions, ADMIN_OPTIONS_CNT, buffer, &row, &col); option = optionMenu(adminOptions, ADMIN_OPTIONS_CNT, buffer, &row, &col);
//Choose the correct option
switch (option) switch (option)
{ {
case FLIGHT_INFO: case FLIGHT_INFO:
break; break;
case CLIENT_INFO: case CLIENT_INFO:
CheckBooking(bookingNumber, &row, &col); if (CheckBooking(con, bookingNumber, &row, &col))
{
checked: ;
menuOption = NONE;
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col); menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
}
break; break;
case EXIT: case EXIT:
goto start; goto start;
default: default:
break; break;
} }
option = NONE; //Choose the correct option to change user info
switch (menuOption) switch (menuOption)
{ {
case NAME: case NAME:
ChangeName(bookingNumber, &row, &col); ChangeName(con, bookingNumber, &row, &col);
goto checked;
break; break;
case DOCUMENT: case DOCUMENT:
ChangeDocument(bookingNumber, &row, &col); ChangeDocument(con, bookingNumber, &row, &col);
goto checked;
break; break;
case SEAT: case SEAT:
goto checked;
break; break;
case BAGGAGE: case BAGGAGE:
ChangeBaggage(bookingNumber, &row, &col); ChangeBaggage(con, bookingNumber, &row, &col);
goto checked;
break; break;
case BACK: case BACK:
goto admin_menu; goto admin_menu;
...@@ -103,77 +123,98 @@ int main() ...@@ -103,77 +123,98 @@ int main()
default: default:
break; break;
} }
menuOption = NONE;
} }
} }
//~ else if (strcmp(username, "assistant") == 0)
else if (position == ASSISTANT) else if (position == ASSISTANT)
{ {
snprintf(buffer, STR_MAX, "Logged in as assistant"); snprintf(buffer, STR_MAX, "Logged in as assistant");
while (1) while (1)
{ {
assistant_menu: ; assistant_menu: ;
menuOption = NONE;
option = NONE;
option = optionMenu(assistantOptions, ASSISTANT_OPTIONS_CNT, buffer, &row, &col); option = optionMenu(assistantOptions, ASSISTANT_OPTIONS_CNT, buffer, &row, &col);
switch (option) switch (option)
{ {
case USER_INFO: case USER_INFO:
CheckBooking(bookingNumber, &row, &col); if (CheckBooking(con, bookingNumber, &row, &col))
{
checked1: ;
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col); menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
}
break; break;
case CHECK_IN: case CHECK_IN:
CheckIn(&row, &col); CheckIn(con, &row, &col);
break; break;
case EXIT: case EXIT:
goto start; goto start;
break; break;
default: default:
break; goto assistant_menu;
} }
option = NONE; option = NONE;
switch (menuOption) switch (menuOption)
{ {
case NAME: case NAME:
ChangeName(bookingNumber, &row, &col); ChangeName(con, bookingNumber, &row, &col);
goto checked1;
break; break;
case DOCUMENT: case DOCUMENT:
ChangeDocument(bookingNumber, &row, &col); ChangeDocument(con, bookingNumber, &row, &col);
goto checked1;
break; break;
case SEAT: case SEAT:
goto checked1;
break; break;
case BAGGAGE: case BAGGAGE:
ChangeBaggage(bookingNumber, &row, &col); ChangeBaggage(con, bookingNumber, &row, &col);
goto checked1;
break; break;
case BACK: case BACK:
goto assistant_menu; goto assistant_menu;
break; break;
default: default:
goto assistant_menu;
break; break;
} }
menuOption = NONE; menuOption = NONE;
} }
} }
//~ wgetch(my_win);
break; break;
case '2': case '2':
my_win = create_newwin(6, 40, 1, col / 2 - 40/2); //Check if booking and document number match
echo(); if (CheckBookingDocument(con, bookingNumber, documentNumber, &row, &col))
wrefresh(my_win); {
strcpy(buffer, " "); //Empty printed buffer
mvwprintw(my_win, 1, 1, "Enter booking number:"); menuOption = NONE; //For safety, menuOption to NONE
mvwscanw(my_win, 2, 1, "%s", bookingNumber); checked2: ; //Goto to pass checking booking and document number
//Display menu options
mvwprintw(my_win, 3, 1, "Enter document number:"); menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
mvwscanw(my_win, 4, 1, "%s", documentNumber); }
switch (menuOption)
//SIIA LÄHEB SQL KONTROLL {
case NAME:
snprintf(buffer, STR_MAX, "Booking number found!"); ChangeName(con, bookingNumber, &row, &col);
goto checked2;
optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col); break;
case DOCUMENT:
ChangeDocument(con, bookingNumber, &row, &col);
goto checked2;
break;
case SEAT:
goto checked2;
break;
case BAGGAGE:
ChangeBaggage(con, bookingNumber, &row, &col);
goto checked2;
break;
case BACK:
goto start;
break;
default:
goto start;
break;
}
wgetch(my_win); wgetch(my_win);
break; break;
case '3': case '3':
...@@ -185,7 +226,8 @@ int main() ...@@ -185,7 +226,8 @@ int main()
goto start; goto start;
break; break;
default: default:
return 1; echo();
return 1; //Exit program if any other key pressed
} }
} }
echo(); echo();
...@@ -211,7 +253,8 @@ void printIntro(int *row, int *col) ...@@ -211,7 +253,8 @@ void printIntro(int *row, int *col)
char action[] = "Choose action:"; char action[] = "Choose action:";
char logIn[] = "Press 1 to log in"; char logIn[] = "Press 1 to log in";
char bookingNum[] = "Press 2 to enter booking number"; char bookingNum[] = "Press 2 to enter booking number";
char newFlight[] = "Press 3 to enter new flight"; char newFlight[] = "Press 3 to book new flight";
char exit[] = "Press any key to exit";
getmaxyx(stdscr, *row, *col); /* get the number of rows and columns */ getmaxyx(stdscr, *row, *col); /* get the number of rows and columns */
...@@ -220,6 +263,7 @@ void printIntro(int *row, int *col) ...@@ -220,6 +263,7 @@ void printIntro(int *row, int *col)
mvprintw(*row / 7 + 4,(*col - strlen(logIn)) / 2, "%s", logIn); mvprintw(*row / 7 + 4,(*col - strlen(logIn)) / 2, "%s", logIn);
mvprintw(*row / 7 + 5,(*col - strlen(bookingNum)) / 2, "%s", bookingNum); mvprintw(*row / 7 + 5,(*col - strlen(bookingNum)) / 2, "%s", bookingNum);
mvprintw(*row / 7 + 6,(*col - strlen(newFlight)) / 2, "%s", newFlight); mvprintw(*row / 7 + 6,(*col - strlen(newFlight)) / 2, "%s", newFlight);
mvprintw(*row / 7 + 7,(*col - strlen(exit)) / 2, "%s", exit);
} }
int printIntroMenu(int *row, int *col) int printIntroMenu(int *row, int *col)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment