/[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:59:40	137
+++ trunk/xmltv_parser/main.cs	2013/03/14 12:24:47	139
@@ -312,32 +312,9 @@
             dataGrid.DataSource = data;
         }
         private void btnFilter_Click(object sender, EventArgs e)
-        {            
-            if (radio_filter_channelnumber.Checked)
-            {
-                FilterByColumn(radio_filter_channelnumber);
-            }
-            else if (radio_filter_title.Checked)
-            {
-                FilterByColumn(radio_filter_title);
-            }
-            else if (radio_filter_subtitle.Checked)
-            {
-                FilterByColumn(radio_filter_subtitle);
-            }
-            else if (radio_filter_description.Checked)
-            {
-                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.");
-            }            
+        {
+            RadioButton button = GetSelectedFilteringControl();
+            FilterByColumn(button);                   
         }
 
         private void dataGrid_SelectionChanged(object sender, EventArgs e)
@@ -349,41 +326,10 @@
                 //var cell = dgv.SelectedCells[0];
                 DataGridViewRow row = null;
                 string data = string.Empty;
-                if (dgv.SelectedCells.Count > 0)
-                {
-                    var cell = dgv.SelectedCells[0];
-                    row = dgv.Rows[cell.RowIndex];
-                }
-                if (dgv.SelectedRows.Count > 0)
-                {
-                    row = dgv.SelectedRows[0];
-                }
-                if (radio_filter_channelnumber.Checked)
-                {
-                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_channelnumber)].Value.ToString();
-                }
-                else if (radio_filter_title.Checked)
-                {
-                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_title)].Value.ToString();
-                }
-                else if (radio_filter_subtitle.Checked)
-                {
-                    data = row.Cells[GetColumnIndexForRadioButton(radio_filter_subtitle)].Value.ToString();
-                }
-                else if (radio_filter_description.Checked)
-                {
-                    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
-                {
-                    // unknown filter
-                    gLog.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, or description.");
-                }
-
+                if (dgv.SelectedCells.Count > 0) { var cell = dgv.SelectedCells[0]; row = dgv.Rows[cell.RowIndex]; }
+                if (dgv.SelectedRows.Count > 0) { row = dgv.SelectedRows[0]; }
+                RadioButton button = GetSelectedFilteringControl();
+                data = row.Cells[GetColumnIndexForRadioButton(button)].Value.ToString();
                 txtFilterText.Text = data;
             }
             catch (Exception ex)
@@ -392,11 +338,24 @@
             }
         }
 
-
-        private int GetColumnIndexForRadioButton(RadioButton radio)
+        private RadioButton GetSelectedFilteringControl()
         {
-            return GetColumnIndex(radio.Tag as string);
+            bool control_selected = false;
+            RadioButton button = new RadioButton();
+            foreach(var c in grpFilter_flow.Controls)
+            {
+                button = (c as RadioButton);
+                if (button != null) { if (button.Checked) { control_selected = true; break; } }
+                else { continue; }
+            }
+            if (!control_selected)
+            {
+                gLog.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, or description.");
+                throw new InvalidOperationException("No filtering control is currently selected.");
+            }
+            else { return button; }
         }
+        private int GetColumnIndexForRadioButton(RadioButton radio) { return GetColumnIndex(radio.Tag as string); }
         private int GetColumnIndex(string columnname)
         {
             int index =0;

 

  ViewVC Help
Powered by ViewVC 1.1.22