コード例 #1
0
        public CustomerContainer LoadAllFromBinary()
        {
            CustomerContainer cc     = new CustomerContainer();
            Stream            stream = File.Open("customersBin\\Customer_List.dat", FileMode.OpenOrCreate);
            BinaryFormatter   bf     = new BinaryFormatter();

            try
            {
                if (stream.Length > 0)
                {
                    cc = (CustomerContainer)bf.Deserialize(stream);
                }
                else
                {
                    cc = new CustomerContainer();
                }
            }
            catch (SerializationException e)
            {
                Console.WriteLine(e.Message);
            }

            stream.Close();
            return(cc);
        }
コード例 #2
0
        public void SaveAllToBinary(CustomerContainer cc)
        {
            Stream          stream = File.OpenWrite("customersBin\\Customer_List.dat");
            BinaryFormatter bf     = new BinaryFormatter();

            bf.Serialize(stream, cc);
            stream.Close();
        }
コード例 #3
0
        public void DeleteAll(CustomerContainer cc)
        {
            foreach (Customer c in cc.customers)
            {
                DeleteCustomer(c);
            }

            File.Delete("customersBin\\Customer_List.dat");
        }
コード例 #4
0
 public void Init()
 {
     S = DataManager.S.LoadAllFromBinary();
     Console.WriteLine("Customer Count: " + customers.Count);
     if (customers.Count > 0)
     {
         currentID = customers[customers.Count - 1].CustomerID;
     }
     else
     {
         currentID = 0;
     }
 }