[chronojump] INPROGRESS compujump stuff. FixIt



commit d7e9d512dd078543068b5776abdc48ea3ce7c2fb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu May 4 12:22:40 2017 +0200

    INPROGRESS compujump stuff. FixIt

 glade/app1.glade            |  119 +++++++++++++++++++++++--------------------
 src/config.cs               |   34 ++++++++++++
 src/gui/chronojump.cs       |   28 ++++++++--
 src/gui/networks.cs         |  103 ++++++++++++++++++++++++++++++++++---
 src/gui/person.cs           |    6 +-
 src/json.cs                 |  107 ++++++++++++++++++++++++++++++++++++++-
 src/person.cs               |   28 +++++++++--
 src/sqlite/main.cs          |    1 +
 src/sqlite/person.cs        |   18 +++++--
 src/sqlite/personSession.cs |    1 +
 10 files changed, 363 insertions(+), 82 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index f3e2f0f..569516d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1236,6 +1236,9 @@
                                                             <placeholder/>
                                                             </child>
                                                             <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkLabel" 
id="label_start_selector_jumps">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -14400,6 +14403,9 @@ Concentric</property>
                                                     <property name="position">1</property>
                                                   </packing>
                                                 </child>
+                                                <child>
+                                                  <placeholder/>
+                                                </child>
                                               </widget>
                                               <packing>
                                                 <property name="expand">True</property>
@@ -14412,8 +14418,57 @@ Concentric</property>
                                                 <property name="can_focus">False</property>
                                                 <property name="spacing">20</property>
                                                 <child>
+                                                  <widget class="GtkHBox" id="hbox_rfid">
+                                                    <property name="can_focus">False</property>
+                                                    <child>
+                                                      <widget class="GtkButton" id="button_rfid_read">
+                                                        <property name="label">Read RFID</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <property name="relief">half</property>
+                                                        <signal name="clicked" 
handler="on_button_rfid_read_clicked" swapped="no"/>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkButton" id="button_rfid_start">
+                                                        <property name="label">Start RFID</property>
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <property name="relief">half</property>
+                                                        <signal name="clicked" 
handler="on_button_rfid_start_clicked" swapped="no"/>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label_rfid">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">2</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
                                                   <widget class="GtkHBox" id="hbox73">
-                                                    <property name="visible">True</property>
                                                     <property name="can_focus">False</property>
                                                     <property name="spacing">20</property>
                                                     <child>
@@ -14518,7 +14573,7 @@ Concentric</property>
                                                   <packing>
                                                     <property name="expand">True</property>
                                                     <property name="fill">True</property>
-                                                    <property name="position">0</property>
+                                                    <property name="position">1</property>
                                                   </packing>
                                                 </child>
                                                 <child>
@@ -14544,7 +14599,7 @@ Concentric</property>
                                                   <packing>
                                                     <property name="expand">True</property>
                                                     <property name="fill">True</property>
-                                                    <property name="position">1</property>
+                                                    <property name="position">2</property>
                                                   </packing>
                                                 </child>
                                                 <child>
@@ -14570,7 +14625,7 @@ Concentric</property>
                                                   <packing>
                                                     <property name="expand">True</property>
                                                     <property name="fill">True</property>
-                                                    <property name="position">2</property>
+                                                    <property name="position">3</property>
                                                   </packing>
                                                 </child>
                                                 <child>
@@ -14595,7 +14650,7 @@ Concentric</property>
                                                   <packing>
                                                     <property name="expand">True</property>
                                                     <property name="fill">True</property>
-                                                    <property name="position">3</property>
+                                                    <property name="position">4</property>
                                                   </packing>
                                                 </child>
                                               </widget>
@@ -16632,57 +16687,6 @@ Concentric</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
-                                                            <child>
-                                                            <widget class="GtkHBox" id="hbox_rfid">
-                                                            <property name="can_focus">False</property>
-                                                            <child>
-                                                            <widget class="GtkButton" id="button_rfid_read">
-                                                            <property name="label">Read RFID</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property name="receives_default">True</property>
-                                                            <property name="relief">half</property>
-                                                            <signal name="clicked" 
handler="on_button_rfid_read_clicked" swapped="no"/>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
-                                                            <widget class="GtkButton" id="button_rfid_start">
-                                                            <property name="label">Start RFID</property>
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property name="receives_default">True</property>
-                                                            <property name="relief">half</property>
-                                                            <signal name="clicked" 
handler="on_button_rfid_start_clicked" swapped="no"/>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
-                                                            <widget class="GtkLabel" id="label_rfid">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">2</property>
-                                                            </packing>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="left_attach">2</property>
@@ -20308,6 +20312,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/config.cs b/src/config.cs
index a418ed2..cf5b3d7 100644
--- a/src/config.cs
+++ b/src/config.cs
@@ -38,10 +38,12 @@ public class Config
        public bool EncoderAnalyzeHide;
        public SessionModeEnum SessionMode;
        public bool Compujump;
+       public string CompujumpServerURL;
        public string RunScriptOnExit;
 
        public Config()
        {
+               /*
                Maximized = Preferences.MaximizedTypes.NO;
                CustomButtons = false;
                UseVideo = true;
@@ -55,8 +57,40 @@ public class Config
                SessionMode = SessionModeEnum.STANDARD;
                Compujump = false;
                RunScriptOnExit = "";
+               */
        }
 
+       public void Read()
+       {
+               string contents = Util.ReadFile(UtilAll.GetConfigFileName(), false);
+               if (contents != null && contents != "") 
+               {
+                       string line;
+                       using (StringReader reader = new StringReader (contents)) {
+                               do {
+                                       line = reader.ReadLine ();
+
+                                       if (line == null)
+                                               break;
+                                       if (line == "" || line[0] == '#')
+                                               continue;
+
+                                       string [] parts = line.Split(new char[] {'='});
+                                       if(parts.Length != 2)
+                                               continue;
+
+                                       if(parts[0] == "Compujump" && Util.StringToBool(parts[1]))
+                                               Compujump = true;
+                                       else if(parts[0] == "CompujumpServerURL" && parts[1] != "")
+                                               CompujumpServerURL = parts[1];
+                                       else if(parts[0] == "SessionMode" && 
Enum.IsDefined(typeof(SessionModeEnum), parts[1]))
+                                               SessionMode = (SessionModeEnum) 
+                                                       Enum.Parse(typeof(SessionModeEnum), parts[1]);
+                               } while(true);
+                       }
+               }
+       }
+       
        /*
        public void Read()
        {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 922978f..613d367 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -550,9 +550,7 @@ public partial class ChronoJumpWindow
                //preferencesLoaded is a fix to a gtk#-net-windows-bug where radiobuttons raise signals
                //at initialization of chronojump and gives problems if this signals are raised while 
preferences are loading
                loadPreferences ();
-
-               rfdList = SqliteForceSensor.SelectAll(false);
-
+               
                createTreeView_persons (treeview_persons);
 
                createTreeView_jumps (treeview_jumps);
@@ -563,6 +561,9 @@ public partial class ChronoJumpWindow
                createTreeView_reaction_times (treeview_reaction_times);
                createTreeView_pulses (treeview_pulses);
                createTreeView_multi_chronopic (false, treeview_multi_chronopic);
+               
+               rfdList = SqliteForceSensor.SelectAll(false);
+
 
                createComboSelectJumps(true);
                createComboSelectJumpsRj(true);
@@ -623,6 +624,8 @@ public partial class ChronoJumpWindow
                cp2016 = new Chronopic2016();
 
                encoderInitializeStuff();       
+               
+               configInitRead();
 
                //presentationInit();
 
@@ -2063,6 +2066,7 @@ public partial class ChronoJumpWindow
                LogB.Information("Bye!");
 
                updatingRestTimes = false;
+               updatingRFIDGuiStuff = false;
 
                //if capturing on the background finish it
                if(eCaptureInertialBG != null)
@@ -2470,10 +2474,21 @@ public partial class ChronoJumpWindow
                personAddModifyWin.FakeButtonAccept.Clicked += new 
EventHandler(on_person_add_single_accepted);
        }
        
-       private void on_person_add_single_accepted (object o, EventArgs args) {
+       private void on_person_add_single_accepted (object o, EventArgs args)
+       {
                if (personAddModifyWin.CurrentPerson != null)
                {
                        currentPerson = personAddModifyWin.CurrentPerson;
+                       person_added();
+               }
+       }
+
+       private void person_added ()
+       {
+       /*      if (personAddModifyWin.CurrentPerson != null)
+               {
+                       currentPerson = personAddModifyWin.CurrentPerson;
+                       */
                        currentPersonSession = SqlitePersonSession.Select(currentPerson.UniqueID, 
currentSession.UniqueID);
                        label_person_change();
                        myTreeViewPersons.Add(currentPerson.UniqueID.ToString(), currentPerson.Name);
@@ -2510,7 +2525,7 @@ public partial class ChronoJumpWindow
                                                false); //means: do not returnPersonAndPSlist
                                personSelectWin.Update(myPersons);
                        }
-               }
+       //      }
        }
 
        //show spinbutton window asking for how many people to create   
@@ -3043,6 +3058,7 @@ public partial class ChronoJumpWindow
                //but don't show if session == UNIQUE
                if(configChronojump.SessionMode == Config.SessionModeEnum.STANDARD)
                        main_menu.Visible = true;
+               //TODO: show preferences and exit button also on contacts
 
                if(m != Constants.Menuitem_modes.POWERGRAVITATORY && m != 
Constants.Menuitem_modes.POWERINERTIAL)
                {
@@ -6527,6 +6543,7 @@ LogB.Debug("X");
 
        private void sensitiveGuiNoSession () 
        {
+               LogB.Information("NO SESSION");
                notebook_session_person.CurrentPage = 0;
 
                treeview_persons.Sensitive = false;
@@ -6566,6 +6583,7 @@ LogB.Debug("X");
        
        private void sensitiveGuiYesSession () 
        {
+               LogB.Information("YES SESSION");
                notebook_session_person.CurrentPage = 1;
 
                button_image_test_zoom.Sensitive = true;
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index a9b6145..0db6b20 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -70,10 +70,20 @@ public partial class ChronoJumpWindow
        Config configChronojump;
        private void configInitRead()
        {
-               //trying new Config class
-               configChronojump = new Config();
+               configChronojump.Read();
+               LogB.Information("PRINT VARS");
+               LogB.Information(configChronojump.Compujump.ToString());
+               LogB.Information(configChronojump.CompujumpServerURL);
+               if(configChronojump.Compujump)
+               {
+                       //on compujump cannot add/edit persons, do it from server
+                       frame_persons_top.Visible = false;
+                       button_contacts_person_change.Visible = false;
+                       button_encoder_person_change.Visible = false;
+                       //TODO: don't allow edit person on person treeview
 
-               //configChronojump.Read();
+                       Json.ChangeServerUrl(configChronojump.CompujumpServerURL);
+               }
 
                configDo();
        }
@@ -188,9 +198,11 @@ public partial class ChronoJumpWindow
                        hbox_encoder_sup_capture_analyze_two_buttons.Visible = false;
                }
 
-               if(configChronojump.SessionMode == Config.SessionModeEnum.UNIQUE || 
configChronojump.SessionMode == Config.SessionModeEnum.MONTHLY)
+               if(currentSession == null && //this is going to be called one time because currentSession 
will change
+                              ( configChronojump.SessionMode == Config.SessionModeEnum.UNIQUE || 
configChronojump.SessionMode == Config.SessionModeEnum.MONTHLY) )
                {
-                       main_menu.Visible = false;
+                       LogB.Information("HEREGUAY");
+                       //main_menu.Visible = false;
                        //app1.Decorated = false;
                        hbox_menu_and_preferences_outside_menu.Visible = true;
 
@@ -205,6 +217,7 @@ public partial class ChronoJumpWindow
                                } else
                                        currentSession = SqliteSession.SelectByName("session");
                        } else {
+                               LogB.Information("HEREGUAY2");
                                //configChronojump.SessionMode == Config.SessionModeEnum.MONTHLY
 
                                string yearMonthStr = UtilDate.GetCurrentYearMonthStr();
@@ -243,6 +256,8 @@ public partial class ChronoJumpWindow
                        }
                        
                        on_load_session_accepted();
+                       sensitiveGuiYesSession();
+                       rfid_start();
                }
 
                //TODO
@@ -286,10 +301,63 @@ public partial class ChronoJumpWindow
                if(Util.FileExists(filePath))
                        label_rfid.Text = Util.ReadFile(filePath, true);
        }
+       
+       static bool updatingRFIDGuiStuff;
+       static string updatingRFIDGuiStuffNewRFID;
+       //called each second and after a test
+       bool updateRFIDGuiStuff()
+       {
+               if(! updatingRFIDGuiStuff)
+                       return false;
+
+               if(updatingRFIDGuiStuffNewRFID == "")
+                       return true;
+
+               string rfid = updatingRFIDGuiStuffNewRFID;
+               updatingRFIDGuiStuffNewRFID = ""; //to not be called again //TODO: ensure this is not called 
two times
+
+               label_rfid.Text = rfid; //take care, maybe cannot read label stuff on a WATCHER
+               Person p = SqlitePerson.SelectByRFID(rfid);
+               if(p.UniqueID == -1)
+               {
+                       LogB.Information("RFID person does not exist!!");
+
+                       Json js = new Json();
+                       p = js.GetPersonByRFID(rfid);
+                       if(p.UniqueID == -1) {
+                               LogB.Information("Person NOT found on server!");
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               "Aquesta pulsera o jugador no es troba identificada al 
servidor");
+                       }
+                       else {
+                               LogB.Information("Person found on server!");
+
+                               currentPerson = p;
+                               currentPersonSession = new PersonSession (
+                                               currentPerson.UniqueID, currentSession.UniqueID, 
+                                               0, js.LastPersonByRFIDWeight,
+                                               Constants.SportUndefinedID, 
+                                               Constants.SpeciallityUndefinedID, 
+                                               Constants.LevelUndefinedID,
+                                               "", false); //comments, dbconOpened
+                               person_added();
+                       }
+               }
+               else
+                       LogB.Information("RFID person exists!!");
+
+               return true;
+       }
+
 
        Process processRFIDcapture;
        void on_button_rfid_start_clicked (object o, EventArgs args)
        {
+               rfid_start();
+       }
+               
+       private void rfid_start()
+       {
                string script_path = Util.GetRFIDCaptureScript();
 
                if(! File.Exists(script_path))
@@ -302,6 +370,10 @@ public partial class ChronoJumpWindow
                string filePath = Util.GetRFIDCapturedFile();
                Util.FileDelete(filePath);
 
+               //create a Timeout function to show changes on process
+               updatingRFIDGuiStuffNewRFID = "";
+               updatingRFIDGuiStuff = true;
+               GLib.Timeout.Add(1000, new GLib.TimeoutHandler(updateRFIDGuiStuff));
 
                // ---- start process ----
                //
@@ -342,21 +414,36 @@ public partial class ChronoJumpWindow
 
        private void rfid_watcher_changed(object source, FileSystemEventArgs e)
        {
+               LogB.Information("WATCHER");
                rfid_read();
+               rfid_reading = false;
 
                //if compujump, wakeup screen if it's off
-               if(configChronojump.Compujump == true)
-                       Networks.WakeUpRaspberryIfNeeded();
+               //if(configChronojump.Compujump == true)
+               //      Networks.WakeUpRaspberryIfNeeded();
        }
 
+       bool rfid_reading = false;
        private void rfid_read()
        {
+               //to avoid being called too continuously by watcher
+               if(rfid_reading)
+                       return;
+
+               rfid_reading = true;
+
                string filePath = Util.GetRFIDCapturedFile();
 
                LogB.Information("Changed file: " +  filePath);
 
                if(Util.FileExists(filePath))
-                       label_rfid.Text = Util.ReadFile(filePath, true);
+               {
+                       string rfid = Util.ReadFile(filePath, true);
+                       if(rfid != "")
+                       {
+                               updatingRFIDGuiStuffNewRFID = rfid;
+                       }
+               }
        }
 
 }
diff --git a/src/gui/person.cs b/src/gui/person.cs
index fea0926..a405927 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -1591,7 +1591,7 @@ public class PersonAddModifyWindow
                        currentPerson = new Person (personName, sex, dateTime,
                                        Constants.RaceUndefinedID,
                                        Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_countries), countries)),
-                                       textview_description.Buffer.Text,
+                                       textview_description.Buffer.Text, "", //future1: rfid
                                        Constants.ServerUndefinedID, false); //dbconOpened
                                        
                        LogB.Information("Going to insert personSession");
@@ -1608,7 +1608,7 @@ public class PersonAddModifyWindow
                        currentPerson = new Person (currentPerson.UniqueID, personName, sex, dateTime,
                                        Constants.RaceUndefinedID,
                                        Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_countries), countries)),
-                                       textview_description.Buffer.Text,
+                                       textview_description.Buffer.Text, "", //future1: rfid
                                        serverUniqueID);
                        SqlitePerson.Update (currentPerson); 
                
@@ -2222,7 +2222,7 @@ public class PersonAddMultipleWindow {
                                                        dateTime,
                                                        Constants.RaceUndefinedID,
                                                        Constants.CountryUndefinedID,
-                                                       "",                                     //description
+                                                       "", "",                                 
//description, future1: rfid
                                                        Constants.ServerUndefinedID
                                                        );
                                
diff --git a/src/json.cs b/src/json.cs
index 9e59dde..89ed1f2 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -31,9 +31,14 @@ using Mono.Unix;
 public class Json
 {
        public string ResultMessage;
-       string serverUrl = "http://api.chronojump.org:8080";;
+       static string serverUrl = "http://api.chronojump.org:8080";;
        //string serverUrl = "http://192.168.200.1:8080";;
 
+       public static void ChangeServerUrl(string url)
+       {
+               serverUrl = url;
+               LogB.Information("NEW URL MAXXX: " + serverUrl);
+       }
 
        public Json()
        {
@@ -266,6 +271,106 @@ public class Json
                return true;
        }
 
+       public Person GetPersonByRFID(string rfid)
+       {
+               Person person = new Person(-1);
+
+               // Create a request using a URL that can receive a post.
+               WebRequest request = WebRequest.Create (serverUrl + "/getPersonByRFID");
+
+               // Set the Method property of the request to POST.
+               request.Method = "POST";
+
+               // Set the ContentType property of the WebRequest.
+               request.ContentType = "application/json; Charset=UTF-8"; //but this is not enough, see this 
line:
+
+               // Creates the json object
+               JsonObject json = new JsonObject();
+               json.Add("rfid", rfid);
+               
+               // Converts it to a String
+               String js = json.ToString();
+
+               // Writes the json object into the request dataStream
+               Stream dataStream;
+               try {
+                       dataStream = request.GetRequestStream ();
+               } catch {
+                       this.ResultMessage =
+                               string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."),
+                               serverUrl);
+                       return person;
+               }
+
+               dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
+
+               dataStream.Close ();
+               
+               HttpWebResponse response;
+               try {
+                       response = (HttpWebResponse) request.GetResponse();
+               } catch {
+                       this.ResultMessage = 
+                               Catalog.GetString("KKKKKKKK") + "\n" +
+                               string.Format(Catalog.GetString("You are not connected to the Internet\nor 
{0} server is down."), 
+                               serverUrl);
+                       return person;
+               }
+
+               string responseFromServer;
+               using (var sr = new StreamReader(response.GetResponseStream()))
+               {
+                       responseFromServer = sr.ReadToEnd();
+               }
+
+               LogB.Information("GetPersonByRFID: " + responseFromServer);
+               
+               if(responseFromServer == "")
+                       LogB.Information(" Empty "); //mai
+               else if(responseFromServer == "[]")
+                       LogB.Information(" Empty2 "); //sempre que no esta el rfid al server
+               else {
+                       LogB.Information(" YES "); //TODO: processar: [[2, "(playername)", 82.0, 
"253,20,150,13"]]
+
+                       //patheticDeserialize("[[2, \"(playername)\", 82.0, \"253,20,150,13\"]]");
+                       person = patheticPersonDeserialize(responseFromServer);
+               }
+
+               return person;
+
+       }
+       public double LastPersonByRFIDWeight = 0;
+       private Person patheticPersonDeserialize(string str)
+       {
+               LogB.Information("str:|" + str + "|");
+               
+               string id = str.Substring(2, str.IndexOf(',') -2);
+               LogB.Information("id:|" + id + "|");
+
+               str = str.Substring(str.IndexOf('"') +1);
+               //LogB.Information("str:|" + str + "|");
+               
+               string player = str.Substring(0, str.IndexOf('"'));
+               LogB.Information("player:|" + player + "|");
+               
+               str = str.Substring(str.IndexOf(',') +2);
+               //LogB.Information("str:|" + str + "|");
+
+               string weight = str.Substring(0, str.IndexOf(','));
+               LogB.Information("weight:|" + weight + "|");
+               
+       
+               LastPersonByRFIDWeight = Convert.ToDouble(Util.ChangeDecimalSeparator(weight));
+               str = str.Substring(str.IndexOf('"') +1);
+               //LogB.Information("str:|" + str + "|");
+               
+               string rfid = str.Substring(0, str.LastIndexOf('"'));
+               LogB.Information("rfid:|" + rfid + "|");
+
+               return new Person(Convert.ToInt32(id), player, rfid);
+       }
+
+
        public bool UploadEncoderData()
        {
                return UploadEncoderData(1, 1, "lateral", "8100", 8);
diff --git a/src/person.cs b/src/person.cs
index efb3b7a..0681316 100644
--- a/src/person.cs
+++ b/src/person.cs
@@ -33,6 +33,7 @@ public class Person {
        private int race;
        private int countryID;
        private string description;
+       private string future1;         //rfid
        private int serverUniqueID; //not on server
 
        public Person() {
@@ -43,12 +44,29 @@ public class Person {
                this.uniqueID = uniqueID;
        }
 
+       //coming from compujump server
+       public Person(int uniqueID, string name, string rfid)
+       {
+               this.uniqueID = uniqueID;
+               this.name = name;
+               this.sex = "M";
+               this.dateBorn = DateTime.Now;
+               this.race = Constants.RaceUndefinedID;
+               this.countryID = Constants.CountryUndefinedID; //1
+               this.description = "";
+               this.future1 = rfid;
+               this.serverUniqueID = Constants.ServerUndefinedID;
+               
+               SqlitePerson.Insert(false,  
+                               uniqueID.ToString(), name, sex, dateBorn, race, countryID,
+                               description, future1, serverUniqueID);
+       }
 
        //suitable when we load a person from the database for being the current Person
        //we know uniqueID
        //used also in class PersonSessionTransaction where we define the uniqueID 
        public Person(int uniqueID, string name, string sex, DateTime dateBorn, 
-                      int race, int countryID, string description, int serverUniqueID) 
+                      int race, int countryID, string description, string future1, int serverUniqueID) 
        {
                //needed by the return of gui/personAddModifyWindow
                name = Util.RemoveTildeAndColon(name);
@@ -61,13 +79,14 @@ public class Person {
                this.race = race;
                this.countryID = countryID;
                this.description = description;
+               this.future1 = future1;
                this.serverUniqueID = serverUniqueID; //remember don't do this on server
        }
 
        //typical constructor
        //used when we create new person 
        //we don't know uniqueID
-       public Person(string name, string sex, DateTime dateBorn, int race, int countryID, string description,
+       public Person(string name, string sex, DateTime dateBorn, int race, int countryID, string 
description, string future1,
                        int serverUniqueID, bool dbconOpened) 
        {
                name = Util.RemoveTildeAndColon(name);
@@ -79,6 +98,7 @@ public class Person {
                this.race = race;
                this.countryID = countryID;
                this.description = description;
+               this.future1 = future1;
                this.serverUniqueID = serverUniqueID; //remember don't do this on server
 
                //insert in the person table
@@ -95,7 +115,7 @@ public class Person {
        public int InsertAtDB (bool dbconOpened, string tableName) {
                int myID = SqlitePerson.Insert(dbconOpened,  
                                uniqueID.ToString(), name, sex, dateBorn, race, countryID,
-                               description, serverUniqueID);
+                               description, future1, serverUniqueID);
                return myID;
        }
        
@@ -120,7 +140,7 @@ public class Person {
        {
                return uniqueID.ToString() + ", '"  + name + "', '" + sex + "', '" + 
                        UtilDate.ToSql(dateBorn) + "', " + race + ", " + countryID + ", '" +
-                       description + "', '', '', " +  //future1, future2
+                       description + "', '" + future1 + "', '', " +  //future1, future2
                        serverUniqueID;
        }
        
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 30487e7..ef7c1da 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2671,6 +2671,7 @@ class Sqlite
                                       pOld.Race,
                                       pOld.CountryID,
                                       pOld.Description,
+                                      "",      //future1: rfid
                                       pOld.ServerUniqueID
                                       );
                        p.InsertAtDB(true, Constants.PersonTable);
diff --git a/src/sqlite/person.cs b/src/sqlite/person.cs
index 7617550..9f59fe5 100644
--- a/src/sqlite/person.cs
+++ b/src/sqlite/person.cs
@@ -53,7 +53,7 @@ class SqlitePerson : Sqlite
         }
 
        public static int Insert(bool dbconOpened, string uniqueID, string name, string sex, DateTime 
dateBorn, 
-                       int race, int countryID, string description, int serverUniqueID)
+                       int race, int countryID, string description, string future1, int serverUniqueID)
        {
                LogB.SQL("going to insert");
                if(! dbconOpened)
@@ -68,7 +68,7 @@ class SqlitePerson : Sqlite
                string myString = "INSERT INTO " + Constants.PersonTable + 
                        " (uniqueID, name, sex, dateBorn, race, countryID, description, future1, future2, 
serverUniqueID) VALUES (" + uniqueID + ", \"" +
                        name + "\", \"" + sex + "\", \"" + UtilDate.ToSql(dateBorn) + "\", " + 
-                       race + ", " + countryID + ", \"" + description + "\", \"\", \"\", " + serverUniqueID 
+ ")";
+                       race + ", " + countryID + ", \"" + description + "\", \"" + future1 + "\", \"\", " + 
serverUniqueID + ")";
                
                dbcmd.CommandText = myString;
                LogB.SQL(dbcmd.CommandText.ToString());
@@ -88,15 +88,21 @@ class SqlitePerson : Sqlite
 
        //This is like SqlitePersonSession.Selectbut this returns a Person
        
+       public static Person Select(bool dbconOpened, int uniqueID) {
+               return Select(dbconOpened, " WHERE uniqueID = " + uniqueID);
+       }
        public static Person Select(int uniqueID) {
-               return Select(false, uniqueID);
+               return Select(false, " WHERE uniqueID = " + uniqueID);
+       }
+       public static Person SelectByRFID(string rfid) {
+               return Select(false, " WHERE future1 = \"" + rfid + "\"");
        }
-       public static Person Select(bool dbconOpened, int uniqueID)
+       public static Person Select(bool dbconOpened, string whereStr)
        {
                if(! dbconOpened)
                        Sqlite.Open();
 
-               dbcmd.CommandText = "SELECT * FROM " + Constants.PersonTable + " WHERE uniqueID == " + 
uniqueID;
+               dbcmd.CommandText = "SELECT * FROM " + Constants.PersonTable + whereStr;
                
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -114,6 +120,7 @@ class SqlitePerson : Sqlite
                                        Convert.ToInt32(reader[4].ToString()), //race
                                        Convert.ToInt32(reader[5].ToString()), //countryID
                                        reader[6].ToString(),                   //description
+                                       reader[7].ToString(),                   //future1: rfid
                                        Convert.ToInt32(reader[9].ToString()) //serverUniqueID
                                        );
                }
@@ -257,6 +264,7 @@ finishForeach:
                                                Convert.ToInt32(reader2[4].ToString()), //race
                                                Convert.ToInt32(reader2[5].ToString()), //countryID
                                                reader2[6].ToString(),                  //description
+                                               reader2[7].ToString(),                  //future1: rfid
                                                Convert.ToInt32(reader2[9].ToString()) //serverUniqueID
                                                );
                                arrayReturn.Add(p);
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index d08d6d1..30df64f 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -280,6 +280,7 @@ class SqlitePersonSession : Sqlite
                                        Convert.ToInt32(reader[4].ToString()),  //race
                                        Convert.ToInt32(reader[5].ToString()),  //countryID
                                        reader[6].ToString(),                   //description
+                                       reader[7].ToString(),                   //future1: rfid
                                        Convert.ToInt32(reader[9].ToString())   //serverUniqueID
                                        );
 


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