private void btnGetFplFromFpd_Click(object sender, RoutedEventArgs e)
 {
     FlightPlanDatabase.FpdApi fd = new FlightPlanDatabase.FpdApi();
     List<FlightPlanDatabase.ApiDataTypes.FlightPlanSummary> fpls = new List<FlightPlanDatabase.ApiDataTypes.FlightPlanSummary>();
     try {
         fpls = fd.searchFlightPlans(txtFromICAO.Text, txtDestICAO.Text);
     }catch(Exception ex)
     {
         String exmsg = ex.Message;
         if (ex.Message.Contains(":")) { exmsg = exmsg.Split(':')[1]; }
         if (ex.Message.Contains(")")) { exmsg = exmsg.Split(')')[1]; }
         lblSearchMsg.Content = "Error: " + exmsg;
         return;
     }
     cbFpls.Items.Clear();
     if (fpls == null || fpls.Count < 1)
     {
         lblSearchMsg.Content = "Suitable FPL could not be found.";
         cbFpls.Visibility = Visibility.Collapsed;
     }
     else
     {
         pFplList = new List<FlightPlanDatabase.ApiDataTypes.FlightPlanSummary>();
         pFplList = fpls;
         foreach (FlightPlanDatabase.ApiDataTypes.FlightPlanSummary f in fpls)
         {
             cbFpls.Items.Add(f.id + " (" + String.Format("{0:0.00}", f.distance) + "nm - " + f.waypoints.ToString() + "wpts)");
         }
         lblSearchMsg.Content = "FPL(s) found. Select below to load.";
         cbFpls.Visibility = Visibility.Visible;
     }
 }
        private void cbFpls_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbFpls.Items.Count > 0 && cbFpls.SelectedValue != null)
            {
                FlightPlanDatabase.FpdApi fd = new FlightPlanDatabase.FpdApi();
                FlightPlanDatabase.ApiDataTypes.FlightPlanDetails planDetail = fd.getPlan(cbFpls.SelectedValue.ToString().Split(' ').First());
                //FMSControl.CustomFPL.waypoints.Clear();
                List <FMS.fplDetails> fpl = new List <FMS.fplDetails>();
                pApiFpl = new Fds.IFAPI.APIFlightPlan();
                List <Fds.IFAPI.APIWaypoint> apiWpts = new List <Fds.IFAPI.APIWaypoint>();

                foreach (FlightPlanDatabase.ApiDataTypes.Node wpt in planDetail.route.nodes)
                {
                    Fds.IFAPI.APIWaypoint apiWpt = new Fds.IFAPI.APIWaypoint();
                    apiWpt.Name      = wpt.ident;
                    apiWpt.Code      = wpt.name;
                    apiWpt.Latitude  = wpt.lat;
                    apiWpt.Longitude = wpt.lon;
                    apiWpts.Add(apiWpt);

                    FMS.fplDetails n = new FMS.fplDetails();
                    n.WaypointName = wpt.ident;
                    n.Altitude     = wpt.alt;

                    //FMSControl.CustomFPL.waypoints.Add(n);
                    fpl.Add(n);
                }

                pApiFpl.Waypoints = apiWpts.ToArray();

                FmsFpl = fpl;
            }
        }
        private void loadFpdFplFromId(string id)
        {
            FlightPlanDatabase.FpdApi fd = new FlightPlanDatabase.FpdApi();
            FlightPlanDatabase.ApiDataTypes.FlightPlanDetails planDetail = fd.getPlan(id);
            //FMSControl.CustomFPL.waypoints.Clear();
            List <FMS.fplDetails> fpl = new List <FMS.fplDetails>();

            pApiFpl = new Fds.IFAPI.APIFlightPlan();
            List <Fds.IFAPI.APIWaypoint> apiWpts = new List <Fds.IFAPI.APIWaypoint>();

            foreach (FlightPlanDatabase.ApiDataTypes.Node wpt in planDetail.route.nodes)
            {
                Fds.IFAPI.APIWaypoint apiWpt = new Fds.IFAPI.APIWaypoint();
                apiWpt.Name      = wpt.ident;
                apiWpt.Code      = wpt.name;
                apiWpt.Latitude  = wpt.lat;
                apiWpt.Longitude = wpt.lon;
                apiWpts.Add(apiWpt);

                FMS.fplDetails n = new FMS.fplDetails();
                n.WaypointName = wpt.ident;
                n.Altitude     = wpt.alt;

                //FMSControl.CustomFPL.waypoints.Add(n);
                fpl.Add(n);
            }

            pApiFpl.Waypoints = apiWpts.ToArray();

            FmsFpl = fpl;
        }
        private void btnGetFplFromFpd_Click(object sender, RoutedEventArgs e)
        {
            FlightPlanDatabase.FpdApi fd = new FlightPlanDatabase.FpdApi();
            List <FlightPlanDatabase.ApiDataTypes.FlightPlanSummary> fpls = new List <FlightPlanDatabase.ApiDataTypes.FlightPlanSummary>();

            try {
                fpls = fd.searchFlightPlans(txtFromICAO.Text, txtDestICAO.Text);
            }catch (Exception ex)
            {
                String exmsg = ex.Message;
                if (ex.Message.Contains(":"))
                {
                    exmsg = exmsg.Split(':')[1];
                }
                if (ex.Message.Contains(")"))
                {
                    exmsg = exmsg.Split(')')[1];
                }
                lblSearchMsg.Content = "Error: " + exmsg;
                return;
            }
            cbFpls.Items.Clear();
            if (fpls == null || fpls.Count < 1)
            {
                lblSearchMsg.Content = "Suitable FPL could not be found.";
                cbFpls.Visibility    = Visibility.Collapsed;
            }
            else
            {
                pFplList = new List <FlightPlanDatabase.ApiDataTypes.FlightPlanSummary>();
                pFplList = fpls;
                foreach (FlightPlanDatabase.ApiDataTypes.FlightPlanSummary f in fpls)
                {
                    cbFpls.Items.Add(f.id + " (" + String.Format("{0:0.00}", f.distance) + "nm - " + f.waypoints.ToString() + "wpts)");
                }
                lblSearchMsg.Content = "FPL(s) found. Select below to load.";
                cbFpls.Visibility    = Visibility.Visible;
            }
        }
        private void loadFpdFplFromId(string id)
        {
            FlightPlanDatabase.FpdApi fd = new FlightPlanDatabase.FpdApi();
            FlightPlanDatabase.ApiDataTypes.FlightPlanDetails planDetail = fd.getPlan(id);
            //FMSControl.CustomFPL.waypoints.Clear();
            List<FMS.fplDetails> fpl = new List<FMS.fplDetails>();
            pApiFpl = new Fds.IFAPI.APIFlightPlan();
            List<Fds.IFAPI.APIWaypoint> apiWpts = new List<Fds.IFAPI.APIWaypoint>();

            foreach (FlightPlanDatabase.ApiDataTypes.Node wpt in planDetail.route.nodes)
            {
                Fds.IFAPI.APIWaypoint apiWpt = new Fds.IFAPI.APIWaypoint();
                apiWpt.Name = wpt.ident;
                apiWpt.Code = wpt.name;
                apiWpt.Latitude = wpt.lat;
                apiWpt.Longitude = wpt.lon;
                apiWpts.Add(apiWpt);

                FMS.fplDetails n = new FMS.fplDetails();
                n.WaypointName = wpt.ident;
                n.Altitude = wpt.alt;

                //FMSControl.CustomFPL.waypoints.Add(n);
                fpl.Add(n);
            }

            pApiFpl.Waypoints = apiWpts.ToArray();

            FmsFpl = fpl;
        }