Esempio n. 1
0
        public static List <Cargo> ObtenerTodos()
        {
            string consulta = "SELECT TOP 500 c.Id, c.IdEstado, c.Nombre FROM Cargo c";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            SqlDataReader reader = ComunDB.EjecutarComandoReader(comando);

            List <Cargo> ListaCargos = new List <Cargo>();

            while (reader.Read())
            {
                Cargo cargo = new Cargo();

                cargo.Id       = reader.GetByte(0);
                cargo.IdEstado = reader.GetByte(1);
                cargo.Nombre   = reader.GetString(2);

                ListaCargos.Add(cargo);
            }

            return(ListaCargos);
        }
Esempio n. 2
0
        public static List <Cargo> Buscar(Cargo pCargo)
        {
            string consulta      = "SELECT TOP 500 c.Id, c.IdEstado, c.Nombre FROM Cargo c";
            string wheresql      = " "; // agrega condiciones a las consultas segun los campos buscados
            byte   contadoCampos = 0;   // sirve para saber si agregar AND a la consulta

            SqlCommand comando = ComunDB.ObtenerComando();

            // agregar condiciones a la consulta para obtener los registros filtrados por los campos de busueda
            if (pCargo.IdEstado > 0)    // verificar que la propiedad IdEstado tenga informacion que buscar
            {
                if (contadoCampos > 0)
                {
                    wheresql += " AND "; //SELECT TOP 500 c.Id, c.IdEstado, c.Nombre FROM Cargo c WHERE IdEstado=@IdEstado
                }

                contadoCampos++;
                wheresql += " IdEstado = @IdEstado";
                comando.Parameters.AddWithValue("@IdEstado", pCargo.IdEstado);
            }

            if (pCargo.Nombre != null && pCargo.Nombre.Trim().Length > 0)  //verificar que nombre tenga informacion para buscar
            {
                if (contadoCampos > 0)
                {
                    wheresql += " AND "; //SELECT TOP 500 c.Id, c.IdEstado, c.Nombre FROM Cargo c WHERE IdEstado=@IdEstado AND Nombre LIKE Nombre
                }
                contadoCampos++;
                wheresql += " Nombre LIKE @Nombre ";
                comando.Parameters.AddWithValue("@Nombre", '%' + pCargo.Nombre + '%');
            }

            if (wheresql.Trim().Length > 0)      // verificar si hay texto
            {
                wheresql = " WHERE " + wheresql; //
            }

            comando.CommandText = consulta + wheresql;

            SqlDataReader reader      = ComunDB.EjecutarComandoReader(comando);
            List <Cargo>  ListaCargos = new List <Cargo>();

            while (reader.Read())
            {
                Cargo cargo = new Cargo();

                cargo.Id       = reader.GetByte(0);
                cargo.IdEstado = reader.GetByte(1);
                cargo.Nombre   = reader.GetString(2);

                ListaCargos.Add(cargo);
            }

            comando.Connection.Dispose();

            return(ListaCargos);
        }
Esempio n. 3
0
        public static int Eliminar(Estado pEstado)
        {
            string consulta = "DELETE FROM Estado WHERE Id=@Id";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            comando.Parameters.AddWithValue("@Id", pEstado.Id);

            return(ComunDB.EjecutarComando(comando));
        }
Esempio n. 4
0
        public static int Guardar(Estado pEstado)
        {
            string consulta = "INSERT INTO Estado(Nombre) VALUES(@Nombre)";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            comando.Parameters.AddWithValue("@Nombre", pEstado.Nombre);

            return(ComunDB.EjecutarComando(comando));
        }
Esempio n. 5
0
        public static int Modificar(Estado pEstado)
        {
            string consulta = @"UPDATE Estado SET Nombre=@Nombre WHERE Id=@Id";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            comando.Parameters.AddWithValue("@Nombre", pEstado.Nombre);
            comando.Parameters.AddWithValue("@Id", pEstado.Id);

            return(ComunDB.EjecutarComando(comando));
        }
Esempio n. 6
0
        public static Estado ObtenerPorId(byte pId)
        {
            string consulta = "SELECT e.Id, e.Nombre FROM Estado e WHERE Id=@Id";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            comando.Parameters.AddWithValue("@Id", pId);

            SqlDataReader reader = ComunDB.EjecutarComandoReader(comando);

            Estado estado = new Estado();

            while (reader.Read())
            {
                estado.Id     = reader.GetByte(0);
                estado.Nombre = reader.GetString(1);
            }

            return(estado);
        }
Esempio n. 7
0
        public static Cargo ObtenerPorId(byte pId)
        {
            string consulta = "SELECT c.Id, C.IdEstado, c.Nombre FROM Cargo c WHERE c.Id=@Id";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;
            comando.Parameters.AddWithValue("@Id", pId);

            SqlDataReader reader = ComunDB.EjecutarComandoReader(comando);

            Cargo cargo = new Cargo();

            while (reader.Read())
            {
                cargo.Id       = reader.GetByte(0);
                cargo.IdEstado = reader.GetByte(1);
                cargo.Nombre   = reader.GetString(2);
            }

            return(cargo);
        }
Esempio n. 8
0
        public static List <Estado> ObtenerTodos()
        {
            string consulta = "SELECT TOP 500 e.Id, e.Nombre FROM Estado e";

            SqlCommand comando = ComunDB.ObtenerComando();

            comando.CommandText = consulta;

            SqlDataReader reader = ComunDB.EjecutarComandoReader(comando);

            List <Estado> ListaEstados = new List <Estado>();

            while (reader.Read())
            {
                Estado estado = new Estado();

                estado.Id     = reader.GetByte(0);
                estado.Nombre = reader.GetString(1);

                ListaEstados.Add(estado);
            }

            return(ListaEstados);
        }