[chronojump] Fixed new person identify on compujump



commit 465d6a3aaaaf1c3ea32138884ed1886c1d73a40b
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Jul 8 18:14:27 2017 +0200

    Fixed new person identify on compujump

 src/gui/networks.cs |   15 +++++++--------
 src/json.cs         |   13 ++++++++++++-
 src/person.cs       |    5 ++---
 3 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 0060a7b..5995c7c 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -437,11 +437,12 @@ public partial class ChronoJumpWindow
                 * This method is shown on diagrams/processes/rfid-local-read.dia
                 */
 
-               Person pLocal = SqlitePerson.SelectByRFID(capturedRFID);
-
                bool currentPersonWasNull = (currentPerson == null);
                bool pChangedShowTasks = false;
                Json json = new Json();
+
+               //select person by RFID
+               Person pLocal = SqlitePerson.SelectByRFID(capturedRFID);
                if(pLocal.UniqueID == -1)
                {
                        LogB.Information("RFID person does not exist locally!!");
@@ -462,14 +463,12 @@ public partial class ChronoJumpWindow
 
                                //personID exists at local DB?
                                //check if this uniqueID already exists on local database (would mean RFID 
changed on server)
-                               bool newPerson = false;
                                pLocal = SqlitePerson.Select(false, pServer.UniqueID);
 
-                               if(pLocal.UniqueID == -1) {
-                                       newPerson = true;
-                               } else {
+                               if(! json.LastPersonWasInserted)
+                               {
                                        /*
-                                        * id exists, RFID has changed. Changed locally
+                                        * id exists locally, RFID has changed. Changed locally
                                         * Note server don't allow having an rfid of a previous person. Must 
be historically unique.
                                         */
 
@@ -480,7 +479,7 @@ public partial class ChronoJumpWindow
                                currentPerson = pLocal;
                                insertAndAssignPersonSessionIfNeeded(json);
 
-                               if(newPerson)
+                               if(json.LastPersonWasInserted)
                                {
                                        if(json.LastPersonByRFIDImageURL != "")
                                        {
diff --git a/src/json.cs b/src/json.cs
index 25d413f..f6f898c 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -338,9 +338,11 @@ public class Json
                return person;
 
        }
+
        public double LastPersonByRFIDHeight = 0;
        public double LastPersonByRFIDWeight = 0;
        public string LastPersonByRFIDImageURL = "";
+       public bool LastPersonWasInserted = false;
        private Person personDeserialize(string strPerson)
        {
                JsonValue jsonPerson = JsonValue.Parse(strPerson);
@@ -356,7 +358,16 @@ public class Json
                LastPersonByRFIDWeight = weight;
                LastPersonByRFIDImageURL = image;
 
-               return new Person(id, player, rfid);
+               Person personTemp = SqlitePerson.Select(false, id);
+               /*
+                * if personTemp == -1, need to insert this person
+                * LastPersonWasInserted will be used:
+                *      to insert person at person.cs
+                *      to know if (it's new person or RFID changed) at gui/networks.cs
+                */
+               LastPersonWasInserted = (personTemp.UniqueID == -1);
+
+               return new Person(LastPersonWasInserted, id, player, rfid);
        }
 
 
diff --git a/src/person.cs b/src/person.cs
index 577c097..7d5bad2 100644
--- a/src/person.cs
+++ b/src/person.cs
@@ -45,7 +45,7 @@ public class Person {
        }
 
        //coming from compujump server
-       public Person(int uniqueID, string name, string rfid)
+       public Person(bool insertPerson, int uniqueID, string name, string rfid)
        {
                this.uniqueID = uniqueID;
                this.name = name;
@@ -61,8 +61,7 @@ public class Person {
                 * Before insertion check that uniqueID exists locally
                 * can happen when there are rfid changes on server
                 */
-               Person personTemp = SqlitePerson.Select(false, uniqueID);
-               if(personTemp.UniqueID == -1) //does not exist
+               if(insertPerson)
                        SqlitePerson.Insert(false,
                                        uniqueID.ToString(), name, sex, dateBorn, race, countryID,
                                        description, future1, serverUniqueID);


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