public void Read(DateTime date) { var year = _calendar.GetYear(date); var month = _calendar.GetMonth(date); var day = _calendar.GetDayOfMonth(date); Read(year, month, day, date.Hour, date.Minute, date.Second, date.Millisecond); }
private void InitializeMe() { System.Globalization.Calendar c1 = _GetCalendar(_Calendar); if (_DateTime != null && _DateTime.Value.Year > 690) { Year = c1.GetYear(_DateTime.Value); Month = c1.GetMonth(_DateTime.Value); Day = c1.GetDayOfMonth(_DateTime.Value); DayOfWeek = c1.GetDayOfWeek(_DateTime.Value); } else { _DateTime = null; } }
// TODO: Need more work to accept (") and (') and (%) and (\) characters. public static string ToCurrentCultureString(DateTime dt, string format, System.Globalization.DateTimeFormatInfo formatProvider) { // Some formats do not need to custom implementation like these string[] autoReplaces = new string[] { "fffffff", "ffffff", "fffff", "ffff", "fff", "ff", "f", "FFFFFFF", "FFFFFF", "FFFFF", "FFFF", "FFF", "FF", "F", "gg", "g", "hh", "HH", "mm", "ss", "tt", "t" }; System.Globalization.Calendar cal = GetCurrentCalendar(); int year = cal.GetYear(dt); int month = cal.GetMonth(dt); int day = cal.GetDayOfMonth(dt); DayOfWeek dayOfWeek = cal.GetDayOfWeek(dt); foreach (string autoReplace in autoReplaces) { format = format.Replace(autoReplace, dt.ToString(autoReplace, formatProvider)); } format = format.Replace("dddd", formatProvider.GetDayName(dayOfWeek)); format = format.Replace("ddd", formatProvider.GetAbbreviatedDayName(dayOfWeek)); format = format.Replace("dd", ((int)dayOfWeek).ToString("00")); format = format.Replace("dd", dayOfWeek.ToString()); format = format.Replace("MMMM", formatProvider.GetMonthName(month)); format = format.Replace("MMM", formatProvider.GetAbbreviatedMonthName(month)); format = format.Replace("MM", month.ToString("00")); format = format.Replace("M", month.ToString()); format = format.Replace("yyyy", year.ToString("0000")); format = format.Replace("yyy", year.ToString("000")); format = format.Replace("yy", (year % 100).ToString("00")); format = format.Replace("y", (year % 100).ToString()); return(format); }
/// <summary> /// Checks whether RadCalendarDay object is associated with a DateTime that represents a recurring event. /// </summary> /// <param name="compareTime">the DateTime to compare.</param> /// <param name="processCalendar">the System.Globalization.Calendar object used to check whether the DateTime /// represents a recurring event.</param> /// <returns></returns> internal protected virtual RecurringEvents IsRecurring(DateTime compareTime, System.Globalization.Calendar processCalendar) { if (Recurring != RecurringEvents.None) { switch (Recurring) { case RecurringEvents.DayInMonth: { int firstCompare = processCalendar.GetDayOfMonth(compareTime); int secondCompare = processCalendar.GetDayOfMonth(this.Date); if (firstCompare.Equals(secondCompare)) { return(Recurring); } } break; case RecurringEvents.Today: if (compareTime.Equals(DateTime.Today)) { return(Recurring); } break; case RecurringEvents.DayAndMonth: { int FirstCompare = processCalendar.GetDayOfMonth(compareTime); int SecondCompare = processCalendar.GetDayOfMonth(this.Date); int FirstMonthCompare = processCalendar.GetMonth(compareTime); int SecondMonthCompare = processCalendar.GetMonth(this.Date); if (FirstCompare.Equals(SecondCompare) && FirstMonthCompare.Equals(SecondMonthCompare)) { return(Recurring); } } break; case RecurringEvents.WeekAndMonth: { DayOfWeek FirstCompare = processCalendar.GetDayOfWeek(compareTime); DayOfWeek SecondCompare = processCalendar.GetDayOfWeek(this.Date); int FirstMonthCompare = processCalendar.GetMonth(compareTime); int SecondMonthCompare = processCalendar.GetMonth(this.Date); if (FirstCompare.Equals(SecondCompare) && FirstMonthCompare.Equals(SecondMonthCompare)) { return(Recurring); } break; } case RecurringEvents.Week: { DayOfWeek FirstCompare = processCalendar.GetDayOfWeek(compareTime); DayOfWeek SecondCompare = processCalendar.GetDayOfWeek(this.Date); if (FirstCompare.Equals(SecondCompare)) { return(Recurring); } break; } default: break; } } return(RecurringEvents.None); }
public Image DrawSchema(out CoordsMaps coordsMaps, int colHeight, DateTime startDate, DateTime endDate, RowsFlags Pflags) { System.Globalization.CultureInfo UICulture = System.Threading.Thread.CurrentThread.CurrentUICulture; System.Globalization.Calendar cal = UICulture.Calendar; ganttStart = startDate; ganttEnd = endDate; int days = endDate.Subtract(startDate).Days; int rowCount = 0; if ((Pflags & RowsFlags.NoYears) != RowsFlags.NoYears) { yearRow = (rowCount++) * rowsSize + top; } int startYear = startDate.Year; int firstColYear = 0; if ((Pflags & RowsFlags.NoMonths) != RowsFlags.NoMonths) { monthRow = (rowCount++) * rowsSize + top; } int startMonth = startDate.Month; int firstColMonth = 0; if ((Pflags & RowsFlags.NoWeeks) != RowsFlags.NoWeeks) { weekRow = (rowCount++) * rowsSize + top; } int startWeek = cal.GetWeekOfYear(startDate, UICulture.DateTimeFormat.CalendarWeekRule, UICulture.DateTimeFormat.FirstDayOfWeek); int firstColWeek = 0; if ((Pflags & RowsFlags.NoDays) != RowsFlags.NoDays) { dayRow = (rowCount++) * rowsSize + top; } this.ganttHeight = colHeight + dayRow + 1; Image img = new Bitmap(days * dayColumnSize + 1, this.ganttHeight); g = Graphics.FromImage(img); g.Clear(Color.White); SolidBrush brush = new SolidBrush(Color.Black); SolidBrush dayBrush = new SolidBrush(Color.LightGray); SolidBrush weekendBrush = new SolidBrush(Color.DarkGray); sf = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.MeasureTrailingSpaces); Font yearFont = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf); monthFont = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf); descFont = FontToFitVertical(new FontFamily("Arial"), FontStyle.Regular, rowsSize, sf); descFontBold = FontToFitVertical(new FontFamily("Arial"), FontStyle.Bold, rowsSize, sf); monthDayFont = FontToFitHorizontal(new FontFamily("Arial"), FontStyle.Regular, dayColumnSize, sf); Pen pen = new Pen(Color.DarkGray, 1F); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; int dayLeft = 0; Rectangle ra = new Rectangle(); CoordsMaps cm = new CoordsMaps(); for (int i = 0; i <= days; i++) { int currentPixel = i * dayColumnSize; DateTime todayDate = cal.AddDays(startDate, i); if (yearRow != -1 && (todayDate.Year != startYear || i == days)) { ra = new Rectangle(left + firstColYear, yearRow, currentPixel - firstColYear, rowsSize); g.DrawRectangle(pen, ra); g.DrawString(startYear.ToString(), monthFont, brush, ra, sf); cm.Add(new CoordsMap(RowTypes.Years, ra, startYear)); startYear = todayDate.Year; firstColYear = currentPixel; } if (monthRow != -1 && (todayDate.Day == 1 || i == days)) { ra = new Rectangle(left + firstColMonth, monthRow, currentPixel - firstColMonth, rowsSize); string month = UICulture.DateTimeFormat.GetMonthName(startMonth); if (yearRow == -1) { month += " " + todayDate.Year; } g.DrawRectangle(pen, ra); if (g.MeasureString(month, monthFont, 100000, sf).Width < ra.Width + 4) { g.DrawString(month, monthFont, brush, ra, sf); } else if (g.MeasureString(UICulture.DateTimeFormat.GetMonthName(startMonth), monthFont, 100000, sf).Width < ra.Width + 4) { g.DrawString(UICulture.DateTimeFormat.GetMonthName(startMonth), monthFont, brush, ra, sf); } cm.Add(new CoordsMap(RowTypes.Months, ra, startMonth)); startMonth = todayDate.Month; firstColMonth = currentPixel; } if (weekRow != -1 && (todayDate.DayOfWeek == UICulture.DateTimeFormat.FirstDayOfWeek || i == days)) { ra = new Rectangle(left + firstColWeek, weekRow, currentPixel - firstColWeek, rowsSize); g.DrawRectangle(pen, ra); g.DrawString(startWeek.ToString(), monthFont, brush, ra, sf); cm.Add(new CoordsMap(RowTypes.Weeks, ra, startWeek)); startWeek++; firstColWeek = currentPixel; } if (dayRow != -1 && i != days) { ra = new Rectangle(left + dayLeft, dayRow, dayColumnSize, rowsSize); dayLeft += (dayColumnSize); Rectangle r = ra; r.Height = colHeight; if (todayDate.DayOfWeek == DayOfWeek.Sunday || todayDate.DayOfWeek == DayOfWeek.Saturday) { g.FillRectangle(dayBrush, r); } g.DrawRectangle(pen, r); cm.Add(new CoordsMap(RowTypes.Days, r, i)); g.DrawString(cal.GetDayOfMonth(todayDate).ToString(), monthDayFont, brush, ra, sf); Rectangle r2 = ra; r2.Y += monthDayFont.Height; g.DrawString(UICulture.DateTimeFormat.GetShortestDayName(cal.GetDayOfWeek(todayDate)).ToUpper().Substring(0, 1), monthDayFont, brush, r2, sf); if (todayDate.ToShortDateString() == DateTime.Now.ToShortDateString()) { g.DrawLine(new Pen(Color.Red), currentPixel, dayRow, currentPixel, dayRow + colHeight); } } } dayRow += monthDayFont.Height; coordsMaps = cm; return(img); }
protected override void Render(HtmlTextWriter writer) { try { DateTime tmpDate; try { tmpDate = this.SelectedDate == "" ? DateTime.Now : Convert.ToDateTime(SelectedDate); } catch (Exception ex) { tmpDate = DateTime.Now; } string temp = CssClass; CssClass = ""; if (temp == "") { temp = "ampicker"; } writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Table); writer.RenderBeginTag(HtmlTextWriterTag.Tr); if (Text != "") { writer.AddAttribute(HtmlTextWriterAttribute.Style, "white-space:nowrap"); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write(Text); writer.RenderEndTag(); } writer.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.AddAttribute("class", temp); writer.AddAttribute("id", ClientID); writer.AddAttribute("name", ClientID); writer.AddAttribute("onblur", "return window." + ClientID + ".onblur(this);"); writer.AddAttribute("onkeypress", "return window." + ClientID + ".onlyDateChars(event);"); //writer.AddAttribute("onkeydown", "return window." & Me.ClientID & ".KeyPress(event);") //writer.AddAttribute("onclick", "return window." & Me.ClientID & ".Click(event);showalert();") if (Enabled == false) { writer.AddAttribute("disabled", "disabled"); } if (ShowDateBox) { writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); } dtFI = Thread.CurrentThread.CurrentCulture.DateTimeFormat; if (!(string.IsNullOrEmpty(SelectedDate))) { DateTime dte = DateTime.Parse(SelectedDate); SelectedDate = dte.ToString(dtFI.ShortDatePattern + " " + dtFI.ShortTimePattern); } writer.AddAttribute("type", "hidden"); writer.AddAttribute("id", "hid_" + ClientID); writer.AddAttribute("name", "hid_" + ClientID); writer.AddAttribute("value", SelectedDate); writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); writer.AddAttribute("id", "cal_" + ClientID); writer.AddAttribute("style", "display:none;position:absolute;"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (ImageUrl == string.Empty) { ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.calendar.gif"); } if (Enabled) { writer.AddAttribute("src", ImageUrl); writer.AddAttribute("onclick", "window." + ClientID + ".Toggle(event);"); writer.AddAttribute("id", "img_" + ClientID); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); var str = new StringBuilder(); str.Append("<script type=\"text/javascript\">"); cal = new System.Globalization.GregorianCalendar(); if (Thread.CurrentThread.CurrentCulture != null) { cal = Thread.CurrentThread.CurrentCulture.Calendar; } DateFormat = dtFI.ShortDatePattern; TimeFormat = dtFI.ShortTimePattern; str.Append("window." + ClientID + "=new asDatePicker('" + ClientID + "');"); str.Append("window." + ClientID + ".Locale='" + Context.Request.UserLanguages[0].Substring(0, 2).ToUpper() + "';"); str.Append("window." + ClientID + ".SelectedDate='" + SelectedDate + "';"); str.Append("window." + ClientID + ".Width='" + CalendarWidth + "';"); str.Append("window." + ClientID + ".Height='" + CalendarHeight + "';"); str.Append("window." + ClientID + ".DateFormat='" + dtFI.ShortDatePattern + "';"); str.Append("window." + ClientID + ".TimeFormat='" + dtFI.ShortTimePattern + "';"); str.Append("window." + ClientID + ".Year=" + tmpDate.Year + ";"); str.Append("window." + ClientID + ".Month=" + (tmpDate.Month - 1) + ";"); str.Append("window." + ClientID + ".Day=" + tmpDate.Day + ";"); str.Append("window." + ClientID + ".SelectedYear=" + tmpDate.Year + ";"); str.Append("window." + ClientID + ".SelectedMonth=" + (tmpDate.Month - 1) + ";"); str.Append("window." + ClientID + ".SelectedDay=" + tmpDate.Day + ";"); str.Append("window." + ClientID + ".ShowTime=" + ShowTime.ToString().ToLower() + ";"); str.Append("window." + ClientID + ".DefaultTime='" + DefaultTime + "';"); str.Append("window." + ClientID + ".CallbackFlag='" + CallbackFlag + "';"); if (!(string.IsNullOrEmpty(RelatedControl))) { Control ctl = Parent.FindControl(RelatedControl); if (ctl == null) { ctl = Page.FindControl(RelatedControl); } if (ctl == null) { RelatedControl = string.Empty; } else { RelatedControl = ctl.ClientID; } } str.Append("window." + ClientID + ".linkedControl='" + RelatedControl + "';"); if (IsEndDate) { str.Append("window." + ClientID + ".isEndDate=true;"); } else { str.Append("window." + ClientID + ".isEndDate=false;"); } string sTime = string.Empty; SelectedTime = tmpDate.ToString(TimeFormat); if (ShowTime) { if (SelectedTime != "12:00 AM") { sTime = SelectedTime; } if (TimeRequired) { str.Append("window." + ClientID + ".RequireTime=true;"); } else { str.Append("window." + ClientID + ".RequireTime=false;"); } } else { str.Append("window." + ClientID + ".RequireTime=false;"); } str.Append("window." + ClientID + ".SelectedTime='" + sTime + "';"); if (string.IsNullOrEmpty(ImgNext)) { str.Append("window." + ClientID + ".ImgNext='" + Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.cal_nextMonth.gif") + "';"); } else { str.Append("window." + ClientID + ".ImgNext='" + Page.ResolveUrl(ImgNext) + "';"); } if (string.IsNullOrEmpty(ImgPrev)) { str.Append("window." + ClientID + ".ImgPrev='" + Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.cal_prevMonth.gif") + "';"); } else { str.Append("window." + ClientID + ".ImgPrev='" + Page.ResolveUrl(ImgPrev) + "';"); } if (SelectedDate != "") { try { if (ShowTime == false && sTime == string.Empty) { str.Append("window." + ClientID + ".textbox.value=new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + ").formatDP('" + DateFormat + "','" + ClientID + "');"); str.Append("window." + ClientID + ".dateSel = new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + ",0,0,0,0);"); } else { str.Append("window." + ClientID + ".textbox.value=new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + "," + tmpDate.Hour + "," + tmpDate.Minute + ",0).formatDP('" + DateFormat + " " + TimeFormat + "','" + ClientID + "');"); str.Append("window." + ClientID + ".dateSel = new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + "," + tmpDate.Hour + "," + tmpDate.Minute + ",0);"); } } catch (Exception ex) { } } int xMonths = cal.GetMonthsInYear(cal.GetYear(tmpDate), cal.GetEra(tmpDate)); int currMonth = cal.GetMonth(tmpDate); int currYear = cal.GetYear(tmpDate); int currDay = cal.GetDayOfMonth(tmpDate); str.Append("window." + ClientID + ".MonthDays = new Array("); for (int i = 0; i < xMonths; i++) { str.Append(cal.GetDaysInMonth(currYear, i + 1)); if (i < (xMonths - 1)) { str.Append(","); } } str.Append(");"); str.AppendLine(); string[] mNames = dtFI.MonthNames; str.Append("window." + ClientID + ".MonthNames = new Array("); for (int i = 0; i < xMonths; i++) { str.Append("'" + mNames[i] + "'"); if (i < (xMonths - 1)) { str.Append(","); } } str.Append(");"); str.AppendLine(); str.Append("window." + ClientID + ".ShortMonthNames = new Array("); string[] mAbbr = dtFI.AbbreviatedMonthNames; for (int i = 0; i < xMonths; i++) { str.Append("'" + mAbbr[i] + "'"); if (i < (xMonths - 1)) { str.Append(","); } } str.Append(");"); str.AppendLine(); str.Append("window." + ClientID + ".ShortDayNames = new Array("); string[] dAbbr = dtFI.AbbreviatedDayNames; for (int i = 0; i <= 6; i++) { str.Append("'" + dAbbr[i] + "'"); if (i < 6) { str.Append(","); } } str.Append(");"); str.AppendLine(); str.Append("window." + ClientID + ".Class={"); str.Append("CssCalendarStyle:'" + CssCalendarStyle + "',"); str.Append("CssMonthStyle:'" + CssMonthStyle + "',"); str.Append("CssWeekendStyle:'" + CssWeekendStyle + "',"); str.Append("CssWeekdayStyle:'" + CssWeekdayStyle + "',"); str.Append("CssSelectedDayStyle:'" + CssSelectedDayStyle + "',"); str.Append("CssCurrentMonthDayStyle:'" + CssCurrentMonthDayStyle + "',"); str.Append("CssOtherMonthDayStyle:'" + CssOtherMonthDayStyle + "',"); str.Append("CssDayHeaderStyle:'" + CssDayHeaderStyle + "',"); str.Append("CssCurrentDayStyle:'" + CssCurrentDayStyle + "'};"); str.Append("window." + ClientID + ".selectedDate=window." + ClientID + ".textbox.value;"); str.Append("window." + ClientID + ".timeLabel='[RESX:Time]';"); str.Append("</script>"); writer.Write(str); } catch (Exception ex) { } }