BasePage例子

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Web.UI.WebControls;

using MCS.WDEDUCloud.Common.DataModel;
using MCS.WDEDUCloud.Common.Business.OP;
using MCS.WDEDUCloud.Common.Utility;

namespace MCS.WDEDUCloud.Portal.OP.Base
{
    public class BasePage : System.Web.UI.Page
    {
        #region UserInfo
        ERoleBLL RoleBll;

        private EUserInfo currentuser = null;
        /// <summary>
        /// 当前登录人
        /// </summary>
        public EUserInfo CurrentUser
        {
            get
            {
                if (currentuser == null)
                {
                    EUserBLL eUserBLL = new EUserBLL();
                    //lxf TODO:需通过Federation获取用户信息
                    currentuser = eUserBLL.GetLoginUserInfo(HttpContext.Current.User.Identity.Name);
                }
                return currentuser;
            }
        }

        /// <summary>
        /// 获取当前用户所属角色
        /// </summary>
        public List<ERoleInfo> CurrentRole
        {
            get
            {
                RoleBll = new ERoleBLL();
                return RoleBll.GetOPRoleList(this.CurrentUser.UserId);
            }
        }

        #endregion

        #region 菜单
       
        /// <summary>
        /// 菜单
        /// </summary>
        /// <returns></returns>
        public string GetMenu()
        {
            string strLeftMenu = "";
            string strHeaderMenu = "<div class=\"nav\" id=\"nav\"> <ul>";
            EMenuBLL MenuBll = new EMenuBLL();
            // 根据角色获取菜单树
            List<EMenuInfo> MenuList = MenuBll.GetRoleMenuTree(this.CurrentRole);

            if (MenuList != null)
            {
                strLeftMenu += "<div class=\"btmenu\" id=\"btmenu\" >";
                int iCount=0;
                // 遍历一级菜单
                foreach (EMenuInfo item in MenuList)
                {
                    if (string.IsNullOrEmpty(item.PageUrl))
                    {
                        strHeaderMenu += "<li><a href=\"#\" id=\"a" + item.MenuId + "\" >" + item.MenuName + "</a></li>";
                    }
                    else
                    {
                        strHeaderMenu += "<li><a href=\""+item.PageUrl+"\" id=\"a" + item.MenuId + "\" >" + item.MenuName + "</a></li>";
                    }
                    // 默认显示第一个菜单
                    if (iCount == 1)
                    {
                        strLeftMenu += "<div  id=\"" + item.MenuId + "\" >";
                    }
                    else
                    {
                        strLeftMenu += "<div  id=\"" + item.MenuId + "\" style=\"display:none;\">";
                    }
                    // 遍历二级菜单
                    foreach (EMenuInfo detail in item.ChildMenuList)
                    {
                        if (detail.ChildMenuList.Count > 0)
                        {
                            // 遍历三级菜单
                            foreach (EMenuInfo details in detail.ChildMenuList)
                            {
                                strLeftMenu += "<div class=\"metitle\"><a href=\"#\" >" + detail.MenuName + "</a></div>";
                                if (!string.IsNullOrEmpty(details.PageUrl))
                                {
                                    strLeftMenu += "<div class=\"metext\"><a " + "href=\"" + details.PageUrl + "\" target=\"FContent\" >" + details.MenuName + "</a></div>";
                                  
                                }
                                else
                                {
                                    strLeftMenu += "<div class=\"metext\"><a " + "href=\"#\"  >" + details.MenuName + "</a></div>";
                                }
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(detail.PageUrl))
                            {
                                strLeftMenu += "<div class=\"metitle\"><a " + "href=\"" + detail.PageUrl + "\" target=\"FContent\" >" + detail.MenuName + "</a></div> <div> </div>";
                            }
                            else
                            {
                                strLeftMenu += "<div class=\"metitle\"><a " + "href=\"#\"  >" + detail.MenuName + "</a></div> <div> </div>";
                            }
                        }
                    }
                    strLeftMenu += "</div>";
                    iCount++;
                }
                strLeftMenu += "</div>";
                strHeaderMenu += "</ul> </div>";
            }
            return strHeaderMenu + strLeftMenu;
        }
        #endregion

        #region 设置控件为只读
        /// <summary>
        /// 设置控件为只读
        /// </summary>
        /// <param name="_Control">Web控件</param>
        protected void SetControlReadOnly(Control _Control, bool isShow)
        {
            if (_Control is WebControl)
            {
                WebControl __Control = (WebControl)_Control;
                if (isShow)
                    __Control.Attributes["style"] = "display:block";
                else
                    __Control.Attributes["style"] = "display:none";

            }
            else if (_Control is HtmlControl)
            {
                HtmlControl __Control = (HtmlControl)_Control;
                if (isShow)
                    __Control.Attributes["style"] = "display:block";
                else
                    __Control.Attributes["style"] = "display:none";
            }
        }
        #endregion

        #region 通用方法
        public void Alert(string message)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language='javascript'>alert('" + message + "');</script>");
        }

        /// <summary>
        /// 显示IE浏览器端的对话框
        /// </summary>
        /// <param name="Message">信息</param>
        /// <param name="page">源页面</param>
        /// <param name="IsClose">是否关闭窗口</param>
        public void MessageBox(string Message, System.Web.UI.Page page, bool IsClose)
        {
            Type cstype = page.GetType();
            if (IsClose)
            {
                page.ClientScript.RegisterStartupScript(cstype, "MessageBox", string.Format("<script>alert('{0}');top.window.opener=null;top.window.close();</script>", Message));
            }
            else
            {
                page.ClientScript.RegisterStartupScript(cstype, "MessageBox", string.Format("<script>alert('{0}');</script>", Message));
            }
        }

        public void Confirm(string message)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language='javascript'>return window.confirm('" + message + "');</script>");
        }

        protected void CloseWindow(string sParentUrl)
        {
            string sScript = "<script language=javascript>\n";
            sScript += "window.close();\n";
            if (sParentUrl != "")
            {
                sScript += "window.opener.location.href=\"" + sParentUrl + "\"";
            }
            sScript += "</script>";
            ClientScript.RegisterStartupScript(this.GetType(), "close", sScript);
        }

        public void GoToUrl(string goUrl)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "location", "<script language='javascript'>window.location.href='" + goUrl + "';</script>");
        }

        public void OpenWindow(string url)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "<script language='javascript'>window.open('" + url + "');</script>");
        }

        public void AlertGoUrl(string alertMessage, string goUrl)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language='javascript'>alert('" + alertMessage + "');window.location.href='" + goUrl + "';</script>");
        }

        public void AlertAndBack(string alertMessage)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language='javascript'>alert('" + alertMessage + "');window.history.back();';</script>");
        }

        public void CloseWindowOK()
        {
            ClientScript.RegisterStartupScript(this.GetType(), "CloseWindowOK", "<script language='javascript'>window.opener='abc';window.returnValue=true;window.close();</script>");
        }

        public void GoUrl(string message)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "CloseWindowOK", "<script language='javascript'>window.alert('" + message + "');</script>");
        }

        #region RegClientScript
        /// <summary>
        /// 向客户端浏览器注册脚本
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="script">脚本代码</param>
        protected void RegClientScript(string key, string script)
        {
            string scr = "<script language='javascript'>" + script + "</script>";
            ClientScriptManager client = Page.ClientScript;
            System.Type cstype = Page.GetType();
            if (!client.IsClientScriptBlockRegistered(key))
                client.RegisterClientScriptBlock(cstype, key, scr);
        }
        #endregion

        #endregion


    }
}

你可能感兴趣的:(page)