/[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 16:17:50	136
+++ trunk/xmltv_parser/main.cs	2013/03/13 16:59:40	137
@@ -257,78 +257,87 @@
             dataGrid.DataSource = datasource;
             ToggleDescedning();
         }
-        private void btnSortChannelName_Click(object sender, EventArgs e)
+
+        private void SortByColumn(Button button)
         {
+            string column = (button.Tag as string);
             object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "channelname");
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, column);
             dataGrid.DataSource = data;
             ToggleDescedning();
         }
 
+        private void btnSortChannelName_Click(object sender, EventArgs e)
+        {
+            Button button = (sender as Button);
+            SortByColumn(button);
+        }
+        private void btnSortChannelNumber_Click(object sender, EventArgs e)
+        {
+            Button button = (sender as Button);
+            SortByColumn(button);
+        }
         private void btnSortStart_Click(object sender, EventArgs e)
         {
-            object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "start");
-            dataGrid.DataSource = data;
-            ToggleDescedning();
+            Button button = (sender as Button);
+            SortByColumn(button);
         }
         private void btnSortStop_Click(object sender, EventArgs e)
         {
-            object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "stop");
-            dataGrid.DataSource = data;
-            ToggleDescedning();
+            Button button = (sender as Button);
+            SortByColumn(button);
         }
         private void btnSortTitle_Click(object sender, EventArgs e)
         {
-            object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "title");
-            dataGrid.DataSource = data;
-            ToggleDescedning();
+            Button button = (sender as Button);
+            SortByColumn(button);
         }
         private void btnSortSubTitle_Click(object sender, EventArgs e)
         {
-            object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "subtitle");
-            dataGrid.DataSource = data;
-            ToggleDescedning();
+            Button button = (sender as Button);
+            SortByColumn(button);
         }
         private void btnSortDescription_Click(object sender, EventArgs e)
         {
-            object data = dataGrid.DataSource;
-            XMLTV.CreateSorterFromDataSource(ref data, Descending, "description");
-            dataGrid.DataSource = data;
-            ToggleDescedning();
+            Button button = (sender as Button);
+            SortByColumn(button);
         }
         #endregion
-
-        private void btnFilter_Click(object sender, EventArgs e)
+        private void FilterByColumn(RadioButton button)
         {
             Type data_type;
-            // grab the data from the master source
+            string column = (button.Tag as string);
             object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
-            if (radio_filter_channelname.Checked)
+            XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);
+            dataGrid.DataSource = data;
+        }
+        private void btnFilter_Click(object sender, EventArgs e)
+        {            
+            if (radio_filter_channelnumber.Checked)
             {
-                XMLTV.CreateFilterFromDataSource(ref data, "channelname", txtFilterText.Text);
+                FilterByColumn(radio_filter_channelnumber);
             }
             else if (radio_filter_title.Checked)
             {
-                XMLTV.CreateFilterFromDataSource(ref data, "title", txtFilterText.Text);
+                FilterByColumn(radio_filter_title);
             }
             else if (radio_filter_subtitle.Checked)
             {
-                XMLTV.CreateFilterFromDataSource(ref data, "subtitle", txtFilterText.Text);
+                FilterByColumn(radio_filter_subtitle);
             }
             else if (radio_filter_description.Checked)
             {
-                XMLTV.CreateFilterFromDataSource(ref data, "description", txtFilterText.Text);
+                FilterByColumn(radio_filter_description);
+            }
+            else if (radio_filter_channelname.Checked)
+            {
+                FilterByColumn(radio_filter_channelname);
             }
             else
             {
                 // unknown filter
                 gLog.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, or description.");
-            }
-            dataGrid.DataSource = data;
+            }            
         }
 
         private void dataGrid_SelectionChanged(object sender, EventArgs e)
@@ -349,21 +358,25 @@
                 {
                     row = dgv.SelectedRows[0];
                 }
-                if (radio_filter_channelname.Checked)
+                if (radio_filter_channelnumber.Checked)
                 {
-                    data = row.Cells[0].Value.ToString();
+                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_channelnumber)].Value.ToString();
                 }
                 else if (radio_filter_title.Checked)
                 {
-                    data = row.Cells[3].Value.ToString();
+                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_title)].Value.ToString();
                 }
                 else if (radio_filter_subtitle.Checked)
                 {
-                    data = row.Cells[4].Value.ToString();
+                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_subtitle)].Value.ToString();
                 }
                 else if (radio_filter_description.Checked)
                 {
-                    data = row.Cells[5].Value.ToString();
+                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_description)].Value.ToString();
+                }
+                else if (radio_filter_channelname.Checked)
+                {
+                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_channelname)].Value.ToString();
                 }
                 else
                 {
@@ -380,10 +393,30 @@
         }
 
 
-        private void UpdateFilterText(RadioButton radio, DataGridView dgv, int cellindex)
+        private int GetColumnIndexForRadioButton(RadioButton radio)
+        {
+            return GetColumnIndex(radio.Tag as string);
+        }
+        private int GetColumnIndex(string columnname)
         {
+            int index =0;
+            Type t = typeof(IProgramDefinition);
+
+            var props = t.GetProperties();
+            foreach (var prop in props)
+            {
+                if (prop.Name.ToLower() == columnname.ToLower()) { break; }
+                index++;
+            }
+            return index;
+        }
+
+        private void UpdateFilterText(RadioButton radio, DataGridView dgv)
+        {            
             if (radio.Checked)
             {
+                int cellindex = GetColumnIndexForRadioButton(radio);
+                string t = radio.Tag as string;
                 DataGridViewRow row = null;
                 string data = string.Empty;
                 if (dgv.SelectedCells.Count > 0)
@@ -399,29 +432,39 @@
                 txtFilterText.Text = data;
             }
         }
-        private void radio_filter_channelname_CheckedChanged(object sender, EventArgs e)
+        private void radio_filter_channelnumber_CheckedChanged(object sender, EventArgs e)
         {
             RadioButton radio = (sender as RadioButton);
-            UpdateFilterText(radio, dataGrid, 0);
+            UpdateFilterText(radio, dataGrid);
         }
-
         private void radio_filter_title_CheckedChanged(object sender, EventArgs e)
         {
             RadioButton radio = (sender as RadioButton);
-            UpdateFilterText(radio, dataGrid, 3);
+            UpdateFilterText(radio, dataGrid);
         }
 
         private void radio_filter_subtitle_CheckedChanged(object sender, EventArgs e)
         {
             RadioButton radio = (sender as RadioButton);
-            UpdateFilterText(radio, dataGrid,4);
+            UpdateFilterText(radio, dataGrid);
         }
 
         private void radio_filter_description_CheckedChanged(object sender, EventArgs e)
         {
             RadioButton radio = (sender as RadioButton);
-            UpdateFilterText(radio, dataGrid,5);
+            UpdateFilterText(radio, dataGrid);
+        }
+
+        private void radio_filter_channelname_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
         }
+
+       
+
+      
+       
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22