예제 #1
0
        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);
        }
예제 #2
0
        private void LoadPrecincts()
        {
            VoterFileDataContext _voterDB = new mapapp.data.VoterFileDataContext(string.Format(mapapp.data.VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName));

            System.Diagnostics.Debug.Assert(_voterDB.DatabaseExists());

            if (!(App.thisApp._settings.DbStatus == DbState.Loaded))
            {
                App.Log("Database not ready to load precincts yet.");
                return;
            }
            IEnumerable <PrecinctTableEntry> precincts = (from precinct in _voterDB.Precincts select precinct);

            foreach (PrecinctTableEntry precinct in precincts)
            {
                App.Log(" Adding precinct: " + precinct.Name);
                PrecinctPinModel pPin = new PrecinctPinModel(precinct);
                Precincts.Add(pPin);
            }
            _voterDB.Dispose();
        }