private void CreateChapterAddress(int chID)
        {
            int newChaKey = 0;
            ChapterAddressDataContext cadc = new ChapterAddressDataContext();
            ChapterAddress            ca   = new ChapterAddress();

            ca.ChapterId      = chID;
            ca.Active         = true;
            ca.StreetAddress1 = txtStreetAddr1.Text.ToString();
            ca.City           = txtCity.Text.ToString();
            ca.StateId        = Convert.ToInt32(cboState.SelectedValue);
            ca.Zip            = txtZip.Text.ToString();
            ca.DateCreated    = System.DateTime.Now;
            ca.DateModified   = System.DateTime.Now;
            try
            {
                cadc.ChapterAddresses.InsertOnSubmit(ca);
                cadc.SubmitChanges();
                newChaKey = ca.ChapterAddressId;
            }
            catch (Exception exceptCha)
            {
                MessageBox.Show(exceptCha.ToString());
            }
            //MessageBox.Show("New Chapter ID " + chID.ToString() +" New Chapter Address Key  "+ newChaKey.ToString());
            //If Successful Update the Google Link
            if (newChaKey > 0)
            {
                UpdateChapterGLink(chID, newChaKey);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the Google Link in the Miles table, shows the best google route, Below is an example
        /// ///https://www.google.com/maps/dir/2472+Marietta+Hwy+Canton+GA+30114/221+Amber+Ridge+Rd+Statham+GA+30680/
        /// </summary>
        /// <param name="toChapter"></param>
        /// <param name="fromChapter"></param>
        /// <returns></returns>
        public static string CreateGoogleMilesTableLink(int fromChapter, int toChapter)
        {
            string milesgUri = string.Empty;
            ChapterAddressDataContext cda = new ChapterAddressDataContext();

            ChapterAddress toChapterAddress = new ChapterAddress();

            toChapterAddress = Helper.GetChapterAddress(toChapter);

            ChapterAddress fromChapterAddress = new ChapterAddress();

            fromChapterAddress = Helper.GetChapterAddress(fromChapter);

            string fromStateCode = GetStateName((Int32)fromChapterAddress.StateId);
            string toStateCode   = GetStateName((Int32)toChapterAddress.StateId);

            milesgUri = gMapUri.Replace("{FromSA}", fromChapterAddress.StreetAddress1)
                        .Replace("{FromCity}", fromChapterAddress.City)
                        .Replace("{FromState}", fromStateCode)
                        .Replace("{FromZip}", fromChapterAddress.Zip)
                        .Replace("{ToSA}", toChapterAddress.StreetAddress1)
                        .Replace("{ToCity}", toChapterAddress.City)
                        .Replace("{ToState}", toStateCode)
                        .Replace("{ToZip}", toChapterAddress.Zip);

            return(milesgUri);
        }
Beispiel #3
0
        public static ChapterAddress GetChapterAddress(int chId)
        {
            ChapterAddress            selChapAddr = new ChapterAddress();
            ChapterAddressDataContext cadc        = new ChapterAddressDataContext();

            selChapAddr = (ChapterAddress)cadc.ChapterAddresses.Where(s => s.ChapterId == chId).FirstOrDefault();
            return(selChapAddr);
        }
        private bool UpdateChapterAddressInfo(bool updateSuccess)
        {
            bool validForm;

            string chapterName = string.Empty;
            string newGLink    = string.Empty;

            RefreshErrorBlock();
            validForm = ValidateForm();
            if (validForm)
            {
                //Update the Chapter Address
                int chID = selChapt;
                ChapterAddressDataContext cadc = new ChapterAddressDataContext();
                ChapterAddress            chA  = new ChapterAddress();
                chA = (from chaA in cadc.ChapterAddresses
                       where chaA.ChapterId == chID
                       select chaA).FirstOrDefault();

                chA.StreetAddress1 = txtStreetAddr1.Text.ToString();
                chA.StateId        = Convert.ToInt32(cboState.SelectedValue);
                chA.City           = txtCity.Text.ToString();
                chA.Zip            = txtZip.Text;
                string streetAddress = (chA.StreetAddress2 == null) ? chA.StreetAddress1 : string.Concat(chA.StreetAddress1, " ", chA.StreetAddress2);
                try
                {
                    cadc.SubmitChanges();
                }
                catch (Exception exceptCA)
                {
                    MessageBox.Show(exceptCA.Message.ToString());
                    updateSuccess = false;
                }

                try
                {
                    //Update Chapter Google Link
                    ChapterClassDataContext cdc = new ChapterClassDataContext();
                    Chapter chU = new Chapter();
                    chU = (from ch in cdc.Chapters
                           where ch.ChapterId == chID
                           select ch).FirstOrDefault();
                    newGLink       = Helper.GoogleHelper.CreateChapterGLink(streetAddress, chA.City, Convert.ToInt32(cboState.SelectedValue), chA.Zip);
                    chU.GoogleLink = newGLink;
                    txtGlink.Text  = newGLink;
                    chapterName    = chU.ChapterName;
                }
                catch (Exception exceptCh)
                {
                    MessageBox.Show(exceptCh.Message.ToString());
                    updateSuccess = false;
                }
            }
            return(updateSuccess);
        }
        private void LoadChapterInfo()
        {
            ChapterAddress selChapterAddress = new ChapterAddress();

            selChapterAddress      = Helper.Helper.GetChapterAddress(selChapt);
            txtStreetAddr1.Text    = (selChapterAddress.StreetAddress1 == null || selChapterAddress.StreetAddress1.ToString() == string.Empty) ? string.Empty : selChapterAddress.StreetAddress1.ToString();
            txtCity.Text           = (selChapterAddress.City == null || selChapterAddress.City.ToString() == string.Empty) ? string.Empty : selChapterAddress.City.ToString();
            txtZip.Text            = (selChapterAddress.Zip == null || selChapterAddress.Zip.ToString() == string.Empty) ? string.Empty : selChapterAddress.Zip.ToString();
            txtGlink.Text          = Helper.GoogleHelper.GetChGLink(selChapt);
            cboState.SelectedValue = (selChapterAddress.StateId == null) ? 1: selChapterAddress.StateId;
        }
 public static void AddAddress(Chapter chapter, ICollection<AddressChapterRel> list)
 {
     foreach (var item in list)
     {
         var addr = new ChapterAddress()
         {
             Street = item.Address.Address1,
             Street2 = item.Address.Address2,
             City = item.Address.City,
             StateId = item.Address.StateId,
             County = item.Address.County,
             ZipCode = $"{item.Address.Zip5}-{item.Address.Zip4}",
             Country = item.Address.Country,
             Latitude = item.Address.Latitude,
             Longitude = item.Address.Longitude,
             DateCreated = item.Address.DateCreated,
             DateUpdated = item.Address.DateModified
             //todo: need primarystatus here
         };
         chapter.ChapterAddresses.Add(addr);
         chapter.LogEntries.Add(new ChapterLogEntry() { Note = $"Added address" });
     }
 }