您的位置:首页 > 运维架构 > 网站架构

第一次尝试三层架构<实现简单的增、删、查、改>

2012-04-19 19:57 489 查看
三层架构:UI(界面,User Interfa)、BLL(业务逻辑层)以及DAL(数据访问层)。三层之间通过Model实现数据的传递。在使用中牢记,三层之间的访问权限;UI→BLL→DAL。

采用三层架构的优点:高可拓展性、可维护性高,不足之处:工作量大、系统比较复杂(感觉最好是精通设计思想,如设计模式)、效率比较低。

项目的结构图:

View Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 三层架构.Model;
using 三层架构.DAL;
using 三层架构.BLL;

namespace 三层架构
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Person p1 = new Person();
p1.Age = 20;
p1.Name = "小文";
int id= new PersonBLL().AddNew(p1);
MessageBox.Show(id.ToString());
}

private void button2_Click(object sender, EventArgs e)
{
int Id = 3;
int count = new PersonBLL().Delete(Id);
MessageBox.Show("删除成功!!");
}

private void button3_Click(object sender, EventArgs e)
{
Person p = new Person();
p.Id = 1;
p.Name = "想你";
p.Age = 21;
new PersonBLL().Update(p);
MessageBox.Show("更新成功!!");
}

private void button4_Click(object sender, EventArgs e)
{
int id = 1;
Person p= new PersonBLL().GetData(id);
int Id = p.Id;
int Age = p.Age;
MessageBox.Show(Id.ToString());
MessageBox.Show(p.Name);
MessageBox.Show(Age.ToString());
}

private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = new PersonBLL().GetAll();
}
}
}


<下篇博客主要是根据本篇的代码格式,完成自己的三层架构的代码生成器,居然现在市面上有很多的代码生成器,但有的时候还是更加喜欢自己的风格,今天写了一些,估计过几天就可以完成,到时候发到博客上,揭秘代码生成器的原理>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐