在C#中实现3层架构(3)

///

/// Function Add new customer. Calls

/// the function in Data layer.

///

public void Add()

{

cusData.Add(this);

}

///

/// Function Update customer details.

/// Calls the function in Data layer.

///

public void Update()

{

cusData.Update(this);

}

///

/// Function Find customer. Calls the

/// function in Data layer.

/// It returns the details of the customer using

/// customer ID via a Dataset to GUI tier.

///

public DataSet Find(String str)

{

if (str == "")

throw new Exception("Please provide ID to search");

DataSet data = null;

data = cusData.Find(str);

return data;

}

}

}

数据访问层

数据层包括处理MS Access数据库的细节。所有这些细节都是透明的,不会影响到商业逻辑层。数据访问层有个指向商业逻辑层的引用BOCustomer cus。为了应用方便并且支持其他数据库。
using System;

using System.Data.OleDb;

using System.Data;

namespace _3tierarchitecture

{

///

/// Summary description for DACustomer.

///

public class DACustomer

{

private OleDbConnection cnn;

//change connection string as per the

//folder you unzip the files

private const string CnnStr =

"Provider=Microsoft.Jet.OLEDB.4.0;Data " +

"Source= D:""Rahman_Backup""Programming""" +

"Csharp""3tierarchitecture""customer.mdb;";

//local variables

private String strTable="";

private String strFields="";

private String strValues="";

private String insertStr="";

//this needs to be changed based on customer

//table fields' Name of the database!

private const String thisTable = "tblCustomer";

private const String cus_ID = "CUS_ID";

private const String cus_LName = "CUS_L_NAME";

private const String cus_FName = "CUS_F_NAME";

private const String cus_Tel = "CUS_TEL";

private const String cus_Address = "CUS_ADDRESS";

public DACustomer()

{

}

posted @ 2009-03-27 10:05  yongbin621  阅读(212)  评论(0编辑  收藏  举报