zoukankan      html  css  js  c++  java
  • DateChooser源码DateChooser.cs

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Drawing;
    using System.Reflection;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using CNBlogs.DCT.THIN.Design;

    namespace CNBlogs.DCT.THIN
    {
     [
     DefaultEvent("DateChanged"),
     DefaultProperty("SelectedDate"),
     Designer(typeof(DataChooserDesigner)),
     ValidationProperty("SelectedDateText"),
     ToolboxData("<{0}:DateChooser runat=\"server\"></{0}:DateChooser>"),
     ToolboxBitmap(typeof(DateChooser),@"DateChooser.bmp")
     ]
     public class DateChooser:WebControl, INamingContainer
     {
      #region Variable

      private TextBox _dateTextBox;
      private HtmlImage _drop;
      private HtmlImage _up;
      private HtmlImage _down;
      private Style _textStyle;
      private Style _imgStyle;
      private bool _renderClientScript = true;
      private bool _renderPopupScript = true;
      private static readonly object EventDateChanged = new object();
      private static string ClientFilesUrlPrefix;

      #endregion
      public DateChooser()
      {
      }
      
      #region Properties
      #region Override Properties
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override Color BackColor
      {
       get
       {
        return Color.Empty;
       }
       set
       {
       }
      }
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override BorderStyle BorderStyle
      {
       get
       {
        return BorderStyle.NotSet;
       }
       set
       {
       }
      }
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override Unit BorderWidth
      {
       get
       {
        return Unit.Empty;
       }
       set
       {
       }
      }
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override FontInfo Font
      {
       get
       {
        return null;
       }
      }
      
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override Color ForeColor
      {
       get
       {
        return Color.Empty;
       }
       set
       {
       }
      }
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override Unit Height
      {
       get
       {
        return Unit.Empty;
       }
       set
       {
       }
      }
      
      [
      Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),EditorBrowsable(EditorBrowsableState.Never)
      ]
      public override Unit Width
      {
       get
       {
        return Unit.Empty;
       }
       set
       {
       }
      }
      #endregion
      [NotifyParentProperty(true),
      DefaultValue(Culture.Cn),
      TypeConverter(typeof(EnumConverter)),
      Category("Behavior"),
      Description("切换日期面板及上面的提示信息使用的语言。")
      ]
      public Culture Culture
      {
       get
       {
        object o = ViewState["Culture"];
        return (o==null)?Culture.Cn:(Culture)o;
       }
       set
       {
        if(value > Culture.En || value < Culture.Cn)
         throw new ArgumentOutOfRangeException("Cn or En.");
        ViewState["Culture"] = value;
       }
      }
      [NotifyParentProperty(true),
      DefaultValue(false),
      TypeConverter(typeof(BooleanConverter)),
      Category("Behavior"),
      Description("设置是否允许空值。")
      ]
      public bool AllowNull
      {
       get
       {
        object o = ViewState["AllowNull"];
        return (o==null)?false:(bool)o;
       }
       set
       {
        ViewState["AllowNull"] = value;
       }
      }

      [NotifyParentProperty(true),
      DefaultValue(FrameContainer.Frame),
      TypeConverter(typeof(EnumConverter)),
      Category("Behavior"),
      Description("设置日期选择面板使用的载体,现行版本提供None和Frame两种选择,下一版本将提供Popup窗口支持。")
      ]
      public FrameContainer Container
      {
       get
       {
        object o = ViewState["Container"];
        return (o == null)?FrameContainer.Frame:(FrameContainer)o;
       }
       set
       {
        if(value < FrameContainer.None || value > FrameContainer.Frame)
         throw new ArgumentOutOfRangeException("None or Frame.");
        ViewState["Container"] = value;
       }
      }
      
      [
      NotifyParentProperty(true),
      Category("Behavior"),
      DefaultValue(false),
      Description("日期改变时,是否引发页面回传。设为True则用户每次在Calendar中选取日期和点击控件后面的的增减按钮将引发页面回传。")
      ]
      public bool AutoPostBack
      {
       get
       {
        EnsureChildControls();
        return _dateTextBox.AutoPostBack;
       }
       set
       {
        EnsureChildControls();
        _dateTextBox.AutoPostBack = value;
       }
      }
      public override ControlCollection Controls
      {
       get
       {
        EnsureChildControls();
        return base.Controls;
       }
      }


      [NotifyParentProperty(true),
      Category("Behavior"),
      DefaultValue(true),
      Description("是否起用日历功能,设为否则控件只生成一个Input。")
      ]
      public bool EnableClientScript
      {
       get
       {
        object b = ViewState["EnableClientScript"];
        return (b == null) ? true : (bool)b;
       }
       set
       {
        ViewState["EnableClientScript"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Behavior"),
      DefaultValue(true),
      Description("是否增减日期的小按钮。")
      ]
      public bool ShowButton
      {
       get
       {
        object b = ViewState["ShowButton"];
        return (b == null) ? true : (bool)b;
       }
       set
       {
        ViewState["ShowButton"] = value;
       }
      }
      [NotifyParentProperty(true),
      Category("Behavior"),
      DefaultValue(false),
      Description("日期是否只读。")
      ]
      public virtual bool ReadOnly
      {
       get
       {
        EnsureChildControls();
        return _dateTextBox.ReadOnly;
       }
       set
       {
        EnsureChildControls();
        _dateTextBox.ReadOnly = value;
       }
      }
      
      [
      NotifyParentProperty(true),
      Category("Behavior"),
      DefaultValue("-"),
      Description("设置日期的间隔符。"),
      TypeConverter(typeof(DateFormatSeparatorConverter))
      ]
      public string DateFormatSeparator
      {
       get
       {
        object o = ViewState["DateFormatSeparator"];
        return (o==null)?"-":o.ToString();
       }
       set
       {
        EnsureChildControls();
        ViewState["DateFormatSeparator"] = value;
        _dateTextBox.Text = _dateTextBox.Text.Replace("-","/").Replace("/",value);
       }
      }
     
      [
      NotifyParentProperty(true),
      Category("Default"),
      DefaultValue(""),
      Description("最大日期值。日期选择器只支持从1745-1-1到9998-12-31之间的日期,此范围之外的日期请手工输入。"),
      Editor(typeof(DateTimeStringEditor),typeof(System.Drawing.Design.UITypeEditor))
      ]
      public string MaxDate
      {
       get
       {
        object o = ViewState["MaxDate"];
        return (o==null)?String.Empty:o.ToString();
       }
       set
       {
        if(value.Trim() != string.Empty)
        {
         DateTime dt = DateTime.Parse(value);
         if(MinDate.Trim() != string.Empty)
         {
          DateTime dt2 = DateTime.Parse(MinDate);
          if(dt < dt2)
           throw new ArgumentException("MaxDate不能早于MinDate","MaxDate");
         }
         ViewState["MaxDate"] = dt.ToString("yyyy-MM-dd");
        }
        else
        {
         ViewState["MaxDate"] = string.Empty;
        }
       }
      }
      [
      NotifyParentProperty(true),
      Category("Default"),
      DefaultValue(""),
      Description("最小日期值。日期选择器只支持从1745-1-1到9998-12-31之间的日期,此范围之外的日期请手工输入。"),
      Editor(typeof(DateTimeStringEditor),typeof(System.Drawing.Design.UITypeEditor))
      ]
      public string MinDate
      {
       get
       {
        object o = ViewState["MinDate"];
        return (o==null)?string.Empty:o.ToString();
       }
       set
       {
        if(value.Trim() != string.Empty)
        {
         DateTime dt = DateTime.Parse((string)value);
         if(MaxDate.Trim() != string.Empty)
         {
          DateTime dt2 = DateTime.Parse(MaxDate);
          if(dt > dt2)
           throw new ArgumentException("MaxDate不能早于MinDate","MinDate");
         }
         ViewState["MinDate"] = dt.ToString("yyyy-MM-dd");
        }
        else
        {
         ViewState["MinDate"] = string.Empty;
        }
       }
      }

      [NotifyParentProperty(true),
      DefaultValue(RevealTransitionType.None),
      Category("Behavior"),
      Editor(typeof(RevealTransitionEditor),typeof(System.Drawing.Design.UITypeEditor)),
      Description("下拉Calendar弹出时使用的效果。")
      ]
      public RevealTransitionType TransitionType
      {
       get
       {
        object b = ViewState["TransitionType"];
        return (b==null)?RevealTransitionType.RandomTransition:(RevealTransitionType)b;
       }
       set
       {
        if(value < RevealTransitionType.BoxIn || value > RevealTransitionType.None)
        {
         throw new ArgumentOutOfRangeException("TransitionType");
        }
        ViewState["TransitionType"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      DefaultValue(0.2),
      TypeConverter(typeof(DoubleConverter)),
      Category("Behavior"),
      Description("弹出效果的完成时间,单位为秒。")
      ]
      public double Duration
      {
       get
       {
        object b = ViewState["Duration"];
        return (b==null)?0.2:(double)b;
       }
       set
       {
        if(value > 2)
        {
         throw new ArgumentOutOfRangeException("时间不能设得太长。");
        }
        ViewState["Duration"] = value;
       }
      }


      [
      NotifyParentProperty(true),
      Browsable(false),
      DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
      ]
      public virtual bool IsDateSelected
      {
       get
       {
        object d = ViewState["SelectedDate"];
        return (d != null);
       }
      }

      
      [
      NotifyParentProperty(true),
      Bindable(true),
      Category("Default"),
      Editor(typeof(DateTimeStringEditor),typeof(System.Drawing.Design.UITypeEditor)),
      Description("设置当前选择的日期。日期选择器只支持从1745-1-1到9998-12-31之间的日期,此范围之外的日期请手工输入。")
      ]
      public virtual string SelectedDate
      {
       get
       {
        object d = ViewState["SelectedDate"];
        return (d == null) ? string.Empty : d.ToString();
        
       }
       set
       {

        EnsureChildControls();
        if(value.Trim() != string.Empty)
        {
         DateTime dt = DateTime.Parse(value);
         ViewState["SelectedDate"] = value;
         _dateTextBox.Text = DateToString(dt);
        }
        else
        {
         ViewState["SelectedDate"] = value;
         _dateTextBox.Text = string.Empty;
        }

       }
      }
      #region Appearence

      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#DCEDFD"),
      TypeConverter(typeof(WebColorConverter)),
      Description("亮色,应用于面板背景等处。")
      ]
      public Color LightColor
      {
       get
       {
        object o = ViewState["LightColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#DCEDFD"))):(Color)o;
       }
       set
       {
        ViewState["LightColor"] = value;
       }
      }

      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#C5D5FC"),
      TypeConverter(typeof(WebColorConverter)),
      Description("主色,应用于按钮背景等处。")
      ]
      public Color MidColor
      {
       get
       {
        object o = ViewState["MidColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#C5D5FC"))):(Color)o;
       }
       set
       {
        ViewState["MidColor"] = value;
       }
      }
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#83A6F4"),
      TypeConverter(typeof(WebColorConverter)),
      Description("深色,应用于选择面板上按钮背景等处。")
      ]
      public Color DarkColor
      {
       get
       {
        object o = ViewState["DarkColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#83A6F4"))):(Color)o;
       }
       set
       {
        ViewState["DarkColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#ABC1F4"),
      TypeConverter(typeof(WebColorConverter)),
      Description("主色,应用于边框等处。")
      ]
      public override Color BorderColor
      {
       get
       {
        object o = ViewState["BorderColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#ABC1F4"))):(Color)o;
       }
       set
       {
        ViewState["BorderColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#ff9900"),
      TypeConverter(typeof(WebColorConverter)),
      Description("应用于鼠标Over。")
      ]
      public Color OverColor
      {
       get
       {
        object o = ViewState["OverColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#ff9900"))):(Color)o;
       }
       set
       {
        ViewState["OverColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"Pink"),
      TypeConverter(typeof(WebColorConverter)),
      Description("出错时输入框背景色。")
      ]
      public Color WrongBackColor
      {
       get
       {
        object o = ViewState["WrongBackColor"];
        return (o==null)?(Color.Pink):(Color)o;
       }
       set
       {
        ViewState["WrongBackColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"Red"),
      TypeConverter(typeof(WebColorConverter)),
      Description("错误时输入框的前景色。")
      ]
      public Color WrongForeColor
      {
       get
       {
        object o = ViewState["WrongForeColor"];
        return (o==null)?(Color.Red):(Color)o;
       }
       set
       {
        ViewState["WrongForeColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#FF9900"),
      TypeConverter(typeof(WebColorConverter)),
      Description("当前选择日期背景色。")
      ]
      public Color CurrentBackColor
      {
       get
       {
        object o = ViewState["CurrentBackColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#FF9900"))):(Color)o;
       }
       set
       {
        ViewState["CurrentBackColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"White"),
      TypeConverter(typeof(WebColorConverter)),
      Description("当前选择日期前景色。")
      ]
      public Color CurrentForeColor
      {
       get
       {
        object o = ViewState["CurrentForeColor"];
        return (o==null)?(Color.White):(Color)o;
       }
       set
       {
        ViewState["CurrentForeColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#0066FF"),
      TypeConverter(typeof(WebColorConverter)),
      Description("今天背景色。")
      ]
      public Color TodayBackColor
      {
       get
       {
        object o = ViewState["TodayBackColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#0066FF"))):(Color)o;
       }
       set
       {
        ViewState["TodayBackColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"White"),
      TypeConverter(typeof(WebColorConverter)),
      Description("今天前景色。")
      ]
      public Color TodayForeColor
      {
       get
       {
        object o = ViewState["TodayForeColor"];
        return (o==null)?(Color.White):(Color)o;
       }
       set
       {
        ViewState["TodayForeColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),""),
      TypeConverter(typeof(WebColorConverter)),
      Description("相邻月的背景色。")
      ]
      public Color OtherBackColor
      {
       get
       {
        object o = ViewState["OtherBackColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString(""))):(Color)o;
       }
       set
       {
        ViewState["OtherBackColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"#606060"),
      TypeConverter(typeof(WebColorConverter)),
      Description("相邻月日期的前景色。")
      ]
      public Color OtherForeColor
      {
       get
       {
        object o = ViewState["OtherForeColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString("#606060"))):(Color)o;
       }
       set
       {
        ViewState["OtherForeColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),""),
      TypeConverter(typeof(WebColorConverter)),
      Description("当前月背景色。")
      ]
      public Color MonthBackColor
      {
       get
       {
        object o = ViewState["MonthBackColor"];
        return (o==null)?((Color)(new WebColorConverter().ConvertFromString(""))):(Color)o;
       }
       set
       {
        ViewState["MonthBackColor"] = value;
       }
      }
      
      [NotifyParentProperty(true),
      Category("Appearence"),
      DefaultValue(typeof(Color),"MediumBlue"),
      TypeConverter(typeof(WebColorConverter)),
      Description("当前月前景色。")
      ]
      public Color MonthForeColor
      {
       get
       {
        object o = ViewState["MonthForeColor"];
        return (o==null)?(Color.MediumBlue):(Color)o;
       }
       set
       {
        ViewState["MonthForeColor"] = value;
       }
      }
      #endregion

      #endregion

      #region Method
      [EditorBrowsable(EditorBrowsableState.Never)]
      public string DateToString(DateTime dt)
      {
       string v;
       try
       {
        v= dt.ToString("yyyy-MM-dd");
       }
       catch
       {
        v =String.Empty;
       }
       return v.Replace("-",this.DateFormatSeparator);
      }
      [EditorBrowsable(EditorBrowsableState.Never)]
      private string ConvertColorToString(Color c)
      {
       WebColorConverter wc = new WebColorConverter();
       return wc.ConvertToString(c);
      }
      [EditorBrowsable(EditorBrowsableState.Never)]
      public string CCS(Color c)
      {
       return ConvertColorToString(c);
      }
      protected override void CreateChildControls()
      {
       //Controls.Clear();
       _dateTextBox = new TextBox();
       _dateTextBox.EnableViewState = true;
       _dateTextBox.TextChanged += new EventHandler(this.dateTextBox_TextChanged);
       _dateTextBox.ID = "DateInput";
       Controls.Add(_dateTextBox);

      }

      private void dateTextBox_TextChanged(object sender, EventArgs e)
      {
       // Handles the TextChanged event of the contained TextBox.
       EnsureChildControls();
       try
       {
        string date = _dateTextBox.Text.Trim();

        // Determine if the selected date has changed.
        if ((IsDateSelected == false) || !(date==SelectedDate))
        {
         SelectedDate = date;
         OnDateChanged(EventArgs.Empty);
        }
       }
       catch
       {
       }
      }

      private void DetermineClientScriptLevel()
      {
       _renderClientScript = false;
       _renderPopupScript = false;

       if ((Page != null) && (Page.Request != null))
       {
        if (EnableClientScript)
        {
         HttpBrowserCapabilities browserCaps = Page.Request.Browser;
         bool hasEcmaScript = (browserCaps.EcmaScriptVersion.CompareTo(new Version(1, 2)) >= 0);
         bool hasDOM = (browserCaps.MSDomVersion.Major >= 4);
         //bool hasBehaviors = (browserCaps.MajorVersion > 5) ||
         // ((browserCaps.MajorVersion == 5) && (browserCaps.MinorVersion >= .5));
         bool hasBehaviors = browserCaps.MajorVersion >= 5 ;
         _renderClientScript = hasEcmaScript && hasDOM;
         _renderPopupScript = _renderClientScript && hasBehaviors;
        }
       }
      }

      private string GetClientFileUrl(string fileName)
      {
       if (ClientFilesUrlPrefix == null)
       {
        // Use the config setting to determine where the client files are located.
        // Client files are located in the aspnet_client v-root and then distributed
        // into subfolders by assembly name and assembly version.
        string location = null;
        if (Context != null)
        {
         IDictionary configData = (IDictionary)Context.GetConfig("system.web/webControls");
         if (configData != null)
         {
          location = (string)configData["clientScriptsLocation"];
         }
        }

        if (location == null)
        {
         location = "/aspnet_client/CNBlogs_DCT/thin/";
        }
        else if (location.IndexOf("{0}") >= 0)
        {
         //AssemblyName assemblyName = GetType().Assembly.GetName();

         string assembly = "CNBlogs_DCT";//assemblyName.Name.Replace('.', '_').ToLower();
         string version =  "thin";//assemblyName.Version.ToString().Replace('.', '_');

         location = String.Format(location, assembly, version);
        }

        ClientFilesUrlPrefix = location;
       }
       return ClientFilesUrlPrefix + fileName;
      }

      protected override void Render(HtmlTextWriter writer)
      {
       if (Page != null)
       {
        Page.VerifyRenderingInServerForm(this);
       }
       if(_renderPopupScript||(Site!=null&&Site.DesignMode))
       {
        //Table
        AddAttributesToRender(writer);
        writer.AddStyleAttribute("Behavior","url('"+GetClientFileUrl("DateChooser.HTC")+"')");
        //writer.AddAttribute(HtmlTextWriterAttribute.Background,"White");//_tblStyle.BackColor = Color.White;
        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle,"solid");//_tblStyle.BorderWidth = new Unit(1);
        
        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth,"1px");//.CellPadding = 1;
        writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,"0");//_tblStyle.CellSpacing = 0;
        writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing,"1");
        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor,CCS(BorderColor));//_tblStyle.BorderColor = BorderColor;
        if(ControlStyleCreated)
        {
         if(ControlStyle.CssClass != null && ControlStyle.CssClass != string.Empty)
          writer.AddAttribute(HtmlTextWriterAttribute.Class,ControlStyle.CssClass);
        }
        writer.AddAttribute(HtmlTextWriterAttribute.Bordercolor,CCS(BorderColor));
       
        writer.AddAttribute("Container",Container.ToString());
        writer.AddAttribute("LightColor",CCS(LightColor));
        writer.AddAttribute("MidColor",CCS(MidColor));
        writer.AddAttribute("DarkColor",CCS(DarkColor));
        writer.AddAttribute("BorderColors",CCS(BorderColor));
        writer.AddAttribute("OverColor",CCS(OverColor));
        writer.AddAttribute("WrongBackColor",CCS(WrongBackColor));
        writer.AddAttribute("WrongForeColor",CCS(WrongForeColor));
        writer.AddAttribute("CurrentBackColor",CCS(CurrentBackColor));
        writer.AddAttribute("CurrentForeColor",CCS(CurrentForeColor));
        writer.AddAttribute("TodayBackColor",CCS(TodayBackColor));
        writer.AddAttribute("TodayForeColor",CCS(TodayForeColor));
        writer.AddAttribute("OtherBackColor",CCS(OtherBackColor));
        writer.AddAttribute("OtherForeColor",CCS(OtherForeColor));
        writer.AddAttribute("MonthBackColor",CCS(MonthBackColor));
        writer.AddAttribute("MonthForeColor",CCS(MonthForeColor));
        writer.AddAttribute("Culture",Culture.ToString());
        writer.AddAttribute("AllowNull",AllowNull.ToString());
        writer.AddAttribute("ReadOnly",ReadOnly.ToString());
        writer.AddAttribute("DateFormatSeparator",DateFormatSeparator);
        if(MaxDate != string.Empty)
         writer.AddAttribute("MaxDate",MaxDate);
        ////else
         //writer.AddAttribute("MaxDate","9998-12-31");
        if(MinDate != string.Empty)
        writer.AddAttribute("MinDate",MinDate);
        //else
         //writer.AddAttribute("MinDate","0001-01-01");
        writer.AddAttribute("RevealTransitType",((int)TransitionType).ToString());
        writer.AddAttribute("RevealTransitDuration",Duration.ToString());
        if(_dateTextBox.Text.Trim()!=string.Empty)
        writer.AddAttribute("OrgValue",_dateTextBox.Text.Trim());
        writer.RenderBeginTag(HtmlTextWriterTag.Table);
        writer.RenderBeginTag(HtmlTextWriterTag.Tr);
        

        //TdStyle
        _imgStyle = new Style();
        _imgStyle.BackColor = this.MidColor;
        _imgStyle.BorderWidth = new Unit(1);
        _imgStyle.BorderStyle = BorderStyle.Solid;
        _imgStyle.BorderColor = this.BorderColor;
        //FontInfo fi = new FontInfo()
        //fi.Size = new FontUnit(new Unit(1));
        //_imgStyle.Font = fi;
        _imgStyle.AddAttributesToRender(writer);
        writer.AddAttribute(HtmlTextWriterAttribute.Width,"13px");
        writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize,"1px");
        writer.AddAttribute(HtmlTextWriterAttribute.Align,"Center");
        //writer.AddAttribute(HtmlTextWriterAttribute.Valign,"Middle");
        writer.RenderBeginTag(HtmlTextWriterTag.Td);
        
        //Drop
        _drop = new HtmlImage();
        _drop.EnableViewState = false;
        _drop.Border = 0;
        _drop.Align = "Middle";
        _drop.Src = GetClientFileUrl("edit_0.gif");
        _drop.RenderControl(writer);
        writer.RenderEndTag();

        writer.RenderBeginTag(HtmlTextWriterTag.Td);
        
        _textStyle = new Style();
        _textStyle.Width = new Unit(72);
        _textStyle.BorderWidth = new Unit(0);
        _dateTextBox.ApplyStyle(_textStyle);
        _dateTextBox.Style.Add("float","left");
        //_dateTextBox.Text = DateToString(SelectedDate);
        _dateTextBox.RenderControl(writer);
        
        writer.RenderEndTag();
        writer.AddAttribute(HtmlTextWriterAttribute.Height,"100%");
        writer.AddAttribute(HtmlTextWriterAttribute.Width,"15");
        if(!ShowButton)
         writer.AddStyleAttribute("display","none");
        writer.RenderBeginTag(HtmlTextWriterTag.Td);
        
        //innerTable
        writer.AddAttribute(HtmlTextWriterAttribute.Id,UniqueID+"InnerTable");
        writer.AddAttribute(HtmlTextWriterAttribute.Width,"100%");
        writer.AddAttribute(HtmlTextWriterAttribute.Height,"100%");
        writer.AddAttribute(HtmlTextWriterAttribute.Border,"0px");
        writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing,"0");
        writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,"0");
        writer.RenderBeginTag(HtmlTextWriterTag.Table);
        writer.RenderBeginTag(HtmlTextWriterTag.Tr);
        
        _imgStyle.AddAttributesToRender(writer);
        writer.AddAttribute(HtmlTextWriterAttribute.Width,"15px");
        writer.AddAttribute(HtmlTextWriterAttribute.Height,"50%");
        writer.AddAttribute(HtmlTextWriterAttribute.Align,"Center");
        //writer.AddAttribute(HtmlTextWriterAttribute.Valign,"Middle");
        writer.RenderBeginTag(HtmlTextWriterTag.Td);
        //up
        _up = new HtmlImage();
        _up.EnableViewState = false;
        _up.Border = 0;
        _up.Align = "Middle";
        _up.Src = GetClientFileUrl("edit_1.gif");
        _up.RenderControl(writer);
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderBeginTag(HtmlTextWriterTag.Tr);
        _imgStyle.AddAttributesToRender(writer);
        writer.AddAttribute(HtmlTextWriterAttribute.Width,"15px");
        writer.AddAttribute(HtmlTextWriterAttribute.Height,"50%");
        writer.AddAttribute(HtmlTextWriterAttribute.Align,"Center");
        //writer.AddAttribute(HtmlTextWriterAttribute.Valign,"Middle");
        writer.RenderBeginTag(HtmlTextWriterTag.Td);

        //down
        _down = new HtmlImage();
        _down.EnableViewState = false;
        _down.Border = 0;
        _down.Align = "Middle";
        _down.Src = GetClientFileUrl("edit_2.gif");
        _down.RenderControl(writer);
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderEndTag();
        writer.RenderEndTag();
       }
       else
       {
        AddAttributesToRender(writer);
        if(ControlStyleCreated)
         ControlStyle.AddAttributesToRender(writer);
        _dateTextBox.RenderControl(writer);
       }

      }
      protected override void OnPreRender(EventArgs e)
      {
       base.OnPreRender (e);
       DetermineClientScriptLevel();
      }

      protected override void AddAttributesToRender(HtmlTextWriter writer)
      {
       writer.WriteLine("\n<!--\nDateChooser 博客园控件开发团队(www.cnblogs.com/team/dotnetcontrols.htm)\nTHIN(www.cnblogs.com/thinhunan)作品\n-->\n");
       base.AddAttributesToRender (writer);
       //writer.AddAttribute(HtmlTextWriterAttribute.Id,ClientID);
       writer.AddAttribute(HtmlTextWriterAttribute.Name,UniqueID);
      }

      #endregion

      #region Event
      
      [
      Category("Change"),
      Description("用户更改选择的日期引发的事件。")
      ]
      public event EventHandler DateChanged
      {
       add
       {
        Events.AddHandler(EventDateChanged, value);
       }
       remove
       {
        Events.RemoveHandler(EventDateChanged, value);
       }
      }

      protected virtual void OnDateChanged(EventArgs e)
      {
       EventHandler handler = (EventHandler)Events[EventDateChanged];
       if (handler != null)
       {
        handler(this, e);
       }
      }

      #endregion
     }
    }

  • 相关阅读:
    vue中的$event
    vue实现div拖拽互换位置
    关于marquee首次加载出现闪跳问题
    微信小程序之深色模式下样式的写法
    html动态添加公共页头和页脚
    微信小程序改变上一页面的数据,页面中的通信
    mui中的a标签无效和click无法点击的问题
    mui.DtPicker is not a constructor解决方案
    mui-slider选项卡设置默认index
    flutter环境配置遇到的一些坑
  • 原文地址:https://www.cnblogs.com/think/p/170128.html
Copyright © 2011-2022 走看看