Esempio n. 1
0
        static void AddInstrumentCurrency(Section section, string caption, List <Aircraft> aircraft)
        {
            DateTime oldestApproach;
            int      approaches = 0;
            int      holds      = 0;

            if (aircraft != null && aircraft.Count > 0)
            {
                foreach (var flight in LogBook.GetFlightsForInstrumentCurrencyRequirements(aircraft))
                {
                    approaches += flight.InstrumentApproaches;
                    holds      += flight.InstrumentHoldingProcedures;

                    oldestApproach = flight.Date;

                    if (approaches >= 6 && holds > 0)
                    {
                        DateTime expires = GetInstrumentCurrencyExipirationDate(oldestApproach);
                        section.Add(new CurrencyElement(caption, expires));
                        return;
                    }
                }
            }

            // currency is out of date
            section.Add(new CurrencyElement(caption, DateTime.Today));
        }
Esempio n. 2
0
        void AddLandingCurrency(Section section, List <Aircraft> list, AircraftClassification @class, bool night, bool tailDragger)
        {
            string   caption       = string.Format("{0} Current{1}", night ? "Night" : "Day", tailDragger ? " (TailDragger)" : "");
            DateTime oldestLanding = DateTime.Now;
            int      landings      = 0;

            foreach (var flight in LogBook.GetFlightsForPassengerCurrencyRequirements(list, night))
            {
                landings += flight.NightLandings;

                if (!night)
                {
                    landings += flight.DayLandings;
                }

                oldestLanding = flight.Date;

                if (landings >= 3)
                {
                    section.Add(new CurrencyElement(caption, oldestLanding.AddDays(90)));
                    return;
                }
            }

            // currency is out of date
            section.Add(new CurrencyElement(caption, DateTime.Now));
        }
Esempio n. 3
0
        void LoadInstrumentCurrency()
        {
            var             section = new Section("Instrument Currency");
            List <Aircraft> list;

            // Instrument currency is per-AircraftCategory
            if (LogBook.Pilot.InstrumentRatings.HasFlag(InstrumentRating.Airplane))
            {
                list = LogBook.GetAircraft(AircraftCategory.Airplane, false);
                AddInstrumentCurrency(section, "Airplane", list);
            }

            if (LogBook.Pilot.InstrumentRatings.HasFlag(InstrumentRating.Helicopter))
            {
                list = LogBook.GetAircraft(AircraftClassification.Helicoptor, false);
                AddInstrumentCurrency(section, "Helicopter", list);
            }

            if (LogBook.Pilot.InstrumentRatings.HasFlag(InstrumentRating.PoweredLift))
            {
                list = LogBook.GetAircraft(AircraftClassification.PoweredLift, false);
                AddInstrumentCurrency(section, "Powered-Lift", list);
            }

            if (section.Count > 0)
            {
                Root.Add(section);
            }
        }
Esempio n. 4
0
        static void AddLandingCurrency(Section section, List <Aircraft> aircraft, bool night)
        {
            string   caption = string.Format("{0} Current", night ? "Night" : "Day");
            DateTime oldestLanding;
            int      landings = 0;

            if (aircraft != null && aircraft.Count > 0)
            {
                foreach (var flight in LogBook.GetFlightsForPassengerCurrencyRequirements(aircraft, night))
                {
                    landings += flight.NightLandings;

                    if (!night)
                    {
                        landings += flight.DayLandings;
                    }

                    oldestLanding = flight.Date;

                    if (landings >= 3)
                    {
                        section.Add(new CurrencyElement(caption, oldestLanding.AddDays(90)));
                        return;
                    }
                }
            }

            // currency is out of date
            section.Add(new CurrencyElement(caption, DateTime.Now));
        }
Esempio n. 5
0
        public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
        {
            var model    = ModelForTableView(tableView);
            var aircraft = model.GetItem(indexPath.Section, indexPath.Row);

            return(LogBook.CanDelete(aircraft));
        }
Esempio n. 6
0
        void OnSaveClicked(object sender, EventArgs args)
        {
            FetchValues();

            // Don't let the user save if the info is incomplete
            if (aircraft.Value == null || aircraft.Value.Length < 2)
            {
                return;
            }

            // Save the values back to the Flight record
            Flight.Date            = date.DateValue;
            Flight.Aircraft        = aircraft.Value;
            Flight.AirportDeparted = departed.Value;
            Flight.AirportVisited1 = visited1.Value;
            Flight.AirportVisited2 = visited2.Value;
            Flight.AirportVisited3 = visited3.Value;
            Flight.AirportArrived  = arrived.Value;

            if (Flight.AirportArrived == null)
            {
                Flight.AirportArrived = Flight.AirportDeparted;
            }

            // Flight Time values
            Flight.FlightTime = total.ValueAsSeconds;
            Flight.CertifiedFlightInstructor = cfi.ValueAsSeconds;
            Flight.InstrumentSimulator       = simulator.ValueAsSeconds;
            Flight.InstrumentActual          = actual.ValueAsSeconds;
            Flight.InstrumentHood            = hood.ValueAsSeconds;
            Flight.SecondInCommand           = sic.ValueAsSeconds;
            Flight.PilotInCommand            = pic.ValueAsSeconds;
            Flight.DualReceived = dual.ValueAsSeconds;
            Flight.CrossCountry = xc.ValueAsSeconds;
            Flight.Night        = night.ValueAsSeconds;

            Flight.Day = Flight.FlightTime - Flight.Night;

            // Landings and Approaches
            Flight.InstrumentApproaches = approaches.Value;
            Flight.NightLandings        = landNight.Value;
            Flight.DayLandings          = landDay.Value;

            // Remarks
            Flight.Remarks = remarks.Value;

            if (exists)
            {
                LogBook.Update(Flight);
            }
            else
            {
                LogBook.Add(Flight);
            }

            NavigationController.PopViewControllerAnimated(true);

            OnEditorClosed();
        }
Esempio n. 7
0
        /// <summary>
        /// This is the main entry point of the application.
        /// </summary>
        static void Main(string[] args)
        {
            Airports.Init();
            LogBook.Init();

            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main(args, null, "AppDelegate");
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
        void OnSaveClicked(object sender, EventArgs args)
        {
            if (profile.TailNumber == null || profile.TailNumber.Length < 2)
            {
                return;
            }

            if (profile.Photograph != null)
            {
                UIImage thumbnail;
                NSError error;

                if (!PhotoManager.Save(profile.TailNumber, profile.Photograph, false, out error))
                {
                    var alert = new UIAlertView("Error", error.LocalizedDescription, null, "Dismiss", null);
                    alert.Show();
                    return;
                }

                thumbnail = PhotoManager.ScaleToSize(profile.Photograph, 96, 72);
                PhotoManager.Save(profile.TailNumber, thumbnail, true, out error);
                // Note: we don't dispose the thumbnail because it has been added to the cache.
                thumbnail = null;
            }

            // Save the values back to the Aircraft object
            Aircraft.TailNumber        = profile.TailNumber;
            Aircraft.Make              = profile.Make;
            Aircraft.Model             = profile.Model;
            Aircraft.Classification    = ClassificationFromIndexes(category.RadioSelected, classes.Selected);
            Aircraft.IsComplex         = isComplex.Value;
            Aircraft.IsHighPerformance = isHighPerformance.Value;
            Aircraft.IsTailDragger     = isTailDragger.Value;
            Aircraft.IsSimulator       = isSimulator.Value;
            Aircraft.Notes             = notes.Value;

            // We'll treat this as a special case for now...
            if (Aircraft.Make == null && Aircraft.IsSimulator)
            {
                Aircraft.Make = "Simulator";
            }

            if (exists)
            {
                LogBook.Update(Aircraft);
            }
            else
            {
                LogBook.Add(Aircraft);
            }

            NavigationController.PopViewControllerAnimated(true);

            OnEditorClosed();
        }
Esempio n. 10
0
        static int GetFlightTime(Aircraft aircraft)
        {
            int total = 0;

            foreach (Flight flight in LogBook.GetFlights(aircraft))
            {
                total += flight.FlightTime;
            }

            return(total);
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        void OnElementDeleted(object sender, ElementEventArgs args)
        {
            AircraftElement deleted = args.Element as AircraftElement;
            NSIndexPath     path    = deleted.IndexPath;

            if (LogBook.Delete(deleted.Aircraft))
            {
                deleted.Changed -= OnElementChanged;
                Root[0].Remove(path.Row);
                SelectOrAdd(path.Row);
            }
        }
Esempio n. 13
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Default to the region for North America
            double minLatitude  = 37.37 - (28.49 / 2);
            double maxLatitude  = 37.37 + (28.49 / 2);
            double minLongitide = -96.24 - (31.025 / 2);
            double maxLongitude = -96.24 + (31.025 / 2);
            bool   initialized  = false;

            foreach (var code in LogBook.GetVisitedAirports())
            {
                Airport airport = Airports.GetAirport(code, AirportCode.FAA);
                if (airport == null)
                {
                    continue;
                }

                if (!initialized)
                {
                    minLongitide = maxLongitude = airport.Longitude;
                    minLatitude  = maxLatitude = airport.Latitude;
                    initialized  = true;
                }
                else
                {
                    minLongitide = Math.Min(minLongitide, airport.Longitude);
                    maxLongitude = Math.Max(maxLongitude, airport.Longitude);
                    minLatitude  = Math.Min(minLatitude, airport.Latitude);
                    maxLatitude  = Math.Max(maxLatitude, airport.Latitude);
                }
            }

            coordinates = new CLLocationCoordinate2D((minLatitude + maxLatitude) / 2, (minLongitide + maxLongitude) / 2);
            double spanLongitude = Math.Abs(maxLongitude - minLongitide);
            double spanLatitude  = Math.Abs(maxLatitude - minLatitude);

            if (initialized)
            {
                spanLongitude = Math.Max(spanLongitude, 1.0) * 1.25;
                spanLatitude  = Math.Max(spanLatitude, 1.0) * 1.25;
            }

            // Get the region for North America
            var region = new MKCoordinateRegion(
                coordinates, new MKCoordinateSpan(spanLatitude, spanLongitude)
                );

            mapView.SetRegion(region, animated);
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (aircraft == null)
            {
                List <Aircraft> list = LogBook.GetAircraft(1);
                aircraft = list != null && list.Count > 0 ? list[0] : null;
            }

            if (aircraft != null)
            {
                UpdateDetails();
            }
        }
Esempio n. 15
0
        void SaveAndClose()
        {
            if (exists)
            {
                LogBook.Update(Flight);
            }
            else
            {
                LogBook.Add(Flight);
            }

            NavigationController.PopViewControllerAnimated(true);

            OnEditorClosed();
        }
Esempio n. 16
0
        void LoadAircraft()
        {
            Section         section = new Section();
            AircraftElement element;

            foreach (var aircraft in LogBook.GetAllAircraft())
            {
                element          = new AircraftElement(aircraft);
                element.Changed += OnElementChanged;
                section.Add(element);
            }

            Root.Add(section);

            LogBook.AircraftAdded += OnAircraftAdded;
        }
Esempio n. 17
0
        public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            if (editingStyle != UITableViewCellEditingStyle.Delete)
            {
                return;
            }

            Aircraft aircraft = GetItem(tableView, indexPath);

            if (!LogBook.Delete(aircraft))
            {
                return;
            }

            OnAircraftDeleted(tableView, indexPath);
        }
Esempio n. 18
0
        void LoadInstrumentCurrency()
        {
            // Instrument currency is per-AircraftCategory
            foreach (var value in Enum.GetValues(typeof(AircraftCategory)))
            {
                AircraftCategory category = (AircraftCategory)value;
                List <Aircraft>  list     = LogBook.GetAircraft(category, false);
                if (list == null || list.Count == 0)
                {
                    continue;
                }

                Section section = new Section(category.ToHumanReadableName());
                AddInstrumentCurrency(section, list, category);
                Root.Add(section);
            }
        }
Esempio n. 19
0
        void OnElementDeleted(object sender, ElementEventArgs args)
        {
            FlightElement deleted = args.Element as FlightElement;
            NSIndexPath   path    = deleted.IndexPath;
            int           n       = GetElementOffsetFromPath(path);

            if (LogBook.Delete(deleted.Flight))
            {
                deleted.Changed -= OnFlightElementChanged;
                Root[path.Section].Remove(path.Row);
                if (Root[path.Section].Count == 0)
                {
                    Root.RemoveAt(path.Section, UITableViewRowAnimation.Fade);
                }

                SelectOrAdd(n);
            }
        }
Esempio n. 20
0
        void AddInstrumentCurrency(Section section, List <Aircraft> list, AircraftCategory category)
        {
            string   caption        = "Instrument Current";
            DateTime oldestApproach = DateTime.Now;
            int      approaches     = 0;

            foreach (var flight in LogBook.GetFlightsForInstrumentCurrencyRequirements(list))
            {
                approaches    += flight.InstrumentApproaches;
                oldestApproach = flight.Date;

                if (approaches >= 6)
                {
                    DateTime expires = GetInstrumentCurrencyExipirationDate(oldestApproach);
                    section.Add(new CurrencyElement(caption, expires));
                    return;
                }
            }

            // currency is out of date
            section.Add(new CurrencyElement(caption, DateTime.Now));
        }
Esempio n. 21
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;
        }
Esempio n. 22
0
        IEnumerable <Airport> GetAirports(MKCoordinateRegion region)
        {
            if (visited)
            {
                foreach (var code in LogBook.GetVisitedAirports())
                {
                    Airport airport = Airports.GetAirport(code, AirportCode.FAA);
                    if (airport != null)
                    {
                        yield return(airport);
                    }
                }
            }
            else
            {
                foreach (var airport in Airports.GetAirports(region))
                {
                    yield return(airport);
                }
            }

            yield break;
        }
Esempio n. 23
0
        void OnFlightTimeEntered(object sender, EventArgs e)
        {
            int seconds = total.ValueAsSeconds;

            if (autoFlightTimes)
            {
                if (certification == PilotCertification.Student)
                {
                    dual.ValueAsSeconds = seconds;
                }
                else
                {
                    pic.ValueAsSeconds = seconds;
                }

                var    craft    = LogBook.GetAircraft(aircraft.Value);
                double minimum  = GetMinimumCrossCountryDistance(craft);
                var    airports = GetAirports();

                if (airports != null && IsCrossCountry(airports, minimum))
                {
                    xc.ValueAsSeconds = seconds;
                }
            }

            // Cap the time limit for each of the time-based entry elements to the total time.
            simulator.MaxValueAsSeconds = seconds;
            actual.MaxValueAsSeconds    = seconds;
            hood.MaxValueAsSeconds      = seconds;
            night.MaxValueAsSeconds     = seconds;
            dual.MaxValueAsSeconds      = seconds;
            cfi.MaxValueAsSeconds       = seconds;
            pic.MaxValueAsSeconds       = seconds;
            sic.MaxValueAsSeconds       = seconds;
            xc.MaxValueAsSeconds        = seconds;
        }
Esempio n. 24
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
            });
        }
Esempio n. 25
0
        void OnSaveClicked(object sender, EventArgs args)
        {
            FetchValues();

            // Don't let the user save if the info is incomplete
            if (aircraft.Value == null || aircraft.Value.Length < 2)
            {
                return;
            }

            // We need at least a departure airport
            var    missing  = new HashSet <string> ();
            var    airports = new List <Airport> ();
            var    via      = new List <string> ();
            string code;

            if ((code = GetAirportCode(departed.Value, airports, missing)) == null)
            {
                return;
            }

            // Save the values back to the Flight record
            Flight.AirportDeparted = code;

            foreach (var airport in visited)
            {
                if (string.IsNullOrEmpty(airport.Value))
                {
                    continue;
                }

                code = GetAirportCode(airport.Value, airports, missing);
                via.Add(code);
            }

            if (via.Count > 0)
            {
                Flight.AirportVisited = string.Join(", ", via);
            }
            else
            {
                Flight.AirportVisited = null;
            }

            Flight.AirportArrived = GetAirportCode(arrived.Value, airports, missing);
            if (Flight.AirportArrived == null)
            {
                Flight.AirportArrived = Flight.AirportDeparted;
            }

            Flight.Date     = date.DateValue;
            Flight.Aircraft = aircraft.Value;

            // Flight Time values
            Flight.FlightTime = total.ValueAsSeconds;
            Flight.CertifiedFlightInstructor = cfi.ValueAsSeconds;
            Flight.SecondInCommand           = sic.ValueAsSeconds;
            Flight.PilotInCommand            = pic.ValueAsSeconds;
            Flight.DualReceived = dual.ValueAsSeconds;
            Flight.CrossCountry = xc.ValueAsSeconds;
            Flight.Night        = night.ValueAsSeconds;

            // Landings
            Flight.NightLandings = landNight.Value;
            Flight.DayLandings   = landDay.Value;

            // Flight Time values
            Flight.InstrumentSimulator = simulator.ValueAsSeconds;
            Flight.InstrumentActual    = actual.ValueAsSeconds;
            Flight.InstrumentHood      = hood.ValueAsSeconds;

            // Holding Procedures and Approaches
            Flight.InstrumentHoldingProcedures = holds.Value;
            Flight.InstrumentApproaches        = approaches.Value;

            // Safety Pilot info
            Flight.InstrumentSafetyPilot = safetyPilot.Value;

            if (Flight.InstrumentSimulator == 0)
            {
                Flight.Day = Flight.FlightTime - Flight.Night;
            }
            else
            {
                Flight.Day = 0;
            }

            // Remarks
            Flight.Remarks = remarks.Value;

            // Verify that the flight was really cross-country.
            var    craft   = LogBook.GetAircraft(Flight.Aircraft);
            double minimum = GetMinimumCrossCountryDistance(craft);

            if (Flight.CrossCountry > 0 && !IsCrossCountry(airports, minimum))
            {
                ShowCrossCountryAlert(craft, Flight.AirportDeparted, missing, minimum);
                return;
            }

            SaveAndClose();
        }
Esempio n. 26
0
        void Save()
        {
            var  cert         = (PilotCertification)certification.RadioSelected;
            var  endorsements = AircraftEndorsement.None;
            var  ratings      = InstrumentRating.None;
            bool changed      = false;
            int  flag         = 1 << 0;

            foreach (var section in this.endorsements)
            {
                foreach (var element in section)
                {
                    if (((BooleanElement)element).Value)
                    {
                        endorsements |= (AircraftEndorsement)flag;
                    }

                    flag <<= 1;
                }
            }

            if (aifr.Value)
            {
                ratings |= InstrumentRating.Airplane;
            }
            if (hifr.Value)
            {
                ratings |= InstrumentRating.Helicopter;
            }
            if (lifr.Value)
            {
                ratings |= InstrumentRating.PoweredLift;
            }

            if (Pilot.Certification != cert)
            {
                Pilot.Certification = cert;
                changed             = true;
            }

            if (Pilot.Endorsements != endorsements)
            {
                Pilot.Endorsements = endorsements;
                changed            = true;
            }

            if (Pilot.IsCertifiedFlightInstructor != cfi.Value)
            {
                Pilot.IsCertifiedFlightInstructor = cfi.Value;
                changed = true;
            }

            if (Pilot.InstrumentRatings != ratings)
            {
                Pilot.InstrumentRatings = ratings;
                changed = true;
            }

            if (Pilot.BirthDate != birthday.DateValue)
            {
                Pilot.BirthDate = birthday.DateValue;
                changed         = true;
            }

            if (Pilot.Name != name.Value)
            {
                Pilot.Name = name.Value;
                changed    = true;
            }

            if (Pilot.LastMedicalExam != medical.DateValue)
            {
                Pilot.LastMedicalExam = medical.DateValue;
                changed = true;
            }

            if (Pilot.LastFlightReview != review.DateValue)
            {
                Pilot.LastFlightReview = review.DateValue;
                changed = true;
            }

            if (changed)
            {
                LogBook.Update(Pilot);
            }
        }
Esempio n. 27
0
        protected override bool AllowTextChange(string currentText, NSRange changedRange, string replacementText, string result)
        {
            if (result.Length == 0)
            {
                return(true);
            }

            // If the user backspaced, allow the change to go through.
            if (replacementText.Length == 0)
            {
                if (autocompleted)
                {
                    // If we've auto-completed and the user backspaces, then he/she is probably entering a name we haven't seen before.
                    backspaced = true;
                }

                return(true);
            }

            for (int i = 0; i < replacementText.Length; i++)
            {
                if (replacementText[i] == '%' || replacementText[i] == '*')
                {
                    return(false);
                }
            }

            if (AutoComplete && result.Length > 0 && !backspaced)
            {
                // Try to auto-complete the safety pilot from the list of known safety pilots matching the provided text
                var matches = LogBook.GetMatchingSafetyPilots(result);

                if (matches != null)
                {
                    // If we've only got 1 match, auto-complete for the user.
                    if (matches.Count == 1)
                    {
                        autocompleted = true;
                        Value         = matches[0];
                        return(false);
                    }

                    // Figure out the maximum amount of matching text so that we can complete up to that far...
                    int maxLength = matches[0].Length;
                    for (int i = 1; i < matches.Count; i++)
                    {
                        int n;

                        for (n = 0; n < Math.Min(matches[i].Length, maxLength); n++)
                        {
                            if (matches[0][n] != matches[i][n])
                            {
                                break;
                            }
                        }

                        if (n < maxLength)
                        {
                            maxLength = n;
                        }
                    }

                    Value         = matches[0].Substring(0, maxLength);
                    autocompleted = true;
                    return(false);
                }
            }

            return(base.AllowTextChange(currentText, changedRange, replacementText, result));
        }
Esempio n. 28
0
        protected override bool AllowTextChange(string currentText, NSRange changedRange, string replacementText, string result)
        {
            int i;

            if (result.Length == 0)
            {
                return(true);
            }

            // If the user backspaced, allow the change to go through.
            if (replacementText.Length == 0)
            {
                return(true);
            }

            // Validate according to http://en.wikipedia.org/wiki/Aircraft_registration

            // First step is to validate that all characters are ASCII AlphaNumeric.
            for (i = 0; i < replacementText.Length; i++)
            {
                if ((replacementText[i] >= 'A' && replacementText[i] <= 'Z') ||
                    (replacementText[i] >= 'a' && replacementText[i] <= 'z') ||
                    (replacementText[i] >= '0' && replacementText[i] <= '9'))
                {
                    continue;
                }

                return(false);
            }

#if ENABLE_GLOBAL_SUPPORT
            // If the resulting tail number begins with a digit, make sure it is valid.
            if (result[0] >= '0' && result[0] <= '9')
            {
                bool matched = false;

                Console.WriteLine("Validating {0}...", result.ToString());
                foreach (var prefix in PrefixesStartingWithDigits)
                {
                    if (result[0] != prefix[0])
                    {
                        Console.WriteLine("0: {0} does not match {1}", result[0], prefix[0]);
                        continue;
                    }

                    if (result.Length > 1 && result[1] != prefix[1])
                    {
                        Console.WriteLine("1: {0} does not match {1}", result[1], prefix[1]);
                        continue;
                    }

                    matched = true;
                    break;
                }

                if (!matched)
                {
                    return(false);
                }
            }
#endif

            if (result.Length == 1)
            {
                return(true);
            }

            // Verify that the text length does not exceed the max length for a tail number.
            if (result.Length > GetMaxLength(result[0], result[1]))
            {
                return(false);
            }

            // If this is a U.S. tail number, verify that it doesn't contain an I or O.
            if (result[0] == 'N')
            {
                if (result.IndexOfAny(NotAllowedInTheUS) != -1)
                {
                    return(false);
                }
            }

            if (AutoComplete && result.Length > 2)
            {
                // Try to auto-complete the registration number from the database of known aircraft.
                var matches = LogBook.GetMatchingAircraft(result);

                // If we've only got 1 match, auto-complete for the user.
                if (matches != null && matches.Count == 1)
                {
                    Value = matches[0].TailNumber;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 29
0
            public override void Draw(RectangleF area)
            {
                UIColor   textColor, airportColor, aircraftColor, remarksColor;
                CGContext ctx         = UIGraphics.GetCurrentContext();
                bool      highlighted = cell.Selected;
                var       bounds      = Bounds;
                var       midx        = bounds.Width / 2;

                if (highlighted)
                {
                    UIColor.FromRGB(4, 0x79, 0xef).SetColor();
                    ctx.FillRect(bounds);
                    //Images.MenuShadow.Draw (bounds, CGBlendMode.Normal, 0.5f);
                    aircraftColor = UIColor.White;
                    airportColor  = UIColor.White;
                    remarksColor  = UIColor.White;
                    textColor     = UIColor.White;
                }
                else
                {
                    UIColor.White.SetColor();
                    ctx.FillRect(bounds);
                    ctx.DrawLinearGradient(BottomGradient, new PointF(midx, bounds.Height - 17), new PointF(midx, bounds.Height), 0);
                    ctx.DrawLinearGradient(TopGradient, new PointF(midx, 1), new PointF(midx, 3), 0);
                    aircraftColor = AircraftColor;
                    airportColor  = AirportColor;
                    remarksColor  = RemarksColor;
                    textColor     = UIColor.Black;
                }

                UIImage image = CalendarImageForDate(Flight.Date);

                image.Draw(new RectangleF(new PointF(bounds.X + ImagePadding, bounds.Y + ImagePadding), image.Size));

                float      width = bounds.Width - (ImagePadding + image.Size.Width + TextPadding * 2);
                float      x     = bounds.X + ImagePadding + image.Size.Width + TextPadding;
                float      y     = bounds.Y + AirportYOffset;
                RectangleF rect;
                SizeF      size;

                if (flight.AirportDeparted != null || flight.AirportArrived != null)
                {
                    // Render the departed airport
                    airportColor.SetColor();
                    rect = new RectangleF(x, y, width, AirportFontSize);
                    if (flight.AirportDeparted != null)
                    {
                        size = DrawString(Flight.AirportDeparted, rect, AirportFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                    }
                    else
                    {
                        size = DrawString(Flight.AirportArrived, rect, AirportFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                    }
                    width -= size.Width;
                    x     += size.Width;

                    if (flight.AirportArrived != null)
                    {
                        // Render the '-' between the departed and arrived airports
                        textColor.SetColor();
                        rect   = new RectangleF(x, y, width, AirportFontSize);
                        size   = DrawString("-", rect, AirportFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                        width -= size.Width;
                        x     += size.Width;

                        // Render the arrived airport
                        airportColor.SetColor();
                        rect   = new RectangleF(x, y, width, AirportFontSize);
                        size   = DrawString(Flight.AirportArrived, rect, AirportFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                        width -= size.Width;
                        x     += size.Width;
                    }

                    // Render any additional airports visited
                    if (flight.AirportVisited != null)
                    {
                        var visited = flight.AirportVisited.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        for (int i = 0; i < visited.Length; i++)
                        {
                            string prefix = i == 0 ? " via " : ", ";

                            textColor.SetColor();
                            rect   = new RectangleF(x, bounds.Y + ViaYOffset, width, ViaFontSize);
                            size   = DrawString(prefix, rect, ViaFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                            width -= size.Width;
                            x     += size.Width;

                            airportColor.SetColor();
                            rect   = new RectangleF(x, bounds.Y + ViaYOffset, width, ViaFontSize);
                            size   = DrawString(visited[i], rect, ViaBoldFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                            width -= size.Width;
                            x     += size.Width;
                        }
                    }
                }

                // Move down onto the next line (to render the aircraft info)
                width = bounds.Width - (ImagePadding + image.Size.Width + TextPadding * 2);
                x     = bounds.X + ImagePadding + image.Size.Width + TextPadding;
                y     = bounds.Y + AircraftYOffset;

                // Render the Aircraft tail number
                aircraftColor.SetColor();
                rect   = new RectangleF(x, y, width, AircraftFontSize);
                size   = DrawString(Flight.Aircraft, rect, AircraftFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                width -= size.Width;
                x     += size.Width;

                // Render the Aircraft model
                Aircraft aircraft = LogBook.GetAircraft(Flight.Aircraft);

                if (aircraft != null && aircraft.Model != null)
                {
                    width -= TextPadding;
                    x     += TextPadding;
                    textColor.SetColor();
                    rect   = new RectangleF(x, y, width, AircraftFontSize);
                    size   = DrawString(aircraft.Model, rect, ModelFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                    width -= size.Width;
                    x     += size.Width;
                }

                // Render the Flight Time
                textColor.SetColor();
                width -= TextPadding;
                x     += TextPadding;
                rect   = new RectangleF(x, y, width, AircraftFontSize);
                size   = DrawString(FormatFlightTime(Flight.FlightTime), rect, ModelFont, UILineBreakMode.TailTruncation,
                                    UITextAlignment.Right);
                width -= size.Width;
                x     += size.Width;

                // Move down onto the next line (to render the remarks)
                width = bounds.Width - (ImagePadding + image.Size.Width + TextPadding * 2);
                x     = bounds.X + ImagePadding + image.Size.Width + TextPadding;
                y     = bounds.Y + RemarksYOffset;

                // Render the remarks
                if (Flight.Remarks != null)
                {
                    remarksColor.SetColor();
                    rect   = new RectangleF(x, y, width, RemarksFontSize);
                    size   = DrawString(Flight.Remarks, rect, RemarksFont, UILineBreakMode.TailTruncation, UITextAlignment.Left);
                    width -= size.Width;
                    x     += size.Width;
                }
            }
Esempio n. 30
0
        bool CanDeleteAircraftElement(Element element)
        {
            AircraftElement aircraft = element as AircraftElement;

            return(aircraft != null && LogBook.CanDelete(aircraft.Aircraft));
        }