private List <Lesson> GetLessonsByTopic(KeyValuePair <string, string> topic) { List <Lesson> lessons = new List <Lesson>(); string kindOfLesson = ""; string minutes = ""; string questionsOfLesson = ""; string materialSupport = ""; string lessonInMaterialSupp = ""; string themeOfLesson = ""; List <string> questions = new List <string>(); string literature = ""; Word.Range range = table.Range; Word.Cells cells = range.Cells; Regex regex = new Regex(@"^Лекция|^Самостоя|^Группов|^Практичес|^Трениров"); char[] charsToTrim = { '\a', '\r' }; for (int i = Int32.Parse(topic.Value.Substring(0, topic.Value.IndexOf(','))) + 1; i < Int32.Parse(topic.Value.Substring(topic.Value.IndexOf(',') + 1)); i++) { Word.Cell cell = cells[i]; Word.Range updateRange = cell.Range; string text = updateRange.Text; if (regex.IsMatch(text)) { kindOfLesson = text.Trim(charsToTrim); kindOfLesson = kindOfLesson.Replace("\r", ""); //get count of hours cell = cells[i + 1]; if (cell.Range.Text.Length > 0) { minutes = cell.Range.Text.Trim(charsToTrim); } //get questions of the lesson cell = cells[i + 2]; questionsOfLesson = cell.Range.Text.Trim(charsToTrim); int a = questionsOfLesson.IndexOf("«"); if (questionsOfLesson.IndexOf("«") > 20) { lessonInMaterialSupp = "Ошибка в темплане"; themeOfLesson = "Ошибка в темплане"; questions = getQuestions(questionsOfLesson); } else { lessonInMaterialSupp = questionsOfLesson.Substring(0, questionsOfLesson.IndexOf("«")); try { themeOfLesson = questionsOfLesson.Substring(questionsOfLesson.IndexOf("«"), questionsOfLesson.IndexOf("»") - questionsOfLesson.IndexOf("«") + 1); } catch (Exception e) { themeOfLesson = questionsOfLesson.Substring(questionsOfLesson.IndexOf("«"), questionsOfLesson.IndexOf(".") - questionsOfLesson.IndexOf("«") + 1); } questions = getQuestions(questionsOfLesson.Substring(questionsOfLesson.IndexOf("«"))); } //get material support cell = cells[i + 3]; materialSupport = cell.Range.Text.Trim(charsToTrim); //get literature cell = cells[i + 4]; literature = cell.Range.Text.Trim(charsToTrim); //get hours if first cell was empty if (minutes == "") { cell = cells[i + 5]; minutes = cell.Range.Text.Trim(charsToTrim); } Lesson lesson = new Lesson(); lesson.Type = kindOfLesson; if (kindOfLesson.Contains("1")) { lesson.NumberLessom = "з1"; } else if (kindOfLesson.Contains("2")) { lesson.NumberLessom = "з2"; } else if (kindOfLesson.Contains("3")) { lesson.NumberLessom = "з3"; } else if (kindOfLesson.Contains("4")) { lesson.NumberLessom = "з4"; } else if (kindOfLesson.Contains("5")) { lesson.NumberLessom = "з5"; } else if (kindOfLesson.Contains("6")) { lesson.NumberLessom = "з6"; } else if (kindOfLesson.Contains("7")) { lesson.NumberLessom = "з7"; } else if (kindOfLesson.Contains("8")) { lesson.NumberLessom = "з8"; } else if (kindOfLesson.Contains("9")) { lesson.NumberLessom = "з9"; } else if (kindOfLesson.Contains("10")) { lesson.NumberLessom = "з10"; } else if (kindOfLesson.Contains("11")) { lesson.NumberLessom = "з11"; } else if (kindOfLesson.Contains("12")) { lesson.NumberLessom = "з12"; } else if (kindOfLesson.Contains("13")) { lesson.NumberLessom = "з13"; } else if (kindOfLesson.Contains("14")) { lesson.NumberLessom = "з14"; } else { lesson.NumberLessom = "з15"; } lesson.Literature = literature; lessonInMaterialSupp = lessonInMaterialSupp.Trim(); lessonInMaterialSupp = lessonInMaterialSupp.Replace("\r", ""); lessonInMaterialSupp = lessonInMaterialSupp.Replace("\a", ""); lesson.LessonInMaterialSupp = lessonInMaterialSupp; lesson.ThemeOfLesson = themeOfLesson; lesson.Questions = questions; materialSupport = materialSupport.Trim(); materialSupport = materialSupport.Replace("\r", ""); materialSupport = materialSupport.Replace("\a", ""); lesson.MaterialSupport = materialSupport; //ПРО САМОСТОЯТЕЛЬНУ РАБОТУ СПРОСИТЬ СКОЛЬКО ТАМ МИНУТ БУДЕТ if (lesson.Type.Contains("Лекци") || lesson.Type.Contains("Групповое") || lesson.Type.Contains("Практичес") || lesson.Type.Contains("Самосто")) { try { int count = Int32.Parse(minutes) * 45; minutes = count.ToString(); } catch (Exception e) { minutes = "Не было указано в темплане!"; } } else if (lesson.Type.Contains("Трениров")) { minutes = "30"; } lesson.Minutes = minutes; lessons.Add(lesson); i += 5; } } return(lessons); }