private void btnAceptar_Click(object sender, EventArgs e) { try { Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); SISTMEDEntities E = new SISTMEDEntities(); var clave = (from U in E.TBL_Usuarios where U.Id_Usuario == Clases.Usuario.UsuarioLogeado.id_usuario_Logeado select new { U.ContraseniaUsuario }).Single(); if (txtClaveActual.Text.Trim() != encripta.DESENCRIPTAR(clave.ContraseniaUsuario)) { MetroMessageBox.Show(this, "La clave ingresada como actual es incorrecta"); } else if (txtClaveNueva.Text.Trim() != txtClaveNueva2.Text.Trim()) { MetroMessageBox.Show(this, "Los campos de nueva clave deben ser iguales"); } else { E.Configuration.ValidateOnSaveEnabled = false; TBL_Usuarios U = new TBL_Usuarios { Id_Usuario = Clases.Usuario.UsuarioLogeado.id_usuario_Logeado, ContraseniaUsuario = encripta.ENCRIPTAR(txtClaveNueva.Text) }; E.TBL_Usuarios.Attach(U); E.Entry(U).Property(p => p.ContraseniaUsuario).IsModified = true; E.SaveChanges(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Guardar() { try { SISTMEDEntities E = new SISTMEDEntities(); TBL_Usuarios _item = new TBL_Usuarios(); Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); if (Convert.ToInt32(txtId.Text) != -1) //Si es -1 es porque es un ingreso nuevo { _item.Id_Usuario = Convert.ToInt32(txtId.Text); } _item.Id_Perfil = 1; _item.IdentificadorUsuario = txtUsuario.Text; _item.ContraseniaUsuario = encripta.ENCRIPTAR(txtClave.Text.ToString()); _item.NombreUsuario = txtDescripcion.Text; _item.Inactivo = chckInactivo.Checked; _item.Sector_id = Convert.ToInt32(cboPerfiles.SelectedValue); _item.Email = txtEmail.Text; _item.matricula = txtMatricula.Text; E.Entry(_item).State = (AlreadyExists(Convert.ToInt32(txtId.Text)) ? EntityState.Modified : EntityState.Added); E.SaveChanges(); MetroMessageBox.Show(this, "Se guardo correctamente"); TraeUsuarios(); LimpiarCampos(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dataGridViewUsuarios_CellClick(object sender, DataGridViewCellEventArgs e) { try { Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); txtUsuario.Text = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.USUARIO].Value.ToString(); txtClave.Text = encripta.DESENCRIPTAR(dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.CLAVE].Value.ToString()); txtDescripcion.Text = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.NOMBRE_USUARIO].Value.ToString(); txtMatricula.Text = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.MATRICULA].Value == null ? "": dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.MATRICULA].Value.ToString(); cboPerfiles.SelectedValue = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.SECTOR_ID].Value; txtId.Text = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.USUARIO_ID].Value.ToString(); chckInactivo.Checked = Convert.ToInt32(dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.USUARIO_ID].Value) == 1 ? true : false; txtEmail.Text = dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.EMAIL].Value == null ? "": dataGridViewUsuarios.CurrentRow.Cells[(int)Col_Usuario.EMAIL].Value.ToString(); } 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); } }
private void metroTile1_Click(object sender, EventArgs e) { try { if (cboSede.SelectedIndex == 0) { MessageBox.Show("Debe seleccionar una Sede", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { #region Usuario MenuSistema.Cls_Menus Menus = new MenuSistema.Cls_Menus(); Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); string ClaveUsu; ClaveUsu = encripta.ENCRIPTAR(txtContrasenia.Text.ToString()); foreach (Entities.Procedures._VALIDACREDENCIAL Creden in Menus.ValidarCredenciales(txtUsuario.Text, ClaveUsu)) { _idUsuario = Creden.idusuario; PerfilUsuario = Creden.perfil; _idSector = Creden.Sector_id; Clases.Usuario.UsuarioLogeado.Id_Sector = Creden.Sector_id; Clases.Usuario.UsuarioLogeado.id_usuario_Logeado = Creden.idusuario; } if (_idUsuario != 0) //SI ES CERO, NO EXISTE O LA CLAVE ES INCORRECTA, SINO TRAE EL ID DE USUARIO Y EL PERFIL AL QUE PERTENECE { IngresoCorrecto = true; //GUARDO EL USUARIO QUE ESTÁ LOGEADO Clases.Usuario.UsuarioLogeado.usuario_Logeado = txtUsuario.Text.ToString(); //TAMBIEN GUARDO LA EMPRESA LOGEADA ---- HECTOR Clases.Usuario.UsuarioLogeado.Id_sede = Convert.ToInt32(this.cboSede.SelectedValue); switch (Clases.Usuario.UsuarioLogeado.Id_sede) { case 1: Clases.Usuario.EmpresaLogeada.EmpresaIngresada = "EGES"; break; case 2: Clases.Usuario.EmpresaLogeada.EmpresaIngresada = "EGES"; break; case 3: Clases.Usuario.EmpresaLogeada.EmpresaIngresada = "RSC"; break; } this.Hide(); if (PerfilUsuario == 2) { Forms.MapaCama.Paciente.Ficha.Indicacion.Indicacion _FormInternacion = new Forms.MapaCama.Paciente.Ficha.Indicacion.Indicacion(); _FormInternacion.Show(); } if (PerfilUsuario == 1 || PerfilUsuario == 8) { Forms.MapaCama.MapaDeCamas _FormMapaCama = new Forms.MapaCama.MapaDeCamas(); int sede = Convert.ToInt32(this.cboSede.SelectedValue); switch (sede) { case 1: _FormMapaCama.sede = "Sede: VENEZUELA"; _FormMapaCama.sede_id = 1; _FormMapaCama.empresa = "EGSAC"; _FormMapaCama.empresa_id = 2; Clases.Paciente.PacienteSede = 1; break; case 2: _FormMapaCama.sede = "Sede: MEXICO"; _FormMapaCama.sede_id = 2; _FormMapaCama.empresa = "EGSAC"; _FormMapaCama.empresa_id = 2; Clases.Paciente.PacienteSede = 2; break; case 3: _FormMapaCama.sede = "Sede: CATAMARCA"; _FormMapaCama.sede_id = 3; _FormMapaCama.empresa = "RSC"; _FormMapaCama.empresa_id = 1; Clases.Paciente.PacienteSede = 3; break; } _FormMapaCama.Show(); } if (PerfilUsuario == 5) // USUARIO DE HOTELERIA { Forms.Internacion.Hoteleria.Hoteleria _FormHoteleria = new Forms.Internacion.Hoteleria.Hoteleria(); _FormHoteleria.Show(); } if (PerfilUsuario == 6) // USUARIO DE FACTURACION { Forms.Parametros.Configuraciones _Parametros = new Parametros.Configuraciones(); _Parametros.Show(); } if (PerfilUsuario == 9) // USUARIO DE LABORATORIO { Forms.MapaCama.Paciente.Ficha.Laboratorio.RecepcionMuestras _Laboratorio = new MapaCama.Paciente.Ficha.Laboratorio.RecepcionMuestras(); _Laboratorio.Show(); } if (PerfilUsuario == 11) // USUARIO DE TEST { //Forms.Farmacia.Farm_Principal _farma = new Farmacia.Farm_Principal(); //_farma.Show(); Forms.Facturacion.Factu_Pacientes _factu = new Facturacion.Factu_Pacientes(); _factu.Show(); } if (PerfilUsuario == 13) // USUARIO DE FARMACIA { Forms.Farmacia.Farm_Principal _farma = new Farmacia.Farm_Principal(); Clases.Usuario.UsuarioLogeado.Id_Sector = 13; _farma.Show(); //Forms.Facturacion.ResumenIM _factu = new Facturacion.ResumenIM(); //_factu.Show(); } } else { if (MessageBox.Show("El usuario o la contraseña no son válidos ó este usuario está inactivo", "Error de credenciales", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel) { Application.Exit(); } } #endregion } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Btn_Aceptar_Click(object sender, EventArgs e) { try { if (ValidarIngreso()) { MenuSistema.Cls_Menus Menus = new MenuSistema.Cls_Menus(); Seguridad.Encriptacion encripta = new Seguridad.Encriptacion(); string ClaveUsu; ClaveUsu = encripta.ENCRIPTAR(Txt_Contrasenia.Text.ToString()); foreach (Entities.Procedures._VALIDACREDENCIAL Creden in Menus.ValidarCredenciales(Txt_Usuario.Text, ClaveUsu)) { _idUsuario = Creden.idusuario; PerfilUsuario = Creden.perfil; _idSector = Creden.sector_id; Clases.Usuario.UsuarioLogeado.id_usuario_Logeado = Creden.idusuario; Clases.Usuario.UsuarioLogeado.Email = Creden.email.ToString(); Clases.Usuario.UsuarioLogeado.EmpresaAutorizada = Creden.empresa.ToString(); } if (_idUsuario != 0) //SI ES CERO, NO EXISTE O LA CLAVE ES INCORRECTA, SINO TRAE EL ID DE USUARIO Y EL PERFIL AL QUE PERTENECE { //VERIFICO SI ESTÁ HABILITADO A LA EMPRESA QUE SELECCIONO Clases.Usuario.EmpresaLogeada.EmpresaIngresada = comboBoxEmpresa.SelectedValue.ToString(); Clases.Usuario.EmpresaLogeada.NombreEmpresaIngresada = comboBoxEmpresa.Text.Trim(); if (Clases.Usuario.UsuarioLogeado.EmpresaAutorizada.ToString().Trim() != "AMBA")//QUIERE DECIR QUE SOLO ESTA AUTORIZADA A UNA EMPRESA { if (Clases.Usuario.EmpresaLogeada.EmpresaIngresada.ToString().Trim() != Clases.Usuario.UsuarioLogeado.EmpresaAutorizada.ToString().Trim()) { MessageBox.Show("Ud. no está autorizado a ingresar a la empresa: " + Clases.Usuario.EmpresaLogeada.EmpresaIngresada, "Error de credenciales", MessageBoxButtons.OK, MessageBoxIcon.Error); // Application.Exit(); return; } } IngresoCorrecto = true; //GUARDO EL USUARIO QUE ESTÁ LOGEADO Clases.Usuario.UsuarioLogeado.usuario_Logeado = Txt_Usuario.Text.ToString(); Clases.Usuario.UsuarioLogeado.Id_Sector = _idSector; // ********************* MUESTRO EVENTOS PARA ESTE USUARIO // Catalogos.Frm_Eventos _evento = new Catalogos.Frm_Eventos(); BLL.Procedures.EVENTOSUSUARIO _usuEvento = new BLL.Procedures.EVENTOSUSUARIO(); List <Entities.Procedures.EVENTOSUSUARIO> _listEvento = new List <Entities.Procedures.EVENTOSUSUARIO>(); if (_usuEvento.ItemList(_idUsuario).Count > 0) { //SOLO MUESTRO EVENTOS SI TIENE PENDIENTE DE VER _evento._listEvento = _usuEvento.ItemList(_idUsuario); //paso la coleccion alformulario _listEvento = _usuEvento.ItemList(_idUsuario); //GRABO ESTOS EVENTOS.. ASI NO LOS MUESTRA MAS .... BLL.Tables.EVENTOUSUARIO _newEvento = new BLL.Tables.EVENTOUSUARIO(); Entities.Tables.EVENTOUSUARIO _itemEv = new Entities.Tables.EVENTOUSUARIO(); foreach (Entities.Procedures.EVENTOSUSUARIO item in _listEvento) { _itemEv = new Entities.Tables.EVENTOUSUARIO(); _itemEv.EVENTO_ID = item.id; _itemEv.FECHA = Convert.ToDateTime(DateTime.Now.ToString()); //GUARDA CON LA HORA _itemEv.ID_USUARIO = _idUsuario; _newEvento.Add(_itemEv); // grabo } _evento.ShowDialog(); } // FIN MUESTRA Y GRABA EVENTOS **************************************************** this.Close(); } else { if (MessageBox.Show("El usuario o la contraseña no son válidos ó este usuario está inactivo", "Error de credenciales", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel) { Application.Exit(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // }