public static void SaveCurrentFile() { BinaryFormatter bf = new BinaryFormatter(); string filePath = Directory.GetCurrentDirectory() + "/" + loadedFileName + ".invo"; FileStream fs = new FileStream(filePath, FileMode.Create); InvoFile invoFile = new InvoFile(Inventory.items); bf.Serialize(fs, invoFile); fs.Close(); }
public static bool LoadInventoryFromFile(string fileName) { InvoFile invoFile = InvoFileTools.LoadFile(fileName); if (invoFile == null) { return(false); } for (int i = 0; i < invoFile.items.Length; i++) { Item item = new Item(invoFile.items[i].name, invoFile.items[i].price, invoFile.items[i].quantity); items.Add(item); } return(true); }
public static InvoFile LoadFile(string fileName) { string filePath = Directory.GetCurrentDirectory() + "/" + fileName + ".invo"; if (File.Exists(filePath)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(filePath, FileMode.Open); InvoFile invoFile = (InvoFile)bf.Deserialize(fs); fs.Close(); loadedFileName = fileName; return(invoFile); } else { Console.WriteLine("Couldn't load file " + fileName); return(null); } }