/// <summary> /// For demo reason, show all maze records. /// </summary> public string[][] GetAllMazeRecord() { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add(Constants.COLUMN_ID); selectvalue.Add(Constants.MAZE_MATRIX); selectvalue.Add(Constants.MAZE_COVERAGE); selectvalue.Add(Constants.MAZE_TIMETAKEN); selectvalue.Add(Constants.MAZE_HISTORY); selectvalue.Add(Constants.MAZE_POINTS); Dictionary <string, string> condition = new Dictionary <string, string>(); List <string[]> res = new List <string[]>(); dataReader = ExecuteQuery(sql.Select(selectvalue, Constants.TABLE_MAZE, condition)); while (dataReader.HasRows) { if (dataReader.Read()) { res.Add(new string[6] { dataReader[Constants.COLUMN_ID].ToString(), dataReader[Constants.MAZE_MATRIX].ToString(), dataReader[Constants.MAZE_COVERAGE].ToString(), dataReader[Constants.MAZE_TIMETAKEN].ToString(), dataReader[Constants.MAZE_HISTORY].ToString(), dataReader[Constants.MAZE_POINTS].ToString() }); } } return(res.ToArray()); }
/// GetSensorMatrixById /// <summary> /// return the sensor according to id /// </summary> /// <param name="sensorId"></param> /// <returns> /// The 2D array of the sensor's information. /// </returns> public int[,] GetSensorMatrixById(int sensorId, int timestamp) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("Content"); string tableName = Constants.TABLE_SENSOR; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add(Constants.COLUMN_ID, sensorId.ToString()); condition.Add(Constants.SENSOR_TIMESTAMP, timestamp.ToString()); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); string res = ""; if (dataReader.Read()) { res = dataReader.GetString(0); } string[] split1 = res.Split(';'); int num1 = split1.Length; int num2 = split1[0].Split(',').Length; int[,] result = new int[num1, num2]; for (int i = 0; i < split1.Length; i++) { string[] split2 = split1[i].Split(','); for (int j = 0; j < split2.Length; j++) { result[i, j] = Convert.ToInt32(split2[j]); } } return(result); }
/// <summary> /// This method is to get back maze matrix by Id /// </summary> /// <param name="id"></param> /// <returns> /// The 2D array of the maze. /// </returns> public int[,] GetMazeById(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add(Constants.MAZE_MATRIX); string tableName = Constants.TABLE_MAZE; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add(Constants.COLUMN_ID, id.ToString()); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); string res = ""; if (dataReader.Read()) { res = dataReader.GetString(0); } string[] split1 = res.Split(';'); int num1 = split1.Length; int num2 = split1[0].Split(',').Length; int[,] result = new int[num1, num2]; for (int i = 0; i < split1.Length; i++) { string[] split2 = split1[i].Split(','); for (int j = 0; j < split2.Length; j++) { result[i, j] = Convert.ToInt32(split2[j]); } } return(result); }
/// <summary> /// return the sepecific Command according to id /// </summary> /// <param name="id"></param> /// <returns></returns> public string[] getCommandByID(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("Step"); selectvalue.Add("Command"); string tableName = "Commands"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("ID", id.ToString()); string[] res = getCommandsSize(id); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); // Debug.Log(dataReader.Read()); while (dataReader.HasRows) { if (dataReader.Read()) { int index = dataReader.GetInt32(0) - 1; res[index] = dataReader.GetString(1); } } return(res); }
/// <summary> /// return the sepecific path according to id /// </summary> /// <param name="id"></param> /// <returns></returns> public int[, ] getPathByID(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("Step"); selectvalue.Add("X"); selectvalue.Add("Y"); string tableName = "Path"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("SolutionID", id.ToString()); int[, ] res = getPathSize(id); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); while (dataReader.HasRows) { if (dataReader.Read()) { int step = dataReader.GetInt32(0) - 1; int x = dataReader.GetInt32(1); int y = dataReader.GetInt32(2); res[step, 0] = x; res[step, 1] = y; } } return(res); }
/// <summary> /// This method is to get back maze record by Id /// </summary> /// <param name="id"></param> /// <returns></returns> public string[][] GetMazeById(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add(Constants.COLUMN_NODE); selectvalue.Add(Constants.COLUMN_CONNECTTO); selectvalue.Add(Constants.COLUMN_DIRECTION); Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add(Constants.COLUMN_ID, id.ToString()); List <string[]> res = new List <string[]>(); dataReader = ExecuteQuery(sql.Select(selectvalue, Constants.TABLE_MAZE, condition)); while (dataReader.HasRows) { if (dataReader.Read()) { res.Add(new string[3] { dataReader[Constants.COLUMN_NODE].ToString(), dataReader[Constants.COLUMN_CONNECTTO].ToString(), dataReader[Constants.COLUMN_DIRECTION].ToString() }); } } return(res.ToArray()); }
public void Test_Select() { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("X"); selectvalue.Add("Y"); selectvalue.Add("Value"); string tableName = "Maze"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("ID", "1"); condition.Add("Z", "2"); Assert.AreEqual("SELECT X,Y,Value FROM Maze WHERE ID = 1 And Z = 2;", sql.Select(selectvalue, tableName, condition)); }
/// <summary> /// return the size of the commands list /// </summary> /// <param name="id"></param> /// <returns></returns> public string[] getCommandsSize(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("count(Step)"); string tableName = "Commands"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("ID", id.ToString()); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); string[] res = new string[0]; if (dataReader.Read()) { int size = dataReader.GetInt32(0); res = new string[size]; } return(res); }
public int[, ] getPathSize(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("count(Step)"); string tableName = "Path"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("SolutionID", id.ToString()); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); int step = 0; if (dataReader.Read()) { step = dataReader.GetInt32(0); } return(new int[step, 2]); }
/// <summary> /// Return the size of the maze according to id. /// </summary> /// <param name="id"></param> /// <returns></returns> private int[, ] getMazeSize(int id) { SqlEncap sql = new SqlEncap(); List <string> selectvalue = new List <string>(); selectvalue.Add("max(X)"); selectvalue.Add("max(Y)"); string tableName = "Maze"; Dictionary <string, string> condition = new Dictionary <string, string>(); condition.Add("ID", id.ToString()); dataReader = ExecuteQuery(sql.Select(selectvalue, tableName, condition)); int x = 0; int y = 0; if (dataReader.Read()) { x = dataReader.GetInt32(0) + 1; y = dataReader.GetInt32(1) + 1; } return(new int[x, y]); }