[chronojump] ExecuteAuto preparing to save in SQL



commit 7f7a33d5affb42c6d9500a7c7169f61475322dea
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Oct 10 19:35:15 2014 +0200

    ExecuteAuto preparing to save in SQL

 src/executeAuto.cs     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 src/gui/executeAuto.cs |   37 ++++++++++++++++++++++++++-----------
 2 files changed, 70 insertions(+), 11 deletions(-)
---
diff --git a/src/executeAuto.cs b/src/executeAuto.cs
index abf8db9..b4e1794 100644
--- a/src/executeAuto.cs
+++ b/src/executeAuto.cs
@@ -20,6 +20,7 @@
 
 using System;
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 
 public class ExecuteAuto {
        public enum ModeTypes { BY_PERSONS, BY_TESTS, BY_SERIES }
@@ -117,3 +118,46 @@ public class ExecuteAuto {
        ~ExecuteAuto() {}       
 }
 
+public class ExecuteAutoSQL 
+{
+       private string name;
+       private ExecuteAuto.ModeTypes mode;
+       private List<int> serie1IDs;
+       private List<int> serie2IDs;
+       private List<int> serie3IDs;
+       //private string future1;
+       //private string future2;
+       //private string future3;
+       
+       public ExecuteAutoSQL(string name, ExecuteAuto.ModeTypes mode, List<int> serie1IDs, List<int> 
serie2IDs, List<int> serie3IDs) 
+       {
+               this.name = name;
+               this.mode = mode;
+               this.serie1IDs = serie1IDs;
+               this.serie2IDs = serie2IDs;
+               this.serie3IDs = serie3IDs;
+       }
+
+
+       private string serieIDsToStr(List<int> serieIDs) 
+       {
+               string str = "";
+               string sep = "";
+               foreach(int i in serieIDs) {
+                       str += sep + i.ToString();
+                       sep = ":";
+               }
+               return str;
+       }
+       public void SaveToSQL() 
+       {
+               Log.WriteLine(name + "\n" + mode + "\n" + serieIDsToStr(serie1IDs) + "\n" + 
serieIDsToStr(serie2IDs) + "\n" + serieIDsToStr(serie3IDs));
+               
+               //TODO: send this to SQL, and add there the future1, future2, future3 strs
+               //SqliteExecuteAuto.Save(false, name, mode, serieIDsToStr(serie1IDs), 
serieIDsToStr(serie2IDs), serieIDsToStr(serie3IDs));
+
+       }
+
+       ~ExecuteAutoSQL() {}    
+}
+
diff --git a/src/gui/executeAuto.cs b/src/gui/executeAuto.cs
index 2b863f8..82cb1d6 100644
--- a/src/gui/executeAuto.cs
+++ b/src/gui/executeAuto.cs
@@ -23,6 +23,7 @@ using Gtk;
 using Gdk;
 using Glade;
 using System.Collections; //ArrayList
+using System.Collections.Generic; //List<T>
 using Mono.Unix;
 
 
@@ -74,6 +75,7 @@ public class ExecuteAutoWindow
        Gtk.Window parent;
        int sessionID;
 
+       ExecuteAuto.ModeTypes mode;
        ArrayList orderedData;
        
        public Gtk.Button FakeButtonAccept; //to return orderedData
@@ -271,6 +273,8 @@ public class ExecuteAutoWindow
                                        new String [] { treeviewSerie3Array.Count.ToString(), tc.trName } );
                }
                
+               button_save.Sensitive = (treeviewSerie1Array.Count > 0 && entry_save.Text.ToString().Length > 
0);
+               
                //a test is added, sensitivize "next" button
                button_next.Sensitive = true;
        }
@@ -278,16 +282,27 @@ public class ExecuteAutoWindow
 
        private void on_entry_save_changed(object o, EventArgs args) 
        {
-               button_save.Sensitive = (entry_save.Text.ToString().Length > 0);
+               button_save.Sensitive = (treeviewSerie1Array.Count > 0 && entry_save.Text.ToString().Length > 
0);
        }
 
        private void on_button_save_clicked(object o, EventArgs args) 
        {
                //si no existeix a la BD amab aquest nom...
-               new DialogMessage(Constants.MessageTypes.INFO, string.Format(
-                                       //Catalog.GetString("Sorry, this sport '{0}' already exists in 
database"), 
-                                       "will save this stuff: '{0}'", 
-                                       entry_save.Text.ToString()));
+               //new DialogMessage(Constants.MessageTypes.INFO, string.Format(
+               //                      //Catalog.GetString("Sorry, this sport '{0}' already exists in 
database"), 
+               //                      "will save this stuff: '{0}'", 
+               //                      entry_save.Text.ToString()));
+
+               ExecuteAutoSQL eaSQL = new ExecuteAutoSQL(entry_save.Text.ToString(), mode, 
+                               getTrComboInts(treeviewSerie1Array), getTrComboInts(treeviewSerie2Array), 
getTrComboInts(treeviewSerie3Array));
+               eaSQL.SaveToSQL();
+       }
+
+       private List<int> getTrComboInts(ArrayList arrayTrCombo) {
+               List<int> IDs = new List<int>();
+               foreach(TrCombo tr in arrayTrCombo)
+                       IDs.Add(tr.id);
+               return IDs;
        }
 
        //true means "by series" (shows more stuff)
@@ -340,6 +355,12 @@ public class ExecuteAutoWindow
        private void on_button_next_clicked (object o, EventArgs args)
        {
                if(notebook.CurrentPage == 0) {
+                       mode = ExecuteAuto.ModeTypes.BY_PERSONS;
+                       if(radio_by_tests.Active)
+                               mode = ExecuteAuto.ModeTypes.BY_TESTS;
+                       else if(radio_by_series.Active)
+                               mode = ExecuteAuto.ModeTypes.BY_SERIES;
+
                        showSeriesStuff(radio_by_series.Active);
                        notebook.NextPage();
                
@@ -347,12 +368,6 @@ public class ExecuteAutoWindow
                        button_next.Sensitive = false;
                }
                else if(notebook.CurrentPage == 1) {
-                       ExecuteAuto.ModeTypes mode = ExecuteAuto.ModeTypes.BY_PERSONS;
-                       if(radio_by_tests.Active)
-                               mode = ExecuteAuto.ModeTypes.BY_TESTS;
-                       else if(radio_by_series.Active)
-                               mode = ExecuteAuto.ModeTypes.BY_SERIES;
-
                        ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(sessionID);
                        orderedData = ExecuteAuto.CreateOrder(mode, persons,  
                                        treeviewSerie1Array, treeviewSerie2Array, treeviewSerie3Array);


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