Example #1
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);
        }
Example #2
0
        private void ToggleEvent(int persianYear, int persianMonth, int persianDay,
                                 DayOfWeekConverter.PersianDayOfWeek thisDayOfWeek, DayModel @event)
        {
            if (@event?.Events?.Count >= 1)
            {
                _panelWrapper.Show <Event>(eventPage =>
                {
                    eventPage.EventDay.Text =
                        $"{thisDayOfWeek.GetDisplayName()} {persianDay} {MonthsName.Persian(persianMonth)} {persianYear}";
                    eventPage.EventText.Text = string.Join(Environment.NewLine, @event.Events.ToArray());

                    var eventsApproxHeight =
                        (eventPage.EventText.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length *
                         22)
                        + eventPage.EventText.Margin.Top;
                    var topMargin = eventsApproxHeight + 50;

                    eventPage.MouseDown += (sender, args) =>
                    {
                        _panelWrapper.Show <Event>(eventPage2 =>
                        {
                            eventPage2.MouseDown += (sender2, args2) =>
                            {
                                _panelWrapper.Show <Event>(_ => topMargin);
                            };
                            return(topMargin);
                        });
                    };
                    return(topMargin);
                }, TimeSpan.FromSeconds(2));
            }
            else
            {
                _panelWrapper.CloseLastPanel();
            }
        }
Example #3
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}";
        }