public void ReadAccount() { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("AccObjects.bin", FileMode.Open, FileAccess.Read, FileShare.Read); _controller.accList = (List <Account>)formatter.Deserialize(stream); SingletonDataAccount.setInstance((SingletonDataAccount)formatter.Deserialize(stream)); stream.Close(); }
//private List<Account> GetAccounts; public Account(string name, int id, decimal fee) { SingletonDataAccount.getInstance(); this.Id = SingletonDataAccount.NextId; this.Name = name; this.CustomerId = id; this.Fee = fee; this.Interest = 0.04m; this.Balance = 0; }
/// <summary> /// Writes Account data to binary file, persists nextID /// </summary> public void WriteBinaryDataAccount() { //create a formatting object IFormatter formatter = new BinaryFormatter(); //Create a new IO stream to write to the file Objects.bin Stream stream = new FileStream("AccObjects.bin", FileMode.Create, FileAccess.Write, FileShare.None); //use the formatter to serialize the collection and send it to the filestream formatter.Serialize(stream, accList); formatter.Serialize(stream, SingletonDataAccount.getInstance()); //close the file stream.Close(); }