Esempio n. 1
0
        public FarsiDate AddDay(int day)
        {
            if (day > DaysInMonth || day < -DaysInPrevMonth)
            {
                throw new ArgumentOutOfRangeException("day");
            }
            FarsiDate fd = new FarsiDate(_Year, _Month, _Day);
            int       d  = fd.Day + day;

            if (d > fd.DaysInMonth)
            {
                d -= fd.DaysInMonth;
                fd = fd.AddMonth(1);
            }
            if (d <= 0)
            {
                d += DaysInPrevMonth;
                fd = fd.AddMonth(-1);
            }
            fd.Day = d;
            // Event
            if (DateChanged != null)
            {
                DateChanged();
            }
            FarsiDate retFD = new FarsiDate(fd.Year, fd.Month, fd.Day);

            retFD.DateChanged = this.DateChanged;
            return(retFD);
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            FarsiDate fd = (FarsiDate)obj;

            if (this.Year == fd.Year &&
                this.Month == fd.Month &&
                this.Day == fd.Day)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public static bool IsToday(int year, int month, int day)
        {
            FarsiDate fd = new FarsiDate();

            if (fd.Year == year &&
                fd.Month == month &&
                fd.Day == day)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     if (e.Delta > 0)
     {
         selectedFarsiDate = selectedFarsiDate.AddMonth(-1);
         SetMonthYear();
         //Invalidate();
     }
     else if (e.Delta < 0)
     {
         selectedFarsiDate = selectedFarsiDate.AddMonth(1);
         SetMonthYear();
         //Invalidate();
     }
     base.OnMouseWheel(e);
 }
        protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Left:
                selectedFarsiDate = selectedFarsiDate.AddDay(1);
                break;

            case Keys.Right:
                selectedFarsiDate = selectedFarsiDate.AddDay(-1);
                break;

            case Keys.Up:
                selectedFarsiDate = selectedFarsiDate.AddDay(-7);
                break;

            case Keys.Down:
                selectedFarsiDate = selectedFarsiDate.AddDay(7);
                break;

            case Keys.PageDown:
                selectedFarsiDate = selectedFarsiDate.AddMonth(1);
                break;

            case Keys.PageUp:
                selectedFarsiDate = selectedFarsiDate.AddMonth(-1);
                break;

            case Keys.Enter:
            case Keys.Space:
                if (SelectDay != null)
                {
                    SelectDay(this);
                }
                break;

            default:
                base.OnPreviewKeyDown(e);
                return;
            }
            if (DateChanged != null)
            {
                DateChanged(this);
            }
            e.IsInputKey = true;
        }
        protected void SelectDateByPoint(Point pt)
        {
            int xCell = pt.X / (int)CX;
            int yCell = pt.Y / (int)CY;

            if (xCell >= 0 && xCell <= 6 &&
                yCell >= 2 && yCell <= 7)
            {
                int cellIndex = (6 - xCell) + (yCell - 2) * 7;
                // number of day
                int number;
                int ret = GetCellIndexNumber(cellIndex, out number);
                selectedFarsiDate     = selectedFarsiDate.AddMonth(ret);
                selectedFarsiDate.Day = number;
                SetMonthYear();
                //Invalidate();
                if (SelectDay != null)
                {
                    SelectDay(this);
                }
            }
        }
Esempio n. 7
0
        public FarsiDate AddMonth(int month)
        {
            int m = _Month + month;
            int y = _Year + month / 12;

            if (m > 12)
            {
                m -= 12;
                y++;
            }
            if (m <= 0)
            {
                m += 12;
                y--;
            }
            int       d;
            FarsiDate temp = new FarsiDate(y, m, 1);

            if (_Day > temp.DaysInMonth)
            {
                d = temp.DaysInMonth;
            }
            else
            {
                d = _Day;
            }
            // Event
            if (DateChanged != null)
            {
                DateChanged();
            }
            FarsiDate retFD = new FarsiDate(y, m, d);

            retFD.DateChanged = this.DateChanged;
            return(retFD);
        }
 private void toolStripMenuItemToday_Click(object sender, EventArgs e)
 {
     selectedFarsiDate = selectedFarsiDate.Today;
     SetMonthYear();
     Invalidate();
 }
 private void buttonPrevMonth_Click(object sender, EventArgs e)
 {
     selectedFarsiDate = selectedFarsiDate.AddMonth(-1);
     SetMonthYear();
 }
 private void buttonNextMonth_Click(object sender, EventArgs e)
 {
     selectedFarsiDate = selectedFarsiDate.AddMonth(1);
     SetMonthYear();
     //Invalidate();
 }
        private void drawNumbers(Graphics g)
        {
            RectangleF   rc = new RectangleF(0, 0, CX - 1, CY - 1);
            StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            int dayNumber = selectedFarsiDate.DaysInPrevMonth - selectedFarsiDate.FirstDayOfMonth;
            int monthPos  = 0;  // 0: Prev month, 1: Cur Month, 2: Next Month

            for (int i = 0; i < 42; i++)
            {
                int y = i / 7;
                int x = 6 - i % 7;  // Right to left
                rc.X = x * CX + 1;
                rc.Y = y * CY + (CY * 2) + 1;
                // Increase number of the day and then show it
                dayNumber++;
                switch (monthPos)
                {
                case 0:
                    if (dayNumber > selectedFarsiDate.DaysInPrevMonth)
                    {
                        // Start of first day of this month
                        dayNumber = 1;
                        // Now we are in current month
                        monthPos = 1;
                    }
                    break;

                case 1:
                    if (dayNumber > selectedFarsiDate.DaysInMonth)
                    {
                        // Start of first day of NEXT month
                        dayNumber = 1;
                        // Now again we are not in current month
                        monthPos = 2;
                    }
                    break;
                }
                // Set the color of numbers
                SolidBrush brush;
                // Check for today
                if (monthPos == 1 && (new FarsiDate(selectedFarsiDate.Year,
                                                    selectedFarsiDate.Month, dayNumber)
                                      == selectedFarsiDate))
                {
                    brush = new SolidBrush(SelectedNumberColor);
                    using (SolidBrush selback = new SolidBrush(SelectedBackColor))
                    {
                        g.FillRectangle(selback,
                                        rc);
                    }
                }
                else if (FarsiDate.IsToday(selectedFarsiDate.Year,
                                           selectedFarsiDate.Month, dayNumber) && monthPos == 1)
                {
                    brush = new SolidBrush(TodayNumberColor);
                }
                else
                {
                    brush =
                        monthPos == 1 ? (new SolidBrush(NumbersColor)) : (new SolidBrush(Color.FromArgb(100, NumbersColor)));
                }

                // For today
                if (FarsiDate.IsToday(selectedFarsiDate.Year,
                                      selectedFarsiDate.Month, dayNumber) && monthPos == 1)
                {
                    using (Pen todayborder = new Pen(TodayBorderColor))
                    {
                        g.DrawRectangle(todayborder,
                                        rc.X, rc.Y, rc.Width - 1, rc.Height - 1);
                    }
                }

                g.DrawString(IntToFarsiStr(dayNumber), this.Font, brush, rc, sf);

                brush.Dispose();
            }
        }
Esempio n. 12
0
 public void CopyEventHandler(FarsiDate fd)
 {
     fd.DateChanged = this.DateChanged;
 }
 public override object ParseFormattedValue(object formattedValue, DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter formattedValueTypeConverter, System.ComponentModel.TypeConverter valueTypeConverter)
 {
     FarsiCalendarComponent.FarsiDate fd = new FarsiDate();
     fd.FarsiDateValue = (string)formattedValue;
     return(fd.GeoDate);
 }