[chronojump] runI distanceInterval can be changed on edit test (except agility, fixed and rsa)



commit c64859977c8fe72ad1c9bba8ff9edd006e21931f
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Aug 31 17:45:08 2022 +0200

    runI distanceInterval can be changed on edit test (except agility, fixed and rsa)

 src/gui/app1/chronojump.cs  |  8 ++++--
 src/gui/event.cs            | 24 ++++++++++++++--
 src/gui/person/addModify.cs |  2 +-
 src/gui/run.cs              | 67 +++++++++++++++++++++++++++++++++++++++------
 src/sqlite/run.cs           |  6 ++--
 src/sqlite/runInterval.cs   |  4 ++-
 6 files changed, 91 insertions(+), 20 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 14a856650..fc61f96c8 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -6692,10 +6692,12 @@ LogB.Debug("mc finished 5");
                RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, 
myTreeViewRunsInterval.EventSelectedID, false, false );
 
                //if person changed, fill treeview again, if not, only update it's line
-               if(eventOldPerson == myRun.PersonID)
-                       myTreeViewRunsInterval.Update(myRun);
-               else
+               //distanceChanged is also managed with no problems because TreeViewEvent.Update has been 
extend to work with two level treeviews
+               if ( eventOldPerson != myRun.PersonID )// ||
+                               //(editRunIntervalWin != null && editRunIntervalWin.DistanceChanged) )
                        pre_fillTreeView_runs_interval(false);
+               else
+                       myTreeViewRunsInterval.Update(myRun);
 
                if(createdStatsWin)
                        stats_win_fillTreeView_stats(false, false);
diff --git a/src/gui/event.cs b/src/gui/event.cs
index 2b21f9afe..0dba5fb98 100644
--- a/src/gui/event.cs
+++ b/src/gui/event.cs
@@ -124,6 +124,9 @@ public class EditEventWindow
 
        protected int oldPersonID; //used to record the % for old person if we change it
 
+       //to know if changed or not in order to redo the treeview
+       //public double distanceAtInit;
+
        //for inheritance
        protected EditEventWindow () {
        }
@@ -168,6 +171,7 @@ public class EditEventWindow
                showLimited = true;
                //showAngle = true; //kneeAngle
                showMistakes = false;
+               //distanceAtInit = 0;
 
                label_simulated.Hide();
        }
@@ -494,7 +498,8 @@ public class EditEventWindow
                }
        }
        
-       private void on_entry_distance_changed (object o, EventArgs args) {
+       protected virtual void on_entry_distance_changed (object o, EventArgs args)
+       {
                if(Util.IsNumber(entry_distance_value.Text.ToString(), distanceCanBeDecimal)){
                        entryDistance = entry_distance_value.Text.ToString();
                        label_speed_value.Text = Util.TrimDecimals(
@@ -506,7 +511,7 @@ public class EditEventWindow
                        //entry_distance_value.Text = entryDistance;
                }
        }
-               
+
        private void on_entry_weight_value_changed (object o, EventArgs args) {
                if(Util.IsNumber(entry_weight_value.Text.ToString(), true)){
                        entryWeight = entry_weight_value.Text.ToString();
@@ -587,6 +592,19 @@ public class EditEventWindow
                get { return button_accept;     }
        }
 
+       /*
+          unused
+       public bool DistanceChanged
+       {
+               get {
+                       LogB.Information ("entry_distance_value: " + entry_distance_value.Text);
+                       if (distanceAtInit != 0 && distanceAtInit != 
Convert.ToDouble(entry_distance_value.Text))
+                               return true;
+                       return false;
+               }
+       }
+       */
+
        ~EditEventWindow() {}
 }
 
@@ -778,7 +796,7 @@ public class EventMoreWindow
                set { button_cancel = value; }
                get { return button_cancel; }
        }
-       
+
        public string SelectedEventName
        {
                set { selectedEventName = value; }
diff --git a/src/gui/person/addModify.cs b/src/gui/person/addModify.cs
index 349ef1cd4..1b169d7ba 100644
--- a/src/gui/person/addModify.cs
+++ b/src/gui/person/addModify.cs
@@ -1189,7 +1189,7 @@ public class PersonAddModifyWindow
                        Run mRun = SqliteRun.SelectRunData(Convert.ToInt32(margaria[1]), false);
                        double distanceMeters = mRun.Distance / 1000;
                        mRun.Description = "P = " + Util.TrimDecimals ( (weight * 9.8 * distanceMeters / 
mRun.Time).ToString(), pDN) + " (Watts)";
-                       SqliteRun.Update(mRun.UniqueID, mRun.Type, mRun.Distance.ToString(), 
mRun.Time.ToString(), mRun.PersonID, mRun.Description);
+                       SqliteRun.Update(mRun.UniqueID, mRun.Type, mRun.Distance, mRun.Time.ToString(), 
mRun.PersonID, mRun.Description);
                }
 
                string personName = Util.MakeValidSQLAndFileName(entry1.Text);
diff --git a/src/gui/run.cs b/src/gui/run.cs
index 478bd1ca5..136349e3f 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -182,8 +182,11 @@ public class EditRunWindow : EditEventWindow
        }
                
 
-       protected override void updateEvent(int eventID, int personID, string description) {
-               SqliteRun.Update(eventID, UtilGtk.ComboGetActive(combo_eventType), entryDistance, entryTime, 
personID, description);
+       protected override void updateEvent(int eventID, int personID, string description)
+       {
+               SqliteRun.Update (eventID, UtilGtk.ComboGetActive(combo_eventType),
+                               Convert.ToDouble (entry_distance_value.Text),
+                               entryTime, personID, description);
        }
 
        protected override void on_button_cancel_clicked (object o, EventArgs args)
@@ -250,6 +253,9 @@ public class EditRunIntervalWindow : EditRunWindow
 
        static EditRunIntervalWindow EditRunIntervalWindowBox;
 
+       private double tracks = -1;
+       private string distancesString; //to manage agility/non agility tests in order to know totalDistance, 
this will not change
+
        EditRunIntervalWindow (Gtk.Window parent) {
                Glade.XML gladeXML;
                gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "edit_event.glade", "edit_event", 
null);
@@ -502,12 +508,18 @@ public class EditRunIntervalWindow : EditRunWindow
        protected override void fillDistance(Event myEvent)
        {
                RunInterval myRun = (RunInterval) myEvent;
-               string distancesString = "";
+
+               //distanceAtInit = 0;
+               tracks = myRun.Tracks;
+
+               //string distancesString = "";
+               distancesString = "";
+               List<object> selectRunITypes_l = SqliteRunIntervalType.SelectRunIntervalTypesNew ("", false);
+               entry_distance_value.Sensitive = false;
 
                //1 on agility test show the distances string in meters
                if (myRun.DistanceInterval < 0)
                {
-                       List<object> selectRunITypes_l = SqliteRunIntervalType.SelectRunIntervalTypesNew ("", 
false);
                        if (selectRunITypes_l != null && selectRunITypes_l.Count > 0)
                                distancesString = SelectRunITypes.RunIntervalTypeDistancesString (myRun.Type, 
selectRunITypes_l);
                }
@@ -520,9 +532,18 @@ public class EditRunIntervalWindow : EditRunWindow
                        //2 on the rest of tests show interval x times
                        entry_distance_value.Text = myRun.DistanceInterval.ToString();
                        label_distance_units.Show ();
-               }
 
-               entry_distance_value.Sensitive = false;
+                       if (selectRunITypes_l != null && selectRunITypes_l.Count > 0)
+                               foreach (SelectRunITypes srit in selectRunITypes_l)
+                               {
+                                       if (srit.NameEnglish == myRun.Type && srit.Distance == 0)
+                                       {
+                                               entry_distance_value.Sensitive = true;
+                                               //distanceAtInit = myRun.DistanceInterval;
+                                               break;
+                                       }
+                               }
+               }
        }
 
        protected override void fillTime(Event myEvent) {
@@ -537,7 +558,24 @@ public class EditRunIntervalWindow : EditRunWindow
                //don't allow to change totaltime in rjedit
                entry_time_value.Sensitive = false; 
        }
-       
+
+       protected override void on_entry_distance_changed (object o, EventArgs args)
+       {
+               if (Util.IsNumber(entry_distance_value.Text.ToString(), distanceCanBeDecimal))
+               {
+                       label_speed_value.Text = Util.TrimDecimals(
+                                       Util.GetSpeed (
+                                               Util.GetRunITotalDistance 
(Convert.ToDouble(entry_distance_value.Text), distancesString, tracks), //TODO: check this ToDouble works on 
RSA
+                                               Convert.ToDouble (entryTime), //totalTime
+                                               metersSecondsPreferred) , pDN);
+                       button_accept.Sensitive = true;
+               } else {
+                       button_accept.Sensitive = false;
+                       //entry_distance_value.Text = "";
+                       //entry_distance_value.Text = entryDistance;
+               }
+       }
+
        protected override void fillSpeed(Event myEvent) {
                RunInterval myRun = (RunInterval) myEvent;
                label_speed_value.Text = Util.TrimDecimals( 
@@ -553,8 +591,19 @@ public class EditRunIntervalWindow : EditRunWindow
        }
 
 
-       protected override void updateEvent(int eventID, int personID, string description) {
-               SqliteRunInterval.Update(eventID, personID, description);
+       protected override void updateEvent (int eventID, int personID, string description)
+       {
+               LogB.Information (string.Format (
+                       "updateEvent eventID: {0}, entry_distance_value.Text: {1}, tracks: {2}, personID: 
{3}, description: {4}",
+                       eventID, entry_distance_value.Text, tracks, personID, description));
+
+               double distanceInterval = 0;
+               if (Util.IsNumber (entry_distance_value.Text, true))
+                       distanceInterval = Convert.ToDouble (entry_distance_value.Text);
+               else
+                       distanceInterval = -1;
+
+               SqliteRunInterval.Update (eventID, distanceInterval, tracks, personID, description);
        }
 
        protected override void on_button_cancel_clicked (object o, EventArgs args)
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index 524d89911..61cee27ad 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.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-2021   Xavier de Blas <xaviblas gmail com>
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -314,13 +314,13 @@ class SqliteRun : Sqlite
                return str;
        }
        
-       public static void Update(int runID, string type, string distance, string time, int personID, string 
description)
+       public static void Update(int runID, string type, double distance, string time, int personID, string 
description)
        {
                Sqlite.Open();
                dbcmd.CommandText = "UPDATE " + Constants.RunTable + 
                        " SET personID = " + personID + 
                        ", type = \"" + type +
-                       "\", distance = " + Util.ConvertToPoint(Convert.ToDouble(distance)) + 
+                       "\", distance = " + Util.ConvertToPoint(distance) +
                        ", time = " + Util.ConvertToPoint(Convert.ToDouble(time)) + 
                        ", description = \"" + description +
                        "\" WHERE uniqueID == " + runID ;
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index b5d2e69a0..cd3848dbf 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -260,11 +260,13 @@ class SqliteRunInterval : SqliteRun
                return myRun;
        }
 
-       public static void Update(int runID, int personID, string description)
+       public static void Update(int runID, double distanceInterval, double tracks, int personID, string 
description)
        {
                Sqlite.Open();
                dbcmd.CommandText = "UPDATE " + Constants.RunIntervalTable +
                        " SET personID = " + personID + 
+                       ", distanceInterval = " + Util.ConvertToPoint(distanceInterval) +
+                       ", distanceTotal = " + Util.ConvertToPoint (tracks * Convert.ToDouble 
(distanceInterval)) + //note the update only is applied to non agility tests
                        ", description = \"" + description +
                        "\" WHERE uniqueID == " + runID ;
                LogB.SQL(dbcmd.CommandText.ToString());


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