Exemple #1
0
        public void TestEndOfWeek() {
            var wellKnownWeek1 = new DateTime(2009, 2, 11);
            var endOfWellKnownWeek1 = new DateTime(2009, 2, 14);
            var wellKnownWeek2 = new DateTime(2007, 10, 20);
            var endOfWellKnownWeek2 = new DateTime(2007, 10, 20);

            Assert.IsTrue(wellKnownWeek1.EndOfWeek().Equals(endOfWellKnownWeek1));
            Assert.IsTrue(wellKnownWeek2.EndOfWeek().Equals(endOfWellKnownWeek2));
            Assert.IsFalse(wellKnownWeek1.EndOfWeek().Equals(endOfWellKnownWeek2));
            Assert.IsFalse(wellKnownWeek2.EndOfWeek().Equals(endOfWellKnownWeek1));
        }
            public void EndOfWeek()
            {
                var anyDate = new DateTime(2014, 1, 3, 3, 24, 50);
                var expectedResult = DateTime.Parse("2014-01-04 23:59:59.9999999");

                Assert.Equal(expectedResult, anyDate.EndOfWeek());
            }
 public void EndOfWeekTestCase1()
 {
     var dateTime = new DateTime( 2014, 3, 27 );
     var expected = new DateTime( 2014, 3, 31 ).AddDays( 1 )
                                               .Subtract( 1.ToMilliseconds() );
     var actual = dateTime.EndOfWeek( DayOfWeek.Monday );
     Assert.AreEqual( expected, actual );
 }
        public void EndOfWeek()
        {
            // Type
            var @this = new DateTime(2014, 04, 16);

            // Examples
            DateTime value = @this.EndOfWeek(); // value = "2013/04/13 23:59:59:999";

            // Unit Test
            Assert.AreEqual(new DateTime(2014, 04, 19, 23, 59, 59, 999), value);
        }
        public void WeekEnd()
        {
            DateTime d = new DateTime(2010, 6, 15);
            Assert.AreEqual(new DateTime(2010, 6, 19), d.EndOfWeek());

            DateTime d1 = new DateTime(2010, 6, 15, 1, 2, 3);
            Assert.AreEqual(new DateTime(2010, 6, 19), d1.EndOfWeek());

            DateTime d2 = new DateTime(2010, 6, 20);
            Assert.AreEqual(new DateTime(2010, 6, 26), d2.EndOfWeek());

            DateTime d3 = new DateTime(2010, 7, 3);
            Assert.AreEqual(new DateTime(2010, 7, 3), d3.EndOfWeek());
        }
Exemple #6
0
        public ScheduleViewModel GenerateSchedule(int userId, DateTime dateFrom, DateTime dateTo)
        {
            var user = DataProvider.Users.FirstOrDefault(p => p.Id == userId);
            if (user == null || (user.Prepod_PrepodMeta == null && user.Student_StudentMeta == null))
                return new ScheduleViewModel();

            List<IGrouping<DateTime, Raspisanie>> schedulesDateGroups;

            dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day);
            dateTo = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day);

            #region Правка даты

            if (dateTo.WeeksInYear() != dateFrom.WeeksInYear())
            {
                dateFrom = dateFrom.StartOfWeek(DayOfWeek.Monday);
                dateTo = dateTo.EndOfWeek(DayOfWeek.Saturday);
            }

            #endregion

            #region Условия для отбора данных из базы

            if (user.Prepod_PrepodMeta != null && user.Prepod_PrepodMeta.Any())
            {

                var prepodIds = DataProvider.PrepodiCafedri.Filter(p => p.Prepod_PrepodMeta.UserId == userId)
                                           .Select(p => p.Id);

                schedulesDateGroups = DataProvider.Raspisanie.Filter(p => prepodIds.Contains(p.IdPrepodaCafedri) && p.Data >= dateFrom && p.Data <= dateTo)

                                                 .GroupBy(p => p.Data)
                                                 .OrderBy(p => p.Key)
                                                 .ToList();

            }

            else
            {
                var userGroup = user.Student_StudentMeta.FirstOrDefault()
                                    .SostavGrupp.OrderByDescending(p => p.DateEdit)
                                               .FirstOrDefault();

                var flow = userGroup.SpisokGrupp.Pot;
                var groupId = userGroup.SpisokGrupp.IdGroup;
                var subGroup = userGroup.Podgroup;
                var specialityId = userGroup.SpisokGrupp.IdSpezMeta;
                //var formOfStudy = user.Student_StudentMeta.FirstOrDefault().FormOfStuduId;
                schedulesDateGroups = DataProvider.Raspisanie.Filter(p => p.Data >= dateFrom &&
                                                                           p.Data <= dateTo &&
                                                                           p.SpezialRazdeliDisziplini.IdSpezMeta == specialityId &&
                                                                           p.Pot == flow &&
                                                                           (!p.IdSpiskaGrupp.HasValue || p.IdSpiskaGrupp == groupId) &&
                                                                           (!p.NomerPodGrupp.HasValue || p.NomerPodGrupp == subGroup)
                                                                          )
                                                .GroupBy(p => p.Data)
                                                .OrderBy(p => p.Key)
                                                .ToList();
            }

            #endregion

            #region Отбор заметок

            var notifications = DataProvider.Notifications.Filter(p => userId == p.UserId && p.Date >= dateFrom && p.Date <= dateTo).ToList();

            #endregion

            var daysCount = (dateTo - dateFrom).Days + 1;

            var scheduleViewModel = new ScheduleViewModel()
            {
                DaysCount = daysCount,
                DateFrom = dateFrom.ToString("yyyy-MM-dd")
            };

            ScheduleWeekViewModel scheduleWeek = new ScheduleWeekViewModel();
            var scheduleDay = new ScheduleDayViewModel();
            var totalCount = schedulesDateGroups.Count;

            int maxLessonsInSimilarTime = 0;

            DateTime dateOfDay = new DateTime();
            List<string> lessonsTimes = new List<string>();

            #region Формируем расписание

            foreach (var schedulesDateGroup in schedulesDateGroups)
            {
                dateOfDay = schedulesDateGroup.Key;
                scheduleDay.DateOfDay = dateOfDay.ToString("yyyy-MM-dd");
                scheduleDay.IsCurrentDay = dateOfDay == DateTime.Now.Date;
                scheduleDay.IsPast = dateOfDay == DateTime.Now.Date;

                #region Добавляем уроки

                scheduleDay.Lessons = schedulesDateGroup.OrderBy(p => p.VremyaZanyatia.StartTime)
                                                   .Select(LessonViewModel.ToLessonViewModel)
                                                   .ToList();
                #endregion

                #region Добавляем заметки

                scheduleDay.Notifications = notifications.Where(p => p.Date == schedulesDateGroup.Key).OrderBy(p => p.IdVremyaZanyatia).Select(NotificationViewModel.ToNotificationViewModel).ToList();

                #endregion

                var tempCount = scheduleDay.Lessons.GroupBy(p => p.LessonTime).Select(p => p.Count()).Max(p => p);
                maxLessonsInSimilarTime = maxLessonsInSimilarTime < tempCount ? tempCount : maxLessonsInSimilarTime;

                lessonsTimes.AddRange(scheduleDay.Lessons.Select(p => p.LessonTime));
                lessonsTimes.AddRange(scheduleDay.Notifications.Select(p => p.NotificationTime));

                switch (dateOfDay.DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        scheduleWeek.Monday = scheduleDay;
                        break;
                    case DayOfWeek.Tuesday:
                        scheduleWeek.Tuesday = scheduleDay;
                        break;
                    case DayOfWeek.Wednesday:
                        scheduleWeek.Wednesday = scheduleDay;
                        break;
                    case DayOfWeek.Thursday:
                        scheduleWeek.Thursday = scheduleDay;
                        break;
                    case DayOfWeek.Friday:
                        scheduleWeek.Friday = scheduleDay;
                        break;
                    case DayOfWeek.Saturday:
                        scheduleWeek.Saturday = scheduleDay;
                        break;
                }

                //если один день то сразу в новую неделю
                if (daysCount == 1)
                {
                    scheduleViewModel.Weeks.Add(scheduleWeek);
                }
                //если суббота или последняя запись то  сохраняем неделю и созаем новую
                if (dateOfDay.DayOfWeek == DayOfWeek.Saturday || schedulesDateGroups.IndexOf(schedulesDateGroup) == totalCount - 1 || schedulesDateGroup.Key.WeeksInYear() != schedulesDateGroups[schedulesDateGroups.IndexOf(schedulesDateGroup) + 1].Key.WeeksInYear())
                {
                    scheduleViewModel.Weeks.Add(scheduleWeek);
                    scheduleWeek = new ScheduleWeekViewModel();
                }
                scheduleDay = new ScheduleDayViewModel();
            }

            #endregion

            List<string> lessons = lessonsTimes.Distinct().OrderBy(p => p).ToList();
            List<string> finalLessons = new List<string>();

            Dictionary<int, string> list = DataProvider.VremyaZanyatia.GetAllNoTracking().AsEnumerable().Select(x => new
            {
                Id = x.Id,
                Name = x.StartTime.ToString("H.mm") + '-' + x.EndTime.ToString("H.mm")
            }).AsEnumerable().ToDictionary(x => x.Id, x => x.Name);

            bool isExist = false;
            for (int i = 1; i <= list.Count; i++)
            {
                for (int j = 0; j < lessons.Count; j++)
                {
                    if (list[i] == lessons[j])
                    {
                        isExist = true;
                        break;
                    }
                }

                if (isExist)
                    finalLessons.Add(list[i]);

                isExist = false;
            }
            scheduleViewModel.MaxLessonsInSimilarTime = maxLessonsInSimilarTime;
            scheduleViewModel.LessonsTime = finalLessons;

            return scheduleViewModel;
        }
 public void EndOfWeekShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 3, 1 );
     var expected = new DateTime( 2013, 3, 2 );
     var actual = date.EndOfWeek();
     Assert.Equal( expected.Date, actual.Date );
 }
Exemple #8
0
 public void DateTimeEndOfWeek()
 {
     DateTime dt = new DateTime(2013, 2, 1);
     var end = dt.EndOfWeek(DayOfWeek.Monday);
     Assert.AreEqual(new DateTime(2013, 2, 5), end);
 }
Exemple #9
0
 public DataTable GetWeeklySales(int avdeling, DateTime date)
 {
     string sql = "SELECT * FROM " + TABLE_NAME + " WHERE " + KEY_AVDELING + " = " + avdeling
         + " AND CONVERT(NVARCHAR(10)," + KEY_DATO + ",121) >= CONVERT(NVARCHAR(10),'" + date.StartOfWeek().ToString("yyyy-MM-dd")
         + "',121) AND CONVERT(NVARCHAR(10)," + KEY_DATO + ",121) <= CONVERT(NVARCHAR(10),'" + date.EndOfWeek().ToString("yyyy-MM-dd") + "',121)";
     DataTable table = main.database.GetSqlDataTable(sql);
     if (table != null)
         table.Columns.Add("SalgsprisExMva", typeof(double), "Salgspris / Mva");
     return table;
 }
        public static DateTime EndOfWeek( this Calendar calendar, DateTime date, DayOfWeek firstDayOfWeek )
        {
            Arg.NotNull( calendar, nameof( calendar ) );

            return date.EndOfWeek( firstDayOfWeek );
        }