private void CreatePDF(string ruta) { try { using (FileStream msReport = new FileStream(ruta, FileMode.Create)) { //step 1 using (Document pdfDoc = new Document(PageSize.LETTER, 22f, 10f, 180f, 40f)) { try { // step 2 PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport); ITextOEN ITE = new ITextOEN(); ITE.NombreDoc = "ORDEN DE ENTRADA OEN"; ITE.NoDoc = OENGralSeleccionada.Id.ToString(); ITE.CodigoDoc = OENGralSeleccionada.CODIGODEBARRAS; ITE.FechaDoc = OENGralSeleccionada.FECHA; ITE.NombreProveedor = ProveedorSeleccionado.NOMBRE; ITE.total = totales; pdfWriter.PageEvent = ITE; //open the stream pdfDoc.Open(); #region tablas // Conv conv = new Conv(); PdfPTable NombreColumnas2 = new PdfPTable(5); NombreColumnas2.TotalWidth = pdfDoc.PageSize.Width - 90f; NombreColumnas2.LockedWidth = true; NombreColumnas2.WidthPercentage = 70; float[] widths2 = new float[] { 1f, 4f, 8f, 1f, 2 }; NombreColumnas2.SetWidths(widths2); #region foreach foreach (oen_indiv partida in OENGralSeleccionada.PARTIDAS) { productos pctos = new productos(partida.ID_PRODUCTO); PdfPCell item = new PdfPCell(new Phrase(partida.ITEM.ToString(), ITextEvents.arial2)); item.HorizontalAlignment = 1; item.VerticalAlignment = Element.ALIGN_MIDDLE; // item.BackgroundColor = BaseColor.LIGHT_GRAY; NombreColumnas2.AddCell(item); PdfPCell Catalogo; Catalogo = new PdfPCell(new Phrase(pctos.CATALOGO, ITextEvents.arial2)); // PdfPCell Catalogo = new PdfPCell(new Phrase(partida.ALIAS, ITextEvents.arial2)); Catalogo.FixedHeight = 22f; Catalogo.HorizontalAlignment = 0; Catalogo.VerticalAlignment = Element.ALIGN_MIDDLE; // Catalogo.BackgroundColor = BaseColor.LIGHT_GRAY; NombreColumnas2.AddCell(Catalogo); PdfPCell Descrip = new PdfPCell(new Phrase(pctos.DESCRIPCION, ITextEvents.arial2)); Descrip.HorizontalAlignment = 0; Descrip.VerticalAlignment = Element.ALIGN_MIDDLE; // Descrip.BackgroundColor = BaseColor.LIGHT_GRAY; NombreColumnas2.AddCell(Descrip); PdfPCell Cantidad = new PdfPCell(new Phrase(partida.QTY.ToString(), ITextEvents.arial2)); Cantidad.HorizontalAlignment = 1; Cantidad.VerticalAlignment = Element.ALIGN_MIDDLE; // Cantidad.BackgroundColor = BaseColor.LIGHT_GRAY; NombreColumnas2.AddCell(Cantidad); PdfPCell Factura = new PdfPCell(new Phrase(partida.FACTURA_PROVEEDOR, ITextEvents.arial2)); Factura.HorizontalAlignment = 1; Factura.VerticalAlignment = Element.ALIGN_MIDDLE; // Cantidad.BackgroundColor = BaseColor.LIGHT_GRAY; NombreColumnas2.AddCell(Factura); } #endregion PdfPCell espacio1 = new PdfPCell(); espacio1.FixedHeight = 8F; espacio1.Colspan = 6; espacio1.Border = 0; NombreColumnas2.AddCell(espacio1); NombreColumnas2.DefaultCell.PaddingBottom = 60; NombreColumnas2.DefaultCell.PaddingTop = 60; pdfDoc.Add(NombreColumnas2); #endregion tablas pdfDoc.Close(); } catch (Exception) { MessageBox.Show("Cierre el pdf"); } finally { } } } } catch { MessageBox.Show("Cierre el pdf"); } }
private void buttonIngresarHoja_Click(object sender, EventArgs e) { List <productos> listaproductos = new List <productos>(); if (ProveedorSeleccionado == null) { return; } if (AccesoInternet()) { OENGralSeleccionada.PARTIDAS.Clear(); OENGralSeleccionada.ItemsInventario.Clear(); OENGralSeleccionada.ID_PROVEEDOR = ProveedorSeleccionado.ID; OENGralSeleccionada.CODIGODEBARRAS = OENGralSeleccionada.Id.ToString(); OENGralSeleccionada.FECHA = DateTime.Now.Date; if (PartidasOEN.Rows.Count > 0) { int item = 1; totales = 0; double tjavier = 0; foreach (DataRow dr in PartidasOEN.Rows) { #region datos individuales oen_indiv PartidaIndividual = new oen_indiv(); PartidaIndividual.Id = partidaId; PartidaIndividual.ID_OENGRAL = OENGralSeleccionada.Id; PartidaIndividual.ITEM = item; PartidaIndividual.ID_PRODUCTO = Convert.ToInt32(dr["ID_PRODUCTO"]); try { PartidaIndividual.QTY = Convert.ToInt32(dr["QTY"]); PartidaIndividual.COMPRA = Convert.ToInt32(dr["COMPRA"]); PartidaIndividual.VENTA = Convert.ToInt32(dr["VENTA"]); PartidaIndividual.PU = Convert.ToDouble(dr["PU"]); if (dr["MONEDA"].ToString() == "USD" || dr["MONEDA"].ToString() == "usd") { tjavier = Convert.ToDouble(dr["PU"]) * Convert.ToDouble(dr["QTY"]); } else { tjavier = (Convert.ToDouble(dr["PU"]) / Convert.ToDouble(dr["TC"])) * Convert.ToDouble(dr["QTY"]); } } catch { MessageBox.Show("Escriba costo unitario de todas las partidas"); return; } totales += tjavier; PartidaIndividual.TC = Convert.ToDouble(dr["TC"]); PartidaIndividual.MONEDA = dr["MONEDA"].ToString(); PartidaIndividual.FACTURA_PROVEEDOR = dr["FACTURA_PROVEEDOR"].ToString(); PartidaIndividual.FECHA_FACTURAP = Convert.ToDateTime(dr["FECHA_FACTURAP"]); string moneda = PartidaIndividual.MONEDA; double pu = PartidaIndividual.PU; double tc = PartidaIndividual.TC; int qty = PartidaIndividual.QTY; #endregion datos productos stock = new productos(PartidaIndividual.ID_PRODUCTO); if (stock.PrecioAlmacen > 0) { int nuevaCantidad = qty + stock.STOCK; if (moneda == "PMX")//convierte a dolar { pu = pu / tc; } //if (stock.PrecioAlmacen < pu) //{ stock.PrecioAlmacen = pu;//guarda el precio /* //} * if (stock.PrecioAlmacen != pu) * { * * double sumaStock = stock.STOCK * stock.PrecioAlmacen; * double sumaIngresos = pu * qty; * double sumaTotal = sumaStock + sumaIngresos; * double nuevoCosto = sumaTotal / nuevaCantidad; * * stock.PrecioAlmacen = nuevoCosto; * }*/ } else { if (moneda == "PMX") { pu /= tc; } stock.PrecioAlmacen = pu; stock.MONEDA = "USD"; } stock.STOCK += PartidaIndividual.QTY; //suma al stock if (PartidaIndividual.QTY <= stock.ORDENADO) //le resta las entradas a las cantidades ordenadas { stock.ORDENADO -= PartidaIndividual.QTY; } else if (stock.ORDENADO > 0)//pone en cero lo ordenado { stock.ORDENADO = 0; } stock.FECHA_FACTURA = PartidaIndividual.FECHA_FACTURAP; listaproductos.Add(stock); //stock.Update("Id");//actualiza los datos del producto /////// #region guarda datos de inventario costos inventariocostos invCost = new inventariocostos();// LLENADO DE InventarioCostos invCost.Id = PartidaIndividual.Id; invCost.id_producto = PartidaIndividual.ID_PRODUCTO; invCost.cantidad_actual = PartidaIndividual.QTY; invCost.cantidad_oen = PartidaIndividual.QTY; invCost.costoU = PartidaIndividual.PU; invCost.Moneda = PartidaIndividual.MONEDA; invCost.tipoCambio = PartidaIndividual.TC; invCost.facturaProveedor = PartidaIndividual.FACTURA_PROVEEDOR; invCost.fechaFactura = PartidaIndividual.FECHA_FACTURAP; invCost.totalItem = PartidaIndividual.PU * PartidaIndividual.QTY; if (PartidaIndividual.MONEDA == "USD")//convierte a pesos { invCost.totalItemPMX = invCost.totalItem * invCost.tipoCambio; } else { invCost.totalItemPMX = invCost.totalItem; } #endregion guarda OENGralSeleccionada.PARTIDAS.Add(PartidaIndividual); OENGralSeleccionada.ItemsInventario.Add(invCost); partidaId++; item++; } SaveFileDialog save = new SaveFileDialog(); save.DefaultExt = "pdf"; save.Filter = "PDF files|*.pdf"; if (save.ShowDialog() == DialogResult.OK) { string ruta = save.FileName; CreatePDF(ruta); System.Diagnostics.Process.Start(ruta); } DialogResult result = MessageBox.Show("DESEA GENERAR LA ENTRADA CON LOS DATOS CAPTURADOS?", "REVISAR PDF ANTES DE GUARDAR", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } else if (result == DialogResult.Yes) { OENGralSeleccionada.InsertarHoja(); foreach (productos prod in listaproductos) { prod.Update("Id"); } if (!(Directory.Exists(Application.StartupPath + @"/OEN_RESPALDO/"))) { Directory.CreateDirectory(Application.StartupPath + @"/OEN_RESPALDO/"); } string ruta = Application.StartupPath + @"/OEN_RESPALDO/OEN_" + textBoxOENid.Text + ".pdf"; CreatePDF(ruta); resetOEN(); } } else { MessageBox.Show("No hay partidas para guardar"); } } else { MessageBox.Show("NO HAY INTERNET INTENTELO EN UN MOMENTO");//10000 } }