示例#1
0
        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());
                    }
                }
            }
        }
示例#2
0
        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());
                }
            }
        }
示例#3
0
        /// <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());
                    }
                }
            }
        }