public StudentRegistrationMainForm()
        {
            InitializeComponent();

            this.Text = "Student Registration using AddUpdate Forms";

            context = new StudentRegistrationEntities();
            context.Database.Log = (s => Debug.Write(s));
            context.SeedDatabase();
            context.SaveChanges();

            this.Load += (s, e) => StudentRegistratioMainForm_Load();

            // set the event handlers for buttons

            AddOrUpdateStudent addOrUpdateStudentForm = new AddOrUpdateStudent();

            buttonStudent.Click += (s, e) => AddOrUpdateForm <Student>(dataGridViewStudent, addOrUpdateStudentForm);

            AddOrUpdateDepartment addOrUpdateDepartmentForm = new AddOrUpdateDepartment();

            buttonDepartment.Click += (s, e) => AddOrUpdateForm <Department>(dataGridViewDepartment, addOrUpdateDepartmentForm);

            AddOrUpdateCourse addOrUpdateCourseForm = new AddOrUpdateCourse();

            buttonCourse.Click += (s, e) => AddOrUpdateForm <Course>(dataGridViewCourse, addOrUpdateCourseForm);

            buttonRegister.Click += ButtonRegister_Click;
            buttonDrop.Click     += ButtonDrop_Click;
        }
 /// <summary>
 /// Method to load all datagridviews and seed the initial database
 /// </summary>
 private void StudentRegistrationAppMainForm_Load()
 {
     // using the Unit-of-work context
     // seed the database
     using (StudentRegistrationEntities context = new StudentRegistrationEntities())
     {
         context.SeedDatabase();
     }
     // common setup for datagridview controls
     InitializeDataGridView <Student>(dataGridViewStudents, "Courses", "Department");
     InitializeDataGridView <Course>(dataGridViewCourses, "Students", "Department");
     InitializeDataGridView <Department>(dataGridViewDepartments, "Courses", "Students");
     // set up the registration view using a custom method
     InitializeRegistrationView(dataGridViewRegistrations);
 }
        public MainForm()
        {
            InitializeComponent();

            this.Text = "Student Using Add/Update Forms App using EF Code First from DB library";

            context = new StudentRegistrationEntities();
            context.Database.Log = (s => Debug.Write(s));
            context.SeedDatabase();
            context.SaveChanges();

            this.Load += (s, e) => MainForm_Load();

            StudentForm studentForm = new StudentForm();

            buttonStudent.Click += (s, e) => AddOrUpdateForm <Student>(dataGridViewStudents, studentForm);

            DepartmentForm departmentForm = new DepartmentForm();

            buttonDepartment.Click += (s, e) => AddOrUpdateForm <Department>(dataGridViewDepartment, departmentForm);
        }