private void aplicar_boton_Click(object sender, EventArgs e)
        {
            int i;
            funciones func = new funciones();
            stored_procedures stored_proc = new stored_procedures(); 
            //this.Visible = false;
            for (i = 0; i < (this.list_funcionalidades.Items.Count); i++)
            {
                
                this.list_funcionalidades.SelectedIndex = i;
                if (this.list_funcionalidades.GetItemChecked(i))
                {
                    //consulto si la func la tnia ya el Rol
                    //si la tnia la dejo sino la agrego
                    if (!func.check_func_activa(this.id_rol_a_mod, this.list_funcionalidades.SelectedValue.ToString()))
                    {
                        stored_proc.insert_funcxrol(this.rol_nomb_mod, Convert.ToInt16(this.list_funcionalidades.SelectedValue.ToString())); 
                    }
                }
                else
                {
                    //consulto si la func la tnia ya el usuario
                    //si la tnia la elimino
                    if (func.check_func_activa(this.id_rol_a_mod, this.list_funcionalidades.SelectedValue.ToString()))
                    {
                        stored_proc.delete_funcxrol(this.id_rol_a_mod, this.list_funcionalidades.SelectedValue.ToString());
                    }
                }

                
            }

            if(this.estado_comboBox.SelectedIndex ==-1) //Devuelve -1 si no se ha seleccionado ninguna opcion del combo
            {
                estado_actual_rol = func.get_estado_BD(id_rol_a_mod);
            }

            //this.Visible = true;
            //devuelve true si se realizaron cambios en el nombre o estado 
            if (func.check_cambio_nomb_est_rol(id_rol_a_mod, this.estado_actual_rol, this.rol_select_tbox.Text, this.rol_nomb_mod))
                stored_proc.update_rol(this.id_rol_a_mod, this.rol_select_tbox.Text, estado_actual_rol);

            MessageBox.Show("Actualización Exitosa", "Modificación  Rol", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
            
        }
Esempio n. 2
0
        private void butt_add_Click(object sender, EventArgs e)
        {
            bool error = false;

            if (this.name_rol.Text == "")
            {
                MessageBox.Show("Debe ingresar un nombre de Rol", "Alta de Rol", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = true;
            }

            if (this.list_funcionalidades.CheckedIndices.Count == 0)
            {
                MessageBox.Show("Debe seleccionar una funcionalidad", "Alta de Rol", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = true;
            }

            //controlamos que el nombre de rol ingresado NO este en la base de datos
            if (func.existe_nombre_rol(name_rol.Text) == true)
            {
                MessageBox.Show("Nombre de Rol existente en la Base de Datos", "Alta de Rol", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = true;
            }

            if (error)
            {
                this.limpiar();
                return;
            }

            procedure.insert_Rol(name_rol.Text);

            foreach (int indice_func in this.list_funcionalidades.CheckedIndices) //checkedIndices devuelve la coleccion de los indices activados
            {
                this.list_funcionalidades.SelectedIndex = indice_func;            //establecemos que el elemento seleccionado posee el indice marcado correspondiente
                //selectValue retorna el value_member del item seleccionado (seleccionado != tildado)
                //insertamos las funcionalidades del nuevo rol
                procedure.insert_funcxrol(name_rol.Text, Convert.ToInt16(this.list_funcionalidades.SelectedValue.ToString()));
            }
            MessageBox.Show("Rol Insertado Correctamente", "Alta de Rol", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.limpiar();
        }