private void btnSearch_Click(object sender, EventArgs e) { try { if (txtSearchKeyword.Text == string.Empty) { MessageBox.Show("StudendID is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtSearchKeyword.Text.Length > 8) { MessageBox.Show("StudendID cannot exceed length of 8", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ListsBL listBL = new ListsBL(); lstMatchingStudents.DataSource = listBL.GetStudents(txtSearchKeyword.Text); lstMatchingStudents.DisplayMember = "FullName"; lstMatchingStudents.ValueMember = "StudentId"; string msg = ""; foreach (ValidationError error in listBL.Errors) { msg += error.Description + Environment.NewLine; } if (msg != string.Empty) { MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSearch_Click(object sender, EventArgs e) { try { if (txtSearchKeyword.Text == string.Empty) { MessageBox.Show("StudendID is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtSearchKeyword.Text.Length > 8) { MessageBox.Show("StudendID cannot exceed length of 8", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ListsBL listBL = new ListsBL(); lstMatchingStudents.DataSource = listBL.GetStudents(txtSearchKeyword.Text); lstMatchingStudents.DisplayMember = "FullName"; lstMatchingStudents.ValueMember = "StudentId"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }