⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar.cs

📁 《Visual Basic案例开发》一书的源代码
💻 CS
字号:
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace _36Hang.Web.UI.WebControls
{
	[DefaultProperty("Text"), ToolboxData("<{0}:Calendar runat=server></{0}:Calendar>")]
	public class Calendar : WebControl
	{
		private HtmlTableCell _HtmlTableCell;
		private CalendarModeFilename ModeFilename;
		private TextBox _TextBox;

		public Calendar() : base()
		{
			_HtmlTableCell = new HtmlTableCell();
			ModeFilename = new CalendarModeFilename();
			_TextBox = new TextBox();
		}

		public string Text
		{
			get
			{
				this.EnsureChildControls();
				return _TextBox.Text;
			}
			set
			{
				this.EnsureChildControls();
				_TextBox.Text = value;
			}
		}

		public string Base
		{
			get { if(ViewState["Base"] == null) return ""; else return (string)ViewState["Base"]; }
			set { ViewState["Base"] = value; }
		}

		public string Pathname
		{
			get { if(ViewState["Pathname"] == null) return ""; else return (string)ViewState["Pathname"]; }
			set { ViewState["Pathname"] = value; }
		}

		public string Icon
		{
			get { if(ViewState["Icon"] == null) return "Images/Calendar/Date.gif"; else return (string)ViewState["Icon"]; }
			set { ViewState["Icon"] = value; }
		}

		private void IFrame()
		{
			base.Page.RegisterStartupScript("_Calendar_IFrame","<iframe id=\"_Calendar_IFrame\" onmouseout=\"document.all('_Calendar_IFrame').style.display='none';\" style=\"DISPLAY: none; Z-INDEX: 999; WIDTH: 288px; POSITION: absolute; HEIGHT: 156px\" frameBorder=\"0\" noResize scrolling=\"no\"></iframe>");
			base.Page.RegisterStartupScript("_Calendar_Onclick","<script language='javascript' event='onclick();' for='document'> if(document.activeElement.id != '_Calendar_Image') { document.all(\'_Calendar_IFrame\').style.display = 'none'; } </script>");
		}

		public CalendarMode Mode
		{
			get { if(ViewState["Mode"] == null) return CalendarMode.Default; else return (CalendarMode)ViewState["Mode"]; }
			set { ViewState["Mode"] = value; }
		}

		protected override void Render(HtmlTextWriter objHtmlTextWriter)
		{
			objHtmlTextWriter.AddStyleAttribute(HtmlTextWriterStyle.Width,"320px");
			objHtmlTextWriter.AddStyleAttribute(HtmlTextWriterStyle.Height,"24px");

			this.EnsureChildControls();
			base.Render(objHtmlTextWriter);
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit (e);
			this.IFrame();
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);

			if(base.Page.IsPostBack != false)
			{
				SetStruct();
				SetControl();
			}
		}

		protected override void CreateChildControls()
		{
			Controls.Add(new LiteralControl("<script language=\"javascript\">" + "\n"));
			Controls.Add(new LiteralControl("<!--" + "\n"));
			Controls.Add(new LiteralControl("	function _" + this.ID + "_Click()" + "\n"));
			Controls.Add(new LiteralControl("	{" + "\n"));
			Controls.Add(new LiteralControl("		var objObject = document.all(\"" + (this.Base == "" ? "" : (this.Base + ":")) + "_" + this.ID + "_TextBox\");" + "\n"));
			Controls.Add(new LiteralControl("		var objValue = objObject.value;" + "\n"));
			Controls.Add(new LiteralControl("		document.all(\"_Calendar_IFrame\").src = \"" + this.Pathname + "Includes/Calendar.aspx?ID=" + (this.Base == "" ? "" : (this.Base + ":")) + "_" + this.ID + "_TextBox&Date=\" + objValue;" + "\n"));
			Controls.Add(new LiteralControl("		document.all(\"_Calendar_IFrame\").style.display = \"block\";" + "\n"));
			Controls.Add(new LiteralControl("		var intLeft = objObject.offsetLeft;" + "\n"));
			Controls.Add(new LiteralControl("		var intTop = objObject.offsetTop;" + "\n"));
			Controls.Add(new LiteralControl("		while(objObject = objObject.offsetParent)" + "\n"));
			Controls.Add(new LiteralControl("		{" + "\n"));
			Controls.Add(new LiteralControl("			intLeft += objObject.offsetLeft;" + "\n"));
			Controls.Add(new LiteralControl("			intTop += objObject.offsetTop;" + "\n"));
			Controls.Add(new LiteralControl("		}" + "\n"));
			Controls.Add(new LiteralControl("		document.all(\"_Calendar_IFrame\").style.left = intLeft;" + "\n"));
			Controls.Add(new LiteralControl("		document.all(\"_Calendar_IFrame\").style.top = intTop + document.all(\"" + (this.Base == "" ? "" : (this.Base + ":")) + "_" + this.ID + "_TextBox\").offsetHeight;" + "\n"));
			Controls.Add(new LiteralControl("	}" + "\n"));
			Controls.Add(new LiteralControl("-->" + "\n"));
			Controls.Add(new LiteralControl("</script>" + "\n"));

			Controls.Add(new LiteralControl("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"background-color:#d6dff7;\">" + "\n"));
			Controls.Add(new LiteralControl("	<tr>" + "\n"));
			Controls.Add(_HtmlTableCell);
			Controls.Add(new LiteralControl("	</tr>" + "\n"));
			Controls.Add(new LiteralControl("</table>" + "\n"));

			if(base.Page.IsPostBack != true)
			{
				SetStruct();
				SetControl();
			}
		}

		private void SetStruct()
		{
			this.ModeFilename.Default = this.Pathname + "Includes/Calendar/Default.css";
			this.ModeFilename.Office2003 = this.Pathname + "Includes/Calendar/Office2003.css";

			string strModeFilename = this.ModeFilename.Default;
			if(this.Mode == CalendarMode.Office2003) strModeFilename = this.ModeFilename.Office2003;
			_HtmlTableCell.Controls.Add(new LiteralControl("<link href=\"" + strModeFilename + "\" type=\"text/css\" rel=\"stylesheet\">" + "\n"));
		}

		private void SetControl()
		{
			_HtmlTableCell.Controls.Add(new LiteralControl("<table width=\"100%\" cellspacing=\"1\" cellpadding=\"0\">" + "\n"));
			_HtmlTableCell.Controls.Add(new LiteralControl("	<tr>" + "\n"));
			_HtmlTableCell.Controls.Add(new LiteralControl("		<td>" + "\n"));
			_TextBox.ID = "_" + this.ID + "_TextBox";
			_TextBox.Text = (this.Text == "" ? DateTime.Now.ToString("yyyy-MM-dd") : this.Text);
			_TextBox.Style.Add("width","100%");
			_TextBox.Attributes.Add("class","Calendar_TextBox");
			_HtmlTableCell.Controls.Add(_TextBox);
			_HtmlTableCell.Controls.Add(new LiteralControl("		</td>" + "\n"));
			_HtmlTableCell.Controls.Add(new LiteralControl("		<td id=\"_Calendar_Image\" width=\"22\"><img src=\"" + this.Pathname + this.Icon + "\" class=\"Calendar_Image\" onclick=\"_" + this.ID + "_Click();\"></td>" + "\n"));
			_HtmlTableCell.Controls.Add(new LiteralControl("	</tr>" + "\n"));
			_HtmlTableCell.Controls.Add(new LiteralControl("</table>" + "\n"));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -