[chronojump] ExportSession with stiffness. RJs subjumps with more data. less SQL calls



commit 77dc97e8e4c3304baced7cf480904af0ec987434
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Jan 11 16:48:54 2015 +0100

    ExportSession with stiffness. RJs subjumps with more data. less SQL calls

 src/exportSession.cs        |  171 +++++++++++++++++++++++++++----------------
 src/gui/chronojump.cs       |   10 ++-
 src/gui/encoder.cs          |   18 ++++-
 src/gui/event.cs            |    6 +-
 src/gui/executeAuto.cs      |    6 +-
 src/gui/person.cs           |   12 ++--
 src/gui/queryServer.cs      |    4 +-
 src/gui/session.cs          |   10 +-
 src/gui/stats.cs            |    5 +-
 src/person.cs               |   29 +++++++-
 src/report.cs               |    4 +-
 src/server.cs               |    8 +-
 src/sqlite/personSession.cs |  101 ++++++-------------------
 src/sqlite/speciallity.cs   |   13 ++-
 src/sqlite/sport.cs         |   12 ++-
 15 files changed, 229 insertions(+), 180 deletions(-)
---
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 1144b42..b7aaaf0 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.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-2014   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -28,7 +28,7 @@ using Mono.Unix;
 
 public class ExportSession
 {
-       protected ArrayList myPersons;
+       protected ArrayList myPersonsAndPS;
        protected string [] myJumps;
        protected string [] myJumpsRj;
        protected string [] myRuns;
@@ -149,7 +149,7 @@ public class ExportSession
        
        protected virtual void getData() 
        {
-               myPersons = SqlitePersonSession.SelectCurrentSessionPersons(mySession.UniqueID);
+               myPersonsAndPS = SqlitePersonSession.SelectCurrentSessionPersons(mySession.UniqueID, true);
                myJumps= SqliteJump.SelectJumps(false, mySession.UniqueID, -1, "", "");
                myJumpsRj = SqliteJumpRj.SelectJumps(mySession.UniqueID, -1, "", "");
                myRuns= SqliteRun.SelectRuns(false, mySession.UniqueID, -1, "");
@@ -225,30 +225,43 @@ public class ExportSession
                                Catalog.GetString ("Sport") + ":" + Catalog.GetString("Speciallity") + ":" +
                                Catalog.GetString ("Level") + ":" + Catalog.GetString ("Comments")
                           );
-       
-               foreach (Person p in myPersons) {
-                       PersonSession ps = SqlitePersonSession.Select(p.UniqueID, mySession.UniqueID);
-                       string sportName = (SqliteSport.Select(ps.SportID)).Name;
-                       string speciallityName = SqliteSpeciallity.Select(ps.SpeciallityID);
+
+               Sqlite.Open();  
+               foreach (PersonAndPS paps in myPersonsAndPS) {
+                       string sportName = (SqliteSport.Select(true, paps.ps.SportID)).Name;
+                       string speciallityName = SqliteSpeciallity.Select(true, paps.ps.SpeciallityID);
                        
                        myData.Add(
-                                       p.UniqueID.ToString() + ":" + p.Name + ":" +
-                                       p.Sex + ":" + p.DateBorn.ToShortDateString() + ":" +
-                                       Util.RemoveNewLine(p.Description, true) + ":" +
-                                       ps.Height + ":" + ps.Weight + ":" + 
+                                       paps.p.UniqueID.ToString() + ":" + paps.p.Name + ":" +
+                                       paps.p.Sex + ":" + paps.p.DateBorn.ToShortDateString() + ":" +
+                                       Util.RemoveNewLine(paps.p.Description, true) + ":" +
+                                       paps.ps.Height + ":" + paps.ps.Weight + ":" + 
                                        sportName + ":" + speciallityName + ":" +
-                                       Util.FindLevelName(ps.Practice) + ":" +
-                                       Util.RemoveNewLine(ps.Comments, true)
+                                       Util.FindLevelName(paps.ps.Practice) + ":" +
+                                       Util.RemoveNewLine(paps.ps.Comments, true)
                                  );
                }
+               Sqlite.Close(); 
                
                writeData(myData);
                writeData("VERTICAL-SPACE");
        }
+       
+       protected string getPower(double tc, double tf, double personWeight, double extraWeightInKg, double 
fall) 
+       {
+               int dec = preferences.digitsNumber; //decimals
+               if(tf > 0) {    
+                       if(tc > 0)              //dj
+                               return Util.TrimDecimals(Util.GetDjPower(tc, tf, (personWeight + 
extraWeightInKg), fall).ToString(), dec);
+                       else                    //it's a normal jump without tc
+                               return Util.TrimDecimals(Util.GetPower(tf, personWeight, 
extraWeightInKg).ToString(), dec);
+               }
+               return "-";
+       }
 
        protected void printJumps(string title)
        {
-               int dec=preferences.digitsNumber; //decimals
+               int dec = preferences.digitsNumber; //decimals
                
                string weightName = Catalog.GetString("Weight");
                if(preferences.weightStatsPercent)
@@ -271,6 +284,7 @@ public class ExportSession
                                        weightName + ":" + 
                                        Catalog.GetString("Height") + ":" +
                                        Catalog.GetString("Power") + ":" +
+                                       Catalog.GetString("Stiffness") + ":" +
                                        Catalog.GetString("Initial Speed") + ":" +
                                        Catalog.GetString("Description") + ":" +
                                        Catalog.GetString("Angle") + ":" +
@@ -278,45 +292,45 @@ public class ExportSession
                                  );
 
 
-                       Sqlite.Open();
                        foreach (string jumpString in myJumps) {
                                string [] myStr = jumpString.Split(new char[] {':'});
-                                       
-                               double personWeight = SqlitePersonSession.SelectAttribute(
-                                               true,   //dbconOpened
-                                               Convert.ToInt32(myStr[2]),
-                                               Convert.ToInt32(myStr[3]),
-                                               Constants.Weight);
-                               double weightInKg = Util.WeightFromPercentToKg(
+                       
+
+                               //find weight of person and extra weight
+                               int papsPosition = PersonAndPSUtil.Find(myPersonsAndPS, 
+                                               Convert.ToInt32(myStr[2])); //personID
+
+                               if(papsPosition == -1) {
+                                       LogB.Error("PersonsAndPSUtil don't found person:", myStr[2]);
+                                       return;
+                               }
+
+                               double personWeight = ((PersonAndPS) myPersonsAndPS[papsPosition]).ps.Weight;
+                               double extraWeightInKg = Util.WeightFromPercentToKg(
                                                        Convert.ToDouble(myStr[8]), 
                                                        personWeight);
 
-                               string myWeight = "";
+                               string extraWeightPrint = "";
                                if(preferences.weightStatsPercent)
-                                       myWeight = myStr[8];
+                                       extraWeightPrint = myStr[8];
                                else
-                                       myWeight = weightInKg.ToString();
+                                       extraWeightPrint = extraWeightInKg.ToString();
+                               
+                               //end of find weight of person and extra weight
                
                                double fall = Convert.ToDouble(myStr[7]);
                                double tc = Convert.ToDouble(myStr[6]);
                                double tf = Convert.ToDouble(myStr[5]);
-                               
-                               string power = "-";
-                               if(tf > 0) {    
-                                       if(tc > 0)              //dj
-                                               power = Util.TrimDecimals(Util.GetDjPower(tc, tf, 
(personWeight + weightInKg), fall).ToString(), dec);
-                                       else                    //it's a normal jump without tc
-                                               power = Util.TrimDecimals(Util.GetPower(tf, personWeight, 
weightInKg).ToString(), dec);
-                               }
 
                                myData.Add (    
                                                myStr[2] + ":" +  myStr[0] + ":" +      //person.UniqueID, 
person.Name
                                                myStr[1] + ":" +                        //jump.uniqueID
                                                myStr[4] + ":" +  Util.TrimDecimals(myStr[6], dec) + ":" +    
  //jump.type, jump.tc
-                                               Util.TrimDecimals(myStr[5], dec) + ":" +  myStr[7] + ":" +    
  //jump.tv, jump.fall
-                                               Util.TrimDecimals(myWeight, dec) + ":" +
+                                               Util.TrimDecimals(myStr[5], dec) + ":" +  
Util.TrimDecimals(myStr[7], dec) + ":" +      //jump.tv, jump.fall
+                                               Util.TrimDecimals(extraWeightPrint, dec) + ":" +
                                                Util.TrimDecimals(Util.GetHeightInCentimeters(myStr[5]), dec) 
+ ":" +  
-                                               power + ":" +  
+                                               Util.TrimDecimals(getPower(tc, tf, personWeight, 
extraWeightInKg, fall), dec) + ":" +
+                                               Util.TrimDecimals(Util.GetStiffness(personWeight, 
extraWeightInKg, tf, tc), dec) + ":" +
                                                Util.TrimDecimals(Util.GetInitialSpeed(myStr[5], 
preferences.metersSecondsPreferred), dec) + ":" +  //true: m/s
                                                Util.RemoveNewLine(myStr[9], true) + ":" +      
//jump.description
                                                Util.TrimDecimals(myStr[10],dec) + ":" +        //jump.angle
@@ -324,7 +338,6 @@ public class ExportSession
                                                
                                           );
                        }
-                       Sqlite.Close();
 
                        writeData(myData);
                        writeData("VERTICAL-SPACE");
@@ -341,7 +354,6 @@ public class ExportSession
                if(myJumpsRj.Length > 0) 
                        printTitles(title); 
 
-               Sqlite.Open();
                foreach (string jump in myJumpsRj) {
                        
                        if(showSubjumps) {
@@ -354,7 +366,7 @@ public class ExportSession
                        else
                                weightName += " Kg";
 
-                       //TODO: add power
+                       //TODO: add power and stiffness
 
                        //if show subjumps show this every time, else show only one
                        if(isFirstHeader || showSubjumps) {
@@ -384,20 +396,30 @@ public class ExportSession
                        }
                
                        string [] myStr = jump.Split(new char[] {':'});
+
                        
-                       string myWeight = "";
+                       //find weight of person and extra weight
+                       int papsPosition = PersonAndPSUtil.Find(myPersonsAndPS, 
+                                       Convert.ToInt32(myStr[2])); //personID
+
+                       if(papsPosition == -1) {
+                               LogB.Error("PersonsAndPSUtil don't found person:", myStr[2]);
+                               return;
+                       }
+
+                       double personWeight = ((PersonAndPS) myPersonsAndPS[papsPosition]).ps.Weight;
+                       double extraWeightInKg = Util.WeightFromPercentToKg(
+                                       Convert.ToDouble(myStr[8]), 
+                                       personWeight);
+
+                       string extraWeightPrint = "";
                        if(preferences.weightStatsPercent)
-                               myWeight = myStr[8];
+                               extraWeightPrint = myStr[8];
                        else
-                               myWeight = Util.WeightFromPercentToKg(
-                                               Convert.ToDouble(myStr[8]), 
-                                               SqlitePersonSession.SelectAttribute(
-                                                       true,   //dbconOpened
-                                                       Convert.ToInt32(myStr[2]),
-                                                       Convert.ToInt32(myStr[3]),
-                                                       Constants.Weight
-                                                       )
-                                               ).ToString();
+                               extraWeightPrint = extraWeightInKg.ToString();
+                               
+                       //end of find weight of person and extra weight
+                       
                        myData.Add ( 
                                        myStr[2] + ":" +                        //jumpRj.personID
                                        myStr[0] + ":" +  myStr[1] + ":" +      //person.name, jumpRj.uniqueID
@@ -415,17 +437,15 @@ public class ExportSession
                                                        myStr[10], preferences.metersSecondsPreferred), dec) 
+ ":" +    //Avg Initial speed (true:m/s)
                                        myStr[7] + ":" +                //jumpRj.Fall
                                        //myStr[8] + ":" +  myStr[14] + ":" +   //jumpRj.Weight, jumpRj.Jumps
-                                       Util.TrimDecimals(myWeight,dec) + ":" +  myStr[14] + ":" +      
//jumpRj.Weight, jumpRj.Jumps
+                                       Util.TrimDecimals(extraWeightPrint,dec) + ":" +  myStr[14] + ":" +    
  //jumpRj.Weight, jumpRj.Jumps
                                        Util.TrimDecimals(myStr[15], dec) + ":" +  
Util.GetLimitedRounded(myStr[16],dec) + ":" +        //jumpRj.Time, jumpRj.Limited
                                        Util.RemoveNewLine(myStr[9], true) + ":" +      //jumpRj.Description
                                        //myStr[17] + ":" +     //jumpRj.Angle
                                        Util.SimulatedTestNoYes(Convert.ToInt32(myStr[18]))             
//simulated
                                        );
                        
-                       if(showSubjumps) {
-                               //TODO: add here all the calculations on all the parameters. eg. initial 
speed, power, ...
-                               //rewrite all
-
+                       if(showSubjumps) 
+                       {
                                writeData(myData);
                        
                                myData = new ArrayList(1);
@@ -434,7 +454,11 @@ public class ExportSession
                                string [] tcString = myStr[13].Split(new char[] {'='});
                                int count = 0;
                                myData.Add( " " + ":" + Catalog.GetString("TC") + 
-                                               ":" + Catalog.GetString("TF"));
+                                               ":" + Catalog.GetString("TF") + 
+                                               ":" + Catalog.GetString("Height") + 
+                                               ":" + Catalog.GetString("Power") + 
+                                               ":" + Catalog.GetString("Stiffness") 
+                                               );
 
                                //print Total, AVG, SD
                                myData.Add(Catalog.GetString("Total") + ":" +
@@ -455,17 +479,32 @@ public class ExportSession
                                                                Util.GetNumberOfJumps(myStr[12], 
false)).ToString(),
                                                        dec));
                                
-                               foreach(string myTv in tvString) {
+                               foreach(string myTv in tvString) 
+                               {
+                                       double tc = Convert.ToDouble(tcString[count]);
+                                       double tv = Convert.ToDouble(myTv);
+                                       
+                                       //on first jump use fall from RJ option
+                                       //on next jumps calculate from previous TV
+                                       double fall;
+                                       if(count == 0)
+                                               fall = Convert.ToDouble(myStr[7]); //jumpRj.Fall
+                                       else
+                                               fall = 
Convert.ToDouble(Util.GetHeightInCentimeters(tvString[count -1].ToString()));
+
                                        myData.Add((count+1).ToString() + ":" + 
-                                                       Util.TrimDecimals(tcString[count], dec) + ":" + 
-                                                       Util.TrimDecimals(myTv, dec));
+                                                       Util.TrimDecimals(tc, dec) + ":" + 
+                                                       Util.TrimDecimals(tv, dec) + ":" +
+                                                       
Util.TrimDecimals(Util.GetHeightInCentimeters(tv.ToString()), dec) + ":" +
+                                                       Util.TrimDecimals(getPower(tc, tv, personWeight, 
extraWeightInKg, fall), dec) + ":" +
+                                                       Util.TrimDecimals(Util.GetStiffness(personWeight, 
extraWeightInKg, tv, tc), dec)
+                                                 );
                                        count ++;
                                }
                                writeData(myData);
                                writeData("VERTICAL-SPACE");
                        }
                }
-               Sqlite.Close();
 
                //if not showSubjumps write data at last for not having every row as TH
                if(! showSubjumps) {
@@ -525,8 +564,9 @@ public class ExportSession
                if(myRunsInterval.Length > 0)
                        printTitles(title); 
 
-               foreach (string runString in myRunsInterval) {
-
+               Sqlite.Open();  
+               foreach (string runString in myRunsInterval) 
+               {
                        if(showSubruns) {
                                myData = new ArrayList(1);
                        }
@@ -556,7 +596,8 @@ public class ExportSession
                        string myRunTypeString = myStr[4];
                        string myRunDistanceInterval = myStr[7];
                        if(myRunDistanceInterval == "-1" || myRunDistanceInterval == "-1.0") {
-                               myRunType = 
SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRunTypeString, false);
+                               myRunType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(
+                                               myRunTypeString, true);
                        }
                        myData.Add (
                                        myStr[2] + ":" +                        //personID
@@ -616,6 +657,8 @@ public class ExportSession
                                writeData("VERTICAL-SPACE");
                        }
                }
+               Sqlite.Close(); 
+
                //if not showSubruns write data at last for not having every row as TH
                if(! showSubruns) {
                        writeData(myData);
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index d7885e6..c9def02 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -1038,7 +1038,9 @@ public partial class ChronoJumpWindow
        }
 
        private void fillTreeView_persons () {
-               ArrayList myPersons = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID); 
+               ArrayList myPersons = SqlitePersonSession.SelectCurrentSessionPersons(
+                               currentSession.UniqueID, 
+                               false); //means: do not returnPersonAndPSlist
 
                if(myPersons.Count > 0) {
                        //fill treeview
@@ -1271,11 +1273,15 @@ public partial class ChronoJumpWindow
                ArrayList undefinedSport = new ArrayList(1);
                
                ArrayList notToUpload = SqlitePersonSessionNotUpload.SelectAll(currentSession.UniqueID);
-               ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID);
+               ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
+                               currentSession.UniqueID,
+                               false); //means: do not returnPersonAndPSlist
+
                foreach (Person person in persons) 
                {
                        if(! Util.FoundInArrayList(notToUpload, person.UniqueID.ToString())) 
                        {
+                               //TODO: this is not needed if true at 
SqlitePersonSession.SelectCurrentSessionPersons
                                PersonSession ps = SqlitePersonSession.Select(person.UniqueID, 
currentSession.UniqueID);
                                if(ps.Weight <= 10 || ps.Weight >= 300)
                                        impossibleWeight.Add(person);
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 5cd902b..e886f2f 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -562,7 +562,10 @@ public partial class ChronoJumpWindow
                genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), 
Constants.ContextMenu.DELETE, false);
        
                //find all persons in current session
-               ArrayList personsPre = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID);
+               ArrayList personsPre = SqlitePersonSession.SelectCurrentSessionPersons(
+                               currentSession.UniqueID,
+                               false); //means: do not returnPersonAndPSlist
+
                string [] persons = new String[personsPre.Count];
                int count = 0;
                foreach (Person p in personsPre)
@@ -824,7 +827,10 @@ public partial class ChronoJumpWindow
                genericWin.MarkActiveCurves(checkboxes);
                
                //find all persons in current session
-               ArrayList personsPre = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID);
+               ArrayList personsPre = SqlitePersonSession.SelectCurrentSessionPersons(
+                               currentSession.UniqueID,
+                               false); //means: do not returnPersonAndPSlist
+               
                string [] persons = new String[personsPre.Count];
                count = 0;
                foreach (Person p in personsPre)
@@ -980,7 +986,9 @@ public partial class ChronoJumpWindow
        void encoder_analyze_data_compare_interperson () 
        {
                //find all persons except current person
-               ArrayList dataPre = SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID); 
+               ArrayList dataPre = SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID,
+                               false); //means: do not returnPersonAndPSlist
+
                ArrayList data = new ArrayList();
                ArrayList nonSensitiveRows = new ArrayList();
                int i = 0;      //list of persons
@@ -1216,7 +1224,9 @@ public partial class ChronoJumpWindow
                genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), 
Constants.ContextMenu.EDITDELETE, true);
        
                //find all persons in current session
-               ArrayList personsPre = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID);
+               ArrayList personsPre = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID,
+                               false); //means: do not returnPersonAndPSlist
+
                string [] persons = new String[personsPre.Count];
                count = 0;
                foreach (Person p in personsPre)
diff --git a/src/gui/event.cs b/src/gui/event.cs
index 5bfc49d..221ce32 100644
--- a/src/gui/event.cs
+++ b/src/gui/event.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -278,7 +278,9 @@ public class EditEventWindow
                        label_run_start_value.Hide();
                }
 
-               ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(myEvent.SessionID);
+               ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
+                               myEvent.SessionID,
+                               false); //means: do not returnPersonAndPSlist
                string [] personsStrings = new String[persons.Count];
                int i=0;
                foreach (Person person in persons) 
diff --git a/src/gui/executeAuto.cs b/src/gui/executeAuto.cs
index 737c622..6de9f53 100644
--- a/src/gui/executeAuto.cs
+++ b/src/gui/executeAuto.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) 2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2014-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -532,7 +532,9 @@ public class ExecuteAutoWindow
                        notebook_main.NextPage();
                }
                else if(notebook_main.CurrentPage == 1) {
-                       ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(sessionID);
+                       ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
+                                       sessionID,
+                                       false); //means: do not returnPersonAndPSlist
                        orderedData = ExecuteAuto.CreateOrder(mode, persons,  
                                        treeviewSerie1Array, treeviewSerie2Array, treeviewSerie3Array);
                        
diff --git a/src/gui/person.cs b/src/gui/person.cs
index f897ce0..7be506b 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -1336,10 +1336,10 @@ public class PersonAddModifyWindow
                        textview_ps_comments.Buffer = tb2;
                }
                        
-               sport = SqliteSport.Select(mySportID);
+               sport = SqliteSport.Select(false, mySportID);
                combo_sports.Active = UtilGtk.ComboMakeActive(sportsTranslated, sport.ToString());
 
-               combo_speciallities.Active = UtilGtk.ComboMakeActive(speciallitiesTranslated, 
SqliteSpeciallity.Select(mySpeciallityID));
+               combo_speciallities.Active = UtilGtk.ComboMakeActive(speciallitiesTranslated, 
SqliteSpeciallity.Select(false, mySpeciallityID));
 
                combo_levels.Active = UtilGtk.ComboMakeActive(levels, myLevelID + ":" + 
Util.FindLevelName(myLevelID));
                
@@ -1394,7 +1394,7 @@ public class PersonAddModifyWindow
                //LogB.Information("changed");
                try {
                        int sportID = Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_sports), sports));
-                       sport = SqliteSport.Select(sportID);
+                       sport = SqliteSport.Select(false, sportID);
 
                        if(Catalog.GetString(sport.Name) == Catalog.GetString(Constants.SportUndefined)) {
                                //if sport is undefined, level should be undefined, and unsensitive
@@ -2136,9 +2136,9 @@ public class PersonAddMultipleWindow {
 
                string sportStuffString = "";
                if(currentSession.PersonsSportID != Constants.SportUndefinedID)
-                       sportStuffString += Catalog.GetString("Sport") + ":<i>" + 
Catalog.GetString(SqliteSport.Select(currentSession.PersonsSportID).Name) + "</i>.";
+                       sportStuffString += Catalog.GetString("Sport") + ":<i>" + 
Catalog.GetString(SqliteSport.Select(false, currentSession.PersonsSportID).Name) + "</i>.";
                if(currentSession.PersonsSpeciallityID != Constants.SpeciallityUndefinedID)
-                       sportStuffString += " " + Catalog.GetString("Speciallity") + ":<i>" + 
SqliteSpeciallity.Select(currentSession.PersonsSpeciallityID) + "</i>.";
+                       sportStuffString += " " + Catalog.GetString("Speciallity") + ":<i>" + 
SqliteSpeciallity.Select(false, currentSession.PersonsSpeciallityID) + "</i>.";
                if(currentSession.PersonsPractice != Constants.LevelUndefinedID)
                        sportStuffString += " " + Catalog.GetString("Level") + ":<i>" + 
Util.FindLevelName(currentSession.PersonsPractice) + "</i>.";
 
diff --git a/src/gui/queryServer.cs b/src/gui/queryServer.cs
index 9deb656..b23b460 100644
--- a/src/gui/queryServer.cs
+++ b/src/gui/queryServer.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -540,7 +540,7 @@ public class QueryServerWindow
                //LogB.Information("changed");
                try {
                        int sportID = Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_sports), sports));
-                       sport = SqliteSport.Select(sportID);
+                       sport = SqliteSport.Select(false, sportID);
 
                        if(Catalog.GetString(sport.Name) == Catalog.GetString(Constants.SportAny)) {
                                //if sport is undefined, level should be undefined, and unsensitive
diff --git a/src/gui/session.cs b/src/gui/session.cs
index 3734619..87cee7f 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -142,7 +142,7 @@ public class SessionAddEditWindow {
 
                if(currentSession.PersonsSportID != Constants.SportUndefinedID) { 
                        radiobutton_same_sport.Active = true;
-                       Sport mySport = SqliteSport.Select(currentSession.PersonsSportID);
+                       Sport mySport = SqliteSport.Select(false, currentSession.PersonsSportID);
                        combo_sports.Active = UtilGtk.ComboMakeActive(sportsTranslated, mySport.ToString());
 
                        if(sport.HasSpeciallities) {
@@ -153,7 +153,7 @@ public class SessionAddEditWindow {
                                if(currentSession.PersonsSpeciallityID != Constants.SpeciallityUndefinedID) { 
                                        radiobutton_same_speciallity.Active = true;
                                        combo_speciallities.Active = 
UtilGtk.ComboMakeActive(speciallitiesTranslated,
-                                                      
SqliteSpeciallity.Select(currentSession.PersonsSpeciallityID));
+                                                      SqliteSpeciallity.Select(false, 
currentSession.PersonsSpeciallityID));
                                                       
                                } else 
                                        combo_speciallities.Active = 
@@ -358,7 +358,7 @@ public class SessionAddEditWindow {
                try {
                        //sport = new Sport(UtilGtk.ComboGetActive(combo_sports));
                        int sportID = Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_sports), sports));
-                       sport = SqliteSport.Select(sportID);
+                       sport = SqliteSport.Select(false, sportID);
 
                        if(Catalog.GetString(sport.Name) == Catalog.GetString(Constants.SportUndefined)) {
                                //if sport is undefined, level should be undefined, and unsensitive
@@ -453,7 +453,7 @@ public class SessionAddEditWindow {
                        else {
                                sportString = Catalog.GetString("All people in session practice the same 
sport:");
                                int sportID = Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_sports), sports));
-                               Sport mySport = SqliteSport.Select(sportID);
+                               Sport mySport = SqliteSport.Select(false, sportID);
 
                                if(sportID == Constants.SportUndefinedID)
                                        sportString += "<tt>" + pleaseDefineItString + "</tt>";
diff --git a/src/gui/stats.cs b/src/gui/stats.cs
index d510a59..e5bf09d 100644
--- a/src/gui/stats.cs
+++ b/src/gui/stats.cs
@@ -576,7 +576,10 @@ public partial class ChronoJumpWindow {
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, nullOptions, "");
                        combo_stats_stat_subtype.Sensitive = false;
                        
-                       ArrayList persons = 
SqlitePersonSession.SelectCurrentSessionPersons(currentSession.UniqueID);
+                       ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
+                                       currentSession.UniqueID,
+                                       false); //means: do not returnPersonAndPSlist
+
                        string [] personsStrings = new String[persons.Count];
                        int i=0;
                        foreach (Person person in persons) 
diff --git a/src/person.cs b/src/person.cs
index b0a27c4..b801297 100644
--- a/src/person.cs
+++ b/src/person.cs
@@ -15,12 +15,13 @@
  *  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-2014   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
 using System.Data;
 using System.Text; //StringBuilder
+using System.Collections; //ArrayList
 using Mono.Unix;
 
 public partial class Person {
@@ -189,3 +190,29 @@ public partial class Person {
           
 }
 
+//useful when you just want to know all of the data of a person in this session
+public class PersonAndPS {
+       public Person p;
+       public PersonSession ps;
+       
+       //default constructor
+       public PersonAndPS(Person p, PersonSession ps) {
+               this.p = p;
+               this.ps = ps;
+       }
+       
+       ~PersonAndPS() {}
+}
+public static class PersonAndPSUtil {
+       public static int Find(ArrayList papsArray, int personID) 
+       {
+               int count = 0;
+               foreach(PersonAndPS paps in papsArray) {
+                       if(paps.p.UniqueID == personID)
+                               return count;
+                       count ++;
+               }
+
+               return -1;
+       }
+}
diff --git a/src/report.cs b/src/report.cs
index 37633f9..922ba0f 100644
--- a/src/report.cs
+++ b/src/report.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-2014   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -96,7 +96,7 @@ public class Report : ExportSession
                }
 
                if(ShowCurrentSessionJumpers) {
-                       myPersons = SqlitePersonSession.SelectCurrentSessionPersons(sessionID);
+                       myPersonsAndPS = SqlitePersonSession.SelectCurrentSessionPersons(sessionID, true);
                }
                if(ShowSimpleJumps) {
                        myJumps= SqliteJump.SelectJumps(false, sessionID, -1, "", "");
diff --git a/src/server.cs b/src/server.cs
index d63b52e..fc7ae84 100644
--- a/src/server.cs
+++ b/src/server.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-2014   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -192,7 +192,9 @@ public class Server
                        string sportsSeparator = "";
 
                        //upload persons (updating also person.serverUniqueID locally)
-                       ArrayList persons = 
SqlitePersonSession.SelectCurrentSessionPersons(serverSession.UniqueID); 
+                       ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
+                                       serverSession.UniqueID,
+                                       false); //means: do not returnPersonAndPSlist
                        
                        Constants.UploadCodes uCode;
                        ArrayList notToUpload = 
SqlitePersonSessionNotUpload.SelectAll(currentSession.UniqueID);
@@ -220,7 +222,7 @@ public class Server
                                        
                                //if sport is user defined, upload it
                                //and when upload the person, do it with new sportID
-                               Sport sport = SqliteSport.Select(ps.SportID);
+                               Sport sport = SqliteSport.Select(false, ps.SportID);
                                //but record old sport ID because locally will be a change in serverUniqueID
                                //(with slite update)
                                //but local sport has not to be changed
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 65eeef5..dba61be 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -241,13 +241,17 @@ class SqlitePersonSession : Sqlite
        //the difference between this select and others, is that this returns and ArrayList of Persons
        //this is better than return the strings that can produce bugs in the future
        //use this in the future:
-       public static ArrayList SelectCurrentSessionPersons(int sessionID) 
+       public static ArrayList SelectCurrentSessionPersons(int sessionID, bool returnPersonAndPSlist) 
        {
                string tp = Constants.PersonTable;
                string tps = Constants.PersonSessionTable;
+                       
+               string tpsString = "";
+               if(returnPersonAndPSlist)
+                       tpsString = ", " + tps + ".* ";
                
                Sqlite.Open();
-               dbcmd.CommandText = "SELECT " + tp + ".*" +
+               dbcmd.CommandText = "SELECT " + tp + ".*" + tpsString +
                        " FROM " + tp + ", " + tps + 
                        " WHERE " + tps + ".sessionID == " + sessionID + 
                        " AND " + tp + ".uniqueID == " + tps + ".personID " + 
@@ -269,86 +273,29 @@ class SqlitePersonSession : Sqlite
                                        reader[6].ToString(),                   //description
                                        Convert.ToInt32(reader[9].ToString())   //serverUniqueID
                                        );
-                       myArray.Add (person);
+
+                       if(returnPersonAndPSlist) {
+                               PersonSession ps = new PersonSession(
+                                               Convert.ToInt32(reader[10].ToString()),         //uniqueID
+                                               Convert.ToInt32(reader[11].ToString()),         //personID
+                                               Convert.ToInt32(reader[12].ToString()),         //sessionID
+                                               
Convert.ToDouble(Util.ChangeDecimalSeparator(reader[13].ToString())), //height
+                                               
Convert.ToDouble(Util.ChangeDecimalSeparator(reader[14].ToString())), //weight
+                                               Convert.ToInt32(reader[15].ToString()),         //sportID
+                                               Convert.ToInt32(reader[16].ToString()),         
//speciallityID
+                                               Convert.ToInt32(reader[17].ToString()), //practice
+                                               reader[18].ToString()                   //comments
+                                               );
+                               myArray.Add(new PersonAndPS(person, ps));
+                               
+                       } else
+                               myArray.Add (person);
                }
                reader.Close();
                Sqlite.Close();
                return myArray;
        }
        
-       /*
-          try to use upper method:
-               public static ArrayList SelectCurrentSessionPersons(int sessionID) 
-               
-       public static string[] SelectCurrentSession(int sessionID, bool onlyIDAndName, bool reverse) 
-       {
-               string tp = Constants.PersonTable;
-               string tps = Constants.PersonSessionTable;
-               
-               Sqlite.Open();
-               dbcmd.CommandText = "SELECT " + tp + ".*, " + tps + ".weight, sport.name, speciallity.name " +
-                       "FROM " + tp + ", " + tps + ", sport, speciallity " +
-                       " WHERE " + tps + ".sessionID == " + sessionID + 
-                       " AND " + tp + ".uniqueID == " + tps + ".personID " + 
-                       " AND " + tp + ".sportID == sport.uniqueID " + 
-                       " AND " + tp + ".speciallityID == speciallity.uniqueID " + 
-                       " ORDER BY upper(" + tp + ".name)";
-               LogB.SQL(dbcmd.CommandText.ToString());
-               dbcmd.ExecuteNonQuery();
-
-               SqliteDataReader reader;
-               reader = dbcmd.ExecuteReader();
-
-               ArrayList myArray = new ArrayList(2);
-
-               int count = new int();
-               count = 0;
-
-               while(reader.Read()) {
-                       if(onlyIDAndName)
-                               myArray.Add (reader[0].ToString() + ":" + reader[1].ToString() );
-                       else {
-                               string sportName = Catalog.GetString(reader[14].ToString());
-
-                               string speciallityName = ""; //to solve a gettext bug (probably because 
speciallity undefined name is "")
-                               if(reader[15].ToString() != "")
-                                       speciallityName = Catalog.GetString(reader[15].ToString());
-                               string levelName = 
Catalog.GetString(Util.FindLevelName(Convert.ToInt32(reader[8])));
-
-                               myArray.Add (
-                                               reader[0].ToString() + ":" + reader[1].ToString() + ":" +     
  //id, name
-                                               reader[2].ToString() + ":" +                                  
  //sex
-                                               UtilDate.FromSql(reader[3].ToString()).ToShortDateString() + 
":" +      //dateborn
-                                               reader[4].ToString() + ":" + reader[13].ToString() + ":" + 
//height, weight (from personSessionWeight)
-                                               sportName + ":" + speciallityName + ":" + levelName + ":" +
-                                               reader[9].ToString()  //desc
-                                           );
-                       }
-                       count ++;
-               }
-
-               reader.Close();
-               Sqlite.Close();
-
-               string [] myJumpers = new string[count];
-               
-               if(reverse) {
-                       //show the results in the combo_sujeto_actual in reversed order, 
-                       //then when we create a new person, this is the active, and this is shown 
-                       //correctly in the combo_sujeto_actual
-                       int count2 = count -1;
-                       foreach (string line in myArray) {
-                               myJumpers [count2--] = line;
-                       }
-               } else {
-                       int count2 = 0;
-                       foreach (string line in myArray) {
-                               myJumpers [count2++] = line;
-                       }
-               }
-               return myJumpers;
-       }
-       */
        
        public static void DeletePersonFromSessionAndTests(string sessionID, string personID)
        {
diff --git a/src/sqlite/speciallity.cs b/src/sqlite/speciallity.cs
index e95679c..3ddbe49 100644
--- a/src/sqlite/speciallity.cs
+++ b/src/sqlite/speciallity.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 
@@ -78,12 +78,13 @@ class SqliteSpeciallity : Sqlite
                return myLast;
        }
 
-       public static string Select(int uniqueID)
+       public static string Select(bool dbconOpened, int uniqueID)
        {
                if(uniqueID == -1)
                        return "";
 
-               Sqlite.Open();
+               if(! dbconOpened)
+                       Sqlite.Open();
                
                dbcmd.CommandText = "SELECT name FROM " + Constants.SpeciallityTable + " WHERE uniqueID == " 
+ uniqueID;
                
@@ -97,8 +98,10 @@ class SqliteSpeciallity : Sqlite
                string speciallityName = reader[0].ToString(); //name
        
                reader.Close();
-               Sqlite.Close();
-               //return uniqueID + ":" + Catalog.GetString(speciallityName);
+               
+               if(! dbconOpened)
+                       Sqlite.Close();
+               
                return Catalog.GetString(speciallityName);
        }
        
diff --git a/src/sqlite/sport.cs b/src/sqlite/sport.cs
index 92c6228..a055a76 100644
--- a/src/sqlite/sport.cs
+++ b/src/sqlite/sport.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 
@@ -84,9 +84,10 @@ class SqliteSport : Sqlite
                return myLast;
        }
 
-       public static Sport Select(int uniqueID)
+       public static Sport Select(bool dbconOpened, int uniqueID)
        {
-               Sqlite.Open();
+               if(! dbconOpened)
+                       Sqlite.Open();
                
                dbcmd.CommandText = "SELECT * FROM " + Constants.SportTable + " WHERE uniqueID == " + 
uniqueID;
                
@@ -106,7 +107,10 @@ class SqliteSport : Sqlite
                                );
        
                reader.Close();
-               Sqlite.Close();
+               
+               if(! dbconOpened)
+                       Sqlite.Close();
+
                return mySport;
        }
                


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