下面是商业逻辑层的所有代码,主要包括定义customer对象的属性。但这仅仅是个虚构的customer对象,如果需要可以加入其他的属性。商业逻辑层还包括添加,更新,查找,等方法。
商业逻辑层是一个中间层,处于GUI层和数据访问层中间。他有一个指向数据访问层的引用cusData = new DACustomer().而且还引用了System.Data名字空间。商业逻辑层使用DataSet返回数据给GUI层。
| using System;
using System.Data; namespace _3tierarchitecture { /// <SUMMARY> /// Summary description for BOCustomer. /// </SUMMARY> public class BOCustomer { //Customer properties private String fName; private String lName; private String cusId; private String address; private String tel; private DACustomer cusData;
{ //An instance of the Data access layer! cusData = new DACustomer(); } /// <SUMMARY> /// Property FirstName (String) /// </SUMMARY> public String FName { get { return this.fName; } set { try { this.fName = value; if (this.fName == "") { throw new Exception( "Please provide first name ..."); } } catch(Exception e) { throw new Exception(e.Message.ToString()); } } } /// <SUMMARY> /// Property LastName (String) /// </SUMMARY> public String LName { get { return this.lName; } set { //could be more checkings here eg revmove ' chars //change to proper case //blah blah this.lName = value; if (this.LName == "") { throw new Exception("Please provide name ..."); } } } /// <SUMMARY> /// Property Customer ID (String) /// </SUMMARY> public String cusID { get { return this.cusId; } set { this.cusId = value; if (this.cusID == "") { throw new Exception("Please provide ID ..."); } } } /// <SUMMARY> /// Property Address (String) /// </SUMMARY> public String Address { get { return this.address; } set { this.address = value;
{ throw new Exception("Please provide address ..."); } } } /// <SUMMARY> /// Property Telephone (String) /// </SUMMARY> public String Tel { get { return this.tel; } set { this.tel = value; if (this.Tel == "") { throw new Exception("Please provide Tel ..."); } } } /// <SUMMARY> /// Function Add new customer. Calls /// the function in Data layer. /// </SUMMARY> public void Add() { cusData.Add(this); } /// <SUMMARY> /// Function Update customer details. /// Calls the function in Data layer. /// </SUMMARY> public void Update() { cusData.Update(this); } /// <SUMMARY> /// 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. /// </SUMMARY> public DataSet Find(String str) { if (str == "") throw new Exception("Please provide ID to search"); DataSet data = null; data = cusData.Find(str); return data; } } } |

