天天看点

我是如何搞定复杂水晶报表的(3)

u实验步骤4:

下面分别介绍上面主程序部分设计的业务逻辑层方法的具体代码,由于这些方法都是引用了数据库存储过程部分,故而同时将展示存储过程开发的代码部分。

1、业务逻辑层方法business.GetCoursecheck的设计

/*******************************************************

       **方 法  名:GetCoursecheck

       **输 入参数:cno课程编号  bno班级编号

       **输 出参数:

       **返 回  值:

       **创 建  人:钱哨

       **创 建日期:08-7-9

       **描     述:通过存储过程输入cno课程编号和bno班级编号,判别该班该门课程是否有判卷,如果没有则需要进行考试表的初始化工作。

*******************************************************/

public void GetCoursecheck(int cno, int bno, out int percent_qm, out int percent_sj, out int percent_ps)

        {

            ///下面,开始实例化另一个命名空间的一个类

            Mydatabase DB = new Mydatabase();

            string sql = String.Format("exec proc_GetCoursecheck " + cno + "," + bno + ",@percent_qm output,@percent_ps output,@percent_sj output");

            //执行的T-SQL串

            SqlCommand MyCommand = DB.GetProcCommand(sql);

            MyCommand.Parameters.Add(new SqlParameter("@percent_qm", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@percent_ps", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@percent_sj", SqlDbType.Int));

            MyCommand.Parameters["@percent_qm"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@percent_ps"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@percent_sj"].Direction = ParameterDirection.Output;

            MyCommand.ExecuteNonQuery();

            percent_qm = Convert.ToInt16(MyCommand.Parameters["@percent_qm"].Value); 

            //接收输出的参数

            percent_ps = Convert.ToInt16(MyCommand.Parameters["@percent_ps"].Value);

            percent_sj = Convert.ToInt16(MyCommand.Parameters["@percent_sj"].Value);

            DB.close();

}

该方法中引用的存储过程proc_GetCoursecheck代码如下:

create proc proc_GetCoursecheck

--通过存储过程输入cno课程编号和bno班级编号,判别该班该门课程是否有判卷,如果没有则需要进行考试表的初始化工作。

@cno int,

@bno int,

@percent_qm int output,

@percent_ps int output,

@percent_sj int output

as

if exists(select sno from sc where cno=@cno and bno=@bno)

begin

 select top 1 @percent_ps=Grade_ps_percent,@percent_qm=Grade_end_percent,@percent_sj=Grade_design_percent

 from sc

 where cno=@cno and bno=@bno

end

else

 --先求一下该课程和班级的派课表中的授课学期信息

declare @skxq varchar(10)  

select @skxq=skxq from tc where bno=@bno and cno=@cno

 --如果成绩表中没有该班级该门课程的任何成绩,则需要将学生表的数据复制过来

 insert into sc(cno,bno,sno,sname,snumber,Grade_ps_percent,Grade_end_percent,Grade_design_percent,skxq)

 select @cno,bno,sno,sname,snumber,20,80,0,@skxq from student where bno=@bno

 set @percent_ps=20

 set @percent_qm=80

 set @percent_sj=0

GO

2、  业务逻辑层方法business.GetPjStatistics方法设计

               /*******************************************************

               **方 法  名:GetPjStatistics

               **输 入参数:int bno班级号码, int cno课程号码

               **输 出参数:

               **返 回  值:

               **创 建  人:钱哨

               **创 建日期:08-7-9

               **描     述:统计试卷各个分值的人数。

               *******************************************************/

public void GetPjStatistics(int cno, int bno, out int first, out int second, out int third, out int forth, out int fifth, out int total)

            string sql = String.Format("exec proc_PjStatistics " + cno + "," + bno + ",@first output,@second output,@third output,@forth output,@fifth output,@total output");

            MyCommand.Parameters.Add(new SqlParameter("@first", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@second", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@third", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@forth", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@fifth", SqlDbType.Int));

            MyCommand.Parameters.Add(new SqlParameter("@total", SqlDbType.Int));

            MyCommand.Parameters["@first"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@second"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@third"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@forth"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@fifth"].Direction = ParameterDirection.Output;

            MyCommand.Parameters["@total"].Direction = ParameterDirection.Output;

            first = Convert.ToInt32(MyCommand.Parameters["@first"].Value); //接收输出的参数

            second = Convert.ToInt32(MyCommand.Parameters["@second"].Value);

            third = Convert.ToInt32(MyCommand.Parameters["@third"].Value);

            forth = Convert.ToInt32(MyCommand.Parameters["@forth"].Value);

            fifth = Convert.ToInt32(MyCommand.Parameters["@fifth"].Value);

            total = Convert.ToInt32(MyCommand.Parameters["@total"].Value);

该方法中引用的存储过程proc_PjStatistics代码如下:

create proc proc_PjStatistics

@first int output,@second int output,@third int output,@forth int output,@fifth int output,@total int output

select @fifth=count(sno) from sc where (Grade>=0 and Grade<60) and bno=@bno and cno=@cno

select @forth=count(sno) from sc where (Grade>=60 and Grade<70) and bno=@bno and cno=@cno

select @third=count(sno) from sc where (Grade>=70 and Grade<80) and bno=@bno and cno=@cno

select @second=count(sno) from sc where (Grade>=80 and Grade<90) and bno=@bno and cno=@cno

select @first=count(sno) from sc where (Grade>=90 and Grade<=100) and bno=@bno and cno=@cno

select @total=count(sno) from sc where bno=@bno and cno=@cno

本文转自 qianshao 51CTO博客,原文链接:http://blog.51cto.com/qianshao/235680,如需转载请自行联系原作者