0% found this document useful (0 votes)
15 views10 pages

C# Inventory Management System Code

This document contains a C# implementation of an Inventory Management System that allows users to add, view, update, delete, and search for inventory items. It also includes functionality to save and load inventory data from a file. The program features a menu-driven interface for user interaction.

Uploaded by

cpm2earlyaccess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views10 pages

C# Inventory Management System Code

This document contains a C# implementation of an Inventory Management System that allows users to add, view, update, delete, and search for inventory items. It also includes functionality to save and load inventory data from a file. The program features a menu-driven interface for user interaction.

Uploaded by

cpm2earlyaccess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

using System;

using [Link];

using [Link];

public class InventoryItem

public string Name { get; set; }

public int Quantity { get; set; }

public decimal Price { get; set; }

public InventoryItem(string name, int quantity, decimal price)

Name = name;

Quantity = quantity;

Price = price;

public void DisplayItem()

[Link]($"Name: {Name}, Quantity: {Quantity}, Price:


{Price:C}");

public class InventoryManager

private List<InventoryItem> inventory = new List<InventoryItem>();


// Add Item

public void AddItem(string name, int quantity, decimal price)

[Link](new InventoryItem(name, quantity, price));

[Link]($"{name} added to inventory.");

// View All Items

public void ViewInventory()

if ([Link] == 0)

[Link]("Inventory is empty.");

return;

[Link]("\nCurrent Inventory:");

foreach (var item in inventory)

[Link]();

// Update Quantity

public void UpdateItemQuantity(string name, int newQuantity)

{
InventoryItem itemToUpdate = [Link](item =>
[Link](name, [Link]));

if (itemToUpdate != null)

[Link] = newQuantity;

[Link]($"Quantity for {name} updated to


{newQuantity}.");

else

[Link]($"Item '{name}' not found in inventory.");

// ⭐ Update Price

public void UpdateItemPrice(string name, decimal newPrice)

InventoryItem itemToUpdate = [Link](item =>


[Link](name, [Link]));

if (itemToUpdate != null)

[Link] = newPrice;

[Link]($"Price for {name} updated to {newPrice:C}");

else

{
[Link]($"Item '{name}' not found in inventory.");

// ⭐ Delete Item

public void DeleteItem(string name)

InventoryItem itemToDelete = [Link](item =>


[Link](name, [Link]));

if (itemToDelete != null)

[Link](itemToDelete);

[Link]($"{name} removed from inventory.");

else

[Link]($"Item '{name}' not found.");

// ⭐ Search Item

public void SearchItem(string name)

InventoryItem item = [Link](i => [Link](name,


[Link]));
if (item != null)

[Link]("Item found:");

[Link]();

else

[Link]($"Item '{name}' not found.");

// ⭐ Save Inventory to File

public void SaveToFile(string filename)

using (StreamWriter writer = new StreamWriter(filename))

foreach (var item in inventory)

[Link]($"{[Link]},{[Link]},{[Link]}");

[Link]("Inventory saved to file.");

// ⭐ Load Inventory from File

public void LoadFromFile(string filename)

{
if (![Link](filename))

[Link]("File not found.");

return;

[Link]();

string[] lines = [Link](filename);

foreach (var line in lines)

string[] parts = [Link](',');

[Link](new InventoryItem(parts[0], [Link](parts[1]),


[Link](parts[2])));

[Link]("Inventory loaded from file.");

// Menu System

public void Run()

while (true)

[Link]("\nInventory Management System Menu:");

[Link]("1. Add Item");

[Link]("2. View Inventory");


[Link]("3. Update Item Quantity");

[Link]("4. Update Item Price");

[Link]("5. Delete Item");

[Link]("6. Search Item");

[Link]("7. Save Inventory to File");

[Link]("8. Load Inventory from File");

[Link]("9. Exit");

[Link]("Enter your choice: ");

string choice = [Link]();

switch (choice)

case "1":

[Link]("Enter item name: ");

string name = [Link]();

[Link]("Enter quantity: ");

int quantity = [Link]([Link]());

[Link]("Enter price: ");

decimal price = [Link]([Link]());

AddItem(name, quantity, price);

break;

case "2":

ViewInventory();

break;
case "3":

[Link]("Enter name of item to update: ");

string updateName = [Link]();

[Link]("Enter new quantity: ");

int newQuantity = [Link]([Link]());

UpdateItemQuantity(updateName, newQuantity);

break;

case "4":

[Link]("Enter name of item to update price: ");

string priceName = [Link]();

[Link]("Enter new price: ");

decimal newPrice = [Link]([Link]());

UpdateItemPrice(priceName, newPrice);

break;

case "5":

[Link]("Enter name of item to delete: ");

string deleteName = [Link]();

DeleteItem(deleteName);

break;

case "6":

[Link]("Enter name of item to search: ");

string searchName = [Link]();

SearchItem(searchName);

break;
case "7":

[Link]("Enter filename to save: ");

string saveFile = [Link]();

SaveToFile(saveFile);

break;

case "8":

[Link]("Enter filename to load: ");

string loadFile = [Link]();

LoadFromFile(loadFile);

break;

case "9":

[Link]("Exiting Inventory Management System.


Goodbye!");

return;

default:

[Link]("Invalid choice. Please try again.");

break;

public class Program


{

public static void Main(string[] args)

InventoryManager manager = new InventoryManager();

[Link]();

You might also like