首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 技术专题 | 电子书下载 | 教学视频 | 网页设计 | 平面设计 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> C# >> 文章正文

教你在c#中实现3层架构

文章来源中国it实验室收集整理 作者佚名 更新时间2008-4-29 保存本文保存本文 推荐给好友推荐给好友 收藏本页收藏本页

     商业逻辑层

    下面是商业逻辑层的所有代码,主要包括定义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;


    public BOCustomer()

    {

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


    if (this.Address == "")

    {

    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;

    }

    }

    }

   

上一页  [1] [2] [3] 下一页  

【责编:Ken】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题
 ·展现C#世界 C#程序设计专题
 ·Java入门 Tomcat的配置技巧精华专题
 ·Oracle RMAN物理备份技术详解
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航