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

📄 basevalidator.cs

📁 不错的人事管理系统
💻 CS
字号:
/*
 *
  
 导读:BaseValidator是
 
 *
 */

using System;
using System.ComponentModel;
using System.Drawing;

namespace System.Web.UI.WebControls
{
	/// <summary>
	/// Summary description for BaseValidator.
	/// </summary>
	public abstract class BaseValidator : Label, System.Web.UI.IValidator
	{

		protected BaseValidator() : base() 
		{
			this.isValid = true;
			this.propertiesChecked = false;
			this.propertiesValid = true;
			this.renderUplevel = false;
			this.ForeColor = Color.Red;
		}
		private const string ValidatorFileName = "WebUIValidation.js";
		private const string ValidatorIncludeScriptKey = "ValidatorIncludeScript";
		private const string ValidatorScriptVersion = "125";
		private const string ValidatorStartupScript = "\r\n<script language=\"javascript\">\r\n<!--\r\nvar Page_V"
								   + "alidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Exp"
								   + "lorer\") != -1) {{\r\n    if (typeof(Page_ValidationVer) == \"undefined\")\r\n        alert(\"{0}\");\r\n    else if (Page_"
								   + "ValidationVer != \"{1}\")\r\n        alert(\"{2}\");\r\n    else\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOn"
								   + "Submit() {{\r\n    if (Page_ValidationActive) {{\r\n        ValidatorCommonOnSubmit();\r\n    }}\r\n}}\r\n// -->\r\n</script"
								   + ">\r\n        ";
		private bool isValid;
		private bool preRenderCalled;
		private bool propertiesChecked;
		private bool propertiesValid;
		private bool renderUplevel;


		protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
		{
			bool local0;
			ValidatorDisplay local1;

			local0 = (!(this.Enabled));

			if (local0)
			{
				this.Enabled = true;
			}

			this.AddAttributesToRender(writer);
			if (this.RenderUplevel) 
			{
				if (this.ID == null)
					writer.AddAttribute("id", this.ClientID);
				if (this.ControlToValidate.Length > 0)
					writer.AddAttribute("controltovalidate", this.GetControlRenderID(this.ControlToValidate));
				if (this.ErrorMessage.Length > 0)
					writer.AddAttribute("errormessage", this.ErrorMessage, true);
				local1 = this.Display;
				if (local1 != ValidatorDisplay.Static)
				{
					//writer.AddAttribute("display", System.Web.UI.PropertyConverter.EnumToString(typeof(ValidatorDisplay), local1));
				}
				if (!(this.IsValid))
					writer.AddAttribute("isvalid", "False");
				if (local0)
					writer.AddAttribute("enabled", "False");
			}
			if (local0)
				this.Enabled = false;
		}

		protected void CheckControlValidationProperty(string name, string propertyName) 
		{
			System.Web.UI.Control V_0;
			PropertyDescriptor local1;

			V_0 = this.NamingContainer.FindControl(name);
			if (V_0 == null)
				throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Validator_control_not_found", name, propertyName, this.ID));
			local1 = BaseValidator.GetValidationProperty(V_0);
			if (local1 == null)
				throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Validator_bad_control_type", name, propertyName, this.ID));
		}

		protected virtual bool ControlPropertiesValid() 
		{
			string local0;

			local0 = this.ControlToValidate;
			if (local0.Length == 0)
				throw new HttpException(System.Web.HttpRuntime.FormatResourceString("Validator_control_blank", this.ID));
			this.CheckControlValidationProperty(local0, "ControlToValidate");
			return true;
		}

		protected virtual bool DetermineRenderUplevel() 
		{
			Page local0;

			local0 = this.Page;
			if (local0 == null || local0.Request == null)
				return false;
			if (this.EnableClientScript && local0.Request.Browser.MSDomVersion.Major >= 4)
				return local0.Request.Browser.EcmaScriptVersion.CompareTo(new Version(1, 2)) >= 0;
			return false;
		}

		protected abstract bool EvaluateIsValid();

		protected string GetControlRenderID(string name) 
		{
			Control local0;

			local0 = this.FindControl(name);
			if (local0 == null)
				return "";
			return local0.ClientID;
		}

		protected string GetControlValidationValue(string name) 
		{
			Control local0;
			PropertyDescriptor local1;
			object local2;

			local0 = this.NamingContainer.FindControl(name);
			if (local0 == null)
				return null;
			local1 = BaseValidator.GetValidationProperty(local0);
			if (local1 == null)
				return null;
			local2 = local1.GetValue(local0);
			if (local2 as ListItem != null)
				return ((ListItem)local2).Value;
			if (local2 != null)
				return local2.ToString();
			return System.String.Empty;
		}

		public static PropertyDescriptor GetValidationProperty(object component) 
		{
			ValidationPropertyAttribute local0;

			local0 = (ValidationPropertyAttribute) System.ComponentModel.TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
			if (local0 != null && local0.Name != null)
				return System.ComponentModel.TypeDescriptor.GetProperties(component, null)[local0.Name];
			return null;
		}

		protected override void OnInit(EventArgs e) 
		{
			this.OnInit(e);
//			this.Page.Validators.Add(this);
		}

		protected override void OnPreRender(EventArgs e) 
		{
			this.OnPreRender(e);
			this.preRenderCalled = true;
			this.propertiesChecked = false;
			this.renderUplevel = this.DetermineRenderUplevel();
			if (this.renderUplevel)
				this.RegisterValidatorCommonScript();
		}

		protected override void OnUnload(EventArgs e) 
		{
//			if (this.Page != null)
//				this.Page.Validators.Remove(this);
//			this.OnUnload(e);
		}

		protected void RegisterValidatorCommonScript() 
		{
			string local0;
			string local1;
			string local2;
			string local3;
			object[] local4;

			if (this.Page.IsClientScriptBlockRegistered("ValidatorIncludeScript"))
				return;
			local0 = System.Web.UI.Util.GetScriptLocation(this.Context);
			local1 = System.Web.HttpRuntime.FormatResourceString("Validator_missing_script", local0 + "WebUIValidation.js");
			local2 = System.Web.HttpRuntime.FormatResourceString("Validator_wrong_script", "WebUIValidation.js", "125", "\" + Page_ValidationVer + \"");
			local4 = new Object[3];
			local4[0] = local1;
			local4[1] = "125";
			local4[2] = local2;
			local3 = System.String.Format("\r\n<script language=\"javascript\">\r\n<!--\r\nvar Page_ValidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Explorer\") != -1) {{\r\n    if (typeof(Page_ValidationVer) == \"undefined\")\r\n        alert(\"{0}\");\r\n    else if (Page_ValidationVer != \"{1}\")\r\n        alert(\"{2}\");\r\n    else\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOnSubmit() {{\r\n    if (Page_ValidationActive) {{\r\n        ValidatorCommonOnSubmit();\r\n    }}\r\n}}\r\n// -->\r\n</script>\r\n        ", local4);
			this.Page.RegisterClientScriptFileInternal("ValidatorIncludeScript", "javascript", local0, "WebUIValidation.js");
			this.Page.RegisterStartupScript("ValidatorIncludeScript", local3);
			this.Page.RegisterOnSubmitStatement("ValidatorOnSubmit", "ValidatorOnSubmit();");
		}

		protected virtual void RegisterValidatorDeclaration() 
		{
			string local0;

			local0 = "document.all[\"" + this.ClientID + "\"]";
			this.Page.RegisterArrayDeclaration("Page_Validators", local0);
		}

		protected override void Render(System.Web.UI.HtmlTextWriter writer) 
		{
			bool local0;
			ValidatorDisplay local1;
			bool local2;
			bool local3;

			if (!(this.preRenderCalled)) //else goto 0021
			{
				this.propertiesChecked = true;
				this.propertiesValid = true;
				this.renderUplevel = false;
				local0 = true;
			} //goto 0036
			else //line 0021
			{
				local0 = (this.Enabled) ? this.isValid : false;
			}

			//line 0036
			if (!(this.PropertiesValid))
				return;

			//line 003f
			if (this.Page != null)
			{
				this.Page.VerifyRenderingInServerForm(this);
			}

			local1 = this.Display;

			//line 005a
			if (this.RenderUplevel) 
			{
				local3 = true;
				local2 = (local1 != ValidatorDisplay.None);
			}
			else 
			{
				local2 = (local1 != ValidatorDisplay.None) ? local0 : false;
				local3 = local2;
			}

			if (local3 && this.RenderUplevel) 
			{
				this.RegisterValidatorDeclaration();
				if((local1 == ValidatorDisplay.None) 
					|| !(local0) 
					&& (local1 == ValidatorDisplay.Dynamic)
					)
				{
					this.Style["display"] = "none";
				}
				else if (!(local0))
				{
					this.Style["visibility"] = "hidden";
				}
			}

			//line 00c2
			if(local3) //else goto 00cc
			{
				this.RenderBeginTag(writer);
			}

			//line 00cc
			if (local2) //else goto 010a
			{
				if (this.Text.Trim().Length > 0) //else goto 00eb
				{
					//line 00e2
					this.RenderContents(writer);
				} //goto 0121
				else if (this.HasControls()) //else goto 00fc
				{
					this.RenderContents(writer);
				}//goto 0121
				else
				{
					//line 00fc
					writer.Write(this.ErrorMessage);
				}
			}
			else if (!(this.RenderUplevel) && local1 == ValidatorDisplay.Static)
			{
				//line 0116
				writer.Write("&nbsp;");
			}

			//line 0021
			if (local3)
				this.RenderEndTag(writer);
		}

		public virtual void Validate() 
		{
			Control local0;

			if (!(this.Visible) || !(this.Enabled)) 
			{
				this.IsValid = true;
				return;
			}

			local0 = this.Parent;
			while (local0 != null) 
			{
				if (!(local0.Visible)) 
				{
					this.IsValid = true;
					return;
				}
				local0 = local0.Parent;
			}

			this.propertiesChecked = false;
			if (!(this.PropertiesValid)) 
			{
				this.IsValid = true;
				return;
			}
			this.IsValid = this.EvaluateIsValid();
		}

		public string ControlToValidate 
		{
			get
			{
				object local0;

				local0 = this.ViewState["ControlToValidate"];
				if (local0 != null)
					return (string) local0;
				return System.String.Empty;
			}
			set
			{
				this.ViewState["ControlToValidate"] = value;
			}
		}

		public ValidatorDisplay Display
		{
			get
			{
				object local0;

				local0 = this.ViewState["Display"];
				if (local0 != null)
					return (ValidatorDisplay) local0;
				return ValidatorDisplay.Static;
			}
			set
			{
				if ((int)value < 0 || (int)value > 2)
					throw new ArgumentOutOfRangeException("value");
				this.ViewState["Display"] = value;
			}
		}
		
		public bool EnableClientScript
		{
			get
			{
				object local0;

				local0 = this.ViewState["EnableClientScript"];
				if (local0 != null)
					return (bool) local0;
				return true;
			}
			set
			{
				this.ViewState["EnableClientScript"] = value;
			}
		}

		public override bool Enabled
		{
			get
			{
				return this.Enabled;
			}
			set
			{
				this.Enabled = value;
				if (!(value))
					this.isValid = true;
			}
		}

		public virtual string ErrorMessage
		{
			get
			{
				object local0;

				local0 = this.ViewState["ErrorMessage"];
				if (local0 != null)
					return (String) local0;
				return System.String.Empty;
			}
			set
			{
				this.ViewState["ErrorMessage"] = value;
			}
		}

		public override Color ForeColor
		{
			get
			{
				return base.ForeColor;
			}
			set
			{
				base.ForeColor = value;
			}
		}

		public virtual bool IsValid
		{
			get
			{
				return this.isValid;
			}
			set
			{
				this.isValid = value;
			}
		}

		protected bool PropertiesValid 
		{
			get
			{
				if (!(this.propertiesChecked)) 
				{
					this.propertiesValid = this.ControlPropertiesValid();
					this.propertiesChecked = true;
				}
				return this.propertiesValid;
			}
		}
		protected bool RenderUplevel
		{
			get
			{
				return this.renderUplevel;
			}
		}
	}
}

⌨️ 快捷键说明

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