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);
//對網站採用緩存處理,這裏可以查看,說的很清楚
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;
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章