Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
krmaet
/
Lennubroneerimis_tarkvara
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
acd8d99a
authored
Apr 24, 2023
by
krmaet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update main.c, final
parent
5c3fa0c1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
58 deletions
main.c
main.c
View file @
acd8d99a
...
@@ -24,6 +24,8 @@ int main()
...
@@ -24,6 +24,8 @@ int main()
int
menuOption
=
-
1
;
int
menuOption
=
-
1
;
int
seatmap
[
ROWS
][
COLUMNS
]
=
{
0
};
int
seatmap
[
ROWS
][
COLUMNS
]
=
{
0
};
int
ticketCount
=
0
;
int
ticketCount
=
0
;
//Strings for info
char
username
[
STR_MAX
];
char
username
[
STR_MAX
];
char
password
[
STR_MAX
];
char
password
[
STR_MAX
];
char
bookingNumber
[
STR_MAX
];
char
bookingNumber
[
STR_MAX
];
...
@@ -31,61 +33,80 @@ int main()
...
@@ -31,61 +33,80 @@ int main()
char
buffer
[
STR_MAX
];
char
buffer
[
STR_MAX
];
char
*
seat
=
malloc
(
10
*
sizeof
(
*
seat
));
char
*
seat
=
malloc
(
10
*
sizeof
(
*
seat
));
//String array for all menu options
char
*
userOptions
[
USER_OPTIONS_CNT
]
=
{
"Name"
,
"Document Number"
,
"Seat"
,
"Baggage"
,
"Back"
};
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"
};
char
*
assistantOptions
[
ASSISTANT_OPTIONS_CNT
]
=
{
"Client info"
,
"Check-in info"
,
"Exit"
};
start:
;
start:
;
clear
();
clear
();
printIntro
(
&
row
,
&
col
);
ch
=
printIntroMenu
(
&
row
,
&
col
);
//~ ch = printIntroMenu(&row, &col);
while
(
(
ch
=
getch
())
!=
KEY_F
(
2
)
)
while
(
1
)
{
{
clear
();
clear
();
refresh
();
refresh
();
switch
(
ch
){
switch
(
ch
){
case
'1'
:
case
1
:
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
);
echo
();
echo
();
wrefresh
(
my_win
);
wrefresh
(
my_win
);
//Ask for username
//Ask for username
mvwprintw
(
my_win
,
1
,
1
,
"Username:"
);
mvwprintw
(
my_win
,
1
,
1
,
"Username:"
);
wscanw
(
my_win
,
"%s"
,
username
);
wscanw
(
my_win
,
"%s"
,
username
);
noecho
();
//Ask for password
//Ask for password
mvwprintw
(
my_win
,
2
,
1
,
"Password:"
);
mvwprintw
(
my_win
,
2
,
1
,
"Password:"
);
wscanw
(
my_win
,
"%s"
,
password
);
wrefresh
(
my_win
);
wrefresh
(
my_win
);
//~ delwin(my_win);
char
c
;
// SIIA LÄHEB SQL KASUTAJA KONTROLL
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
);
position
=
CheckUser
(
con
,
username
,
password
);
//If CheckUser comes back with wrong username or password
if
(
position
==
-
1
)
if
(
position
==
-
1
)
{
{
refresh
();
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
,
1
,
1
,
"Wrong username or password!"
);
mvwprintw
(
my_win
,
2
,
1
,
"Press any key to start again!"
);
mvwprintw
(
my_win
,
2
,
1
,
"Press any key to start again!"
);
wgetch
(
my_win
);
wgetch
(
my_win
);
goto
start
;
goto
start
;
}
}
//CheckUser confirms user is admin
if
(
position
==
ADMIN
)
if
(
position
==
ADMIN
)
{
{
//Print into buffer for future usage
snprintf
(
buffer
,
STR_MAX
,
"Logged in as admin"
);
snprintf
(
buffer
,
STR_MAX
,
"Logged in as admin"
);
while
(
1
)
while
(
1
)
{
{
admin_menu:
;
admin_menu:
;
//Goto for admin_menu
option
=
NONE
;
option
=
NONE
;
//Zero option
menuOption
=
NONE
;
//Ask for admin option
option
=
optionMenu
(
adminOptions
,
ADMIN_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
option
=
optionMenu
(
adminOptions
,
ADMIN_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
//Choose the correct option
//Choose the correct option
switch
(
option
)
switch
(
option
)
{
{
case
FLIGHT_INFO
:
//Add flight info
case
ADD_FLIGHT
:
AddFlightDest
(
con
,
&
col
,
&
row
);
break
;
break
;
//Delete existing flight
case
DELETE_FLIGHT
:
DeleteFlight
(
con
,
&
row
,
&
col
);
break
;
//Change client info
case
CLIENT_INFO
:
case
CLIENT_INFO
:
if
(
CheckBooking
(
con
,
bookingNumber
,
&
row
,
&
col
))
if
(
CheckBooking
(
con
,
bookingNumber
,
&
row
,
&
col
))
{
{
...
@@ -94,12 +115,13 @@ int main()
...
@@ -94,12 +115,13 @@ int main()
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
}
}
break
;
break
;
//Exit back to the start
case
EXIT
:
case
EXIT
:
goto
start
;
goto
start
;
default:
default:
break
;
break
;
}
}
//Choose the correct option to change
user
info
//Choose the correct option to change
client
info
switch
(
menuOption
)
switch
(
menuOption
)
{
{
case
NAME
:
case
NAME
:
...
@@ -111,6 +133,7 @@ int main()
...
@@ -111,6 +133,7 @@ int main()
goto
checked
;
goto
checked
;
break
;
break
;
case
SEAT
:
case
SEAT
:
ChangeSeat
(
con
,
bookingNumber
,
&
row
,
&
col
);
goto
checked
;
goto
checked
;
break
;
break
;
case
BAGGAGE
:
case
BAGGAGE
:
...
@@ -127,15 +150,18 @@ int main()
...
@@ -127,15 +150,18 @@ int main()
}
}
else
if
(
position
==
ASSISTANT
)
else
if
(
position
==
ASSISTANT
)
{
{
//Print into buffer for future usage
snprintf
(
buffer
,
STR_MAX
,
"Logged in as assistant"
);
snprintf
(
buffer
,
STR_MAX
,
"Logged in as assistant"
);
while
(
1
)
while
(
1
)
{
{
assistant_menu:
;
assistant_menu:
;
//Goto to start at assistant menu again
menuOption
=
NONE
;
menuOption
=
NONE
;
//Options to NONE
option
=
NONE
;
option
=
NONE
;
//Ask for assistant option
option
=
optionMenu
(
assistantOptions
,
ASSISTANT_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
option
=
optionMenu
(
assistantOptions
,
ASSISTANT_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
switch
(
option
)
switch
(
option
)
{
{
//Change user info
case
USER_INFO
:
case
USER_INFO
:
if
(
CheckBooking
(
con
,
bookingNumber
,
&
row
,
&
col
))
if
(
CheckBooking
(
con
,
bookingNumber
,
&
row
,
&
col
))
{
{
...
@@ -143,16 +169,19 @@ int main()
...
@@ -143,16 +169,19 @@ int main()
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
}
}
break
;
break
;
//Check person in
case
CHECK_IN
:
case
CHECK_IN
:
CheckIn
(
con
,
&
row
,
&
col
);
CheckIn
(
con
,
&
row
,
&
col
);
break
;
break
;
case
EXIT
:
//Exit to the start page
case
EXIT_ASSISTANT
:
goto
start
;
goto
start
;
break
;
break
;
default:
default:
goto
assistant_menu
;
goto
assistant_menu
;
}
}
option
=
NONE
;
option
=
NONE
;
//Choose correct userOption
switch
(
menuOption
)
switch
(
menuOption
)
{
{
case
NAME
:
case
NAME
:
...
@@ -164,6 +193,7 @@ int main()
...
@@ -164,6 +193,7 @@ int main()
goto
checked1
;
goto
checked1
;
break
;
break
;
case
SEAT
:
case
SEAT
:
ChangeSeat
(
con
,
bookingNumber
,
&
row
,
&
col
);
goto
checked1
;
goto
checked1
;
break
;
break
;
case
BAGGAGE
:
case
BAGGAGE
:
...
@@ -181,7 +211,7 @@ int main()
...
@@ -181,7 +211,7 @@ int main()
}
}
}
}
break
;
break
;
case
'2'
:
case
2
:
//Check if booking and document number match
//Check if booking and document number match
if
(
CheckBookingDocument
(
con
,
bookingNumber
,
documentNumber
,
&
row
,
&
col
))
if
(
CheckBookingDocument
(
con
,
bookingNumber
,
documentNumber
,
&
row
,
&
col
))
{
{
...
@@ -191,6 +221,7 @@ int main()
...
@@ -191,6 +221,7 @@ int main()
//Display menu options
//Display menu options
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
menuOption
=
optionMenu
(
userOptions
,
USER_OPTIONS_CNT
,
buffer
,
&
row
,
&
col
);
}
}
//Switch to selected menuOption
switch
(
menuOption
)
switch
(
menuOption
)
{
{
case
NAME
:
case
NAME
:
...
@@ -202,6 +233,7 @@ int main()
...
@@ -202,6 +233,7 @@ int main()
goto
checked2
;
goto
checked2
;
break
;
break
;
case
SEAT
:
case
SEAT
:
ChangeSeat
(
con
,
bookingNumber
,
&
row
,
&
col
);
goto
checked2
;
goto
checked2
;
break
;
break
;
case
BAGGAGE
:
case
BAGGAGE
:
...
@@ -217,17 +249,24 @@ int main()
...
@@ -217,17 +249,24 @@ int main()
}
}
wgetch
(
my_win
);
wgetch
(
my_win
);
break
;
break
;
case
'3'
:
case
3
:
//Buy new ticket
int
flightId
=
ShowDestinations
(
con
,
&
row
,
&
col
);
int
flightId
=
ShowDestinations
(
con
,
&
row
,
&
col
);
//Fill seat 3d array with seats
FillSeatmap
(
seatmap
,
ROWS
,
COLUMNS
,
con
,
flightId
);
FillSeatmap
(
seatmap
,
ROWS
,
COLUMNS
,
con
,
flightId
);
//Ask for new seat
PrintSeats
(
seatmap
,
ROWS
,
COLUMNS
,
&
row
,
&
col
,
seat
);
PrintSeats
(
seatmap
,
ROWS
,
COLUMNS
,
&
row
,
&
col
,
seat
);
//Ask info and create new ticket
NewTicket
(
&
row
,
&
col
,
seat
,
flightId
,
con
,
ticketCount
);
NewTicket
(
&
row
,
&
col
,
seat
,
flightId
,
con
,
ticketCount
);
ticketCount
++
;
ticketCount
++
;
goto
start
;
goto
start
;
break
;
break
;
case
4
:
echo
();
exit
(
EXIT_SUCCESS
);
default:
default:
echo
();
echo
();
return
1
;
//Exit program if any other key pressed
goto
start
;
//Exit program if any other key pressed
}
}
}
}
echo
();
echo
();
...
@@ -247,25 +286,6 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
...
@@ -247,25 +286,6 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
return
local_win
;
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
)
int
printIntroMenu
(
int
*
row
,
int
*
col
)
{
{
WINDOW
*
menu_win
;
WINDOW
*
menu_win
;
...
@@ -274,62 +294,61 @@ int printIntroMenu(int *row, int *col)
...
@@ -274,62 +294,61 @@ int printIntroMenu(int *row, int *col)
noecho
();
noecho
();
int
i
,
choice
;
int
i
,
choice
;
int
highlight
=
0
;
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'!"
;
char
introMesg
[]
=
"Welcome to booking system 'Boing'!"
;
getmaxyx
(
stdscr
,
*
row
,
*
col
);
/* get the number of rows and columns */
getmaxyx
(
stdscr
,
*
row
,
*
col
);
/* get the number of rows and columns */
menu_win
=
create_newwin
(
28
,
100
,
1
,
*
col
/
2
-
100
/
2
);
menu_win
=
create_newwin
(
WIN_LENGTH
,
WIN_WIDTH
,
1
,
*
col
/
2
-
WIN_WIDTH
/
2
);
mvwprintw
(
menu_win
,
1
,
100
/
2
,
"%s"
,
introMesg
);
//Check if booking exists!!!
mvwprintw
(
menu_win
,
1
,
(
WIN_WIDTH
-
strlen
(
introMesg
))
/
2
,
"%s"
,
introMesg
);
//Selectable list of options
while
(
1
)
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
);
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
);
wattroff
(
menu_win
,
A_REVERSE
);
}
}
else
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
);
choice
=
wgetch
(
menu_win
);
switch
(
choice
){
switch
(
choice
){
case
UP_KEY
:
case
UP_KEY
:
highlight
--
;
highlight
--
;
if
(
highlight
==
-
1
)
if
(
highlight
==
-
1
)
{
{
highlight
=
0
;
highlight
=
0
;
//If choice is at the top of the list already
}
}
break
;
break
;
case
DOWN_KEY
:
case
DOWN_KEY
:
highlight
++
;
highlight
++
;
if
(
highlight
==
2
)
if
(
highlight
==
4
)
{
{
highlight
=
2
-
1
;
highlight
=
4
-
1
;
//If choice is at the bottom of the list already
}
}
break
;
break
;
default:
default:
break
;
break
;
}
}
if
(
choice
==
ENTER_KEY
)
if
(
choice
==
ENTER_KEY
)
{
{
break
;
break
;
}
}
}
}
mvwprintw
(
menu_win
,
4
+
4
,
100
/
2
,
"Your choice was: %s"
,
options
[
highlight
]);
wrefresh
(
menu_win
);
wrefresh
(
menu_win
);
delwin
(
menu_win
);
return
highlight
;
return
highlight
+
1
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment