コード例 #1
0
        void CalculateMonth(int thisYear, int thisMonth)
        {
            yearForNavigating  = thisYear;
            monthForNavigating = thisMonth;

            System.DateTime tempDateTime = persianCalendar.ToDateTime(yearForNavigating, monthForNavigating, 15, 01, 01, 01, 01);

            int thisDay = 1;

            TextBlockThisMonth.Text = string.Empty;
            TextBlockThisMonth.Text = monthForNavigating.ConvertToPersianMonth() + " " + yearForNavigating.ConvertToPersianNumber();

            //Different between first place of calendar and first place of this month
            //اختلاف بین خانه شروع ماه و اولین خانه تقویم

            string DayOfWeek = persianCalendar.GetDayOfWeek(persianCalendar.ToDateTime(thisYear, thisMonth, 01, 01, 01, 01, 01)).ToString();

            int span = CalculatePersianSpan(DayOfWeek.ConvertToPersianDay());

            DecreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, span);

            string persianDate;//حاوی تاریخ روزهای شمسی Contains the date of Persian

            ////////////////////////////////////

            for (int i = 0; i < 6 * 7; i++)
            {
                tempDateTime = persianCalendar.ToDateTime(thisYear, thisMonth, thisDay, 01, 01, 01, 01);

                persianDate = thisDay.ConvertToPersianNumber();

                DayOfWeek = persianCalendar.GetDayOfWeek(tempDateTime).ToString();

                //RectangleStyleEventedDay

                if (thisMonth == monthForNavigating)                                                   // ماه کنونی
                {
                    if (thisDay == currentDay && thisMonth == currentMonth && thisYear == currentYear) // امروز
                    {
                        ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.TodayStyle, Infrastructure.Resources.PersianDatePicker.ThisMonthTextBlockStyle);

                        SelectedDateTime = new FarsiLibrary.Utils.PersianDate(thisYear, thisMonth, thisDay);

                        SelectedDateTimeChanged?.Invoke(this, System.EventArgs.Empty);
                    }

                    else // سایر روزهای ماه کنونی
                    {
                        ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.NoneStyle, Infrastructure.Resources.PersianDatePicker.ThisMonthTextBlockStyle);
                    }
                }

                else // ماه های دیگر
                {
                    ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.NoneStyle, Infrastructure.Resources.PersianDatePicker.OutOfThisMonthTextBlockStyle);
                }

                IncreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, 1);
            }
        }
コード例 #2
0
        public void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            int todayIndex;

            foreach (System.Windows.Shapes.Rectangle item in Rectangles)
            {
                item.Style = (System.Windows.Style)FindResource("RectangleStyleNone");

                if (item.Style == (System.Windows.Style)FindResource("RectangleStyleToday"))
                {
                    todayIndex = Rectangles.IndexOf(item);
                }
            }

            SelectedRectangleBaseName = System.Text.RegularExpressions.Regex.Replace((sender as System.Windows.Controls.Grid).Name, @"Grid", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            System.Windows.Shapes.Rectangle SelectedRectangle = FindName("Rectangle" + SelectedRectangleBaseName) as System.Windows.Shapes.Rectangle;

            int Index = Rectangles.IndexOf(SelectedRectangle);

            System.Windows.Controls.TextBlock SelectedTextBlock = TextBlocks.ElementAt(Index);

            if ((SelectedRectangle.Style == FindResource("RectangleStyleNone") && SelectedTextBlock.Style == FindResource("TextBlockStyleForOtherMonths")))
            {
                return;
            }

            foreach (int index in IntEventedIndex)
            {
                (Rectangles.ElementAt(index)).Style = (System.Windows.Style)FindResource("RectangleStyleEventedDay");
            }

            SelectedRectangle.Style = (System.Windows.Style)FindResource("RectangleStyleToday");

            PreviousRectangle = SelectedRectangle;

            ////بدست آوردن اطلاعات امروز
            this.yearPersian  = this.yearForNavigating;
            this.monthPersian = this.monthForNavigating;
            this.dayPersian   = (FindName("TextBlock" + SelectedRectangleBaseName) as System.Windows.Controls.TextBlock).Text.ConvertToInteger();

            SelectedDateTime = new FarsiLibrary.Utils.PersianDate(yearPersian, monthPersian, dayPersian);

            SelectedDateTimeChanged?.Invoke(this, System.EventArgs.Empty);
        }
コード例 #3
0
        void CalculateMonth(int thisYear, int thisMonth)
        {
            IntEventedIndex = new System.Collections.Generic.List <int>();

            try
            {
                yearForNavigating  = thisYear;
                monthForNavigating = thisMonth;

                System.DateTime tempDateTime = persianCalendar.ToDateTime(yearForNavigating, monthForNavigating, 15, 01, 01, 01, 01);

                int thisDay = 1;
                TextBlockThisMonth.Text = string.Empty;
                TextBlockThisMonth.Text = monthForNavigating.ConvertToPersianMonth() + " " + yearForNavigating.ConvertToPersianNumber();

                //Different between first place of calendar and first place of this month
                //اختلاف بین خانه شروع ماه و اولین خانه تقویم

                string DayOfWeek = persianCalendar.GetDayOfWeek(persianCalendar.ToDateTime(thisYear, thisMonth, 01, 01, 01, 01, 01)).ToString();

                int span = CalculatePersianSpan(DayOfWeek.ConvertToPersianDay());

                DecreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, span);

                string persianDate;//حاوی تاریخ روزهای شمسی Contains the date of Persian

                ////////////////////////////////////

                for (int i = 0; i < 6 * 7; i++)
                {
                    tempDateTime = persianCalendar.ToDateTime(thisYear, thisMonth, thisDay, 01, 01, 01, 01);

                    persianDate = thisDay.ConvertToPersianNumber();

                    DayOfWeek = persianCalendar.GetDayOfWeek(tempDateTime).ToString();

                    //RectangleStyleEventedDay
                    if (thisMonth == monthForNavigating)                                                   // ماه کنونی
                    {
                        if (thisDay == currentDay && thisMonth == currentMonth && thisYear == currentYear) // امروز
                        {
                            if (GetEventCountOfDay(thisYear, thisMonth, thisDay) != 0)
                            {
                                IntEventedIndex.Add(i);
                            }

                            ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.TodayStyle, Infrastructure.Resources.PersianDatePicker.ThisMonthTextBlockStyle);

                            SelectedDateTime = new FarsiLibrary.Utils.PersianDate(thisYear, thisMonth, thisDay);

                            SelectedDateTimeChanged?.Invoke(this, System.EventArgs.Empty);
                        }

                        else // سایر روزهای ماه کنونی
                        {
                            if (GetEventCountOfDay(thisYear, thisMonth, thisDay) == 0)
                            {
                                ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.NoneStyle, Infrastructure.Resources.PersianDatePicker.ThisMonthTextBlockStyle);
                            }
                            else
                            {
                                ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.EventedDayStyle, Infrastructure.Resources.PersianDatePicker.ThisMonthTextBlockStyle);

                                IntEventedIndex.Add(i);
                            }
                        }
                    }

                    else // ماه های دیگر
                    {
                        ChangeProperties(i, persianDate, Infrastructure.Resources.PersianDatePicker.NoneStyle, Infrastructure.Resources.PersianDatePicker.OutOfThisMonthTextBlockStyle);
                    }

                    IncreasePersianDay(ref thisYear, ref thisMonth, ref thisDay, 1);
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Exception", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
            }
        }