private void metroButtonSearch_Click(object sender, EventArgs e) { Student obj = new Student(); StudentTransactions tr2 = new StudentTransactions(); try { obj = tr2.dataFill(metroTextSearch.Text); metroTextBoxStudentId.Text = obj.getid(); metroTextBoxFirstName.Text = obj.getFirstName(); metroTextBoxLastName.Text = obj.getLastName(); metroTextBoxDOB.Text = obj.getDOB(); metroTextBoxMobileNo.Text = obj.getContactNo(); metroTextBoxEmail.Text = obj.getEmail(); metroTextBoxAddress.Text = obj.getAddress(); metroComboBoxGen.Text = obj.getGender(); metroTextBoxUsername.Text = obj.getUsername(); metroTextBoxPassword.Text = obj.getPassword(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Stafford University Registration System", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void metroButtonProceed_Click(object sender, EventArgs e) { if (metroComboBoxOptStd.Text == "Add") { if (metroTextBoxStudentId.Text == "" || metroTextBoxFirstName.Text == "" || metroTextBoxLastName.Text == "" || metroTextBoxDOB.Text == "" || metroTextBoxMobileNo.Text == "" || metroTextBoxEmail.Text == "" || metroTextBoxAddress.Text == "" || metroComboBoxGen.Text == "" || metroTextBoxUsername.Text == "" || metroTextBoxPassword.Text == "") { MetroMessageBox.Show(this, "Fields cannot be left empty"); } if (!Regex.Match(metroTextBoxMobileNo.Text, @"^\d{10}$").Success) { MetroMessageBox.Show(this, "Please re-enter the contact number", "Warning"); metroTextBoxMobileNo.Focus(); } if (!Regex.Match(metroTextBoxEmail.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,4})+)$").Success) { MetroMessageBox.Show(this, "Invalid E-Mail address Please re-enter correct address"); metroTextBoxEmail.Focus(); } else { CommonDBTransaction c = new CommonDBTransaction(); string sql = "SELECT * FROM Student WHERE SId = '" + metroTextBoxStudentId.Text + "' or Username = '******'"; DataTable d = c.searchData(sql); metroGridStudents.DataSource = d; if (d.Rows.Count > 0) { MetroMessageBox.Show(this, "This Data already exist"); } else { Student obj = new Student(metroTextBoxStudentId.Text, metroTextBoxFirstName.Text, metroTextBoxLastName.Text, metroTextBoxDOB.Text, metroTextBoxMobileNo.Text, metroTextBoxEmail.Text, metroTextBoxAddress.Text, metroComboBoxGen.Text, metroTextBoxUsername.Text, metroTextBoxPassword.Text); StudentTransactions tr = new StudentTransactions(); tr.addstudent(obj); MetroMessageBox.Show(this, "Data Saved Sucessfully !"); clearStudent(); metroGridStudents.Refresh(); } } } else if (metroComboBoxOptStd.Text == "Update") { if (metroTextBoxStudentId.Text == "" || metroTextBoxFirstName.Text == "" || metroTextBoxLastName.Text == "" || metroTextBoxDOB.Text == "" || metroTextBoxMobileNo.Text == "" || metroTextBoxEmail.Text == "" || metroTextBoxAddress.Text == "" || metroComboBoxGen.Text == "" || metroTextBoxUsername.Text == "" || metroTextBoxPassword.Text == "") { MetroMessageBox.Show(this, "Fields cannot be left empty"); } if (!Regex.Match(metroTextBoxMobileNo.Text, @"^\d{10}$").Success) { MetroMessageBox.Show(this, "Please re-enter the contact number", "Warning"); metroTextBoxMobileNo.Focus(); } if (!Regex.Match(metroTextBoxEmail.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,4})+)$").Success) { MetroMessageBox.Show(this, "Invalid E-Mail address Please re-enter correct address"); metroTextBoxEmail.Focus(); } else { Student obj = new Student(metroTextBoxStudentId.Text, metroTextBoxFirstName.Text, metroTextBoxLastName.Text, metroTextBoxDOB.Text, metroTextBoxMobileNo.Text, metroTextBoxEmail.Text, metroTextBoxAddress.Text, metroComboBoxGen.Text, metroTextBoxUsername.Text, metroTextBoxPassword.Text); StudentTransactions tr = new StudentTransactions(); tr.updateStudent(obj); MetroMessageBox.Show(this, "Data Saved Sucessfully !"); clearStudent(); metroGridStudents.Refresh(); } } else if (metroComboBoxOptStd.Text == "Search") { Student obj = new Student(); StudentTransactions tr2 = new StudentTransactions(); try { obj = tr2.dataFill(metroTextSearch.Text); metroTextBoxStudentId.Text = obj.getid(); metroTextBoxFirstName.Text = obj.getFirstName(); metroTextBoxLastName.Text = obj.getLastName(); metroTextBoxDOB.Text = obj.getDOB(); metroTextBoxMobileNo.Text = obj.getContactNo(); metroTextBoxEmail.Text = obj.getEmail(); metroTextBoxAddress.Text = obj.getAddress(); metroComboBoxGen.Text = obj.getGender(); metroTextBoxUsername.Text = obj.getUsername(); metroTextBoxPassword.Text = obj.getPassword(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Stafford University Registration System", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (metroComboBoxOptStd.Text == "Delete") { if (metroGridStudents.Rows.Count == 0) { MetroMessageBox.Show(this, "No data found to delete"); } else { DialogResult del = MessageBox.Show("Are you Sure you want to delete :" + metroTextBoxStudentId.Text + "", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (del == DialogResult.Yes) { StudentTransactions tr3 = new StudentTransactions(); try { tr3.deleteFromStudentModule(metroTextBoxStudentId.Text); tr3.deleteStudent(metroTextBoxStudentId.Text); MetroMessageBox.Show(this, "Successfully Deleted"); clearStudent(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Delete Student", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Ok. As per confirmation, this record has not been deleted."); } } } else { MetroMessageBox.Show(this, "Please select a option button to Proceed!"); } }