Exemple #1
0
        public static bool Modificar(Televisor tele)
        {
            SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);

            SqlCommand comando = new SqlCommand();

            comando.CommandType = CommandType.Text;
            comando.CommandText = "UPDATE dbo.Televisores SET marca='" + tele.marca + "', precio=" + tele.precio + ",pulgadas=" + tele.pulgadas + "," +
                                  "pais='" + tele.pais + "' WHERE codigo=" + tele.id + "";
            comando.Connection = conexion;

            try
            {
                conexion.Open();
                comando.ExecuteNonQuery();
                conexion.Close();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Exemple #2
0
        public static Televisor TraerUno(int id)
        {
            Televisor     t        = null;
            SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);

            conexion.Open();

            SqlCommand comando = new SqlCommand();

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT * FROM dbo.Televisores WHERE codigo=" + id + "";
            comando.Connection  = conexion;

            SqlDataReader reader = comando.ExecuteReader();

            //if (reader.HasRows)
            //{
            //  t = new Televisor(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4));
            //}
            while (reader.Read())
            {
                t = new Televisor(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4));
            }

            return(t);
        }
Exemple #3
0
        public static List <Televisor> TraerTodos()
        {
            List <Televisor> televisores = new List <Televisor>();

            SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);

            conexion.Open();

            SqlCommand comando = new SqlCommand();

            comando.CommandType = CommandType.Text;
            comando.CommandText = "SELECT * FROM dbo.Televisores";
            comando.Connection  = conexion;

            SqlDataReader reader = comando.ExecuteReader();


            while (reader.Read())
            {
                Televisor t = new Televisor(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4));
                televisores.Add(t);
            }

            return(televisores);
        }
        public static Televisor TraerUno(int id)
        {
            Televisor     retorno    = null;
            SqlConnection connection = new SqlConnection(Properties.Settings.Default.Conexion);
            SqlCommand    command    = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = String.Format("SELECT * FROM Televisores WHERE codigo = {0}", id);
            command.Connection  = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                retorno = new Televisor(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4));
            }
            connection.Close();
            return(retorno);
        }
        public static List <Televisor> TraerTodos()
        {
            List <Televisor> lista      = new List <Televisor>();
            SqlConnection    connection = new SqlConnection(Properties.Settings.Default.Conexion);
            SqlCommand       command    = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = "SELECT * FROM TELEVISORES";
            command.Connection  = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Televisor televisor = new Televisor(reader.GetInt32(0), reader.GetString(1), reader.GetDouble(2), reader.GetInt32(3), reader.GetString(4));
                lista.Add(televisor);
            }
            connection.Close();
            return(lista);
        }
        public static bool Borrar(Televisor televisor)
        {
            bool          retorno    = true;
            SqlConnection connection = new SqlConnection(Properties.Settings.Default.Conexion);
            SqlCommand    command    = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = String.Format("DELETE Televisores WHERE codigo = {0}", televisor.id);
            command.Connection  = connection;

            try
            {
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception)
            {
                retorno = false;
            }
            return(retorno);
        }
        public static bool Modificar(Televisor televisor)
        {
            bool          retorno    = true;
            SqlConnection connection = new SqlConnection(Properties.Settings.Default.Conexion);
            SqlCommand    command    = new SqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = String.Format("UPDATE Televisores SET marca = '{0}', precio = {1}, pulgadas = {2}, pais = '{3}' WHERE codigo = {4}", televisor.marca, televisor.precio, televisor.pulgadas, televisor.pais, televisor.id);
            command.Connection  = connection;

            try
            {
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception e)
            {
                retorno = false;
            }
            return(retorno);
        }
Exemple #8
0
        public static bool Borrar(Televisor tele)
        {
            SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);

            SqlCommand comando = new SqlCommand();

            comando.CommandType = CommandType.Text;
            comando.CommandText = "DELETE dbo.Televisores WHERE codigo=" + tele.id + "";
            comando.Connection  = conexion;

            try
            {
                conexion.Open();
                comando.ExecuteNonQuery();
                conexion.Close();
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }