using Grpc.Core;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using Dapper;
using System.Text.RegularExpressions;
using XYY.Common.Standard;
using XYY.Core.Standard.Mvc;

namespace XYY.gRpc.Order
{
    public class ZipCodePushService : ZipCodePush.ZipCodePushBase
    {
        private readonly ILogger<ZipCodePushService> _logger;
        private readonly IUnitOfWork _unitOfWork;

        public ZipCodePushService(ILogger<ZipCodePushService> logger, IUnitOfWork unitOfWork)
        {
            _logger = logger;
            _unitOfWork = unitOfWork;
        }

        public override async Task<WaitPush> GetWaitPush(Empty request, ServerCallContext context)
        {
            string sql = @"select top 10000  ReceiverZipCode,a.Id,
	case when d.Destination ='SFO' then 'LAX' else d.Destination end as Destination from Order_Order(nolock)a 
                                join logistics_BoxDetail(nolock)b on a.id=b.orderId
                                join logistics_Box(nolock)c on c.Id=b.boxId
                                join Logistics_LadingBill(nolock)d on d.LadingBillNumber = c.LadingBillNumber and d.IsDeleted = 0
                                where ReceiveTime>'2021-11-01' and (CreateOrderChannelId=30 or CreateOrderChannelId = 171) and _917ZipZone is  null 
                            ";
            var data = await _unitOfWork.QueryBySqlAsync<dynamic>(sql);
            var result = new WaitPush();
            result.Items.AddRange(data.Select(x => new WaitPushItem { Id = x.Id, ZipCode = x.ReceiverZipCode,Area = x.Destination }));
            return result;
        }

        public override async Task<PushResult> Push(WaitPush request, ServerCallContext context)
        {
            var order = request.Items.Select(x => new
            {
                Id = x.Id,
                _917ZipZone =  x.Area=="LAX"? _917ZipHelper.GetFCLaxAreaCode(x.ZipCode):_917ZipHelper.GetFCOrdAreaCode(x.ZipCode)
            });
            try
            {
                if (_unitOfWork.Connection != null && _unitOfWork.Connection.State != System.Data.ConnectionState.Open)
                    _unitOfWork.Connection.Open();

                string tableName = "Order_Order";
                if (order.Count() > 0)
                {
                    var frist = order.First();
                    string columns = DataXmlUpdateHelper.GetColumns(frist);
                    string sets = DataXmlUpdateHelper.Sets(frist);
                    string body = string.Join("\r\n", order.ToList().Select(x => DataXmlUpdateHelper.XmlValues(x)));
                    string sql = $@"DECLARE @idoc int
                                            DECLARE @doc varchar(max)
                                            SET @doc ='
                                            <?xml version=""1.0"" encoding=""gb2312"" ?>
                                            <ROOT>
                                               {body}
                                            </ROOT>' 
                                            EXEC sp_xml_preparedocument @idoc OUTPUT, @doc 
                                            SELECT * into #temp_searchs
                                            FROM   OPENXML (@idoc, '/ROOT/item',2)
                                                     WITH ({columns})
                                            update a set {sets} from {tableName}(nolock)a join #temp_searchs b on a.Id = b.Id ";
                    try
                    {
                        await _unitOfWork.ExecuteAsync(sql);
                    }
                    catch (Exception ex)
                    {
                        return new PushResult { Success = false, Message = ex.Message };
                    }
                    finally
                    {
                        if (_unitOfWork.Connection != null)
                            _unitOfWork.Connection.Close();
                    }
                }

                return new PushResult { Success = true };
            }
            catch (Exception ex)
            {
                return new PushResult { Success = false, Message = ex.Message };
            }

        }
    }

    public class OrderUpdate
    {
        public int Id
        {
            get; set;
        }

        public int _917ZipZone
        {
            get; set;
        }
    }




    public class _917ZipHelper
    {

        public static string GetZip5(string zip)
        {
            string zip5 = "";
            ///直接截取前5位邮编
            if (zip.Contains('-'))
            {
                zip5 = zip.Split('-')[0];
            }
            else
            {
                zip5 = zip;
            }

            if (!Regex.IsMatch(zip5, @"^[0-9]\d+"))
            {
                return "";
            }
            else if (zip5.Length > 5)
            {
                zip5 = zip5.Substring(0, 5);
            }
            else
            {
                zip5 = zip5.PadLeft(5, '0');
            }
            return zip5;

        }

        public static List<USPSZipArea> GetORDZipAreas()
        {
            return new List<USPSZipArea>()
            {
                 new USPSZipArea("005","5","ORD"),
 new USPSZipArea("006","8","ORD"),
 new USPSZipArea("007","8","ORD"),
 new USPSZipArea("008","8","ORD"),
 new USPSZipArea("009","8","ORD"),
 new USPSZipArea("010","5","ORD"),
 new USPSZipArea("011","5","ORD"),
 new USPSZipArea("012","5","ORD"),
 new USPSZipArea("013","5","ORD"),
 new USPSZipArea("014","5","ORD"),
 new USPSZipArea("015","5","ORD"),
 new USPSZipArea("016","5","ORD"),
 new USPSZipArea("017","5","ORD"),
 new USPSZipArea("018","5","ORD"),
 new USPSZipArea("019","5","ORD"),
 new USPSZipArea("020","5","ORD"),
 new USPSZipArea("021","5","ORD"),
 new USPSZipArea("022","5","ORD"),
 new USPSZipArea("023","5","ORD"),
 new USPSZipArea("024","5","ORD"),
 new USPSZipArea("025","5","ORD"),
 new USPSZipArea("026","5","ORD"),
 new USPSZipArea("027","5","ORD"),
 new USPSZipArea("028","5","ORD"),
 new USPSZipArea("029","5","ORD"),
 new USPSZipArea("030","5","ORD"),
 new USPSZipArea("031","5","ORD"),
 new USPSZipArea("032","5","ORD"),
 new USPSZipArea("033","5","ORD"),
 new USPSZipArea("034","5","ORD"),
 new USPSZipArea("035","5","ORD"),
 new USPSZipArea("036","5","ORD"),
 new USPSZipArea("037","5","ORD"),
 new USPSZipArea("038","5","ORD"),
 new USPSZipArea("039","5","ORD"),
 new USPSZipArea("040","5","ORD"),
 new USPSZipArea("041","5","ORD"),
 new USPSZipArea("042","5","ORD"),
 new USPSZipArea("043","5","ORD"),
 new USPSZipArea("044","5","ORD"),
 new USPSZipArea("045","5","ORD"),
 new USPSZipArea("046","5","ORD"),
 new USPSZipArea("047","5","ORD"),
 new USPSZipArea("048","5","ORD"),
 new USPSZipArea("049","5","ORD"),
 new USPSZipArea("050","5","ORD"),
 new USPSZipArea("051","5","ORD"),
 new USPSZipArea("052","5","ORD"),
 new USPSZipArea("053","5","ORD"),
 new USPSZipArea("054","5","ORD"),
 new USPSZipArea("055","5","ORD"),
 new USPSZipArea("056","5","ORD"),
 new USPSZipArea("057","5","ORD"),
 new USPSZipArea("058","5","ORD"),
 new USPSZipArea("059","5","ORD"),
 new USPSZipArea("060","5","ORD"),
 new USPSZipArea("061","5","ORD"),
 new USPSZipArea("062","5","ORD"),
 new USPSZipArea("063","5","ORD"),
 new USPSZipArea("064","5","ORD"),
 new USPSZipArea("065","5","ORD"),
 new USPSZipArea("066","5","ORD"),
 new USPSZipArea("067","5","ORD"),
 new USPSZipArea("068","5","ORD"),
 new USPSZipArea("069","5","ORD"),
 new USPSZipArea("070","5","ORD"),
 new USPSZipArea("071","5","ORD"),
 new USPSZipArea("072","5","ORD"),
 new USPSZipArea("073","5","ORD"),
 new USPSZipArea("074","5","ORD"),
 new USPSZipArea("075","5","ORD"),
 new USPSZipArea("076","5","ORD"),
 new USPSZipArea("077","5","ORD"),
 new USPSZipArea("078","5","ORD"),
 new USPSZipArea("079","5","ORD"),
 new USPSZipArea("080","5","ORD"),
 new USPSZipArea("081","5","ORD"),
 new USPSZipArea("082","5","ORD"),
 new USPSZipArea("083","5","ORD"),
 new USPSZipArea("084","5","ORD"),
 new USPSZipArea("085","5","ORD"),
 new USPSZipArea("086","5","ORD"),
 new USPSZipArea("087","5","ORD"),
 new USPSZipArea("088","5","ORD"),
 new USPSZipArea("089","5","ORD"),
 new USPSZipArea("090","5","ORD"),
 new USPSZipArea("091","5","ORD"),
 new USPSZipArea("092","5","ORD"),
 new USPSZipArea("093","5","ORD"),
 new USPSZipArea("094","5","ORD"),
 new USPSZipArea("095","5","ORD"),
 new USPSZipArea("096","5","ORD"),
 new USPSZipArea("097","5","ORD"),
 new USPSZipArea("098","5","ORD"),
 new USPSZipArea("099","5","ORD"),
 new USPSZipArea("100","5","ORD"),
 new USPSZipArea("101","5","ORD"),
 new USPSZipArea("102","5","ORD"),
 new USPSZipArea("103","5","ORD"),
 new USPSZipArea("104","5","ORD"),
 new USPSZipArea("105","5","ORD"),
 new USPSZipArea("106","5","ORD"),
 new USPSZipArea("107","5","ORD"),
 new USPSZipArea("108","5","ORD"),
 new USPSZipArea("109","5","ORD"),
 new USPSZipArea("110","5","ORD"),
 new USPSZipArea("111","5","ORD"),
 new USPSZipArea("112","5","ORD"),
 new USPSZipArea("113","5","ORD"),
 new USPSZipArea("114","5","ORD"),
 new USPSZipArea("115","5","ORD"),
 new USPSZipArea("116","5","ORD"),
 new USPSZipArea("117","5","ORD"),
 new USPSZipArea("118","5","ORD"),
 new USPSZipArea("119","5","ORD"),
 new USPSZipArea("120","5","ORD"),
 new USPSZipArea("121","5","ORD"),
 new USPSZipArea("122","5","ORD"),
 new USPSZipArea("123","5","ORD"),
 new USPSZipArea("124","5","ORD"),
 new USPSZipArea("125","5","ORD"),
 new USPSZipArea("126","5","ORD"),
 new USPSZipArea("127","5","ORD"),
 new USPSZipArea("128","5","ORD"),
 new USPSZipArea("129","5","ORD"),
 new USPSZipArea("130","5","ORD"),
 new USPSZipArea("131","5","ORD"),
 new USPSZipArea("132","5","ORD"),
 new USPSZipArea("133","5","ORD"),
 new USPSZipArea("134","5","ORD"),
 new USPSZipArea("135","5","ORD"),
 new USPSZipArea("136","5","ORD"),
 new USPSZipArea("137","5","ORD"),
 new USPSZipArea("138","5","ORD"),
 new USPSZipArea("139","5","ORD"),
 new USPSZipArea("140","4","ORD"),
 new USPSZipArea("141","4","ORD"),
 new USPSZipArea("142","4","ORD"),
 new USPSZipArea("143","4","ORD"),
 new USPSZipArea("144","4","ORD"),
 new USPSZipArea("145","4","ORD"),
 new USPSZipArea("146","4","ORD"),
 new USPSZipArea("147","4","ORD"),
 new USPSZipArea("148","4","ORD"),
 new USPSZipArea("149","4","ORD"),
 new USPSZipArea("150","4","ORD"),
 new USPSZipArea("151","4","ORD"),
 new USPSZipArea("152","4","ORD"),
 new USPSZipArea("153","4","ORD"),
 new USPSZipArea("154","4","ORD"),
 new USPSZipArea("155","4","ORD"),
 new USPSZipArea("156","4","ORD"),
 new USPSZipArea("157","4","ORD"),
 new USPSZipArea("158","4","ORD"),
 new USPSZipArea("159","4","ORD"),
 new USPSZipArea("160","4","ORD"),
 new USPSZipArea("161","4","ORD"),
 new USPSZipArea("162","4","ORD"),
 new USPSZipArea("163","4","ORD"),
 new USPSZipArea("164","4","ORD"),
 new USPSZipArea("165","4","ORD"),
 new USPSZipArea("166","4","ORD"),
 new USPSZipArea("167","4","ORD"),
 new USPSZipArea("168","4","ORD"),
 new USPSZipArea("169","4","ORD"),
 new USPSZipArea("170","4","ORD"),
 new USPSZipArea("171","4","ORD"),
 new USPSZipArea("172","4","ORD"),
 new USPSZipArea("173","4","ORD"),
 new USPSZipArea("174","4","ORD"),
 new USPSZipArea("175","4","ORD"),
 new USPSZipArea("176","4","ORD"),
 new USPSZipArea("177","4","ORD"),
 new USPSZipArea("178","4","ORD"),
 new USPSZipArea("179","4","ORD"),
 new USPSZipArea("180","5","ORD"),
 new USPSZipArea("181","5","ORD"),
 new USPSZipArea("182","5","ORD"),
 new USPSZipArea("183","5","ORD"),
 new USPSZipArea("184","5","ORD"),
 new USPSZipArea("185","5","ORD"),
 new USPSZipArea("186","5","ORD"),
 new USPSZipArea("187","5","ORD"),
 new USPSZipArea("188","5","ORD"),
 new USPSZipArea("189","5","ORD"),
 new USPSZipArea("190","5","ORD"),
 new USPSZipArea("191","5","ORD"),
 new USPSZipArea("192","5","ORD"),
 new USPSZipArea("193","5","ORD"),
 new USPSZipArea("194","5","ORD"),
 new USPSZipArea("195","4","ORD"),
 new USPSZipArea("196","4","ORD"),
 new USPSZipArea("197","5","ORD"),
 new USPSZipArea("198","5","ORD"),
 new USPSZipArea("199","5","ORD"),
 new USPSZipArea("200","5","ORD"),
 new USPSZipArea("201","4","ORD"),
 new USPSZipArea("202","5","ORD"),
 new USPSZipArea("203","5","ORD"),
 new USPSZipArea("204","5","ORD"),
 new USPSZipArea("205","5","ORD"),
 new USPSZipArea("206","5","ORD"),
 new USPSZipArea("207","5","ORD"),
 new USPSZipArea("208","4","ORD"),
 new USPSZipArea("209","4","ORD"),
 new USPSZipArea("210","5","ORD"),
 new USPSZipArea("211","5","ORD"),
 new USPSZipArea("212","5","ORD"),
 new USPSZipArea("213","5","ORD"),
 new USPSZipArea("214","5","ORD"),
 new USPSZipArea("215","5","ORD"),
 new USPSZipArea("216","5","ORD"),
 new USPSZipArea("217","5","ORD"),
 new USPSZipArea("218","5","ORD"),
 new USPSZipArea("219","5","ORD"),
 new USPSZipArea("220","4","ORD"),
 new USPSZipArea("221","4","ORD"),
 new USPSZipArea("222","4","ORD"),
 new USPSZipArea("223","4","ORD"),
 new USPSZipArea("224","5","ORD"),
 new USPSZipArea("225","5","ORD"),
 new USPSZipArea("226","4","ORD"),
 new USPSZipArea("227","4","ORD"),
 new USPSZipArea("228","5","ORD"),
 new USPSZipArea("229","5","ORD"),
 new USPSZipArea("230","5","ORD"),
 new USPSZipArea("231","5","ORD"),
 new USPSZipArea("232","5","ORD"),
 new USPSZipArea("233","5","ORD"),
 new USPSZipArea("234","5","ORD"),
 new USPSZipArea("235","5","ORD"),
 new USPSZipArea("236","5","ORD"),
 new USPSZipArea("237","5","ORD"),
 new USPSZipArea("238","5","ORD"),
 new USPSZipArea("239","5","ORD"),
 new USPSZipArea("240","4","ORD"),
 new USPSZipArea("241","4","ORD"),
 new USPSZipArea("242","4","ORD"),
 new USPSZipArea("243","4","ORD"),
 new USPSZipArea("244","5","ORD"),
 new USPSZipArea("245","4","ORD"),
 new USPSZipArea("246","4","ORD"),
 new USPSZipArea("247","4","ORD"),
 new USPSZipArea("248","4","ORD"),
 new USPSZipArea("249","4","ORD"),
 new USPSZipArea("250","4","ORD"),
 new USPSZipArea("251","4","ORD"),
 new USPSZipArea("252","4","ORD"),
 new USPSZipArea("253","4","ORD"),
 new USPSZipArea("254","4","ORD"),
 new USPSZipArea("255","4","ORD"),
 new USPSZipArea("256","4","ORD"),
 new USPSZipArea("257","4","ORD"),
 new USPSZipArea("258","4","ORD"),
 new USPSZipArea("259","4","ORD"),
 new USPSZipArea("260","4","ORD"),
 new USPSZipArea("261","4","ORD"),
 new USPSZipArea("262","4","ORD"),
 new USPSZipArea("263","4","ORD"),
 new USPSZipArea("264","4","ORD"),
 new USPSZipArea("265","4","ORD"),
 new USPSZipArea("266","4","ORD"),
 new USPSZipArea("267","5","ORD"),
 new USPSZipArea("268","4","ORD"),
 new USPSZipArea("269","4","ORD"),
 new USPSZipArea("270","4","ORD"),
 new USPSZipArea("271","4","ORD"),
 new USPSZipArea("272","4","ORD"),
 new USPSZipArea("273","4","ORD"),
 new USPSZipArea("274","4","ORD"),
 new USPSZipArea("275","5","ORD"),
 new USPSZipArea("276","5","ORD"),
 new USPSZipArea("277","5","ORD"),
 new USPSZipArea("278","5","ORD"),
 new USPSZipArea("279","5","ORD"),
 new USPSZipArea("280","4","ORD"),
 new USPSZipArea("281","4","ORD"),
 new USPSZipArea("282","4","ORD"),
 new USPSZipArea("283","5","ORD"),
 new USPSZipArea("284","5","ORD"),
 new USPSZipArea("285","5","ORD"),
 new USPSZipArea("286","4","ORD"),
 new USPSZipArea("287","4","ORD"),
 new USPSZipArea("288","4","ORD"),
 new USPSZipArea("289","4","ORD"),
 new USPSZipArea("290","5","ORD"),
 new USPSZipArea("291","5","ORD"),
 new USPSZipArea("292","5","ORD"),
 new USPSZipArea("293","4","ORD"),
 new USPSZipArea("294","5","ORD"),
 new USPSZipArea("295","5","ORD"),
 new USPSZipArea("296","4","ORD"),
 new USPSZipArea("297","4","ORD"),
 new USPSZipArea("298","5","ORD"),
 new USPSZipArea("299","5","ORD"),
 new USPSZipArea("300","4","ORD"),
 new USPSZipArea("301","4","ORD"),
 new USPSZipArea("302","4","ORD"),
 new USPSZipArea("303","4","ORD"),
 new USPSZipArea("304","5","ORD"),
 new USPSZipArea("305","4","ORD"),
 new USPSZipArea("306","4","ORD"),
 new USPSZipArea("307","4","ORD"),
 new USPSZipArea("308","5","ORD"),
 new USPSZipArea("309","5","ORD"),
 new USPSZipArea("310","5","ORD"),
 new USPSZipArea("311","4","ORD"),
 new USPSZipArea("312","5","ORD"),
 new USPSZipArea("313","5","ORD"),
 new USPSZipArea("314","5","ORD"),
 new USPSZipArea("315","5","ORD"),
 new USPSZipArea("316","5","ORD"),
 new USPSZipArea("317","5","ORD"),
 new USPSZipArea("318","5","ORD"),
 new USPSZipArea("319","5","ORD"),
 new USPSZipArea("320","5","ORD"),
 new USPSZipArea("321","5","ORD"),
 new USPSZipArea("322","5","ORD"),
 new USPSZipArea("323","5","ORD"),
 new USPSZipArea("324","5","ORD"),
 new USPSZipArea("325","5","ORD"),
 new USPSZipArea("326","5","ORD"),
 new USPSZipArea("327","5","ORD"),
 new USPSZipArea("328","5","ORD"),
 new USPSZipArea("329","5","ORD"),
 new USPSZipArea("330","6","ORD"),
 new USPSZipArea("331","6","ORD"),
 new USPSZipArea("332","6","ORD"),
 new USPSZipArea("333","6","ORD"),
 new USPSZipArea("334","6","ORD"),
 new USPSZipArea("335","5","ORD"),
 new USPSZipArea("336","5","ORD"),
 new USPSZipArea("337","6","ORD"),
 new USPSZipArea("338","6","ORD"),
 new USPSZipArea("339","6","ORD"),
 new USPSZipArea("340","6","ORD"),
 new USPSZipArea("341","6","ORD"),
 new USPSZipArea("342","6","ORD"),
 new USPSZipArea("343","6","ORD"),
 new USPSZipArea("344","5","ORD"),
 new USPSZipArea("345","5","ORD"),
 new USPSZipArea("346","5","ORD"),
 new USPSZipArea("347","5","ORD"),
 new USPSZipArea("348","5","ORD"),
 new USPSZipArea("349","6","ORD"),
 new USPSZipArea("350","4","ORD"),
 new USPSZipArea("351","4","ORD"),
 new USPSZipArea("352","4","ORD"),
 new USPSZipArea("353","4","ORD"),
 new USPSZipArea("354","4","ORD"),
 new USPSZipArea("355","4","ORD"),
 new USPSZipArea("356","4","ORD"),
 new USPSZipArea("357","4","ORD"),
 new USPSZipArea("358","4","ORD"),
 new USPSZipArea("359","4","ORD"),
 new USPSZipArea("360","5","ORD"),
 new USPSZipArea("361","5","ORD"),
 new USPSZipArea("362","4","ORD"),
 new USPSZipArea("363","5","ORD"),
 new USPSZipArea("364","5","ORD"),
 new USPSZipArea("365","5","ORD"),
 new USPSZipArea("366","5","ORD"),
 new USPSZipArea("367","5","ORD"),
 new USPSZipArea("368","5","ORD"),
 new USPSZipArea("369","5","ORD"),
 new USPSZipArea("370","4","ORD"),
 new USPSZipArea("371","4","ORD"),
 new USPSZipArea("372","4","ORD"),
 new USPSZipArea("373","4","ORD"),
 new USPSZipArea("374","4","ORD"),
 new USPSZipArea("375","4","ORD"),
 new USPSZipArea("376","4","ORD"),
 new USPSZipArea("377","4","ORD"),
 new USPSZipArea("378","4","ORD"),
 new USPSZipArea("379","4","ORD"),
 new USPSZipArea("380","4","ORD"),
 new USPSZipArea("381","4","ORD"),
 new USPSZipArea("382","4","ORD"),
 new USPSZipArea("383","4","ORD"),
 new USPSZipArea("384","4","ORD"),
 new USPSZipArea("385","4","ORD"),
 new USPSZipArea("386","4","ORD"),
 new USPSZipArea("387","5","ORD"),
 new USPSZipArea("388","4","ORD"),
 new USPSZipArea("389","5","ORD"),
 new USPSZipArea("390","5","ORD"),
 new USPSZipArea("391","5","ORD"),
 new USPSZipArea("392","5","ORD"),
 new USPSZipArea("393","5","ORD"),
 new USPSZipArea("394","5","ORD"),
 new USPSZipArea("395","5","ORD"),
 new USPSZipArea("396","5","ORD"),
 new USPSZipArea("397","5","ORD"),
 new USPSZipArea("398","5","ORD"),
 new USPSZipArea("399","4","ORD"),
 new USPSZipArea("400","3","ORD"),
 new USPSZipArea("401","3","ORD"),
 new USPSZipArea("402","3","ORD"),
 new USPSZipArea("403","3","ORD"),
 new USPSZipArea("404","3","ORD"),
 new USPSZipArea("405","3","ORD"),
 new USPSZipArea("406","3","ORD"),
 new USPSZipArea("407","4","ORD"),
 new USPSZipArea("408","4","ORD"),
 new USPSZipArea("409","4","ORD"),
 new USPSZipArea("410","3","ORD"),
 new USPSZipArea("411","4","ORD"),
 new USPSZipArea("412","4","ORD"),
 new USPSZipArea("413","3","ORD"),
 new USPSZipArea("414","3","ORD"),
 new USPSZipArea("415","4","ORD"),
 new USPSZipArea("416","4","ORD"),
 new USPSZipArea("417","4","ORD"),
 new USPSZipArea("418","4","ORD"),
 new USPSZipArea("419","4","ORD"),
 new USPSZipArea("420","3","ORD"),
 new USPSZipArea("421","4","ORD"),
 new USPSZipArea("422","4","ORD"),
 new USPSZipArea("423","3","ORD"),
 new USPSZipArea("424","3","ORD"),
 new USPSZipArea("425","4","ORD"),
 new USPSZipArea("426","4","ORD"),
 new USPSZipArea("427","3","ORD"),
 new USPSZipArea("428","3","ORD"),
 new USPSZipArea("429","3","ORD"),
 new USPSZipArea("430","3","ORD"),
 new USPSZipArea("431","3","ORD"),
 new USPSZipArea("432","3","ORD"),
 new USPSZipArea("433","3","ORD"),
 new USPSZipArea("434","3","ORD"),
 new USPSZipArea("435","3","ORD"),
 new USPSZipArea("436","3","ORD"),
 new USPSZipArea("437","3","ORD"),
 new USPSZipArea("438","3","ORD"),
 new USPSZipArea("439","4","ORD"),
 new USPSZipArea("440","4","ORD"),
 new USPSZipArea("441","4","ORD"),
 new USPSZipArea("442","4","ORD"),
 new USPSZipArea("443","4","ORD"),
 new USPSZipArea("444","4","ORD"),
 new USPSZipArea("445","4","ORD"),
 new USPSZipArea("446","4","ORD"),
 new USPSZipArea("447","4","ORD"),
 new USPSZipArea("448","4","ORD"),
 new USPSZipArea("449","4","ORD"),
 new USPSZipArea("450","3","ORD"),
 new USPSZipArea("451","3","ORD"),
 new USPSZipArea("452","3","ORD"),
 new USPSZipArea("453","3","ORD"),
 new USPSZipArea("454","3","ORD"),
 new USPSZipArea("455","3","ORD"),
 new USPSZipArea("456","3","ORD"),
 new USPSZipArea("457","3","ORD"),
 new USPSZipArea("458","3","ORD"),
 new USPSZipArea("459","3","ORD"),
 new USPSZipArea("460","3","ORD"),
 new USPSZipArea("461","3","ORD"),
 new USPSZipArea("462","3","ORD"),
 new USPSZipArea("463","2","ORD"),
 new USPSZipArea("464","2","ORD"),
 new USPSZipArea("465","2","ORD"),
 new USPSZipArea("466","2","ORD"),
 new USPSZipArea("467","2","ORD"),
 new USPSZipArea("468","2","ORD"),
 new USPSZipArea("469","3","ORD"),
 new USPSZipArea("470","3","ORD"),
 new USPSZipArea("471","3","ORD"),
 new USPSZipArea("472","3","ORD"),
 new USPSZipArea("473","3","ORD"),
 new USPSZipArea("474","3","ORD"),
 new USPSZipArea("475","3","ORD"),
 new USPSZipArea("476","3","ORD"),
 new USPSZipArea("477","3","ORD"),
 new USPSZipArea("478","3","ORD"),
 new USPSZipArea("479","3","ORD"),
 new USPSZipArea("480","3","ORD"),
 new USPSZipArea("481","3","ORD"),
 new USPSZipArea("482","3","ORD"),
 new USPSZipArea("483","3","ORD"),
 new USPSZipArea("484","3","ORD"),
 new USPSZipArea("485","3","ORD"),
 new USPSZipArea("486","3","ORD"),
 new USPSZipArea("487","3","ORD"),
 new USPSZipArea("488","3","ORD"),
 new USPSZipArea("489","3","ORD"),
 new USPSZipArea("490","2","ORD"),
 new USPSZipArea("491","2","ORD"),
 new USPSZipArea("492","3","ORD"),
 new USPSZipArea("493","2","ORD"),
 new USPSZipArea("494","2","ORD"),
 new USPSZipArea("495","2","ORD"),
 new USPSZipArea("496","3","ORD"),
 new USPSZipArea("497","3","ORD"),
 new USPSZipArea("498","3","ORD"),
 new USPSZipArea("499","3","ORD"),
 new USPSZipArea("500","3","ORD"),
 new USPSZipArea("501","3","ORD"),
 new USPSZipArea("502","3","ORD"),
 new USPSZipArea("503","3","ORD"),
 new USPSZipArea("504","3","ORD"),
 new USPSZipArea("505","3","ORD"),
 new USPSZipArea("506","3","ORD"),
 new USPSZipArea("507","3","ORD"),
 new USPSZipArea("508","3","ORD"),
 new USPSZipArea("509","3","ORD"),
 new USPSZipArea("510","4","ORD"),
 new USPSZipArea("511","4","ORD"),
 new USPSZipArea("512","4","ORD"),
 new USPSZipArea("513","4","ORD"),
 new USPSZipArea("514","3","ORD"),
 new USPSZipArea("515","4","ORD"),
 new USPSZipArea("516","4","ORD"),
 new USPSZipArea("517","4","ORD"),
 new USPSZipArea("518","4","ORD"),
 new USPSZipArea("519","4","ORD"),
 new USPSZipArea("520","3","ORD"),
 new USPSZipArea("521","3","ORD"),
 new USPSZipArea("522","3","ORD"),
 new USPSZipArea("523","3","ORD"),
 new USPSZipArea("524","3","ORD"),
 new USPSZipArea("525","3","ORD"),
 new USPSZipArea("526","2","ORD"),
 new USPSZipArea("527","2","ORD"),
 new USPSZipArea("528","2","ORD"),
 new USPSZipArea("529","2","ORD"),
 new USPSZipArea("530","2","ORD"),
 new USPSZipArea("531","2","ORD"),
 new USPSZipArea("532","2","ORD"),
 new USPSZipArea("533","2","ORD"),
 new USPSZipArea("534","2","ORD"),
 new USPSZipArea("535","2","ORD"),
 new USPSZipArea("536","2","ORD"),
 new USPSZipArea("537","2","ORD"),
 new USPSZipArea("538","2","ORD"),
 new USPSZipArea("539","2","ORD"),
 new USPSZipArea("540","4","ORD"),
 new USPSZipArea("541","3","ORD"),
 new USPSZipArea("542","3","ORD"),
 new USPSZipArea("543","3","ORD"),
 new USPSZipArea("544","3","ORD"),
 new USPSZipArea("545","3","ORD"),
 new USPSZipArea("546","4","ORD"),
 new USPSZipArea("547","3","ORD"),
 new USPSZipArea("548","3","ORD"),
 new USPSZipArea("549","2","ORD"),
 new USPSZipArea("550","4","ORD"),
 new USPSZipArea("551","4","ORD"),
 new USPSZipArea("552","4","ORD"),
 new USPSZipArea("553","4","ORD"),
 new USPSZipArea("554","4","ORD"),
 new USPSZipArea("555","4","ORD"),
 new USPSZipArea("556","4","ORD"),
 new USPSZipArea("557","4","ORD"),
 new USPSZipArea("558","4","ORD"),
 new USPSZipArea("559","4","ORD"),
 new USPSZipArea("560","4","ORD"),
 new USPSZipArea("561","4","ORD"),
 new USPSZipArea("562","4","ORD"),
 new USPSZipArea("563","4","ORD"),
 new USPSZipArea("564","4","ORD"),
 new USPSZipArea("565","4","ORD"),
 new USPSZipArea("566","4","ORD"),
 new USPSZipArea("567","4","ORD"),
 new USPSZipArea("568","4","ORD"),
 new USPSZipArea("569","4","ORD"),
 new USPSZipArea("570","4","ORD"),
 new USPSZipArea("571","4","ORD"),
 new USPSZipArea("572","4","ORD"),
 new USPSZipArea("573","4","ORD"),
 new USPSZipArea("574","4","ORD"),
 new USPSZipArea("575","4","ORD"),
 new USPSZipArea("576","5","ORD"),
 new USPSZipArea("577","5","ORD"),
 new USPSZipArea("578","5","ORD"),
 new USPSZipArea("579","5","ORD"),
 new USPSZipArea("580","4","ORD"),
 new USPSZipArea("581","4","ORD"),
 new USPSZipArea("582","4","ORD"),
 new USPSZipArea("583","4","ORD"),
 new USPSZipArea("584","4","ORD"),
 new USPSZipArea("585","5","ORD"),
 new USPSZipArea("586","5","ORD"),
 new USPSZipArea("587","5","ORD"),
 new USPSZipArea("588","5","ORD"),
 new USPSZipArea("589","5","ORD"),
 new USPSZipArea("590","6","ORD"),
 new USPSZipArea("591","6","ORD"),
 new USPSZipArea("592","6","ORD"),
 new USPSZipArea("593","6","ORD"),
 new USPSZipArea("594","6","ORD"),
 new USPSZipArea("595","6","ORD"),
 new USPSZipArea("596","6","ORD"),
 new USPSZipArea("597","6","ORD"),
 new USPSZipArea("598","6","ORD"),
 new USPSZipArea("599","6","ORD"),
 new USPSZipArea("600","2","ORD"),
 new USPSZipArea("601","2","ORD"),
 new USPSZipArea("602","2","ORD"),
 new USPSZipArea("603","2","ORD"),
 new USPSZipArea("604","2","ORD"),
 new USPSZipArea("605","2","ORD"),
 new USPSZipArea("606","2","ORD"),
 new USPSZipArea("607","2","ORD"),
 new USPSZipArea("608","2","ORD"),
 new USPSZipArea("609","2","ORD"),
 new USPSZipArea("610","2","ORD"),
 new USPSZipArea("611","2","ORD"),
 new USPSZipArea("612","2","ORD"),
 new USPSZipArea("613","2","ORD"),
 new USPSZipArea("614","2","ORD"),
 new USPSZipArea("615","2","ORD"),
 new USPSZipArea("616","2","ORD"),
 new USPSZipArea("617","2","ORD"),
 new USPSZipArea("618","2","ORD"),
 new USPSZipArea("619","2","ORD"),
 new USPSZipArea("620","3","ORD"),
 new USPSZipArea("621","3","ORD"),
 new USPSZipArea("622","3","ORD"),
 new USPSZipArea("623","2","ORD"),
 new USPSZipArea("624","2","ORD"),
 new USPSZipArea("625","2","ORD"),
 new USPSZipArea("626","2","ORD"),
 new USPSZipArea("627","2","ORD"),
 new USPSZipArea("628","3","ORD"),
 new USPSZipArea("629","3","ORD"),
 new USPSZipArea("630","3","ORD"),
 new USPSZipArea("631","3","ORD"),
 new USPSZipArea("632","3","ORD"),
 new USPSZipArea("633","3","ORD"),
 new USPSZipArea("634","3","ORD"),
 new USPSZipArea("635","3","ORD"),
 new USPSZipArea("636","3","ORD"),
 new USPSZipArea("637","3","ORD"),
 new USPSZipArea("638","3","ORD"),
 new USPSZipArea("639","3","ORD"),
 new USPSZipArea("640","4","ORD"),
 new USPSZipArea("641","4","ORD"),
 new USPSZipArea("642","4","ORD"),
 new USPSZipArea("643","4","ORD"),
 new USPSZipArea("644","4","ORD"),
 new USPSZipArea("645","4","ORD"),
 new USPSZipArea("646","4","ORD"),
 new USPSZipArea("647","4","ORD"),
 new USPSZipArea("648","4","ORD"),
 new USPSZipArea("649","4","ORD"),
 new USPSZipArea("650","3","ORD"),
 new USPSZipArea("651","3","ORD"),
 new USPSZipArea("652","3","ORD"),
 new USPSZipArea("653","3","ORD"),
 new USPSZipArea("654","4","ORD"),
 new USPSZipArea("655","4","ORD"),
 new USPSZipArea("656","4","ORD"),
 new USPSZipArea("657","4","ORD"),
 new USPSZipArea("658","4","ORD"),
 new USPSZipArea("659","4","ORD"),
 new USPSZipArea("660","4","ORD"),
 new USPSZipArea("661","4","ORD"),
 new USPSZipArea("662","4","ORD"),
 new USPSZipArea("663","4","ORD"),
 new USPSZipArea("664","4","ORD"),
 new USPSZipArea("665","4","ORD"),
 new USPSZipArea("666","4","ORD"),
 new USPSZipArea("667","4","ORD"),
 new USPSZipArea("668","4","ORD"),
 new USPSZipArea("669","4","ORD"),
 new USPSZipArea("670","4","ORD"),
 new USPSZipArea("671","4","ORD"),
 new USPSZipArea("672","4","ORD"),
 new USPSZipArea("673","4","ORD"),
 new USPSZipArea("674","4","ORD"),
 new USPSZipArea("675","4","ORD"),
 new USPSZipArea("676","4","ORD"),
 new USPSZipArea("677","5","ORD"),
 new USPSZipArea("678","4","ORD"),
 new USPSZipArea("679","5","ORD"),
 new USPSZipArea("680","4","ORD"),
 new USPSZipArea("681","4","ORD"),
 new USPSZipArea("682","4","ORD"),
 new USPSZipArea("683","4","ORD"),
 new USPSZipArea("684","4","ORD"),
 new USPSZipArea("685","4","ORD"),
 new USPSZipArea("686","4","ORD"),
 new USPSZipArea("687","4","ORD"),
 new USPSZipArea("688","4","ORD"),
 new USPSZipArea("689","4","ORD"),
 new USPSZipArea("690","5","ORD"),
 new USPSZipArea("691","5","ORD"),
 new USPSZipArea("692","5","ORD"),
 new USPSZipArea("693","5","ORD"),
 new USPSZipArea("694","5","ORD"),
 new USPSZipArea("695","5","ORD"),
 new USPSZipArea("696","5","ORD"),
 new USPSZipArea("697","5","ORD"),
 new USPSZipArea("698","5","ORD"),
 new USPSZipArea("699","5","ORD"),
 new USPSZipArea("700","5","ORD"),
 new USPSZipArea("701","5","ORD"),
 new USPSZipArea("702","5","ORD"),
 new USPSZipArea("703","5","ORD"),
 new USPSZipArea("704","5","ORD"),
 new USPSZipArea("705","5","ORD"),
 new USPSZipArea("706","5","ORD"),
 new USPSZipArea("707","5","ORD"),
 new USPSZipArea("708","5","ORD"),
 new USPSZipArea("709","5","ORD"),
 new USPSZipArea("710","5","ORD"),
 new USPSZipArea("711","5","ORD"),
 new USPSZipArea("712","5","ORD"),
 new USPSZipArea("713","5","ORD"),
 new USPSZipArea("714","5","ORD"),
 new USPSZipArea("715","5","ORD"),
 new USPSZipArea("716","4","ORD"),
 new USPSZipArea("717","4","ORD"),
 new USPSZipArea("718","5","ORD"),
 new USPSZipArea("719","4","ORD"),
 new USPSZipArea("720","4","ORD"),
 new USPSZipArea("721","4","ORD"),
 new USPSZipArea("722","4","ORD"),
 new USPSZipArea("723","4","ORD"),
 new USPSZipArea("724","4","ORD"),
 new USPSZipArea("725","4","ORD"),
 new USPSZipArea("726","4","ORD"),
 new USPSZipArea("727","4","ORD"),
 new USPSZipArea("728","4","ORD"),
 new USPSZipArea("729","4","ORD"),
 new USPSZipArea("730","5","ORD"),
 new USPSZipArea("731","5","ORD"),
 new USPSZipArea("732","5","ORD"),
 new USPSZipArea("733","5","ORD"),
 new USPSZipArea("734","5","ORD"),
 new USPSZipArea("735","5","ORD"),
 new USPSZipArea("736","5","ORD"),
 new USPSZipArea("737","5","ORD"),
 new USPSZipArea("738","5","ORD"),
 new USPSZipArea("739","5","ORD"),
 new USPSZipArea("740","4","ORD"),
 new USPSZipArea("741","4","ORD"),
 new USPSZipArea("742","4","ORD"),
 new USPSZipArea("743","4","ORD"),
 new USPSZipArea("744","4","ORD"),
 new USPSZipArea("745","4","ORD"),
 new USPSZipArea("746","4","ORD"),
 new USPSZipArea("747","4","ORD"),
 new USPSZipArea("748","5","ORD"),
 new USPSZipArea("749","4","ORD"),
 new USPSZipArea("750","5","ORD"),
 new USPSZipArea("751","5","ORD"),
 new USPSZipArea("752","5","ORD"),
 new USPSZipArea("753","5","ORD"),
 new USPSZipArea("754","5","ORD"),
 new USPSZipArea("755","5","ORD"),
 new USPSZipArea("756","5","ORD"),
 new USPSZipArea("757","5","ORD"),
 new USPSZipArea("758","5","ORD"),
 new USPSZipArea("759","5","ORD"),
 new USPSZipArea("760","5","ORD"),
 new USPSZipArea("761","5","ORD"),
 new USPSZipArea("762","5","ORD"),
 new USPSZipArea("763","5","ORD"),
 new USPSZipArea("764","5","ORD"),
 new USPSZipArea("765","5","ORD"),
 new USPSZipArea("766","5","ORD"),
 new USPSZipArea("767","5","ORD"),
 new USPSZipArea("768","5","ORD"),
 new USPSZipArea("769","5","ORD"),
 new USPSZipArea("770","5","ORD"),
 new USPSZipArea("771","5","ORD"),
 new USPSZipArea("772","5","ORD"),
 new USPSZipArea("773","5","ORD"),
 new USPSZipArea("774","5","ORD"),
 new USPSZipArea("775","5","ORD"),
 new USPSZipArea("776","5","ORD"),
 new USPSZipArea("777","5","ORD"),
 new USPSZipArea("778","5","ORD"),
 new USPSZipArea("779","6","ORD"),
 new USPSZipArea("780","5","ORD"),
 new USPSZipArea("781","5","ORD"),
 new USPSZipArea("782","5","ORD"),
 new USPSZipArea("783","6","ORD"),
 new USPSZipArea("784","6","ORD"),
 new USPSZipArea("785","6","ORD"),
 new USPSZipArea("786","5","ORD"),
 new USPSZipArea("787","5","ORD"),
 new USPSZipArea("788","5","ORD"),
 new USPSZipArea("789","5","ORD"),
 new USPSZipArea("790","5","ORD"),
 new USPSZipArea("791","5","ORD"),
 new USPSZipArea("792","5","ORD"),
 new USPSZipArea("793","5","ORD"),
 new USPSZipArea("794","5","ORD"),
 new USPSZipArea("795","5","ORD"),
 new USPSZipArea("796","5","ORD"),
 new USPSZipArea("797","6","ORD"),
 new USPSZipArea("798","6","ORD"),
 new USPSZipArea("799","6","ORD"),
 new USPSZipArea("800","5","ORD"),
 new USPSZipArea("801","5","ORD"),
 new USPSZipArea("802","5","ORD"),
 new USPSZipArea("803","5","ORD"),
 new USPSZipArea("804","5","ORD"),
 new USPSZipArea("805","5","ORD"),
 new USPSZipArea("806","5","ORD"),
 new USPSZipArea("807","5","ORD"),
 new USPSZipArea("808","5","ORD"),
 new USPSZipArea("809","5","ORD"),
 new USPSZipArea("810","5","ORD"),
 new USPSZipArea("811","5","ORD"),
 new USPSZipArea("812","5","ORD"),
 new USPSZipArea("813","6","ORD"),
 new USPSZipArea("814","6","ORD"),
 new USPSZipArea("815","6","ORD"),
 new USPSZipArea("816","6","ORD"),
 new USPSZipArea("817","6","ORD"),
 new USPSZipArea("818","6","ORD"),
 new USPSZipArea("819","6","ORD"),
 new USPSZipArea("820","5","ORD"),
 new USPSZipArea("821","6","ORD"),
 new USPSZipArea("822","5","ORD"),
 new USPSZipArea("823","5","ORD"),
 new USPSZipArea("824","5","ORD"),
 new USPSZipArea("825","5","ORD"),
 new USPSZipArea("826","5","ORD"),
 new USPSZipArea("827","5","ORD"),
 new USPSZipArea("828","5","ORD"),
 new USPSZipArea("829","6","ORD"),
 new USPSZipArea("830","6","ORD"),
 new USPSZipArea("831","6","ORD"),
 new USPSZipArea("832","6","ORD"),
 new USPSZipArea("833","7","ORD"),
 new USPSZipArea("834","6","ORD"),
 new USPSZipArea("835","7","ORD"),
 new USPSZipArea("836","7","ORD"),
 new USPSZipArea("837","7","ORD"),
 new USPSZipArea("838","7","ORD"),
 new USPSZipArea("839","7","ORD"),
 new USPSZipArea("840","6","ORD"),
 new USPSZipArea("841","6","ORD"),
 new USPSZipArea("842","6","ORD"),
 new USPSZipArea("843","6","ORD"),
 new USPSZipArea("844","6","ORD"),
 new USPSZipArea("845","6","ORD"),
 new USPSZipArea("846","6","ORD"),
 new USPSZipArea("847","6","ORD"),
 new USPSZipArea("848","6","ORD"),
 new USPSZipArea("849","6","ORD"),
 new USPSZipArea("850","6","ORD"),
 new USPSZipArea("851","6","ORD"),
 new USPSZipArea("852","6","ORD"),
 new USPSZipArea("853","6","ORD"),
 new USPSZipArea("854","6","ORD"),
 new USPSZipArea("855","6","ORD"),
 new USPSZipArea("856","6","ORD"),
 new USPSZipArea("857","6","ORD"),
 new USPSZipArea("858","6","ORD"),
 new USPSZipArea("859","6","ORD"),
 new USPSZipArea("860","6","ORD"),
 new USPSZipArea("861","6","ORD"),
 new USPSZipArea("862","6","ORD"),
 new USPSZipArea("863","6","ORD"),
 new USPSZipArea("864","7","ORD"),
 new USPSZipArea("865","6","ORD"),
 new USPSZipArea("866","6","ORD"),
 new USPSZipArea("867","6","ORD"),
 new USPSZipArea("868","6","ORD"),
 new USPSZipArea("869","6","ORD"),
 new USPSZipArea("870","6","ORD"),
 new USPSZipArea("871","6","ORD"),
 new USPSZipArea("872","6","ORD"),
 new USPSZipArea("873","6","ORD"),
 new USPSZipArea("874","6","ORD"),
 new USPSZipArea("875","6","ORD"),
 new USPSZipArea("876","6","ORD"),
 new USPSZipArea("877","6","ORD"),
 new USPSZipArea("878","6","ORD"),
 new USPSZipArea("879","6","ORD"),
 new USPSZipArea("880","6","ORD"),
 new USPSZipArea("881","5","ORD"),
 new USPSZipArea("882","5","ORD"),
 new USPSZipArea("883","6","ORD"),
 new USPSZipArea("884","6","ORD"),
 new USPSZipArea("885","6","ORD"),
 new USPSZipArea("886","6","ORD"),
 new USPSZipArea("887","6","ORD"),
 new USPSZipArea("888","6","ORD"),
 new USPSZipArea("889","7","ORD"),
 new USPSZipArea("890","7","ORD"),
 new USPSZipArea("891","7","ORD"),
 new USPSZipArea("892","7","ORD"),
 new USPSZipArea("893","7","ORD"),
 new USPSZipArea("894","7","ORD"),
 new USPSZipArea("895","7","ORD"),
 new USPSZipArea("896","7","ORD"),
 new USPSZipArea("897","7","ORD"),
 new USPSZipArea("898","6","ORD"),
 new USPSZipArea("899","6","ORD"),
 new USPSZipArea("900","7","ORD"),
 new USPSZipArea("901","7","ORD"),
 new USPSZipArea("902","7","ORD"),
 new USPSZipArea("903","7","ORD"),
 new USPSZipArea("904","7","ORD"),
 new USPSZipArea("905","7","ORD"),
 new USPSZipArea("906","7","ORD"),
 new USPSZipArea("907","7","ORD"),
 new USPSZipArea("908","7","ORD"),
 new USPSZipArea("909","7","ORD"),
 new USPSZipArea("910","7","ORD"),
 new USPSZipArea("911","7","ORD"),
 new USPSZipArea("912","7","ORD"),
 new USPSZipArea("913","7","ORD"),
 new USPSZipArea("914","7","ORD"),
 new USPSZipArea("915","7","ORD"),
 new USPSZipArea("916","7","ORD"),
 new USPSZipArea("917","7","ORD"),
 new USPSZipArea("918","7","ORD"),
 new USPSZipArea("919","7","ORD"),
 new USPSZipArea("920","7","ORD"),
 new USPSZipArea("921","7","ORD"),
 new USPSZipArea("922","7","ORD"),
 new USPSZipArea("923","7","ORD"),
 new USPSZipArea("924","7","ORD"),
 new USPSZipArea("925","7","ORD"),
 new USPSZipArea("926","7","ORD"),
 new USPSZipArea("927","7","ORD"),
 new USPSZipArea("928","7","ORD"),
 new USPSZipArea("929","7","ORD"),
 new USPSZipArea("930","7","ORD"),
 new USPSZipArea("931","7","ORD"),
 new USPSZipArea("932","7","ORD"),
 new USPSZipArea("933","7","ORD"),
 new USPSZipArea("934","7","ORD"),
 new USPSZipArea("935","7","ORD"),
 new USPSZipArea("936","7","ORD"),
 new USPSZipArea("937","7","ORD"),
 new USPSZipArea("938","7","ORD"),
 new USPSZipArea("939","7","ORD"),
 new USPSZipArea("940","8","ORD"),
 new USPSZipArea("941","8","ORD"),
 new USPSZipArea("942","7","ORD"),
 new USPSZipArea("943","8","ORD"),
 new USPSZipArea("944","8","ORD"),
 new USPSZipArea("945","8","ORD"),
 new USPSZipArea("946","8","ORD"),
 new USPSZipArea("947","8","ORD"),
 new USPSZipArea("948","8","ORD"),
 new USPSZipArea("949","8","ORD"),
 new USPSZipArea("950","7","ORD"),
 new USPSZipArea("951","7","ORD"),
 new USPSZipArea("952","7","ORD"),
 new USPSZipArea("953","7","ORD"),
 new USPSZipArea("954","8","ORD"),
 new USPSZipArea("955","8","ORD"),
 new USPSZipArea("956","7","ORD"),
 new USPSZipArea("957","7","ORD"),
 new USPSZipArea("958","7","ORD"),
 new USPSZipArea("959","7","ORD"),
 new USPSZipArea("960","7","ORD"),
 new USPSZipArea("961","7","ORD"),
 new USPSZipArea("962","8","ORD"),
 new USPSZipArea("963","8","ORD"),
 new USPSZipArea("964","8","ORD"),
 new USPSZipArea("965","8","ORD"),
 new USPSZipArea("966","8","ORD"),
 new USPSZipArea("967","8","ORD"),
 new USPSZipArea("968","8","ORD"),
 new USPSZipArea("969","9","ORD"),
 new USPSZipArea("970","7","ORD"),
 new USPSZipArea("971","7","ORD"),
 new USPSZipArea("972","7","ORD"),
 new USPSZipArea("973","7","ORD"),
 new USPSZipArea("974","7","ORD"),
 new USPSZipArea("975","7","ORD"),
 new USPSZipArea("976","7","ORD"),
 new USPSZipArea("977","7","ORD"),
 new USPSZipArea("978","7","ORD"),
 new USPSZipArea("979","7","ORD"),
 new USPSZipArea("980","7","ORD"),
 new USPSZipArea("981","7","ORD"),
 new USPSZipArea("982","7","ORD"),
 new USPSZipArea("983","7","ORD"),
 new USPSZipArea("984","7","ORD"),
 new USPSZipArea("985","7","ORD"),
 new USPSZipArea("986","7","ORD"),
 new USPSZipArea("987","7","ORD"),
 new USPSZipArea("988","7","ORD"),
 new USPSZipArea("989","7","ORD"),
 new USPSZipArea("990","7","ORD"),
 new USPSZipArea("991","7","ORD"),
 new USPSZipArea("992","7","ORD"),
 new USPSZipArea("993","7","ORD"),
 new USPSZipArea("994","7","ORD"),
 new USPSZipArea("995","8","ORD"),
 new USPSZipArea("996","8","ORD"),
 new USPSZipArea("997","8","ORD"),
 new USPSZipArea("998","8","ORD"),
 new USPSZipArea("999","8","ORD"),
 
            };
        }

        public static List<USPSZipArea> GetFCZipAreas()
        {
            return new List<USPSZipArea>()
            {
                new USPSZipArea("005-089","8","ORD"),
                new USPSZipArea("090-099","8","ORD"),
                new USPSZipArea("100-212","8","ORD"),
                new USPSZipArea("214-268","8","ORD"),
                new USPSZipArea("270-323","8","ORD"),
                new USPSZipArea("324-325","7","ORD"),
                new USPSZipArea("326-342","8","ORD"),
                new USPSZipArea("344","8","ORD"),
                new USPSZipArea("346-347","8","ORD"),
                new USPSZipArea("349","8","ORD"),
                new USPSZipArea("350-352","7","ORD"),
                new USPSZipArea("354-359","7","ORD"),
                new USPSZipArea("360-361","8","ORD"),
                new USPSZipArea("362","7","ORD"),
                new USPSZipArea("363-364","8","ORD"),
                new USPSZipArea("365-366","7","ORD"),
                new USPSZipArea("367-368","8","ORD"),
                new USPSZipArea("369-372","7","ORD"),
                new USPSZipArea("373-374","8","ORD"),
                new USPSZipArea("375","7","ORD"),
                new USPSZipArea("376-379","8","ORD"),
                new USPSZipArea("380-397","7","ORD"),
                new USPSZipArea("398-399","8","ORD"),
                new USPSZipArea("400-402","7","ORD"),
                new USPSZipArea("403-418","8","ORD"),
                new USPSZipArea("420-424","7","ORD"),
                new USPSZipArea("425-426","8","ORD"),
                new USPSZipArea("427","7","ORD"),
                new USPSZipArea("430-459","8","ORD"),
                new USPSZipArea("460-466","7","ORD"),
                new USPSZipArea("467-468","8","ORD"),
                new USPSZipArea("469","7","ORD"),
                new USPSZipArea("470","8","ORD"),
                new USPSZipArea("471-472","7","ORD"),
                new USPSZipArea("473","8","ORD"),
                new USPSZipArea("474-479","7","ORD"),
                new USPSZipArea("480-489","8","ORD"),
                new USPSZipArea("490-491","7","ORD"),
                new USPSZipArea("492","8","ORD"),
                new USPSZipArea("493-495","7","ORD"),
                new USPSZipArea("496-497","8","ORD"),
                new USPSZipArea("498-499","7","ORD"),
                new USPSZipArea("500-503","6","ORD"),
                new USPSZipArea("504","7","ORD"),
                new USPSZipArea("505","6","ORD"),
                new USPSZipArea("506-507","7","ORD"),
                new USPSZipArea("508-516","6","ORD"),
                new USPSZipArea("520-524","7","ORD"),
                new USPSZipArea("525","6","ORD"),
                new USPSZipArea("526-528","7","ORD"),
                new USPSZipArea("530-532","7","ORD"),
                new USPSZipArea("534-535","7","ORD"),
                new USPSZipArea("537-551","7","ORD"),
                new USPSZipArea("553-564","7","ORD"),
                new USPSZipArea("565","6","ORD"),
                new USPSZipArea("566","7","ORD"),
                new USPSZipArea("567","6","ORD"),
                new USPSZipArea("570-577","6","ORD"),
                new USPSZipArea("580-588","6","ORD"),
                new USPSZipArea("590-599","5","LAX"),
                new USPSZipArea("600-620","7","ORD"),
                new USPSZipArea("622-631","7","ORD"),
                new USPSZipArea("633-639","7","ORD"),
                new USPSZipArea("640-641","6","ORD"),
                new USPSZipArea("644-649","6","ORD"),
                new USPSZipArea("650-653","7","ORD"),
                new USPSZipArea("654-658","6","ORD"),
                new USPSZipArea("660-662","6","ORD"),
                new USPSZipArea("664-678","6","ORD"),
                new USPSZipArea("679","5","LAX"),
                new USPSZipArea("680-681","6","ORD"),
                new USPSZipArea("683-693","6","ORD"),
                new USPSZipArea("700-701","7","ORD"),
                new USPSZipArea("703-708","7","ORD"),
                new USPSZipArea("710-714","6","ORD"),
                new USPSZipArea("716-717","7","ORD"),
                new USPSZipArea("718","6","ORD"),
                new USPSZipArea("719-725","7","ORD"),
                new USPSZipArea("726-727","6","ORD"),
                new USPSZipArea("728","7","ORD"),
                new USPSZipArea("729-731","6","ORD"),
                new USPSZipArea("733-738","6","ORD"),
                new USPSZipArea("739","5","LAX"),
                new USPSZipArea("740-741","6","ORD"),
                new USPSZipArea("743-770","6","ORD"),
                new USPSZipArea("772-789","6","ORD"),
                new USPSZipArea("790-794","5","LAX"),
                new USPSZipArea("795-796","6","ORD"),
                new USPSZipArea("797-816","5","LAX"),
                new USPSZipArea("820-828","5","LAX"),
                new USPSZipArea("829-832","4","LAX"),
                new USPSZipArea("833","5","LAX"),
                new USPSZipArea("834","4","LAX"),
                new USPSZipArea("835-838","5","LAX"),
                new USPSZipArea("840-847","4","LAX"),
                new USPSZipArea("850-853","4","LAX"),
                new USPSZipArea("855-857","4","LAX"),
                new USPSZipArea("859-860","4","LAX"),
                new USPSZipArea("863","4","LAX"),
                new USPSZipArea("864","3","LAX"),
                new USPSZipArea("865","5","LAX"),
                new USPSZipArea("870-871","5","LAX"),
                new USPSZipArea("873-885","5","LAX"),
                new USPSZipArea("889-891","3","LAX"),
                new USPSZipArea("893","3","LAX"),
                new USPSZipArea("894-895","4","LAX"),
                new USPSZipArea("897-898","4","LAX"),
                new USPSZipArea("900-908","1","LAX"),
                new USPSZipArea("910-918","1","LAX"),
                new USPSZipArea("919-921","2","LAX"),
                new USPSZipArea("922-928","1","LAX"),
                new USPSZipArea("930-935","2","LAX"),
                new USPSZipArea("936-939","3","LAX"),
                new USPSZipArea("940-949","4","LAX"),
                new USPSZipArea("950-951","3","LAX"),
                new USPSZipArea("952-961","4","LAX"),
                new USPSZipArea("962-966","4","LAX"),
                new USPSZipArea("967-968","8","ORD"),
                new USPSZipArea("969","9","ORD"),
                new USPSZipArea("970-974","5","LAX"),
                new USPSZipArea("975-976","4","LAX"),
                new USPSZipArea("977-986","5","LAX"),
                new USPSZipArea("988-994","5","LAX"),
                new USPSZipArea("995-998","8","ORD"),
                new USPSZipArea("999","7","ORD")
            };
        }
        public class USPSZipArea
        {
            public USPSZipArea(string zipArea, string area, string port)
            {
                var zipArray = zipArea.Split('-');
                if (zipArray.Length > 1)
                {
                    this.zip3Start = int.Parse(zipArray[0]);
                    this.zip3End = int.Parse(zipArray[1]);
                }
                else
                {
                    this.zip3Start = int.Parse(zipArray[0]);
                    this.zip3End = int.Parse(zipArray[0]);
                }
                this.AreaCode = area;
                this.PortCode = port;
            }

            public int zip3Start
            {
                get; set;
            }

            public int zip3End
            {
                get; set;
            }

            public string AreaCode
            {
                get; set;
            }

            public string PortCode
            {
                get; set;
            }
        }


        public static int GetFCOrdAreaCode(string zip)
        {

            string zip5 = GetZip5(zip);
            if (string.IsNullOrEmpty(zip5))
                return 0;
            string zip3 = zip5.Substring(0, 3);
            List<USPSZipArea> zipAreas = GetORDZipAreas();

            int intZip3 = int.Parse(zip3);
            var code = zipAreas.Where(x => intZip3 >= x.zip3Start && intZip3 <= x.zip3End).FirstOrDefault();
            if (code == null)
                return 0;
            else
            {
                return int.Parse(code.AreaCode);
            }
        }

        public static int GetFCLaxAreaCode(string zip)
        {
            string zip5 = GetZip5(zip);
            if (string.IsNullOrEmpty(zip5))
                return 0;
            string zip3 = zip5.Substring(0, 3);
            List<USPSZipArea> zipAreas = GetFCZipAreas();

            int intZip3 = int.Parse(zip3);
            var code = zipAreas.Where(x => intZip3 >= x.zip3Start && intZip3 <= x.zip3End).FirstOrDefault();
            if (code == null)
                return 0;
            else
            {
                return int.Parse(code.AreaCode);
            }
        }
    }
}
