[chronojump] Person can be loaded from person add if exists on db



commit 93b58fe3cadff3e90e330ebb1f55bdd645758794
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 9 13:55:16 2018 +0100

    Person can be loaded from person add if exists on db

 glade/person_win.glade |   58 +++++++++++++++++++++++++++++++++++++++-
 src/gui/chronojump.cs  |    9 +++++-
 src/gui/person.cs      |   70 ++++++++++++++++++++++++++++++++++++++++-------
 src/personSession.cs   |    3 +-
 4 files changed, 126 insertions(+), 14 deletions(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index e3afecf..afd2ad6 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -2084,6 +2084,61 @@
               </packing>
             </child>
             <child>
+              <widget class="GtkHButtonBox" id="hbuttonbox2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <widget class="GtkButton" id="button_load_person">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <signal name="clicked" handler="on_button_load_person_clicked" swapped="no"/>
+                    <child>
+                      <widget class="GtkHBox" id="hbox9">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <widget class="GtkImage" id="image_load_person">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="stock">gtk-missing-image</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label_button_load_person">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Load person</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </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">1</property>
+              </packing>
+            </child>
+            <child>
               <widget class="GtkHButtonBox" id="hbuttonbox1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -2108,7 +2163,8 @@
               <packing>
                 <property name="expand">True</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
+                <property name="padding">20</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </widget>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 98d379a..c8222e4 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2633,7 +2633,14 @@ public partial class ChronoJumpWindow
                personAddModifyWin.FakeButtonAccept.Clicked -= new 
EventHandler(on_person_add_single_accepted);
                personAddModifyWin.FakeButtonAccept.Clicked += new 
EventHandler(on_person_add_single_accepted);
        }
-       
+
+       /*
+        * note: while adding, if a person name is written,
+        * and this name exists in database but not in current session,
+        * a person load will appear
+        * and if clicked, this will be called, so this will be used also as a loader
+        * TODO: unify most of the code of person add and person load
+        */
        private void on_person_add_single_accepted (object o, EventArgs args)
        {
                personAddModifyWin.FakeButtonAccept.Clicked -= new 
EventHandler(on_person_add_single_accepted);
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 0e55b30..8da8f4a 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -792,6 +792,8 @@ public class PersonAddModifyWindow
        [Widget] Gtk.HButtonBox hbuttonbox_main;
        [Widget] Gtk.VBox vbox_error;
        [Widget] Gtk.Label label_error;
+       [Widget] Gtk.Button button_load_person;
+       [Widget] Gtk.Image image_load_person;
 
        [Widget] Gtk.Button button_add_photo_file;
        [Widget] Gtk.Button button_take_photo;
@@ -899,6 +901,9 @@ public class PersonAddModifyWindow
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + Constants.FileNameZoomInIcon);
                image_zoom.Pixbuf = pixbuf;
 
+               pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_person_outline.png");
+               image_load_person.Pixbuf = pixbuf;
+
                button_take_photo.Visible = showCapturePhoto;
 
                //delete a -1.png or -1.jpg added before on a new user where "accept" button was not pressed 
and window was closed
@@ -1638,7 +1643,9 @@ public class PersonAddModifyWindow
                }
        }
                
-       
+
+       Person loadingPerson;
+
        void on_button_accept_clicked (object o, EventArgs args)
        {
                string errorMessage = "";
@@ -1653,19 +1660,36 @@ public class PersonAddModifyWindow
                if(errorMessage.Length > 0)
                {
                        label_error.Text = errorMessage;
-                       showErrorMessage(true);
+                       showErrorMessage(true, false);
                        return;
                }
 
                bool personExists;
+               bool personLoadable = false; // this person exists but is not in this session
                if(adding)
+               {
                        personExists = Sqlite.Exists (false, Constants.PersonTable, personName);
+                       if(personExists)
+                       {
+                               Person p = SqlitePerson.Select(false, "WHERE LOWER(name) = LOWER(\"" + 
personName + "\")");
+                               if(p.UniqueID != -1)
+                               {
+                                       personLoadable = ! SqlitePersonSession.PersonSelectExistsInSession(
+                                                       p.UniqueID, currentSession.UniqueID);
+                                       loadingPerson = p;
+                               }
+                       }
+               }
                else
                        personExists = SqlitePerson.ExistsAndItsNotMe (currentPerson.UniqueID, personName);
 
-               if(personExists) 
-                       errorMessage += string.Format(Catalog.GetString("Person: '{0}' exists. Please, use 
another name"), 
+               if(personExists)
+               {
+                       errorMessage += string.Format(Catalog.GetString("Person: '{0}' exists. Please, use 
another name."),
                                        Util.RemoveTildeAndColonAndDot(personName) );
+                       if(adding && personLoadable)
+                               errorMessage += "\n" + Catalog.GetString("Or load this person from another 
session using this button:");
+               }
                else {
                        //if weight has changed
                        if(!adding && (double) spinbutton_weight.Value != weightIni) {
@@ -1692,20 +1716,44 @@ public class PersonAddModifyWindow
                if(errorMessage.Length > 0)
                {
                        label_error.Text = errorMessage;
-                       showErrorMessage(true);
+                       //show error message, show button_load_person if adding, personExists and not in this 
session
+                       showErrorMessage(true, adding && personExists && personLoadable);
                }
        }
 
-       void on_button_error_go_back_clicked (object o, EventArgs args)
-       {
-               showErrorMessage(false);
-       }
-
-       void showErrorMessage(bool show)
+       private void showErrorMessage(bool show, bool showLoadPerson)
        {
                vbox_error.Visible = show;
                notebook_main.Visible = ! show;
                hbuttonbox_main.Visible = ! show;
+
+               button_load_person.Visible = showLoadPerson;
+       }
+
+       private void on_button_load_person_clicked (object o, EventArgs args)
+       {
+               currentPerson = loadingPerson;
+               PersonAddModifyWindowBox.person_win.Hide();
+               PersonAddModifyWindowBox = null;
+
+               PersonSession myPS = SqlitePersonSession.Select(false, currentPerson.UniqueID, -1);
+
+               LogB.Information("Going to insert personSession");
+               //this inserts in DB
+               currentPersonSession = new PersonSession (
+                               currentPerson.UniqueID, currentSession.UniqueID,
+                               myPS.Height, myPS.Weight,
+                               myPS.SportID, myPS.SpeciallityID,
+                               myPS.Practice,
+                               myPS.Comments,
+                               false); //dbconOpened
+
+               fakeButtonAccept.Click();
+       }
+
+       private void on_button_error_go_back_clicked (object o, EventArgs args)
+       {
+               showErrorMessage(false, false);
        }
 
        void on_convertWeightWin_accepted (object o, EventArgs args) {
diff --git a/src/personSession.cs b/src/personSession.cs
index ba27b2d..6a8fec5 100644
--- a/src/personSession.cs
+++ b/src/personSession.cs
@@ -42,7 +42,8 @@ public class PersonSession {
 
        //loading
        //we know uniqueID
-       public PersonSession(int uniqueID, int personID, int sessionID,
+       public PersonSession(int uniqueID,
+                       int personID, int sessionID,
                        double height, double weight, int sportID, 
                        int speciallityID, int practice, string comments)
        {


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