private void Button1_Click(object sender, EventArgs e) { CoordinatorEdit coordinatorEdit = new CoordinatorEdit("", ID); coordinatorEdit.ShowDialog(); UpdateTable(); }
private void Button3_Click(object sender, EventArgs e) { CoordinatorEdit coordinatorEdit = new CoordinatorEdit(textBox1.Text, ID); SqlConnection connection = UserCoordinator.GetDBConnection(); connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); try { using (SqlCommand sql = new SqlCommand()) { SqlCommand sqlCom = new SqlCommand(@"SELECT WorkerID, ZoneID, TimeStart, TimeEnd, EventID FROM Appointment WHERE ID = @ID", connection); sqlCom.Transaction = transaction; sqlCom.Parameters.Add("@ID", SqlDbType.Int); sqlCom.Parameters["@ID"].Value = Convert.ToInt32(textBox1.Text); SqlDataReader reader = sqlCom.ExecuteReader(); if (reader.Read() && reader.GetInt32(4).ToString() == ID) { int rankID = reader.GetInt32(1); if (rankID != 4 && rankID != 5) { coordinatorEdit.textBox1.Text = reader.GetInt32(0).ToString(); coordinatorEdit.comboBox1.SelectedIndex = rankID - 1; coordinatorEdit.textBox4.Text = reader.GetDateTime(2).ToString("dd/MM/yyyy HH:mm"); coordinatorEdit.textBox5.Text = reader.GetDateTime(3).ToString("dd/MM/yyyy HH:mm"); reader.Close(); coordinatorEdit.ShowDialog(); UpdateTable(); transaction.Commit(); } else { MessageBox.Show("Вы не имеете права изменять организатора и координатора мероприятия.", "Ошибка"); transaction.Rollback(); } } else { reader.Close(); MessageBox.Show("Такого номера нет в таблице.", "Ошибка"); transaction.Rollback(); } } } catch (Exception ex) { MessageBox.Show("Что-то пошло не так! Обратитесь к разработчику.", "Ошибка"); transaction.Rollback(); } connection.Close(); }