Step by step. NET three-layer architecture Analysis 5. Design of DAL and IDAL

Source: Internet
Author: User
Tags configuration settings

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 );

&

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.