DeleteTournment.xaml.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. DataTable sel = Select("select * from [dbo].[sorevnovaniya] where id = " + id_sorevi.Text);
  30. if (MessageBox.Show("Вы действительно хотите удалить данные ", "Удаление", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  31. {
  32. if(sel.Rows.Count > 0)
  33. {
  34. for (int i = 0; i < id_sorevi.Text.Length; i++)
  35. {
  36. if (id_sorevi.Text.Length > 0 && id_sorevi.Text[i] >= '0' && id_sorevi.Text[i] <= '9')
  37. {
  38. DataTable dt_tournments = Delete("delete from [dbo].[sorevnovaniya] where [id] = " + id_sorevi.Text);
  39. MessageBox.Show("Соревнование удалено");
  40. Tournments tournments = new Tournments();
  41. tournments.Show();
  42. Close();
  43. }
  44. else
  45. {
  46. MessageBox.Show("Поле код соревнования не заполнено");
  47. }
  48. }
  49. }
  50. else
  51. {
  52. MessageBox.Show("Данного кода не существует");
  53. }
  54. }
  55. }
  56. private void Button_Click_Back(object sender, RoutedEventArgs e)
  57. {
  58. Tournments tournments = new Tournments();
  59. tournments.Show();
  60. Close();
  61. }
  62. public DataTable Delete(string selectSQL)
  63. {
  64. DataTable dataTable = new DataTable("dataBase");
  65. SqlConnection sqlConnection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  66. sqlConnection.Open();
  67. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  68. sqlCommand.CommandText = selectSQL;
  69. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  70. sqlDataAdapter.Fill(dataTable);
  71. sqlConnection.Close();
  72. return dataTable;
  73. }
  74. public DataTable Select(string selectSQL)
  75. {
  76. DataTable dataTable = new DataTable("dataBase");
  77. SqlConnection sqlConnection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  78. sqlConnection.Open();
  79. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  80. sqlCommand.CommandText = selectSQL;
  81. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  82. sqlDataAdapter.Fill(dataTable);
  83. sqlConnection.Close();
  84. return dataTable;
  85. }
  86. }
  87. }