protected void grdPedidos_RowDataBound(object sender, GridViewRowEventArgs e) { int index; try { ValidaVariables(); if (e.Row.RowType == DataControlRowType.DataRow) { //Recupera la clave del pedido index = e.Row.RowIndex; NegocioPF.Pedido oPedido = new NegocioPF.Pedido(Convert.ToString(grdPedidos.DataKeys[e.Row.RowIndex].Values[0]), Convert.ToString(grdPedidos.DataKeys[e.Row.RowIndex].Values[1])); oPedido.Cargar(); GridView grdDetalle = e.Row.FindControl("grdDetalle") as GridView; foreach (DataControlField c in grdDetalle.Columns) { c.HeaderText = ((Idioma)Session["oIdioma"]).Texto(c.HeaderText); } grdDetalle.DataSource = oPedido.Materiales; grdDetalle.DataBind(); //string customerId = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString(); //GridView gvOrders = e.Row.FindControl("gvOrders") as GridView; //gvOrders.DataSource = GetData(string.Format("select top 3 * from Orders where CustomerId='{0}'", customerId)); //gvOrders.DataBind(); } } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } }
private void ArmarArchivo(ref NegocioPF.Pedidos oPedidos) { string path; int ren = 0; try { path = Server.MapPath("") + @"\\Facturas\\Pedidos.xlsx"; FileInfo newFile = new FileInfo(path); if (newFile.Exists) { newFile.Delete(); // ensures we create a new workbook newFile = new FileInfo(path); } using (ExcelPackage package = new ExcelPackage(newFile)) { // add a new worksheet to the empty workbook ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Pedidos"); foreach (DataRow r in oPedidos.Datos.Tables[0].Rows) { NegocioPF.Pedido oPedido = new NegocioPF.Pedido(r["id_sociedad"].ToString(), r["id_pedido"].ToString()); oPedido.Cargar(); //Add the headers ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("Pedido"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Font.Bold = true; range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Silver); //range.Style.Font.Color.SetColor(System.Drawing.Color.White); } //Agrega los datos del pedido ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("NoPedido"); worksheet.Cells[ren, 2].Value = ((Idioma)Session["oIdioma"]).Texto("Sociedad"); worksheet.Cells[ren, 3].Value = ((Idioma)Session["oIdioma"]).Texto("OrgCompras"); worksheet.Cells[ren, 4].Value = ((Idioma)Session["oIdioma"]).Texto("GpoCompras"); worksheet.Cells[ren, 5].Value = ((Idioma)Session["oIdioma"]).Texto("ClaseDocto"); worksheet.Cells[ren, 6].Value = ((Idioma)Session["oIdioma"]).Texto("Proveedor"); worksheet.Cells[ren, 7].Value = ((Idioma)Session["oIdioma"]).Texto("NomProveedor"); using (var range = worksheet.Cells[ren, 7, ren, 9]) { range.Merge = true; } worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto("Estatus"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.WhiteSmoke); } //Agrega los datos del pedido ren++; worksheet.Cells[ren, 1].Value = Convert.ToString(r["id_pedido"]); worksheet.Cells[ren, 2].Value = Convert.ToString(r["id_sociedad"]); worksheet.Cells[ren, 3].Value = Convert.ToString(r["id_orgcomp"]); worksheet.Cells[ren, 4].Value = Convert.ToString(r["id_gpocomp"]); worksheet.Cells[ren, 5].Value = Convert.ToString(r["id_clasedoc"]); worksheet.Cells[ren, 6].Value = Convert.ToString(r["id_proveedor"]); worksheet.Cells[ren, 7].Value = Convert.ToString(r["nombre"]); using (var range = worksheet.Cells[ren, 7, ren, 9]) { range.Merge = true; } worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto(oPedido.Status); //Encabezados de Entregas if (oPedido.Entregas.Tables[0].Rows.Count > 0) { ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("Entregas"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Font.Bold = true; range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); range.Merge = true; //range.Style.Font.Color.SetColor(System.Drawing.Color.White); } ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("NoPedido"); worksheet.Cells[ren, 2].Value = ((Idioma)Session["oIdioma"]).Texto("Posicion"); worksheet.Cells[ren, 3].Value = ((Idioma)Session["oIdioma"]).Texto("Entrega"); worksheet.Cells[ren, 4].Value = ((Idioma)Session["oIdioma"]).Texto("PosEntrega"); worksheet.Cells[ren, 5].Value = ((Idioma)Session["oIdioma"]).Texto("Cantidad"); worksheet.Cells[ren, 6].Value = ((Idioma)Session["oIdioma"]).Texto("Importe"); worksheet.Cells[ren, 7].Value = ((Idioma)Session["oIdioma"]).Texto("Material"); worksheet.Cells[ren, 8].Value = ((Idioma)Session["oIdioma"]).Texto("Descripcion"); worksheet.Cells[ren, 9].Value = ((Idioma)Session["oIdioma"]).Texto("NotaEntrega"); worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto("Estatus"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.WhiteSmoke); } //Valores de las entregas foreach (DataRow e in oPedido.Entregas.Tables[0].Rows) { ren++; worksheet.Cells[ren, 1].Value = Convert.ToString(e["id_pedido"]); worksheet.Cells[ren, 2].Value = Convert.ToString(e["id_pos_ped"]); worksheet.Cells[ren, 3].Value = Convert.ToString(e["id_entrega"]); worksheet.Cells[ren, 4].Value = Convert.ToString(e["id_posicion"]); worksheet.Cells[ren, 5].Value = Convert.ToInt32(e["cantidad"]); worksheet.Cells[ren, 5].Style.Numberformat.Format = "#,##0"; worksheet.Cells[ren, 6].Value = Convert.ToDouble(e["importe"]); //String.Format("{0:n2}", Convert.ToDouble(e["importe"])); worksheet.Cells[ren, 6].Style.Numberformat.Format = "#,##0.00"; worksheet.Cells[ren, 7].Value = Convert.ToString(e["id_material"]); worksheet.Cells[ren, 8].Value = Convert.ToString(e["descripcion"]); worksheet.Cells[ren, 9].Value = Convert.ToString(e["nota_entrega"]); worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto(Convert.ToString(e["status"])); } } if (oPedido.Costos.Tables[0].Rows.Count > 0) { ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("CostosInd"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Font.Bold = true; range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); //range.Style.Font.Color.SetColor(System.Drawing.Color.White); } //Encabezados de Costos indirectos ren++; worksheet.Cells[ren, 1].Value = ((Idioma)Session["oIdioma"]).Texto("NoPedido"); worksheet.Cells[ren, 2].Value = ((Idioma)Session["oIdioma"]).Texto("Posicion"); worksheet.Cells[ren, 3].Value = ((Idioma)Session["oIdioma"]).Texto("DocRefer"); worksheet.Cells[ren, 4].Value = ((Idioma)Session["oIdioma"]).Texto("Posicion"); worksheet.Cells[ren, 5].Value = ((Idioma)Session["oIdioma"]).Texto("Cantidad"); worksheet.Cells[ren, 6].Value = ((Idioma)Session["oIdioma"]).Texto("Importe"); worksheet.Cells[ren, 7].Value = ((Idioma)Session["oIdioma"]).Texto("Proveedor"); worksheet.Cells[ren, 8].Value = ((Idioma)Session["oIdioma"]).Texto("TipoCond"); worksheet.Cells[ren, 9].Value = ((Idioma)Session["oIdioma"]).Texto("NotaEntrega"); worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto("Estatus"); using (var range = worksheet.Cells[ren, 1, ren, 10]) { range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.WhiteSmoke); } //Valores de los costos foreach (DataRow c in oPedido.Costos.Tables[0].Rows) { ren++; worksheet.Cells[ren, 1].Value = Convert.ToString(c["id_pedido"]); worksheet.Cells[ren, 2].Value = Convert.ToString(c["id_pos_ped"]); worksheet.Cells[ren, 3].Value = Convert.ToString(c["id_entrega"]); worksheet.Cells[ren, 4].Value = Convert.ToString(c["id_posicion"]); worksheet.Cells[ren, 5].Value = Convert.ToInt32(c["cantidad"]); worksheet.Cells[ren, 5].Style.Numberformat.Format = "#,##0"; worksheet.Cells[ren, 6].Value = Convert.ToDouble(c["importe"]); worksheet.Cells[ren, 6].Style.Numberformat.Format = "#,##0.00"; worksheet.Cells[ren, 7].Value = Convert.ToString(c["id_proveedor"]); worksheet.Cells[ren, 8].Value = Convert.ToString(c["id_tipoCond"]); worksheet.Cells[ren, 9].Value = Convert.ToString(c["ref_docto"]); worksheet.Cells[ren, 10].Value = ((Idioma)Session["oIdioma"]).Texto(Convert.ToString(c["status"])); } } } //Autofit columns for all cells worksheet.Cells.AutoFitColumns(0); // set some document properties package.Workbook.Properties.Title = "Pedidos"; //package.Workbook.Properties.Author = "Jan Källman"; //package.Workbook.Properties.Comments = "This sample demonstrates how to create an Excel 2007 workbook using EPPlus"; //// set some extended property values //package.Workbook.Properties.Company = "AdventureWorks Inc."; //// set some custom property values //package.Workbook.Properties.SetCustomPropertyValue("Checked by", "Jan Källman"); //package.Workbook.Properties.SetCustomPropertyValue("AssemblyName", "EPPlus"); //// save our new workbook and we are done! package.Save(); } if (ren > 0) { //string txtPath = dirDestino + nomFile; Response.ContentType = "application/vnd.ms-excel"; // "text/plain"; Response.AppendHeader("content-disposition", "attachment; filename=" + "Pedidos.xls"); Response.TransmitFile(path); Response.End(); } } catch (Exception ex) { MessageBox(null, null, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } }
private void ArmarTabla(ref NegocioPF.Pedidos oPedidos) { TableRow row; TableCell cell; string proveedor = ""; try { NegocioPF.Proveedor oProveedor = new NegocioPF.Proveedor(((Usuario)Session["oUsuario"]).Id); oProveedor.Cargar(); if (oProveedor.Nombre != "" && oProveedor.Nombre != null) { proveedor = oProveedor.Id; } foreach (DataRow r in oPedidos.Datos.Tables[0].Rows) { NegocioPF.Pedido oPedido = new NegocioPF.Pedido(r["id_sociedad"].ToString(), r["id_pedido"].ToString()); oPedido.Cargar(proveedor); //Crea los encabezados tabPedidos.CssClass = "table"; // Llena la tabla con los resultados row = new TableRow(); cell = new TableCell(); cell.Text = ((Idioma)Session["oIdioma"]).Texto("Pedido"); cell.CssClass = "cellTitulo"; cell.ColumnSpan = 12; row.Cells.Add(cell); tabPedidos.Rows.Add(row); //Encabezados del Pedido row = new TableRow(); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NoPedido"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Sociedad"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("OrgCompras"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("GpoCompras"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("ClaseDocto"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Proveedor"))); cell = NewCell(((Idioma)Session["oIdioma"]).Texto("NomProveedor")); cell.ColumnSpan = 3; row.Cells.Add(cell); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Estatus"))); row.Cells.Add(NewCell("")); row.Cells.Add(NewCell("")); tabPedidos.Rows.Add(row); //Valores del pedido row = new TableRow(); row.Cells.Add(NewCell(Convert.ToString(r["id_pedido"]))); row.Cells.Add(NewCell(Convert.ToString(r["id_sociedad"]))); row.Cells.Add(NewCell(Convert.ToString(r["id_orgcomp"]))); row.Cells.Add(NewCell(Convert.ToString(r["id_gpocomp"]))); row.Cells.Add(NewCell(Convert.ToString(r["id_clasedoc"]))); row.Cells.Add(NewCell(Convert.ToString(r["id_proveedor"]))); cell = NewCell(Convert.ToString(r["nombre"])); cell.ColumnSpan = 3; row.Cells.Add(cell); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto(Convert.ToString(oPedido.Status)))); row.Cells.Add(NewCell("")); row.Cells.Add(NewCell("")); tabPedidos.Rows.Add(row); //Encabezados de Entregas if (oPedido.Entregas.Tables[0].Rows.Count > 0) { row = new TableRow(); cell = new TableCell(); cell.Text = ((Idioma)Session["oIdioma"]).Texto("Entregas"); cell.CssClass = "cellSubtitulo"; cell.ColumnSpan = 12; row.Cells.Add(cell); tabPedidos.Rows.Add(row); row = new TableRow(); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NoPedido"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Posicion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Entrega"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("PosEntrega"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Cantidad"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("ImporteML"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Importe"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Moneda"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Material"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Descripcion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NotaEntrega"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Estatus"))); tabPedidos.Rows.Add(row); //Valores de las entregas foreach (DataRow e in oPedido.Entregas.Tables[0].Rows) { row = new TableRow(); row.Cells.Add(NewCell(Convert.ToString(e["id_pedido"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_pos_ped"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_entrega"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_posicion"]))); row.Cells.Add(NewCell(Convert.ToString(e["cantidad"]))); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(e["importeML"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(e["importe"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); row.Cells.Add(NewCell(Convert.ToString(e["moneda"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_material"]))); row.Cells.Add(NewCell(Convert.ToString(e["descripcion"]))); row.Cells.Add(NewCell(Convert.ToString(e["nota_entrega"]))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto(Convert.ToString(e["status"])))); tabPedidos.Rows.Add(row); } } if (oPedido.Costos.Tables[0].Rows.Count > 0) { row = new TableRow(); cell = new TableCell(); cell.Text = ((Idioma)Session["oIdioma"]).Texto("CostosInd"); cell.CssClass = "cellSubtitulo"; cell.ColumnSpan = 12; row.Cells.Add(cell); tabPedidos.Rows.Add(row); //Encabezados de Costos indirectos row = new TableRow(); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NoPedido"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Posicion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("DocRefer"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Posicion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Cantidad"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("ImporteML"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Importe"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Moneda"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Proveedor"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("TipoCond"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NotaEntrega"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Estatus"))); tabPedidos.Rows.Add(row); //Valores de las entregas foreach (DataRow c in oPedido.Costos.Tables[0].Rows) { row = new TableRow(); row.Cells.Add(NewCell(Convert.ToString(c["id_pedido"]))); row.Cells.Add(NewCell(Convert.ToString(c["id_pos_ped"]))); row.Cells.Add(NewCell(Convert.ToString(c["id_entrega"]))); row.Cells.Add(NewCell(Convert.ToString(c["id_posicion"]))); row.Cells.Add(NewCell(Convert.ToString(c["cantidad"]))); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(c["importeML"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(c["importe"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); row.Cells.Add(NewCell(Convert.ToString(c["moneda"]))); row.Cells.Add(NewCell(Convert.ToString(c["id_proveedor"]))); row.Cells.Add(NewCell(Convert.ToString(c["id_tipoCond"]))); row.Cells.Add(NewCell(Convert.ToString(c["ref_docto"]))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto(Convert.ToString(c["status"])))); tabPedidos.Rows.Add(row); } } //Encabezados de Servicios if (oPedido.Servicios.Tables[0].Rows.Count > 0) { row = new TableRow(); cell = new TableCell(); cell.Text = ((Idioma)Session["oIdioma"]).Texto("Servicios"); cell.CssClass = "cellSubtitulo"; cell.ColumnSpan = 12; row.Cells.Add(cell); tabPedidos.Rows.Add(row); row = new TableRow(); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("NoPedido"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Posicion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Documento"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Posicion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Cantidad"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("ImporteML"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Importe"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Moneda"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Material"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Descripcion"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Referencia"))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto("Estatus"))); tabPedidos.Rows.Add(row); //Valores de las entregas foreach (DataRow e in oPedido.Servicios.Tables[0].Rows) { row = new TableRow(); row.Cells.Add(NewCell(Convert.ToString(e["id_pedido"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_pos_ped"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_documento"]))); row.Cells.Add(NewCell(Convert.ToString(e["id_posicion"]))); row.Cells.Add(NewCell(Convert.ToString(e["cantidad"]))); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(e["importeML"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); cell = NewCell(String.Format("{0:n2}", Convert.ToDouble(e["importe"]))); cell.HorizontalAlign = HorizontalAlign.Right; row.Cells.Add(cell); row.Cells.Add(NewCell(Convert.ToString(e["moneda"]))); row.Cells.Add(NewCell(Convert.ToString(e["material"]))); row.Cells.Add(NewCell(Convert.ToString(e["descripcion"]))); row.Cells.Add(NewCell(Convert.ToString(e["ref_docto"]))); row.Cells.Add(NewCell(((Idioma)Session["oIdioma"]).Texto(Convert.ToString(e["status"])))); tabPedidos.Rows.Add(row); } } } } catch (Exception ex) { MessageBox(null, null, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } }