protected void btnModificar_Click(object sender, ImageClickEventArgs e) { this.txtRFC.Text = this.txtRFC.Text.Trim().ToUpper(); if (!CRutinas.Validar_RFC(this.txtRFC.Text)) { ((master_MasterPage)Page.Master).MostrarMensajeError("RFC no tiene el formato correcto"); return; } if (!string.IsNullOrEmpty(this.txtDiasEntrega.Text)) { byte btDias; if (!byte.TryParse(this.txtDiasEntrega.Text, out btDias)) { ((master_MasterPage)Page.Master).MostrarMensajeError("Días de entrega debe ser numérico y menor a 255 días"); return; } this.txtDiasEntrega.Text = btDias.ToString(); } if (this.hdID.Value.Equals("0")) { Agregar_Proveedor(); } else { Modificar_Proveedor(); } }
private string Validar_Campos() { if (!string.IsNullOrEmpty(this.txtCriterio.Text.Trim())) { StringBuilder strCriterio = new StringBuilder(); switch (this.dlBusqueda.SelectedValue) { case "0": case "1": strCriterio.Append("%"); strCriterio.Append(this.txtCriterio.Text.Trim()); strCriterio.Append("%"); break; case "2": if (this.dlRoles.Items.FindByText(CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim())) == null) { return("Criterio de búsqueda debe ser " + this.hdRoles.Value); } strCriterio.Append(this.dlRoles.Items.FindByText(CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim())).Value); break; case "3": if (!CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim()).Equals("Activo") && !CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim()).Equals("No activo")) { return("Criterio de búsqueda debe ser Activo, No activo"); } if (CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim()).Equals("Activo")) { strCriterio.Append("1"); } else { strCriterio.Append("0"); } break; } ViewState["SortCampo"] = "1"; ViewState["SortOrden"] = 1; ViewState["CriterioCampo"] = this.dlBusqueda.SelectedValue; ViewState["Criterio"] = strCriterio.ToString(); ViewState["PagActual"] = 1; Llenar_Grid(); this.lblMostrar.Visible = true; } else { return("Ingrese el criterio de búsqueda"); } return(string.Empty); }
private bool Validar_Email(string strTexto) { char[] chSeparador = new char[] { ' ' }; if (strTexto.Contains(",")) { chSeparador[0] = ','; } else if (strTexto.Contains(";")) { chSeparador[0] = ';'; } string[] strEmails = strTexto.Split(chSeparador); int intValidos = 0; foreach (string strEmail in strEmails) { if (!string.IsNullOrEmpty(strEmail)) { if (!CRutinas.Validar_Email(strEmail)) { return(false); } else { intValidos++; } } } if (intValidos > 0) { return(true); } else { return(false); } }
private string Validar_Campos() { if (!string.IsNullOrEmpty(this.txtCriterio.Text.Trim())) { DateTime dtFecha = DateTime.Today; long valor = 0; switch (this.dlBusqueda.SelectedValue) { case "0": if (!long.TryParse(this.txtCriterio.Text.Trim(), out valor)) { return("Criterio de búsqueda debe ser numérico"); } break; case "2": case "3": if (!CRutinas.FechaValida(this.txtCriterio.Text.Trim(), out dtFecha)) { return("Criterio de búsqueda no es una fecha válida, usar formato dd/mm/yyyy"); } break; case "4": if (this.dlEstatus.Items.FindByText(CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim())) == null) { return("Criterio de búsqueda debe ser " + this.hdEstatus.Value); } break; } StringBuilder strCriterio = new StringBuilder(); switch (this.dlBusqueda.SelectedValue) { case "0": strCriterio.Append(this.txtCriterio.Text.Trim()); break; case "1": case "5": strCriterio.Append("%"); strCriterio.Append(this.txtCriterio.Text.Trim()); strCriterio.Append("%"); break; case "2": case "3": strCriterio.Append(dtFecha.ToString("yyyy-MM-dd")); break; case "4": strCriterio.Append(this.dlEstatus.Items.FindByText(CRutinas.PrimeraLetraMayuscula(this.txtCriterio.Text.Trim())).Value); break; } ViewState["SortCampo"] = "4"; ViewState["SortOrden"] = 1; ViewState["CriterioCampo"] = this.dlBusqueda.SelectedValue; ViewState["Criterio"] = strCriterio.ToString(); Llenar_Grid(); this.lblMostrar.Visible = true; } else { return("Ingrese el criterio de búsqueda"); } return(string.Empty); }
public override void OnStartPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.DirectContent; cb.AddTemplate(pdfPage1, 0, 0); BaseFont fDetB = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); BaseFont fDet = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Image imgEmpresa = iTextSharp.text.Image.GetInstance(strMapPath + strLogoEmpresa); imgEmpresa.SetAbsolutePosition(45, 700); imgEmpresa.ScalePercent(flEscala, flEscala); document.Add(imgEmpresa); StringBuilder strTemp = new StringBuilder(); // -------------------------- urx, ury // | | // | | // | | // |________________________| // llx, lly //Dibujar linea para ver de donde a donde es //cb.MoveTo(50, 550); //cb.LineTo(360, 660); //cb.Stroke(); ColumnText ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strRazonSocial, FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 8))), 150, 700, 410, 744, 10, Element.ALIGN_LEFT); ct.Go(); strTemp.Clear(); //strTemp.Append(objDirEmisor.Direccion_Lineas_SinPais); strTemp.Append(objDirEmisor.Direccion_Lineas); strTemp.Append(" RFC: " + CRutinas.RFC_Guiones(strRFC)); if (!string.IsNullOrEmpty(strTelefono)) strTemp.Append("\nTel. " + strTelefono); if (!string.IsNullOrEmpty(strEmail)) strTemp.Append("\nEmail: " + strEmail); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strTemp.ToString(), FontFactory.GetFont(BaseFont.HELVETICA, 7))), 150, 600, 390, 730, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strNota, FontFactory.GetFont(BaseFont.HELVETICA, 10))), 425, 720, 567, 740, 10, Element.ALIGN_CENTER); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(dtFecha.ToString("dd"), FontFactory.GetFont(BaseFont.HELVETICA, 8))), 425, 670, 472, 685, 10, Element.ALIGN_CENTER); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(dtFecha.ToString("MM"), FontFactory.GetFont(BaseFont.HELVETICA, 8))), 472, 670, 519, 685, 10, Element.ALIGN_CENTER); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(dtFecha.ToString("yyyy"), FontFactory.GetFont(BaseFont.HELVETICA, 8))), 519, 670, 567, 685, 10, Element.ALIGN_CENTER); ct.Go(); strTemp.Clear(); strTemp.Append(strCliente + "\n"); strTemp.Append(objDirReceptor.Direccion_Lineas + "\n"); strTemp.Append("RFC: " + CRutinas.RFC_Guiones(strClienteRFC) + "\n"); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strTemp.ToString(), FontFactory.GetFont(BaseFont.HELVETICA, 7))), 50, 550, 315, 645, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(objEnvio.Direccion_Lineas, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 310, 550, 567, 645, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strContacto, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 310, 500, 567, 575, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strOrdenCompra, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 150, 500, 300, 560, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strNumeroCliente, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 365, 500, 567, 560, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strCotizacion, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 150, 500, 300, 546, 10, Element.ALIGN_LEFT); ct.Go(); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strEjecutivoVentas, FontFactory.GetFont(BaseFont.HELVETICA, 7))), 400, 500, 567, 546, 10, Element.ALIGN_LEFT); ct.Go(); strTemp.Clear(); strTemp.Append("SUBTOTAL:\n\n"); if (dcmDescuento != 0) strTemp.Append("SUBTOTAL CON DESCUENTO:\n\n"); strTemp.Append("IVA:\n\n"); strTemp.Append("TOTAL:"); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strTemp.ToString(), FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 7))), 410, 40, 490, 120, 10, Element.ALIGN_RIGHT); ct.Go(); strTemp.Clear(); strTemp.Append(dcmSubtotal.ToString("c") + " " + strMoneda + "\n\n"); if (dcmDescuento != 0) strTemp.Append(dcmDescuento.ToString("c") + " " + strMoneda + "\n\n"); strTemp.Append(dcmIVA.ToString("c") + " " + strMoneda + "\n\n"); strTemp.Append(dcmTotal.ToString("c") + " " + strMoneda + ""); ct = new ColumnText(cb); ct.SetSimpleColumn(new Phrase(new Chunk(strTemp.ToString(), FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 7))), 490, 40, 566, 120, 10, Element.ALIGN_RIGHT); ct.Go(); cb.BeginText(); cb.SetFontAndSize(fDet, 7); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Hoja " + writer.PageNumber + " de " + intTotalPaginas, 580, 20, 0); cb.EndText(); }
private void Crear_Archivo(int intTotalPaginas) { Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL)); int intMaxWidth = 190, intMaxHeight = 50, intLogoWidth, intLogoHeight; HttpCookie ckSIAN = Request.Cookies["userCng"]; int intNombreLogo = ckSIAN["ck_logo"].LastIndexOf("/") + 1; string[] strSize = ckSIAN["ck_logo_size"].Split('x'); intLogoWidth = int.Parse(strSize[0]); intLogoHeight = int.Parse(strSize[1]); float flRelacion = CRutinas.Calcular_Relacion(intMaxWidth, intMaxHeight, intLogoWidth, intLogoHeight); MyPageEvents events = new MyPageEvents(); events.strMapPath = Server.MapPath("../imagenes") + "/"; events.strLogoEmpresa = ckSIAN["ck_logo"].Substring(intNombreLogo); events.flEscala = flRelacion * 100; events.strCotizacion = this.strCotizacion; events.strRazonSocial = this.strRazonSocial; events.strRFC = this.strRFC; events.strTelefono = this.strTelefono; events.strEmail = this.strEmail; events.objDirEmisor = this.objDirEmisor; events.strNumeroCliente = this.strNumeroCliente; events.strCliente = this.strCliente; events.strClienteRFC = this.strClienteRFC; events.strDiasCredito = this.strDiasCredito; events.objDirReceptor = this.objDirReceptor; events.objEnvio = this.objEnvio; events.strEjecutivoVentas = this.strEjecutivoVentas; events.dtFecha = this.dtFecha; events.strNota = this.strNota; events.strOrdenCompra = this.strOrdenCompra; events.strContacto = this.strContacto; events.dcmSubtotal = this.dcmSubtotal; events.dcmDescuento = this.dcmDescuento; events.dcmIVA = this.dcmIVA; events.dcmTotal = this.dcmTotal; events.strMoneda = this.strMoneda; events.intTotalPaginas = intTotalPaginas; string strArchivoFormato = Server.MapPath("remision_ipisa.pdf"); PdfReader pdfEntrada = new PdfReader(strArchivoFormato); MemoryStream m = new MemoryStream(); Document document = new Document( new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height)); // 1 in = 25.4 mm = 72 points document.SetMargins(32.0f, 32.0f, 290.0f, 135.0f); Response.ContentType = "application/pdf"; PdfWriter writer; string strArchivo = "remision_" + Request.QueryString["notID"] + ".pdf"; if (Request.QueryString["m"] == null) { writer = PdfWriter.GetInstance(document, m); writer.CloseStream = false; } else { FileStream flArchivo = new FileStream(Server.MapPath("../xml_facturas" + HttpContext.Current.Request.ApplicationPath + "/" + strArchivo), FileMode.Create); writer = PdfWriter.GetInstance(document, flArchivo); } writer.PageEvent = events; events.pdfPage1 = writer.GetImportedPage(pdfEntrada, 1); document.Open(); float[] ancho_columnas = new float[6]; ancho_columnas[0] = 50; ancho_columnas[1] = 75; ancho_columnas[2] = 242; ancho_columnas[3] = 63; ancho_columnas[4] = 62; ancho_columnas[5] = 74; char tab = '\u0009'; foreach (CProducto objProducto in this.lstProductos) { PdfPTable tblLinea = new PdfPTable(ancho_columnas); tblLinea.TotalWidth = 532; tblLinea.DefaultCell.Border = Rectangle.NO_BORDER; tblLinea.HorizontalAlignment = Element.ALIGN_LEFT; tblLinea.LockedWidth = true; Paragraph texto = new Paragraph(string.Empty, ftProductos); PdfPCell celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph(objProducto.StrCodigo, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); if (!string.IsNullOrEmpty(objProducto.StrDetalle)) texto = new Paragraph(objProducto.StrDescripcion + "\n" + objProducto.StrDetalle.Replace(tab.ToString(), " "), ftProductos); else texto = new Paragraph(objProducto.StrDescripcion, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; if (objProducto.IntGrupoID == 0) celda.PaddingLeft = 0; else celda.PaddingLeft = 10; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); document.Add(tblLinea); } document.Close(); if (Request.QueryString["m"] == null) { Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End(); m.Close(); } else Response.Redirect("cotizacion_correo.aspx?t=c&c=" + Request.QueryString["notID"] + "&f=" + strArchivo); }
private void Generar_Reporte(string strTipo) { if (Request.QueryString["m"] == null) { Response.Clear(); } DataSet objDataResult = new DataSet(); string strQuery = string.Empty; switch (strTipo) { case "o": strQuery = "SELECT ID, monto_subtotal, descuento, monto_descuento " + ",porc_iva, monto_iva, total " + " FROM compra_orden " + " WHERE ID = " + Request.QueryString["c"].ToString(); break; case "c": strQuery = "SELECT ID, monto_subtotal, descuento, monto_descuento " + ",porc_iva, monto_iva, total " + " FROM compra " + " WHERE ID = " + Request.QueryString["c"].ToString(); break; case "d": strQuery = "SELECT ID, monto_subtotal, descuento, monto_descuento " + ",porc_iva, monto_iva, total " + " FROM compra_dev " + " WHERE ID = " + Request.QueryString["c"].ToString(); break; } try { objDataResult = CComunDB.CCommun.Ejecutar_SP(strQuery); } catch (ApplicationException ex) { throw new ApplicationException("Error: " + ex.Message); } DataRow objRowResultC = objDataResult.Tables[0].Rows[0]; switch (strTipo) { case "o": strQuery = "SELECT P.proveedor, P.contacto, C.fecha_creacion " + " FROM compra_orden C" + " INNER JOIN proveedores P " + " ON C.proveedorID = P.ID " + " WHERE C.ID = " + Request.QueryString["c"].ToString(); break; case "c": strQuery = "SELECT P.proveedor, P.contacto, C.fecha_creacion " + " FROM compra C" + " INNER JOIN proveedores P " + " ON C.proveedorID = P.ID " + " WHERE C.ID = " + Request.QueryString["c"].ToString(); break; case "d": strQuery = "SELECT P.proveedor, P.contacto, C.fecha_creacion " + " FROM compra_dev C" + " INNER JOIN proveedores P " + " ON C.proveedorID = P.ID " + " WHERE C.ID = " + Request.QueryString["c"].ToString(); break; } try { objDataResult = CComunDB.CCommun.Ejecutar_SP(strQuery); } catch (ApplicationException ex) { throw new ApplicationException("Error: " + ex.Message); } DataRow objRowResultE = objDataResult.Tables[0].Rows[0]; switch (strTipo) { case "o": strQuery = "SELECT * FROM (" + "SELECT C.productoID as productoID " + ", C.cantidad as cantidad " + ", C.consecutivo as consecutivo " + ", C.costo_unitario as costo_unitario " + ", C.costo as costo " + ", C.exento as exento " + ", P.nombre as producto " + ", P.codigo " + ", TRIM(P.ubicacion) as ubicacion " + " FROM compra_orden_productos C " + " INNER JOIN productos P " + " ON C.productoID = P.ID " + " AND compra_ordenID = " + Request.QueryString["c"].ToString() + ") AS AA ORDER BY consecutivo, producto"; break; case "c": strQuery = "SELECT * FROM (" + "SELECT C.productoID as productoID " + ", C.cantidad as cantidad " + ", C.consecutivo as consecutivo " + ", C.costo_unitario as costo_unitario " + ", C.costo as costo " + ", C.exento as exento " + ", P.nombre as producto " + ", P.codigo " + ", TRIM(P.ubicacion) as ubicacion " + " FROM compra_productos C " + " INNER JOIN productos P " + " ON C.productoID = P.ID " + " AND compraID = " + Request.QueryString["c"].ToString() + ") AS AA ORDER BY consecutivo, producto"; break; case "d": strQuery = "SELECT * FROM (" + "SELECT C.productoID as productoID " + ", C.cantidad as cantidad " + ", C.consecutivo as consecutivo " + ", C.costo_unitario as costo_unitario " + ", C.costo as costo " + ", C.exento as exento " + ", P.nombre as producto " + ", P.codigo " + ", TRIM(P.ubicacion) as ubicacion " + " FROM compra_dev_productos C " + " INNER JOIN productos P " + " ON C.productoID = P.ID " + " AND compra_devID = " + Request.QueryString["c"].ToString() + ") AS AA ORDER BY consecutivo, producto"; break; } try { objDataResult = CComunDB.CCommun.Ejecutar_SP(strQuery); } catch (ApplicationException ex) { throw new ApplicationException("Error: " + ex.Message); } FileInfo newFile; int intRegistros = objDataResult.Tables[0].Rows.Count; DataRow[] dtUbicacion = objDataResult.Tables[0].Select("ubicacion <> ''"); intRegistros += dtUbicacion.Length; int intMaxRow; if (intRegistros < 31) { newFile = new FileInfo(Server.MapPath(@"./formatocompra.xlsx")); intMaxRow = 42; } else if (intRegistros < 61) { newFile = new FileInfo(Server.MapPath(@"./formatocompra60.xlsx")); intMaxRow = 72; } else { newFile = new FileInfo(Server.MapPath(@"./formatocompra100.xlsx")); intMaxRow = 112; } ExcelPackage xlsFile = new ExcelPackage(newFile); ExcelWorksheet xlsWorkSheet = xlsFile.Workbook.Worksheets.First(); xlsWorkSheet.Cells["E9"].Value = CRutinas.PrimeraLetraMayuscula(((DateTime)objRowResultE["fecha_creacion"]).ToString("ddd dd MMM yy", CultureInfo.CreateSpecificCulture("es-MX"))); switch (strTipo) { case "o": xlsWorkSheet.Cells["D10"].Value = "ORDEN DE COMPRA " + objRowResultC["ID"].ToString(); break; case "c": xlsWorkSheet.Cells["D10"].Value = "COMPRA " + objRowResultC["ID"].ToString(); break; case "d": xlsWorkSheet.Cells["D10"].Value = "DEVOLUCIÓN " + objRowResultC["ID"].ToString(); break; } xlsWorkSheet.Cells["B9"].Value = objRowResultE["contacto"].ToString(); xlsWorkSheet.Cells["B10"].Value = objRowResultE["proveedor"].ToString(); int intRow = 12; foreach (DataRow objRowResult in objDataResult.Tables[0].Rows) { string strProducto = string.Empty; if (intRow < intMaxRow) { if (Convert.ToBoolean(objRowResult["exento"])) { strProducto = "(" + objRowResult["codigo"].ToString() + ") " + objRowResult["producto"].ToString(); } else { strProducto = "(" + objRowResult["codigo"].ToString() + ") " + objRowResult["producto"].ToString() + "*"; } xlsWorkSheet.Cells["A" + intRow.ToString()].Value = (decimal)objRowResult["cantidad"]; xlsWorkSheet.Cells["B" + intRow.ToString()].Value = strProducto; xlsWorkSheet.Cells["D" + intRow.ToString()].Value = (decimal)objRowResult["costo_unitario"]; } intRow++; if (!string.IsNullOrEmpty(objRowResult["ubicacion"].ToString()) && intRow < intMaxRow) { xlsWorkSheet.Cells["B" + intRow.ToString()].Value = objRowResult["ubicacion"].ToString(); intRow++; } } if (intRegistros < 31) { xlsWorkSheet.Cells["D45"].Value = "IVA " + ((decimal)objRowResultC["porc_iva"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E45"].Value = ((decimal)objRowResultC["monto_iva"]).ToString("c"); xlsWorkSheet.Cells["E46"].Value = ((decimal)objRowResultC["total"]).ToString("c"); if ((decimal)objRowResultC["monto_descuento"] != 0) { xlsWorkSheet.Cells["D44"].Value = "MONTO DESCTO " + ((decimal)objRowResultC["descuento"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E44"].Value = ((decimal)objRowResultC["monto_descuento"]).ToString("c"); } else { xlsWorkSheet.DeleteRow(44, 1); } } else if (intRegistros < 61) { xlsWorkSheet.Cells["D75"].Value = "IVA " + ((decimal)objRowResultC["porc_iva"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E75"].Value = ((decimal)objRowResultC["monto_iva"]).ToString("c"); xlsWorkSheet.Cells["E76"].Value = ((decimal)objRowResultC["total"]).ToString("c"); if ((decimal)objRowResultC["monto_descuento"] != 0) { xlsWorkSheet.Cells["D74"].Value = "MONTO DESCTO " + ((decimal)objRowResultC["descuento"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E74"].Value = ((decimal)objRowResultC["monto_descuento"]).ToString("c"); } else { xlsWorkSheet.DeleteRow(74, 1); } } else { xlsWorkSheet.Cells["D115"].Value = "IVA " + ((decimal)objRowResultC["porc_iva"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E115"].Value = ((decimal)objRowResultC["monto_iva"]).ToString("c"); xlsWorkSheet.Cells["E116"].Value = ((decimal)objRowResultC["total"]).ToString("c"); if ((decimal)objRowResultC["monto_descuento"] != 0) { xlsWorkSheet.Cells["D114"].Value = "MONTO DESCTO " + ((decimal)objRowResultC["descuento"]).ToString("0.##") + "%"; xlsWorkSheet.Cells["E114"].Value = ((decimal)objRowResultC["monto_descuento"]).ToString("c"); } else { xlsWorkSheet.DeleteRow(114, 1); } } Regex regexInValidChars = new Regex(@"[\\\/:\*\?""'<>|]"); string strFile = string.Empty; switch (strTipo) { case "o": strFile = regexInValidChars.Replace(objRowResultE["proveedor"].ToString(), "").Replace(" ", "_") + "_ORD_" + Request.QueryString["c"].ToString() + ".xlsx"; break; case "c": strFile = regexInValidChars.Replace(objRowResultE["proveedor"].ToString(), "").Replace(" ", "_") + "_COM_" + Request.QueryString["c"].ToString() + ".xlsx"; break; case "d": strFile = regexInValidChars.Replace(objRowResultE["proveedor"].ToString(), "").Replace(" ", "_") + "_DEV_" + Request.QueryString["c"].ToString() + ".xlsx"; break; } if (Request.QueryString["m"] == null) { Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", "attachment; " + "filename=" + strFile); Response.BinaryWrite(xlsFile.GetAsByteArray()); Response.End(); } else { try { Byte[] btArchivo = xlsFile.GetAsByteArray(); File.WriteAllBytes(Server.MapPath("../xml_facturas") + "/" + strFile, btArchivo); } catch { } Response.Redirect("compras_correo.aspx?t=" + strTipo + "&c=" + Request.QueryString["c"].ToString() + "&f=" + strFile); } }
public override void OnStartPage(PdfWriter writer, Document document) { StringBuilder strCadena = new StringBuilder(); Font ftHeader = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL)); Font ftFooter = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL)); Font ftHeaderB = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD)); Font ftFooterB = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.BOLD)); Font ftHeader30 = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 30, Font.NORMAL)); Font ftHeader11 = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.NORMAL)); Rectangle page = document.PageSize; #region Header PdfPTable tblHeaderA = new PdfPTable(1); PdfPTable tblHeaderB = new PdfPTable(1); PdfPTable tblHeaderC = new PdfPTable(1); tblHeaderA.TotalWidth = page.Width - document.LeftMargin - document.RightMargin; tblHeaderA.DefaultCell.Border = Rectangle.NO_BORDER; tblHeaderA.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; tblHeaderB.TotalWidth = page.Width - document.LeftMargin - document.RightMargin; tblHeaderB.DefaultCell.Border = Rectangle.NO_BORDER; tblHeaderB.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; tblHeaderC.TotalWidth = page.Width - document.LeftMargin - document.RightMargin; tblHeaderC.DefaultCell.Border = Rectangle.NO_BORDER; tblHeaderC.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; float[] ancho_columnas = new float[2]; ancho_columnas[0] = 120; ancho_columnas[1] = tblHeaderA.TotalWidth - 120; PdfPTable tblHeader1 = new PdfPTable(ancho_columnas); iTextSharp.text.Image imgEmpresa = iTextSharp.text.Image.GetInstance(_strMapPath + _strLogoEmpresa); imgEmpresa.SetAbsolutePosition(45, 700); imgEmpresa.ScalePercent(_flEscala, _flEscala); document.Add(imgEmpresa); // iTextSharp.text.Imagen de la empresa PdfPCell celda = new PdfPCell(); celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_MIDDLE; celda.Border = Rectangle.NO_BORDER; tblHeader1.AddCell(celda); // Datos Fiscales Paragraph texto = new Paragraph(_strNombreEmisor + "\n", ftHeader); strCadena.Append(_dirDomicilioFiscal.StrCalle); strCadena.Append(" "); strCadena.Append(_dirDomicilioFiscal.StrNumeroExterior); if (!string.IsNullOrEmpty(_dirDomicilioFiscal.StrNumeroInterior)) { strCadena.Append("-"); strCadena.Append(_dirDomicilioFiscal.StrNumeroInterior); } texto.Add(new Paragraph(strCadena.ToString(), ftHeader)); texto.Add(new Paragraph(_dirDomicilioFiscal.StrColonia, ftHeader)); strCadena.Remove(0, strCadena.Length); strCadena.Append(_dirDomicilioFiscal.StrLocalidad); strCadena.Append(", "); strCadena.Append(_dirDomicilioFiscal.StrEstado); strCadena.Append(", "); strCadena.Append(_dirDomicilioFiscal.StrPais); texto.Add(new Paragraph(strCadena.ToString(), ftHeader)); texto.Add(new Paragraph("C.P. " + _dirDomicilioFiscal.StrCP, ftHeader)); texto.Add(new Paragraph("RFC " + _strRFCEmisor, ftHeader)); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.VerticalAlignment = Element.ALIGN_MIDDLE; celda.Border = Rectangle.NO_BORDER; tblHeader1.AddCell(celda); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.VerticalAlignment = Element.ALIGN_MIDDLE; celda.Border = Rectangle.NO_BORDER; tblHeader1.AddCell(celda); tblHeaderA.AddCell(tblHeader1); //Datos Expedición float[] ancho_columnas2 = new float[4]; ancho_columnas2[0] = 100; ancho_columnas2[1] = 200; ancho_columnas2[3] = 100; ancho_columnas2[2] = tblHeaderB.TotalWidth - 400; PdfPTable tblHeader2 = new PdfPTable(ancho_columnas2); texto = new Paragraph("AT'N:", ftHeaderB); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph(_strContacto, ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph("FECHA:", ftHeaderB); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph(CRutinas.Fecha_DD_MMM_YYYY(_dtFechaCertificado), ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph(string.Empty, ftHeaderB); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph(_strNombreCliente, ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph("REMISIÓN:", ftHeaderB); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); texto = new Paragraph(_strNotaID, ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblHeader2.AddCell(celda); tblHeaderB.AddCell(tblHeader2); // Cuádricula para los productos PdfContentByte cb = writer.DirectContent; // x, y, ancho, alto cb.Rectangle(30, 600, 550, 15); cb.Stroke(); cb.MoveTo(100, 600); cb.LineTo(100, 615); cb.Stroke(); cb.MoveTo(440, 600); cb.LineTo(440, 615); cb.Stroke(); cb.MoveTo(520, 600); cb.LineTo(520, 615); cb.Stroke(); cb.Rectangle(30, 150, 550, 440); cb.Stroke(); cb.MoveTo(100, 150); cb.LineTo(100, 590); cb.Stroke(); cb.MoveTo(440, 150); cb.LineTo(440, 590); cb.Stroke(); cb.MoveTo(520, 150); cb.LineTo(520, 590); cb.Stroke(); // Encabezados de los productos float[] ancho_columnas3 = new float[4]; ancho_columnas3[0] = 55; ancho_columnas3[1] = 345; ancho_columnas3[2] = 68; ancho_columnas3[3] = 60; PdfPTable tblHeader3 = new PdfPTable(ancho_columnas3); texto = new Paragraph("CANTIDAD", ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.Border = Rectangle.NO_BORDER; tblHeader3.AddCell(celda); texto = new Paragraph("DESCRIPCIÓN", ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.Border = Rectangle.NO_BORDER; tblHeader3.AddCell(celda); texto = new Paragraph("P.UNITARIO", ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.Border = Rectangle.NO_BORDER; tblHeader3.AddCell(celda); texto = new Paragraph("TOTAL", ftHeader); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.Border = Rectangle.NO_BORDER; tblHeader3.AddCell(celda); tblHeaderC.AddCell(tblHeader3); #endregion tblHeaderA.WriteSelectedRows(0, -1, 0, -1, document.LeftMargin, 760, writer.DirectContent); tblHeaderB.WriteSelectedRows(0, -1, 0, -1, document.LeftMargin, 670, writer.DirectContent); tblHeaderC.WriteSelectedRows(0, -1, 0, -1, document.LeftMargin, 617, writer.DirectContent); #region Footer PdfPTable tblFooterA = new PdfPTable(1); PdfPTable tblFooterB = new PdfPTable(1); tblFooterA.TotalWidth = page.Width - document.LeftMargin - document.RightMargin; tblFooterA.DefaultCell.Border = Rectangle.NO_BORDER; tblFooterA.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; tblFooterB.TotalWidth = page.Width - document.LeftMargin - document.RightMargin; tblFooterB.DefaultCell.Border = Rectangle.NO_BORDER; tblFooterB.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; float[] ancho_columnasFA = new float[3]; ancho_columnasFA[0] = 380; ancho_columnasFA[1] = 88; ancho_columnasFA[2] = 60; PdfPTable tblFooter1 = new PdfPTable(ancho_columnasFA); texto = new Paragraph(_strTotalLetras.ToUpper(), ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Rowspan = 2; tblFooter1.AddCell(celda); texto = new Paragraph("SUBTOTAL:", ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph(_amtSubTotal.ToString("c"), ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.BOTTOM_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); if (_amtDescuento > 0) { texto = new Paragraph("MONTO CON DESCUENTO:", ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); decimal amtConDescuento = _amtSubTotal - _amtDescuento; texto = new Paragraph(amtConDescuento.ToString("c"), ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.BOTTOM_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph(string.Empty, ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); } texto = new Paragraph("IVA " + _amtTasa + "%:", ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph(_amtImpuesto.ToString("c"), ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.BOTTOM_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph(string.Empty, ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph("TOTAL:", ftFooterB); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; tblFooter1.AddCell(celda); texto = new Paragraph(_amtTotal.ToString("c"), ftFooterB); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Border = Rectangle.BOTTOM_BORDER; tblFooter1.AddCell(celda); texto = new Paragraph(" \n\n\n ", ftFooter); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 3; tblFooter1.AddCell(celda); tblFooterA.AddCell(tblFooter1); float[] ancho_columnasFB = new float[4]; ancho_columnasFB[0] = 200; ancho_columnasFB[1] = 200; ancho_columnasFB[2] = 200; ancho_columnasFB[3] = 200; PdfPTable tblFooter2 = new PdfPTable(ancho_columnasFB); texto = new Paragraph(string.Empty, ftHeaderB); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 2; tblFooter2.AddCell(celda); texto = new Paragraph(_strVendedor, ftHeader); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); texto = new Paragraph(string.Empty, ftHeaderB); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); texto = new Paragraph("CLIENTE", ftHeader); celda = new PdfPCell(texto); celda.Border = Rectangle.TOP_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); texto = new Paragraph(string.Empty, ftHeaderB); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); texto = new Paragraph("VENDEDOR", ftHeaderB); celda = new PdfPCell(texto); celda.Border = Rectangle.TOP_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); texto = new Paragraph(string.Empty, ftHeaderB); celda = new PdfPCell(texto); celda.Border = Rectangle.NO_BORDER; celda.HorizontalAlignment = Element.ALIGN_CENTER; celda.VerticalAlignment = Element.ALIGN_TOP; celda.Colspan = 1; tblFooter2.AddCell(celda); tblFooterB.AddCell(tblFooter2); #endregion tblFooterA.WriteSelectedRows(0, -1, 0, -1, document.LeftMargin, 150, writer.DirectContent); tblFooterB.WriteSelectedRows(0, -1, 0, -1, document.LeftMargin, 90, writer.DirectContent); }
private void Crear_Archivo(int intTotalPaginas) { int intMaxWidth = 190, intMaxHeight = 50, intLogoWidth, intLogoHeight; HttpCookie ckSIAN = Request.Cookies["userCng"]; int intNombreLogo = ckSIAN["ck_logo"].LastIndexOf("/") + 1; string[] strSize = ckSIAN["ck_logo_size"].Split('x'); intLogoWidth = int.Parse(strSize[0]); intLogoHeight = int.Parse(strSize[1]); float flRelacion = CRutinas.Calcular_Relacion(intMaxWidth, intMaxHeight, intLogoWidth, intLogoHeight); Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL)); MyPageEvents events = new MyPageEvents(); events._strNotaID = strNotaID; events._strContacto = strContacto; events._strCertificado = objFactura.StrCertificadoSAT; events._strFolioFiscal = objFactura.StrFolioFiscal; events._strSelloCFDI = objFactura.StrSelloCFDI; events._strSelloSAT = objFactura.StrSelloSAT; events._strCadenaOriginal = "N/A"; events._intFolio = objFactura.IntFolio; events._dtFechaCertificado = objFactura.DtFechaCertificado; events._intNoAprobacion = objFactura.IntNoAprobacion; events._intAnoAprobacion = objFactura.IntAnoAprobacion; events._strMetodoDePago = objFactura.StrMetodoDePago; events._strCondicionesDePago = objFactura.StrCondicionesDePago; events._amtSubTotal = objFactura.AmtSubTotal; events._amtDescuento = objFactura.AmtDescuento; events._amtTotal = objFactura.AmtTotal; events._strTotalLetras = CRutinas.ObtenerImporteLetras(objFactura.AmtTotal, objFactura.StrMoneda); events._strRFCEmisor = objFactura.StrRFCEmisor; events._strNombreEmisor = objFactura.StrNombreEmisor; events._dirDomicilioFiscal = objFactura.DirDomicilioFiscal; events._dirDomicilioExpedicion = objFactura.DirDomicilioExpedicion; events._strRFCCliente = objFactura.StrRFCCliente; events._strNombreCliente = objFactura.StrNombreCliente; events._strCedulaFiscalCliente = objFactura.StrCedulaFiscalCliente; events._strCedulaIEPSCliente = objFactura.StrCedulaIEPSCliente; events._dirDomicilioCliente = objFactura.DirDomicilioCliente; events._amtTotalImpuestosRetenidos = objFactura.AmtTotalImpuestosRetenidos; events._amtImpuesto = objFactura.AmtImpuesto; events._amtTasa = objFactura.AmtTasa; events._amtImporte = objFactura.AmtImporte; events._amtTotalImpuestos = objFactura.AmtTotalImpuestos; events._strMapPath = Server.MapPath("../imagenes") + "/"; events._strLogoEmpresa = ckSIAN["ck_logo"].Substring(intNombreLogo); events._flEscala = flRelacion * 100; events._intTotalPaginas = intTotalPaginas; events._strOrdenCompra = string.Empty; events._strProveedor = strProveedor; events._strVendedor = strVendedor; MemoryStream m = new MemoryStream(); Document document = new Document( new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height)); // 1 in = 25.4 mm = 72 points document.SetMargins(32.0f, 32.0f, 205.0f, 150.0f); Response.ContentType = "application/pdf"; PdfWriter writer = PdfWriter.GetInstance(document, m); writer.CloseStream = false; writer.PageEvent = events; document.Open(); float[] ancho_columnas = new float[5]; ancho_columnas[0] = 60; ancho_columnas[1] = 10; ancho_columnas[2] = 335; ancho_columnas[3] = 73; ancho_columnas[4] = 60; foreach (CProducto objProducto in objFactura.LstProductos) { PdfPTable tblLinea = new PdfPTable(ancho_columnas); tblLinea.TotalWidth = 548; tblLinea.DefaultCell.Border = Rectangle.NO_BORDER; tblLinea.HorizontalAlignment = Element.ALIGN_LEFT; tblLinea.LockedWidth = true; Paragraph texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos); PdfPCell celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph(string.Empty, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph(objProducto.StrDescripcion, ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_LEFT; celda.Border = Rectangle.NO_BORDER; if (objProducto.IntGrupoID == 0) { celda.PaddingLeft = 0; } else { celda.PaddingLeft = 10; } tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos); celda = new PdfPCell(texto); celda.HorizontalAlignment = Element.ALIGN_RIGHT; celda.Border = Rectangle.NO_BORDER; tblLinea.AddCell(celda); document.Add(tblLinea); } document.Close(); Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End(); m.Close(); }
public bool Enviar(out string strError) { strError = string.Empty; if (string.IsNullOrEmpty(strAsunto)) { strError = "Asunto es requerido"; return(false); } if (string.IsNullOrEmpty(strDe)) { strError = "Dirección de correo DE es requerida"; return(false); } if (!CRutinas.Validar_Email(strDe)) { strError = "Dirección de correo DE no es válida"; return(false); } if (strPara.Count == 0) { strError = "Dirección de correo PARA es requerida"; return(false); } foreach (string strEmail in strPara) { if (!CRutinas.Validar_Email(strEmail)) { strError = "Dirección de correo PARA no es válida"; return(false); } } if (strPara.Count != 0) { foreach (string strEmail in strCC) { if (!CRutinas.Validar_Email(strEmail)) { strError = "Dirección de correo CC no es válida"; return(false); } } } HttpCookie ckSIAN = System.Web.HttpContext.Current.Request.Cookies["userCng"]; string img_path = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath) + System.Web.HttpContext.Current.Request.ApplicationPath + ckSIAN["ck_logo"]; string[] strSize = ckSIAN["ck_logo_size"].Split('x'); int intLogoWidth = int.Parse(strSize[0]); int intLogoHeight = int.Parse(strSize[1]); int max_pixeles = 200; if (intLogoWidth > max_pixeles || intLogoHeight > max_pixeles) { double relacion = 0; if (intLogoWidth > intLogoHeight) { relacion = max_pixeles / (double)intLogoWidth; } else { relacion = max_pixeles / (double)intLogoHeight; } intLogoWidth = (int)(intLogoWidth * relacion); intLogoHeight = (int)(intLogoHeight * relacion); } string strImgSize = " height=\"" + intLogoHeight.ToString() + "\" width=\"" + intLogoWidth.ToString() + "\""; MailMessage objMailMensaje = new MailMessage(); objMailMensaje.From = new MailAddress(this.strDe); foreach (string strEmail in strPara) { objMailMensaje.To.Add(new MailAddress(strEmail)); } foreach (string strEmail in strCC) { objMailMensaje.CC.Add(new MailAddress(strEmail)); } objMailMensaje.Subject = strAsunto.Trim(); LinkedResource logo = new LinkedResource(img_path); logo.ContentId = "companylogo"; AlternateView av1 = AlternateView.CreateAlternateViewFromString( "<html><body><table><tr><td style='font-size: 11px; font-family: Verdana;'>" + strMensaje.Trim().Replace("\r\n", "<br />") + "</td></tr><tr>" + "<td align='left'><img src=cid:companylogo" + strImgSize + "/></td>" + "</tr></table></body></html>", null, System.Net.Mime.MediaTypeNames.Text.Html); av1.LinkedResources.Add(logo); objMailMensaje.AlternateViews.Add(av1); objMailMensaje.IsBodyHtml = true; foreach (string strAtt in strAttachments) { try { if (File.Exists(strAtt)) { objMailMensaje.Attachments.Add(new Attachment(strAtt)); } } catch { } } SmtpClient objSmtp = new SmtpClient(); try { objSmtp.Send(objMailMensaje); return(true); } catch (Exception ex) { strError = "No se pudo enviar el correo: " + ex.Message; } return(false); }