Beispiel #1
0
        protected void gvImportResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                airportImportCandidate aic = (airportImportCandidate)e.Row.DataItem;

                Dictionary <string, string> dContext = new Dictionary <string, string>()
                {
                    { "useMapCheckID", e.Row.FindControl("ckUseMap").ClientID },
                    { "lat", txtLat.ClientID },
                    { "lon", txtLong.ClientID }
                };

                Literal litRowContext = (Literal)e.Row.FindControl("litRowContext");
                litRowContext.Text = String.Format(CultureInfo.InvariantCulture, @"<script type=""text/javascript""> var {0} = {1}; var {2} = {3}; </script>", ImportVarNameForIndex(e.Row.DataItemIndex), JsonConvert.SerializeObject(aic), ContextVarNameForIndex(e.Row.DataItemIndex), JsonConvert.SerializeObject(dContext));

                Label         lblProposed = (Label)e.Row.FindControl("lblProposed");
                StringBuilder sb          = new StringBuilder();
                if (!String.IsNullOrEmpty(aic.FAA))
                {
                    sb.AppendFormat(CultureInfo.InvariantCulture, "FAA: {0}<br />", aic.FAA);
                }
                if (!String.IsNullOrEmpty(aic.IATA))
                {
                    sb.AppendFormat(CultureInfo.InvariantCulture, "IATA: {0}<br />", aic.IATA);
                }
                if (!String.IsNullOrEmpty(aic.ICAO))
                {
                    sb.AppendFormat(CultureInfo.InvariantCulture, "ICAO: {0}<br />", aic.ICAO);
                }
                lblProposed.Text = sb.ToString();

                airportImportCandidate.PopulateAirport(e.Row.FindControl("plcFAAMatch"), aic.FAAMatch, aic.MatchStatusFAA, aic);
                airportImportCandidate.PopulateAirport(e.Row.FindControl("plcIATAMatch"), aic.IATAMatch, aic.MatchStatusIATA, aic);
                airportImportCandidate.PopulateAirport(e.Row.FindControl("plcICAOMatch"), aic.ICAOMatch, aic.MatchStatusICAO, aic);
                airportImportCandidate.PopulateAirport(e.Row.FindControl("plcAirportProposed"), aic, airportImportCandidate.MatchStatus.NotApplicable, null);

                SetUpImportButtons(e.Row, aic, util.GetIntParam(Request, "blast", 0) != 0);

                if (aic.IsOK)
                {
                    e.Row.BackColor = System.Drawing.Color.LightGreen;
                }
            }
        }
Beispiel #2
0
        private static void SetUpAddButtons(Control row, airportImportCandidate aic, bool fAllowBlast)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            if (aic == null)
            {
                throw new ArgumentNullException(nameof(aic));
            }

            row.FindControl("btnAddFAA").Visible  = !String.IsNullOrEmpty(aic.FAA) && (fAllowBlast || aic.FAAMatch == null);
            row.FindControl("btnAddIATA").Visible = !String.IsNullOrEmpty(aic.IATA) && (fAllowBlast || aic.IATAMatch == null);
            row.FindControl("btnAddICAO").Visible = !String.IsNullOrEmpty(aic.ICAO) && (fAllowBlast || aic.ICAOMatch == null);
        }
Beispiel #3
0
        private static void SetUpLocationButtons(Control row, airportImportCandidate aic)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            if (aic == null)
            {
                throw new ArgumentNullException(nameof(aic));
            }

            // don't offer to fix distances over maxDistanceToFix, to avoid accidentally stomping on airports somewhere else in the world.
            row.FindControl("btnFixLocationFAA").Visible  = (aic.FAAMatch != null && aic.MatchStatusFAA == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.FAAMatch) < maxDistanceToFix);
            row.FindControl("btnFixLocationIATA").Visible = (aic.IATAMatch != null && aic.MatchStatusIATA == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.IATAMatch) < maxDistanceToFix);
            row.FindControl("btnFixLocationICAO").Visible = (aic.ICAOMatch != null && aic.MatchStatusICAO == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.ICAOMatch) < maxDistanceToFix);
        }
Beispiel #4
0
        private static void SetUpFixButtons(Control row, airportImportCandidate aic)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            if (aic == null)
            {
                throw new ArgumentNullException(nameof(aic));
            }

            // And don't offer to fix type if that's not the error
            row.FindControl("btnFixTypeFAA").Visible  = (aic.FAAMatch != null && aic.MatchStatusFAA == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.FAAMatch) < maxDistanceToFix);
            row.FindControl("btnFixTypeIATA").Visible = (aic.IATAMatch != null && aic.MatchStatusIATA == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.IATAMatch) < maxDistanceToFix);
            row.FindControl("btnFixTypeICAO").Visible = (aic.ICAOMatch != null && aic.MatchStatusICAO == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.ICAOMatch) < maxDistanceToFix);

            // And don't offer to fix type if that's not the error
            row.FindControl("btnOverwriteFAA").Visible  = aic.FAAMatch != null && (aic.MatchStatusFAA == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.FAAMatch) >= maxDistanceToFix);
            row.FindControl("btnOverwriteIATA").Visible = aic.IATAMatch != null && (aic.MatchStatusIATA == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.IATAMatch) >= maxDistanceToFix);
            row.FindControl("btnOverwriteICAO").Visible = aic.ICAOMatch != null && (aic.MatchStatusICAO == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.ICAOMatch) >= maxDistanceToFix);
        }
    protected void gvImportResults_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException(nameof(e));
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            airportImportCandidate aic = (airportImportCandidate)e.Row.DataItem;

            Label         lblProposed = ((Label)e.Row.FindControl("lblProposed"));
            StringBuilder sb          = new StringBuilder();
            if (!String.IsNullOrEmpty(aic.FAA))
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "FAA: {0}<br />", aic.FAA);
            }
            if (!String.IsNullOrEmpty(aic.IATA))
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "IATA: {0}<br />", aic.IATA);
            }
            if (!String.IsNullOrEmpty(aic.ICAO))
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "ICAO: {0}<br />", aic.ICAO);
            }
            lblProposed.Text = sb.ToString();

            PopulateAirport(e.Row.FindControl("plcFAAMatch"), aic.FAAMatch, aic.MatchStatusFAA, aic);
            PopulateAirport(e.Row.FindControl("plcIATAMatch"), aic.IATAMatch, aic.MatchStatusIATA, aic);
            PopulateAirport(e.Row.FindControl("plcICAOMatch"), aic.ICAOMatch, aic.MatchStatusICAO, aic);
            PopulateAirport(e.Row.FindControl("plcAirportProposed"), aic, airportImportCandidate.MatchStatus.NotApplicable, null);

            SetUpImportButtons(e.Row, aic, util.GetIntParam(Request, "blast", 0) != 0);

            if (aic.IsOK)
            {
                e.Row.BackColor = System.Drawing.Color.LightGreen;
            }
        }
    }
    private static void SetUpImportButtons(Control row, airportImportCandidate aic, bool fAllowBlast)
    {
        ((Button)row.FindControl("btnAddFAA")).Visible  = !String.IsNullOrEmpty(aic.FAA) && (fAllowBlast || aic.FAAMatch == null);
        ((Button)row.FindControl("btnAddIATA")).Visible = !String.IsNullOrEmpty(aic.IATA) && (fAllowBlast || aic.IATAMatch == null);
        ((Button)row.FindControl("btnAddICAO")).Visible = !String.IsNullOrEmpty(aic.ICAO) && (fAllowBlast || aic.ICAOMatch == null);

        // don't offer to fix distances over maxDistanceToFix, to avoid accidentally stomping on airports somewhere else in the world.
        const double maxDistanceToFix = 50.0;

        ((Button)row.FindControl("btnFixLocationFAA")).Visible  = (aic.FAAMatch != null && aic.MatchStatusFAA == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.FAAMatch) < maxDistanceToFix);
        ((Button)row.FindControl("btnFixLocationIATA")).Visible = (aic.IATAMatch != null && aic.MatchStatusIATA == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.IATAMatch) < maxDistanceToFix);
        ((Button)row.FindControl("btnFixLocationICAO")).Visible = (aic.ICAOMatch != null && aic.MatchStatusICAO == airportImportCandidate.MatchStatus.InDBWrongLocation && aic.DistanceFromAirport(aic.ICAOMatch) < maxDistanceToFix);

        // And don't offer to fix type if that's not the error
        ((Button)row.FindControl("btnFixTypeFAA")).Visible  = (aic.FAAMatch != null && aic.MatchStatusFAA == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.FAAMatch) < maxDistanceToFix);
        ((Button)row.FindControl("btnFixTypeIATA")).Visible = (aic.IATAMatch != null && aic.MatchStatusIATA == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.IATAMatch) < maxDistanceToFix);
        ((Button)row.FindControl("btnFixTypeICAO")).Visible = (aic.ICAOMatch != null && aic.MatchStatusICAO == airportImportCandidate.MatchStatus.WrongType && aic.DistanceFromAirport(aic.ICAOMatch) < maxDistanceToFix);

        // And don't offer to fix type if that's not the error
        ((Button)row.FindControl("btnOverwriteFAA")).Visible  = aic.FAAMatch != null && (aic.MatchStatusFAA == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.FAAMatch) >= maxDistanceToFix);
        ((Button)row.FindControl("btnOverwriteIATA")).Visible = aic.IATAMatch != null && (aic.MatchStatusIATA == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.IATAMatch) >= maxDistanceToFix);
        ((Button)row.FindControl("btnOverwriteICAO")).Visible = aic.ICAOMatch != null && (aic.MatchStatusICAO == airportImportCandidate.MatchStatus.WrongType || aic.DistanceFromAirport(aic.ICAOMatch) >= maxDistanceToFix);
    }
    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();
    }
Beispiel #8
0
    protected void btnImport_Click(object sender, EventArgs e)
    {
        if (!fileUploadAirportList.HasFile)
        {
            return;
        }

        if (!ckShowAllUserAirports.Checked)
        {
            gvMyAirports.DataSource = null;
            gvMyAirports.DataBind();
        }

        ImportContext ic = new ImportContext();

        using (CSVReader csvReader = new CSVReader(fileUploadAirportList.FileContent))
        {
            try
            {
                ic.InitFromHeader(csvReader.GetCSVLine(true));
            }
            catch (CSVReaderInvalidCSVException ex)
            {
                lblUploadErr.Text = ex.Message;
                return;
            }
            catch (MyFlightbookException ex)
            {
                lblUploadErr.Text = ex.Message;
                return;
            }

            List <airportImportCandidate> lst = ImportedAirportCandidates;
            lst.Clear();
            string[] rgCols = null;

            while ((rgCols = csvReader.GetCSVLine()) != null)
            {
                airportImportCandidate aic = new airportImportCandidate();
                aic.FAA              = GetCol(rgCols, ic.iColFAA).Replace("-", "");
                aic.IATA             = GetCol(rgCols, ic.iColIATA).Replace("-", "");
                aic.ICAO             = GetCol(rgCols, ic.iColICAO).Replace("-", "");
                aic.Name             = GetCol(rgCols, ic.iColName);
                aic.FacilityTypeCode = GetCol(rgCols, ic.iColType);
                if (String.IsNullOrEmpty(aic.FacilityTypeCode))
                {
                    aic.FacilityTypeCode = "A";     // default to airport
                }
                aic.Name = GetCol(rgCols, ic.iColName);
                aic.Code = "(TBD)";
                string szLat     = GetCol(rgCols, ic.iColLatitude);
                string szLon     = GetCol(rgCols, ic.iColLongitude);
                string szLatLong = GetCol(rgCols, ic.iColLatLong);
                aic.LatLong = null;

                if (!String.IsNullOrEmpty(szLatLong))
                {
                    // see if it is decimal; if so, we'll fall through.
                    if (Regex.IsMatch(szLatLong, "[NEWS]", RegexOptions.IgnoreCase))
                    {
                        aic.LatLong = DMSAngle.LatLonFromDMSString(GetCol(rgCols, ic.iColLatLong));
                    }
                    else
                    {
                        string[] rgsz = szLatLong.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (rgsz.Length == 2)
                        {
                            szLat = rgsz[0];
                            szLon = rgsz[1];
                        }
                    }
                }
                if (aic.LatLong == null)
                {
                    aic.LatLong = new LatLong();
                    double d;
                    if (double.TryParse(szLat, out d))
                    {
                        aic.LatLong.Latitude = d;
                    }
                    else
                    {
                        aic.LatLong.Latitude = new DMSAngle(szLat).Value;
                    }

                    if (double.TryParse(szLon, out d))
                    {
                        aic.LatLong.Longitude = d;
                    }
                    else
                    {
                        aic.LatLong.Longitude = new DMSAngle(szLon).Value;
                    }
                }

                lst.Add(aic);
            }

            UpdateCandidateStatus(lst);

            bool fHideKHack = util.GetIntParam(Request, "khack", 0) == 0;
            lst.RemoveAll(aic => aic.IsOK || (fHideKHack && aic.IsKHack));

            gvImportResults.DataSource = lst;
            gvImportResults.DataBind();
            pnlImportResults.Visible = true;
        }
    }
Beispiel #9
0
 protected static void SetUpImportButtons(Control row, airportImportCandidate aic, bool fAllowBlast)
 {
     SetUpAddButtons(row, aic, fAllowBlast);
     SetUpLocationButtons(row, aic);
     SetUpFixButtons(row, aic);
 }
        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);
        }