Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help solving this assignment Below are the directions to the assignment, along with a pictures of what the win form should look like.

I need help solving this assignment

Below are the directions to the assignment, along with a pictures of what the win form should look like. Also there will be a starting code that i have to build my code around.

The code must be done in the C# programming language, and must be EXTREAMLY easy/ basic as I am very new to programming

Program must be a GUI (Graphic user interface)

You help would be much appreciated.

-------------------------------------------------------------------------------------------------------------------------

Modify a list class to use an indexer, a delegate, an event, and operators

In this 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

1. Open the InventoryMaintenance project in the Assignment2\InventoryMaintenance directory. This is an enhanced version of the Inventory Maintenance application from A1_Ex1 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

1. 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.

2. 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.

image text in transcribed

image text in transcribed

image text in transcribed

------------------------------------------------------------------------------------------------------------------

HERE IS THE CODE THAT THE ASSIGNMENT NEEDS TO BE WORKED AROUND!

InvItem.cs

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

namespace InventoryMaintenance { public class InvItem { private int itemNo; private string description; private decimal price;

public InvItem() { }

public InvItem(int itemNo, string description, decimal price) { this.itemNo = itemNo; this.description = description; this.price = price; }

public int ItemNo { get { return itemNo; } set { itemNo = value; } }

public string Description { get { return description; } set { description = value; } }

public decimal Price { get { return price; } set { price = value; } }

public string GetDisplayText() => itemNo + " " + description + " (" + price.ToString("c") + ")"; } }

InvItemDB.cs

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(); } } }

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 GetItemByIndex(int i) => 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); } }

Program.cs

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms;

namespace InventoryMaintenance { static class Program { ///

/// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmInvMaint()); } } }

Validator.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace InventoryMaintenance

{

public static class Validator

{

private static string title = "Entry Error";

public static string Title

{

get

{

return title;

}

set

{

title = value;

}

}

public static bool IsPresent(TextBox textBox)

{

if (textBox.Text == "")

{

MessageBox.Show(textBox.Tag + " is a required field.", Title);

textBox.Focus();

return false;

}

return true;

}

public static bool IsDecimal(TextBox textBox)

{

decimal number = 0m;

if (Decimal.TryParse(textBox.Text, out number))

{

return true;

}

else

{

MessageBox.Show(textBox.Tag + " must be a decimal value.", Title);

textBox.Focus();

return false;

}

}

public static bool IsInt32(TextBox textBox)

{

int number = 0;

if (Int32.TryParse(textBox.Text, out number))

{

return true;

}

else

{

MessageBox.Show(textBox.Tag + " must be an integer.", Title);

textBox.Focus();

return false;

}

}

public static bool IsWithinRange(TextBox textBox, decimal min, decimal max)

{

decimal number = Convert.ToDecimal(textBox.Text);

if (number max)

{

MessageBox.Show(textBox.Tag + " must be between " + min

+ " and " + max + ".", Title);

textBox.Focus();

return false;

}

return true;

}

}

}

-------------------------------------------------------

Thank you so much for all of your help

Inventory Maintenance 3245649 3762592 9210584 4738459 Agapanthus ($7.95) Lionium ($6.95) Snail pellets ($12.95) Japanese Red Maple (S89.95) Add Item Delete Item Exit

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_2

Step: 3

blur-text-image_3

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

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions