protected void deletebutton_OnClick(object sender, EventArgs e) { int posi = Convert.ToInt32(Session["posicion"]); using (modeloOcupacional contexto = new modeloOcupacional()) { try { ///Borrar Nota de Alumno var vnotas = (from pnotas in contexto.NOTAS where pnotas.COD_ALU == codalu select pnotas).First(); contexto.NOTAS.Remove(vnotas); contexto.SaveChanges(); ///Borrar Alumno var valumno = (from pcurso in contexto.ALUMNOS where pcurso.COD_ALU == codalu select pcurso).First(); contexto.ALUMNOS.Remove(valumno); contexto.SaveChanges(); Response.Redirect("WebFormAlumnos.aspx"); } catch (Exception) { string mensaje = "Error al intentar borrar el registro "; ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('" + mensaje + "')", true); Session["nuevo"] = "0"; return; } } }
/// <summary> /// Evento del botón que graba un nuevo registro. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rec_OnClick(object sender, EventArgs e) { int posi = Convert.ToInt32(Session["posicion"]); using (modeloOcupacional contexto = new modeloOcupacional()) { //posi = contexto.CURSOS.Count() - 1; /// si encuentra codcur try { if (contexto.CURSOS.SingleOrDefault(x => x.COD_CUR == campocurso.Text) != null) { // Enlace a ese curso var x = contexto.CURSOS.SingleOrDefault(c => c.COD_CUR == campocurso.Text); x.DESCRIPCION = campodescripcion.Text.ToString(); x.HORAS = Convert.ToInt32(campohoras.Text); x.TUTOR = campotutor.Text.ToString(); contexto.SaveChanges(); } else { CURSOS graba = new CURSOS(); graba.COD_CUR = campocurso.Text.ToString(); graba.DESCRIPCION = campodescripcion.Text.ToString(); graba.HORAS = Convert.ToInt32(campohoras.Text); graba.TUTOR = campotutor.Text.ToString(); contexto.CURSOS.Add(graba); contexto.SaveChanges(); } /*var vcurso = * (from pcurso in contexto.CURSOS orderby pcurso.COD_CUR ascending select pcurso).Skip(posi) * .First();*/ } catch (Exception exception) { string mensaje = "Error al grabar "; ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('" + mensaje + "')", true); Session["nuevo"] = "0"; return; } } }
/// <summary> /// Botón borrar el registro actual. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Delete_OnClick(object sender, EventArgs e) { int posi = Convert.ToInt32(Session["posicion"]); using (modeloOcupacional contexto = new modeloOcupacional()) { try { var vcurso = (from pcurso in contexto.CURSOS where pcurso.COD_CUR == campocurso.Text select pcurso).First(); contexto.CURSOS.Remove(vcurso); contexto.SaveChanges(); campocurso.Text = ""; campodescripcion.Text = ""; campohoras.Text = ""; campotutor.Text = ""; } catch (Exception) { string mensaje = "Error al intentar borrar el registro "; ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('" + mensaje + "')", true); Session["nuevo"] = "0"; return; } } }
protected void savebutton_OnClick(object sender, EventArgs e) { //ALUMNOS grabaalAlumnos = new ALUMNOS(); //NOTAS grabaNotas = new NOTAS(); int posi = Convert.ToInt32(Session["posicion"]); using (modeloOcupacional contexto = new modeloOcupacional()) { try { ALUMNOS grabaalAlumnos = new ALUMNOS() { COD_ALU = campocodalu.Text, COD_CUR = comboboxcursos.SelectedValue.ToString(), DNI = campodni.Text, NOMBRE = camponombre.Text, APELLIDOS = campoapellido.Text }; contexto.ALUMNOS.Add(grabaalAlumnos); NOTAS grabaNotas = new NOTAS() { COD_ALU = grabaalAlumnos.COD_ALU, COD_CUR = grabaalAlumnos.COD_CUR, NOTA1 = Convert.ToInt32(camponota1.Text), NOTA2 = Convert.ToInt32(camponota2.Text), NOTA3 = Convert.ToInt32(camponota1.Text), MEDIA = (Convert.ToInt32(camponota1.Text) + Convert.ToInt32(camponota2.Text) + Convert.ToInt32(camponota3.Text)) / 3 }; contexto.NOTAS.Add(grabaNotas); contexto.SaveChanges(); } catch (Exception exception) { string mensaje = "Error al grabar "; ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('" + mensaje + "')", true); Session["nuevo"] = "0"; return; } } }
protected void acceptbutton_OnClick(object sender, EventArgs e) { using (modeloOcupacional contexto = new modeloOcupacional()) { foreach (var alu in contexto.ALUMNOS) { if (alu.COD_ALU == codalu) { alu.COD_ALU = alumno_codalu.Text; alu.COD_CUR = alumno_codcur.Text; alu.APELLIDOS = alumno_apellido.Text; alu.NOMBRE = alumno_nombre.Text; alu.DNI = alumno_dni.Text; } } contexto.SaveChanges(); } }
protected void deletebutton_OnClick(object sender, EventArgs e) { using (modeloOcupacional contexto = new modeloOcupacional()) { foreach (NOTAS nota in contexto.NOTAS) { if (nota.COD_ALU == campocodalu.Text) { nota.NOTA1 = 0; nota.NOTA2 = 0; nota.NOTA3 = 0; nota.MEDIA = 0; } } contexto.SaveChanges(); combobox1.SelectedIndex = 0; gridView2.Visible = false; } }
protected void savebutton_OnClick(object sender, EventArgs e) { using (modeloOcupacional contexto = new modeloOcupacional()) { foreach (NOTAS nota in contexto.NOTAS) { if (nota.COD_ALU == campocodalu.Text) { nota.NOTA1 = Convert.ToInt32(note1.Text); nota.NOTA2 = Convert.ToInt32(note2.Text); nota.NOTA3 = Convert.ToInt32(note3.Text); nota.MEDIA = ((Convert.ToInt32((note1.Text)) + Convert.ToInt32((note2.Text)) + Convert.ToInt32((note3.Text))) / 3); } } contexto.SaveChanges(); combobox1.SelectedIndex = 0; gridView2.Visible = false; gridView2.DataBind(); } }