public static void UpdateGoogleMilesUri(int originKey, Dictionary <int, string> lookupDestinationDict, bool updateAll = false) { int destKey = 0; //bool updateAll = UpdateAll.IsChecked.Value; using (var mdc = new MilesDataContext()) { foreach (var dest in lookupDestinationDict) { destKey = dest.Key; //Get the Mile Record var mRec = from mtable in mdc.Miles where mtable.FromId == originKey && mtable.ToId == destKey select mtable; foreach (Mile mile in mRec) { mile.GoogleUri = GoogleHelper.CreateGoogleMilesTableLink(originKey, mile.ToId); } //Submit changes to table try { mdc.SubmitChanges(); } catch (Exception exceptUpdate) { MessageBox.Show(exceptUpdate.Message.ToString()); } } } }
/// <summary> /// MOVED TO HELPER SO CAN BE USED BY CREATE CHAPTER AS WELL /// This Method will add the chapters that do not exist in the Miles table to the miles table /// </summary> /// <param name="chAddList"></param> //private void AddChapterToMilesTable(List<int> chAddList, Dictionary<int, string> chList) //{ // using(MilesDataContext mdc = new MilesDataContext()) // { // // Loop through the Add list and then the list of current chapters to create the Mile // foreach (int chId in chAddList) // { // foreach (var ch in chList) // { // if (chId != ch.Key) // { // Mile mAdd = new Mile(); // mAdd.FromId = chId; // mAdd.ToId = ch.Key; // mAdd.Active = true; // mAdd.DateCreated = System.DateTime.Now; // mAdd.DateModified = System.DateTime.Now; // mdc.Miles.InsertOnSubmit(mAdd); // } // } // } // try // { // mdc.SubmitChanges(); // } // catch (Exception exceptAdd) // { // MessageBox.Show(exceptAdd.Message.ToString()); // } // } //} /// <summary> /// This Method Looks at the Miles Table, Gets a disticnt list of Chapters in the From Id column /// checks the list against the chapters in the chapters table /// Returns the list of chapters that need to be added to the Miles table /// </summary> private List <int> GetChapterToAddList() { List <int> chAddList = new List <int>(); List <int> distinctList = new List <int>(); bool exists = false; MilesDataContext mdc = new MilesDataContext(); //Get the distinct list of Chapters in Miles table var idList = mdc.Miles.Select(m => m.FromId).Distinct(); distinctList = idList.ToList(); //Get the List of Chapters from The Chapters Table Dictionary <int, string> chList = Helper.Helper.GetChapters(); //Compare the 2 lists and add a chapter that needs to be added to the Add List foreach (var ch in chList) { exists = distinctList.Any(id => id == ch.Key); if (exists == false) { chAddList.Add(ch.Key); } } return(chAddList); }
private int CheckMilesTableCount() { int mCount = 0; MilesDataContext mdc = new MilesDataContext(); mCount = mdc.Miles.Count(); return(mCount); }
public static void AddChapterToMilesTable(List <int> chAddList) { Dictionary <int, string> chList = new Dictionary <int, string>(); chList = GetChapters(); using (MilesDataContext mdc = new MilesDataContext()) { // Loop through the Add list and then the list of current chapters to create the Mile foreach (int chId in chAddList) { //This is for the From ID foreach (var ch in chList) { if (chId != ch.Key) { Mile mAdd = new Mile(); mAdd.FromId = chId; mAdd.ToId = ch.Key; mAdd.Active = true; mAdd.DateCreated = System.DateTime.Now; mAdd.DateModified = System.DateTime.Now; mdc.Miles.InsertOnSubmit(mAdd); } } //This is for the To ID foreach (var ch in chList) { if (chId != ch.Key) { Mile mAdd = new Mile(); mAdd.ToId = chId; mAdd.FromId = ch.Key; mAdd.Active = true; mAdd.DateCreated = System.DateTime.Now; mAdd.DateModified = System.DateTime.Now; mdc.Miles.InsertOnSubmit(mAdd); } } } try { mdc.SubmitChanges(); } catch (Exception exceptAdd) { MessageBox.Show(exceptAdd.Message.ToString()); } } }
// Moved to Helper 20200819 //private void UpdateGoogleMilesUri(int originKey, Dictionary<int, string> lookupDestinationDict) //{ // int destKey = 0; // bool updateAll = UpdateAll.IsChecked.Value; // using (var mdc = new MilesDataContext()) // { // foreach (var dest in lookupDestinationDict) // { // destKey = dest.Key; // //Get the Mile Record // var mRec = from mtable in mdc.Miles // where mtable.FromId == originKey && mtable.ToId == destKey // select mtable; // foreach (Mile mile in mRec) // { // mile.GoogleUri = Helper.GoogleHelper.CreateGoogleMilesTableLink(originKey, mile.ToId); // } // //Submit changes to table // try // { // mdc.SubmitChanges(); // } // catch (Exception exceptUpdate) // { // MessageBox.Show(exceptUpdate.Message.ToString()); // } // } // } //} /// <summary> /// If do not want to update the whole table then only update where miles = 0 /// so this method checks to see if there are any miles = 0 /// </summary> /// <returns></returns> private bool CheckZeroMiles() { bool zeroMiles = false; using (var mdc = new MilesDataContext()) { var mRec = from mtable in mdc.Miles where mtable.Miles == 0 select mtable; if (mRec.Count() > 0) { zeroMiles = true; } } return(zeroMiles); }
/// <summary> /// Method that updates the miles in the miles table /// </summary> /// <param name="originKey"></param> /// <param name="lookupOrigin"></param> /// <param name="lookupDestinationDict"></param> public static void UpdateMileage(int originKey, string lookupOrigin, Dictionary <int, string> lookupDestinationDict, bool updateAll = false) { int destKey = 0; using (var mdc = new MilesDataContext()) { foreach (var dest in lookupDestinationDict) { destKey = dest.Key; if (updateAll) { //Get the Mile Record var mRec = from mtable in mdc.Miles where mtable.FromId == originKey && mtable.ToId == destKey select mtable; foreach (Mile mile in mRec) { mile.Miles = (Int32)GoogleHelper.GetMileage(lookupOrigin, dest.Value); } } else { //Get the Mile Record var mRec = from mtable in mdc.Miles where mtable.FromId == originKey && mtable.ToId == destKey && mtable.Miles == 0 select mtable; foreach (Mile mile in mRec) { mile.Miles = (Int32)GoogleHelper.GetMileage(lookupOrigin, dest.Value); } } //Submit changes to table try { mdc.SubmitChanges(); } catch (Exception exceptUpdate) { MessageBox.Show(exceptUpdate.Message.ToString()); } } } }
private void UpdateChapterMiles(bool updateSuccess) { int chID = Convert.ToInt32(cboChapter.SelectedValue); //Check and see if the chapter in the miles table //Check the To and From ChapterId try { MilesDataContext mdc = new MilesDataContext(); int chFromCount = (from c in mdc.Miles where c.FromId == chID || c.ToId == chID select c).Count(); //if the count = 0 first add the missing miles records if (chFromCount == 0) { CreateChapterMiles(chID); } // Update the to and from for the selected chapter //Get All the Chapter Addresses into a List List <DAL.ChapterAddress> caList = new List <DAL.ChapterAddress>(); caList = Helper.Helper.GetChapterAddressesAll(); // Create the List of clubhouse addresses Dictionary <int, string> chList = new Dictionary <int, string>(); List <int> chAddList = new List <int>(); chList = Helper.Helper.GetChapters(); List <Model.ChapterAddressMiles> camList = new List <Model.ChapterAddressMiles>(); camList = Helper.Helper.CreateClubhouseAddressList(chList, caList); Helper.Helper.CreateChapterMilesUpdateLists(caList, camList); //Update the google uri for the new chapter Helper.Helper.UpdateGoogleUrl(); } catch (Exception exMiles) { MessageBox.Show(exMiles.Message.ToString()); updateSuccess = false; } if (updateSuccess) { MessageBox.Show(string.Concat(_successMsg, cboChapter.Text.ToString())); } }
/// <summary> /// Loads the Grid with the miles table info /// </summary> private void GetMilesTable() { MilesDataContext mdc = new MilesDataContext(); List <ChapterMiles> lcm = new List <ChapterMiles>(); Dictionary <int, string> chList = Helper.Helper.GetChapters(); var lcmSQL = from m in mdc.Miles select new ChapterMiles() { MilesId = m.MilesId, FromID = m.FromId, ToId = m.ToId, GoogleUri = m.GoogleUri, Miles = m.Miles }; lcm = lcmSQL.ToList(); foreach (ChapterMiles cm in lcm) { cm.ToChapter = chList.Single(x => x.Key == cm.ToId).Value; cm.FromChapter = chList.Single(x => x.Key == cm.FromID).Value; cm.FromChapter = chList.Single(x => x.Key == cm.FromID).Value; } dgChapterMiles.ItemsSource = lcm; }