DeleteRaspisaniye.xaml.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /// Логика взаимодействия для DeleteRaspisaniye.xaml
  20. /// </summary>
  21. public partial class DeleteRaspisaniye : Window
  22. {
  23. public DeleteRaspisaniye()
  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_raspisaniye.Text.Length;i++)
  32. {
  33. if (id_raspisaniye.Text.Length > 0 && id_raspisaniye.Text[i] >= '0' && id_raspisaniye.Text[i] <='9')
  34. {
  35. DataTable dt_raspisaniye = Delete("delete from [dbo].[raspisaniye] where [id] = " + id_raspisaniye.Text);
  36. Raspisaniye a = new Raspisaniye();
  37. a.Show();
  38. Close();
  39. }
  40. else
  41. {
  42. MessageBox.Show("Поле id не заполнено или введено не корректно");
  43. }
  44. }
  45. }
  46. }
  47. public DataTable Delete(string selectSQL)
  48. {
  49. DataTable dataTable = new DataTable("dataBase");
  50. SqlConnection sqlConnection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
  51. sqlConnection.Open();
  52. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  53. sqlCommand.CommandText = selectSQL;
  54. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  55. sqlDataAdapter.Fill(dataTable);
  56. sqlConnection.Close();
  57. return dataTable;
  58. }
  59. private void Button_Click_Back(object sender, RoutedEventArgs e)
  60. {
  61. Raspisaniye ras = new Raspisaniye();
  62. ras.Show();
  63. Close();
  64. }
  65. }
  66. }