public void PDFESTADOCERO() { Buscadores bus = new Buscadores(); var doc = new iTextSharp.text.Document(PageSize.A4); string path = Server.MapPath("~"); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path + "/Factura.pdf", FileMode.Create)); vehiculo ovehiculo = bus.buscarvehiculoid(Ordenn.id_vehiculo ?? default(int)); cliente ocliente = bus.ocliente(ovehiculo); modelo omodelo = bus.buscarmodelo(ovehiculo); marca omarca = bus.buscarmarca(omodelo); doc.Open(); //Cabecera BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfntHead, 16, 1, iTextSharp.text.BaseColor.BLUE.Darker()); Paragraph prgHeading = new Paragraph(); prgHeading.Alignment = 1; prgHeading.Add(new Chunk("Factura".ToUpper(), fntHead)); doc.Add(prgHeading); doc.Add(Chunk.NEWLINE); //Generado By Paragraph prgGeneratedBY = new Paragraph(); BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntAuthor = new iTextSharp.text.Font(btnAuthor, 12, 2, iTextSharp.text.BaseColor.BLACK); prgGeneratedBY.Alignment = Element.ALIGN_RIGHT; prgGeneratedBY.Add(new Chunk("Generado por: " + LogEmpleado.nombreyapellido, fntAuthor)); //Agregar LOG Empleado prgGeneratedBY.Add(new Chunk("\nFecha : " + DateTime.Now.ToShortDateString(), fntAuthor)); prgGeneratedBY.Add(new Chunk("\nN° de Orden : " + Ordenn.id_orden, fntAuthor)); doc.Add(prgGeneratedBY); doc.Add(Chunk.NEWLINE); doc.Add(Chunk.NEWLINE); //tablados PdfPTable tabla2 = new PdfPTable(2); tabla2.WidthPercentage = 100; tabla2.SpacingAfter = 20; PdfPCell vehiculoTitulo = new PdfPCell(new Phrase("Vehiculo")); vehiculoTitulo.BorderWidth = 0; vehiculoTitulo.BorderWidthRight = 0.75f; vehiculoTitulo.BorderWidthTop = 0.75f; vehiculoTitulo.BorderWidthLeft = 0.75f; vehiculoTitulo.HorizontalAlignment = Element.ALIGN_CENTER; vehiculoTitulo.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell clienteTitulo = new PdfPCell(new Phrase("Cliente")); clienteTitulo.BorderWidth = 0; clienteTitulo.BorderWidthTop = 0.75f; clienteTitulo.BorderWidthRight = 0.75f; clienteTitulo.HorizontalAlignment = Element.ALIGN_CENTER; clienteTitulo.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell patente = new PdfPCell(new Phrase("Patente: " + ovehiculo.patente)); patente.BorderWidth = 0; patente.BorderWidthRight = 0.75f; patente.BorderWidthBottom = 0.75f; patente.BorderWidthLeft = 0.75f; patente.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell marca = new PdfPCell(new Phrase("Marca: " + omarca.nombre)); marca.BorderWidth = 0; marca.BorderWidthRight = 0.75f; marca.BorderWidthLeft = 0.75f; marca.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell modelo = new PdfPCell(new Phrase("Modelo: " + omodelo.nombre)); modelo.BorderWidth = 0; modelo.BorderWidthRight = 0.75f; modelo.BorderWidthLeft = 0.75f; modelo.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell nombre = new PdfPCell(new Phrase("Apellido y Nombre: " + ocliente.nombre)); nombre.BorderWidth = 0; nombre.BorderWidthLeft = 0.75f; nombre.BorderWidthBottom = 0.75f; nombre.BorderWidthRight = 0.75f; nombre.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); PdfPCell dni = new PdfPCell(new Phrase("DNI: " + ocliente.dni)); dni.BorderWidth = 0; dni.BorderWidthBottom = 0.75f; dni.BorderWidthRight = 0.75f; dni.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); tabla2.AddCell(vehiculoTitulo); tabla2.AddCell(clienteTitulo); tabla2.AddCell(marca); tabla2.AddCell(modelo); tabla2.AddCell(nombre); tabla2.AddCell(patente); tabla2.AddCell(dni); doc.Add(tabla2); dt.Rows.Add("", "", "Total", lblprecio.Text); PdfPTable table = new PdfPTable(dt.Columns.Count); for (int i = 0; i < dt.Columns.Count; i++) { string cellText = Server.HtmlDecode(dt.Columns[i].ColumnName); PdfPCell cell = new PdfPCell(); cell.Phrase = new Phrase(cellText, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 1, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#000000")))); cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_CENTER; cell.PaddingBottom = 5; table.AddCell(cell); } //Agregando Campos a la tabla for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { PdfPCell cell = new PdfPCell(); cell.Phrase = new Phrase(dt.Rows[i][j].ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 0, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#000000")))); if (j == 1) { cell.HorizontalAlignment = Element.ALIGN_LEFT; } else { cell.HorizontalAlignment = Element.ALIGN_CENTER; } if (dt.Rows[i][j].ToString() == "Total") { cell.Phrase = new Phrase(dt.Rows[i][j].ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 1, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#000000")))); } table.AddCell(cell); } } table.SetWidths(new float[] { 2, 8, 1, 1 }); doc.Add(table); //Espacio doc.Close(); Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('Factura.pdf','_newtab');", true); //Response.Redirect("Presupuesto.pdf"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (LogEmpleado.id_tipo != 6) { Server.Transfer("Default.aspx"); } Buscadores bus = new Buscadores(); ordenempleado OrdenEmpleado = bus.buscarempleadoorden(LogEmpleado.id_empleado); if (OrdenEmpleado == null) { lblpatente.Text = "No tienes ningun vehiculo asignado. "; lblmodelo.Text = "-"; btnaceptar.Visible = false; btnfinalizar.Visible = false; } else { int a = int.Parse(OrdenEmpleado.id_orden.ToString()); orden Orden = bus.buscarorden(a); OrdenActual = Orden; vehiculo ovehiculo = bus.buscarvehiculoid(int.Parse(Orden.id_vehiculo.ToString())); modelo omodelo = bus.buscarmodelo(ovehiculo); ordenestado oestado = bus.buscarvestadoorden(Orden.id_orden); List <ordenservicio> Lidservidcios = new List <ordenservicio>(); Lidservidcios = bus.buscarlistaid(Orden.id_orden); CheckBoton(oestado); List <servicio> Lservicios = ObtenerServicios(Lidservidcios); List <serviciostock> Lserstock = new List <serviciostock>(); List <serviciostock> Lserstock2 = new List <serviciostock>(); foreach (servicio s in Lservicios) { Lserstock = Lserviciostock(s.id_servicios.ToString()); if (Lserstock.Count != 0) { foreach (serviciostock ss in Lserstock) { Lserstock2.Add(ss); } } } List <stock> Nstock = Lstockuso(Lserstock2); if ((oestado.estado == 1) || (oestado.estado == 2)) { GridView1.DataSource = Lservicios; GridView1.DataBind(); GridView2.DataSource = Nstock; GridView2.DataBind(); lblpatente.Text = "PATENTE: " + ovehiculo.patente.ToString(); lblmodelo.Text = "MODELO: " + omodelo.nombre.ToString(); } else { lblpatente.Text = "No tienes ningun vehiculo asignado. "; lblmodelo.Text = "-"; btnaceptar.Visible = false; btnfinalizar.Visible = false; } } } }
protected void PDFRPE(object sender, EventArgs e) { if (((FechaFinale.Value != "") && (FechaInicios.Value != ""))) { Buscadores bus = new Buscadores(); DateTime oDateinicio = Convert.ToDateTime(FechaInicios.Value); DateTime oDatefin = Convert.ToDateTime(FechaFinale.Value); int tipodempleado = int.Parse(DropTipodeEmpleados.SelectedValue); List <empleado> Lempleados = bus.Lempleado(); Lempleados = Lempleados.FindAll(x => (x.id_tipo ?? default(int)) == tipodempleado); if (Lempleados.Count != 0) { var doc = new iTextSharp.text.Document(PageSize.A4); string path = Server.MapPath("~"); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path + "/RE.pdf", FileMode.Create)); doc.Open(); //Cabecera BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfntHead, 16, 1, iTextSharp.text.BaseColor.GREEN.Darker()); Paragraph prgHeading = new Paragraph(); prgHeading.Alignment = 1; prgHeading.Add(new Chunk("Taller de Reparaciones".ToUpper(), fntHead)); doc.Add(prgHeading); doc.Add(Chunk.NEWLINE); //Generado By Paragraph prgGeneratedBY = new Paragraph(); BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntAuthor = new iTextSharp.text.Font(btnAuthor, 12, 2, iTextSharp.text.BaseColor.BLACK); prgGeneratedBY.Alignment = Element.ALIGN_RIGHT; prgGeneratedBY.Add(new Chunk("Generado por: " + LogEmpleado.nombreyapellido, fntAuthor)); //Agregar LOG Empleado prgGeneratedBY.Add(new Chunk("\nFecha : " + DateTime.Now.ToShortDateString(), fntAuthor)); doc.Add(prgGeneratedBY); Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1))); doc.Add(p); //Espacio doc.Add(new Chunk("\n", fntHead)); //Datos Paragraph Datos = new Paragraph(); BaseFont bfntDatos = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font fntDatos = new iTextSharp.text.Font(bfntDatos, 16, 0, iTextSharp.text.BaseColor.BLACK); Datos.Alignment = Element.ALIGN_CENTER; Datos.Add(new Chunk("\nEmpleado tipo: " + DropTipodeEmpleados.SelectedItem.Text, fntDatos)); doc.Add(Datos); //Espacio doc.Add(new Chunk("\n", fntHead)); int controlprecio; foreach (empleado oempleado in Lempleados) { controlprecio = 0; DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("N°Orden"), new DataColumn("Vehiculo"), new DataColumn("Fecha"), new DataColumn("PrecioTotal") }); //nombre de las columnas List <ordenempleado> Lordenempleado = bus.buscarListOrdenEstadoporempleado(oempleado.id_empleado); List <orden> Lorden = bus.buscarordexempleado(Lordenempleado); foreach (orden OrdenActual in Lorden) { int id = int.Parse(OrdenActual.id_vehiculo.ToString()); vehiculo ovehiculo = bus.buscarvehiculoid(id); int preciototal = 0; ordenestado oestado = bus.buscarvestadoorden(OrdenActual.id_orden); if ((oestado.fecha_entregado >= oDateinicio) && (oestado.fecha_entregado <= oDatefin)) { List <ordenservicio> Lidservidcios = new List <ordenservicio>(); Lidservidcios = bus.buscarlistaid(OrdenActual.id_orden); List <servicio> Lservicio = bus.ObtenerServicios(Lidservidcios); foreach (ordenservicio ordenservi in Lidservidcios) { servicio oservicio = Lservicio.Find(x => x.id_servicios == ordenservi.id_servicio); int cantidad = ordenservi.cantidad ?? default(int); string total = (double.Parse(oservicio.precio) * Convert.ToDouble(cantidad)).ToString(); preciototal = preciototal + int.Parse(total); } string fecha = oestado.fecha_entregado.ToString(); string[] fechasinhora; fechasinhora = fecha.Split(' '); dt.Rows.Add(OrdenActual.id_orden, ovehiculo.patente, fechasinhora[0], preciototal); controlprecio = preciototal; } } //aqui if (dt.Rows.Count != 0) { doc.Add(p); Paragraph Dato = new Paragraph(); Dato.Alignment = Element.ALIGN_LEFT; Dato.Add(new Chunk("\nNombre y Apellido: " + oempleado.nombreyapellido + " Correo: " + oempleado.correo + " Direccion: " + oempleado.direccion + "\nDireccion: " + oempleado.telefono, fntDatos)); doc.Add(Dato); //Espacio doc.Add(new Chunk("\n", fntHead)); //Tabla PdfPTable table = new PdfPTable(dt.Columns.Count); for (int i = 0; i < dt.Columns.Count; i++) { string cellText = Server.HtmlDecode(dt.Columns[i].ColumnName); PdfPCell cell = new PdfPCell(); cell.Phrase = new Phrase(cellText, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 1, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#000000")))); cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#C8C8C8")); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.PaddingBottom = 5; table.AddCell(cell); } for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { table.AddCell(dt.Rows[i][j].ToString()); } } table.HorizontalAlignment = Element.ALIGN_CENTER; doc.Add(table); //Espacio doc.Add(new Chunk("\n", fntHead)); } } doc.Close(); Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('RE.pdf','_newtab');", true); } } }
protected void BtnBuscar(object sender, EventArgs e) { Buscadores bus = new Buscadores(); if (txtidorden.Value != "") { orden oOrden = bus.buscarorden(int.Parse(txtidorden.Value)); ordenestado Oordenestado = new ordenestado(); if (oOrden != null) { Oordenestado = bus.buscarvestadoorden(oOrden.id_orden); } if (oOrden != null) { if ((Oordenestado == null) || (Oordenestado.estado == null) || (Oordenestado.estado == 0) || (Oordenestado.estado == 5)) { //Validar orden estado 2 o superior aca? si? NoAuto.Visible = false; vehiculo Ovehiculo = bus.buscarvehiculoid(int.Parse(oOrden.id_vehiculo.ToString())); cliente oCliente = bus.ocliente(Ovehiculo); modelo omodelo = bus.buscarmodelo(Ovehiculo); Ovehiculo.modelo = omodelo; marca omarca = bus.buscarmarca(Ovehiculo.modelo); Ovehiculo.modelo.marca = omarca; Ovehiculo.cliente = oCliente; oOrden.vehiculo = Ovehiculo; txtpatente.Value = oOrden.vehiculo.patente; txtmodelo.Value = oOrden.vehiculo.modelo.nombre; txtmarca.Value = oOrden.vehiculo.modelo.marca.nombre; txtaño.Value = oOrden.vehiculo.annio; string[] separadas; if (Ovehiculo.cliente.dni != null) { separadas = Ovehiculo.cliente.nombre.Split(' '); txtdni.Value = Ovehiculo.cliente.dni; txtapellido.Value = separadas[0]; txtnombre.Value = separadas[1]; txttelefono.Value = Ovehiculo.cliente.telefono; txtemail.Value = Ovehiculo.cliente.email; } OrdenActual = oOrden; CargarGrid(oOrden); PDFESTADOCERO(); } else { Label3.Text = "EL VEHICULO YA POSEE UNA ORDEN ACTIVA"; NoAuto.Visible = true; } } else { Label3.Text = "ORDEN NO EXISTENTE"; NoAuto.Visible = true; } } }