Question
I could really use some help finishing this question! I have some some done, but I cannot figure out how to make it work properly.
I could really use some help finishing this question!
I have some some done, but I cannot figure out how to make it work properly. Can you please look at it and tell me what is wrong so that I can fix it and get it working properly?
First I will show you the direcions for the assignment, then I will show you what I have so far. Thanks.
The below assignment is made up of two windows forms, and one 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.
------------------------------------------------------------------------------------------------------
Now here is what I have done so far!
FORM 1
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 EX1_Inventory_Maintenance { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { int products = 0; int Product = 0; }
private List
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { products = ProductDB.GetProducts(); FillItemListBox();
} private void FillItemListBox() { lstProducts.Items.Clear(); foreach (Product p in products) { lstProduct.Items.Add(p.GetDisplayText("\t")); } }
private void btnAdd_Click(object sender, EventArgs e) { frmNewProduct newProductForm = new frmNewProduct(); Product product = newProductForm.GetNewProduct(); if (product != null) { products.Add(product); ProductDB.SaveProducts(products); ; FillProductListBox();
} }
private void btnDelete_Click(object sender, EventArgs e) { int i = lstProducts.SelectedIndex; if (i != -1) { Product product = products[i]; string message = "Are you sure you want to delete this product?" + product.Description; DialogResult button = MessageBox.Show(message, "Conferm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { product.Remove(product); ProductDB.SaveProducts(products); FillProductListBox(); }
} }
private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }
FORM 2 (PRODUCT ENTRY)
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 EX1_Inventory_Maintenance { public partial class frmNewProduct : Form { public frmNewProduct() { InitializeComponent(); } private Product products = null; public Product GetNewProduct() { this.ShowDialog(); return products; }
private void btnSave_Click(object sender, EventArgs e) { if (IsValidData()) { products = new Product(Itemtxt.Text, txtDescription.Text, Convert.ToDecimal(txtPrice.Text)); this.Close(); } } private bool IsValidData() { return Valdator.IsPresent(Itemtxt) && Validator.IsPresent(txtPrice) && Validator.IsDecimal(txtPrice) && Validator.IsPresent(txtDescription);
}
private void btnCancle_Click(object sender, EventArgs e) { this.Close(); } } }
CLASS (VALIDATOR)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace EX1_Inventory_Maintenance { public static class Validator public static string title = "Entry Error"; public static string Title { get { return title; } set { title = value;
} } public static bool IsPrsent(TextBox textbox) { if (textBox.Text == "") { MessageBox.Show(textbox.Tag + " is a required feild." 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; } } }
--------------------------------------------------------------------
PLEASE 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 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