private void btnContactInformationSelectCompanyContact_Click(object sender, EventArgs e)
        {
            frmSelectCompanyContact frm = new frmSelectCompanyContact();

            frm.CurrentCompany     = CurrentEnquiry.Companies.FirstOrDefault <Data.Models.Company>();
            frm.SelectedIndividual = CurrentEnquiry.Individuals.FirstOrDefault <Individual>();
            frm.ShowDialog();
            this.clearSelectedCompanies();
            this.clearSelectedIndividuals();


            using (var Dbconnection = new MCDEntities())
            {
                Dbconnection.Enquiries.Attach(CurrentEnquiry);
                if (frm.CurrentCompany != null)
                {
                    //Data.Models.Company CompanyToLink = new Data.Models.Company
                    //{
                    //    CompanyID = frm.CurrentCompany.CompanyID
                    //};
                    //Dbconnection.Companies.Attach(CompanyToLink);
                    //CurrentEnquiry.Companies.Add(CompanyToLink);

                    //Dbconnection.Entry(CompanyToLink).Reload();
                    CurrentEnquiry.Companies.Add(frm.CurrentCompany);
                }
                else
                {
                    CurrentEnquiry.Companies.Clear();
                }
                if (frm.SelectedIndividual != null)
                {
                    //Individual ContactPersonToLink = new Individual
                    //{
                    //    IndividualID = frm.SelectedIndividual.IndividualID
                    //};
                    //Dbconnection.Individuals.Attach(ContactPersonToLink);
                    //CurrentEnquiry.Individuals.Add(ContactPersonToLink);


                    //Dbconnection.Entry(ContactPersonToLink).Reload();

                    //Dbconnection.Entry(ContactPersonToLink).Collection(a => a.ContactDetails).Load();
                    //foreach (ContactDetail ConDetail in ContactPersonToLink.ContactDetails)
                    //{
                    //    Dbconnection.Entry(ConDetail).Reference("LookupContactType").Load();
                    //}
                    CurrentEnquiry.Individuals.Add(frm.SelectedIndividual);
                }
                else
                {
                    CurrentEnquiry.Individuals.Clear();
                }
            };
            this.refreshCompanyName();
            this.refreshContact();
            this.refreshContactDetails();
        }
        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 button5_Click(object sender, EventArgs e)
        {
            frmSelectCompanyContact frm = new frmSelectCompanyContact();

            frm.ShowDialog();
        }
        private void btnInProgressSwitchBetweenCompanyANdPrivate_Click(object sender, EventArgs e)
        {
            if (((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Companies.Count == 0)
            {
                using (frmSelectCompanyContact frm = new frmSelectCompanyContact())
                {
                    Data.Models.Enquiry CurrentEnquiry = (Data.Models.Enquiry)enquiryInprogressBindingSource.Current;
                    Individual          CurrentContact = CurrentEnquiry.Individuals.FirstOrDefault <Individual>();
                    //frm.CurrentCompany = CurrentEnquiry.Companies.FirstOrDefault<Data.Models.Company>();
                    //frm.SelectedIndividual = CurrentEnquiry.Individuals.FirstOrDefault<Individual>();
                    frm.ShowDialog();


                    if (frm.CurrentCompany != null)
                    {
                        using (var Dbconnection = new MCDEntities())
                        {
                            Dbconnection.Enquiries.Attach(CurrentEnquiry);
                            //REmova Current Contact from tthe Enquiry
                            Dbconnection.Enquiries.Attach(CurrentEnquiry);

                            CurrentEnquiry.Individuals.Clear();
                            CurrentEnquiry.Companies.Clear();
                            Dbconnection.SaveChanges();
                        }
                        //Link Company That Is responible for the Enquiry
                        using (var Dbconnection = new MCDEntities())
                        {
                            Dbconnection.Enquiries.Attach(CurrentEnquiry);
                            Data.Models.Company CompanyToLink = new Data.Models.Company
                            {
                                CompanyID = frm.CurrentCompany.CompanyID
                            };
                            Dbconnection.Companies.Attach(CompanyToLink);
                            CurrentEnquiry.Companies.Add(CompanyToLink);
                            Dbconnection.SaveChanges();
                        };

                        using (var Dbconnection = new MCDEntities())
                        {
                            Dbconnection.Enquiries.Attach(CurrentEnquiry);
                            Individual NewContact = new Individual
                            {
                                IndividualID = frm.SelectedIndividual.IndividualID
                            };
                            Dbconnection.Individuals.Attach(NewContact);
                            CurrentEnquiry.Individuals.Add(NewContact);
                            Dbconnection.SaveChanges();
                        };

                        //Link the Copmpany Contact
                        // Dbconnection.Individuals.Add(frm.SelectedIndividual);


                        //Remove the current Contact

                        //Dbconnection.Entry(CompanyToLink).Reload();
                        //CurrentEnquiry.Companies.Add(frm.CurrentCompany);
                    }
                }
                refreshInProgressEnquiry(CurrentSelectedEnquiryID);
            }
            else
            {
                //Selects From List Of All Students from the Custom Student Search Form
                using (frmSelectIndividualContact frm = new frmSelectIndividualContact())
                {
                    frm.ShowDialog();
                    //get the Individual Selected Which represents the Student Selected.

                    if (frm.SelectedIndividual.IndividualID != 0)
                    {
                        using (var Dbconnection = new MCDEntities())
                        {
                            /*1. Removes the current Slected Company Contact*/
                            Data.Models.Enquiry CurrentEnquiry = ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current);

                            Dbconnection.Enquiries.Attach(CurrentEnquiry);

                            List <Individual>          temp          = ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Individuals.ToList <Individual>();
                            List <Data.Models.Company> tempCompanies = ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Companies.ToList <Data.Models.Company>();
                            foreach (Individual individ in temp)
                            {
                                ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Individuals.Remove(individ);
                            }
                            foreach (Data.Models.Company comp in tempCompanies)
                            {
                                ((Data.Models.Enquiry)enquiryInprogressBindingSource.Current).Companies.Remove(comp);
                            }
                            // Dbconnection.Entry(CurrentEnquiry).State = EntityState.Modified;
                            Dbconnection.SaveChanges();
                            /*1. End Removal of Current Enquiry Contact*/


                            /*2. Adds The Cuurentlty Selected Student Contact to be linked with the Enquiry for future contacting*/
                            Individual IndividualToLink = (from a in Dbconnection.Individuals
                                                           where a.IndividualID == frm.SelectedIndividual.IndividualID
                                                           select a).FirstOrDefault <Individual>();
                            CurrentEnquiry.Individuals.Add(IndividualToLink);
                            Dbconnection.SaveChanges();
                            /*2. End Adding the Student Contact Details To the Enquiry.*/
                        };
                    }
                    this.refreshInProgressEnquiry(CurrentSelectedEnquiryID);
                }
            }
        }