Example #1
0
        public static string[] GetCities(string prefixText, int count, string state)
        {
            PostalInfoLookupDataSet ds = PostalInfoLookupDataSet.Instance;
            string cityFilter          = string.Format(CultureInfo.CurrentCulture,
                                                       @"(State = '{0}' OR '{0}' = '') 
                  AND City LIKE '{1}%'"
                                                       , state, prefixText);
            DataView dw = new DataView(ds.Zip);

            dw.RowFilter = cityFilter;
            dw.Sort      = "City";

            List <string> resultCities    = new List <string>();
            string        previousCity    = null;
            int           remainingValues = count;

            foreach (DataRowView rowView in dw)
            {
                PostalInfoLookupDataSet.ZipRow zipRow = (PostalInfoLookupDataSet.ZipRow)rowView.Row;
                //The following is to remove duplicate cities, because there is no select DISTINCT clause on in-memory datasets.
                if (zipRow.City != previousCity)
                {
                    previousCity = zipRow.City;
                    resultCities.Add(zipRow.City);
                    remainingValues--;
                    if (remainingValues == 0)
                    {
                        break;
                    }
                }
            }

            return(resultCities.ToArray());
        }
Example #2
0
        public IEnumerable <string> GetCities(string prefix, string state, int maxResults)
        {
            string query = string.Format(
                @"(State = '{0}' OR '{0}' = '') 
                  AND City LIKE '{1}%'",
                InputValidator.EncodeQueryStringParameter(state),
                InputValidator.EncodeQueryStringParameter(prefix));

            DataView view = new DataView(_data.Zip);

            view.RowFilter = query;
            view.Sort      = "City";

            string previousCity  = null;
            int    rowsRemaining = maxResults;

            foreach (DataRowView viewRow in view)
            {
                PostalInfoLookupDataSet.ZipRow row = (PostalInfoLookupDataSet.ZipRow)viewRow.Row;
                //The following is to remove duplicate cities, because there is no select DISTINCT clause on in-memory datasets.
                if (row.City != previousCity)
                {
                    previousCity = row.City;
                    yield return(row.City);

                    if (--rowsRemaining == 0)
                    {
                        yield break;
                    }
                }
            }
        }
Example #3
0
        public static string[] GetZipCodes(string prefixText, int count, string state, string city)
        {
            PostalInfoLookupDataSet ds = PostalInfoLookupDataSet.Instance;
            string zipCodeFilter       = string.Format(CultureInfo.CurrentCulture,
                                                       @"(State = '{0}' OR '{0}' = '')
									    AND (City = '{1}' OR '{1}' = '')
									    AND ZipCode LIKE '{2}%'"
                                                       , state, city, prefixText);

            DataView dw = new DataView(ds.Zip);

            dw.RowFilter = zipCodeFilter;
            dw.Sort      = "ZipCode";

            List <string> resultZipCodes  = new List <string>();
            int           remainingValues = count;

            foreach (DataRowView rowView in dw)
            {
                PostalInfoLookupDataSet.ZipRow zipRow = (PostalInfoLookupDataSet.ZipRow)rowView.Row;
                resultZipCodes.Add(zipRow.ZipCode);
                remainingValues--;
                if (remainingValues == 0)
                {
                    break;
                }
            }
            return(resultZipCodes.ToArray());
        }
Example #4
0
        public IEnumerable <ZipCode> GetZipCodes(string prefix, string city, string state, int maxResults)
        {
            string query = string.Format(@"(State = '{0}' OR '{0}' = '')
									    AND (City = '{1}' OR '{1}' = '')
									    AND ZipCode LIKE '{2}%'"                                    ,
                                         InputValidator.EncodeQueryStringParameter(state),
                                         InputValidator.EncodeQueryStringParameter(city),
                                         InputValidator.EncodeQueryStringParameter(prefix));

            DataView view = new DataView(_data.Zip);

            view.RowFilter = query;

            for (int i = 0; i < view.Count && i < maxResults; ++i)
            {
                PostalInfoLookupDataSet.ZipRow row =
                    (PostalInfoLookupDataSet.ZipRow)(view[i].Row);
                yield return(_data.ZipRowToZipCode(row));
            }
        }