/**//****************************************************************** ** Copyright (c) 2001-2006 ** FileName: UIHelper.cs ** Creator: ** CreateDate: ** Changer: ** LastChangeDate: ** Description: Class used for UI unification. * It will make easier to set the UI. * More info please read the remark of functions. ** VersionInfo: ******************************************************************/ using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing; using System.Text; using System.Collections;
/**////<summary> /// Summary description for UIHelper ///</summary> publicclass UIHelper { Property Get BaseUrl#region Property Get BaseUrl /**////<summary> /// The base url of application ///</summary> publicstaticstring BaseUrl { get { string strBaseUrl =""; strBaseUrl +="http://"+ HttpContext.Current.Request.Url.Host; if (HttpContext.Current.Request.Url.Port.ToString() !="80") { strBaseUrl +=":"+ HttpContext.Current.Request.Url.Port; } strBaseUrl += HttpContext.Current.Request.ApplicationPath;
/**////<summary> /// Add the confirm message to button /// /// ///</summary> ///<param name="button">The control, must be a button</param> ///<param name="strMsg">The popup message</param> publicstaticvoid AddConfirm(System.Web.UI.WebControls.ImageButton button, string strMsg) { strMsg = strMsg.Replace("\n", "\\n"); strMsg = strMsg.Replace("\r", "\\r"); strMsg = strMsg.Replace("\"", "\\\""); strMsg = strMsg.Replace("\'", "\\\'"); button.Attributes.Add("onClick", "return confirm('"+ strMsg +"')"); }
/**////<summary> /// Add the confirm message to one column of gridview ///</summary> ///<param name="grid">The control, must be a GridView</param> ///<param name="intColIndex">The column index. It's usually the column which has the "delete" button.</param> ///<param name="strMsg">The popup message</param> publicvoid AddConfirm(System.Web.UI.WebControls.GridView grid, int intColIndex, string strMsg) { strMsg = strMsg.Replace("\n", "\\n"); strMsg = strMsg.Replace("\r", "\\r"); strMsg = strMsg.Replace("\"", "\\\""); strMsg = strMsg.Replace("\'", "\\\'"); for (int i =0; i < grid.Rows.Count; i++) { grid.Rows[i].Cells[intColIndex].Attributes.Add("onclick", "return confirm('"+ strMsg +"')"); } } #endregion
Static AddShowDialog#region Static AddShowDialog /**////<summary> /// Add the javascript method showModalDialog to button ///</summary> ///<param name="button">The control, must be a button</param> ///<param name="strUrl">The page url, including query string</param> ///<param name="intWidth">Width of window</param> ///<param name="intHeight">Height of window</param> publicstaticvoid AddShowDialog(System.Web.UI.WebControls.Button button, string strUrl, int intWidth, int intHeight) { string strScript =""; strScript +="var strFeatures = 'dialogWidth="+ intWidth.ToString() +"px;dialogHeight="+ intHeight.ToString() +"px;center=yes;help=no;status=no';"; strScript +="var strName ='';";
Static SetGridStyle#region Static SetGridStyle /**////<summary> /// Set the style of GridView. /// You may call "base.SetGridStyle(MyGridId)" to set the style. So the application has the same grid style. /// Note: Do not set any style of your GridView, and only use this method. /// Created : /// Modified: ///</summary> ///<param name="objGrid"></param> publicstaticvoid SetGridStyle(System.Web.UI.WebControls.GridView objGrid) {
DateTime DT =new DateTime(); for (int i =0; i < objGrid.Rows.Count; i++) { for (int j =0; j < objGrid.Rows[i].Cells.Count; j++) { if (DateTime.TryParse(objGrid.Rows[i].Cells[j].Text, out DT)) { if (DT.Year == DateTime.Parse("0001-1-1 0:00:00").Year) { objGrid.Rows[i].Cells[j].Text ="--"; } } }
Static SetTreeStyle#region Static SetTreeStyle /**////<summary> /// Set the style of TreeView. /// You may call "base.SetTreeStyle(MyTreeId)" to set the style. So the application has the same tree style. /// Note: Do not set any style of your TreeView, and only use this method. /// ///</summary> ///<param name="objTree"></param> publicstaticvoid SetTreeStyle(System.Web.UI.WebControls.TreeView objTree) { objTree.ShowLines =true; objTree.BackColor = System.Drawing.Color.FromName("#FFFFFF"); objTree.BorderColor = System.Drawing.Color.FromName("#5D7B9D"); objTree.BorderStyle = BorderStyle.Solid; objTree.BorderWidth =1; objTree.SelectedNodeStyle.BackColor = System.Drawing.Color.LightGray;
Float the element of the window#region Float the element of the window /**////<summary> /// Float the element of the window ///</summary> ///<param name="pageCurrent"></param> ///<param name="TargetControlClientID"></param> ///<param name="StartLocationX"></param> ///<param name="StartLocationY"></param> ///<remarks> Gerry.Liang</remarks> publicstaticvoid SetElementFloatAndScroll(Page pageCurrent, string TargetControlClientID, int StartLocationX, int StartLocationY) { string strScript =@" <script type='text/javascript'> function MoveDivOnTime( ) { var divfloat=document.getElementById('"+ TargetControlClientID +@"'); divfloat.className='FloatElement'; var startY ="+ StartLocationY +@"; var y = document.documentElement.scrollTop + startY ; divfloat.style.posLeft ="+ StartLocationX +@"; divfloat.style.posTop = y; if(divfloat.children.length!=2) { var iframeback=document.createElement('<iframe src=about:blank frameborder=0 style=position:absolute;z-index:-1;></iframe>'); divfloat.children[0].insertAdjacentElement('afterEnd', iframeback); iframeback.style.top=0; iframeback.style.left=0; iframeback.style.width=divfloat.children[0].offsetWidth; iframeback.style.height=divfloat.children[0].offsetHeight; iframeback.style.zIndex=-1; } } function window_onload() { setInterval('MoveDivOnTime( )',100); } </script>"; pageCurrent.ClientScript.RegisterClientScriptBlock(pageCurrent.GetType(), Guid.NewGuid().ToString(), strScript); (pageCurrent.Form.Parent as HtmlGenericControl).Attributes.Add("onload", "window_onload()"); }