public int GetGameID() { int GameID = -2; string TheLine = "SELECT MAX(GameID) from PlayerScoreSchema." + VDataTab + ";"; MySqlCommand GetGameID = new MySqlCommand((TheLine), DBconnect); GetGameID.Connection.Open(); MySqlDataReader RecordData; RecordData = GetGameID.ExecuteReader(); try { while (RecordData.Read()) { if (RecordData.HasRows) { GameID = RecordData.GetInt32(0); } } } catch { //do nothing for now. - means there's nothing in the database } RecordData.Close(); GetGameID.Connection.Close(); return(GameID); }
public void getCountAndSpeed(string Name, string EndTime, ref int vcount, ref double AvSp, ref TimeSpan StartTime) { string QueryLine = ("SELECT VCount, AvSpeed, StartTime FROM " + VDataTab + " WHERE "); QueryLine += "(LoopName LIKE '%" + Name + "%') AND "; QueryLine += "EndTime = '" + EndTime + "';"; MySqlCommand LookUpData = new MySqlCommand(QueryLine, DBconnect); LookUpData.Connection.Open(); MySqlDataReader RecordData; RecordData = LookUpData.ExecuteReader(); while (RecordData.Read()) { //TODO come back to this vcount = RecordData.GetInt32("VCount"); AvSp = RecordData.GetDouble("AvSpeed"); string TimeString = RecordData.GetString("StartTime"); StartTime = Convert.ToDateTime(TimeString).TimeOfDay; } RecordData.Close(); LookUpData.Connection.Close(); }
public int CountInVDataTab(string Condition) { string QueryLine = ("SELECT COUNT(*) FROM " + VDataTab + " WHERE "); QueryLine += (Condition + ";"); MySqlCommand LookUpData = new MySqlCommand(QueryLine, DBconnect); LookUpData.Connection.Open(); MySqlDataReader RecordData; RecordData = LookUpData.ExecuteReader(); int Count = 0; while (RecordData.Read()) { Count = RecordData.GetInt32(0); } RecordData.Close(); LookUpData.Connection.Close(); return(Count); }
public void GetVLifeTime(string Condition, ref double LifeTime, ref int NumV) { string QueryLine = ("SELECT SUM(TIME_TO_SEC(SUBTIME(AtTime,BornTime))),COUNT(*) FROM " + VDataTab + " WHERE "); QueryLine += (Condition + ";"); MySqlCommand LookUpData = new MySqlCommand(QueryLine, DBconnect); LookUpData.Connection.Open(); MySqlDataReader RecordData; RecordData = LookUpData.ExecuteReader(); LifeTime = 0; NumV = 0; try { while (RecordData.Read()) { LifeTime = RecordData.GetDouble(0); NumV = RecordData.GetInt32(1); } } catch (Exception e) { //let this fail quietly and log zero's because it is probably because there are no vehicles in the sim. } RecordData.Close(); LookUpData.Connection.Close(); }
public List <VehicleIdentity> VidGrabLine(string Condition) { string QueryLine = ("SELECT * FROM " + ViDTab + " WHERE "); QueryLine += (Condition + ";"); MySqlCommand LookUpData = new MySqlCommand(QueryLine, DBconnect); List <VehicleIdentity> TempIDL = new List <VehicleIdentity>(); LookUpData.Connection.Open(); MySqlDataReader RecordData; RecordData = LookUpData.ExecuteReader(); while (RecordData.Read()) { VehicleIdentity TempID = new VehicleIdentity(); TempID.ViD = RecordData.GetString(0); TempID.Vtype = RecordData.GetInt32(1); TempID.BornAt = DateTime.Parse(RecordData.GetString(2)); TempID.BornLink = new LinkID(RecordData.GetString(3)); if (!RecordData.IsDBNull(4)) { TempID.Routename = RecordData.GetString(4); } if (!RecordData.IsDBNull(5)) { TempID.Origin = RecordData.GetInt32(5); } if (!RecordData.IsDBNull(6)) { TempID.Destination = RecordData.GetInt32(6); } TempID.Tag = RecordData.GetInt32(7); TempID.BornStage = RecordData.GetInt32(8); TempID.BornScenario = RecordData.GetInt32(9); TempID.Obsolete = RecordData.GetBoolean(10); if (!RecordData.IsDBNull(11)) { TempID.MagicNumbers = RecordData.GetString(11); } TempIDL.Add(TempID); } RecordData.Close(); LookUpData.Connection.Close(); return(TempIDL); }