当前位置:编程学习 > asp >>

步步为营 .NET三层架构解析 五、DAL与IDAL的设计

IDAL:数据访问层接口,接口是一种系列‘功能’的声明或名单,接口没有实现细节.
IDAL的作用是把访问数据的实现与客户端分开,符合“Program to an inte易做图ce, not an implementation”的设计原理,这样
1。客户端不依赖于DAL的具体实现的类
2。可以通过工厂类/配置设置改换具体实现的类(譬如从Oracle到SQLServer)
DAL:数据访问层,主要用来做数据逻辑处理,具体为业务逻辑层或表示层提供数据服务。
先来看下IDAL的设计:

ICustom.cs

view sourceprint?public inte易做图ce ICustom 

   { 

       /// <summary> 

       /// 添加一条记录 

       /// </summary> 

       /// <param name="Custom"></param> 

       /// <returns></returns> 

       int Addcustom(custom Custom); 

       /// <summary> 

       /// 概据帐户名获取用户的信息 

       /// </summary> 

       /// <param name="nename"></param> 

       /// <returns></returns> 

       custom Getsinglecname(string nename); 

       /// <summary> 

       /// 更样用户的密码 

       /// </summary> 

       /// <param name="Custom"></param> 

       void Updatepassword(custom Custom); 

       /// <summary> 

       /// 获取用户列表 

       /// </summary> 

       /// <returns></returns> 

       List<custom> Getcustom(); 

       /// <summary> 

       /// 根据ID删除用户记录 

       /// </summary> 

       /// <param name="nid"></param> 

       void Deletecustom(int nid); 

       /// <summary> 

       /// 根据ID获取用户信息 

       /// </summary> 

       /// <param name="nid"></param> 

       /// <returns></returns> 

       custom Getcustomer(int nid); 

       /// <summary> 

       /// 更新用户信息 

       /// </summary> 

       /// <param name="Custom"></param> 

       void updatecustom(custom Custom); 

       /// <summary> 

       /// 根据部门ID获取部门员工列表 

       /// </summary> 

       /// <param name="nid"></param> 

       /// <returns></returns> 

       List<custom> Getdepartcustom(int nid);
view sourceprint?}

与之想对应的customSQL.cs设计:

view sourceprint?public class customSQL:ICustom 

   { 

 

       public int Addcustom(custom Custom) 

       { 

           SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); 

           SqlParameter[] ParamList = { 

              sqlHelper.CreateInParam("@cname",SqlDbType.NVarChar,50,Custom.cname), 

              sqlHelper .CreateInParam("@departID",SqlDbType.Int ,4,Custom.departID), 

              sqlHelper .CreateInParam("@age",SqlDbType.Int,4,Custom.age), 

              sqlHelper.CreateInParam("@ename",SqlDbType.NVarChar,50,Custom.ename), 

              sqlHelper.CreateInParam("@password",SqlDbType.NVarChar,50,Custom.password) 

          }; 

           try

           { 

               return (sqlHelper.RunProc("spInsertCustom", ParamList)); 

           } 

           catch (Exception ex) 

           { 

               SystemError.CreateErrorLog(ex.Message); 

               throw new Exception(ex.Message, ex); 

           } 

 

       } 

       public custom Getsinglecname(string nename) 

       { 

           SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); 

           SqlParameter[] Paramlist = { 

          sqlHelper.CreateInParam("ename",SqlDbType.NVarChar,50,nename) 

            

          }; 

           SqlDataReader dr = null; 

           try

           { 

               sqlHelper.RunProc("spGetsingleename", Paramlist, out dr); 

           } 

           catch (Exception ex) 

           { 

               SystemError.CreateErrorLog(ex.Message); 

   &

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,