Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

namespace InventoryMaintenance { public partial class frmInvMaint : Form { public frmInvMaint() { InitializeComponent(); } private InvItemList invItems = new InvItemList(); private void frmInvMaint_Load(object sender,

image text in transcribed

namespace InventoryMaintenance { public partial class frmInvMaint : Form { public frmInvMaint() { InitializeComponent(); }

private InvItemList invItems = new InvItemList();

private void frmInvMaint_Load(object sender, System.EventArgs e) { invItems.Fill(); FillItemListBox(); }

private void FillItemListBox() { InvItem item; lstItems.Items.Clear(); for (int i = 0; i

private void btnAdd_Click(object sender, System.EventArgs e) { frmNewItem newItemForm = new frmNewItem(); InvItem invItem = newItemForm.GetNewItem(); if (invItem != null) { invItems.Add(invItem); invItems.Save(); FillItemListBox(); } }

private void btnDelete_Click(object sender, System.EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { InvItem invItem = invItems.GetItemByIndex(i); string message = "Are you sure you want to delete " + invItem.Description + "?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { invItems.Remove(invItem); invItems.Save(); FillItemListBox(); } } }

private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }

InvItemList.cs ------------------------

namespace InventoryMaintenance { public class InvItemList { private List invItems;

public InvItemList() { invItems = new List(); }

public int Count { get { return invItems.Count; } }

public InvItem GetItemByIndex(int i) { return invItems[i]; }

public void Add(InvItem invItem) { invItems.Add(invItem); }

public void Add(int itemNo, string description, decimal price) { InvItem i = new InvItem(itemNo, description, price); invItems.Add(i); }

public void Remove(InvItem invItem) { invItems.Remove(invItem); }

public void Fill() { invItems = InvItemDB.GetItems(); }

public void Save() { InvItemDB.SaveItems(invItems); } } }

Extra 13-1 Modify a list class to use an indexer, a delegate, an event, and operators In this exercise, you'll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators. Then, you'll modify the code for the Inventory Maintenance form so it uses these features. Open the project and review the code 1. Open the InventoryMaintenance project in the Extra Exercises Chapter 13\InventoryMaintenance directory. This is an enhanced version of the Inventory Maintenance application from extra exercise 12-1 that uses a list class. 2. 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 3. 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 that's passed to it is a valid index. If the index isn't valid, the accessor should throw an ArgumentOutOfRangeException with a message that consists of the index value. 4. 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 5. Add overloaded + and - operators to the InvitemList class that add and remove an inventory item from the inventory item list. 6. 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 7. Add a delegate named ChangeHandler to the InvitemList class. This delegate should specify a method with a void return type and an InvitemList parameter. 8. 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. 9. 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, you'll need to code an event handler that has the signature specified by the delegate, you'll need to wire the event to the event handler, and you'll need to remove any unnecessary code from the event handlers for the Save and Delete buttons. When you're done, test the application to be sure it still works. Extra 13-1 Modify a list class to use an indexer, a delegate, an event, and operators In this exercise, you'll modify a class that stores a list of inventory items so it uses an indexer, a delegate, an event, and operators. Then, you'll modify the code for the Inventory Maintenance form so it uses these features. Open the project and review the code 1. Open the InventoryMaintenance project in the Extra Exercises Chapter 13\InventoryMaintenance directory. This is an enhanced version of the Inventory Maintenance application from extra exercise 12-1 that uses a list class. 2. 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 3. 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 that's passed to it is a valid index. If the index isn't valid, the accessor should throw an ArgumentOutOfRangeException with a message that consists of the index value. 4. 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 5. Add overloaded + and - operators to the InvitemList class that add and remove an inventory item from the inventory item list. 6. 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 7. Add a delegate named ChangeHandler to the InvitemList class. This delegate should specify a method with a void return type and an InvitemList parameter. 8. 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. 9. 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, you'll need to code an event handler that has the signature specified by the delegate, you'll need to wire the event to the event handler, and you'll need to remove any unnecessary code from the event handlers for the Save and Delete buttons. When you're done, test the application to be sure it still works

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions