128 lines
4.0 KiB
C#
128 lines
4.0 KiB
C#
using DAL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
public partial class registrar_participante : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
FillUniversidades();
|
|
FillSeminarios();
|
|
inscripcion_box.Text = DateTime.Today.ToString("yyyy-MM-dd");
|
|
}
|
|
}
|
|
|
|
private void FillUniversidades()
|
|
{
|
|
Entities entities = new Entities();
|
|
var universidades = from u in entities.Universidades select u;
|
|
universidad_select.DataSource = universidades.ToList();
|
|
universidad_select.DataTextField = "nombre";
|
|
universidad_select.DataValueField = "id";
|
|
universidad_select.DataBind();
|
|
universidad_select.Items.Insert(0, "Seleccione una Universidad");
|
|
}
|
|
|
|
private void FillSeminarios()
|
|
{
|
|
Entities entities = new Entities();
|
|
var seminarios = from s in entities.Seminarios select s;
|
|
seminario_select.DataSource = seminarios.ToList();
|
|
seminario_select.DataTextField = "nombre";
|
|
seminario_select.DataValueField = "id";
|
|
seminario_select.DataBind();
|
|
seminario_select.Items.Insert(0, "Seleccione un Seminario");
|
|
}
|
|
|
|
protected void IndexChangedUniversidad(object sender, EventArgs e)
|
|
{
|
|
if (universidad_select.SelectedIndex > 0)
|
|
{
|
|
var id = int.Parse(universidad_select.SelectedValue);
|
|
Entities entities = new Entities();
|
|
var carreras = from c in entities.Carreras where c.idUniversidad == id select c;
|
|
carrera_select.DataSource = carreras.ToList();
|
|
carrera_select.DataTextField = "nombre";
|
|
carrera_select.DataValueField = "id";
|
|
carrera_select.DataBind();
|
|
carrera_select.Items.Insert(0, "Seleccione una Carrera");
|
|
}
|
|
else
|
|
{
|
|
carrera_select.Items.Clear();
|
|
}
|
|
}
|
|
|
|
protected void OnRegistrarClick(object sender, EventArgs e)
|
|
{
|
|
if(Page.IsValid)
|
|
{
|
|
Entities entities = new Entities();
|
|
Participante participante = new Participante();
|
|
participante.nombre = nombre_box.Text;
|
|
participante.fechaInscripcion = DateTime.Parse(inscripcion_box.Text);
|
|
participante.pga = double.Parse(pga_box.Text);
|
|
participante.idCarrera = int.Parse(carrera_select.SelectedValue);
|
|
participante.idSeminario = int.Parse(seminario_select.SelectedValue);
|
|
entities.Participantes.Add(participante);
|
|
entities.SaveChanges();
|
|
|
|
Response.Redirect("/index.aspx");
|
|
}
|
|
}
|
|
|
|
protected void ValidateNombre(object source, ServerValidateEventArgs args)
|
|
{
|
|
if (nombre_box.Text.Trim().Length > 80)
|
|
{
|
|
args.IsValid = false;
|
|
nombre_validator.Text = "El nombre es muy largo, maximo de 80 caracteres";
|
|
return;
|
|
}
|
|
|
|
args.IsValid = true;
|
|
}
|
|
|
|
protected void ValidateUniversidad(object source, ServerValidateEventArgs args)
|
|
{
|
|
if (universidad_select.SelectedIndex == 0)
|
|
{
|
|
args.IsValid = false;
|
|
universidad_validator.Text = "Porfavor seleccionar una universidad";
|
|
return;
|
|
}
|
|
|
|
args.IsValid = true;
|
|
}
|
|
|
|
protected void ValidateCarrera(object source, ServerValidateEventArgs args)
|
|
{
|
|
if (carrera_select.SelectedIndex == 0)
|
|
{
|
|
args.IsValid = false;
|
|
carrera_validator.Text = "Porfavor seleccionar una carrera";
|
|
return;
|
|
}
|
|
|
|
args.IsValid = true;
|
|
}
|
|
|
|
protected void ValidateSeminario(object source, ServerValidateEventArgs args)
|
|
{
|
|
if (seminario_select.SelectedIndex == 0)
|
|
{
|
|
args.IsValid = false;
|
|
seminario_validator.Text = "Porfavor seleccionar un seminario";
|
|
return;
|
|
}
|
|
|
|
args.IsValid = true;
|
|
}
|
|
|
|
} |