Beispiel #1
0
        void LoadDayAndNightCurrency()
        {
            if (LogBook.Pilot.Endorsements.HasFlag(AircraftEndorsement.TailDragger))
            {
                var list         = LogBook.GetAircraft(AircraftCategory.Airplane, false);
                var taildraggers = new List <Aircraft> ();

                foreach (var aircraft in list)
                {
                    if (aircraft.IsTailDragger)
                    {
                        taildraggers.Add(aircraft);
                    }
                }

                var section = new Section("Taildragger Currency");
                AddLandingCurrency(section, taildraggers, false);
                AddLandingCurrency(section, taildraggers, true);
                Root.Add(section);
            }

            // Day/Night currency is per-AircraftClassification
            foreach (AircraftClassification @class in Enum.GetValues(typeof(AircraftClassification)))
            {
                AircraftCategory    category = Aircraft.GetCategoryFromClass(@class);
                AircraftEndorsement endorsement;

                if (!Enum.TryParse <AircraftEndorsement> (@class.ToString(), out endorsement))
                {
                    continue;
                }

                if (!LogBook.Pilot.Endorsements.HasFlag(endorsement))
                {
                    continue;
                }

                var    list = LogBook.GetAircraft(@class, false);
                string caption;

                if (category == AircraftCategory.Airplane)
                {
                    caption = "Airplane " + @class.ToHumanReadableName();
                }
                else
                {
                    caption = @class.ToHumanReadableName();
                }

                var section = new Section(string.Format("{0} Currency", caption));
                AddLandingCurrency(section, list, false);
                AddLandingCurrency(section, list, true);
                Root.Add(section);
            }
        }
        void LoadDayAndNightCurrency()
        {
            // Day/Night currency is per-AircraftClassification and TailDragger vs not.
            foreach (var value in Enum.GetValues(typeof(AircraftClassification)))
            {
                AircraftClassification @class = (AircraftClassification)value;

                List <Aircraft> list = LogBook.GetAircraft(@class, false);
                if (list == null || list.Count == 0)
                {
                    continue;
                }

                AircraftCategory category = Aircraft.GetCategoryFromClass(@class);
                Section          section;
                string           caption;

                if (category == AircraftCategory.Airplane)
                {
                    caption = string.Format("{0} {1}", category.ToHumanReadableName(), @class.ToHumanReadableName());
                }
                else
                {
                    caption = @class.ToHumanReadableName();
                }

                section = new Section(caption);

                // Only Airplanes can be tail-draggers
                if (category == AircraftCategory.Airplane)
                {
                    List <Aircraft> taildraggers = new List <Aircraft> ();
                    foreach (var aircraft in list)
                    {
                        if (aircraft.IsTailDragger)
                        {
                            taildraggers.Add(aircraft);
                        }
                    }

                    if (taildraggers.Count > 0)
                    {
                        AddLandingCurrency(section, taildraggers, @class, false, true);
                        AddLandingCurrency(section, taildraggers, @class, true, true);
                    }
                }

                AddLandingCurrency(section, list, @class, false, false);
                AddLandingCurrency(section, list, @class, true, false);

                Root.Add(section);
            }
        }
Beispiel #3
0
        void LoadFlightTimeTotals()
        {
            var totals          = new List <Totals> ();
            var twelveMonthsAgo = GetMonthsAgo(12);
            var sixMonthsAgo    = GetMonthsAgo(6);
            Dictionary <string, Aircraft> dict;
            Aircraft aircraft;
            int      time;

            dict = new Dictionary <string, Aircraft> ();
            foreach (var craft in LogBook.GetAllAircraft())
            {
                dict.Add(craft.TailNumber, craft);
            }

            totals.Add(new Totals("Flight Time Totals", FlightProperty.FlightTime));
            totals.Add(new Totals("Pilot-in-Command Totals", FlightProperty.PilotInCommand));
            totals.Add(new Totals("Certified Flight Instructor Totals", FlightProperty.CertifiedFlightInstructor));
            totals.Add(new Totals("Cross-Country Totals", FlightProperty.CrossCountry));
            totals.Add(new Totals("Cross-Country (PIC) Totals", FlightProperty.CrossCountryPIC));
            totals.Add(new Totals("Night Totals", FlightProperty.Night));
            totals.Add(new Totals("Instrument (Actual) Totals", FlightProperty.InstrumentActual));
            totals.Add(new Totals("Instrument (Hood) Totals", FlightProperty.InstrumentHood));

            if (LogBook.Pilot.Endorsements.HasFlag(AircraftEndorsement.Complex))
            {
                totals.Add(new Totals("Complex Totals", AircraftProperty.IsComplex));
            }
            if (LogBook.Pilot.Endorsements.HasFlag(AircraftEndorsement.HighPerformance))
            {
                totals.Add(new Totals("High-Performance Totals", AircraftProperty.IsHighPerformance));
            }
            if (LogBook.Pilot.Endorsements.HasFlag(AircraftEndorsement.TailDragger))
            {
                totals.Add(new Totals("Taildragger Totals", AircraftProperty.IsTailDragger));
            }

            foreach (AircraftClassification @class in Enum.GetValues(typeof(AircraftClassification)))
            {
                AircraftCategory category = Aircraft.GetCategoryFromClass(@class);
                string           title    = @class.ToHumanReadableName() + " Totals";

                if (category == AircraftCategory.Airplane)
                {
                    title = "Airplane " + title;
                }

                totals.Add(new Totals(title, @class));
            }

            foreach (var flight in LogBook.GetAllFlights())
            {
                if (!dict.TryGetValue(flight.Aircraft, out aircraft))
                {
                    continue;
                }

                if (aircraft.IsSimulator)
                {
                    continue;
                }

                foreach (var total in totals)
                {
                    if (total.Property is FlightProperty)
                    {
                        time = flight.GetFlightTime((FlightProperty)total.Property);
                    }
                    else if (total.Property is AircraftProperty)
                    {
                        if (!((bool)aircraft.GetValue((AircraftProperty)total.Property)))
                        {
                            continue;
                        }

                        time = flight.FlightTime;
                    }
                    else
                    {
                        if (aircraft.Classification != (AircraftClassification)total.Property)
                        {
                            continue;
                        }

                        time = flight.FlightTime;
                    }

                    if (flight.Date >= sixMonthsAgo)
                    {
                        total.Last12Months += time;
                        total.Last6Months  += time;
                    }
                    else if (flight.Date >= twelveMonthsAgo)
                    {
                        total.Last12Months += time;
                    }

                    total.Total += time;
                }
            }

            var aircraftTotals = new RootElement("By Aircraft Category...");
            var otherTotals    = new RootElement("Other Totals");

            for (int i = 1; i < totals.Count; i++)
            {
                if (totals[i].Total == 0)
                {
                    continue;
                }

                if (totals[i].Property is FlightProperty)
                {
                    otherTotals.Add(new Section(totals[i].Title)
                    {
                        new StringElement("Total", FlightExtension.FormatFlightTime(totals[i].Total, true)),
                        new StringElement("12 Months", FlightExtension.FormatFlightTime(totals[i].Last12Months, true)),
                        new StringElement("6 Months", FlightExtension.FormatFlightTime(totals[i].Last6Months, true)),
                    });
                }
                else
                {
                    aircraftTotals.Add(new Section(totals[i].Title)
                    {
                        new StringElement("Total", FlightExtension.FormatFlightTime(totals[i].Total, true)),
                        new StringElement("12 Months", FlightExtension.FormatFlightTime(totals[i].Last12Months, true)),
                        new StringElement("6 Months", FlightExtension.FormatFlightTime(totals[i].Last6Months, true)),
                    });
                }
            }

            Root.Add(new Section(totals[0].Title)
            {
                new StringElement("Total", FlightExtension.FormatFlightTime(totals[0].Total, true)),
                new StringElement("12 Months", FlightExtension.FormatFlightTime(totals[0].Last12Months, true)),
                new StringElement("6 Months", FlightExtension.FormatFlightTime(totals[0].Last6Months, true)),
                aircraftTotals,
                otherTotals
            });
        }