项目中常用封装方法(信息提示、权限验证、数据连接验证)-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

项目中常用封装方法(信息提示、权限验证、数据连接验证)

简介: 1、常用信息提示方法类 using System; using System.Collections.Generic; using System.

1、常用信息提示方法类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Web.SessionState;

namespace ECS.Utility
{
    public class JScript
    {
        protected static HttpResponse Response;
        protected static HttpSessionState Session;
        public JScript()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowAlert(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>alert('" + msg + "');</script>");
        }

        /// <summary>
        /// 注册脚本提示信息
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="script">注册的脚本</param>
        public static void ShowAlert(System.Web.UI.Page page, string msg, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>alert('" + msg + "'); " + script + "</script>");
        }

        /// <summary>
        /// 刷新页面并且弹出提示信息
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowRefresh(System.Web.UI.Page page, string msg)
        {

            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>location.reload();alert('" + msg + "。');</script>");
        }

        /// <summary>
        /// 刷新页面并且弹出提示信息并注册脚本
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowRefresh(System.Web.UI.Page page, string msg, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>location.reload();" + script + "</script>");
        }

        /// <summary>
        /// 刷新父页面并且弹出提示信息
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowParentRefresh(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>parent.location.reload();alert('" + msg + "。');</script>");
        }

        /// <summary>
        /// 刷新父页面后提示信息执行脚本
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="script">注册脚本</param>
        public static void ShowParentRefresh(System.Web.UI.Page page, string msg, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>parent.location.reload();alert('" + msg + "。');" + script + "</script>");
        }




        /// <summary>
        ///  注册脚本
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="script">注册的脚本</param>
        public static void ShowRegisterScript(System.Web.UI.Page page, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "<script>" + script + "</script>");
        }



        /// <summary>
        /// 弹出JavaScript小窗口
        /// </summary>
        /// <param name="js">窗口信息</param>
        public static void Alert(string message)
        {
            message = StringUtil.DeleteUnVisibleChar(message);
            string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
            HttpContext.Current.Response.Write(js);
        }


        /// <summary>
        /// 弹出JavaScript小窗口,并转向指定的页面
        /// </summary>
        /// <param name="message">弹出信息</param>
        /// <param name="toURL">专转向的网页</param>
        public static void AlertAndRedirect(string message, string toURL)
        {
            string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
        }

        public static void Redirect(string toURL)
        {
            string js = "<script language=javascript>window.location.replace('{0}')</script>";
            HttpContext.Current.Response.Write(string.Format(js, toURL));
        }

        /// <summary>		
        /// 函数名:GotoParentWindow	
        /// 功能描述:返回父窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-04-30 10:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="parentWindowUrl">父窗口</param>		
        public static void GotoParentWindow(string parentWindowUrl, string Msg)
        {
            string js = @"<Script language='JavaScript'> this.parent.location.replace('../" + parentWindowUrl + "');" + Msg + "</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>
        /// 刷新窗口
        /// </summary>
        public static void Refresh()
        {
            string js = @"<Script language='JavaScript'>
                    window.location.href=window.location.href;
                  </Script>";
            HttpContext.Current.Response.Write(js);
        }
    }
}


 

2、页面权限校验

    /// <summary>
    /// 判断权限
    /// </summary>
    /// <param name="DisplayName">权限名称</param>
    public static void MyRole(string DisplayName)
    {
        bool bfg = false;
        IYUEJIE.Model.A_AdminUser AdminUserModel = HttpContext.Current.Session["AdminUser"] as IYUEJIE.Model.A_AdminUser;//得到登录LoginId
        DataTable dt = new DBHelper().GetDataSet("SELECT * FROM  View_SysRoleList where  RoleID='" + AdminUserModel.RoleId + "' and [Custom

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章