Commit 5d0823f0 by krmaet

Algne programm, esimesed funktsionaalsused töötavad

Pileti ostmine toimib ning suhtleb andmebaasiga
parent afdf6a1e
Showing with 291 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>
#include <ncurses.h>
#include "main.h"
#include "changedata.h"
#include "readdata.h"
int main()
{
WINDOW *my_win;
MYSQL* con = connectToMySQLServer();
initscr(); /* start the curses mode */
noecho();
keypad(stdscr, TRUE);
refresh();
int row,col, ch, option, position;
int menuOption = -1;
int seatmap[ROWS][COLUMNS]= {0};
int ticketCount = 0;
char username[STR_MAX];
char password[STR_MAX];
char bookingNumber[STR_MAX];
char documentNumber[STR_MAX];
char buffer[STR_MAX];
char* seat = malloc(10 * sizeof(*seat));
char *userOptions[USER_OPTIONS_CNT] = {"Name", "Document Number", "Seat", "Baggage", "Back"};
char *adminOptions[ADMIN_OPTIONS_CNT] = {"Flight info", "Client info", "Exit"};
char *assistantOptions[ASSISTANT_OPTIONS_CNT]= {"Client info", "Check-in info", "Exit"};
start: ;
clear();
printIntro(&row, &col);
//~ ch = printIntroMenu(&row, &col);
while((ch = getch()) != KEY_F(2))
{
clear();
refresh();
switch(ch){
case '1':
my_win = create_newwin(5, 40, 1, col / 2 - 40/2);
echo();
wrefresh(my_win);
//Ask for username
mvwprintw(my_win, 1, 1, "Username:");
wscanw(my_win, "%s", username);
//Ask for password
mvwprintw(my_win, 2, 1, "Password:");
wscanw(my_win, "%s", password);
// SIIA LÄHEB SQL KASUTAJA KONTROLL
position = CheckUser(con, username, password);
//~ mvwprintw(my_win, 3, 1, "Wrong username or password!");
//~ if (strcmp(username, "admin") == 0)
if (position == ADMIN)
{
snprintf(buffer, STR_MAX, "Logged in as admin");
while (1)
{
admin_menu: ;
option = optionMenu(adminOptions, ADMIN_OPTIONS_CNT, buffer, &row, &col);
switch (option)
{
case FLIGHT_INFO:
break;
case CLIENT_INFO:
CheckBooking(bookingNumber, &row, &col);
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
break;
case EXIT:
goto start;
default:
break;
}
option = NONE;
switch (menuOption)
{
case NAME:
ChangeName(bookingNumber, &row, &col);
break;
case DOCUMENT:
ChangeDocument(bookingNumber, &row, &col);
break;
case SEAT:
break;
case BAGGAGE:
ChangeBaggage(bookingNumber, &row, &col);
break;
case BACK:
goto admin_menu;
break;
default:
break;
}
menuOption = NONE;
}
}
//~ else if (strcmp(username, "assistant") == 0)
else if (position == ASSISTANT)
{
snprintf(buffer, STR_MAX, "Logged in as assistant");
while (1)
{
assistant_menu: ;
option = optionMenu(assistantOptions, ASSISTANT_OPTIONS_CNT, buffer, &row, &col);
switch (option)
{
case USER_INFO:
CheckBooking(bookingNumber, &row, &col);
menuOption = optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
break;
case CHECK_IN:
CheckIn(&row, &col);
break;
case EXIT:
goto start;
break;
default:
break;
}
option = NONE;
switch (menuOption)
{
case NAME:
ChangeName(bookingNumber, &row, &col);
break;
case DOCUMENT:
ChangeDocument(bookingNumber, &row, &col);
break;
case SEAT:
break;
case BAGGAGE:
ChangeBaggage(bookingNumber, &row, &col);
break;
case BACK:
goto assistant_menu;
break;
default:
break;
}
menuOption = NONE;
}
}
//~ wgetch(my_win);
break;
case '2':
my_win = create_newwin(6, 40, 1, col / 2 - 40/2);
echo();
wrefresh(my_win);
mvwprintw(my_win, 1, 1, "Enter booking number:");
mvwscanw(my_win, 2, 1, "%s", bookingNumber);
mvwprintw(my_win, 3, 1, "Enter document number:");
mvwscanw(my_win, 4, 1, "%s", documentNumber);
//SIIA LÄHEB SQL KONTROLL
snprintf(buffer, STR_MAX, "Booking number found!");
optionMenu(userOptions, USER_OPTIONS_CNT, buffer, &row, &col);
wgetch(my_win);
break;
case '3':
int flightId = ShowDestinations(con, &row, &col);
FillSeatmap(seatmap, ROWS, COLUMNS, con, flightId);
PrintSeats(seatmap, ROWS, COLUMNS, &row, &col, seat);
NewTicket(&row, &col, seat, flightId, con, ticketCount);
ticketCount++;
goto start;
break;
default:
return 1;
}
}
echo();
endwin();
free(seat);
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{
WINDOW *local_win;
local_win = newwin(height, width, starty, startx);
box(local_win, 0 , 0); /* 0, 0 gives default characters
for the vertical and horizontal
lines */
wrefresh(local_win); /* Show that box */
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 enter new flight";
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);
}
int printIntroMenu(int *row, int *col)
{
WINDOW *menu_win;
clear();
refresh();
noecho();
int i, choice;
int highlight = 0;
char *options[2] = {"Log In", "Change booking info",};
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!!!
while (1)
{
for (i = 0; i < 2; i++)
{
if (i == highlight)
{
wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, i + 6, 100 / 2, "%s", options[i]);
wattroff(menu_win, A_REVERSE);
}
else
{
mvwprintw(menu_win, i + 6, 100 / 2, "%s", options[i]);
}
}
choice = wgetch(menu_win);
switch(choice){
case UP_KEY:
highlight--;
if (highlight == -1)
{
highlight = 0;
}
break;
case DOWN_KEY:
highlight++;
if (highlight == 2)
{
highlight = 2 - 1;
}
break;
default:
break;
}
if (choice == ENTER_KEY)
{
break;
}
}
mvwprintw(menu_win, 4 + 4, 100 / 2, "Your choice was: %s", options[highlight]);
wrefresh(menu_win);
return highlight;
}
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