Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MidtermProj_Sim_134713
- {
- class Inventory
- {
- public Items[] inventoryitems;
- public int max;
- public int current;
- int inventorycode2;
- double inventoryprice2;
- bool validinventorycode;
- bool validinventoryprice;
- string inventorycode;
- string inventoryname;
- string inventoryprice;
- public Inventory()
- {
- max = 25;
- inventoryitems = new Items[max];
- current = 0;
- }
- public Items Find(string inventorycode)
- {
- Items target = null;
- for (int i = 0; i < max; i++)
- {
- if (inventoryitems[i] != null)
- {
- if (inventorycode == inventoryitems[i].GetCode())
- {
- target = inventoryitems[i];
- break;
- }
- }
- }
- return target;
- }
- public void AddItems()
- {
- Console.Clear();
- do
- {
- Console.Write("Input Inventory Code: ");
- inventorycode = Console.ReadLine();
- validinventorycode = int.TryParse(inventorycode, out inventorycode2);
- if (inventorycode == "\\c")
- {
- Console.WriteLine("Transacation Cancelled!");
- validinventorycode = true;
- }
- else if ((validinventorycode == false) || (inventorycode.Length != 5))
- {
- Console.WriteLine("Inventory Code is Invalid!");
- validinventorycode = false;
- }
- for (int i = 0; i < current; i++)
- {
- if (inventorycode == inventoryitems[i].GetCode())
- {
- Console.WriteLine("Inventory code already exists.");
- validinventorycode = false;
- }
- }
- }while ((validinventorycode == false));
- if (inventorycode != "\\c")
- {
- do
- {
- Console.Write("Input Inventory Name: ");
- inventoryname = Console.ReadLine();
- if (inventoryname == "\\c")
- {
- Console.WriteLine("Transaction Cancelled!");
- validinventorycode = true;
- }
- }
- while (validinventorycode == false);
- if (inventoryname != "\\c")
- {
- do
- {
- Console.Write("Input Inventory Price: ");
- inventoryprice = Console.ReadLine();
- validinventoryprice = double.TryParse(inventoryprice, out inventoryprice2);
- if (inventoryprice == "\\c")
- {
- Console.WriteLine("Transaction Cancelled!");
- validinventoryprice = true;
- }
- if (validinventoryprice == false)
- {
- Console.WriteLine("Inventory price is invalid!");
- }
- }
- while ((validinventoryprice == false));
- if (current > max)
- {
- Console.WriteLine("Inventory is full.");
- }
- if (inventoryprice != "\\c")
- {
- Console.WriteLine("Inventory is successfully added.");
- inventoryitems[current] = new Items(inventorycode, inventoryname, inventoryprice);
- current++;
- }
- }
- }
- }
- public void EditInventory()
- {
- int i = 0,x=0 ;
- Console.Clear();
- Items target = Find(inventorycode);
- do
- {
- Console.Write("Input Inventory Code: ");
- inventorycode = Console.ReadLine();
- validinventorycode = int.TryParse(inventorycode, out inventorycode2);
- if (inventorycode == "\\c")
- {
- Console.WriteLine("Transacation Cancelled.");
- validinventorycode = true;
- }
- else if ((validinventorycode == false) || (inventorycode.Length != 5))
- {
- Console.WriteLine("Inventory code is invalid!");
- }
- for (i= 0; i < current; i++)
- {
- if (inventorycode == inventoryitems[i].GetCode())
- {
- x = 1;
- target = inventoryitems[i];
- Console.Write("Change Name [{0}]: ", target.GetName());
- inventoryname = Console.ReadLine();
- if (inventoryname == "")
- {
- inventoryname = target.GetName();
- }
- if (inventoryname == "\\c")
- {
- Console.WriteLine("Transaction cancelled!");
- }
- else
- {
- do
- {
- Console.Write("Change Price [{0}]: ", target.GetPrice());
- inventoryprice = Console.ReadLine();
- validinventoryprice = double.TryParse(inventoryprice, out inventoryprice2);
- if (inventoryprice == "\\c")
- {
- Console.WriteLine("Transaction cancelled!");
- }
- else if (validinventoryprice == false)
- {
- Console.WriteLine("Invalid Inventory Price!");
- }
- else
- {
- target.code = inventorycode;
- target.name = inventoryname;
- target.price = inventoryprice;
- Console.WriteLine("Inventory Item " + target.GetCode() + " Successfully Edited!");
- validinventoryprice = true;
- }
- } while ((validinventoryprice == false));
- }
- i = current;
- validinventorycode = true;
- }
- }
- if (x == 0 && inventorycode.Length==5)
- {
- Console.WriteLine("Inventory Code Does Not Exists!");
- }
- }while (validinventorycode == false);
- }
- public void DeleteInventory()
- {
- int y = 0;
- Console.Clear();
- do
- {
- Console.Write("Input Inventory Code: ");
- inventorycode = Console.ReadLine();
- validinventorycode = int.TryParse(inventorycode, out inventorycode2);
- if (inventorycode == "\\c")
- {
- Console.WriteLine("Transacation Cancelled.");
- }
- if ((validinventorycode == false) || (inventorycode.Length != 5))
- {
- Console.WriteLine("Inventory code is invalid!");
- }
- }
- while ((inventorycode.Length != 5) || (inventorycode == "\\c") || (validinventorycode == false));
- if ((validinventorycode == true) && (inventorycode.Length == 5) && (inventorycode != "\\c"))
- {
- Items target = Find(inventorycode);
- for (int i = 0; i < current; i++)
- {
- if (inventorycode == inventoryitems[i].GetCode())
- {
- y = 1;
- Console.WriteLine("=================");
- Console.WriteLine("{0}", target.GetName());
- Console.WriteLine("{0}", target.GetPrice());
- Console.WriteLine("=================");
- Console.Write("Are you sure you want to delete this entry? [y/n]: ");
- string answer = Console.ReadLine();
- if (answer == "Y" || answer == "y")
- {
- if (inventoryitems[i] != null)
- {
- inventoryitems[i] = null;
- current--;
- Console.WriteLine("Entry Deleted!");
- }
- }
- else if (answer == "N" || answer == "n" || answer == "\\c")
- {
- Console.WriteLine("Transaction Cancelled!");
- }
- }
- }
- if (y == 0 && inventorycode.Length == 5)
- Console.WriteLine("Inventory code does not exist.");
- }
- }
- public void DisplayAllItems()
- {
- Console.Clear();
- Console.WriteLine("--------------------------------------------");
- Console.WriteLine("|Code Name Price|");
- Console.WriteLine("--------------------------------------------");
- for (int i = 0; i <= current; i++)
- {
- if (current == 0)
- {
- Console.WriteLine("Inventory is empty.");
- }
- else if (inventoryitems[i] != null)
- {
- Console.WriteLine("|{0}\t\t{1}\t\t{2}|", inventoryitems[i].GetCode(), inventoryitems[i].GetName(), inventoryitems[i].GetPrice());
- }
- }
- Console.WriteLine("--------------------------------------------");
- }
- public void ClearInventory()
- {
- Console.Clear();
- if (current == 0)
- Console.WriteLine("Inventory is empty.");
- else
- {
- Console.Write("Are you sure you want to delete all entries? [y/n]:");
- string answer = Console.ReadLine();
- if (answer == "Y" || answer == "y")
- {
- for (int i = 0; i < current; i++)
- {
- if (inventoryitems[i].code != null)
- {
- inventoryitems[i].code = null;
- inventoryitems[i].price = null;
- inventoryitems[i].name = null;
- current--;
- }
- }
- Console.WriteLine("All inventory items deleted");
- }
- else
- Console.WriteLine("Transaction Cancelled!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement