private byte[] ExportPDF(ReportDocument rpt) { string fileName = System.IO.Path.GetTempFileName(); CrystalDecisions.Shared.ExportFormatType exp = ExportFormatType.PortableDocFormat; rpt.ExportToDisk(exp, fileName); byte[] myData; using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { myData = new byte[Convert.ToInt32(fs.Length - 1) + 1]; fs.Read(myData, 0, Convert.ToInt32(fs.Length)); fs.Close(); } try { System.IO.File.Delete(fileName); } catch (Exception) { // fixme: data cleanup } return(myData); }
public void SetarFormatoArquivo(string formato) { FormatoArquivo = formato; switch (formato) { case "DOC": eFormato = CrystalDecisions.Shared.ExportFormatType.WordForWindows; break; case "HTML": eFormato = CrystalDecisions.Shared.ExportFormatType.HTML40; break; case "PDF": eFormato = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; break; case "RTF": eFormato = CrystalDecisions.Shared.ExportFormatType.RichText; break; case "XLS": eFormato = CrystalDecisions.Shared.ExportFormatType.ExcelRecord; break; default: eFormato = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; break; } }
public RPT( string file, ExportFormatType type, Dictionary<string, DataSet> listData, Dictionary<string, object> parameters) { _file = file; _type = stringTOExportFormatType(type); _parameters = parameters; _listData = listData; }
private void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft) { selectedReport.ExportOptions.ExportFormatType = eft; string contentType = ""; // Make sure asp.net has create and delete permissions in the directory string tempDir = System.Configuration.ConfigurationSettings.AppSettings["TempDir"]; string tempFileName = Session.SessionID.ToString() + "."; switch (eft) { case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat: tempFileName += "pdf"; contentType = "application/pdf"; break; case CrystalDecisions.Shared.ExportFormatType.WordForWindows: tempFileName += "doc"; contentType = "application/msword"; break; case CrystalDecisions.Shared.ExportFormatType.Excel: tempFileName += "xls"; contentType = "application/vnd.ms-excel"; break; case CrystalDecisions.Shared.ExportFormatType.HTML32: case CrystalDecisions.Shared.ExportFormatType.HTML40: tempFileName += "htm"; contentType = "text/html"; CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions(); hop.HTMLBaseFolderName = tempDir; hop.HTMLFileName = tempFileName; selectedReport.ExportOptions.FormatOptions = hop; break; } CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions(); dfo.DiskFileName = tempDir + tempFileName; selectedReport.ExportOptions.DestinationOptions = dfo; selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; selectedReport.Export(); selectedReport.Close(); string tempFileNameUsed; //if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40) //{ // string[] fp = selectedReport.FilePath.Split("\\".ToCharArray()); // string leafDir = fp[fp.Length - 1]; // // strip .rpt extension // leafDir = leafDir.Substring(0, leafDir.Length–4); // tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName); //} //else tempFileNameUsed = tempDir + tempFileName; Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = contentType; Response.WriteFile(tempFileNameUsed); Response.Flush(); Response.Close(); System.IO.File.Delete(tempFileNameUsed); }
/// <summary> /// ''' Imprime el Report directamente en archivo con la ruta pasada y el tipo de archivo /// ''' </summary> /// ''' <param name="FileReport">Ruta del Report</param> /// ''' <param name="Username">usuario Base datos</param> /// ''' <param name="Password">password del usuario Base de datos</param> /// ''' <param name="Servername">Servidor de la Base de Datos</param> /// ''' <param name="listadeParametros">parametros para el crystal</param> /// ''' <param name="_rutadestinoAGuardar">Ruta donde se guarda el archivo</param> /// ''' <param name="Export">Tipo de Archivo a guardar</param> /// ''' <remarks></remarks> public void PrintEnArchivoSP(string FileReport, string Username, string Password, string Servername, DataTable dtParametros, string _rutadestinoAGuardar = "", CrystalDecisions.Shared.ExportFormatType Export = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat) { clsFunciones clsFunciones = new clsFunciones(); frmVerInformes frmCRNet = new frmVerInformes(); bool IsConnecting = true; ReportDocument crNicasoftStandarReport = new ReportDocument(); Sections crSections; ReportObjects crReportObjects; SubreportObject crSubreportObject; ReportDocument crSubreportDocument; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ConnectionInfo crConnectioninfo; string BaseDatos = "TRANSPORTES"; while (IsConnecting) { try { Cursor.Current = Cursors.WaitCursor; crConnectioninfo = new ConnectionInfo(); { var withBlock = crConnectioninfo; withBlock.ServerName = Servername; withBlock.DatabaseName = BaseDatos; withBlock.UserID = Username; withBlock.Password = Password; withBlock.IntegratedSecurity = false; } { var withBlock = frmCRNet; crNicasoftStandarReport.Load(FileReport); crDatabase = crNicasoftStandarReport.Database; crTables = crDatabase.Tables; foreach (Table crTable in crTables) { crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectioninfo; crTableLogOnInfo.ConnectionInfo.IntegratedSecurity = false; crTableLogOnInfo.ConnectionInfo.ServerName = Servername; crTableLogOnInfo.ConnectionInfo.UserID = Username; crTableLogOnInfo.ConnectionInfo.Password = Password; crTableLogOnInfo.ConnectionInfo.DatabaseName = BaseDatos; crTableLogOnInfo.ConnectionInfo.Type = ConnectionInfoType.SQL; crTableLogOnInfo.ReportName = FileReport; crTable.ApplyLogOnInfo(crTableLogOnInfo); } crSections = crNicasoftStandarReport.ReportDefinition.Sections; foreach (Section crSection in crSections) { crReportObjects = crSection.ReportObjects; foreach (ReportObject crReportObject in crReportObjects) { if (crReportObject.Kind == ReportObjectKind.SubreportObject) { crSubreportObject = (SubreportObject)crReportObject; crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName); crDatabase = crSubreportDocument.Database; crTables = crDatabase.Tables; foreach (Table crTable in crTables) { { var withBlock1 = crConnectioninfo; withBlock1.ServerName = Servername; withBlock1.DatabaseName = BaseDatos; withBlock1.UserID = Username; withBlock1.Password = Password; } crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectioninfo; crTable.ApplyLogOnInfo(crTableLogOnInfo); } } } } withBlock.visorRPT.ReportSource = crNicasoftStandarReport; withBlock.visorRPT.LogOnInfo[0].ConnectionInfo.Type = ConnectionInfoType.SQL; foreach (DataRow dr in dtParametros.Rows) { crNicasoftStandarReport.SetParameterValue(dr["nombre_parametro"].ToString(), dr["valor_parametro"].ToString()); } crNicasoftStandarReport.ExportToDisk(ExportFormatType.PortableDocFormat, _rutadestinoAGuardar); IsConnecting = false; DidPreviouslyConnect = true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Cursor.Current = Cursors.Default; frmCRNet.Close(); break; } } }
/// <summary> /// ''' Imprime el Report directamente en archivo con la ruta pasada y el tipo de archivo /// ''' </summary> /// ''' <param name="FileReport">Ruta del Report</param> /// ''' <param name="Username">usuario Base datos</param> /// ''' <param name="Password">password del usuario Base de datos</param> /// ''' <param name="Servername">Servidor de la Base de Datos</param> /// ''' <param name="Filter">Filtro del crystal</param> /// ''' <param name="_rutadestinoAGuardar">Ruta donde se guarda el archivo</param> /// ''' <param name="Export">Tipo de Archivo a guardar</param> /// ''' <remarks></remarks> public void PrintEnArchivo(string FileReport, string Username, string Password, string Servername, string Filter = "", string _rutadestinoAGuardar = "", CrystalDecisions.Shared.ExportFormatType Export = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat) { frmVerInformes frmCRNet = new frmVerInformes(); bool IsConnecting = true; ReportDocument crNicasoftStandarReport = new ReportDocument(); Sections crSections; ReportObjects crReportObjects; SubreportObject crSubreportObject; ReportDocument crSubreportDocument; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ConnectionInfo crConnectioninfo; string BaseDatos = "TRANSPORTES"; while (IsConnecting) { try { Cursor.Current = Cursors.WaitCursor; crConnectioninfo = new ConnectionInfo(); { var withBlock = crConnectioninfo; withBlock.ServerName = Servername; withBlock.DatabaseName = BaseDatos; withBlock.UserID = Username; withBlock.Password = Password; withBlock.IntegratedSecurity = false; } { var withBlock = frmCRNet; crNicasoftStandarReport.Load(FileReport); crDatabase = crNicasoftStandarReport.Database; crTables = crDatabase.Tables; foreach (Table crTable in crTables) { crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectioninfo; crTableLogOnInfo.ConnectionInfo.IntegratedSecurity = false; crTableLogOnInfo.ConnectionInfo.ServerName = Servername; crTableLogOnInfo.ConnectionInfo.UserID = Username; crTableLogOnInfo.ConnectionInfo.Password = Password; crTableLogOnInfo.ConnectionInfo.DatabaseName = BaseDatos; crTableLogOnInfo.ConnectionInfo.Type = ConnectionInfoType.SQL; crTableLogOnInfo.ReportName = FileReport; crTable.ApplyLogOnInfo(crTableLogOnInfo); } crSections = crNicasoftStandarReport.ReportDefinition.Sections; foreach (Section crSection in crSections) { crReportObjects = crSection.ReportObjects; foreach (ReportObject crReportObject in crReportObjects) { if (crReportObject.Kind == ReportObjectKind.SubreportObject) { crSubreportObject = (SubreportObject)crReportObject; crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName); crDatabase = crSubreportDocument.Database; crTables = crDatabase.Tables; foreach (Table crTable in crTables) { { var withBlock1 = crConnectioninfo; withBlock1.ServerName = Servername; withBlock1.DatabaseName = BaseDatos; withBlock1.UserID = Username; withBlock1.Password = Password; } crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectioninfo; crTable.ApplyLogOnInfo(crTableLogOnInfo); } } } } withBlock.visorRPT.ReportSource = crNicasoftStandarReport; withBlock.visorRPT.LogOnInfo[0].ConnectionInfo.Type = ConnectionInfoType.SQL; if (Filter != "") { withBlock.visorRPT.SelectionFormula = Filter; crNicasoftStandarReport.RecordSelectionFormula = Filter; } if (_rutadestinoAGuardar != string.Empty) { // ** Si existe el Archivo, lo tenemos que borrar antes de guardar porque da errores // ** Borrar Archivo File.Delete(_rutadestinoAGuardar); // ** Exporta el archivo directamente. No pasa por el Visor // ** Export está por defecto a pdf. Se puede cambiar en las variables de la función crNicasoftStandarReport.ExportToDisk(Export, _rutadestinoAGuardar); } withBlock.visorRPT.Refresh(); IsConnecting = false; DidPreviouslyConnect = true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Cursor.Current = Cursors.Default; frmCRNet.Close(); break; } } }