IdVremyaUpdateRaspisaniye.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /// Логика взаимодействия для IdVremyaUpdateRaspisaniye.xaml
  20. /// </summary>
  21. public partial class IdVremyaUpdateRaspisaniye : Window
  22. {
  23. public DataTable Select1(string selectSQL)
  24. {
  25. DataTable dataTable = new DataTable("dataBase");
  26. SqlConnection sqlConnection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  27. sqlConnection.Open();
  28. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  29. sqlCommand.CommandText = selectSQL;
  30. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  31. sqlDataAdapter.Fill(dataTable);
  32. sqlConnection.Close();
  33. return dataTable;
  34. }
  35. public DataTable Select(string selectSQL)
  36. {
  37. DataTable dataTable = new DataTable("dataBase");
  38. SqlConnection sqlConnection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  39. sqlConnection.Open();
  40. SqlCommand sqlCommand = sqlConnection.CreateCommand();
  41. sqlCommand.CommandText = selectSQL;
  42. SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
  43. sqlDataAdapter.Fill(dataTable);
  44. sqlConnection.Close();
  45. return dataTable;
  46. }
  47. public DataTable Update(string selectSQL)
  48. {
  49. DataTable dataTable = new DataTable("dataBase");
  50. SqlConnection sqlConnection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
  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. public IdVremyaUpdateRaspisaniye()
  60. {
  61. InitializeComponent();
  62. }
  63. private void Button_Click_Up(object sender, RoutedEventArgs e)
  64. {
  65. if (id_turik.Text.Length != 0 && Name.Text.Length != 0)
  66. {
  67. bool turik = false, imya = false;
  68. DataTable sel1 = Select1("select * from [dbo].[RASPISANIYE] where id = " + id_turik.Text);
  69. for (int i = 0; i < id_turik.Text.Length; i++)
  70. {
  71. if (turik)
  72. {
  73. turik = false;
  74. }
  75. if (id_turik.Text[i] >= '1' && id_turik.Text[i] <= '9')
  76. {
  77. if (sel1.Rows.Count > 0)
  78. {
  79. turik = true;
  80. }
  81. else
  82. {
  83. turik = false;
  84. }
  85. }
  86. if (turik == false)
  87. {
  88. MessageBox.Show("Поле код занятия должно содержать только цифры или вы ввели код, которого нет");
  89. }
  90. }
  91. DataTable sel = Select("select * from [dbo].[vremya_zanyatiya] where id = " + Name.Text);
  92. for (int i = 0; i < Name.Text.Length; i++)
  93. {
  94. if (imya)
  95. {
  96. imya = false;
  97. }
  98. if (Name.Text[i] >= '1' && Name.Text[i] <= '7' && Name.Text.Length == 1)
  99. {
  100. if (sel.Rows.Count > 0)
  101. {
  102. imya = true;
  103. }
  104. else
  105. {
  106. imya = false;
  107. }
  108. }
  109. if (imya == false)
  110. {
  111. MessageBox.Show("Поле время занятия должно содержать код времени занятия (1-(06:00-08:00) , 2-(08:30-10:30), 3-(11:00-13:00), 4-(13:30-15:30), 5-(16:00-18:00), 6-(18:30-20:30), 7-(21:00-23:00))");
  112. }
  113. }
  114. if (turik && imya)
  115. {
  116. DataTable upname = Update("update [dbo].[RASPISANIYE] set fk_vremya_zanyatiya_id = '" + Name.Text + "' where id = " + id_turik.Text);
  117. MessageBox.Show("Поле время занятия для занятия " + id_turik.Text + " успешно изменено");
  118. ViborUpdateRaspisaniye updateRaspisaniye = new ViborUpdateRaspisaniye();
  119. updateRaspisaniye.Show();
  120. Close();
  121. }
  122. else
  123. {
  124. MessageBox.Show("Неправильный формат");
  125. }
  126. }
  127. else
  128. {
  129. MessageBox.Show("Все поля должны быть введены");
  130. }
  131. }
  132. private void Button_Click_Back(object sender, RoutedEventArgs e)
  133. {
  134. ViborUpdateRaspisaniye updateRaspisaniye = new ViborUpdateRaspisaniye();
  135. updateRaspisaniye.Show();
  136. Close();
  137. }
  138. }
  139. }