private void ProcessDownload(string EmpresaID) { FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService(); string strId = Request.QueryString["nc"]; string strTipoCbte = Request.QueryString["nt"]; string strNumeroLegal = Request.QueryString["leg"]; try { Settings oSettings = new Settings(EmpresaID); FEPrintService.Url = oSettings.UrlPrintWebService; FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials; byte[] fileData = null; switch (Request.QueryString["type"]) { case "o": fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original);//(byte[])sqlDReader["PDF" + strType]; break; case "d": fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Duplicado); break; case "t": fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Triplicado); break; case "c": fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Copia); break; } if (fileData != null) { Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=" + strNumeroLegal + ".pdf"); Response.ContentType = "application/pdf"; BinaryWriter bw = new BinaryWriter(Response.OutputStream); bw.Write(fileData); bw.Close(); Response.End(); } else { lblMsg.Text = "No se pudo generar archivo PDF.<br>No se encontro detalle del comprobante."; } } catch (Exception ex) { throw (ex); } }
//todo: hacer private void ProcessDownload(string EmpresaID) { Settings oSettings = new Settings(EmpresaID); FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService(); FEPrintService.Url = oSettings.UrlPrintWebService; FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials; string strIds = Request.QueryString["ids"]; string strId = string.Empty; string strTipoCbte = string.Empty; string strNumeroLegal = string.Empty; string strTipoCbteName = string.Empty; try { foreach (string strCbte in strIds.Split('|')) { if (strCbte != string.Empty && strCbte.Split(';').Length == 3) { strId = strCbte.Split(';')[0]; strTipoCbte = strCbte.Split(';')[1]; strNumeroLegal = strCbte.Split(';')[2]; string fileName = oSettings.PathTemporales + @"\" + strNumeroLegal; FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original);//(byte[])sqlDReader["PDF" + strType]; if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Original.pdf")) fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Original.pdf", "Comprobantes"); if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Duplicado.pdf")) fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Duplicado.pdf", "Comprobantes"); if (!fiZip.EntryFileNames.Contains("Comprobantes/" + strNumeroLegal + "-" + strTipoCbteName + "-Triplicado.pdf")) fiZip.AddFile(fileName + "-" + strTipoCbteName + "-Triplicado.pdf", "Comprobantes"); } } if (fiZip.Count > 0) { LoadZipFile(fiZip); } } catch (Exception ex) { Response.Write(ex.Message); Response.End(); } Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "window.close();", true); }
protected void btnSend_Click(object sender, EventArgs e) { string strIds = Request.QueryString["ids"]; string strId = string.Empty; MailMessage oMessage = null; Attachment oAttach = null; SmtpClient emailClient = null; System.Net.NetworkCredential SMTPUserInfo = null; FEPrint.FEPrintService FEPrintService = new FEPrint.FEPrintService(); byte[] fileData = null; Stream oStream = null; DataTable dtCbte = new DataTable(); DataTable dtUser = new DataTable(); TableRow tbRow; TableCell tbCell; try { tblComprobantes.Rows.Clear(); btnSend.Visible = false; EmpresaID = Request.QueryString["eid"]; Settings oSettings = new Settings(EmpresaID); FEPrintService.Url = oSettings.UrlPrintWebService; FEPrintService.Credentials = System.Net.CredentialCache.DefaultCredentials; foreach (string strCbte in strIds.Split('|')) { tbCell = new TableCell(); tbRow = new TableRow(); if (strCbte != string.Empty && strCbte.Split(';').Length == 2) { strId = strCbte.Split(';')[0]; dtCbte = GetComprobanteDataTable(strId); if (dtCbte.Rows[0]["COMPRADORCODIGOCLIENTE"].ToString() != string.Empty) { dtUser = GetUserData(oSettings.Entrada.Split('\\')[0], oSettings.Entrada.Split('\\')[1], "IFMSFA_TERCEROS_AFIP", dtCbte.Rows[0]["COMPRADORCODIGOCLIENTE"].ToString()); if (dtUser.Rows.Count > 0) { if (dtUser.Rows[0]["CORREO"].ToString() != string.Empty) { fileData = FEPrintService.GetCbte(EmpresaID, strId, FEPrint.TipoDeCopia.Original); oStream = new MemoryStream(fileData); oAttach = new Attachment(oStream, "Comprobante.pdf"); oMessage = new MailMessage(oSettings.SMTPFrom, dtUser.Rows[0]["CORREO"].ToString(), oSettings.MailSubject, oSettings.MailMessage); oMessage.Attachments.Add(oAttach); if (oSettings.SMTPServer != string.Empty) { emailClient = new SmtpClient(oSettings.SMTPServer); if (oSettings.SMTPUser != string.Empty && oSettings.SMTPPassword != string.Empty) { SMTPUserInfo = new System.Net.NetworkCredential(oSettings.SMTPUser, oSettings.SMTPPassword); emailClient.UseDefaultCredentials = false; emailClient.Credentials = SMTPUserInfo; } emailClient.Send(oMessage); tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - OK.<br>")); } } else { tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - El cliente no tiene correo.<br>")); } } else { tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - No hay información de Usuario para este cliente.<br>")); } } else { tbCell.Controls.Add(new LiteralControl(dtCbte.Rows[0]["nrocomprobantedesde"].ToString() + " - El cliente no tiene un usuario creado.<br>")); } } tbRow.Cells.Add(tbCell); tblComprobantes.Rows.Add(tbRow); } } catch (Exception ex) { tblComprobantes.Rows.Clear(); lblErrors.Text = "Error Enviando Correos. " + ex.Message; } }