Exemplo n.º 1
0
            //
            // Creates a TableCell control for the given calendar day.
            //
            // Note: This object is included in the DayRenderEventArgs passed to
            // the DayRender event handler.
            //
            private TableCell Cell(CalendarDay day)
            {
                var tbcell = new TableCell();

                tbcell.HorizontalAlign = HorizontalAlign.Center;

                // Add styling based on day flags.
                // - Styles are applied per the precedence order used by the
                // base Calendar control.
                // - For CssClass, multiple class names may be added.
                var sb            = new StringBuilder();
                var currdayofweek = DayOfWeekMapping(day.Date.DayOfWeek);

                if ((WeekEndDays & currdayofweek) == currdayofweek && !day.IsOtherMonth)
                {
                    tbcell.MergeStyle(WeekendDayStyle);
                    sb.AppendFormat(" {0}", WeekendDayStyle.CssClass);
                }
                if (day.IsOtherMonth)
                {
                    if (day.IsWeekend)
                    {
                        tbcell.ApplyStyle(OtherMonthDayStyle);
                        sb = new StringBuilder();
                        sb.AppendFormat(" {0}", OtherMonthDayStyle.CssClass);
                    }
                    else
                    {
                        tbcell.MergeStyle(OtherMonthDayStyle);
                        sb.AppendFormat(" {0}", OtherMonthDayStyle.CssClass);
                    }
                }

                if (SelectedDates.Contains(day.Date))
                {
                    tbcell.MergeStyle(SelectedDayStyle);
                    sb.AppendFormat(" {0}", SelectedDayStyle.CssClass);
                }
                if (day.IsToday)
                {
                    tbcell.MergeStyle(TodayDayStyle);
                    sb.AppendFormat(" {0}", TodayDayStyle.CssClass);
                }

                tbcell.MergeStyle(DayStyle);
                sb.AppendFormat(" {0}", DayStyle.CssClass);

                var s = Convert.ToString(sb.ToString().Trim());

                if (s.Length > 0)
                {
                    tbcell.CssClass = s;
                }

                // Add a literal control to the cell using the day number for the
                // text.
                tbcell.Controls.Add(new LiteralControl(day.DayNumberText));

                return(tbcell);
            }
Exemplo n.º 2
0
        private void OnSelectedDateChanged()
        {
            if (_dayPresenter == null)
            {
                return;
            }

            if (!_isInternalSet)
            {
                if (SelectedDates == null)
                {
                    SelectedDates = new ObservableCollection <DateTime>();
                }
                if (SelectedDate != null && !SelectedDates.Contains((DateTime)SelectedDate))
                {
                    _isInternalSet = true;
                    SelectedDates.Add((DateTime)SelectedDate);
                    _isInternalSet = false;
                }
                var date = SelectedDate ?? new DateTime(CurrentYear, CurrentMonth, 1);
                UpdateDays(date.Year, date.Month);
                UpdateMonths(date.Year, date.Month);
                UpdateYears(date.Year, date.Month);
            }
            RaiseSelectedDateChanged();
        }
Exemplo n.º 3
0
        private void DayPresenter_Unselected(object sender, SelectedDateChangedEventArgs e)
        {
            var dateTime = (DateTime)e.SelectedDate;

            _isInternalSet = true;
            if (SelectedDates == null)
            {
                SelectedDates = new ObservableCollection <DateTime>();
            }
            switch (Mode)
            {
            case CalendarXMode.Date:
                break;

            case CalendarXMode.DateRange:
                SelectedDate = null;
                break;

            case CalendarXMode.MultipleDate:
                if (SelectedDates.Contains(dateTime))
                {
                    SelectedDates.Remove(dateTime);
                }
                SelectedDate = null;
                break;
            }
            UpdateDays(CurrentYear, CurrentMonth);
            UpdateYears(CurrentYear, CurrentMonth);
            UpdateMonths(CurrentYear, CurrentMonth);
            _isInternalSet = false;
        }
Exemplo n.º 4
0
        void WriteDay(DateTime date, HtmlTextWriter writer, bool enabled)
        {
            TableItemStyle style = new TableItemStyle();
            TableCell      cell  = new TableCell();

            CalendarDay day = new CalendarDay(date,
                                              IsWeekEnd(date.DayOfWeek),
                                              date == TodaysDate, SelectedDates.Contains(date),
                                              GetGlobalCalendar().GetMonth(DisplayDate) != GetGlobalCalendar().GetMonth(date),
                                              date.Day.ToString());

            day.IsSelectable     = SelectionMode != CalendarSelectionMode.None;
            cell.HorizontalAlign = HorizontalAlign.Center;
            cell.Width           = Unit.Percentage(GetCellWidth());

            LiteralControl lit = new LiteralControl(day.DayNumberText);

            cell.Controls.Add(lit);

            OnDayRender(cell, day);

            if (dayStyle != null && !dayStyle.IsEmpty)
            {
                style.CopyFrom(dayStyle);
            }

            if (day.IsWeekend && weekendDayStyle != null && !weekendDayStyle.IsEmpty)
            {
                style.CopyFrom(weekendDayStyle);
            }

            if (day.IsToday && todayDayStyle != null && !todayDayStyle.IsEmpty)
            {
                style.CopyFrom(todayDayStyle);
            }

            if (day.IsOtherMonth && otherMonthDayStyle != null && !otherMonthDayStyle.IsEmpty)
            {
                style.CopyFrom(otherMonthDayStyle);
            }

            if (enabled && day.IsSelected)
            {
                style.BackColor = Color.Silver;
                style.ForeColor = Color.White;
                if (selectedDayStyle != null && !selectedDayStyle.IsEmpty)
                {
                    style.CopyFrom(selectedDayStyle);
                }
            }

            cell.ApplyStyle(style);

            lit.Text = BuildLink(GetDaysFromZenith(date).ToString(), day.DayNumberText,
                                 cell.ForeColor, enabled && day.IsSelectable);

            cell.RenderControl(writer);
        }
Exemplo n.º 5
0
        protected void SetButton(CalendarButton b, bool isFirst = false, bool isLast = false)
        {
            if (!SelectedDates.Contains(b.Date.Value.Date))
            {
                SelectedDates.Add(b.Date.Value.Date);
            }

            var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == b.Date.Value.Date);

            SetButtonSelected(b, spD, isFirst, isLast);
        }
        private void AddDateIfNotExist(DateTime date)
        {
            if (SpecialDates == null)
            {
                return;
            }

            if (!SelectedDates.Contains(date))
            {
                SelectedDates.Add(date);
            }
        }
        protected void calSelect_SelectionChanged(object sender, EventArgs e)
        {
            if (SelectedDates.Count() != 2 && calSelect.SelectedDate >= DateTime.Today)
            {
                if (!SelectedDates.Contains(calSelect.SelectedDate))
                {
                    SelectedDates.Add(calSelect.SelectedDate);
                }
                else
                {
                    SelectedDates.Remove(calSelect.SelectedDate);
                }
            }
            else if (SelectedDates.Count() == 2 && SelectedDates.Contains(calSelect.SelectedDate))
            {
                SelectedDates.Remove(calSelect.SelectedDate);
            }

            ViewState["SelectedDates"] = SelectedDates;
            int dayz = 0;

            if (SelectedDates.Count() == 2)
            {
                dayz = (SelectedDates[0] - SelectedDates[1]).Days;
                if (dayz < 0)
                {
                    dayz          = -dayz;
                    lblDates.Text = SelectedDates[0].ToString("dd/MM/yyyy") + " - " + SelectedDates[1].ToString("dd/MM/yyyy");
                }
                else
                {
                    lblDates.Text = SelectedDates[1].Date.ToString("dd/MM/yyyy") + " - " + SelectedDates[0].Date.ToString("dd/MM/yyyy");
                }
                txtDayz.Text = (dayz + 1).ToString();
            }
            else if (SelectedDates.Count() == 1)
            {
                dayz          = 1;
                txtDayz.Text  = (dayz).ToString();
                lblDates.Text = SelectedDates[0].ToString("dd/MM/yyyy");
            }
            else
            {
                txtDayz.Text  = "0";
                lblDates.Text = "";
            }
        }
Exemplo n.º 8
0
 private void OnDateLimitChanged()
 {
     _isInternalSet = true;
     if (SelectedDates == null)
     {
         SelectedDates = new ObservableCollection <DateTime>();
     }
     if (SelectedDate != null && MinDate != null && SelectedDate < MinDate)
     {
         var date = (DateTime)SelectedDate;
         if (SelectedDates.Contains(date))
         {
             SelectedDates.Remove(date);
         }
         SelectedDate = MinDate;
         SelectedDates.Add((DateTime)SelectedDate);
     }
     else if (SelectedDate != null && MaxDate != null && SelectedDate > MaxDate)
     {
         var date = (DateTime)SelectedDate;
         if (SelectedDates.Contains(date))
         {
             SelectedDates.Remove(date);
         }
         SelectedDate = MaxDate;
         SelectedDates.Add((DateTime)SelectedDate);
     }
     if (SelectedDates != null)
     {
         for (int i = SelectedDates.Count - 1; i >= 0; i--)
         {
             var date = SelectedDates[i];
             if (date < MinDate || date > MaxDate)
             {
                 SelectedDates.RemoveAt(i);
             }
         }
     }
     UpdateDays(CurrentYear, CurrentMonth);
     UpdateMonths(CurrentYear, CurrentMonth);
     UpdateYears(CurrentYear, CurrentMonth);
 }
Exemplo n.º 9
0
        /*private DatePicker_DayButton GetDayTemplateForDate(DateTime date)
         * {
         *  DatePicker_DayButton dayTemplate = null;
         *
         *  if ((DateSelectionMode == Dates.DateSelectionMode.SingleDate && SelectedDate.HasValue && date.Equals(SelectedDate.Date))
         || (DateSelectionMode == Dates.DateSelectionMode.MultipleDates && SelectedDates.Contains(date)))
         || {
         ||     dayTemplate = Ref_Template_Day_SelectedDay;
         || }
         || else if (date.Equals(DateTime.Today))
         || {
         ||     dayTemplate = Ref_Template_Day_Today;
         || }
         || else if (date.Month == VisibleDate.Date.Month)
         || {
         ||     dayTemplate = Ref_Template_Day_CurrentMonth;
         || }
         || else
         || {
         ||     dayTemplate = Ref_Template_Day_OtherMonths;
         || }
         ||
         || return dayTemplate;
         ||}*/

        private DatePickerDayButtonType GetDayTypeForDate(DateTime date)
        {
            DatePickerDayButtonType type;

            if ((DateSelectionMode == Dates.DateSelectionMode.SingleDate && SelectedDate.HasValue && date.Equals(SelectedDate.Date)) ||
                (DateSelectionMode == Dates.DateSelectionMode.MultipleDates && SelectedDates.Contains(date)))
            {
                type = DatePickerDayButtonType.SelectedDay;
            }
            else if (date.Equals(DateTime.Today))
            {
                type = DatePickerDayButtonType.Today;
            }
            else if (date.Month == VisibleDate.Date.Month)
            {
                type = DatePickerDayButtonType.CurrentMonth;
            }
            else
            {
                type = DatePickerDayButtonType.OtherMonths;
            }

            return(type);
        }
Exemplo n.º 10
0
            /// <summary>
            ///     This member overrides <see cref="System.Web.UI.Control.Render" />.
            /// </summary>
            protected override void Render(HtmlTextWriter output)
            {
                // Create the main table.
                var table = new Table();

                table.CellPadding = CellPadding;
                table.CellSpacing = CellSpacing;

                if (ShowGridLines)
                {
                    table.GridLines = GridLines.Both;
                }
                else
                {
                    table.GridLines = GridLines.None;
                }

                // If ShowTitle is true, add a row with the calendar title.
                if (ShowTitle)
                {
                    // Create a one-cell table row.
                    var row  = new TableRow();
                    var cell = new TableCell();
                    if (HasWeekSelectors(SelectionMode))
                    {
                        cell.ColumnSpan = 8;
                    }
                    else
                    {
                        cell.ColumnSpan = 7;
                    }

                    // Apply styling.
                    cell.MergeStyle(TitleStyle);

                    // Add the title table to the cell.
                    cell.Controls.Add(TitleTable());
                    row.Cells.Add(cell);

                    // Add it to the table.
                    table.Rows.Add(row);
                }

                // If ShowDayHeader is true, add a row with the days header.
                if (ShowDayHeader)
                {
                    table.Rows.Add(DaysHeaderTableRow());
                }

                // Find the first date that will be visible on the calendar.
                var date = GetFirstCalendarDate();

                // Create a list for storing nonselectable dates.
                var nonselectableDates = new ArrayList();

                // Add rows for the dates (six rows are always displayed).
                for (var i = 0; i <= 5; i++)
                {
                    var row = new TableRow();

                    // Create a week selector, if needed.
                    if (HasWeekSelectors(SelectionMode))
                    {
                        var cell = new TableCell();
                        cell.HorizontalAlign = HorizontalAlign.Center;
                        cell.MergeStyle(SelectorStyle);

                        if (Enabled)
                        {
                            // Create the post back link.
                            var anchor = new HtmlAnchor();
                            var arg    = string.Format("R{0}07", DayCountFromDate(date));
                            anchor.HRef = Page.ClientScript.GetPostBackClientHyperlink(this, arg);
                            anchor.Controls.Add(new LiteralControl(SelectWeekText));

                            // Add a color style to the anchor if it is explicitly
                            // set.
                            if (!SelectorStyle.ForeColor.IsEmpty)
                            {
                                anchor.Attributes.Add(
                                    "style", string.Format("color:{0}", SelectorStyle.ForeColor.Name));
                            }

                            cell.Controls.Add(anchor);
                        }
                        else
                        {
                            cell.Controls.Add(new LiteralControl(SelectWeekText));
                        }

                        row.Cells.Add(cell);
                    }

                    // Add the days (there are always seven days per row).
                    for (var j = 0; j <= 6; j++)
                    {
                        // Create a CalendarDay and a TableCell for the date.
                        var day  = Day(date);
                        var cell = Cell(day);

                        // Raise the OnDayRender event.
                        OnDayRender(cell, day);

                        // If the day was marked nonselectable, add it to the list.
                        if (!day.IsSelectable)
                        {
                            nonselectableDates.Add(day.Date.ToShortDateString());
                        }

                        // If the day is selectable, and the selection mode allows
                        // it, convert the text to a link with post back.
                        if (Enabled && day.IsSelectable && SelectionMode != CalendarSelectionMode.None)
                        {
                            try
                            {
                                // Create the post back link.
                                var anchor = new HtmlAnchor();
                                var arg    = Convert.ToString(DayCountFromDate(date).ToString());
                                anchor.HRef = Page.ClientScript.GetPostBackClientHyperlink(this, arg);

                                // Copy the existing text.
                                anchor.Controls.Add(new LiteralControl(((LiteralControl)cell.Controls[0]).Text));

                                // Add a color style to the anchor if it is
                                // explicitly set. Note that the style precedence
                                // follows that of the base Calendar control.
                                var s = "";
                                if (!DayStyle.ForeColor.IsEmpty)
                                {
                                    s = DayStyle.ForeColor.Name;
                                }
                                var currdayofweek = DayOfWeekMapping(day.Date.DayOfWeek);
                                if ((WeekEndDays & currdayofweek) == currdayofweek &&
                                    !WeekendDayStyle.ForeColor.IsEmpty)
                                {
                                    s = WeekendDayStyle.ForeColor.Name;
                                }
                                if (day.IsOtherMonth && !OtherMonthDayStyle.ForeColor.IsEmpty)
                                {
                                    s = OtherMonthDayStyle.ForeColor.Name;
                                }
                                if (day.IsToday && !TodayDayStyle.ForeColor.IsEmpty)
                                {
                                    s = TodayDayStyle.ForeColor.Name;
                                }
                                if (SelectedDates.Contains(day.Date) && !SelectedDayStyle.ForeColor.IsEmpty)
                                {
                                    s = SelectedDayStyle.ForeColor.Name;
                                }
                                if (s.Length > 0)
                                {
                                    anchor.Attributes.Add("style", string.Format("color:{0}", s));
                                }

                                // Replace the literal control in the cell with
                                // the anchor.
                                cell.Controls.RemoveAt(0);
                                cell.Controls.AddAt(0, anchor);
                            }
                            // ReSharper disable once EmptyGeneralCatchClause
                            catch (Exception)
                            { }
                        }

                        // Add the cell to the current table row.
                        row.Cells.Add(cell);

                        // Bump the date.
                        date = date.AddDays(1);
                    }

                    // Add the row.
                    table.Rows.Add(row);
                }

                // Save the list of nonselectable dates.
                if (nonselectableDates.Count > 0)
                {
                    SaveNonselectableDates(nonselectableDates);
                }

                // Apply styling.
                AddAttributesToRender(output);

                // Render the table.
                table.RenderControl(output);
            }
Exemplo n.º 11
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var inflater = (LayoutInflater)_context.GetSystemService(Context.LayoutInflaterService);
            var cellView = convertView;

            // For reuse
            if (convertView == null)
            {
                cellView = inflater.Inflate(Resource.Layout.CustomCell, null);
            }

            var paddingTop    = cellView.PaddingTop;
            var paddingLeft   = cellView.PaddingLeft;
            var paddingBottom = cellView.PaddingBottom;
            var paddingRight  = cellView.PaddingRight;

            TextView tv1 = cellView.FindViewById <TextView>(Resource.Id.tv1);
            TextView tv2 = cellView.FindViewById <TextView>(Resource.Id.tv2);

            tv1.SetTextColor(Color.Black);

            // Get dateTime of this cell
            var dateTime  = DateTimes[position];
            var resources = _context.Resources;

            // Set color of the dates in previous / next month
            if (dateTime.Month != _month)
            {
                var resource = Caldroid.Xamarin.Resource.Color.caldroid_darker_gray;
                var color    = new Color(ContextCompat.GetColor(_context, resource));

                tv1.SetTextColor(color);
            }

            var shouldResetDiabledView  = false;
            var shouldResetSelectedView = false;

            // Customize for disabled dates and date outside min/max dates
            if ((MinDate != null && dateTime.Date < MinDate.Value.Date) ||
                (MaxDate != null && dateTime.Date > MaxDate.Value.Date) ||
                (DisabledDates != null && DisabledDates.Contains(dateTime)))
            {
                tv1.SetTextColor(CaldroidFragment.DisabledTextColor);

                if (CaldroidFragment.DisabledBackgroundDrawable == -1)
                {
                    cellView.SetBackgroundResource(Caldroid.Xamarin.Resource.Drawable.disable_cell);
                }
                else
                {
                    cellView.SetBackgroundResource(CaldroidFragment.DisabledBackgroundDrawable);
                }

                if (dateTime.Date == DateTime.Now.Date)
                {
                    cellView.SetBackgroundResource(Caldroid.Xamarin.Resource.Drawable.red_border_gray_bg);
                }
            }
            else
            {
                shouldResetDiabledView = true;
            }

            // Customize for selected dates
            if (SelectedDates != null && SelectedDates.Contains(dateTime))
            {
                var resource = Caldroid.Xamarin.Resource.Color.caldroid_sky_blue;
                var color    = new Color(ContextCompat.GetColor(_context, resource));

                cellView.SetBackgroundColor(color);

                tv1.SetTextColor(Color.Black);
            }
            else
            {
                shouldResetSelectedView = true;
            }

            if (shouldResetDiabledView && shouldResetSelectedView)
            {
                // Customize for today
                if (dateTime.Date == DateTime.Now.Date)
                {
                    cellView.SetBackgroundResource(Caldroid.Xamarin.Resource.Drawable.red_border);
                }
                else
                {
                    cellView.SetBackgroundResource(Caldroid.Xamarin.Resource.Drawable.cell_bg);
                }
            }

            tv1.Text = "" + dateTime.ToString("dd");
            tv2.Text = "Hi";

            // Somehow after setBackgroundResource, the padding collapse.
            // This is to recover the padding
            cellView.SetPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

            // Set custom color if required
            SetCustomResources(dateTime, cellView, tv1);

            return(cellView);
        }