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

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: 在此处添加构造函数逻辑
            //
        }

        /// 
        /// 提示信息
        /// 
        /// this
        /// 提示信息
        public static void ShowAlert(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "");
        }

        /// 
        /// 注册脚本提示信息
        /// 
        /// this
        /// 提示信息
        /// 注册的脚本
        public static void ShowAlert(System.Web.UI.Page page, string msg, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "");
        }

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

            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "");
        }

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

        /// 
        /// 刷新父页面并且弹出提示信息
        /// 
        /// this
        /// 提示信息
        public static void ShowParentRefresh(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "");
        }

        /// 
        /// 刷新父页面后提示信息执行脚本
        /// 
        /// this
        /// 提示信息
        /// 注册脚本
        public static void ShowParentRefresh(System.Web.UI.Page page, string msg, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "msg", "");
        }




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



        /// 
        /// 弹出JavaScript小窗口
        /// 
        /// 窗口信息
        public static void Alert(string message)
        {
            message = StringUtil.DeleteUnVisibleChar(message);
            string js = @"";
            HttpContext.Current.Response.Write(js);
        }


        /// 
        /// 弹出JavaScript小窗口,并转向指定的页面
        /// 
        /// 弹出信息
        /// 专转向的网页
        public static void AlertAndRedirect(string message, string toURL)
        {
            string js = "";
            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
        }

        public static void Redirect(string toURL)
        {
            string js = "";
            HttpContext.Current.Response.Write(string.Format(js, toURL));
        }

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

        /// 
        /// 刷新窗口
        /// 
        public static void Refresh()
        {
            string js = @"";
            HttpContext.Current.Response.Write(js);
        }
    }
}


 

2、页面权限校验

    /// 
    /// 判断权限
    /// 
    /// 权限名称
    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_DisplayName]='" + DisplayName + "'");
        if (dt.Rows.Count > 0)
        {
            bfg = true;
        }
        else
        {
            bfg = false;
        }

        if (bfg == false)
        {
            HttpContext.Current.Session["AdminUser"] = null;
            IYUEJIE.Utility.JScript.GotoParentWindow("../AdminWeb/login.aspx", "alert('你没有权限或者非法操作,请重新登录。');");

        }
    }


 

3、数据库连接校验

if (DBHelper.IsOpen() == false)
        {
            JScript.ShowAlert(this, "系统无法连接数据库服务器,请联系管理员!");
            return;
        }

    public static bool IsOpen()     {

        bool IsOpen = false;         SqlConnection _SqlConnection = new SqlConnection(str);         try         {             _SqlConnection.Open();             IsOpen = true;         }         catch (Exception)         {

            IsOpen = false;

        }         finally         {             _SqlConnection.Close();         }

        return IsOpen;     }


 

你可能感兴趣的:(技术日记,常用方法,DotNet+C#)