private void populateLinkedCurriculumCourses()
        {
            using (var Dbconnection = new MCDEntities())
            {
                List <CurriculumCourse> AllItems = (from a1 in Dbconnection.GetCurriculumCourseInOrder(CurrentEnrollemnt.CurriculumID)
                                                    select a1).Intersect(from a2 in Dbconnection.CurriculumCourseEnrollments
                                                                         where a2.EnrollmentID == CurrentEnrollemnt.EnrollmentID
                                                                         select a2.CurriculumCourse)
                                                   .ToList <CurriculumCourse>();

                curriculumCourseLinkedBindingSource.DataSource = (from a in AllItems
                                                                  orderby a.Course.CourseName
                                                                  select a).ToList();

                foreach (CurriculumCourse CurriculumCourseObj in curriculumCourseLinkedBindingSource.List)
                {
                    if (!Dbconnection.Entry(CurriculumCourseObj).Reference(a => a.Course).IsLoaded)
                    {
                        Dbconnection.Entry(CurriculumCourseObj).Reference(a => a.Course).Load();
                    }
                    if (!Dbconnection.Entry(CurriculumCourseObj).Collection(a => a.CurriculumCourseEnrollments).IsLoaded)
                    {
                        Dbconnection.Entry(CurriculumCourseObj).Collection(a => a.CurriculumCourseEnrollments).Load();
                    }
                }
            };
        }
        private void btnPropcessException_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                try
                {
                    Dbconnection.Enrollments.Attach(SelectedEnrollment);
                    SelectedEnrollment.LookupEnrollmentProgressStateID = (int)EnumEnrollmentProgressStates.Excempt;
                    Dbconnection.Entry(SelectedEnrollment).State       = System.Data.Entity.EntityState.Modified;
                    Dbconnection.SaveChanges();

                    EquiryHistory hist = new EquiryHistory
                    {
                        EnquiryID  = EnquiryID,
                        EmployeeID = this.CurrentEmployeeLoggedIn.EmployeeID,
                        LookupEquiyHistoryTypeID = (int)EnumEquiryHistoryTypes.Enrollment_Course_PreRequisite_Was_Except,
                        DateEnquiryUpdated       = DateTime.Now,
                        EnquiryNotes             = "For Enrollment : " + EnquiryID.ToString() + "\n\nThe following Curriculum: " + SelectedEnrollment.Curriculum.CurriculumName.ToString() + " Has Been Excempt.\n\nEnrollment Ref:\n" + SelectedEnrollment.EnrollmentID + "\n\nNotes:" + txtExceptionNotes.Text.ToString()
                    };
                    Dbconnection.EquiryHistories.Add(hist);
                    int IsSaved = Dbconnection.SaveChanges();
                    //SelectedEnrollment.LookupEnrollmentProgressState = null;
                    Dbconnection.Entry(SelectedEnrollment).Reference("LookupEnrollmentProgressState").Load();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.Close();
                }
            };
        }
        private void btnUpdateContactDetials_Click(object sender, EventArgs e)
        {
            using (frmAddUpdateContactDetails frm = new frmAddUpdateContactDetails(0))
            {
                ContactDetail CurrentDetail = (ContactDetail)contactDetailBindingSource.Current;
                frm.CurrentDetail   = CurrentDetail;
                frm.ContactDetailID = CurrentDetail.ContactDetailID;

                Individual CurrentContact = (Individual)individualBindingSource.Current;

                frm.ShowDialog();
                if (frm.CurrentDetail != null)
                {
                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.ContactDetails.Attach(CurrentDetail);

                        Dbconnection.Entry(CurrentDetail).State = EntityState.Modified;

                        Dbconnection.SaveChanges();

                        Dbconnection.Entry(frm.CurrentDetail).Reference("LookupContactType").Load();
                    };
                    this.refreshContactDetails();
                }
            }
        }
Exemple #4
0
        private void btnAddStudentAddress_Click(object sender, EventArgs e)
        {
            frmAddUpdateAddresses frm = new frmAddUpdateAddresses(0);

            frm.ShowDialog();
            if (frm.CurrentAddress != null)
            {
                if (frm.CurrentAddress.AddressID != 0)
                {
                    using (var Dbconnection = new MCDEntities())
                    {
                        Data.Models.Company CurrentCompany = ((Data.Models.Company)companyBindingSource.Current);
                        Dbconnection.Companies.Attach(CurrentCompany);
                        Dbconnection.Addresses.Attach(frm.CurrentAddress);

                        CurrentCompany.Addresses.Add(frm.CurrentAddress);

                        Dbconnection.SaveChanges();
                        Dbconnection.Entry(frm.CurrentAddress).Reference("LookupAddressType").Load();
                        Dbconnection.Entry(frm.CurrentAddress).Reference("LookupProvince").Load();
                        Dbconnection.Entry(frm.CurrentAddress).Reference("LookupCountry").Load();
                    };
                    refreshCompanyAddresses();
                }
            }
        }
        private void btnStudentAddressAddUpdate_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                if (CurrentAddress != null)
                {
                    Dbconnection.Addresses.Attach(CurrentAddress);

                    CurrentAddress.AddressTypeID    = Convert.ToInt32(cboStudentAddressAddressType.SelectedValue);
                    CurrentAddress.AddressIsDefault = chkStudnetAddressIsDefault.Checked;
                    CurrentAddress.CountryID        = Convert.ToInt32(cboStudentAddressCountry.SelectedValue);
                    CurrentAddress.ProvinceID       = Convert.ToInt32(cboStudentAddressProvince.SelectedValue);
                    CurrentAddress.AddressLineTwo   = txtStudentAddressLineTwo.Text.ToString();
                    CurrentAddress.AddressLineOne   = txtStudentAddressLineOne.Text.ToString();
                    CurrentAddress.AddressTown      = txtStudentAddressTown.Text.ToString();
                    CurrentAddress.AddressSuburb    = txtStudentAddressSuburb.Text.ToString();
                    CurrentAddress.AddressAreaCode  = txtStudentAddressAreaCode.Text.ToString();

                    Dbconnection.SaveChanges();

                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupAddressType).Load();
                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupProvince).Load();
                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupCountry).Load();
                }
                ;
            };
            this.Close();
        }
        private void btnStudentAddressAddUpdate_Click(object sender, EventArgs e)
        {
            //using (var Dbconnection = new MCDEntities())
            //{
            //    Address AddressToUpdate = (from a in Dbconnection.Addresses
            //                               where a.AddressID == this.AddressID
            //                               select a).FirstOrDefault<Address>();

            //    AddressToUpdate.AddressTypeID = Convert.ToInt32(cboStudentAddressAddressType.SelectedValue);
            //    AddressToUpdate.AddressIsDefault = chkStudnetAddressIsDefault.Checked;
            //    AddressToUpdate.CountryID = Convert.ToInt32(cboStudentAddressCountry.SelectedValue);
            //    AddressToUpdate.ProvinceID = Convert.ToInt32(cboStudentAddressProvince.SelectedValue);
            //    AddressToUpdate.AddressLineTwo = txtStudentAddressLineTwo.Text.ToString();
            //    AddressToUpdate.AddressLineOne = txtStudentAddressLineOne.Text.ToString();
            //    AddressToUpdate.AddressTown = txtStudentAddressTown.Text.ToString();
            //    AddressToUpdate.AddressSuburb = txtStudentAddressSuburb.Text.ToString();
            //    AddressToUpdate.AddressAreaCode = txtStudentAddressAreaCode.Text.ToString();
            //    AddressToUpdate.AddressModifiedDate = DateTime.Now;

            //    Dbconnection.SaveChanges();

            //    Dbconnection.Entry(AddressToUpdate).Reference(a => a.LookupAddressType).Load();
            //    Dbconnection.Entry(AddressToUpdate).Reference(a => a.LookupProvince).Load();
            //    Dbconnection.Entry(AddressToUpdate).Reference(a => a.LookupCountry).Load();


            //};

            using (var Dbconnection = new MCDEntities())
            {
                if (CurrentAddress != null)
                {
                    Dbconnection.Addresses.Attach(CurrentAddress);

                    CurrentAddress.AddressTypeID    = Convert.ToInt32(cboStudentAddressAddressType.SelectedValue);
                    CurrentAddress.AddressIsDefault = chkStudnetAddressIsDefault.Checked;
                    CurrentAddress.CountryID        = Convert.ToInt32(cboStudentAddressCountry.SelectedValue);
                    CurrentAddress.ProvinceID       = Convert.ToInt32(cboStudentAddressProvince.SelectedValue);
                    CurrentAddress.AddressLineTwo   = txtStudentAddressLineTwo.Text.ToString();
                    CurrentAddress.AddressLineOne   = txtStudentAddressLineOne.Text.ToString();
                    CurrentAddress.AddressTown      = txtStudentAddressTown.Text.ToString();
                    CurrentAddress.AddressSuburb    = txtStudentAddressSuburb.Text.ToString();
                    CurrentAddress.AddressAreaCode  = txtStudentAddressAreaCode.Text.ToString();

                    Dbconnection.SaveChanges();

                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupAddressType).Load();
                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupProvince).Load();
                    Dbconnection.Entry(CurrentAddress).Reference(a => a.LookupCountry).Load();
                }
                ;
            };
            this.Close();
        }
Exemple #7
0
        private void picSearchStudents_Click(object sender, EventArgs e)
        {
            List <Student> StudentExcemptionList = new List <Student>();

            using (var Dbconnection = new MCDEntities())
            {
                //Loadds the associated Collections in this case the Enrollment with their associated Students that are enrolled.
                Dbconnection.CurriculumEnquiries.Attach(CurrentCurriculumEnquiry);
                //Load all enrollments that linked to the Enquiry Item.
                Dbconnection.Entry(CurrentCurriculumEnquiry).Collection(a => a.Enrollments).Load();
                foreach (Enrollment EnrollmentObj in CurrentCurriculumEnquiry.Enrollments)
                {
                    //Load the student linked to the enrollment
                    Dbconnection.Entry(EnrollmentObj).Reference(a => a.Student).Load();
                    StudentExcemptionList.Add(EnrollmentObj.Student);
                }
            };
            using (frmStudentSearchForStudent frm = new frmStudentSearchForStudent())
            {
                //Set the list of student that are already Enrolled for this Enquiry Item.
                frm.StudentExpceptionList = StudentExcemptionList;
                frm.ShowDialog();
                if (frm.CurrentSelectedStudent != null)
                {
                    txtStudentFullName.Text = frm.CurrentSelectedStudent.Individual.FullName;
                    txtStudentIdNumber.Text = frm.CurrentSelectedStudent.StudentIDNumber;
                    txtStudentNember.Text   = frm.CurrentSelectedStudent.StudentID.ToString();
                    CurrentSelectedStudent  = frm.CurrentSelectedStudent;
                    //Summary Fields
                    txtSummaryFullName.Text          = txtStudentFullName.Text;
                    txtSummaryIDNumber.Text          = txtStudentIdNumber.Text;
                    txtSummaryStudentNumber.Text     = txtStudentNember.Text;
                    picbtnEditCurrentStudent.Visible = true;
                }
                else
                {
                    picbtnEditCurrentStudent.Visible = false;
                    txtStudentFullName.Clear();
                    txtStudentIdNumber.Clear();
                    txtStudentNember.Clear();
                    //Summary Fields
                    txtSummaryFullName.Clear();
                    txtSummaryIDNumber.Clear();
                    txtSummaryStudentNumber.Clear();
                    CurrentSelectedStudent = null;
                }
            };
        }
        private void btnSearchForCompany_Click(object sender, EventArgs e)
        {
            using (frmCompanySearch frm = new frmCompanySearch())
            {
                frm.ShowDialog();
                if (frm.CurrentCompany != null)
                {
                    //this.CurrentScheduleConfiguration.Clear();
                    CurrentlySelectedCompany = frm.CurrentCompany;

                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.Companies.Attach(CurrentlySelectedCompany);

                        Dbconnection.Entry(CurrentlySelectedCompany).Collection(a => a.Addresses).Load();
                    };
                    companyBindingSource.DataSource = CurrentlySelectedCompany;

                    addressBindingSource.DataSource = (from a in CurrentlySelectedCompany.Addresses
                                                       select a).ToList <Data.Models.Address>();
                }
                else
                {
                    companyBindingSource.DataSource = null;

                    addressBindingSource.DataSource = null;
                    //this.CurrentScheduleConfiguration.Companies.Clear();
                }
            };
            this.refreshCompanyInfo();
        }
Exemple #9
0
        private void btnUpdateEmployee_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                Dbconnection.Employees.Attach(CurrentEmployee);

                CurrentEmployee.EmployeeNumber                  = txtEmployeeNumber.Text.ToString();
                CurrentEmployee.Individual.TitleID              = Convert.ToInt32(this.cboEmployeeTitle.SelectedValue);
                CurrentEmployee.Individual.IndividualFirstName  = txtEmployeeFirstName.Text.ToString();
                CurrentEmployee.Individual.IndividualSecondName = txtEmployeeSecondName.Text.ToString();
                CurrentEmployee.Individual.IndividualLastname   = txtEmployeeLastName.Text.ToString();



                Dbconnection.Entry <Employee>(CurrentEmployee).State = System.Data.Entity.EntityState.Modified;

                Dbconnection.SaveChanges();

                //Dbconnection.Entry(CurrentEmployee).Reference(a => a.Individual.LookupTitle).Load();
                //Dbconnection.Entry(CurrentEmployee).Reference(a => a.LookupProvince).Load();
                //Dbconnection.Entry(CurrentEmployee).Reference(a => a.LookupCountry).Load();
            };

            this.Close();
        }
        private void btnRemoveStudentIDDocuments_Click(object sender, EventArgs e)
        {
            DialogResult Rtn = MessageBox.Show("Are You Sure You Wish To Remove This File?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (Rtn == DialogResult.Yes)
            {
                Data.Models.File FileToRemove = (Data.Models.File)fileStudentIDDocumentBindingSource.Current;

                using (var Dbconnection = new MCDEntities())
                {
                    //Data.Models.File x = (from a in Dbconnection.Files
                    //                      where a.)
                    List <StudentIDDocument> x = (from a in Dbconnection.StudentIDDocuments
                                                  where a.FileID == FileToRemove.FileID
                                                  select a).ToList <StudentIDDocument>();
                    foreach (StudentIDDocument doc in x)
                    {
                        Dbconnection.Entry(doc).State = EntityState.Deleted;
                    }

                    Dbconnection.SaveChanges();
                };
                this.refreshStudentIDDocumnets();
            }
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (var Dbconnection = new MCDEntities())
     {
         string InitialConsultationText = "None or No Notes where documented.";
         if (txtNotes.Text.Length > 0)
         {
             InitialConsultationText = txtNotes.Text;
         }
         EquiryHistory hist = new EquiryHistory
         {
             EnquiryID  = CurrentEnquiry.EnquiryID,
             EmployeeID = this.EmployeeID,
             LookupEquiyHistoryTypeID = (int)EnumEquiryHistoryTypes.Enquiry_Initial_Consultation_Completed,
             DateEnquiryUpdated       = DateTime.Now,
             EnquiryNotes             = InitialConsultationText
         };
         Dbconnection.EquiryHistories.Add(hist);
         int IsSaved = Dbconnection.SaveChanges();
         if (IsSaved > 0)
         {
             Dbconnection.Enquiries.Attach(CurrentEnquiry);
             CurrentEnquiry.InitialConsultationComplete = true;
             Dbconnection.Entry <Data.Models.Enquiry>(CurrentEnquiry).State = System.Data.Entity.EntityState.Modified;
             Dbconnection.SaveChanges();
         }
     };
     this.Close();
 }
Exemple #12
0
        private void btnUpdateContact_Click(object sender, EventArgs e)
        {
            Individual IndividualToUpdate = null;

            using (var Dbconnection = new MCDEntities())
            {
                IndividualToUpdate = (from a in Dbconnection.Individuals
                                      where a.IndividualID == IndividualID
                                      select a).FirstOrDefault <Individual>();
                IndividualToUpdate.TitleID              = Convert.ToInt32(cboIndividualTitle.SelectedValue);
                IndividualToUpdate.IndividualFirstName  = txtFirstName.Text.ToString();
                IndividualToUpdate.IndividualSecondName = txtSecondName.Text.ToString();
                IndividualToUpdate.IndividualLastname   = txtLastName.Text.ToString();
                Dbconnection.SaveChanges();
                Dbconnection.Entry(IndividualToUpdate).Reference(a => a.LookupTitle).Load();
            };
            if (CurrentContact != null)
            {
                CurrentContact.TitleID              = Convert.ToInt32(cboIndividualTitle.SelectedValue);
                CurrentContact.IndividualFirstName  = txtFirstName.Text.ToString();
                CurrentContact.IndividualSecondName = txtSecondName.Text.ToString();
                CurrentContact.IndividualLastname   = txtLastName.Text.ToString();

                CurrentContact.LookupTitle = IndividualToUpdate.LookupTitle;
            }
            this.Close();
        }
        private void btnAddNewContactDetails_Click(object sender, EventArgs e)
        {
            if (CurrentEnquiry.Individuals.Count > 0)
            {
                frmAddUpdateContactDetails frm = new frmAddUpdateContactDetails(0);
                Individual CurrentContact      = CurrentEnquiry.Individuals.FirstOrDefault <Individual>();

                frm.ShowDialog();
                if (frm.CurrentDetail != null)
                {
                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.Individuals.Attach(CurrentContact);

                        Dbconnection.ContactDetails.Attach(frm.CurrentDetail);

                        CurrentContact.ContactDetails.Add(frm.CurrentDetail);

                        Dbconnection.SaveChanges();

                        Dbconnection.Entry(frm.CurrentDetail).Reference("LookupContactType").Load();
                    };
                    this.refreshContactDetails();
                }
            }
        }
        private Boolean DetermineIfAllPreRequisiteCourseHaveBeenScheduled(int _CurriculumCourseID, int _EnrollmentID)
        {
            Boolean Rtn = true;
            IEnumerable <CurriculumCourse> PreRequisiteCoursesNotScheduled;

            using (var Dbconnection = new MCDEntities())
            {
                PreRequisiteCoursesNotScheduled = (from a in Dbconnection.GetCurriculumCoursePreRequisiteCourseNotYetScheduled(_CurriculumCourseID, _EnrollmentID)
                                                   select a)
                                                  .ToList <CurriculumCourse>();

                if (PreRequisiteCoursesNotScheduled.Count <CurriculumCourse>() > 0)
                {
                    int iCounter = 1;
                    Rtn = false;
                    String ErrorMessage = "Before proceeding to schedule this course please schedule the following course first, as these are Pre-Requisite Courses for the currently selected course:\n\n";
                    foreach (CurriculumCourse CC in PreRequisiteCoursesNotScheduled)
                    {
                        Dbconnection.Entry(CC).Reference(a => a.Course).Load();
                        ErrorMessage += iCounter + " - " + CC.Course.CourseName + "\n";
                        iCounter++;
                    }
                    MessageBox.Show(ErrorMessage, "Pre-Requisite Course To Schedule", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            };


            return(Rtn);
        }
        private void dgvClientFullName_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            var gridView = (DataGridView)sender;

            foreach (DataGridViewRow row in gridView.Rows)
            {
                if (!row.IsNewRow)
                {
                    Individual IndividualObj = (Individual)(row.DataBoundItem);

                    if (IndividualObj.Companies == null)
                    {
                        using (var Dbconnection = new MCDEntities())
                        {
                            Dbconnection.Configuration.LazyLoadingEnabled = false;
                            Dbconnection.Individuals.Attach(IndividualObj);
                            Dbconnection.Entry(IndividualObj).Collection(a => a.Companies).Load();
                        };
                    }
                    if (IndividualObj.Companies != null)
                    {
                        if (IndividualObj.Companies.Count > 0)
                        {
                            row.Cells[colContactCompany.Index].Value = IndividualObj.Companies.FirstOrDefault().CompanyName.ToString();
                        }
                        else
                        {
                            row.Cells[colContactCompany.Index].Value = "NA - Private Client";
                        }
                    }
                }
            }
        }
        private void btnAddContactInfo_Click(object sender, EventArgs e)
        {
            using (frmAddUpdateContactDetails frm = new frmAddUpdateContactDetails(0))
            {
                Individual CurrentContact = (Individual)individualBindingSource.Current;

                frm.ShowDialog();
                if (frm.CurrentDetail != null)
                {
                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.Individuals.Attach(CurrentContact);

                        Dbconnection.ContactDetails.Attach(frm.CurrentDetail);

                        CurrentContact.ContactDetails.Add(frm.CurrentDetail);

                        Dbconnection.SaveChanges();

                        Dbconnection.Entry(frm.CurrentDetail).Reference("LookupContactType").Load();
                    };
                    this.refreshContactDetails();
                }
            }
        }
        private void btnUpdateCurriculumEnquiryItemEnrollmentQty_Click(object sender, EventArgs e)
        {
            using (frmUpdateSelectedCurriculumEnrollQty frm = new frmUpdateSelectedCurriculumEnrollQty())
            {
                CurriculumEnquiry CE = (CurriculumEnquiry)curriculumEnquiryInprogressBindingSource.Current;

                using (var Dbconnection = new MCDEntities())
                {
                    Data.Models.Enquiry EnquiryObj = (Data.Models.Enquiry)enquiryInprogressBindingSource.Current;
                    Dbconnection.Enquiries.Attach(EnquiryObj);

                    Dbconnection.Entry(CE).Collection(a => a.Enrollments).Load();

                };

                frm.nudQtyToEnroll.Minimum = CE.Enrollments.Count + 1;
                frm.nudQtyToEnroll.Value = CE.Enrollments.Count + 1;
                frm.CurrentCurriculumEnquiry = CE;
                frm.ShowDialog();
                //any change to the Qty will be saved.
                using (var Dbconnection = new MCDEntities())
                {
                    Dbconnection.CurriculumEnquiries.Attach(CE);
                    Dbconnection.Entry(CE).State = EntityState.Modified;
                    Dbconnection.SaveChanges();
                };
                this.curriculumEnquiryInprogressBindingSource.ResetCurrentItem();
                //this.refreshInProgressEnquiry(CurrentSelectedEnquiryID);
            }
        }
Exemple #18
0
        private void btnAddContactDetail_Click(object sender, EventArgs e)
        {
            using (frmAddUpdateContactDetails frm = new frmAddUpdateContactDetails(0))
            {
                Individual CurrentContact = (Individual)((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Individuals.FirstOrDefault <Individual>();

                frm.ShowDialog();
                if (frm.CurrentDetail != null)
                {
                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.Individuals.Attach(CurrentContact);

                        ContactDetail Con = new ContactDetail
                        {
                            ContactTypeID      = frm.CurrentDetail.ContactTypeID,
                            ContactDetailValue = frm.CurrentDetail.ContactDetailValue
                        };

                        Dbconnection.ContactDetails.Attach(frm.CurrentDetail);

                        Dbconnection.Entry(frm.CurrentDetail).Reference(a => a.LookupContactType).Load();
                        CurrentContact.ContactDetails.Add(frm.CurrentDetail);

                        Dbconnection.SaveChanges();
                    };
                    // refreshInProgressEnquiry(CurrentSelectedEnquiryID);
                }
            }
        }
        private void tbnRemoveCourse_Click(object sender, EventArgs e)
        {
            dgvLinkedCourses.EndEdit();
            using (var Dbconnection = new MCDEntities())
            {
                List <FacilitatorAssociatedCourse> CoursesToBeRemoved = new List <FacilitatorAssociatedCourse>();

                foreach (DataGridViewRow currentRow in dgvLinkedCourses.Rows)
                {
                    DataGridViewCheckBoxCell chk = currentRow.Cells[chkItemToReomve.Index] as DataGridViewCheckBoxCell;

                    if (chk.Value != null)
                    {
                        Course CurrentCourse = (Course)currentRow.DataBoundItem;

                        FacilitatorAssociatedCourse LinkedFacilitatorCourse = (from a in CurrentCourse.FacilitatorAssociatedCourses
                                                                               where
                                                                               a.CourseID == CurrentCourse.CourseID &&
                                                                               a.IndividualID == currentFacilitator.FacilitatorID
                                                                               select a).FirstOrDefault <FacilitatorAssociatedCourse>();
                        Dbconnection.Entry(LinkedFacilitatorCourse).State = System.Data.Entity.EntityState.Deleted;
                        Dbconnection.SaveChanges();
                        //Dbconnection.FacilitatorAssociatedCourses.Attach(LinkedFacilitatorCourse);
                        //CoursesToBeRemoved.Add(LinkedFacilitatorCourse);
                    }
                }

                //Dbconnection.FacilitatorAssociatedCourses.RemoveRange(CoursesToBeRemoved);
                Dbconnection.SaveChanges();
            }
            refreshAvailableCourses();
            refreshLinkedCourses();
        }
Exemple #20
0
        private void btnUpdateCompanyDetails_Click(object sender, EventArgs e)
        {
            Data.Models.Company CompanyToUpdate = (Data.Models.Company)companyBindingSource.Current;
            CompanyToUpdate.CompanySARSLevyRegistrationNumber = this.txtSARSLevyRegistration.Text.ToString();
            CompanyToUpdate.CompanySETANumber = this.txtCompanySETANumber.Text.ToString();
            CompanyToUpdate.CompanySicCode    = this.txtSicCode.Text.ToString();
            this.UpdateCompanyContactDetails(CompanyToUpdate);

            using (var Dbconnection = new MCDEntities())
            {
                Dbconnection.Companies.Attach(CompanyToUpdate);
                Dbconnection.Entry(CompanyToUpdate).State = System.Data.Entity.EntityState.Modified;
                foreach (ContactDetail contactDetailToUpdate in CompanyToUpdate.ContactDetails)
                {
                    Dbconnection.Entry(contactDetailToUpdate).State = System.Data.Entity.EntityState.Modified;
                }
                Dbconnection.SaveChanges();
            };
        }
Exemple #21
0
        private void btnUpdateCompanyInfo_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = Dbconnection.Database.BeginTransaction())
                {
                    try
                    {
                        //CRUD Operations
                        Data.Models.Company UpdateCompany = (from a in Dbconnection.Companies

                                                             where a.CompanyID == CurrentlySelectedCompany.CompanyID
                                                             select a)

                                                            .FirstOrDefault <Data.Models.Company>();

                        UpdateCompany.CompanyName       = txtCompanyName.Text;
                        UpdateCompany.CompanySETANumber = txtSETANumber.Text;
                        UpdateCompany.CompanySicCode    = txtSiCode.Text;
                        UpdateCompany.CompanySARSLevyRegistrationNumber = txtSARSLevyReg.Text;
                        Dbconnection.Entry(UpdateCompany).State         = EntityState.Modified;



                        ////saves all above operations within one transaction
                        Dbconnection.SaveChanges();

                        //commit transaction
                        dbTran.Commit();
                    }
                    catch (Exception ex)
                    {
                        if (ex is DbEntityValidationException)
                        {
                            foreach (DbEntityValidationResult entityErr in ((DbEntityValidationException)ex).EntityValidationErrors)
                            {
                                foreach (DbValidationError error in entityErr.ValidationErrors)
                                {
                                    MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        //Rollback transaction if exception occurs
                        dbTran.Rollback();
                    }
                }
            };
        }
        private void btnUpdateMessage_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                Dbconnection.MessageTemplates.Attach(CurrentMessageTemplate);
                CurrentMessageTemplate.Message = txtMessage.Text.ToString();
                Dbconnection.Entry(CurrentMessageTemplate).State = System.Data.Entity.EntityState.Modified;

                Dbconnection.SaveChanges();

                MessageBox.Show("Template Updated!", "Update Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            };
        }
Exemple #23
0
 private void populateLinkedCurriculumCourses()
 {
     using (var Dbconnection = new MCDEntities())
     {
         curriculumCourseLinkedBindingSource.DataSource = (from a1 in Dbconnection.GetCurriculumCourseInOrder(CurrentEnrollemnt.CurriculumID)
                                                           select a1).Intersect(from a2 in Dbconnection.CurriculumCourseEnrollments
                                                                                where a2.EnrollmentID == CurrentEnrollemnt.EnrollmentID
                                                                                select a2.CurriculumCourse)
                                                          .ToList <CurriculumCourse>();
         foreach (CurriculumCourse CurriculumCourseObj in curriculumCourseLinkedBindingSource.List)
         {
             Dbconnection.Entry(CurriculumCourseObj).Reference("Course").Load();
             Dbconnection.Entry(CurriculumCourseObj).Collection("CurriculumCourseEnrollments").Load();
         }
         //curriculumCourseLinkedBindingSource.DataSource = (from a in Dbconnection.CurriculumCourseEnrollments
         //                                                  where a.EnrollmentID == CurrentEnrollemnt.EnrollmentID
         //                                                  select a.CurriculumCourse)
         //                                                  .Include("Course")
         //                                                  .Include("CurriculumCourseEnrollments")
         //                                                  .ToList<CurriculumCourse>();
     };
 }
        private void AddCurriculumCoursePreRequesiteCourse(int _CurrCourseParentID, int _CurrCourseChildID)
        {
            using (var Dbconnection = new MCDEntities())
            {
                CurriculumCourse currCourseObj = (from a in Dbconnection.CurriculumCourses
                                                  where a.CurriculumCourseID == _CurrCourseChildID
                                                  select a).FirstOrDefault <CurriculumCourse>();

                currCourseObj.CurriculumCourseParentID  = _CurrCourseParentID;
                Dbconnection.Entry(currCourseObj).State = System.Data.Entity.EntityState.Modified;
                Dbconnection.SaveChanges();
            };
        }
        private void btnUpdateVenueFromForm_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = Dbconnection.Database.BeginTransaction())
                {
                    try
                    {
                        //CRUD Operations
                        Venue CurrentVenue  = (Venue)venueBindingSource.Current;
                        Venue VenueToUpdate = Dbconnection.Venues.Where(a => a.VenueID == CurrentVenue.VenueID).FirstOrDefault();
                        VenueToUpdate.VenueName                 = this.txtVenueName.Text;
                        VenueToUpdate.VenueMaxCapacity          = (int)this.nudAddUpdateVenueCapacity.Value;
                        Dbconnection.Entry(VenueToUpdate).State = EntityState.Modified;

                        //CurrentVenue.VenueName = this.txtVenueName.Text;
                        //CurrentVenue.VenueMaxCapacity = (int)this.nudAddUpdateVenueCapacity.Value;
                        //Dbconnection.Entry(CurrentVenue).State = System.Data.Entity.EntityState.Modified;
                        ////saves all above operations within one transaction
                        Dbconnection.SaveChanges();

                        //commit transaction
                        dbTran.Commit();
                        this.hideAddEditVenues();
                    }
                    catch (Exception ex)
                    {
                        if (ex is DbEntityValidationException)
                        {
                            foreach (DbEntityValidationResult entityErr in ((DbEntityValidationException)ex).EntityValidationErrors)
                            {
                                foreach (DbValidationError error in entityErr.ValidationErrors)
                                {
                                    MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        //Rollback transaction if exception occurs
                        dbTran.Rollback();
                    }
                }
            };


            refreshVenues();
        }
Exemple #26
0
        private void prePopulateCurrentlySelectedCourse()
        {
            using (var Dbconnection = new MCDEntities())
            {
                CurrentlySelectedCurriculumCourseToSchedule = CurrentSelectedCurriculumCourseEnrollment.CurriculumCourse;
                Dbconnection.CurriculumCourses.Attach(CurrentlySelectedCurriculumCourseToSchedule);
                //loads the days that can be scheduled.
                if (!Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Collection(a => a.CurriculumCourseDayCanBeScheduleds).IsLoaded)
                {
                    Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Collection(a => a.CurriculumCourseDayCanBeScheduleds).Load();
                }
                //load the course that associated with the Curriculum Course
                if (!Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Reference <Course>(a => a.Course).IsLoaded)
                {
                    Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Reference <Course>(a => a.Course).Load();
                }

                //if (!Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Collection(a => a.Course.VenueAssociatedCourses).IsLoaded)
                //{
                //    Dbconnection.Entry(CurrentlySelectedCurriculumCourseToSchedule).Collection(a => a.Course.VenueAssociatedCourses).Load();
                //}
            };
        }
        private void btnAddDisability_Click(object sender, EventArgs e)
        {
            using (var Dbconnection = new MCDEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = Dbconnection.Database.BeginTransaction())
                {
                    try
                    {
                        //CRUD Operations
                        CurrentStudentDisablity = new StudentDisability()
                        {
                            DisabilityID           = this.DisablityID,
                            StudentID              = this.StudentID,
                            StudentDisabilityNotes = this.txtStudentDisablityNotes.Text
                        };
                        Dbconnection.StudentDisabilities.Add(CurrentStudentDisablity);


                        ////saves all above operations within one transaction
                        Dbconnection.SaveChanges();

                        //commit transaction
                        dbTran.Commit();
                        Dbconnection.Entry(CurrentStudentDisablity).Reference(a => a.LookupDisability).Load();
                    }
                    catch (Exception ex)
                    {
                        if (ex is DbEntityValidationException)
                        {
                            foreach (DbEntityValidationResult entityErr in ((DbEntityValidationException)ex).EntityValidationErrors)
                            {
                                foreach (DbValidationError error in entityErr.ValidationErrors)
                                {
                                    MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        //Rollback transaction if exception occurs
                        dbTran.Rollback();
                    }
                    finally{
                        this.Close();
                    }
                }
            };
        }
 private void btnREmoveVenueCourse_Click(object sender, EventArgs e)
 {
     if (venueAssociatedCourseBindingSource.Count > 0)
     {
         using (var Dbconnection = new MCDEntities())
         {
             VenueAssociatedCourse VenueAssociatedCourseToRemove = ((VenueAssociatedCourse)venueAssociatedCourseBindingSource.Current);
             Dbconnection.Entry(VenueAssociatedCourseToRemove).State = EntityState.Deleted;
             Dbconnection.SaveChanges();
         };
         this.refreshDepartmentCourses();
         this.refreshVenueCourses();
     }
 }
        private void btnInProgressChangeContact_Click(object sender, EventArgs e)
        {
            if (((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Companies.Count > 0)
            {
                using (frmSelectCompanyContact frm = new frmSelectCompanyContact())
                {
                    Data.Models.Enquiry _CurentSelectedEnquiry = (Data.Models.Enquiry)enquiryInprogressBindingSource.Current;
                    using (var Dbconnection = new MCDEntities())
                    {
                        Dbconnection.Enquiries.Attach(_CurentSelectedEnquiry);
                        Dbconnection.Entry(_CurentSelectedEnquiry).Collection(a => a.Companies).Load();

                        frm.CurrentCompany = ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Companies.FirstOrDefault<Data.Models.Company>();
                        frm.ShowDialog();
                        if (frm.SelectedIndividual != null)
                        {


                            Individual CurrentEnquiryContact = ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Individuals.FirstOrDefault<Individual>();

                            //REmove C=urrent Contact
                            Dbconnection.Enquiries.Attach(_CurentSelectedEnquiry);

                            _CurentSelectedEnquiry.Individuals.Remove(CurrentEnquiryContact);

                            Dbconnection.SaveChanges();

                            //Link Selected Contact

                            Dbconnection.Individuals.Attach(frm.SelectedIndividual);

                            _CurentSelectedEnquiry.Individuals.Add(frm.SelectedIndividual);

                            Dbconnection.SaveChanges();



                        };
                        //REfresh Enquiry
                        this.refreshInProgressEnquiry(CurrentSelectedEnquiryID);

                    }

                }
            }
            else
            {
                MetroMessageBox.Show(this, "Can Only Change Company Contacts, Not Private Contacts", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void btnRemoveLinkedDaysToSchedule_Click(object sender, EventArgs e)
        {
            CurriculumCourseDayCanBeScheduled CurriculumCourseDayCanBeScheduledObj = (CurriculumCourseDayCanBeScheduled)(linkedCcurriculumCourseDayCanBeScheduledBindingSource.Current);

            CurriculumCourseDayCanBeScheduledObj.ObjectState = EntityObjectState.Deleted;


            using (var Dbconnection = new MCDEntities())
            {
                Dbconnection.Entry(CurriculumCourseDayCanBeScheduledObj).State = EntityState.Deleted;
                Dbconnection.SaveChanges();
                this.loadupStepThree();
                this.btnLinkDayAvailableToSchedule.Enabled = true;
            };
        }