public static Insert ( bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated, bool initialSpeed ) : int | ||
dbconOpened | bool | |
tableName | string | |
uniqueID | string | |
personID | int | |
sessionID | int | |
type | string | |
distance | double | |
time | double | |
description | string | |
simulated | int | |
initialSpeed | bool | |
return | int |
public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string type, double distance, double time, string description, int simulated, bool initialSpeed)
{
if(! dbconOpened)
Sqlite.Open();
if(uniqueID == "-1")
uniqueID = "NULL";
dbcmd.CommandText = "INSERT INTO " + tableName +
" (uniqueID, personID, sessionID, type, distance, time, description, simulated, initialSpeed)" +
" VALUES (" + uniqueID + ", " +
+ personID + ", " + sessionID + ", \"" + type + "\", "
+ Util.ConvertToPoint(distance) + ", " + Util.ConvertToPoint(time) + ", \"" +
description + "\", " + simulated + ", " + Util.BoolToInt(initialSpeed) + ")" ;
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
//int myLast = dbcon.LastInsertRowId;
//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
string myString = @"select last_insert_rowid()";
dbcmd.CommandText = myString;
int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
if(! dbconOpened)
Sqlite.Close();
return myLast;
}
protected override void write() { LogB.Information(string.Format("TIME: {0}", time.ToString())); /* * string myStringPush = Catalog.GetString("Last run") + ": " + RunnerName + " " + * type + " " + Catalog.GetString("time") + ": " + Util.TrimDecimals( time.ToString(), pDN ) + * " " + Catalog.GetString("speed") + ": " + Util.TrimDecimals ( (distance/time).ToString(), pDN ); */ if (simulated) { feedbackMessage = Catalog.GetString(Constants.SimulatedMessage); } else { feedbackMessage = ""; } needShowFeedbackMessage = true; string description = ""; if (type == "Margaria") { // P = W * 9.8 * D / t // W: person weight // D: distance between 3d and 9th stair double weight = SqlitePersonSession.SelectAttribute(false, personID, sessionID, Constants.Weight); double distanceMeters = distance / 1000; description = "P = " + Util.TrimDecimals((weight * 9.8 * distanceMeters / time).ToString(), pDN) + " (Watts)"; } else if (type == "Gesell-DBT") { description = "0"; } string table = Constants.RunTable; uniqueID = SqliteRun.Insert(false, table, "NULL", personID, sessionID, type, distance, time, description, Util.BoolToNegativeInt(simulated), !startIn //initialSpeed true if not startIn ); //define the created object eventDone = new Run(uniqueID, personID, sessionID, type, distance, time, description, Util.BoolToNegativeInt(simulated), !startIn); //event will be raised, and managed in chronojump.cs fakeButtonFinished.Click(); //app1.PrepareRunSimpleGraph(time, distance/time); PrepareEventGraphRunSimpleObject = new PrepareEventGraphRunSimple(time, distance / time, sessionID, personID, table, type); needUpdateGraphType = eventType.RUN; needUpdateGraph = true; needEndEvent = true; //used for hiding some buttons on eventWindow }