IDAL: data access layer interface, which is a series of 'functions' declarations or lists. The interface has no implementation details.
The role of IDAL is to separate the implementation of access data from the client and comply with the design principle of "Program to an interface, not an implementation ".
1. Classes that the client does not rely on specific implementations of DAL
2. You can change the specific implemented classes through the factory class/configuration settings (for example, from Oracle to SQLServer)
DAL: data access layer, which is mainly used for data logic processing and provides data services for the business logic layer or presentation layer.
Let's take a look at the IDAL design:
ICustom. cs
View sourceprint? Public interface ICustom
{
/// <Summary>
/// Add a record
/// </Summary>
/// <Param name = "Custom"> </param>
/// <Returns> </returns>
Int Addcustom (custom Custom );
/// <Summary>
/// Obtain user information by account name
/// </Summary>
/// <Param name = "nename"> </param>
/// <Returns> </returns>
Custom Getsinglecname (string nename );
/// <Summary>
/// Change the user's password
/// </Summary>
/// <Param name = "Custom"> </param>
Void Updatepassword (custom Custom );
/// <Summary>
/// Obtain the user list
/// </Summary>
/// <Returns> </returns>
List <custom> Getcustom ();
/// <Summary>
/// Delete user records by ID
/// </Summary>
/// <Param name = "nid"> </param>
Void Deletecustom (int nid );
/// <Summary>
/// Obtain user information by ID
/// </Summary>
/// <Param name = "nid"> </param>
/// <Returns> </returns>
Custom Getcustomer (int nid );
/// <Summary>
/// Update user information
/// </Summary>
/// <Param name = "Custom"> </param>
Void updatecustom (custom Custom );
/// <Summary>
/// Obtain the Department employee list based on the department 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 );
&