public CargarRolForm(Rol rol)
        {
            InitializeComponent();

            List<Funcionalidad> funciones = Funcionalidad.getFunciones();
            foreach (Funcionalidad f in funciones)
            {
                this.checkedListBox1.Items.Insert(f.Id-1, f.Descripcion);
            }
            this.checkedListBox1.Refresh();

            if (rol != null)
            {
                this.rol = rol;
                this.checkBox1.Checked = rol.Activo;
                this.descripcion.Text = rol.Descripcion;
                List<Funcionalidad> funcionalidades = rol.buscarFuncionalidades(rol.Id);
                foreach (Funcionalidad f in funcionalidades)
                {
                    this.checkedListBox1.SetItemChecked(f.Id-1, true);
                }
            }
            else
            {
                this.checkBox1.Visible = false;
            }
        }
 private void modificar_Click(object sender, EventArgs e)
 {
     Rol rol = new Rol();
     rol.Id = Convert.ToInt32(data.Rows[data.CurrentRow.Index].Cells[0].Value);
     rol.Descripcion = Convert.ToString(data.Rows[data.CurrentRow.Index].Cells[1].Value);
     rol.Activo = Convert.ToBoolean(data.Rows[data.CurrentRow.Index].Cells[2].Value);
     new CargarRolForm(rol).ShowDialog();
     this.buscar_Click(this, null);
 }
Exemplo n.º 3
0
        public Rol buscarRol(int rolId)
        {
            Rol rol;
            this.rolTableAdapter.Fill(this.dataSet.Roles);
            if (this.dataSet.Roles.Select("rol_id='" + rolId + "'").Length != 0)
            {
                GD2C2015DataSet.RolesRow row = (GD2C2015DataSet.RolesRow)this.dataSet.Roles.Select("rol_id='" + rolId + "'").First();
                rol = new Rol();
                rol.Activo = row.rol_activo;
                rol.Descripcion = row.rol_descripcion;
                rol.Id = row.rol_id;

                return rol;
            }
            return null;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.valido())
            {

                if (rol != null)
                {
                    // update

                    this.rolesTableAdapter.Fill(this.dataSet.Roles);
                    GD2C2015DataSet.RolesRow[] result = (GD2C2015DataSet.RolesRow[])this.dataSet.Roles.Select("rol_descripcion='" + this.descripcion.Text + "' AND rol_id <> " + rol.Id);
                    if (result.Length > 0)
                    {
                        MessageBox.Show("Ya existe otro rol con esa descripción\n");
                        return;
                    }

                    this.rolesTableAdapter.rolModificar(this.descripcion.Text, this.checkBox1.Checked, this.rol.Id);
                    this.funcionesRolesTableAdapter.funcionesRolesBorrar(this.rol.Id);
                }
                else
                {
                    this.rolesTableAdapter.Fill(this.dataSet.Roles);
                    GD2C2015DataSet.RolesRow[] result = (GD2C2015DataSet.RolesRow[])this.dataSet.Roles.Select("rol_descripcion='" + this.descripcion.Text + "'");
                    if (result.Length > 0)
                    {
                        MessageBox.Show("Ya existe el rol con esa descripción\n");
                        return;
                    }

                    // insert
                    this.rol = new Rol();
                    this.rol.Id = Convert.ToInt32(this.rolesTableAdapter.rolInsertar(this.descripcion.Text));
                }

                foreach (object itemChecked in this.checkedListBox1.CheckedItems)
                {
                    int funcId = this.checkedListBox1.Items.IndexOf(itemChecked) + 1;
                    if (funcId != 0)
                    {
                        this.funcionesRolesTableAdapter.funcionesRolesInsertar(funcId, this.rol.Id);
                    }
                }
                this.rolesTableAdapter.Fill(this.dataSet.Roles);
                this.funcionesRolesTableAdapter.Fill(this.dataSet.Funciones_Roles);

                MessageBox.Show("El rol ha sido guardado correctamente");
                this.Close();
            }
            else
            {
                return;
            }
        }