/// <summary> /// 保存订单 /// </summary> /// <param name="courses"></param> public static void SaveOrders(OrderDAL courses) { using (FileStream fs = new FileStream(orderDocPath, FileMode.Create, FileAccess.Write)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, courses); } }
/// <summary> /// 读取订单 /// </summary> /// <returns></returns> public static OrderDAL GetOrders() { OrderDAL orders; if (File.Exists(orderDocPath)) { using (FileStream fs = new FileStream(orderDocPath, FileMode.Open, FileAccess.Read)) { BinaryFormatter bf = new BinaryFormatter(); orders = (OrderDAL)bf.Deserialize(fs); } } else { using (FileStream fs = new FileStream(orderDocPath, FileMode.CreateNew, FileAccess.Write)) { BinaryFormatter bf = new BinaryFormatter(); orders = new OrderDAL(); bf.Serialize(fs, orders); } } return(orders); }