Exemple #1
0
    public static void DeleteDupeUserAirport(string idDelete, string idMap, string szUser, string szType)
    {
        CheckAdmin();

        airport apToDelete = new airport(idDelete, "(None)", 0, 0, szType, string.Empty, 0, szUser);

        if (apToDelete.FDelete(true))
        {
            if (!String.IsNullOrEmpty(szUser))
            {
                DBHelper dbh = new DBHelper("UPDATE flights SET route=REPLACE(route, ?idDelete, ?idMap) WHERE username=?user AND route LIKE CONCAT('%', ?idDelete, '%')");
                if (!dbh.DoNonQuery((comm) =>
                {
                    comm.Parameters.AddWithValue("idDelete", idDelete);
                    comm.Parameters.AddWithValue("idMap", idMap);
                    comm.Parameters.AddWithValue("user", szUser);
                }))
                {
                    throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, "Error mapping from {0} to {1} in flights for user {2}: {3}", idDelete, idMap, szUser, dbh.LastError));
                }
            }
        }
        else
        {
            throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, "Error deleting airport {0}: {1}", apToDelete.Code, apToDelete.ErrorText));
        }
    }
    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);
        }