Esempio n. 1
0
        protected void rptConstituent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            CRM_FormFieldItem item = (CRM_FormFieldItem)e.Item.DataItem;

            CheckBox chk = (CheckBox)e.Item.FindControl("chkOption");

            chk.Attributes["data-id"] = item.ID.ToString();

            HtmlGenericControl lblOption = (HtmlGenericControl)e.Item.FindControl("lblOption");

            lblOption.InnerText         = item.Label;
            lblOption.Attributes["for"] = chk.ClientID;

            /*
             * if (item.ID == 18 && Entity.BasketContents.Contains("Event"))
             * {
             *  chk.Checked = true;
             * }*/

            if (item.ID == 20)
            {
                chk.Checked = true;
            }

            if (item.ID == 1 && (Entity.MembershipA != "" || Entity.MembershipB != ""))
            {
                chk.Checked = true;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            MainDataContext db = new MainDataContext();

            foreach (CRM_FormFieldAnswer formFieldAnswer in db.CRM_FormFieldAnswers)
            {
                string[] individualAnswerSet = formFieldAnswer.Answer.Split(new string[] { "<br/>" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string individualAnswer in individualAnswerSet)
                {
                    CRM_FormField     field = formFieldAnswer.CRM_FormField;
                    CRM_FormFieldItem item  = field.CRM_FormFieldItems.FirstOrDefault(f => f.Label == individualAnswer);


                    CRM_FormFieldResponse formFieldResponse = new CRM_FormFieldResponse();
                    formFieldResponse.TargetReference = formFieldAnswer.TargetReference;
                    formFieldResponse.CRM_FormFieldID = field.ID;

                    if (field.Type == (byte)CRM_FormField.Types.SingleLineTextBox || field.Type == (byte)CRM_FormField.Types.MultiLineTextBox || field.Type == (byte)CRM_FormField.Types.SingleCheckBox)
                    {
                        formFieldResponse.Answer = individualAnswer;
                        formFieldResponse.CRM_FormFieldItemID = null;
                        db.CRM_FormFieldResponses.InsertOnSubmit(formFieldResponse);
                        db.SubmitChanges();

                        if (individualAnswerSet.Count() > 1)
                        {
                            HttpContext.Current.Response.Write("multiple answers for single item" + individualAnswerSet.Count() + " on " + formFieldAnswer.ID);
                        }
                    }
                    else
                    {
                        if (item == null)
                        {
                            // this answer doesn't exist as an option, possibly because of the issue we are resolving here (changing parent item doesn't update responses since just a mash of strings).

                            item                 = new CRM_FormFieldItem();
                            item.IsArchived      = true;
                            item.IsActive        = false;
                            item.Label           = individualAnswer;
                            item.OrderNo         = CRM.Code.Utils.Ordering.Ordering.GetNextOrderID(db.CRM_FormFieldItems);
                            item.CRM_FormFieldID = field.ID;
                            db.CRM_FormFieldItems.InsertOnSubmit(item);
                            db.SubmitChanges();
                        }


                        formFieldResponse.Answer = "";
                        formFieldResponse.CRM_FormFieldItemID = item.ID;
                        db.CRM_FormFieldResponses.InsertOnSubmit(formFieldResponse);
                        db.SubmitChanges();
                    }
                }
            }
        }
Esempio n. 3
0
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/ConstTypes.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.CRM_FormFieldID == 1 && f.Label.ToLower() == contentsSplit[(int)accountPos.ConstDesc].ToLower());


                        if (ffItem == null)
                        {
                            ffItem = new CRM_FormFieldItem()
                            {
                                Label           = contentsSplit[(int)accountPos.ConstDesc],
                                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.SingleOrDefault(s => s.LegacyID.ToString() == contentsSplit[(int)accountPos.ConstID]);

                        if (person != null)
                        {
                            CRM_FormFieldAnswer answer = db.CRM_FormFieldAnswers.FirstOrDefault(f => f.TargetReference == person.Reference && f.CRM_FormFieldID == 1);


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

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

                                if (!items.Any(i => i == contentsSplit[(int)accountPos.ConstDesc]))
                                {
                                    answer.Answer += "<br/>" + contentsSplit[(int)accountPos.ConstDesc];
                                }

                                db.SubmitChanges();
                            }
                        }
                        else
                        {
                            HttpContext.Current.Response.Write("Person not in system - " + contentsSplit[(int)accountPos.ConstID] + "<br/>");
                        }
                    }
                }
            }
        }
Esempio n. 4
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();
                        }
                    }
                }
            }
        }
        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/>");
                        }
                    }
                }
            }
        }