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; }
CalendarDay getDay(DateTime d, DateTime todaysDate, DateTime visibleDate, System.Globalization.Calendar threadCalendar) { int dayOfWeek = (int)threadCalendar.GetDayOfWeek(d); int dayOfMonth = threadCalendar.GetDayOfMonth(d); string dayNumberText = d.ToString("dd", CultureInfo.CurrentCulture); int visibleDateMonth = threadCalendar.GetMonth(visibleDate); return new CalendarDay(d, (dayOfWeek == 0 || dayOfWeek == 6), // IsWeekend d.Equals(todaysDate), // IsToday threadCalendar.GetMonth(d) != visibleDateMonth, // IsOtherMonth dayNumberText // Number Text ); }