Exemple #1
0
 void popupDatePicker_DropDown(object sender, EventArgs e)
 {
     lblToday.Text = string.Format("تاریخ امروز: {0}",
                                   FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetLongFarsiDate(DateTime.Now)));
     lblToday.Tag = DateTime.Now;
     CreateCells(Value.GregorianSelectedDate);
 }
Exemple #2
0
        private void lblCurrent_Click(object sender, EventArgs e)
        {
            var currentDate = (DateTime)lblCurrent.Tag;

            CreateCells(currentDate);
            Value.FarsiSelectedDate = FarsiDateHelper.GetShortFarsiDate(currentDate);
        }
Exemple #3
0
 public FarsiDate()
 {
     _format        = DateFormat.Long;
     _mode          = ControlType.DatePicker;
     _pSelectedDate = FarsiDateHelper.GetShortFarsiDate(DateTime.Now);
     _theme         = CalendarTheme.WhiteSmoke;
     _event         = "";
 }
 public FarsiDatePickerEventArgs(string newFarsiDate, string oldFarsiDate)
 {
     if (!FarsiDateHelper.ValidateFarsiDate(newFarsiDate) || (!string.IsNullOrEmpty(oldFarsiDate) && !FarsiDateHelper.ValidateFarsiDate(oldFarsiDate)))
     {
         throw new Exception("Incorrect Persian Date.");
     }
     NewFarsiDate = newFarsiDate;
     OldFarsiDate = oldFarsiDate;
 }
Exemple #5
0
        private void num_ValueChanged(object sender, EventArgs e)
        {
            var selectedYearAndMonth = FarsiDateHelper.GetGregorianDate(string.Format("{0}/{1}/{2}", numYear.Value, numMonth.Value, 1));
            var gDate       = Value.GregorianSelectedDate;
            var isSameMonth = FarsiDateHelper.GetSectionOfDate(gDate, true, SectionOfDate.Year) == numYear.Value &&
                              FarsiDateHelper.GetSectionOfDate(gDate, true, SectionOfDate.Month) == numMonth.Value;

            table.ClearSelection();

            CreateCells(isSameMonth ? gDate : selectedYearAndMonth);
        }
Exemple #6
0
        private void SetDatePickerText()
        {
            var gDate = Value.GregorianSelectedDate;
            var str   = Value.Format == DateFormat.Short
                                     ? FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetShortFarsiDate(gDate))
                                     : FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetLongFarsiDate(gDate));

            popupDatePicker.Items.Clear();
            popupDatePicker.Items.Add(str);
            popupDatePicker.SelectedIndex = 0;
            if (Value.Mode == ControlType.DatePicker)
            {
                popupDatePicker.HideDropDown();
            }
        }
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            var val = (string)value;

            if (FarsiDateHelper.ValidateFarsiDate(val))
            {
                if (DateFormat == DateFormat.Long)
                {
                    val = FarsiDateHelper.GetLongFarsiDate(FarsiDateHelper.GetGregorianDate(val));
                }
                if (ShowFarsiDigitInCell)
                {
                    val = FarsiDateHelper.ToFarsiDigit(val);
                }
            }
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, val, errorText, cellStyle, advancedBorderStyle, paintParts);
        }
Exemple #8
0
        private void table_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (table.SelectedCells.Count <= 1)
            {
                _multiSelectIndex = null;
            }
            if (e.RowIndex == -1)
            {
                return;
            }
            var gDate = (DateTime)table.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag;

            Value.FarsiSelectedDate = FarsiDateHelper.GetShortFarsiDate(gDate);
            popupDatePicker.HideDropDown();

            Value._event  = _dayEvents[e.RowIndex, e.ColumnIndex];
            lblEvent.Text = Value.Event;
        }
Exemple #9
0
 private void SetControlMode()
 {
     if (Value.Mode == ControlType.DatePicker)
     {
         popupDatePicker.DropDownControl = contentPanel;
         popupDatePicker.DropDown       += popupDatePicker_DropDown;
         popupDatePicker.DropDownClosed += popupDatePicker_DropDownClosed;
         this.Controls.Remove(contentPanel);
         this.Controls.Add(popupDatePicker);
     }
     else
     {
         lblToday.Text                   = string.Format("تاریخ امروز: {0}", FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetLongFarsiDate(DateTime.Now)));
         lblToday.Tag                    = DateTime.Now;
         popupDatePicker.DropDown       -= popupDatePicker_DropDown;
         popupDatePicker.DropDownClosed -= popupDatePicker_DropDownClosed;
         CreateCells(Value.GregorianSelectedDate);
         this.Controls.Remove(popupDatePicker);
         this.Controls.Add(contentPanel);
     }
     SetControlSize();
 }
Exemple #10
0
        private void _refereshCalendar()
        {
            int selectedRow, selectedCol;

            selectedRow = table.SelectedCells.Count == 0? -1: table.SelectedCells[0].RowIndex;
            selectedCol = table.SelectedCells.Count == 0 ? -1 : table.SelectedCells[0].ColumnIndex;

            if (selectedRow == -1)
            {
                return;
            }
            var gDate = (DateTime)table.Rows[selectedRow].Cells[selectedCol].Tag;

            Value.FarsiSelectedDate = FarsiDateHelper.GetShortFarsiDate(gDate);
            lbl_monthName.Text      = FarsiDateHelper.GetFarsiMonthName(gDate);
            lbl_yearName.Text       = FarsiDateHelper.GetSectionOfDate(gDate, true, SectionOfDate.Year).ToString();

            // center header lables
            lbl_monthName.Location = new Point((Int32)(headerPanel.ClientSize.Width - lbl_monthName.Width) / 2, 1);
            lbl_yearName.Location  = new Point((Int32)(headerPanel.ClientSize.Width - lbl_yearName.Width) / 2, 15);

            lblCurrent.Text = FarsiDateHelper.GetLongFarsiDate(gDate);

            if (selectedRow == -1)
            {
                return;
            }
            Value._event = _dayEvents[selectedRow, selectedCol];

            lblEvent.Text = Value.Event;

            SetTheme();
            table.ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle
            {
                Font      = CellsHeaderFont,
                Alignment = DataGridViewContentAlignment.MiddleCenter,
            };
        }
Exemple #11
0
 private void lblToday_Click(object sender, EventArgs e)
 {
     Value.FarsiSelectedDate = FarsiDateHelper.GetShortFarsiDate((DateTime)lblToday.Tag);
     //popupDatePicker.HideDropDown();
 }
Exemple #12
0
        private void CreateCells(DateTime currentDate)
        {
            if (table.SelectedCells.Count > 1)
            {
                _multiSelectIndex = new string[table.SelectedCells.Count];
                for (int i = 0; i < table.SelectedCells.Count; i++)
                {
                    _multiSelectIndex[i] = table.SelectedCells[i].RowIndex + "," + table.SelectedCells[i].ColumnIndex;
                }
            }
            else
            {
                _multiSelectIndex = null;
            }

            table.Rows.Clear();
            numYear.Value  = FarsiDateHelper.GetSectionOfDate(currentDate, true, SectionOfDate.Year);
            numMonth.Value = FarsiDateHelper.GetSectionOfDate(currentDate, true, SectionOfDate.Month);
            //lblCurrent.Text = string.Format("تاریخ انتخابی: {0}", FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetLongFarsiDate(Value.GregorianSelectedDate)));
            lblCurrent.Tag = Value.GregorianSelectedDate;
            var firstSaturday = currentDate;

            while (firstSaturday.DayOfWeek != DayOfWeek.Saturday ||
                   FarsiDateHelper.GetSectionOfDate(firstSaturday, true, SectionOfDate.Month) ==
                   FarsiDateHelper.GetSectionOfDate(currentDate, true, SectionOfDate.Month))
            {
                firstSaturday = firstSaturday.AddDays(-1);
            }
            var index = 0;
            DataGridViewCell currentCell = null;
            var dayEvents = FarsiDateHelper.CalendarEvents.Where(c =>
                                                                 c.Month >= FarsiDateHelper.GetSectionOfDate(firstSaturday, c.IsPersian, SectionOfDate.Month, (c.IsPersian || FarsiDateHelper.CalendarHijriAdjustment == null ? 0 : FarsiDateHelper.CalendarHijriAdjustment[c.Month])) ||
                                                                 c.Month <= FarsiDateHelper.GetSectionOfDate(firstSaturday.AddDays(42), c.IsPersian, SectionOfDate.Month, (c.IsPersian || FarsiDateHelper.CalendarHijriAdjustment == null ? 0 : FarsiDateHelper.CalendarHijriAdjustment[c.Month]))).ToList();

            for (var i = 0; i < 6; i++)
            {
                table.Rows.Add(1);
                for (var j = 0; j < 7; j++)
                {
                    var newDate = firstSaturday.AddDays(index++);
                    table.Rows[i].Cells[j].Value = FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetSectionOfDate(newDate, true, SectionOfDate.Day).ToString("00"));
                    table.Rows[i].Cells[j].Tag   = newDate;
                    _dayEvents[i, j]             = string.Empty;
                    var todayEvents = dayEvents.Where(c => c.Month == FarsiDateHelper.GetSectionOfDate(newDate, c.IsPersian, SectionOfDate.Month, (c.IsPersian || FarsiDateHelper.CalendarHijriAdjustment == null ? 0 : FarsiDateHelper.CalendarHijriAdjustment[c.Month])) &&
                                                      c.Day == FarsiDateHelper.GetSectionOfDate(newDate, c.IsPersian, SectionOfDate.Day, (c.IsPersian || FarsiDateHelper.CalendarHijriAdjustment == null ? 0 : FarsiDateHelper.CalendarHijriAdjustment[c.Month]))).ToList();
                    if (newDate.DayOfWeek == DayOfWeek.Friday || todayEvents.Any(c => c.IsHoliday))
                    {
                        table.Rows[i].Cells[j].Style = new DataGridViewCellStyle {
                            ForeColor = Color.Red
                        }
                    }
                    ;
                    if (todayEvents.Count > 0)
                    {
                        _dayEvents[i, j] = todayEvents.Aggregate(string.Empty, (current, tEvent) => current + (!string.IsNullOrEmpty(current) ? " | " : string.Empty) + tEvent.Event);
                    }
                    if (FarsiDateHelper.GetSectionOfDate(currentDate, true, SectionOfDate.Year) != FarsiDateHelper.GetSectionOfDate(newDate, true, SectionOfDate.Year) ||
                        FarsiDateHelper.GetSectionOfDate(currentDate, true, SectionOfDate.Month) != FarsiDateHelper.GetSectionOfDate(newDate, true, SectionOfDate.Month))
                    {
                        table.Rows[i].Cells[j].Style = table.Rows[i].Cells[j].Style.ForeColor == Color.Red
                                                            ? new DataGridViewCellStyle {
                            ForeColor = Color.FromArgb(255, 150, 150)
                        }
                    }
                    : new DataGridViewCellStyle {
                        ForeColor = Color.DarkGray
                    };
                    if (currentDate == newDate)
                    {
                        currentCell = table.Rows[i].Cells[j];
                    }
                }
            }
            table.ClearSelection();
            if (currentCell == null)
            {
                return;
            }
            table.CurrentCell = currentCell;
            table.Rows[currentCell.RowIndex].Cells[currentCell.ColumnIndex].Selected = true;
            //table.Rows[3].Cells[3].Selected = true;
            table.MultiSelect = _multiSelect;

            if (_multiSelectIndex != null)
            {
                foreach (var s in _multiSelectIndex)
                {
                    var _indexSplit = s.Split(',');
                    table.Rows[Convert.ToInt32(_indexSplit[0])].Cells[Convert.ToInt32(_indexSplit[1])].Selected = true;
                }
            }

            _refereshCalendar();
        }
Exemple #13
0
 public override string ToString()
 {
     return(Format == DateFormat.Short
                              ? FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetShortFarsiDate(GregorianSelectedDate))
                              : FarsiDateHelper.ToFarsiDigit(FarsiDateHelper.GetLongFarsiDate(GregorianSelectedDate)));
 }