`
冷寒冰
  • 浏览: 252686 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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


    }
}
分享到:
评论

相关推荐

    asp.net 接口(interface)例子

     BasePage中存放了页面的公用资料  Default继承BasePage,并使用IProgramer类库 IProgramer类库:  InterfaceTest 被页面使用的接口  clsVBProgramer 继存接口InterfaceTest ,实现一种功能  ...

    P127~134C++类和对象继承学习笔记.docx

    例如,在上面的例子中,我们可以使用BasePage类的公共方法header()、footer()和left(),而不需要在每个页面类中重复编写这些方法。 继承的好处: 1. 降低代码耦合度:继承可以降低类之间的耦合度,使得代码更加...

    Python+Selenium使用Page Object实现页面自动化测试

    在这个例子中,`TestLoginPage`包含了登录功能的测试用例。`setUp`方法用于初始化`BasePage`类的实例,`test_login_success`方法调用了Page Object提供的方法来完成登录操作并验证登录是否成功。 总的来说,结合...

    auto_framework_demo_screenshot.zip

    在这个例子中,`LoginPage`类继承了`BasePage`,并定义了与登录页面交互的方法。这样,即使页面元素的定位发生改变,我们只需修改对应页面类中的代码,而不会影响其他部分。 "auto_framework_demo"可能是压缩包内的...

    Xamarin.Forms.Breadcrumb:这是一个完全自动的面包屑导航控件,并使用导航堆栈和页面标题来生成面包屑

    基本例子生产实例如何使用它? 将安装到共享项目中Install-Package Xamarin.Forms.Breadcrumb要添加到页面,我们要做的第一件事是告诉XAML页面可以在何处找到面包屑控件,这是通过向ContentPage添加以下属性来完成...

    python+selenium+ddt关键字驱动搭建自动化测试框架(csdn)————程序.pdf

    在这个例子中,Python作为主要的编程语言,用来编写测试脚本和实现自动化测试框架。 2. Selenium:Selenium 是一个强大的Web应用程序自动化测试工具,它可以模拟用户与浏览器的交互,如点击按钮、填写表单等。在这...

    Tapestry教程

    在这个例子中,`Login.page`声明了三个抽象属性:`userName`、`passWord`和`message`,这些属性将在`Login.java`中实现。`page-specification`标签指定了页面的Java类,`description`标签用于添加页面的描述,而`...

    C#基础类库

    序列化帮助类,还有例子 SerializeHelper 序列化帮助类,Xml序列化,Json序列化,SoapFormatter序列化,BinaryFormatter序列化 27.压缩解压缩 SharpZip 28.验证码 YZMHelper Captcha 验证码类,一个很个性的...

    C#基类库(苏飞版)

    序列化帮助类,还有例子 SerializeHelper 序列化帮助类,Xml序列化,Json序列化,SoapFormatter序列化,BinaryFormatter序列化 27.压缩解压缩 SharpZip 28.验证码 YZMHelper Captcha 验证码类,一个很个性的...

Global site tag (gtag.js) - Google Analytics