Question
I could use some assistance with this question. Here is what I have so far, pleae help me make it work. The code must be
I could use some assistance with this question.
Here is what I have so far, pleae help me make it work.
The code must be in C#, and must be easy/ basic as possible because I am a beginner.
-------------------------------------------------------------------------------
Create and use an Inventory Item class
In this exercise, youll add a class to an Inventory Maintenance application and then add code to the two forms that use this class.
Open the project and add an InvItem class
1. Open the InventoryMaintenance project in the Assignments\InventoryMaintenance directory. Then, review the existing code for both of the forms so you get an idea of how this application should work.
1. Add a class named InvItem to this project, and add the properties, method, and constructors that are shown in the table below.
Property Description
ItemNo Gets or sets an int that contains the items number.
Description Gets or sets a string that contains the items description.
Price Gets or sets a decimal that contains the items price.
Method Description
GetDisplayText() Returns a string that contains the items number, description, and price formatted like this: 3245649 Agapanthus ($7.95). (The item number and description are separated by four spaces.)
Constructor Description
() Creates an InvItem object with default values.
(itemNo, description, price) Creates an InvItem object with the specified values.
Add code to implement the New Item form
2. Display the code for the New Item form, and declare a class variable named invItem of type InvItem with an initial value of null.
3. Add a public method named GetNewItem that displays the form as a dialog box and returns an InvItem object.
4. Add code to the btnSave_Click event handler that creates a new InvItem object and closes the form if the data is valid.
Add code to implement the Inventory Maintenance form
5. Display the code for the Inventory Maintenance form, and declare a class variable named invItems of type List
6. Add a statement to the frmInvMaint_Load event handler that uses the GetItems method of the InvItemDB class to load the items list.
7. Add code to the FillItemListBox method that adds the items in the list to the Items list box. Use the GetDisplayText method of the InvItem class to format the item data.
8. Add code to the btnAdd_Click event handler that creates a new instance of the New Item form and executes the GetNewItem method of that form. If the InvItem object thats returned by this method is not null, this event handler should add the new item to the list, call the SaveItems method of the InvItemDB class to save the list, and then refresh the Items list box. Test the application to be sure this event handler works.
9. Add code to the btnDelete_Click event handler that removes the selected item from the list, calls the SaveItems method of the InvItemDB class to save the list, and refreshes the Items list box. Be sure to confirm the delete operation. Then, test the application to be sure this event handler works.
-------------------------------------------------------------------------------------------------------------------------------------------
HERE IS WHAT I HAVE SO FAR
InvitemDB.cs
namespace InventoryMaintenance { public static class InvItemDB { private const string Path = @"..\..\InventoryItems.xml";
public static 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
// 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(); } } }
Program.cs
namespace InventoryMaintenance { static class Program { ///
Validator.cs
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!!!! I could really use the 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 ExitStep 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