C#Page基础功能,⽤于各页⾯继承IBasePage.cs⽂件
///<summary>
///⽤于页⾯或⽤户控件
///</summary>
public interface IBasePage
{
///<summary>
///数据缓存类
///</summary>
DbCache CacheHelp { get; }
///<summary>
/
//页⾯视图,⽤于页⾯级别访问,模仿MVC
///</summary>
ViewDataDict ViewData { get; }
///<summary>
///获取DataTable.Rows,此⽅法不会出错异常
///</summary>
///<param name="pName">数据名称</param>
///<returns></returns>
DataRowCollection ViewDataRows(string pName);
///<summary>
/// 1:true否则false
/
//</summary>
///<param name="pName"></param>
///<returns></returns>
bool IsViewData(string pName);
///<summary>
/// URL参数类
writeline方法的作用///</summary>
UrlQuery UQ { get; }
///<summary>
///页⾯搜索关键词,搜索关键词是最基本功能,故在这⾥放⼀个字段
///</summary>
string searchStr { get; set; }
///<summary>
///权限使⽤次数
///</summary>
int UserFunCount { get; set; }
///<summary>
///数据库链接次数
///</summary>
int DbCount { get; set; }
///<summary>
///⽤与判断增加style,js等是否已重复添加
/
//</summary>
///<param name="pName"></param>
///<returns></returns>
TempListHandler TempList { get; }
}
BasePage.cs⽂件
///<summary>
///整站页⾯基础类
///</summary>
public class BasePage : System.Web.UI.Page, IBasePage
{
private static readonly DataRowCollection EmptyRows = new DataTable().Rows;
private DbCache cacheHelp;
private ViewDataDict viewData;
private ViewDataDict viewDataM;
private int userFunCount = 0;//权限使⽤次数
private int dbCount = 0;//数据库连接次数
private TempListHandler tempList;
protected bool IsOpenXingNengTongji = true;
#region搜索关键词
//private string _searchStr;
public string searchStr
{
get
{
//if (this._searchStr == null)
//{
// return string.Empty;
//}
return ViewData["keyword"].ToString();
}
set
{
/
/this._searchStr = value;
ViewData["keyword"] = value;
}
}
#endregion
#region将数据保存在页⾯控件⾥ ViewDataPage
///<summary>
///将数据保存在页⾯控件⾥
///</summary>
public string ViewDataPage
{
get
{
return Req.Form("__viewdatapage");
}
set
{
this.ClientScript.RegisterHiddenField("__viewdatapage", value);
//this.ClientScript.RegisterClientScriptBlock(this.GetType(), "__urlreferrer", "<input id=\"__urlreferrer\" name=\"__urlreferrer\" type=\"hidden\" value=\"" + value + "\" />");
}
}
#endregion
public BasePage()
{
cacheHelp = new DbCache();
viewData = new ViewDataDict();
viewDataM = new ViewDataDict("model_");
tempList = new TempListHandler();
}
private DateTime __time1;
private DateTime __time2;
private static int __i = 0;
#region跟根URL重写获取参数
/
//<summary>
///跟根URL重写获取参数
///</summary>
private UrlQuery _UQ;
protected override void OnInit(EventArgs e)
{
_UQ = new UrlQuery(true);
__time1 = DateTime.Now;
base.OnInit(e);
}
protected override void OnPreInit(EventArgs e)
{
//"OnPreInit".WriteLine();
base.OnPreInit(e);
}
#endregion
#region基本信息统计
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
//"Render".WriteLine();
base.Render(writer);
__i++;
__time2 = DateTime.Now;
TimeSpan ts = __time2 - __time1;
if (IsOpenXingNengTongji)
Response.Write(@"<div text-align:center;color:#ccc"">Number:" + __i + ", Time:" + ts.TotalMilliseconds + "ms, DB=" + this.dbCount + ",fun=" + this.userFunCount + "</div>"); }
#endregion
protected override void OnUnload(EventArgs e)
{
//"OnUnload".WriteLine();
base.OnUnload(e);
}
#region将搜索到的结果为醒⽬显⽰
///<summary>
///将搜索到的结果为醒⽬显⽰
///</summary>
///<param name="str"></param>
///<returns></returns>
public string ReplaceSearchText(object str)
{
if (searchStr == null || searchStr.Length == 0)
return str.ToString();
//return str.ToString().Replace(searchStr, "<strong style=\"color:#F00\">" + searchStr + "</strong>");
return Regex.Replace(str.ToString(), Regex.Escape(searchStr), "<strong style=\"color:#F00\">" + searchStr + "</strong>", RegexOptions.IgnoreCase);
}
#endregion
#region IBasePage 成员
///<summary>
///数据缓存类
///</summary>
public DbCache CacheHelp
{
get { return this.cacheHelp; }
}
///<summary>
/
//页⾯视图,⽤于页⾯级别访问,模仿MVC
///</summary>
public ViewDataDict ViewData
{
get { return this.viewData; }
}
///<summary>
///页⾯视图(Model),⽤于页⾯级别访问,模仿MVC
///</summary>
public ViewDataDict ViewDataM
{
get { return this.viewDataM; }
}
///<summary>
///获取DataTable.Rows,此⽅法不会出错异常
///</summary>
///<param name="pName"></param>
///<returns></returns>
public DataRowCollection ViewDataRows(string pName) {
DataTable dt = ViewData[pName] as DataTable;
if (dt == null)
{
return EmptyRows;
}
return dt.Rows;
}
public bool IsViewData(string pName)
{
return viewData[pName].ToString() == "1";
}
public UrlQuery UQ
{
get { return this._UQ; }
}
///// <summary>
///// 获取系统配置
///// </summary>
///// <param name="key"></param>
///// <returns></returns>
//public string SysConfig(string key)
//{
// return WConfigBLL.GetValue(key).ToString();
//}
public TempListHandler TempList
{
get { pList; }
}
public int UserFunCount
{
get { return this.userFunCount; }
set { this.userFunCount = value; }
}
public int DbCount
{
get { return this.dbCount; }
set { this.dbCount = value; }
}
#endregion
#region ITrace 成员
//private int dbConnectionCount;
///// <summary>
///// 数据库连接次数
///// </summary>
//public int DbConnectionCount
//{
// get
/
/ {
// return this.dbConnectionCount;
// }
// set
// {
// dbConnectionCount = value;
// }
//}
#endregion
#region获取或设置提交后返回的路径,若未指定,则是当前url
///<summary>
/
//获取或设置提交后返回的路径,若未指定,则是当前url
///</summary>
public string UrlReferrer
{
get
{
string s = Req.Form("___urlreferrer");
if (s.Length == 0)
{
s = ViewData["___urlreferrer"].ToString();
}
if (s.Length == 0)
{
s = Request.Url.ToString();
}
return s;
}
set
{
ViewData["___urlreferrer"] = value;
this.ClientScript.RegisterHiddenField("___urlreferrer", value);\" type=\"hidden\" value=\"" + value + "\" />"); }
}
#endregion
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论