Пример #1
0
        } // LoadReport()


        private static string _saveCrystalReport( CswNbtResources CswNbtResources, string ReportTempFileName, string ReportName, DataTable ReportTable )
        {
            CswTempFile TempFile = new CswTempFile( CswNbtResources );
            string DestinationFileName = DateTime.Now.Ticks + "_" + CswTools.SafeFileName( ReportName ) + ".pdf";
            string DestFilePath, DestWebPath;
            TempFile.getFullTempFilePath( DestinationFileName, out DestFilePath, out DestWebPath );

            DiskFileDestinationOptions dFileDOpts = new DiskFileDestinationOptions();
            dFileDOpts.DiskFileName = DestFilePath;

            ReportDocument oRD = new ReportDocument();
            oRD.Load( ReportTempFileName );
            oRD.SetDataSource( ReportTable );

            ExportOptions eOpts = new ExportOptions();
            eOpts = oRD.ExportOptions;
            eOpts.ExportDestinationType = ExportDestinationType.DiskFile;
            eOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
            eOpts.DestinationOptions = dFileDOpts;

            oRD.Export();
            oRD.Close();

            return DestWebPath;
        }
        /// <summary>
        /// 转成PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToPDFbtn_Click(object sender, EventArgs e)
        {
            try
            {
                //reportDataBind();
                string ExportPath;
                string Fname;
                ExportPath = User.rootpath + "\\" + drawingno + "附页";
                if (!Directory.Exists(ExportPath))
                {
                    System.IO.Directory.CreateDirectory(ExportPath);
                }

                Fname = "Accessories";
                CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                //导出为磁盘文件
                CrystalDecisions.Shared.ExportOptions myExportOptiions = tpm.ExportOptions;
                myExportOptiions.ExportDestinationOptions = opts;
                myExportOptiions.ExportDestinationType    = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                tpm.ExportOptions.ExportFormatType        = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                Fname             = Fname + ".PDF";
                opts.DiskFileName = ExportPath + "\\" + Fname;
                tpm.Export();
                MessageBox.Show("--------转换成功---------");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
        }
        private void Btn_Excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog Archivo = new SaveFileDialog();

            if (Archivo.ShowDialog() == DialogResult.OK)
            {
                CrystalDecisions.Shared.ExportOptions              Opt     = new CrystalDecisions.Shared.ExportOptions();
                CrystalDecisions.Shared.ExcelFormatOptions         Opt_Exc = new CrystalDecisions.Shared.ExcelFormatOptions();
                CrystalDecisions.Shared.DiskFileDestinationOptions Opt_Dsk = new CrystalDecisions.Shared.DiskFileDestinationOptions();

                Opt.ExportFormatType      = CrystalDecisions.Shared.ExportFormatType.Excel;
                Opt.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

                Opt_Exc.ExcelUseConstantColumnWidth = false;
                Opt.ExportFormatOptions             = Opt_Exc;

                Opt_Dsk.DiskFileName         = Archivo.FileName;
                Opt.ExportDestinationOptions = Opt_Dsk;
                Reporte.Export(Opt);
            }
        }
Пример #4
0
        private void ExportPDF()
        {
            try
            {
                string exportPath;
                string fileName;
                exportPath = User.rootpath + "\\" + DrawingNo + "附页";
                if (!Directory.Exists(exportPath))
                {
                    System.IO.Directory.CreateDirectory(exportPath);
                }

                fileName = "TotalPipeMaterialCR.pdf";

                CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                //导出为磁盘文件
                CrystalDecisions.Shared.ExportOptions myExportOptions = cr.ExportOptions;
                myExportOptions.DestinationOptions    = opts;
                myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                //导出为pdf格式
                cr.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                //目的路径
                fileName          = exportPath + "\\" + fileName;
                opts.DiskFileName = fileName;
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                //导出操作
                cr.Export();
                MessageBox.Show("--------转换成功---------");
                button1.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("导出PDF时:" + ex.Message.ToString());

                this.Close();
            }
        }
        //private void EXPORTTOPDF(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string exportPath;
        //        string fileName;
        //        exportPath = Application.StartupPath + "\\" + DrawingNo + "附页";
        //        if (!Directory.Exists(exportPath))
        //        {
        //            System.IO.Directory.CreateDirectory(exportPath);
        //        }

        //        fileName = "WeightBarycenterCR.pdf";

        //        CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
        //        //导出为磁盘文件
        //        CrystalDecisions.Shared.ExportOptions myExportOptions = cr.ExportOptions;
        //        myExportOptions.DestinationOptions = opts;
        //        myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
        //        //导出为pdf格式
        //        cr.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
        //        //目的路径
        //        fileName = exportPath + "\\" + fileName;
        //        opts.DiskFileName = fileName;
        //        if (File.Exists(fileName))
        //            File.Delete(fileName);
        //        //导出操作
        //        cr.Export();
        //        MessageBox.Show("--------转换成功---------");
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("导出PDF时:" + ex.Message.ToString());

        //        this.Close();
        //    }
        //}
        //private void ReplaceExportButton()
        //{
        //    //遍历crystalReportViewer1控件里的控件
        //    foreach (object ctl in crystalReportViewer1.Controls)
        //    {
        //        string sControl = ctl.GetType().Name.ToString().ToLower();
        //        if (sControl == "toolstrip")
        //        {
        //            ToolStrip tab1 = (ToolStrip)ctl;
        //            for (int i = 0; i <= tab1.Items.Count - 1; i++)
        //            {
        //                if (tab1.Items[i].ToolTipText == "导出报表")
        //                {
        //                    ToolStripButton tbutton = new ToolStripButton();
        //                    Image img1 = tab1.Items[i].Image;
        //                    tab1.Items.Remove(tab1.Items[i]);
        //                    tbutton.Image = img1;
        //                    tbutton.ToolTipText = "导出报表";
        //                    tab1.Items.Insert(0, tbutton);
        //                    tbutton.Click += new System.EventHandler(this.EXPORTTOPDF);
        //                    break;
        //                }
        //            }
        //        }
        //    }
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string exportPath;
                string fileName;
                exportPath = Application.StartupPath + "\\" + DrawingNo + "附页";
                if (!Directory.Exists(exportPath))
                {
                    System.IO.Directory.CreateDirectory(exportPath);
                }

                fileName = "WeightBarycenterCR.pdf";

                CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                //导出为磁盘文件
                CrystalDecisions.Shared.ExportOptions myExportOptions = cr.ExportOptions;
                myExportOptions.DestinationOptions    = opts;
                myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                //导出为pdf格式
                cr.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                //目的路径
                fileName          = exportPath + "\\" + fileName;
                opts.DiskFileName = fileName;
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                //导出操作
                cr.Export();
                MessageBox.Show("--------转换成功---------");
            }
            catch (Exception ex)
            {
                MessageBox.Show("导出PDF时:" + ex.Message.ToString());

                this.Close();
            }
        }
Пример #6
0
        public byte[] RunReport(String reportName, String fileName, string travelRequestId)
        {
            byte[]         response         = null;
            ConnectionInfo crConnectionInFo = new ConnectionInfo();

            CrystalDecisions.CrystalReports.Engine.Tables crTables;
            TableLogOnInfo             crTableLogonInfo             = new TableLogOnInfo();
            DiskFileDestinationOptions crDiskFileDestinationOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            ExportOptions crExportOptions = new CrystalDecisions.Shared.ExportOptions();

            CrystalDecisions.CrystalReports.Engine.ReportDocument dReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            String rptPath = System.Web.Hosting.HostingEnvironment.MapPath(System.Configuration.ConfigurationManager.AppSettings["rptPath"]);
            String fName   = fileName;

            dReport.Load(rptPath + reportName);

            dReport.SetParameterValue("p_travelrequestID", travelRequestId);
            if (reportName == "Travel_Business_Expense.rpt")
            {
                dReport.SetParameterValue("p_travelrequestID", travelRequestId);
            }


            string defaultConnectionString = ConfigurationManager.ConnectionStrings["CrystalReport"].ConnectionString;
            var    builder = new DbConnectionStringBuilder();

            builder.ConnectionString = defaultConnectionString;

            crConnectionInFo.DatabaseName = "";
            crConnectionInFo.ServerName   = builder["SERVICE_NAME"].ToString();
            crConnectionInFo.UserID       = builder["User ID"].ToString();
            crConnectionInFo.Password     = builder["Password"].ToString();



            crTables = dReport.Database.Tables;
            crTableLogonInfo.ConnectionInfo = crConnectionInFo;

            foreach (CrystalDecisions.CrystalReports.Engine.Table rTable in crTables)
            {
                rTable.ApplyLogOnInfo(crTableLogonInfo);
            }
            foreach (CrystalDecisions.CrystalReports.Engine.ReportDocument subrpt in dReport.Subreports)
            {
                foreach (CrystalDecisions.CrystalReports.Engine.Table rTable in subrpt.Database.Tables)
                {
                    rTable.ApplyLogOnInfo(crTableLogonInfo);
                }
            }

            try
            {
                var memoryStream = new MemoryStream();
                var data         = dReport.ExportToStream(ExportFormatType.PortableDocFormat);
                data.CopyTo(memoryStream);
                response = memoryStream.ToArray();


                if (File.Exists(rptPath + "Exported/" + fileName + ".pdf"))
                {
                    File.Delete(rptPath + "Exported/" + fileName + ".pdf");
                }
                FileStream file = new FileStream(rptPath + "Exported/" + fileName + ".pdf", FileMode.Create, FileAccess.ReadWrite);
                memoryStream.WriteTo(file);
                file.Close();
                file.Dispose();
                memoryStream.Close();
                memoryStream.Dispose();

                //File.WriteAllBytes(rptPath+"Exported/"+fileName+".pdf", response);
            }
            catch (Exception ex)
            {
                LogMessage.Log("Error generating crystal report : " + ex.Message);
                throw new Exception(ex.Message);
            }
            finally
            {
                dReport.Close();
                dReport.Dispose();
            }
            return(response);
        }
Пример #7
0
        /// <summary>
        /// Genera el reporte
        /// </summary>
        /// <param name="reportPath">Ruta del reporte</param>
        /// <param name="outputPath">Regresa el reporte</param>
        /// <param name="fechaInicial">Valor fecha inicial</param>
        /// <param name="fechaFinal">Valor fecha final</param>
        /// <param name="oficinaVentas">Código de la oficina</param>
        /// <param name="Usuario">Código del usuario</param>
        /// <param name="_Company">Objeto de SAP</param>
        /// <param name="msgError">Mensaje de error</param>
        /// <returns>true/false</returns>
        public bool RunReport(string reportPath, string outputPath, DateTime fechaInicial, DateTime fechaFinal, string oficinaVentas, SAPbobsCOM.Company _Company, ref string msgError)
        {
            msgError = string.Empty;
            if (System.IO.File.Exists(outputPath))
            {
                try
                {
                    System.IO.File.Delete(outputPath);
                }
                catch (Exception ex)
                {
                    throw new Exception("No se pudo reemplazar el archivo " + System.IO.Path.GetFileName(outputPath) + ", revise que no se esté ejecutando.");
                }
            }
            try
            {
                rpt = new ReportDocument();

                loginfo              = new CrystalDecisions.Shared.ConnectionInfo();
                loginfo.ServerName   = _Company.Server;
                loginfo.DatabaseName = _Company.CompanyDB;
                loginfo.UserID       = _Company.DbUserName;
                loginfo.Password     = Extensor.Configuracion.PBD.PBD; //ConfigurationManager.AppSettings["PBD"].ToString();

                rpt.Load(reportPath);
                Actualiza(ref rpt, loginfo);

                rpt.SetParameterValue("@FechaInicial", fechaInicial);
                rpt.SetParameterValue("@FechaFinal", fechaFinal);
                rpt.SetParameterValue("@AlmacenOficina", oficinaVentas);
                //rpt.SetParameterValue("@Usuario", Usuario);


                CrystalDecisions.Shared.DiskFileDestinationOptions filedest = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                CrystalDecisions.Shared.ExportOptions o = default(CrystalDecisions.Shared.ExportOptions);
                o = new CrystalDecisions.Shared.ExportOptions();

                ExportOptions opt = new ExportOptions();

                opt = rpt.ExportOptions;

                o.ExportFormatType      = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                o.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                filedest.DiskFileName   = outputPath;


                o.ExportDestinationOptions = (ExportDestinationOptions)filedest.Clone();

                rpt.Export(o);
                o = null;

                filedest = null;
                rpt.Dispose();
                rpt.Close();


                opt = null;
                rpt = null;

                return(true);
            }
            catch (Exception ex)
            {
                msgError = "No se creó el archivo: " + ex.Message + Environment.NewLine +
                           "Detalles: " + ex.InnerException.Message;
                return(false);
            }
        }