Example #1
0
        private ApplicationState()
        {
            // read the application state from db
            SqlCeConnection _dataConn = null;

            try
            {
                _dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
                _dataConn.Open();
                SqlCeCommand selectCmd = new SqlCeCommand();
                selectCmd.Connection = _dataConn;
                StringBuilder selectQuery = new StringBuilder();
                selectQuery.Append("SELECT cruiseSpeed,cruiseFuelFlow,minFuel,speed,unit,utcOffset,locationFormat,deckHoldFuel,registeredClientName FROM ApplicationState");
                selectCmd.CommandText = selectQuery.ToString();
                SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
                if (results.HasRows)
                {
                    results.ReadFirst();
                    cruiseSpeed          = results.GetInt64(0);
                    cruiseFuelFlow       = results.GetInt64(1);
                    minFuel              = results.GetInt64(2);
                    speed                = results.GetSqlString(3).ToString();
                    unit                 = results.GetSqlString(4).ToString();
                    utcOffset            = results.GetSqlString(5).ToString();
                    locationFormat       = results.GetSqlString(6).ToString();
                    deckHoldFuel         = results.IsDBNull(7) ? 0 : results.GetInt64(7);
                    registeredClientName = results.IsDBNull(8) ? string.Empty : results.GetString(8);
                }
            }

            finally
            {
                _dataConn.Close();
            }
        }
Example #2
0
 public void InitializePilotsDataFromDatabase()
 {
     try
     {
         _dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
         _dataConn.Open();
         SqlCeCommand selectCmd = new SqlCeCommand();
         selectCmd.Connection = _dataConn;
         StringBuilder selectQuery = new StringBuilder();
         selectQuery.Append("SELECT [First Name],[Last Name],[Weight]");
         selectQuery.Append(" FROM Airports");
         selectCmd.CommandText = selectQuery.ToString();
         SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
         if (results.HasRows)
         {
             results.ReadFirst();
             while (true)
             {
                 Pilot currPilot = new Pilot();
                 currPilot.FName  = results.GetSqlString(0).ToString();
                 currPilot.LName  = results.GetSqlString(1).ToString();
                 currPilot.Weight = results.GetDouble(2);
                 PersonId pid = new PersonId(currPilot.FName, currPilot.LName);
                 if (!listofPilots.ContainsKey(pid))
                 {
                     listofPilots.Add(pid, new List <Pilot>());
                 }
                 listofPilots[pid].Add(currPilot);
                 nameList.Add(pid);
                 if (!results.Read())
                 {
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
     finally
     {
         _dataConn.Close();
     }
 }
Example #3
0
        public List <string> getIdentsFromRoute(string routeIdent)
        {
            List <string> idents = new List <string>();

            try
            {
                _dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
                _dataConn.Open();
                // first delete the existing data
                SqlCeCommand selectCmd = new SqlCeCommand();
                selectCmd.Connection = _dataConn;
                StringBuilder selectQuery = new StringBuilder();
                selectQuery.Append(string.Format("SELECT AirportIdent FROM RouteIdents where RouteId = '{0}' order by RouteSequenceNumber asc", routeIdent));
                selectCmd.CommandText = selectQuery.ToString();
                SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
                if (results.HasRows)
                {
                    results.ReadFirst();
                    while (true)
                    {
                        idents.Add(results.GetSqlString(0).ToString());
                        if (!results.Read())
                        {
                            break;
                        }
                    }
                }

                return(idents);
            }
            catch (Exception ex)
            {
                return(idents);
            }
            finally
            {
                if (_dataConn != null)
                {
                    _dataConn.Close();
                }
            }
        }
Example #4
0
        public void InitializeAirportdataFromDatabase()
        {
            try
            {
                _dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
                _dataConn.Open();

                // first delete the existing data
                SqlCeCommand selectCmd = new SqlCeCommand();
                selectCmd.Connection = _dataConn;
                StringBuilder selectQuery = new StringBuilder();
                selectQuery.Append("SELECT airport_id, airport_ident, airport_type, airport_name, airport_latdeg, airport_longdeg, airport_elev_ft, airport_muncipality, airport_freqkhz, airport_gps_code,");
                selectQuery.Append("airport_iata_code, airport_magnetic_deg, associated_airport FROM Airports");
                selectCmd.CommandText = selectQuery.ToString();
                SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
                if (results.HasRows)
                {
                    results.ReadFirst();
                    while (true)
                    {
                        Airport currAirport = new Airport();

                        currAirport.ID            = results.GetSqlString(0).ToString();
                        currAirport.ident         = results.GetSqlString(1).ToString();
                        currAirport.type          = results.GetSqlString(2).ToString();
                        currAirport.name          = results.GetSqlString(3).ToString();
                        currAirport.latitude_deg  = results.GetSqlString(4).ToString();
                        currAirport.longitude_deg = results.GetSqlString(5).ToString();
                        currAirport.elev_ft       = results.GetSqlString(6).ToString();


                        currAirport.municipality  = results.GetSqlString(7).ToString();
                        currAirport.frequency_khz = results.GetSqlString(8).ToString();


                        currAirport.gps_code  = results.GetSqlString(9).ToString();
                        currAirport.iata_code = results.GetSqlString(10).ToString();
                        currAirport.magnetic_variation_deg = results.GetSqlString(11).ToString();
                        currAirport.associated_airport     = results.GetSqlString(12).ToString();


                        if (!listofAirports.ContainsKey(currAirport.ident))
                        {
                            listofAirports.Add(currAirport.ident, new List <Airport>());
                        }
                        listofAirports[currAirport.ident].Add(currAirport);

                        identList.Add(currAirport.ident);

                        if (!results.Read())
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (_dataConn != null)
                {
                    _dataConn.Close();
                }
            }
        }