protected void gvImportResults_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException(nameof(e));
        }
        GridViewRow grow = (GridViewRow)((WebControl)e.CommandSource).NamingContainer;
        int         iRow = grow.RowIndex;

        airportImportCandidate aic = ImportedAirportCandidates[iRow];

        AirportImportRowCommand airc = (AirportImportRowCommand)Enum.Parse(typeof(AirportImportRowCommand), e.CommandName);

        CheckBox ckUseMap = (CheckBox)grow.FindControl("ckUseMap");

        if (ckUseMap.Checked)
        {
            aic.LatLong.Latitude  = Convert.ToDouble(txtLat.Text, System.Globalization.CultureInfo.InvariantCulture);
            aic.LatLong.Longitude = Convert.ToDouble(txtLong.Text, System.Globalization.CultureInfo.InvariantCulture);
        }

        airport ap = null;

        switch (e.CommandArgument.ToString())
        {
        case "FAA":
            ap = aic.FAAMatch;
            break;

        case "ICAO":
            ap = aic.ICAOMatch;
            break;

        case "IATA":
            ap = aic.IATAMatch;
            break;
        }

        switch (airc)
        {
        case AirportImportRowCommand.FixLocation:
            ap.LatLong = aic.LatLong;
            ap.FCommit(true, false);
            break;

        case AirportImportRowCommand.FixType:
            ap.FDelete(true);       // delete the existing one before we update - otherwise REPLACE INTO will not succeed (because we are changing the REPLACE INTO primary key, which includes Type)
            ap.FacilityTypeCode = aic.FacilityTypeCode;
            ap.FCommit(true, true); // force this to be treated as a new airport
            break;

        case AirportImportRowCommand.Overwrite:
        case AirportImportRowCommand.AddAirport:
            if (airc == AirportImportRowCommand.Overwrite)
            {
                ap.FDelete(true);       // delete the existing airport
            }
            switch (e.CommandArgument.ToString())
            {
            case "FAA":
                aic.Code = aic.FAA;
                break;

            case "ICAO":
                aic.Code = aic.ICAO;
                break;

            case "IATA":
                aic.Code = aic.IATA;
                break;
            }
            aic.Code = Regex.Replace(aic.Code, "[^a-zA-Z0-9]", string.Empty);
            aic.FCommit(true, true);
            break;
        }

        UpdateImportData();
    }
        public static bool AirportImportCommand(airportImportCandidate aic, string source, string szCommand)
        {
            CheckAdmin();

            if (aic == null)
            {
                throw new ArgumentNullException(nameof(aic));
            }
            if (szCommand == null)
            {
                throw new ArgumentNullException(nameof(szCommand));
            }

            AirportImportRowCommand airc = (AirportImportRowCommand)Enum.Parse(typeof(AirportImportRowCommand), szCommand);
            AirportImportSource     ais  = (AirportImportSource)Enum.Parse(typeof(AirportImportSource), source);

            airport ap = null;

            switch (ais)
            {
            case AirportImportSource.FAA:
                ap = aic.FAAMatch;
                break;

            case AirportImportSource.ICAO:
                ap = aic.ICAOMatch;
                break;

            case AirportImportSource.IATA:
                ap = aic.IATAMatch;
                break;
            }

            switch (airc)
            {
            case AirportImportRowCommand.FixLocation:
                ap.LatLong = aic.LatLong;
                ap.FCommit(true, false);
                if (!String.IsNullOrWhiteSpace(aic.Country))
                {
                    ap.SetLocale(aic.Country, aic.Admin1);
                }
                break;

            case AirportImportRowCommand.FixType:
                ap.FDelete(true);       // delete the existing one before we update - otherwise REPLACE INTO will not succeed (because we are changing the REPLACE INTO primary key, which includes Type)
                ap.FacilityTypeCode = aic.FacilityTypeCode;
                ap.FCommit(true, true); // force this to be treated as a new airport
                break;

            case AirportImportRowCommand.Overwrite:
            case AirportImportRowCommand.AddAirport:
                if (airc == AirportImportRowCommand.Overwrite)
                {
                    ap.FDelete(true);       // delete the existing airport
                }
                switch (ais)
                {
                case AirportImportSource.FAA:
                    aic.Code = aic.FAA;
                    break;

                case AirportImportSource.ICAO:
                    aic.Code = aic.ICAO;
                    break;

                case AirportImportSource.IATA:
                    aic.Code = aic.IATA;
                    break;
                }
                aic.Code = Regex.Replace(aic.Code, "[^a-zA-Z0-9]", string.Empty);
                aic.FCommit(true, true);
                if (!String.IsNullOrWhiteSpace(aic.Country))
                {
                    aic.SetLocale(aic.Country, aic.Admin1);
                }
                break;
            }
            return(true);
        }