/// <summary> /// Заполнить расписание /// </summary> public static void ParseXMLToList() { FileInfo dirInfo = new FileInfo(GlobalSetting.Path + @"\schedule\" + GlobalSetting.GetTypeScheduleActiveToFile()); if (dirInfo.Exists) { XDocument xdoc = XDocument.Load(GlobalSetting.Path + @"\schedule\" + GlobalSetting.GetTypeScheduleActiveToFile()); //XDocument xdoc = XDocument.Load(@"C:\Users\Frosty\source\repos\ServiceVPT\ServiceVPT\bin\Debug\schedule\DefaultTest"); foreach (XElement LessonElement in xdoc.Element("Schedule").Elements("pair")) { Lesson lesson = new Lesson(); XElement startHour = LessonElement.Element("StartHour"); XElement startMinutes = LessonElement.Element("StartMinutes"); XElement endHour = LessonElement.Element("EndHour"); XElement endMinutes = LessonElement.Element("EndMinutes"); lesson.startLesson = new DateTime (DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, int.Parse(startHour.Value), int.Parse(startMinutes.Value), 0); lesson.endLesson = new DateTime (DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, int.Parse(endHour.Value), int.Parse(endMinutes.Value), 0); lessons.Add(lesson); } } }
void LoadToFileScheduleXML() { string path = $@"{Environment.CurrentDirectory}\schedule\{GlobalSetting.GetTypeScheduleActiveToFile()}"; //Путь к загрузке //Создать путь к директории FileInfo fileInfo = new FileInfo(path); XDocument xdoc = null; //Если данный путь существует if (fileInfo.Exists) { xdoc = XDocument.Load($@"{path}"); } else { ClearTextForSchedule(); return; } TextBox[] textBoxStart = new TextBox[] { Pairs0Hours, Pairs0Minutes, Pairs1Hours, Pairs1Minutes, Pairs2Hours, Pairs2Minutes, Pairs3Hours, Pairs3Minutes, Pairs4Hours, Pairs4Minutes, Pairs5Hours, Pairs5Minutes, Pairs6Hours, Pairs6Minutes, Pairs7Hours, Pairs7Minutes, }; TextBox[] textBoxEnd = new TextBox[] { EndPairs0Hours, EndPairs0Minutes, EndPairs1Hours, EndPairs1Minutes, EndPairs2Hours, EndPairs2Minutes, EndPairs3Hours, EndPairs3Minutes, EndPairs4Hours, EndPairs4Minutes, EndPairs5Hours, EndPairs5Minutes, EndPairs6Hours, EndPairs6Minutes, EndPairs7Hours, EndPairs7Minutes, }; int countPair = 0; /*textBox[0].Text = xdoc.Element("Schedule").Element("pair0start").Element("hour").Value; * textBox[1].Text = xdoc.Element("Schedule").Element("pair0start").Element("minutes").Value; * * textBox[2].Text = xdoc.Element("Schedule").Element("pair1start").Element("hour").Value; * textBox[3].Text = xdoc.Element("Schedule").Element("pair1start").Element("minutes").Value;*/ //Заполнение полей (Часы и минуты начала) /*for (int i = 0; i < textBoxStart.Length; i=i+2) * { * string textPair = "pair"; * textBoxStart[i].Text = xdoc.Element("Schedule").Elements(textPair).Element("StartHour").Value; * textBoxStart[i+1].Text = xdoc.Element("Schedule").Element(textPair).Element("StartMinutes").Value; * * textBoxEnd[i].Text = xdoc.Element("Schedule").Element(textPair).Element("EndHour").Value; * textBoxEnd[i+1].Text = xdoc.Element("Schedule").Element(textPair).Element("EndHour").Value; * * countPair++; * }*/ foreach (XElement element in xdoc.Element("Schedule").Elements("pair")) { XElement startHour = element.Element("StartHour"); XElement startMinutes = element.Element("StartMinutes"); XElement endHour = element.Element("EndHour"); XElement endMinutes = element.Element("EndMinutes"); textBoxStart[countPair].Text = int.Parse(startHour.Value).ToString(); textBoxStart[countPair + 1].Text = int.Parse(startMinutes.Value).ToString(); textBoxEnd[countPair].Text = int.Parse(endHour.Value).ToString(); textBoxEnd[countPair + 1].Text = int.Parse(endMinutes.Value).ToString(); countPair = countPair + 2; } }