[chronojump/77] gui/person add/modify adapted to 77 tables



commit 613e2e072e1c8690494de0cde56ab17b2c1e972a
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Mar 1 16:10:36 2010 +0800

    gui/person add/modify adapted to 77 tables

 glade/chronojump.glade      |   24 ++++----
 src/gui/chronojump.cs       |    6 ++-
 src/gui/person.cs           |  117 +++++++++++++++++++++++++------------------
 src/person.cs               |    6 ++
 src/personSession.cs        |    8 +--
 src/sqlite/main.cs          |    4 +-
 src/sqlite/personSession.cs |   35 +++++++++++--
 7 files changed, 127 insertions(+), 73 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 035e287..84a74e4 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -18,8 +18,8 @@
         <child>
           <widget class="GtkLabel" id="label76">
             <property name="visible">True</property>
-            <property name="label" translatable="yes">Please fill these values
-(bold titles are required)</property>
+            <property name="label" translatable="yes">Please fill these values. &lt;b&gt;Bold&lt;/b&gt; titles are required.</property>
+            <property name="use_markup">True</property>
           </widget>
           <packing>
             <property name="expand">False</property>
@@ -46,8 +46,8 @@
                         <property name="visible">True</property>
                         <property name="n_rows">6</property>
                         <property name="n_columns">3</property>
-                        <property name="column_spacing">8</property>
-                        <property name="row_spacing">6</property>
+                        <property name="column_spacing">6</property>
+                        <property name="row_spacing">4</property>
                         <child>
                           <widget class="GtkLabel" id="label19">
                             <property name="visible">True</property>
@@ -355,8 +355,8 @@
                         <property name="visible">True</property>
                         <property name="n_rows">6</property>
                         <property name="n_columns">3</property>
-                        <property name="column_spacing">8</property>
-                        <property name="row_spacing">6</property>
+                        <property name="column_spacing">6</property>
+                        <property name="row_spacing">4</property>
                         <child>
                           <widget class="GtkLabel" id="label47">
                             <property name="visible">True</property>
@@ -566,12 +566,6 @@
                           </packing>
                         </child>
                         <child>
-                          <placeholder/>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
-                        <child>
                           <widget class="GtkLabel" id="label3">
                             <property name="visible">True</property>
                             <property name="xalign">0</property>
@@ -634,6 +628,12 @@
                             <property name="y_options">GTK_FILL</property>
                           </packing>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 209d374..ad7d2c4 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2021,7 +2021,8 @@ public class ChronoJumpWindow
 	}
 		
 	private void on_person_add_single_activate (object o, EventArgs args) {
-		personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, -1, prefsDigitsNumber); 
+		//personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, -1, prefsDigitsNumber); 
+		personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, new Person(-1), prefsDigitsNumber); 
 		//-1 means we are adding a new person
 		//if we were modifying it will be it's uniqueID
 		
@@ -2079,7 +2080,8 @@ public class ChronoJumpWindow
 	
 	private void on_edit_current_person_clicked (object o, EventArgs args) {
 		Log.WriteLine("modify person");
-		personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, currentPerson.UniqueID, prefsDigitsNumber);
+		//personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, currentPerson.UniqueID, prefsDigitsNumber);
+		personAddModifyWin = PersonAddModifyWindow.Show(app1, currentSession, currentPerson, prefsDigitsNumber);
 		personAddModifyWin.FakeButtonAccept.Clicked += new EventHandler(on_edit_current_person_accepted);
 	}
 	
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 7495573..d8db37e 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -848,6 +848,7 @@ public class PersonAddModifyWindow
 
 	private Person currentPerson;
 	private Session currentSession;
+	private PersonSession currentPersonSession;
 	private int personID;
 	private string sex = Constants.M;
 	private double weightIni;
@@ -858,7 +859,7 @@ public class PersonAddModifyWindow
 	//
 	//if we are adding a person, personID it's -1
 	//if we are modifying a person, personID is obviously it's ID
-	PersonAddModifyWindow (Gtk.Window parent, Session currentSession, int personID) {
+	PersonAddModifyWindow (Gtk.Window parent, Session currentSession, Person currentPerson) {
 		Glade.XML gladeXML;
 		gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "person_win", null);
 		gladeXML.Autoconnect(this);
@@ -868,9 +869,9 @@ public class PersonAddModifyWindow
 	
 		this.parent = parent;
 		this.currentSession = currentSession;
-		this.personID = personID;
+		this.currentPerson = currentPerson;
 
-		if(personID == -1)
+		if(currentPerson.UniqueID == -1)
 			adding = true;
 		else
 			adding = false;
@@ -965,10 +966,10 @@ public class PersonAddModifyWindow
 		sex = Constants.F;
 	}
 	
-	static public PersonAddModifyWindow Show (Gtk.Window parent, Session mySession, int personID, int pDN)
+	static public PersonAddModifyWindow Show (Gtk.Window parent, Session mySession, Person currentPerson, int pDN)
 	{
 		if (PersonAddModifyWindowBox == null) {
-			PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, personID);
+			PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession, currentPerson);
 		}
 
 		PersonAddModifyWindowBox.pDN = pDN;
@@ -1105,45 +1106,52 @@ public class PersonAddModifyWindow
 			mySpeciallityID = currentSession.PersonsSpeciallityID;
 			myLevelID = currentSession.PersonsPractice;
 		} else {
-			Person myPerson = SqlitePersonSession.PersonSelect(personID, currentSession.UniqueID); 
-		
-			entry1.Text = myPerson.Name;
-			if (myPerson.Sex == Constants.M) {
+			//PERSON STUFF
+			entry1.Text = currentPerson.Name;
+			if (currentPerson.Sex == Constants.M) {
 				radiobutton_man.Active = true;
 			} else {
 				radiobutton_woman.Active = true;
 			}
 
-			dateTime = myPerson.DateBorn;
+			dateTime = currentPerson.DateBorn;
 			if(dateTime == DateTime.MinValue)
 				label_date.Text = Catalog.GetString("Undefined");
 			else
 				label_date.Text = dateTime.ToLongDateString();
-
-			spinbutton_height.Value = myPerson.Height;
-			spinbutton_weight.Value = myPerson.Weight;
-
-			weightIni = myPerson.Weight; //store for tracking if changes
-		
-			mySportID = myPerson.SportID;
-			mySpeciallityID = myPerson.SpeciallityID;
-			myLevelID = myPerson.Practice;
-
-
-			TextBuffer tb = new TextBuffer (new TextTagTable());
-			tb.Text = myPerson.Description;
-			textview_description.Buffer = tb;
-
 			//country stuff
-			if(myPerson.CountryID != Constants.CountryUndefinedID) {
-				string [] countryString = SqliteCountry.Select(myPerson.CountryID);
+			if(currentPerson.CountryID != Constants.CountryUndefinedID) {
+				string [] countryString = SqliteCountry.Select(currentPerson.CountryID);
 				combo_continents.Active = UtilGtk.ComboMakeActive(continentsTranslated, 
 						Catalog.GetString(countryString[3]));
 				combo_countries.Active = UtilGtk.ComboMakeActive(countriesTranslated, 
 						Catalog.GetString(countryString[1]));
 			}
 
-			serverUniqueID = myPerson.ServerUniqueID;
+			tb.Text = currentPerson.Description;
+			textview_description.Buffer = tb;
+			
+			serverUniqueID = currentPerson.ServerUniqueID;
+			
+
+			//PERSONSESSION STUFF
+			//select a personSession of last session
+			//to obtain it's attributes
+			PersonSession myPS = SqlitePersonSession.Select(currentPerson.UniqueID, -1);
+
+			spinbutton_height.Value = myPS.Height;
+			spinbutton_weight.Value = myPS.Weight;
+
+			weightIni = myPS.Weight; //store for tracking if changes
+		
+			mySportID = myPS.SportID;
+			mySpeciallityID = myPS.SpeciallityID;
+			myLevelID = myPS.Practice;
+
+			TextBuffer tb = new TextBuffer (new TextTagTable());
+			tb.Text = myPS.Comments;
+			textview_comments.Buffer = tb;
+
 		}
 			
 		sport = SqliteSport.Select(mySportID);
@@ -1440,34 +1448,46 @@ public class PersonAddModifyWindow
 
 
 		if(adding) {
-			//currentPerson = new Person (entry1.Text, sex, dateFull, 
+			//here we add rows in the database
 			currentPerson = new Person (entry1.Text, sex, dateTime, 
-					(double) spinbutton_height.Value, (double) weight, 
-					sport.UniqueID, 
-					Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)),
-					Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
-					textview_description.Buffer.Text,
 					Constants.RaceUndefinedID,
 					Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)),
+					textview_description.Buffer.Text,
 					Constants.ServerUndefinedID,
 					currentSession.UniqueID);
-		} else {
-			//currentPerson = new Person (personID, entry1.Text, sex, dateFull, 
-			currentPerson = new Person (personID, entry1.Text, sex, dateTime, 
+					
+			currentPersonSession = new PersonSession (
+					currentPerson.UniqueID, currentSession.UniqueID, 
 					(double) spinbutton_height.Value, (double) weight, 
 					sport.UniqueID, 
 					Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)),
 					Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
-					textview_description.Buffer.Text,
+					textview_comments.Buffer.Text);
+		} else {
+			//here we update rows in the database
+			currentPerson = new Person (personID, entry1.Text, sex, dateTime, 
 					Constants.RaceUndefinedID,
 					Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)),
+					textview_description.Buffer.Text,
 					serverUniqueID);
-			
 			SqlitePerson.Update (currentPerson); 
-		
-			//change weight if needed
-			if((double) spinbutton_weight.Value != weightIni)
-				SqlitePersonSession.UpdateWeight (currentPerson.UniqueID, currentSession.UniqueID, (double) spinbutton_weight.Value); 
+
+			//person session stuff
+			//1.- search uniqueID
+			PersonSession ps = SqlitePersonSession.Select(personID, currentSession.UniqueID);
+			
+			//2.- create new instance with data from gui
+			currentPersonSession = new PersonSession (
+					ps.UniqueID,
+					currentPerson.UniqueID, currentSession.UniqueID, 
+					(double) spinbutton_height.Value, (double) weight, 
+					sport.UniqueID, 
+					Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)),
+					Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
+					textview_comments.Buffer.Text);
+			
+			//3.- update in database
+			SqlitePersonSession.Update (currentPersonSession); 
 		}
 
 		fakeButtonAccept.Click();
@@ -1486,11 +1506,12 @@ public class PersonAddModifyWindow
 		get { return fakeButtonAccept; }
 	}
 
-	public Person CurrentPerson 
-	{
-		get {
-			return currentPerson;
-		}
+	public Person CurrentPerson {
+		get { return currentPerson; }
+	}
+	
+	public PersonSession CurrentPersonSession {
+		get { return currentPersonSession; }
 	}
 	
 }
diff --git a/src/person.cs b/src/person.cs
index 8feca49..023dadd 100644
--- a/src/person.cs
+++ b/src/person.cs
@@ -38,6 +38,12 @@ public partial class Person {
 	
 	public Person() {
 	}
+	
+	//used when we create a new person, then uniqueID is -1
+	public Person(int uniqueID) {
+		this.uniqueID = uniqueID;
+	}
+
 
 	//suitable when we load a person from the database for being the current Person
 	//we know uniqueID
diff --git a/src/personSession.cs b/src/personSession.cs
index 6daa956..7b4d743 100644
--- a/src/personSession.cs
+++ b/src/personSession.cs
@@ -55,10 +55,10 @@ public partial class PersonSession {
 		this.practice = practice;
 		this.comments = comments;
 	}
-	
-	//typical constructor
+
 	//creation
-	//we don't know uniqueID
+	//we know personID but not personSession.UniqueID
+	//this adds to database
 	public PersonSession(int personID, int sessionID,
 			double height, double weight, int sportID, 
 			int speciallityID, int practice, string comments)
@@ -77,8 +77,6 @@ public partial class PersonSession {
 		//when insert as personSession we don't know uniqueID
 		uniqueID = -1;
 		int insertedID = this.InsertAtDB(false, Constants.PersonSessionTable);
-
-		//we need uniqueID for personSession
 		uniqueID = insertedID;
 
 		Log.WriteLine(this.ToString());
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index b09ccfc..bf02fe8 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -1362,7 +1362,7 @@ class Sqlite
 
 		foreach(int personID in myArray) {
 			//if person is not in other sessions, delete it from DB
-			if(! SqlitePersonSession.PersonExistsInPSW(personID))
+			if(! SqlitePersonSession.PersonExistsInPS(personID))
 				SqlitePerson.Delete(personID);
 		}
 	}
@@ -1386,7 +1386,7 @@ class Sqlite
 
 		foreach(int personID in myArray) {
 			//if person is not in other sessions, delete it from DB
-			if(! SqlitePersonSessionOld.PersonExistsInPSW(personID))
+			if(! SqlitePersonSessionOld.PersonExistsInPS(personID))
 				SqlitePersonOld.Delete(personID);
 		}
 	}
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 4400efc..cb208ba 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -126,6 +126,24 @@ class SqlitePersonSession : Sqlite
 		return myReturn;
 	}
 	
+	public static void Update(PersonSession ps)
+	{
+		dbcon.Open();
+		dbcmd.CommandText = "UPDATE " + Constants.PersonSessionTable + 
+			" SET personID = " + ps.PersonID + 
+			" SET sessionID = " + ps.SessionID + 
+			" SET height = " + Util.ConvertToPoint(ps.Height) + 
+			" SET weight = " + Util.ConvertToPoint(ps.Weight) + 
+			" SET sportID = " + ps.SportID + 
+			" SET speciallityID = " + ps.SpeciallityID + 
+			" SET practice = " + ps.Practice + 
+			" SET comments = '" + ps.Comments + 
+			"' WHERE uniqueID == " + ps.UniqueID;
+		Log.WriteLine(dbcmd.CommandText.ToString());
+		dbcmd.ExecuteNonQuery();
+		dbcon.Close();
+	}
+
 	//double
 	public static void UpdateAttribute(int personID, int sessionID, string attribute, double attrValue)
 	{
@@ -161,15 +179,24 @@ class SqlitePersonSession : Sqlite
 		dbcon.Close();
 		return exists;
 	}
-	
+
+	//if sessionID == -1
+	//then we search data in last sessionID
+	//this is used to know personSession attributes
+	//in a newly created person	
 	public static PersonSession Select(int personID, int sessionID)
 	{
 		string tps = Constants.PersonSessionTable;
+			
+		string sessionIDString = "";
+		if(sessionID == -1)
+			sessionIDString = " AND sessionID == " + sessionID +
+				" ORDER BY sessionID DESC limit 1";
 
 		dbcon.Open();
 		dbcmd.CommandText = "SELECT * FROM " + tps +
 			" WHERE uniqueID == " + uniqueID + 
-			" AND sessionID == " + sessionID;
+			sessionIDString;
 		
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		
@@ -319,7 +346,7 @@ class SqlitePersonSession : Sqlite
 		dbcmd.ExecuteNonQuery();
 
 		//if person is not in other sessions, delete it from DB
-		if(! PersonExistsInPSW(Convert.ToInt32(personID)))
+		if(! PersonExistsInPS(Convert.ToInt32(personID)))
 			SqlitePerson.Delete(Convert.ToInt32(personID));
 				
 		//delete normal jumps
@@ -367,7 +394,7 @@ class SqlitePersonSession : Sqlite
 		dbcon.Close();
 	}
 
-	public static bool PersonExistsInPSW(int personID)
+	public static bool PersonExistsInPS(int personID)
 	{
 		dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionTable + 
 			" WHERE personID == " + personID;



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