Download the Inventory.txt text file from the Homework Assignments folder for our class

  • I suggest you make a backup copy of the file

Create the form on the next page

  • ID is a combo box
  • Quantity change is a textbox. Integers can be positive or negative amount
  • The large box is a ListBox

Add a class (or can download clsInventory and include in project)

  • Create class-level variables for Product ID, Item Name, Quantity, and a separator
  • Create a constructor with a string argument (one line that was read from the text file)
  • Split the string and create properties for ID, Item Name, Quantity
    • Note: Quantity is an integer
  • Create a read-only property to set up the string used in the list box
  • Create a read-only property to set up the string used to write a line to the text file
  • Create a static method GetItems()
    • Set up a StreamReader
    • Create a collection list
    • Until end of stream: read a line, create a class object, add to the collection list
    • Close the stream
    • Return the collection list
  • Create a static method WriteItems()
    • Set up a StreamWriter
    • Use a ForEach to loop through the objects in the class-level collection list Write a line to the text file
    • Close the stream

In the form file:

  • The only class-level variable in the form file will be a collection list
  • In the Load event:
    • Fill the combo box with the item numbers
    • Fill the list box with data from the file
  • In the Update button click event:
    • If nothing is selected from the combo box display an error message
    • If the change quantity is empty, display an error message
    • If the change quantity cannot be converted (in a TryParse), display an error message
    • Use a ForEach to loop through the objects in the class-level collection list When the ID in the combo box matches the ID in the file, add the change amount to the Quantity property (unless that new quantity would be less than zero. If so, display an error message, clear the quantity text box, reset the focus, and return.)
    • Reset the DataSource and DisplayMember for the list box
    • Clear the text box and set the combo boxs selected index to -1
  • In the Exit event:
    • Use the WriteItems method

Before the Update button is clicked See image.

When the form opens, the combo box is filled and the files text is displayed in the list box

User can repeatedly select items from the combo box, enter a quantity change amount (positive numbers will increase the quantity, negative numbers will decrease the quantity), and click the Update button

Each time the Update Quantity button is clicked, the new collection is displayed in the list box

When the Exit button is clicked, the collection is written to the text file

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.