using System;
using System.Web.UI;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Collections;
using System.Threading;
namespace DBWebControls.Controls{
/// <summary>
/// Summary description for DatePicker.
/// </summary>
[ToolboxData("<{0}:DatePicker runat=\"server\"></{0}:DatePicker>")]
public class DatePicker:Control, INamingContainer
{
#region Private Properties
private string m_closeGif = "close.gif";
private string m_dividerGif = "divider.gif";
private string m_drop1Gif = "drop1.gif";
private string m_drop2Gif = "drop2.gif";
private string m_left1Gif = "left1.gif";
private string m_left2Gif = "left2.gif";
private string m_right1Gif = "right1.gif";
private string m_right2Gif = "right2.gif";
private string m_imgDirectory = "/img/";
private string m_ControlCssClass = "";
private DateTime m_value = DateTime.Now;
private string m_Css = "";
private string m_DateFormat = "dd/mm/yyyy";
private string m_DateSeparator = "/";
private string m_gotoString = "Go To Current Month";
private string m_todayString = "Today is";
private string m_weekString = "Wk";
private string m_scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
private string m_scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
private string m_selectMonthMessage = "Click to select a month.";
private string m_selectYearMessage = "Click to select a year.";
private string m_selectDateMessagePrefix = "Select ";
private string m_selectDateMessageSuffix = " as date. ";
#endregion
#region Public Properties
public DateTime Value
{
get
{
if (this.Controls.Count == 2)
{
string [] val = ((System.Web.UI.HtmlControls.HtmlInputText)Controls[1]).Value.Split(new char[]{'/'});
try
{
m_value = new DateTime(int.Parse(val[2]), int.Parse(val[1]) + 1, int.Parse(val[0]));
}
catch{}
}
return m_value;
}
set
{
m_value = value;
if (this.Controls.Count == 2)
{
((System.Web.UI.WebControls.TextBox)Controls[0]).Text = constructDate( m_DateFormat, m_value, Thread.CurrentThread.CurrentCulture);
((System.Web.UI.HtmlControls.HtmlInputText)Controls[1]).Value = GetRealDateString(m_value);
}
}
}
public string CssClass
{
get
{
if (this.Controls.Count == 0)
return "";
return ((System.Web.UI.WebControls.TextBox)Controls[0]).CssClass;
}
set
{
if (this.Controls.Count != 0)
{
((System.Web.UI.WebControls.TextBox)Controls[0]).CssClass = value;
m_Css = "";
}
else
m_Css = value;
}
}
public string imgClose
{
get {return m_closeGif;}
set {m_closeGif = value;}
}
public string imgDivider
{
get {return m_dividerGif;}
set {m_dividerGif = value;}
}
public string imgDrop1
{
get {return m_drop1Gif;}
set {m_drop1Gif = value;}
}
public string imgDrop2
{
get {return m_drop2Gif;}
set {m_drop2Gif = value;}
}
public string imgLeft1
{
get {return m_left1Gif;}
set {m_left1Gif = value;}
}
public string imgLeft2
{
get {return m_left2Gif;}
set {m_left2Gif = value;}
}
public string imgRight1
{
get {return m_right1Gif;}
set {m_right1Gif = value;}
}
public string imgDirectory
{
get {return m_imgDirectory;}
set {m_imgDirectory = value;}
}
public string ControlCssClass
{
get {return m_ControlCssClass;}
set {m_ControlCssClass = value;}
}
public string DateFormat
{
get {return m_DateFormat;}
set
{
m_DateFormat = value;
}
}
public string DateSeparator
{
get{return m_DateSeparator;}
set{m_DateSeparator = value;}
}
public string gotoString
{
get{return m_gotoString;}
set{m_gotoString = value;}
}
public string todayString
{
get{return m_todayString;}
set{m_todayString = value;}
}
public string weekString
{
get{return m_weekString;}
set{m_weekString = value;}
}
public string scrollLeftMessage
{
get{return m_scrollLeftMessage;}
set{m_scrollLeftMessage = value;}
}
public string scrollRightMessage
{
get{return m_scrollRightMessage;}
set{m_scrollRightMessage = value;}
}
public string selectMonthMessage
{
get{return m_selectMonthMessage;}
set{m_selectMonthMessage = value;}
}
public string selectYearMessage
{
get{return m_selectYearMessage;}
set{m_selectYearMessage = value;}
}
public string selectDateMessagePrefix
{
get{return m_selectDateMessagePrefix;}
set{m_selectDateMessagePrefix = value;}
}
public string selectDateMessageSuffix
{
get{return m_selectDateMessageSuffix;}
set{m_selectDateMessageSuffix = value;}
}
#endregion
#region Constructors
public DatePicker()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region Private Methods/Properties
private static string GetAbreviatedMonths(CultureInfo ci)
{
StringBuilder sb = new StringBuilder(200);
for(int i = 0; i < ci.DateTimeFormat.MonthNames.Length; i++)
{
if(sb.Length > 0)
sb.Append("','");
else
sb.Append("'");
sb.Append(ci.DateTimeFormat.GetAbbreviatedMonthName(i+1));
}
sb.Append("'");
return sb.ToString();
}
private static string GetMonths(CultureInfo ci)
{
StringBuilder sb = new StringBuilder(200);
for(int i = 0; i < ci.DateTimeFormat.MonthNames.Length; i++)
{
if(sb.Length > 0)
sb.Append("','");
else
sb.Append("'");
sb.Append(ci.DateTimeFormat.MonthNames[i]);
}
sb.Append("'");
return sb.ToString();
}
private string GetFirstDayOfWeek(CultureInfo ci)
{
if(ci.DateTimeFormat.FirstDayOfWeek == DayOfWeek.Sunday)
return "0";
else
return "1";
}
private string GetAbreviatedWeekDays(CultureInfo ci)
{
StringBuilder sb = new StringBuilder(200);
sb.Append("'");
if(ci.DateTimeFormat.FirstDayOfWeek == DayOfWeek.Sunday)
{
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Sunday));
sb.Append("','");
}
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Monday));
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Tuesday));
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Wednesday));
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Thursday));
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Friday));
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Saturday));
if(ci.DateTimeFormat.FirstDayOfWeek != DayOfWeek.Sunday)
{
sb.Append("','");
sb.Append(ci.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Sunday));
}
sb.Append("'");
return sb.ToString();
}
private static string padZero(int num)
{
return (num < 10)? "0" + num.ToString() : num.ToString();
}
private static string constructDate(string p_DateFormat ,DateTime date, CultureInfo ci)
{
StringBuilder sTmp = new StringBuilder(p_DateFormat);
sTmp.Replace("dd","<e>");
sTmp.Replace("d","<d>");
sTmp.Replace("<e>",date.Day.ToString());
sTmp.Replace("<d>",date.Day.ToString());
sTmp.Replace("mmmm","<o>");
sTmp.Replace("mmm","<L>");
sTmp.Replace("mm","<n>");
sTmp.Replace("m","<m>");
sTmp.Replace("<L>", ci.DateTimeFormat.GetAbbreviatedMonthName(date.Month));
sTmp.Replace("<m>",date.Month.ToString());
sTmp.Replace("<n>",padZero(date.Month));
sTmp.Replace("<o>", ci.DateTimeFormat.MonthNames[date.Month]);
sTmp.Replace("yyyy", date.Year.ToString());
return sTmp.ToString();
}
private void placeJavascript()
{
if(Page.IsClientScriptBlockRegistered("iX.Controls.DataTimePicker"))
return;
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
//CultureInfo ci = new CultureInfo("ro-RO");
StringBuilder sb = new StringBuilder(10000);
sb.Append("<script language=JavaScript>");
sb.Append("// written by Tan Ling Wee on 2 Dec 2001\n");
sb.Append("// last updated 23 June 2002\n");
sb.Append("// email : fuushikaden@yahoo.com\n\n");
sb.Append("var fixedX = -1 // x position (-1 if to appear below control)\n");
sb.Append("var fixedY = -1 // y position (-1 if to appear below control)\n");
sb.Append("var startAt = "+GetFirstDayOfWeek(ci)+" // 0 - sunday ; 1 - monday\n");
sb.Append("var showWeekNumber = 1 // 0 - don't show; 1 - show\n");
sb.Append("var showToday = 1 // 0 - don't show; 1 - show\n");
sb.Append(@"var imgDir = """ + m_imgDirectory + @"""" + "\n");
sb.Append(@"var gotoString = '" + m_gotoString + "'\n");
sb.Append(@"var todayString = '" + m_todayString + "'\n");
sb.Append(@"var weekString = '" + m_weekString + "'\n");
sb.Append("var scrollLeftMessage = '" + m_scrollLeftMessage + "'\n");
sb.Append(@"var scrollRightMessage = '" + m_scrollRightMessage + "'\n");
sb.Append(@"var selectMonthMessage = '" + m_selectMonthMessage + "'\n");
sb.Append(@"var selectYearMessage = '" + m_selectYearMessage + "'\n");
sb.Append(@"var selectDateMessage = '" + m_selectDateMessagePrefix + "[date]"+m_selectDateMessageSuffix + "' // do not replace [date], it will be replaced by date." + "\n");
sb.Append("var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlToPlaceRealValue, ctlNow, dateFormat, nStartingYear\n\n");
sb.Append("var bPageLoaded=false\n");
sb.Append("var ie=document.all\n");
sb.Append("var dom=document.getElementById\n\n");
sb.Append("var ns4=document.layers\n");
sb.Append("var today = new Date()\n");
sb.Append("var dateNow = today.getDate()\n");
sb.Append("var monthNow = today.getMonth()\n");
sb.Append("var yearNow = today.getYear()\n");
sb.Append(@"var imgsrc = new Array(""" + m_drop1Gif + @""",""" + m_drop2Gif + @""",""" + m_left1Gif + @""",""" + m_left2Gif + @""",""" + m_right1Gif + @""",""" + m_right2Gif + @""")" + "\n");
sb.Append("var img = new Array()\n\n");
sb.Append("var bShow = false;\n\n");
sb.Append("/* hides <select> and <applet> objects (for IE only) */\n");
sb.Append("function hideElement( elmID, overDiv )\n");
sb.Append("{\n");
sb.Append("if( ie )\n");
sb.Append("{\n");
sb.Append("for( i = 0; i < document.all.tags( elmID ).length; i++ )\n");
sb.Append("{\n");
sb.Append("obj = document.all.tags( elmID )[i];\n");
sb.Append("if( !obj || !obj.offsetParent )\n");
sb.Append("{\n");
sb.Append("continue;\n");
sb.Append("}\n\n");
sb.Append("// Find the element's offsetTop and offsetLeft relative to the BODY tag.\n");
sb.Append("objLeft = obj.offsetLeft;\n");
sb.Append("objTop = obj.offsetTop;\n");
sb.Append("objParent = obj.offsetParent;\n\n");
sb.Append(@"while( objParent.tagName.toUpperCase() != ""BODY"" )" + "\n");
sb.Append("{\n");
sb.Append("objLeft += objParent.offsetLeft;\n");
sb.Append("objTop += objParent.offsetTop;\n");
sb.Append("objParent = objParent.offsetParent;\n");
sb.Append("}\n\n");
sb.Append("objHeight = obj.offsetHeight;\n");
sb.Append("objWidth = obj.offsetWidth;\n\n");
sb.Append("if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );\n");
sb.Append("else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );\n");
sb.Append("else if( overDiv.offsetTop >= ( objTop + objHeight ));\n");
sb.Append("else if( overDiv.offsetLeft >= ( objLeft + objWidth ));\n");
sb.Append("else\n");
sb.Append("{\n");
sb.Append(@"obj.style.visibility = ""hidden"";" + "\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("/*\n");
sb.Append("* unhides <select> and <applet> objects (for IE only)\n");
sb.Append("*/\n");
sb.Append("function showElement( elmID )\n");
sb.Append("{\n");
sb.Append("if( ie )\n");
sb.Append("{\n");
sb.Append("for( i = 0; i < document.all.tags( elmID ).length; i++ )\n");
sb.Append("{\n");
sb.Append("obj = document.all.tags( elmID )[i];\n\n");
sb.Append("if( !obj || !obj.offsetParent )\n");
sb.Append("{\n");
sb.Append("continue;\n");
sb.Append("}\n\n");
sb.Append(@"obj.style.visibility = """";" + "\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("function HolidayRec (d, m, y, desc)\n");
sb.Append("{\n");
sb.Append("this.d = d\n");
sb.Append("this.m = m\n");
sb.Append("this.y = y\n");
sb.Append("this.desc = desc\n");
sb.Append("}\n\n");
sb.Append("var HolidaysCounter = 0\n");
sb.Append("var Holidays = new Array()\n\n");
sb.Append("function addHoliday (d, m, y, desc)\n");
sb.Append("{\n");
sb.Append("Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )\n");
sb.Append("}\n\n");
sb.Append("if (dom)\n");
sb.Append("{\n");
sb.Append("for (i=0;i<imgsrc.length;i++)\n");
sb.Append("{\n");
sb.Append("img[i] = new Image\n");
sb.Append("img[i].src = imgDir + imgsrc[i]\n");
sb.Append("}\n");
sb.Append(@"document.write (""<div onclick='bShow=true' id='calendar' style='z-index:+999;position:absolute;visibility:hidden;'><table width=""+((showWeekNumber==1)?250:220)+"" style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:11px}' bgcolor='#ffffff'><tr bgcolor='#0000aa'><td><table width='""+((showWeekNumber==1)?248:218)+""'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='""+imgDir+""" + m_closeGif + @"' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content'></span></td></tr>"")" + "\n\n");
sb.Append("if (showToday==1)\n");
sb.Append("{\n");
sb.Append(@"document.write (""<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>"")" + "\n");
sb.Append("}\n\n");
sb.Append(@"document.write (""</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>"");" + "\n");
sb.Append("}\n\n");
sb.Append("var AbreviatedmonthName = new Array("+GetAbreviatedMonths(ci)+")" + "\n");
sb.Append("var monthName = new Array("+GetMonths(ci)+")" + "\n");
sb.Append("var dayName = new Array ("+GetAbreviatedWeekDays(ci)+")" + "\n");
sb.Append(@"var styleAnchor=""text-decoration:none;color:black;""" + "\n");
sb.Append(@"var styleLightBorder=""border-style:solid;border-width:1px;border-color:#a0a0a0;""" + "\n\n");
sb.Append("function swapImage(srcImg, destImg){\n");
sb.Append(@"if (ie) { document.getElementById(srcImg).setAttribute(""src"",imgDir + destImg) }" + "\n");
sb.Append("}\n\n");
sb.Append("function init() {\n");
sb.Append("if (!ns4)\n");
sb.Append("{\n");
sb.Append("if (!ie) { yearNow += 1900 }\n\n");
sb.Append(@"crossobj=(dom)?document.getElementById(""calendar"").style : ie? document.all.calendar : document.calendar" + "\n");
sb.Append("hideCalendar()\n\n");
sb.Append(@"crossMonthObj=(dom)?document.getElementById(""selectMonth"").style : ie? document.all.selectMonth : document.selectMonth" + "\n\n");
sb.Append(@"crossYearObj=(dom)?document.getElementById(""selectYear"").style : ie? document.all.selectYear : document.selectYear" + "\n\n");
sb.Append("monthConstructed=false;\n");
sb.Append("yearConstructed=false;\n\n");
sb.Append("if (showToday==1)\n");
sb.Append("{\n");
sb.Append(@"document.getElementById(""lblToday"").innerHTML = todayString + "" <a onmousemove='window.status=\""""+gotoString+""\""' onmouseout='window.status=\""\""' title='""+gotoString+""' style='""+styleAnchor+""' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>""+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+"", "" + dateNow + "" "" + monthName[monthNow].substring(0,3) + "" "" + yearNow + ""</a>""" + "\n");
sb.Append("}\n\n");
sb.Append(@"sHTML1=""<span id='spanLeft' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\""changeLeft\"",\""left2.gif\"");this.style.borderColor=\""#88AAFF\"";window.status=\""""+scrollLeftMessage+""\""' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\""changeLeft\"",\""left1.gif\"");this.style.borderColor=\""#3366FF\"";window.status=\""\""' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\""StartDecMonth()\"",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeLeft' SRC='""+imgDir+""left1.gif' width=10 height=11 BORDER=0> </span> """ + "\n");
sb.Append(@"sHTML1+=""<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\""changeRight\"",\""right2.gif\"");this.style.borderColor=\""#88AAFF\"";window.status=\""""+scrollRightMessage+""\""' onmouseout='clearInterval(intervalID1);swapImage(\""changeRight\"",\""right1.gif\"");this.style.borderColor=\""#3366FF\"";window.status=\""\""' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\""StartIncMonth()\"",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeRight' SRC='""+imgDir+""right1.gif' width=10 height=11 BORDER=0> </span> """ + "\n");
sb.Append(@"sHTML1+=""<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\""changeMonth\"",\""drop2.gif\"");this.style.borderColor=\""#88AAFF\"";window.status=\""""+selectMonthMessage+""\""' onmouseout='swapImage(\""changeMonth\"",\""drop1.gif\"");this.style.borderColor=\""#3366FF\"";window.status=\""\""' onclick='popUpMonth()'></span> """ + "\n");
sb.Append(@"sHTML1+=""<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\""changeYear\"",\""drop2.gif\"");this.style.borderColor=\""#88AAFF\"";window.status=\""""+selectYearMessage+""\""' onmouseout='swapImage(\""changeYear\"",\""drop1.gif\"");this.style.borderColor=\""#3366FF\"";window.status=\""\""' onclick='popUpYear()'></span> """ + "\n\n");
sb.Append(@"document.getElementById(""caption"").innerHTML = sHTML1" + "\n\n");
sb.Append("bPageLoaded=true\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("function hideCalendar() {\n");
sb.Append(@"crossobj.visibility=""hidden""" + "\n");
sb.Append(@"if (crossMonthObj != null){crossMonthObj.visibility=""hidden""}" + "\n");
sb.Append(@"if (crossYearObj != null){crossYearObj.visibility=""hidden""}" + "\n\n");
sb.Append("showElement( 'SELECT' );\n");
sb.Append("showElement( 'APPLET' );\n");
sb.Append("}\n\n");
sb.Append("function padZero(num) {\n");
sb.Append("return (num < 10)? '0' + num : num ;\n");
sb.Append("}\n\n");
sb.Append("function constructDate(d,m,y)\n");
sb.Append("{\n");
sb.Append("sTmp = dateFormat\n");
sb.Append(@"sTmp = sTmp.replace (""dd"",""<e>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""d"",""<d>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<e>"",padZero(d))" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<d>"",d)" + "\n");
sb.Append(@"sTmp = sTmp.replace (""mmmm"",""<o>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""mmm"",""<L>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""mm"",""<n>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""m"",""<m>"")" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<m>"",m+1)" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<n>"",padZero(m+1))" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<o>"",monthName[m])" + "\n");
sb.Append(@"sTmp = sTmp.replace (""<L>"",AbreviatedmonthName[m])" + "\n");
sb.Append(@"return sTmp.replace (""yyyy"",y)" + "\n");
sb.Append("}\n\n");
sb.Append("function closeCalendar() {\n");
sb.Append("var sTmp\n\n");
sb.Append("hideCalendar();\n");
sb.Append("ctlToPlaceRealValue.value = dateSelected +'/'+ monthSelected+'/'+yearSelected \n");
sb.Append("ctlToPlaceValue.value = constructDate(dateSelected,monthSelected,yearSelected)\n");
sb.Append("}\n\n");
sb.Append("/*** Month Pulldown ***/\n\n");
sb.Append("function StartDecMonth()\n");
sb.Append("{\n");
sb.Append(@"intervalID1=setInterval(""decMonth()"",80)" + "\n");
sb.Append("}\n\n");
sb.Append("function StartIncMonth()\n");
sb.Append("{\n");
sb.Append(@"intervalID1=setInterval(""incMonth()"",80)" + "\n");
sb.Append("}\n\n");
sb.Append("function incMonth () {\n");
sb.Append("monthSelected++\n");
sb.Append("if (monthSelected>11) {\n");
sb.Append("monthSelected=0\n");
sb.Append("yearSelected++\n");
sb.Append("}\n");
sb.Append("constructCalendar()\n");
sb.Append("}\n\n");
sb.Append("function decMonth () {\n");
sb.Append("monthSelected--\n");
sb.Append("if (monthSelected<0) {\n");
sb.Append("monthSelected=11\n");
sb.Append("yearSelected--\n");
sb.Append("}\n");
sb.Append("constructCalendar()\n");
sb.Append("}\n\n");
sb.Append("function constructMonth() {\n");
sb.Append("popDownYear()\n");
sb.Append("if (!monthConstructed) {\n");
sb.Append(@"sHTML = """"" + "\n");
sb.Append("for (i=0; i<12; i++) {\n");
sb.Append("sName = monthName[i];\n");
sb.Append("if (i==monthSelected){\n");
sb.Append(@"sName = ""<B>"" + sName + ""</B>""" + "\n");
sb.Append("}\n");
sb.Append(@"sHTML += ""<tr><td id='m"" + i + ""' onmouseover='this.style.backgroundColor=\""#FFCC99\""' onmouseout='this.style.backgroundColor=\""\""' style='cursor:pointer' onclick='monthConstructed=false;monthSelected="" + i + "";constructCalendar();popDownMonth();event.cancelBubble=true'> "" + sName + "" </td></tr>""" + "\n");
sb.Append("}\n\n");
sb.Append(@"document.getElementById(""selectMonth"").innerHTML = ""<table width=70 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(timeoutID1)' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\""popDownMonth()\"",100);event.cancelBubble=true'>"" + sHTML + ""</table>""" + "\n\n");
sb.Append("monthConstructed=true\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("function popUpMonth() {\n");
sb.Append("constructMonth()\n");
sb.Append(@"crossMonthObj.visibility = (dom||ie)? ""visible"" : ""show""" + "\n");
sb.Append("crossMonthObj.left = parseInt(crossobj.left) + 50\n");
sb.Append("crossMonthObj.top = parseInt(crossobj.top) + 26\n\n");
sb.Append(@"hideElement( 'SELECT', document.getElementById(""selectMonth"") );" + "\n");
sb.Append(@"hideElement( 'APPLET', document.getElementById(""selectMonth"") );" + "\n");
sb.Append("}\n\n");
sb.Append("function popDownMonth() {\n");
sb.Append(@"crossMonthObj.visibility= ""hidden""" + "\n");
sb.Append("}\n\n");
sb.Append("/*** Year Pulldown ***/\n\n");
sb.Append("function incYear() {\n");
sb.Append("for (i=0; i<7; i++){\n");
sb.Append("newYear = (i+nStartingYear)+1\n");
sb.Append("if (newYear==yearSelected)\n");
sb.Append(@"{ txtYear = "" <B>"" + newYear + ""</B> "" }" + "\n");
sb.Append("else\n");
sb.Append(@"{ txtYear = "" "" + newYear + "" "" }" + "\n");
sb.Append(@"document.getElementById(""y""+i).innerHTML = txtYear" + "\n");
sb.Append("}\n");
sb.Append("nStartingYear ++;\n");
sb.Append("bShow=true\n");
sb.Append("}\n\n");
sb.Append("function decYear() {\n");
sb.Append("for (i=0; i<7; i++){\n");
sb.Append("newYear = (i+nStartingYear)-1\n");
sb.Append("if (newYear==yearSelected)\n");
sb.Append(@"{ txtYear = "" <B>"" + newYear + ""</B> "" }" + "\n");
sb.Append("else\n");
sb.Append(@"{ txtYear = "" "" + newYear + "" "" }" + "\n");
sb.Append(@"document.getElementById(""y""+i).innerHTML = txtYear" + "\n");
sb.Append("}\n");
sb.Append("nStartingYear --;\n");
sb.Append("bShow=true\n");
sb.Append("}\n\n");
sb.Append("function selectYear(nYear) {\n");
sb.Append("yearSelected=parseInt(nYear+nStartingYear);\n");
sb.Append("yearConstructed=false;\n");
sb.Append("constructCalendar();\n");
sb.Append("popDownYear();\n");
sb.Append("}\n\n");
sb.Append("function constructYear() {\n");
sb.Append("popDownMonth()\n");
sb.Append(@"sHTML = """"" + "\n");
sb.Append("if (!yearConstructed) {\n\n");
sb.Append(@"sHTML = ""<tr><td align='center' onmouseover='this.style.backgroundColor=\""#FFCC99\""' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\""\""' style='cursor:pointer' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\""decYear()\"",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>""" + "\n\n");
sb.Append("j = 0\n");
sb.Append("nStartingYear = yearSelected-3\n");
sb.Append("for (i=(yearSelected-3); i<=(yearSelected+3); i++) {\n");
sb.Append("sName = i;\n");
sb.Append("if (i==yearSelected){\n");
sb.Append(@"sName = ""<B>"" + sName + ""</B>""" + "\n");
sb.Append("}\n\n");
sb.Append(@"sHTML += ""<tr><td id='y"" + j + ""' onmouseover='this.style.backgroundColor=\""#FFCC99\""' onmouseout='this.style.backgroundColor=\""\""' style='cursor:pointer' onclick='selectYear(""+j+"");event.cancelBubble=true'> "" + sName + "" </td></tr>""" + "\n");
sb.Append("j ++;\n");
sb.Append("}\n\n");
sb.Append(@"sHTML += ""<tr><td align='center' onmouseover='this.style.backgroundColor=\""#FFCC99\""' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\""\""' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\""incYear()\"",30)' onmouseup='clearInterval(intervalID2)'>+</td></tr>""" + "\n\n");
sb.Append(@"document.getElementById(""selectYear"").innerHTML = ""<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\""popDownYear()\"",100)' cellspacing=0>"" + sHTML + ""</table>""" + "\n\n");
sb.Append("yearConstructed = true\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("function popDownYear() {\n");
sb.Append("clearInterval(intervalID1)\n");
sb.Append("clearTimeout(timeoutID1)\n");
sb.Append("clearInterval(intervalID2)\n");
sb.Append("clearTimeout(timeoutID2)\n");
sb.Append(@"crossYearObj.visibility= ""hidden""" + "\n");
sb.Append("}\n\n");
sb.Append("function popUpYear() {\n");
sb.Append("var leftOffset\n\n");
sb.Append("constructYear()\n");
sb.Append(@"crossYearObj.visibility = (dom||ie)? ""visible"" : ""show""" + "\n");
sb.Append(@"leftOffset = parseInt(crossobj.left) + document.getElementById(""spanYear"").offsetLeft" + "\n");
sb.Append("if (ie)\n");
sb.Append("{\n");
sb.Append("leftOffset += 6\n");
sb.Append("}\n");
sb.Append("crossYearObj.left = leftOffset\n");
sb.Append("crossYearObj.top = parseInt(crossobj.top) + 26\n");
sb.Append("}\n\n");
sb.Append("/*** calendar ***/\n");
sb.Append("function WeekNbr(n) {\n");
sb.Append("// Algorithm used:\n");
sb.Append("// From Klaus Tondering's Calendar document (The Authority/Guru)\n");
sb.Append("// hhtp://www.tondering.dk/claus/calendar.html\n");
sb.Append("// a = (14-month) / 12\n");
sb.Append("// y = year + 4800 - a\n");
sb.Append("// m = month + 12a - 3\n");
sb.Append("// J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045\n");
sb.Append("// d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461\n");
sb.Append("// L = d4 / 1460\n");
sb.Append("// d1 = ((d4 - L) mod 365) + L\n");
sb.Append("// WeekNumber = d1 / 7 + 1\n\n");
sb.Append("year = n.getFullYear();\n");
sb.Append("month = n.getMonth() + 1;\n");
sb.Append("if (startAt == 0) {\n");
sb.Append("day = n.getDate() + 1;\n");
sb.Append("}\n");
sb.Append("else {\n");
sb.Append("day = n.getDate();\n");
sb.Append("}\n\n");
sb.Append("a = Math.floor((14-month) / 12);\n");
sb.Append("y = year + 4800 - a;\n");
sb.Append("m = month + 12 * a - 3;\n");
sb.Append("b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);\n");
sb.Append("J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;\n");
sb.Append("d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;\n");
sb.Append("L = Math.floor(d4 / 1460);\n");
sb.Append("d1 = ((d4 - L) % 365) + L;\n");
sb.Append("week = Math.floor(d1/7) + 1;\n\n");
sb.Append("return week;\n");
sb.Append("}\n\n");
sb.Append("function constructCalendar () {\n");
sb.Append("var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)\n\n");
sb.Append("var dateMessage\n");
sb.Append("var startDate = new Date (yearSelected,monthSelected,1)\n");
sb.Append("var endDate\n\n");
sb.Append("if (monthSelected==1)\n");
sb.Append("{\n");
sb.Append("endDate = new Date (yearSelected,monthSelected+1,1);\n");
sb.Append("endDate = new Date (endDate - (24*60*60*1000));\n");
sb.Append("numDaysInMonth = endDate.getDate()\n");
sb.Append("}\n");
sb.Append("else\n");
sb.Append("{\n");
sb.Append("numDaysInMonth = aNumDays[monthSelected];\n");
sb.Append("}\n\n");
sb.Append("datePointer = 0\n");
sb.Append("dayPointer = startDate.getDay() - startAt\n\n");
sb.Append("if (dayPointer<0)\n");
sb.Append("{\n");
sb.Append("dayPointer = 6\n");
sb.Append("}\n\n");
sb.Append(@"sHTML = ""<table border=0 style='font-family:verdana;font-size:10px;'><tr>""" + "\n\n");
sb.Append("if (showWeekNumber==1)\n");
sb.Append("{\n");
sb.Append(@"sHTML += ""<td width=27><b>"" + weekString + ""</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='""+imgDir+""" + m_dividerGif + @"' width=1></td>""" + "\n");
sb.Append("}\n\n");
sb.Append("for (i=0; i<7; i++) {\n");
sb.Append(@"sHTML += ""<td width='27' align='right'><B>""+ dayName[i]+""</B></td>""" + "\n");
sb.Append("}\n");
sb.Append(@"sHTML +=""</tr><tr>""" + "\n\n");
sb.Append("if (showWeekNumber==1)\n");
sb.Append("{\n");
sb.Append(@"sHTML += ""<td align=right>"" + WeekNbr(startDate) + "" </td>""" + "\n");
sb.Append("}\n\n");
sb.Append("for ( var i=1; i<=dayPointer;i++ )\n");
sb.Append("{\n");
sb.Append(@"sHTML += ""<td> </td>""" + "\n");
sb.Append("}\n\n");
sb.Append("for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )\n");
sb.Append("{\n");
sb.Append("dayPointer++;\n");
sb.Append(@"sHTML += ""<td align=right>""" + "\n");
sb.Append("sStyle=styleAnchor\n");
sb.Append("if ((datePointer==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected))\n");
sb.Append("{ sStyle+=styleLightBorder }\n\n");
sb.Append(@"sHint = """"" + "\n");
sb.Append("for (k=0;k<HolidaysCounter;k++)\n");
sb.Append("{\n");
sb.Append("if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))\n");
sb.Append("{\n");
sb.Append("if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))\n");
sb.Append("{\n");
sb.Append(@"sStyle+=""background-color:#FFDDDD;""" + "\n");
sb.Append(@"sHint+=sHint==""""?Holidays[k].desc:""\n""+Holidays[k].desc" + "\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append(@"var regexp= /\""/g" + "\n");
sb.Append(@"sHint=sHint.replace(regexp,""""")" + "\n\n");
sb.Append(@"dateMessage = ""onmousemove='window.status=\""""+selectDateMessage.replace(""[date]"",constructDate(datePointer,monthSelected,yearSelected))+""\""' onmouseout='window.status=\""\""' """ + "\n\n");
sb.Append("if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))\n");
sb.Append(@"{ sHTML += ""<b><a ""+dateMessage+"" title=\"""" + sHint + ""\"" style='""+sStyle+""' href='javascript:dateSelected=""+datePointer+"";closeCalendar();'><font color=#ff0000> "" + datePointer + ""</font> </a></b>""}" + "\n");
sb.Append("else if (dayPointer % 7 == (startAt * -1)+1)\n");
sb.Append(@"{ sHTML += ""<a ""+dateMessage+"" title=\"""" + sHint + ""\"" style='""+sStyle+""' href='javascript:dateSelected=""+datePointer + "";closeCalendar();'> <font color=#909090>"" + datePointer + ""</font> </a>"" }" + "\n");
sb.Append("else\n");
sb.Append(@"{ sHTML += ""<a ""+dateMessage+"" title=\"""" + sHint + ""\"" style='""+sStyle+""' href='javascript:dateSelected=""+datePointer + "";closeCalendar();'> "" + datePointer + "" </a>"" }" + "\n\n");
sb.Append(@"sHTML += """"" + "\n");
sb.Append("if ((dayPointer+startAt) % 7 == startAt) {\n");
sb.Append(@"sHTML += ""</tr><tr>""" + "\n");
sb.Append("if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))\n");
sb.Append("{\n");
sb.Append(@"sHTML += ""<td align=right>"" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "" </td>""" + "\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append(@"document.getElementById(""content"").innerHTML = sHTML" + "\n");
sb.Append(@"document.getElementById(""spanMonth"").innerHTML = "" "" + monthName[monthSelected] + "" <IMG id='changeMonth' SRC='""+imgDir+""drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>""" + "\n");
sb.Append(@"document.getElementById(""spanYear"").innerHTML = "" "" + yearSelected + "" <IMG id='changeYear' SRC='""+imgDir+""drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>""" + "\n");
sb.Append("}\n\n");
sb.Append("function popUpCalendar(ctl, ctl2, ctlvalue, format, paramformatChar ) {\n");
sb.Append("var leftpos=0\n");
sb.Append("var toppos=0\n");
sb.Append("var InvalidDateFormat=0\n\n");
sb.Append("if (bPageLoaded)\n");
sb.Append("{\n");
sb.Append("formatChar = paramformatChar;\n");
sb.Append(@"if ( crossobj.visibility == ""hidden"" ) {" + "\n");
sb.Append(" ctlToPlaceValue = ctl2\n");
sb.Append(" ctlToPlaceRealValue = ctlvalue\n");
sb.Append(" dateFormat=format;\n\n");
sb.Append(" aFormat = dateFormat.split(formatChar)\n");
sb.Append(" if (aFormat.length<3)\n");
sb.Append(" {\n");
sb.Append(" // invalid date format\n");
sb.Append(" InvalidDateFormat=1; \n");
sb.Append(" }\n\n");
sb.Append("tokensChanged = 0\n");
sb.Append(@"if ( InvalidDateFormat == 0 )" + "\n");
sb.Append("{\n");
sb.Append("// use user's date\n");
sb.Append("aData = ctl2.value.split(formatChar)\n\n");
sb.Append("for (i=0;i<3;i++)\n");
sb.Append("{\n");
sb.Append(@"if ((aFormat[i]==""d"") || (aFormat[i]==""dd""))" + "\n");
sb.Append("{\n");
sb.Append("dateSelected = parseInt(aData[i], 10)\n");
sb.Append("tokensChanged ++\n");
sb.Append("}\n");
sb.Append(@"else if ((aFormat[i]==""m"") || (aFormat[i]==""mm""))" + "\n");
sb.Append("{\n");
sb.Append("monthSelected = parseInt(aData[i], 10) - 1\n");
sb.Append("tokensChanged ++\n");
sb.Append("}\n");
sb.Append(@"else if (aFormat[i]==""yyyy"")" + "\n");
sb.Append("{\n");
sb.Append("yearSelected = parseInt(aData[i], 10)\n");
sb.Append("tokensChanged ++\n");
sb.Append("}\n");
sb.Append(@"else if (aFormat[i]==""mmm"")" + "\n");
sb.Append("{\n");
sb.Append("for (j=0; j<12; j++)\n");
sb.Append("{\n");
sb.Append("if (aData[i]==monthName[j])\n");
sb.Append("{\n");
sb.Append("monthSelected=j\n");
sb.Append("tokensChanged ++\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))\n");
sb.Append("{\n");
sb.Append("dateSelected = dateNow\n");
sb.Append("monthSelected = monthNow\n");
sb.Append("yearSelected = yearNow\n");
sb.Append("}\n\n");
sb.Append("odateSelected=dateSelected\n");
sb.Append("omonthSelected=monthSelected\n");
sb.Append("oyearSelected=yearSelected\n\n");
sb.Append("aTag = ctl\n");
sb.Append("do {\n");
sb.Append("aTag = aTag.offsetParent;\n");
sb.Append("leftpos += aTag.offsetLeft;\n");
sb.Append("toppos += aTag.offsetTop;\n");
sb.Append(@"} while(aTag.tagName!=""BODY"");" + "\n\n");
sb.Append("crossobj.left = fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX\n");
sb.Append("crossobj.top = fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY\n");
sb.Append("constructCalendar (1, monthSelected, yearSelected);\n");
sb.Append(@"crossobj.visibility=(dom||ie)? ""visible"" : ""show""" + "\n\n");
sb.Append(@"hideElement( 'SELECT', document.getElementById(""calendar"") );" + "\n");
sb.Append(@"hideElement( 'APPLET', document.getElementById(""calendar"") );" + "\n\n");
sb.Append("bShow = true;\n");
sb.Append("}\n");
sb.Append("else\n");
sb.Append("{\n");
sb.Append("hideCalendar()\n");
sb.Append("if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, ctlvalue, format, formatChar)}\n");
sb.Append("}\n");
sb.Append("ctlNow = ctl\n");
sb.Append("}\n");
sb.Append("}\n\n");
sb.Append("document.onkeypress = function hidecal1 () {\n");
sb.Append("if (event.keyCode==27)\n");
sb.Append("{\n");
sb.Append("hideCalendar()\n");
sb.Append("}\n");
sb.Append("}\n");
sb.Append("document.onclick = function hidecal2 () {\n");
sb.Append("if (!bShow)\n");
sb.Append("{\n");
sb.Append("hideCalendar()\n");
sb.Append("}\n");
sb.Append("bShow = false\n");
sb.Append("}\n\n");
sb.Append("if(ie)\n");
sb.Append("{\n");
sb.Append("init()\n");
sb.Append("}\n");
sb.Append("else\n");
sb.Append("{\n");
sb.Append("window.onload=init;\n");
sb.Append("}\n");
sb.Append("<");
sb.Append("/");
sb.Append("script>");
Page.RegisterClientScriptBlock("iX.Controls.DataTimePicker", sb.ToString());
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
placeJavascript();
System.Web.UI.WebControls.TextBox txtTextBox = new TextBox();
System.Web.UI.HtmlControls.HtmlInputText hiddenPickerValue = new HtmlInputText("hidden");
if (m_ControlCssClass.Length > 0)
txtTextBox.CssClass = m_ControlCssClass;
txtTextBox.ReadOnly = true;
txtTextBox.Text = constructDate( m_DateFormat, m_value, Thread.CurrentThread.CurrentCulture);
hiddenPickerValue.Value = GetRealDateString(m_value);
if (m_Css == "")
txtTextBox.CssClass = m_Css;
hiddenPickerValue.ID="foovalue";
txtTextBox.ID = "foo";
txtTextBox.Attributes.Add("onclick", "popUpCalendar(document.all." + this.ClientID + "_foo, document.all." + this.ClientID + "_foo, document.all." + this.ClientID + "_foovalue, '" + m_DateFormat.ToLower() + "', '" + m_DateSeparator + "');");
txtTextBox.EnableViewState = false;
hiddenPickerValue.EnableViewState = false;
this.Controls.Add(txtTextBox);
this.Controls.Add(hiddenPickerValue);
}
private static string GetRealDateString(DateTime datevalue)
{
return datevalue.Day.ToString() + "/" + (datevalue.Month -1).ToString() + "/" + datevalue.Year.ToString();
}
#endregion
}
}
|