Beispiel #1
0
        private void btnContactInformationSelectPrivateContact_Click(object sender, EventArgs e)
        {
            frmSelectIndividualContact frm = new frmSelectIndividualContact();

            frm.SelectedIndividual = CurrentEnquiry.Individuals.FirstOrDefault <Individual>();
            frm.ShowDialog();
            this.clearSelectedIndividuals();
            using (var Dbconnection = new MCDEntities())
            {
                if (frm.SelectedIndividual != null)
                {
                    CurrentEnquiry.Individuals.Add(frm.SelectedIndividual);
                }
            };

            this.refreshPrivateIndividualDetails();
            this.refreshContactDetails();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            frmSelectIndividualContact frm = new frmSelectIndividualContact();

            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);
                }
            }
        }