本文主要是介绍Petshop4.0 超级详细介绍(一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Petshop4.0 超级详细介绍(一)
今天辞职了,看了一下 petshop4.0, 通俗的把代码解释一下 , 希望能给初学者提供一些帮助,写的不好的地方还请大家理解!现在开始吧。
我们从启始页 Default.aspx 开始 , 微软的启始页当然是 Default.aspx 啦,该页面有一个用户控件 NavigationControl 先来说说它,从简单入手嘛 。
从它的 Page_Load事件开始:
protected void Page_Load(object sender, EventArgs e)
{
GetControlStyle();//设置<td>的样式,在webconfig中已经配置了网站的全局样式App_Themes中有它的详细配置资料,在这里进行样式的选择
BindCategories();//这里对Repeater控件进行了绑定,请看BindCategories()方法;
//让它选择了连接会变颜色
string categoryId = Request.QueryString["categoryId"];
if (!string.IsNullOrEmpty(categoryId))
SelectCategory(categoryId);
//对网站采用缓存处理,这里可以查看,说的很清楚
http://blog.csdn.net/sunchaohuang/archive/2007/07/18/1697435.aspx过程如下
DependencyAccess -> TableDependency -> IPetShopCacheDependency
this.CachePolicy.Dependency = DependencyFacade.GetCategoryDependency();
}
private void BindCategories() {
Category category = new Category();//这里调用BLL(业务逻辑层),对产品的类别进行处理
repCategories.DataSource = category.GetCategories();
//这个方法返回一个 IList <CategoryInfo>它的类型为CategoryInfo位于Model项目中该项目有点像与数据库中相对应的表用来放数据便于对数据处理, 使用Ilist将许多CategoryInfo实例放进去
repCategories.DataBind();
//这样Repeater控件的绑定就完成了
}
private static readonly ICategory dal = PetShop.DALFactory.DataAccess.CreateCategory();
//数据抽象工厂不能继承此类 ,相对应的方法,这样做可以实现动态创建类和调用类型的功能:
public static PetShop.IDAL.ICategory CreateCategory() {
string className = path + ".Category";
return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);
//这里返回的是SQLServerDAL.Category它继承了 Icategory 接口因此要实现 GetCategories()与GetCategory()方法
}
//这里调用SQLServerDAL.Category.GetCategories()方法
public IList<CategoryInfo> GetCategories() {
return dal.GetCategories();
}
//SQLServerDAL.Category.GetCategories()方法
public IList<CategoryInfo> GetCategories() {
IList <CategoryInfo> categories = new List<CategoryInfo>();
//使用using对 SqlDataReader 自动释放
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CATEGORIES, null)) {
while (rdr.Read()) {
CategoryInfo cat = new CategoryInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2));
categories.Add(cat);
}
}
return categories;
}
今天下午找了个跑业务的工作哈哈,明天晚上继续,如果有哪些不对的地方还请大家指出。
这篇关于Petshop4.0 超级详细介绍(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!