[chronojump] new sessionMode: MONTHLY. Each month a new session is created/used



commit 027ca5a1bbdf10e24ada3669f0cab49b3aa9c376
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jan 26 16:42:23 2017 +0100

    new sessionMode: MONTHLY. Each month a new session is created/used

 src/config.cs       |    2 +-
 src/gui/networks.cs |   33 ++++++++++++++++++++++++---------
 src/utilDate.cs     |    8 ++++++++
 3 files changed, 33 insertions(+), 10 deletions(-)
---
diff --git a/src/config.cs b/src/config.cs
index ea2cabc..0f264aa 100644
--- a/src/config.cs
+++ b/src/config.cs
@@ -25,7 +25,7 @@ using System.IO;
 public class Config
 {
        public enum AutodetectPortEnum { ACTIVE, DISCARDFIRST, INACTIVE }
-       public enum SessionModeEnum { STANDARD, UNIQUE }
+       public enum SessionModeEnum { STANDARD, UNIQUE, MONTHLY }
 
        public bool Maximized;
        public bool CustomButtons;
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index d7f683e..b834bf2 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -141,19 +141,34 @@ public partial class ChronoJumpWindow
                        hbox_encoder_sup_capture_analyze_two_buttons.Visible = false;
                }
 
-               if(configChronojump.SessionMode == Config.SessionModeEnum.UNIQUE)
+               if(configChronojump.SessionMode == Config.SessionModeEnum.UNIQUE || 
configChronojump.SessionMode == Config.SessionModeEnum.MONTHLY)
                {
                        main_menu.Visible = false;
                        hbox_menu_and_preferences_outside_menu.Visible = true;
 
-                       if(! Sqlite.Exists(false, Constants.SessionTable, "session")) {
-                               //this creates the session and inserts at DB
-                               currentSession = new Session(
-                                               "session", "", DateTime.Today,  //name, place, dateTime
-                                               Constants.SportUndefinedID, Constants.SpeciallityUndefinedID, 
Constants.LevelUndefinedID,
-                                               "", Constants.ServerUndefinedID); //comments, serverID
-                       } else
-                               currentSession = SqliteSession.SelectByName("session");
+                       if(configChronojump.SessionMode == Config.SessionModeEnum.UNIQUE)
+                       {
+                               if(! Sqlite.Exists(false, Constants.SessionTable, "session")) {
+                                       //this creates the session and inserts at DB
+                                       currentSession = new Session(
+                                                       "session", "", DateTime.Today,  //name, place, 
dateTime
+                                                       Constants.SportUndefinedID, 
Constants.SpeciallityUndefinedID, Constants.LevelUndefinedID,
+                                                       "", Constants.ServerUndefinedID); //comments, serverID
+                               } else
+                                       currentSession = SqliteSession.SelectByName("session");
+                       } else {
+                               //configChronojump.SessionMode == Config.SessionModeEnum.MONTHLY
+
+                               string yearMonthStr = UtilDate.GetCurrentYearMonthStr();
+                               if(! Sqlite.Exists(false, Constants.SessionTable, yearMonthStr)) {
+                                       //this creates the session and inserts at DB
+                                       currentSession = new Session(
+                                                       yearMonthStr, "", DateTime.Today,       //name, 
place, dateTime
+                                                       Constants.SportUndefinedID, 
Constants.SpeciallityUndefinedID, Constants.LevelUndefinedID,
+                                                       "", Constants.ServerUndefinedID); //comments, serverID
+                               } else
+                                       currentSession = SqliteSession.SelectByName(yearMonthStr);
+                       }
                        
                        on_load_session_accepted();
                }
diff --git a/src/utilDate.cs b/src/utilDate.cs
index 7c6aae3..2731bd4 100644
--- a/src/utilDate.cs
+++ b/src/utilDate.cs
@@ -21,6 +21,7 @@
 using System;
 using System.Text; //StringBuilder
 using System.Collections; //ArrayList
+using Mono.Unix;
 
 //this class tries to be a space for methods that are used in different classes
 public class UtilDate
@@ -86,4 +87,11 @@ public class UtilDate
                return dt;
        }
 
+       public static string GetCurrentYearMonthStr()
+       {
+               DateTime dt = DateTime.Now;
+
+               return UtilAll.DigitsCreate(dt.Year,4) + "-" + Catalog.GetString(dt.ToString("MMMM"));
+       }
+
 }


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