/// <summary> /// prototipo: public ObservableCollection<ClsLuchador> ObtenerListadoLuchadoresDAL() /// comentarios: sirve para obtener el listado de los todos los luchadores /// precondiciones: no hay /// </summary> /// <returns>ObservableCollection<ClsLuchador> luchadores</returns> /// postcondiciones: asociado a nombre devuelve el listado de todos los luchadores o un null si no hay Luchadores o SQLException si no hay conexion public ObservableCollection <ClsLuchador> ObtenerListadoLuchadoresDAL() { ObservableCollection <ClsLuchador> luchadores = new ObservableCollection <ClsLuchador>(); ClsLuchador luchador = null; ClsMyConnection miConexion = null; SqlCommand miComando = new SqlCommand(); SqlConnection conexion = null; SqlDataReader miLector = null; miConexion = new ClsMyConnection(); try { conexion = miConexion.getConnection(); miComando.CommandText = "select * from SH_Luchadores"; miComando.Connection = conexion; miLector = miComando.ExecuteReader(); //Si hay lineas en el lector if (miLector.HasRows) { while (miLector.Read()) { luchador = new ClsLuchador(); luchador.IdLuchador = (int)miLector["idLuchador"]; if (!String.IsNullOrEmpty(miLector["nombreLuchador"].ToString())) { luchador.NombreLuchador = miLector["nombreLuchador"].ToString(); } luchador.FotoLuchador = (miLector["fotoLuchador"] is DBNull) ? new byte[1] : (Byte[])miLector["fotoLuchador"]; luchadores.Add(luchador); } } } catch (SqlException exSql) { throw exSql; } finally { if (conexion != null) { miConexion.closeConnection(ref conexion); } } return(luchadores); }
public ClsPuntuacionVM(ObservableCollection <ClsLuchador> listadoTodosLosLuchadores, ObservableCollection <ClsLuchador> listadoLuchadoresConLaImagenBitmapeada, int ratingLuchador1, int ratingLuchador2, ClsLuchador luchadorSeleccionado1, ClsLuchador luchadorSeleccionado2, string mensajeError, string colorError) { this.listadoTodosLosLuchadores = listadoTodosLosLuchadores; this.listadoLuchadoresConLaImagenBitmapeada = listadoLuchadoresConLaImagenBitmapeada; this.ratingLuchador1 = ratingLuchador1; this.ratingLuchador2 = ratingLuchador2; this.luchadorSeleccionado1 = luchadorSeleccionado1; this.luchadorSeleccionado2 = luchadorSeleccionado2; this.mensajeError = mensajeError; this.colorError = colorError; }
/// <summary> /// sirve para enviar los datos a la capa BL o mostrar mensaje de error /// </summary> private void enviar() { this.visibilidadProgressBar = "Visible"; NotifyPropertyChanged("VisibilidadProgressBar"); if (this.listadoTodosLosLuchadores != null) { if (this.luchadorSeleccionado1 == null || this.luchadorSeleccionado2 == null || this.ratingLuchador1 <= 0 || this.ratingLuchador2 <= 0) { this.colorError = "Yellow"; NotifyPropertyChanged("ColorError"); this.mensajeError = "Hay que seleccionar un luchador de cada lista y sus puntuaciones"; NotifyPropertyChanged("MensajeError"); this.visibilidadProgressBar = "Collapsed"; NotifyPropertyChanged("VisibilidadProgressBar"); } else if (this.luchadorSeleccionado1.IdLuchador == this.luchadorSeleccionado2.IdLuchador) { this.colorError = "Yellow"; NotifyPropertyChanged("ColorError"); this.mensajeError = "No puedo luchar conmigo mismo picha"; NotifyPropertyChanged("MensajeError"); this.visibilidadProgressBar = "Collapsed"; NotifyPropertyChanged("VisibilidadProgressBar"); } else { try { new ClsManejadoraCombatesBL().InsertarCombateOActualizarPuntuacionBL(this.luchadorSeleccionado1.IdLuchador, this.luchadorSeleccionado2.IdLuchador, this.ratingLuchador1, this.ratingLuchador2); this.colorError = "Chartreuse"; NotifyPropertyChanged("ColorError"); mensajeError = "Se ha guardado correctamente"; NotifyPropertyChanged("MensajeError"); this.visibilidadProgressBar = "Collapsed"; NotifyPropertyChanged("VisibilidadProgressBar"); } catch (Exception) { var dlg = new MessageDialog("Error de conexion. Intentalo más tarde por favor"); var res = dlg.ShowAsync(); } //this.visibilidadProgressBar = "Collapsed"; //NotifyPropertyChanged("VisibilidadProgressBar"); this.luchadorSeleccionado1 = null; //para que deseleccione el luchador seleccionado para poder seleccionarlo otra vez NotifyPropertyChanged("LuchadorSeleccionado1"); this.luchadorSeleccionado2 = null; NotifyPropertyChanged("LuchadorSeleccionado2"); this.ratingLuchador1 = (-1); NotifyPropertyChanged("RatingLuchador1"); this.ratingLuchador2 = (-1); NotifyPropertyChanged("RatingLuchador2"); } //this.visibilidadProgressBar = "Collapsed"; //NotifyPropertyChanged("VisibilidadProgressBar"); } }