/[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 15:16:59	131
+++ trunk/xmltv_parser/main.cs	2013/03/14 13:13:46	142
@@ -200,7 +200,7 @@
             catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
 
-        
+
         void CreatControlsFromType(Type data_type)
         {
 #if USE_DYNAMIC_SORTING_FILTERING_CONTROLS
@@ -244,7 +244,7 @@
         {
             gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
         }
-        #endregion     
+        #endregion
 
 
         #region Column Sorting Support
@@ -257,52 +257,179 @@
             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 FilterByColumn(RadioButton button)
+        {
+            Type data_type;
+            string column = (button.Tag as string);
+            object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
+            XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);
+            dataGrid.DataSource = data;
+        }
+        private void btnFilter_Click(object sender, EventArgs e)
+        {
+            RadioButton button = GetSelectedFilteringControl();
+            FilterByColumn(button);                   
+        }
 
-       
+        private void dataGrid_SelectionChanged(object sender, EventArgs e)
+        {
+            try
+            {
+                DataGridView dgv = (DataGridView)sender;
+                //var row = dgv.SelectedRows[0]; // the row that was selected
+                //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]; }
+                RadioButton button = GetSelectedFilteringControl();
+                data = row.Cells[GetColumnIndexForRadioButton(button)].Value.ToString();
+                txtFilterText.Text = data;
+            }
+            catch (Exception ex)
+            {
+                gLog.Verbose.Error.WriteLine(ex.ToString());
+            }
+        }
+
+        private RadioButton GetSelectedFilteringControl()
+        {
+            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;
+            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)
+                {
+                    var cell = dgv.SelectedCells[0];
+                    row = dgv.Rows[cell.RowIndex];
+                }
+                if (dgv.SelectedRows.Count > 0)
+                {
+                    row = dgv.SelectedRows[0];
+                }
+                data = row.Cells[cellindex].Value.ToString();
+                txtFilterText.Text = data;
+            }
+        }
+        private void radio_filter_channelnumber_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+        private void radio_filter_title_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+
+        private void radio_filter_subtitle_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+
+        private void radio_filter_description_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+
+        private void radio_filter_channelname_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+
+        private void radio_filter_start_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
+        private void radio_filter_stop_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }       
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22