TestInfoBikes.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 veloprokat2
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для TestInfoBikes.xaml
  20. /// </summary>
  21. public partial class TestInfoBikes : Window
  22. {
  23. public TestInfoBikes()
  24. {
  25. InitializeComponent();
  26. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  27. connection.Open();
  28. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость' from Bikes,Zanyatost where Bikes.IDZan = Zanyatost.ID";
  29. SqlCommand createcommand = new SqlCommand(cmd, connection);
  30. createcommand.ExecuteNonQuery();
  31. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  32. DataTable dt = new DataTable("Bikes");
  33. sql.Fill(dt);
  34. prodinfo.ItemsSource = dt.DefaultView;
  35. connection.Close();
  36. }
  37. public bool SearchTest (string search)
  38. {
  39. Search.Text = search;
  40. if (Search.Text.Length > 0)
  41. {
  42. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  43. connection.Open();
  44. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость' from Bikes,Zanyatost where Bikes.IDZan = Zanyatost.ID" +
  45. " and ( Bikes.ID like '%" + Search.Text + "%' or Bikes.Company like '%" + Search.Text + "%' or Bikes.[Type] like '%" + Search.Text + "%' or Bikes.Title like '%" + Search.Text + "%')";
  46. SqlCommand createcommand = new SqlCommand(cmd, connection);
  47. createcommand.ExecuteNonQuery();
  48. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  49. DataTable dt = new DataTable("SpisProk");
  50. sql.Fill(dt);
  51. prodinfo.ItemsSource = dt.DefaultView;
  52. connection.Close();
  53. if (dt.Rows.Count > 0)
  54. {
  55. MessageBox.Show("Тест вывода пройден");
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63. else if (Search.Text.Length == 0)
  64. {
  65. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  66. connection.Open();
  67. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость' from Bikes,Zanyatost where Bikes.IDZan = Zanyatost.ID";
  68. SqlCommand createcommand = new SqlCommand(cmd, connection);
  69. createcommand.ExecuteNonQuery();
  70. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  71. DataTable dt = new DataTable("SpisProk");
  72. sql.Fill(dt);
  73. prodinfo.ItemsSource = dt.DefaultView;
  74. connection.Close();
  75. return false;
  76. }
  77. return false;
  78. }
  79. public bool TestVivod ()
  80. {
  81. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  82. connection.Open();
  83. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость' from Bikes,Zanyatost where Bikes.IDZan = Zanyatost.ID" +
  84. " and ( Bikes.ID like '%" + Search.Text + "%' or Bikes.Company like '%" + Search.Text + "%' or Bikes.[Type] like '%" + Search.Text + "%' or Bikes.Title like '%" + Search.Text + "%')";
  85. SqlCommand createcommand = new SqlCommand(cmd, connection);
  86. createcommand.ExecuteNonQuery();
  87. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  88. DataTable dt = new DataTable("SpisProk");
  89. sql.Fill(dt);
  90. prodinfo.ItemsSource = dt.DefaultView;
  91. connection.Close();
  92. if (dt.Rows.Count > 0)
  93. {
  94. return true;
  95. }
  96. else
  97. {
  98. return false;
  99. }
  100. }
  101. private void Button_Search(object sender, RoutedEventArgs e)
  102. {
  103. }
  104. private void Vixod(object sender, RoutedEventArgs e)
  105. {
  106. }
  107. private void Insert(object sender, RoutedEventArgs e)
  108. {
  109. }
  110. }
  111. }