public static void ExportPdf(string filename, ReportClass crReport) { var dest = new DiskFileDestinationOptions { DiskFileName = GetPath(filename) }; var formatOpt = new PdfFormatOptions { FirstPageNumber = 0, LastPageNumber = 0, UsePageRange = false, CreateBookmarksFromGroupTree = false }; var ex = new ExportOptions { ExportDestinationType = ExportDestinationType.DiskFile, ExportDestinationOptions = dest, ExportFormatType = ExportFormatType.PortableDocFormat, ExportFormatOptions = formatOpt }; crReport.SetDatabaseLogon("sa", "sabroso123"); crReport.Export(ex); }
protected void ExportPDF(ReportClass rpt, string output_file_name) { if (rpt != null) { ExportOptions options = new ExportOptions(); DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions(); SaveFile_SFD.InitialDirectory = SettingsMng.Instance.GetPDFPrintsFolder(); SaveFile_SFD.FileName = output_file_name; SaveFile_SFD.AddExtension = true; SaveFile_SFD.DefaultExt = "pdf"; if (SaveFile_SFD.ShowDialog() == DialogResult.OK) { PgMng.Grow(String.Format(Face.Resources.Messages.EXPORTING_PDF, SaveFile_SFD.FileName), string.Empty); diskFileDestinationOptions.DiskFileName = SaveFile_SFD.FileName; options.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; options.ExportDestinationOptions = diskFileDestinationOptions; PgMng.Grow(); rpt.Export(options); } } else { PgMng.ShowInfoException(Resources.Messages.NO_DATA_REPORTS); } }
private void button2_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PDF 文件 (*.pdf)|*.pdf"; sfd.FileName = this.outfilename; if (sfd.ShowDialog() == DialogResult.OK) { //this.crystalReportViewer1.ExportReport(); DiskFileDestinationOptions diskOpts = ExportOptions.CreateDiskFileDestinationOptions(); ExportOptions exportOpts = new ExportOptions(); exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat; exportOpts.ExportDestinationType = ExportDestinationType.DiskFile; diskOpts.DiskFileName = sfd.FileName; exportOpts.ExportDestinationOptions = diskOpts; printCrystalReport.Export(exportOpts); MessageBox.Show("PDF导出完成", "注意"); } }
/** * Funcion que crea el pdf y lo convierte a un httpresponseMessage para enviar por http * @param pbjeto de Crystal report que contiene la tabla del pdf a generar * @returns httpResponseMessage del pdf */ public HttpResponseMessage obtener_Response(ReportClass objRpt) { ExportOptions CrExportOptions; PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrExportOptions = objRpt.ExportOptions; CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.FormatOptions = CrFormatTypeOptions; Stream stream = objRpt.ExportToStream(ExportFormatType.PortableDocFormat); objRpt.Export(CrExportOptions); MemoryStream ms = new MemoryStream(); stream.CopyTo(ms); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(ms.ToArray()) }; result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = "Report.pdf" }; result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); return(result); }
/// <summary> /// Stampa il report che gli viene passato con il nome specificato /// </summary> public void StampaPdf(ReportClass ReportDaStampare, string NomeFile) { // try // { NomeFile = _s_DirectoryStampa + NomeFile + ".pdf"; ExportOptions optExp; DiskFileDestinationOptions optDsk = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions optPdfRtf = new PdfRtfWordFormatOptions(); optExp = ReportDaStampare.ExportOptions; optExp.ExportFormatType = ExportFormatType.PortableDocFormat; optExp.FormatOptions = optPdfRtf; optExp.ExportDestinationType = ExportDestinationType.DiskFile; optDsk.DiskFileName = NomeFile; optExp.DestinationOptions = optDsk; ReportDaStampare.Export(); // } // catch(Exception ex) // { // throw ex; // } }
public static void SendMailsFacturasPendientes() { try { OutputInvoiceList facturas = OutputInvoiceList.GetNoCobradasList(true); ClienteList clientes = ClienteList.GetList(false); SerieList series = SerieList.GetList(false); CompanyInfo empresa = CompanyInfo.Get(AppContext.ActiveSchema.Oid); SerieInfo serie; ClienteInfo cliente; Registro registro = Registro.New(ETipoRegistro.Email); registro.Nombre = "Envio automático de Facturas"; registro.Observaciones = "Envio automático de Facturas pendientes de pago"; foreach (OutputInvoiceInfo item in facturas) { if (item.Prevision.AddDays(ModulePrincipal.GetPeriodicidadEnvioFacturasPendientes()) > DateTime.Today) { continue; } cliente = clientes.GetItem(item.OidCliente); if (!cliente.EnviarFacturaPendiente) { continue; } serie = series.GetItem(item.OidSerie); FormatConfFacturaAlbaranReport conf = new FormatConfFacturaAlbaranReport(); conf.nota = (cliente.OidImpuesto == 1) ? Resources.Messages.NOTA_EXENTO_IGIC : string.Empty; conf.nota += Environment.NewLine + (item.Nota ? serie.Cabecera : ""); OutputInvoiceReportMng reportMng = new OutputInvoiceReportMng(AppContext.ActiveSchema, string.Empty, string.Empty); ReportClass report = reportMng.GetDetailReport(item, serie, cliente, null, conf); if (report != null) { LineaRegistro linea = registro.LineaRegistros.NewItem(registro, cliente); ExportOptions options = new ExportOptions(); DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions(); string fileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); fileName += "\\" + item.FileName; diskFileDestinationOptions.DiskFileName = fileName; options.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; options.ExportDestinationOptions = diskFileDestinationOptions; report.Export(options); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(new MailAddress(cliente.Email, cliente.Nombre)); mail.From = new MailAddress(SettingsMng.Instance.GetSMTPMail(), empresa.Name); mail.Body = String.Format(Resources.Messages.FACTURA_EMAIL_ATTACHMENT_BODY, empresa.Name); mail.Subject = Resources.Messages.FACTURA_EMAIL_SUBJECT; mail.Attachments.Add(new Attachment(fileName)); try { Thread mailThread = new Thread(SendMailDelegate); mailThread.Start(mail); while (mailThread.IsAlive) { ; } linea.Observaciones = linea.Descripcion; linea.Descripcion = String.Format(Resources.Messages.FACTURA_EMAIL_OK, item.NFactura); } catch (Exception ex) { linea.Observaciones = linea.Descripcion; linea.Descripcion = String.Format(Resources.Messages.FACTURA_EMAIL_ERROR, item.NFactura); registro.Save(); throw new iQException(ex.Message + Environment.NewLine + Environment.NewLine + moleQule.Library.Resources.Errors.SMTP_SETTINGS); } finally { mail.Dispose(); try { File.Delete(fileName); } catch (Exception ex) { string a = ex.Message; } } } } registro.Save(); ModulePrincipal.SetFechaUltimoEnvioFacturasPendientes(DateTime.Now); AppContext.Principal.SaveSettings(); } catch { } }
public override void EmailPDFAction() { if (ActiveItem == null) { return; } PgMng.Reset(10, 1, Face.Resources.Messages.RETRIEVING_DATA, this); SerieInfo serie = SerieInfo.Get(ActiveItem.OidSerie, false); PgMng.Grow(); ClienteInfo client = ClienteInfo.Get(ActiveItem.OidCliente, false); PgMng.Grow(); TransporterInfo transporter = TransporterInfo.Get(ActiveItem.OidTransportista, ETipoAcreedor.TransportistaDestino, false); PgMng.Grow(); CompanyInfo company = CompanyInfo.Get(AppContext.ActiveSchema.Oid); PgMng.Grow(); FormatConfFacturaAlbaranReport conf = new FormatConfFacturaAlbaranReport(); conf.nota = (client.OidImpuesto == 1) ? Library.Invoice.Resources.Messages.NOTA_EXENTO_IGIC : string.Empty; conf.nota += Environment.NewLine + (ActiveItem.Nota ? serie.Cabecera : ""); conf.cuenta_bancaria = ActiveItem.CuentaBancaria; PgMng.Grow(); OutputInvoiceInfo item = OutputInvoiceInfo.Get(ActiveOID, true); PgMng.Grow(); OutputInvoiceReportMng reportMng = new OutputInvoiceReportMng(AppContext.ActiveSchema, this.Text, this.FilterValues); ReportClass report = reportMng.GetDetailReport(item, serie, client, transporter, conf); PgMng.Grow(); if (report != null) { ExportOptions options = new ExportOptions(); DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions(); string fileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); fileName += "\\" + ActiveItem.FileName; PgMng.Grow(String.Format(Face.Resources.Messages.EXPORTING_PDF, fileName), string.Empty); diskFileDestinationOptions.DiskFileName = fileName; options.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; options.ExportDestinationOptions = diskFileDestinationOptions; PgMng.Grow(); report.Export(options); PgMng.Grow(Face.Resources.Messages.SENDING_EMAIL); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(new MailAddress(client.Email, client.Nombre)); mail.From = new MailAddress(SettingsMng.Instance.GetSMTPMail(), company.Name); mail.Body = String.Format(Library.Invoice.Resources.Messages.FACTURA_EMAIL_ATTACHMENT_BODY, company.Name); mail.Subject = Library.Invoice.Resources.Messages.FACTURA_EMAIL_SUBJECT; mail.Attachments.Add(new Attachment(fileName)); try { PgMng.Grow(moleQule.Face.Resources.Messages.SENDING_EMAIL, string.Empty); EMailClient.Instance.SmtpCliente.Send(mail); if (item.EEstado == EEstado.Abierto) { ChangeStateAction(EEstadoItem.Emitido); } PgMng.ShowInfoException("Mensaje enviado con éxito"); } catch (Exception ex) { PgMng.ShowInfoException(ex.Message + Environment.NewLine + Environment.NewLine + moleQule.Library.Resources.Errors.SMTP_SETTINGS); } finally { mail.Dispose(); PgMng.FillUp(); } } else { PgMng.ShowInfoException(Face.Resources.Messages.NO_DATA_REPORTS); PgMng.FillUp(); } }