天天看點

我是如何搞定複雜水晶報表的(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,如需轉載請自行聯系原作者