[chronojump] Capture trigger code fixed



commit 57b2035427fb13d232f100dbd755eac22d0546e3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Mar 31 18:43:20 2017 +0200

    Capture trigger code fixed

 src/encoderCapture.cs |    4 ++--
 src/gui/encoder.cs    |    2 +-
 src/sqlite/trigger.cs |    2 +-
 src/trigger.cs        |   18 +++++++++++++++---
 4 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 93ec555..f559a86 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -681,9 +681,9 @@ public abstract class EncoderCapture
                ((IDisposable)writer).Dispose();
        }
 
-       public void SaveTriggers()
+       public void SaveTriggers(int signalID)
        {
-               triggerList.SQLInsert();
+               triggerList.SQLInsert(signalID);
        }
        
        //this methods only applies to inertial subclass
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index c2a4eb0..f679298 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5744,7 +5744,7 @@ public partial class ChronoJumpWindow
 
                                        //save the triggers now that we have an encoderSignalUniqueID
                                        if(action == encoderActions.CURVES_AC)
-                                               eCapture.SaveTriggers(); //dbcon is closed
+                                               
eCapture.SaveTriggers(Convert.ToInt32(encoderSignalUniqueID)); //dbcon is closed
 
                                } else
                                        encoder_pulsebar_capture.Text = "";
diff --git a/src/sqlite/trigger.cs b/src/sqlite/trigger.cs
index d96e988..07ad3ce 100644
--- a/src/sqlite/trigger.cs
+++ b/src/sqlite/trigger.cs
@@ -92,7 +92,7 @@ class SqliteTrigger : Sqlite
                {
                        dbcmd.CommandText = "INSERT INTO " + table + 
                                " (uniqueID, mode, modeID, ms, inOut, name, color, comments) VALUES (" +
-                               trigger.ToSQL() + ")";
+                               trigger.ToSQLInsertString() + ")";
                        LogB.SQL(dbcmd.CommandText.ToString());
                        dbcmd.ExecuteNonQuery();
                }
diff --git a/src/trigger.cs b/src/trigger.cs
index e3671ea..2ec60cc 100644
--- a/src/trigger.cs
+++ b/src/trigger.cs
@@ -63,10 +63,14 @@ public class Trigger
                ms -= msToSubstract;
        }
 
-       public string ToSQL()
+       public string ToSQLInsertString()
        {
+                string idStr = uniqueID.ToString();
+                if(idStr == "-1")
+                        idStr = "NULL";
+
                return 
-                       uniqueID.ToString() + "," +
+                       idStr + "," +
                        "\"" + mode.ToString() + "\"" + "," +
                        modeID.ToString() + "," +
                        ms.ToString() + "," +
@@ -80,6 +84,10 @@ public class Trigger
        public int UniqueID {
                get { return uniqueID; }
        }
+
+       public int ModeID {
+               set { modeID = value; }
+       }
 }
 
 public class TriggerList
@@ -109,12 +117,16 @@ public class TriggerList
                        LogB.Information(trigger.ToString());
        }
 
-       public void SQLInsert()
+       public void SQLInsert(int signalID)
        {
                //save triggers to file (if any)
                if(l == null || l.Count == 0)
                        return;
 
+               //update triggers with encoderSignalUniqueID
+               foreach(Trigger trigger in l)
+                       trigger.ModeID = signalID;
+
                LogB.Debug("runEncoderCaptureCsharp SQL inserting triggers");
                SqliteTrigger.InsertList(false, l);
        }


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