private void btoCargar(object sender, RoutedEventArgs e) { try { int Nivel = -1; int Fuerza = -1; int Destreza = -1; int Constitucion = -1; int Inteligencia = -1; int Sabiduria = -1; int Carisma = -1; //Validacion de los valores ingresados if (string.IsNullOrEmpty(this.NombreTxt.Text)) { throw new Exception("Debe especificar un nombre para el personaje"); } if (!int.TryParse(this.NivelTxt.Text, out Nivel) && Nivel > 0 && Nivel < 10) { throw new Exception("El nivel especificado no es válido."); } if (!int.TryParse(this.FueTxt.Text, out Fuerza) && Fuerza > 0 && Fuerza < 10) { throw new Exception("El valor de Fuerza especificado no es válido."); } if (!int.TryParse(this.DesTXT.Text, out Destreza) && Destreza > 0 && Destreza < 10) { throw new Exception("El valor de Destreza especificado no es válido."); } if (!int.TryParse(this.ConstTxt.Text, out Constitucion) && Constitucion > 0 && Constitucion < 10) { throw new Exception("El valor de Constitución especificado no es válido."); } if (!int.TryParse(this.InteTxt.Text, out Inteligencia) && Inteligencia > 0 && Inteligencia < 10) { throw new Exception("El valor de Inteligencia especificado no es válido."); } if (!int.TryParse(this.SabTxt.Text, out Sabiduria) && Sabiduria > 0 && Sabiduria < 10) { throw new Exception("El valor de Sabiduria especificado no es válido."); } if (!int.TryParse(this.CarTxt.Text, out Carisma) && Carisma > 0 && Carisma < 10) { throw new Exception("El valor de Carisma especificado no es válido."); } if (r == null) { throw new Exception("Debe Seleccionar una Raza al Personaje"); } if (c == null) { throw new Exception("Debe Seleccionar una Clase al Personaje"); } // Asignación de datos al personaje p.Nombre = NombreTxt.Text; p.Nivel = Nivel; p.Fuerza = Fuerza; p.Destreza = Destreza; p.Constitucion = Constitucion; p.Inteligencia = Inteligencia; p.Sabiduria = Sabiduria; p.Carisma = Carisma; p.Imagen = imagen; //Alta del Personaje if (p.Id == 0) { int newPersonaje = PersonajeBL.Crear(p, c, r); if (newPersonaje > 0) { SetClientMessage("Personaje agregado correctamente!", TipoMensaje.Correcto); this.NavigationService.Navigate(new PerCaracteristica()); } } else { PersonajeBL.Modificar(p, c, r); this.NavigationService.Navigate(new ListaPersonaje()); } } catch (Exception ex) { SetClientMessage(ex.Message, TipoMensaje.Error); } }