Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inventory Maintenance Hello I have been working on this problem for quite some time now and I stuck and need some help finishing it! The

Inventory Maintenance

Hello I have been working on this problem for quite some time now and I stuck and need some help finishing it!

The code must be done with the c# language and needs to be super basic and easy to understand as I am a beginner.

The directions to the assignment along with what I have done so far are below

If you could please highlighy any changes that you make that would be amazing

Please help me get this program working properly! Thanks!

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

Open the InventoryMaintenance project in the Assignments3\InventoryMaintenance directory. Then, review the code for the New Item form to see that the items in the combo box and the label for the combo box depend on which radio button is selected.

Display the InvItem Class and modify the GetDisplayText method so its overridable.

Add a class named Plant that inherits the InvItem class. This new class should add a string property named Size. It should also provide a default constructor and a constructor that accepts four parameters (item number, description, price, and size) to initialize the class properties. This constructor should call the base class constructor to initialize the properties defined by that class. Finally, this class should override the GetDisplayText method to add the size in front of the description, as in this example:

3245649 1 gallon Agapanthus ($7.95)

Add another class named Supply that inherits the InvItem class and adds a string property named Manufacturer. Like the Plant class, the Supply class should provide a default constructor and a constructor that accepts four parameters, and it should override the GetDisplayText method so the manufacturer is added in front of the description like this:

9210584 Ortho Snail pellets ($12.95)

Modify the event handler for the Click event of the Save button on New Item form so it creates a new item of the appropriate type using the data entered by the user.

Test the application by adding at least one of each type of inventory item.

image text in transcribed

image text in transcribed

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

And here is what I have done so far! PLEASE HELP!

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 EX_1_Inventory_Maintenance { public partial class frmInvMaint : Form { public frmInvMaint() { InitializeComponent(); } private InvItemList invItems = new InvItemList();

private void frmInvMaint_Load(object sender, EventArgs e) { invItems.Changed += new InvItemList.ChangeHandler(HandleChange); invItems.Fill(); FillItemListBox(); }

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

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

private void btnDelete_Click(object sender, EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { InvItem invItem = invItems[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 -= invItem; } } }

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

} private void HandleChange(InvItemList invItems) { invItems.Save(); FillItemListBox(); } } }

frmNewItem.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 EX_1_Inventory_Maintenance { public partial class frmNewItem : Form { public frmNewItem() { InitializeComponent(); } private InvItem invItem = null; public InvItem GetNewItem() { LoadComboBox(); this.ShowDialog(); return invItem; } private void LoadComboBox() { cboManufacture.Items.Clear(); if (rdoPlant.Checked) { cboManufacture.Items.Add("1 gallon"); cboManufacture.Items.Add("5 gallon"); cboManufacture.Items.Add("15 gallon"); cboManufacture.Items.Add("24-inch box"); cboManufacture.Items.Add("36-inch box"); } else { cboManufacture.Items.Add("Bayer"); cboManufacture.Items.Add("Jobe's"); cboManufacture.Items.Add("Ortho"); cboManufacture.Items.Add("Roundup"); cboManufacture.Items.Add("Scotts"); } }

private void btnSave_Click(object sender, EventArgs e) { if (IsValidData()) { invItem = new InvItem(Convert.ToInt32(txtItemNo.Text), txtDescription.Text, Convert.ToDecimal(txtPrice.Text)); this.Close(); } } private bool IsValidData() { return Validator.IsPresent(txtItemNo) && Validator.IsInt32(txtItemNo) && Validator.IsPresent(txtDescription) && Validator.IsPresent(txtPrice) && Validator.IsDecimal(txtPrice); }

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

private void rdoPlant_CheckedChanged(object sender, EventArgs e) { if (rdoPlant.Checked) { lblManSize.Text = "Size:"; } else { lblManSize.Text = "Manufacturer:"; } LoadComboBox(); }

private void cboManufacture_SelectedIndexChanged(object sender, EventArgs e) {

} } }

InvItem.cs

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

namespace EX_1_Inventory_Maintenance { 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 virtual 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 EX_1_Inventory_Maintenance { 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; xmlIn.ReadStartElement("Item"); string type = xmlIn.ReadElementContentAsString(); if (type == "Plant") { Plant p = new Plant(); ReadBase(xmlIn, p); p.Size = xmlIn.ReadElementContentAsString(); item = p; } else { Supply s = new Supply(); ReadBase(xmlIn, s); s.Manufacturer = xmlIn.ReadElementContentAsString(); item = s; } items.Add(item); } while (xmlIn.ReadToNextSibling("Item")); }

// close the XmlReader object xmlIn.Close(); return items; } private static void ReadBase(XmlReader xmlIn, InvItem i) { i.ItemNo = xmlIn.ReadElementContentAsInt(); i.Description = xmlIn.ReadElementContentAsString(); i.Price = xmlIn.ReadElementContentAsDecimal(); } 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"); if (item.GetType().Name == "Plant") { Plant p = (Plant)item; xmlOut.WriteElementString("Type", "Plant"); WriteBase(p, xmlOut); xmlOut.WriteElementString("Size", p.Size); } else { Supply s = (Supply)item; xmlOut.WriteElementString("Type", "Supply"); WriteBase(s, xmlOut); xmlOut.WriteElementString("Manufacturer", s.Manufacturer); } xmlOut.WriteEndElement(); } // write the end tag for the root element xmlOut.WriteEndElement(); // close the xmlWriter object xmlOut.Close(); } private static void WriteBase(InvItem item, XmlWriter xmlOut) { xmlOut.WriteElementString("ItemNo", Convert.ToString(item.ItemNo)); xmlOut.WriteElementString("Description", item.Description); xmlOut.WriteElementString("Price", Convert.ToString(item.Price)); } }

}

InvItemList.cs

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

namespace EX_1_Inventory_Maintenance { public class InvItemList { private List invItems; public delegate void ChangeHandler(InvItemList invItems); public event ChangeHandler Changed; public InvItemList() { invItems = new List(); } public int Count => invItems.Count; public InvItem this[int i] { get { if (i invItems.Count) { throw new ArgumentOutOfRangeException(i.ToString()); } return invItems[i]; } set { invItems[i] = value; Changed(this); } } public void Add(InvItem invItem) { invItems.Add(invItem); Changed(this); } public void Add(int itemNo, string description, decimal price) { InvItem i = new InvItem(itemNo, description, price); invItems.Add(i); Changed(this); } public void Remove(InvItem invItem) { invItems.Remove(invItem); Changed(this); } public static InvItemList operator +(InvItemList il, InvItem i) { il.Add(i); return il; } public static InvItemList operator -(InvItemList il, InvItem i) { il.Remove(i); return il; } public void Fill() => invItems = InvItemDB.GetItems(); public void Save() => InvItemDB.SaveItems(invItems);

} }

Validator.cs

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

namespace EX_1_Inventory_Maintenance { public 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 for your help

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago