示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Entity = db.HoldingPens.Single(c => c.ID.ToString() == Request.QueryString["id"]);


            Dictionary <byte, string> comparibles = new Dictionary <byte, string>();

            comparibles.Add((byte)CRM_Person.SearchKeys.DoB, "");
            comparibles.Add((byte)CRM_Person.SearchKeys.PrimaryEmail, Entity.Email);
            comparibles.Add((byte)CRM_Person.SearchKeys.Postcode, Entity.Postcode);
            comparibles.Add((byte)CRM_Person.SearchKeys.Telephone, Entity.Telephone);
            comparibles.Add((byte)CRM_Person.SearchKeys.Fullname, Entity.Firstname + " " + Entity.Lastname);


            if (!Page.IsPostBack)
            {
                lnkNextRecord.Text += " (" + (HoldingPen.BaseSet(db).Count() - 1 - HoldingPen.BaseSet(db).ToList().IndexOf(Entity)) + " remaining)";


                var dupes = from p in CRM_Person.BaseSet(db)
                            where p.SearchDictionary.Any(c => comparibles.ContainsKey(c.Key) && comparibles[c.Key].Trim() != "" && c.Value.ToLower().Trim() == (comparibles[c.Key].ToLower().Trim()))
                            orderby p.SearchDictionary.Where(c => comparibles.ContainsKey(c.Key) && comparibles[c.Key].Trim() != "" && c.Value.ToLower().Trim() == (comparibles[c.Key])).Count() descending
                            select(object) p;

                lvItems.DataSource = dupes.Take(20);
                lvItems.DataBind();

                ddlTitle.DataSource = from p in db.CRM_Titles
                                      select p;
                ddlTitle.DataBind();

                PopulateFields();
            }
        }
示例#2
0
        protected void lnkSelectNew_Click(object sender, EventArgs e)
        {
            CRM_Person person = db.CRM_Persons.Single(c => c.ID.ToString() == ucACNewPerson.SelectedID);

            AddPersonToPass(person.Reference);
            NoticeManager.SetMessage(person.Fullname + " added to pass " + Entity.MembershipNumber);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Type   Type     = Type.GetType(Request.QueryString["namespace"]);
            object myObject = Activator.CreateInstance(Type);

            MainDataContext db = new MainDataContext();

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            object[] comparibles = (object[])serializer.DeserializeObject(Request.QueryString["compare"]);

            var collection = comparibles.Select(c => c);

            var items = from p in ((IDuplicate)myObject).GetBaseSet(db)
                        where p.ID.ToString() != Request.QueryString["id"]
                        select(object) p;


            ucList.Type = Type;

            try
            {
                //todo:compare both dictionaries against eachother.  Any and Count are calling same query twice so should be arranged into one object
                ucList.DataSet = from p in CRM_Person.BaseSet(db)
                                 where p.SearchDictionary.Any(c => (int)((Array)comparibles[c.Key]).Length > 0 && ((Array)comparibles[(int)((Array)comparibles[c.Key]).GetValue(0)]) != null && c.Value.ToLower().Trim() == ((string)((Array)comparibles[(int)((Array)comparibles[c.Key]).GetValue(0)]).GetValue(1)).ToLower().Trim() && c.Value != "")
                                 where p.ID.ToString() != Request.QueryString["id"]
                                 orderby p.SearchDictionary.Count(c => (int)((Array)comparibles[c.Key]).Length > 0 && ((Array)comparibles[(int)((Array)comparibles[c.Key]).GetValue(0)]) != null && c.Value.ToLower().Trim() == ((string)((Array)comparibles[(int)((Array)comparibles[c.Key]).GetValue(0)]).GetValue(1)).ToLower().Trim() && c.Value != "") descending
                                 select(object) p;
            }
            catch { }

            ucList.ItemsPerPage      = 10000;
            ucList.ShowCustomisation = false;
            ucList.ShowExport        = false;
        }
示例#4
0
        protected CRM_Person TransformPerson(CRM_Person person)
        {
            if (chkTitle.Checked)
            {
                person.Title = ddlTitle.SelectedItem.Text;
            }

            if (chkFirstname.Checked)
            {
                person.Firstname = txtFirstname.Text;
            }

            if (chkLastname.Checked)
            {
                person.Lastname = txtLastname.Text;
            }

            if (chkEmail.Checked)
            {
                person.PrimaryEmail = txtEmail.Text;
            }

            if (chkAddress1.Checked)
            {
                person.PrimaryAddress.AddressLine1 = txtAddress1.Text;
            }

            if (chkAddress2.Checked)
            {
                person.PrimaryAddress.AddressLine2 = txtAddress2.Text;
            }

            if (chkAddress3.Checked)
            {
                person.PrimaryAddress.AddressLine3 = txtAddress3.Text;
            }

            if (chkCity.Checked)
            {
                person.PrimaryAddress.Town = txtCity.Text;
            }

            if (chkCounty.Checked)
            {
                person.PrimaryAddress.County = txtCounty.Text;
            }

            if (chkPostcode.Checked)
            {
                person.PrimaryAddress.Postcode = txtPostcode.Text;
            }

            if (chkTel.Checked)
            {
                person.PrimaryTelephone = txtTelephone.Text;
            }

            return(person);
        }
示例#5
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 + ")");
        }
示例#6
0
        public new void Page_PreInit(object sender, EventArgs e)
        {
            base.Page_PreInit(sender, e);

            Entity = db.CRM_Persons.SingleOrDefault(a => a.ID.ToString() == Request.QueryString["id"]);

            if (Entity == null)
            {
                NoticeManager.SetMessage("Person not found", "/admin/person/list.aspx");
            }
        }
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext   db     = new MainDataContext();
            HttpServerUtility Server = HttpContext.Current.Server;
            string            path   = "/TaskScript/payment_history.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  = "";

                        try
                        {
                            CRM_Person person = db.CRM_Persons.SingleOrDefault(s => s.LegacyID.ToString() == contentsSplit[(int)accountPos.ConstituteID]);

                            var passes = person.CRM_AnnualPassPersons.Select(c => c.CRM_AnnualPass);

                            foreach (CRM_AnnualPass pass in passes)
                            {
                                if (pass.ExpiryDate.ToString("MM/dd/yyyy") == SwitchUsToUk(contentsSplit[(int)accountPos.HistoryExpireDate]).ToString("MM/dd/yyyy") && pass.CRM_AnnualPassCard.MembershipNumber.ToString() == contentsSplit[(int)accountPos.MembershipID])
                                {
                                    pass.AmountPaid = Convert.ToDecimal(contentsSplit[(int)accountPos.TotalAmount].Substring(1));

                                    try
                                    {
                                        pass.PaymentMethod = (byte)Enumeration.GetEnumValueByName <CRM.Code.Helpers.PaymentType.Types>(contentsSplit[(int)accountPos.PayMethod]);
                                    }
                                    catch
                                    {
                                        pass.PaymentMethod = (byte)CRM.Code.Helpers.PaymentType.Types.Unknown;
                                        HttpContext.Current.Response.Write(pass.ID + "<br/>");
                                    }
                                }
                            }

                            db.SubmitChanges();
                        }
                        catch { }
                    }
                }
            }
        }
示例#8
0
        protected void AddPersonToPass(string reference)
        {
            CRM_Person           person     = db.CRM_Persons.Single(p => p.Reference == reference);
            CRM_AnnualPassPerson passperson = new CRM_AnnualPassPerson()
            {
                CRM_AnnualPassID = CRM_AnnualPass.ID,
                CRM_PersonID     = person.ID,
                IsArchived       = false
            };

            db.CRM_AnnualPassPersons.InsertOnSubmit(passperson);
            db.SubmitChanges();
        }
示例#9
0
        protected void ApplyConstituentsToSelected(CRM_Person person)
        {
            foreach (RepeaterItem item in rptConstituent.Items)
            {
                CheckBox           chk = (CheckBox)item.FindControl("chkOption");
                HtmlGenericControl lbl = (HtmlGenericControl)item.FindControl("lblOption");

                if (chk.Checked)
                {
                    ApplyCustomField(person, 1, Convert.ToInt32(chk.Attributes["data-id"]));
                }
            }
        }
        protected void lnkSelect_Click(object sender, EventArgs e)
        {
            CRM_Person       person  = CRM_Person.BaseSet(db).Single(v => v.ID.ToString() == ucACFamily.SelectedID);
            CRM_FamilyPerson fPerson = new CRM_FamilyPerson()
            {
                CRM_FamilyID     = Entity.ID,
                CRM_PersonID     = person.ID,
                IsPrimaryContact = false
            };

            db.CRM_FamilyPersons.InsertOnSubmit(fPerson);
            db.SubmitChanges();

            NoticeManager.SetMessage(person.Name + " added to the family");
        }
示例#11
0
        protected void ApplyCustomField(CRM_Person Person, int formFieldID, int formFieldItemID)
        {
            IEnumerable <CRM_FormFieldResponse> answers =
                db.CRM_FormFieldResponses.Where(f => f.CRM_FormFieldID == formFieldID && f.TargetReference == Person.Reference && f.CRM_FormFieldItemID == formFieldItemID);

            if (!answers.Any())
            {
                CRM_FormFieldResponse answer = new CRM_FormFieldResponse()
                {
                    CRM_FormFieldItemID = formFieldItemID,
                    CRM_FormFieldID     = formFieldID,
                    Answer          = "",
                    TargetReference = Person.Reference
                };

                db.CRM_FormFieldResponses.InsertOnSubmit(answer);
            }

            db.SubmitChanges();
        }
        public void ProcessRequest(HttpContext context)
        {
            MainDataContext db = new MainDataContext();

            var dueReminders = (from p in db.CRM_AnnualPasses
                                where !p.IsArchived
                                where !p.IsPending
                                where p.ExpiryDate.Date >= new DateTime(2014, 08, 01)
                                where p.ExpiryDate.Date < UKTime.Now
                                where p.PaymentMethod == (byte)CRM.Code.Helpers.PaymentType.Types.Cash ||
                                p.PaymentMethod == (byte)CRM.Code.Helpers.PaymentType.Types.CreditCard
                                select p);

            HttpContext.Current.Response.Write("Sending " + dueReminders.Count());

            foreach (CRM_AnnualPass pass in dueReminders)
            {
                try
                {
                    EmailManager      manager     = new EmailManager();
                    AnnualPassManager passManager = new AnnualPassManager();
                    CRM_Person        person      = passManager.GetPrimaryContact(pass);

                    if (person != null && !String.IsNullOrEmpty(person.PrimaryEmail))
                    {
                        if (person.PrimaryEmail != "*****@*****.**" && person.PrimaryEmail != "*****@*****.**")
                        {
                            manager.SendRenewalEmail(pass, db, person.PrimaryEmail);
                        }
                        HttpContext.Current.Response.Write("Sent");
                    }
                }
                catch
                {
                    EmailManager manager = new EmailManager();
                    manager.AddTo(Constants.DeveloperEmail);
                    manager.SendNonTemplate("Failed pass reminder on jupiter CRM - ID " + pass.ID.ToString(), "Failed Jupiter CRM reminder");
                }
            }
        }
示例#13
0
        protected void AddRelationship(CRM_Person person)
        {
            if (Entity.JointHoldingPenID != null)
            {
                CRM_Person otherRecord = db.CRM_Persons.FirstOrDefault(f => f.WebsiteAccountID == Entity.OriginAccountID &&
                                                                       Entity.OriginType == (byte)HoldingPen.Origins.websitemembership &&
                                                                       person.ID != f.ID);

                if (otherRecord != null)
                {
                    CRM_PersonRelationship relationship = new CRM_PersonRelationship();
                    relationship.CRM_PersonIDAddress = person.ID;
                    relationship.PersonA             = otherRecord;
                    relationship.PersonB             = person;
                    relationship.CRM_RelationCodeID  = (int)Entity.JointAtoBID;
                    relationship.CRM_RelationCodeID2 = (int)Entity.JointBtoAID;
                    relationship.Salutation          = Entity.JointSalutation;

                    db.CRM_PersonRelationships.InsertOnSubmit(relationship);
                    db.SubmitChanges();
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            var             jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            StringBuilder   item           = new StringBuilder();
            MainDataContext db             = new MainDataContext();


            string basepersonid = HttpContext.Current.Request.QueryString["basepersonid"];
            string reference    = HttpContext.Current.Request.QueryString["reference"];
            string addressID    = HttpContext.Current.Request.QueryString["addressID"];

            CRM_Person person = db.CRM_Persons.SingleOrDefault(s => s.ID.ToString() == HttpContext.Current.Request.QueryString["basepersonid"]);

            List <ILabel> labels = person.Labels;

            ILabel label = labels.FirstOrDefault(f => f.Reference == reference);

            if (!String.IsNullOrEmpty(addressID))
            {
                label = labels.FirstOrDefault(f => f.LabelCRM_AddressID.ToString() == addressID);
            }


            string labelOutput = label.LabelName;

            if (!String.IsNullOrEmpty(label.LabelOrganisation))
            {
                labelOutput += label.LabelOrganisation;
            }

            labelOutput += label.LabelAddress;



            jsonSerializer.Serialize(new { Address = labelOutput }, item);
            HttpContext.Current.Response.Write(item.ToString());
        }
示例#15
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();
                            }
                        }
                    }
                }
            }
        }
示例#16
0
        public void RunImport(int startLine, int endLine)
        {
            MainDataContext db = new MainDataContext();

            HttpServerUtility Server = HttpContext.Current.Server;

            string path = "/TaskScript/payment_history.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  = "";

                        try
                        {
                            CRM_Person person = db.CRM_Persons.SingleOrDefault(s => s.LegacyID.ToString() == contentsSplit[(int)accountPos.ConstituteID]);

                            if (person != null)
                            {
                                DateTime startDate = SwitchUsToUk(contentsSplit[(int)accountPos.JoinedOn]);

                                if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.HistoryRenewDate]))
                                {
                                    startDate = SwitchUsToUk(contentsSplit[(int)accountPos.HistoryRenewDate]);
                                }

                                CRM_AnnualPass pass = db.CRM_AnnualPasses.ToArray().FirstOrDefault(f =>
                                                                                                   f.CRM_AnnualPassCard.MembershipNumber.ToString() == contentsSplit[(int)accountPos.MembershipID] &&
                                                                                                   f.CRM_AnnualPassPersons.Any(c => c.CRM_PersonID == person.ID) &&
                                                                                                   f.StartDate.ToString("dd/MM/yyyy") == startDate.ToString("dd/MM/yyyy"));


                                if (pass == null)
                                {
                                    CRM_AnnualPassCard card = db.CRM_AnnualPassCards.FirstOrDefault(s => s.MembershipNumber.ToString() == contentsSplit[(int)accountPos.MembershipID]);

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

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

                                    pass = new CRM_AnnualPass()
                                    {
                                        AmountPaid              = 0,
                                        CRM_AnnualPassCardID    = card.ID,
                                        CRM_OfferID             = null,
                                        DiscountApplied         = "",
                                        IsArchived              = false,
                                        IsPending               = false,
                                        PrimaryContactReference = person.Reference
                                    };

                                    db.CRM_AnnualPasses.InsertOnSubmit(pass);
                                }


                                pass.StartDate = startDate;

                                if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.HistoryExpireDate]))
                                {
                                    pass.ExpiryDate = SwitchUsToUk(contentsSplit[(int)accountPos.HistoryExpireDate]);
                                }
                                else
                                {
                                    pass.ExpiryDate = pass.StartDate.AddYears(1);
                                }


                                try
                                {
                                    pass.PaymentMethod = (byte)Enumeration.GetEnumValueByName <CRM.Code.Helpers.PaymentType.Types>(contentsSplit[(int)accountPos.PayMethod]);
                                }
                                catch
                                {
                                    pass.PaymentMethod = (byte)CRM.Code.Helpers.PaymentType.Types.Unknown;
                                }

                                if (!String.IsNullOrEmpty(contentsSplit[(int)accountPos.TotalAmount]))
                                {
                                    pass.AmountPaid = Convert.ToDecimal(contentsSplit[(int)accountPos.TotalAmount].Substring(1));
                                }
                                else
                                {
                                    pass.AmountPaid = 0M;
                                }


                                CRM_AnnualPassType type = db.CRM_AnnualPassTypes.FirstOrDefault(f => f.DefaultPrice == pass.AmountPaid);

                                if (type == null)
                                {
                                    pass.CRM_AnnualPassTypeID = db.CRM_AnnualPassTypes.First(f => f.ID == 15).ID;
                                }
                                else
                                {
                                    pass.CRM_AnnualPassTypeID = type.ID;
                                }

                                db.SubmitChanges();

                                if (!pass.CRM_AnnualPassPersons.Any(c => c.CRM_PersonID == person.ID))
                                {
                                    CRM_AnnualPassPerson passperson = new CRM_AnnualPassPerson()
                                    {
                                        CRM_PersonID     = person.ID,
                                        IsArchived       = false,
                                        CRM_AnnualPassID = pass.ID
                                    };

                                    db.CRM_AnnualPassPersons.InsertOnSubmit(passperson);
                                    db.SubmitChanges();
                                }
                            }
                            else
                            {
                                HttpContext.Current.Response.Write(contentsSplit[(int)accountPos.ConstituteID] + " person not found");
                            }
                        }
                        catch (Exception ex)
                        {
                            HttpContext.Current.Response.Write(ex.Message);
                            HttpContext.Current.Response.Write(lineNumber);
                            HttpContext.Current.Response.End();
                        }
                    }
                }
            }
        }
示例#17
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();
                            }
                        }
                    }
                }
            }
        }
        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/>");
                        }
                    }
                }
            }
        }
示例#19
0
        internal static void ContactsByInterest(List <ExportByInterestHelper> Helpers, List <CRM_FormFieldItem> interests, HttpResponse Response)
        {
            string columns = "Title, Firstname, Lastname, IsAnnualPassHolder, PrimaryEmail, CalculatedSalutation, PrimaryAddressLine1, PrimaryAddressLine2, PrimaryAddressLine3, PrimaryAddressLine4, PrimaryAddressLine5, PrimaryAddressTown, PrimaryAddressCounty, PrimaryAddressPostcode, PrimaryAddressCountry, NextExpiryDate, IsDoNotEmail, IsDoNotMail, IsDeceased, ";

            string filename = "contacts_by_interest";

            Response.Clear();
            Response.ContentType = "text/csv";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + "-" + DateTime.UtcNow.ToString("dd-MM-yyyy") + ".csv\"");
            Response.ContentEncoding = Encoding.GetEncoding("Windows-1252");


            foreach (CRM_FormFieldItem item in interests)
            {
                columns += item.DisplayName.Replace(",", "") + ",";
            }

            HttpContext.Current.Response.Write(columns);
            HttpContext.Current.Response.Write(Environment.NewLine);


            StringBuilder sbItems = new StringBuilder();

            foreach (ExportByInterestHelper helper in Helpers)
            {
                CRM_Person p = helper.Person;

                AddComma(p.Title, sbItems);
                AddComma(p.Firstname, sbItems);
                AddComma(p.Lastname, sbItems);
                AddComma(p.IsAnnualPassHolder ? "TRUE" : "FALSE", sbItems);
                AddComma(p.PrimaryEmail, sbItems);
                AddComma(p.CalculatedSalutation, sbItems);
                AddComma(p.PrimaryAddressLine1, sbItems);
                AddComma(p.PrimaryAddressLine2, sbItems);
                AddComma(p.PrimaryAddressLine3, sbItems);
                AddComma(p.PrimaryAddressLine4, sbItems);
                AddComma(p.PrimaryAddressLine5, sbItems);
                AddComma(p.PrimaryAddressTown, sbItems);
                AddComma(p.PrimaryAddressCounty, sbItems);
                AddComma(p.PrimaryAddressPostcode, sbItems);
                AddComma(p.PrimaryAddressCountry, sbItems);
                AddComma(p.NextExpiryDate, sbItems);
                AddComma(p.IsDoNotEmail ? "TRUE" : "FALSE", sbItems);
                AddComma(p.IsDoNotMail ? "TRUE" : "FALSE", sbItems);
                AddComma(p.IsDeceased ? "TRUE" : "FALSE", sbItems);

                foreach (CRM_FormFieldItem interest in interests)
                {
                    if (helper.Responses.Any(c => c.TargetReference == p.Reference && c.CRM_FormFieldItemID == interest.ID))
                    {
                        AddComma("TRUE", sbItems);
                    }
                    else
                    {
                        AddComma("FALSE", sbItems);
                    }
                }

                Response.Write(sbItems.ToString());
                Response.Write(Environment.NewLine);
                sbItems = new StringBuilder();
            }


            Response.End();
        }
示例#20
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();
                        }

                    }
                }
            }
        }
示例#21
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();
                        }
                    }
                }
            }
        }
示例#22
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/>");
                        }
                    }
                }
            }
        }
示例#23
0
        public void ProcessRequest(HttpContext context)
        {
            string JSONOutput = EmptyOutput;

            context.Response.AddHeader("Content-type", "text/json");
            using (MainDataContext db = new MainDataContext())
            {
                string dataset = context.Request.QueryString["dataset"];


                int    parseddataset  = Enumeration.GetEnumValueByName <JSONSet.DataSets>(dataset);
                string searchCriteria = HttpUtility.HtmlDecode(context.Request.QueryString["query"]).ToLower();

                IEnumerable <JSONSet> jsonItems = Enumerable.Empty <JSONSet>();

                switch (parseddataset)
                {
                case (int)JSONSet.DataSets.venue:
                {
                    var venues = CRM_Venue.BaseSet(db);
                    jsonItems = from p in venues
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_Address.Postcode, p.Reference.ToString(), "", p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.person:
                {
                    var persons = CRM_Person.BaseSet(db);
                    jsonItems = from p in persons
                                where !p.IsArchived
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Fullname + " : " + p.PrimaryAddressRecord.FormattedAddressBySep(", "), p.DateOfBirthOutput, p.ID.ToString(), p.Photo, p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.archivedperson:
                {
                    var persons = db.CRM_Persons;
                    jsonItems = from p in (from p in persons
                                           where p.IsArchived
                                           select p).ToList()
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Fullname + " : " + p.PrimaryAddressRecord.FormattedAddressBySep(", "), p.DateOfBirthOutput, p.Reference.ToString(), p.Photo, p.Reference);
                }
                break;


                case (int)JSONSet.DataSets.contact:
                {
                    var unarchivedContacts = from p in CRM.Code.Utils.SharedObject.SharedObject.GetSharedObjects <IContact>(db)
                                             where !p.IsArchived
                                             select p;

                    jsonItems = from p in unarchivedContacts
                                where p.Tokens.Any(t => t.ToLower().Contains(searchCriteria.ToLower()))
                                orderby p.Lastname, p.Firstname
                    select new JSONSet(p.Fullname + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.OutputTableName, p.Reference, p.Photo, p.CRM_PersonReference);
                }
                break;

                case (int)JSONSet.DataSets.organisation:
                {
                    var orgs = CRM_Organisation.BaseSet(db);
                    jsonItems = from p in orgs
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_OrganisationType.Name, p.ID.ToString(), "", p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.school:
                {
                    var schools = CRM_School.BaseSet(db);
                    jsonItems = from p in schools
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.CRM_SchoolType.Name, p.ID.ToString(), "", p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.schoolperson:
                {
                    var schoolsp = CRM_PersonSchool.BaseSet(db);
                    jsonItems = from p in schoolsp
                                where !p.IsArchived
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.CRM_School.Name, p.ID.ToString(), p.CRM_Person.Photo, p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.orgperson:
                {
                    var orgpers = CRM_PersonOrganisation.BaseSet(db);
                    jsonItems = from p in orgpers
                                where !p.IsArchived
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.PrimaryAddress.FormattedAddressBySep(", "), p.CRM_Organisation.Name, p.ID.ToString(), p.CRM_Person.Photo, p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.family:
                {
                    var families = CRM_Family.BaseSet(db);
                    jsonItems = from p in families
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.CRM_FamilyPersons.Count() + " members", p.MemberList, p.ID.ToString(), "", p.Reference);
                }
                break;

                case (int)JSONSet.DataSets.mytasks:
                {
                    var tasks = db.CRM_Tasks.ToArray().Where(c => c.IsVisible(Convert.ToInt32(HttpContext.Current.Request.QueryString["adminuserid"])));
                    jsonItems = from p in tasks
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + "", p.DueDate.ToString("dd/MM/yyyy"), p.ID.ToString(), "", p.Reference);
                }
                break;


                case (int)JSONSet.DataSets.admin:
                {
                    var admins = db.Admins.ToArray();
                    jsonItems = from p in admins
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.DisplayName + "",
                                                   p.LastLogin == null ? "Never logged in" : "Last Login: "******"dd/MM/yyyy HH:mm"),
                                                   p.ID.ToString(), "", p.ID.ToString());
                }
                break;

                case (int)JSONSet.DataSets.schoolorgs:
                {
                    var schoolorgs = CRM.Code.Utils.SharedObject.SharedObject.GetSharedObjects <ISchoolOrganisation>(db);

                    jsonItems = from p in schoolorgs
                                where p.Tokens.Any(t => t.Contains(searchCriteria))
                                select new JSONSet(p.Name + " : " + p.CRM_Address.FormattedAddressBySep(", "), p.OutputTableName,
                                                   p.Reference, "", p.Reference.ToString());
                }
                break;
                }

                if (jsonItems.Any())
                {
                    JSONOutput = JSONSet.ConvertToJSON(jsonItems);
                }
                else
                {
                    jsonItems  = Enumerable.Concat(jsonItems, new [] { new JSONSet("No results found", "Please alter your search", "", "", "") });
                    JSONOutput = JSONSet.ConvertToJSON(jsonItems);
                }
                context.Response.Write(JSONOutput);
            }

            context.Response.End();
        }