[chronojump] ForceSensor change person at load works!
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] ForceSensor change person at load works!
- Date: Fri, 13 Sep 2019 16:18:23 +0000 (UTC)
commit 6037d1dc80aae1e8a0c00afec55a20aadc529de2
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Sep 13 18:17:52 2019 +0200
ForceSensor change person at load works!
src/forceSensor.cs | 41 ++++++++++++++++++++++++++++++++++++++++-
src/gui/forceSensor.cs | 46 +++++++++++++++++++++++++++++++++++++++++++---
src/sqlite/encoder.cs | 10 ----------
src/sqlite/forceSensor.cs | 36 +++++++++++-------------------------
src/sqlite/main.cs | 10 ++++++++++
src/util.cs | 2 +-
6 files changed, 105 insertions(+), 40 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index a67c3c73..00612baf 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -77,7 +77,6 @@ public class ForceSensor
{
return SqliteForceSensor.Insert(dbconOpened, toSQLInsertString());
}
-
private string toSQLInsertString()
{
string uniqueIDStr = "NULL";
@@ -90,6 +89,28 @@ public class ForceSensor
comments + "\", \"" + videoURL + "\")";
}
+ public void UpdateSQL(bool dbconOpened)
+ {
+ SqliteForceSensor.Update(dbconOpened, toSQLUpdateString());
+ }
+ private string toSQLUpdateString()
+ {
+ return
+ " uniqueID = " + uniqueID +
+ ", personID = " + personID +
+ ", sessionID = " + sessionID +
+ ", exerciseID = " + exerciseID +
+ ", captureOption = \"" + captureOption.ToString() +
+ "\", angle = " + angle +
+ ", laterality = \"" + laterality +
+ "\", filename = \"" + filename +
+ "\", url = \"" + url +
+ "\", dateTime = \"" + dateTime +
+ "\", comments = \"" + comments +
+ "\", videoURL = \"" + Util.MakeURLrelative(videoURL) +
+ "\" WHERE uniqueID = " + uniqueID;
+ }
+
public string [] ToStringArray (int count)
{
int all = 8;
@@ -138,6 +159,24 @@ public class ForceSensor
}
+ //uniqueID:name
+ public ForceSensor ChangePerson(string newIDAndName)
+ {
+ int newPersonID = Util.FetchID(newIDAndName);
+ string newPersonName = Util.FetchName(newIDAndName);
+ string newFilename = filename;
+
+ personID = newPersonID;
+ newFilename = newPersonID + "-" + newPersonName + "-" + dateTime + ".txt";
+
+ bool success = false;
+ success = Util.FileMove(url, filename, newFilename);
+ if(success)
+ filename = newFilename;
+
+ //will update SqliteForceSensor
+ return (this);
+ }
public string FullURL
{
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 5133b222..b5263f8b 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -972,7 +972,7 @@ LogB.Information(" re C ");
currentForceSensor.VideoURL =
Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.FORCESENSOR,
currentForceSensor.UniqueID);
- SqliteForceSensor.Update(false, currentForceSensor);
+ currentForceSensor.UpdateSQL(false);
label_video_feedback.Text = "";
button_video_play_this_test.Sensitive = true;
}
@@ -1332,6 +1332,8 @@ LogB.Information(" re R ");
//select row corresponding to current signal
genericWin.SelectRowWithID(0, currentForceSensor.UniqueID); //colNum, id
+ genericWin.CommentColumn = 7;
+
genericWin.ShowButtonCancel(true);
genericWin.SetButtonAcceptLabel(Catalog.GetString("Load"));
genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
@@ -1402,7 +1404,45 @@ LogB.Information(" re R ");
protected void on_force_sensor_load_signal_row_edit_apply (object o, EventArgs args)
{
LogB.Information("row edit apply at load signal. Opening db:");
- new DialogMessage(Constants.MessageTypes.INFO, "TODO");
+
+ Sqlite.Open();
+
+ //1) select set
+ int setID = genericWin.TreeviewSelectedUniqueID;
+ ForceSensor fs = (ForceSensor) SqliteForceSensor.Select(true, setID, -1, -1)[0];
+
+ //2) if changed comment, update SQL, and update treeview
+ //first remove conflictive characters
+ string comment = Util.RemoveTildeAndColonAndDot(genericWin.EntryEditRow);
+ if(comment != fs.Comments)
+ {
+ fs.Comments = comment;
+ fs.UpdateSQL(true);
+
+ //update treeview
+ genericWin.on_edit_selected_done_update_treeview();
+ }
+
+ //3) change the session param and the url of signal and curves (if any)
+ string idName = genericWin.GetComboSelected;
+ LogB.Information("new person: " + idName);
+ int newPersonID = Util.FetchID(idName);
+ if(newPersonID != currentPerson.UniqueID)
+ {
+ //change stuff on signal
+ ForceSensor fsChangedPerson = fs.ChangePerson(idName);
+ fsChangedPerson.UpdateSQL(true);
+ genericWin.RemoveSelectedRow();
+ genericWin.SetButtonAcceptSensitive(false);
+ }
+
+ genericWin.ShowEditRow(false);
+
+ //remove signal from gui just in case the edited signal is the same we have loaded
+ //removeSignalFromGuiBecauseDeletedOrCancelled();
+ blankForceSensorInterface();
+
+ Sqlite.Close();
}
protected void on_force_sensor_load_signal_row_delete_pre (object o, EventArgs args)
@@ -1517,7 +1557,7 @@ LogB.Information(" re R ");
currentForceSensor.Laterality = getLaterality(false);
currentForceSensor.Comments = getCaptureComment();
- SqliteForceSensor.Update(false, currentForceSensor);
+ currentForceSensor.UpdateSQL(false);
}
private void on_button_force_sensor_analyze_analyze_clicked (object o, EventArgs args)
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 7ac07143..daf209d2 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -690,16 +690,6 @@ class SqliteEncoder : Sqlite
Sqlite.Close();
}
- //when select from database, ensure path separators are ok for this platform
- //useful if person moved database between diff OS
- private static string fixOSpath(string url) {
- if(UtilAll.IsWindows())
- return url.Replace("/","\\");
- else
- return url.Replace("\\","/");
- }
-
-
/*
* EncoderExercise stuff
*/
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 33969adf..cdfbfcd9 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -62,8 +62,7 @@ class SqliteForceSensor : Sqlite
public static int Insert (bool dbconOpened, string insertString)
{
- if(! dbconOpened)
- Sqlite.Open();
+ openIfNeeded(dbconOpened);
dbcmd.CommandText = "INSERT INTO " + table +
" (uniqueID, personID, sessionID, exerciseID, captureOption, angle,
laterality, filename, url, dateTime, comments, videoURL)" +
@@ -75,30 +74,21 @@ class SqliteForceSensor : Sqlite
dbcmd.CommandText = myString;
int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since
`ExecuteScalar` returns an object.
- if(! dbconOpened)
- Sqlite.Close();
+ closeIfNeeded(dbconOpened);
return myLast;
}
- public static void Update (bool dbconOpened, ForceSensor fs)
+ public static void Update (bool dbconOpened, string updateString)
{
- if(! dbconOpened)
- Sqlite.Open();
+ openIfNeeded(dbconOpened);
- dbcmd.CommandText = "UPDATE " + table + " SET " +
- " exerciseID = " + fs.ExerciseID +
- ", captureOption = \"" + fs.CaptureOption.ToString() +
- "\", laterality = \"" + fs.Laterality +
- "\", comments = \"" + fs.Comments +
- "\", videoURL = \"" + Util.MakeURLrelative(fs.VideoURL) +
- "\" WHERE uniqueID = " + fs.UniqueID;
+ dbcmd.CommandText = "UPDATE " + table + " SET " + updateString;
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
- if(! dbconOpened)
- Sqlite.Close();
+ closeIfNeeded(dbconOpened);
}
/* right now unused
@@ -126,8 +116,7 @@ class SqliteForceSensor : Sqlite
//SELECT forceSensor.*, forceSensorExercise.Name FROM forceSensor, forceSensorExercise WHERE
forceSensor.exerciseID = forceSensorExercise.UniqueID ORDER BY forceSensor.uniqueID;
public static ArrayList Select (bool dbconOpened, int uniqueID, int personID, int sessionID)
{
- if(! dbconOpened)
- Sqlite.Open();
+ openIfNeeded(dbconOpened);
string selectStr = "SELECT " + table + ".*, " + Constants.ForceSensorExerciseTable + ".Name
FROM " + table + ", " + Constants.ForceSensorExerciseTable;
string whereStr = " WHERE " + table + ".exerciseID = " + Constants.ForceSensorExerciseTable +
".UniqueID ";
@@ -166,7 +155,7 @@ class SqliteForceSensor : Sqlite
Convert.ToInt32(reader[5].ToString()), //angle
reader[6].ToString(), //laterality
reader[7].ToString(), //filename
- reader[8].ToString(), //url
+ Util.MakeURLabsolute(fixOSpath(reader[8].ToString())), //url
reader[9].ToString(), //datetime
reader[10].ToString(), //comments
reader[11].ToString(), //videoURL
@@ -176,16 +165,14 @@ class SqliteForceSensor : Sqlite
}
reader.Close();
- if(! dbconOpened)
- Sqlite.Close();
+ closeIfNeeded(dbconOpened);
return array;
}
public static ArrayList SelectRowsOfAnExercise(bool dbconOpened, int exerciseID)
{
- if(! dbconOpened)
- Sqlite.Open();
+ openIfNeeded(dbconOpened);
dbcmd.CommandText = "select count(*), " +
Constants.PersonTable + ".name, " +
@@ -216,8 +203,7 @@ class SqliteForceSensor : Sqlite
}
reader.Close();
- if(! dbconOpened)
- Sqlite.Close();
+ closeIfNeeded(dbconOpened);
return array;
}
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index acb78df1..fc7fe332 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -3481,6 +3481,16 @@ LogB.SQL("5" + tableName);
/* methods for different classes */
+ //when select from database, ensure path separators are ok for this platform
+ //useful if person moved database between diff OS
+ protected static string fixOSpath(string url) {
+ if(UtilAll.IsWindows())
+ return url.Replace("/","\\");
+ else
+ return url.Replace("\\","/");
+ }
+
+
protected static double selectDouble (string sqlSelect)
{
dbcmd.CommandText = sqlSelect;
diff --git a/src/util.cs b/src/util.cs
index d4b6fd3e..cf339f4f 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1299,7 +1299,7 @@ public class Util
public static bool FileMove(string path, string filenameOrigin, string filenameDestination)
{
LogB.Information(string.Format("Going to move: {0} to {1}",
- path + Path.DirectorySeparatorChar + filenameOrigin
+ path + Path.DirectorySeparatorChar + filenameOrigin,
path + Path.DirectorySeparatorChar + filenameDestination
));
try {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]