WEB常用函数方法

/******************************************************************
** Copyright (c) 2001-2006 Suzsoft Co., Ltd.
** FileName:    UIHelper.cs
** Creator:     Clark.li   
** CreateDate:  Dec 20,2006
** 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;

/// <summary>
/// Summary description for UIHelper
/// </summary>
public class UIHelper
{
    #region Static Property Get BaseUrl
    /// <summary>
    /// The base url of application
    /// </summary>
    public static string 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;

            return strBaseUrl + "/";
        }
    }
    #endregion

    #region Static Alert()
    public static void Alert(System.Web.UI.Page pageCurrent, string strMsg)
    {
        //Replace /n
        strMsg = strMsg.Replace("/n", "//n");
        //Replace /r
        strMsg = strMsg.Replace("/r", "//r");
        //Replace "
        strMsg = strMsg.Replace("/"", "///"");
        //Replace '
        strMsg = strMsg.Replace("/'", "///'");

        pageCurrent.RegisterStartupScript(
            System.Guid.NewGuid().ToString(),
            "<script>window.alert('" + strMsg + "')</script>"
            );
    }

    #endregion

    #region Static Redirect()
    /// <summary>
    /// Add the javascript method to redirect page on client
    /// Created : Wang Hui, May 18,2006
    /// Modified:
    /// </summary>
    /// <param name="pageCurrent"></param>
    /// <param name="strPage"></param>
    public static void Redirect(System.Web.UI.Page pageCurrent, string strPage)
    {
        pageCurrent.RegisterStartupScript(
            System.Guid.NewGuid().ToString(),
            "<script>window.location.href='" + strPage + "'</script>"
            );
    }
    #endregion

    #region Static AddConfirm
    /// <summary>
    /// Add the confirm message to button
    /// Created : Wang Hui, Mar 1,2006
    /// Modified: Wang Hui, Mar 1,2006
    /// </summary>
    /// <param name="button">The control, must be a button</param>
    /// <param name="strMsg">The popup message</param>
    public static void AddConfirm(System.Web.UI.WebControls.Button 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 button
    /// Created : Wang Hui, Mar 1,2006
    /// Modified: Wang Hui, Mar 1,2006
    /// </summary>
    /// <param name="button">The control, must be a button</param>
    /// <param name="strMsg">The popup message</param>
    public void 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>
    public void 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

    #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>
    public static void 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 ='';";

        if (strUrl.Substring(0, 1) == "/")
        {
            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);
    }
    #endregion

    #region Static AddShowDialog
    /// <summary>
    /// Add the javascript method showModalDialog to button
    /// </summary>
    /// <param name="button">The control, must be a link 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>
    public static void AddShowDialog(System.Web.UI.WebControls.LinkButton 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 ='';";

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

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

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

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

    #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>
    public static void AddShowDialog(System.Web.UI.WebControls.ImageButton 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 ='';";

        if (strUrl.Substring(0, 1) == "/")
        {
            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);
    }
    #endregion

    #region Static OpenWindow
    /// <summary>
    /// Use "window.open" to popup the window
    /// Created : Wang Hui, Feb 24,2006
    /// Modified: Wang Hui, Feb 24,2006
    /// </summary>
    /// <param name="strUrl">The url of window, start with "/", not "http://"</param>
    /// <param name="intWidth">Width of popup window</param>
    /// <param name="intHeight">Height of popup window</param>
    public static void OpenWindow(System.Web.UI.Page pageCurrent, string strUrl, int intWidth, int intHeight)
    {
        string strScript = "";
        strScript += "var strFeatures = 'width:" + intWidth.ToString() + "px;height:" + intHeight.ToString() + "px';";
        strScript += "var strName ='__WIN';";
        //strScript += "alert(strFeatures);";

        //--- Add by Wang Hui on Feb 27
        if (strUrl.Substring(0, 1) == "/")
        {
            strUrl = strUrl.Substring(1, strUrl.Length - 1);
        }
        //--- End Add by Wang Hui on Feb 27

        strUrl = BaseUrl + strUrl;

        strScript += "window.open(/"" + strUrl + "/",strName,strFeatures);";

        pageCurrent.RegisterStartupScript(
            System.Guid.NewGuid().ToString(),
            "<script language='javascript'>" + strScript + "</script>"
            );
    }
    #endregion

    #region Static ShowDialog
    /// <summary>
    /// Use "window.showModalDialog" to show the dialog
    /// Created : Wang Hui, Feb 24,2006
    /// Modified: Wang Hui, Feb 27,2006
    /// </summary>
    /// <param name="strUrl">The url of dialog, start with "/", not "http://"</param>
    /// <param name="intWidth">Width of dialog</param>
    /// <param name="intHeight">Height of dialog</param>
    public static void ShowDialog(System.Web.UI.Page pageCurrent, 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 ='';";

        //--- Add by Wang Hui on Feb 27
        if (strUrl.Substring(0, 1) == "/")
        {
            strUrl = strUrl.Substring(1, strUrl.Length - 1);
        }
        //--- End Add by Wang Hui on Feb 27

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

        //strScript += "window.showModalDialog(/"" + strUrl + "/",strName,strFeatures);";
        strScript += "window.showModalDialog(/"" + strUrl + "/",window,strFeatures); ";

        pageCurrent.RegisterStartupScript(
            System.Guid.NewGuid().ToString(),
            "<script language='javascript'>" + strScript + "</script>"
            );
    }
    #endregion
}

/******************************************************************
** Copyright (c) 2001-2006 Suzsoft Co., Ltd.
** FileName       :    PageBase.cs
** Creator        :    Eric Gu   
** CreateDate     :    2006-12-19
** Changer        :    Herry.Wan 
** LastChangeDate :    2006-12-25
** Description    :
** 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;

namespace Suzsoft.CRM.Web
{
    /// <summary>
    /// Summary description for PageBase
    /// </summary>
    public class PageBase : System.Web.UI.Page
    {
        #region PageInit
        /// <summary>
        /// 重载PreInit事件,实现对Theme的控制
        /// </summary>
        /// <param name="e"></param>
        /// <remarks>
        /// Author : Eric Gu  Date : 2006-12-29
        /// </remarks>
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            System.Web.Profile.ProfileBase profile;
            profile = HttpContext.Current.Profile;
            this.Theme = profile.GetPropertyValue("ThemePreference").ToString();
        }
        #endregion

        #region PageLoad
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (Session["Login_UserID"] == null)
            {
                Response.Redirect(BaseUrl + "Logon.aspx");
            }
        }
        #endregion

        #region PageBase
        public PageBase()
        {
            //
            // TODO: Add constructor logic here
            //           
        }
        #endregion

        #region Property BaseUrl
        /// <summary>
        /// The base url of application
        /// </summary>
        public string 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;

                return strBaseUrl + "/";
            }
        }
        #endregion

        #region Property UserID
        /// <summary>
        /// Current User ID of the person who is login
        /// </summary>
        /// Add By Herry.Wan Date:2006-12-25
        public string Login_UserID
        {
            get
            {
                if (Session["Login_UserID"] != null)
                {
                    return Session["Login_UserID"].ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                Session["Login_UserID"] = value;
            }
        }
        #endregion

        #region Property IsAdmin
        /// <summary>
        /// Current User is Admin or not
        /// </summary>
        /// Add By Herry.Wan Date:2006-12-25
        public bool IsAdmin
        {
            get
            {
                if (Session["IsAdmin"] != null)
                {
                    try
                    {
                        return Convert.ToBoolean(Session["IsAdmin"]);
                    }
                    catch
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            set
            {
                Session["IsAdmin"] = value;
            }
        }
        #endregion

        #region Property sugar_Login
        /// <summary>
        /// Current User log on or not
        /// </summary>
        /// Add By Herry.Wan Date:2006-12-25
        public bool sugar_Login
        {
            get
            {
                if (Session["sugar_Login"] != null)
                {
                    try
                    {
                        return Convert.ToBoolean(Session["sugar_Login"]);
                    }
                    catch
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            set
            {
                Session["sugar_Login"] = value;
            }
        }
        #endregion
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值