private void btn_Edit_Click(object sender, EventArgs e) { student = new Student(); try { //Checks if the ID number exists in the database if (db.SearchStudentID((int.Parse(txtBox_ID.Text))) == false) { MessageBox.Show("Please input an existing student ID number.", "COA Registration System", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Form_RegistrantProfile registrant = new Form_RegistrantProfile((uint.Parse(txtBox_ID.Text))); this.Hide(); registrant.ShowDialog(); } } catch (Exception) { //Will usually show if the inputted ID number is not a positive integer //Will also appear on other kinds of errors MessageBox.Show("Please input a valid ID Number.", "COA Registration System", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Show(); }
public Registration_Form() { InitializeComponent(); db = new DBFunction(); student = new Student(); su = new StringUtil(); enterBtnPress = false; }
private void txtBox_ID_Enter(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { student = db.GetOldStudentData(int.Parse(txtBox_ID.Text)); label_name.Text = student.FullName; //Added one since this was last year's database int year = int.Parse(student.Level) + 1; student.Level = year.ToString(); label_YrCourse.Text = String.Format(student.Level + " - " + student.Course); enterBtnPress = true; } else { enterBtnPress = false; } }
//Searches ID number if it exist in the database //Old DB public Boolean SearchStudentID(int idNum) { student = new Student(); myConn = ConnectToDatabase(); //Makes a MySQL query string cmd = "SELECT student_id FROM coa.old_student_t WHERE student_id = @StudentID"; //Passes the command into the database connection MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); //To prevent SQL Injections, it would consider 'idNum' as a paramater SelectCommand.Parameters.AddWithValue("@StudentID", idNum); try { myConn.Open(); myReader = SelectCommand.ExecuteReader(); while (myReader.Read()) { try { student.StudentID = myReader.GetUInt16(0); } catch (InvalidCastException) { } } if (myReader.FieldCount > 0) { return true; } else { return false; } } catch (Exception) { return false; } }
//Gets the Student's data from the old DB public Student GetOldStudentData(int idNum) { student = new Student(idNum); myConn = ConnectToDatabase(); //Makes a MySQL query string cmd = "SELECT * FROM coa.old_student_t WHERE student_id = @StudentID"; //Passes the command into the database connection MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); //To prevent SQL Injections, it would consider 'idNum' as a paramater SelectCommand.Parameters.AddWithValue("@StudentID", idNum); try { myConn.Open(); myReader = SelectCommand.ExecuteReader(); while (myReader.Read()) { try { student.StudentID = myReader.GetInt32(0); } catch (InvalidCastException) { } try { student.FullName = myReader.IsDBNull(1) ? null : myReader.GetString(1); } catch (InvalidCastException) { } try { student.Level = myReader.IsDBNull(2) ? null : myReader.GetString(2); } catch (InvalidCastException) { } try { student.Course = myReader.IsDBNull(3) ? null : myReader.GetString(3); } catch (InvalidCastException) { } } } catch (Exception) { return null; } myConn.Close(); return student; }
//New DB public Student EditStudent(int idNum) { student = new Student(idNum); try { } catch (Exception) { } return student; }