public void FillLessons(Worksheet sheet, int monthStart, int row, int column, List <ScheduleLesson> tmp, Week week1, Week week2) { int startRow = row; for (int counterDay = 1; counterDay <= 6; counterDay++) { List <ScheduleLesson> query1 = (from x in tmp from p in x.Dates where x.Day == (ScheduleClasses.Day)counterDay && (x.Week == week1 || x.Week == week2) select x).ToList(); List <int> Hours = (from x in query1 select x.Hour).Distinct().OrderBy(e => e).ToList(); for (int i = 0; i < Hours.Count; i++) { row = Hours[i] + ((Hours[i] - 1) * (lessonHorizontalMult - 1)) + ((counterDay - 1) * lsnCntMult * lessonHorizontalMult) + (startRow - 1); List <ScheduleLesson> t1 = query1.Where(x => x.Hour == Hours[i] && x.Week == week1).ToList(); List <ScheduleLesson> t2 = query1.Where(x => x.Hour == Hours[i] && x.Week == week2).ToList(); ScheduleLesson lesson = (t1.Count > 0) ? t1.First() : null; ScheduleLesson lesson2 = (t2.Count > 0) ? t2.First() : null; if (lesson != null && lesson2 != null && lesson.IsEqual(lesson2)) { WriteLesson(sheet, row, column, 0, lesson, false); } else if (lesson != null && lesson2 != null && !lesson.IsEqual(lesson2)) { WriteLesson(sheet, row, column, 0, lesson, true); WriteLesson(sheet, row, column, 1, lesson2, true); } else { if (lesson != null) { WriteLesson(sheet, row, column, 0, lesson, true); } if (lesson2 != null) { WriteLesson(sheet, row, column, 0, lesson2, true); } } if (!(lesson != null && lesson2 != null && !lesson.IsEqual(lesson2))) { Range range1 = new Range(sheet[column, row], sheet[column + 1, row]); range1.Merge(); Range range2 = new Range(sheet[column, row + 1], sheet[column + 1, row + 1]); range2.Merge(); Range range3 = new Range(sheet[column, row + 2], sheet[column + 1, row + 2]); range3.Merge(); Range range4 = new Range(sheet[column, row + 3], sheet[column + 1, row + 3]); range4.Merge(); Range range5 = new Range(sheet[column, row + 4], sheet[column + 1, row + 4]); range5.Merge(); } } } }
private void FillLessons(WordTable table, int monthStart, int row, List <ScheduleLesson> tmp, Week week1, Week week2) { int column = 1; for (int counterDay = 1; counterDay <= 6; counterDay++) { column = 1; for (int counterMonth = monthStart; counterMonth < monthStart + 5; counterMonth++) { List <int> numbers = (from x in tmp from p in x.Dates where x.Day == (ScheduleClasses.Day)counterDay && p.Month == counterMonth && (x.Week == week1 || x.Week == week2) select p.Day).Distinct().OrderBy(e => e).ToList(); foreach (int day in numbers) { table.Cell(row, column).WriteLine(); table.Cell(row, column).Write(day.ToString()); } column++; } List <ScheduleLesson> query1 = (from x in tmp from p in x.Dates where x.Day == (ScheduleClasses.Day)counterDay && (x.Week == week1 || x.Week == week2) select x).ToList(); List <int> Hours = (from x in query1 select x.Hour).Distinct().OrderBy(e => e).ToList(); foreach (int hour in Hours) { string str = ""; str = ScheduleTime.GetHourDiscription(hour); table.Cell(row, 7).Write(str); table.Cell(row, 7).WriteLine(); } for (int i = 0; i < Hours.Count; i++) { List <ScheduleLesson> t1 = query1.Where(x => x.Hour == Hours[i] && x.Week == week1).ToList(); List <ScheduleLesson> t2 = query1.Where(x => x.Hour == Hours[i] && x.Week == week2).ToList(); ScheduleLesson lesson = (t1.Count > 0) ? t1.First() : null; ScheduleLesson lesson2 = (t2.Count > 0) ? t2.First() : null; if (lesson != null && lesson2 != null && lesson.IsEqual(lesson2)) { WriteLesson(table, row, lesson, false); if (i + 1 < Hours.Count) { List <ScheduleLesson> Next1 = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week1).ToList(); ScheduleLesson next1 = (t1.Count > 0) ? t1.First() : null; List <ScheduleLesson> Next2 = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week2).ToList(); ScheduleLesson next2 = (t1.Count > 0) ? t1.First() : null; if (next1 != null && next2 != null && next1.IsEqual(next2) && lesson.IsEqual(next1)) { i++; } } } else { if (lesson != null) { if (lesson2 == null) { WriteLesson(table, row, lesson, false); } else { WriteLesson(table, row, lesson, true); } if (i + 1 < Hours.Count) { List <ScheduleLesson> Next = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week1).ToList(); ScheduleLesson next = (Next.Count > 0) ? Next.First() : null; if (next != null && lesson.IsEqual(next)) { i++; } } } if (lesson2 != null) { if (lesson == null) { WriteLesson(table, row, lesson2, false); } else { WriteLesson(table, row, lesson2, true); } if (i + 1 < Hours.Count) { List <ScheduleLesson> Next = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week2).ToList(); ScheduleLesson next = (Next.Count > 0) ? Next.First() : null; if (next != null && lesson2.IsEqual(next)) { i++; } } } } } row++; } }