public VM_Stocker(string fileInput) { inventory = new Dictionary <string, VM_Item>(); using (StreamReader sRead = new StreamReader(fileInput)) { string currentLine = ""; while (!sRead.EndOfStream) { currentLine = sRead.ReadLine(); int currentIndex = currentLine.IndexOf("|"); string slot = currentLine.Substring(0, currentIndex); string remainder = currentLine.Substring(currentIndex + 1); currentIndex = remainder.IndexOf("|"); string itemName = remainder.Substring(0, currentIndex); remainder = remainder.Substring(currentIndex + 1); double price = double.Parse(remainder); VM_Item newItem = new VM_Item(itemName, price, slot); inventory.Add(slot, newItem); } } }
public void Purchase(VM_Item item) { item.QuantityRemaining--; item.QuantitySold++; currentBalance -= item.Price; totalSales += item.Price; TxWriter.Audit(item); }
public static void Audit(VM_Item item) { bool logExists = File.Exists("transactionLog.txt"); using (StreamWriter sw = new StreamWriter("transactionLog.txt", true)) { if (!logExists) { CreateHeader(sw); } sw.Write($"\n{DateTime.Now}".PadRight(24) + $"{item.Name}".PadRight(20) + $"{item.Slot}".PadRight(7) + item.Price.ToString("C")); } }