Guest User

Untitled

a guest
Nov 18th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. private void SqlSelect(object sqlcommand)
  2.         {
  3.             int i = 0;
  4.             foreach (var database in SelectedItem)
  5.             {
  6.                 using (NpgsqlConnection connect = new NpgsqlConnection(connectionString + "Database=" + database))
  7.                     try
  8.                     {
  9.                         connect.Open();
  10.                         NpgsqlCommand command = new NpgsqlCommand(sqlcommand.ToString(), connect);
  11.                         NpgsqlDataReader reader = command.ExecuteReader();
  12.                         if (reader.HasRows)
  13.                         {
  14.                             if (Tselect == sampling)
  15.                             {
  16.                                 listBox1.Invoke((MethodInvoker)(() => listBox1.Items.Add(database)));
  17.                             }
  18.                             else
  19.                             {
  20.                                 while (i != reader.VisibleFieldCount)
  21.                                 {
  22.                                     Invoke((MethodInvoker)delegate { dataGridView1.Columns.Add(reader.GetName(i), reader.GetName(i)); }, new object[] { });
  23.                                     i++;
  24.                                 }
  25.                                 i = 0;
  26.                                 foreach (DbDataRecord datarecord in reader)
  27.                                 {
  28.                                     Invoke((MethodInvoker)delegate { dataGridView1.Rows.Add(); }, new object[] { });
  29.                                     for (int count = 0; count < reader.VisibleFieldCount; count++)
  30.                                     {
  31.                                         Invoke((MethodInvoker)delegate { dataGridView1.Rows[i].Cells[count].Value = datarecord[count].ToString(); }, new object[] { });
  32.                                     }
  33.                                     i++;
  34.                                 }
  35.                             }
  36.                         }
  37.                         else
  38.                         {
  39.                             listBox2.Invoke((MethodInvoker)(() => listBox2.Items.Add(database)));
  40.                         }
  41.                     }
  42.                     catch (NpgsqlException e)
  43.                     {
  44.                         ++id;
  45.                         find_err_lbl.Text = string.Format("Ошибок: {0}", id);
  46.                         find_err_lbl.ToolTipText += database + Environment.NewLine;
  47.                     }
  48.                     finally
  49.                     {
  50.                         connect.Close();
  51.                     }
  52.                 Invoke((MethodInvoker)delegate { toolStripProgressBar1.Value++; }, new object[] { });
  53.                 Invoke(new SetToolStripDelegate(SetToolStrip), string.Format("Прогресс: {0}%", 100 * ++i / SelectedItem.Count));
  54.             }
  55.             execute.Invoke((MethodInvoker)(() => execute.Text = "Выполнить"));
  56.             execute.Invoke((MethodInvoker)(() => execute.Click -= new EventHandler(secondAction)));
  57.             execute.Invoke((MethodInvoker)(() => execute.Click += new EventHandler(firstAction)));
  58.             Invoke(new SetToolStripDelegate(SetToolStrip), "Готово");
  59.             _thread.ForEach(delegate (Thread thread)
  60.             {
  61.                 thread.Abort();
  62.             });
  63.         }
Advertisement
Add Comment
Please, Sign In to add comment