private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text.Length == 0) { MessageBox.Show("Please enter Student's Name, then Add", "Name Field is blank"); } else if (txtContact.Text.Length == 0) { MessageBox.Show("Please enter Student's Contact number, then Add", "Contact Field is blank"); } else if (txtEmail.Text.Length == 0) { MessageBox.Show("Please enter Student's Email address, then Add", "Email Field is blank"); } else if (txtHabibID.Text.Length == 0) { MessageBox.Show("Please enter Student's Habib ID, then Add.", "Habib ID Field is blank"); } else { SqlDataReader rd; SqlTransaction tran = con.BeginTransaction(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.Transaction = tran; cmd.CommandType = CommandType.Text; cmd.CommandText = "select StudentID,Name,Contact,Email," + "HabibID from Students where HabibID = '" + myStudent.HabibID + "' or Email = '" + myStudent.Email + "'"; rd = cmd.ExecuteReader(); if (rd.Read()) { string tempID = rd[0].ToString(); string tempName = rd[1].ToString(); string tempContact = rd[2].ToString(); string tempEmail = rd[3].ToString(); string tempHabibID = rd[4].ToString(); MessageBox.Show("The Email or HabibID provided matches an existing record:\n" + tempID + "\n" + tempName + "\n" + tempContact + "\n" + tempEmail + "\n" + tempHabibID, "Duplicate entry"); rd.Close(); return; } rd.Close(); cmd.CommandText = "insert into Students (Name,Contact," + "Email,HabibID) values ('" + myStudent.Name + "','" + myStudent.Contact + "','" + myStudent.Email + "','" + myStudent.HabibID + "')"; cmd.ExecuteNonQuery(); cmd.CommandText = "select top 1 StudentID from Students" + " order by StudentID desc"; rd = cmd.ExecuteReader(); if (rd.Read() == true) { myStudent.ID = rd[0].ToString(); } rd.Close(); tran.Commit(); state = "Incomplete"; //UpdateFields(state); //temp scene MessageBox.Show(myStudent.Name + " has been added", "Student added"); frmEnrolment enrolment = new frmEnrolment(currentUser: CurrentUser); enrolment.Show(); Close(); } catch (Exception ex) { tran.Rollback(); MessageBox.Show(ex.Message, "Error in btnAdd"); } } }
public void OpenForm(string type, string task) { if (task == "Search") { if (type == "Booking") { frmSearch frm = new frmSearch(type, CurrentUser); frm.Show(); } else if (type == "EmailAccount") { frmEmailDetails frm = new frmEmailDetails(currentUser: CurrentUser); frm.Show(); } } else if (task == "Add") { if (type == "Booking") { frmBooking frm = new frmBooking(CurrentUser); frm.Show(); } else if (type == "User") { frmUser frm = new frmUser(CurrentUser); frm.Show(); } else if (type == "Course") { frmCourse frm = new frmCourse(CurrentUser); frm.Show(); } else if (type == "Instructor") { frmInstructor frm = new frmInstructor(CurrentUser); frm.Show(); } else if (type == "Staff") { frmStaff frm = new frmStaff(CurrentUser); frm.Show(); } else if (type == "Student") { frmStudent frm = new frmStudent(CurrentUser); frm.Show(); } else if (type == "Enrolment") { frmEnrolment frm = new frmEnrolment(CurrentUser); frm.Show(); } else if (type == "Equipment") { frmEquipment frm = new frmEquipment(); frm.Show(); } } else { MessageBox.Show("Incorrect value for task: " + task, "Error in OpenForm()"); } }