Question
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.
--------------------------------------------------------------------------------------------------------------------------------------------
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
// 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
}
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
} }
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started