예제 #1
0
    /// <summary>
    /// מחזיר טיסות שבחרתי
    /// </summary>
    internal List <Flights> ReturnFlightsChosen()
    {
        List <Flights> FlightsList = new List <Flights>();
        Flights        objFlight   = new Flights();
        SqlConnection  con;
        SqlCommand     cmd;

        try
        {
            con = connect("destinationsDBConnectionString"); // create the connection
        }
        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }

        try
        {
            String cStr = $@"SELECT *
                             FROM [dbo].[MyFlights]";
            cmd = CreateCommand(cStr, con);             // create the command
            SqlDataReader reader2;
            reader2 = cmd.ExecuteReader();
            if (reader2.HasRows)
            {
                while (reader2.Read())
                {
                    objFlight.FlightId  = reader2["FlightNum"].ToString();
                    objFlight.dateFrom  = reader2["DateFrom"].ToString();
                    objFlight.dateUntil = reader2["DateTo"].ToString();
                    objFlight.cityFrom  = reader2["CityFrom"].ToString();
                    objFlight.cityTo    = reader2["CityTo"].ToString();
                    objFlight.InitialRoutesList();//מאתחל רשימת קונקשיינים ואחר כך יכניס אותם
                    FlightsList.Add(objFlight);
                    objFlight = new Flights();
                }
            }
            else
            {
                Console.WriteLine("No rows found.");
            }
            reader2.Close();
        }

        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }

        finally
        {
            if (con != null)
            {
                // close the db connection
                con.Close();
            }
        }
        return(FlightsList);
    }