Exemplo n.º 1
0
        List <PathLocation> arrangeInSequence(List <PathLocation> pathList)
        {
            List <PathLocation> arrangedPathList = new List <PathLocation>();
            int count = 1;

            while (count <= pathList.Count)
            {
                for (int j = 0; j < pathList.Count; j++)
                {
                    PathLocation p = pathList[j];

                    if (p.Sequence == count)
                    {
                        arrangedPathList.Add(p);
                    }
                }
                count++;
            }

            return(arrangedPathList);
        }
Exemplo n.º 2
0
        public List <PathLocation> GetPath(int journeyID)
        {
            List <PathLocation> pathList = new List <PathLocation>();

            try
            {
                conn.ConnectionString = conString;
                conn.Open();

                sqlComm            = new SqlCommand();
                sqlComm.Connection = conn;
                int count = 0;

                string[] modeList = new string[] { "Walk", "Train", "Bus" };

                for (int i = 0; i < modeList.Length; i++)
                {
                    sqlComm.CommandText = "SELECT Sequence,Location,startLat,startLong,endLat,endLong from " + modeList[i] + " where JourneyID=@jID" + count;

                    if (modeList[i].Equals("Bus"))
                    {
                        sqlComm.CommandText = "SELECT Sequence,serviceNum,startLat,startLong,endLat,endLong from " + modeList[i] + " where JourneyID=@jID" + count;
                    }

                    sqlComm.Parameters.AddWithValue("@jID" + count, journeyID);

                    SqlDataReader dr = sqlComm.ExecuteReader();

                    while (dr.Read())
                    {
                        PathLocation p = new PathLocation();
                        p.Mode = modeList[i];

                        if (modeList[i].Equals("Bus"))
                        {
                            p.BusServiceNum = Convert.ToInt32(dr["serviceNum"].ToString());
                            p.Location      = p.BusServiceNum.ToString();
                        }
                        else
                        {
                            p.Location = dr["Location"].ToString();
                        }
                        p.Sequence = Convert.ToInt32(dr["Sequence"].ToString());

                        p.StartLatitude  = Convert.ToDouble(dr["startLat"].ToString());
                        p.StartLongitude = Convert.ToDouble(dr["startLong"].ToString());
                        p.EndLatitude    = Convert.ToDouble(dr["endLat"].ToString());
                        p.EndLongitude   = Convert.ToDouble(dr["endLong"].ToString());
                        pathList.Add(p);
                    }
                    count++;
                    dr.Close();
                }
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            pathList = arrangeInSequence(pathList);

            return(pathList);
        }