//Argument to this function should be changed //into the SQLResults object returned from //runQuery above (and used in fQR above) /// <summary> /// A public method allowing the Track Model and external modules to format /// database queries into coherent RouteInfo objects /// </summary> /// <param name="rr">A SQLiteDataReader object provided by the runQuery method in the DBManager</param> /// <returns>A valid RouteInfo object, or null in the case of a database error.</returns> public RouteInfo formatRouteQueryResults(SQLiteDataReader rr) { if (rr == null) { return(null); } //Temp list used to store blocks, since we dont know //ahead of time how many to expect var blockList = new List <Block>(); int nBlocks = 0; //We need to get our list of blocks, and the number of blocks int bIDFinal = -1, locXFinal = -1, locYFinal = -1; double sEFinal = -1.0, gradeFinal = -0.0, bSizeFinal = -1.0; int dest1Final = -1, dest2Final = -1, prevFinal = -1; int trackCirIDFinal = -1; int speedLimitFinal = -1; while (rr.Read()) { //Get all fields for a given block bIDFinal = rr.GetInt32(rr.GetOrdinal("blockID")); string line = rr.GetString(rr.GetOrdinal("line")); string infra = rr.GetString(rr.GetOrdinal("infra")); string dir = rr.GetString(rr.GetOrdinal("dir")); string state = rr.GetString(rr.GetOrdinal("state")); sEFinal = rr.GetDouble(rr.GetOrdinal("starting_elev")); gradeFinal = rr.GetDouble(rr.GetOrdinal("grade")); bSizeFinal = rr.GetDouble(rr.GetOrdinal("bSize")); trackCirIDFinal = rr.GetInt32(rr.GetOrdinal("trackCirID")); speedLimitFinal = rr.GetInt32(rr.GetOrdinal("speedLimit")); locXFinal = rr.GetInt32(rr.GetOrdinal("locX")); locYFinal = rr.GetInt32(rr.GetOrdinal("locY")); prevFinal = rr.GetInt32(rr.GetOrdinal("prev")); dest1Final = rr.GetInt32(rr.GetOrdinal("dest1")); dest2Final = rr.GetInt32(rr.GetOrdinal("dest2")); ////////////////////////////////////////////////////////////////////// //Parse fields that must be provided as a different type string[] infraFinal = infra.Split(';'); var dirFinal = (DirEnum)Enum.Parse(typeof(DirEnum), dir, true); var stateFinal = (StateEnum)Enum.Parse(typeof(StateEnum), state, true); var locFinal = new int[2]; locFinal[0] = locXFinal; locFinal[1] = locYFinal; blockList.Add(new Block(bIDFinal, stateFinal, prevFinal, sEFinal, gradeFinal, locFinal, bSizeFinal, dirFinal, infraFinal, dest1Final, dest2Final, trackCirIDFinal, line, speedLimitFinal)); nBlocks++; } //If we didnt find any blocks, give up. if (nBlocks == 0) { //if (_dbCon.State != ConnectionState.Closed) // _dbCon.Close(); return(null); } Block[] blocks = blockList.ToArray(); string rName = blocks[0].Line; int rID; if (rName.Equals("Red", StringComparison.OrdinalIgnoreCase)) { rID = 0; } else { rID = 1; } //All routes start and end at the yard int sID = 0; int eID = 0; var tempRoute = new RouteInfo(rID, rName, nBlocks, blocks, sID, eID); //if (_dbCon.State != ConnectionState.Closed) // _dbCon.Close(); return(tempRoute); }
//Argument to this function should be changed //into the SQLResults object returned from //runQuery above (and used in fQR above) /// <summary> /// A public method allowing the Track Model and external modules to format /// database queries into coherent RouteInfo objects /// </summary> /// <param name="rr">A SQLiteDataReader object provided by the runQuery method in the DBManager</param> /// <returns>A valid RouteInfo object, or null in the case of a database error.</returns> public RouteInfo formatRouteQueryResults(SQLiteDataReader rr) { if (rr == null) return null; //Temp list used to store blocks, since we dont know //ahead of time how many to expect var blockList = new List<Block>(); int nBlocks = 0; //We need to get our list of blocks, and the number of blocks int bIDFinal = -1, locXFinal = -1, locYFinal = -1; double sEFinal = -1.0, gradeFinal = -0.0, bSizeFinal = -1.0; int dest1Final = -1, dest2Final = -1, prevFinal = -1; int trackCirIDFinal = -1; int speedLimitFinal =-1; while (rr.Read()) { //Get all fields for a given block bIDFinal = rr.GetInt32(rr.GetOrdinal("blockID")); string line = rr.GetString(rr.GetOrdinal("line")); string infra = rr.GetString(rr.GetOrdinal("infra")); string dir = rr.GetString(rr.GetOrdinal("dir")); string state = rr.GetString(rr.GetOrdinal("state")); sEFinal = rr.GetDouble(rr.GetOrdinal("starting_elev")); gradeFinal = rr.GetDouble(rr.GetOrdinal("grade")); bSizeFinal = rr.GetDouble(rr.GetOrdinal("bSize")); trackCirIDFinal = rr.GetInt32(rr.GetOrdinal("trackCirID")); speedLimitFinal = rr.GetInt32(rr.GetOrdinal("speedLimit")); locXFinal = rr.GetInt32(rr.GetOrdinal("locX")); locYFinal = rr.GetInt32(rr.GetOrdinal("locY")); prevFinal = rr.GetInt32(rr.GetOrdinal("prev")); dest1Final = rr.GetInt32(rr.GetOrdinal("dest1")); dest2Final = rr.GetInt32(rr.GetOrdinal("dest2")); ////////////////////////////////////////////////////////////////////// //Parse fields that must be provided as a different type string[] infraFinal = infra.Split(';'); var dirFinal = (DirEnum) Enum.Parse(typeof (DirEnum), dir, true); var stateFinal = (StateEnum) Enum.Parse(typeof (StateEnum), state, true); var locFinal = new int[2]; locFinal[0] = locXFinal; locFinal[1] = locYFinal; blockList.Add(new Block(bIDFinal, stateFinal, prevFinal, sEFinal, gradeFinal, locFinal, bSizeFinal, dirFinal, infraFinal, dest1Final, dest2Final, trackCirIDFinal, line,speedLimitFinal)); nBlocks++; } //If we didnt find any blocks, give up. if (nBlocks == 0) { //if (_dbCon.State != ConnectionState.Closed) // _dbCon.Close(); return null; } Block[] blocks = blockList.ToArray(); string rName = blocks[0].Line; int rID; if (rName.Equals("Red", StringComparison.OrdinalIgnoreCase)) rID = 0; else rID = 1; //All routes start and end at the yard int sID = 0; int eID = 0; var tempRoute = new RouteInfo(rID, rName, nBlocks, blocks, sID, eID); //if (_dbCon.State != ConnectionState.Closed) // _dbCon.Close(); return tempRoute; }