Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this Visual Basic exercise, youll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event,

In this Visual Basic exercise, youll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators. Then, youll modify the code for the Inventory Maintenance form so it uses these features. Open the project and review the code 18. Please review the Inventory Maintenance application code below. 19. 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 20. 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. 21. 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 22. Add overloaded + and - operators to the InvItemList class that add and remove an inventory item from the inventory item list. 23. 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 24. Add a delegate named ChangeHandler to the InvItemList class. This delegate should specify a method with a void return type and an InvItemList parameter. 25. 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. 26. 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.

InventoryMaintenance code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml;

namespace InventoryMaintenance { public static class InvItemDB { private const string Path = @"..\..\InventoryItems.xml";

public static List GetItems() { // create the list List items = new List();

// create the XmlReaderSettings object XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true;

// create the XmlReader object XmlReader xmlIn = XmlReader.Create(Path, settings);

// read past all nodes to the first Book node if (xmlIn.ReadToDescendant("Item")) { // create one Product object for each Product node do { InvItem item = new InvItem(); xmlIn.ReadStartElement("Item"); item.ItemNo = xmlIn.ReadElementContentAsInt(); item.Description = xmlIn.ReadElementContentAsString(); item.Price = xmlIn.ReadElementContentAsDecimal(); items.Add(item); } while (xmlIn.ReadToNextSibling("Item")); } // close the XmlReader object xmlIn.Close();

return items; }

public static void SaveItems(List items) { // create the XmlWriterSettings object XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" ");

// create the XmlWriter object XmlWriter xmlOut = XmlWriter.Create(Path, settings);

// write the start of the document xmlOut.WriteStartDocument(); xmlOut.WriteStartElement("Items");

// write each product object to the xml file foreach (InvItem item in items) { xmlOut.WriteStartElement("Item"); xmlOut.WriteElementString("ItemNo", Convert.ToString(item.ItemNo)); xmlOut.WriteElementString("Description", item.Description); xmlOut.WriteElementString("Price", Convert.ToString(item.Price)); xmlOut.WriteEndElement(); }

// write the end tag for the root element xmlOut.WriteEndElement();

// close the xmlWriter object xmlOut.Close(); } } }

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Find each square root. If it is not a real number, say so. V225

Answered: 1 week ago