private void ImportButton_Click(object sender, EventArgs e) { StudentServices service = new StudentServices(); int i = 0; if (listViewInfo == ListViewInfo.Students) { try { service.InsertClassToDB(currClass); Classes.Items.Add(currClass); foreach (Information data in FileData) { try { service.InsertStudentToDB(data, currClass); i++; } catch (Exception ex) { MessageBox.Show($"Student with ID '{data.Id}' cannot be imported!!" + Environment.NewLine + ex.Message); } } } catch (Exception ex) { MessageBox.Show($"Class '{currClass}' cannot be imported!!" + Environment.NewLine + ex.Message); } NotiLabel.Text = $"{i} student(s) have been imported to class '{currClass}' successfully."; } else if (listViewInfo == ListViewInfo.Schedule) { try { service.InsertClassToDB(currClass); Classes.Items.Add(currClass); } catch { } foreach (Information data in FileData) { try { service.InsertScheduleToDB(data, currClass); i++; } catch (Exception ex) { MessageBox.Show($"Subject with ID '{data.Id}' cannot be imported!!" + Environment.NewLine + ex.Message); } } NotiLabel.Text = $"{i} subject(s) from schedule have been imported for class '{currClass}' successfully."; } else if (listViewInfo == ListViewInfo.Scoreboard) { try { service.InsertClassToDB(currClass); Classes.Items.Add(currClass); } catch { } foreach (Information data in FileData) { try { if (service.InsertScoreToDB(data, currClass, currSubject)) { i++; } else { MessageBox.Show($"Score of student with ID '{data.Id}' cannot be imported!!"); } } catch (Exception ex) { MessageBox.Show($"Score of student with ID '{data.Id}' cannot be imported!!" + Environment.NewLine + ex.Message); } } NotiLabel.Text = $"{i} student(s)' score have been imported for class '{currClass}' successfully."; } ImportButton.Enabled = false; }