Question: Code: Visual Basic Question: Add a class to an Inventory Maintenance application and then add code to the two forms that use this class. Code
Code: Visual Basic
Question:
Add a class to an Inventory Maintenance application and then add code to the two forms that use this class.
Code below is for the 2 forms:
Form1: 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
Form 2: 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
1. Add a class named InvItem to this project, and add the properties, method, and constructors that are shown in the table below.
Add code to implement the New Item form 2. Display the code for the New Item form, and declare a public module-level variable named InvItem of type InvItem.
3. 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 4. Display the code for the Inventory Maintenance form, and declare a module-level variable named invItems of type List(Of InvItem).
5. Add a statement to the frmInvMaint_Load event handler that uses the GetItems method of the InvItemDB class to load the items list.
6. 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.
7. 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.
8. Reenter the code from above into the text box below. Make sure you have adequately commented your code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
