Exemplo n.º 1
0
        private void CargarTablaDetalleFacturas(int idFactura, string criterio)
        {
            try
            {
                var dt   = new DataTable();
                var rows = objDeF.ConsultarPorIdFactura(-1, "");
                gvwDetalleFactura.DataSource = null;
                gvwDetalleFactura.DataBind();
                if (idFactura != -1)
                {
                    rows = objDeF.ConsultarPorIdFactura(idFactura, criterio);
                }

                //dt.Columns.Add("idFactura", typeof(System.String));
                dt.Columns.Add("idProducto", typeof(System.String));
                dt.Columns.Add("codProducto", typeof(System.String));
                dt.Columns.Add("CantidadProducto", typeof(System.String));
                dt.Columns.Add("Regresado", typeof(System.String));

                foreach (Vista_ProductosPorDetalleFactura r in rows)
                {
                    // Crear una fila por cada unidad del producto.
                    int cantidadDeProductos = r.CantidadProducto;
                    int cantidadDeDevueltos = r.CantidadDevuelta;

                    for (int i = 0; i < cantidadDeProductos; i++)
                    {
                        var tempCategoria = new CAT_CATEGORIA();

                        tempCategoria.idCategoria = r.IdCategoria;
                        tempCategoria             = objCat.ConsultarPorIdCategoria(tempCategoria);
                        // Crear la fila, asignar valores y agregarla.
                        DataRow fila = dt.NewRow();
                        //fila["idFactura"] = r.idFactura;
                        fila["idProducto"] = r.NombreProducto + ", " + tempCategoria.Nombre;

                        fila["codProducto"] = r.CodigoNumerico;
                        // La catidad siempre va ser 1.
                        fila["CantidadProducto"] = "1";
                        // Ver si esta marcado.
                        if (cantidadDeDevueltos > 0)
                        {
                            fila["Regresado"] = "true";
                            cantidadDeDevueltos--;
                        }
                        else
                        {
                            fila["Regresado"] = "false";
                        }
                        dt.Rows.Add(fila);
                    }
                }
                gvwDetalleFactura.DataSource = dt;
                gvwDetalleFactura.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
        private void CargarTablaDetalleFacturas(int idFactura)
        {
            try
            {
                var dt   = new System.Data.DataTable();
                var rows = objDeF.ConsultarPorIdFactura(-1, "");
                //var contadorDeFilas = 0;
                gvwDetalleFactura.DataSource = null;
                gvwDetalleFactura.DataBind();
                if (idFactura != -1)
                {
                    rows = objDeF.ConsultarPorIdFactura(idFactura, "");
                }

                dt.Columns.Add("categoria", typeof(System.String));
                dt.Columns.Add("idProducto", typeof(System.String));
                dt.Columns.Add("CantidadProducto", typeof(System.String));

                // Recorrer las filas.
                foreach (Vista_ProductosPorDetalleFactura r in rows)
                {
                    //// Crear una fila por cada unidad del producto.
                    var tempProducto  = new PRO_PRODUCTO();
                    var tempCategoria = new CAT_CATEGORIA();

                    tempProducto.IdProducto = r.idProducto;
                    tempProducto            = objProd.ConsultarPorId(tempProducto).FirstOrDefault();

                    tempCategoria.idCategoria = tempProducto.IdCategoria;
                    tempCategoria             = objCateg.ConsultarPorId(tempCategoria).FirstOrDefault();
                    // Crear la fila, asignar valores y agregarla.
                    DataRow fila = dt.NewRow();
                    fila["categoria"]        = tempProducto.NombreProducto + " " + tempCategoria.Nombre;
                    fila["idProducto"]       = tempProducto.CodigoNumerico;
                    fila["CantidadProducto"] = r.CantidadProducto;

                    dt.Rows.Add(fila);
                }
                gvwDetalleFactura.DataSource = dt;
                gvwDetalleFactura.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
Exemplo n.º 3
0
        protected void btnFinalizarLaFactura_Click(object sender, EventArgs e)
        {
            //var rows = objDeF.Consultar();
            if (hdfIdFactura.Value == "-1")
            {
                //No imprime nada
                DynamicHyperLink1.Visible = false;
            }
            else
            {
                var metal            = "";
                var contadorDeFilas  = 0;
                var rows             = objDeF.ConsultarPorIdFactura(Convert.ToInt32(hdfIdFactura.Value), txtCriterio.Text);
                var datosDeLaFactura = new FAC_FACTURA();
                var tempCategoria    = new CAT_CATEGORIA();
                var fechaCreacion    = CreacionDeFechaDesdeElTxtFecha();

                datosDeLaFactura.idFactura = Convert.ToInt32(hdfIdFactura.Value);

                // obteber el objeto
                datosDeLaFactura = objFact.ConsultarPorId(datosDeLaFactura).FirstOrDefault();

                // actulizar el estado de la factura
                if (datosDeLaFactura.estado == Convert.ToInt32(EstadoFacturas.EnCreacion))
                {
                    datosDeLaFactura = actualizarDatosFactura(datosDeLaFactura);
                }

                tempCategoria.idCategoria = datosDeLaFactura.idCategoriaMetal;
                tempCategoria             = objCat.ConsultarPorId(tempCategoria).FirstOrDefault();
                metal = tempCategoria.Nombre;
                llenaArregloConCeros();
                // Recorrer las filas.
                foreach (Vista_ProductosPorDetalleFactura r in rows)
                {
                    //// Crear una fila por cada unidad del producto.
                    var tempProducto = new PRO_PRODUCTO();

                    tempProducto.IdProducto = r.idProducto;
                    tempProducto            = objProd.ConsultarPorId(tempProducto).FirstOrDefault();

                    arregloTemporal[contadorDeFilas, 0] = tempProducto.NombreProducto;
                    arregloTemporal[contadorDeFilas, 1] = tempProducto.CodigoNumerico.ToString();
                    arregloTemporal[contadorDeFilas, 2] = r.CantidadProducto.ToString();

                    contadorDeFilas++;
                }
                contadorDeFilas = 0;
                //string sFile = "C:\\joyeriaSYS\\joyeriaSYS\\ExcelFacturas\\000Machote.xls";
                string sFile = "C:\\inetpub\\wwwroot\\joyeriasys\\ExcelFacturas\\000Machote.xls";
                //string sTemplate = "C:\\Template.xls";
                object opc = Type.Missing;

                var excelApp = new Excel.Application();
                excelApp.DisplayAlerts = false;
                // Make the object visible.
                //excelApp.Visible = true;

                //var excelBook = new Excel.Workbook();
                //var excelSheet = new Excel.Worksheet();
                var excelBook  = excelApp.Workbooks.Open(sFile, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc);
                var excelSheet = (Excel.Worksheet)excelBook.Sheets.get_Item(1);
                try
                {
                    var tempCliente = new CLI_CLIENTES();
                    tempCliente.idCliente = Convert.ToInt32(ddlCliente.SelectedValue);
                    tempCliente           = objCli.ConsultarPorIdCliente(tempCliente);
                    //Ponemos la fecha actual, el vendedor y el metal respectivamente.
                    excelSheet.Cells[3, 5] = fechaCreacion;
                    excelSheet.Cells[5, 3] = tempCliente.NombreEncargado;
                    excelSheet.Cells[6, 3] = metal;
                    //Ponemos la descripci+on del producto.
                    for (int i = 8; i < 43; i++)
                    {
                        excelSheet.Cells[i, 2] = arregloTemporal[contadorDeFilas, 0].ToString();
                        excelSheet.Cells[i, 3] = arregloTemporal[contadorDeFilas, 1].ToString();
                        excelSheet.Cells[i, 4] = arregloTemporal[contadorDeFilas, 2].ToString();
                        contadorDeFilas++;
                    }

                    excelSheet.Cells[46, 2] = datosDeLaFactura.montoFactura;
                    excelSheet.Cells[47, 3] = datosDeLaFactura.totalPiezas;
                    excelSheet.Cells[48, 3] = fechaCreacion.AddDays(50);

                    excelSheet.SaveAs("C:\\inetpub\\wwwroot\\joyeriasys\\ExcelFacturas\\" + datosDeLaFactura.NoFactura + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
                    //excelSheet.SaveAs("C:\\joyeriaSYS\\joyeriaSYS\\ExcelFacturas\\" + datosDeLaFactura.NoFactura + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, opc, opc, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, opc, opc);
                    //excelApp.Visible = true;

                    //excelSheet.PrintOut();

                    //Marshal.FinalReleaseComObject(excelSheet);
                    excelBook.Close();
                    excelApp.Quit();
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook);
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet);
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);

                    DynamicHyperLink1.NavigateUrl = "~/ExcelFacturas/" + datosDeLaFactura.NoFactura + ".xls";
                    DynamicHyperLink1.Visible     = true;
                    //string _open = "window.open('/ExcelFacturas/" + datosDeLaFactura.NoFactura + ".xls', '_newtab');";
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), _open, true);

                    //btnImprimir.PostBackUrl = "198.38.93.222/ExcelFacturas/"+ datosDeLaFactura.NoFactura +".xls";
                    //MostrarMensaje("Excel creado");
                    excelBook  = null;
                    excelSheet = null;
                    excelApp   = null;
                    //System.GC.Collect();
                }
                catch (Exception ex)
                {
                    //Console.Error.Write(ex.Message);
                    excelBook.Close();
                    excelApp.Quit();
                }
            }//Fin else
        }