SpisokProk.xaml.cs 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /// Логика взаимодействия для SpisokProk.xaml
  20. /// </summary>
  21. public partial class SpisokProk : Window
  22. {
  23. public SpisokProk()
  24. {
  25. InitializeComponent();
  26. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  27. connection.Open();
  28. string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab " +
  29. "where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID";
  30. SqlCommand createcommand = new SqlCommand(cmd, connection);
  31. createcommand.ExecuteNonQuery();
  32. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  33. DataTable dt = new DataTable("SpisProk");
  34. sql.Fill(dt);
  35. prodinfo.ItemsSource = dt.DefaultView;
  36. connection.Close();
  37. }
  38. private void Vixod(object sender, RoutedEventArgs e)
  39. {
  40. MainWindowProd MWP = new MainWindowProd();
  41. MWP.Show();
  42. Close();
  43. }
  44. private void Button_Search(object sender, RoutedEventArgs e)
  45. {
  46. if (Search.Text.Length > 0)
  47. {
  48. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  49. connection.Open();
  50. string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID" +
  51. " and ( SpisProk.ID like '%" + Search.Text + "%' or Bikes.Title like '%" + Search.Text + "%' or Bikes.[Type] like '%" + Search.Text + "%' or Tarif.NameOfTarif like '%" + Search.Text + "%' or cast(Tarif.Price as int) like '%" + Search.Text + "%' or FORMAT(SpisProk.Date, 'dd/MM/yyyy') like '%" + Search.Text + "%' or FORMAT(Time, N'hh\\:mm') like '%" + Search.Text + "%' or[Count] like '%" + Search.Text + "%' or SpisProk.Lname like '%" + Search.Text + "%' or InfoRab.Lname like '%" + Search.Text + "%' )";
  52. SqlCommand createcommand = new SqlCommand(cmd, connection);
  53. createcommand.ExecuteNonQuery();
  54. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  55. DataTable dt = new DataTable("SpisProk");
  56. sql.Fill(dt);
  57. prodinfo.ItemsSource = dt.DefaultView;
  58. connection.Close();
  59. }
  60. else if (Search.Text.Length == 0)
  61. {
  62. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  63. connection.Open();
  64. string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab " +
  65. "where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID";
  66. SqlCommand createcommand = new SqlCommand(cmd, connection);
  67. createcommand.ExecuteNonQuery();
  68. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  69. DataTable dt = new DataTable("SpisProk");
  70. sql.Fill(dt);
  71. prodinfo.ItemsSource = dt.DefaultView;
  72. connection.Close();
  73. }
  74. }
  75. }
  76. }