循环打印Crystal Report

时间:2013-08-26 04:21:47

标签: c# crystal-reports

我的要求是在水晶报告中单击一下,生成/打印特定班级所有学生的标记表。

当我使用For循环时,它只显示报告的最后一条记录/页面。

我的代码是

private void btnGenerate_Click(object sender,EventArgs e)         {

        try
        {
            axCrystalActiveXReportViewer1.ReportSource = null;

            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;


            crConnectionInfo.ServerName = Configuration.ServerName;
            crConnectionInfo.DatabaseName = Configuration.DataBaseName;
            crConnectionInfo.UserID = Configuration.Server_userName;
            crConnectionInfo.Password = Configuration.Server_password;



            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

           for(int i=0; i<=x; i++)
            {
                DataSet ds_ViewTermMarkSheet = new DataSet();
                Hashtable htViewTermMarkSheet = new Hashtable();

                htViewTermMarkSheet.Add("@Year", txtYear.Text);
                htViewTermMarkSheet.Add("@Faculty", cboFaculty.Text);
                htViewTermMarkSheet.Add("@Level", cboClass.Text);
                htViewTermMarkSheet.Add("@Section", cboSection.Text);
                htViewTermMarkSheet.Add("@term", cboTerm.Text);
                htViewTermMarkSheet.Add("@CRN",.ToString());

                DbOperations _dbAccess = new DbOperations();
                _dbAccess.selectStoredProcedure(ds_ViewTermMarkSheet, "spSelectExamView_Exam_TermWiseMarkSheet", htViewTermMarkSheet, "Marks");





            cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]);
           }



                axCrystalActiveXReportViewer1.Refresh();


            cryRpt.Close();

        }
        catch (Exception ex)
        {
            MessageBox.Show("Mark Sheet generation was not successful.\r" + ex.Message, "Error!");
        }
    }

如何一次附加多个标记并立即打印?

2 个答案:

答案 0 :(得分:0)

你必须致电:

cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]); 

..从外面的for循环

在for循环中使用您需要的所有信息填充数据表。然后从外面循环调用SetDataSource() method.

干杯

答案 1 :(得分:0)

您的代码将循环并多次设置数据源,但只会为最后一个刷新报告。您需要移动刷新指示循环,并在那里打印报告:

        cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]);
        axCrystalActiveXReportViewer1.Refresh();
        // print the rpeort
       }

处理此问题的正确方法是创建一份报告,其中显示有关所有学生的信息。您可以按学生ID或姓名分组,并在小组后设置新页面。然后打印此报告(仅一次)。