DeleteSpisokTrenerov.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 KursachMukha692gr
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для DeleteSpisokTrenerov.xaml
  20. /// </summary>
  21. public partial class DeleteSpisokTrenerov : Window
  22. {
  23. public DeleteSpisokTrenerov()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Button_Click_Delete(object sender, RoutedEventArgs e)
  28. {
  29. if (MessageBox.Show("Вы действительно хотите удалить данные ", "Удаление", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  30. {
  31. for(int i = 0; i < id_trener.Text.Length; i++)
  32. {
  33. if (id_trener.Text.Length > 0 && id_trener.Text[i] >='0' && id_trener.Text[i] <='9')
  34. {
  35. DataTable dt_uch = Delete("delete from [dbo].[infotrener] where [id] = " + id_trener.Text);
  36. SpisokTrenerov uch = new SpisokTrenerov();
  37. uch.Show();
  38. Close();
  39. }
  40. else
  41. {
  42. MessageBox.Show("Поле id не заполнено или введено не корректно");
  43. }
  44. }
  45. }
  46. }
  47. private void Button_Click_Back(object sender, RoutedEventArgs e)
  48. {
  49. SpisokTrenerov trenerov = new SpisokTrenerov();
  50. trenerov.Show();
  51. Close();
  52. }
  53. public DataTable Delete(string selectSQL)
  54. {
  55. DataTable dataTable = new DataTable("dataBase");
  56. SqlConnection sqlConnection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  57. sqlConnection.Open();
  58. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  59. sqlCommand.CommandText = selectSQL;
  60. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  61. sqlDataAdapter.Fill(dataTable);
  62. sqlConnection.Close();
  63. return dataTable;
  64. }
  65. }
  66. }