我学院:深入浅出学习C#三层架构 下载本文

内容发布更新时间 : 2024/5/22 8:52:51星期一 下面是文章的全部内容请认真阅读。

String cusID = txtID.Text.ToString();

BOCustomer thisCus = new BOCustomer();

DataSet ds = thisCus.Find(cusID);

DataRow row;

row = ds.Tables[0].Rows[0];

//via looping

foreach(DataRow rows in ds.Tables[0].Rows ) {

txtFName.Text = rows[\

txtLName.Text = rows[\

学游戏,就上我学院!www.woxueyuan.com

txtAddress.Text = rows[\

txtTel.Text = rows[\ } }

catch (Exception err) {

MessageBox.Show(err.Message.ToString()); } }

//this function used to update the customer details.

private void cmdUpdate_Click(object sender, System.EventArgs e)

学游戏,就上我学院!www.woxueyuan.com

{ try {

cus = new BOCustomer();

cus.cusID=txtID.Text.ToString();

cus.LName = txtLName.Text.ToString();

cus.FName = txtFName.Text.ToString();

cus.Tel= txtTel.Text.ToString();

cus.Address = txtAddress.Text.ToString();

cus.Update();

学游戏,就上我学院!www.woxueyuan.com

}

catch(Exception err) {

MessageBox.Show(err.Message.ToString()); } }

商业逻辑层

下面是商业逻辑层的所有代码,主要包括定义customer对象的属性。但这仅仅是个虚构的customer对象,如果需要可以加入其他的属性。商业逻辑层还包括添加,更新,查找,等方法。

商业逻辑层是一个中间层,处于GUI层和数据访问层中间。他有一个指向数据访问层的引用cusData = new DACustomer().而且还引用了System.Data名字空间。商业逻辑层使用DataSet返回数据给GUI层。

using System; using System.Data;

namespace _3tierarchitecture { ///

/// Summary description for BOCustomer.

学游戏,就上我学院!www.woxueyuan.com

///

public class BOCustomer {

//Customer properties private String fName; private String lName; private String cusId; private String address; private String tel; private DACustomer cusData; public BOCustomer() {

//An instance of the Data access layer! cusData = new DACustomer(); } ///

/// Property FirstName (String) ///

public String FName { get {

return this.fName; }

学游戏,就上我学院!www.woxueyuan.com