[chronojump] 1RM can be saved manually



commit 21962f1509d2aaba9e7ae30b402e30d0d46b33cb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jun 8 20:37:03 2016 +0200

    1RM can be saved manually

 glade/chronojump.glade   |   90 ++++++++++++++++++++++++++++++++++++++++++---
 src/constants.cs         |    2 +-
 src/gui/encoder.cs       |   35 ++++++++++++++++++
 src/gui/executeAuto.cs   |    6 ++--
 src/gui/genericWindow.cs |   26 +++++++++++++-
 src/sqlite/encoder.cs    |   10 +++++-
 src/utilGtk.cs           |   10 ++++--
 7 files changed, 164 insertions(+), 15 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index c695b04..210bd62 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -16531,6 +16531,9 @@ on current Chronojump version.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -21220,6 +21223,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -22390,6 +22396,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -24052,6 +24061,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -24771,6 +24783,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -31834,6 +31849,30 @@ One set can contain several tests.</property>
               </packing>
             </child>
             <child>
+              <widget class="GtkHButtonBox" id="hbuttonbox_middle">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <widget class="GtkButton" id="button_middle">
+                    <property name="label" translatable="yes">button</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">10</property>
+              </packing>
+            </child>
+            <child>
               <widget class="GtkScrolledWindow" id="scrolled_window_textview">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -31850,7 +31889,7 @@ One set can contain several tests.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">10</property>
+                <property name="position">11</property>
               </packing>
             </child>
             <child>
@@ -31869,7 +31908,7 @@ One set can contain several tests.</property>
               <packing>
                 <property name="expand">True</property>
                 <property name="fill">True</property>
-                <property name="position">11</property>
+                <property name="position">12</property>
               </packing>
             </child>
             <child>
@@ -31964,7 +32003,7 @@ One set can contain several tests.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">12</property>
+                <property name="position">13</property>
               </packing>
             </child>
           </widget>
@@ -37732,6 +37771,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -40375,6 +40432,18 @@ 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>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -41630,9 +41699,6 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -42802,6 +42868,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
@@ -46858,6 +46927,9 @@ It starts before and arrives there with some speed.</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -47692,6 +47764,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -48541,6 +48616,9 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/constants.cs b/src/constants.cs
index 0aeed90..b4322c1 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -615,7 +615,7 @@ public class Constants
        //heightmetric contains 2 spins
        public enum GenericWindowShow {
                ENTRY, ENTRY2, ENTRY3, SPININT, SPININT2, SPININT3, SPINDOUBLE, HBOXSPINDOUBLE2, 
-               HEIGHTMETRIC, COMBO, COMBOALLNONESELECTED, TEXTVIEW, TREEVIEW
+               HEIGHTMETRIC, COMBO, COMBOALLNONESELECTED, BUTTONMIDDLE, TEXTVIEW, TREEVIEW
        }
 
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 4df923b..167497f 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -726,10 +726,18 @@ public partial class ChronoJumpWindow
 
                ArrayList bigArray = new ArrayList();
                ArrayList a1 = new ArrayList();
+               ArrayList a2 = new ArrayList();
+               ArrayList a3 = new ArrayList();
 
                //0 is the widgget to show; 1 is the editable; 2 id default value
                a1.Add(Constants.GenericWindowShow.TREEVIEW); a1.Add(true); a1.Add("");
                bigArray.Add(a1);
+               
+               a2.Add(Constants.GenericWindowShow.HBOXSPINDOUBLE2); a2.Add(true); a2.Add("");
+               bigArray.Add(a2);
+       
+               a3.Add(Constants.GenericWindowShow.BUTTONMIDDLE); a3.Add(true); a3.Add("");
+               bigArray.Add(a3);
        
                genericWin = GenericWindow.Show(false,  //don't show now
                                string.Format(Catalog.GetString("Saved 1RM values of athlete {0} on this 
session."), 
@@ -739,6 +747,10 @@ public partial class ChronoJumpWindow
                                bigArray);
 
                genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), 
Constants.ContextMenu.DELETE, false);
+               genericWin.LabelSpinDouble2 = Catalog.GetString("Manually add");
+               genericWin.SetSpinDouble2Increments(0.1,1);
+               genericWin.SetSpinDouble2Range(0,5000);
+               genericWin.SetButtonMiddleLabel(Catalog.GetString("Add"));
        
                //find all persons in current session
                ArrayList personsPre = SqlitePersonSession.SelectCurrentSessionPersons(
@@ -754,6 +766,9 @@ public partial class ChronoJumpWindow
                genericWin.SetButtonAcceptSensitive(true);
                genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
                //manage selected, unselected curves
+               genericWin.Button_middle.Clicked -= new EventHandler(on_encoder_1RM_win_row_added);
+               genericWin.Button_middle.Clicked += new EventHandler(on_encoder_1RM_win_row_added);
+               
                genericWin.Button_accept.Clicked += new 
EventHandler(on_spin_encoder_extra_weight_value_changed);
                genericWin.Button_row_delete.Clicked += new EventHandler(on_encoder_1RM_win_row_delete);
 
@@ -765,6 +780,26 @@ public partial class ChronoJumpWindow
                genericWin.ShowNow();
        }
 
+       private void on_encoder_1RM_win_row_added (object o, EventArgs args) 
+       {
+               LogB.Information("row adding at encoder 1RM");
+               
+               double d = genericWin.SpinDouble2Selected;
+               int uniqueID = SqliteEncoder.Insert1RM(false, currentPerson.UniqueID, 
currentSession.UniqueID, 
+                               getExerciseIDFromCombo (exerciseCombos.CAPTURE), 
genericWin.SpinDouble2Selected);
+
+               genericWin.Row_add(new string[] {
+                               uniqueID.ToString(), currentPerson.Name, 
UtilGtk.ComboGetActive(combo_encoder_exercise_capture),
+                               d.ToString(), DateTime.Now.ToShortDateString()
+                               }
+                               );
+               
+               array1RMUpdate(false);
+               encoder_change_displaced_weight_and_1RM ();
+               
+               LogB.Information("row added at encoder 1RM");
+       }
+
        protected void on_encoder_1RM_win_row_delete (object o, EventArgs args) {
                LogB.Information("row delete at encoder 1RM");
 
diff --git a/src/gui/executeAuto.cs b/src/gui/executeAuto.cs
index 88bf312..f0e9ce4 100644
--- a/src/gui/executeAuto.cs
+++ b/src/gui/executeAuto.cs
@@ -421,17 +421,17 @@ public class ExecuteAutoWindow
                {
                        treeviewSerie1Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie1, store_serie1, 
-                                       new String [] { treeviewSerie1Array.Count.ToString(), tc.trName } );
+                                       new String [] { treeviewSerie1Array.Count.ToString(), tc.trName }, 
false ); //at end
                } else if(treeviewNum == 2) 
                {
                        treeviewSerie2Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie2, store_serie2, 
-                                       new String [] { treeviewSerie2Array.Count.ToString(), tc.trName } );
+                                       new String [] { treeviewSerie2Array.Count.ToString(), tc.trName }, 
false ); //at end
                } else 
                {       //treeviewNum == 3
                        treeviewSerie3Array.Add(tc);
                        UtilGtk.TreeviewAddRow(treeview_serie3, store_serie3, 
-                                       new String [] { treeviewSerie3Array.Count.ToString(), tc.trName } );
+                                       new String [] { treeviewSerie3Array.Count.ToString(), tc.trName }, 
false ); //at end
                }
                
                button_save.Sensitive = (treeviewSerie1Array.Count > 0 && 
entry_save_name.Text.ToString().Length > 0);
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index dabc976..8b160fc 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -50,6 +50,9 @@ public class GenericWindow
 
        [Widget] Gtk.SpinButton spin_double;
        [Widget] Gtk.Box hbox_height_metric;
+       
+       [Widget] Gtk.HButtonBox hbuttonbox_middle;
+       [Widget] Gtk.Button button_middle;
 
        //Edit row
        [Widget] Gtk.Box hbox_edit_row;
@@ -193,6 +196,7 @@ public class GenericWindow
                hbox_edit_row.Hide();
                hbox_all_none_selected.Hide();
                hbox_combo_all_none_selected.Hide();
+               hbuttonbox_middle.Hide();
                scrolled_window_textview.Hide();
                scrolled_window_treeview.Hide();
        }
@@ -258,6 +262,9 @@ public class GenericWindow
                        hbox_combo_all_none_selected.Show();
                        hbox_all_none_selected.Show();
                }
+               else if(stuff == Constants.GenericWindowShow.BUTTONMIDDLE) {
+                       hbuttonbox_middle.Show();
+               }
                else if(stuff == Constants.GenericWindowShow.TEXTVIEW) {
                        scrolled_window_textview.Show();
                }
@@ -293,6 +300,8 @@ public class GenericWindow
                        combo.Show();
                        */
                }
+               else if(stuff == Constants.GenericWindowShow.BUTTONMIDDLE)
+                       hbuttonbox_middle.Show();
                else if(stuff == Constants.GenericWindowShow.TEXTVIEW)
                        scrolled_window_textview.Show();
                else //if(stuff == Constants.GenericWindowShow.TREEVIEW)
@@ -343,6 +352,9 @@ public class GenericWindow
        public void SetSpinDouble2Increments(double min, double max) {
                spin_double2.SetIncrements(min, max);
        }
+       public void SetSpinDouble2Range(double min, double max) {
+               spin_double2.SetRange(min, max);
+       }
        
        public void SetComboValues(string [] values, string current) {
                combo = ComboBox.NewText ();
@@ -451,7 +463,9 @@ public class GenericWindow
                //buttonRecuperateChangeSensitiveness();
        }
        
-       
+       public void SetButtonMiddleLabel(string str) {
+               button_middle.Label=str;
+       }
        
        public void SetTextview(string str) {
                TextBuffer tb = new TextBuffer (new TextTagTable());
@@ -788,6 +802,12 @@ public class GenericWindow
                store = UtilGtk.RemoveRow(treeview, store);
        }
        
+       public void Row_add(string [] row) {
+               //add row to treeview
+               UtilGtk.TreeviewAddRow(treeview, store, row, true); //insert at beginning
+       }
+       
+       
        public void ShowTextview() {
                scrolled_window_textview.Show();
        }
@@ -851,6 +871,10 @@ public class GenericWindow
                GenericWindowBox = null;
        }
        
+       public Button Button_middle {
+               get { return button_middle; }
+       }
+       
        public Button Button_delete {
                set { button_delete = value; }
                get { return button_delete; }
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 11c0d0f..6234b0f 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -871,7 +871,7 @@ class SqliteEncoder : Sqlite
                dbcmd.ExecuteNonQuery();
        }
        
-       public static void Insert1RM(bool dbconOpened, int personID, int sessionID, int exerciseID, double 
load1RM)     
+       public static int Insert1RM(bool dbconOpened, int personID, int sessionID, int exerciseID, double 
load1RM)      
        {
                if(! dbconOpened)
                        Sqlite.Open();
@@ -882,9 +882,17 @@ class SqliteEncoder : Sqlite
                                exerciseID + ", " + Util.ConvertToPoint(load1RM) + ", \"\",\"\",\"\")";
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
+               
+               //int myLast = dbcon.LastInsertRowId;
+               //http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+               string myString = @"select last_insert_rowid()";
+               dbcmd.CommandText = myString;
+               int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since 
`ExecuteScalar` returns an object.
 
                if(! dbconOpened)
                        Sqlite.Close();
+
+               return myLast;
        }
 
        public static ArrayList Select1RM (bool dbconOpened, int personID, int sessionID, int exerciseID, 
bool returnPersonNameAndExerciseName)
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 72c170b..ffd889d 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -314,11 +314,15 @@ public class UtilGtk
                return tv;
        }
 
-       public static void TreeviewAddRow(Gtk.TreeView tv, TreeStore store, string [] row) {
+       //startOrEnd is true at start, false at end
+       public static void TreeviewAddRow(Gtk.TreeView tv, TreeStore store, string [] row, bool startOrEnd) {
                TreeIter iter = new TreeIter();
                bool iterOk = store.GetIterFirst(out iter);
-                       
-               iter = store.AppendValues(row);
+               
+               if(startOrEnd)
+                       iter = store.InsertWithValues(0,row);
+               else
+                       iter = store.AppendValues(row);
 
                //scroll treeview if needed
                TreePath path = store.GetPath (iter);


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