using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        Buessiness business = new Buessiness();
        Mydatabase db = new Mydatabase();
        //此处的重载，接收来自外部的系统参数，课程号cno和班级号bno
        public Form1(object cno,object bno)
        {
            InitializeComponent();
            //初始化界面各个参数
            int percent_qm, percent_sj, percent_ps, ctime;
            //获取表头三项成绩百分比。
            business.GetCoursecheck(Convert.ToInt32(cno), Convert.ToInt32(bno), out percent_qm, out percent_sj, out  percent_ps);
            string xqmess, cname, zy, nj, bname, tname, year1, month1, day1, clx_string;
            Int16 clx_num;
            //获取表头标题各项信息
            business.GetPaperMessage(Convert.ToInt32(cno), Convert.ToInt32(bno), 2, out xqmess, out cname, out zy, out nj, out bname, out tname, out year1, out month1, out day1, out clx_num, out clx_string, out ctime);
            //获取表尾统计信息
            int first, second, third, forth, fifth, total1;
            business.GetPjStatistics(Convert.ToInt32(cno), Convert.ToInt32(bno), out first, out second, out third, out forth, out fifth, out total1);
            //1、如何获取水晶报表的rpt文件
            string path = Environment.CurrentDirectory + "\\CrystalReport1.rpt";
            //MessageBox.Show(path);
            ReportDocument report = new ReportDocument();
            report.Load(path);//加载报表

            ((TextObject)report.ReportDefinition.ReportObjects["Text_title1"]).Text = xqmess;
            ((TextObject)report.ReportDefinition.ReportObjects["Text_cname"]).Text = cname;
            ((TextObject)report.ReportDefinition.ReportObjects["Text3"]).Text = zy;
            ((TextObject)report.ReportDefinition.ReportObjects["Text5"]).Text = bname;

            //下面是表尾部分：
            ((TextObject)report.ReportDefinition.ReportObjects["Text_yx"]).Text = first.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text_lh"]).Text = second.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text_zd"]).Text = third.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text_jg"]).Text = forth.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text_nojg"]).Text = fifth.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text_totalnum"]).Text = total1.ToString();

            //下面是显示标头各个分值的百分比
            ((TextObject)report.ReportDefinition.ReportObjects["Text19"]).Text = percent_ps.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text21"]).Text = percent_sj.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text25"]).Text = percent_qm.ToString();

            //下面是写年月日信息
            ((TextObject)report.ReportDefinition.ReportObjects["Text38"]).Text = year1.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text39"]).Text = month1.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text40"]).Text = day1.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text43"]).Text = year1.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text42"]).Text = month1.ToString();
            ((TextObject)report.ReportDefinition.ReportObjects["Text41"]).Text = day1.ToString();

            

            //下面开始动态加载SQL脚本，此次是通过dataset加载水晶报表
            DataSet Ds = db.GetDataSet("select snumber,sname,Grade,Grade_ps,Grade_end,Grade_design from sc where cno=" + Convert.ToString(cno) + " and bno=" + Convert.ToString(bno));
            
            
            report.SetDataSource(Ds.Tables[0]);

            //最后绑定数据源，不写无法显示哦^o^
            this.crystalReportViewer1.ReportSource = report;
        }

       
    }
}