예제 #1
0
        protected override void Render(HtmlTextWriter output)
        {
            base.Render(output);
            foreach (Control c in Controls)
            {
                c.RenderControl(output);
            }

            string sScript = "<script type=\"text/javascript\">" + Environment.NewLine;

            sScript += "    Calendar.setup({" + Environment.NewLine;
            if (DisplayArea.Length > 0)
            {
                sScript += "displayArea        :    \"" + DisplayArea + "\"," + Environment.NewLine;
                sScript += "daFormat        :    \"" + GetDaFormat(OutputFormat) + "\"," + Environment.NewLine;
            }
            sScript += "ifFormat       :    \"%Y-%m-%d %H::%M::%S\"," + Environment.NewLine;
            sScript += "showsTime      :    " + ShowTime.ToString().ToLower() + ",   " + Environment.NewLine;
            sScript += "timeFormat      :    " + (Clock24Hour == true ? "24" : "12") + ",   " + Environment.NewLine;
            sScript += "weekNumbers      :    " + ShowWeekNumber.ToString().ToLower() + ",   " + Environment.NewLine;
            sScript += "button         :    \"" + m_TriggerButton.ClientID + "\"," + Environment.NewLine;
            sScript += "singleClick    :    " + SingleClick.ToString().ToLower() + "," + Environment.NewLine;
            //if ( DateTimeValue.Year > 1970  )
            //    sScript += "date    :    new Date(" + DateTimeValue.Year.ToString() + "," + (DateTimeValue.Month-1).ToString() + "," + DateTimeValue.Day.ToString() + "," + (DateTimeValue.Hour-1).ToString() + "," + DateTimeValue.Minute.ToString() + "," + DateTimeValue.Second.ToString() + ")," + Environment.NewLine;
            //else
            sScript += "inputField  : \"" + m_oField.ClientID + "\"," + Environment.NewLine;
            sScript += "onSelect         :    " + ClientID + "_onSelect," + Environment.NewLine;
            sScript += "step    :    1" + Environment.NewLine;
            sScript += "   });" + Environment.NewLine;

            sScript += "function " + ChangeHandler + "(calendar, date) {" + Environment.NewLine;
            sScript += "var input_field = document.getElementById(\"" + ClientID + "\");" + Environment.NewLine;
            sScript += "var dDat = Date.parseDate(date, '%Y-%m-%d %H::%M::%S');";
            sScript += "input_field.value = dDat.print(\"" + GetDaFormat(OutputFormat) + "\");" + Environment.NewLine;
            sScript += "input_field = document.getElementById(\"" + m_oField.ClientID + "\");" + Environment.NewLine;
            sScript += "input_field.value = date;" + Environment.NewLine;
            sScript += "};" + Environment.NewLine;
            sScript += "</script>" + Environment.NewLine;

            output.Write(sScript);
        }
예제 #2
0
        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)
            {
            }
        }