protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //

            object oldEntity = null;

            if (newRecord)
            {
                Entity = new CRM_RelationCode();
                db.CRM_RelationCodes.InsertOnSubmit(Entity);
            }

            Entity.Name = txtName.Text;

            db.SubmitChanges();

            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(AdminUser, oldEntity, Entity);
                db.SubmitChanges();
            }
            else
            {
                CRM.Code.History.History.RecordLinqInsert(AdminUser, Entity);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RunSecurity(CRM.Code.Models.Admin.AllowedSections.NotSet);
            Entity = db.CRM_RelationCodes.SingleOrDefault(c => c.ID.ToString() == Request.QueryString["id"]);

            btnSubmitChanges.Visible = PermissionManager.CanUpdate;
            if (!PermissionManager.CanAdd && Entity == null)
            {
                Response.Redirect("list.aspx");
            }

            // buttons //

            btnSubmit.EventHandler        = btnSubmit_Click;
            btnSubmitChanges.EventHandler = btnSubmitChanges_Click;
            btnDelete.EventHandler        = btnDelete_Click;

            // Security //

            btnSubmitChanges.Visible = PermissionManager.CanUpdate;
            btnDelete.Visible        = PermissionManager.CanDelete;
            if (!PermissionManager.CanAdd && Entity == null)
            {
                Response.Redirect("list.aspx");
            }

            // confirmations //

            confirmationDelete.StandardDeleteHidden("role", btnRealDelete_Click);

            // process //

            CRMContext = Entity;
            if (!IsPostBack)
            {
                if (Entity != null)
                {
                    PopulateFields();
                }
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RunSecurity(CRM.Code.Models.Admin.AllowedSections.NotSet);
            PersonRelationship = db.CRM_PersonRelationships.SingleOrDefault(c => c.ID.ToString() == Request.QueryString["pid"]);

            btnSubmitChanges.Visible = PermissionManager.CanUpdate;
            if (!PermissionManager.CanAdd && Entity == null)
            {
                Response.Redirect("list.aspx");
            }

            ucNavPerson.Entity = Entity;
            ucLogNotes.INotes  = PersonRelationship;

            ucAcPerson.EventHandler = lnkSelect_Click;
            ucAcPerson.Config       = new AutoCompleteConfig(JSONSet.DataSets.person);

            ucAcPersonB.EventHandler = lnkSelectB_Click;
            ucAcPersonB.Config       = new AutoCompleteConfig(JSONSet.DataSets.person);

            // buttons //

            btnSubmit.EventHandler        = btnSubmit_Click;
            btnSubmitChanges.EventHandler = btnSubmitChanges_Click;
            btnDelete.EventHandler        = btnDelete_Click;
            // Security //

            btnSubmitChanges.Visible = PermissionManager.CanUpdate;
            btnDelete.Visible        = PermissionManager.CanDelete;
            if (!PermissionManager.CanAdd && Entity == null)
            {
                Response.Redirect("list.aspx");
            }

            // confirmations //

            confirmationDelete.StandardDeleteHidden("personal relationship record", btnRealDelete_Click);

            // process //

            CRMContext = Entity;

            if (!IsPostBack)
            {
                ddlRelationCodeToA.DataSource = CRM_RelationCode.BaseSet(db);
                ddlRelationCodeToA.DataBind();

                ddlRelationCodetoB.DataSource = CRM_RelationCode.BaseSet(db);
                ddlRelationCodetoB.DataBind();

                if (PersonRelationship != null)
                {
                    PopulateFields();
                }
                else
                {
                    ucAcPerson.Populate(Entity);
                    RebindAddresses();
                }
            }
        }
示例#4
0
        protected void PopulateFields()
        {
            txtFirstname.Text = Entity.Firstname;
            txtLastname.Text  = Entity.Lastname;
            txtEmail.Text     = Entity.Email;
            txtAddress1.Text  = Entity.Address1;
            txtAddress2.Text  = Entity.Address2;
            txtAddress3.Text  = Entity.Address3;
            txtCity.Text      = Entity.City;
            txtCounty.Text    = Entity.County;
            txtPostcode.Text  = Entity.Postcode;
            txtTelephone.Text = Entity.Telephone;

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            IEnumerable <ListItem> interests = db.CRM_FormFieldItems.Where(f => f.CRM_FormFieldID == 24 && f.IsActive && !f.IsArchived).Select(s => new ListItem(s.Label, s.ID.ToString()));


            rptConstituent.DataSource = db.CRM_FormFieldItems.Where(f => f.CRM_FormFieldID == 1 &&
                                                                    f.IsActive && !f.IsArchived
                                                                    );
            rptConstituent.DataBind();

            if (Entity.JointBtoAID != null)
            {
                CRM_RelationCode code = db.CRM_RelationCodes.SingleOrDefault(f => f.ID == Entity.JointBtoAID);
                if (code != null)
                {
                    litOtherRecordRel.Text = code.Name;
                }
            }


            if (Entity.JointAtoBID != null)
            {
                CRM_RelationCode code = db.CRM_RelationCodes.SingleOrDefault(f => f.ID == Entity.JointAtoBID);
                if (code != null)
                {
                    litFromRel.Text = code.Name;
                }
            }

            try
            {
                if (Entity.InterestObjects != null)
                {
                    var items = from p in serializer.Deserialize <IEnumerable <CRM.WebService.CRMSync.InterestAnswer> >(Entity.InterestObjects)
                                select p;

                    rptInterests.DataSource = interests;
                    rptInterests.DataBind();
                }
            }
            catch (ArgumentNullException ex) { }

            /*
             * for (int i = 0; i < rptInterests.Items.Count; i++)
             * {
             *
             *  foreach (CRM.WebService.CRMSync.InterestAnswer displayItem in items)
             *  {
             *
             *      if (rptInterests.Items[i].Value == displayItem.FormFieldItemID.ToString() && displayItem.OptIn == true)
             *          rptInterests.Items[i].Selected = true;
             *  }
             *
             * }
             */
        }
示例#5
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();
                            }
                        }
                    }
                }
            }
        }