public static Ropa TraerRopa(int idRopa) { Ropa Ropita = new Ropa(); SqlConnection conn = Conectar(); SqlCommand consulta = conn.CreateCommand(); consulta.CommandText = "SELECT * FROM Ropa where IdRopa = " + idRopa; consulta.CommandType = System.Data.CommandType.Text; SqlDataReader lector = consulta.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { int IdRopa = Convert.ToInt32(lector["IdRopa"]); string Nombre = lector["Nombre"].ToString(); string precio = lector["Precio"].ToString(); string Descripcion = lector["Descripcion"].ToString(); string Stock = (lector["Stock"].ToString()); string Imagen = lector["Foto"].ToString(); Boolean Destacada = Convert.ToBoolean(lector["Destacado"] is DBNull ? 0 : lector["Destacado"]); Ropita = new Ropa(IdRopa, Nombre, precio, Imagen, Descripcion, Stock, Destacada); } } Desconectar(conn); return(Ropita); }
public static List <Ropa> ListarRopa() { List <Ropa> ListaRopa = new List <Ropa>(); SqlConnection Conn = Conectar(); SqlCommand Consulta = Conn.CreateCommand(); Consulta.CommandType = System.Data.CommandType.Text; Consulta.CommandText = "SELECT * from Ropa"; SqlDataReader Lector = Consulta.ExecuteReader(); while (Lector.Read()) { int IdR = Convert.ToInt32(Lector["idRopa"]); string Nom = (Lector["Nombre"].ToString()); string Prc = (Lector["Precio"].ToString()); string Desc = (Lector["Descripcion"].ToString()); string Foto = (Lector["Foto"].ToString()); string Stock = (Lector["Stock"].ToString()); Boolean Dest = Convert.ToBoolean(Lector["Destacado"] is DBNull ? 0 : Lector["Destacado"]); Ropa miRopa = new Ropa(IdR, Nom, Prc, Foto, Desc, Stock, Dest); ListaRopa.Add(miRopa); } Desconectar(Conn); return(ListaRopa); }
public static void InsertarROPA(Ropa Ropita) { SqlConnection Conn = Conectar(); SqlCommand Consulta = Conn.CreateCommand(); Consulta.CommandType = System.Data.CommandType.Text; Consulta.CommandText = "INSERT into Ropa(Nombre,Precio,Descripcion,Stock,Foto) VALUES('" + Ropita.Nombre + "','" + Ropita.Precio + "','" + Ropita.Descripcion + "'," + Ropita.Stock + ",'" + Ropita.Foto + "')"; Consulta.ExecuteNonQuery(); }
public static void EliminarRopa(int IdRopa) { Ropa Ropita = new Ropa(); SqlConnection Conn = Conectar(); SqlCommand Consulta = Conn.CreateCommand(); Consulta.CommandType = System.Data.CommandType.Text; Consulta.CommandText = "DELETE from Ropa where IdRopa= " + IdRopa + ""; Consulta.ExecuteNonQuery(); }
public static void EditarRopa(Ropa Ropita) { SqlConnection Conn = Conectar(); SqlCommand Consulta = Conn.CreateCommand(); Consulta.CommandType = System.Data.CommandType.Text; string SQL = "UPDATE Ropa SET "; SQL += "Nombre = '" + Ropita.Nombre + "', Foto='" + Ropita.Foto + "', " + "Descripcion= '" + Ropita.Descripcion + "', " + " Stock = " + Ropita.Stock + ", " + " Precio = '" + Ropita.Precio + "' WHERE IdRopa = " + Ropita.IdRopa; Consulta.CommandText = SQL; Consulta.ExecuteNonQuery(); }