private void CargarUsuarios() { try { BLL.Tables.TBL_USUARIOS _usuarios = new BLL.Tables.TBL_USUARIOS(); _usuarios.OrderByParameter.Add(DAL.Tables.TBL_USUARIOS.ColumnEnum.NombreUsuario, DAL.SqlEnums.DirEnum.ASC); _usuarios.Items(); Entities.Tables.TBL_USUARIOS _itemSeleccion = new Entities.Tables.TBL_USUARIOS(); //Limpia el combo this.comboBoxUsuario.SuspendLayout(); this.comboBoxUsuario.DataSource = null; this.comboBoxUsuario.Items.Clear(); //Carga el item de Seleccion.- _itemSeleccion.NOMBREUSUARIO = "<Seleccione un Usuario>"; _itemSeleccion.ID_USUARIO = 0; _usuarios.Result.Insert(0, _itemSeleccion); //Carga el combo this.comboBoxUsuario.ValueMember = "Id_Usuario"; this.comboBoxUsuario.DisplayMember = "NombreUsuario"; this.comboBoxUsuario.DataSource = _usuarios.Result; this.comboBoxUsuario.SelectedValue = 0; this.comboBoxUsuario.ResumeLayout(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmdGrabarUsuario_Click(object sender, EventArgs e) { try { if (VerificaDatos()) { Entities.Tables.TBL_USUARIOS item_user = new Entities.Tables.TBL_USUARIOS(); if (this.TextClave.Text == string.Empty) { //ACTUALIZO DATOS, NO INCLUIDO LA CLAVE BLL.Procedures._TBL_USUARIOS_UPDATE_SIN_CLAVE update_user = new BLL.Procedures._TBL_USUARIOS_UPDATE_SIN_CLAVE(); item_user.ID_USUARIO = id_usuario; item_user.ID_PERFIL = (int)this.comboPerfil.SelectedValue; item_user.IDENTIFICADORUSUARIO = this.textUsuario.Text; item_user.NOMBREUSUARIO = this.textNombre.Text; item_user.INACTIVO = this.checkInactivo.Checked; item_user.SECTOR_ID = (int)this.comboBoxSector.SelectedValue; item_user.EMAIL = (this.textBoxMail.Text == string.Empty) ? null : this.textBoxMail.Text.ToString(); if (this.comboBoxEmpresa.SelectedIndex == 0) { item_user.EMPRESA = "AMBA"; } if (this.comboBoxEmpresa.SelectedIndex == 1) { item_user.EMPRESA = "EGES"; } if (this.comboBoxEmpresa.SelectedIndex == 2) { item_user.EMPRESA = "RSC"; } if (this.comboBoxEmpresa.SelectedIndex == 3) { item_user.EMPRESA = "GSC"; } update_user.UpdateUsuario(item_user.ID_USUARIO, item_user.ID_PERFIL, item_user.IDENTIFICADORUSUARIO, item_user.NOMBREUSUARIO, item_user.INACTIVO, item_user.SECTOR_ID, item_user.EMAIL, item_user.EMPRESA); MessageBox.Show("Usuario Actualizado correctamente", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } else // ACTUALIZA DATOS DEL USUARIO INCLUYENDO SU CLAVE { BLL.Tables.TBL_USUARIOS user = new BLL.Tables.TBL_USUARIOS(); Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); item_user.ID_USUARIO = id_usuario; item_user.ID_PERFIL = (int)this.comboPerfil.SelectedValue; item_user.CONTRASENIAUSUARIO = encripta.ENCRIPTAR(this.TextClave.Text).ToString(); item_user.IDENTIFICADORUSUARIO = this.textUsuario.Text; item_user.NOMBREUSUARIO = this.textNombre.Text; item_user.INACTIVO = this.checkInactivo.Checked; item_user.SECTOR_ID = (int)this.comboBoxSector.SelectedValue; item_user.EMAIL = (this.textBoxMail.Text == string.Empty) ? null : this.textBoxMail.Text.ToString(); if (this.comboBoxEmpresa.SelectedIndex == 0) { item_user.EMPRESA = "AMBA";//AMBAS EMPRESAS } if (this.comboBoxEmpresa.SelectedIndex == 1) { item_user.EMPRESA = "EGES"; } if (this.comboBoxEmpresa.SelectedIndex == 2) { item_user.EMPRESA = "RSC"; } if (this.comboBoxEmpresa.SelectedIndex == 3) { item_user.EMPRESA = "GSC"; } if (id_usuario == 0) { item_user = user.Add(item_user); MessageBox.Show("Se creó un nuevo usuario", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { user.Update(item_user); MessageBox.Show("Usuario Actualizado correctamente", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } } this.comboBoxEmpresa.SelectedIndex = 0; CargarUsuarios(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }