Beispiel #1
0
        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();
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
            }
        }