[chronojump] force sensor SQL 75% done



commit 2cc29d1d5b301d1dad803508a310fa9a6316fbc6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 20 20:35:18 2017 +0200

    force sensor SQL 75% done

 chronojump.csproj                     |    4 +-
 diagrams/sqlite/chronojump_sqlite.dia |  Bin 14969 -> 15171 bytes
 glade/preferences_win.glade           |   13 ++--
 po/POTFILES.in                        |    1 +
 src/Makefile.am                       |    1 +
 src/constants.cs                      |    1 +
 src/forceSensor.cs                    |  111 +++++++++++++++++++++++++++++
 src/gui/chronojump.cs                 |    5 +-
 src/gui/preferences.cs                |  124 +++++++++++++++++++++++++-------
 src/preferences.cs                    |    2 +-
 src/sqlite/forceSensor.cs             |  125 +++++++++++++++++++++++++++++++++
 src/sqlite/main.cs                    |   16 ++++-
 12 files changed, 364 insertions(+), 39 deletions(-)
---
diff --git a/chronojump.csproj b/chronojump.csproj
index 30316b4..e70adb0 100644
--- a/chronojump.csproj
+++ b/chronojump.csproj
@@ -1118,6 +1118,8 @@
     <Compile Include="src\sqlite\trigger.cs" />
     <Compile Include="src\trigger.cs" />
     <Compile Include="src\forceSensor.cs" />
+    <Compile Include="src\sqlite\force.cs" />
+    <Compile Include="src\sqlite\forceSensor.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="src\" />
@@ -2164,4 +2166,4 @@
       </Properties>
     </MonoDevelop>
   </ProjectExtensions>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/diagrams/sqlite/chronojump_sqlite.dia b/diagrams/sqlite/chronojump_sqlite.dia
index 59bc8c2..4d90ae0 100644
Binary files a/diagrams/sqlite/chronojump_sqlite.dia and b/diagrams/sqlite/chronojump_sqlite.dia differ
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 2c87503..a467079 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -2898,8 +2898,7 @@ Other</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="active">1</property>
-                                        <property name="items">RAW
-Fitted</property>
+                                        <property name="items"/>
                                       </widget>
                                       <packing>
                                         <property name="expand">False</property>
@@ -3199,8 +3198,7 @@ Fitted</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="active">1</property>
-                                        <property name="items">RAW
-Fitted</property>
+                                        <property name="items"/>
                                       </widget>
                                       <packing>
                                         <property name="expand">False</property>
@@ -3500,8 +3498,7 @@ Fitted</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="active">1</property>
-                                        <property name="items">RAW
-Fitted</property>
+                                        <property name="items"/>
                                       </widget>
                                       <packing>
                                         <property name="expand">False</property>
@@ -3801,8 +3798,7 @@ Fitted</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="active">1</property>
-                                        <property name="items">RAW
-Fitted</property>
+                                        <property name="items"/>
                                       </widget>
                                       <packing>
                                         <property name="expand">False</property>
@@ -4054,6 +4050,7 @@ Fitted</property>
                                     <property name="can_focus">True</property>
                                     <property name="can_default">True</property>
                                     <property name="receives_default">False</property>
+                                    <signal name="clicked" handler="on_button_force_rfd_default_clicked" 
swapped="no"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ae939cf..1a7296f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,6 +59,7 @@ src/execute/pulse.cs
 src/execute/reactionTime.cs
 src/execute/run.cs
 src/exportSession.cs
+src/forceSensor.cs
 src/gui/chronojump.cs
 src/gui/chronopic.cs
 src/gui/chronopicRegister.cs
diff --git a/src/Makefile.am b/src/Makefile.am
index b03239f..410684f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -101,6 +101,7 @@ SOURCES = \
        sqlite/encoder.cs\
        sqlite/encoderConfiguration.cs\
        sqlite/executeAuto.cs\
+       sqlite/forceSensor.cs\
        sqlite/jump.cs\
        sqlite/jumpRj.cs\
        sqlite/jumpType.cs\
diff --git a/src/constants.cs b/src/constants.cs
index 89f2e58..8aca135 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -142,6 +142,7 @@ public class Constants
        public const string Encoder1RMTable = "encoder1RM";
        public const string ExecuteAutoTable = "executeAuto";
        public const string TriggerTable = "trigger";
+       public const string ForceRFDTable = "forceRFD";
 
        // Dummy variables that exists for translating purposes
        // pragma warning is to avoid warnings of "defined and not used" for these variables.
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 9b53f6a..f1aa751 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -21,7 +21,117 @@
 using System;
 using System.IO;               //for detect OS
 using System.Collections.Generic; //List<T>
+using Mono.Unix;
 
+public class ForceSensorRFD
+
+{
+       //if these names change, change FunctionPrint() below
+       public enum Functions { RAW, FITTED } //on SQL is inserted like this
+       private static string function_RAW_name = "RAW";
+       private static string function_FITTED_name = "Fitted";
+
+       //if these names change, change TypePrint() below
+       public enum Types { INSTANTANEOUS, AVERAGE, PERCENT_F_MAX, RFD_MAX } //on SQL is inserted like this
+       private static string type_INSTANTANEOUS_name = "Instantaneous";
+       private static string type_AVERAGE_name = "Average";
+       private static string type_PERCENT_F_MAX_name = "% Force max";
+       private static string type_RFD_MAX_name = "RFD max";
+
+       private string code; //RFD1...4
+       public bool active;
+       public Functions function;
+       public Types type;
+       public int num1;
+       public int num2;
+
+       public ForceSensorRFD(string code, bool active, Functions function, Types type, int num1, int num2)
+       {
+               this.code = code;
+               this.active = active;
+               this.function = function;
+               this.type = type;
+               this.num1 = num1;
+               this.num2 = num2;
+       }
+
+       public static string [] FunctionsArray(bool translated)
+       {
+               if(translated)
+                       return new string [] { Catalog.GetString(function_RAW_name), 
Catalog.GetString(function_FITTED_name) };
+               else
+                       return new string [] { function_RAW_name, function_FITTED_name };
+       }
+       public static string [] TypesArray(bool translated)
+       {
+               if(translated)
+                       return new string [] {
+                               Catalog.GetString(type_INSTANTANEOUS_name), 
Catalog.GetString(type_AVERAGE_name),
+                               Catalog.GetString(type_PERCENT_F_MAX_name), 
Catalog.GetString(type_RFD_MAX_name)
+                       };
+               else
+                       return new string [] {
+                               type_INSTANTANEOUS_name, type_AVERAGE_name, type_PERCENT_F_MAX_name, 
type_RFD_MAX_name
+                       };
+       }
+
+       public string FunctionPrint(bool translated)
+       {
+               if(function == Functions.RAW) {
+                       if(translated)
+                               return Catalog.GetString(function_RAW_name);
+                       else
+                               return function_RAW_name;
+               }
+
+               if(translated)
+                       return Catalog.GetString(function_FITTED_name);
+               else
+                       return function_FITTED_name;
+       }
+
+       public string TypePrint(bool translated)
+       {
+               if(type == Types.INSTANTANEOUS) {
+                       if(translated)
+                               return Catalog.GetString(type_INSTANTANEOUS_name);
+                       else
+                               return type_INSTANTANEOUS_name;
+               }
+               else if(type == Types.AVERAGE) {
+                       if(translated)
+                               return Catalog.GetString(type_AVERAGE_name);
+                       else
+                               return type_AVERAGE_name;
+               }
+               else if(type == Types.PERCENT_F_MAX) {
+                       if(translated)
+                               return Catalog.GetString(type_PERCENT_F_MAX_name);
+                       else
+                               return type_PERCENT_F_MAX_name;
+               }
+               else { //if(type == Types.RFD_MAX)
+                       if(translated)
+                               return Catalog.GetString(type_RFD_MAX_name);
+                       else
+                               return type_RFD_MAX_name;
+               }
+       }
+
+       public string ToSQLInsertString()
+       {
+               return
+                       "\"" + code  + "\"" + "," +
+                       Util.BoolToInt(active).ToString() + "," +
+                       "\"" + function.ToString() + "\"" + "," +
+                       "\"" + type.ToString() + "\"" + "," +
+                       num1.ToString() + "," +
+                       num2.ToString();
+       }
+
+}
+
+/*
 public class ForceSensor
 {
        double averageLength;
@@ -128,3 +238,4 @@ public class ForceSensor
                ((IDisposable)writer).Dispose();
        }
 }
+*/
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a653856..310c6ff 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -380,6 +380,7 @@ public partial class ChronoJumpWindow
        private TreeViewMultiChronopic myTreeViewMultiChronopic;
        
        private Preferences preferences;
+       private List<ForceSensorRFD> rfdList;
 
        private static Person currentPerson;
        private static Session currentSession;
@@ -548,6 +549,8 @@ public partial class ChronoJumpWindow
                //at initialization of chronojump and gives problems if this signals are raised while 
preferences are loading
                loadPreferences ();
 
+               rfdList = SqliteForceSensor.SelectAll(false);
+
                createTreeView_persons (treeview_persons);
 
                createTreeView_jumps (treeview_jumps);
@@ -2690,7 +2693,7 @@ public partial class ChronoJumpWindow
 
        private void on_preferences_activate (object o, EventArgs args) 
        {
-               preferencesWin = PreferencesWindow.Show(preferences, getMenuItemMode());
+               preferencesWin = PreferencesWindow.Show(preferences, rfdList, getMenuItemMode());
                
                preferencesWin.FakeButtonImported.Clicked += new 
EventHandler(on_preferences_import_configuration);
                preferencesWin.FakeButtonDebugModeStart.Clicked += new 
EventHandler(on_preferences_debug_mode_start);
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 72f7ec5..be8724e 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -27,6 +27,7 @@ using Glade;
 //using GLib; //for Value
 using System.Text; //StringBuilder
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using Mono.Unix;
 using System.Threading;
 using System.Globalization; //CultureInfo stuff
@@ -154,6 +155,22 @@ public class PreferencesWindow
        [Widget] Gtk.HBox hbox_force_2_from_to;
        [Widget] Gtk.HBox hbox_force_3_from_to;
        [Widget] Gtk.HBox hbox_force_4_from_to;
+       [Widget] Gtk.SpinButton spinbutton_force_1_at_ms;
+       [Widget] Gtk.SpinButton spinbutton_force_2_at_ms;
+       [Widget] Gtk.SpinButton spinbutton_force_3_at_ms;
+       [Widget] Gtk.SpinButton spinbutton_force_4_at_ms;
+       [Widget] Gtk.SpinButton spinbutton_force_1_at_percent;
+       [Widget] Gtk.SpinButton spinbutton_force_2_at_percent;
+       [Widget] Gtk.SpinButton spinbutton_force_3_at_percent;
+       [Widget] Gtk.SpinButton spinbutton_force_4_at_percent;
+       [Widget] Gtk.SpinButton spinbutton_force_1_from;
+       [Widget] Gtk.SpinButton spinbutton_force_2_from;
+       [Widget] Gtk.SpinButton spinbutton_force_3_from;
+       [Widget] Gtk.SpinButton spinbutton_force_4_from;
+       [Widget] Gtk.SpinButton spinbutton_force_1_to;
+       [Widget] Gtk.SpinButton spinbutton_force_2_to;
+       [Widget] Gtk.SpinButton spinbutton_force_3_to;
+       [Widget] Gtk.SpinButton spinbutton_force_4_to;
 
        //multimedia tab
        [Widget] Gtk.CheckButton checkbutton_volume;
@@ -187,6 +204,7 @@ public class PreferencesWindow
        static PreferencesWindow PreferencesWindowBox;
        
        private Preferences preferences; //stored to update SQL if anything changed
+       private List<ForceSensorRFD> rfdList; //stored to update SQL if anything changed
        private Thread thread;
 
        string databaseURL;
@@ -217,7 +235,8 @@ public class PreferencesWindow
                FakeButtonDebugModeStart = new Gtk.Button();
        }
        
-       static public PreferencesWindow Show (Preferences preferences, Constants.Menuitem_modes menu_mode)
+       static public PreferencesWindow Show (Preferences preferences, List <ForceSensorRFD> rfdList,
+                       Constants.Menuitem_modes menu_mode)
        {
                if (PreferencesWindowBox == null) {
                        PreferencesWindowBox = new PreferencesWindow ();
@@ -235,6 +254,7 @@ public class PreferencesWindow
                        PreferencesWindowBox.notebook.GetNthPage(FORCEPAGE).Hide();
 
                PreferencesWindowBox.preferences = preferences;
+               PreferencesWindowBox.rfdList = rfdList;
 
                PreferencesWindowBox.createComboLanguage();
 
@@ -507,8 +527,7 @@ public class PreferencesWindow
        private void initForceSensor ()
        {
                createForceCombos();
-
-               check_force_visibilities();
+               setRFDValues();
        }
 
        private void check_force_visibilities()
@@ -524,29 +543,17 @@ public class PreferencesWindow
                check_force_visibilities();
        }
 
-       //private static string [] forceTypes = {
-       //      "Instantaneous", "Average", "% Force max", "RFD max"
-       //};
-       private static string [] forceTypesTranslated = {
-               Catalog.GetString("Instantaneous"), Catalog.GetString("Average"),
-               Catalog.GetString("% Force max"), Catalog.GetString("RFD max")
-       };
        private void createForceCombos ()
        {
-               combo_force_1_function.Active = 0;
-               combo_force_2_function.Active = 0;
-               combo_force_3_function.Active = 0;
-               combo_force_4_function.Active = 0;
-
-               UtilGtk.ComboUpdate(combo_force_1_type, forceTypesTranslated, "");
-               UtilGtk.ComboUpdate(combo_force_2_type, forceTypesTranslated, "");
-               UtilGtk.ComboUpdate(combo_force_3_type, forceTypesTranslated, "");
-               UtilGtk.ComboUpdate(combo_force_4_type, forceTypesTranslated, "");
-
-               combo_force_1_type.Active = 0;
-               combo_force_2_type.Active = 0;
-               combo_force_3_type.Active = 0;
-               combo_force_4_type.Active = 0;
+               UtilGtk.ComboUpdate(combo_force_1_function, ForceSensorRFD.FunctionsArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_2_function, ForceSensorRFD.FunctionsArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_3_function, ForceSensorRFD.FunctionsArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_4_function, ForceSensorRFD.FunctionsArray(true), "");
+
+               UtilGtk.ComboUpdate(combo_force_1_type, ForceSensorRFD.TypesArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_2_type, ForceSensorRFD.TypesArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_3_type, ForceSensorRFD.TypesArray(true), "");
+               UtilGtk.ComboUpdate(combo_force_4_type, ForceSensorRFD.TypesArray(true), "");
        }
 
        private void on_combo_force_type_changed (object o, EventArgs args)
@@ -585,10 +592,8 @@ public class PreferencesWindow
        {
                //valid for active == "" and active == "RFD max"
                at_ms.Visible = false;
-               at_percent.Visible = false;
                from_to.Visible = false;
-
-               //LogB.Information("Selected:" + selected + ";");
+               at_percent.Visible = false;
 
                if(selected == Catalog.GetString("Instantaneous"))
                {
@@ -604,6 +609,71 @@ public class PreferencesWindow
                }
        }
 
+       private void setRFDValues ()
+       {
+               setRFDValue(rfdList[0], check_force_1, combo_force_1_function, combo_force_1_type,
+                               hbox_force_1_at_ms, spinbutton_force_1_at_ms,
+                               hbox_force_1_at_percent, spinbutton_force_1_at_percent,
+                               hbox_force_1_from_to, spinbutton_force_1_from, spinbutton_force_1_to);
+
+               setRFDValue(rfdList[1], check_force_2, combo_force_2_function, combo_force_2_type,
+                               hbox_force_2_at_ms, spinbutton_force_2_at_ms,
+                               hbox_force_2_at_percent, spinbutton_force_2_at_percent,
+                               hbox_force_2_from_to, spinbutton_force_2_from, spinbutton_force_2_to);
+
+               setRFDValue(rfdList[2], check_force_3, combo_force_3_function, combo_force_3_type,
+                               hbox_force_3_at_ms, spinbutton_force_3_at_ms,
+                               hbox_force_3_at_percent, spinbutton_force_3_at_percent,
+                               hbox_force_3_from_to, spinbutton_force_3_from, spinbutton_force_3_to);
+
+               setRFDValue(rfdList[3], check_force_4, combo_force_4_function, combo_force_4_type,
+                               hbox_force_4_at_ms, spinbutton_force_4_at_ms,
+                               hbox_force_4_at_percent, spinbutton_force_4_at_percent,
+                               hbox_force_4_from_to, spinbutton_force_4_from, spinbutton_force_4_to);
+       }
+
+       private void setRFDValue(ForceSensorRFD rfd, Gtk.CheckButton check, Gtk.ComboBox 
combo_force_function, Gtk.ComboBox combo_force_type,
+                               Gtk.HBox hbox_force_at_ms, Gtk.SpinButton spinbutton_force_at_ms,
+                               Gtk.HBox hbox_force_at_percent, Gtk.SpinButton spinbutton_force_at_percent,
+                               Gtk.HBox hbox_force_from_to, Gtk.SpinButton spinbutton_force_from, 
Gtk.SpinButton spinbutton_force_to)
+       {
+               check.Active = rfd.active;
+
+               combo_force_function.Active = UtilGtk.ComboMakeActive(combo_force_function, 
rfd.FunctionPrint(true));
+               combo_force_type.Active = UtilGtk.ComboMakeActive(combo_force_type, rfd.TypePrint(true));
+
+               hbox_force_at_ms.Visible = false;
+               hbox_force_at_percent.Visible = false;
+               hbox_force_from_to.Visible = false;
+
+               if(rfd.type == ForceSensorRFD.Types.INSTANTANEOUS)
+               {
+                       hbox_force_at_ms.Visible = true;
+                       spinbutton_force_at_ms.Value = rfd.num1;
+               }
+               else if(rfd.type == ForceSensorRFD.Types.AVERAGE)
+               {
+                       hbox_force_from_to.Visible = true;
+                       spinbutton_force_from.Value = rfd.num1;
+                       spinbutton_force_to.Value = rfd.num2;
+               }
+               else if(rfd.type == ForceSensorRFD.Types.PERCENT_F_MAX)
+               {
+                       hbox_force_at_percent.Visible = true;
+                       spinbutton_force_at_percent.Value = rfd.num1;
+               }
+       }
+
+       private void on_button_force_rfd_default_clicked (object o, EventArgs args)
+       {
+               Sqlite.Open();
+
+               SqliteForceSensor.DeleteAll(true);
+               SqliteForceSensor.InsertDefaultValues(true);
+
+               Sqlite.Close();
+       }
+
        // ---- end of Force sensor stuff
 
 
diff --git a/src/preferences.cs b/src/preferences.cs
index 25a0074..00115eb 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -76,7 +76,7 @@ public class Preferences
        public string language;
        public bool RGraphsTranslate;
        public bool useHeightsOnJumpIndexes;
-       
+
        /*
         * these are NOT sent to preferences window
         */
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
new file mode 100644
index 0000000..d627230
--- /dev/null
+++ b/src/sqlite/forceSensor.cs
@@ -0,0 +1,125 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Copyright (C) 2017   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+//using System.Data;
+using System.Collections.Generic; //List<T>
+using Mono.Data.Sqlite;
+
+class SqliteForceSensor : Sqlite
+{
+       private static string table = Constants.ForceRFDTable;
+
+       public SqliteForceSensor() {
+       }
+
+       ~SqliteForceSensor() {}
+
+       /*
+        * create and initialize tables
+        */
+
+       protected internal static void createTableForceRFD()
+       {
+               dbcmd.CommandText = 
+                       "CREATE TABLE " + table + " ( " +
+                       "code TEXT, " +         //RFD1...4
+                       "active INT, " +        //bool
+                       "function TEXT, " +
+                       "type TEXT, " +
+                       "num1 INT, " +
+                       "num2 INT )";
+               dbcmd.ExecuteNonQuery();
+       }
+
+       public static void InsertDefaultValues(bool dbconOpened)
+       {
+               openIfNeeded(dbconOpened);
+
+               Insert(true, new ForceSensorRFD("RFD1", true,
+                                       ForceSensorRFD.Functions.FITTED, ForceSensorRFD.Types.INSTANTANEOUS, 
0, -1));
+               Insert(true, new ForceSensorRFD("RFD2", true,
+                                       ForceSensorRFD.Functions.RAW, ForceSensorRFD.Types.AVERAGE, 0, 100));
+               Insert(true, new ForceSensorRFD("RFD3", false,
+                                       ForceSensorRFD.Functions.FITTED, ForceSensorRFD.Types.PERCENT_F_MAX, 
50, -1));
+               Insert(true, new ForceSensorRFD("RFD4", false,
+                                       ForceSensorRFD.Functions.RAW, ForceSensorRFD.Types.RFD_MAX, -1, -1));
+
+               closeIfNeeded(dbconOpened);
+       }
+
+       public static void Insert(bool dbconOpened, ForceSensorRFD rfd)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "INSERT INTO " + table +
+                       " (code, active, function, type, num1, num2) VALUES (" + rfd.ToSQLInsertString() + 
")";
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
+       //used when button_force_rfd_default is clicked
+       public static void DeleteAll(bool dbconOpened)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "DELETE FROM " + table;
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               closeIfNeeded(dbconOpened);
+       }
+
+       public static List<ForceSensorRFD> SelectAll (bool dbconOpened)
+       {
+               openIfNeeded(dbconOpened);
+
+               dbcmd.CommandText = "SELECT * FROM " + table;
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               List<ForceSensorRFD> l = new List<ForceSensorRFD>();
+               while(reader.Read()) {
+                       ForceSensorRFD rfd = new ForceSensorRFD(
+                                       reader[0].ToString(),                           //code
+                                       Util.IntToBool(Convert.ToInt32(reader[1])),     //active
+                                       (ForceSensorRFD.Functions) Enum.Parse(
+                                               typeof(ForceSensorRFD.Functions), reader[2].ToString()),      
  //function
+                                       (ForceSensorRFD.Types) Enum.Parse(
+                                               typeof(ForceSensorRFD.Types), reader[3].ToString()),    //type
+                                       Convert.ToInt32(reader[4]),                     //num1
+                                       Convert.ToInt32(reader[5])                      //num2
+                                       );
+                       l.Add(rfd);
+               }
+
+               reader.Close();
+               closeIfNeeded(dbconOpened);
+
+               return l;
+       }
+
+}
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index ec1bfb5..755a3fd 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.41";
+       static string lastChronojumpDatabaseVersion = "1.42";
 
        public Sqlite() {
        }
@@ -2168,6 +2168,16 @@ class Sqlite
                                currentVersion = updateVersion("1.41");
                        }
 
+                       if(currentVersion == "1.41")
+                       {
+                               LogB.SQL("Created and default values for ForceSensorRFD");
+
+                               SqliteForceSensor.createTableForceRFD();
+                               SqliteForceSensor.InsertDefaultValues(true);
+
+                               currentVersion = updateVersion("1.42");
+                       }
+
 
                        // --- add more updates here
                
@@ -2344,7 +2354,11 @@ class Sqlite
                SqliteChronopicRegister.createTableChronopicRegister();
                SqliteTrigger.createTableTrigger();
 
+               SqliteForceSensor.createTableForceRFD();
+               SqliteForceSensor.InsertDefaultValues(true);
+
                //changes [from - to - desc]
+               //1.41 - 1.42 Converted DB to 1.42 Created and default values for ForceSensorRFD
                //1.40 - 1.41 Converted DB to 1.41 Updated preferences maximized: from true/false to 
no/yes/undecorated
                //1.39 - 1.40 Converted DB to 1.40 Added to preferences: maximized, personWinHide, 
encoderCaptureShowOnlyBars
                //1.38 - 1.39 Converted DB to 1.39 Created trigger table 


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