public eJugador buscarJugador(string idJugador) { eJugador aux = null; try { SqlCommand cmd = new SqlCommand(string.Format("SELECT dni,nombre,partidosJugados,trofeosObtenidos,talla,peso,edad,posicionDeJuego FROM tabla_Jugadores WHERE dni='{0}'", idJugador), db.conectaDB()); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { aux = new eJugador(); aux.DNI = (string)reader["dni"]; aux.NombreCompleto = (string)reader["nombre"]; aux.partidosJugados = (int)reader["partidosJugados"]; aux.trofeosObtenidos = (int)reader["trofeosObtenidos"]; aux.talla = (decimal)reader["talla"]; aux.peso = (decimal)reader["peso"]; aux.edad = (int)reader["edad"]; aux.posicionDeJuego = (string)reader["posicionDeJuego"]; } reader.Close(); return(aux); } catch (SqlException ex) { return(null); } finally { db.desconectaDB(); } }
public List <eJugador> listarJugadores() { List <eJugador> listaJugadores = new List <eJugador>(); eJugador aux = null; try { SqlCommand cmd = new SqlCommand("SELECT dni,nombre,partidosJugados,trofeosObtenidos,talla,peso,edad,posicionDeJuego FROM tabla_Jugadores", db.conectaDB()); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { aux = new eJugador(); aux.DNI = (string)reader["dni"]; aux.NombreCompleto = (string)reader["nombre"]; aux.partidosJugados = (int)reader["partidosJugados"]; aux.trofeosObtenidos = (int)reader["trofeosObtenidos"]; aux.talla = (decimal)reader["talla"]; aux.peso = (decimal)reader["peso"]; aux.edad = (int)reader["edad"]; aux.posicionDeJuego = (string)reader["posicionDeJuego"]; listaJugadores.Add(aux); } reader.Close(); return(listaJugadores); } catch (SqlException ex) { return(null); } finally { db.desconectaDB(); } }
public string modificarJugador(eJugador Jugador, string idJugador) { try { SqlCommand cmd = new SqlCommand(string.Format("UPDATE tabla_Jugadores SET dni = '{0}', nombre = '{1}', partidosJugados = {2}, trofeosObtenidos = {3},talla = {4},peso = {5},edad = {6},posicionDeJuego = {7} WHERE dni = '{8}' ", Jugador.DNI, Jugador.NombreCompleto, Jugador.partidosJugados, Jugador.trofeosObtenidos, Jugador.talla, Jugador.peso, Jugador.edad, Jugador.posicionDeJuego, idJugador), db.conectaDB()); cmd.ExecuteNonQuery(); return("Jugador Modificado"); } catch (SqlException ex) { return(ex.Message); } finally { db.desconectaDB(); } }
public string insertarJugador(eJugador Jugador) { try { string insert = string.Format("INSERT INTO tabla_Jugadores (dni,nombre,partidosJugados,trofeosObtenidos,talla,peso,edad,posicionDeJuego) VALUES ('{0}','{1}',{2},{3},{4},{5},{6},'{7}')", Jugador.DNI, Jugador.NombreCompleto, Jugador.partidosJugados, Jugador.trofeosObtenidos, Jugador.talla, Jugador.peso, Jugador.edad, Jugador.posicionDeJuego); SqlCommand cmd = new SqlCommand(insert, db.conectaDB()); cmd.ExecuteNonQuery(); return("Jugador Registrado"); } catch (SqlException ex) { return(ex.Message); } finally { db.desconectaDB(); } }
public string modificarJugador(string nombre, string dni, int partidosJugados, int trofeosObtenidos, decimal talla, decimal peso, int edad, string posicionJuego, string idAModificar) { eJugador aux = new eJugador { NombreCompleto = nombre, DNI = dni, partidosJugados = partidosJugados, trofeosObtenidos = trofeosObtenidos, talla = talla, peso = peso, edad = edad, posicionDeJuego = posicionJuego }; return(jugador.modificarJugador(aux, idAModificar)); }
private void listBox1_DoubleClick(object sender, EventArgs e) { jugadorAux = nJugador.buscarJugador(listBox1.SelectedValue.ToString()); if (!jugadoresEquipo.Exists(delegate(eJugador jugador) { return(jugador.DNI == jugadorAux.DNI); })) { listView2.Items.Clear(); jugadoresEquipo.Add(jugadorAux); foreach (eJugador jugador in jugadoresEquipo) { item = new ListViewItem(); item = listView2.Items.Add(jugador.DNI); item.SubItems.Add(jugador.NombreCompleto); item.SubItems.Add(jugador.posicionDeJuego); } listBox1.SelectedIndex = -1; } else { MessageBox.Show("El jugador ya pertenece a un equipo"); } }
public string registrarJugador(string nombre, string dni, int partidosJugados, int trofeosObtenidos, decimal talla, decimal peso, int edad, string posicionJuego) { eJugador aux = new eJugador { NombreCompleto = nombre, DNI = dni, partidosJugados = partidosJugados, trofeosObtenidos = trofeosObtenidos, talla = talla, peso = peso, edad = edad, posicionDeJuego = posicionJuego }; if (jugador.buscarJugador(dni) == null) { return(jugador.insertarJugador(aux)); } else { return("El jugador ya existe"); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex != -1) { listView2.Items.Clear(); ListViewItem item; eJugador aux = null; foreach (eEquipo equipo in nEquipo.buscarEquipo(comboBox1.SelectedValue.ToString())) { item = new ListViewItem(); aux = new eJugador(); aux = nJugador.buscarJugador(equipo.idJugador); item = listView2.Items.Add(aux.DNI); item.SubItems.Add(aux.NombreCompleto); item.SubItems.Add(aux.partidosJugados.ToString()); item.SubItems.Add(aux.trofeosObtenidos.ToString()); item.SubItems.Add(aux.talla.ToString()); item.SubItems.Add(aux.peso.ToString()); item.SubItems.Add(aux.edad.ToString()); item.SubItems.Add(aux.posicionDeJuego); } } }