日期:2014-05-20 浏览次数:20994 次
ReportDoc.Load(Server.MapPath("../Report") + "\\CrystalReport2.rpt");
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Buyautomation;User ID=sa;Password=123456");
            SqlCommand comm = new SqlCommand("SELECT * FROM View_tbOperate", conn);
            SqlDataAdapter adapter = new SqlDataAdapter();
            if (conn.State == ConnectionState.Closed) conn.Open();
            // get data from db
            DataSet2 ds = new DataSet2();
            adapter.SelectCommand = comm;
            adapter.Fill(ds, "View_tbOperate");
            conn.Close();
            // set data to report
            ReportDoc.SetDataSource(ds);
            ReportDoc.Refresh();
            // set output type "pdf"
            ReportDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            ReportDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            CrystalDecisions.Shared.DiskFileDestinationOptions options = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            options.DiskFileName = Server.MapPath("../DOC") + "\\Chap0101.pdf";
            ReportDoc.ExportOptions.DestinationOptions = options;
            FileLockedThenWait(Server.MapPath("../DOC") + "\\Chap0101.pdf");
            if (File.Exists(Server.MapPath("../DOC") + "\\Chap0101.pdf"))
            {
                File.Delete(Server.MapPath("../DOC") + "\\Chap0101.pdf");
            }
            ReportDoc.Export();
            //set data to view
            //this.CrystalReportViewer1.ReportSource = ReportDoc;