Advertisement
dajinn

Blackboard_Activity_Accumulator

Sep 10th, 2014
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Windows.Documents;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Reflection;
  14. using System.Collections;
  15.  
  16.  
  17. namespace Blackboard_Activity_Accumulator
  18. {
  19.    
  20.     public static class ExtensionMethods
  21.     {
  22.      
  23.         public static void DoubleBuffered(this DataGridView dgv, bool setting)
  24.        {
  25.            Type dgvType = dgv.GetType();
  26.             PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
  27.               BindingFlags.Instance | BindingFlags.NonPublic);
  28.             pi.SetValue(dgv, setting, null);
  29.         }
  30.     }
  31.  
  32.  
  33.     public partial class Form1 : Form
  34.     {
  35.         StringFormat strFormat; //Used to format the grid rows.
  36.         ArrayList arrColumnLefts = new ArrayList();//Used to save left coordinates of columns
  37.         ArrayList arrColumnWidths = new ArrayList();//Used to save column widths
  38.         int iCellHeight = 0; //Used to get/set the datagridview cell height
  39.         int iTotalWidth = 0; //
  40.  
  41.         int iRow = 0;//Used as counter
  42.         bool bFirstPage = false; //Used to check whether we are printing first page
  43.         bool bNewPage = false;// Used to check whether we are printing a new page
  44.         int iHeaderHeight = 0; //Used for the header height
  45.  
  46.        
  47.  
  48.  
  49.         public Form1()
  50.         {
  51.             InitializeComponent();
  52.             dataGridView1.DoubleBuffered(true);
  53.             this.Location = new Point(0, 0);
  54.             this.Size = Screen.PrimaryScreen.WorkingArea.Size;
  55.  
  56.         }
  57.  
  58.  
  59.  
  60.  
  61.         private void btnRunQuery_Click(object sender, EventArgs e)
  62.         {
  63.             if (txtBoxUsername.Text == "" && txtBoxCourseID.Text == "")
  64.             {
  65.                 MessageBox.Show("The username and course ID fields were blank.",
  66.                 "Warning",
  67.                 MessageBoxButtons.OK,
  68.                 MessageBoxIcon.Exclamation,
  69.                 MessageBoxDefaultButton.Button1);
  70.             }
  71.             else if (txtBoxUsername.Text == "" && txtBoxCourseID.Text != "")
  72.             {
  73.                 MessageBox.Show("The username field was blank.",
  74.                 "Warning",
  75.                 MessageBoxButtons.OK,
  76.                 MessageBoxIcon.Exclamation,
  77.                 MessageBoxDefaultButton.Button1);
  78.             }
  79.             else if (txtBoxUsername.Text != "" && txtBoxCourseID.Text == "")
  80.             {
  81.  
  82.  
  83.                 SqlConnection myConnection = new SqlConnection("user id=<removed_for_security>;" +
  84.                                         "password=<removed_for_security>;server=<removed_for_security>;" +
  85.                                         "Trusted_Connection=no;" +
  86.                                         "connection timeout=30");
  87.                 try
  88.                 {
  89.                     myConnection.Open();
  90.                 }
  91.                 catch (Exception ex1)
  92.                 {
  93.                     Console.WriteLine(ex1.ToString());
  94.                 }
  95.                 string username = string.Empty;
  96.                 myCommand1.Parameters.Add(new SqlParameter("@userID", System.Data.SqlDbType.VarChar));
  97.                 myCommand1.Parameters["@userID"].Value = txtBoxUsername.Text;
  98.                 SqlCommand myCommand1 = new SqlCommand("use BBLEARN select user_id from users where user_id = @userID", myConnection);
  99.                 username = (string)myCommand1.ExecuteScalar();
  100.  
  101.  
  102.  
  103.                 if (username == null)
  104.                 {
  105.                     MessageBox.Show("A user by the handle of " + txtBoxUsername.Text + " could not be identified in the database. Their Blackboard account may be disabled. Please double check your entry and try again.",
  106.                 "Warning",
  107.                 MessageBoxButtons.OK,
  108.                 MessageBoxIcon.Exclamation,
  109.                 MessageBoxDefaultButton.Button1);
  110.                 }
  111.  
  112.  
  113.                 else
  114.                 {
  115.  
  116.                     try
  117.                     {
  118.                 myCommand.Parameters.Add(new SqlParameter("@userID", System.Data.SqlDbType.VarChar));
  119.                 myCommand.Parameters["@userID"].Value = txtBoxUsername.Text;
  120.                         SqlCommand myCommand = new SqlCommand("SELECT u.user_id, aa.timestamp, cm.batch_uid, cc.title, aa.event_type, aa.data, aa.session_id FROM users u INNER JOIN activity_accumulator aa on u.pk1 = aa.user_pk1 LEFT JOIN course_main cm ON aa.course_pk1 = cm.pk1 LEFT JOIN course_contents cc on aa.content_pk1 = cc.pk1 WHERE u.user_id = @userID AND DateDiff(Hour, aa.timestamp, CURRENT_TIMESTAMP) <= 120 UNION SELECT u.user_id, aa.timestamp, cm.batch_uid, cc.title, aa.event_type, aa.data, aa.session_id FROM users u INNER JOIN activity_accumulator_queue aa on u.pk1 = aa.user_pk1 LEFT JOIN course_main cm ON aa.course_pk1 = cm.pk1 LEFT JOIN course_contents cc on aa.content_pk1 = cc.pk1 WHERE u.user_id = @userID AND DateDiff(Hour, aa.timestamp, CURRENT_TIMESTAMP) <= 120 ORDER BY aa.timestamp desc", myConnection);
  121.                         SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
  122.                         DataTable t = new DataTable();
  123.                         adapter.Fill(t);
  124.                        
  125.                         dataGridView1.DataSource = t;
  126.  
  127.                     }
  128.                     catch (Exception ex2)
  129.                     {
  130.                         Console.WriteLine(ex2.ToString());
  131.                     }
  132.  
  133.                     try
  134.                     {
  135.                         myConnection.Close();
  136.                     }
  137.                     catch (Exception ex3)
  138.                     {
  139.                         Console.WriteLine(ex3.ToString());
  140.                     }
  141.                 }
  142.             }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.             else
  150.             {
  151.                 SqlConnection myConnection = new SqlConnection("user id=<removed_for_security>;" +
  152.                                        "password=<removed_for_security>;server=<removed_for_security>;" +
  153.                                        "Trusted_Connection=no;" +
  154.                                        "connection timeout=30");
  155.                 try
  156.                 {
  157.                     myConnection.Open();
  158.                 }
  159.                 catch (Exception ex1)
  160.                 {
  161.                     Console.WriteLine(ex1.ToString());
  162.                 }
  163.                 string username = string.Empty;
  164.                 myCommand1.Parameters.Add(new SqlParameter("@userID", System.Data.SqlDbType.VarChar));
  165.                 myCommand1.Parameters["@userID"].Value = txtBoxUsername.Text;
  166.                 SqlCommand myCommand1 = new SqlCommand("use BBLEARN select user_id from users where user_id = @userID", myConnection);
  167.                 username = (string)myCommand1.ExecuteScalar();
  168.  
  169.                 string courseID = string.Empty;
  170.                 myCommand2.Parameters.Add(new SqlParameter("@courseID", System.Data.SqlDbType.VarChar));
  171.                 myCommand2.Parameters["@courseID"].Value = txtBoxCourseID.Text;
  172.                 SqlCommand myCommand2 = new SqlCommand("use BBLEARN select course_id from course_main where course_id = @courseID", myConnection);
  173.                 courseID = (string)myCommand2.ExecuteScalar();
  174.  
  175.                 try
  176.                 {
  177.                     myConnection.Close();
  178.                 }
  179.                 catch (Exception ex3)
  180.                 {
  181.                     Console.WriteLine(ex3.ToString());
  182.                 }
  183.  
  184.                 int invalidDataCounter = -1;
  185.  
  186.                 if (username == null)
  187.                 {
  188.                     invalidDataCounter = 0;
  189.                 }
  190.                 if (courseID == null)
  191.                 {
  192.                     invalidDataCounter = 1;
  193.                 }
  194.                 if (username == null && courseID == null)
  195.                 {
  196.                     invalidDataCounter = 2;
  197.                 }
  198.  
  199.                 switch (invalidDataCounter)
  200.                 {
  201.                     case 0:
  202.                         MessageBox.Show("A user by the handle of " + txtBoxUsername.Text + " could not be identified in the database. Their Blackboard account may be disabled. Please double check your entry and try again.",
  203.                 "Warning",
  204.                 MessageBoxButtons.OK,
  205.                 MessageBoxIcon.Exclamation,
  206.                 MessageBoxDefaultButton.Button1);
  207.                         break;
  208.                     case 1:
  209.                         MessageBox.Show("A course by the ID of " + txtBoxCourseID.Text + " could not be identified in the database. The course might be disabled if it didn't make. Please double check your entry and try again. ",
  210.                 "Warning",
  211.                 MessageBoxButtons.OK,
  212.                 MessageBoxIcon.Exclamation,
  213.                 MessageBoxDefaultButton.Button1);
  214.                         break;
  215.                     case 2:
  216.                         MessageBox.Show("Both the username and course ID were invalid. Please double check your entries and try again.",
  217.                 "Warning",
  218.                 MessageBoxButtons.OK,
  219.                 MessageBoxIcon.Exclamation,
  220.                 MessageBoxDefaultButton.Button1);
  221.                         break;
  222.                     default:
  223.                         break;
  224.                 }
  225.                 if (invalidDataCounter == -1)
  226.                 {
  227.                     try
  228.                     {
  229.                         myConnection.Open();
  230.                     }
  231.                     catch (Exception ex1)
  232.                     {
  233.                         Console.WriteLine(ex1.ToString());
  234.                     }
  235.                     try
  236.                     {
  237. myCommand.Parameters.Add(new SqlParameter("@userID", System.Data.SqlDbType.VarChar));
  238.                 myCommand.Parameters["@userID"].Value = txtBoxUsername.Text;
  239. myCommand.Parameters.Add(new SqlParameter("@courseID", System.Data.SqlDbType.VarChar));
  240.                 myCommand.Parameters["@courseID"].Value = txtBoxCourseID.Text;
  241.                         SqlCommand myCommand = new SqlCommand("SELECT u.user_id, aa.timestamp, cm.batch_uid, cc.title, aa.event_type, aa.data, aa.session_id FROM users u INNER JOIN activity_accumulator aa on u.pk1 = aa.user_pk1 LEFT JOIN course_main cm ON aa.course_pk1 = cm.pk1 LEFT JOIN course_contents cc on aa.content_pk1 = cc.pk1 WHERE u.user_id = @userID and cm.course_id = @courseID AND DateDiff(Hour, aa.timestamp, CURRENT_TIMESTAMP) <= 120 UNION SELECT u.user_id, aa.timestamp, cm.batch_uid, cc.title, aa.event_type, aa.data, aa.session_id FROM users u INNER JOIN activity_accumulator_queue aa on u.pk1 = aa.user_pk1 LEFT JOIN course_main cm ON aa.course_pk1 = cm.pk1 LEFT JOIN course_contents cc on aa.content_pk1 = cc.pk1 WHERE u.user_id = @userID and cm.course_id = @courseID AND DateDiff(Hour, aa.timestamp, CURRENT_TIMESTAMP) <= 120 ORDER BY aa.timestamp desc", myConnection);
  242.                         SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
  243.                         DataTable t = new DataTable();
  244.                         adapter.Fill(t);
  245.  
  246.                         dataGridView1.DataSource = t;
  247.  
  248.                     }
  249.                     catch (Exception ex2)
  250.                     {
  251.                         Console.WriteLine(ex2.ToString());
  252.                     }
  253.  
  254.                     try
  255.                     {
  256.                         myConnection.Close();
  257.                     }
  258.                     catch (Exception ex3)
  259.                     {
  260.                         Console.WriteLine(ex3.ToString());
  261.                     }
  262.                 }
  263.             }
  264.  
  265.         }
  266.  
  267.         private void exportToExcelSpreadsheetxlsToolStripMenuItem_Click(object sender, EventArgs e)
  268.         {
  269.  
  270.             copyAlltoClipboard();
  271.             Microsoft.Office.Interop.Excel.Application xlexcel;
  272.             Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
  273.             Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
  274.             object misValue = System.Reflection.Missing.Value;
  275.             xlexcel = new Microsoft.Office.Interop.Excel.Application();
  276.             xlexcel.Visible = true;
  277.             xlWorkBook = xlexcel.Workbooks.Add(misValue);
  278.             xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  279.             Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1];
  280.             Microsoft.Office.Interop.Excel.Range colorRange;
  281.             colorRange = xlWorkSheet.get_Range("A1", "G1");
  282.             colorRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
  283.             CR.Cells[1, 1] = "user_id";
  284.             CR.Cells[1, 2] = "timestamp";
  285.             CR.Cells[1, 2].EntireColumn.NumberFormat = "M/d/yyyy h:mm:ss AM/PM";
  286.             CR.Cells[1, 3] = "batch_uid";
  287.             CR.Cells[1, 4] = "title";
  288.             CR.Cells[1, 5] = "event_type";
  289.             CR.Cells[1, 6] = "data";
  290.             CR.Cells[1, 7] = "session_id";
  291.             CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[2, 1];
  292.             CR.Select();
  293.             xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
  294.             xlWorkSheet.Columns.AutoFit();
  295.  
  296.         }
  297.  
  298.         private void copyAlltoClipboard()
  299.         {
  300.             dataGridView1.SelectAll();
  301.             DataObject dataObj = dataGridView1.GetClipboardContent();
  302.             if (dataObj != null)
  303.                 Clipboard.SetDataObject(dataObj);
  304.         }
  305.  
  306.         private void printActivityReportToolStripMenuItem_Click(object sender, EventArgs e)
  307.         {
  308.  
  309.  
  310.  
  311.             PrintPreviewDialog objPPdialog = new PrintPreviewDialog();
  312.             objPPdialog.Document = printDocument2;
  313.  
  314.             ToolStrip ts = new ToolStrip();
  315.             ts.Name = "wrongToolStrip";
  316.             foreach (Control ctl in objPPdialog.Controls)
  317.             {
  318.                 if (ctl.Name.Equals("toolStrip1"))
  319.                 {
  320.                     ts = ctl as ToolStrip;
  321.                     break;
  322.                 }
  323.             }
  324.             ToolStripButton printButton = new ToolStripButton();
  325.             foreach (ToolStripItem tsi in ts.Items)
  326.             {
  327.                 if (tsi.Name.Equals("printToolStripButton"))
  328.                 {
  329.                     printButton = tsi as ToolStripButton;
  330.                 }
  331.             }
  332.  
  333.             printButton.Click += new EventHandler(this.SelectPrinterAfterPreview);
  334.  
  335.             ts.Items.Remove(printButton);
  336.             ToolStripButton b = new ToolStripButton();
  337.             b.ImageIndex = printButton.ImageIndex;
  338.             b.Visible = true;
  339.             ts.Items.Insert(0, b);
  340.             b.Click += new EventHandler(this.SelectPrinterAfterPreview);
  341.  
  342.             printDocument2.DefaultPageSettings.Landscape = true;
  343.             //((ToolStripButton)((ToolStrip)objPPdialog.Controls[1]).Items[0]).
  344.             objPPdialog.ShowDialog();
  345.  
  346.         }
  347.  
  348.         private void SelectPrinterAfterPreview(object sender, EventArgs e)
  349.         {
  350.             PagedPrintDocument ppd = new PagedPrintDocument();
  351.             PrintDialog printDialog = new PrintDialog();
  352.             printDialog.Document = printDocument2;
  353.             printDocument2.DefaultPageSettings.Landscape = true;
  354.  
  355.             ppd.PageFrom = printDialog.PrinterSettings.FromPage;
  356.             ppd.PageTo = printDialog.PrinterSettings.ToPage;
  357.  
  358.             printDialog.AllowSomePages = true;
  359.             printDialog.UseEXDialog = true;
  360.             if (DialogResult.OK == printDialog.ShowDialog())
  361.             {
  362.                 printDocument2.DocumentName = "Activity Report";
  363.                 printDocument2.Print();
  364.             }
  365.         }
  366.  
  367.         private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  368.         {
  369.  
  370.  
  371.             try
  372.             {
  373.                 strFormat = new StringFormat();
  374.                 strFormat.Alignment = StringAlignment.Near;
  375.                 strFormat.LineAlignment = StringAlignment.Center;
  376.                 strFormat.Trimming = StringTrimming.EllipsisCharacter;
  377.  
  378.                 arrColumnLefts.Clear();
  379.                 arrColumnWidths.Clear();
  380.                 iCellHeight = 0;
  381.                 iRow = 0;
  382.                 bFirstPage = true;
  383.                 bNewPage = true;
  384.  
  385.                 // Calculating Total Widths
  386.                 iTotalWidth = 0;
  387.                 foreach (DataGridViewColumn dgvGridCol in dataGridView1.Columns)
  388.                 {
  389.                     iTotalWidth += dgvGridCol.Width;
  390.                 }
  391.             }
  392.             catch (Exception ex)
  393.             {
  394.                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  395.             }
  396.         }
  397.  
  398.         private void printDocument1_PrintPage(object sender,
  399.     System.Drawing.Printing.PrintPageEventArgs e)
  400.         {
  401.             try
  402.             {
  403.                 //Set the left margin
  404.                 int iLeftMargin = e.MarginBounds.Left;
  405.                 //Set the top margin
  406.                 int iTopMargin = e.MarginBounds.Top;
  407.                 //Whether more pages have to print or not
  408.                 bool bMorePagesToPrint = false;
  409.                 int iTmpWidth = 0;
  410.  
  411.                 //For the first page to print set the cell width and header height
  412.                 if (bFirstPage)
  413.                 {
  414.                     foreach (DataGridViewColumn GridCol in dataGridView1.Columns)
  415.                     {
  416.                         iTmpWidth = (int)(Math.Floor((double)((double)GridCol.Width /
  417.                             (double)iTotalWidth * (double)iTotalWidth *
  418.                             ((double)e.MarginBounds.Width / (double)iTotalWidth))));
  419.  
  420.                         iHeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText,
  421.                             GridCol.InheritedStyle.Font, iTmpWidth).Height) + 11;
  422.  
  423.                         // Save width and height of headers
  424.                         arrColumnLefts.Add(iLeftMargin);
  425.                         arrColumnWidths.Add(iTmpWidth);
  426.                         iLeftMargin += iTmpWidth;
  427.                     }
  428.                 }
  429.                 //Loop till all the grid rows not get printed
  430.                 while (iRow <= dataGridView1.Rows.Count - 1)
  431.                 {
  432.                     DataGridViewRow GridRow = dataGridView1.Rows[iRow];
  433.                     //Set the cell height
  434.                     iCellHeight = GridRow.Height;
  435.                     int iCount = 0;
  436.                     //Check whether the current page settings allows more rows to print
  437.                     if (iTopMargin + iCellHeight >= e.MarginBounds.Height + e.MarginBounds.Top)
  438.                     {
  439.                         bNewPage = true;
  440.                         bFirstPage = false;
  441.                         bMorePagesToPrint = true;
  442.                         break;
  443.                     }
  444.                     else
  445.                     {
  446.                         if (bNewPage)
  447.                         {
  448.                             //Draw Header
  449.                             e.Graphics.DrawString("Activity Report for " + txtBoxUsername.Text + "",
  450.                                 new Font(dataGridView1.Font, FontStyle.Bold),
  451.                                 Brushes.Black, e.MarginBounds.Left,
  452.                                 e.MarginBounds.Top - e.Graphics.MeasureString("Activity Report for " + txtBoxUsername.Text + "",
  453.                                 new Font(dataGridView1.Font, FontStyle.Bold),
  454.                                 e.MarginBounds.Width).Height - 13);
  455.  
  456.                             String strDate = DateTime.Now.ToLongDateString() + " " +
  457.                                 DateTime.Now.ToShortTimeString();
  458.                             //Draw Date
  459.                             e.Graphics.DrawString(strDate,
  460.                                 new Font(dataGridView1.Font, FontStyle.Bold), Brushes.Black,
  461.                                 e.MarginBounds.Left +
  462.                                 (e.MarginBounds.Width - e.Graphics.MeasureString(strDate,
  463.                                 new Font(dataGridView1.Font, FontStyle.Bold),
  464.                                 e.MarginBounds.Width).Width),
  465.                                 e.MarginBounds.Top - e.Graphics.MeasureString("Activity Report for " + txtBoxUsername.Text + "",
  466.                                 new Font(new Font(dataGridView1.Font, FontStyle.Bold),
  467.                                 FontStyle.Bold), e.MarginBounds.Width).Height - 13);
  468.  
  469.                             //Draw Columns                
  470.                             iTopMargin = e.MarginBounds.Top;
  471.                             foreach (DataGridViewColumn GridCol in dataGridView1.Columns)
  472.                             {
  473.                                 e.Graphics.FillRectangle(new SolidBrush(Color.LightGray),
  474.                                     new Rectangle((int)arrColumnLefts[iCount], iTopMargin,
  475.                                     (int)arrColumnWidths[iCount], iHeaderHeight));
  476.  
  477.                                 e.Graphics.DrawRectangle(Pens.Black,
  478.                                     new Rectangle((int)arrColumnLefts[iCount], iTopMargin,
  479.                                     (int)arrColumnWidths[iCount], iHeaderHeight));
  480.  
  481.                                 e.Graphics.DrawString(GridCol.HeaderText,
  482.                                     GridCol.InheritedStyle.Font,
  483.                                     new SolidBrush(GridCol.InheritedStyle.ForeColor),
  484.                                     new RectangleF((int)arrColumnLefts[iCount], iTopMargin,
  485.                                     (int)arrColumnWidths[iCount], iHeaderHeight), strFormat);
  486.                                 iCount++;
  487.                             }
  488.                             bNewPage = false;
  489.                             iTopMargin += iHeaderHeight;
  490.                         }
  491.                         iCount = 0;
  492.                         //Draw Columns Contents                
  493.                         foreach (DataGridViewCell Cel in GridRow.Cells)
  494.                         {
  495.                             if (Cel.Value != null)
  496.                             {
  497.                                 Font font = new Font("Arial", 7);
  498.                                 e.Graphics.DrawString(Cel.Value.ToString(), font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)arrColumnLefts[iCount], (float)iTopMargin, (int)arrColumnWidths[iCount], (float)iCellHeight), strFormat);
  499.                             }
  500.                             //Drawing Cells Borders
  501.                             e.Graphics.DrawRectangle(Pens.Black,
  502.                                 new Rectangle((int)arrColumnLefts[iCount], iTopMargin,
  503.                                 (int)arrColumnWidths[iCount], iCellHeight));
  504.                             iCount++;
  505.                         }
  506.                     }
  507.                     iRow++;
  508.                     iTopMargin += iCellHeight;
  509.                 }
  510.                 //If more lines exist, print another page.
  511.                 if (bMorePagesToPrint)
  512.                     e.HasMorePages = true;
  513.                 else
  514.                     e.HasMorePages = false;
  515.             }
  516.             catch (Exception exc)
  517.             {
  518.                 MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK,
  519.                    MessageBoxIcon.Error);
  520.             }
  521.         }
  522.  
  523.         private void btnSearchResults_Click(object sender, EventArgs e)
  524.         {
  525.             string filterType = dropDownFilter.SelectedItem.ToString() + " = '{0}'";
  526.             (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format(filterType, txtBoxSearchResults.Text);
  527.            
  528.         }
  529.  
  530.        
  531.  
  532.     }
  533. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement