public Register_Form() { InitializeComponent(); db = new DBFunction(); student = new Student(); eventList = new List<Event>(); su = new StringUtil(); btn_Add.Hide(); db.LoadEventList(); eventList = db.GetEventList; id = new Int32[eventList.Count]; name = new String[eventList.Count]; FormPrepare(); }
public void UpdateStudent(int studentID, string lName, string fName, string year, string course, int gender, int member, int oldMember, DateTime birthday, string contactNo, string email, string houseHold, string committee, int paid) { student = SearchStudent(studentID); studentList.Remove(student); MySqlConnection myConn = OpenDBConnection(); string cmd = "UPDATE yfc.new_student_t SET last_name = @LastName, first_name = @Firstname, year = @Year, course = @Course, gender = @Gender, member = @Member, old_member = @OldMember, birthday = @Birthday, contact_no = @ContactNo, email = @Email, household = @HouseHold, committee = @Committee, paid = @Paid WHERE student_id = @StudentID"; //Passes the command into the database connection MySqlCommand UpdateCommand = new MySqlCommand(cmd, myConn); UpdateCommand.Parameters.AddWithValue("@StudentID", studentID); UpdateCommand.Parameters.AddWithValue("@LastName", lName); UpdateCommand.Parameters.AddWithValue("@FirstName", fName); UpdateCommand.Parameters.AddWithValue("@Year", year); UpdateCommand.Parameters.AddWithValue("@Course", course); UpdateCommand.Parameters.AddWithValue("@Gender", gender); UpdateCommand.Parameters.AddWithValue("@Member", member); UpdateCommand.Parameters.AddWithValue("@OldMember", oldMember); UpdateCommand.Parameters.AddWithValue("@Birthday", birthday); UpdateCommand.Parameters.AddWithValue("@ContactNo", contactNo); UpdateCommand.Parameters.AddWithValue("@Email", email); UpdateCommand.Parameters.AddWithValue("@HouseHold", houseHold); UpdateCommand.Parameters.AddWithValue("@Committee", committee); UpdateCommand.Parameters.AddWithValue("@Paid", paid); try { myConn.Open(); UpdateCommand.ExecuteNonQuery(); studentList.Add(new Student(studentID, lName, fName, year, course, gender, member, oldMember, birthday, contactNo, email, houseHold, committee, paid)); GetMemberList = studentList; } catch (Exception) { } }
//Selects all the students in the DB and their info public void LoadStudentList() { student = new Student(); studentList = new List<Student>(); MySqlConnection myConn = OpenDBConnection(); string cmd = "SELECT * FROM yfc.new_student_t"; MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); MySqlDataReader myReader; try { myConn.Open(); myReader = SelectCommand.ExecuteReader(); while (myReader.Read()) { try { student.StudentID = myReader.GetInt32(0); } catch (InvalidCastException) { } try { student.LastName = myReader.IsDBNull(1) ? null : myReader.GetString(1); } catch (InvalidCastException) { } try { student.FirstName = myReader.IsDBNull(2) ? null : myReader.GetString(2); } catch (InvalidCastException) { } try { student.Year = myReader.IsDBNull(3) ? null : myReader.GetString(3); } catch (InvalidCastException) { } try { student.Course = myReader.IsDBNull(4) ? null : myReader.GetString(4); } catch (InvalidCastException) { } try { student.Gender = myReader.IsDBNull(5) ? 0 : myReader.GetInt32(5); } catch (InvalidCastException) { } try { student.Member = myReader.IsDBNull(6) ? 0 : myReader.GetInt32(6); } catch (InvalidCastException) { } try { student.OldMember = myReader.IsDBNull(7) ? 0 : myReader.GetInt32(7); } catch (InvalidCastException) { } try { student.Birthday = myReader.IsDBNull(8) ? DateTime.Now : myReader.GetDateTime(8); } catch (InvalidCastException) { } try { student.ContactNo = myReader.IsDBNull(9) ? null : myReader.GetString(9); } catch (InvalidCastException) { } try { student.Email = myReader.IsDBNull(10) ? null : myReader.GetString(10); } catch (InvalidCastException) { } try { student.HouseHold = myReader.IsDBNull(11) ? null : myReader.GetString(11); } catch (InvalidCastException) { } try { student.Committee = myReader.IsDBNull(12) ? null : myReader.GetString(12); } catch (InvalidCastException) { } try { student.Paid = myReader.IsDBNull(13) ? 0 : myReader.GetInt32(13); } catch (InvalidCastException) { } studentList.Add(new Student(student.StudentID, student.LastName, student.FirstName, student.Year, student.Course, student.Gender, student.Member, student.OldMember, student.Birthday, student.ContactNo, student.Email, student.HouseHold, student.Committee, student.Paid)); } } catch (Exception) { } myConn.Close(); GetMemberList = studentList; }
public Student LoadOldStudentData(int studentID) { student = new Student(); MySqlConnection myConn = OpenDBConnection(); string cmd = "SELECT * FROM yfc.old_student_t WHERE student_id = @StudentID"; MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); SelectCommand.Parameters.AddWithValue("@StudentID", studentID); MySqlDataReader myReader; 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.Year = myReader.IsDBNull(2) ? null : myReader.GetString(2); } catch (InvalidCastException) { } try { student.Course = myReader.IsDBNull(3) ? null : myReader.GetString(3); } catch (InvalidCastException) { } int year = int.Parse(student.Year) + 1; student.Year = year.ToString(); } } catch (Exception) { } myConn.Close(); return student; }
//Loads only ID and Name of student public Student LoadNameYearSection(int studentID) { student = new Student(); MySqlConnection myConn = OpenDBConnection(); string cmd = "SELECT last_name, first_name, year, course FROM yfc.new_student_t WHERE student_id = @StudentID"; MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); SelectCommand.Parameters.AddWithValue("@StudentID", studentID); MySqlDataReader myReader; try { myConn.Open(); myReader = SelectCommand.ExecuteReader(); while (myReader.Read()) { try { student.LastName = myReader.IsDBNull(0) ? null : myReader.GetString(0); } catch (InvalidCastException) { } try { student.FirstName = myReader.IsDBNull(1) ? null : myReader.GetString(1); } catch (InvalidCastException) { } try { student.Year = myReader.IsDBNull(2) ? null : myReader.GetString(2); } catch (InvalidCastException) { } try { student.Course = myReader.IsDBNull(3) ? null : myReader.GetString(3); } catch (InvalidCastException) { } } } catch (Exception) { } myConn.Close(); return student; }
//For Form_ViewStudent, so that they can view all of their details public Student LoadFullStudentData(int studentID) { student = new Student(); MySqlConnection myConn = OpenDBConnection(); string cmd = "SELECT * FROM yfc.new_student_t WHERE student_id = @StudentID"; MySqlCommand SelectCommand = new MySqlCommand(cmd, myConn); SelectCommand.Parameters.AddWithValue("@StudentID", studentID); MySqlDataReader myReader; try { myConn.Open(); myReader = SelectCommand.ExecuteReader(); while (myReader.Read()) { try { student.StudentID = myReader.GetInt32(0); } catch (InvalidCastException) { } try { student.LastName = myReader.IsDBNull(1) ? null : myReader.GetString(1); } catch (InvalidCastException) { } try { student.FirstName = myReader.IsDBNull(2) ? null : myReader.GetString(2); } catch (InvalidCastException) { } try { student.Year = myReader.IsDBNull(3) ? null : myReader.GetString(3); } catch (InvalidCastException) { } try { student.Course = myReader.IsDBNull(4) ? null : myReader.GetString(4); } catch (InvalidCastException) { } try { student.Gender = myReader.IsDBNull(5) ? 0 : myReader.GetInt16(5); } catch (InvalidCastException) { } try { student.Member = myReader.IsDBNull(6) ? 0 : myReader.GetInt16(6); } catch (InvalidCastException) { } try { student.OldMember = myReader.IsDBNull(7) ? 0 : myReader.GetInt16(7); } catch (InvalidCastException) { } try { student.Birthday = myReader.IsDBNull(8) ? DateTime.Now : myReader.GetDateTime(8); } catch (InvalidCastException) { } try { student.ContactNo = myReader.IsDBNull(9) ? null : myReader.GetString(9); } catch (InvalidCastException) { } try { student.Email = myReader.IsDBNull(10) ? null : myReader.GetString(10); } catch (InvalidCastException) { } try { student.HouseHold = myReader.IsDBNull(11) ? null : myReader.GetString(11); } catch (InvalidCastException) { } try { student.Committee = myReader.IsDBNull(12) ? null : myReader.GetString(12); } catch (InvalidCastException) { } try { student.Paid = myReader.IsDBNull(13) ? 0 : myReader.GetInt16(13); } catch (InvalidCastException) { } } } catch (Exception) { } myConn.Close(); return student; }
public void DeleteStudent(string idNum) { MySqlConnection myConn = OpenDBConnection(); string cmd = "DELETE FROM yfc.new_student_t WHERE student_id = @StudentID"; MySqlCommand DeleteCommand = new MySqlCommand(cmd, myConn); DeleteCommand.Parameters.AddWithValue("@StudentID", int.Parse(idNum)); try { myConn.Open(); DeleteCommand.ExecuteNonQuery(); student = SearchStudent(int.Parse(idNum)); studentList.Remove(student); } catch (Exception) { } GetMemberList = studentList; }
private void txtBox_ID_EnterBtn(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { if (comboBox_Event.Text != "RecWeek") { if (db.CheckStudentID(int.Parse(txtBox_IDNum.Text)) == false) { lbl_fname.Visible = false; lbl_yandc.Visible = false; label_Name.Visible = false; label_YearCourse.Visible = false; lbl_notmember.Visible = true; lbl_notmember.Text = "Not a member yet."; lbl_notmember.Location = new Point(380, 406); btn_Register.Enabled = false; btn_Add.Show(); status = 1; } else { lbl_notmember.Visible = false; btn_Add.Hide(); lbl_fname.Visible = true; lbl_yandc.Visible = true; label_Name.Visible = true; label_YearCourse.Visible = true; btn_Register.Enabled = true; student = db.LoadFullStudentData(int.Parse(txtBox_IDNum.Text)); label_Name.Text = String.Format(student.FirstName + " " + student.LastName); label_YearCourse.Text = String.Format(student.Year + " - " + student.Course); status = 0; } } else { student = db.LoadOldStudentData(int.Parse(txtBox_IDNum.Text)); if (student.StudentID != 0) { btn_Register.Enabled = true; lbl_fname.Visible = true; lbl_yandc.Visible = true; label_Name.Visible = true; label_YearCourse.Visible = true; label_Name.Text = student.FullName; label_YearCourse.Text = String.Format(student.Year + " - " + student.Course); status = 0; } else { lbl_fname.Visible = false; lbl_yandc.Visible = false; label_Name.Visible = false; label_YearCourse.Visible = false; lbl_notmember.Visible = true; lbl_notmember.Location = new Point(220, 406); lbl_notmember.Text = "Student does not exist in the old database."; btn_Register.Enabled = false; btn_Add.Show(); status = 1; } } } catch (Exception) { } } }
public ViewStudent_Form() { InitializeComponent(); student = new Student(); db = new DBFunction(); }
private void FillForm(int id, string state) { student = new Student(); if (state == "old") { student = db.LoadOldStudentData(id); txtBox_ID.Text = student.StudentID.ToString(); string[] names = student.FullName.Split(','); txtBox_LastName.Text = names[0]; txtBox_FirstName.Text = names[1]; //student.Year = student.Year + 1; if (student.Year == "1") { comboBox_Year.Text = "Freshman"; } else if (student.Year == "2") { comboBox_Year.Text = "Sophomore"; } else if (student.Year == "3") { comboBox_Year.Text = "Junior"; } else if (student.Year == "4") { comboBox_Year.Text = "Senior"; } else { //Super Senior or Graduate comboBox_Year.Text = "Super Senior"; } txtBox_Course.Text = student.Course; } else if (state == "new") { if (db.CheckStudentID(id) == true) { student = db.LoadFullStudentData(id); txtBox_ID.Text = student.StudentID.ToString(); txtBox_LastName.Text = student.LastName; txtBox_FirstName.Text = student.FirstName; if (student.Year == "1") { comboBox_Year.Text = "Freshman"; } else if (student.Year == "2") { comboBox_Year.Text = "Sophomore"; } else if (student.Year == "3") { comboBox_Year.Text = "Junior"; } else if (student.Year == "4") { comboBox_Year.Text = "Senior"; } else { //Super Senior or Graduate comboBox_Year.Text = "Super Senior"; } txtBox_Course.Text = student.Course; if (student.Gender == 1) { comboBox_Gender.Text = "Male"; } else { comboBox_Gender.Text = "Female"; } dateTimePicker_Birthday.Text = DateTime.Now.ToString(); if (student.Member == 1) { comboBox_Member.Text = "Yes"; } else if (student.Member == 0) { comboBox_Member.Text = "No"; } if (student.OldMember == 1) { comboBox_OldMember.Text = "Yes"; } else if (student.OldMember == 0) { comboBox_OldMember.Text = "No"; } txtBox_ContactNo.Text = student.ContactNo; txtBox_Email.Text = student.Email; txtBox_Household.Text = student.HouseHold; txtBox_Commitee.Text = student.Committee; if (student.Paid == 1) { comboBox_Paid.Text = "Yes"; } else if (student.Paid == 0) { comboBox_Paid.Text = "No"; } } else { txtBox_ID.Text = id.ToString(); } } }