Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete in C# In this exercise, you'll add two classes to the Inventory Maintenance app that inherit the InventoryItem class. Then, you'll add code

Please complete in C#
In this exercise, you'll add two classes to the Inventory Maintenance app that inherit
the InventoryItem class. Then, you'll add code to the forms to provide for these new
classes.
1.Open the InventoryMaintenance project in the ExtraStarts ??? Ch 14 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.
2.Display the InventoryItem class and modify the GetDisplayText () method so it's
overridable.
3.Add a class named Plant that inherits the InventoryItem 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:
32456491 gallon Agapanthus ($7.95)
4.Add another class named Supply that inherits the InventoryItem 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)
5.Modify the event handler for the Click event of the Save button on the New Item
form so it creates a new item of the appropriate type using the data entered by the
user.
6.Modify the event handler for the Click event of the Add button on the Inventory
Maintenance form so it displays a dialog indicating that the item has been added
successfully, as shown above. The message should use the Size and Description
properties for a Plant object, and the Manufacturer and Description properties for
a Supply object.
7.Test the app by adding at least one of each type of inventory item.
This is the code I have so far:
using System.Xml.Linq;
namespace InventoryMaintenance
{
public partial class frmNewItem : Form
{
public frmNewItem()
{
InitializeComponent();
}
private InventoryItem item = null!;
public InventoryItem GetNewItem()
{
rdoPlant.Checked = true;
this.ShowDialog();
return item;
}
private void rdoPlant_CheckedChanged(object sender, EventArgs e)
{
if (rdoPlant.Checked)
lblSizeOrManufacturer.Text = "Size:";
else
lblSizeOrManufacturer.Text = "Manufacturer:";
LoadComboBox();
}
private void LoadComboBox()
{
cboSizeOrManufacturer.Items.Clear();
if (rdoPlant.Checked)
{
cboSizeOrManufacturer.Items.Add("1 gallon");
cboSizeOrManufacturer.Items.Add("5 gallon");
cboSizeOrManufacturer.Items.Add("15 gallon");
cboSizeOrManufacturer.Items.Add("24-inch box");
cboSizeOrManufacturer.Items.Add("36-inch box");
}
else
{
cboSizeOrManufacturer.Items.Add("Bayer");
cboSizeOrManufacturer.Items.Add("Jobe's");
cboSizeOrManufacturer.Items.Add("Ortho");
cboSizeOrManufacturer.Items.Add("Roundup");
cboSizeOrManufacturer.Items.Add("Scotts");
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (IsValidData())
{
item = new(
Convert.ToInt32(txtItemNo.Text),
txtDescription.Text,
Convert.ToDecimal(txtPrice.Text)
);
this.Close();
}
}
private bool IsValidData()
{
bool success = true;
string errorMessage ="";
errorMessage += Validator.IsPresent(txtItemNo.Text, "Item no");
errorMessage += Validator.IsInt32(txtItemNo.Text, "Item no");
errorMessage += Validator.IsPresent(txtDescription.Text, "Description");
errorMessage += Validator.IsPresent(txtPrice.Text, "Price");
errorMessage += Validator.IsDecimal(txtPrice.Text, "Price");
// Validate combo box - use label text for name - remove ending colon
string name = lblSizeOrManufacturer.Text.Substring(0, lblSizeOrManufacturer.Text.Length -1);
errorMessage += Validator.IsSelected(cboSizeOrManufacturer.SelectedIndex, name);
if (errorMessage !="")
{
success = false;
MessageBox.Show(errorMessage, "Entry Error");
image text in transcribed

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

More Books

Students also viewed these Databases questions