Tournments.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace KursachMukha692gr
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для Tournments.xaml
  20. /// </summary>
  21. public partial class Tournments : Window
  22. {
  23. public Tournments()
  24. {
  25. InitializeComponent();
  26. SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  27. connection.Open();
  28. string cmd = "select id,name_tournment as 'Название турнира', mesto_provedeniya as 'Место проведения', fk_disciplina_id as 'id дисциплины',fk_gruppa_id as 'Номер группы, принимающей участие', fk_infotrener_id as 'id тренера' from sorevnovaniya";
  29. SqlCommand createcommand = new SqlCommand(cmd, connection);
  30. createcommand.ExecuteNonQuery();
  31. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  32. DataTable dt = new DataTable("sorevi");
  33. sql.Fill(dt);
  34. sorevigrid.ItemsSource = dt.DefaultView;
  35. connection.Close();
  36. }
  37. private void Button_Click_add(object sender, RoutedEventArgs e)
  38. {
  39. AddTournment tournment = new AddTournment();
  40. tournment.Show();
  41. Close();
  42. }
  43. private void Button_Click_delete(object sender, RoutedEventArgs e)
  44. {
  45. DeleteTournment tournment = new DeleteTournment();
  46. tournment.Show();
  47. Close();
  48. }
  49. private void Button_Click_Back(object sender, RoutedEventArgs e)
  50. {
  51. KabinetAdmina kabinet = new KabinetAdmina();
  52. kabinet.Show();
  53. Close();
  54. }
  55. private void Button_Click_update(object sender, RoutedEventArgs e)
  56. {
  57. ViborUpdateTournments tournments = new ViborUpdateTournments();
  58. tournments.Show();
  59. Close();
  60. }
  61. private void Button_Click_Search(object sender, RoutedEventArgs e)
  62. {
  63. /*ViborSearchTournment searchTournment = new ViborSearchTournment();
  64. searchTournment.Show();
  65. Close();*/
  66. /*SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  67. connection.Open();
  68. string cmd = "select id,name_tournment as 'Название турнира', mesto_provedeniya as 'Место проведения', fk_disciplina_id as 'id дисциплины',fk_gruppa_id as 'Номер группы, принимающей участие', fk_infotrener_id as 'id тренера' from sorevnovaniya";
  69. SqlCommand createcommand = new SqlCommand(cmd, connection);
  70. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  71. DataTable dt = new DataTable("sorevi");
  72. if(dt.Rows.Count > 0)
  73. {
  74. dt.DefaultView.RowFilter = string.Format("id like '%{0}%'", search.Text);
  75. sorevigrid.ItemsSource = dt.DefaultView;
  76. }
  77. */
  78. if(search.Text.Length > 0)
  79. {
  80. SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  81. connection.Open();
  82. string cmd = "select id,name_tournment as 'Название турнира', mesto_provedeniya as 'Место проведения', fk_disciplina_id as 'id дисциплины',fk_gruppa_id as 'Номер группы, принимающей участие', fk_infotrener_id as 'id тренера' from sorevnovaniya where id like '%" + search.Text + "%' or mesto_provedeniya like '%" + search.Text + "%'" +
  83. " or fk_disciplina_id like '%" + search.Text + "%' or fk_gruppa_id like '%" + search.Text + "%' or fk_infotrener_id like '%" + search.Text + "%'";
  84. SqlCommand createcommand = new SqlCommand(cmd, connection);
  85. createcommand.ExecuteNonQuery();
  86. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  87. DataTable dt = new DataTable("sorevi");
  88. sql.Fill(dt);
  89. sorevigrid.ItemsSource = dt.DefaultView;
  90. connection.Close();
  91. }
  92. else if (search.Text.Length == 0)
  93. {
  94. SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  95. connection.Open();
  96. string cmd = "select id,name_tournment as 'Название турнира', mesto_provedeniya as 'Место проведения', fk_disciplina_id as 'id дисциплины',fk_gruppa_id as 'Номер группы, принимающей участие', fk_infotrener_id as 'id тренера' from sorevnovaniya";
  97. SqlCommand createcommand = new SqlCommand(cmd, connection);
  98. createcommand.ExecuteNonQuery();
  99. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  100. DataTable dt = new DataTable("sorevi");
  101. sql.Fill(dt);
  102. sorevigrid.ItemsSource = dt.DefaultView;
  103. connection.Close();
  104. }
  105. }
  106. private void search_TextChanged(object sender, TextChangedEventArgs e)
  107. {
  108. /*if (search.Text.Length > 0)
  109. {
  110. SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  111. connection.Open();
  112. string cmd = "select id,name_tournment as 'Название турнира', mesto_provedeniya as 'Место проведения', fk_disciplina_id as 'id дисциплины',fk_gruppa_id as 'Номер группы, принимающей участие', fk_infotrener_id as 'id тренера' from sorevnovaniya";
  113. SqlCommand createcommand = new SqlCommand(cmd, connection);
  114. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  115. if(connection.State == ConnectionState.Open)
  116. {
  117. DataTable dt = new DataTable("sorevi");
  118. sql.Fill(dt);
  119. sorevigrid.ItemsSource = dt.DefaultView;
  120. connection.Close();
  121. }
  122. //sorevigrid.ItemsSource = dataSet.Tables[o]
  123. }
  124. */
  125. }
  126. }
  127. }