/// <summary> /// Evento al pulsar Asignar: /// Se envia al cliente http el id del alumno y el id del curso /// que va a cursar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonAssign_Click(object sender, EventArgs e) { if (this.dgvCourses.SelectedRows[0].Cells[0].Value != null) { try { int id = (int)this.dgvCourses.SelectedRows[0].Cells[0].Value; //El cliente http retornado un objeto alumno con el curso actualizado Student student = await StudentHttpService .AssignCourse(_student.Id, id); //Ventanita con mensaje de exito string message = string .Format("El alumno {0} cursará {1}º de {2} y " + "todas las asignaturas del curso por defecto.", student.FullName, student.Course.Year, student.Course.Cycle.Name); new CustomSuccesMessageWindow(message).ShowDialog(); this.Close(); this.OnAssignCourseDelegate(student); } catch (ServerErrorException ex) { new CustomErrorMessageWindow(ex.Message).ShowDialog(); } } else { new CustomErrorMessageWindow("Debes seleccionar un curso antes.") .ShowDialog(); } }
/// <summary> /// Evento al pulsar Guardar: /// Se envia al cliente http un objeto alumno /// con los nuevos datos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonCreateTeacher_Click(object sender, EventArgs e) { this.ResetAsterisks(); string dni = this.tbDni.Text.TrimStart(' ').TrimEnd(' '); string firstName = this.tbFirstName.Text.TrimStart(' ').TrimEnd(' '); string lastName1 = this.tbLastName1.Text.TrimStart(' ').TrimEnd(' '); string lastName2 = this.tbLastName2.Text.TrimStart(' ').TrimEnd(' '); //Si los 3 campos obligatorios tienen texto, se crea el objeto if (dni.Length > 0 && firstName.Length > 0 && lastName1.Length > 0) { Student student = new Student() { Id = _student.Id, Dni = dni, FirstName = firstName, LastName1 = lastName1, LastName2 = lastName2 }; try { student = await StudentHttpService.Update(student); //Ventanita con mensaje de éxito string message = string .Format("Has actualizado los datos personales del alumno {0}.", student.FullName); new CustomSuccesMessageWindow(message).ShowDialog(); this.Close(); this.OnStudentUpdatedDelegate(student); } catch (ServerErrorException ex) { new CustomErrorMessageWindow(ex.Message).ShowDialog(); } } //Se cambia el color del asteriscos de los campos obligatorios vacios if (dni.Length == 0) { this.lblDniAsterisk.ForeColor = Settings.Default.OPTIMA_COLOR; } if (firstName.Length == 0) { this.lblFirstNameAsterisk.ForeColor = Settings.Default.OPTIMA_COLOR; } if (lastName1.Length == 0) { this.lblLastNameAsterisk.ForeColor = Settings.Default.OPTIMA_COLOR; } }
/// <summary> /// Obtiene del cliente http, una página de 8 alumnos cuyo primer /// apellido empieze por la cadena introducida por paramentro /// </summary> /// <param name="firstname"></param> /// <returns></returns> private async Task GetAllByPageAndName() { try { students = await StudentHttpService .GetByPageAndLasttName(this.lastName, this.currentPage); } catch (ServerErrorException ex) { new CustomErrorMessageWindow(ex.Message).ShowDialog(); } }
/// <summary> /// Evento al pulsar Retirar asignación: /// Se envia al cliente http el id del alumno para retirar /// el curso que tiene asignado /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonRemoveAssignedCourse_Click(object sender, EventArgs e) { if (this.dgvCourses.SelectedRows[0].Cells[0].Value != null) { //Si el alumno ya tiene un curso asignado if (this._student.Course != null) { try { await StudentHttpService.RemoveCourse(_student.Id); //Ventanita con mensaje de exito string message = string .Format("El alumno {0} ya no cursará {1}ª de {2}.", this._student.FullName, this._student.Course.Year, this._student.Course.Cycle.Name); new CustomSuccesMessageWindow(message).ShowDialog(); this.Close(); this.OnRemovedCourseDelegate(); } catch (ServerErrorException ex) { new CustomErrorMessageWindow(ex.Message).ShowDialog(); } } else { string message = string.Format("El alumno {0} no tiene curso asignado.", this._student.FullName); new CustomErrorMessageWindow(message).ShowDialog(); } } else { new CustomErrorMessageWindow("Debes seleccionar un curso antes.") .ShowDialog(); } }
/// <summary> /// Evento al pulsar Guardar: /// Envia al cliente http el id del alumno, y los ids de cada /// asignaturas que va a cursar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonSave_Click(object sender, EventArgs e) { if (this.clbSubjects.Items.Count > 0) { //Lista de ids de asignaturas List <int> subjectIds = new List <int>(); //Recorre las asignaturas marcadas y agrega su id a la lista foreach (object itemChecked in this.clbSubjects.CheckedItems) { //Recupero el Id de la asignatura comparando el nombre int id = subjects .Where(s => s.Name == itemChecked.ToString()) .Select(s => s.Id) .FirstOrDefault(); subjectIds.Add(id); } try { //El cliente http retorna un alumno actualizado Student student = await StudentHttpService .AssignSubjects(_student.Id, subjectIds.ToArray()); string message = string .Format("Has actualizado las asignaturas cursadas por el alumno {0}", _student.FullName); new CustomSuccesMessageWindow(message).ShowDialog(); this.Close(); this.OnAssignedSubjectsDelegate(student);//Respuesta } catch (ServerErrorException ex) { new CustomErrorMessageWindow(ex.Message).ShowDialog(); } } }