InfoBikes.xaml.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /// Логика взаимодействия для InfoBikes.xaml
  20. /// </summary>
  21. public partial class InfoBikes : Window
  22. {
  23. public InfoBikes()
  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 'Занятость',InfoAdm.Lname as 'Фамилия администратора' from Bikes,Zanyatost, InfoAdm where Bikes.IDZan = Zanyatost.ID and Bikes.IdAdm = InfoAdm.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. private void Button_Search(object sender, RoutedEventArgs e)
  38. {
  39. if (Search.Text.Length > 0)
  40. {
  41. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  42. connection.Open();
  43. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость', InfoAdm.Lname as 'Фамилия администратора' from Bikes,Zanyatost where Bikes.IDZan = Zanyatost.ID and Bikes.IdAdm = InfoAdm.ID" +
  44. " and ( Bikes.ID like '%" + Search.Text + "%' or Bikes.Company like '%" + Search.Text + "%' or Bikes.[Type] like '%" + Search.Text + "%' or Bikes.Title like '%" + Search.Text + "%' or Zanyatost.Zan like '%" + Search.Text + "%' or InfoAdm.Lname like '%" + Search.Text + "%')";
  45. SqlCommand createcommand = new SqlCommand(cmd, connection);
  46. createcommand.ExecuteNonQuery();
  47. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  48. DataTable dt = new DataTable("SpisProk");
  49. sql.Fill(dt);
  50. prodinfo.ItemsSource = dt.DefaultView;
  51. connection.Close();
  52. }
  53. else if (Search.Text.Length == 0)
  54. {
  55. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  56. connection.Open();
  57. string cmd = "Select Bikes.ID as '№ велосипеда', Bikes.Company as 'Компания', Bikes.Title as 'Название',Bikes.[Type] as 'Тип',Zanyatost.Zan as 'Занятость',InfoAdm.Lname as 'Фамилия администратора' from Bikes,Zanyatost, InfoAdm where Bikes.IDZan = Zanyatost.ID and Bikes.IdAdm = InfoAdm.ID";
  58. SqlCommand createcommand = new SqlCommand(cmd, connection);
  59. createcommand.ExecuteNonQuery();
  60. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  61. DataTable dt = new DataTable("SpisProk");
  62. sql.Fill(dt);
  63. prodinfo.ItemsSource = dt.DefaultView;
  64. connection.Close();
  65. }
  66. }
  67. private void Vixod(object sender, RoutedEventArgs e)
  68. {
  69. MainWindowProd MWA = new MainWindowProd();
  70. MWA.Show();
  71. Close();
  72. }
  73. private void Insert(object sender, RoutedEventArgs e)
  74. {
  75. Changing_the_type CTT = new Changing_the_type();
  76. CTT.Show();
  77. Close();
  78. }
  79. }
  80. }