Exemplo n.º 1
0
        public void ReadZipCodes(string file)
        {
            using (StreamReader reader = new StreamReader(file))
            {
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    ZipCodeTable zip = new ZipCodeTable();

                    string line = reader.ReadLine();
                    string[] splitLine = line.Split(',');

                    zip.ZipCode = splitLine[0].Substring(1, splitLine[0].Length - 2);
                    zip.State = splitLine[3].Substring(1, splitLine[3].Length - 2);
                    zip.City = splitLine[2].Substring(1, splitLine[2].Length - 2);
                    ZipCodes.ZipCodeTables.AddObject(zip);
                }
                try
                {
                    ZipCodes.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Unable to save", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
Exemplo n.º 2
0
        public static bool FindZipOrPostalCode(string zipToFind, out ZipCodeTable zipToReturn)
        {
            zipToReturn = new ZipCodeTable();
            ZipPostalCodeDbEntities ZipCodes = new ZipPostalCodeDbEntities();

            IEnumerable<ZipCodeTable> matchingZipCode =
                from z in ZipCodes.ZipCodeTables
                where z.ZipCode.Equals(zipToFind)
                select z;

            if (matchingZipCode.Count() > 0)
            {
                zipToReturn = matchingZipCode.First();
                return true;
            }
            else
            {
                return false;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ZipCodeTables EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToZipCodeTables(ZipCodeTable zipCodeTable)
 {
     base.AddObject("ZipCodeTables", zipCodeTable);
 }
 /// <summary>
 /// Create a new ZipCodeTable object.
 /// </summary>
 /// <param name="zipKey">Initial value of the zipKey property.</param>
 /// <param name="zipCode">Initial value of the ZipCode property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="state">Initial value of the State property.</param>
 public static ZipCodeTable CreateZipCodeTable(global::System.Int32 zipKey, global::System.String zipCode, global::System.String city, global::System.String state)
 {
     ZipCodeTable zipCodeTable = new ZipCodeTable();
     zipCodeTable.zipKey = zipKey;
     zipCodeTable.ZipCode = zipCode;
     zipCodeTable.City = city;
     zipCodeTable.State = state;
     return zipCodeTable;
 }