private void CreateNewPushpin(GeoCoordinate location) { PushpinModel p = new PushpinModel(); p.Location = location; Pushpins.Add(p); }
public void DisplayVoter(PushpinModel _currVoter) { DataContext = _currVoter; _CurrentVoterModified = false; // TODO: Determine whether we really need to open the database at this point _voterDB = new VoterFileDataContext(string.Format(VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName)); if (_voterDB.DatabaseExists()) { try { IQueryable <VoterFileEntry> voterQuery = from voter in _voterDB.AllVoters where voter.VoterID == _currVoter.VoterID select voter; VoterFileEntry voterToUpdate = voterQuery.FirstOrDefault(); if (voterToUpdate.VoterID == _currVoter.VoterID) { DataContext = voterToUpdate; voterToUpdate.PropertyChanging += voterToUpdate_PropertyChanging; App.Log(String.Format("Setting Voter Detail page DataContext to voter {0}", voterToUpdate.FullName)); } else { App.Log(String.Format("ERROR: Setting Voter Detail page DataContext to voter {0} failed.", voterToUpdate.FullName)); } } catch (Exception ex) { App.Log("Exception setting voter as DataContext" + ex.ToString()); } } /* */ ApplicationBarIconButton buttonPrevious = ApplicationBar.Buttons[0] as ApplicationBarIconButton; ApplicationBarIconButton buttonNext = ApplicationBar.Buttons[2] as ApplicationBarIconButton; if (VotersInViewList.VoterList.Count > 1) { if (_VoterIndexInList > 0) { buttonPrevious.IsEnabled = true; } else { buttonPrevious.IsEnabled = false; } if (_VoterIndexInList < (VotersInViewList.VoterList.Count - 1)) { buttonNext.IsEnabled = true; } else { buttonNext.IsEnabled = false; } } else { buttonPrevious.IsEnabled = false; buttonNext.IsEnabled = false; } }
private List <PushpinModel> GetVoterList() { VoterFileDataContext _voterDB = new mapapp.data.VoterFileDataContext(string.Format(mapapp.data.VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName)); System.Diagnostics.Debug.Assert(_voterDB.DatabaseExists()); List <PushpinModel> _list = new List <PushpinModel>(); if (!(App.thisApp._settings.DbStatus == DbState.Loaded)) { App.Log("Database not ready to load voters yet."); return(_list); } IEnumerable <VoterFileEntry> data = from VoterFileEntry voter in _voterDB.AllVoters select voter; PushpinModel _pin; int _counter = 0; foreach (VoterFileEntry _v in data) { _pin = new PushpinModel(_v); if (0.0 == _pin.Location.Latitude || 0.0 == _pin.Location.Longitude) { App.Log("Skipping voter with no location:" + _pin.Address); continue; } _counter++; if (!_pin.Location.IsUnknown) { _pin.Visibility = Visibility.Visible; _list.Add(_pin); } else { System.Diagnostics.Debug.WriteLine("Error: A pin doesn't have a location: " + _pin.Content); // This pin doesn't have valid location info - Set the location for the pushpin to the center of the street or precinct StreetPinModel _street = (from StreetPinModel _st in Streets where _st.Content == _pin.Street select _st).FirstOrDefault(); if (_street != null) { _pin.Location = _street.Center; App.Log(string.Format("Voter at {0} lacks location, setting to center of {1} street.", _pin.Address, _street.Content)); _list.Add(_pin); } } } if (_list.Count == 0 || _counter == 0) { App.Log("There are no voters around here!"); } else { System.Diagnostics.Debug.WriteLine("Found {0} voters near here.", _counter); } _voterDB.Dispose(); return(_list); }
int SortDistance(PushpinModel p1, PushpinModel p2) { if (p1.dist > p2.dist) { return(1); } else if (p1.dist < p2.dist) { return(-1); } return(0); }
public void FillVoterList(List <PushpinModel> fillWith) { if (fillWith == null || fillWith.Count < 1) { VoterFileDataContext _voterDB = new VoterFileDataContext(string.Format(VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName)); if (!(App.thisApp._settings.DbStatus == DbState.Loaded) || !_voterDB.DatabaseExists()) { App.Log("Database not ready to load voters yet."); return; } App.VotersViewModel.StreetList.Clear(); App.VotersViewModel.VoterList.Clear(); IEnumerable <VoterFileEntry> data = from VoterFileEntry voter in _voterDB.AllVoters select voter; foreach (VoterFileEntry _v in data) { PushpinModel p = new PushpinModel(_v); if ((p.Street != null) && (!App.VotersViewModel.StreetList.Contains(p.Street))) { App.VotersViewModel.StreetList.Add(p.Street); } App.VotersViewModel.VoterList.Add(p); } _voterDB.Dispose(); } else { App.VotersViewModel.StreetList.Clear(); App.VotersViewModel.VoterList.Clear(); foreach (PushpinModel p in fillWith) { if ((p.Street != null) && (!App.VotersViewModel.StreetList.Contains(p.Street))) { App.VotersViewModel.StreetList.Add(p.Street); } App.VotersViewModel.VoterList.Add(p); } } if (App.VotersViewModel.VoterList.Count <= 0) { App.Log("There are no voters in database!"); return; } else { System.Diagnostics.Debug.WriteLine("Found {0} voters in database.", App.VotersViewModel.VoterList.Count); } }
private void Pushpin_Hold(object sender, System.Windows.Input.GestureEventArgs e) { if (sender is Pushpin) { Pushpin pinHeld = sender as Pushpin; if (pinHeld.DataContext is PushpinModel) { if (watcher != null) { watcher.Stop(); } if (backThread != null && backThread.ThreadState != ThreadState.Stopped) { // TODO: Is there ay way other than the embedded waits to suspend the thread? } PushpinModel pinModel = pinHeld.DataContext as PushpinModel; App.thisApp.SelectedHouse = pinModel; this.NavigationService.Navigate(new Uri("/VoterDetailsPage.xaml", UriKind.Relative)); } } }
private void lstVoters_ItemTap(object sender, Telerik.Windows.Controls.ListBoxItemTapEventArgs e) { if (this.lstVoters.SelectedItem is PushpinModel) { PushpinModel _pin = this.lstVoters.SelectedItem as PushpinModel; App.thisApp.SelectedHouse = _pin; if (this.lstVoters.FilterDescriptors.Count > 0 && lstVoters.Groups != null && lstVoters.Groups[0] != null) { string filterStreet = lstVoters.Groups[0].Key as string; // TODO: Determine whether including OrderBy here loses our odd/even sorting List <PushpinModel> filteredPins = App.VotersViewModel.VoterList.Where <PushpinModel>(voter => voter.Street == filterStreet).OrderBy <PushpinModel, int>(voter => voter.HouseNum).ToList(); if (sortByHouseNumber.SortMode == ListSortMode.Descending) { filteredPins.Reverse(); } App.VotersViewModel.VoterList.Clear(); foreach (PushpinModel _p in filteredPins) { App.VotersViewModel.VoterList.Add(_p); } } this.NavigationService.Navigate(new Uri("/VoterDetailsPage.xaml", UriKind.Relative)); } }