C# · 12月 20, 2021

谁都会写代码 ,但是以最有效率的方式编码就需要下更多的功夫

<table id=”table13″ height=”335″ cellspacing=”0″ cellpadding=”0″ width=”98%” border=”0″>
<tr>
<td style=”FONT-SIZE: 10pt” align=”middle” height=”60″>

谁都会写代码!几个月的编程经验可以让你写出“可运行应用程序”。让它可运行容易,但是以最有效率的方式编码就需要下更多的功夫! </td> </tr> <p style="FONT-SIZE: 10pt">背景

<p style="FONT-SIZE: 10pt">首先,我介绍一些3层架构的理论知识。简单说明:什么是3层架构?3层架构的优点是什么?

<p style="FONT-SIZE: 10pt">什么是3层架构?

<p style="FONT-SIZE: 10pt">3层架构是一种“客户端-服务器”架构,在此架构中用户接口,商业逻辑,数据保存以及数据访问被设计为独立的模块。主要有3个层面,第一层(表现层,GUI层),第二层(商业对象,商业逻辑层),第三层(数据访问层)。这些层可以单独开发,单独测试。

<p style="FONT-SIZE: 10pt">为什么要把程序代码分为3层,把用户接口层,商业逻辑层,数据访问层分离有许多的优点。

<p style="FONT-SIZE: 10pt"> 在快速开发中重用商业逻辑组件,我们已经在系统中实现添加,更新,删除,查找客户数据的组件。这个组件已经开发并且测试通过,我们可以在其他要保存客户数据的项目中使用这个组件。

<p style="FONT-SIZE: 10pt"> 系统比较容易迁移,商业逻辑层与数据访问层是分离的,修改数据访问层不会影响到商业逻辑层。系统如果从用sql Server存储数据迁移到用Oracle存储数据,并不需要修改商业逻辑层组件和GUI组件

<p style="FONT-SIZE: 10pt"> 系统容易修改,假如在商业层有一个小小的修改,我们不需要在用户的机器上重装整个系统。我们只需要更新商业逻辑组件就可以了。

<p style="FONT-SIZE: 10pt"> 应用程序开发人员可以并行,独立的开发单独的层。

<p style="FONT-SIZE: 10pt"> 代码

<p style="FONT-SIZE: 10pt"> 这个组件有3层,第一个层或者称为GUI层用form实现,叫做FrmGUI。第二层或者称为商业逻辑层,叫做BOCustomer,是Bussniess Object Customer的缩写。最后是第三层或者称为数据层,叫做DACustomer,是Data Access Customer的缩写。为了方便我把三个层编译到一个项目中。

<p style="FONT-SIZE: 10pt"> 用户接口层

<p style="FONT-SIZE: 10pt">   下面是用户接口成的一段代码,我只选取了调用商业逻辑层的一部分代码。

<p style="FONT-SIZE: 10pt">//This function get the details from the user via GUI

<p style="FONT-SIZE: 10pt">//tier and calls the Add method of business logic layer.

<p style="FONT-SIZE: 10pt">private void cmdAdd_Click(object sender,System.EventArgs e)

<p style="FONT-SIZE: 10pt">{

<p style="FONT-SIZE: 10pt">      try

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            cus = new BOCustomer();

<p style="FONT-SIZE: 10pt">            cus.cusID=txtID.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.LName = txtLName.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.FName = txtFName.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.Tel= txtTel.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.Address = txtAddress.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.Add();

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">      catch(Exception err)

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            Message@R_965_2419@.Show(err.Message.ToString());

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">}

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">//This function gets the ID from the user and finds the

<p style="FONT-SIZE: 10pt">//customer details and return the details in the form of

<p style="FONT-SIZE: 10pt">//a dataset via busniss object layer. Then it loops through

<p style="FONT-SIZE: 10pt">//the content of the dataset and fills the controls.

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">private void cmdFind_Click(object sender,System.EventArgs e)

<p style="FONT-SIZE: 10pt">{

<p style="FONT-SIZE: 10pt">      try

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            String cusID = txtID.Text.ToString();

<p style="FONT-SIZE: 10pt">                 

<p style="FONT-SIZE: 10pt">            BOCustomer thisCus = new BOCustomer();

<p style="FONT-SIZE: 10pt">                 

<p style="FONT-SIZE: 10pt">            DataSet ds = thisCus.Find(cusID);

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            DaTarow row;

<p style="FONT-SIZE: 10pt">            row = ds.Tables[0].Rows[0];

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            //via looping

<p style="FONT-SIZE: 10pt">            foreach(DaTarow rows in ds.Tables[0].Rows )

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">               txtFName.Text = rows["CUS_F_NAME"].ToString();

<p style="FONT-SIZE: 10pt">               txtLName.Text = rows["CUS_L_NAME"].ToString();

<p style="FONT-SIZE: 10pt">               txtAddress.Text = rows["CUS_ADDRESS"].ToString();

<p style="FONT-SIZE: 10pt">               txtTel.Text = rows["CUS_TEL"].ToString();

<p style="FONT-SIZE: 10pt">           }

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">      catch (Exception err)

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            Message@R_965_2419@.Show(err.Message.ToString());

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">}

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">//this function used to update the customer details.

<p style="FONT-SIZE: 10pt">private void cmdUpdate_Click(object sender,

<p style="FONT-SIZE: 10pt">                                 System.EventArgs e)

<p style="FONT-SIZE: 10pt">{

<p style="FONT-SIZE: 10pt">      try

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            cus = new BOCustomer();

<p style="FONT-SIZE: 10pt">            cus.cusID=txtID.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.LName = txtLName.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.FName = txtFName.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.Tel= txtTel.Text.ToString();

<p style="FONT-SIZE: 10pt">            cus.Address = txtAddress.Text.ToString();

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            cus.Update();

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">      catch(Exception err)

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            Message@R_965_2419@.Show(err.Message.ToString());

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">}

<p style="FONT-SIZE: 10pt">商业逻辑层

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

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

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">using System;

<p style="FONT-SIZE: 10pt">using System.Data;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">namespace _3tierarchitecture

<p style="FONT-SIZE: 10pt">{

<p style="FONT-SIZE: 10pt">      ///

<p style="FONT-SIZE: 10pt">      /// Summary description for BOCustomer.

<p style="FONT-SIZE: 10pt">      ///

<p style="FONT-SIZE: 10pt">     

<p style="FONT-SIZE: 10pt">      public class BOCustomer

<p style="FONT-SIZE: 10pt">      {

<p style="FONT-SIZE: 10pt">            //Customer properties

<p style="FONT-SIZE: 10pt">            private String fName;

<p style="FONT-SIZE: 10pt">            private String lName;

<p style="FONT-SIZE: 10pt">            private String cusId;

<p style="FONT-SIZE: 10pt">            private String address;

<p style="FONT-SIZE: 10pt">            private String tel;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            private DACustomer cusData;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">       public BOCustomer()

<p style="FONT-SIZE: 10pt">       {

<p style="FONT-SIZE: 10pt">            //An instance of the Data access layer!

<p style="FONT-SIZE: 10pt">             cusData = new DACustomer();

<p style="FONT-SIZE: 10pt">         }  

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Property FirstName (String)

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public String FName

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">     

<p style="FONT-SIZE: 10pt">                  get

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        return this.fName;

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">                  set

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        try

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              this.fName = value;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                              if (this.fName == "")

<p style="FONT-SIZE: 10pt">                              {

<p style="FONT-SIZE: 10pt">                                    throw new Exception(

<p style="FONT-SIZE: 10pt">                                      "Please provide first name …");

<p style="FONT-SIZE: 10pt">                              }

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt">                        catch(Exception e)

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              throw new Exception(e.Message.ToString());

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Property LastName (String)

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public String LName

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  get

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        return this.lName;

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">                  set

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        //Could be more checkings here eg revmove ' chars

<p style="FONT-SIZE: 10pt">                        //change to proper case

<p style="FONT-SIZE: 10pt">                        //blah blah

<p style="FONT-SIZE: 10pt">                        this.lName = value;

<p style="FONT-SIZE: 10pt">                        if (this.LName == "")

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              throw new Exception("Please provide name …");

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt">            

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Property Customer ID (String)

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public String cusID

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  get

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        return this.cusId;

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">                  set

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        this.cusId = value;

<p style="FONT-SIZE: 10pt">                        if (this.cusID == "")

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              throw new Exception("Please provide ID …");

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Property Address (String)

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public String Address

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  get

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        return this.address;

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">                  set

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        this.address = value;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                        if (this.Address == "")

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              throw new Exception("Please provide address …");

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Property Telephone (String)

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public String Tel

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  get

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        return this.tel;

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">                  set

<p style="FONT-SIZE: 10pt">                  {

<p style="FONT-SIZE: 10pt">                        this.tel = value;

<p style="FONT-SIZE: 10pt">                        if (this.Tel == "")

<p style="FONT-SIZE: 10pt">                        {

<p style="FONT-SIZE: 10pt">                              throw new Exception("Please provide Tel …");

<p style="FONT-SIZE: 10pt">                        }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                  }

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Function Add new customer. Calls

<p style="FONT-SIZE: 10pt">            /// the function in Data layer.

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public void Add()

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  cusData.Add(this);

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Function Update customer details.

<p style="FONT-SIZE: 10pt">            /// Calls the function in Data layer.

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public void Update()

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  cusData.Update(this);

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            /// Function Find customer. Calls the

<p style="FONT-SIZE: 10pt">            /// function in Data layer.

<p style="FONT-SIZE: 10pt">            /// It returns the details of the customer using

<p style="FONT-SIZE: 10pt">            /// customer ID via a Dataset to GUI tier.

<p style="FONT-SIZE: 10pt">            ///

<p style="FONT-SIZE: 10pt">            public DataSet Find(String str)

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                  if (str == "")

<p style="FONT-SIZE: 10pt">                      throw new Exception("Please provide ID to search");

<p style="FONT-SIZE: 10pt">                     

<p style="FONT-SIZE: 10pt">                  DataSet data = null;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                  data = cusData.Find(str);

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">                  return data;

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt">      }

<p style="FONT-SIZE: 10pt">}

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">数据访问层

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

<p style="FONT-SIZE: 10pt">using System.Data.OleDb;

<p style="FONT-SIZE: 10pt">using System.Data;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">namespace _3tierarchitecture

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">{

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">    ///

<p style="FONT-SIZE: 10pt">    /// Summary description for DACustomer.

<p style="FONT-SIZE: 10pt">    ///

<p style="FONT-SIZE: 10pt">    public class DACustomer

<p style="FONT-SIZE: 10pt">    {

<p style="FONT-SIZE: 10pt">        private OleDbConnection cnn;

<p style="FONT-SIZE: 10pt">        //change connection string as per the

<p style="FONT-SIZE: 10pt">        //folder you unzip the files

<p style="FONT-SIZE: 10pt">        private const string CnnStr =

<p style="FONT-SIZE: 10pt">          "Provider=Microsoft.Jet.OLEDB.4.0;Data " +

<p style="FONT-SIZE: 10pt">          "Source= D:\\Rahman_Backup\\Programming\\" +

<p style="FONT-SIZE: 10pt">             "Csharp\\3tierarchitecture\\customer.mdb;";

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">        //local variables

<p style="FONT-SIZE: 10pt">        private String strTable="";

<p style="FONT-SIZE: 10pt">        private String strFields="";

<p style="FONT-SIZE: 10pt">        private String strValues="";

<p style="FONT-SIZE: 10pt">        private String insertStr="";

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        //this needs to be changed based on customer

<p style="FONT-SIZE: 10pt">        //table fields' Name of the database!

<p style="FONT-SIZE: 10pt">        private const String thisTable = "tblCustomer";

<p style="FONT-SIZE: 10pt">        private const String cus_ID = "CUS_ID";

<p style="FONT-SIZE: 10pt">        private const String cus_LName = "CUS_L_NAME";

<p style="FONT-SIZE: 10pt">        private const String cus_FName = "CUS_F_NAME";

<p style="FONT-SIZE: 10pt">        private const String cus_Tel = "CUS_TEL";

<p style="FONT-SIZE: 10pt">        private const String cus_Address = "CUS_ADDRESS";

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">        public DACustomer()

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        public DACustomer(BOCustomer cus)

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            // A reference of the business object class

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        //standard dataset function that adds a new customer

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">        public void Add(BOCustomer cus)

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            String str = BuildAddString(cus);

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            OpenCnn();

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            //Open command option – cnn parameter is imporant

<p style="FONT-SIZE: 10pt">            OleDbCommand cmd = new OleDbCommand(str,cnn);

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            //execute connection

<p style="FONT-SIZE: 10pt">            cmd.ExecuteNonQuery();

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            // close connection

<p style="FONT-SIZE: 10pt">            CloseCnn();

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        //standard dataset function that updates

<p style="FONT-SIZE: 10pt">        //details of a customer based on ID

<p style="FONT-SIZE: 10pt">        public void Update(BOCustomer cus)

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            OpenCnn();

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            String selectStr = "UPDATE " + thisTable +

<p style="FONT-SIZE: 10pt">                " set " + cus_LName + " = '" + cus.LName + "'" +

<p style="FONT-SIZE: 10pt">                "," + cus_FName + " = '" + cus.FName + "'" +

<p style="FONT-SIZE: 10pt">                "," + cus_Address + " = '" + cus.Address + "'" +

<p style="FONT-SIZE: 10pt">                "," + cus_Tel + " = '" + cus.Tel + "'" +

<p style="FONT-SIZE: 10pt">                " where cus_ID = '" + cus.cusID + "'";

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            OleDbCommand cmd = new OleDbCommand(selectStr,cnn);

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            cmd.ExecuteNonQuery();

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            CloseCnn();

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        //standard dataset function that finds and

<p style="FONT-SIZE: 10pt">        //return the detail of a customer in a dataset

<p style="FONT-SIZE: 10pt">        public DataSet Find(String argStr)

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            DataSet ds=null;

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            try

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                OpenCnn();

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">                String selectStr = "select * from " + thisTable +

<p style="FONT-SIZE: 10pt">                              " where cus_ID = '" + argStr + "'";

<p style="FONT-SIZE: 10pt">                OleDbDataAdapter da =

<p style="FONT-SIZE: 10pt">                       new OleDbDataAdapter(selectStr,cnn);

<p style="FONT-SIZE: 10pt">                ds = new DataSet();

<p style="FONT-SIZE: 10pt">                da.Fill(ds,thisTable);

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">                CloseCnn();

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">               

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt">            catch(Exception e)

<p style="FONT-SIZE: 10pt">            {

<p style="FONT-SIZE: 10pt">                String Str = e.Message;

<p style="FONT-SIZE: 10pt">            }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            return ds;

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">        private void OpenCnn()

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            // initialise connection

<p style="FONT-SIZE: 10pt">            String cnnStr = CnnStr;

<p style="FONT-SIZE: 10pt">            cnn = new OleDbConnection(cnnStr);

<p style="FONT-SIZE: 10pt">            // open connection

<p style="FONT-SIZE: 10pt">            cnn.open();

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">        private void CloseCnn()

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            // 5- step five

<p style="FONT-SIZE: 10pt">            cnn.Close();

<p style="FONT-SIZE: 10pt">        }

<p style="FONT-SIZE: 10pt">       

<p style="FONT-SIZE: 10pt">        // just a supporting function that builds

<p style="FONT-SIZE: 10pt">        // and return the insert string for dataset.

<p style="FONT-SIZE: 10pt">        private String BuildAddString(BOCustomer cus)

<p style="FONT-SIZE: 10pt">        {

<p style="FONT-SIZE: 10pt">            // these are the constants as

<p style="FONT-SIZE: 10pt">            // set in the top of this module.

<p style="FONT-SIZE: 10pt">            strTable="Insert into " + thisTable;

<p style="FONT-SIZE: 10pt">            strFields=" (" + cus_ID +

<p style="FONT-SIZE: 10pt">            "," + cus_LName +

<p style="FONT-SIZE: 10pt">            "," + cus_FName +

<p style="FONT-SIZE: 10pt">            "," + cus_Address +

<p style="FONT-SIZE: 10pt">            "," + cus_Tel + ")";

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            //these are the attributes of the

<p style="FONT-SIZE: 10pt">            //customer business object.

<p style="FONT-SIZE: 10pt">            strValues= " Values ( '" + cus.cusID +

<p style="FONT-SIZE: 10pt">            "','" + cus.LName +

<p style="FONT-SIZE: 10pt">            "','" + cus.FName +

<p style="FONT-SIZE: 10pt">            "','" + cus.Address +

<p style="FONT-SIZE: 10pt">            "','" + cus.Tel + "' )";

<p style="FONT-SIZE: 10pt"> 

<p style="FONT-SIZE: 10pt">            insertStr = strTable + strFields + strValues;

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">            return insertStr;

<p style="FONT-SIZE: 10pt">           

<p style="FONT-SIZE: 10pt">       }

<p style="FONT-SIZE: 10pt">    }

<p style="FONT-SIZE: 10pt">}

</td> </tr></table> </td> </tr></table>