/// <summary> /// Método para guardar los valores del contexto /// </summary> private void Guardar() { bool guardar = ValidaGuardar(); if (guardar) { try { var nivelAlertaPL = new NivelAlertaPL(); nivelAlertaPL.Guardar(Contexto); SkMessageBox.Show(this, Properties.Resources.GuardadoConExitoNivelAlerta, MessageBoxButton.OK, MessageImage.Correct); confirmaSalir = false; // valido si el id es diferente de 0 cuando se edita el nivel para que se cierrre la ventana. if (Contexto.NivelAlertaId != 0) { Close(); } txtDescripcion.Clear(); txtDescripcion.Focus(); } catch (ExcepcionGenerica) { SkMessageBox.Show(this, Properties.Resources.NivelAlerta_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error); } catch (Exception ex) { Logger.Error(ex); SkMessageBox.Show(this, Properties.Resources.NivelAlerta_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error); } } }
/// <summary> /// Obtiene lista de nivel de alerta /// </summary> /// <param name="inicio"></param> /// <param name="limite"></param> private void ObtenerListaNivelAlerta(int inicio, int limite) { try { if (ucPaginacion.ContextoAnterior != null) { bool contextosIguales = ucPaginacion.CompararObjetos(Contexto, ucPaginacion.ContextoAnterior); if (!contextosIguales) { ucPaginacion.Inicio = 1; inicio = 1; } } // se crean los filtros para le paginado para posterior mandar llamar el SP. var nivelAlertaPL = new NivelAlertaPL(); NivelAlertaInfo filtros = ObtenerFiltros(); var pagina = new PaginacionInfo { Inicio = inicio, Limite = limite }; ResultadoInfo <NivelAlertaInfo> resultadoInfo = nivelAlertaPL.ObtenerPorPagina(pagina, filtros); if (resultadoInfo != null && resultadoInfo.Lista != null && resultadoInfo.Lista.Count > 0) { gridDatos.ItemsSource = resultadoInfo.Lista; ucPaginacion.TotalRegistros = resultadoInfo.TotalRegistros; } else { ucPaginacion.TotalRegistros = 0; gridDatos.ItemsSource = new List <NivelAlerta>(); } } catch (ExcepcionGenerica) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.NivelAlerta_ErrorBuscar, MessageBoxButton.OK, MessageImage.Error); } catch (Exception ex) { Logger.Error(ex); SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.NivelAlerta_ErrorBuscar, MessageBoxButton.OK, MessageImage.Error); } }
//Metodo de validar al guardar el nivel de alerta. private bool ValidaGuardar() { bool resultado = true; string mensaje = string.Empty; try { // si esta en blanco manda un mensaje que es requerido el campo descripcion. if (string.IsNullOrWhiteSpace(Contexto.Descripcion) && txtDescripcion.Text.Trim() == string.Empty) { resultado = false; mensaje = Properties.Resources.NivelAlertaEdicion_MsgDescripcionRequerida; txtDescripcion.Focus(); } else if (cmbActivo.SelectedItem == null) { resultado = false; mensaje = Properties.Resources.NivelAlertaEdicion_MsgActivoRequerida; cmbActivo.Focus(); } else { // se realiza la busqueda por descripcion para no editar y asignarle una descripcion igual a una ya existente. int NivelAlertaID = Contexto.NivelAlertaId; var NivelAlertaPL = new NivelAlertaPL(); NivelAlertaInfo NivelALerta = NivelAlertaPL.ObtenerPorDescripcion(Contexto.Descripcion.Trim()); //Obtiene un contador de los niveles que se encuentran deshabilitados int nivelesAlertaDesactivados = NivelAlertaPL.NivelesAlertaDesactivados(); //validacion si la descripcion del nivel registrado ya existe if (NivelALerta != null && (NivelAlertaID == 0 || NivelAlertaID != NivelALerta.NivelAlertaId)) { resultado = false; mensaje = string.Format(Properties.Resources.NivelAlertaEdicion_MsgDescripcionExistente, NivelALerta.NivelAlertaId); } //validacion para cuando se crea un nuevo registro activo pero hay un registro previo desactivado else if (nivelesAlertaDesactivados > 0 && Contexto.Activo == EstatusEnum.Activo && Contexto.NivelAlertaId == 0) { resultado = false; mensaje = string.Format(Properties.Resources.NivelAlertaCreacion_MsgInactivos); } //validacion para cuando editas un nivel alerta else if (Contexto.Activo == EstatusEnum.Inactivo && Contexto.NivelAlertaId != 0) { //validacion para cuando editas un nivel alerta pero solo modificas su descripcion //(AuxInactivo guarda en valor original en cuanto se cargan los datos del nivel a editar if (AuxInactivo != Contexto.Activo) { int verificarAsignacionNivelAlerta = NivelAlertaPL.VerificarAsignacionNivelAlerta(NivelAlertaID); //verifica si el nivel seleccionado no a sido asignado if (verificarAsignacionNivelAlerta > 0) { resultado = false; mensaje = string.Format(Properties.Resources.NivelAlertaEdicion_MsgAsignado); } } } //validacion cuando un inactivo quiere pasar a activo... else if (AuxInactivo != EstatusEnum.Activo && Contexto.NivelAlertaId != 0) { int habilitarPrimerRegistro = NivelAlertaPL.NivelAlerta_ActivarPrimerNivelDesactivado(NivelAlertaID); //Si regresa 0 no es el primero deshabilitado si regresa > 0 es el primero deshabilitado if (habilitarPrimerRegistro == 0) { resultado = false; mensaje = string.Format(Properties.Resources.NivelAlertaActivacion_MsgActivar); } } } } catch (Exception ex) { throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } if (!string.IsNullOrWhiteSpace(mensaje)) { SkMessageBox.Show(this, mensaje, MessageBoxButton.OK, MessageImage.Warning); } return(resultado); }