SpisokUchenikov.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /// Логика взаимодействия для SpisokUchenikov.xaml
  20. /// </summary>
  21. public partial class SpisokUchenikov : Window
  22. {
  23. public SpisokUchenikov()
  24. {
  25. InitializeComponent();
  26. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  27. connection.Open();
  28. string cmd = "select infouchenik.id as 'Код',familiya as 'Фамилия', imya as 'Имя', otchestvo as 'Отчество' , dataUchenik as 'Дата рождения',disciplina.disciplina as 'Дисциплина', gruppa.gruppa as 'Номер группы',pol.pol_name as 'Пол', telephonenumUchenik as 'Номер телефона' from infouchenik,disciplina,gruppa,pol " +
  29. "where disciplina.id = infouchenik.fk_disciplina_id and gruppa.id = infouchenik.fk_gruppa_id and pol.id = infouchenik.fk_pol_id";
  30. SqlCommand createcommand = new SqlCommand(cmd, connection);
  31. createcommand.ExecuteNonQuery();
  32. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  33. DataTable dt = new DataTable("ucheniki");
  34. sql.Fill(dt);
  35. uchenikigrid.ItemsSource = dt.DefaultView;
  36. connection.Close();
  37. }
  38. private void Button_Click_add(object sender, RoutedEventArgs e)
  39. {
  40. AddUchenik uchenik = new AddUchenik();
  41. uchenik.Show();
  42. Close();
  43. }
  44. private void Button_Click_delete(object sender, RoutedEventArgs e)
  45. {
  46. DeleteSpisokUchenikov spisokUchenikov = new DeleteSpisokUchenikov();
  47. spisokUchenikov.Show();
  48. Close();
  49. }
  50. private void Button_Click_Back(object sender, RoutedEventArgs e)
  51. {
  52. KabinetAdmina kabinet = new KabinetAdmina();
  53. kabinet.Show();
  54. Close();
  55. }
  56. private void Button_Click_update(object sender, RoutedEventArgs e)
  57. {
  58. ViborUchenikUpdate uchenikUpdate = new ViborUchenikUpdate();
  59. uchenikUpdate.Show();
  60. Close();
  61. }
  62. private void Button_Click_Search(object sender, RoutedEventArgs e)
  63. {
  64. if (search.Text.Length > 0)
  65. {
  66. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  67. connection.Open();
  68. string cmd = "select infouchenik.id as 'Код',familiya as 'Фамилия', imya as 'Имя', otchestvo as 'Отчество' , dataUchenik as 'Дата рождения',disciplina.disciplina as 'Дисциплина', gruppa.gruppa as 'Номер группы',pol.pol_name as 'Пол', telephonenumUchenik as 'Номер телефона' from infouchenik,disciplina,gruppa,pol " +
  69. "where disciplina.id = infouchenik.fk_disciplina_id and gruppa.id = infouchenik.fk_gruppa_id and pol.id = infouchenik.fk_pol_id and (infouchenik.id like '%" + search.Text + "%' or familiya like '%" + search.Text + "%' or otchestvo like '%" + search.Text + "%' or dataUchenik like '%" + search.Text + "%' or disciplina.disciplina like '%" + search.Text + "%' or gruppa.gruppa like '%" + search.Text + "%' or pol.pol_name like '%" + search.Text + "%' or telephonenumUchenik like '%" + search.Text + "%')";
  70. SqlCommand createcommand = new SqlCommand(cmd, connection);
  71. createcommand.ExecuteNonQuery();
  72. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  73. DataTable dt = new DataTable("sorevi");
  74. sql.Fill(dt);
  75. uchenikigrid.ItemsSource = dt.DefaultView;
  76. connection.Close();
  77. }
  78. else if (search.Text.Length == 0)
  79. {
  80. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  81. connection.Open();
  82. string cmd = "select infouchenik.id as 'Код',familiya as 'Фамилия', imya as 'Имя', otchestvo as 'Отчество' , dataUchenik as 'Дата рождения',disciplina.disciplina as 'Дисциплина', gruppa.gruppa as 'Номер группы',pol.pol_name as 'Пол', telephonenumUchenik as 'Номер телефона' from infouchenik,disciplina,gruppa,pol " +
  83. "where disciplina.id = infouchenik.fk_disciplina_id and gruppa.id = infouchenik.fk_gruppa_id and pol.id = infouchenik.fk_pol_id";
  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. uchenikigrid.ItemsSource = dt.DefaultView;
  90. connection.Close();
  91. }
  92. }
  93. private void search_TextChanged(object sender, TextChangedEventArgs e)
  94. {
  95. }
  96. }
  97. }