我做了个Report1.rpt报表:
1、想在c#里点击一个按钮把它给调起来,不知道是那个方法才能实现。
2、那报表在c#里面怎样进行预览、设置和打印。
谢谢大家!

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace com.zggps
    {
    /// <summary>
    /// frmReportView 的摘要说明。
    /// </summary>
    public class frmReportView : System.Windows.Forms.Form
    {
    public CrystalDecisions.Windows.Forms.CrystalReportViewer rptView;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public frmReportView()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.rptView = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
    this.SuspendLayout();
    // 
    // rptView
    // 
    this.rptView.ActiveViewIndex = -1;
    this.rptView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
    this.rptView.DisplayGroupTree = false;
    this.rptView.Location = new System.Drawing.Point(8, 8);
    this.rptView.Name = "rptView";
    this.rptView.ReportSource = "F:\\user\\我的文档\\环卫处\\dataInput\\Rerport.rpt";
    this.rptView.ShowCloseButton = false;
    this.rptView.ShowGroupTreeButton = false;
    this.rptView.ShowRefreshButton = false;
    this.rptView.ShowTextSearchButton = false;
    this.rptView.Size = new System.Drawing.Size(680, 376);
    this.rptView.TabIndex = 0;
    // 
    // frmReportView
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(688, 382);
    this.Controls.Add(this.rptView);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
    this.Name = "frmReportView";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "报表预览";
    this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
    this.ResumeLayout(false); }
    #endregion
    }
    }
      

  2.   

    /// <summary>
    /// 生成报表
    /// </summary>
    private void GenReport()
    {
    ShowProcess();
    try
    {
    accessConnect.Open();
    }
    catch(Exception err)
    {
    MessageBox.Show(string.Format("打开数据库错误,错误{0}",err.Message));
    }
    string strSql="SELECT * FROM 环卫所";
    DataSet dsHws=new DataSet();
    System.Data.OleDb.OleDbDataAdapter adp=new System.Data.OleDb.OleDbDataAdapter(strSql,accessConnect);
    adp.Fill(dsHws);
    strSql="";
    nMaxPos=dsHws.Tables[0].Rows.Count;
    for(int i=0;i<dsHws.Tables[0].Rows.Count;i++)
    {
    strSql+=string.Format("(SELECT '{0}' AS 环卫编号, '{1}' AS 环卫所名称, COUNT(*) AS 车次, SUM(重量) AS 净重 FROM (SELECT A.车牌号, B.净重 AS 重量, B.记录时间, C.ID AS 环卫所编号, C.CONTENT AS 环卫所 FROM ((车辆 A LEFT OUTER JOIN 日常 B ON A.车牌号 = B.车牌号) LEFT OUTER JOIN 环卫所 C ON A.环卫所 = C.ID) WHERE 记录时间>=#{2}# AND 记录时间<#{3}# AND C.ID = '{0}' ORDER BY C.ID)) UNION ",dsHws.Tables[0].Rows[i]["ID"].ToString(),dsHws.Tables[0].Rows[i]["CONTENT"].ToString(),dtDay.ToString("yyyy-MM-dd"),dtDay.AddDays(1).ToString("yyyy-MM-dd"));
    }
    strSql=strSql.Substring(0,strSql.Length-7);
    adp.SelectCommand.CommandText=strSql;
    DataSet dsTemp=new DataSet();
    adp.Fill(dsTemp);
    nValue=1;
    ShowProcess();
    foreach(System.Data.DataRow row in dsTemp.Tables[0].Rows)
    {
    System.Data.DataRow newRow=dsResult.Tables[0].NewRow();
    newRow[0]=row[0];
    newRow[1]=row[1];
    newRow[2]=row[2].ToString();
    if(row[3].ToString()=="")
    newRow[3]="0";
    else
                        newRow[3]=row[3].ToString();
    dsResult.Tables[0].Rows.Add(newRow);
    }
    dsResult.AcceptChanges();
    nValue=2;
    ShowProcess();
    accessConnect.Close();
    dataInput.Rerport rpt=new dataInput.Rerport();
    rpt.SetDataSource(dsResult.Tables[0]);
    TextObject text;
    text = (TextObject)rpt.ReportDefinition.ReportObjects["txtTitle"];
    text.Text="汇总日报表";
    text = (TextObject)rpt.ReportDefinition.ReportObjects["txtDate"];
    text.Text=string.Format("统计日期:{0}",dtDay.ToString("yyyy年M月d日"));
    frmReportView frmPre=new frmReportView();
    frmPre.rptView.ReportSource=rpt;
    frmPre.ShowDialog(this);
    Close();
    }
      

  3.   

    public CrystalDecisions.Windows.Forms.CrystalReportViewer rptView;
    这个CrystalReportViewer可以打印及其设置
      

  4.   

    把预览、设置和打印做一个dll控件,怎样放到Crystal reports报表里去?
      

  5.   

    用   窗体 + crystalreportviewer
      

  6.   

    把预览、设置和打印做一个dll控件,怎样放到Crystal reports报表里去?--------------
    水晶报表都有了,你还要用其他控件为什么?
      

  7.   

    Crystal reports使用帮助那里有?