Created
December 3, 2019 03:48
-
-
Save lianeyue/a1e5214974e296ca8920ffc921571b26 to your computer and use it in GitHub Desktop.
Hotel Metropole - Final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Strict On | |
Imports System.IO | |
'Images sourced from: http://www.metropolehotel.com/ | |
Public Class frmMetropoleNewReservation | |
'DECLARATION OF VARIABLES/CONSTANTS | |
'A. Declare input variables | |
Dim dtmCheckIn As DateTime | |
Dim dtmCheckOut As DateTime | |
Dim strRoomType As String | |
Dim strNumOfRooms As String | |
Dim strNumOfAdults As String | |
Dim strNumOfChildren As String | |
Dim dblRoomRate As Double | |
Dim strTotalNumberOfNights As String | |
Dim dblTotalNumberOfNights As Double | |
Dim strFirstName As String | |
Dim strLastName As String | |
Dim strPhone As String | |
Dim strEmail As String | |
Dim strTotalNumberOfRooms As String | |
Dim strCCType As String | |
Dim dblCCNum As Double | |
'B. Declare output variables | |
Dim tmsTotalNumberOfNights As TimeSpan | |
Dim dblTotalRatePerNight As Double | |
Dim dblSubtotal As Double | |
Dim dblTax As Double | |
Dim dblConvenienceFee As Double | |
Dim dblQuoteTotal As Double | |
Dim dblConvenienceValue As Double = 10 | |
'C. Declare reader variables | |
Dim roomList(5) As Room | |
Dim i As Integer | |
Private Sub frmMetropoleNewReservation_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
'Form Validations: Reservation Information | |
'None. | |
End Sub | |
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click | |
'VALIDATION | |
'Validate that only upon user clicking submit button And quote populating, they can input customer information. | |
'Validate room type is selected using If statement. | |
If cboRoomType.ToString = "" Then | |
MessageBox.Show("A room type must be selected.") | |
Exit Sub | |
End If | |
'Validate check-in date is not in the past using If statement | |
If dtpArrivalDate.Value < Today Then | |
MessageBox.Show("Arrival Date must be today or at a later date.") | |
Exit Sub | |
End If | |
'Validate that check-out date is later than check-in date using If statement | |
If dtpDepartureDate.Value < dtpArrivalDate.Value Then | |
MessageBox.Show("Departure date must be later than check-in date.") | |
Exit Sub | |
End If | |
'Validate that user has completed all fields in reservation information groupbox using If statement | |
If dtpArrivalDate.ToString = "" Or dtpDepartureDate.ToString = "" Or cboRoomType.ToString = "" Or numRooms.Value.ToString = "" Or numAdults.Value.ToString = "" Or numChildren.Value.ToString = "" Then | |
MessageBox.Show("All fields within Reservation Information must be completed.") | |
Exit Sub | |
End If | |
'PULL INFO FROM ROOMS.TXT | |
'Define variables | |
Dim strLine As String | |
Dim strData() As String | |
Dim reader As StreamReader | |
reader = New StreamReader("..\..\Rooms.txt") | |
'Loop reader | |
i = 0 | |
Do Until reader.EndOfStream | |
strLine = reader.ReadLine() | |
strData = strLine.Split(Convert.ToChar("|")) | |
'Add to array | |
roomList(i) = New Room(strData(0), Convert.ToDouble(strData(1)), Convert.ToDouble(strData(2))) | |
i += 1 | |
Loop | |
reader.Close() | |
'Match Room Type | |
i = 0 | |
For Each room As Room In roomList | |
If room.RoomType = cboRoomType.SelectedItem.ToString Then | |
i = Array.IndexOf(roomList, room) | |
Exit For | |
End If | |
Next | |
'Get Room Price | |
lblRatePerNightOutput.Text = FormatCurrency(roomList(i).Price.ToString, 2) | |
dblRoomRate = roomList(i).Price | |
'CALCULATE QUOTE FIELDS | |
tmsTotalNumberOfNights = (dtpDepartureDate.Value.Date - dtpArrivalDate.Value.Date) | |
strTotalNumberOfNights = tmsTotalNumberOfNights.TotalDays.ToString | |
dblTotalNumberOfNights = Convert.ToDouble(tmsTotalNumberOfNights.TotalDays) | |
lblNumberofNightsOutput.Text = strTotalNumberOfNights | |
'If statement to determine Total Rate Per Night. | |
'If cboRoomType Then | |
dblSubtotal = Convert.ToDouble(strTotalNumberOfNights) * roomList(i).Price * Convert.ToDouble(numRooms.Value) | |
dblTax = dblSubtotal * 0.07 | |
dblConvenienceFee = dblConvenienceValue * dblTotalNumberOfNights | |
dblQuoteTotal = dblSubtotal + dblTax + dblConvenienceFee | |
'Assign Values | |
lblSubtotalOutput.Text = FormatCurrency(dblSubtotal.ToString, 2) | |
lblTaxOutput.Text = FormatCurrency(dblTax.ToString, 2) | |
lblConvenienceFeeOutput.Text = FormatCurrency(dblConvenienceFee.ToString, 2) | |
lblTotalOutput.Text = FormatCurrency(dblQuoteTotal.ToString, 2) | |
strTotalNumberOfRooms = numRooms.Value.ToString | |
lblNumberOfRoomsOutput.Text = strTotalNumberOfRooms | |
strRoomType = cboRoomType.SelectedItem.ToString | |
txtFirstName.Enabled = True | |
txtLastName.Enabled = True | |
txtEmail.Enabled = True | |
txtPhone.Enabled = True | |
txtCCNumber.Enabled = True | |
txtCCType.Enabled = True | |
'shoTotalNumberOfNights = lblNumberOfNightsOutput.ToShort | |
End Sub | |
Private Sub btnConfirmCustomerInfo_Click(sender As Object, e As EventArgs) Handles btnConfirmCustomerInfo.Click | |
'Link Customer Information group box to text file. | |
'Validate that all fields, except email are completed using If statement. | |
If txtFirstName.Text = "" Or txtLastName.Text = "" Or txtCCType.Text = "" Or txtCCNumber.Text = "" Or txtPhone.Text = "" Then | |
MessageBox.Show("All mandatory fields within the Customer Information box must be completed.") | |
Exit Sub | |
End If | |
'Validate phone number is entered in the correct format | |
If IsNumeric(txtPhone.Text) = False Then | |
MessageBox.Show("Please enter a numeric 10-digit phone number.") | |
Exit Sub | |
Else | |
If Convert.ToDouble(txtPhone.Text) >= 1000000000 And Convert.ToDouble(txtPhone.Text) <= 9999999999 Then | |
txtPhone.Text = Format(Convert.ToDouble(txtPhone.Text), "###-###-####") | |
Else | |
MessageBox.Show("Please enter a numeric 10-digit phone number.") | |
Exit Sub | |
End If | |
End If | |
'Display confirmation message including room type, check-in date, number of nights, and total cost. | |
Dim strMessage As String = "" | |
strMessage = "Thank you for booking your reservation with Hotel Metropole!" & vbNewLine & "Listed below are your reservation details." & vbNewLine & vbNewLine & "Room Type: " & strRoomType & vbNewLine & "Check-in Date: " & DateValue(dtpArrivalDate.Value.ToString) & vbNewLine & "Number of Nights: " & tmsTotalNumberOfNights.TotalDays.ToString & vbNewLine & "Total Cost: " & FormatCurrency(dblQuoteTotal.ToString, 2) | |
MessageBox.Show(strMessage) | |
'WRITE TO TEXT FILE | |
'Create reservation | |
strFirstName = txtFirstName.Text | |
strLastName = txtLastName.Text | |
strPhone = txtPhone.Text | |
strEmail = txtEmail.Text | |
strCCType = txtCCType.Text | |
dblCCNum = Convert.ToDouble(txtCCNumber.Text) | |
Dim dtmArrivalDate As DateTime | |
Dim newReservation As Reservation | |
newReservation = New Reservation(dtpArrivalDate.Value, dblTotalNumberOfNights, strRoomType, Convert.ToDouble(numRooms.Value), dblRoomRate, dblSubtotal, dblTax, dblConvenienceFee, dblQuoteTotal, strFirstName, strLastName, strCCType, dblCCNum, strPhone, strEmail) | |
'Writer | |
Dim writer As StreamWriter | |
writer = New StreamWriter("..\..\Reservations.txt", True) | |
writer.WriteLine(String.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}", newReservation.CheckInDate.ToString, newReservation.NumberOfNights.ToString, newReservation.RoomType, newReservation.NumberOfRooms.ToString, newReservation.RoomPrice.ToString, newReservation.SubTotal.ToString, newReservation.Tax.ToString, newReservation.Fee.ToString, newReservation.Total.ToString, newReservation.FirstName, newReservation.LastName, newReservation.CCType, newReservation.CCNum.ToString, newReservation.Phone, newReservation.Email)) | |
writer.Close() | |
'RESET FORM | |
dtpArrivalDate.Value = Today() | |
dtpDepartureDate.Value = Today() | |
cboRoomType.SelectedIndex = -1 | |
numRooms.Value = 1 | |
numAdults.Value = 1 | |
numChildren.Value = 0 | |
lblNumberofNightsOutput.Text = "" | |
lblNumberOfRoomsOutput.Text = "" | |
lblRatePerNightOutput.Text = "" | |
lblSubtotalOutput.Text = "" | |
lblTaxOutput.Text = "" | |
lblConvenienceFeeOutput.Text = "" | |
txtFirstName.Text = "" | |
txtLastName.Text = "" | |
txtCCNumber.Text = "" | |
txtCCType.Text = "" | |
txtPhone.Text = "" | |
txtEmail.Text = "" | |
End Sub | |
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click | |
'RETURN TO MAIN MENU | |
'Close form | |
Me.Hide() | |
'Open main menu | |
frmHotelMetropoleMainMenu.Show() | |
End Sub | |
Private Sub btnClearNewReservation_Click(sender As Object, e As EventArgs) Handles btnClearNewReservation.Click | |
dtpArrivalDate.Value = Today() | |
dtpDepartureDate.Value = Today() | |
cboRoomType.SelectedIndex = -1 | |
numRooms.Value = 1 | |
numAdults.Value = 1 | |
numChildren.Value = 0 | |
lblNumberofNightsOutput.Text = "" | |
lblNumberOfRoomsOutput.Text = "" | |
lblRatePerNightOutput.Text = "" | |
lblSubtotalOutput.Text = "" | |
lblTaxOutput.Text = "" | |
lblConvenienceFeeOutput.Text = "" | |
txtFirstName.Text = "" | |
txtLastName.Text = "" | |
txtCCNumber.Text = "" | |
txtCCType.Text = "" | |
txtPhone.Text = "" | |
txtEmail.Text = "" | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Strict On | |
Imports System.IO | |
'Images sourced from: http://www.metropolehotel.com/ | |
Public Class frmMetropoleReservationsReport | |
Dim reservationsList(i) As Reservation | |
Dim i As Integer = 0 | |
'Declare variable to hold a StreamReader class | |
Dim strLine As String | |
Dim strData() As String | |
Dim reader As StreamReader = New StreamReader("..\..\Reservations.txt") | |
Private Sub frmMetropoleReservationsReport_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
'Clear out the list box and add headings | |
lboSearchOutput.Items.Clear() | |
'Write a do until loop that reads through each line of the text file and splits up the line with a delimiter | |
reservationsList = {} | |
i = 0 | |
Do Until reader.EndOfStream | |
strLine = reader.ReadLine() | |
strData = strLine.Split(Convert.ToChar("|")) | |
'Display in listbox | |
lboSearchOutput.Items.Add(strData(0).PadRight(15) + strData(9).PadRight(10) + strData(10)) | |
'Convert text file to array | |
Array.Resize(reservationsList, reservationsList.Length + 1) | |
reservationsList(i) = New Reservation(Convert.ToDateTime(strData(0)), Convert.ToDouble(strData(1)), strData(2), Convert.ToDouble(strData(3)), Convert.ToDouble(strData(4)), Convert.ToDouble(strData(5)), Convert.ToDouble(strData(6)), Convert.ToDouble(strData(7)), Convert.ToDouble(strData(8)), strData(9), strData(10), strData(11), Convert.ToDouble(strData(12)), strData(13), strData(14)) | |
i += 1 | |
Loop | |
'Close the StreamReader | |
reader.Close() | |
End Sub | |
Private Sub btnSubmitRS_Click(sender As Object, e As EventArgs) Handles btnSubmitRS.Click | |
'Clear box | |
lboSearchOutput.Items.Clear() | |
'Declare input and output variables | |
Dim dtFromDate As DateTime | |
Dim dtToDate As DateTime | |
Dim strLastName As String | |
'Validate the date range | |
'If dtpFromDate.Value > Today Or dtpToDate.Value > Today Then | |
'MessageBox.Show("Please select a valid date.") | |
'End If | |
'Assign to variables | |
dtFromDate = dtpFromDate.Value | |
dtToDate = dtpToDate.Value | |
strLastName = txtLastNameSearch.Text | |
'Validate Reservation exists | |
Dim bolLastName As Boolean = True | |
Dim bolCheckInDate As Boolean = True | |
'Clear out the list box and add headings | |
lboSearchOutput.Items.Clear() | |
'Write a do until loop that reads through each line of the text file and splits up the line with a delimiter | |
i = 0 | |
For Each reservation As Reservation In reservationsList | |
If dtFromDate <= Convert.ToDateTime(reservation.CheckInDate) And dtToDate >= Convert.ToDateTime(reservation.CheckInDate) Or strLastName.ToUpper = reservation.LastName.ToUpper Then | |
lboSearchOutput.Items.Add(Format(reservation.CheckInDate, "Short Date").ToString.PadRight(15) + reservation.FirstName.PadRight(10) + reservation.LastName) | |
End If | |
Next | |
If bolCheckInDate = False Or bolLastName = False Then | |
MessageBox.Show("No reservations found. Please enter valid reservation dates or a valid customer last name.") | |
End If | |
End Sub | |
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboSearchOutput.SelectedIndexChanged | |
'Capture user selection in list box and display reservation details in the correct text boxes | |
Dim res As Reservation | |
res = reservationsList(lboSearchOutput.SelectedIndex) | |
lblCheckInDateOutput.Text = res.CheckInDate.ToString | |
lblNumberOfNightsOutput.Text = res.NumberOfNights.ToString | |
lblRoomTypeOutput.Text = res.RoomType | |
lblNumberOfRoomsOutput.Text = res.NumberOfRooms.ToString | |
lblRoomPriceOutput.Text = "$" + res.RoomPrice.ToString | |
lblTotalOutput.Text = "$" + res.Total.ToString | |
lblFirstNameOutput.Text = res.FirstName | |
lblLastNameOutput.Text = res.LastName | |
lblPhoneOutput.Text = res.Phone | |
lblEmailOutput.Text = res.Email | |
End Sub | |
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click | |
'Close the form and return to the main menu | |
Me.Close() | |
frmHotelMetropoleMainMenu.Show() | |
End Sub | |
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click | |
'Clear out the list box and add headings | |
lboSearchOutput.Items.Clear() | |
lboSearchOutput.Text = "" | |
dtpFromDate.Value = Today | |
dtpToDate.Value = Today | |
txtLastNameSearch.Text = "" | |
lblCheckInDateOutput.Text = "" | |
lblNumberOfNightsOutput.Text = "" | |
lblRoomTypeOutput.Text = "" | |
lblNumberOfRoomsOutput.Text = "" | |
lblRoomPriceOutput.Text = "" | |
lblTotalOutput.Text = "" | |
lblFirstNameOutput.Text = "" | |
lblLastNameOutput.Text = "" | |
lblPhoneOutput.Text = "" | |
lblEmailOutput.Text = "" | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Strict On | |
Imports System.IO | |
'Images sourced from: http://www.metropolehotel.com/ | |
Public Class frmMetropoleRoomManagement | |
Dim roomList(5) As Room | |
Dim strRoomType As String | |
Dim dblQuantity As Double | |
Dim dblPrice As Double | |
Dim i As Integer | |
Private Sub frmMetropoleRoomManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
'READ TEXT FILE | |
'Define variables | |
Dim strLine As String | |
Dim strData() As String | |
Dim reader As StreamReader | |
reader = New StreamReader("..\..\Rooms.txt") | |
lstDisplay.Items.Clear() | |
lstDisplay.Items.Add("Room Type".PadRight(30) + "#".PadRight(5) + "Price") | |
'Loop reader | |
Dim i As Integer = 0 | |
Do Until reader.EndOfStream | |
strLine = reader.ReadLine() | |
strData = strLine.Split(Convert.ToChar("|")) | |
'Display in listbox | |
lstDisplay.Items.Add(strData(0).PadRight(30) + strData(1).PadRight(5) + FormatNumber(strData(2), 2,)) | |
'Add to array | |
roomList(i) = New Room(strData(0), Convert.ToDouble(strData(1)), Convert.ToDouble(strData(2))) | |
i += 1 | |
Loop | |
reader.Close() | |
End Sub | |
Private Sub lstDisplay_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstDisplay.SelectedIndexChanged | |
'CLEAR | |
txtRoomType.Text = "" | |
numQuantity.Value = 0 | |
numPrice.Value = 0 | |
'SELECT INPUT | |
'STORE | |
'Pull information from listbox selected index | |
i = lstDisplay.SelectedIndex | |
If i >= 1 And i <= 6 Then | |
i -= 1 | |
strRoomType = roomList(i).RoomType | |
dblQuantity = roomList(i).Quantity | |
dblPrice = roomList(i).Price | |
Else | |
i = 0 | |
txtRoomType.Text = "" | |
numQuantity.Value = 0 | |
numPrice.Value = 0 | |
End If | |
'DISPLAY | |
txtRoomType.Text = strRoomType | |
numQuantity.Value = Convert.ToDecimal(dblQuantity) | |
numPrice.Value = Convert.ToDecimal(dblPrice) | |
End Sub | |
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click | |
'SUBMIT INPUT | |
'Define variables | |
Dim bolRoom As Boolean = False | |
Dim bolQuantity As Boolean = False | |
Dim bolPrice As Boolean = False | |
'Validate input | |
''Room type exists | |
For Each room As Room In roomList | |
If txtRoomType.Text = room.RoomType Then | |
bolRoom = True | |
Exit For | |
End If | |
Next | |
If bolRoom = False Then | |
MessageBox.Show("Please enter an existing room type in sentence case.") | |
Exit Sub | |
End If | |
''Quantity exists | |
'''' Within range (30 > x > 0) | |
If numQuantity.Value >= 0 And numQuantity.Value <= 30 Then | |
'''' Whole number | |
If numQuantity.Value = Int(numQuantity.Value) Then | |
bolQuantity = True | |
Else | |
MessageBox.Show("Please enter a whole quantity.") | |
Exit Sub | |
End If | |
Else | |
MessageBox.Show("Please enter a quantity between 0 and 30.") | |
Exit Sub | |
End If | |
''Price exists | |
'''' Within range(1000 > x > 0) | |
If numPrice.Value >= 0 And numPrice.Value <= 1000 Then | |
bolPrice = True | |
Else | |
MessageBox.Show("Please enter a price between $0 and $1000.") | |
Exit Sub | |
End If | |
'STORE INPUT | |
If bolRoom = True And bolQuantity = True And bolPrice = True Then | |
strRoomType = txtRoomType.Text | |
dblQuantity = numQuantity.Value | |
dblPrice = numPrice.Value | |
End If | |
'WRITE TO TEXT FILE | |
'Match room type | |
For Each room As Room In roomList | |
If room.RoomType = strRoomType Then | |
i = Array.IndexOf(roomList, room) | |
Exit For | |
End If | |
Next | |
'i = Array.IndexOf(roomList, strRoomType) + 1 | |
'Update array element | |
roomList(i) = New Room(strRoomType, dblQuantity, dblPrice) | |
'Writer | |
Dim writer As StreamWriter | |
writer = New StreamWriter("..\..\Rooms.txt", False) | |
i = 0 | |
Do While i <= roomList.Length - 1 | |
writer.WriteLine(String.Format("{0}|{1}|{2}", roomList(i).RoomType, roomList(i).Quantity, roomList(i).Price)) | |
i += 1 | |
Loop | |
writer.Close() | |
'Display in listbox | |
'READ TEXT FILE | |
'Define variables | |
Dim strLine As String | |
Dim strData() As String | |
Dim reader As StreamReader | |
reader = New StreamReader("..\..\Rooms.txt") | |
lstDisplay.Items.Clear() | |
lstDisplay.Items.Add("Room Type".PadRight(30) + "#".PadRight(5) + "Price") | |
'Loop reader | |
i = 0 | |
Do Until reader.EndOfStream | |
strLine = reader.ReadLine() | |
strData = strLine.Split(Convert.ToChar("|")) | |
'Display in listbox | |
lstDisplay.Items.Add(strData(0).PadRight(30) + strData(1).PadRight(5) + FormatNumber(strData(2), 2)) | |
'Add to array | |
roomList(i) = New Room(strData(0), Convert.ToDouble(strData(1)), Convert.ToDouble(strData(2))) | |
i += 1 | |
Loop | |
reader.Close() | |
End Sub | |
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click | |
'CLEAR FIELDS | |
txtRoomType.Text = "" | |
numQuantity.Value = 0 | |
numPrice.Value = 0 | |
End Sub | |
Private Sub btnReturn_Click(sender As Object, e As EventArgs) Handles btnReturn.Click | |
'RETURN TO MAIN MENU | |
'Close form | |
Me.Hide() | |
'Open main menu | |
frmHotelMetropoleMainMenu.Show() | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment