示例#1
0
        private void Nuevo_Click(object sender, EventArgs e)
        {
            RolDialog rolDialog = new RolDialog("", Enums.tipoDialog.nuevo);

            rolDialog.ShowDialog();

            if (rolDialog.dr == DialogResult.Cancel)
            {
                return;
            }

            String nuevaDescripcion = rolDialog.descripcion;

            DAO.connect();

            Rol rol = new Rol();

            rol.Descripcion = nuevaDescripcion;
            rol.Activo      = true;
            int affected = DAO.insert <Rol>(rol);

            DAO.closeConnection();

            this.rolTableAdapter.Fill(this.dataSetRol.Rol);
            rolDataGrid.DataSource = this.dataSetRol.Rol; // Vuelve a cargar los datos en la tabla
        }
示例#2
0
        private void Modificar_Click(object sender, EventArgs e)
        {
            if (this.rolDataGrid.SelectedRows.Count == 0)
            {
                MessageBox.Show("Debe elegir un rol a modificar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (this.rolDataGrid.SelectedRows.Count > 1)
            {
                MessageBox.Show("Solo puede elegir un rol a modificar a la vez", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            DataGridViewRow row = this.rolDataGrid.SelectedRows[0];

            int    id          = (int)row.Cells[0].Value;
            String descripcion = (String)row.Cells[1].Value;

            RolDialog rolDialog = new RolDialog(descripcion, Enums.tipoDialog.modificar);
            var       dr        = rolDialog.ShowDialog();

            if (rolDialog.dr == DialogResult.Cancel)
            {
                return;
            }

            String nuevaDescripcion = rolDialog.descripcion;

            DAO.connect();

            Rol rol = DAO.selectOne <Rol>(new[] { "id = " + id });

            rol.Descripcion = nuevaDescripcion;
            int affected = DAO.update <Rol>(rol);

            DAO.closeConnection();

            this.rolTableAdapter.Fill(this.dataSetRol.Rol);
            rolDataGrid.DataSource = this.dataSetRol.Rol; // Vuelve a cargar los datos en la tabla
        }