[chronojump] Encoder tests can be deleted



commit be18f71f84d5083379ae27a5665914f318261ff9
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Sep 16 18:06:57 2014 +0200

    Encoder tests can be deleted

 glade/chronojump.glade      |  238 ++++++++++++++++++++++++++++++++-----------
 src/gui/encoder.cs          |  107 +++++++++++++------
 src/gui/encoderTreeviews.cs |    2 +-
 src/gui/genericWindow.cs    |   23 ++++-
 src/sqlite/encoder.cs       |   58 ++++++++++-
 src/sqlite/main.cs          |   18 +++-
 src/sqlite/personSession.cs |    4 +-
 src/sqlite/session.cs       |    4 +-
 8 files changed, 348 insertions(+), 106 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index cf72921..2984e38 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -6233,6 +6233,12 @@ Second Chronopic to platforms.</property>
                                                         <child>
                                                           <placeholder/>
                                                         </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">True</property>
@@ -6882,6 +6888,12 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -7665,6 +7677,12 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -8207,6 +8225,12 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -12239,8 +12263,8 @@ on current Chronojump version.</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
@@ -17381,8 +17405,8 @@ Just select and then close this window.</property>
                 <property name="icon-size">6</property>
               </widget>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="padding">4</property>
                 <property name="position">0</property>
               </packing>
@@ -17395,8 +17419,8 @@ Just select and then close this window.</property>
                 <property name="icon-size">6</property>
               </widget>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">1</property>
               </packing>
             </child>
@@ -17408,8 +17432,8 @@ Just select and then close this window.</property>
                 <property name="icon-size">6</property>
               </widget>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">2</property>
               </packing>
             </child>
@@ -17718,6 +17742,12 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -18168,6 +18198,12 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -19082,6 +19118,18 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -25022,7 +25070,6 @@ One serie can contain several tests.</property>
     </child>
   </widget>
   <widget class="GtkWindow" id="generic_window">
-    <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="border_width">10</property>
     <property name="title" translatable="yes">Chronojump</property>
@@ -25522,6 +25569,8 @@ One serie can contain several tests.</property>
               <widget class="GtkScrolledWindow" id="scrolled_window_textview">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
                 <property name="shadow_type">in</property>
                 <child>
                   <widget class="GtkTextView" id="textview">
@@ -25532,7 +25581,7 @@ One serie can contain several tests.</property>
               </widget>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">False</property>
+                <property name="fill">True</property>
                 <property name="position">10</property>
               </packing>
             </child>
@@ -25658,65 +25707,70 @@ One serie can contain several tests.</property>
           </packing>
         </child>
         <child>
-          <widget class="GtkHButtonBox" id="hbuttonbox42">
+          <widget class="GtkAlignment" id="alignment1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="spacing">10</property>
-            <property name="layout_style">edge</property>
-            <child>
-              <widget class="GtkButton" id="button_delete">
-                <property name="label">gtk-remove</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="on_button_delete_clicked" swapped="no"/>
-                <accelerator key="Escape" signal="clicked"/>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
+            <property name="top_padding">10</property>
             <child>
-              <widget class="GtkButton" id="button_cancel">
-                <property name="label">gtk-cancel</property>
+              <widget class="GtkHButtonBox" id="hbuttonbox42">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
-                <accelerator key="Escape" signal="clicked"/>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkButton" id="button_accept">
-                <property name="label">gtk-ok</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="on_button_accept_clicked" swapped="no"/>
+                <property name="can_focus">False</property>
+                <property name="spacing">10</property>
+                <property name="layout_style">edge</property>
+                <child>
+                  <widget class="GtkButton" id="button_delete">
+                    <property name="label">gtk-remove</property>
+                    <property name="can_focus">True</property>
+                    <property name="can_default">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_stock">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_cancel">
+                    <property name="label">gtk-cancel</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="can_default">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_stock">True</property>
+                    <signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
+                    <accelerator key="Escape" signal="clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_accept">
+                    <property name="label">gtk-ok</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="can_default">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_stock">True</property>
+                    <signal name="clicked" handler="on_button_accept_clicked" swapped="no"/>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
               </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
             </child>
           </widget>
           <packing>
             <property name="expand">False</property>
             <property name="fill">False</property>
-            <property name="padding">10</property>
+            <property name="pack_type">end</property>
             <property name="position">3</property>
           </packing>
         </child>
@@ -27174,6 +27228,42 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -29014,6 +29104,12 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </widget>
                             </child>
                           </widget>
@@ -29523,6 +29619,12 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -32005,6 +32107,12 @@ show elevation as:</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -32119,6 +32227,12 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -32248,6 +32362,12 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index ce3a04c..fcfafc6 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -748,7 +748,7 @@ public partial class ChronoJumpWindow
        void on_button_encoder_analyze_data_select_curves_clicked (object o, EventArgs args) 
        {
                ArrayList data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                "curve", EncoderSQL.Eccons.ALL, 
                                false, true);
 
@@ -845,7 +845,7 @@ public partial class ChronoJumpWindow
                string [] checkboxes = genericWin.GetCheckboxesStatus(1, false);
 
                ArrayList data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                "curve", EncoderSQL.Eccons.ALL, 
                                false, true);
 
@@ -892,7 +892,7 @@ public partial class ChronoJumpWindow
 
                int curveID = genericWin.TreeviewSelectedUniqueID;
                EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(
-                               false, curveID, 0, 0, 
+                               false, curveID, 0, 0, -1,
                                "", EncoderSQL.Eccons.ALL, 
                                false, true)[0];
 
@@ -943,7 +943,7 @@ public partial class ChronoJumpWindow
        void delete_encoder_curve(int uniqueID) {
                Log.WriteLine(uniqueID.ToString());
 
-               EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, uniqueID, 0, 0, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
+               EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, uniqueID, 0, 0, -1, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
                //remove the file
                bool deletedOk = Util.FileDelete(eSQL.GetFullURL(false));       //don't convertPathToR
                if(deletedOk)  {
@@ -987,7 +987,7 @@ public partial class ChronoJumpWindow
                foreach(Person p in dataPre) {
                        if(p.UniqueID != currentPerson.UniqueID) {
                                ArrayList eSQLarray = SqliteEncoder.Select(
-                                               false, -1, p.UniqueID, currentSession.UniqueID, 
+                                               false, -1, p.UniqueID, currentSession.UniqueID, -1, 
                                                "curve", EncoderSQL.Eccons.ALL, 
                                                false, true);
                                string [] s = { p.UniqueID.ToString(), "", p.Name,
@@ -1175,7 +1175,7 @@ public partial class ChronoJumpWindow
        void on_button_encoder_load_signal_clicked (object o, EventArgs args) 
        {
                ArrayList data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                "signal", EncoderSQL.Eccons.ALL, 
                                false, true);
 
@@ -1247,7 +1247,7 @@ public partial class ChronoJumpWindow
                genericWin.HideAndNull();
 
                ArrayList data = SqliteEncoder.Select(
-                               false, uniqueID, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, uniqueID, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                "signal", EncoderSQL.Eccons.ALL, 
                                false, true);
 
@@ -1295,7 +1295,7 @@ public partial class ChronoJumpWindow
                Log.WriteLine("row edit apply at load signal");
                        
                int curveID = genericWin.TreeviewSelectedUniqueID;
-               EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, curveID, 0, 0, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
+               EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, curveID, 0, 0, -1, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
                
                //if changed comment, update SQL, and update treeview
                //first remove conflictive characters
@@ -1341,7 +1341,7 @@ public partial class ChronoJumpWindow
                        on_button_encoder_delete_signal_accepted (o, args);
                else {
                        EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(
-                                       false, signalID, 0, 0, "signal", EncoderSQL.Eccons.ALL, false, 
true)[0];
+                                       false, signalID, 0, 0, -1, "signal", EncoderSQL.Eccons.ALL, false, 
true)[0];
                
                        //delete signal and related curves (both from SQL and files)
                        encoderSignalDelete(eSQL.GetFullURL(false), signalID);  //don't convertPathToR
@@ -1369,7 +1369,7 @@ public partial class ChronoJumpWindow
                {
                        //select related curves to find URL
                        EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(
-                                       false, esc.curveID, -1, -1, "curve", EncoderSQL.Eccons.ALL, false, 
true)[0];
+                                       false, esc.curveID, -1, -1, -1, "curve", EncoderSQL.Eccons.ALL, 
false, true)[0];
                        
                        //delete file
                        Util.FileDelete(eSQL.GetFullURL(false));        //don't convertPathToR
@@ -1566,7 +1566,7 @@ public partial class ChronoJumpWindow
        void on_button_encoder_delete_signal_accepted (object o, EventArgs args) 
        {
                EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(
-                               false, Convert.ToInt32(encoderSignalUniqueID), 0, 0, "signal", 
EncoderSQL.Eccons.ALL, false, true)[0];
+                               false, Convert.ToInt32(encoderSignalUniqueID), 0, 0, -1, "signal", 
EncoderSQL.Eccons.ALL, false, true)[0];
 
                //delete signal and related curves (both from SQL and files)
                encoderSignalDelete(eSQL.GetFullURL(false), Convert.ToInt32(encoderSignalUniqueID));
@@ -1591,7 +1591,7 @@ public partial class ChronoJumpWindow
 
        private void updateUserCurvesLabelsAndCombo() {
                ArrayList data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1, 
                                "curve", EncoderSQL.Eccons.ALL, 
                                false, true);
                int activeCurvesNum = getActiveCurvesNum(data);
@@ -1804,7 +1804,7 @@ public partial class ChronoJumpWindow
                if( ! check_encoder_analyze_signal_or_curves.Active)    //saved curves
                {
                        ArrayList data = SqliteEncoder.Select(
-                                       false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                                       false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1, 
                                        "curve", EncoderSQL.Eccons.ALL, 
                                        false, true);
 
@@ -2199,7 +2199,7 @@ public partial class ChronoJumpWindow
                        //onlyActive is false to have all the curves
                        //this is a need for "single" to select on display correct curve
                        data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1, 
                                "curve", ecconSelect, 
                                false, true);
 
@@ -2214,7 +2214,8 @@ public partial class ChronoJumpWindow
                                                dataPre = SqliteEncoder.Select(
                                                                false, -1, 
                                                                
Util.FetchID(encoderCompareInterperson[i].ToString()),
-                                                               currentSession.UniqueID,
+                                                               currentSession.UniqueID, 
+                                                               -1,
                                                                "curve", EncoderSQL.Eccons.ALL, 
                                                                true, true);
                                                //this curves are added to data, data included currentPerson, 
currentSession
@@ -2229,6 +2230,7 @@ public partial class ChronoJumpWindow
                                                                false, -1,
                                                                currentPerson.UniqueID, 
                                                                
Util.FetchID(encoderCompareIntersession[i].ToString()),
+                                                               -1,
                                                                "curve", EncoderSQL.Eccons.ALL,
                                                                true, true);
                                                //this curves are added to data, data included currentPerson, 
currentSession
@@ -2468,7 +2470,7 @@ public partial class ChronoJumpWindow
                else {
                        if(currentPerson != null) {
                                ArrayList data = SqliteEncoder.Select(
-                                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
-1,
                                                "curve", EncoderSQL.Eccons.ALL,
                                                false, true);
                                int activeCurvesNum = getActiveCurvesNum(data);
@@ -3140,7 +3142,10 @@ public partial class ChronoJumpWindow
                        exerciseName = Catalog.GetString(ex.name);
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
-               a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(exerciseName);
+
+               //name cannot be changed because we have to detect if new name already exists, check problems 
with translations,
+               //but most important, if user can change name and then click delete, it will be a mess to 
confirm that the type "newname" or "oldname" will be deleted
+               a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(false); a1.Add(exerciseName);
                bigArray.Add(a1);
 
                a2.Add(Constants.GenericWindowShow.SPININT); a2.Add(true); a2.Add("");
@@ -3181,6 +3186,7 @@ public partial class ChronoJumpWindow
                genericWin.Button_delete.Clicked += new EventHandler(on_button_encoder_exercise_delete);
                
                genericWin.nameOld = ex.name;
+               genericWin.uniqueID = ex.uniqueID;
                
                genericWin.Button_accept.Clicked += new 
EventHandler(on_button_encoder_exercise_edit_accepted);
                genericWin.ShowNow();
@@ -3246,7 +3252,7 @@ public partial class ChronoJumpWindow
                encoder_exercise_edit(true);
                genericWin.Button_accept.Clicked -= new EventHandler(on_button_encoder_exercise_add_accepted);
        }
-       
+                       
        void encoder_exercise_edit (bool adding) 
        {
                string name = Util.RemoveTildeAndColonAndDot(genericWin.EntrySelected);
@@ -3296,27 +3302,62 @@ public partial class ChronoJumpWindow
                }
        }
        
-       void on_button_encoder_exercise_delete (object o, EventArgs args) {
-               //TODO:
-               //select if there is encoder stuff with this encoder exercise   
-               //      TRUE: DialogMessage WARNING, or confirmWindow or confirmWindowJumpRun saying that 
there are tests on session X by person Y. Accept and exit
-               //      FALSE: confirmWindow or confirmWindowJumpRun saying that there are no tests. Confirm 
delete or cancel
-               //              CONFIRM: 
-               //                      delete encoder, encoderSignalCurve, encoder1RM table records with 
this exercise. 
-               //                      delete row from encoderExercise
-               //              CANCEL: close
+       void on_button_encoder_exercise_delete (object o, EventArgs args) 
+       {
+               ArrayList array = SqliteEncoder.SelectEncoderRowsOfAnExercise(false, genericWin.uniqueID); 
//dbconOpened, exerciseID
+
+               if(array.Count > 0) {
+                       //there are some records of this exercise on encoder table, do not delete
+                       genericWin.SetTextview(
+                                       Catalog.GetString("Sorry, this exercise cannot be deleted.") + "\n" +
+                                       Catalog.GetString("Please delete first the following repetitions:"));
+
+                       ArrayList nonSensitiveRows = new ArrayList();
+                       for(int i=0; i < array.Count; i ++)
+                               nonSensitiveRows.Add(i);
+
+                       genericWin.SetTreeview(
+                                       new string [] {
+                                       "count",        //not shown, unused
+                                       Catalog.GetString("Repetitions"), Catalog.GetString("Person"),
+                                       Catalog.GetString("Session"), Catalog.GetString("Date") }, 
+                                       false, array, nonSensitiveRows, Constants.ContextMenu.NONE, false);
+
+                       genericWin.ShowTextview();
+                       genericWin.ShowTreeview();
+                       genericWin.ShowButtonDelete(false);
+                       genericWin.DeletingExerciseHideSomeWidgets();
+               
+                       genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_edit_accepted);
+                       genericWin.Button_accept.Clicked += new 
EventHandler(on_button_encoder_exercise_do_not_delete);
+               } else {
+                       //encoder table has not records of this exercise
+                       //delete exercise
+                       Sqlite.Delete(false, Constants.EncoderExerciseTable, genericWin.uniqueID);
+                       //delete 1RM records of this exercise
+                       Sqlite.DeleteFromAnInt(false, Constants.Encoder1RMTable, "exerciseID", 
genericWin.uniqueID);
+
+                       genericWin.HideAndNull();
+                               
+                       combo_encoder_exercise.Active = 0;
 
-               new DialogMessage(Constants.MessageTypes.WARNING, 
-                               "TODO: Message on deleting exercise.");
+                       new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Exercise 
deleted."));
+               }
        }
 
+       //accept does not save changes, just closes window
+       void on_button_encoder_exercise_do_not_delete (object o, EventArgs args) {
+               genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_do_not_delete);
+               genericWin.HideAndNull();
+       }
+       
 
        /* sensitivity stuff */ 
                        
        //called when a person changes
        private void encoderPersonChanged() {
                ArrayList data = SqliteEncoder.Select(
-                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                               false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                "curve", EncoderSQL.Eccons.ALL, 
                                false, true);
                
@@ -4656,13 +4697,13 @@ public partial class ChronoJumpWindow
                                         */
                                        bool deletedUserCurves = false;
                                        EncoderSQL currentSignalSQL = (EncoderSQL) SqliteEncoder.Select(
-                                                       false, Convert.ToInt32(encoderSignalUniqueID), 0, 0, 
+                                                       false, Convert.ToInt32(encoderSignalUniqueID), 0, 0, 
-1,
                                                        "", EncoderSQL.Eccons.ALL, 
                                                        false, true)[0];
 
 
                                        ArrayList data = SqliteEncoder.Select(
-                                                       false, -1, currentPerson.UniqueID, 
currentSession.UniqueID, 
+                                                       false, -1, currentPerson.UniqueID, 
currentSession.UniqueID, -1,
                                                        "curve", EncoderSQL.Eccons.ALL,  
                                                        false, true);
                                        foreach(EncoderSQL eSQL in data) {
diff --git a/src/gui/encoderTreeviews.cs b/src/gui/encoderTreeviews.cs
index 77092d7..18db892 100644
--- a/src/gui/encoderTreeviews.cs
+++ b/src/gui/encoderTreeviews.cs
@@ -460,7 +460,7 @@ public partial class ChronoJumpWindow
                        totalMass = findMass(Constants.MassType.DISPLACED);
                } else {                                                //user curves
                        curvesData = SqliteEncoder.Select(
-                                       false, -1, currentPerson.UniqueID, currentSession.UniqueID, 
+                                       false, -1, currentPerson.UniqueID, currentSession.UniqueID, -1,
                                        "curve", EncoderSQL.Eccons.ALL, 
                                        true, true);
                }
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index 8c956ec..7fd6db3 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -104,6 +104,7 @@ public class GenericWindow
        private int commentColumn;
 
        //used on encoder edit exercise
+       public int uniqueID;
        public string nameOld;
 
        public GenericWindow ()
@@ -128,6 +129,7 @@ public class GenericWindow
                foreach(ArrayList widgetArray in array)
                        GenericWindowBox.showWidgetsPowerful(widgetArray);
 
+               GenericWindowBox.generic_window.Resizable = false;
                GenericWindowBox.label_header.Text = textHeader;
                //maybe more things have to be done before showing
                if(showNow)
@@ -691,7 +693,18 @@ Log.WriteLine("aaaaaaaaaaaaaaaa2");
                treeview.Selection.GetSelected (out model, out iter);
                store.SetValue (iter, commentColumn, entry_edit_row.Text);
        }
-       
+
+       //this method is only used when try to delete an encoder exercise,
+       //and cannot because there are encoder rows done with this exercise.
+       //Just unsensitive some stuff now in order to not be able to change them
+       public void DeletingExerciseHideSomeWidgets() {
+               hbox_spin_int.Hide();
+               hbox_entry2.Hide();
+               hbox_entry3.Hide();
+               hbox_spin_double2.Hide();
+
+               SetButtonAcceptLabel(Catalog.GetString("Close"));
+       }       
 
        public void RemoveSelectedRow () {
                store = UtilGtk.RemoveRow(treeview, store);
@@ -707,6 +720,14 @@ Log.WriteLine("aaaaaaaaaaaaaaaa2");
                //remove selected row from treeview
                store = UtilGtk.RemoveRow(treeview, store);
        }
+       
+       public void ShowTextview() {
+               scrolled_window_textview.Show();
+       }
+
+       public void ShowTreeview() {
+               scrolled_window_treeview.Show();
+       }
 
        public void ShowButtonDelete(bool show) {
                button_delete.Visible = show;
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index fe1ccb3..476e3d3 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -142,20 +142,21 @@ class SqliteEncoder : Sqlite
        }
        
        //pass uniqueID value and then will return one record. do like this:
-       //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
-       //don't care for the 0, 0 , because selection will be based on the myUniqueID and only one row will 
be returned
+       //EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, 0, "", 
EncoderSQL.Eccons.ALL, false, true)[0];
+       //don't care for the 0, 0, 0  because selection will be based on the myUniqueID and only one row will 
be returned
        //or
        //pass uniqueID==-1 and personID, sessionID, signalOrCurve values, and will return some records
        //personID can be -1 to get all on that session
        //sessionID can be -1 to get all sessions
+       //exerciseID can be -1 to get all exercises
        //signalOrCurve can be "all"
        
        //orderIDascendent is good for all the situations except when we want to convert from 1.05 to 1.06
        //in that conversion, we want first the last ones, and later the previous
        //      (to delete them if they are old copies)
        public static ArrayList Select (
-                       bool dbconOpened, int uniqueID, int personID, int sessionID, 
-                       string signalOrCurve, EncoderSQL.Eccons ecconSelect,    
+                       bool dbconOpened, int uniqueID, int personID, int sessionID, int exerciseID,
+                       string signalOrCurve, EncoderSQL.Eccons ecconSelect,
                        bool onlyActive, bool orderIDascendent)
        {
                if(! dbconOpened)
@@ -169,14 +170,18 @@ class SqliteEncoder : Sqlite
                if(sessionID != -1)
                        sessionIDStr = " sessionID = " + sessionID + " AND ";
 
+               string exerciseIDStr = "";
+               if(exerciseID != -1)
+                       exerciseIDStr = " exerciseID = " + exerciseID + " AND ";
+
                string selectStr = "";
                if(uniqueID != -1)
                        selectStr = Constants.EncoderTable + ".uniqueID = " + uniqueID;
                else {
                        if(signalOrCurve == "all")
-                               selectStr = personIDStr + sessionIDStr;
+                               selectStr = personIDStr + sessionIDStr + exerciseIDStr;
                        else
-                               selectStr = personIDStr + sessionIDStr + " signalOrCurve = '" + signalOrCurve 
+ "'";
+                               selectStr = personIDStr + sessionIDStr + exerciseIDStr + " signalOrCurve = '" 
+ signalOrCurve + "'";
                
                        if(ecconSelect != EncoderSQL.Eccons.ALL)
                                selectStr += " AND " + Constants.EncoderTable + ".eccon = '" + 
EncoderSQL.Eccons.ecS.ToString() + "'";
@@ -603,6 +608,47 @@ class SqliteEncoder : Sqlite
 
                return array;
        }
+
+
+       public static ArrayList SelectEncoderRowsOfAnExercise(bool dbconOpened, int exerciseID) 
+       {
+               if(! dbconOpened)
+                       dbcon.Open();
+
+               dbcmd.CommandText = "select count(*), " + 
+                       Constants.PersonTable + ".name, " +
+                       Constants.SessionTable + ".name, " + 
+                       Constants.SessionTable + ".date " + 
+                       " FROM " + Constants.EncoderTable + ", " + Constants.PersonTable + ", " + 
Constants.SessionTable +
+                       " WHERE exerciseID == " + exerciseID + 
+                       " AND " + Constants.PersonTable + ".uniqueID == " + Constants.EncoderTable + 
".personID " +
+                       " AND " + Constants.SessionTable + ".uniqueID == " + Constants.EncoderTable + 
".sessionID " + 
+                       " GROUP BY sessionID, personID";
+                       
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+
+               ArrayList array = new ArrayList();
+               int count = 0;
+               while(reader.Read()) {
+                       array.Add(new string [] {
+                                       count.ToString(),
+                                       reader[0].ToString(), //count
+                                       reader[1].ToString(), //person name
+                                       reader[2].ToString(), //session name
+                                       reader[3].ToString()  //session date
+                       });
+                       count ++;
+               }
+
+               reader.Close();
+               if(! dbconOpened)
+                       dbcon.Close();
+
+               return array;
+       }
        
        //conversion from DB 0.99 to 1.00
        protected internal static void putEncoderExerciseAnglesAt90() {
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index e1cf02c..a2aa73d 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -1499,8 +1499,8 @@ class Sqlite
                
                                SqliteEncoder.createTableEncoderSignalCurve();
 
-                               ArrayList signals = SqliteEncoder.Select(true, -1, -1, -1, "signal", 
EncoderSQL.Eccons.ALL, false, false);
-                               ArrayList curves = SqliteEncoder.Select(true, -1, -1, -1, "curve", 
EncoderSQL.Eccons.ALL, false, false);
+                               ArrayList signals = SqliteEncoder.Select(true, -1, -1, -1, -1, "signal", 
EncoderSQL.Eccons.ALL, false, false);
+                               ArrayList curves = SqliteEncoder.Select(true, -1, -1, -1, -1, "curve", 
EncoderSQL.Eccons.ALL, false, false);
                                int signalID;
                                conversionRateTotal = signals.Count;
                                conversionRate = 1;
@@ -2640,6 +2640,20 @@ Console.WriteLine("5" + tableName);
                        dbcon.Close();
        }
 
+       public static void DeleteFromAnInt(bool dbconOpened, string tableName, string colName, int id)
+       {
+               if( ! dbconOpened)
+                       dbcon.Open();
+
+               dbcmd.CommandText = "Delete FROM " + tableName +
+                       " WHERE " + colName + " == " + id;
+               Log.WriteLine(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+               
+               if( ! dbconOpened)
+                       dbcon.Close();
+       }
+
 
        /* end of methods for different classes */
        
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 059c7a6..ccc8ff0 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -424,7 +424,7 @@ class SqlitePersonSession : Sqlite
 
                //delete encoder signal and curves (and it's videos)
                ArrayList encoderArray = SqliteEncoder.Select(
-                               true, -1, Convert.ToInt32(personID), Convert.ToInt32(sessionID), 
+                               true, -1, Convert.ToInt32(personID), Convert.ToInt32(sessionID), -1,
                                "signal", EncoderSQL.Eccons.ALL,
                                false, true);
 
@@ -436,7 +436,7 @@ class SqlitePersonSession : Sqlite
                }
 
                encoderArray = SqliteEncoder.Select(
-                               true, -1, Convert.ToInt32(personID), Convert.ToInt32(sessionID), 
+                               true, -1, Convert.ToInt32(personID), Convert.ToInt32(sessionID), -1, 
                                "curve", EncoderSQL.Eccons.ALL, 
                                false, true);
                
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 56be195..89445f8 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -630,7 +630,7 @@ class SqliteSession : Sqlite
 
                //delete encoder signal and curves (and it's videos)
                ArrayList encoderArray = SqliteEncoder.Select(
-                               true, -1, -1, Convert.ToInt32(uniqueID), 
+                               true, -1, -1, Convert.ToInt32(uniqueID), -1,
                                "signal", EncoderSQL.Eccons.ALL,
                                false, true);
                
@@ -642,7 +642,7 @@ class SqliteSession : Sqlite
                }
                
                encoderArray = SqliteEncoder.Select(
-                               true, -1, -1, Convert.ToInt32(uniqueID), 
+                               true, -1, -1, Convert.ToInt32(uniqueID), -1,
                                "curve",  EncoderSQL.Eccons.ALL,
                                false, true);
                



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