Exemplo n.º 1
0
 /// <summary>
 /// 保存停车信息
 /// </summary>
 /// <param name="courses"></param>
 public static void SaveParks(ParkDAL courses)
 {
     using (FileStream fs = new FileStream(parkDocPath, FileMode.Create, FileAccess.Write))
     {
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(fs, courses);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 读取停车信息
        /// </summary>
        /// <returns></returns>
        public static ParkDAL GetParks()
        {
            ParkDAL parks;

            if (File.Exists(parkDocPath))
            {
                using (FileStream fs = new FileStream(parkDocPath, FileMode.Open, FileAccess.Read))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    parks = (ParkDAL)bf.Deserialize(fs);
                }
            }
            else
            {
                using (FileStream fs = new FileStream(parkDocPath, FileMode.CreateNew, FileAccess.Write))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    parks = new ParkDAL();
                    bf.Serialize(fs, parks);
                }
            }
            return(parks);
        }