DeleteTournment.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /// Логика взаимодействия для DeleteTournment.xaml
  20. /// </summary>
  21. public partial class DeleteTournment : Window
  22. {
  23. public DeleteTournment()
  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_sorevi.Text.Length;i++)
  32. {
  33. if (id_sorevi.Text.Length > 0 && id_sorevi.Text[i] >='0' && id_sorevi.Text[i] <='9')
  34. {
  35. DataTable dt_tournments = Delete("delete from [dbo].[sorevnovaniya] where [id] = " + id_sorevi.Text);
  36. Tournments tournments = new Tournments();
  37. tournments.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. Tournments tournments = new Tournments();
  50. tournments.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. }