Esempio n. 1
0
    protected void btnMigrateSim_Click(object sender, EventArgs e)
    {
        Aircraft acOriginal = new Aircraft(MfbEditAircraft1.AircraftID);

        if (!CouldBeSim(acOriginal))
        {
            lblErr.Text = Resources.Aircraft.AdminNotASim;
            return;
        }

        // detect likely sim type
        AircraftInstanceTypes ait = PseudoSimTypeFromTail(acOriginal.TailNumber);

        // see if the specified sim exists
        string   szSimTail = Aircraft.SuggestSims(acOriginal.ModelID, ait)[0].TailNumber;
        Aircraft acNew     = new Aircraft(szSimTail);

        if (acNew.IsNew)
        {
            acNew.TailNumber   = szSimTail;
            acNew.ModelID      = acOriginal.ModelID;
            acNew.InstanceType = ait;
            acNew.Commit();
        }

        // set the original's instance type so that merge works.
        acOriginal.InstanceType = ait;
        AircraftUtility.AdminMergeDupeAircraft(acNew, acOriginal);
        Response.Redirect(Request.Url.PathAndQuery.Replace(String.Format(CultureInfo.InvariantCulture, "id={0}", acOriginal.AircraftID), String.Format(CultureInfo.InvariantCulture, "id={0}", acNew.AircraftID)));
    }
        protected void ValidateSim(object sender, ServerValidateEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            CountryCodePrefix     cc  = CountryCodePrefix.BestMatchCountryCode(txtTail.Text);
            AircraftInstanceTypes ait = SelectedInstanceType;

            if (ait == AircraftInstanceTypes.RealAircraft && cc.IsSim)
            {
                args.IsValid = false;
            }

            if (ait != AircraftInstanceTypes.RealAircraft && !cc.IsSim)
            {
                args.IsValid = false;
            }
        }
        private static Dictionary <string, VisitedAirport> PopulateAirports(DBHelperCommandArgs commandArgs)
        {
            Dictionary <string, VisitedAirport> dictVA = new Dictionary <string, VisitedAirport>();

            DBHelper dbh = new DBHelper(commandArgs);

            dbh.ReadRows(
                (comm) => { },
                (dr) =>
            {
                // ignore anything not in a real aircraft.
                AircraftInstanceTypes instanceType = (AircraftInstanceTypes)Convert.ToInt32(dr["InstanceType"], CultureInfo.InvariantCulture);
                if (instanceType != AircraftInstanceTypes.RealAircraft)
                {
                    return;
                }

                DateTime dtFlight = Convert.ToDateTime(dr["date"], CultureInfo.InvariantCulture);
                string szRoute    = dr["route"].ToString();
                int idFlight      = Convert.ToInt32(dr["idflight"], CultureInfo.InvariantCulture);

                decimal total = Convert.ToDecimal(util.ReadNullableField(dr, "totalFlightTime", 0.0M), CultureInfo.InvariantCulture);
                decimal PIC   = Convert.ToDecimal(util.ReadNullableField(dr, "PIC", 0.0M), CultureInfo.InvariantCulture);
                decimal SIC   = Convert.ToDecimal(util.ReadNullableField(dr, "SIC", 0.0M), CultureInfo.InvariantCulture);
                decimal CFI   = Convert.ToDecimal(util.ReadNullableField(dr, "CFI", 0.0M), CultureInfo.InvariantCulture);
                decimal Dual  = Convert.ToDecimal(util.ReadNullableField(dr, "dualReceived", 0.0M), CultureInfo.InvariantCulture);

                // ignore any flight with no time logged.
                if (total + PIC + SIC + CFI + Dual == 0)
                {
                    return;
                }

                // we want to defer any db hit to the airport list until later, so we create an uninitialized airportlist
                // We then visit each airport in the flight.
                string[] rgszapFlight = AirportList.NormalizeAirportList(szRoute);

                for (int iAp = 0; iAp < rgszapFlight.Length; iAp++)
                {
                    string szap = rgszapFlight[iAp].ToUpperInvariant();

                    // If it's explicitly a navaid, ignore it
                    if (szap.StartsWith(airport.ForceNavaidPrefix, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    VisitedAirport va = dictVA.ContainsKey(szap) ? dictVA[szap] : null;

                    // Heuristic: if the flight only has a single airport, we visit that airport
                    // BUT if the flight has multiple airport codes, ignore the first airport in the list
                    // UNLESS we've never seen that airport before.  (E.g., fly commercial to Stockton to pick up 40FG).
                    if (iAp == 0 && va != null && rgszapFlight.Length > 1)
                    {
                        continue;
                    }

                    // for now, the key holds the airport code, since the airport itself within the visited airport is still null
                    if (va == null)
                    {
                        dictVA[szap] = va = new VisitedAirport(dtFlight)
                        {
                            FlightIDOfFirstVisit = idFlight
                        }
                    }
                    ;
                    else
                    {
                        va.VisitAirport(dtFlight, idFlight);
                    }
                }
            });

            return(dictVA);
        }