Question: Extra 11-1 Create and use an Inventory Item class In this exercise, youll add a class to an Inventory Maintenance application and then add code

Extra 11-1 Create and use an Inventory Item class

In this exercise, youll add a class to an Inventory Maintenance application and then add code to the two forms that use this class.

Open the project and add an InvItem class

Open the InventoryMaintenance project in the Extra Exercises\Chapter 11\InventoryMaintenance directory. Then, review the existing code for both of the forms so you get an idea of how this application should work.

Add a class named InvItem to this project, and add the properties, method, and constructors that are shown in the table below. Use standard properties rather than auto-implemented properties.

Property Description

ItemNo Gets or sets an integer that contains the items number.

Description Gets or sets a string that contains the items description.

Price Gets or sets a decimal that contains the items price.

Method Description

GetDisplayText() Returns a string that contains the items number, description, and price formatted like this: 3245649 Agapanthus ($7.95). (The item number and description are separated by four spaces.)

Constructor Description

New() Creates an InvItem object with default values.

New(itemNo, description, price) Creates an InvItem object with the specified values.

Add code to implement the New Item form

Display the code for the New Item form, and declare a public module-level variable named InvItem of type InvItem.

Add code to the btnSave_Click event handler that creates a new InvItem object, assigns it to the invItem variable, and closes the form if the data is valid.

Add code to implement the Inventory Maintenance form

Display the code for the Inventory Maintenance form, and declare a module-level variable named invItems of type List(Of InvItem).

Add a statement to the frmInvMaint_Load event handler that uses the GetItems method of the InvItemDB class to load the items list.

Add code to the FillItemListBox method that adds the items in the list to the Items list box. Use the GetDisplayText method of the InvItem class to format the item data.

Add code to the btnAdd_Click event handler that creates a new instance of the New Item form and displays it as a dialog box. If the InvItem object thats stored in the public InvItem variable of this dialog box is not equal to Nothing, this event handler should add the new item to the list, call the SaveItems method of the InvItemDB class to save the list, and then refresh the Items list box. Test the application to be sure this event handler works.

Add code to the btnDelete_Click event handler that removes the selected item from the list, calls the SaveItems method of the InvItemDB class to save the list, and refreshes the Items list box. Be sure to confirm the delete operation. Then, test the application to be sure this event handler works.

Public Class frmInvMaint

' Add a statement here that declares the list of items.

Private Sub frmInvMaint_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Add code here that gets the list of items and fills the list box. End Sub

Private Sub FillItemListBox() lstItems.Items.Clear() ' Add code here that loads the list box with the items in the list. End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click ' Add code here that creates an instance of the New Item form, ' displays the form as a dialog box, and gets the new item ' entered on that form. End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click Dim i As Integer = lstItems.SelectedIndex If i <> -1 Then ' Add code here that displays a dialog box to confirm ' the deletion and then removes the item from the list, ' saves the list of products, and refreshes the list box ' if the deletion is confirmed. End If End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class

Public Class frmNewItem

' Add a statement here that declares a public inventory item.

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click If IsValidData() Then ' Add code here that creates a new item ' and closes the form. End If End Sub

Private Function IsValidData() As Boolean Return Validator.IsPresent(txtItemNo) AndAlso Validator.IsInt32(txtItemNo) AndAlso Validator.IsPresent(txtDescription) AndAlso Validator.IsPresent(txtPrice) AndAlso Validator.IsDecimal(txtPrice) End Function

Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click Me.Close() End Sub End Class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!