Modificar y eliminar participantes
This commit is contained in:
193
Universidad/modificar_participante.aspx.cs
Normal file
193
Universidad/modificar_participante.aspx.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
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 modificar_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");
|
||||
}
|
||||
}
|
||||
protected void OnBuscarClick(object sender, EventArgs e)
|
||||
{
|
||||
Entities entities = new Entities();
|
||||
int id = 0;
|
||||
try
|
||||
{
|
||||
int.TryParse(id_box.Text, out id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
id_error.Text = "No se encontro un participante con el id entregado";
|
||||
ClearInput();
|
||||
form_panel.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var participante = (from p in entities.Participantes where p.id == id select p).SingleOrDefault();
|
||||
|
||||
if (participante == null)
|
||||
{
|
||||
id_error.Text = "No se encontro un participante con el id entregado";
|
||||
ClearInput();
|
||||
form_panel.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
id_error.Text = "";
|
||||
|
||||
var idUniversidad = (from c in entities.Carreras where c.id == participante.idCarrera select c.idUniversidad).SingleOrDefault();
|
||||
|
||||
nombre_box.Text = participante.nombre;
|
||||
inscripcion_box.Text = participante.fechaInscripcion.ToString("yyyy-MM-dd");
|
||||
pga_box.Text = participante.pga.ToString("0.##");
|
||||
universidad_select.SelectedValue = idUniversidad.ToString();
|
||||
IndexChangedUniversidad(sender, e);
|
||||
carrera_select.SelectedValue = participante.idCarrera.ToString();
|
||||
seminario_select.SelectedValue = participante.idSeminario.ToString();
|
||||
|
||||
form_panel.Visible = true;
|
||||
}
|
||||
|
||||
private void ClearInput()
|
||||
{
|
||||
nombre_box.Text = "";
|
||||
inscripcion_box.Text = "";
|
||||
pga_box.Text = "";
|
||||
universidad_select.SelectedIndex = 0;
|
||||
carrera_select.Items.Clear();
|
||||
seminario_select.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
protected void OnActualizarClick(object sender, EventArgs e)
|
||||
{
|
||||
Entities entities = new Entities();
|
||||
int id = 0;
|
||||
try { int.TryParse(id_box.Text, out id); }
|
||||
catch (Exception ex) { return; }
|
||||
|
||||
var participante = (from p in entities.Participantes where p.id == id select p).SingleOrDefault();
|
||||
if (participante == null) return;
|
||||
|
||||
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.SaveChanges();
|
||||
Response.Redirect("/index.aspx");
|
||||
}
|
||||
|
||||
protected void OnEliminarClick(object sender, EventArgs e)
|
||||
{
|
||||
Entities entities = new Entities();
|
||||
int id = 0;
|
||||
try { int.TryParse(id_box.Text, out id); }
|
||||
catch (Exception ex) { return; }
|
||||
|
||||
var participante = (from p in entities.Participantes where p.id == id select p).SingleOrDefault();
|
||||
if (participante == null) return;
|
||||
|
||||
entities.Participantes.Remove(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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user