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); } }
/// <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); }
public static List <ChapterAddress> GetChapterAddressesAll() { List <ChapterAddress> chList = new List <ChapterAddress>(); ChapterAddressDataContext cadc = new ChapterAddressDataContext(); chList = cadc.ChapterAddresses.ToList(); return(chList); }
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); }
public static Dictionary <int, string> CreateGoogleMapLink() { string googleuri = string.Empty; List <string> googleUrisList = new List <string>(); Dictionary <int, string> chGlink = new Dictionary <int, string>(); foreach (DAL.Chapter ch in chList) { //Get the Chapter Address DAL.ChapterAddress chA; ChapterAddressDataContext cadc = new ChapterAddressDataContext(); chA = (from ca in cadc.ChapterAddresses where ca.ChapterId == ch.ChapterId select ca).FirstOrDefault(); string streetAddress = (chA.StreetAddress2 == null) ? chA.StreetAddress1 : string.Concat(chA.StreetAddress1, " ", chA.StreetAddress2); //StateDataContext sdc = new StateDataContext(); //string stateCode = (from st in sdc.States where st.Id == chA.StateId select st.Code).FirstOrDefault(); string stateCode = GetStateName(Convert.ToInt32(chA.StateId)); googleuri = gUri.Replace("{SA}", streetAddress).Replace("{City}", chA.City).Replace("{State}", stateCode).Replace("{Zip}", chA.Zip.ToString()); chGlink.Add(ch.ChapterId, googleuri); } return(chGlink); }