private void PopulateFields()
        {
            ddlTitles.DataSource = CRM_Title.SetDropDownWithString(db.CRM_Titles.Cast <IArchivable>(), Entity.InvoiceTitle);
            ddlTitles.DataBind();

            txtPriceAgreed.Text        = Entity.PriceAgreed.ToString("N2");
            ddlPriceType.SelectedValue = Entity.PriceType.ToString();
            txtFirstname.Text          = Entity.InvoiceFirstname;
            txtLastname.Text           = Entity.InvoiceLastname;
            ddlTitles.SelectedValue    = Entity.InvoiceTitle;
            ucLogNotes.INotes          = Entity;
            ucLogHistory.IHistory      = Entity;
            ucLogHistory.ParentID      = Entity.ID.ToString();
            txtPONumber.Text           = Entity.PONumber;


            if (Entity.DatePaid != null)
            {
                txtDatePaid.Value = (DateTime)Entity.DatePaid;
            }

            if (Entity.InvoiceAddressID == null && Entity.PrimaryContactReference != "")
            {
                IContact Contact = ContactManager.GetIContactByReference(Entity.PrimaryContactReference);

                ucAddress.Populate(Contact.PrimaryAddress);

                ddlTitles.DataSource = CRM_Title.SetDropDownWithString(db.CRM_Titles.Cast <IArchivable>(), Contact.Title);
                ddlTitles.DataBind();

                ddlTitles.SelectedValue = Contact.Title;
                txtFirstname.Text       = Contact.Firstname;
                txtLastname.Text        = Contact.Lastname;
            }
            else
            {
                CRM_Address invoiceAddress = db.CRM_Addresses.SingleOrDefault(c => c.ID == Entity.InvoiceAddressID);

                if (invoiceAddress != null)
                {
                    ucAddress.Populate(invoiceAddress);
                }
                else
                {
                    IContact contact = new Code.Managers.ContactManager().Contacts.SingleOrDefault(c => c.Reference == Entity.PrimaryContactReference);


                    if (contact != null && contact.PrimaryAddress != null)
                    {
                        ucAddress.Populate(contact.PrimaryAddress);
                    }
                }

                ddlTitles.SelectedValue = Entity.InvoiceTitle;
                txtFirstname.Text       = Entity.InvoiceFirstname;
                txtLastname.Text        = Entity.InvoiceLastname;
            }
        }
Ejemplo n.º 2
0
        protected void lnkCreateNew_Click(object sender, EventArgs e)
        {
            CRM_Address address = new CRM_Address()
            {
                AddressLine1 = txtAddress1.Text,
                AddressLine2 = txtAddress2.Text,
                AddressLine3 = txtAddress3.Text,
                AddressLine4 = "",
                AddressLine5 = "",
                CountryID    = db.Countries.First().ID,
                County       = txtCounty.Text,
                Postcode     = txtPostcode.Text,
                Town         = txtCity.Text
            };

            db.CRM_Addresses.InsertOnSubmit(address);
            db.SubmitChanges();

            CRM_Person person = new CRM_Person()
            {
                DateAdded        = UKTime.Now,
                CRM_AddressID    = address.ID,
                DateModified     = UKTime.Now,
                DateOfBirth      = null,
                Firstname        = txtFirstname.Text,
                IsArchived       = false,
                IsChild          = false,
                IsConcession     = false,
                IsContactEmail   = (bool)Entity.DoNotEmail,
                IsContactPost    = (bool)Entity.DoNotMail,
                IsGiftAid        = false,
                Lastname         = txtLastname.Text,
                PrimaryEmail     = txtEmail.Text,
                PrimaryTelephone = txtTelephone.Text,
                Title            = ddlTitle.SelectedItem.Text,
                WebsiteAccountID = Entity.OriginAccountID,
                IsCarerMinder    = false,
                PreviousNames    = "",
                LegacyID         = null,
                IsMale           = null,
                AddressType      = 0,
                Telephone2       = "",
                PrimaryAddressID = address.ID,
                Password         = "",
                TempCode         = ""
            };

            db.CRM_Persons.InsertOnSubmit(person);
            db.SubmitChanges();

            ApplyCustomField(person, 2, 22);
            ApplyConstituentsToSelected(person);

            AddRelationship(person);

            NoticeManager.SetMessage("Record added (" + person.Reference + ")");
        }
Ejemplo n.º 3
0
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/relationships.csv";

            using (StreamReader reader = new StreamReader(Server.MapPath(path)))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";

                        CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.Firstname.Trim().ToLower() == contentsSplit[(int)accountPos.firstname].Trim().ToLower() &&
                                                                          f.Lastname.Trim().ToLower() == contentsSplit[(int)accountPos.surname].Trim().ToLower() && f.Firstname.Trim() != "");

                        CRM_RelationCode unknownRelationCode = db.CRM_RelationCodes.Single(s => s.Name == "");;

                        CRM_Person personB = db.CRM_Persons.FirstOrDefault(f => f.Firstname.Trim().ToLower() == contentsSplit[(int)accountPos.relfirstname].Trim().ToLower() &&
                                                                           f.Lastname.Trim().ToLower() == contentsSplit[(int)accountPos.relsurname].Trim().ToLower());

                        if (person != null && personB == null)
                        {
                            CRM_Address relationAddress = person.PrimaryAddress;

                            CRM_Address address = new CRM_Address()
                            {
                                AddressLine1 = relationAddress.AddressLine1,
                                AddressLine2 = relationAddress.AddressLine2,
                                AddressLine3 = relationAddress.AddressLine3,
                                AddressLine4 = relationAddress.AddressLine4,
                                AddressLine5 = relationAddress.AddressLine5,
                                Town         = relationAddress.Town,
                                CountryID    = relationAddress.CountryID,
                                County       = relationAddress.County,
                                Postcode     = relationAddress.Postcode
                            };

                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();

                            personB = new CRM_Person()
                            {
                                Title            = "",
                                Firstname        = contentsSplit[(int)accountPos.relfirstname],
                                Lastname         = contentsSplit[(int)accountPos.relsurname],
                                DateAdded        = UKTime.Now,
                                DateModified     = UKTime.Now,
                                DateOfBirth      = null,
                                IsArchived       = false,
                                IsMale           = null,
                                PrimaryEmail     = "",
                                PrimaryTelephone = "",
                                IsContactEmail   = false,
                                IsContactPost    = true,
                                IsChild          = false,
                                IsConcession     = false,
                                IsCarerMinder    = false,
                                IsDeceased       = false,
                                IsGiftAid        = false,
                                IsDoNotEmail     = false,
                                IsDoNotMail      = false,
                                Telephone2       = "",
                                PreviousNames    = "",
                                CRM_AddressID    = address.ID,
                                Password         = "",
                                TempCode         = ""
                            };

                            db.CRM_Persons.InsertOnSubmit(personB);
                            db.SubmitChanges();

                            CRM_FormFieldAnswer originAnswer = new CRM_FormFieldAnswer()
                            {
                                Answer          = "Import",
                                CRM_FormFieldID = 2,
                                TargetReference = personB.Reference
                            };

                            db.CRM_FormFieldAnswers.InsertOnSubmit(originAnswer);
                            db.SubmitChanges();
                        }


                        if (person != null && personB != null && contentsSplit[(int)accountPos.relcode] != "Daughter" && contentsSplit[(int)accountPos.relcode] != "Son")
                        {
                            CRM_RelationCode relCode = db.CRM_RelationCodes.FirstOrDefault(f => f.Name.Trim().ToLower() == contentsSplit[(int)accountPos.relcode].Trim().ToLower());


                            if (relCode != null)
                            {
                                CRM_PersonRelationship personRel = new CRM_PersonRelationship();
                                personRel.PersonA             = person;
                                personRel.PersonB             = personB;
                                personRel.CRM_PersonIDAddress = person.ID;
                                personRel.PersonACode         = relCode;
                                personRel.PersonBCode         = unknownRelationCode;

                                string salutation = "";


                                // mr and mrs somebody
                                if (person.Lastname.Trim().ToLower() == personB.Lastname.Trim().ToLower() && person.Title != "" && personB.Title != "")
                                {
                                    if (person.Title == "Mr")
                                    {
                                        salutation = person.Title + " and " + personB.Title + " " + person.Lastname;
                                    }
                                    else
                                    {
                                        salutation = personB.Title + " and " + person.Title + " " + person.Lastname;
                                    }
                                }
                                else if ((person.Lastname.Trim().ToLower() != personB.Lastname.Trim().ToLower()) && person.Title != "" && personB.Title != "")
                                {
                                    // mr smith and mrs somebody

                                    if (person.Title == "Mr")
                                    {
                                        salutation = person.Title + " " + person.Lastname + " and " + personB.Title + " " + personB.Lastname;
                                    }
                                    else
                                    {
                                        salutation = personB.Title + " " + personB.Lastname + " and " + person.Title + " " + person.Lastname;
                                    }
                                }
                                else if (person.Lastname.Trim().ToLower() == personB.Lastname.Trim().ToLower())
                                {
                                    salutation = person.Firstname + " and " + personB.Firstname + " " + person.Lastname;
                                }
                                else
                                {
                                    salutation = person.Firstname + " " + person.Lastname + " and " + personB.Firstname + " " + personB.Lastname;
                                }

                                personRel.Salutation = salutation;

                                db.CRM_PersonRelationships.InsertOnSubmit(personRel);
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
        }
        protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //

            object oldEntity  = null;
            object oldAddress = null;


            if (newRecord)
            {
                Entity = new CRM_Fundraising();
                db.CRM_Fundraisings.InsertOnSubmit(Entity);
            }
            else
            {
                oldEntity  = Entity.ShallowCopy();
                oldAddress = Entity.CRM_Address.ShallowCopy();
            }


            int recurring = 0;

            Int32.TryParse(txtRecurringWeeks.Text, out recurring);

            Entity.IsInKind                = chkIsInKind.Checked;
            Entity.PledgedAmount           = Convert.ToDecimal(txtAmount.Text);
            Entity.IsGiftAid               = chkIsGiftAid.Checked;
            Entity.GiftAidFirstname        = txtGiftaidFirstname.Text;
            Entity.GiftAidLastname         = txtGiftaidLastname.Text;
            Entity.IsRecurring             = chkIsRecurring.Checked;
            Entity.RecurringEveryWeeks     = recurring;
            Entity.Duration                = Convert.ToInt32(txtDuration.Text);
            Entity.CRM_PaymentTypeID       = Convert.ToInt32(ddlPaymentType.SelectedValue);
            Entity.CRM_FundraisingReasonID = Convert.ToInt32(ddlFundReason.SelectedValue);
            Entity.PrimaryContactReference = ucACPrimaryContact.SelectedID;

            using (ContactManager manager = new ContactManager())
            {
                IContact selectedContact = new ContactManager().Contacts.Single(c => c.Reference == ucACPrimaryContact.SelectedID);

                Entity.ContactName = selectedContact.Fullname;
                Entity.ContactType = selectedContact.DisplayName;
                manager.Dispose();
            }

            if (newRecord)
            {
                CRM_Address address = new CRM_Address();
                Entity.CRM_Address = (CRM_Address)((Address)ucGiftAidAddress).Save(address);
            }
            else
            {
                Entity.CRM_Address = (CRM_Address)((Address)ucGiftAidAddress).Save(Entity.CRM_Address);
            }

            db.SubmitChanges();

            db.CRM_FundraisingSplits.DeleteAllOnSubmit(Entity.CRM_FundraisingSplits);
            db.SubmitChanges();

            foreach (CRM_FundraisingSplit serialSplit in GetSplitsFromRepeater())
            {
                CRM_FundraisingSplit split = new CRM_FundraisingSplit()
                {
                    Amount            = serialSplit.Amount,
                    CRM_FundID        = serialSplit.CRM_FundID,
                    DateGiven         = serialSplit.DateGiven,
                    GiftAidRate       = serialSplit.GiftAidRate,
                    CRM_FundRaisingID = Entity.ID
                };

                db.CRM_FundraisingSplits.InsertOnSubmit(split);
                db.SubmitChanges();
            }

            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, Entity);
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldAddress, Entity.CRM_Address);
                db.SubmitChanges();
            }
            else
            {
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity);
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity.CRM_Address);
            }

            ucCustomFields.Save(Entity.Reference);

            Session.Remove(SplitListConst);
        }
Ejemplo n.º 5
0
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/FinalListforCoalFace.csv";

            using (StreamReader reader = new StreamReader(Server.MapPath(path)))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";


                        CRM_FormFieldItem ffItem = db.CRM_FormFieldItems.FirstOrDefault(f => f.Label == contentsSplit[(int)accountPos.Constituent]);

                        if (ffItem == null)
                        {
                            ffItem = new CRM_FormFieldItem()
                            {
                                Label           = contentsSplit[(int)accountPos.Constituent],
                                CRM_FormFieldID = 1,
                                OrderNo         = Code.Utils.Ordering.Ordering.GetNextOrderID(db.CRM_FormFieldItems),
                                IsActive        = true,
                                IsArchived      = false
                            };

                            db.CRM_FormFieldItems.InsertOnSubmit(ffItem);
                            db.SubmitChanges();
                        }

                        CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.LegacyID != null && f.LegacyID.ToString() == contentsSplit[(int)accountPos.LegacyID]);

                        if (person == null)
                        {
                            CRM_Address address = new CRM_Address();
                            address.AddressLine1 = contentsSplit[(int)accountPos.Address1];
                            address.AddressLine2 = contentsSplit[(int)accountPos.Address2];
                            address.AddressLine3 = contentsSplit[(int)accountPos.Address3];
                            address.AddressLine4 = contentsSplit[(int)accountPos.Address4];
                            address.AddressLine5 = contentsSplit[(int)accountPos.Address5];
                            address.Town         = contentsSplit[(int)accountPos.City];
                            address.County       = contentsSplit[(int)accountPos.County];
                            address.Postcode     = contentsSplit[(int)accountPos.Postcode];
                            address.CountryID    = 1;
                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();

                            person = new CRM_Person();
                            db.CRM_Persons.InsertOnSubmit(person);
                            if (contentsSplit[(int)accountPos.AddressType] == "Business")
                            {
                                person.AddressType = (byte)CRM_Address.Types.Business;
                            }
                            person.AddressType      = (byte)CRM_Address.Types.Home;
                            person.DateAdded        = UKTime.Now;
                            person.DateModified     = UKTime.Now;
                            person.IsArchived       = false;
                            person.IsChild          = false;
                            person.IsCarerMinder    = false;
                            person.PreviousNames    = "";
                            person.PrimaryEmail     = "";
                            person.PrimaryTelephone = "";
                            person.Telephone2       = "";
                            person.IsDoNotMail      = false;
                            person.LegacyID         = Convert.ToInt32(contentsSplit[(int)accountPos.LegacyID]);
                            person.CRM_AddressID    = address.ID;
                            person.Password         = "";
                            person.TempCode         = "";
                        }


                        person.Title     = contentsSplit[(int)accountPos.Title];
                        person.Firstname = contentsSplit[(int)accountPos.Firstname];
                        person.Lastname  = contentsSplit[(int)accountPos.Surname];

                        if (contentsSplit[(int)accountPos.Gender] == "Male")
                        {
                            person.IsMale = true;
                        }
                        else if (contentsSplit[(int)accountPos.Gender] == "Female")
                        {
                            person.IsMale = false;
                        }
                        else
                        {
                            person.IsMale = null;
                        }

                        if (contentsSplit[(int)accountPos.NoEmail] == "Yes")
                        {
                            person.IsDoNotEmail = true;
                        }

                        db.SubmitChanges();

                        CRM_FormFieldAnswer answer = new CRM_FormFieldAnswer()
                        {
                            Answer          = contentsSplit[(int)accountPos.Constituent],
                            CRM_FormFieldID = ffItem.CRM_FormFieldID,
                            TargetReference = person.Reference
                        };

                        db.CRM_FormFieldAnswers.InsertOnSubmit(answer);
                        db.SubmitChanges();


                        if (contentsSplit[(int)accountPos.PhoneNumber11].Contains("@"))
                        {
                            person.PrimaryEmail = contentsSplit[(int)accountPos.PhoneNumber11];
                        }
                        else
                        {
                            person.PrimaryTelephone = contentsSplit[(int)accountPos.PhoneNumber11];
                            person.PrimaryEmail     = contentsSplit[(int)accountPos.PhoneNumber12];
                        }

                        if (!contentsSplit[(int)accountPos.PhoneNumber12].Contains("@"))
                        {
                            person.Telephone2 = contentsSplit[(int)accountPos.PhoneNumber12];
                        }

                        db.SubmitChanges();


                        if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.MembershipID].Trim()))
                        {
                            CRM_AnnualPassCard card = new CRM_AnnualPassCard()
                            {
                                MembershipNumber = Convert.ToInt32(contentsSplit[(int)accountPos.MembershipID])
                            };

                            db.CRM_AnnualPassCards.InsertOnSubmit(card);
                            db.SubmitChanges();

                            CRM_AnnualPass pass = new CRM_AnnualPass();
                            pass.CRM_AnnualPassCardID    = card.ID;
                            pass.AmountPaid              = 0;
                            pass.CRM_AnnualPassTypeID    = 15;
                            pass.IsArchived              = false;
                            pass.DiscountApplied         = "";
                            pass.PrimaryContactReference = person.Reference;

                            try
                            {
                                if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.MembershipExpiry]) && String.IsNullOrEmpty((contentsSplit[(int)accountPos.MembershipLastRenew])))
                                {
                                    pass.StartDate = Code.Utils.Text.Text.FormatInputDate(contentsSplit[(int)accountPos.MembershipExpiry]);
                                }
                                else
                                {
                                    pass.StartDate = Code.Utils.Text.Text.FormatInputDate(contentsSplit[(int)accountPos.MembershipExpiry]).AddYears(-1);
                                }
                            }
                            catch {
                                pass.StartDate = UKTime.Now;
                            }

                            try
                            {
                                pass.ExpiryDate = Code.Utils.Text.Text.FormatInputDate(contentsSplit[(int)accountPos.MembershipExpiry]);
                            }
                            catch { pass.ExpiryDate = new DateTime(2075, 12, 31); }

                            db.CRM_AnnualPasses.InsertOnSubmit(pass);
                            db.SubmitChanges();

                            CRM_AnnualPassPerson passPerson = new CRM_AnnualPassPerson()
                            {
                                CRM_AnnualPassID = pass.ID,
                                CRM_PersonID     = person.ID,
                                IsArchived       = false
                            };

                            db.CRM_AnnualPassPersons.InsertOnSubmit(passPerson);
                            db.SubmitChanges();
                        }

                        if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.OrgName]))
                        {
                            CRM_Organisation org = db.CRM_Organisations.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.OrgName]);

                            if (org == null)
                            {
                                CRM_Address orgAddress = new CRM_Address()
                                {
                                    AddressLine1 = contentsSplit[(int)accountPos.OrgAddr1],
                                    AddressLine2 = contentsSplit[(int)accountPos.OrgAddr2],
                                    AddressLine3 = contentsSplit[(int)accountPos.OrgAddr3],
                                    AddressLine4 = contentsSplit[(int)accountPos.OrgAddr4],
                                    AddressLine5 = "",
                                    County       = "",
                                    Town         = contentsSplit[(int)accountPos.OrgAddrCity],
                                    Postcode     = contentsSplit[(int)accountPos.Postcode],
                                    CountryID    = 1
                                };

                                db.CRM_Addresses.InsertOnSubmit(orgAddress);
                                db.SubmitChanges();

                                org = new CRM_Organisation()
                                {
                                    CRM_OrganisationTypeID = 1,
                                    CRM_AddressID          = orgAddress.ID,
                                    Name       = contentsSplit[(int)accountPos.OrgName],
                                    IsArchived = false,
                                    PrimaryContactReference = person.Reference
                                };
                                db.CRM_Organisations.InsertOnSubmit(org);
                                db.SubmitChanges();
                            }

                            CRM_Role role = db.CRM_Roles.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.OrgPosition]);

                            if (role == null)
                            {
                                role = new CRM_Role();
                                db.CRM_Roles.InsertOnSubmit(role);
                                role.Name = contentsSplit[(int)accountPos.OrgPosition];
                                db.SubmitChanges();
                            }

                            CRM_PersonOrganisation personOrg = new CRM_PersonOrganisation()
                            {
                                CRM_OrganisationID = org.ID,
                                CRM_RoleID         = role.ID,
                                IsArchived         = false,
                                Email        = "",
                                Telephone    = "",
                                CRM_PersonID = person.ID
                            };

                            db.CRM_PersonOrganisations.InsertOnSubmit(personOrg);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }
        protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //

            object oldEntity  = null;
            object oldAddress = null;

            if (newRecord)
            {
                Entity            = new CRM_Person();
                Entity.IsArchived = false;
                Entity.DateAdded  = UKTime.Now;
                Entity.Password   = "";
                Entity.TempCode   = "";
                db.CRM_Persons.InsertOnSubmit(Entity);
            }
            else
            {
                oldEntity  = Entity.ShallowCopy();
                oldAddress = Entity.CRM_Address.ShallowCopy();
            }

            Entity.DateModified     = UKTime.Now;
            Entity.Title            = ddlTitles.SelectedValue;
            Entity.Firstname        = txtFirstname.Text;
            Entity.Lastname         = txtLastname.Text;
            Entity.PreviousNames    = txtPrevious.Text;
            Entity.PrimaryEmail     = txtPrimaryEmail.Text;
            Entity.PrimaryTelephone = txtTelephone.Text;
            Entity.IsContactEmail   = chkIsContactEmail.Checked;
            Entity.IsChild          = chkIsChild.Checked;
            Entity.IsConcession     = chkIsConcession.Checked;
            Entity.IsCarerMinder    = chkIsCarerMinder.Checked;
            Entity.IsDeceased       = chkIsDeceased.Checked;
            Entity.IsGiftAid        = chkIsGiftAid.Checked;
            Entity.IsDoNotMail      = chkIsDoNotMail.Checked;
            Entity.IsDoNotEmail     = chkIsDoNotEmail.Checked;
            Entity.AddressType      = (byte)CRM_Address.Types.Home;
            Entity.Telephone2       = txtTelephone2.Text;
            if (!String.IsNullOrEmpty(txtDateOfBirth.Text))
            {
                Entity.DateOfBirth = txtDateOfBirth.Value;
            }

            if (newRecord)
            {
                CRM_Address address = new CRM_Address();
                Entity.CRM_Address = (CRM_Address)((Address)ucAddress).Save(address);
            }
            else
            {
                Entity.CRM_Address = (CRM_Address)((Address)ucAddress).Save(Entity.CRM_Address);
            }

            db.SubmitChanges();

            if (ddlPrimaryAddress.SelectedValue != "")
            {
                Entity.PrimaryAddressID = Convert.ToInt32(ddlPrimaryAddress.SelectedValue);
            }

            db.SubmitChanges();

            Entity.CRM_Address.ParentID = Entity.ID;
            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, Entity);
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldAddress, Entity.CRM_Address);
                db.SubmitChanges();
            }
            else
            {
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity);
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity.CRM_Address);
            }

            ucCustomFields.Save(Entity.Reference);

            if (hdnCaptured.Value == "1")
            {
                File.Copy(MapPath(AdminUser.TempPhotoFile), MapPath(Entity.PersonImageURL), true);
            }
        }
Ejemplo n.º 7
0
        protected void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/Art_Booking.csv";
            using (StreamReader reader = new StreamReader(Server.MapPath(path)))
            {

                lineNumber = 0;

                while (!reader.EndOfStream)
                {

                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string errorMessage = "";

                        CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.PrimaryEmail.Trim().ToLower() == contentsSplit[(int)accountPos.Email].Trim().ToLower()
                            && f.Lastname.Trim().ToLower() == contentsSplit[(int)accountPos.Lastname].Trim().ToLower());

                        if (person == null)
                        {

                            CRM_Address address = new CRM_Address();
                            address.AddressLine1 = contentsSplit[(int)accountPos.Address1];
                            address.AddressLine2 = contentsSplit[(int)accountPos.Address2];
                            address.AddressLine3 = contentsSplit[(int)accountPos.Address3];
                            address.AddressLine4 = contentsSplit[(int)accountPos.Address4];
                            address.AddressLine5 = "";
                            address.Town = "";
                            address.County = contentsSplit[(int)accountPos.Address4];
                            address.Postcode = contentsSplit[(int)accountPos.Postcode];
                            address.CountryID = 1;
                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();

                            person = new CRM_Person();
                            db.CRM_Persons.InsertOnSubmit(person);

                            person.AddressType = (byte)CRM_Address.Types.Home;
                            person.DateAdded = UKTime.Now;
                            person.IsArchived = false;
                            person.IsChild = false;
                            person.IsCarerMinder = false;
                            person.PreviousNames = "";
                            person.PrimaryEmail = contentsSplit[(int)accountPos.Email];
                            person.PrimaryTelephone = contentsSplit[(int)accountPos.Phone1];
                            person.Telephone2 = contentsSplit[(int)accountPos.Phone2];
                            person.IsDoNotMail = false;
                            person.LegacyID = null;
                            person.CRM_AddressID = address.ID;
                            person.Password = "";
                            person.TempCode = "";
                        }

                        person.DateModified = UKTime.Now;
                        person.Title = "";
                        person.Firstname = contentsSplit[(int)accountPos.Firstname];
                        person.Lastname = contentsSplit[(int)accountPos.Lastname];
                        person.IsMale = null;
                        person.IsDoNotEmail = false;

                        db.SubmitChanges();

                        if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.Company]))
                        {

                            CRM_Organisation org = db.CRM_Organisations.FirstOrDefault(f =>
                                f.Name.Trim().ToLower() == contentsSplit[(int)accountPos.Company].Trim().ToLower());

                            if (org == null)
                            {
                                CRM_Address orgAddress = new CRM_Address()
                                {
                                    AddressLine1 = contentsSplit[(int)accountPos.Address1],
                                    AddressLine2 = contentsSplit[(int)accountPos.Address2],
                                    AddressLine3 = contentsSplit[(int)accountPos.Address3],
                                    AddressLine4 = contentsSplit[(int)accountPos.Address4],
                                    AddressLine5 = "",
                                    County = "",
                                    Town = "",
                                    Postcode = contentsSplit[(int)accountPos.Postcode],
                                    CountryID = 1
                                };

                                db.CRM_Addresses.InsertOnSubmit(orgAddress);
                                db.SubmitChanges();

                                org = new CRM_Organisation()
                                {
                                    CRM_OrganisationTypeID = 1,
                                    CRM_AddressID = orgAddress.ID,
                                    Name = contentsSplit[(int)accountPos.Company],
                                    IsArchived = false,
                                    PrimaryContactReference = person.Reference,
                                };
                                db.CRM_Organisations.InsertOnSubmit(org);
                                db.SubmitChanges();
                            }

                            CRM_Role role = db.CRM_Roles.FirstOrDefault(f => f.Name == "");

                            CRM_PersonOrganisation personOrg = new CRM_PersonOrganisation()
                            {
                                CRM_OrganisationID = org.ID,
                                CRM_RoleID = role.ID,
                                IsArchived = false,
                                Email = "",
                                Telephone = "",
                                CRM_PersonID = person.ID
                            };

                            db.CRM_PersonOrganisations.InsertOnSubmit(personOrg);
                            db.SubmitChanges();

                        }

                        //constituent type
                        CRM_FormFieldAnswer consTypeAnswer = db.CRM_FormFieldAnswers.FirstOrDefault(f => f.TargetReference == person.Reference && f.CRM_FormFieldID == 1);

                        //origin
                        CRM_FormFieldAnswer originAnswer = db.CRM_FormFieldAnswers.FirstOrDefault(f => f.TargetReference == person.Reference && f.CRM_FormFieldID == 2);

                        if (consTypeAnswer == null)
                        {

                            consTypeAnswer = new CRM_FormFieldAnswer()
                            {
                                Answer = "Group Booking",
                                CRM_FormFieldID = 1,
                                TargetReference = person.Reference
                            };

                            db.CRM_FormFieldAnswers.InsertOnSubmit(consTypeAnswer);
                            db.SubmitChanges();
                        }
                        else
                        {
                            string[] items = consTypeAnswer.Answer.Split(new string[] { "<br/>" }, StringSplitOptions.None);

                            if (!items.Any(i => i == "Group Booking"))
                            {
                                consTypeAnswer.Answer += "<br/>Group Booking";
                            }

                            db.SubmitChanges();
                        }

                        if (originAnswer == null)
                        {

                            originAnswer = new CRM_FormFieldAnswer()
                            {
                                Answer = "Import",
                                CRM_FormFieldID = 2,
                                TargetReference = person.Reference
                            };

                            db.CRM_FormFieldAnswers.InsertOnSubmit(originAnswer);
                            db.SubmitChanges();
                        }
                        else
                        {
                            string[] items = originAnswer.Answer.Split(new string[] { "<br/>" }, StringSplitOptions.None);

                            if (!items.Any(i => i == "Import"))
                            {
                                consTypeAnswer.Answer += "<br/>Import";
                            }

                            db.SubmitChanges();
                        }

                    }
                }
            }
        }
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            using (StreamReader reader = new StreamReader(Server.MapPath("/taskscript/scotschools.csv")))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";

                        string postcode = contentsSplit[(int)accountPos.postcodea] + " " + contentsSplit[(int)accountPos.postcodeb];

                        CRM_School school = db.CRM_Schools.FirstOrDefault(s => s.Name == contentsSplit[(int)accountPos.name] &&
                                                                          s.CRM_Address.Postcode.Trim().Replace(" ", "").ToLower() == postcode.Trim().Replace(" ", "").ToLower());

                        CRM_LEA        lea     = db.CRM_LEAs.Single(s => s.ID == 25);       // blank
                        CRM_SchoolType type    = db.CRM_SchoolTypes.Single(s => s.ID == 1); // none
                        Country        country = db.Countries.Single(s => s.ID == 1);       // uk

                        if (school == null)
                        {
                            CRM_Address address = new CRM_Address()
                            {
                                AddressLine1 = contentsSplit[(int)accountPos.address1].Trim(),
                                AddressLine2 = "",
                                AddressLine3 = "",
                                AddressLine4 = "",
                                AddressLine5 = "",
                                Town         = contentsSplit[(int)accountPos.address2],
                                County       = "",
                                Postcode     = postcode,
                                CountryID    = country.ID
                            };


                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();

                            school = new CRM_School()
                            {
                                CRM_AddressID           = address.ID,
                                ApproxPupils            = 0,
                                CRM_LEAID               = lea.ID,
                                CRM_RegionID            = null,
                                CRM_SchoolTypeID        = type.ID,
                                Email                   = "",
                                IsArchived              = false,
                                IsSEN                   = false,
                                Name                    = contentsSplit[(int)accountPos.name].Trim(),
                                Phone                   = "",
                                SageAccountNumber       = "",
                                PrimaryContactReference = "",
                                SENSupportFreq          = "",
                            };

                            db.CRM_Schools.InsertOnSubmit(school);
                            db.SubmitChanges();
                        }
                    }
                }
            }
        }
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            using (StreamReader reader = new StreamReader(Server.MapPath("/taskscript/CBM_Europe_import.csv"), Encoding.GetEncoding("iso-8859-1")))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";

                        CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.Firstname.ToUpper().Trim() == contentsSplit[(int)accountPos.first].ToUpper().Trim() &&
                                                                          f.Lastname.ToUpper().Trim() == contentsSplit[(int)accountPos.last].ToUpper().Trim() &&
                                                                          (f.PrimaryEmail.ToUpper().Trim() == contentsSplit[(int)accountPos.email].ToUpper().Trim() || contentsSplit[(int)accountPos.email] == ""));


                        Country country = db.Countries.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.country]);

                        if (country == null)
                        {
                            country = db.Countries.Single(s => s.ID == 1);
                            HttpContext.Current.Response.Write("country missing - " + contentsSplit[(int)accountPos.country]);
                        }


                        if (person == null)
                        {
                            HttpContext.Current.Response.Write("adding person - " + contentsSplit[(int)accountPos.last] + "<br/>");

                            CRM_Address address = new CRM_Address()
                            {
                                AddressLine1 = "",
                                AddressLine2 = "",
                                AddressLine3 = "",
                                AddressLine4 = "",
                                AddressLine5 = "",
                                CountryID    = country.ID,
                                Postcode     = "",
                                Town         = "",
                                County       = ""
                            };

                            if (contentsSplit[(int)accountPos.company].Trim() == "")
                            {
                                address.AddressLine1 = contentsSplit[(int)accountPos.address].Replace("@", ",");
                                address.Postcode     = contentsSplit[(int)accountPos.zip].Replace("@", ",");
                                address.Town         = contentsSplit[(int)accountPos.city].Replace("@", ",");
                                address.County       = contentsSplit[(int)accountPos.state].Replace("@", ",");
                            }

                            db.CRM_Addresses.InsertOnSubmit(address);
                            db.SubmitChanges();


                            person = new CRM_Person()
                            {
                                CRM_AddressID    = address.ID,
                                AddressType      = (byte)CRM_Address.Types.Business,
                                DateAdded        = UKTime.Now,
                                DateModified     = UKTime.Now,
                                DateOfBirth      = null,
                                Firstname        = contentsSplit[(int)accountPos.first],
                                Lastname         = contentsSplit[(int)accountPos.last],
                                IsArchived       = false,
                                IsCarerMinder    = false,
                                IsChild          = false,
                                IsConcession     = false,
                                IsContactEmail   = true,
                                IsContactPost    = true,
                                IsDeceased       = false,
                                IsDoNotEmail     = false,
                                IsDoNotMail      = false,
                                IsGiftAid        = false,
                                IsMale           = null,
                                LegacyID         = null,
                                PreviousNames    = "",
                                PrimaryEmail     = contentsSplit[(int)accountPos.company].Trim() == "" ? contentsSplit[(int)accountPos.email] : "",
                                PrimaryTelephone = "",
                                Telephone2       = "",
                                Title            = "",
                                Password         = "",
                                TempCode         = ""
                            };

                            db.CRM_Persons.InsertOnSubmit(person);
                            db.SubmitChanges();
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("person exists already - " + contentsSplit[(int)accountPos.last] + "<br/>");
                        }

                        CRM_FormFieldItem gallery   = db.CRM_FormFieldItems.Single(s => s.ID == 9);
                        CRM_FormFieldItem collector = db.CRM_FormFieldItems.Single(s => s.ID == 31);


                        CRM_FormFieldResponse galleryresponse   = db.CRM_FormFieldResponses.FirstOrDefault(f => f.CRM_FormFieldItemID == gallery.ID && f.TargetReference == person.Reference);
                        CRM_FormFieldResponse collectorresponse = db.CRM_FormFieldResponses.FirstOrDefault(f => f.CRM_FormFieldItemID == collector.ID && f.TargetReference == person.Reference);

                        if (galleryresponse == null)
                        {
                            HttpContext.Current.Response.Write("adding gallery for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                            galleryresponse = new CRM_FormFieldResponse()
                            {
                                CRM_FormFieldItemID = gallery.ID,
                                CRM_FormFieldID     = gallery.CRM_FormFieldID,
                                TargetReference     = person.Reference,
                                Answer = ""
                            };

                            db.CRM_FormFieldResponses.InsertOnSubmit(galleryresponse);
                            db.SubmitChanges();
                        }


                        if (collectorresponse == null)
                        {
                            HttpContext.Current.Response.Write("adding collector for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                            collectorresponse = new CRM_FormFieldResponse()
                            {
                                CRM_FormFieldItemID = collector.ID,
                                CRM_FormFieldID     = collector.CRM_FormFieldID,
                                TargetReference     = person.Reference,
                                Answer = ""
                            };

                            db.CRM_FormFieldResponses.InsertOnSubmit(collectorresponse);
                            db.SubmitChanges();
                        }


                        string companystr = contentsSplit[(int)accountPos.company].Replace("@", ",").Trim();

                        if (companystr != "")
                        {
                            CRM_Organisation company = db.CRM_Organisations.FirstOrDefault(s => s.Name.ToUpper() == companystr.ToUpper());

                            if (company == null)
                            {
                                HttpContext.Current.Response.Write("adding company for - " + contentsSplit[(int)accountPos.last] + "<br/>");

                                CRM_Address address = new CRM_Address()
                                {
                                    AddressLine1 = contentsSplit[(int)accountPos.address].Replace("@", ",").Trim(),
                                    AddressLine2 = "",
                                    AddressLine3 = "",
                                    AddressLine4 = "",
                                    AddressLine5 = "",
                                    Town         = contentsSplit[(int)accountPos.city].Replace("@", ","),
                                    County       = "",
                                    Postcode     = contentsSplit[(int)accountPos.zip].Replace("@", ","),
                                    CountryID    = country.ID
                                };


                                db.CRM_Addresses.InsertOnSubmit(address);
                                db.SubmitChanges();

                                company = new CRM_Organisation()
                                {
                                    CRM_AddressID           = address.ID,
                                    IsArchived              = false,
                                    Name                    = companystr,
                                    PrimaryContactReference = "",
                                    CRM_OrganisationTypeID  = 1
                                };

                                db.CRM_Organisations.InsertOnSubmit(company);
                                db.SubmitChanges();
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("company already exists for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                            }

                            CRM_PersonOrganisation personOrg = db.CRM_PersonOrganisations.FirstOrDefault(f => f.CRM_OrganisationID == company.ID && f.CRM_PersonID == person.ID);

                            if (personOrg == null)
                            {
                                HttpContext.Current.Response.Write("adding organisation link for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                                personOrg = new CRM_PersonOrganisation()
                                {
                                    CRM_OrganisationID = company.ID,
                                    CRM_PersonID       = person.ID,
                                    IsArchived         = false,
                                    Telephone          = "",
                                    Email      = contentsSplit[(int)accountPos.email],
                                    CRM_RoleID = 7 // empty
                                };

                                db.CRM_PersonOrganisations.InsertOnSubmit(personOrg);
                                db.SubmitChanges();

                                person.PrimaryAddressID = company.CRM_AddressID;
                                db.SubmitChanges();
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("organisation link already exists for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("no company for - " + contentsSplit[(int)accountPos.last] + "<br/>");
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/FinalListforCoalFace.csv";

            using (StreamReader reader = new StreamReader(Server.MapPath(path)))
            {
                lineNumber = 0;

                while (!reader.EndOfStream)
                {
                    lineNumber++;

                    string contents = reader.ReadLine();
                    if (lineNumber >= startLine && lineNumber <= endLine)
                    {
                        string[] contentsSplit = contents.Split(',');
                        string   errorMessage  = "";

                        CRM_Person person = db.CRM_Persons.FirstOrDefault(f => f.LegacyID != null && f.LegacyID.ToString() == contentsSplit[(int)accountPos.LegacyID]);

                        if (person != null && contentsSplit[(int)accountPos.Constituent] == "Schools and universities")
                        {
                            /*
                             * if (contentsSplit[(int)accountPos.PhoneNumber11].Contains("@"))
                             * {
                             *  person.PrimaryEmail = contentsSplit[(int)accountPos.PhoneNumber11];
                             * }
                             * else
                             * {
                             *  person.PrimaryTelephone = contentsSplit[(int)accountPos.PhoneNumber11];
                             *  person.PrimaryEmail = contentsSplit[(int)accountPos.PhoneNumber12];
                             * }
                             *
                             * if (!contentsSplit[(int)accountPos.PhoneNumber12].Contains("@"))
                             * {
                             *  person.Telephone2 = contentsSplit[(int)accountPos.PhoneNumber12];
                             * }
                             *
                             * db.SubmitChanges();
                             */


                            if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.Address1]))
                            {
                                CRM_School org = db.CRM_Schools.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.Address1]);

                                if (org == null)
                                {
                                    string name = "";

                                    CRM_Address orgAddress = new CRM_Address();
                                    if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.OrgAddr1].Trim()))
                                    {
                                        orgAddress = new CRM_Address()
                                        {
                                            AddressLine1 = contentsSplit[(int)accountPos.OrgAddr1],
                                            AddressLine2 = contentsSplit[(int)accountPos.OrgAddr2],
                                            AddressLine3 = contentsSplit[(int)accountPos.OrgAddr3],
                                            AddressLine4 = contentsSplit[(int)accountPos.OrgAddr4],
                                            AddressLine5 = "",
                                            County       = "",
                                            Town         = contentsSplit[(int)accountPos.OrgAddrCity],
                                            Postcode     = contentsSplit[(int)accountPos.OrgAddrPostcode],
                                            CountryID    = 1
                                        };

                                        db.CRM_Addresses.InsertOnSubmit(orgAddress);
                                        db.SubmitChanges();

                                        name = contentsSplit[(int)accountPos.OrgName];
                                    }
                                    else
                                    {
                                        orgAddress = new CRM_Address()
                                        {
                                            AddressLine1 = contentsSplit[(int)accountPos.Address1],
                                            AddressLine2 = contentsSplit[(int)accountPos.Address2],
                                            AddressLine3 = contentsSplit[(int)accountPos.Address3],
                                            AddressLine4 = contentsSplit[(int)accountPos.Address4],
                                            AddressLine5 = "",
                                            County       = "",
                                            Town         = contentsSplit[(int)accountPos.City],
                                            Postcode     = contentsSplit[(int)accountPos.Postcode],
                                            CountryID    = 1
                                        };


                                        db.CRM_Addresses.InsertOnSubmit(orgAddress);
                                        db.SubmitChanges();
                                        name = contentsSplit[(int)accountPos.Address1];
                                    }

                                    org = new CRM_School()
                                    {
                                        CRM_SchoolTypeID        = 1,
                                        CRM_AddressID           = orgAddress.ID,
                                        Name                    = name,
                                        IsArchived              = false,
                                        PrimaryContactReference = person.Reference,
                                        SENSupportFreq          = "",
                                        SageAccountNumber       = "",
                                        Phone                   = "",
                                        Email                   = ""
                                    };
                                    db.CRM_Schools.InsertOnSubmit(org);
                                    db.SubmitChanges();
                                }

                                CRM_Role role = db.CRM_Roles.FirstOrDefault(f => f.Name == contentsSplit[(int)accountPos.OrgPosition]);

                                if (role == null)
                                {
                                    role = new CRM_Role();
                                    db.CRM_Roles.InsertOnSubmit(role);
                                    role.Name = contentsSplit[(int)accountPos.OrgPosition];
                                    db.SubmitChanges();
                                }

                                CRM_PersonSchool personOrg = new CRM_PersonSchool()
                                {
                                    CRM_SchoolID = org.ID,
                                    CRM_RoleID   = role.ID,
                                    IsArchived   = false,
                                    Email        = "",
                                    Telephone    = contentsSplit[(int)accountPos.PhoneNumber21],
                                    CRM_PersonID = person.ID
                                };

                                db.CRM_PersonSchools.InsertOnSubmit(personOrg);
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
        }