Exemple #1
0
        protected void gvwDetalleFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            var tempCategoria = new CAT_CATEGORIA();

            tempCategoria.Nombre = gvwDetalleFactura.SelectedRow.Cells[4].Text;
            tempCategoria        = objCat.ConsultarPorNombre(tempCategoria).FirstOrDefault();

            var tempProducto = new PRO_PRODUCTO();

            tempProducto.NombreProducto = gvwDetalleFactura.SelectedRow.Cells[2].Text;
            tempProducto.CodigoNumerico = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[3].Text);
            tempProducto.IdCategoria    = tempCategoria.idCategoria;
            tempProducto = objProd.ConsultarPorNombreCodigoCategoria(tempProducto).FirstOrDefault();

            hdfIdDetalleFactura.Value = gvwDetalleFactura.SelectedRow.Cells[0].Text;
            int noFactura   = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[1].Text);
            int idProducto  = tempProducto.IdProducto;
            int idCategoria = tempCategoria.idCategoria;
            int Cantidad    = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[5].Text);

            ddlProducto.SelectedValue = tempProducto.IdProducto.ToString();

            var detFac = new DEF_DETALLE_FACTURA();

            detFac.idDetalleFactura = Convert.ToInt32(hdfIdDetalleFactura.Value);
            actualizarFacturaLuegoDeBorrado(noFactura, idProducto, Cantidad);
            actualizarCantidadProducto(idProducto, Cantidad, false);
            objDeF.Eliminar(detFac);

            CargarTablaDetalleFacturas(Convert.ToInt32(hdfIdFactura.Value));
            CargarTablaFacturas(txtCriterio.Text);
        }
Exemple #2
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;
            }
        }
Exemple #3
0
        private void cargarProductosPorIdCategoria(int IdCategoria)
        {
            try
            {
                var dt   = new DataTable();
                var rows = objProd.ConsultarPorCategoria(IdCategoria);

                ddlProducto.Items.Clear();
                ddlProducto.DataTextField  = "NombreProducto";
                ddlProducto.DataValueField = "IdProducto";
                dt.Columns.Add("IdProducto", typeof(System.String));
                dt.Columns.Add("NombreProducto", typeof(System.String));

                foreach (PRO_PRODUCTO r in rows)
                {
                    var tempCategoria = new CAT_CATEGORIA();
                    tempCategoria.idCategoria = r.IdCategoria;
                    tempCategoria             = objCat.ConsultarPorId(tempCategoria).FirstOrDefault();

                    DataRow fila = dt.NewRow();

                    fila["IdProducto"]     = r.IdProducto;
                    fila["NombreProducto"] = r.NombreProducto + " " + tempCategoria.Nombre + " " + r.CodigoNumerico;
                    dt.Rows.Add(fila);
                }
                ddlProducto.DataSource = dt;
                ddlProducto.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
Exemple #4
0
        protected void btnCalcular_Click(object sender, EventArgs e)
        {
            try
            {
                var tempFactura = new FAC_FACTURA();
                tempFactura.NoFactura = Convert.ToInt32(ddlFactura.SelectedValue);
                tempFactura           = objFact.ConsultaPorNumeroDeFactura(tempFactura);
                var SaldoActual    = tempFactura.saldo;
                var listaProductos = new List <PRO_PRODUCTO>();
                var listaDetalles  = new List <DEF_DETALLE_FACTURA>();

                foreach (GridViewRow mRow in gvwDetalleFactura.Rows)
                {
                    CheckBox mCheck = (CheckBox)mRow.FindControl("cbSelect");
                    if (mCheck != null)
                    {
                        if (mCheck.Checked)
                        {
                            var tempProducto        = new PRO_PRODUCTO();
                            var tempCategoria       = new CAT_CATEGORIA();
                            var splitProducto       = mRow.Cells[0].Text.Split(',');
                            var splitNombreProducto = splitProducto[0];

                            tempCategoria.Nombre = splitProducto[1].TrimStart();
                            tempCategoria        = objCat.ConsultarPorNombreDeCategoria(tempCategoria);

                            tempProducto.CodigoNumerico = Convert.ToInt32(mRow.Cells[1].Text);
                            tempProducto.IdCategoria    = tempCategoria.idCategoria;
                            tempProducto.NombreProducto = splitNombreProducto;
                            tempProducto            = objProd.ConsultarProductoPorNombreCodigoCategoria(tempProducto);
                            tempProducto.Inventario = tempProducto.Inventario + 1;
                            SaldoActual             = SaldoActual - tempProducto.Precio;
                            txtSaldoActual.Text     = SaldoActual.ToString();
                            Session["SaldoActual"]  = SaldoActual;
                            var tempDetalleFactura = new DEF_DETALLE_FACTURA();
                            tempDetalleFactura.idFactura        = tempFactura.idFactura;
                            tempDetalleFactura.idProducto       = tempProducto.IdProducto;
                            tempDetalleFactura                  = objDeF.ConsultarPorIdFacturaYIdProducto(tempDetalleFactura);
                            tempDetalleFactura.CantidadDevuelta = tempDetalleFactura.CantidadDevuelta + 1;

                            objProd.Actualizar(tempProducto);
                            objDeF.Actualizar(tempDetalleFactura);
                        }
                    }
                }
                tempFactura.saldo         = SaldoActual;
                tempFactura.estado        = Convert.ToInt32(EstadoFacturas.Cancelada);
                tempFactura.totalDevuelto = tempFactura.saldo - SaldoActual;
                objFact.Actualizar(tempFactura);
                cargarTablaFacturas(tempFactura.NoFactura);
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Factura cancelada con éxito, el monto a pagar es: " + SaldoActual + "')", true);
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                throw ex;
            }
        }
Exemple #5
0
        private void CargarTablaFacturas(string criterio)
        {
            try
            {
                var dt   = new DataTable();
                var rows = objFact.ConsultarPorNoFactura(criterio);

                dt.Columns.Add("idFactura", typeof(System.String));
                dt.Columns.Add("NoFactura", typeof(System.String));
                //dt.Columns.Add("CodTabla", typeof(System.String));
                dt.Columns.Add("montoFactura", typeof(System.String));
                dt.Columns.Add("estado", typeof(System.String));
                dt.Columns.Add("totalPiezas", typeof(System.String));
                dt.Columns.Add("idCliente", typeof(System.String));
                dt.Columns.Add("idTipoMetal", typeof(System.String));
                dt.Columns.Add("nombreUsuario", typeof(System.String));
                //dt.Columns.Add("fechaCreacion", typeof(System.String));
                //dt.Columns.Add("fechaLiquidacion", typeof(System.String));

                foreach (FAC_FACTURA r in rows)
                {
                    var tempCliente   = new CLI_CLIENTES();
                    var tempCategoria = new CAT_CATEGORIA();
                    tempCliente.idCliente     = r.idCliente;
                    tempCliente               = objCli.ConsultarPorId(tempCliente).FirstOrDefault();
                    tempCategoria.idCategoria = r.idCategoriaMetal;
                    tempCategoria             = objCat.ConsultarPorIdCategoria(tempCategoria);

                    DataRow fila = dt.NewRow();

                    fila["idFactura"] = r.idFactura;
                    fila["NoFactura"] = r.NoFactura;
                    //fila["CodTabla"] = r.CodTabla;
                    fila["montoFactura"]  = r.montoFactura;
                    fila["estado"]        = EstadoFacturaEnLetras(r.estado);
                    fila["totalPiezas"]   = r.totalPiezas;
                    fila["idCliente"]     = tempCliente.NombreEncargado;
                    fila["idTipoMetal"]   = tempCategoria.Nombre;
                    fila["nombreUsuario"] = obtenerNombreUsuarioPorId(r.idUsuario);
                    //fila["fechaCreacion"] = r.fechaCreacion;
                    //fila["fechaLiquidacion"] = r.fechaLiquidacion;
                    dt.Rows.Add(fila);
                }
                gvwFacturas.DataSource = dt;
                gvwFacturas.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
Exemple #6
0
        //public void CargarTablaProductos(string nombre, string categoria, string codigo)
        public void CargarTablaProductos(string criterio)
        {
            try
            {
                //var idCategoria = 0;
                var tempCriterioCategoria = new CAT_CATEGORIA();
                tempCriterioCategoria.Nombre = criterio;
                tempCriterioCategoria        = objCat.ConsultarPorNombre(tempCriterioCategoria).FirstOrDefault();

                if (tempCriterioCategoria != null)
                {
                    criterio = tempCriterioCategoria.idCategoria.ToString();
                }

                var dt = new DataTable();
                //var rows = objProd.Consultar(nombre, idCategoria, codigo);
                var rows = objProd.Consultar(criterio);

                dt.Columns.Add("IdProducto", typeof(System.String));
                dt.Columns.Add("NombreProducto", typeof(System.String));
                dt.Columns.Add("Metal", typeof(System.String));
                dt.Columns.Add("CodigoNumerico", typeof(System.String));
                dt.Columns.Add("Precio", typeof(System.String));
                dt.Columns.Add("Inventario", typeof(System.String));

                foreach (PRO_PRODUCTO r in rows)
                {
                    var tempCategoria = new CAT_CATEGORIA();
                    tempCategoria.idCategoria = r.IdCategoria;
                    DataRow fila = dt.NewRow();

                    fila["IdProducto"]     = r.IdProducto;
                    fila["NombreProducto"] = r.NombreProducto;
                    fila["Metal"]          = objCat.ConsultarPorId(tempCategoria).FirstOrDefault().Nombre;
                    fila["CodigoNumerico"] = r.CodigoNumerico;
                    fila["Precio"]         = r.Precio;
                    fila["Inventario"]     = r.Inventario;
                    dt.Rows.Add(fila);
                }
                gvwProductos.DataSource = dt;
                gvwProductos.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;
            }
        }
Exemple #8
0
        public int guardarActualizar(int id)
        {
            CAT_CATEGORIA temp = new CAT_CATEGORIA();

            temp.idCategoria = id;
            temp.Nombre      = txtNombre.Text;
            temp.Codigo      = "---";

            if (objCat.ConsultarPorId(temp).Count() > 0)
            {
                objCat.Actualizar(temp);
            }
            else
            {
                objCat.Insertar(temp);
            }
            return(1);
        }
Exemple #9
0
        protected void btnCalcularSaldo_Click(object sender, EventArgs e)
        {
            try
            {
                var tempFactura = new FAC_FACTURA();
                tempFactura.NoFactura = Convert.ToInt32(ddlFactura.SelectedValue);
                tempFactura           = objFact.ConsultaPorNumeroDeFactura(tempFactura);
                var SaldoActual = tempFactura.saldo;

                foreach (GridViewRow mRow in gvwDetalleFactura.Rows)
                {
                    CheckBox mCheck = (CheckBox)mRow.FindControl("cbSelect");
                    if (mCheck != null)
                    {
                        if (mCheck.Checked)
                        {
                            var tempProducto        = new PRO_PRODUCTO();
                            var tempCategoria       = new CAT_CATEGORIA();
                            var splitProducto       = mRow.Cells[0].Text.Split(',');
                            var splitNombreProducto = splitProducto[0];

                            tempCategoria.Nombre = splitProducto[1].TrimStart();
                            tempCategoria        = objCat.ConsultarPorNombreDeCategoria(tempCategoria);

                            tempProducto.CodigoNumerico = Convert.ToInt32(mRow.Cells[1].Text);
                            tempProducto.IdCategoria    = tempCategoria.idCategoria;
                            tempProducto.NombreProducto = splitNombreProducto;
                            tempProducto            = objProd.ConsultarProductoPorNombreCodigoCategoria(tempProducto);
                            tempProducto.Inventario = tempProducto.Inventario + 1;
                            SaldoActual             = SaldoActual - tempProducto.Precio;
                            txtSaldoActual.Text     = SaldoActual.ToString();
                            Session["SaldoActual"]  = SaldoActual;
                            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + mRow.Cells[2].Text + "')", true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = ex.Message;
                throw ex;
            }
        }
Exemple #10
0
        protected void gvwProductos_SelectedIndexChanged(object sender, EventArgs e)
        {
            var tempCategoria = new CAT_CATEGORIA();

            tempCategoria.Nombre = gvwProductos.SelectedRow.Cells[2].Text;
            tempCategoria        = objCat.ConsultarPorNombre(tempCategoria).FirstOrDefault();

            hdfId.Value                = gvwProductos.SelectedRow.Cells[0].Text;
            txtNombreProducto.Text     = gvwProductos.SelectedRow.Cells[1].Text;
            ddlCategoria.SelectedValue = tempCategoria.idCategoria.ToString();
            txtCodNumerico.Text        = gvwProductos.SelectedRow.Cells[3].Text;
            txtPrecio.Text             = gvwProductos.SelectedRow.Cells[4].Text;
            txtCantidad.Text           = gvwProductos.SelectedRow.Cells[5].Text;
            btnInsertarActualizar.Text = "Actualizar";

            //var temp = new CQR_CODIGO_QR();
            //temp.idQR = Convert.ToInt32(hdfId.Value + "" + txtCodNumerico.Text);
            //temp = objQR.ConsultarPorId(temp).FirstOrDefault();

            //QRImage.ImageUrl = "../" + temp.urlImagen.Substring(70);
            //QRImage.ImageUrl = "../" + temp.urlImagen.Substring(32);
        }
Exemple #11
0
        private void cargarProductos()
        {
            try
            {
                lblLoad.Text = "Cargando...";
                var dt   = new DataTable();
                var rows = objProd.ConsultarPorCategoria(Convert.ToInt32(ddlMetal.SelectedValue));

                ddlProducto.Items.Clear();
                ddlProducto.DataTextField  = "NombreProducto";
                ddlProducto.DataValueField = "IdProducto";
                dt.Columns.Add("IdProducto", typeof(System.String));
                dt.Columns.Add("NombreProducto", typeof(System.String));

                foreach (PRO_PRODUCTO r in rows)
                {
                    var tempCategoria = new CAT_CATEGORIA();
                    tempCategoria.idCategoria = r.IdCategoria;
                    tempCategoria             = objCat.ConsultarPorId(tempCategoria).FirstOrDefault();

                    // filtrar por nombre seleccionado
                    if (ddlCategoria.SelectedItem.Text.Equals(r.NombreProducto, StringComparison.CurrentCultureIgnoreCase))
                    {
                        DataRow fila = dt.NewRow();

                        fila["IdProducto"]     = r.IdProducto;
                        fila["NombreProducto"] = r.NombreProducto + " " + tempCategoria.Nombre + " " + r.CodigoNumerico;
                        dt.Rows.Add(fila);
                    }
                }
                ddlProducto.DataSource = dt;
                ddlProducto.DataBind();
                lblLoad.Text = "";
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
        protected void btnImprimir_Click(object sender, EventArgs e)
        {
            //var rows = objDeF.Consultar();
            var metal            = "";
            var contadorDeFilas  = 0;
            var rows             = objDeF.ConsultarPorIdFactura(Convert.ToInt32(ddlFacturas.SelectedValue), "");
            var datosDeLaFactura = new FAC_FACTURA();
            var tempCategoria    = new CAT_CATEGORIA();

            datosDeLaFactura.idFactura = Convert.ToInt32(ddlFacturas.SelectedValue);
            datosDeLaFactura           = objFact.ConsultarPorId(datosDeLaFactura).FirstOrDefault();

            tempCategoria.idCategoria = datosDeLaFactura.idCategoriaMetal;
            tempCategoria             = objCateg.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
            {
                //Ponemos la fecha actual, el vendedor y el metal respectivamente.
                excelSheet.Cells[3, 5] = DateTime.Now.Date;
                excelSheet.Cells[5, 3] = txtNombreVendedor.Text;
                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] = DateTime.Now.Date.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);

                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();
            }
        }
Exemple #13
0
        private void CargarTablaDetalleFacturas(int idFactura)
        {
            try
            {
                var dt = new DataTable();
                //var rows = objDeF.Consultar();
                gvwDetalleFactura.DataSource = null;
                gvwDetalleFactura.DataBind();

                dt.Columns.Add("idDetalleFactura", typeof(System.String));
                dt.Columns.Add("idFactura", typeof(System.String));
                dt.Columns.Add("idProducto", typeof(System.String));
                dt.Columns.Add("CodProducto", typeof(System.String));
                dt.Columns.Add("idCategoria", typeof(System.String));
                dt.Columns.Add("CantidadProducto", typeof(System.String));

                if (idFactura != -1)
                {
                    //var rows = objDeF.ConsultarPorIdFactura(idFactura, txtCriterio.Text);
                    var tempDetalleFactura = new DEF_DETALLE_FACTURA();
                    tempDetalleFactura.idFactura = idFactura;
                    var rows = objDeF.ConsultarDetalleFacturaPorIdFactura(tempDetalleFactura);

                    foreach (DEF_DETALLE_FACTURA r in rows)
                    {
                        var tempCategoria = new CAT_CATEGORIA();
                        var tempProducto  = new PRO_PRODUCTO();
                        var tempFactura   = new FAC_FACTURA();

                        tempFactura.idFactura     = r.idFactura;
                        tempFactura               = objFact.ConsultarPorId(tempFactura).FirstOrDefault();
                        tempProducto.IdProducto   = r.idProducto;
                        tempProducto              = objProd.ConsultarPorId(tempProducto).FirstOrDefault();
                        tempCategoria.idCategoria = tempProducto.IdCategoria;
                        DataRow fila = dt.NewRow();

                        fila["idDetalleFactura"] = r.idDetalleFactura;
                        fila["idFactura"]        = tempFactura.NoFactura;
                        fila["idProducto"]       = tempProducto.NombreProducto;
                        fila["CodProducto"]      = tempProducto.CodigoNumerico;
                        fila["idCategoria"]      = objCat.ConsultarPorId(tempCategoria).FirstOrDefault().Nombre;
                        fila["CantidadProducto"] = r.CantidadProducto;
                        dt.Rows.Add(fila);
                    }
                }
                else
                {
                    DataRow fila = dt.NewRow();

                    fila["idDetalleFactura"] = "---";
                    fila["idFactura"]        = "---";
                    fila["idProducto"]       = "---";
                    fila["CodProducto"]      = "---";
                    fila["idCategoria"]      = "---";
                    fila["CantidadProducto"] = "---";
                    dt.Rows.Add(fila);
                }
                var estadoFactura = new FAC_FACTURA();
                estadoFactura.idFactura = idFactura;
                estadoFactura           = objFact.ConsultarPorId(estadoFactura).FirstOrDefault();
                if (estadoFactura.estado == Convert.ToInt32(EstadoFacturas.EnCreacion))
                {
                    this.gvwDetalleFactura.Columns[6].Visible = true;
                }
                else
                {
                    this.gvwDetalleFactura.Columns[6].Visible = false;
                }
                gvwDetalleFactura.DataSource = dt;
                gvwDetalleFactura.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }