private void GetLoadedUnits() { DataGridViewRow dgvRow; loadedUnits = new List <UnitInCourse>(); for (int i = 0; i < DGV_DialogCourseUnit.Rows.Count; i++) { dgvRow = DGV_DialogCourseUnit.Rows[i]; if ((bool)dgvRow.Cells["Select"].FormattedValue) { UnitInCourse unitsInCourse = new UnitInCourse() { UnitCode = dgvRow.Cells["UnitCode"].Value.ToString(), CourseCode = courseCode, Core = (bool)dgvRow.Cells["Core"].Value }; loadedUnits.Add(unitsInCourse); } } }
private void BTN_DialogCourseUnitAdd_Click(object sender, EventArgs e) { int compareSemesterKey = int.Parse(cmd.GetEarliestSemesterKeyOfCourse(courseCode)); // review if (compareSemesterKey != 99999) { _ = MessageBox.Show(null, "You cannot modify a course after it has become available at a college.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = DialogResult.Cancel; return; } selectedUnits = new List <UnitInCourse>(); for (int i = 0; i < DGV_DialogCourseUnit.Rows.Count; i++) { if ((bool)DGV_DialogCourseUnit.Rows[i].Cells["Select"].FormattedValue) { UnitInCourse unitsInCourse = new UnitInCourse() { UnitCode = DGV_DialogCourseUnit.Rows[i].Cells["UnitCode"].Value.ToString(), CourseCode = courseCode, Core = (bool)DGV_DialogCourseUnit.Rows[i].Cells["Core"].FormattedValue }; selectedUnits.Add(unitsInCourse); } } var toAdd = selectedUnits .Select(o => new { o.UnitCode, o.CourseCode, o.Core, }) .Except( loadedUnits .Select(o => new { o.UnitCode, o.CourseCode, o.Core }) ); var toDelete = loadedUnits .Select(o => new { o.UnitCode, o.CourseCode, o.Core }) .Except( selectedUnits .Select(o => new { o.UnitCode, o.CourseCode, o.Core }) ); if (toAdd.Count() < 1 && toDelete.Count() < 1) { _ = MessageBox.Show(null, "No modifications have been made.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } List <UnitInCourse> a = new List <UnitInCourse>(); List <UnitInCourse> d = new List <UnitInCourse>(); if (toAdd.Count() > 0) { foreach (var item in toAdd) { a.Add(new UnitInCourse { UnitCode = item.UnitCode, CourseCode = item.CourseCode, Core = item.Core }); } } if (toDelete.Count() > 0) { foreach (var item in toDelete) { d.Add(new UnitInCourse { UnitCode = item.UnitCode, CourseCode = item.CourseCode, Core = item.Core }); } } if (cmd.ModifyUnitInCourse(a, d)) { if (mainForm.TABCTRL_Main.SelectedTab.Text.Equals("Courses")) { mainForm.GetView("Courses"); } else if (mainForm.TABCTRL_Main.SelectedTab.Text.Equals("Course Assigned Units")) { mainForm.GetView("Course Assigned Units"); } } }