Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I really need help creating the code for my Visual Basic App that deals with serialized sequential files and classes . I have two forms:

I really need help creating the code for my Visual Basic App that deals with serialized sequential files and classes. I have two forms: Travel Request Form and the Request List Form. (pictured below). I also need a Travel record class. I need to add a serializable class to hold the input data, and a serialized sequential file (travel.ser) to store the data. I will also add a the secind form, Request List Form, that will display the data contained in the serialized sequential file.

TRAVEL REQUEST FORM: (form on the left)

This form will be the Startup Form for the application. When this form is Activated, aFileStream should be created in Append mode. If the data file does not yet exist (as is the case the first time the application runs, or of the file is deleted or moved from the specified location), the FileStream should be created in OpenOrCreate mode. When the Save Request Button is clicked the existing Project 5 code will execute, after which a call will be made to a Function named RecordSaved which will create an instance of the TravelRequest class that contains the GUID and user entered data and use a Binary Formatter to serialize the data to the record.ser file. The function will return a Boolean indicating whether or not the record was saved successfully or not. If an exception occurs during the save operation the function will display a Message Box displaying the exception message to the user before returning False REQUEST LIST FORM: (form on the right)

When this form is Activated, a FileStream should be created in Openmode with Read access. A call should also be made to a sub procedure named LoadList that will cause the contents of the travel.ser file to be deserialized and listed in the form's ListBox. If an exception is encountered during the execution of LoadList the FileStream should be closed. The Add Request Button will close the form, however, you need to be sure that whether the form is closed using the Add Request Button or the Control Box that FileStrteam is closed. It should be noted that since the Request List form was launched in dialog mode, its closing will reactivate the Travel Request form

TRAVEL RECORD CLASS: This will be a serializable public class. It will contain public members for each of the data fields identified in TableA. This class will have at least an empty constructor. You could also add a second constructor that will accept an argument for each of the public members if you desire. This class will override the To String function with a formatted string that contains each of the public members. You should use the following format:

String.Format("{0,-40}{1,-10}{2,-10}{3,-15}{4,12:d}{5,12:d}{6,12:C}" _ID, FirstName, LastName, Purpose, StartDate, EndDate, Amount)

image text in transcribed

Here is the code I have started for the Travel Request Form:

Public Class TravelRequestForm

Private Sub CancelButton_Click(sender As Object, e As EventArgs) Handles CancelButton.Click ClearInputControls 'Query user on close form Dim message As String Dim userResponse As MsgBoxResult message = "Do you want to close this form?" userResponse = MessageBox.Show(message, "Close Form?", MessageBoxButtons.YesNo) If userResponse = MsgBoxResult.Yes Then Me.Close() End If End Sub

Private Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click MessageLabel.Text = "Valdating Data ..." Try ValidateNotBlank(FirstNameBox) ValidateNotBlank(LastNameBox) ValidateNotBlank(PurposeBox) ValidateStartDate(StartDateBox) ValidateEndDate(EndDateBox, Convert.ToDateTime(StartDateBox.Text.Trim)) ValidateAmount(AmountBox) MessageLabel.Text = "All data is valid." Catch ex As Exception MessageLabel.Text = ex.Message End Try End Sub

Private Sub ClearInputControls() FirstNameBox.Clear() LastNameBox.Clear() PurposeBox.Clear() StartDateBox.Clear() EndDateBox.Clear() AmountBox.Clear() End Sub

Private Function ValidateNotBlank(input As TextBox) As Boolean If input.Text.Trim = String.Empty Then Throw New InputBlankException(input.Name & " cannot be blank.") Return False End If Return True End Function

Private Function ValidateStartDate(input As TextBox) As Boolean Dim startDate As Date Dim currentDate As Date = Today() Try startDate = Date.Parse(input.Text.Trim) If startDate

Private Function ValidateEndDate(input As TextBox, startDate As Date) As Boolean Dim endDate As Date Try endDate = Date.Parse(input.Text.Trim) If endDate

Private Function ValidateAmount(input As TextBox) As Boolean Dim amt As Double Try amt = Double.Parse(input.Text.Trim) Catch ex As Exception Throw ex Return False End Try If amt

Public Class InputBlankException Inherits Exception ' default constructor Public Sub New() MyBase.New("Input cannot be blank.") End Sub

' constructor for customizing error message Public Sub New(messageValue As String) MyBase.New(messageValue) End Sub

' constructor for customizing the exception's error ' message and specifying the InnerException object Public Sub New(messageValue As String, inner As Exception) MyBase.New(messageValue, inner) End Sub End Class 'InputBlankException

Public Class StartsInPastException Inherits Exception ' default constructor Public Sub New() MyBase.New("Start date is in the past.") End Sub

' constructor for customizing error message Public Sub New(messageValue As String) MyBase.New(messageValue) End Sub

' constructor for customizing the exception's error ' message and specifying the InnerException object Public Sub New(messageValue As String, inner As Exception) MyBase.New(messageValue, inner) End Sub End Class 'StartsInPastException

Public Class EndsBeforeStartException Inherits Exception ' default constructor Public Sub New() MyBase.New("End date is before start date.") End Sub

' constructor for customizing error message Public Sub New(messageValue As String) MyBase.New(messageValue) End Sub

' constructor for customizing the exception's error ' message and specifying the InnerException object Public Sub New(messageValue As String, inner As Exception) MyBase.New(messageValue, inner) End Sub End Class 'EndsBeforeStartException

Public Class NonPositiveAmountException Inherits Exception ' default constructor Public Sub New() MyBase.New("Requested amount must be greater than zero.") End Sub

' constructor for customizing error message Public Sub New(messageValue As String) MyBase.New(messageValue) End Sub

' constructor for customizing the exception's error ' message and specifying the InnerException object Public Sub New(messageValue As String, inner As Exception) MyBase.New(messageValue, inner) End Sub End Class 'NonPositiveAmountException End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

ISBN: 133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

When 81(27)^(x+2) is converted to base 3 , the exponent is

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago