[chronojump] DB: 2.01 RunEncoderExercise with segmentMeters, edit/add work



commit 8906081942c4730abc20fa0bdf703103cdc6a127
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Oct 4 22:58:34 2020 +0200

    DB: 2.01 RunEncoderExercise with segmentMeters, edit/add work

 src/gui/app1/runEncoder.cs | 23 +++++++++++++++++++++--
 src/runEncoder.cs          | 11 +++++++++--
 src/sqlite/main.cs         | 16 +++++++++++++++-
 src/sqlite/runEncoder.cs   | 17 ++++++++++-------
 4 files changed, 55 insertions(+), 12 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 43ad2947..c96c02f8 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -988,6 +988,7 @@ public partial class ChronoJumpWindow
                                currentPersonSession.Height,
                                race_analyzer_temperature,
                                race_analyzer_device,
+                               currentRunEncoderExercise, //TODO: do not let capture if there's no exercise
                                title,
                                currentRunEncoder.DateTimePublic,
                                preferences.runEncoderMinAccel,
@@ -1388,6 +1389,7 @@ public partial class ChronoJumpWindow
 
                ArrayList a1 = new ArrayList();
                ArrayList a2 = new ArrayList();
+               ArrayList a3 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
                a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(ex.Name);
@@ -1396,6 +1398,9 @@ public partial class ChronoJumpWindow
                a2.Add(Constants.GenericWindowShow.ENTRY2); a2.Add(true); a2.Add(ex.Description);
                bigArray.Add(a2);
 
+               a3.Add(Constants.GenericWindowShow.SPININT2); a3.Add(true); a3.Add("");
+               bigArray.Add(a3);
+
                genericWin = GenericWindow.Show(Catalog.GetString("Exercise"), false,   //don't show now
                                Catalog.GetString("Force sensor exercise:"), bigArray);
                genericWin.LabelEntry2 = Catalog.GetString("Description");
@@ -1404,6 +1409,9 @@ public partial class ChronoJumpWindow
                genericWin.HideOnAccept = false;
 
                genericWin.uniqueID = ex.UniqueID;
+               genericWin.LabelSpinInt2 = "Segments size (m)";
+               genericWin.SetSpin2Range(1, 30);
+               genericWin.SetSpin2Value(ex.SegmentMeters);
 
                genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_edit_accepted);
                genericWin.Button_accept.Clicked += new 
EventHandler(on_button_run_encoder_exercise_edit_accepted);
@@ -1416,6 +1424,7 @@ public partial class ChronoJumpWindow
 
                ArrayList a1 = new ArrayList();
                ArrayList a2 = new ArrayList();
+               ArrayList a3 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
                a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add("");
@@ -1424,6 +1433,9 @@ public partial class ChronoJumpWindow
                a2.Add(Constants.GenericWindowShow.ENTRY2); a2.Add(true); a2.Add("");
                bigArray.Add(a2);
 
+               a3.Add(Constants.GenericWindowShow.SPININT2); a3.Add(true); a3.Add("");
+               bigArray.Add(a3);
+
                genericWin = GenericWindow.Show(Catalog.GetString("Exercise"), false,   //don't show now
                                Catalog.GetString("Write the name of the exercise:"), bigArray);
                genericWin.LabelEntry2 = Catalog.GetString("Description");
@@ -1431,6 +1443,10 @@ public partial class ChronoJumpWindow
                genericWin.SetButtonAcceptLabel(Catalog.GetString("Add"));
                genericWin.HideOnAccept = false;
 
+               genericWin.LabelSpinInt2 = "Segments size (m)";
+               genericWin.SetSpin2Range(1, 30);
+               genericWin.SetSpin2Value(RunEncoderExercise.SegmentMetersDefault);
+
                genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_run_encoder_exercise_add_accepted);
                genericWin.Button_accept.Clicked += new 
EventHandler(on_button_run_encoder_exercise_add_accepted);
                genericWin.ShowNow();
@@ -1488,9 +1504,12 @@ public partial class ChronoJumpWindow
                }
 
                if(adding)
-                       SqliteRunEncoderExercise.Insert(false, -1, name, genericWin.Entry2Selected);
+                       SqliteRunEncoderExercise.Insert(false, -1, name,
+                                       genericWin.Entry2Selected, genericWin.SpinInt2Selected);
                else {
-                       RunEncoderExercise ex = new RunEncoderExercise(genericWin.uniqueID, name, 
genericWin.Entry2Selected);
+                       RunEncoderExercise ex = new RunEncoderExercise(genericWin.uniqueID, name,
+                                       genericWin.Entry2Selected, genericWin.SpinInt2Selected);
+
                        SqliteRunEncoderExercise.Update(false, ex);
                }
 
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 2feb13a0..0dfb838c 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -249,6 +249,8 @@ public class RunEncoderExercise
        private int uniqueID;
        private string name;
        private string description;
+       private int segmentMeters;
+       public static int SegmentMetersDefault = 5;
 
        public RunEncoderExercise()
        {
@@ -259,16 +261,17 @@ public class RunEncoderExercise
                this.name = name;
        }
 
-       public RunEncoderExercise(int uniqueID, string name, string description)
+       public RunEncoderExercise(int uniqueID, string name, string description, int segmentMeters)
        {
                this.uniqueID = uniqueID;
                this.name = name;
                this.description = description;
+               this.segmentMeters = segmentMeters;
        }
 
        public override string ToString()
        {
-               return uniqueID.ToString() + ":" + name + ":" + description + ":";
+               return string.Format("{0}:{1}:{2}:{3}", uniqueID, name, description, segmentMeters);
        }
 
        public int UniqueID
@@ -283,6 +286,10 @@ public class RunEncoderExercise
        {
                get { return description; }
        }
+       public int SegmentMeters
+       {
+               get { return segmentMeters; }
+       }
 }
 
 public class RunEncoderGraph
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 82dd0e3b..c3fc5bc1 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -129,7 +129,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "2.00";
+       static string lastChronojumpDatabaseVersion = "2.01";
 
        public Sqlite()
        {
@@ -2771,6 +2771,20 @@ class Sqlite
 
                                currentVersion = updateVersion("2.00");
                        }
+                       if(currentVersion == "2.00")
+                       {
+                               LogB.SQL("RunEncoderExercise ALTER TABLE: added column segmentMeters");
+                               try {
+                                       //sqlite does not have drop column
+                                       executeSQL("ALTER TABLE " + Constants.RunEncoderExerciseTable + " ADD 
COLUMN segmentMeters INT DEFAULT 5;");
+                               } catch {
+                                       LogB.SQL("Catched. ");
+
+                               }
+                               LogB.SQL("Done!");
+
+                               currentVersion = updateVersion("2.01");
+                       }
 
                        /*
                        if(currentVersion == "1.79")
diff --git a/src/sqlite/runEncoder.cs b/src/sqlite/runEncoder.cs
index e0becd6e..9eb1327d 100644
--- a/src/sqlite/runEncoder.cs
+++ b/src/sqlite/runEncoder.cs
@@ -328,7 +328,7 @@ class SqliteRunEncoder : Sqlite
 
                //need to create an exercise to assign to the imported files
                if(importedSomething)
-                       SqliteRunEncoderExercise.Insert(true, 0, "Sprint", "");
+                       SqliteRunEncoderExercise.Insert(true, 0, "Sprint", "", 
RunEncoderExercise.SegmentMetersDefault);
 
                LogB.Information("end of import_from_1_70_to_1_71()");
                //LogB.PrintAllThreads = false; //TODO: remove this
@@ -355,14 +355,15 @@ class SqliteRunEncoderExercise : Sqlite
                        "CREATE TABLE " + table + " ( " +
                        "uniqueID INTEGER PRIMARY KEY, " +
                        "name TEXT, " +
-                       "description TEXT)";
+                       "description TEXT, " +
+                       "segmentMeters INT)";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
        }
 
        //undefined defaultAngle will be 1000
        //note execution can have a different angle than the default angle
-       public static int Insert (bool dbconOpened, int uniqueID, string name, string description)
+       public static int Insert (bool dbconOpened, int uniqueID, string name, string description, int 
segmentMeters)
        {
                if(! dbconOpened)
                        Sqlite.Open();
@@ -372,8 +373,8 @@ class SqliteRunEncoderExercise : Sqlite
                        uniqueIDStr = uniqueID.ToString();
 
                dbcmd.CommandText = "INSERT INTO " + table +
-                               " (uniqueID, name, description) VALUES (" +
-                               uniqueIDStr + ", \"" + name + "\", \"" + description + "\")";
+                               " (uniqueID, name, description, segmentMeters) VALUES (" +
+                               uniqueIDStr + ", \"" + name + "\", \"" + description + "\", " + segmentMeters 
+ ")";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
 
@@ -401,7 +402,8 @@ class SqliteRunEncoderExercise : Sqlite
                dbcmd.CommandText = "UPDATE " + table + " SET " +
                        " name = \"" + ex.Name +
                        "\", description = \"" + ex.Description +
-                       "\" WHERE uniqueID = " + ex.UniqueID;
+                       "\", segmentMeters = " + ex.SegmentMeters +
+                       " WHERE uniqueID = " + ex.UniqueID;
 
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -458,7 +460,8 @@ class SqliteRunEncoderExercise : Sqlite
                                ex = new RunEncoderExercise (
                                                Convert.ToInt32(reader[0].ToString()),  //uniqueID
                                                reader[1].ToString(),                   //name
-                                               reader[2].ToString()                    //description
+                                               reader[2].ToString(),                   //description
+                                               Convert.ToInt32(reader[3].ToString())   //segmentMeters
                                                );
                                array.Add(ex);
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]