📄 basepage.cs
字号:
using System;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Diagnostics;
using System.Configuration;
using Botheighten.Yanghui.BusinessFacade;
using Botheighten.Yanghui.BusinessRules;
using Botheighten.Yanghui.Framework;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace Botheighten.Yanghui.Web
{
/// <summary>
/// BasePage 的摘要说明。
/// </summary>
public class BasePage : System.Web.UI.Page
{
protected bool validate=true;
protected bool DemoCheck=true;
public BasePage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool DefaultValidate
{
get
{
return this.validate;
}
set
{
this.validate=value;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//验证权限
if(validate)
{
if (!this.IsPostBack )
{
if (Session ["User"] == null)
{
Response.Write(@"<script>parent.location='"+Request.ApplicationPath + "/" + g.LOGIN_PAGE+"'</script>");
}
else
{
//this.validate=true;
// Principal p = (Principal) Session["User"];
// string page = Request.FilePath.Substring (Request.ApplicationPath.Length );
// if (!p.HasPermission (page))
// {
// Response.Redirect (Request.ApplicationPath + "/" + g.ERROR_PAGE );
// }
}
}
}
//初始化数据库连接
if(Application["DatabaseSetting"]==null || Application["DatabaseSetting"].ToString()!="Y")
{
string applicationPath=Request.ApplicationPath;
if(applicationPath=="")
applicationPath="/";
if(!applicationPath.EndsWith("/"))
applicationPath +="/";
string DatabaseXml=applicationPath + ConfigurationSettings.AppSettings["DatabaseConfig"].ToString();
DatabaseSetting.SettingDatabase(Server.MapPath(DatabaseXml));
Application["DatabaseSetting"]="Y";
}
//激活访问
if(this.DemoCheck)
{
if(Application["Author"]==null || Application["Author"].ToString()!="Y")
{
string cpuId="";
try
{
cpuId=Enc.GetCPUInfo();
}
catch
{
Response.Redirect(Request.ApplicationPath +"/Security.aspx",true);
}
if(Enc.IsAuthor(cpuId))
{
Application["Author"]="Y";
}
else
{
if( Application["Demo"]==null || Application["Demo"].ToString()!="Y")
{
Response.Redirect(Request.ApplicationPath + "/Demo.aspx",true);
}
else
{
// Config config=ConfigSystem.GetConfig();
// if(config!=null)
// {
// string userDate=Enc.Decrypt(config.UserDate,Enc.EncKey(Enc.GetCPUInfo()));
// if(DateTime.Parse(userDate).AddDays(30)<System.DateTime.Now)
// {
// Application["Expire"]="Y";
// Response.Redirect(Request.ApplicationPath + "/Demo.aspx",true);
// }
// }
}
}
}
}
//获取有关Application配置信息
//公司名称 和每页显示信息条数
if(Application["CompanyInfo"]==null || Application["PageSize"]==null)
{
Config config=ConfigSystem.GetConfig();
if(config!=null)
{
if(config.CompanyName!=null)
Application["CompanyInfo"]=config.CompanyName;
else
Application["CompanyInfo"]="";
Application["PageSize"]=config.PrintCount;
}
else
{
Application["CompanyInfo"]="";
Application["PageSize"]=20;
}
}
//每页显示条数
this.Load += new System.EventHandler(this.BasePage_Load);
this.Error +=new System.EventHandler(this.BasePage_Error);
}
protected void BasePage_Error(object sender,System.EventArgs e)
{
string errMsg;
Exception currentError=Server.GetLastError();
errMsg = "<link rel=\"stylesheet\" href=\""+Request.ApplicationPath+"/Styles/Site.css\">";
errMsg += "<h1>页面出错[Page Error]</h1><hr/>本页发生一个异常 系统管理员请注意." +
"请联系我们以便更好的解决此问题" +
".<br/>"+
"An unexpected error has occurred on this page.The system administrators have been notified.Please feel free to contact us with the information surrounding this error."+
"<br/>"+
"页面发生于[The error occurred in]: "+Request.Url.ToString()+"<br/>"+
"出错信息[Error Message]: <font class=\"Alert\">"+ currentError.Message.ToString() + "</font><br/>"+
"引发异常的方法[Error Method]:"+currentError.TargetSite.ToString()+"<hr/>"+
"<b> 堆栈跟踪[Stack Trace]:</b><br/>"+
currentError.ToString();
//具体的错误事件处理
//建议记录进Error.Log文件
// if ( !(currentError is AppException) )
// {
// // It is not one of ours, so we cannot guarantee that it has been logged
// // into the event log.
// //LogEvent( currentError.ToString(), EventLogEntryType.Error );
//
// }
Response.Write( errMsg );
Server.ClearError();
}
protected void GoBackFunction(System.Web.UI.WebControls.Button btnBack)
{
if (!this.IsPostBack)
{
ViewState["Count"]="-1";
btnBack.Attributes.Add("onclick","history.go("+ViewState["Count"].ToString()+");return false;");
}
if (this.IsPostBack)
{
ViewState["Count"]=int.Parse(ViewState["Count"].ToString())-1;
btnBack.Attributes.Add("onclick","history.go("+ViewState["Count"]+");return false;");
}
}
private void BasePage_Load(object sender,System.EventArgs e)
{
//获取当前应用项目名称
//定义CSS文件引用
string cssFile="<link rel=\"stylesheet\" href=\""+Request.ApplicationPath+"/Styles/Site.css\">";
Response.Write (cssFile);
}
/// <summary>
/// 返回当前登陆用户
/// </summary>
/// <returns>Principal对象</returns>
protected Principal CurrentUser ()
{
if (Session ["User"] != null)
{
return (Principal)Session["User"];
}
else
{
Response.Write(@"<script>parent.location='"+Request.ApplicationPath + "/" + g.LOGIN_PAGE+"'</script>");
return null;
}
}
protected void ReponseWriteDeleteScript()
{
Response.Write(@"<script language='javascript'>
<!--
function Delete()
{
return confirm('"+"您确定要删除记录吗?"+@"');
}
//-->
</script>");
}
protected void CheckPermissionPage(string userId,string IsSuper,string per)
{
if(!LoginSystem.CheckPermission(userId,IsSuper,per))
{
//Response.Write(@"<script>parent.location='"+Request.ApplicationPath + "/" + g.LOGIN_PAGE+"'</script>");
Response.Write("<table width='80%' border=0><tr><td align='center'><font color='red'>您没有此管理权限,请跟超级管理员联系!</font></td></tr></table>");
Response.End();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -