/[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/13 16:59:40	137
@@ -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,51 +257,213 @@
             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)
+        {            
+            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.");
+            }            
+        }
+
+        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];
+                }
+                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.");
+                }
+
+                txtFilterText.Text = data;
+            }
+            catch (Exception ex)
+            {
+                gLog.Verbose.Error.WriteLine(ex.ToString());
+            }
+        }
+
+
+        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);
+        }
+
+       
 
+      
        
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22