Guest User

Untitled

a guest
Dec 14th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. public Form1()
  4. {
  5. InitializeComponent();
  6. }
  7.  
  8. private void Form1_Load(object sender, EventArgs e)
  9. {
  10. SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  11. SqlCommand command = new SqlCommand("Select * FROM address_book ", connection);
  12.  
  13. try
  14. {
  15. connection.Open();
  16. {
  17. SqlDataReader drd = command.ExecuteReader();
  18.  
  19. while (drd.Read())
  20. {
  21. this.checkedListBox1.Items.Add(drd.GetString(0).ToString());
  22. }
  23. }
  24. }
  25. catch (Exception ex)
  26. {
  27. MessageBox.Show(ex.Message.ToString());
  28. }
  29.  
  30. connection.Close();
  31. }
  32.  
  33. private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
  34. {
  35. SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  36. con.Open();
  37. SqlCommand cmd = new SqlCommand("select * from address_book where name='" + checkedListBox1.Text + "'", con);
  38. SqlDataReader dr;
  39. dr = cmd.ExecuteReader();
  40. while (dr.Read())
  41. {
  42. textBox1.Text += Convert.ToString(dr["id"] + ",");
  43. }
  44. dr.Close();
  45. }
  46.  
  47. private void textBox1_Enter(object sender, EventArgs e)
  48. {
  49. ToolTip tt = new ToolTip();
  50. tt.SetToolTip(textBox1, "sorry");
  51. }
  52. }
  53.  
  54. private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  55.  
  56. private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  57. {
  58. StringBuilder stringBuilder = new StringBuilder();
  59.  
  60. foreach (var item in checkedListBox1.CheckedItems)
  61. {
  62. SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True");
  63. con.Open();
  64. SqlCommand cmd = new SqlCommand(string.Format("select * from address_book where name='{0}'", item), con);
  65. SqlDataReader dr = cmd.ExecuteReader();
  66. while (dr.Read())
  67. {
  68. stringBuilder.Append(Convert.ToString(dr["id"] + ","));
  69. }
  70. dr.Close();
  71. }
  72.  
  73. textBox1.Text = stringBuilder.ToString().TrimEnd(',');
  74. }
  75.  
  76. textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
Add Comment
Please, Sign In to add comment