Question: Open the project and review the code 1 . Open the InventoryMaintenance project. This is an enhanced version of the Inventory Maintenance application from module
Open the project and review the code
Open the InventoryMaintenance project. This is an enhanced version of the Inventory Maintenance application from module six that uses a list class.
InventoryMaintenance zipDownload InventoryMaintenance zip
Review the code for the InvItemList class so you understand how it works. Then, review the code for the Inventory Maintenance form to see how it uses this class. Finally, run the application to see how it works.
Add an index to the InvItemList class
Delete the GetItemByIndex method from the InvItemList class, and replace it with an indexer that receives an int value. This indexer should include both get and set accessors, and the get accessor should check that the value thats passed to it is a valid index. If the index isnt valid, the accessor should throw an ArgumentOutOfRangeException with a message that consists of the index value.
Modify the Invoice Maintenance form to use this indexer instead of the GetItemByIndex method. Then, test the application to be sure it still works.
Add overloaded operators to the InvItemList class
Add overloaded and operators to the InvItemList class that add and remove an inventory item from the inventory item list.
Modify the Inventory Maintenance form to use these operators instead of the Add and Remove methods. Then, test the application to be sure it still works.
Add a delegate and an event to the InvItemList class
Add a delegate named ChangeHandler to the InvItemList class. This delegate should specify a method with a void return type and an InvItemList parameter.
Add an event named Changed to the InvItemList class. This event should use the ChangeHandler delegate and should be raised any time the inventory item list changes.
Modify the Inventory Maintenance form to use the Changed event to save the inventory items and refresh the list box any time the list changes. To do that, youll need to code an event handler that has the signature specified by the delegate, youll need to wire the event to the event handler, and youll need to remove any unnecessary code from the event handlers for the Save and Delete buttons. When youre done, test the application to be sure it still works. Take a screenshot.
The code Im working with below
invitemlist.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InventoryMaintenance
public class InvItemList
private List invItems;
public InvItemList
invItems new List;
public int Count invItems.Count;
public InvItem GetItemByIndexint i invItemsi;
public void AddInvItem invItem invItems.AddinvItem;
public void Addint itemNo, string description, decimal price
InvItem i new InvItemitemNo description, price;
invItems.Addi;
public void RemoveInvItem invItem invItems.RemoveinvItem;
public void Fill invItems InvItemDB.GetItems;
public void Save InvItemDB.SaveItemsinvItems;
frminvmaint.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace InventoryMaintenance
public partial class frmInvMaint : Form
public frmInvMaint
InitializeComponent;
private InvItemList invItems new InvItemList;
private void frmInvMaintLoadobject sender EventArgs e
invItems.Fill;
FillItemListBox;
private void FillItemListBox
InvItem item;
lstItems.Items.Clear;
for int i ; i invItems.Count; i
item invItems.GetItemByIndexi;
lstItems.Items.AdditemGetDisplayText;
private void btnAddClickobject sender EventArgs e
frmNewItem newItemForm new frmNewItem;
InvItem invItem newItemForm.GetNewItem;
if invItem null
invItems.AddinvItem;
invItems.Save;
FillItemListBox;
private void btnDeleteClickobject sender EventArgs e
int i lstItems.SelectedIndex;
if i
InvItem invItem invItems.GetItemByIndexi;
string message "Are you sure you want to delete
invItem.Description ;
DialogResult button
MessageBox.Showmessage "Confirm Delete",
MessageBoxButtons.YesNo;
if button DialogResult.Yes
invItems.RemoveinvItem;
invItems.Save;
FillItemListBox;
private void btnExitClickobject sender EventArgs e
this.Close;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
