/[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/14 13:13:46	142
+++ trunk/xmltv_parser/main.cs	2013/03/14 13:43:21	143
@@ -196,6 +196,7 @@
                 //XMLTV.CreateSorterFromDataSource(ref datasource, "title");
                 dataGrid.DataSource = datasource;
                 flow_datagrid_sort.Enabled = true;
+                btnSort.PerformClick();
             }
             catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
@@ -246,10 +247,55 @@
         }
         #endregion
 
+        #region Datasource support / events
+        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];
+                }
 
-        #region Column Sorting Support
-        private bool Descending = false;
-        private void ToggleDescedning() { Descending = Descending ? false : true; }
+                if (row != null)
+                {
+                    RadioButton button = GetSelectedFilteringControl();
+                    int index = GetColumnIndexForRadioButton(button);
+                    data = row.Cells[index].Value.ToString();
+                    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;
+        }
+        #endregion
+        #region Reset event
         private void btnResetSort_Click(object sender, EventArgs e)
         {
             Type data_type;
@@ -257,52 +303,8 @@
             dataGrid.DataSource = datasource;
             ToggleDescedning();
         }
-
-        private void SortByColumn(Button button)
-        {
-            string column = (button.Tag as string);
-            object data = dataGrid.DataSource;
-            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)
-        {
-            Button button = (sender as Button);
-            SortByColumn(button);
-        }
-        private void btnSortStop_Click(object sender, EventArgs e)
-        {
-            Button button = (sender as Button);
-            SortByColumn(button);
-        }
-        private void btnSortTitle_Click(object sender, EventArgs e)
-        {
-            Button button = (sender as Button);
-            SortByColumn(button);
-        }
-        private void btnSortSubTitle_Click(object sender, EventArgs e)
-        {
-            Button button = (sender as Button);
-            SortByColumn(button);
-        }
-        private void btnSortDescription_Click(object sender, EventArgs e)
-        {
-            Button button = (sender as Button);
-            SortByColumn(button);
-        }
         #endregion
+        #region Filtering events
         private void FilterByColumn(RadioButton button)
         {
             Type data_type;
@@ -311,38 +313,11 @@
             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)
+            foreach (var c in grpFilter_flow.Controls)
             {
                 button = (c as RadioButton);
                 if (button != null) { if (button.Checked) { control_selected = true; break; } }
@@ -350,28 +325,14 @@
             }
             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.");
+                gLog.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, description, start, or stop.");
+                //throw new InvalidOperationException("No filtering control is currently selected.");
+                return button;
             }
             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);
@@ -391,6 +352,11 @@
                 txtFilterText.Text = data;
             }
         }
+        private void btnFilter_Click(object sender, EventArgs e)
+        {
+            RadioButton button = GetSelectedFilteringControl();
+            FilterByColumn(button);
+        }
         private void radio_filter_channelnumber_CheckedChanged(object sender, EventArgs e)
         {
             RadioButton radio = (sender as RadioButton);
@@ -401,25 +367,21 @@
             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);
@@ -429,7 +391,43 @@
         {
             RadioButton radio = (sender as RadioButton);
             UpdateFilterText(radio, dataGrid);
-        }       
+        }
+        #endregion
+        #region Sorting events
+        private bool Descending = false;
+        private void ToggleDescedning() { Descending = Descending ? false : true; }
+        private void SortByColumn(RadioButton button)
+        {
+            string column = (button.Tag as string);
+            object data = dataGrid.DataSource;
+            XMLTV.CreateSorterFromDataSource(ref data, Descending, column);
+            dataGrid.DataSource = data;
+            ToggleDescedning();
+        }
+        private RadioButton GetSelectedSortControl()
+        {
+            bool control_selected = false;
+            RadioButton button = new RadioButton();
+            foreach (var c in grpSort_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 sort value used.  Was not: channelname, title, subtitle, description, stop, or start.");
+                //throw new InvalidOperationException("No sorting control is currently selected.");
+                return button;
+            }
+            else { return button; }
+        }
+        private void btnSort_Click(object sender, EventArgs e)
+        {
+            RadioButton button = GetSelectedSortControl();
+            SortByColumn(button);
+        }
+        #endregion
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22