/// <summary> /// 更新 /// </summary> /// <param name="pathTime">时间表路径,文件夹</param> /// <param name="pathClass">课表路径,文件</param> /// <param name="changHeTime">长河时间</param> public static void Load(string pathTime, string pathClass) { //Console.WriteLine(); //Console.WriteLine("ChangHetime={0}", changHeTime); for (int i = 0; i < timeSections.Length; i++)//初始化 { timeSections[i] = new List <TimeSection>(); } for (int i = 0; i < classSection.GetLength(0); i++) { for (int j = 0; j < classSection.GetLength(1); j++) { classSection[i, j] = new ClassSection(); } } XElement ClassSection = XElement.Load(pathClass);//读取课表 foreach (var Sections in ClassSection.Elements()) { foreach (var Section in Sections.Elements()) { ClassSection classsection = new ClassSection { Name = Section.Attribute("Name").Value }; int week = int.Parse(Sections.Attribute("Week").Value); int @class = int.Parse(Section.Attribute("Class").Value); classSection[week, @class] = classsection; // Console.WriteLine(classSection[week].Count); // classSection[week][1] = classsection; // classSection[int.Parse(Sections.Attribute("Week").Value)][@class] = classsection; } } //for (int i = 0; i < classSection.GetLength(0); i++) //{ // for (int j = 0; j < classSection.GetLength(1); j++) // { // Console.WriteLine("i={0},j={1},Name={2}", i, j, classSection[i, j].Name); // } //} XElement TimeFile = XElement.Load(pathTime + "TimeFile.xml");//读取总起时间表,并解析时间段 foreach (var day in TimeFile.Elements()) { foreach (var File in day.Elements()) { LoadTimeSections(int.Parse(day.Attribute("week").Value), pathTime + File.Value); } } for (int i = 0; i < timeSections.Length; i++) { for (int j = 0; j < timeSections[i].Count; j++) { #region 计算结束时间 DateTime dt = DateTime.Now; DateTime st = timeSections[i][j].beginTime; timeSections[i][j].beginTime = new DateTime(dt.Year, dt.Month, dt.Day, st.Hour, st.Minute, st.Second); if (j < timeSections[i].Count - 1) { timeSections[i][j].endTime = timeSections[i][j + 1].beginTime; } else { timeSections[i][j].endTime = new DateTime(dt.Year, dt.Month, dt.Day).AddDays(1);//末尾,置为第二天00:00 } #endregion if (timeSections[i][j].Class >= 0) { classSection[i, timeSections[i][j].Class].EndTime = timeSections[i][j].endTime; } //Console.Write(timeSections[i][j].beginTime.ToString()); //Console.Write(" "); //Console.WriteLine(timeSections[i][j].endTime.ToString()); //Console.WriteLine(timeSections[i][j].ToString()); } } for (int i = 0; i < timeSections.Length; i++)//计算最后一节课的结束时间,辅助明日课表功能 { foreach (var item in timeSections[i]) { if (item.Class != -1) { LastClassEndTime[i] = item.endTime; } } } //foreach (var item in lastClassEndTime) //{ // Console.WriteLine(item); //} //Console.WriteLine(currentTimeSection.beginTime); //Console.WriteLine(currentTimeSection.endTime); //Console.WriteLine(); }