/[xmltv_parser]/trunk/xmltv_parser/main.cs
ViewVC logotype

Diff of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/xmltv_parser/main.cs	2013/03/13 12:00:01	127
+++ trunk/xmltv_parser/main.cs	2013/03/13 15:16:59	131
@@ -1,5 +1,6 @@
 //#define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
 //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
+//#define USE_DYNAMIC_SORTING_FILTERING_CONTROLS // when defined will setup dynamic sorting and filtering controls for XMLTV Data
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -189,14 +190,119 @@
                     catch { }
                     return;
                 }
-                object datasource = XMLTV.CreateDataSourceFromObject(XMLTV.GetPrograms());
-                XMLTV.CreateSorterFromDataSource(ref datasource, "title");
+                Type data_type;
+                object datasource = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
+                CreatControlsFromType(data_type);
+                //XMLTV.CreateSorterFromDataSource(ref datasource, "title");
                 dataGrid.DataSource = datasource;
+                flow_datagrid_sort.Enabled = true;
             }
             catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
+
+        
+        void CreatControlsFromType(Type data_type)
+        {
+#if USE_DYNAMIC_SORTING_FILTERING_CONTROLS
+              _CreatControlsFromType(data_type);
+#else
+            gLog.Warn.WriteLine("Dynamic creation of sorting and filtering controls has not been enabled.");
+            gLog.Warn.WriteLine("To enable: #define USE_DYNAMIC_SORTING_FILTERING_CONTROLS");
+#endif
+        }
+        [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
+        void _CreatControlsFromType(Type data_type)
+        {
+            string strType = data_type.Name;
+            switch (strType)
+            {
+                case "IChannelDefintionList": CreateChannelDefinitionControls(data_type); break;
+                case "IProgramDefinitionList": CreateProgramDefinitionControls(data_type); break;
+                case "IXMLTVSource": CreateSourceDefinitionControls(data_type); break;
+                default: CreateDefaultControls(data_type); break;
+            }
+        }
+        [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
+        void CreateDefaultControls(Type data_type)
+        {
+            // no default controls
+            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+        }
+        [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
+        void CreateSourceDefinitionControls(Type data_type)
+        {
+            // no controls needed
+            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+        }
+        [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
+        void CreateChannelDefinitionControls(Type data_type)
+        {
+            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+        }
+        [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
+        void CreateProgramDefinitionControls(Type data_type)
+        {
+            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+        }
+        #endregion     
+
+
+        #region Column Sorting Support
+        private bool Descending = false;
+        private void ToggleDescedning() { Descending = Descending ? false : true; }
+        private void btnResetSort_Click(object sender, EventArgs e)
+        {
+            Type data_type;
+            object datasource = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
+            dataGrid.DataSource = datasource;
+            ToggleDescedning();
+        }
+        private void btnSortChannelName_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "channelname");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+
+        private void btnSortStart_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "start");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+        private void btnSortStop_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "stop");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+        private void btnSortTitle_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "title");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+        private void btnSortSubTitle_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "subtitle");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+        private void btnSortDescription_Click(object sender, EventArgs e)
+        {
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, "description");
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
         #endregion
 
+       
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22