菜鸟学PetShop一

  category

BLL 中声明了一个 ICATEGORY 对象,
private static readonly ICategory dal = PetShop.DALFactory.DataAccess.CreateCategory();
声明了一个实例,调用的是DALFactory中的CreateCategory()方法。
然后下面用了泛形的方法。
public IList<CategoryInfo> GetCategories() {
            return dal.GetCategories();
        }
将类型转化为CategoryInfo类型的方法。
而dal实际上是哪个类的实例呢,就得看createCategory()
定义如下:
public static PetShop.IDAL.ICategory CreateCategory() {
            string className = path + ".Category";
            return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);
        }
(PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className); 这句话据说是利用反射创建了一个实例。
而path是什么呢。找一下web.config就可以了。
private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];
找一下WEBDAL就可以了。
< add key = "WebDAL"value="PetShop.SQLServerDAL"/>
所以path就得出来了,看className的值吧。
className=PetShop.SQLServerDAL.Category
于是 return dal.GetCategories(); 这句话返回的是className的实例,而方法就是这个类中的方法,并把返回类型转化为<CategoryInfo>类型。细看一下这个类下面的这个方法的定义。
   public IList<CategoryInfo> GetCategories() {
           IList<CategoryInfo> categories = new List<CategoryInfo>();
            //Execute a query to read the categories
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;
        }
这个里面又牵涉到了SqlHelper的内容,
SqlHelper 位于Dbutility中用来对数据库进行操作,先看一下SqlHelper.ConnectionStringLocalTransaction的内容是什么,肯定是一个静态的变量public static readonly string ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["SQLConnString1"].ConnectionString;可见又是放在web.config中间了,找找看,只找到这么一句并没有找到连接字符串。<addname="MSPetShop4"connectionStringName="SQLConnString1"pollTime="10000"/>再找找
<add name="SQLConnString1" connectionString="server=.;database=MSPetShop4;user id=mspetshop;password=pass@word1;min pool size=4;max pool size=4;"
   providerName="System.Data.SqlClient" />
找到了,操作是数据库MSPetShop4 原来微软还把web.config给加密了,不过也提供了一个解密工具,DecryptWebConfig.bat,于是一切都明了了。 SQL_SELECT_CATEGORIES 是声明的一个字符串常量,private const string SQL_SELECT_CATEGORIES = "SELECT CategoryId, Name, Descn FROM Category";
一切又来到了 return dal.GetCategories(); 再看看外面如何与BLL联系吧。
在NavigationControl.ascx自定义控件中绑定了category方法如下:
   private void BindCategories() {
            Category category = new Category();
            repCategories.DataSource = category.GetCategories();
            repCategories.DataBind();           
        }
于是总算完了绑定种类到repeater控件上。这里面共牵涉到几个项目如下:
BLL,SQLserverDAL,DButility,Model,IDAL,DALFACTORY
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值