锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / C#3层架构引导 中文译文
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850 手机:138-0381-0136 Q Q:396806883 淘宝:店铺

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

Introduction

This article discusses and implements 3-tier architecture using C# and a dummy customer using MS Access database. In this article I am trying to implement a small reusable component that maintains customers in 3-tier architecture. It shows how to add, update and find customer details.

Background

To begin with I would like to discuss a little about the theoretical aspects of 3-tier architecture. I'll briefly go through what 3-tier architecture is and what are its advantages.

What is a 3-tier architecture

Three-tier (layer) is a client-server architecture in which the user interface, business process (business rules) and data storage and data access are developed and maintained as independent modules or most often on separate platforms. Basically, there are 3 layers, tier 1 (presentation tier, GUI tier), tier 2 (business objects, business logic tier) and tier 3 (data access tier). These tiers can be developed and tested separately.

What is the need for dividing the code in 3-tiers? Separation of the user interface from business logic and database access has many advantages. Some of the advantages are as follows:

  • Reusability of the business logic component results in quick development. Let's say we have a module that handles adding, updating, deleting and finding customers in the system. As this component is developed and tested, we can use it in any other project that might involve maintaining customers.
  • Transformation of the system is easy. Since the business logic is separate from the data access layer, changing the data access layer won’t affect the business logic module much. Let's say if we are moving from SQL Server data storage to Oracle there shouldn’t be any changes required in the business layer component and in the GUI component.
  • Change management of the system is easy. Let's say if there is a minor change in the business logic, we don’t have to install the entire system in individual user’s PCs. E.g. if GST (TAX) is changed from 10% to 15% we only need to update the business logic component without affecting the users and without any downtime.
  • Having separate functionality servers allows for parallel development of individual tiers by application specialists.
  • Provides more flexible resource allocation. Can reduce the network traffic by having the functionality servers strip data to the precise structure needed before sending it to the clients.

Using the code

This component has 3 tiers. Tier 1 or GUI tier with a form will be called FrmGUI, tier 2 or business logic will be called BOCustomer short for Bussniess Object Customer and finally the tier 3 or the data tier will be called DACustomer short for Data Access Customer. I have compiled all the 3 tiers in the same project for ease of work. I am including all the source code along with the MS Access database that is used to test this project in the included zip file.

User Interface tier

This is a chunk of code from the user interface. I am only including the functions that are used to call the middle tier or the business logic layer.

I am keeping a reference to business logic layer as BOCustomer.

//This function get the details from  the user via GUI 
//tier and calls the Add method of  business logic layer.
private void cmdAdd_Click(object  sender, System.EventArgs e)
{
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.Add();
}
catch(Exception err)
{
MessageBox.Show(err.Message.ToString());
}
}
//This function gets the ID from the  user and finds the 
//customer details and return the  details in the form of
//a dataset via busniss object  layer. Then it loops through 
//the content of the dataset and  fills the controls.
                  
private void cmdFind_Click(object  sender, System.EventArgs e)
{
try
{
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["CUS_F_NAME"].ToString();
txtLName.Text =  rows["CUS_L_NAME"].ToString();
txtAddress.Text =  rows["CUS_ADDRESS"].ToString();
txtTel.Text =  rows["CUS_TEL"].ToString();
}
}
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)
{
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();
}
catch(Exception err)
{
MessageBox.Show(err.Message.ToString());
}
}
友情链接
版权所有 Copyright(c)2004-2015 锐英源软件 公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768 地址:郑州市文化路47号院1号楼4层(47-1楼位于文化路和红专路十字路口东北角,郑州大学工学院招待所南边,工学院科技报告厅西边。)