コード例 #1
0
ファイル: EventCalendar.cs プロジェクト: zahedbri/mojoportal
        private TableRow CreateDayHeader(DateTime firstDay, DateTime visibleDate, System.Globalization.Calendar threadCalendar)
        {
            TableRow row = new TableRow();

            DateTimeFormatInfo dtf = DateTimeFormatInfo.CurrentInfo;

            TableItemStyle dayNameStyle = new TableItemStyle();

            dayNameStyle.HorizontalAlign = HorizontalAlign.Center;
            dayNameStyle.CopyFrom(DayHeaderStyle);
            DayNameFormat dayNameFormat = DayNameFormat;

            int numericFirstDay = (int)threadCalendar.GetDayOfWeek(firstDay);

            for (int i = numericFirstDay; i < numericFirstDay + 7; i++)
            {
                string dayName;
                int    dayOfWeek = i % 7;
                switch (dayNameFormat)
                {
                case DayNameFormat.FirstLetter:
                    dayName = dtf.GetDayName((DayOfWeek)dayOfWeek).Substring(0, 1);
                    break;

                case DayNameFormat.FirstTwoLetters:
                    dayName = dtf.GetDayName((DayOfWeek)dayOfWeek).Substring(0, 2);
                    break;

                case DayNameFormat.Full:
                    dayName = dtf.GetDayName((DayOfWeek)dayOfWeek);
                    break;

                case DayNameFormat.Short:
                    dayName = dtf.GetAbbreviatedDayName((DayOfWeek)dayOfWeek);
                    break;

                case DayNameFormat.Shortest:
                    dayName = dtf.GetShortestDayName((DayOfWeek)dayOfWeek);
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown DayNameFormat value!");

                    goto
                case DayNameFormat.Short;
                }

                TableCell cell = new TableCell();
                cell.ApplyStyle(dayNameStyle);
                cell.Text = dayName;
                row.Cells.Add(cell);
            }
            return(row);
        }
コード例 #2
0
        /// <summary>
        /// Gets the string representation for a particular day in the week.
        /// </summary>
        /// <param name="weekDay">Specifies the day of the week.</param>
        /// <returns>the string representation for the specified day.</returns>
        internal protected virtual string GetDayHeaderString(int weekDay)
        {
            DateTimeFormatInfo dateLocalInfo = this.Calendar.DateTimeFormat;
            DayNameFormat      dayFormat     = this.Calendar.DayNameFormat;
            string             dayString     = String.Empty;

            switch (dayFormat)
            {
            case DayNameFormat.Full:
            {
                dayString = dateLocalInfo.GetDayName((DayOfWeek)weekDay);
                break;
            }

            case DayNameFormat.FirstLetter:
            {
                string str = dateLocalInfo.ShortestDayNames[weekDay];
                TextElementEnumerator iter = StringInfo.GetTextElementEnumerator(str);
                iter.MoveNext();
                dayString = iter.Current.ToString();
                break;
            }

            case DayNameFormat.FirstTwoLetters:
            {
                string str = dateLocalInfo.ShortestDayNames[weekDay];
                TextElementEnumerator iter = StringInfo.GetTextElementEnumerator(str);
                iter.MoveNext();
                StringBuilder ftl = new StringBuilder(iter.Current.ToString());
                if (iter.MoveNext())         //in case of Arabic cultures
                {
                    ftl.Append(iter.Current.ToString());
                }
                dayString = ftl.ToString();
                break;
            }

            case DayNameFormat.Short:
            {
                dayString = dateLocalInfo.GetAbbreviatedDayName((DayOfWeek)weekDay);
                break;
            }

            case DayNameFormat.Shortest:
            default:
            {
                dayString = dateLocalInfo.ShortestDayNames[weekDay];
                break;
            }
            }
            return(dayString);
        }
コード例 #3
0
        protected internal virtual string GetDayHeaderString(int weekDay)
        {
            DateTimeFormatInfo dateTimeFormat = this.Calendar.DateTimeFormat;
            DayNameFormat      dayNameFormat  = this.Calendar.DayNameFormat;
            string             empty          = string.Empty;
            string             str;

            switch (dayNameFormat)
            {
            case DayNameFormat.Full:
                str = dateTimeFormat.GetDayName((DayOfWeek)weekDay);
                break;

            case DayNameFormat.Short:
                str = dateTimeFormat.GetAbbreviatedDayName((DayOfWeek)weekDay);
                break;

            case DayNameFormat.FirstLetter:
                TextElementEnumerator elementEnumerator1 = StringInfo.GetTextElementEnumerator(dateTimeFormat.ShortestDayNames[weekDay]);
                elementEnumerator1.MoveNext();
                str = elementEnumerator1.Current.ToString();
                break;

            case DayNameFormat.FirstTwoLetters:
                TextElementEnumerator elementEnumerator2 = StringInfo.GetTextElementEnumerator(dateTimeFormat.ShortestDayNames[weekDay]);
                elementEnumerator2.MoveNext();
                StringBuilder stringBuilder = new StringBuilder(elementEnumerator2.Current.ToString());
                if (elementEnumerator2.MoveNext())
                {
                    stringBuilder.Append(elementEnumerator2.Current.ToString());
                }
                str = stringBuilder.ToString();
                break;

            default:
                str = dateTimeFormat.ShortestDayNames[weekDay];
                break;
            }
            return(str);
        }
コード例 #4
0
        protected virtual void OnRenderDayHeader(HtmlTextWriter writer, DateTime visibleDate, CalendarSelectionMode selectionMode, bool buttonsActive)
        {
            writer.Write("<tr>");
            DateTimeFormatInfo currentInfo = GetDateTimeFormatter();

            if (this.HasWeekSelectors(selectionMode))
            {
                TableItemStyle style = new TableItemStyle();
                style.HorizontalAlign = HorizontalAlign.Center;
                if (selectionMode == CalendarSelectionMode.DayWeekMonth)
                {
                    int days       = visibleDate.Subtract(baseDate).Days;
                    int dayOfMonth = this.threadCalendar.GetDaysInMonth(this.threadCalendar.GetYear(visibleDate), this.threadCalendar.GetMonth(visibleDate), this.threadCalendar.GetEra(visibleDate));
                    if (this.IsMinSupportedYearMonth(visibleDate))
                    {
                        dayOfMonth = (dayOfMonth - this.threadCalendar.GetDayOfMonth(visibleDate)) + 1;
                    }
                    else if (this.IsMaxSupportedYearMonth(visibleDate))
                    {
                        dayOfMonth = this.threadCalendar.GetDayOfMonth(this.maxSupportedDate);
                    }
                    string eventArgument = "R" + (((days * 100) + dayOfMonth)).ToString(CultureInfo.InvariantCulture);
                    style.CopyFrom(this.SelectorStyle);
                    string title = null;

                    this.OnRenderCalendarCell(writer, style, this.SelectMonthText, title, buttonsActive, eventArgument);
                }
                else
                {
                    style.CopyFrom(this.DayHeaderStyle);
                    this.OnRenderCalendarCell(writer, style, string.Empty, null, false, null);
                }
            }

            TableItemStyle weekdayStyle = new TableItemStyle();

            weekdayStyle.HorizontalAlign = HorizontalAlign.Center;
            weekdayStyle.CopyFrom(this.DayHeaderStyle);

            DayNameFormat dayNameFormat = this.DayNameFormat;
            int           firstDay      = this.NumericFirstDayOfWeek();

            for (int i = firstDay; i < (firstDay + 7); i++)
            {
                string dayName;
                int    dayOfWeekNumber = i % 7;

                switch (dayNameFormat)
                {
                case DayNameFormat.Full:
                    dayName = currentInfo.GetDayName((DayOfWeek)dayOfWeekNumber);
                    break;

                case DayNameFormat.FirstLetter:
                    dayName = currentInfo.GetDayName((DayOfWeek)dayOfWeekNumber).Substring(0, 1);
                    break;

                case DayNameFormat.FirstTwoLetters:
                    dayName = currentInfo.GetDayName((DayOfWeek)dayOfWeekNumber).Substring(0, 2);
                    break;

                case DayNameFormat.Shortest:
                    dayName = currentInfo.GetShortestDayName((DayOfWeek)dayOfWeekNumber);
                    break;

                default:
                    dayName = currentInfo.GetAbbreviatedDayName((DayOfWeek)dayOfWeekNumber);
                    break;
                }

                this.OnRenderCalendarCell(writer, weekdayStyle, dayName, null, false, null);
            }
            writer.Write("</tr>");
        }