[chronojump] Can download jumpType, jumpRjType from networks (pending rj unlimited)



commit dc6051601fb5acfa642c2eb9fdfd0859ecce2178
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Aug 3 13:40:14 2022 +0200

    Can download jumpType, jumpRjType from networks (pending rj unlimited)

 src/Makefile.am              |   1 +
 src/eventType.cs             |   5 ++
 src/gui/eventExecute.cs      |   5 +-
 src/gui/networks.cs          |  69 +++++++++++++++++++++--
 src/json/compujump.cs        |  99 +++++---------------------------
 src/json/compujumpEncoder.cs | 107 +++++++++++++++++++++++++++++++++++
 src/json/compujumpJumps.cs   | 131 +++++++++++++++++++++++++++++++++++++++++++
 src/sqlite/jumpType.cs       |  42 ++++++++++----
 src/sqlite/usefulObjects.cs  |  15 ++++-
 9 files changed, 372 insertions(+), 102 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a8e503de6..ef1d2fcdf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -212,6 +212,7 @@ SOURCES = \
        json/compujump.cs\
        json/compujumpEncoder.cs\
        json/compujumpForceSensor.cs\
+       json/compujumpJumps.cs\
        json/compujumpSprint.cs\
        json/compujumpOther.cs\
        json/exhibitions.cs\
diff --git a/src/eventType.cs b/src/eventType.cs
index 84e75534f..866658fba 100644
--- a/src/eventType.cs
+++ b/src/eventType.cs
@@ -63,6 +63,11 @@ public class EventType
                return false;
        }
        
+       public int UniqueID
+       {
+               get { return uniqueID; }
+       }
+
        /*
         * defined on webservice
         */
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index fc4f1c0cb..df7a6a17f 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -622,13 +622,16 @@ public partial class ChronoJumpWindow
        }
 
        // simple and DJ jump   
-       public void PrepareJumpSimpleGraph(PrepareEventGraphJumpSimple eventGraph, bool animate)
+       public void PrepareJumpSimpleGraph (PrepareEventGraphJumpSimple eventGraph, bool animate)
        {
                /*
                 * if not dj show heights
                 * and it is a single jump type, and it has tc, tv (it is a dj or similar)
                 * then show tc, tf
                 */
+               if (eventGraph == null)
+                       return;
+
                bool useHeights = true;
                if(! eventGraph.djShowHeights &&
                                eventGraph.type != "" && //it is a concrete type, not all jumps
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 83f5d7e4a..71c8a050a 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -1112,7 +1112,21 @@ public partial class ChronoJumpWindow
        private void getTasksExercisesAndPopup()
        {
                //1) get tasks
-               JsonCompujump json = new JsonCompujump(configChronojump.CompujumpDjango);
+               JsonCompujump json;
+
+               if(configChronojump.CompujumpStationMode == Constants.Modes.POWERGRAVITATORY ||
+                               configChronojump.CompujumpStationMode == Constants.Modes.POWERINERTIAL)
+               {
+                       json = new JsonCompujumpEncoder (configChronojump.CompujumpDjango);
+               }
+               else if(configChronojump.CompujumpStationMode == Constants.Modes.JUMPSSIMPLE ||
+                               configChronojump.CompujumpStationMode == Constants.Modes.JUMPSREACTIVE)
+               {
+                       json = new JsonCompujumpJumps (configChronojump.CompujumpDjango);
+               }
+               else
+                       return;
+
                string tasksStr = json.GetTasksResponse (currentPerson.UniqueID, 
configChronojump.CompujumpStationID);
 
                List<Task> tasks = new List<Task>();
@@ -1125,8 +1139,55 @@ public partial class ChronoJumpWindow
                                tasks = new TaskDeserialize().DeserializeTaskEncoder(tasksStr);
                }
 
-               //3) get exercises and insert if needed (only on encoder)
-               if(configChronojump.CompujumpStationMode == Constants.Modes.POWERGRAVITATORY ||
+               // 1) get tasks
+               // 3) get exercises and insert if needed (at the moment only for jumps and encoder)
+               // 3a) jumps
+               if(configChronojump.CompujumpStationMode == Constants.Modes.JUMPSSIMPLE ||
+                               configChronojump.CompujumpStationMode == Constants.Modes.JUMPSREACTIVE)
+               {
+                       List<object> jumpsSimpleExercisesOnLocal = SqliteJumpType.SelectJumpTypesNew (false, 
"", "", false);
+                       List<object> jumpsRjExercisesOnLocal = SqliteJumpType.SelectJumpRjTypesNew ("", 
false);
+
+                       //List<SelectJumpTypes> exRemote_l = json.GetJumpStationExercises 
(configChronojump.CompujumpStationID);
+                       json.GetJumpStationExercises (configChronojump.CompujumpStationID);
+
+                       // 3a1) Jumps simple
+                       foreach(SelectJumpTypes exRemote in json.JumpSimpleExercises_l)
+                       {
+                               bool found = false;
+                               foreach(SelectJumpTypes jLocal in jumpsSimpleExercisesOnLocal)
+                                       if(jLocal.Id == exRemote.Id)
+                                       {
+                                               found = true;
+                                               break;
+                                       }
+
+                               if(! found)
+                               {
+                                       SqliteJumpType.JumpTypeInsert (exRemote.Id, exRemote.ToSQLString (), 
false);
+                                       createComboSelectJumps (false);
+                               }
+                       }
+                       // 3a2) Jumps Reactive
+                       foreach(SelectJumpRjTypes exRemote in json.JumpRjExercises_l)
+                       {
+                               bool found = false;
+                               foreach(SelectJumpRjTypes jLocal in jumpsRjExercisesOnLocal)
+                                       if(jLocal.Id == exRemote.Id)
+                                       {
+                                               found = true;
+                                               break;
+                                       }
+
+                               if(! found)
+                               {
+                                       SqliteJumpType.JumpRjTypeInsert (exRemote.Id, exRemote.ToSQLString 
(), false);
+                                       createComboSelectJumpsRj (false);
+                               }
+                       }
+               }
+               // 3b) encoder
+               else if(configChronojump.CompujumpStationMode == Constants.Modes.POWERGRAVITATORY ||
                                configChronojump.CompujumpStationMode == Constants.Modes.POWERINERTIAL)
                {
                        Constants.EncoderGI type = Constants.EncoderGI.GRAVITATORY;
@@ -1134,7 +1195,7 @@ public partial class ChronoJumpWindow
                                type = Constants.EncoderGI.INERTIAL;
 
                        ArrayList encoderExercisesOnLocal = SqliteEncoder.SelectEncoderExercises(false, -1, 
false, type);
-                       List<EncoderExercise> exRemote_list = 
json.GetStationExercises(configChronojump.CompujumpStationID, type);
+                       List<EncoderExercise> exRemote_list = json.GetEncoderStationExercises 
(configChronojump.CompujumpStationID, type);
 
                        foreach(EncoderExercise exRemote in exRemote_list)
                        {
diff --git a/src/json/compujump.cs b/src/json/compujump.cs
index 00222d769..2d05dcaee 100644
--- a/src/json/compujump.cs
+++ b/src/json/compujump.cs
@@ -16,7 +16,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Copyright (C) 2016-2017 Carles Pina
- * Copyright (C) 2016-2021 Xavier de Blas
+ * Copyright (C) 2016-2022 Xavier de Blas
  */
 
 using System;
@@ -32,7 +32,13 @@ using Mono.Unix;
 
 public class JsonCompujump : Json
 {
-       private bool django;
+       protected bool django;
+       protected string exercisesFailedStr = Catalog.GetString("Could not get station exercises.");
+
+       //for inheritance
+       public JsonCompujump ()
+       {
+       }
 
        public JsonCompujump(bool django)
        {
@@ -310,94 +316,17 @@ public class JsonCompujump : Json
                return stations;
        }
 
-       //stationType can be GRAVITATORY or INERTIAL
-       public List<EncoderExercise> GetStationExercises(int stationId, Constants.EncoderGI stationType)
-       {
-               List<EncoderExercise> ex_list = new List<EncoderExercise>();
-
-               // Create a request using a URL that can receive a post.
-               if (! createWebRequest(requestType.AUTHENTICATED, "/api/v1/client/getStationExercises"))
-                       return ex_list;
-
-               // Set the Method property of the request to GET.
-               request.Method = "GET";
-
-               HttpWebResponse response;
-               if(! getHttpWebResponse (request, out response, Catalog.GetString("Could not get station 
exercises.")))
-                       return ex_list;
-
-               string responseFromServer;
-               using (var sr = new StreamReader(response.GetResponseStream()))
-               {
-                       responseFromServer = sr.ReadToEnd();
-               }
-
-               LogB.Information("GetStationExercises: " + responseFromServer);
-
-               if(responseFromServer == "")
-                       LogB.Information(" Empty "); //never happens
-               else if(responseFromServer == "[]")
-                       LogB.Information(" Empty2 "); //when rfid is not on server
-               else {
-                       ex_list = stationExercisesDeserialize(responseFromServer, stationId, stationType);
-               }
+       public List<SelectJumpTypes> JumpSimpleExercises_l;
+       public List<SelectJumpRjTypes> JumpRjExercises_l;
 
-               return ex_list;
+       public virtual void GetJumpStationExercises (int stationId)
+       {
        }
-       private List<EncoderExercise> stationExercisesDeserialize(string str, int stationId, 
Constants.EncoderGI stationType)
+       public virtual List<EncoderExercise> GetEncoderStationExercises (int stationId, Constants.EncoderGI 
stationType)
        {
-               List<EncoderExercise> ex_list = new List<EncoderExercise>();
-               JsonValue jsonStationExercises = JsonValue.Parse (str);
-
-               foreach (JsonValue jsonSE in jsonStationExercises)
-               {
-                       /*
-                          not needed, as exercises on the json are the related to our station
-                          and this code uses machineID, but the list jsonSEStation ["id"] contains logical 
instead of physical.
-                          so no need to check anything
-                       // 1) discard exercise if is not for this station
-                       JsonValue jsonSEStations = JsonValue.Parse (jsonSE["stations"].ToString());
-                       bool exerciseForThisStation = false;
-                       foreach (JsonValue jsonSEStation in jsonSEStations)
-                       {
-                               Int32 stations_id = jsonSEStation ["id"];
-                               if(stations_id == stationId)
-                                       exerciseForThisStation = true;
-                       }
-
-                       if(! exerciseForThisStation)
-                               continue;
-                       */
-
-                       // 2) discard if is not for this station type
-                       string type = jsonSE ["measurable"];
-                       Constants.EncoderGI newExEncoderGi = Constants.EncoderGI.GRAVITATORY;
-                       if(type == "I")
-                               newExEncoderGi = Constants.EncoderGI.INERTIAL;
-
-                       if(stationType != newExEncoderGi)
-                               continue;
-
-                       // 3) add exercise to the list
-                       Int32 newExId = jsonSE ["id"];
-                       string newExName = jsonSE ["name"];
-
-                       int newExPercentBodyMassDisplaced = 0;
-                       if(jsonSE ["measurable_info"]["percent_body_mass_displaced"] != null)
-                               newExPercentBodyMassDisplaced = jsonSE 
["measurable_info"]["percent_body_mass_displaced"];
-
-                       double newExSpeedAt1RM = 0;
-                       if(type == "G" && jsonSE ["measurable_info"]["speed_at_one_rm"] != null)
-                               newExSpeedAt1RM = Convert.ToDouble(Util.ChangeDecimalSeparator(
-                                                       jsonSE 
["measurable_info"]["speed_at_one_rm"].ToString() )); //ToString is mandatory
-
-                       ex_list.Add(new EncoderExercise(newExId, newExName, newExPercentBodyMassDisplaced,
-                                               "", "", newExSpeedAt1RM, newExEncoderGi));
-               }
-               return ex_list;
+               return new List<EncoderExercise> ();
        }
 
-
        /*
         * Unused, now using the above methods
         *
diff --git a/src/json/compujumpEncoder.cs b/src/json/compujumpEncoder.cs
index b38e41eda..9c48a7b67 100644
--- a/src/json/compujumpEncoder.cs
+++ b/src/json/compujumpEncoder.cs
@@ -20,9 +20,116 @@
  */
 
 using System;
+using System.Net;
+using System.IO;
+using System.Json;
 using System.Text;
 using System.Collections;
+using System.Collections.Generic; //List<>
 
+public class JsonCompujumpEncoder : JsonCompujump
+{
+       public JsonCompujumpEncoder (bool django)
+       {
+               this.django = django;
+
+               ResultMessage = "";
+       }
+
+       //stationType can be GRAVITATORY or INERTIAL
+       public override List<EncoderExercise> GetEncoderStationExercises (int stationId, Constants.EncoderGI 
stationType)
+       {
+               List<EncoderExercise> ex_list = new List<EncoderExercise>();
+
+               // Create a request using a URL that can receive a post.
+               if (! createWebRequest(requestType.AUTHENTICATED, "/api/v1/client/getStationExercises"))
+                       return ex_list;
+
+               // Set the Method property of the request to GET.
+               request.Method = "GET";
+
+               HttpWebResponse response;
+               if(! getHttpWebResponse (request, out response, exercisesFailedStr))
+                       return ex_list;
+
+               string responseFromServer;
+               using (var sr = new StreamReader(response.GetResponseStream()))
+               {
+                       responseFromServer = sr.ReadToEnd();
+               }
+
+               LogB.Information("GetStationExercises: " + responseFromServer);
+
+               if(responseFromServer == "")
+                       LogB.Information(" Empty "); //never happens
+               else if(responseFromServer == "[]")
+                       LogB.Information(" Empty2 "); //when rfid is not on server
+               else {
+                       ex_list = stationExercisesDeserialize(responseFromServer, stationId, stationType);
+               }
+
+               return ex_list;
+       }
+
+       private List<EncoderExercise> stationExercisesDeserialize (string str, int stationId, 
Constants.EncoderGI stationType)
+       {
+               List<EncoderExercise> ex_list = new List<EncoderExercise>();
+               JsonValue jsonStationExercises = JsonValue.Parse (str);
+
+               foreach (JsonValue jsonSE in jsonStationExercises)
+               {
+                       /*
+                          not needed, as exercises on the json are the related to our station
+                          and this code uses machineID, but the list jsonSEStation ["id"] contains logical 
instead of physical.
+                          so no need to check anything
+                       // 1) discard exercise if is not for this station
+                       JsonValue jsonSEStations = JsonValue.Parse (jsonSE["stations"].ToString());
+                       bool exerciseForThisStation = false;
+                       foreach (JsonValue jsonSEStation in jsonSEStations)
+                       {
+                               Int32 stations_id = jsonSEStation ["id"];
+                               if(stations_id == stationId)
+                                       exerciseForThisStation = true;
+                       }
+
+                       if(! exerciseForThisStation)
+                               continue;
+                       */
+
+                       // 2) discard if is not for this station type
+                       string type = jsonSE ["measurable"];
+                       Constants.EncoderGI newExEncoderGi = Constants.EncoderGI.GRAVITATORY;
+                       if(type == "E")
+                               newExEncoderGi = Constants.EncoderGI.GRAVITATORY;
+                       else if(type == "I")
+                               newExEncoderGi = Constants.EncoderGI.INERTIAL;
+                       else
+                               continue;
+
+                       if(stationType != newExEncoderGi)
+                               continue;
+
+                       // 3) add exercise to the list
+                       Int32 newExId = jsonSE ["id"];
+                       string newExName = jsonSE ["name"];
+
+                       int newExPercentBodyMassDisplaced = 0;
+                       if(jsonSE ["measurable_info"]["percent_body_mass_displaced"] != null)
+                               newExPercentBodyMassDisplaced = jsonSE 
["measurable_info"]["percent_body_mass_displaced"];
+
+                       double newExSpeedAt1RM = 0;
+                       if(type == "G" && jsonSE ["measurable_info"]["speed_at_one_rm"] != null)
+                               newExSpeedAt1RM = Convert.ToDouble(Util.ChangeDecimalSeparator(
+                                                       jsonSE 
["measurable_info"]["speed_at_one_rm"].ToString() )); //ToString is mandatory
+
+                       ex_list.Add(new EncoderExercise(newExId, newExName, newExPercentBodyMassDisplaced,
+                                               "", "", newExSpeedAt1RM, newExEncoderGi));
+               }
+               return ex_list;
+       }
+
+
+}
 
 public class UploadEncoderDataFullObject
 {
diff --git a/src/json/compujumpJumps.cs b/src/json/compujumpJumps.cs
new file mode 100644
index 000000000..0815a8188
--- /dev/null
+++ b/src/json/compujumpJumps.cs
@@ -0,0 +1,131 @@
+/*
+ * 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) 2022 Xavier de Blas
+ */
+
+using System;
+using System.Net;
+using System.IO;
+using System.Json;
+using System.Text;
+using System.Collections;
+using System.Collections.Generic; //List<>
+
+public class JsonCompujumpJumps : JsonCompujump
+{
+       public JsonCompujumpJumps (bool django)
+       {
+               this.django = django;
+
+               ResultMessage = "";
+       }
+
+       public override void GetJumpStationExercises (int stationId)
+       {
+               JumpSimpleExercises_l = new List<SelectJumpTypes> ();
+               JumpRjExercises_l = new List<SelectJumpRjTypes> ();
+
+               // Create a request using a URL that can receive a post.
+               if (! createWebRequest(requestType.AUTHENTICATED, "/api/v1/client/getStationExercises"))
+                       return;
+
+               // Set the Method property of the request to GET.
+               request.Method = "GET";
+
+               HttpWebResponse response;
+               if(! getHttpWebResponse (request, out response, exercisesFailedStr))
+                       return;
+
+               string responseFromServer;
+               using (var sr = new StreamReader(response.GetResponseStream()))
+               {
+                       responseFromServer = sr.ReadToEnd();
+               }
+
+               LogB.Information("GetStationExercises: " + responseFromServer);
+
+               if(responseFromServer == "")
+                       LogB.Information(" Empty "); //never happens
+               else if(responseFromServer == "[]")
+                       LogB.Information(" Empty2 "); //when rfid is not on server
+               else
+                       stationExercisesDeserialize(responseFromServer, stationId);
+       }
+
+       private void stationExercisesDeserialize (string str, int stationId)
+       {
+               JsonValue jsonStationExercises = JsonValue.Parse (str);
+
+               foreach (JsonValue jsonSE in jsonStationExercises)
+               {
+                       // 2) discard if is not for this station type
+                       string type = jsonSE ["measurable"];
+                       if(type != "J") //TODO: check jumpsMultiple
+                               continue;
+
+                       // 3) add exercise to the list
+                       Int32 newExId = jsonSE ["id"];
+                       string newExName = jsonSE ["name"];
+
+                       /*
+                          on the server put percent_additional_body_weight as 0 for sj and 100 for lj
+                          then here the 100 will be a hasWeight = true
+                          and user maybe can change it
+                          */
+                       bool hasWeight = false;
+                       if (jsonSE ["measurable_info"]["percent_additional_body_weight"] == 100)
+                               hasWeight = true;
+
+                       /*
+                       //the description is not being downloaded and the comment is not saved in the server
+                       string comment = "";
+                       JsonValue jsonSEStations = JsonValue.Parse (jsonSE["stations"].ToString());
+                       foreach (JsonValue jsonSEStation in jsonSEStations)
+                               comment = jsonSEStation ["comment"];
+                       */
+
+                       //TODO: think on unlimited jumps
+                       if (
+                                       (jsonSE ["measurable_info"]["jump_limit"] != null &&
+                                        jsonSE ["measurable_info"]["jump_limit"] > 1) ||
+                                       (jsonSE ["measurable_info"]["time_limit"] != null &&
+                                        jsonSE ["measurable_info"]["time_limit"] > 1) )
+                       {
+                               bool jumpsLimited;
+                               double fixedValue;
+                               if (jsonSE ["measurable_info"]["jump_limit"] != null &&
+                                               jsonSE ["measurable_info"]["jump_limit"] > 1)
+                               {
+                                       jumpsLimited = true;
+                                       fixedValue = jsonSE ["measurable_info"]["jump_limit"];
+                               } else {
+                                       jumpsLimited = false;
+                                       fixedValue = jsonSE ["measurable_info"]["time_limit"];
+                               }
+
+                               JumpRjExercises_l.Add (new SelectJumpRjTypes (newExId, newExName,
+                                                       (bool) jsonSE ["measurable_info"]["start_inside"],
+                                                       hasWeight, jumpsLimited, fixedValue, ""));
+                       }
+                       else
+                               JumpSimpleExercises_l.Add (new SelectJumpTypes (newExId, newExName,
+                                                       (bool) jsonSE ["measurable_info"]["start_inside"],
+                                                       hasWeight, ""));
+               }
+       }
+}
diff --git a/src/sqlite/jumpType.cs b/src/sqlite/jumpType.cs
index 5a60506cc..899cf2b0b 100644
--- a/src/sqlite/jumpType.cs
+++ b/src/sqlite/jumpType.cs
@@ -15,7 +15,7 @@
  *  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) 2004-2017   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -78,7 +78,7 @@ class SqliteJumpType : Sqlite
                                dbcmdTr.Transaction = tr;
        
                                foreach(string myJumpType in iniJumpTypes) {
-                                       JumpTypeInsert(myJumpType, true, dbcmdTr);
+                                       JumpTypeInsert(-1, myJumpType, true, dbcmdTr);
                                        conversionSubRate ++;
                                }
                        }
@@ -159,7 +159,7 @@ class SqliteJumpType : Sqlite
                                dbcmdTr.Transaction = tr;
 
                                foreach(string myJumpType in iniJumpTypes) {
-                                       JumpRjTypeInsert(myJumpType, true, dbcmdTr);
+                                       JumpRjTypeInsert(-1, myJumpType, true, dbcmdTr);
                                }
                        }
                        tr.Commit();
@@ -190,20 +190,30 @@ class SqliteJumpType : Sqlite
 
        //called from some Chronojump methods
        //adds dbcmd to be used on next Insert method
-       public static void JumpTypeInsert(string myJump, bool dbconOpened)
+       public static void JumpTypeInsert (string myJump, bool dbconOpened)
        {
-               JumpTypeInsert(myJump, dbconOpened, dbcmd);
+               JumpTypeInsert (-1, myJump, dbconOpened, dbcmd);
+       }
+       //used on networks when will force the server id of that exercise
+       public static void JumpTypeInsert (int uniqueID, string myJump, bool dbconOpened)
+       {
+               JumpTypeInsert (uniqueID, myJump, dbconOpened, dbcmd);
        }
        //Called from initialize
-       public static void JumpTypeInsert(string myJump, bool dbconOpened, SqliteCommand mycmd)
+       public static void JumpTypeInsert (int uniqueID, string myJump, bool dbconOpened, SqliteCommand mycmd)
        {
                string [] myStr = myJump.Split(new char[] {':'});
                if(! dbconOpened) {
                        Sqlite.Open();
                }
+               string uniqueIDstr = "NULL";
+               if (uniqueID >= 0)
+                       uniqueIDstr = uniqueID.ToString ();
+
                mycmd.CommandText = "INSERT INTO " + Constants.JumpTypeTable +  
                                " (uniqueID, name, startIn, weight, description)" +
-                               " VALUES (NULL, \""
+                               //" VALUES (NULL, \""
+                               " VALUES (" + uniqueIDstr + ", \""
                                + myStr[0] + "\", " + myStr[1] + ", " + //name, startIn
                                myStr[2] + ", \"" + myStr[3] + "\")" ;  //weight, description
                LogB.SQL(mycmd.CommandText.ToString());
@@ -215,20 +225,30 @@ class SqliteJumpType : Sqlite
 
        //called from some Chronojump methods
        //adds dbcmd to be used on next Insert method
-       public static void JumpRjTypeInsert(string myJump, bool dbconOpened)
+       public static void JumpRjTypeInsert (string myJump, bool dbconOpened)
        {
-               JumpRjTypeInsert(myJump, dbconOpened, dbcmd);
+               JumpRjTypeInsert (-1, myJump, dbconOpened, dbcmd);
+       }
+       //used on networks when will force the server id of that exercise
+       public static void JumpRjTypeInsert (int uniqueID, string myJump, bool dbconOpened)
+       {
+               JumpRjTypeInsert (uniqueID, myJump, dbconOpened, dbcmd);
        }
        //Called from initialize
-       public static void JumpRjTypeInsert(string myJump, bool dbconOpened, SqliteCommand mycmd)
+       public static void JumpRjTypeInsert (int uniqueID, string myJump, bool dbconOpened, SqliteCommand 
mycmd)
        {
                string [] myStr = myJump.Split(new char[] {':'});
                if(! dbconOpened) {
                        Sqlite.Open();
                }
+               string uniqueIDstr = "NULL";
+               if (uniqueID >= 0)
+                       uniqueIDstr = uniqueID.ToString ();
+
                mycmd.CommandText = "INSERT INTO " + Constants.JumpRjTypeTable + 
                                " (uniqueID, name, startIn, weight, jumpsLimited, fixedValue, description)" +
-                               " VALUES (NULL, \""
+                               //" VALUES (NULL, \""
+                               " VALUES (" + uniqueIDstr + ", \""
                                + myStr[0] + "\", " + myStr[1] + ", " + //name, startIn
                                myStr[2] + ", " + myStr[3] + ", " +     //weight, jumpsLimited
                                myStr[4] + ", \"" + myStr[5] + "\")" ;  //fixedValue, description
diff --git a/src/sqlite/usefulObjects.cs b/src/sqlite/usefulObjects.cs
index 6868e0ee3..e22415885 100644
--- a/src/sqlite/usefulObjects.cs
+++ b/src/sqlite/usefulObjects.cs
@@ -15,7 +15,7 @@
  *  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-2020   Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2017-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -152,6 +152,12 @@ public class SelectJumpTypes : SelectTypes
                this.HasWeight = hasWeight;
                this.Description = description;
        }
+
+       public string ToSQLString ()
+       {
+               return string.Format("{0}:{1}:{2}:{3}",
+                               NameEnglish, Util.BoolToInt (StartIn), Util.BoolToInt (HasWeight), 
Description);
+       }
 }
 
 public class SelectJumpRjTypes : SelectJumpTypes
@@ -175,6 +181,13 @@ public class SelectJumpRjTypes : SelectJumpTypes
                this.FixedValue = fixedValue;
                this.Description = description;
        }
+
+       public new string ToSQLString () //"new" to override inherited
+       {
+               return string.Format("{0}:{1}:{2}:{3}:{4}:{5}",
+                               NameEnglish, Util.BoolToInt (StartIn), Util.BoolToInt (HasWeight),
+                               Util.BoolToInt (JumpsLimited), Util.ConvertToPoint (FixedValue), Description);
+       }
 }
 
 public class SelectRunTypes : SelectTypes


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