using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace KursachMukha692gr { /// /// Логика взаимодействия для UpdateIdTrenerTournment.xaml /// public partial class UpdateIdTrenerTournment : Window { public DataTable Update(string selectSQL) { DataTable dataTable = new DataTable("dataBase"); SqlConnection sqlConnection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;"); sqlConnection.Open(); SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = selectSQL; SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); sqlDataAdapter.Fill(dataTable); sqlConnection.Close(); return dataTable; } public UpdateIdTrenerTournment() { InitializeComponent(); } private void Button_Click_Back(object sender, RoutedEventArgs e) { ViborUpdateTournments tournments = new ViborUpdateTournments(); tournments.Show(); Close(); } private void Button_Click_Up(object sender, RoutedEventArgs e) { if (id_turik.Text.Length != 0 && Name.Text.Length != 0) { bool turik = false, imya = false; for (int i = 0; i < id_turik.Text.Length; i++) { if (turik) { turik = false; } if (id_turik.Text[i] >= '1' && id_turik.Text[i] <= '9') { turik = true; } if (turik == false) { MessageBox.Show("Поле id соревнования должно содержать только цифры"); } } for (int i = 0; i < Name.Text.Length; i++) { if (imya) { imya = false; } if (Name.Text[i] >= '0' && Name.Text[i] <= '9') { imya = true; } if (imya == false) { MessageBox.Show("Поле тренер должно содержать id тренера"); } } if (turik && imya) { DataTable upname = Update("update [dbo].[sorevnovaniya] set fk_infotrener_id = '" + Name.Text + "' where id = " + id_turik.Text); MessageBox.Show("Поле id тренера для id " + id_turik.Text + " успешно изменено"); ViborUpdateTournments viborUpdate = new ViborUpdateTournments(); viborUpdate.Show(); Close(); } else { MessageBox.Show("Неправильный формат"); } } else { MessageBox.Show("Все поля должны быть введены"); } } } }