C#使用三层架构开发Winform的详细案例

三层架构将整个业务应用划分为:

  • (1)界面UI层
  • (2)业务逻辑层
  • (3)数据访问层

对于复杂的系统分层可以让结构更加清晰,模块更加独立,便于维护。

各层的任务:

  • (1)数据访问层:负责数据库的操作。
  • (2)业务逻辑层:实现功能模块的业务逻辑。
  • (3)界面UI层:绘制界面,以及负责界面相关代码。
  • (4)实体类:将数据库中的表转化为面向对象思想中的类。

一、案例需求

使用三层架构实现学生管理:

(1)专业下拉框绑定专业表数据,网格控件绑定学生数据,并且点击"搜索"按钮可以多条件组合查询。

(2)选中某一行,右键可以弹出"删除"菜单,点击"删除"菜单可以删除学生数据。

(3)点击"新增"按钮,弹出新增窗体,在此窗体中完成学生的新增操作。

(4)选中某一行,点击"编辑"按钮,弹出编辑窗体,在此窗体中完成数据的修改。

备注:其中性别的单选框,以及爱好的多选框分别用两个Pannel容器包含。

数据库准备:

--专业
create table ProfessionInfo
(
	ProfessionID int primary key identity(1,1), --专业编号
	ProfessionName varchar(50) not null unique --专业名称
)
--学生
create table StudentInfo
(
	StuID varchar(20) primary key,  --学生学号
	StuName varchar(50) not null,		--学生姓名
	StuAge int not null check(StuAge > 0 and StuAge < 130), --学生年龄
	StuSex char(2) not null check(StuSex in('男','女')),  --学生性别
	StuHobby nvarchar(100), --爱好
	ProfessionID int not null references ProfessionInfo(ProfessionID), --所属专业编号
)
--添加专业信息
insert into ProfessionInfo(ProfessionName) values('电子竞技')
insert into ProfessionInfo(ProfessionName) values('软件开发')
insert into ProfessionInfo(ProfessionName) values('医疗护理')
--插入学生信息
insert into StudentInfo(StuID,StuName,StuAge,StuSex,StuHobby,ProfessionID)
values('001','刘备',18,'男','',1)
insert into StudentInfo(StuID,StuName,StuAge,StuSex,StuHobby,ProfessionID)
values('002','关羽',20,'男','',2)
insert into StudentInfo(StuID,StuName,StuAge,StuSex,StuHobby,ProfessionID)
values('003','张飞',19,'男','',2)
insert into StudentInfo(StuID,StuName,StuAge,StuSex,StuHobby,ProfessionID)
values('004','孙尚香',17,'女','',3)

二、项目结构

(1)创建一个空白解决方案。

(2)在解决方案中创建类库项目MyEntity代表"实体类"。

(3)在解决方案中创建类库项目MyDAL代表"数据访问层"。

(4)在解决方案中创建类库项目MyBLL代表"业务逻辑层"。

(5)在解决方案中创建Windows窗体应用程序MyUI代表"界面UI层"。

三、实体类编写

在MyEntity项目中添加两个实体类,实体类代码如下:

ProfessionInfoEntity:

public class ProfessionInfoEntity
{
    public ProfessionInfoEntity()
    {
        this.ProfessionID = 0;
        this.ProfessionName = "";
    }
    public int ProfessionID { get; set; }  //专业编号
    public string ProfessionName { get; set; }//专业名称
}

StudentInfoEntiy:

public class StudentInfoEntiy
{
    public StudentInfoEntiy()
    {
        this.StuID = "";
        this.StuName = "";
        this.StuAge = 0;
        this.StuSex = "";
        this.StuHobby = "";
        this.ProfessionID = 0;
        this.ProfessionName = "";
    }
    public string StuID { get; set; }  //学生学号
    public string StuName { get; set; }  //学生姓名
    public int StuAge { get; set; }  //学生年龄
    public string StuSex { get; set; }  //学生性别
    public string StuHobby { get; set; }  //学生爱好
    public int ProfessionID { get; set; }  //学生所属专业编号
    public string ProfessionName { get; set; } //学生所属专业名称
}

四、数据访问层编写

(1)由于数据访问层需要使用实体类,所以需要添加实体类的引用。

即在MyDAL项目上右键-->添加-->引用-->项目,在项目中勾选MyEntity项目。

(2)将之前封装好的DBHelper文件复制到MyDAL项目中,并通过添加现有项,将DBHelper加入项目。

(3)在MyDAL项目中添加两个类,类代码如下:

ProfessionInfoDAL:

public class ProfessionInfoDAL
{
    #region 新增
    public int Add(ProfessionInfoEntity entity)
    {
        string sql = "insert into ProfessionInfo(professionName) values(@professionName)";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("ProfessionName",entity.ProfessionName);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 删除
    public int Delete(int id)
    {
        string sql = "delete from ProfessionInfo where ProfessionID=@ProfessionID";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("ProfessionID", id);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 修改
    public int Update(ProfessionInfoEntity entity)
    {
        string sql = "update ProfessionInfo set professionName=@professionName where ProfessionID=@ProfessionID";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("professionName", entity.ProfessionName);
        DBHelper.SetParameter("ProfessionID", entity.ProfessionID);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 列表
    public List<ProfessionInfoEntity> List()
    {
        string sql = "select * from ProfessionInfo";
        DataTable dt = new DataTable();
        DBHelper.PrepareSql(sql);
        dt = DBHelper.ExecQuery();
        List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
        foreach (DataRow item in dt.Rows)
        {
            ProfessionInfoEntity entity = new ProfessionInfoEntity();
            entity.ProfessionID = int.Parse(item["ProfessionID"].ToString());
            entity.ProfessionName = item["ProfessionName"].ToString();
            list.Add(entity);
        }
        return list;
    }
    #endregion

    #region 详情
    public ProfessionInfoEntity Detail(int id)
    {
        string sql = "select * from ProfessionInfo where ProfessionID=@ProfessionID";
        DataTable dt = new DataTable();
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("ProfessionID", id);
        dt = DBHelper.ExecQuery();
        if (dt.Rows.Count == 0)
            return null;
        ProfessionInfoEntity entity = new ProfessionInfoEntity();
        entity.ProfessionID = int.Parse(dt.Rows[0]["ProfessionID"].ToString());
        entity.ProfessionName = dt.Rows[0]["ProfessionName"].ToString();
        return entity;
    }
    #endregion
}

StudentInfoDAL:

public class StudentInfoDAL
{
    #region 新增
    public int Add(StudentInfoEntiy entity)
    {
        string sql = "insert into StudentInfo(StuID,StuName,StuAge,StuSex,StuHobby,ProfessionID) values(@StuID,@StuName,@StuAge,@StuSex,@StuHobby,@ProfessionID)";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("StuID", entity.StuID);
        DBHelper.SetParameter("StuName", entity.StuName);
        DBHelper.SetParameter("StuAge", entity.StuAge);
        DBHelper.SetParameter("StuSex", entity.StuSex);
        DBHelper.SetParameter("StuHobby", entity.StuHobby);
        DBHelper.SetParameter("ProfessionID", entity.ProfessionID);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 删除
    public int Delete(string id)
    {
        string sql = "delete from StudentInfo where StuID=@StuID";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("StuID", id);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 修改
    public int Update(StudentInfoEntiy entity)
    {
        string sql = "update StudentInfo set StuName=@StuName,StuAge=@StuAge,StuSex=@StuSex,StuHobby=@StuHobby,ProfessionID=@ProfessionID where StuID=@StuID";
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("StuName", entity.StuName);
        DBHelper.SetParameter("StuAge", entity.StuAge);
        DBHelper.SetParameter("StuSex", entity.StuSex);
        DBHelper.SetParameter("StuHobby", entity.StuHobby);
        DBHelper.SetParameter("ProfessionID", entity.ProfessionID);
        DBHelper.SetParameter("StuID", entity.StuID);
        return DBHelper.ExecNonQuery();
    }
    #endregion

    #region 列表
    public List<StudentInfoEntiy> List()
    {
        string sql = "select * from StudentInfo";
        DataTable dt = new DataTable();
        DBHelper.PrepareSql(sql);
        dt = DBHelper.ExecQuery();
        List<StudentInfoEntiy> list = new List<StudentInfoEntiy>();
        foreach (DataRow item in dt.Rows)
        {
            StudentInfoEntiy entity = new StudentInfoEntiy();
            entity.StuID = item["StuID"].ToString();
            entity.StuName = item["StuName"].ToString();
            entity.StuAge = int.Parse(item["StuAge"].ToString());
            entity.StuSex = item["StuSex"].ToString();
            entity.StuHobby = item["StuHobby"].ToString();
            entity.ProfessionID = int.Parse(item["ProfessionID"].ToString());
            list.Add(entity);
        }
        return list;
    }
    #endregion

    #region 详情
    public StudentInfoEntiy Detail(string id)
    {
        string sql = "select * from StudentInfo where StuID=@StuID";
        DataTable dt = new DataTable();
        DBHelper.PrepareSql(sql);
        DBHelper.SetParameter("StuID", id);
        dt = DBHelper.ExecQuery();
        if (dt.Rows.Count == 0)
            return null;
        StudentInfoEntiy entity = new StudentInfoEntiy();
        entity.StuID = dt.Rows[0]["StuID"].ToString();
        entity.StuName = dt.Rows[0]["StuName"].ToString();
        entity.StuAge = int.Parse(dt.Rows[0]["StuAge"].ToString());
        entity.StuSex = dt.Rows[0]["StuSex"].ToString();
        entity.StuHobby = dt.Rows[0]["StuHobby"].ToString();
        entity.ProfessionID = int.Parse(dt.Rows[0]["ProfessionID"].ToString());
        return entity;
    }
    #endregion
}

五、业务逻辑层编写

(1)由于业务逻辑层需要使用实体类,所以需要添加实体类的引用。

即在MyBLL项目上右键-->添加-->引用-->项目,在项目中勾选MyEntity项目。

(2)由于业务逻辑层需要调用数据访问层,所以需要添加数据访问层的引用。

即在MyBLL项目上右键-->添加-->引用-->项目,在项目中勾选MyDAL项目。

(3)在MyBLL项目中添加两个类,类代码如下:

ProfessionInfoBLL:

public class ProfessionInfoBLL
{
    ProfessionInfoDAL dal = new ProfessionInfoDAL();
    #region 新增
    public int Add(ProfessionInfoEntity entity)
    {
        return dal.Add(entity);
    }
    #endregion

    #region 删除
    public int Delete(int id)
    {
        return dal.Delete(id);
    }
    #endregion

    #region 修改
    public int Update(ProfessionInfoEntity entity)
    {
        return dal.Update(entity);
    }
    #endregion

    #region 列表
    public List<ProfessionInfoEntity> List()
    {
        return dal.List();
    }
    #endregion

    #region 详情
    public ProfessionInfoEntity Detail(int id)
    {
        return dal.Detail(id);
    }
    #endregion
}

StudentInfoBLL:

public class StudentInfoBLL
{
    StudentInfoDAL dal = new StudentInfoDAL();
    #region 新增
    public int Add(StudentInfoEntiy entity)
    {
        return dal.Add(entity);
    }
    #endregion

    #region 删除
    public int Delete(string id)
    {
        return dal.Delete(id);
    }
    #endregion

    #region 修改
    public int Update(StudentInfoEntiy entity)
    {
        return dal.Update(entity);
    }
    #endregion

    #region 列表
    public List<StudentInfoEntiy> List()
    {
        return dal.List();
    }
    #endregion

    #region 详情
    public StudentInfoEntiy Detail(string id)
    {
        return dal.Detail(id);
    }
    #endregion
}

六、界面UI层代码编写

(1)由于界面UI层需要使用实体类,所以需要添加实体类的引用。

即在MyUI项目上右键-->添加-->引用-->项目,在项目中勾选MyEntity项目。

(2)由于界面UI层需要调用业务逻辑层,所以需要添加业务逻辑层的引用。

即在MyUI项目上右键-->添加-->引用-->项目,在项目中勾选MyBLL项目。

查询窗体界面及代码:

(1)由于查询学生需要多条件组合查询,所以给数据访问层和业务逻辑层添加条件搜索的方法。

给数据访问层MyDAL中StudentInfoDAL类添加方法:

#region 条件查询
public List<StudentInfoEntiy> Search(StudentInfoEntiy searchObj)
{
    string sql = "select * from StudentInfo inner join ProfessionInfo on StudentInfo.ProfessionID = ProfessionInfo.ProfessionID where 1 = 1";
    if (searchObj.ProfessionID != 0)
        sql += " and StudentInfo.ProfessionID = " + searchObj.ProfessionID;
    if (!searchObj.StuName.Equals(""))
        sql += " and StuName like '%" + searchObj.StuName + "%'";
    DataTable dt = new DataTable();
    DBHelper.PrepareSql(sql);
    dt = DBHelper.ExecQuery();
    List<StudentInfoEntiy> list = new List<StudentInfoEntiy>();
    foreach (DataRow item in dt.Rows)
    {
        StudentInfoEntiy entity = new StudentInfoEntiy();
        entity.StuID = item["StuID"].ToString();
        entity.StuName = item["StuName"].ToString();
        entity.StuAge = int.Parse(item["StuAge"].ToString());
        entity.StuSex = item["StuSex"].ToString();
        entity.StuHobby = item["StuHobby"].ToString();
        entity.ProfessionID = int.Parse(item["ProfessionID"].ToString());
        entity.ProfessionName = item["ProfessionName"].ToString();
        list.Add(entity);
    }
    return list;
}
#endregion

给业务逻辑层MyBLL中StudentInfoBLL类添加方法:

#region 条件查询
public List<StudentInfoEntiy> Search(StudentInfoEntiy searchObj)
{
	return dal.Search(searchObj);
}
#endregion

(2)在此界面中多个功能需要调用业务逻辑层,定义两个业务逻辑层对象:

ProfessionInfoBLL proBll = new ProfessionInfoBLL();
StudentInfoBLL stuBll = new StudentInfoBLL();

(3)查询窗体绑定专业信息、绑定学生信息以及搜索功能代码:

#region 绑定下拉框
private void BindPro()
{
    List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
    list = proBll.List();
    list.Insert(0,new ProfessionInfoEntity { ProfessionID=0,ProfessionName="--请选择--"});
    this.cmbPro.DataSource = list;
    this.cmbPro.DisplayMember = "ProfessionName";
    this.cmbPro.ValueMember = "ProfessionID";
}
#endregion

#region 绑定学生数据
private void BindData()
{
    StudentInfoEntiy searchObj = new StudentInfoEntiy();
    searchObj.ProfessionID = int.Parse(this.cmbPro.SelectedValue.ToString());
    searchObj.StuName = this.txtName.Text;
    this.dataGridView1.AutoGenerateColumns = false;
    this.dataGridView1.DataSource = stuBll.Search(searchObj);
}
#endregion

#region 窗体加载
private void FrmSelect_Load(object sender, EventArgs e)
{
    BindPro();
    BindData();
}
#endregion

#region 搜索按钮
private void btSearch_Click(object sender, EventArgs e)
{
    BindData();
}
#endregion

(4)删除菜单代码:

private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
    //添加是否确定删除的对话框
    DialogResult result = MessageBox.Show("确定要删除数据吗,删除之后无法恢复!", "提示框",
        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
    if (result == DialogResult.Cancel)
        return;
    string stuid = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
    if(stuBll.Delete(stuid) == 1)
        MessageBox.Show("删除成功!");
    else
        MessageBox.Show("删除失败!");
    BindData();
}

新增窗体界面及代码:

ProfessionInfoBLL proBll = new ProfessionInfoBLL();
StudentInfoBLL stuBll = new StudentInfoBLL();
#region 绑定下拉框
private void BindPro()
{
    List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
    list = proBll.List();
    list.Insert(0, new ProfessionInfoEntity { ProfessionID = 0, ProfessionName = "--请选择--" });
    this.cmbPro.DataSource = list;
    this.cmbPro.DisplayMember = "ProfessionName";
    this.cmbPro.ValueMember = "ProfessionID";
}
#endregion
private void FrmAdd_Load(object sender, EventArgs e)
{
    BindPro();
}

private void btAdd_Click(object sender, EventArgs e)
{
    //性别处理
    string sex = "";
    if (this.rbBoy.Checked == true) sex = this.rbBoy.Text;
    if (this.rbGirl.Checked == true) sex = this.rbGirl.Text;
    //爱好处理
    string hobby = "";
    foreach (CheckBox ck in this.panel2.Controls)
    {
        if (ck.Checked == true)
        {
            if (!hobby.Equals(""))
                hobby += ",";
            hobby += ck.Text;
        }
    }
    StudentInfoEntiy entity = new StudentInfoEntiy();
    entity.StuID = this.txtId.Text;
    entity.StuName = this.txtName.Text;
    entity.StuAge = int.Parse(this.txtAge.Text);
    entity.StuSex = sex;
    entity.StuHobby = hobby;
    entity.ProfessionID = int.Parse(this.cmbPro.SelectedValue.ToString());
    if (stuBll.Add(entity) == 1)
        MessageBox.Show("新增成功!");
    else
        MessageBox.Show("新增失败!");
    this.Close();
}

编辑修改窗体界面及代码:

public string StuID { get; set; } //学生编号
ProfessionInfoBLL proBll = new ProfessionInfoBLL();
StudentInfoBLL stuBll = new StudentInfoBLL();
#region 绑定下拉框
private void BindPro()
{
    List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
    list = proBll.List();
    list.Insert(0, new ProfessionInfoEntity { ProfessionID = 0, ProfessionName = "--请选择--" });
    this.cmbPro.DataSource = list;
    this.cmbPro.DisplayMember = "ProfessionName";
    this.cmbPro.ValueMember = "ProfessionID";
}
#endregion

#region 绑定详情
private void BindDetail()
{
    StudentInfoEntiy entity = new StudentInfoEntiy();
    entity = stuBll.Detail(this.StuID);
    this.txtId.Text = entity.StuID;
    this.txtName.Text = entity.StuName;
    this.txtAge.Text = entity.StuAge.ToString();
    this.cmbPro.SelectedValue = entity.ProfessionID;
    //性别处理
    if (entity.StuSex.Equals("男"))
        this.rbBoy.Checked = true;
    else
        this.rbGirl.Checked = true;
    //爱好处理
    string[] arrHobby = entity.StuHobby.Split(',');
    foreach (string hobby in arrHobby)
    {
        foreach (CheckBox ck in this.panel2.Controls)
        {
            if (ck.Text.Equals(hobby))
                ck.Checked = true;
        }
    }
}
#endregion

private void FrmEdit_Load(object sender, EventArgs e)
{
    BindPro();
    BindDetail();
}

private void btUpdate_Click(object sender, EventArgs e)
{
    //性别处理
    string sex = "";
    if (this.rbBoy.Checked == true) sex = this.rbBoy.Text;
    if (this.rbGirl.Checked == true) sex = this.rbGirl.Text;
    //爱好处理
    string hobby = "";
    foreach (CheckBox ck in this.panel2.Controls)
    {
        if (ck.Checked == true)
        {
            if (!hobby.Equals(""))
                hobby += ",";
            hobby += ck.Text;
        }
    }
    StudentInfoEntiy entity = new StudentInfoEntiy();
    entity.StuID = this.txtId.Text;
    entity.StuName = this.txtName.Text;
    entity.StuAge = int.Parse(this.txtAge.Text);
    entity.StuSex = sex;
    entity.StuHobby = hobby;
    entity.ProfessionID = int.Parse(this.cmbPro.SelectedValue.ToString());
    if (stuBll.Update(entity) == 1)
        MessageBox.Show("修改成功!");
    else
        MessageBox.Show("修改失败!");
    this.Close();
}

查询窗体中"新增"和"编辑"按钮代码:

private void btAdd_Click(object sender, EventArgs e)
{
    FrmAdd frm = new FrmAdd();
    frm.Show();
}

private void btEdit_Click(object sender, EventArgs e)
{
    string stuid = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
    FrmEdit frm = new FrmEdit();
    frm.StuID = stuid;
    frm.Show();
}

到此这篇关于C#使用三层架构开发Winform的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • ASP.NET创建三层架构图解详细教程

    1.新建项目 2.创建Visual Studio解决方案 3.再创建项目 4.选择类库类型 5.依次创建bll(业务逻辑层),dal(数据访问层)和model(模型层也可以叫实体层) 6.添加一个网站 7.选择相应的类型 8.修改名称 9.设为启动项目 10.结构如下 11. 生成model 12.在dal中引用model 13.选择model引用 14.看一下 15.dal还可以引用其他类库,如DBUtility 16.数据库帮助类库 17.model不引用任何类库 18.底层类库在上层类库中

  • asp.net用三层实现多条件检索示例

    众所周知,三层将项目分为界面层,业务逻辑层和数据访问层(以最基本的三层为例) 同样都知道,多条件检索其实就是根据用户选择的条件项,然后来拼sql语句 那么,既然要根据用户选择的条件项来拼sql语句,就肯定要在界面层接收用户的选择,这时候问题来了: 我是要在界面层拼sql语句吗,这么做完全没问题,功能也完全可以实现,可是这么一来,你是破坏了三层的原则了吗 那么还架三层做什么? 那我在数据访问层拼sql语句好了,然后问题又来了: 在数据访问层拼的话这么知道用户选择了哪几个条件项呢,根据分层的原则,是

  • C# ComboBox的联动操作(三层架构)

    项目需求:根据年级下拉框的变化使得科目下拉框绑定次年级下对应有的值 我们用三层架构的模式来实现 1.我们想和数据库交互,我们首先得来先解决DAL数据库交互层 01.获得年级下拉框的数据 在GradeDAL类中 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient;

  • asp.net实现三层架构的例子

    看了2天的三层架构,其实自己以前也看过这个,可以由于没有使用过,所以对于三层架构也只是知道罢了,昨天看了一下他一些内部的具体架构,三层分别是BLL.WEB.DAL,在web接受用户请求,bll处理业务,dal处理数据库事务,下面是一个简单的例子!这是一个添加新员工的页面: 后台代码如下: usingSystem.Collections; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.U

  • 基于C#实现的三层架构实例

    本文所述为基于C#实现的三层架构.对于三层的概念查相信大家并不陌生,这里举一个关于三层的简单实例,真正看一下它是如何具体实现的. 我们先来一起看看实体类-Model 实质:实体类就是在完成数据库与实体类对应的功能,一个类是一张表,一个属性是一个字段! using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace model { public class User {

  • ASP.NET存储过程实现分页效果(三层架构)

    本文实例为大家分享了ASP.NET存储过程实现分页的具体代码,供大家参考,具体内容如下 实现效果: 文本框内输入跳转的页数,点击GO会跳转到该页 首先在项目下加入BLL,DAL,DataAccess,MODEL类库 1.前台界面 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="原始刷新分页.aspx.cs" Inherits="分页.原始刷新分页" %&

  • ASP.NET三层架构详解 如何实现三层架构

    一.数据库 /*==============================================================*/ /* DBMS name: Microsoft SQL Server 2000 */ /*==============================================================*/ if exists (select 1 from sysobjects where id = object_id('newsConte

  • .net三层结构初探分析第1/4页

    对于学习,我选择了ACCESS数据库+存储过程的方式,这里记录的是我个人的学习体会和笔记,与网上的可能有不同之处,观点也不可能全部相同.为什么使用三层结构: 首先要明确,三层结构并不能使系统变快,实际上它会比起"单类结构"慢.但越来越多人使用三层结构开发,为啥呢?我在使用中,发现三层结构十分清晰,一个类,一个文件你该放在哪层就放哪层,不会象单类结构那样全部放到App_Data中,造成结构混乱.当然,使用三层结构的原因肯定不是那么肤浅,它对团队开发,系统可维护性有十分重要的意义. 三层结

  • C#使用三层架构开发Winform的详细案例

    三层架构将整个业务应用划分为: (1)界面UI层 (2)业务逻辑层 (3)数据访问层 对于复杂的系统分层可以让结构更加清晰,模块更加独立,便于维护. 各层的任务: (1)数据访问层:负责数据库的操作. (2)业务逻辑层:实现功能模块的业务逻辑. (3)界面UI层:绘制界面,以及负责界面相关代码. (4)实体类:将数据库中的表转化为面向对象思想中的类. 一.案例需求 使用三层架构实现学生管理: (1)专业下拉框绑定专业表数据,网格控件绑定学生数据,并且点击"搜索"按钮可以多条件组合查询.

  • java开发MVC三层架构上再加一层Manager层原理详解

    目录 MVC三层架构 MVC架构弊端 Manager层的特征 Manager层使用案例 MVC三层架构 我们在刚刚成为程序员的时候,就会被前辈们 "教育" 说系统的设计要遵循 MVC(Model-View-Controller)架构.它将整体的系统分成了 Model(模型),View(视图)和 Controller(控制器)三个层次,也就是将用户视图和业务处理隔离开,并且通过控制器连接起来,很好地实现了表现和逻辑的解耦,是一种标准的软件分层架构. MVC分层架构是架构上最简单的一种分层

  • ssi框架学习总结(mvc三层架构)

    相信大家对于mvc的三层架构已经灰常熟悉了,在这就不细讲了,个人感觉ssi的框架结构还是比较典型的mvc三层架构,还是比较容易上手的.关于这块的入门我想特别感谢下FrankHui童鞋,在他的帮助下,我才能比较快滴熟悉了这个架构,对我学习ssi的框架还是很有帮助滴.ssi的框架主要是由struts2,spring以及ibatis组成,他们负责各层之间的交互与协作,从而实现整个web端的功能实现与整合.Struts目前主要负责数据传递和控制方面,spring则依靠其强大的依赖注入技术实现了类似bea

  • java三层架构原理与作用小结

    三层架构 三层架构(3-tier application) 通常意义上的三层架构就是将整个业务应用划分为:表现层(UI).业务逻辑层(BLL).数据访问层(DAL).区分层次的目的即为了"高内聚,低耦合"的思想. 概念简介 1.表现层(UI):通俗讲就是展现给用户的界面,即用户在使用一个系统的时候他的所见所得. 2.业务逻辑层(BLL):针对具体问题的操作,也可以说是对数据层的操作,对数据业务逻辑处理. 3.数据访问层(DAL):该层所做事务直接操作数据库,针对数据的增添.删除.修改.

  • Java Web三层架构的配置详解

    一.软件下载: 1.java 这里使用的是jdk1.4.2.     下载地址:http://dlc.sun.com/jdk/j2sdk-1_4_2_07-windows-i586-p.exe;     2.tomcat 5.0.28 这里的tomcat的版本是5.0的,安装版或是解压版都是可以的. 3.数据库 推荐使用mysql,but暂时找不到下载地址,由于此次偶们班有课程设计要用sqlserver的,所以下面实践会使用sqlserver(找张安装盘安装)     注:连接sqlserver

  • 简单介绍三层架构工作原理

    目录 前言 一.什么是三层架构 各模块功能划分表: 三层架构运作流程图: 三层架构中各功能模块如何联系? Entity在三层架构中的作用:  三层及实体层之间的依赖关系: 二.为什么使用三层架构 三.三层与两层的区别 三层架构的优势: 三层架构的劣势: 前言 在阅读本篇文章时请关注如下问题: 1.什么是三层架构? 2.为什么使用三层架构? 3.三层与以往使用的两层相比有什么不同?它的优势在哪里? 4.如何学好三层架构?如何应用三层架构?  一.什么是三层架构 三层架构就是为了符合"高内聚,低耦合

  • .Net6开发winform程序使用依赖注入

    .net  Blazor webassembly 和 webAPI 内建支持依赖注入, Winform 和 Console 应用虽然不带有依赖注入功能, 但增加依赖注入也很简单.  本文将示例如何为 WinForm 程序增加依赖注入特性, 实现通过DI容器获取Cofiguration 实例, 并读取appsettings.json文件. 安装依赖库, 有点多 Microsoft.Extensions.DependencyInjection 库, 依赖注入的类库 Microsoft.Extensi

  • ASP 三层架构 Error处理类

    从这节开始,将会给大家介绍几个ASP中的三大通用类,它贯穿于我所设计的三层架构中,是对ASP语法的扩展,可以提高很多细节处理上的效率,可以算是一点点框架的味道. 本节介绍错误处理类,类名Con_Error,在代码页面之初就进行初始化,实例名为e,以下的e.add 即使用该错误类的实例化对象进行操作. 方法介绍: e.Add(ByVal vErrorMessage ) 记录一个错误,并且设置 e.Error = true . 在程序检测用户名合法性等地方发现错误时,就调用这个方法,记录一个错误信息

  • 使用vue.js2.0 + ElementUI开发后台管理系统详细教程(二)

    在上篇文章给大家介绍了使用vue.js2.0 + ElementUI开发后台管理系统详细教程(一) 1. 引入路由工具vue-router,切换视图 # 安装vue-router cnpm install vue-router --save-dev 2. 使用vue-router main.js import Vue from 'vue' import App from './App' import VueRouter from 'vue-router' import routeConfig f

  • 使用vue.js2.0 + ElementUI开发后台管理系统详细教程(一)

    1. 根据官方指引,构建项目框架 # 安装vue $ cnpm install vue@2.1.6 # 全局安装 vue-cli $ cnpm install --global vue-cli # 创建一个基于 webpack 模板的新项目my-project $ vue init webpack my-project # 进入项目目录 $ cd my-project # 安装依赖,走你 $ cnpm install # 运行项目 $ cnpm run dev 2. 运行项目之后,会看到以下界面

随机推荐