private void populateCurriculums() { LookupDepartment currentDepartment = (LookupDepartment)lookupDepartmentBindingSource.Current; curriculumBindingSource.DataSource = (from a in currentDepartment.Curriculums select a).ToList <Curriculum>(); }
private void btnAddDepartment_Click(object sender, EventArgs e) { using (var DbConnection = new MCDEntities()) { LookupDepartment newDep = new LookupDepartment() { DepartmentName = this.txtAddDepartment.Text.ToString() }; DbConnection.LookupDepartments.Add(newDep); DbConnection.SaveChanges(); this.Close(); } }
private void btnAddCourse_Click(object sender, EventArgs e) { LookupDepartment CurrentDepartment = (LookupDepartment)lookupDepartmentBindingSource.Current; int AmountCouresesTheSame = (from a in CurrentDepartment.Courses where a.CourseName.ToLower().Contains(txtNewCourse.Text.ToLower()) select a).Count <Course>(); if (AmountCouresesTheSame == 0) { try { using (var Dbconnection = new MCDEntities()) { Course newCourse = new Course() { DepartmentID = Convert.ToInt32(cboDepartment.SelectedValue), CourseName = txtNewCourse.Text, CourseDescription = txtNewCourseDescription.Text }; Dbconnection.Courses.Add(newCourse); Dbconnection.SaveChanges(); CurrentDepartment.Courses.Add(newCourse); this.populateCourses(); }; } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (DbUpdateException dbEx) { MessageBox.Show(dbEx.Message); } } else { MessageBox.Show(txtNewCourse.Text + " - Already Exisits For this Department.", "Add Course Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgvEnrollmentApplications_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { var gridView = (DataGridView)sender; foreach (DataGridViewRow row in gridView.Rows) { if (!row.IsNewRow) { var EnrollmentObj = (Enrollment)(row.DataBoundItem); Curriculum CurriculumObj = EnrollmentObj.Curriculum; LookupDepartment DepartmentObj = CurriculumObj.LookupDepartment; ApprienticeshipEnrollment ApprienticeshipEnrollmentObj = EnrollmentObj.ApprienticeshipEnrollment; LookupSectionalEnrollmentType LookupSectionalEnrollmentTypeObj = ApprienticeshipEnrollmentObj.LookupSectionalEnrollmentType; row.Cells[CurriculumName.Index].Value = CurriculumObj.CurriculumName; row.Cells[Department.Index].Value = DepartmentObj.DepartmentName; row.Cells[EnrollmentType.Index].Value = LookupSectionalEnrollmentTypeObj.LookupSectionalEnrollmentTypeName; } } }