C
C#9mo ago
u41c

Inventory Maintence Project Issue

I have two forms, one that lets you enter data for a new item. Once you hit Save, it should create a new InvItem object and add it to a list of inventory items and display it in the list. I can't seem to figure out how to get it to add the item. Any suggestions?
13 Replies
Angius
Angius9mo ago
someListOfItems.Add(newItem)
u41c
u41c9mo ago
There's a helper class called InvItemDB.cs and I'm somehow supposed to use a method from it to add the item and save it.
u41c
u41c9mo ago
Pastebin
InvItemDB.cs - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
u41c
u41c9mo ago
Here's the new item form
using System;
using System.Windows.Forms;

namespace InventoryMaintenance
{
public partial class frmNewItem : Form
{
public frmNewItem()
{
InitializeComponent();
}

InvItem invItem = null;

public InvItem GetNewItem()
{
if (IsValidData())
{
int newItemNumber = int.Parse(txtItemNo.Text);
string newDescription = txtDescription.Text;
decimal newPrice = decimal.Parse(txtPrice.Text);

return new InvItem(newItemNumber, newDescription, newPrice);
}

return null;
}

private bool IsValidData()
{
return Validator.IsPresent(txtItemNo) &&
Validator.IsInt32(txtItemNo) &&
Validator.IsPresent(txtDescription) &&
Validator.IsPresent(txtPrice) &&
Validator.IsDecimal(txtPrice);
}

private void btnSave_Click(object sender, EventArgs e)
{
if (IsValidData())
{
invItem = GetNewItem();
InvItemDB.GetItems();
this.Close();
}
}

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

namespace InventoryMaintenance
{
public partial class frmNewItem : Form
{
public frmNewItem()
{
InitializeComponent();
}

InvItem invItem = null;

public InvItem GetNewItem()
{
if (IsValidData())
{
int newItemNumber = int.Parse(txtItemNo.Text);
string newDescription = txtDescription.Text;
decimal newPrice = decimal.Parse(txtPrice.Text);

return new InvItem(newItemNumber, newDescription, newPrice);
}

return null;
}

private bool IsValidData()
{
return Validator.IsPresent(txtItemNo) &&
Validator.IsInt32(txtItemNo) &&
Validator.IsPresent(txtDescription) &&
Validator.IsPresent(txtPrice) &&
Validator.IsDecimal(txtPrice);
}

private void btnSave_Click(object sender, EventArgs e)
{
if (IsValidData())
{
invItem = GetNewItem();
InvItemDB.GetItems();
this.Close();
}
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
u41c
u41c9mo ago
No description
Angius
Angius9mo ago
That helper class lets you save a list of items to a file, yes
u41c
u41c9mo ago
No description
Angius
Angius9mo ago
So you need to read items from that file, add the new item, then save items to that file again
u41c
u41c9mo ago
Yeah but the list isn't updating once I save and load the items back.
Angius
Angius9mo ago
On btnSave click you get the items from file I don't see you saving them
u41c
u41c9mo ago
I've taken a long break from coding and this is very frustrating that I can't figure this out
private void btnAdd_Click(object sender, EventArgs e)
{
// Add code here that creates an instance of the New Item form
// and then gets a new item from that form.
// Create an instance of the frmNewItem form
frmNewItem newItemForm = new frmNewItem();

DialogResult result = newItemForm.ShowDialog();

if (result == DialogResult.OK)
{
InvItem newItem = newItemForm.GetNewItem();

if (newItem != null)
{
newItemForm.Close();
FillItemListBox();
lstItems.Items.Add(newItem);
}
}
else
{
}

newItemForm.Dispose();
}
private void btnAdd_Click(object sender, EventArgs e)
{
// Add code here that creates an instance of the New Item form
// and then gets a new item from that form.
// Create an instance of the frmNewItem form
frmNewItem newItemForm = new frmNewItem();

DialogResult result = newItemForm.ShowDialog();

if (result == DialogResult.OK)
{
InvItem newItem = newItemForm.GetNewItem();

if (newItem != null)
{
newItemForm.Close();
FillItemListBox();
lstItems.Items.Add(newItem);
}
}
else
{
}

newItemForm.Dispose();
}
FillItemListBox(); should do it, right?
Angius
Angius9mo ago
Where do you call InvItemDB.SaveItems(items)? Because that is what saves items to a file
u41c
u41c9mo ago
🤦‍♂️ oh lemme try that
Want results from more Discord servers?
Add your server
More Posts
❔ Factory Design method patternHello! Can some one help me with Factory Method, I am working on RPN Calculator project and need to ❔ Is there a way to make this more cleaner?```html <div class="buttons"> <div class="dropdown"> <a button type="button" class="btn btn-Is there a way to determine if a Winforms .exe is run by double clicking on it on Windows explorer?What I wish to achieve is nothing too fancy. I just want to determine if my winforms exe is run from❔ Recommended way to follow developments in C# / .NET world?I'm looking for a way to follow weekly or monthly developments in the C# / .NET world, something com✅ dotnet add reference in vscodethere is gui way to add reference in vscode instead of run command or type , i mean like vs communit❔ win form app desinger app erorrSeverity Code Description Project File Line Suppression State Error CS1061 '✅ ASP.NET EFC MVC deletes authentication cookie after next request.I've been having this issue that my asp.net app is deleting the login cookie right next request afte❔ What does "Specify the UNC path" mean when deploying using ClickOnce?I am attempting to deploy my application using ClickOnce, as per the title. I have set my publish lo❔ Stack Overflow Exception due to excessive cancellation token related method invocations?I'm getting a stack overflow exception at unpredicable times and upon investigation in Rider's paral❔ Insert a document to a MongoDBHey there... I am trying to build a simple API connected to a MongoDB. I have customers and I want