Exemple #1
0
        public bool Guardar(ProductoBe productoBe, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_guardar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@EmpresaId", productoBe.EmpresaId.GetNullable());
                    cmd.Parameters.AddWithValue("@ProductoId", productoBe.ProductoId.GetNullable());
                    cmd.Parameters.AddWithValue("@CategoriaId", productoBe.CategoriaId.GetNullable());
                    cmd.Parameters.AddWithValue("@Nombre", productoBe.Nombre.GetNullable());
                    cmd.Parameters.AddWithValue("@TipoAfectacionIgvId", productoBe.TipoAfectacionIgvId.GetNullable());
                    cmd.Parameters.AddWithValue("@UnidadMedidaId", productoBe.UnidadMedidaId.GetNullable());
                    cmd.Parameters.AddWithValue("@TipoCalculo", productoBe.TipoCalculo.GetNullable());
                    cmd.Parameters.AddWithValue("@Monto", productoBe.Monto.GetNullable());
                    cmd.Parameters.AddWithValue("@StockMinimo", productoBe.StockMinimo.GetNullable());
                    cmd.Parameters.AddWithValue("@Usuario", productoBe.Usuario.GetNullable());
                    cmd.Parameters.AddWithValue("@TipoProductoId", productoBe.TipoProductoId.GetNullable());
                    cmd.Parameters.AddWithValue("@CodigoSunat", productoBe.CodigoSunat.GetNullable());
                    cmd.Parameters.AddWithValue("@Codigo", productoBe.Codigo.GetNullable());


                    int filasAfectadas = cmd.ExecuteNonQuery();
                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex)
            {
                seGuardo = false;
            }
            return(seGuardo);
        }
Exemple #2
0
        public bool GuardarProducto(ProductoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_guardar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoProducto", registro.CodigoProducto.GetNullable());
                    cmd.Parameters.AddWithValue("@nombre", registro.Nombre.GetNullable());
                    cmd.Parameters.AddWithValue("@codigoUnidadMedida", registro.CodigoUnidadMedida.GetNullable());
                    cmd.Parameters.AddWithValue("@cantidad", registro.Cantidad.GetNullable());
                    cmd.Parameters.AddWithValue("@valorCompra", registro.ValorCompra.GetNullable());
                    cmd.Parameters.AddWithValue("@valorVenta", registro.ValorVenta.GetNullable());
                    cmd.Parameters.AddWithValue("@descuentoMaximo", registro.DescuentoMaximo.GetNullable());
                    cmd.Parameters.AddWithValue("@color", registro.Color.GetNullable());
                    cmd.Parameters.AddWithValue("@metrajeTotal", registro.MetrajeTotal.GetNullable());
                    cmd.Parameters.AddWithValue("@estado", registro.Estado.GetNullable());
                    cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();

                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(seGuardo);
        }
        void CargarProducto()
        {
            ProductoBe item = productoBl.ObtenerProducto(codigoProducto.Value);

            txtNombre.Text = item.Nombre;
            cbbCodigoUnidadMedida.SelectedValue = item.CodigoUnidadMedida;
            txtCantidad.Text        = item.Cantidad.ToString("0.00");
            txtValorCompra.Text     = item.ValorCompra.ToString("0.00");
            txtValorVenta.Text      = item.ValorVenta.ToString("0.00");
            txtDescuentoMaximo.Text = item.DescuentoMaximo.ToString("0.00");
            txtColor.Text           = item.Color;
            txtMetrajeTotal.Text    = item.MetrajeTotal.ToString("0.00");
            cbbEstado.SelectedValue = item.Estado.ToString();
        }
Exemple #4
0
        public List <ProductoBe> BuscarProducto(int?codigoProducto, string nombre, string color, int?estado, SqlConnection cn)
        {
            List <ProductoBe> resultados = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_buscar", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoProducto", codigoProducto.GetNullable());
                    cmd.Parameters.AddWithValue("@nombre", nombre.GetNullable());
                    cmd.Parameters.AddWithValue("@color", color.GetNullable());
                    cmd.Parameters.AddWithValue("@estado", estado.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            resultados = new List <ProductoBe>();

                            while (dr.Read())
                            {
                                ProductoBe item = new ProductoBe();
                                item.Fila               = dr.GetData <int>("Fila");
                                item.CodigoProducto     = dr.GetData <int>("CodigoProducto");
                                item.Nombre             = dr.GetData <string>("Nombre");
                                item.CodigoUnidadMedida = dr.GetData <int>("CodigoUnidadMedida");
                                item.UnidadMedida       = new UnidadMedidaBe();
                                item.UnidadMedida.CodigoUnidadMedida = dr.GetData <int>("CodigoUnidadMedida");
                                item.UnidadMedida.Descripcion        = dr.GetData <string>("DescripcionUnidadMedida");
                                item.UnidadMedida.FlagActivo         = dr.GetData <bool>("FlagActivoUnidadMedida");
                                item.Cantidad        = dr.GetData <decimal>("Cantidad");
                                item.ValorCompra     = dr.GetData <decimal>("ValorCompra");
                                item.ValorVenta      = dr.GetData <decimal>("ValorVenta");
                                item.DescuentoMaximo = dr.GetData <decimal>("DescuentoMaximo");
                                item.Color           = dr.GetData <string>("Color");
                                item.MetrajeTotal    = dr.GetData <decimal>("MetrajeTotal");
                                item.Estado          = dr.GetData <int>("Estado");

                                resultados.Add(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(resultados);
        }
        void CargarProducto(int?codigoProducto)
        {
            ProductoBe producto = codigoProducto == null ? null : productoBl.ObtenerProducto(codigoProducto.Value);

            if (producto != null)
            {
                this.codigoProducto    = producto.CodigoProducto;
                txtNombreProducto.Text = producto.Nombre;
            }
            else
            {
                this.codigoProducto    = null;
                txtNombreProducto.Text = "";
            }
        }
Exemple #6
0
        public bool ProductoGuardar(ProductoBe registro)
        {
            bool seGuardo = false;

            try
            {
                cn.Open();
                seGuardo = productoDa.Guardar(registro, cn);
                cn.Close();
            }
            catch (Exception ex) { seGuardo = false; }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }
            return(seGuardo);
        }
Exemple #7
0
        public ProductoBe ObtenerProducto(int codigoProducto)
        {
            ProductoBe item = null;

            try
            {
                cn.Open();
                item = productoDa.ObtenerProducto(codigoProducto, cn);
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(item);
        }
Exemple #8
0
        public bool CambiarEstadoProducto(ProductoBe registro)
        {
            bool seGuardo = false;

            try
            {
                cn.Open();
                seGuardo = productoDa.CambiarEstadoProducto(registro, cn);
            }
            catch (Exception ex) { log.Error(ex.Message); }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }

            return(seGuardo);
        }
Exemple #9
0
        public ProductoBe Obtener(int EmpresaId, int productoId)
        {
            ProductoBe respuesta = null;

            try
            {
                cn.Open();
                respuesta = new ProductoDa().Obtener(EmpresaId, productoId, cn);
                cn.Close();
            }
            catch (Exception ex) { respuesta = null; }
            finally { if (cn.State == ConnectionState.Open)
                      {
                          cn.Close();
                      }
            }
            return(respuesta);
        }
Exemple #10
0
        public List <ProductoBe> Buscar(string categoriaNombre, string nombre, int empresaId, int pagina, int cantidadRegistros, string columnaOrden, string ordenMax, SqlConnection cn, out int totalRegistros)
        {
            totalRegistros = 0;
            List <ProductoBe> lista = null;

            using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_buscar", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@categoriaNombre", categoriaNombre.GetNullable());
                cmd.Parameters.AddWithValue("@nombre", nombre.GetNullable());
                cmd.Parameters.AddWithValue("@EmpresaId", empresaId.GetNullable());
                cmd.Parameters.AddWithValue("@pagina", pagina.GetNullable());
                cmd.Parameters.AddWithValue("@cantidadRegistros", cantidadRegistros.GetNullable());
                cmd.Parameters.AddWithValue("@columnaOrden", columnaOrden.GetNullable());
                cmd.Parameters.AddWithValue("@ordenMax", ordenMax.GetNullable());
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.HasRows)
                    {
                        lista = new List <ProductoBe>();
                        while (dr.Read())
                        {
                            ProductoBe item = new ProductoBe();
                            item.Fila                     = dr.GetData <int>("Fila");
                            item.ProductoId               = dr.GetData <int>("ProductoId");
                            item.Nombre                   = dr.GetData <string>("NombreProducto");
                            item.TipoAfectacionIgvId      = dr.GetData <int>("TipoAfectacionIgvId");
                            item.UnidadMedidaId           = dr.GetData <string>("UnidadMedidaId");
                            item.TipoCalculo              = dr.GetData <string>("TipoCalculo");
                            item.Monto                    = dr.GetData <decimal>("Monto");
                            item.StockMinimo              = dr.GetData <decimal>("StockMinimo");
                            item.categoriaProducto        = new CategoriaProductoBe();
                            item.categoriaProducto.Nombre = dr.GetData <string>("NombreCategoria");
                            item.StockMinimo              = dr.GetData <decimal>("StockMinimo");
                            lista.Add(item);

                            totalRegistros = dr.GetData <int>("Total");
                        }
                    }
                }
            }
            return(lista);
        }
Exemple #11
0
        public List <ProductoBe> BuscarPorCodigo(int?tipoProductoId, string codigo, int empresaId, SqlConnection cn, int sedeAlmacenId = 0)
        {
            List <ProductoBe> lista = null;

            using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_buscar_x_codigo", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@tipoProductoId", tipoProductoId.GetNullable());
                cmd.Parameters.AddWithValue("@codigo", codigo.GetNullable());
                cmd.Parameters.AddWithValue("@empresaId", empresaId.GetNullable());
                cmd.Parameters.AddWithValue("@SedeAlmacenId", sedeAlmacenId.GetNullable());
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.HasRows)
                    {
                        lista = new List <ProductoBe>();
                        while (dr.Read())
                        {
                            ProductoBe item = new ProductoBe();
                            item.Fila                = dr.GetData <int>("Fila");
                            item.ProductoId          = dr.GetData <int>("ProductoId");
                            item.EmpresaId           = dr.GetData <int>("EmpresaId");
                            item.CategoriaId         = dr.GetData <int>("CategoriaId");
                            item.TipoProductoId      = dr.GetData <int>("TipoProductoId");
                            item.Codigo              = dr.GetData <string>("Codigo");
                            item.CodigoSunat         = dr.GetData <string>("CodigoSunat");
                            item.Nombre              = dr.GetData <string>("Nombre");
                            item.StockActual         = dr.GetData <decimal>("Stock");
                            item.TipoAfectacionIgvId = dr.GetData <int>("TipoAfectacionIgvId");
                            item.UnidadMedidaId      = dr.GetData <string>("UnidadMedidaId");
                            item.TipoCalculo         = dr.GetData <string>("TipoCalculo");
                            //item.categoriaProducto = new CategoriaProductoBe();
                            //item.categoriaProducto.Nombre = dr.GetData<string>("NombreCategoria");
                            //item.Stock = dr.GetData<int>("Stock");
                            item.StockMinimo = dr.GetData <decimal>("StockMinimo");
                            lista.Add(item);
                        }
                    }
                }
            }
            return(lista);
        }
Exemple #12
0
        public ProductoBe Obtener(int empresaId, int productoId, SqlConnection cn)
        {
            ProductoBe respuesta = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_obtener", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@EmpresaId", empresaId.GetNullable());
                    cmd.Parameters.AddWithValue("@ProductoId", productoId.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            if (dr.Read())
                            {
                                respuesta                     = new ProductoBe();
                                respuesta.Nombre              = dr.GetData <string>("Nombre");
                                respuesta.CategoriaId         = dr.GetData <int>("CategoriaId");
                                respuesta.TipoAfectacionIgvId = dr.GetData <int>("TipoAfectacionIgvId");
                                respuesta.UnidadMedidaId      = dr.GetData <string>("UnidadMedidaId");
                                respuesta.TipoCalculo         = dr.GetData <string>("TipoCalculo");
                                respuesta.Monto               = dr.GetData <decimal>("Monto");
                                respuesta.StockMinimo         = dr.GetData <decimal>("StockMinimo");
                                respuesta.Codigo              = dr.GetData <string>("Codigo");
                                respuesta.CodigoSunat         = dr.GetData <string>("CodigoSunat");
                                respuesta.TipoProductoId      = dr.GetData <int>("TipoProductoId");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                respuesta = null;
            }
            return(respuesta);
        }
Exemple #13
0
        public JsonResult InsertarProducto(ProductoBe p)
        {
            int       FilasAfectadas = 0;
            UsuarioBe usuario        = new UsuarioBe();

            usuario = MetodosUtiles.ObtenerUsuario();
            if (p.IdProducto == 0)
            {
                p.UsuarioCrea = usuario.IdUsuario;
            }
            else
            {
                p.UsuarioModifica = usuario.IdUsuario;
            }

            FilasAfectadas = ServiceManager <ProductoSvc> .Provider.InsertarProducto(p);

            JsonResult json = Json(new { d = FilasAfectadas }, JsonRequestBehavior.AllowGet);

            json.MaxJsonLength = int.MaxValue;
            return(json);
        }
Exemple #14
0
        public bool CambiarEstadoProducto(ProductoBe registro, SqlConnection cn)
        {
            bool seGuardo = false;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_cambiar_estado", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoProducto", registro.CodigoProducto.GetNullable());
                    cmd.Parameters.AddWithValue("@flagActivo", registro.Estado.GetNullable());
                    cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable());

                    int filasAfectadas = cmd.ExecuteNonQuery();

                    seGuardo = filasAfectadas > 0;
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(seGuardo);
        }
Exemple #15
0
        public ProductoBe ObtenerProducto(int codigoProducto, SqlConnection cn)
        {
            ProductoBe item = null;

            try
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_producto_obtener", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@codigoProducto", codigoProducto.GetNullable());

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            item = new ProductoBe();

                            if (dr.Read())
                            {
                                item.CodigoProducto     = dr.GetData <int>("CodigoProducto");
                                item.Nombre             = dr.GetData <string>("Nombre");
                                item.CodigoUnidadMedida = dr.GetData <int>("CodigoUnidadMedida");
                                item.Cantidad           = dr.GetData <decimal>("Cantidad");
                                item.ValorCompra        = dr.GetData <decimal>("ValorCompra");
                                item.ValorVenta         = dr.GetData <decimal>("ValorVenta");
                                item.DescuentoMaximo    = dr.GetData <decimal>("DescuentoMaximo");
                                item.Color        = dr.GetData <string>("Color");
                                item.MetrajeTotal = dr.GetData <decimal>("MetrajeTotal");
                                item.Estado       = dr.GetData <int>("Estado");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { log.Error(ex.Message); }

            return(item);
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            bool estaValidado = ValidarFormulario();

            if (!estaValidado)
            {
                return;
            }

            ProductoBe registro = new ProductoBe();

            if (codigoProducto.HasValue)
            {
                registro.CodigoProducto = codigoProducto.Value;
            }
            registro.Nombre             = txtNombre.Text.Trim();
            registro.CodigoUnidadMedida = (int)cbbCodigoUnidadMedida.SelectedValue;
            registro.Cantidad           = decimal.Parse(txtCantidad.Text.Trim());
            registro.ValorCompra        = decimal.Parse(txtValorCompra.Text.Trim());
            registro.ValorVenta         = decimal.Parse(txtValorVenta.Text.Trim());
            registro.DescuentoMaximo    = decimal.Parse(txtDescuentoMaximo.Text.Trim());
            registro.Color        = txtColor.Text.Trim();
            registro.MetrajeTotal = decimal.Parse(txtMetrajeTotal.Text.Trim());
            registro.Estado       = int.Parse(cbbEstado.SelectedValue.ToString());

            bool seGuardoRegistro = productoBl.GuardarProducto(registro);

            if (seGuardoRegistro)
            {
                DialogResult = MessageBox.Show("¡El registro se guardó correctamente!", "¡Bien hecho!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
            }
            else
            {
                MessageBox.Show("¡Ocurrió un error! Contáctese con el administrador del sistema", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool GuardarProducto(ProductoBe registro)
        {
            bool respuesta = productoBl.ProductoGuardar(registro);

            return(respuesta);
        }
Exemple #18
0
 public abstract int InsertarProducto(ProductoBe p);
        public override List <ProductoBe> PaginarProducto(string Filtro, int PageSize, int PageNumber, out int TotalRegistros)
        {
            List <ProductoBe> Lista = null;

            using (SqlConnection conexion = new SqlConnection(_conexion))
            {
                SqlCommand cmd = new SqlCommand("USP_PRODUCTO_PAGINACION", conexion);
                try
                {
                    conexion.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@Filtro", SqlDbType = SqlDbType.VarChar, Value = (object)Filtro ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@PageSize", SqlDbType = SqlDbType.Int, Value = (object)PageSize ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@PageNumber", SqlDbType = SqlDbType.Int, Value = (object)PageNumber ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (dr != null)
                    {
                        int pIdProducto     = dr.GetOrdinal("IdProducto");
                        int pCodigoProducto = dr.GetOrdinal("CodigoProducto");
                        int pCodigoSunat    = dr.GetOrdinal("CodigoSunat");
                        int pCodigoBarras   = dr.GetOrdinal("CodigoBarras");
                        int pUnidadStr      = dr.GetOrdinal("UnidadStr");
                        int pAfectoStr      = dr.GetOrdinal("AfectoStr");
                        int pIdCategoria    = dr.GetOrdinal("IdCategoria");
                        int pBienStr        = dr.GetOrdinal("BienStr");
                        int pMonedaStr      = dr.GetOrdinal("MonedaStr");
                        int pNombre         = dr.GetOrdinal("Nombre");
                        int pStock          = dr.GetOrdinal("Stock");
                        int pPrecioCompra   = dr.GetOrdinal("PrecioCompra");
                        int pPrecioVenta    = dr.GetOrdinal("PrecioVenta");
                        Lista = new List <ProductoBe>();
                        ProductoBe p = null;
                        while (dr.Read())
                        {
                            p                = new ProductoBe();
                            p.IdProducto     = dr.GetValueInt32(pIdProducto);
                            p.CodigoProducto = dr.GetValueString(pCodigoProducto);
                            p.CodigoSunat    = dr.GetValueString(pCodigoSunat);
                            p.CodigoBarras   = dr.GetValueString(pCodigoBarras);
                            p.UnidadStr      = dr.GetValueString(pUnidadStr);
                            p.AfectoStr      = dr.GetValueString(pAfectoStr);
                            p.IdCategoria    = dr.GetValueInt32(pIdCategoria);
                            p.BienStr        = dr.GetValueString(pBienStr);
                            p.MonedaStr      = dr.GetValueString(pMonedaStr);
                            p.Nombre         = dr.GetValueString(pNombre);
                            p.Stock          = dr.GetValueInt32(pStock);
                            p.PrecioCompra   = dr.GetValueDecimal(pPrecioCompra);
                            p.PrecioVenta    = dr.GetValueDecimal(pPrecioVenta);
                            Lista.Add(p);
                        }
                        dr.Close();
                    }
                    TotalRegistros = (Lista == null || Lista.Count == 0) ? 0 : Lista[0].TotalRegistros;
                    return(Lista);
                }
                catch (SqlException ex)
                {
                    Log.GrabarLog(ex.Message, ex.StackTrace);
                    throw ex;
                }
                catch (Exception ex1)
                {
                    Log.GrabarLog(ex1.Message, ex1.StackTrace);
                    throw ex1;
                }
            }
        }
        public override ProductoBe ProductoPorCodigo(int IdProducto)
        {
            ProductoBe p = null;

            using (SqlConnection conexion = new SqlConnection(_conexion))
            {
                SqlCommand cmd = new SqlCommand("USP_PRODUCTO_POR_CODIGO", conexion);
                try
                {
                    conexion.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdProducto", SqlDbType = SqlDbType.Int, Value = (object)IdProducto ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (dr != null)
                    {
                        int pIdProducto     = dr.GetOrdinal("IdProducto");
                        int pCodigoProducto = dr.GetOrdinal("CodigoProducto");
                        int pCodigoSunat    = dr.GetOrdinal("CodigoSunat");
                        int pCodigoBarras   = dr.GetOrdinal("CodigoBarras");
                        int pIdUnidad       = dr.GetOrdinal("IdUnidad");
                        int pIdAfectacion   = dr.GetOrdinal("IdAfectacion");
                        int pIdCategoria    = dr.GetOrdinal("IdCategoria");
                        int pIdTipo         = dr.GetOrdinal("IdTipo");
                        int pIdMoneda       = dr.GetOrdinal("IdMoneda");
                        int pNombre         = dr.GetOrdinal("Nombre");
                        int pStock          = dr.GetOrdinal("Stock");
                        int pPrecioCompra   = dr.GetOrdinal("PrecioCompra");
                        int pPrecioVenta    = dr.GetOrdinal("PrecioVenta");
                        if (dr.Read())
                        {
                            p                = new ProductoBe();
                            p.IdProducto     = dr.GetValueInt32(pIdProducto);
                            p.CodigoProducto = dr.GetValueString(pCodigoProducto);
                            p.CodigoSunat    = dr.GetValueString(pCodigoSunat);
                            p.CodigoBarras   = dr.GetValueString(pCodigoBarras);
                            p.IdUnidad       = dr.GetValueString(pIdUnidad);
                            p.IdAfectacion   = dr.GetValueString(pIdAfectacion);
                            p.IdCategoria    = dr.GetValueInt32(pIdCategoria);
                            p.IdTipo         = dr.GetValueInt32(pIdTipo);
                            p.IdMoneda       = dr.GetValueInt32(pIdMoneda);
                            p.Nombre         = dr.GetValueString(pNombre);
                            p.Stock          = dr.GetValueInt32(pStock);
                            p.PrecioCompra   = dr.GetValueDecimal(pPrecioCompra);
                            p.PrecioVenta    = dr.GetValueDecimal(pPrecioVenta);
                        }
                        dr.Close();
                    }
                    return(p);
                }
                catch (SqlException ex)
                {
                    Log.GrabarLog(ex.Message, ex.StackTrace);
                    throw ex;
                }
                catch (Exception ex1)
                {
                    Log.GrabarLog(ex1.Message, ex1.StackTrace);
                    throw ex1;
                }
            }
        }
        public override int InsertarProducto(ProductoBe p)
        {
            int FilasAfectadas = 0;

            using (SqlConnection conexion = new SqlConnection(_conexion))
            {
                try
                {
                    conexion.Open();
                    SqlCommand cmd = new SqlCommand("USP_PRODUCTO_INSERT", conexion);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdProducto", SqlDbType = SqlDbType.Int, Value = (object)p.IdProducto ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@CodigoSunat", SqlDbType = SqlDbType.VarChar, Value = (object)p.CodigoSunat ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@CodigoBarras", SqlDbType = SqlDbType.VarChar, Value = (object)p.CodigoBarras ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdUnidad", SqlDbType = SqlDbType.VarChar, Value = (object)p.IdUnidad ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdAfectacion", SqlDbType = SqlDbType.Char, Value = (object)p.IdAfectacion ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdCategoria", SqlDbType = SqlDbType.Int, Value = (object)p.IdCategoria ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdTipo", SqlDbType = SqlDbType.Int, Value = (object)p.IdTipo ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@IdMoneda", SqlDbType = SqlDbType.Int, Value = (object)p.IdMoneda ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@Nombre", SqlDbType = SqlDbType.VarChar, Value = (object)p.Nombre ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@Stock", SqlDbType = SqlDbType.Int, Value = (object)p.Stock ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@PrecioCompra", SqlDbType = SqlDbType.Decimal, Value = (object)p.PrecioCompra ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@PrecioVenta", SqlDbType = SqlDbType.Decimal, Value = (object)p.PrecioVenta ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@UsuarioCrea", SqlDbType = SqlDbType.Int, Value = (object)p.UsuarioCrea ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });
                    cmd.Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@UsuarioModifica", SqlDbType = SqlDbType.Int, Value = (object)p.UsuarioModifica ?? DBNull.Value, Direction = ParameterDirection.Input, IsNullable = false
                    });

                    FilasAfectadas = cmd.ExecuteNonQuery();
                    return(FilasAfectadas);
                }
                catch (SqlException ex)
                {
                    Log.GrabarLog(ex.Message, ex.StackTrace);
                    throw ex;
                }
                catch (Exception ex1)
                {
                    Log.GrabarLog(ex1.Message, ex1.StackTrace);
                    throw ex1;
                }
            }
        }