SpisokBikes.xaml.cs 4.2 KB

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