private void btnRemoveTeacher_Click(object sender, EventArgs e) { if (lbxTeachers.SelectedIndices.Count == 1) { DialogResult result = MessageBox.Show(this, "Är du säker på att du vill ta bort " + lbxTeachers.SelectedItem.ToString() + " från skolan?", "Ta bort lärare", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { PolhemTeacher tmpTeacher = null; for (int i = 0; i < teacherList.Count; i++) { if (teacherList[i].TeacherName == lbxTeachers.SelectedItem.ToString()) { tmpTeacher = teacherList[i]; break; } } string connectionString = "server=192.168.2.209; port=3306; " + "database=School; uid=DataDennisCunt7; pwd=MicrophoneRedKlyft67#;"; MySqlConnection deleteConnection = new MySqlConnection(connectionString); deleteConnection.Open(); MySqlCommand deleteCmd = new MySqlCommand("DELETE FROM teachercourses WHERE teacher_id = (SELECT id FROM teachers WHERE name='" + tmpTeacher.TeacherName + "' AND email='" + tmpTeacher.TeacherEmail + "');", deleteConnection); MySqlCommand deleteTeacher = new MySqlCommand("DELETE FROM teachers WHERE name = '" + tmpTeacher.TeacherName + "' AND email = '" + tmpTeacher.TeacherEmail + "'; ", deleteConnection); int affectedCourses = deleteCmd.ExecuteNonQuery(); int affectedTeachers = deleteTeacher.ExecuteNonQuery(); deleteConnection.Close(); MessageBox.Show(this, "Tog bort " + affectedTeachers.ToString() + " lärare, och påverkade " + affectedCourses.ToString() + " kurser.", "Borttagning genomförd", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } else { MessageBox.Show(this, "Läraren har inte blivit borttagen.", "Borttagning avbruten", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } getData(); updateGUI(); } else { MessageBox.Show(this, "Var vänlig välj en lärare för borttagning", "Ingen lärare vald", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void btnUpdateTeacher_Click(object sender, EventArgs e) { PolhemTeacher tmpTeacher = null; for (int i = 0; i < teacherList.Count; i++) { if (teacherList[i].TeacherName == lbxTeachers.SelectedItem.ToString()) { tmpTeacher = teacherList[i]; break; } } using (var updateItem = new UpdateItem("teacher", null, null, tmpTeacher)) { updateItem.ShowDialog(); } getData(); updateGUI(); }
private bool doesItemExist(string updateCase, PolhemStudent student = null, PolhemTeacher teacher = null, PolhemCourse course = null) { bool itemExists = true; string authenticationString = "server=192.168.2.209; port=3306; " + "database=School; uid=DataDennisCunt7; pwd=MicrophoneRedKlyft67#;"; MySqlConnection testConnection = new MySqlConnection(authenticationString); testConnection.Open(); MySqlCommand testCommand = new MySqlCommand("SELECT * FROM tables;", testConnection); if (updateCase == "teacher") { testCommand = new MySqlCommand("SELECT * FROM teachers WHERE name='" + teacher.TeacherName + "' AND code='" + teacher.TeacherCode + "' AND email='" + teacher.TeacherEmail + "' AND phone='" + teacher.TeacherPhone + "';", testConnection); } else if (updateCase == "student") { testCommand = new MySqlCommand("SELECT * FROM students WHERE name='" + student.StudentName + "' AND email='" + student.StudentEmail + "' AND class='" + student.StudentClass + "' AND phone='" + student.StudentPhone + "';", testConnection); } else if (updateCase == "course") { testCommand = new MySqlCommand("SELECT * FROM courses WHERE name='" + course.CourseName + "' AND code='" + course.CourseCode + "' AND size='" + course.CoursePoints + "' AND start='" + course.CourseStartDate + "' AND end='" + course.CourseEndDate + "';", testConnection); } int affectedRows = testCommand.ExecuteNonQuery(); if (affectedRows <= 0) { itemExists = false; } else { itemExists = true; } return(itemExists); }
private void getData() { courseList.Clear(); studentList.Clear(); teacherList.Clear(); string connectionString = "server=192.168.2.209; port=3306; " + "database=School; uid=DataDennisCunt7; pwd=MicrophoneRedKlyft67#;"; MySqlConnection dbCourse = new MySqlConnection(connectionString); dbCourse.Open(); MySqlCommand cmdCourse = new MySqlCommand("SELECT * FROM courses;", dbCourse); MySqlDataReader rdrCourse = cmdCourse.ExecuteReader(); if (rdrCourse.HasRows) { while (rdrCourse.Read()) { string tmpCourseName = rdrCourse["name"].ToString(); string tmpCourseCode = rdrCourse["code"].ToString(); int tmpCourseSize = int.Parse(rdrCourse["size"].ToString()); DateTime tmpCourseStart = DateTime.Parse(rdrCourse["start"].ToString()); DateTime tmpCourseEnd = DateTime.Parse(rdrCourse["end"].ToString()); PolhemCourse tmpCourse = new PolhemCourse(tmpCourseName, tmpCourseCode, tmpCourseSize, tmpCourseStart, tmpCourseEnd); MySqlConnection dbTeacher = new MySqlConnection(connectionString); dbTeacher.Open(); MySqlCommand cmdTeacher = new MySqlCommand("SELECT * FROM teachers WHERE teachers.id in (SELECT teachercourses.teacher_id FROM teachercourses WHERE teachercourses.course_id = (SELECT id FROM courses WHERE courses.name = '" + tmpCourse.CourseName + "'));", dbTeacher); MySqlDataReader rdrTeacher = cmdTeacher.ExecuteReader(); if (rdrTeacher.HasRows) { while (rdrTeacher.Read()) { string tmpTeacherName = rdrTeacher["name"].ToString(); string tmpTeacherCode = rdrTeacher["code"].ToString(); string tmpTeacherEmail = rdrTeacher["email"].ToString(); string tmpTeacherPhone = rdrTeacher["phone"].ToString(); PolhemTeacher tmpTeacher = new PolhemTeacher(tmpTeacherName, tmpTeacherCode, tmpTeacherEmail, tmpTeacherPhone); tmpCourse.CourseTeachers.Add(tmpTeacher); } } rdrTeacher.Close(); dbTeacher.Close(); MySqlConnection dbStudent = new MySqlConnection(connectionString); dbStudent.Open(); MySqlCommand cmdStudent = new MySqlCommand("SELECT * FROM students WHERE students.id in (SELECT coursestudents.students_id FROM coursestudents WHERE coursestudents.courses_id = (SELECT id FROM courses WHERE courses.name = '" + tmpCourse.CourseName + "'));", dbStudent); MySqlDataReader rdrStudent = cmdStudent.ExecuteReader(); if (rdrStudent.HasRows) { while (rdrStudent.Read()) { string tmpStudentName = rdrStudent["name"].ToString(); string tmpStudentClass = rdrStudent["class"].ToString(); string tmpStudentEmail = rdrStudent["email"].ToString(); string tmpStundentPhone = rdrStudent["phone"].ToString(); PolhemStudent tmpStudent = new PolhemStudent(tmpStudentName, tmpStudentClass, tmpStudentEmail, tmpStundentPhone); tmpCourse.CourseStudents.Add(tmpStudent); } } rdrStudent.Close(); dbStudent.Close(); courseList.Add(tmpCourse); } } rdrCourse.Close(); dbCourse.Close(); MySqlConnection dbTeachers = new MySqlConnection(connectionString); dbTeachers.Open(); MySqlCommand cmdTeachers = new MySqlCommand("SELECT * FROM teachers;", dbTeachers); MySqlDataReader rdrTeachers = cmdTeachers.ExecuteReader(); if (rdrTeachers.HasRows) { while (rdrTeachers.Read()) { string tmpTeacherName = rdrTeachers["name"].ToString(); string tmpTeacherCode = rdrTeachers["code"].ToString(); string tmpTeacherEmail = rdrTeachers["email"].ToString(); string tmpTeacherPhone = rdrTeachers["phone"].ToString(); PolhemTeacher tmpTeacher = new PolhemTeacher(tmpTeacherName, tmpTeacherCode, tmpTeacherEmail, tmpTeacherPhone); teacherList.Add(tmpTeacher); } } rdrTeachers.Close(); dbTeachers.Close(); MySqlConnection dbStudents = new MySqlConnection(connectionString); dbStudents.Open(); MySqlCommand cmdStudents = new MySqlCommand("SELECT * FROM students;", dbStudents); MySqlDataReader rdrStudents = cmdStudents.ExecuteReader(); if (rdrStudents.HasRows) { while (rdrStudents.Read()) { string tmpStudentName = rdrStudents["name"].ToString(); string tmpStudentClass = rdrStudents["class"].ToString(); string tmpStudentEmail = rdrStudents["email"].ToString(); string tmpStundentPhone = rdrStudents["phone"].ToString(); PolhemStudent tmpStudent = new PolhemStudent(tmpStudentName, tmpStudentClass, tmpStudentEmail, tmpStundentPhone); studentList.Add(tmpStudent); } } rdrStudents.Close(); dbStudents.Close(); }
public UpdateItem(string item, PolhemCourse course = null, PolhemStudent student = null, PolhemTeacher teacher = null) { InitializeComponent(); updateCase = item; studentData = student; teacherData = teacher; courseData = course; switch (updateCase) { case "student": this.Controls.Add(gbxUpdateContainer); gbxUpdateContainer.Size = new Size(365, 151); gbxUpdateContainer.Location = new Point(13, 13); gbxUpdateContainer.Text = "Elev"; this.Size = new Size(405, 220 + System.Windows.Forms.SystemInformation.CaptionHeight); this.FormBorderStyle = FormBorderStyle.FixedSingle; btnUpdate = new Button(); this.Controls.Add(btnUpdate); btnUpdate.Location = new Point(13, 170); btnUpdate.Size = new Size((gbxUpdateContainer.Size.Width - 20) / 2, 20); btnUpdate.Text = "Uppdatera"; btnAbort = new Button(); this.Controls.Add(btnAbort); btnAbort.Location = new Point(33 + ((gbxUpdateContainer.Size.Width - 20) / 2), 170); btnAbort.Size = new Size((gbxUpdateContainer.Size.Width - 20) / 2, 20); btnAbort.Text = "Avbryt"; lblStudentClass = new Label(); lblStudentEmail = new Label(); lblStudentName = new Label(); lblStudentPhone = new Label(); tbxStudentClass = new TextBox(); tbxStudentEmail = new TextBox(); tbxStudentName = new TextBox(); tbxStudentPhone = new TextBox(); this.Controls.Add(lblStudentClass); this.Controls.Add(lblStudentEmail); this.Controls.Add(lblStudentName); this.Controls.Add(lblStudentPhone); this.Controls.Add(tbxStudentClass); this.Controls.Add(tbxStudentEmail); this.Controls.Add(tbxStudentName); this.Controls.Add(tbxStudentPhone); gbxUpdateContainer.Controls.Add(tbxStudentPhone); gbxUpdateContainer.Controls.Add(tbxStudentEmail); gbxUpdateContainer.Controls.Add(tbxStudentName); gbxUpdateContainer.Controls.Add(tbxStudentClass); gbxUpdateContainer.Controls.Add(lblStudentPhone); gbxUpdateContainer.Controls.Add(lblStudentEmail); gbxUpdateContainer.Controls.Add(lblStudentName); gbxUpdateContainer.Controls.Add(lblStudentClass); lblStudentName.Text = "Namn"; lblStudentName.Location = new Point(15, 30); lblStudentName.Size = new Size(35, 13); lblStudentClass.Text = "Klass"; lblStudentClass.Location = new Point(271, 30); lblStudentClass.Size = new Size(32, 13); lblStudentEmail.Text = "Epost"; lblStudentEmail.Location = new Point(18, 69); lblStudentEmail.Size = new Size(34, 13); lblStudentPhone.Text = "Telefonnummer"; lblStudentPhone.Location = new Point(18, 108); lblStudentPhone.Size = new Size(80, 13); tbxStudentName.Location = new Point(18, 46); tbxStudentName.Size = new Size(240, 20); tbxStudentClass.Location = new Point(274, 46); tbxStudentClass.Size = new Size(73, 20); tbxStudentEmail.Location = new Point(18, 85); tbxStudentEmail.Size = new Size(329, 20); tbxStudentPhone.Location = new Point(18, 124); tbxStudentPhone.Size = new Size(329, 20); tbxStudentClass.Text = student.StudentClass; tbxStudentEmail.Text = student.StudentEmail; tbxStudentName.Text = student.StudentName; tbxStudentPhone.Text = student.StudentPhone; tbxStudentEmail.TextChanged += emailUpdated; tbxStudentClass.TextChanged += classUpdated; tbxStudentName.TextChanged += nameUpdated; break; case "teacher": this.Controls.Add(gbxUpdateContainer); gbxUpdateContainer.Size = new Size(365, 151); gbxUpdateContainer.Location = new Point(13, 13); gbxUpdateContainer.Text = "Lärare"; this.Size = new Size(405, 220 + System.Windows.Forms.SystemInformation.CaptionHeight); this.FormBorderStyle = FormBorderStyle.FixedSingle; btnUpdate = new Button(); this.Controls.Add(btnUpdate); btnUpdate.Location = new Point(13, 170); btnUpdate.Size = new Size((gbxUpdateContainer.Size.Width - 20) / 2, 20); btnUpdate.Text = "Uppdatera"; btnAbort = new Button(); this.Controls.Add(btnAbort); btnAbort.Location = new Point(33 + ((gbxUpdateContainer.Size.Width - 20) / 2), 170); btnAbort.Size = new Size((gbxUpdateContainer.Size.Width - 20) / 2, 20); btnAbort.Text = "Avbryt"; lblTeacherCode = new Label(); lblTeacherEmail = new Label(); lblTeacherName = new Label(); lblTeacherPhone = new Label(); tbxTeacherCode = new TextBox(); tbxTeacherEmail = new TextBox(); tbxTeacherName = new TextBox(); tbxTeacherPhone = new TextBox(); this.Controls.Add(lblTeacherCode); this.Controls.Add(lblTeacherEmail); this.Controls.Add(lblTeacherName); this.Controls.Add(lblTeacherPhone); this.Controls.Add(tbxTeacherCode); this.Controls.Add(tbxTeacherEmail); this.Controls.Add(tbxTeacherName); this.Controls.Add(tbxTeacherPhone); gbxUpdateContainer.Controls.Add(tbxTeacherPhone); gbxUpdateContainer.Controls.Add(tbxTeacherEmail); gbxUpdateContainer.Controls.Add(tbxTeacherName); gbxUpdateContainer.Controls.Add(tbxTeacherCode); gbxUpdateContainer.Controls.Add(lblTeacherPhone); gbxUpdateContainer.Controls.Add(lblTeacherEmail); gbxUpdateContainer.Controls.Add(lblTeacherName); gbxUpdateContainer.Controls.Add(lblTeacherCode); lblTeacherName.Text = "Namn"; lblTeacherName.Location = new Point(15, 30); lblTeacherName.Size = new Size(35, 13); lblTeacherCode.Text = "Kod"; lblTeacherCode.Location = new Point(271, 30); lblTeacherCode.Size = new Size(32, 13); lblTeacherEmail.Text = "Epost"; lblTeacherEmail.Location = new Point(18, 69); lblTeacherEmail.Size = new Size(34, 13); lblTeacherPhone.Text = "Telefonnummer"; lblTeacherPhone.Location = new Point(18, 108); lblTeacherPhone.Size = new Size(80, 13); tbxTeacherName.Location = new Point(18, 46); tbxTeacherName.Size = new Size(240, 20); tbxTeacherCode.Location = new Point(274, 46); tbxTeacherCode.Size = new Size(73, 20); tbxTeacherEmail.Location = new Point(18, 85); tbxTeacherEmail.Size = new Size(329, 20); tbxTeacherPhone.Location = new Point(18, 124); tbxTeacherPhone.Size = new Size(329, 20); tbxTeacherCode.Text = teacher.TeacherCode; tbxTeacherEmail.Text = teacher.TeacherEmail; tbxTeacherName.Text = teacher.TeacherName; tbxTeacherPhone.Text = teacher.TeacherPhone; tbxTeacherEmail.TextChanged += emailUpdated; tbxTeacherCode.TextChanged += codeUpdated; tbxTeacherName.TextChanged += nameUpdated; break; case "course": this.Controls.Add(gbxUpdateContainer); gbxUpdateContainer.Size = new Size(217, 217); gbxUpdateContainer.Location = new Point(13, 13); gbxUpdateContainer.Text = "Kurs"; this.Size = new Size(262, 288 + System.Windows.Forms.SystemInformation.CaptionHeight); this.FormBorderStyle = FormBorderStyle.FixedSingle; btnUpdate = new Button(); this.Controls.Add(btnUpdate); btnUpdate.Location = new Point(13, 235); btnUpdate.Size = new Size((this.Width - 40) / 2, 20); btnUpdate.Text = "Uppdatera"; btnAbort = new Button(); this.Controls.Add(btnAbort); btnAbort.Location = new Point(13 + ((this.Width - 40) / 2), 235); btnAbort.Size = new Size((this.Width - 40) / 2, 20); btnAbort.Text = "Avbryt"; lblCourseCode = new Label(); lblCourseEnd = new Label(); lblCourseName = new Label(); lblCoursePoints = new Label(); lblCourseStart = new Label(); tbxCourseCode = new TextBox(); tbxCourseEnd = new TextBox(); tbxCourseName = new TextBox(); tbxCoursePoints = new TextBox(); tbxCourseStart = new TextBox(); this.Controls.Add(lblCourseCode); this.Controls.Add(lblCourseEnd); this.Controls.Add(lblCourseName); this.Controls.Add(lblCoursePoints); this.Controls.Add(lblCourseStart); this.Controls.Add(tbxCourseCode); this.Controls.Add(tbxCourseEnd); this.Controls.Add(tbxCoursePoints); this.Controls.Add(tbxCourseName); this.Controls.Add(tbxCourseStart); gbxUpdateContainer.Controls.Add(lblCourseCode); gbxUpdateContainer.Controls.Add(lblCourseEnd); gbxUpdateContainer.Controls.Add(lblCourseName); gbxUpdateContainer.Controls.Add(lblCoursePoints); gbxUpdateContainer.Controls.Add(lblCourseStart); gbxUpdateContainer.Controls.Add(tbxCourseCode); gbxUpdateContainer.Controls.Add(tbxCourseEnd); gbxUpdateContainer.Controls.Add(tbxCoursePoints); gbxUpdateContainer.Controls.Add(tbxCourseName); gbxUpdateContainer.Controls.Add(tbxCourseStart); lblCourseCode.Text = "Kod"; lblCourseCode.Location = new Point(6, 90); lblCourseCode.Size = new Size(26, 13); lblCourseEnd.Text = "S**t"; lblCourseEnd.Location = new Point(6, 190); lblCourseEnd.Size = new Size(25, 13); lblCourseName.Text = "Namn"; lblCourseName.Location = new Point(6, 30); lblCourseName.Size = new Size(35, 13); lblCoursePoints.Text = "Omfattning"; lblCoursePoints.Location = new Point(6, 125); lblCoursePoints.Size = new Size(58, 13); lblCourseStart.Text = "Start"; lblCourseStart.Location = new Point(6, 160); lblCourseStart.Size = new Size(29, 13); tbxCourseCode.Location = new Point(131, 87); tbxCourseCode.Size = new Size(80, 20); tbxCourseEnd.Location = new Point(85, 187); tbxCourseEnd.Size = new Size(126, 20); tbxCourseName.Location = new Point(6, 50); tbxCourseName.Size = new Size(205, 20); tbxCoursePoints.Location = new Point(147, 122); tbxCoursePoints.Size = new Size(64, 20); tbxCourseStart.Location = new Point(85, 157); tbxCourseStart.Size = new Size(126, 20); tbxCourseCode.Text = course.CourseCode; tbxCourseEnd.Text = course.CourseEndDate.ToShortDateString(); tbxCourseName.Text = course.CourseName; tbxCoursePoints.Text = course.CoursePoints.ToString(); tbxCourseStart.Text = course.CourseStartDate.ToShortDateString(); break; default: break; } btnUpdate.Click += btnUpdateClick; btnAbort.Click += btnAbortClick; }
private bool areInputsCorrect(string updateCase, out string errorMessage) { bool result = false; errorMessage = ""; if (updateCase == "course") { bool pointsCorrect = false; bool startDateCorrect = false; bool endDateCorrect = false; if (!string.IsNullOrEmpty(tbxCoursePoints.Text) && !string.IsNullOrWhiteSpace(tbxCoursePoints.Text)) { if (int.TryParse(tbxCoursePoints.Text, out int outPut)) { pointsCorrect = true; } } if (!string.IsNullOrEmpty(tbxCourseStart.Text) && !string.IsNullOrWhiteSpace(tbxCourseStart.Text)) { if (DateTime.TryParse(tbxCourseStart.Text, out DateTime result1)) { startDateCorrect = true; } } if (!string.IsNullOrEmpty(tbxCourseEnd.Text) && !string.IsNullOrWhiteSpace(tbxCourseEnd.Text)) { if (DateTime.TryParse(tbxCourseEnd.Text, out DateTime result2)) { endDateCorrect = true; } } if (!string.IsNullOrEmpty(tbxCourseName.Text) && !string.IsNullOrWhiteSpace(tbxCourseName.Text) && !string.IsNullOrEmpty(tbxCourseCode.Text) && !string.IsNullOrWhiteSpace(tbxCourseCode.Text) && !string.IsNullOrEmpty(tbxCoursePoints.Text) && !string.IsNullOrWhiteSpace(tbxCoursePoints.Text) && !string.IsNullOrEmpty(tbxCourseStart.Text) && !string.IsNullOrWhiteSpace(tbxCourseStart.Text) && !string.IsNullOrEmpty(tbxCourseEnd.Text) && !string.IsNullOrWhiteSpace(tbxCourseEnd.Text) && pointsCorrect && startDateCorrect && endDateCorrect) { PolhemCourse tmpCourse = new PolhemCourse(tbxCourseName.Text, tbxCourseCode.Text, int.Parse(tbxCoursePoints.Text), DateTime.Parse(tbxCourseStart.Text), DateTime.Parse(tbxCourseEnd.Text)); if (!doesItemExist("course", null, null, tmpCourse)) { result = true; } else { errorMessage = "alreadyExists"; } } } else if (updateCase == "student") { if (!string.IsNullOrEmpty(tbxStudentName.Text) && !string.IsNullOrWhiteSpace(tbxStudentName.Text) && !string.IsNullOrEmpty(tbxStudentClass.Text) && !string.IsNullOrWhiteSpace(tbxStudentClass.Text) && !string.IsNullOrEmpty(tbxStudentEmail.Text) && !string.IsNullOrWhiteSpace(tbxStudentEmail.Text) && !string.IsNullOrEmpty(tbxStudentPhone.Text) && !string.IsNullOrWhiteSpace(tbxStudentPhone.Text) && Regex.IsMatch(tbxStudentName.Text, "^[a-zA-Z åÅäÄöÖ-]*$") && Regex.IsMatch(tbxStudentClass.Text, "^[A-ZÅÄÖ0-9]*$")) { PolhemStudent tmpStudent = new PolhemStudent(tbxStudentName.Text, tbxStudentClass.Text, tbxStudentEmail.Text, tbxStudentPhone.Text); if (!doesItemExist("student", tmpStudent)) { try { MailAddress tmpEmail = new MailAddress(tbxStudentEmail.Text); result = true; } catch { errorMessage = "emailIncorrect"; } result = true; } else { errorMessage = "alreadyExists"; } } } else if (updateCase == "teacher") { if (!string.IsNullOrEmpty(tbxTeacherName.Text) && !string.IsNullOrWhiteSpace(tbxTeacherName.Text) && !string.IsNullOrEmpty(tbxTeacherCode.Text) && !string.IsNullOrWhiteSpace(tbxTeacherCode.Text) && !string.IsNullOrEmpty(tbxTeacherEmail.Text) && !string.IsNullOrWhiteSpace(tbxTeacherEmail.Text) && !string.IsNullOrEmpty(tbxTeacherPhone.Text) && !string.IsNullOrWhiteSpace(tbxTeacherPhone.Text) && Regex.IsMatch(tbxTeacherName.Text, "^[a-zA-Z åÅäÄöÖ-]*$") && Regex.IsMatch(tbxTeacherCode.Text, "^[A-ZÅÄÖ]*$")) { PolhemTeacher tmpTeacher = new PolhemTeacher(tbxTeacherName.Text, tbxTeacherCode.Text, tbxTeacherEmail.Text, tbxTeacherPhone.Text); if (!doesItemExist("teacher", null, tmpTeacher)) { try { MailAddress tmpEmail = new MailAddress(tbxTeacherEmail.Text); result = true; } catch { errorMessage = "emailIncorrect"; } } else { errorMessage = "alreadyExists"; } } } return(result); }