private List <VendingMachineItem> GetVendingMachineItemFromLine(string[] splitLine) { List <VendingMachineItem> inventList = new List <VendingMachineItem>(); VendingMachineItem item; if (splitLine[Col_SlotId].Contains('A')) { item = new ChipItem(splitLine[Col_Name], decimal.Parse(splitLine[Col_Cost])); } else if (splitLine[Col_SlotId].Contains('B')) { item = new CandyItem(splitLine[Col_Name], decimal.Parse(splitLine[Col_Cost])); } else if (splitLine[Col_SlotId].Contains('C')) { item = new BeverageItem(splitLine[Col_Name], decimal.Parse(splitLine[Col_Cost])); } else { item = new GumItem(splitLine[Col_Name], decimal.Parse(splitLine[Col_Cost])); } item.ItemStock = DefaultQuantity; inventList.Add(item); return(inventList); }
public Dictionary <string, List <ItemGeneral> > GetInventory() { using (StreamReader sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { string thisLine = sr.ReadLine(); string[] temp = thisLine.Split('|'); List <ItemGeneral> list = new List <ItemGeneral>(); const int SlotId = 0; const int ProductName = 1; const int Cost = 2; if (temp[0].Contains("A")) { for (int i = 0; i < 5; i++) { ChipsItem chips = new ChipsItem(temp[ProductName], decimal.Parse(temp[Cost])); list.Add(chips); } } if (temp[0].Contains("B")) { for (int i = 0; i < 5; i++) { CandyItem candy = new CandyItem(temp[ProductName], decimal.Parse(temp[Cost])); list.Add(candy); } } if (temp[0].Contains("C")) { for (int i = 0; i < 5; i++) { BeverageItem drink = new BeverageItem(temp[ProductName], decimal.Parse(temp[Cost])); list.Add(drink); } } if (temp[0].Contains("D")) { for (int i = 0; i < 5; i++) { GumItem gum = new GumItem(temp[ProductName], decimal.Parse(temp[Cost])); list.Add(gum); } } inventory[temp[SlotId]] = list; } } return(inventory); }
/// <summary> /// Reads in from the given file and creates a new string array split on the pipes ('|'). /// Item type is determined by the value of the array at the last index position. /// Couples the slot position (slotId, ex. "A1") and inventory item by adding them to the /// _inventory dictionary where slotId = key, inventory item = value. /// </summary> public void ReadFile() { try { using (StreamReader sr = new StreamReader(_logFullPath)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] itemArray = line.Split('|'); if (itemArray[itemArray.Length - 1] == "Chip") { ChipItem chipsItem = new ChipItem(itemArray[1], decimal.Parse(itemArray[2])); InventoryItem invItem = new InventoryItem(chipsItem, 5); _inventory.Add(itemArray[0], invItem); } else if (itemArray[itemArray.Length - 1] == "Candy") { CandyItem candyItem = new CandyItem(itemArray[1], decimal.Parse(itemArray[2])); InventoryItem invItem = new InventoryItem(candyItem, 5); _inventory.Add(itemArray[0], invItem); } else if (itemArray[itemArray.Length - 1] == "Drink") { BeverageItem drinkItem = new BeverageItem(itemArray[1], decimal.Parse(itemArray[2])); InventoryItem invItem = new InventoryItem(drinkItem, 5); _inventory.Add(itemArray[0], invItem); } else if (itemArray[itemArray.Length - 1] == "Gum") { GumItem gumItem = new GumItem(itemArray[1], decimal.Parse(itemArray[2])); InventoryItem invItem = new InventoryItem(gumItem, 5); _inventory.Add(itemArray[0], invItem); } } } } catch (IOException ie) //catch a specific type of Exception { Console.WriteLine("Error reading the file"); Console.WriteLine(ie.Message); } catch (Exception e) //catch a specific type of Exception { Console.WriteLine("Unknown Error"); Console.WriteLine(e.Message); } }
private List <VendingMachineItem> ParseInventoryLine(string[] tempArray) { List <VendingMachineItem> vmiList = new List <VendingMachineItem>(); if (tempArray[SlotID].StartsWith("A")) { for (int i = 0; i < 5; i++) { ChipItem chips = new ChipItem(tempArray[Product], decimal.Parse(tempArray[Cost])); vmiList.Add(chips); } } if (tempArray[SlotID].StartsWith("B")) { for (int i = 0; i < 5; i++) { CandyItem candy = new CandyItem(tempArray[Product], decimal.Parse(tempArray[Cost])); vmiList.Add(candy); } } if (tempArray[SlotID].StartsWith("C")) { for (int i = 0; i < 5; i++) { BeverageItem bev = new BeverageItem(tempArray[Product], decimal.Parse(tempArray[Cost])); vmiList.Add(bev); } } if (tempArray[SlotID].StartsWith("D")) { for (int i = 0; i < 5; i++) { GumItem gum = new GumItem(tempArray[Product], decimal.Parse(tempArray[Cost])); vmiList.Add(gum); } } return(vmiList); }
public static Dictionary <string, InventorySlot> CreateStartingInventory() { Dictionary <string, InventorySlot> inventoryItems = new Dictionary <string, InventorySlot>(); string inventoryPath = @"C:\Workspace\team\team7-c-week4-pair-exercises\c#-capstone\etc"; string inventoryFile = @"vendingmachine.csv"; string fullPath = Path.Combine(inventoryPath, inventoryFile); var lines = File.ReadAllLines(fullPath); foreach (var line in lines) { string[] itemArray = line.Split('|'); if (itemArray[3].ToString() == "Chip") { ChipItem chip = new ChipItem(itemArray[1], decimal.Parse(itemArray[2])); InventorySlot item = new InventorySlot(chip); inventoryItems.Add(itemArray[0], item); } else if (itemArray[3].ToString() == "Drink") { BeverageItem drink = new BeverageItem(itemArray[1], decimal.Parse(itemArray[2])); InventorySlot item = new InventorySlot(drink); inventoryItems.Add(itemArray[0], item); } else if (itemArray[3].ToString() == "Candy") { CandyItem candy = new CandyItem(itemArray[1], decimal.Parse(itemArray[2])); InventorySlot item = new InventorySlot(candy); inventoryItems.Add(itemArray[0], item); } else if (itemArray[3].ToString() == "Gum") { GumItem gum = new GumItem(itemArray[1], decimal.Parse(itemArray[2])); InventorySlot item = new InventorySlot(gum); inventoryItems.Add(itemArray[0], item); } } return(inventoryItems); }
public Dictionary <string, List <VendingMachineItem> > GetInventory() { using (StreamReader sr = new StreamReader("vendingmachine.csv")) { Dictionary <string, List <VendingMachineItem> > inventory = new Dictionary <string, List <VendingMachineItem> >(); while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] splitLine = line.Split('|'); List <VendingMachineItem> inventList = new List <VendingMachineItem>(); if (splitLine[0].Contains('A')) { ChipItem item = new ChipItem(splitLine[1], decimal.Parse(splitLine[2])); inventList.Add(item); inventory.Add(splitLine[0], inventList); } else if (splitLine[0].Contains('B')) { CandyItem item = new CandyItem(splitLine[1], decimal.Parse(splitLine[2])); inventList.Add(item); inventory.Add(splitLine[0], inventList); } else if (splitLine[0].Contains('C')) { BeverageItem item = new BeverageItem(splitLine[1], decimal.Parse(splitLine[2])); inventList.Add(item); inventory.Add(splitLine[0], inventList); } else { GumItem item = new GumItem(splitLine[1], decimal.Parse(splitLine[2])); inventList.Add(item); inventory.Add(splitLine[0], inventList); } } return(inventory); } }
private static List <Product> GetProducts(string line) { List <Product> products = new List <Product>(); string[] fields = line.Split('|'); string location = fields[Col_SlotId]; string name = fields[Col_Name]; decimal price = decimal.Parse(fields[Col_Price]); for (int i = 0; i < Default_Quantity; i++) { Product productItem; if (location.StartsWith("A")) { productItem = new ChipItem(name, price, location); products.Add(productItem); } else if (location.StartsWith("B")) { productItem = new CandyItem(name, price, location); products.Add(productItem); } else if (location.StartsWith("C")) { productItem = new BeverageItem(name, price, location); products.Add(productItem); } else if (location.StartsWith("D")) { productItem = new GumItem(name, price, location); products.Add(productItem); } } return(products); }
public VMItem CreateInitialInventory(string[] lineData) { if (lineData[0].Contains("A")) { ChipItem chip = new ChipItem(lineData[Product], Decimal.Parse(lineData[Cost])); return(chip); } else if (lineData[0].Contains("B")) { CandyItem candy = new CandyItem(lineData[Product], Decimal.Parse(lineData[Cost])); return(candy); } else if (lineData[0].Contains("C")) { BeverageItem beverage = new BeverageItem(lineData[Product], Decimal.Parse(lineData[Cost])); return(beverage); } else { GumItem gum = new GumItem(lineData[Product], Decimal.Parse(lineData[Cost])); return(gum); } }
private void ReadFile() { string fullPath = @"C:\Workspace\Team(git)\(4)team6-c-week4-pair-exercises(Dan)\c#-capstone\etc\vendingmachine.csv"; using (StreamReader sr = new StreamReader(fullPath)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] pipeSplit = line.Split('|'); if (pipeSplit[3] == "Candy") { CandyItem candyItem = new CandyItem(pipeSplit[1], decimal.Parse(pipeSplit[2]), "Munch Munch, Yum!"); InventoryItem inventoryItem = new InventoryItem(candyItem); Inventory.Add(pipeSplit[0], inventoryItem); } else if (pipeSplit[3] == "Chip") { ChipItem chipItem = new ChipItem(pipeSplit[1], decimal.Parse(pipeSplit[2]), "Crunch Crunch, Yum!"); InventoryItem inventoryItem = new InventoryItem(chipItem); Inventory.Add(pipeSplit[0], inventoryItem); } else if (pipeSplit[3] == "Gum") { GumItem gumItem = new GumItem(pipeSplit[1], decimal.Parse(pipeSplit[2]), "Chew Chew, Yum!"); InventoryItem inventoryItem = new InventoryItem(gumItem); Inventory.Add(pipeSplit[0], inventoryItem); } else if (pipeSplit[3] == "Drink") { BeverageItem beverageItem = new BeverageItem(pipeSplit[1], decimal.Parse(pipeSplit[2]), "Glug Glug, Yum!"); InventoryItem inventoryItem = new InventoryItem(beverageItem); Inventory.Add(pipeSplit[0], inventoryItem); } } } }
public InventoryFileDAL() { string currentDirectory = Directory.GetCurrentDirectory(); string path = "vendingmachine.csv"; string fullFilePath = Path.Combine(currentDirectory, path); try { using (StreamReader sr = new StreamReader(fullFilePath)) { while (!sr.EndOfStream) { string nextLine = sr.ReadLine(); List <string> itemList = nextLine.Split('|').ToList(); if (itemList[0].Contains("A")) { List <VendingMachineItem> chips = new List <VendingMachineItem>(); ChipItem chip = new ChipItem(itemList[1], Decimal.Parse(itemList[2])); for (int i = 0; i < 5; i++) { chips.Add(chip); } inventory.Add(itemList[0], chips); } else if (itemList[0].Contains("B")) { List <VendingMachineItem> candies = new List <VendingMachineItem>(); CandyItem candy = new CandyItem(itemList[1], Decimal.Parse(itemList[2])); for (int i = 0; i < 5; i++) { candies.Add(candy); } inventory.Add(itemList[0], candies); } else if (itemList[0].Contains("C")) { List <VendingMachineItem> beverages = new List <VendingMachineItem>(); BeverageItem beverage = new BeverageItem(itemList[1], Decimal.Parse(itemList[2])); for (int i = 0; i < 5; i++) { beverages.Add(beverage); } inventory.Add(itemList[0], beverages); } else if (itemList[0].Contains("D")) { List <VendingMachineItem> gums = new List <VendingMachineItem>(); GumItem gum = new GumItem(itemList[1], Decimal.Parse(itemList[2])); for (int i = 0; i < 5; i++) { gums.Add(gum); } inventory.Add(itemList[0], gums); } } } } catch (IOException ex) { Console.WriteLine("error"); Console.WriteLine(ex.Message); } }
public InventoryFileDAL() { string filePath = "vendingmachine.csv"; string currentDirectory = Directory.GetCurrentDirectory(); string fullFilePath = Path.Combine(currentDirectory, filePath); using (StreamReader sr = new StreamReader(fullFilePath)) { while (!sr.EndOfStream) { string nextLine = sr.ReadLine(); string[] line = nextLine.Split('|'); string slot = line[slotId]; string name = line[product]; decimal price = decimal.Parse(line[cost]); if (slot.StartsWith("A")) { List <VendingMachineItem> list = new List <VendingMachineItem>(); for (int i = 0; i < 5; i++) { ChipItem chip = new ChipItem(name, price); list.Add(chip); } inventory[slot] = list; } if (slot.StartsWith("B")) { List <VendingMachineItem> list = new List <VendingMachineItem>(); for (int i = 0; i < 5; i++) { CandyItem candy = new CandyItem(name, price); list.Add(candy); } inventory[slot] = list; } if (slot.StartsWith("C")) { List <VendingMachineItem> list = new List <VendingMachineItem>(); for (int i = 0; i < 5; i++) { BeverageItem beverage = new BeverageItem(name, price); list.Add(beverage); } inventory[slot] = list; } if (slot.StartsWith("D")) { List <VendingMachineItem> list = new List <VendingMachineItem>(); for (int i = 0; i < 5; i++) { BeverageItem gum = new BeverageItem(name, price); list.Add(gum); } inventory[slot] = list; } } } }