Commit acd8d99a by krmaet

Update main.c, final

parent 5c3fa0c1
Showing with 78 additions and 59 deletions
......@@ -24,6 +24,8 @@ int main()
int menuOption = -1;
int seatmap[ROWS][COLUMNS]= {0};
int ticketCount = 0;
//Strings for info
char username[STR_MAX];
char password[STR_MAX];
char bookingNumber[STR_MAX];
......@@ -31,61 +33,80 @@ int main()
char buffer[STR_MAX];
char* seat = malloc(10 * sizeof(*seat));
//String array for all menu options
char *userOptions[USER_OPTIONS_CNT] = {"Name", "Document Number", "Seat", "Baggage", "Back"};
char *adminOptions[ADMIN_OPTIONS_CNT] = {"Flight info", "Client info", "Exit"};
char *adminOptions[ADMIN_OPTIONS_CNT] = {"Add flight", "Delete flight", "Client info", "Exit"};
char *assistantOptions[ASSISTANT_OPTIONS_CNT]= {"Client info", "Check-in info", "Exit"};
start: ;
clear();
printIntro(&row, &col);
//~ ch = printIntroMenu(&row, &col);
ch = printIntroMenu(&row, &col);
while((ch = getch()) != KEY_F(2))
while(1)
{
clear();
refresh();
switch(ch){
case '1':
my_win = create_newwin(5, 40, 1, col / 2 - 40/2);
case 1:
my_win = create_newwin(SMALL_WIN_LENGTH, SMALL_WIN_WIDTH, 1, col / 2 - SMALL_WIN_WIDTH/2);
echo();
wrefresh(my_win);
//Ask for username
mvwprintw(my_win, 1, 1, "Username:");
wscanw(my_win, "%s", username);
noecho();
//Ask for password
mvwprintw(my_win, 2, 1, "Password:");
wscanw(my_win, "%s", password);
wrefresh(my_win);
//~ delwin(my_win);
// SIIA LÄHEB SQL KASUTAJA KONTROLL
char c;
int index = 0;
//Ask for password
while((c = getch()) != ENTER_KEY){
password[index++] = c;
wprintw(my_win, "*");
wrefresh(my_win);
}
password[index] = '\0';
wrefresh(my_win);
//Check user for access
position = CheckUser(con, username, password);
//If CheckUser comes back with wrong username or password
if (position == -1)
{
refresh();
my_win = create_newwin(5, 40, 1, col / 2 - 40/2);
my_win = create_newwin(SMALL_WIN_LENGTH, SMALL_WIN_WIDTH, 1, col / 2 - SMALL_WIN_WIDTH/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;
}
//CheckUser confirms user is admin
if (position == ADMIN)
{
//Print into buffer for future usage
snprintf(buffer, STR_MAX, "Logged in as admin");
while (1)
{
admin_menu: ;
option = NONE;
admin_menu: ; //Goto for admin_menu
option = NONE; //Zero option
menuOption = NONE;
//Ask for admin option
option = optionMenu(adminOptions, ADMIN_OPTIONS_CNT, buffer, &row, &col);
//Choose the correct option
switch (option)
{
case FLIGHT_INFO:
//Add flight info
case ADD_FLIGHT:
AddFlightDest(con, &col, &row);
break;
//Delete existing flight
case DELETE_FLIGHT:
DeleteFlight(con, &row, &col);
break;
//Change client info
case CLIENT_INFO:
if (CheckBooking(con, bookingNumber, &row, &col))
{
......@@ -94,12 +115,13 @@ int main()
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
}
break;
//Exit back to the start
case EXIT:
goto start;
default:
break;
}
//Choose the correct option to change user info
//Choose the correct option to change client info
switch (menuOption)
{
case NAME:
......@@ -111,6 +133,7 @@ int main()
goto checked;
break;
case SEAT:
ChangeSeat(con, bookingNumber, &row, &col);
goto checked;
break;
case BAGGAGE:
......@@ -127,15 +150,18 @@ int main()
}
else if (position == ASSISTANT)
{
//Print into buffer for future usage
snprintf(buffer, STR_MAX, "Logged in as assistant");
while (1)
{
assistant_menu: ;
menuOption = NONE;
assistant_menu: ; //Goto to start at assistant menu again
menuOption = NONE; //Options to NONE
option = NONE;
//Ask for assistant option
option = optionMenu(assistantOptions, ASSISTANT_OPTIONS_CNT, buffer, &row, &col);
switch (option)
{
//Change user info
case USER_INFO:
if (CheckBooking(con, bookingNumber, &row, &col))
{
......@@ -143,16 +169,19 @@ int main()
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
}
break;
//Check person in
case CHECK_IN:
CheckIn(con, &row, &col);
break;
case EXIT:
//Exit to the start page
case EXIT_ASSISTANT:
goto start;
break;
default:
goto assistant_menu;
}
option = NONE;
//Choose correct userOption
switch (menuOption)
{
case NAME:
......@@ -164,6 +193,7 @@ int main()
goto checked1;
break;
case SEAT:
ChangeSeat(con, bookingNumber, &row, &col);
goto checked1;
break;
case BAGGAGE:
......@@ -181,7 +211,7 @@ int main()
}
}
break;
case '2':
case 2:
//Check if booking and document number match
if (CheckBookingDocument(con, bookingNumber, documentNumber, &row, &col))
{
......@@ -191,6 +221,7 @@ int main()
//Display menu options
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
}
//Switch to selected menuOption
switch (menuOption)
{
case NAME:
......@@ -202,6 +233,7 @@ int main()
goto checked2;
break;
case SEAT:
ChangeSeat(con, bookingNumber, &row, &col);
goto checked2;
break;
case BAGGAGE:
......@@ -217,17 +249,24 @@ int main()
}
wgetch(my_win);
break;
case '3':
case 3:
//Buy new ticket
int flightId = ShowDestinations(con, &row, &col);
//Fill seat 3d array with seats
FillSeatmap(seatmap, ROWS, COLUMNS, con, flightId);
//Ask for new seat
PrintSeats(seatmap, ROWS, COLUMNS, &row, &col, seat);
//Ask info and create new ticket
NewTicket(&row, &col, seat, flightId, con, ticketCount);
ticketCount++;
goto start;
break;
case 4:
echo();
exit(EXIT_SUCCESS);
default:
echo();
return 1; //Exit program if any other key pressed
goto start; //Exit program if any other key pressed
}
}
echo();
......@@ -247,25 +286,6 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
return local_win;
}
void printIntro(int *row, int *col)
{
char introMesg[] = "Welcome to booking system 'Boing'!";
char action[] = "Choose action:";
char logIn[] = "Press 1 to log in";
char bookingNum[] = "Press 2 to enter booking number";
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 */
mvprintw(*row / 7,(*col-strlen(introMesg)) / 2, "%s", introMesg);
mvprintw(*row / 7 + 3,(*col - strlen(action)) / 2, "%s", action);
mvprintw(*row / 7 + 4,(*col - strlen(logIn)) / 2, "%s", logIn);
mvprintw(*row / 7 + 5,(*col - strlen(bookingNum)) / 2, "%s", bookingNum);
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)
{
WINDOW *menu_win;
......@@ -274,62 +294,61 @@ int printIntroMenu(int *row, int *col)
noecho();
int i, choice;
int highlight = 0;
char *options[2] = {"Log In", "Change booking info",};
char *options[4] = {"Log In", "Change booking", "Book new flight", "Exit program"};
char introMesg[] = "Welcome to booking system 'Boing'!";
getmaxyx(stdscr, *row, *col); /* get the number of rows and columns */
menu_win = create_newwin(28, 100, 1, *col / 2 - 100/2);
mvwprintw(menu_win, 1, 100 / 2 , "%s", introMesg);
//Check if booking exists!!!
menu_win = create_newwin(WIN_LENGTH, WIN_WIDTH, 1, *col / 2 - WIN_WIDTH/2);
mvwprintw(menu_win, 1, (WIN_WIDTH - strlen(introMesg)) / 2, "%s", introMesg);
//Selectable list of options
while (1)
{
for (i = 0; i < 2; i++)
//Print all options
for (i = 0; i < 4; i++)
{
if (i == highlight)
if (i == highlight) //Highlight current selected option
{
wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, i + 6, 100 / 2, "%s", options[i]);
mvwprintw(menu_win, i + 6, (WIN_WIDTH - strlen(options[i])) / 2, "%s", options[i]);
wattroff(menu_win, A_REVERSE);
}
else
{
mvwprintw(menu_win, i + 6, 100 / 2, "%s", options[i]);
mvwprintw(menu_win, i + 6, (WIN_WIDTH - strlen(options[i])) / 2, "%s", options[i]);
}
}
//Ask for arrow input
choice = wgetch(menu_win);
switch(choice){
case UP_KEY:
highlight--;
if (highlight == -1)
{
highlight = 0;
highlight = 0; //If choice is at the top of the list already
}
break;
case DOWN_KEY:
highlight++;
if (highlight == 2)
if (highlight == 4)
{
highlight = 2 - 1;
highlight = 4 - 1; //If choice is at the bottom of the list already
}
break;
default:
break;
}
if (choice == ENTER_KEY)
{
break;
}
}
mvwprintw(menu_win, 4 + 4, 100 / 2, "Your choice was: %s", options[highlight]);
wrefresh(menu_win);
delwin(menu_win);
return highlight;
return highlight + 1;
}
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