// ## edit /// <summary> /// The editToolStripMenuItem method will open a edit form for the /// selected course/semester element. It will update the respective /// list and viewer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editToolStripMenuItem_Click(object sender, EventArgs e) { //course if (CourseView.SelectedItems.Count == 1) { //edit the selected course CourseEdit edit = new CourseEdit(ref courseList, courseList[CourseView.SelectedItems[0].Index]); this.SuspendLayout(); edit.ShowDialog(); //update viewer updateCourseViewer(); //update prefixes updatePrefixes(); } //semester else if (SemesterViewer.SelectedItems.Count == 1) { //edit the selected semester SemesterEdit edit = new SemesterEdit(ref semesterList, semesterList[SemesterViewer.SelectedItems[0].Index]); this.SuspendLayout(); edit.ShowDialog(); //update viewer updateSemesterViewer(); } else { throw new Exception("Not Allowed!"); } }
public SemesterEdit ValidateEditSemester(Semester semester) { var model = new SemesterEdit(); Regex rgx = new Regex(@"[A-Z]+[a-z0-9 ]+$"); if (string.IsNullOrEmpty(semester.Name) || string.IsNullOrWhiteSpace(semester.Name)) { model.NameMessage = "Name is required"; model.Error = true; } else { if (!rgx.IsMatch(semester.Name)) { model.NameMessage = "Name must starts with uppercase " + "and contains at least 2 letters"; model.Error = true; } } if (string.IsNullOrEmpty(semester.StartDate) || string.IsNullOrWhiteSpace(semester.StartDate)) { model.StartDateMessage = "Start date is required"; model.Error = true; } else { try { var dateTime = DateTime.Parse(semester.StartDate); } catch { model.StartDateMessage = "Invalid start date"; model.Error = true; } } if (string.IsNullOrEmpty(semester.EndDate) || string.IsNullOrWhiteSpace(semester.EndDate)) { model.EndDateMessage = "End date is required"; model.Error = true; } else { try { var dateTime = DateTime.Parse(semester.EndDate); } catch { model.EndDateMessage = "Invalid end date"; model.Error = true; } } return(model); }