Ejemplo n.º 1
0
        private void SetTodayDate()
        {
            var persianCalendar       = PersianDateTime.GetFromDateTime(DateTime.Now);
            var persianTodayYear      = persianCalendar.Year;
            var persianTodayMonth     = persianCalendar.Month;
            var persianTodayDay       = persianCalendar.Day;
            var persianTodayDayOfWeek = persianCalendar.DayOfWeek;

            TodayDate.Content =
                $"امروز: {((DayOfWeekConverter.PersianDayOfWeek)persianTodayDayOfWeek).GetDisplayName()} {persianTodayDay} {MonthsName.Persian(persianTodayMonth)} {persianTodayYear}";
        }
Ejemplo n.º 2
0
        private void DesignCalendar(DateTime?targetDateTime = null)
        {
            CalendarDays.Children.Clear();

            targetDateTime ??= NowDateTime;
            var persianCalendar = PersianDateTime.GetFromDateTime(targetDateTime.Value);

            var persianYear  = persianCalendar.Year;
            var persianMonth = persianCalendar.Month;

            var monthDays = Database.GetMonthDays(persianMonth);

            var sync = SynchronizationContext.Current;

            Months = Database.DeserializeJson(persianYear, persianMonth);

            for (var dayIndex = 0; dayIndex < monthDays; dayIndex++)
            {
                var day      = dayIndex + 1;
                var dayModel = Months.FirstOrDefault(x => x.Key == persianMonth).Value.Find(x => x.DayOfMonth == day);

                var currentDate      = PersianDateTime.GetFromDateTime(new DateTime(targetDateTime.Value.Year, targetDateTime.Value.Month, day));
                var persianDayOfWeek = (DayOfWeekConverter.PersianDayOfWeek)currentDate.DayOfWeek;

                DesignDayButton(CalendarDays, persianYear, persianMonth, day, persianDayOfWeek, dayModel);
            }

            SetTodayDate();

            var firstDayOfGregorianMonth = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime();
            var lastDayOfGregorianMonth  = new PersianDateTime(persianYear, persianMonth, monthDays).ToDateTime();

            // var lastDayOfGregorianMonth = Calendar.ConvertToGregorian(persianYear, monthDays, 1, DateType.Persian);

            PersianTitle.Text   = $"{MonthsName.Persian(persianMonth)} {persianYear}";
            GregorianTitle.Text = MonthsName.Gregorian((DateTime)targetDateTime, firstDayOfGregorianMonth, lastDayOfGregorianMonth);
            HijriTitle.Text     = MonthsName.Hijri(firstDayOfGregorianMonth, lastDayOfGregorianMonth);
        }
Ejemplo n.º 3
0
        private static void UpdateLibrary(this ConcurrentDictionary <int, List <DayModel> > monthResult,
                                          List <MonthModel> date, IEnumerable <DateTime> range, CalendarTypes calendarType)
        {
            foreach (var neededDay in range)
            {
                int currentMonth;
                int currentDay;
                int currentPersianMonth;
                int currentPersianDay;

                var persianate = PersianDateTime.GetFromDateTime(neededDay);

                switch (calendarType)
                {
                case CalendarTypes.Persian:
                    currentMonth = persianate.Month;
                    currentDay   = persianate.Day;
                    break;

                case CalendarTypes.Hijri:
                    var hijri = new HijriCalendar();
                    // var currentHijriDate = Calendar.ConvertToIslamic(neededDay);
                    currentMonth = hijri.GetMonth(neededDay);
                    currentDay   = hijri.GetDayOfMonth(neededDay);
                    break;

                case CalendarTypes.Gregorian:
                default:
                    currentMonth = neededDay.Month;
                    currentDay   = neededDay.Day;
                    break;
                }

                if (calendarType != CalendarTypes.Persian)
                {
                    currentPersianMonth = persianate.Month;
                    currentPersianDay   = persianate.Day;
                }
                else
                {
                    currentPersianMonth = currentMonth;
                    currentPersianDay   = currentDay;
                }

                var gregorianMonthModel = date.Find(mnth => mnth.MonthNo == currentMonth);
                if (!(gregorianMonthModel?.Days.Count > 0))
                {
                    continue;
                }

                var day = gregorianMonthModel.Days.Find(x => x.DayOfMonth == currentDay);
                if (day == null)
                {
                    continue;
                }

                var baseMonth = monthResult.FirstOrDefault(x => x.Key == currentPersianMonth);
                var baseDay   = baseMonth.Value.Find(x => x.DayOfMonth == currentPersianDay);

                if (!baseDay.IsHoliday && day.IsHoliday)
                {
                    baseDay.IsHoliday = true;
                }

                baseDay.Events = day.Events?.Select(x => x).ToList();
            }
        }