IDAL:数据访问层接口,接口是一种系列‘功能’的声明或名单,接口没有实现细节.
DAL:数据访问层,主要用来做数据逻辑处理,具体为业务逻辑层或表示层提供数据服务。
先来看下IDAL的设计:
ICustom.cs
/// <param name="Custom"></param> |
int Addcustom(custom Custom); |
/// <param name="nename"></param> |
custom Getsinglecname( string nename); |
/// <param name="Custom"></param> |
void Updatepassword(custom Custom); |
List<custom> Getcustom(); |
/// <param name="nid"></param> |
void Deletecustom( int nid); |
/// <param name="nid"></param> |
custom Getcustomer( int nid); |
/// <param name="Custom"></param> |
void updatecustom(custom Custom); |
/// <param name="nid"></param> |
List<custom> Getdepartcustom( int nid); |
/// 把SqlDataReader转化成Custom |
/// <param name="dr"></param> |
custom ConvertDrToCustom(SqlDataReader dr); |
/// 把SqlDataReader转化成List Custom |
/// <param name="dr"></param> |
List<custom> ConvertDrToCustomList(SqlDataReader dr); |
与之想对应的customSQL.cs设计:
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) |
return (sqlHelper.RunProc( "spInsertCustom" , ParamList)); |
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) |
sqlHelper.RunProc( "spGetsingleename" , Paramlist, out dr); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
custom Custom = new custom(); |
Custom.id = Int32.Parse(dr[ "id" ].ToString()); |
Custom.cname = dr[ "cname" ].ToString(); |
Custom.ename = dr[ "ename" ].ToString(); |
Custom.departID = int .Parse(dr[ "departID" ].ToString()); |
Custom.password = dr[ "password" ].ToString(); |
Custom.age = int .Parse(dr[ "age" ].ToString()); |
public void Updatepassword(custom Custom) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@id" ,SqlDbType.Int,4,Custom.id), |
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) |
sqlHelper.RunProc( "spUpdatepassword" , ParamList); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public List<custom> Getcustom() |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
sqlHelper.RunProc( "spGetcustom" , out dr); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToCustomList(dr); |
public void Deletecustom( int nid) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] Paramlist = { |
sqlHelper.CreateInParam( "id" ,SqlDbType.Int,4,nid) |
sqlHelper.RunProc( "spDeletecustom" , Paramlist); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public custom Getcustomer( int nid) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] Paramlist = { |
sqlHelper.CreateInParam( "id" ,SqlDbType.Int,4,nid) |
sqlHelper.RunProc( "spGetcustomer" , Paramlist, out dr); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToCustom(dr); |
public void updatecustom(custom Custom) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@id" ,SqlDbType.Int,4,Custom.id), |
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.RunProc( "spupdatecustom" , ParamList); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public List<custom> Getdepartcustom( int nid) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] Paramlist = { |
sqlHelper.CreateInParam( "departID" ,SqlDbType.Int,4,nid) |
sqlHelper.RunProc( "spGetdepartcustom" , Paramlist, out dr); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToCustomList(dr); |
public custom ConvertDrToCustom(SqlDataReader dr) |
custom Custom = new custom(); |
departmentSQL DepartmentSQL = new departmentSQL(); |
department Department = new department(); |
Department = DepartmentSQL.Getsingledepartment(Int32.Parse(dr[ "departID" ].ToString())); |
Custom.id = Int32.Parse(dr[ "id" ].ToString()); |
Custom.ename = dr[ "ename" ].ToString(); |
Custom.cname = dr[ "cname" ].ToString(); |
Custom.age = Int32.Parse(dr[ "age" ].ToString()); |
Custom.departID = Int32.Parse(dr[ "departID" ].ToString()); |
Custom.departname = Department.departname; |
Custom.password = dr[ "password" ].ToString(); |
public List<custom> ConvertDrToCustomList(SqlDataReader dr) |
List<custom> Customlist = new List<custom>(); |
departmentSQL DepartmentSQL = new departmentSQL(); |
department Department = new department(); |
Department = DepartmentSQL.Getsingledepartment(Int32.Parse(dr[ "departID" ].ToString())); |
custom Custom = new custom(); |
Custom.id = Int32.Parse(dr[ "id" ].ToString()); |
Custom.ename = dr[ "ename" ].ToString(); |
Custom.cname = dr[ "cname" ].ToString(); |
Custom.age = Int32.Parse(dr[ "age" ].ToString()); |
Custom.departID = Int32.Parse(dr[ "departID" ].ToString()); |
Custom.departname = Department.departname; |
Custom.password = dr[ "password" ].ToString(); |
接下来再看IDepartment.cs的设计:
public interface IDepartment |
/// <param name="Department"></param> |
int Adddepartment(department Department); |
List<department> Getdepartment(); |
/// 把SqlDataReader转化为List Department |
/// <param name="dr"></param> |
List<department> ConvertDrToListDepartment(SqlDataReader dr); |
/// <param name="nid"></param> |
department Getsingledepartment( int nid); |
/// <param name="ndepartname"></param> |
department Getdepartmenter( string ndepartname); |
/// <param name="Department"></param> |
void Updatepartment(department Department); |
/// <param name="nid"></param> |
void Deletedepart( int nid); |
/// 把SqlDataReader转化为department |
/// <param name="dr"></param> |
department ConvertDrToDepartment(SqlDataReader dr); |
与之相对应的departmentSQL.cs的设计:
public class departmentSQL:IDepartment |
public int Adddepartment(department Department) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@departname" ,SqlDbType.NVarChar,50,Department.departname), |
sqlHelper .CreateInParam( "@description" ,SqlDbType.NVarChar,50,Department.description) |
return (sqlHelper.RunProc( "spInsertDepartment" , ParamList)); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public List<department> Getdepartment() |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
{ sqlHelper.RunProc( "spGetAlldepartment" , out dr); } |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToListDepartment(dr); |
public List<department> ConvertDrToListDepartment(SqlDataReader dr) |
List<department> Departmentlist = new List<department>(); |
department Department = new department(); |
Department.id = Int32.Parse(dr[ "id" ].ToString()); |
Department.departname = dr[ "departname" ].ToString(); |
Department.description = dr[ "description" ].ToString(); |
Departmentlist.Add(Department); |
public department Getsingledepartment( int nid) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@id" ,SqlDbType.Int,4,nid) |
{ sqlHelper.RunProc( "spGetdepartment" ,ParamList, out dr); } |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToDepartment(dr); |
public department Getdepartmenter( string ndepartname) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@departname" ,SqlDbType.NVarChar,50,ndepartname) |
{ sqlHelper.RunProc( "spGetdepartmenter" , ParamList, out dr); } |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
return ConvertDrToDepartment(dr); |
public void Updatepartment(department Department) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@id" ,SqlDbType.Int,4,Department.id), |
sqlHelper.CreateInParam( "@departname" ,SqlDbType.NVarChar,50,Department.departname), |
sqlHelper .CreateInParam( "@description" ,SqlDbType.NVarChar,50,Department.description) |
sqlHelper.RunProc( "spupdatedepart" , ParamList); |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public void Deletedepart( int nid) |
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper(); |
SqlParameter[] ParamList = { |
sqlHelper.CreateInParam( "@id" ,SqlDbType.Int,4,nid) |
{ sqlHelper.RunProc( "spdeletedepart" , ParamList); } |
SystemError.CreateErrorLog(ex.Message); |
throw new Exception(ex.Message, ex); |
public department ConvertDrToDepartment(SqlDataReader dr) |
department Department = new department(); |
Department.id = Int32.Parse(dr[ "id" ].ToString()); |
Department.departname = dr[ "departname" ].ToString(); |
Department.description = dr[ "description" ].ToString(); |
DAL层我们就设计完了,接下来我们就开始设计BLL层了,欢迎拍砖.
你的持续关注,就是我不断前进的最好动力.