Пример #1
0
 /// <summary>
 /// 保存学期开设课程信息
 /// </summary>
 /// <param name="courses"></param>
 public static void SaveTermCourses(TermCourseDAL courses)
 {
     using (FileStream fs = new FileStream(termCourseDocPath, FileMode.Create, FileAccess.Write))
     {
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(fs, courses);
     }
 }
Пример #2
0
        /// <summary>
        /// 读取学期开设课程信息
        /// </summary>
        /// <returns></returns>
        public static TermCourseDAL GetTermCourses()
        {
            TermCourseDAL courses;

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