Exemplo n.º 1
0
        internal static Producto GetDetalleProducto(string text)
        {
            Producto obj = null;

            try
            {
                using (SqlConnection cnn = ConexionBD.GetConexion())
                {
                    cnn.Open();
                    string     strComando = "SELECT IdProducto, CodigoBarra, idCategoria, idMarca, DescripcionProducto, Precio, Stock, Estado FROM Productos WHERE DescripcionProducto=@desc or (CodigoBarra=@desc)";
                    SqlCommand comando    = new SqlCommand(strComando, cnn);
                    comando.Parameters.AddWithValue("@desc", text);
                    using (SqlDataReader reader = comando.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (reader.HasRows)
                        {
                            reader.Read();
                            obj                     = new Producto();
                            obj.IdProducto          = reader.GetInt32(0);
                            obj.CodigoBarra         = reader[1] == DBNull.Value ? string.Empty : reader.GetString(1);
                            obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                            obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                            obj.DescripcionProducto = reader[4] == DBNull.Value ? string.Empty : reader.GetString(4);
                            obj.Precio              = reader.GetDecimal(5);
                            obj.Stock               = reader.GetInt32(6);
                        }
                    }
                }
                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        private static List <Producto> GetListaActivos()
        {
            List <Producto> listaProd = new List <Producto>();

            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                cnn.Open();
                string     strComando = "SELECT * FROM Productos WHERE Estado=1 ORDER BY DescripcionProducto asc  ";
                SqlCommand comando    = new SqlCommand(strComando, cnn);
                using (SqlDataReader reader = comando.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Producto obj = new Producto();
                        obj.IdProducto          = reader.GetInt32(0);
                        obj.CodigoBarra         = reader[1] == DBNull.Value ? string.Empty : reader.GetString(1);
                        obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                        obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                        obj.DescripcionProducto = reader[4] == DBNull.Value ? string.Empty : reader.GetString(4);
                        obj.Precio = reader.GetDecimal(5);
                        obj.Stock  = reader.GetInt32(6);
                        obj.Estado = (EstadoProducto)reader.GetInt32(7);


                        listaProd.Add(obj);
                    }
                }
            }
            return(listaProd);
        }
Exemplo n.º 3
0
        internal static List <Producto> GetListaFilrada(string producto)
        {
            List <Producto> listaProdFilt = new List <Producto>();

            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                cnn.Open();
                string     strComando = "SELECT IdProducto, CodigoBarra, idCategoria, idMarca, DescripcionProducto, Precio, Stock, Estado FROM Productos Where CodigoBarra like @prod+'%' or DescripcionProducto like '%'+@desc+'%' ORDER BY DescripcionProducto asc ";
                SqlCommand comando    = new SqlCommand(strComando, cnn);
                comando.Parameters.AddWithValue("@prod", producto);
                comando.Parameters.AddWithValue("@desc", producto);
                using (SqlDataReader reader = comando.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Producto obj = new Producto();
                        obj.IdProducto          = reader.GetInt32(0);
                        obj.CodigoBarra         = reader[1] == DBNull.Value ? string.Empty : reader.GetString(1);
                        obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                        obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                        obj.DescripcionProducto = reader[4] == DBNull.Value ? string.Empty : reader.GetString(4);
                        obj.Precio = reader.GetDecimal(5);
                        obj.Stock  = reader.GetInt32(6);
                        obj.Estado = (EstadoProducto)reader.GetInt32(7);



                        listaProdFilt.Add(obj);
                    }
                }
            }
            return(listaProdFilt);
        }
Exemplo n.º 4
0
        internal static void CargarCombo(ref ComboBox cboMarca)
        {
            List <Marca> lista  = MarcasBD.GetLista();
            Marca        marca2 = new Marca()
            {
                DescripcionMarca = "<Seleccione la marca>"
            };

            lista.Insert(0, marca2);
            cboMarca.DataSource    = lista;
            cboMarca.DisplayMember = "DescripcionMarca";
            cboMarca.ValueMember   = "IdMarca";
        }
Exemplo n.º 5
0
        internal static List <Producto> GetProductosPorCodigo(string codigo)
        {
            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                List <Producto> listaFiltrada = new List <Producto>();
                cnn.Open();

                string     filterCommand = "SELECT IdProducto, CodigoBarra, idCategoria, idMarca, DescripcionProducto, Precio, Stock, Estado FROM Productos WHERE CodigoBarra like '%'+@codigo+'%'";
                SqlCommand comando       = new SqlCommand(filterCommand, cnn);
                comando.Parameters.AddWithValue("@codigo", codigo);

                try
                {
                    SqlDataReader reader = comando.ExecuteReader();

                    while (reader.Read())
                    {
                        Producto obj = new Producto();

                        obj.IdProducto          = reader.GetInt32(0);
                        obj.CodigoBarra         = reader[1] == DBNull.Value ? string.Empty : reader.GetString(1);
                        obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                        obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                        obj.DescripcionProducto = reader[4] == DBNull.Value ? string.Empty : reader.GetString(4);
                        obj.Precio = reader.GetDecimal(5);
                        obj.Stock  = reader.GetInt32(6);
                        obj.Estado = (EstadoProducto)reader.GetInt32(7);

                        listaFiltrada.Add(obj);
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al intentar una busqueda", ex.Message);
                }
                finally
                {
                    cnn.Close();
                }
                return(listaFiltrada);
            }
        }
Exemplo n.º 6
0
        internal static bool RevisarStock(int cantidad, Producto prod)
        {
            using (SqlConnection cnn = ConexionBD.GetConexion())

                try
                {
                    cnn.Open();
                    string     selectCommand = "SELECT IdProducto, CodigoBarra, idCategoria, idMarca, DescripcionProducto, Precio, Stock, Estado FROM Productos WHERE Stock>=@cantidad and idProducto=@id";
                    SqlCommand comando       = new SqlCommand(selectCommand, cnn);
                    comando.Parameters.AddWithValue("@cantidad", cantidad);
                    comando.Parameters.AddWithValue("id", prod.IdProducto);
                    SqlDataReader reader = comando.ExecuteReader(CommandBehavior.SingleRow);
                    if (reader.HasRows)
                    {
                        Producto obj = new Producto();
                        reader.Read();
                        obj.IdProducto          = reader.GetInt32(0);
                        obj.CodigoBarra         = reader[1] == DBNull.Value ? string.Empty : reader.GetString(1);
                        obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                        obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                        obj.DescripcionProducto = reader[4] == DBNull.Value ? string.Empty : reader.GetString(4);
                        obj.Precio = reader.GetDecimal(5);
                        obj.Stock  = reader.GetInt32(6);



                        reader.Close();
                        cnn.Close();
                        return(true);
                    }
                    else
                    {
                        cnn.Close();
                        reader.Close();
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
        }
Exemplo n.º 7
0
        internal static string ObtenerIdAPartirDesc(string v)
        {
            Producto obj = null;

            try
            {
                using (SqlConnection cnn = ConexionBD.GetConexion())
                {
                    cnn.Open();
                    string     strComando = "SELECT IdProducto, CodigoBarra, idCategoria, idMarca, DescripcionProducto, Precio, Stock, Estado FROM Productos WHERE DescripcionProducto=@id";
                    SqlCommand comando    = new SqlCommand(strComando, cnn);
                    comando.Parameters.AddWithValue("@id", v);
                    using (SqlDataReader reader = comando.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (reader.HasRows)
                        {
                            reader.Read();
                            obj                     = new Producto();
                            obj.IdProducto          = reader.GetInt32(0);
                            obj.CodigoBarra         = reader.GetString(1);
                            obj.idCategoria         = CategoriasBD.GetObjeto(reader.GetInt32(2));
                            obj.idMarca             = MarcasBD.GetObjeto(reader.GetInt32(3));
                            obj.DescripcionProducto = reader.GetString(4);
                            obj.Precio              = reader.GetDecimal(5);
                            obj.Stock               = reader.GetInt32(6);
                            obj.Estado              = (EstadoProducto)reader.GetInt32(7);
                        }
                    }
                }
                return(v);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }