private void btnAddIncident_Click(object sender, EventArgs e) { String givenName = tBStudentGN.Text; String sureName = tBStudentSN.Text; Student currentStudent; Class currentClass; Teacher currentTeacher; try { currentStudent = UtilityDB.getStudent(givenName, sureName); currentClass = UtilityDB.getClass(currentStudent.class_ID); currentTeacher = UtilityDB.getTeacher(currentClass.teacher_ID); } catch (Exception) { // Fehlerhafte Eingabe. currentTeacher = new Teacher(0, "", "nicht", "gefunden", "nope"); currentClass = new Class(0, 0, "nicht gefunden"); } lBClassFilled.Text = currentClass.className; lbTeacherFilled.Text = currentTeacher.givenName + " " + currentTeacher.surname; }
/// <summary> /// Gets a teacher object by className. /// </summary> /// <param name="className">The name of the class.</param> /// <returns>Returns a teacher object or null</returns> public static Teacher getClassTeacher(String className) { try { Class c = getClass(className); openconnection(); cmd = new OleDbCommand("SELECT * FROM Teacher WHERE Teacher_ID = " + c.teacher_ID, connection); dr = cmd.ExecuteReader(); dr.Read(); String title = dr[1].ToString(); String givenName = dr[2].ToString(); String surname = dr[3].ToString(); String initials = dr[4].ToString(); Teacher t = new Teacher(c.teacher_ID, title, givenName, surname, initials); closeconnection(); return t; } catch { return null; } }
/// <summary> /// Gets a teacher objectby the full name. /// </summary> /// <param name="givenName">The given Name of the teacher.</param> /// <param name="surname">The Surname of the teacher.</param> /// <returns>Returns a teacher object or null</returns> public static Teacher getTeacher(String givenName, String surname) { try { openconnection(); cmd = new OleDbCommand("SELECT * FROM Teacher WHERE GivenName =@givenName AND surname =@surname ", connection); cmd.Parameters.AddWithValue("@givenName", givenName); cmd.Parameters.AddWithValue("@surname", surname); dr = cmd.ExecuteReader(); dr.Read(); int teacherID = Convert.ToInt32(dr[0].ToString()); String title = dr[1].ToString(); givenName = dr[2].ToString(); surname = dr[3].ToString(); String initials = dr[4].ToString(); Teacher t = new Teacher(teacherID, title, givenName, surname, initials); closeconnection(); return t; } catch { return null; } }