NOTA Imprimir E-Mail
miércoles, 23 de abril de 2008
NOTA POLOP
MENU PRINCIPAL

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

 

namespace EquipoDeJugadores

{

public partial class MenuPrincipal : Form

{

private ENEquipo equipo;

public MenuPrincipal()

{

InitializeComponent();

}

private void salirToolStripMenuItem_Click( object sender, EventArgs e)

{

Application .Exit();

}

private void introducToolStripMenuItem_Click( object sender, EventArgs e)

{

Introducir_Datos f = new Introducir_Datos ();

f.ShowDialog();

}

private void consultarEquipoToolStripMenuItem_Click( object sender, EventArgs e)

{

ConsultarEquipo g = new ConsultarEquipo ();

g.ShowDialog();

}

private void acercaDeToolStripMenuItem_Click( object sender, EventArgs e)

{

MessageBox .Show( "Práctica realizada por Antonio José Fuster Marco, 48299468C" );

}

private void MenuPrincipal_Load( object sender, EventArgs e)

{

equipo = ENEquipo .obtenerENEquipo();

}

}

}

FORMULARIO INPUT_DATOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace EquipoDeJugadores

{

public partial class Introducir_Datos : Form

{

private ENEquipo equipo;

public Introducir_Datos()

{

InitializeComponent();

}

private void buttonAceptar_Click( object sender, EventArgs e)

{

bool insertar = true ;

ENJugador jugador;

jugador = new ENJugador ();

try

{

if (textBoxNombre.Text == "" )

{

throw new InvalidProgramException ();

insertar = false ;

}

else

{

jugador.Nombre = textBoxNombre.Text;

}

jugador.DNI = textBoxDNI.Text;

if ( Int32 .Parse(textBoxEdad.Text) < 0)

{

throw new IndexOutOfRangeException ();

insertar = false ;

}

else

{

jugador.Edad = Int32 .Parse(textBoxEdad.Text);

MessageBox .Show( "Los datos han sido introducidos correctamente." );

}

}

catch (System. InvalidProgramException ex)

{

MessageBox .Show( "Excepción: Error en el campo Nombre. No puede ser nulo." );

}

catch ( IndexOutOfRangeException ex)

{

MessageBox .Show( "Excepción: Error en el campo Edad, por favor introduzca un número entero mayor que cero." );

}

catch ( Exception ex)

{

MessageBox .Show( "Excepción: Error ha introducido un valor incorrecto. Por favor compruebe los datos introducidos." );

}

finally

{

if (insertar == true )

{

equipo.setJugador(jugador);

MessageBox .Show( "El jugador fue introducido" );

}

}

}

private void buttonCancelar_Click( object sender, EventArgs e)

{

Close();

}

private void Introducir_Datos_Load( object sender, EventArgs e)

{

equipo = ENEquipo .obtenerENEquipo();

}

}

}

FORMULARIO MOSTRAR_DATOS

namespace EquipoDeJugadores

{

public partial class ConsultarEquipo : Form

{

private ENEquipo equipo;

public ConsultarEquipo()

{

InitializeComponent();

}

private void buttonAceptar_Click( object sender, EventArgs e)

{

Close();

}

private void ConsultarEquipo_Load( object sender, EventArgs e)

{

try

{

equipo= ENEquipo .obtenerENEquipo();

if (equipo != null )

{

labelNum.Text = equipo.NumeroJugadores.ToString();

labelEdad.Text = equipo.EdadMedia.ToString();

dataGridViewConsulta.DataSource = equipo.Jugadores;

}

}

catch

{

MessageBox .Show( "Se produjo un error" );

}

}

}

}


EN_EQUIPO

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace EquipoDeJugadores

{

public sealed class ENEquipo

{

private ArrayList jugadores;
private int numeroJugadores;
private double edadMedia;
private static ENEquipo equipo= null ;

private ENEquipo()
{
jugadores = new ArrayList ();
numeroJugadores = 0;
edadMedia = 0;
}

public static ENEquipo obtenerENEquipo()
{
if (equipo == null )
{
equipo = new ENEquipo ();
}
return equipo;
}

public int NumeroJugadores

{

get { return numeroJugadores; }

set { numeroJugadores = value ; }

}

public double EdadMedia

{

get { return edadMedia; }

set { edadMedia = value ; }

}

public ArrayList Jugadores

{

get { return jugadores; }

set { jugadores = value ; }

}

public void setJugador( ENJugador jugador)

{

jugadores.Add(jugador);

numeroJugadores++;

edadMedia = ((edadMedia + jugador.Edad)/numeroJugadores);

}

}

}

EN_JUGADOR

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace EquipoDeJugadores

{

public class ENJugador

{

private string nombre;

private string dni;

private int edad;

public string Nombre
{
get { return nombre; }
set { nombre = value ; }
}

public string DNI

{

get { return dni; }

set { dni = value ; }

}

 

public int Edad

{

get { return edad; }

set { edad = value ; }

}

}

}

 

 
Siguiente >
© 2008 Marina Digital