public async Task<string> GetScheduleCadetWorkReportAsync(int cadetId, DateTime date) { var cadet = await _context.Cadets.GetAsync(cadetId); if (cadet != null) { string path = string.Format("{0}Reports/{1}{2}{3}.pdf", _serverPath, "ГрафикОбучения", cadet.Initials, date.ToShortDateString()); if (File.Exists(path)) { File.Delete(path); } var group = cadet.Group; ScheduleCadetWorkReport report = new ScheduleCadetWorkReport(path) { FIO = cadet.Initials, Date = date, Group = group.GroupName, }; List<CadetWorkEntity> listLessons = new List<CadetWorkEntity>(); DateTime dateStart = group.PracticeStartDate; for (DateTime i = dateStart; i <= date; i = i.AddDays(1)) { var lessons = cadet.SchedulePractices.Where(d => d.DayOfWeek == DayOfWeekRus(i)); foreach (var less in lessons) { CadetWorkEntity work = new CadetWorkEntity { Date = i, StartTime = less.StartTime, EndTime = less.EndTime, Instructor = less.Instructor.Initials, Type = "Практика" }; listLessons.Add(work); } } dateStart = group.TheoryStartDate; for (DateTime i = dateStart; i <= date; i = i.AddDays(1)) { var lessons = group.ScheduleTheories.Where(d => d.DayOfWeek == DayOfWeekRus(i)); foreach (var less in lessons) { CadetWorkEntity work = new CadetWorkEntity { Date = i, StartTime = less.StartTime, EndTime = less.EndTime, Instructor = less.Instructor.Initials, Type = "Теория" }; listLessons.Add(work); } } report.Lessons = listLessons; return report.GetReport(); } return null; }
//public static void ReportFive() //{ // ScheduleInstructorWorkReport obj = new ScheduleInstructorWorkReport("D:\\new5.pdf") // { // FIO = "Петров В. В.", // StartDate = new DateTime(2015, 10, 1), // EndDate = new DateTime(2015, 10, 18), // Lessons = new List<InstructorWorkEntity> // { // new InstructorWorkEntity // { // DayOfWeek = "Четверг", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 1), // new DateTime(2015, 10, 15), // new DateTime(2015, 10, 8), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorPracticeLesson // { // StartTime = new TimeSpan(14, 0, 0), // EndTime = new TimeSpan(14, 45, 0), // Training = "Иванов И. И." // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(12, 0, 0), // EndTime = new TimeSpan(12, 45, 0), // Training = "C-102" // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(18, 0, 0), // EndTime = new TimeSpan(18, 45, 0), // Training = "B-140" // } // }, // }, // new InstructorWorkEntity // { // DayOfWeek = "Пятница", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 2), // new DateTime(2015, 10, 9), // new DateTime(2015, 10, 16), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorPracticeLesson // { // StartTime = new TimeSpan(15, 0, 0), // EndTime = new TimeSpan(15, 45, 0), // Training = "Иванов И. И." // }, // new InstructorPracticeLesson // { // StartTime = new TimeSpan(16, 0, 0), // EndTime = new TimeSpan(16, 45, 0), // Training = "Сидоров И. И." // } // }, // }, // new InstructorWorkEntity // { // DayOfWeek = "Понедельник", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 12), // new DateTime(2015, 10, 5), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorTheoryLesson // { // StartTime = new TimeSpan(15, 0, 0), // EndTime = new TimeSpan(15, 45, 0), // Training = "B-140" // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(12, 0, 0), // EndTime = new TimeSpan(12, 45, 0), // Training = "C-102" // }, // new InstructorPracticeLesson // { // StartTime = new TimeSpan(14, 0, 0), // EndTime = new TimeSpan(14, 45, 0), // Training = "Иванов И. И." // } // }, // }, // new InstructorWorkEntity // { // DayOfWeek = "Вторник", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 6), // new DateTime(2015, 10, 13), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorPracticeLesson // { // StartTime = new TimeSpan(12, 0, 0), // EndTime = new TimeSpan(12, 45, 0), // Training = "Сидоров И. И." // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(15, 0, 0), // EndTime = new TimeSpan(15, 45, 0), // Training = "C-102" // } // }, // }, // new InstructorWorkEntity // { // DayOfWeek = "Среда", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 14), // new DateTime(2015, 10, 7), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorPracticeLesson // { // StartTime = new TimeSpan(12, 0, 0), // EndTime = new TimeSpan(12, 45, 0), // Training = "Сидоров И. И." // }, // new InstructorPracticeLesson // { // StartTime = new TimeSpan(14, 0, 0), // EndTime = new TimeSpan(14, 45, 0), // Training = "Иванов И. И." // } // }, // }, // new InstructorWorkEntity // { // DayOfWeek = "Суббота", // Dates = new List<DateTime> // { // new DateTime(2015, 10, 10), // new DateTime(2015, 10, 3), // new DateTime(2015, 10, 17), // }, // Lessons = new List<IInstuctorLesson> // { // new InstructorPracticeLesson // { // StartTime = new TimeSpan(12, 0, 0), // EndTime = new TimeSpan(12, 45, 0), // Training = "Сидоров И. И." // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(14, 0, 0), // EndTime = new TimeSpan(14, 45, 0), // Training = "B-140" // }, // new InstructorTheoryLesson // { // StartTime = new TimeSpan(10, 0, 0), // EndTime = new TimeSpan(10, 45, 0), // Training = "C-102" // } // }, // }, // } // }; // Console.WriteLine(obj.GetReport()); //} public static void ReportSix() { ScheduleCadetWorkReport obj = new ScheduleCadetWorkReport("d:\\new6.pdf") { FIO = "Сидоров К. К.", Date = new DateTime(2015, 10, 15), Group = "AD-140", Lessons = new List<CadetWorkEntity> { new CadetWorkEntity { Date = new DateTime(2015, 10, 1), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Павлов П. П.", Type = "Практика", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 3), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Иванов И. И.", Type = "Теория", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 5), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Павлов П. П.", Type = "Практика", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 9), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Иванов И. И.", Type = "Теория", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 11), StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(16, 45, 0), Instructor = "Павлов П. П.", Type = "Практика", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 11), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Иванов И. И.", Type = "Теория", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 13), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Иванов И. И.", Type = "Теория", }, new CadetWorkEntity { Date = new DateTime(2015, 10, 15), StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Павлов П. П.", Type = "Практика", }, } }; Console.WriteLine(obj.GetReport()); }