Exemplo n.º 1
0
        public List <DataRepository.PropiedadesRol> ConsultarRol(int id)
        {
            string     sqlConsultar = @"Select Rol, Descripcion from Usuario.Seguridad where IdSeguridad = @id";
            SqlCommand command      = conn.Comando(sqlConsultar);

            DataRepository.PropiedadesRol        rol     = new DataRepository.PropiedadesRol();
            List <DataRepository.PropiedadesRol> miLista = new List <DataRepository.PropiedadesRol>();

            miLista.Add(rol);
            try
            {
                conn.DbOpen();
                using (command)
                {
                    command.Parameters.Add("@id", SqlDbType.Int).Value = id;
                    command.ExecuteNonQuery();
                }
                SqlDataReader rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    rol.Rol         = (rdr.GetString(0));
                    rol.Descripcion = rdr.GetString(1);
                    miLista.Add(rol);
                }
                return(miLista);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.DbClose();
            }
        }
Exemplo n.º 2
0
        public bool ModificarRol(DataRepository.PropiedadesRol rol, int id)
        {
            string     sqlModificar = @"Update Usuario.Seguridad set Rol = @rol, Descripcion = @descripcion, FechaModificacion = @fechaModificacion, ModificadoPor = @modificadoPor Where IdSeguridad = @id";
            SqlCommand command      = conn.Comando(sqlModificar);

            try
            {
                conn.DbOpen();
                using (command)
                {
                    command.Parameters.Add("@id", SqlDbType.Int).Value                     = id;
                    command.Parameters.Add("@rol", SqlDbType.VarChar).Value                = rol.Rol;
                    command.Parameters.Add("@descripcion", SqlDbType.VarChar).Value        = rol.Descripcion;
                    command.Parameters.Add("@fechaModificacion", SqlDbType.DateTime).Value = DateTime.Now;
                    command.Parameters.Add("@modificadoPor", SqlDbType.Int).Value          = DataRepository.PropiedadesInicioSesion.IdUsuario;
                    command.ExecuteNonQuery();
                }
                return(true);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.DbClose();
            }
        }
Exemplo n.º 3
0
        public List <DataRepository.PropiedadesRol> ConsultarRoles()
        {
            string     sqlConsultar = @"Select IdSeguridad, Rol from Usuario.Seguridad";
            ComboBox   cbRoles      = new ComboBox();
            SqlCommand command2     = conn.Comando(sqlConsultar);

            DataRepository.PropiedadesRol        rol     = new DataRepository.PropiedadesRol();
            List <DataRepository.PropiedadesRol> miLista = new List <DataRepository.PropiedadesRol>();

            try
            {
                string g;
                conn.DbOpen();
                SqlDataReader rdr = command2.ExecuteReader();
                while (rdr.Read())
                {
                    rol             = new DataRepository.PropiedadesRol();
                    rol.IdSeguridad = rdr.GetInt32(0);
                    rol.Rol         = rdr.GetString(1);
                    miLista.Add(rol);
                }

                return(miLista);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.DbClose();
            }
        }
Exemplo n.º 4
0
        public bool InsertarRol(DataRepository.PropiedadesRol roles)
        {
            string sqlInsertar = @"Insert into Usuario.Seguridad (Rol, Descripcion, FechaCreacion, CreadoPor, FechaModificacion, ModificadoPor) values (@rol, @descripcion, @fechaCreacion, @creadoPor, @fechaModificacion, @modificadoPor)";

            SqlCommand command = conn.Comando(sqlInsertar);

            try
            {
                conn.DbOpen();
                using (command)
                {
                    command.Parameters.Add("@rol", SqlDbType.VarChar).Value                = roles.Rol;
                    command.Parameters.Add("@descripcion", SqlDbType.VarChar).Value        = roles.Descripcion;
                    command.Parameters.Add("@fechaCreacion", SqlDbType.DateTime).Value     = DateTime.Now;
                    command.Parameters.Add("@creadoPor", SqlDbType.Int).Value              = DataRepository.PropiedadesInicioSesion.IdUsuario;
                    command.Parameters.Add("@fechaModificacion", SqlDbType.DateTime).Value = DateTime.Now;
                    command.Parameters.Add("@modificadoPor", SqlDbType.Int).Value          = DataRepository.PropiedadesInicioSesion.IdUsuario;
                    command.ExecuteNonQuery();

                    MessageBox.Show("Se ha agregado exitosamente el rol");
                }
                return(true);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("No se puede ingresar este nuevo rol, ya que el nombre existe.");
                return(false);
            }
            finally
            {
                conn.DbClose();
            }
        }
Exemplo n.º 5
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text.Any() && txtDescripcion.Text.Any() && lstpermisos.Items.Count > 0)
            {
                DataRepository.PropiedadesRol PR = new DataRepository.PropiedadesRol();
                Services.OperacionesRoles     OR = new Services.OperacionesRoles();

                PR.Rol         = txtNombre.Text.ToString();
                PR.Descripcion = txtDescripcion.Text.ToString();
                OR.InsertarRol(PR);
                int id;
                id = OR.ObtenerIdRol(txtNombre.Text.ToString());
                foreach (var item in lstpermisos.Items)
                {
                    OR.AgregarPermisos(id, item.ToString());
                }
                chkselecionar.Text = "Seleccionar todo";
                txtNombre.Clear();
                txtDescripcion.Clear();
                chkselecionar.Checked = false;
                lstpermisos.Items.Clear();
                selecionarFalse();
                txtNombre.Focus();
            }
            else
            {
                MessageBox.Show("Debe de ingresar datos para poder guardar.");
                txtNombre.Focus();
            }
        }
Exemplo n.º 6
0
        private void PopularRol()
        {
            ComboBox cbP = new ComboBox();

            Services.OperacionesRoles     OR = new Services.OperacionesRoles();
            DataRepository.PropiedadesRol PR = new DataRepository.PropiedadesRol();
            cbRoles.DataSource    = OR.ConsultarRoles();
            cbRoles.DisplayMember = "Rol";
            cbRoles.ValueMember   = "IdSeguridad";
        }
Exemplo n.º 7
0
        private void btnModificar_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text.Any() && txtDescripcion.Text.Any() && lstpermisos.Items.Count > 0)
            {
                id = int.Parse(idSeguridad);
                DataRepository.PropiedadesRol PR = new DataRepository.PropiedadesRol();
                Services.OperacionesRoles     OR = new Services.OperacionesRoles();
                PR.Rol         = txtNombre.Text.ToString();
                PR.Descripcion = txtDescripcion.Text.ToString();
                OR.ModificarRol(PR, id);
                int id2;
                id2 = OR.ObtenerIdRol(txtNombre.Text.ToString());

                foreach (var item in OR.PopularLista(id2))
                {
                    OR.QuitarPermisos(id2, item.ToString());
                }
                foreach (var item in lstpermisos.Items)
                {
                    OR.AgregarPermisos(id2, item.ToString());
                }
                MessageBox.Show("Se ha actualizado exitosamente el rol.");
                chkselecionar.Text = "Seleccionar todo";
                cbRoles.DataSource = new List <string>();
                txtNombre.Clear();
                txtDescripcion.Clear();
                chkselecionar.Checked = false;
                lstpermisos.Items.Clear();
                selecionarFalse();
                txtNombre.Focus();
            }
            else
            {
                MessageBox.Show("Debe de ingresar datos para poder modificar.");
                txtNombre.Focus();
            }
        }