代码改变世界

如何开发一个学生成绩管理糸统(11)

2010-08-20 20:44  ScriptZhang  阅读(408)  评论(1编辑  收藏  举报

由于需要,现在开始重新写学生成绩管理糸统,这一次,还是使用数据集作为DAL层,在数据库方面,将全面引用关糸型的数据集,

在这里,还是先介绍一下数据层的开发过程,DAL

我会在每一个开发过程分享代码出来,让大家帮评价一下,有什么意见,请大家多提提

 

核心表是学生表,bsms_student,

年级表 bsms_grade

专业表 bsms_professional

班级表 bsms_class

还有两个字典表 words_sex   性别表

                     words_politics  政治面貌表

 

项目列表如下:

 

新建项目,添加数据集,

 

在数据集里面将TableAdapter 拉进入里面就进弹出相应的程序

 

选择连接字符串,也可以新建连接字条串

 

为了操作的方便,我没有使用存储过程,全面使用SQL语句

 

 

添加数据表格,就可以完成整个流程了。

 

 

 

再帮完成的方法取一个名字就可了。

对大部分的表格完成方法操作后就大概是这样子了。

 

 

在BLL层添加 新的类,StudentBLL.cs 用于管理学生数据

 

在StudentBLL头引用

DAL.DBTableAdapter

 

在类中添加 两个方法,

在类使用单件模式,

代码
namespace BLL
{
[System.ComponentModel.DataObject]
public class StudentBLL
{
private bsms_studentTableAdapter _productsAdapter = null;

protected bsms_studentTableAdapter Adapter
{
get
{
if (_productsAdapter == null)
_productsAdapter
= new bsms_studentTableAdapter();

return _productsAdapter;
}
}

/// <summary>
/// 取得全部学生数据
/// </summary>
/// <returns></returns>
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select,
true)]
public DAL.DB.bsms_studentDataTable Getstudents()
{
return Adapter.GetData();
}

/// <summary>
/// 取得指定Id学生数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select,
false)]
public DAL.DB.bsms_studentDataTable GetstudentById(int id)
{
return Adapter.GetDataByStudentId(id);
}





}
}

在web层引用DAL和BLL后,在default.aspx的代码中添加以下代码

在页面引入BLL

 

代码
StudentBLL StudentAPI = new StudentBLL();

protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource
= StudentAPI.Getstudents();
GridView1.DataBind();
}
}

 

数据显示正常