public List<Tgsegment> GetList()
    {
        List<Tgsegment> lvResult = new List<Tgsegment>();
        DataSet ds = null;
        int lvLastLocation = Int32.MinValue;
        Tgsegment lvElement = null;

        ds = TgsegmentDataAccess.GetData(this.lvlocation, this.lvstart_coordinate, this.lvend_coordinate, this.lvcapacity, "location asc");

        foreach (DataRow row in ds.Tables[0].Rows)
        {
            lvElement = new Tgsegment();

            lvElement.Location = ((row["location"] == DBNull.Value) ? Int32.MinValue : (int)row["location"]);
            lvElement.Start_coordinate = ((row["start_coordinate"] == DBNull.Value) ? Int32.MinValue : (int)row["start_coordinate"]);
            lvElement.End_coordinate = ((row["end_coordinate"] == DBNull.Value) ? Int32.MinValue : (int)row["end_coordinate"]);
            lvElement.Capacity = ((row["capacity"] == DBNull.Value) ? Int16.MinValue : Convert.ToInt16(row["capacity"]));

            if (FIRST_STOP_SEGMENT == Int32.MinValue)
            {
                FIRST_STOP_SEGMENT = lvElement.Location;
            }

            lvLastLocation = lvElement.Location;

            lvResult.Add(lvElement);
            lvElement = null;
        }

        LAST_STOP_SEGMENT = lvLastLocation;

        return lvResult;
    }
    public Tgsegment GetCurrentStopSegment(int pCoordinate, int pDirection, out int pIdxSegment)
    {
        int lvStopSegIndex = -1;
        Tgsegment lvSubSegment = new Tgsegment();
        Tgsegment lvResSegment = null;

        if (pDirection > 0)
        {
            lvSubSegment.Start_coordinate = pCoordinate;
            lvSubSegment.End_coordinate = pCoordinate + 100;
        }
        else if (pDirection < 0)
        {
            lvSubSegment.Start_coordinate = pCoordinate - 100;
            lvSubSegment.End_coordinate = pCoordinate;
        }

        lvStopSegIndex = mListStopLoc.BinarySearch(lvSubSegment, mTGSegmentComparer);

        pIdxSegment = lvStopSegIndex;
        if (lvStopSegIndex >= 0)
        {
            lvResSegment = mListStopLoc[lvStopSegIndex];
        }
        else
        {
            lvResSegment = null;
        }

        return lvResSegment;
    }