我的代码,写的pagebase。还是留着吧,是这套cms的核心了。语义化,与我的云平台一样,只不过云平台是用js写的。这个是webform.下回写mvc吧。核心很简单。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using JGDJWeb.Helper;
using JGDJWeb.Model;
namespace JGDJWeb.Extensions {
public abstract class PageBase:System.Web.UI.Page {
protected PageBase()
{
}
protected void BindModule(Page page, Action<Repeater, string> bindSingRpt) {
BindControls(page, "List_", bindSingRpt);
}
protected void BindControls(Page page, String prefix, Action<Repeater, string> bindSingControl) {
var controlList = page.Controls;
foreach (Control control in controlList) {
if (control.ID != null && control.ID.StartsWith(prefix) && control is Repeater) {
var suffix = control.ID.Split(‘_‘)[1];
if (prefix == "List_")
bindSingControl(control as Repeater, suffix);
}
}
}
protected void Bind(string className, HtmlAnchor anchor, Repeater repeater, int count) {
try {
using (var context = new JGDJEntities()) {
var classNo = context.JY_News_Classs.Where(n => n.ClassCName == className).First().ClassNo;
var newss = Common.GetNewsListByCNo(Encrypt.MD5Encrypt(classNo));
if (anchor != null) {
anchor.HRef = "/List.aspx?ClassNo=" + Encrypt.MD5Encrypt(classNo);
}
repeater.DataSource = newss.Take(count);
repeater.DataBind();
}
} catch (Exception e) { }
}
#region 网站访问量
protected void pageviews() {
int count = 0;
//数据累加
int Stat = 0;
StreamReader srd;
//取得文件的实际路径
string file_path = Server.MapPath("/XML/counter.txt");
//打开文件进行读取
srd = File.OpenText(file_path);
while (srd.Peek() != -1) {
string str = srd.ReadLine();
count = int.Parse(str);
}
srd.Close();
// 在新会话启动时运行的代码
Application.Lock();
//获取Application对象中保存的网站总访问量
Stat = count;
Stat += 1;
object obj = Stat;
Application["counter"] = obj;
//将数据记录写入文件
StreamWriter srw = new StreamWriter(file_path, false);
srw.WriteLine(Stat);
srw.Close();
Application.UnLock();
}
#endregion
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。