代码改变世界

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

2010-05-17 08:34  ScriptZhang  阅读(527)  评论(3编辑  收藏  举报

通过前面两个逻辑类的编写,应该基本可以明白逻辑类的编写了,还有如何调用DAL层的数据集调用 。

现在要编写的是CourseInfoBLL的类,基本的添删改就不再多说了,帖上代码就行了。

 

代码
/// <summary>
///ClassBLL 的摘要说明
/// </summary>
[System.ComponentModel.DataObject]
public class CourseInfoBLL
{
private s_courseinfoTableAdapter _productsAdapter = null;

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

return _productsAdapter;
}
}

[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select,
true)]
public GYsms.s_courseinfoDataTable GetCourseInfo()
{
return Adapter.GetCourseInfo();
}



[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select,
false)]
public GYsms.s_courseinfoDataTable GetCourseInfoById(int id)
{
return Adapter.GetCinfoById(id);
}


[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Insert,
true)]
public bool AddCourseInfo(int id,int pid,int thours,int lhours,int phours)
{
GYsms.s_courseinfoDataTable table
=new GYsms.s_courseinfoDataTable();
GYsms.s_courseinfoRow row
=table.News_courseinfoRow();

row.id
= id;
row.pid
= pid == 0 ? 0 : pid;
row.thours
=thours==0?0:thours;
row.lhours
=lhours==0?0:lhours;
row.phours
= phours == 0 ? 0 : phours;

table.Adds_courseinfoRow(row);
int rowsAffacted = Adapter.Update(table);
return rowsAffacted == 1;
}

[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Update,
true)]
public bool UpdateCourseInfo(int id ,int pid, int thours, int lhours, int phours)
{
GYsms.s_courseinfoDataTable table
= Adapter.GetCinfoById(id);
if(table.Count==0)
return false;

GYsms.s_courseinfoRow row
=table[0];
row.pid
= pid == 0 ? 0 : pid;
row.thours
= thours == 0 ? 0 : thours;
row.lhours
= lhours == 0 ? 0 : lhours;
row.phours
= phours ==0? 0 : phours;
int rowsAffacted = Adapter.Update(table);
return rowsAffacted == 1;
}



[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Delete,
true)]
public bool DeleteCourseInfo(int id)
{
int rowsAffacted = Adapter.Delete(id);
return rowsAffacted == 1;
}

 

这里有一个方法,就是为了可以将两个表s_course和s_courseinfo表进行关联使用的方法

通过查询Pid,返回与s_course表相关联的多个数据集合,再通过Id来调用各个数据,

在构思的时候,我想的是一门课程只有一个s_course表和s_courseinfo表中的一列数据。

 

代码

/// <summary>
/// 返回Ids的集合,查询专业号
/// </summary>
/// <param name="pid">专业号</param>
/// <returns>Ids集合</returns>
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select,
false)]
public GYsms.s_courseinfoDataTable GetCourseInfoByPId(int pid)
{
//System.Collections.Generic.List<int>
return Adapter.GetIdsByPid(pid);
}

 

 

我在这里放一下DAL层,数据集的代码,还有逻辑层的全部代码,有兴趣的可以自己下载来看看。代码编写主要用来参考,

因为在设计数据表时没有使用关糸,我觉得有点不妥,以后会再重写文章,写一个使用关糸的数据层设计。作为第二板。

https://files.cnblogs.com/ScriptZhang/DAL.rar

https://files.cnblogs.com/ScriptZhang/BLL.rar

还是请大家多给点意见.