Example #1
0
        public static List <Pedido> ObtenerPedidoCliente(int id)
        {
            SqlConnection conexion = BdComun.EstablecerConexion();
            List <Pedido> lista    = new List <Pedido>();
            String        consulta = "GetPedidosClientes";
            SqlCommand    comando  = new SqlCommand(consulta, conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@IdCliente", id);

            SqlDataReader reader = comando.ExecuteReader();

            while (reader.Read())
            {
                Pedido pedido = new Pedido();
                pedido.IdCliente = reader.GetInt32(0);
                pedido.Nombre    = reader.GetString(1);
                pedido.Producto  = reader.GetString(2);
                pedido.Cantidad  = reader.GetInt32(3);
                pedido.Precio    = reader.GetDouble(4);


                lista.Add(pedido);
            }
            conexion.Close();
            return(lista);
        }
Example #2
0
        public static List <Cliente> Obtener()
        {
            SqlConnection  conexion = BdComun.EstablecerConexion();
            List <Cliente> lista    = new List <Cliente>();

            String     consulta = "GetClientes";
            SqlCommand comando  = new SqlCommand(consulta, conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = comando.ExecuteReader();

            while (reader.Read())
            {
                Cliente cliente = new Cliente();
                cliente.Id        = reader.GetInt32(0);
                cliente.Nombre    = reader.GetString(1);
                cliente.Apellido  = reader.GetString(2);
                cliente.Fecha_Nac = reader.GetString(3);
                cliente.Direccion = reader.GetString(4);

                lista.Add(cliente);
            }
            conexion.Close();

            return(lista);
        }
Example #3
0
        public static List <Producto> Obtener()
        {
            SqlConnection   conexion = BdComun.EstablecerConexion();
            List <Producto> lista    = new List <Producto>();

            //String consulta = "SELECT IDProducto, Nombre, Descripcion, Precio, Stock FROM productos";
            String     consulta = "GetProductos";
            SqlCommand comando  = new SqlCommand(consulta, conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = comando.ExecuteReader();

            while (reader.Read())
            {
                Producto producto = new Producto();
                producto.Id          = reader.GetInt32(0);
                producto.Nombre      = reader.GetString(1);
                producto.Descripcion = reader.GetString(2);
                producto.Precio      = reader.GetString(3);
                producto.Stock       = reader.GetString(4);

                lista.Add(producto);
            }
            conexion.Close();

            return(lista);
        }
Example #4
0
        public static void Eliminar(int Id)
        {
            SqlConnection conexion = BdComun.EstablecerConexion();
            //String consulta = "DELETE from productos where IDProducto= '" + producto.Id + "'";
            String     consulta = "DeleteProducto";
            SqlCommand comando  = new SqlCommand(consulta, conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;

            comando.Parameters.AddWithValue("@IDProducto", Id);
            comando.ExecuteNonQuery();
            conexion.Close();
        }
Example #5
0
        public static void Modificar(Producto producto)
        {
            SqlConnection conexion = BdComun.EstablecerConexion();
            SqlCommand    comando  = new SqlCommand("UpdateProductos", conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;

            comando.Parameters.AddWithValue("@Nombre", producto.Nombre);
            comando.Parameters.AddWithValue("@Descripcion", producto.Descripcion);
            comando.Parameters.AddWithValue("@Precio", producto.Precio);
            comando.Parameters.AddWithValue("@Stock", producto.Stock);
            comando.Parameters.AddWithValue("@IDProducto", producto.Id);

            comando.ExecuteNonQuery();
            conexion.Close();
        }
Example #6
0
        public static void GuardarNuevo(Pedido pedido)
        {
            SqlConnection conexion = BdComun.EstablecerConexion();
            SqlCommand    comando  = new SqlCommand("AddPedido", conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;

            comando.Parameters.AddWithValue("@IdCliente", pedido.IdCliente);
            comando.Parameters.AddWithValue("@IdProducto", pedido.IdProducto);
            comando.Parameters.AddWithValue("@Cantidad", pedido.Cantidad);


            SqlParameter outPutParameter = new SqlParameter();

            outPutParameter.ParameterName = "@IDPedido";
            outPutParameter.SqlDbType     = System.Data.SqlDbType.Int;
            outPutParameter.Direction     = System.Data.ParameterDirection.Output;
            comando.Parameters.Add(outPutParameter);

            comando.ExecuteNonQuery();
            conexion.Close();
        }
Example #7
0
        public static void GuardarNuevo(Producto producto)
        {
            SqlConnection conexion = BdComun.EstablecerConexion();
            SqlCommand    comando  = new SqlCommand("AddProducto", conexion);

            comando.CommandType = System.Data.CommandType.StoredProcedure;

            comando.Parameters.AddWithValue("@Nombre", producto.Nombre);
            comando.Parameters.AddWithValue("@Descripcion", producto.Descripcion);
            comando.Parameters.AddWithValue("@Precio", producto.Precio);
            comando.Parameters.AddWithValue("@Stock", producto.Stock);

            SqlParameter outPutParameter = new SqlParameter();

            outPutParameter.ParameterName = "@IDProducto";
            outPutParameter.SqlDbType     = System.Data.SqlDbType.Int;
            outPutParameter.Direction     = System.Data.ParameterDirection.Output;
            comando.Parameters.Add(outPutParameter);

            comando.ExecuteNonQuery();
            conexion.Close();
        }