/// <summary> /// Handles the event when the user leave the masked student number textbox. /// Updates the form fields based on the student number /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void studentNumberMaskedTextBox_Leave(object sender, EventArgs e) { BITCollege_TravisTaylorContext db = new BITCollege_TravisTaylorContext(); try { if (studentNumberMaskedTextBox.MaskCompleted == true) { string boxValue = studentNumberMaskedTextBox.Text; long studentNumber = long.Parse(boxValue); Student student = (from results in db.Students where results.StudentNumber == studentNumber select results).SingleOrDefault(); if (student != null) { studentBindingSource.DataSource = student; registrationNumberComboBox.Enabled = true; int studentID = student.StudentId; IQueryable <Registration> registrations = from results in db.Registrations where results.StudentId == studentID select results; if (registrations.Count() > 0) { lnkUpdate.Enabled = true; lnkDetails.Enabled = true; registrationBindingSource.DataSource = registrations.ToList(); //If it is not null, then we are returning from another form //Sets the drop down list that is generated to the current registration if (constructorData.registration != null) { registrationNumberComboBox.Text = constructorData.registration.RegistrationNumber.ToString(); } } else { lnkUpdate.Enabled = false; lnkDetails.Enabled = false; registrationBindingSource.Clear(); } } else { MessageBox.Show("Student Number does not exist"); registrationNumberComboBox.Enabled = false; lnkDetails.Enabled = false; lnkUpdate.Enabled = false; studentBindingSource.Clear(); registrationBindingSource.Clear(); studentNumberMaskedTextBox.Focus(); } } registrationNumberComboBox.Focus(); } catch (Exception exception) { studentBindingSource.Clear(); registrationBindingSource.Clear(); MessageBox.Show(exception.Message); } }