SpisRab.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /// Логика взаимодействия для Window1.xaml
  20. /// </summary>
  21. public partial class SpisRab : Window
  22. {
  23. public SpisRab()
  24. {
  25. InitializeComponent();
  26. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  27. connection.Open();
  28. string cmd = "select id as '№ сотрудника', Login as 'Логин',Password as 'Пароль',LName 'Фамилия',Fname 'Имя',Mname 'Отчество',Email 'Почта',Phone 'Телефон',FORMAT(Dr, 'dd/MM/yyyy') as 'День рожджения' from InfoRab";
  29. SqlCommand createcommand = new SqlCommand(cmd, connection);
  30. createcommand.ExecuteNonQuery();
  31. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  32. DataTable dt = new DataTable("InfoRab");
  33. sql.Fill(dt);
  34. prodinfo.ItemsSource = dt.DefaultView;
  35. connection.Close();
  36. }
  37. private void Vixod(object sender, RoutedEventArgs e)
  38. {
  39. MainWindowAdm MWA = new MainWindowAdm();
  40. MWA.Show();
  41. Close();
  42. }
  43. private void Button_Search(object sender, RoutedEventArgs e)
  44. {
  45. if (Search.Text.Length > 0)
  46. {
  47. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  48. connection.Open();
  49. string cmd = "select ID as '№ сотрудника', Login as 'Логин',Password as 'Пароль',LName 'Фамилия',Fname 'Имя',Mname 'Отчество',Email 'Почта',Phone 'Телефон',FORMAT(Dr, 'dd/MM/yyyy') as 'День рожджения' from InfoRab" +
  50. " where ( Login like '%" + Search.Text + "%' or Password like '%" + Search.Text + "%' or LName like '%" + Search.Text + "%' or FName like '%" + Search.Text + "%' or Mname like '%" + Search.Text + "%' or Email like '%" + Search.Text + "%' or Phone like '%" + Search.Text + "%' or Dr like '%" + Search.Text + "%')";
  51. SqlCommand createcommand = new SqlCommand(cmd, connection);
  52. createcommand.ExecuteNonQuery();
  53. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  54. DataTable dt = new DataTable("SpisProk");
  55. sql.Fill(dt);
  56. prodinfo.ItemsSource = dt.DefaultView;
  57. connection.Close();
  58. }
  59. else if (Search.Text.Length == 0)
  60. {
  61. SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;");
  62. connection.Open();
  63. string cmd = "select ID as '№ сотрудника', Login as 'Логин',Password as 'Пароль',LName 'Фамилия',Fname 'Имя',Mname 'Отчество',Email 'Почта',Phone 'Телефон',FORMAT(Dr, 'dd/MM/yyyy') as 'День рожджения' from InfoRab";
  64. SqlCommand createcommand = new SqlCommand(cmd, connection);
  65. createcommand.ExecuteNonQuery();
  66. SqlDataAdapter sql = new SqlDataAdapter(createcommand);
  67. DataTable dt = new DataTable("SpisProk");
  68. sql.Fill(dt);
  69. prodinfo.ItemsSource = dt.DefaultView;
  70. connection.Close();
  71. }
  72. }
  73. private void Delete(object sender, RoutedEventArgs e)
  74. {
  75. DeleteRab DR = new DeleteRab();
  76. DR.Show();
  77. Close();
  78. }
  79. }
  80. }