//Updates a value on the table, or creates a new one in case it doesn't exist public void Update(Connection c, string s) { DataRow foundRows; string search = "Type = " + c.categorie.ToString() + " and Direction = " + c.side.ToString() + " and Distance = " + c.Distance().ToString(); foundRows = table.Select(search).FirstOrDefault(); if (foundRows != null) { foundRows["Solution"] = s; //changes the Solution } else { table.Rows.Add(c.categorie.ToString(), c.side.ToString(), c.Distance(), s); } }
public String getAlternative(Connection cc) { DataRow[] foundRows; DataRow newRow; string search = "Type = " + cc.categorie.ToString() + " and Direction = " + cc.side.ToString(); foundRows = table.Select(search); newRow = table.Select(search).FirstOrDefault(); if (foundRows != null) { foreach (DataRow row in foundRows) { int a = Convert.ToInt32(row["Distance"]); int b = Convert.ToInt32(newRow["Distance"]); int c = cc.Distance(); if (Math.Abs(c - b) > Math.Abs(c - a)) { newRow = row; } } } return newRow["Solution"].ToString(); }