Ejemplo n.º 1
0
        void LoadFlightLog()
        {
            int           year    = Int32.MaxValue;
            Section       section = null;
            FlightElement element;

            foreach (var flight in LogBook.GetAllFlights())
            {
                if (flight.Date.Year != year)
                {
                    year    = flight.Date.Year;
                    section = new YearSection(year);
                    Root.Add(section);
                }

                element          = new FlightElement(flight);
                element.Changed += OnFlightElementChanged;
                section.Add(element);
            }

            LogBook.FlightAdded += OnFlightAdded;
        }
Ejemplo n.º 2
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
            });
        }