123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- using System;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace Ant.Service.Utilities
- {
- public class PageHelper
- {
- #region 控件状态设置
-
-
-
-
-
- public static void LockPage(Page page, object[] obj)
- {
- System.Web.UI.Control htmlForm = null;
- foreach (System.Web.UI.Control ctl in page.Controls)
- {
- if (ctl is HtmlForm)
- {
- htmlForm = ctl;
- break;
- }
- }
-
- foreach (System.Web.UI.Control ctl in htmlForm.Controls)
- {
- if (IsContains(obj, ctl) == false)
- {
-
- LockControl(page, ctl);
- }
- else
- {
-
- UnLockControl(page, ctl);
- }
- }
- }
-
-
-
-
-
- public static void UnLockPage(Page page, object[] obj)
- {
- System.Web.UI.Control htmlForm = null;
- foreach (System.Web.UI.Control ctl in page.Controls)
- {
- if (ctl is HtmlForm)
- {
- htmlForm = ctl;
- break;
- }
- }
-
- foreach (System.Web.UI.Control ctl in htmlForm.Controls)
- {
- if (IsContains(obj, ctl) == false)
- {
-
- UnLockControl(page, ctl);
- }
- else
- {
-
- LockControl(page, ctl);
- }
- }
- }
-
-
-
-
-
- private static void LockControl(Page page, System.Web.UI.Control ctl)
- {
-
- if (ctl is Button || ctl is CheckBox || ctl is HyperLink || ctl is LinkButton
- || ctl is ListControl || ctl is TextBox)
- {
- ((WebControl)ctl).Enabled = false;
- #region 多行文本框不能禁用,应设为只读,不然滚动条不能使用
- if (ctl is TextBox)
- {
- if (((TextBox)ctl).TextMode == TextBoxMode.MultiLine)
- {
- ((TextBox)ctl).Enabled = true;
- ((TextBox)ctl).ReadOnly = true;
- }
- }
- #endregion
- #region 时间控件禁用时不显示图片
- #endregion
- }
-
- if (ctl is HtmlInputFile)
- {
- ((HtmlInputFile)ctl).Disabled = true;
- }
- }
-
-
-
-
-
- private static void UnLockControl(Page page, System.Web.UI.Control ctl)
- {
-
- if (ctl is Button || ctl is CheckBox || ctl is HyperLink || ctl is LinkButton
- || ctl is ListControl || ctl is TextBox)
- {
- ((WebControl)ctl).Enabled = true;
-
- if (ctl is TextBox)
- {
- ((TextBox)ctl).ReadOnly = false;
- }
-
-
-
-
-
-
-
-
-
-
-
- }
-
- if (ctl is HtmlInputFile)
- {
- ((HtmlInputFile)ctl).Disabled = false;
- }
- }
-
-
-
-
-
-
- private static bool IsContains(object[] obj, System.Web.UI.Control ctl)
- {
- foreach (System.Web.UI.Control c in obj)
- {
- if (c.ID == ctl.ID)
- {
- return true;
- }
- }
- return false;
- }
- #endregion
- #region 页面处理其它辅助方法
-
-
-
-
- public static Page GetCurrentPage()
- {
- return (Page)HttpContext.Current.Handler;
- }
-
-
-
-
- public static string GetPageName()
- {
- int start = 0;
- int end = 0;
- string Url = HttpContext.Current.Request.RawUrl;
- start = Url.LastIndexOf("/") + 1;
- end = Url.IndexOf("?");
- if (end <= 0)
- {
- return Url.Substring(start, Url.Length - start);
- }
- else
- {
- return Url.Substring(start, end - start);
- }
- }
-
-
-
-
-
- public static string GetQueryString(string queryStringName)
- {
- if ((HttpContext.Current.Request.QueryString[queryStringName] != null) &&
- (HttpContext.Current.Request.QueryString[queryStringName] != "undefined"))
- {
- return HttpContext.Current.Request.QueryString[queryStringName].Trim();
- }
- else
- {
- return "";
- }
- }
-
-
-
-
- public void Redirect(string url)
- {
- Page page = GetCurrentPage();
- page.Response.Redirect(url);
- }
-
-
-
-
- public static string GetRelativeLevel()
- {
- string ApplicationPath = HttpContext.Current.Request.ApplicationPath;
- if (ApplicationPath.Trim() == "/")
- {
- ApplicationPath = "";
- }
- int i = ApplicationPath == "" ? 1 : 2;
- return "";
- }
-
-
-
-
- public static void WriteScript(string script)
- {
- Page page = GetCurrentPage();
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static int GetClientBrowserVersion()
- {
- string USER_AGENT = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
- if (USER_AGENT.IndexOf("MSIE") < 0) return -1;
- string version = USER_AGENT.Substring(USER_AGENT.IndexOf("MSIE") + 5, 1);
- if (!Utility.IsInt(version)) return -1;
- return Convert.ToInt32(version);
- }
- #endregion
- }
- }
|