一个常用的Class used for UI unification

/******************************************************************
** 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>

public class UIHelper
{
    
Property Get BaseUrl

    
Static Alert()

    
Static Alert()

    
Static Redirect()

    
Static AddConfirm

    
Static AddShowDialog

    
Static AddShowDialog

    
Static AddShowDialog

    
public static void AddShowDialog(System.Web.UI.WebControls.ImageButton button, string strUrl, int intWidth, int intHeight, bool isRefreshParentPage)
    
{
        
if (isRefreshParentPage)
        
{
            
string strScript = "";
            strScript 
+= "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";
            strScript 
+= "var strName ='';";

            
if (strUrl.Substring(01== "/")
            
{
                strUrl 
= strUrl.Substring(1, strUrl.Length - 1);
            }


            strUrl 
= BaseUrl + "DialogFrame.aspx?URL=" + strUrl;

            strScript 
+= "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return true;";

            button.Attributes.Add(
"onClick", strScript);
        }

        
else
        
{
            
string strScript = "";
            strScript 
+= "var strFeatures = 'dialogWidth=" + intWidth.ToString() + "px;dialogHeight=" + intHeight.ToString() + "px;center=yes;help=no;status=no';";
            strScript 
+= "var strName ='';";

            
if (strUrl.Substring(01== "/")
            
{
                strUrl 
= strUrl.Substring(1, strUrl.Length - 1);
            }


            strUrl 
= BaseUrl + "DialogFrame.aspx?URL=" + strUrl;

            strScript 
+= "window.showModalDialog(\'" + strUrl + "\',window,strFeatures);return false;";

            button.Attributes.Add(
"onClick", strScript);

        }

    }


    
Static OpenWindow

    
Static OpenWindow

    
Static ShowDialog

    
Static ShowDialog

    
Static SetGridStyle

    
Static SetTreeStyle

    
Static ValidateTxtLength()


    
public static void BindEnumValue(SortedList SLKeyValue, DropDownList Targeddl)
    
{
        Targeddl.Items.Clear();
        
for (int i = 0; i < SLKeyValue.Count; i++)
        
{
            Targeddl.Items.Add(
new ListItem(SLKeyValue.GetValueList()[i].ToString(), SLKeyValue.GetKeyList()[i].ToString()));
        }

    }


    
/// <summary>
    
/// 绑定GridView时显示表头
    
/// </summary>
    
/// <param name="sgv"></param>

    //public static void BindNullSGridView(SGridView sgv)
    public static void BindNullSGridView(GridView sgv)
    
{
        
if (sgv != null)
        
{
            
if (sgv.Rows.Count == 0)//在gridview的数据为空的情况下显示gird的title
            {
                
//排序冲突 Leo.Wu
                sgv.AllowSorting = false;
                DataTable dt 
= new DataTable();
                DataRow dr 
= dt.NewRow();
                dt.Rows.Add(dr);
                sgv.DataSource 
= dt;
                
try
                
{
                    sgv.DataBind();
//数据为空,此时会报错,但是grid的标题会显示出来
                }

                
catch
                
{
                    
//不做处理
                }

                
if (sgv.Rows.Count > 0)
                
{
                    sgv.Rows[
0].Visible = false;
                }

            }

            
else
            
{
            }


        }

    }


    
/// <summary>
    
/// 设置页面点击Enter键后触发的按钮事件
    
/// </summary>
    
/// <param name="pageCurrent">页面对象</param>
    
/// <param name="strButtonClientID">按钮的客户端ID</param>
    
/// <remarks>Add By Herry.Wan</remarks>

    public static void SetDefaultButton(System.Web.UI.Page pageCurrent, string strButtonClientID)
    
{
        pageCurrent.RegisterStartupScript(Guid.NewGuid().ToString(), 
"<script language=\"javascript\"> function document.onkeydown() { var e=event.srcElement;if(event.keyCode==13){ try{document.getElementById('" + strButtonClientID + "').click();return false;}catch(e){} }}</script>");
    }


    
Float the element of the window
}

posted @ 2007-06-27 09:42  jhtchina  阅读(974)  评论(0编辑  收藏  举报