laba4
.pdf31
return;
}
int id;
if (!int.TryParse(textBoxKod.Text, out id))
{
MessageBox.Show("Некоректное значение кода абитуриента!", "Внимание",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
}
int place;
if (!int.TryParse(textBoxPlace.Text, out place))
{
MessageBox.Show("Некоректное значение места в списке!", "Внимание",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
}
int ege;
if (!int.TryParse(textBoxEGE.Text, out ege))
{
MessageBox.Show("Некоректное значение баллов!", "Внимание",
MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
}
string sqlUpdate = ("UPDATE Конкурсный_список SET {0} [ID_абитуриента]=@ID_абитуриента");
SqlConnection connection = new SqlConnection(Properties.Settings.Default.VUZConnectionString); connection.Open();
SqlCommand command = connection.CreateCommand(); string sqlValues = "";
if (!String.IsNullOrEmpty(textBoxFIO.Text))
32
sqlValues += "ФИО=@FIO,";
if (!String.IsNullOrEmpty(textBoxPlace.Text)) sqlValues += "Место_в_списке=@Place,"; if (!String.IsNullOrEmpty(textBoxEGE.Text))
sqlValues += "Результаты_ЕГЭ=@ege,"; if (!String.IsNullOrEmpty(textBoxKod.Text)) sqlValues += "ID_абитуриента=@id,";
command.CommandText = String.Format(sqlUpdate, sqlValues); if (!String.IsNullOrEmpty(textBoxFIO.Text))
command.Parameters.AddWithValue("@FIO", textBoxFIO.Text); if (!String.IsNullOrEmpty(textBoxPlace.Text))
command.Parameters.AddWithValue("@Place", place); if (!String.IsNullOrEmpty(textBoxEGE.Text))
command.Parameters.AddWithValue("@ege", ege); if (!String.IsNullOrEmpty(textBoxKod.Text))
command.Parameters.AddWithValue("@id", textBoxKod.Text); try
{
command.ExecuteNonQuery();
}
catch (Exception err)
{
MessageBox.Show("Ошибка выполнения запроса:\n" + err.Message,
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
connection.Close();
}
void Delete()
{
if (String.IsNullOrEmpty(textBoxKod.Text))
33
{
MessageBox.Show("Обязательно укажите код абитуриента данные которого необходимо удалить", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
int id;
if (!int.TryParse(textBoxKod.Text, out id))
{
MessageBox.Show("Некоректное значение кода абитуриента!", "Внимание",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string sqlDelete = @"DELETE FROM Конкурсный_список WHERE ID_абитуриента=@ID_абитуриента";
SqlConnection connection = new
SqlConnection(Properties.Settings.Default.VUZConnectionString);
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = sqlDelete;
command.Parameters.AddWithValue("@ID_абитуриента", id);
try
{
command.ExecuteNonQuery();
}
catch (Exception err)
{
MessageBox.Show(err.Message, "Ошибка удаления");
}
connection.Close();
}
private void radioButtonDelete_CheckedChanged(object sender, EventArgs e)
34
{
}
}
}