📄 pagebase.cs
字号:
using System;
using System.Web;
using System.Web.UI;
using System.Web.SessionState;
using System.Diagnostics;
using qminoa.Common;
using qminoa.Common.Data;
using qminoa.DA;
namespace qminoa.Webs
{
/// <summary>
/// 页面基类
/// </summary>
public class PageBase : System.Web.UI.Page
{
#region 构造函数
/// <summary>
/// 空构造函数
/// </summary>
public PageBase()
{
}
#endregion
#region 属性
/// <summary>
/// 登录ID
/// </summary>
// public string Loginid = "";
/// <summary>
/// 员工号:唯一标识当前用户
/// </summary>
public string Empid = "-1";
/// <summary>
/// 当前员工姓名
/// </summary>
public string EmpName="";
/// <summary>
/// 功能名称
/// </summary>
public string FunName="";
/// <summary>
/// 窗体功能代码
/// </summary>
public string FunctionName
{
get
{
return GetViewState("FunctionName");
}
set
{
SetViewState("FunctionName",value);
}
}
/// <summary>
/// 权限代码
/// </summary>
public int EmpRightCode
{
get
{
try
{
return CheckAuth();
}
catch(NullReferenceException)
{
return -1;
}
}
}
#endregion
#region 方法
/// <summary>
/// 从ViewState中获取某个属性的值。如果该属性不存在,返回空字符串。
/// </summary>
/// <param name="PropertyName">属性名称</param>
/// <returns>属性值(属性不存在时返回空字符串)</returns>
public string GetViewState(string PropertyName)
{
try
{
return ViewState[PropertyName].ToString() ;
}
catch(NullReferenceException)
{
return "";
}
}
/// <summary>
/// 设置ViewState中某个属性的值
/// </summary>
/// <param name="PropertyName">属性名称</param>
/// <param name="PropertyValue">属性值</param>
public void SetViewState(string PropertyName, string PropertyValue)
{
ViewState[PropertyName]=PropertyValue;
}
/// <summary>
/// 权限检验函数
/// </summary>
/// <returns>int</returns>
public int CheckAuth()
{
int _empid = Convert.ToInt16(this.Empid);
string _funcname = this.FunName;
CheckEmpRight myCheckAuth_DA = new CheckEmpRight();
return myCheckAuth_DA.GetEmpRight(_empid,_funcname);
}
/// <summary>
/// 给定模块名称,权限检验函数
/// </summary>
/// <returns>int</returns>
public int CheckAuth(string funcname)
{
int _empid = Convert.ToInt16(this.Empid);
CheckEmpRight myCheckAuth_DA = new CheckEmpRight();
return myCheckAuth_DA.GetEmpRight(_empid,funcname);
}
/// <summary>
/// 页面初始函数
/// </summary>
/// <param name="fName">模块名称</param>
/// <param name="isChecked">是否验证</param>
public void PageBegin(string fName,bool isChecked)
{
//--------------------------------------------
//设定页面入口的模块名称。没有为空。
//如果本页不定义,一定要从前一页确定。
if (ValidateUtil.isBlank(fName))
{
this.FunctionName=this.GetParaValue("FunctionName");
this.FunName =this.FunctionName;
}
else
{
this.FunName =fName ;
this.FunctionName =fName;
}
//---------------------------------------------
//读取当前用户
//第一步:获取用户唯一标识Empid
this.Empid=this.GetParaValue("EmpID");
this.EmpName =this.GetParaValue("username");
// this.Loginid=this.GetParaValue("LoginID");
//如果Empid为空,表示没有当前用户,则跳转至登录页面。
if (ValidateUtil.isBlank(this.Empid))
{
Response.Redirect(Application["vRoot"]+"/login.aspx");
}
//-----------------------------------------------------
//第二步:判断是否具有本页访问权限
if (isChecked && this.CheckAuth() == -1)
{
Response.Redirect(Application["vRoot"]+"/login.aspx");
}
}
/// <summary>
/// 记录操作日志
/// </summary>
/// <param name="operation">操作描述</param>
public void WriteOptLog(string operation)
{
//创建登录信息数据结构
LogData mylogdata = new LogData();
//调用数据访问层操作日志服务
LogDB LogDataAccess = new LogDB();
//填写操作日志信息
mylogdata.OperatorID = this.Empid;
mylogdata.OperatorName = this.EmpName;
mylogdata.OperateTime = DateTime.Now.ToString();
mylogdata.FuncName = this.FunName;
mylogdata.OperationDescription = operation;
//记录操作日志
LogDataAccess.WriteOperationLog(mylogdata);
}
/// <summary>
/// 获取页面参数的值
/// </summary>
/// <param name="oSession">Page.Session</param>
/// <param name="oRequest">Page.Request</param>
/// <param name="paraName">参数名称</param>
/// <returns>参数值,字符串形式</returns>
public string GetParaValue(HttpSessionState oSession, HttpRequest oRequest,string paraName)
{
string strValue="";
//如果Session中能够找到相应的参数值,则返回参数值
try
{
strValue=oSession[paraName].ToString();
}
catch(NullReferenceException)
{
strValue="";
}
//如果Session中不存在,从Request中寻找。
if (ValidateUtil.isBlank(strValue))
{
try
{
strValue=oRequest[paraName].ToString();
}
catch(NullReferenceException)
{
strValue="";
}
//均为空时,返回空字符串。
if (ValidateUtil.isBlank(strValue))
strValue="";
}
return strValue;
}
/// <summary>
/// 获取页面参数的值
/// </summary>
/// <param name="paraName">参数名称</param>
/// <returns>参数值,字符串形式</returns>
public string GetParaValue(string paraName)
{
return GetParaValue(Session,Request,paraName);
}
#endregion
#region 事件处理
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new System.EventHandler(this.PageBase_Load);
this.Error += new System.EventHandler(this.PageBase_Error);
}
protected void LogEvent(string message, EventLogEntryType entryType)
{
//EventLog提供与Windows事件日志的交互
//如果事件源hotop100没有在计算机中注册,则创建事件源
if (!EventLog.SourceExists("hotop100"))
{
EventLog.CreateEventSource("hotop100", "Application");
}
//将错误日志信息写入Windows事件日志中
EventLog.WriteEntry("hotop100", message, entryType);
}
protected void PageBase_Error(object sender, System.EventArgs e)
{
string errMsg;
//得到系统上一个异常
Exception currentError = Server.GetLastError();
errMsg = "<link rel=\"stylesheet\" href=\"/default.css\">";
errMsg += "<h1>页面错误</h1><hr/>此页面发现一个意外错,对此我们非常抱歉。"+
"此错误消息已信息了系统管理员,请及时联系我们,我们会及时解决此问题! <br/>" +
"错误发生位置: "+Request.Url.ToString()+"<br/>"+
"错误消息: <font class=\"ErrorMessage\">"+ currentError.Message.ToString() + "</font><hr/>"+
"<b>Stack Trace:</b><br/>"+
currentError.ToString();
//如果发生致命应用程序错误
if ( !(currentError is ApplicationException) )
{
//向Windows事件日志中写入错误日志
LogEvent( currentError.ToString(), EventLogEntryType.Error );
}
//在页面中显示错误
Response.Write( errMsg );
//清除异常
Server.ClearError();
}
private void PageBase_Load(object sender, System.EventArgs e)
{
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -