private void handleStudentDelete() { int index = studentsListBox.SelectedIndex; if (index < students.Count && index != -1) { bool isLastIndex = index == studentsListBox.Items.Count - 1; students.RemoveAt(index); StudentIO.RemoveStudent(index); if (isLastIndex) { index = index - 1; } } if (studentsListBox.SelectedIndex != -1) { studentsListBox.SelectedIndex = index; updateStudentDetails(index); toggleStudentDetailsEdit(false); } else { idDisplayText.Clear(); nameDisplayText.Clear(); classDisplayText.Clear(); sectionDisplayText.Clear(); contactDisplayText.Clear(); addressDisplayText.Clear(); editStudentButton.Enabled = false; } idText.Text = StudentIO.NextId().ToString(); }
public MainWindow() { InitializeComponent(); students = new BindingList <Student>(StudentIO.LoadStudents()); ShowData(); idText.Text = StudentIO.NextId().ToString(); editStudentButton.Enabled = false; }
private void handleLoadButtonClick() { toggleStudentDetailsEdit(false); List <Student> loadedStudents = StudentIO.LoadStudents(); if (studentsListBox.Items.Count != loadedStudents.Count) { students = new BindingList <Student>(loadedStudents); ShowData(); } idText.Text = StudentIO.NextId().ToString(); }
private void saveStudentButton_Click(object sender, EventArgs e) { toggleStudentDetailsEdit(false); updateStudentDetails(studentsListBox.SelectedIndex); int _id = StudentIO.NextId(); string _name = nameText.Text; string _class = classText.Text; string _section = sectionText.Text; string _contact = contactText.Text; string _address = addressText.Text; if (IsValid(_name) && IsValid(_class) && IsValid(_section) && IsValid(_contact) && IsValid(_address)) { Student student = new Student(_id, _name, _class, _section, _contact, _address); StudentIO.SaveStudent(student); students.Add(student); idText.Text = StudentIO.NextId().ToString(); } else { MessageBox.Show(text: "Please enter all the details!", caption: "Invalid Input Error!", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } studentsListBox.SelectedIndex = studentsListBox.Items.Count - 1; }