public VrpForm(Vrp vrp) { InitializeComponent(); Text = "Изменить"; comboBox1.SelectedIndex = vrp.ClassId - 1; vrpAboutTextBox.Text = vrp.About; vrpNameTextBox.Text = vrp.Name; }
private void button1_Click(object sender, EventArgs e) { Vrp = new Vrp() { About = vrpAboutTextBox.Text, ClassId = 1, Name = vrpNameTextBox.Text }; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
public void DeleteVrp(Vrp vrp, string table) { string removeObject = string.Format("DELETE FROM {0} WHERE Id = @id", table); using (SqlCommand sqlCommand = new SqlCommand(removeObject, _sqlConnection)) { sqlCommand.Parameters.AddWithValue("@id", vrp.Id); if (sqlCommand.ExecuteNonQuery() > 0) { MessageBox.Show("Удалено"); } else { MessageBox.Show("Ошибка при удалении"); } } }
public void ChangeVrp(Vrp oldVrp, Vrp newVrp, string table) { string updateObject = string.Format("UPDATE {0} SET Name = @name, About = @about, Class_Id = @classId WHERE Id = @id", table); using (SqlCommand sqlCommand = new SqlCommand(updateObject, _sqlConnection)) { sqlCommand.Parameters.AddWithValue("@name", newVrp.Name); sqlCommand.Parameters.AddWithValue("@about", newVrp.About); sqlCommand.Parameters.AddWithValue("@classId", newVrp.ClassId); sqlCommand.Parameters.AddWithValue("@id", oldVrp.Id); if (sqlCommand.ExecuteNonQuery() > 0) { MessageBox.Show("Изменено"); } else { MessageBox.Show("Ошибка при изменении"); } } }
public void AddVrp(Vrp vrp, string table) { string insertObject = string.Format("INSERT INTO {0} (Name, About, Class_Id) VALUES (@name, @about, @classId)", table); using (SqlCommand sqlCommand = new SqlCommand(insertObject, _sqlConnection)) { sqlCommand.Parameters.AddWithValue("@name", vrp.Name); sqlCommand.Parameters.AddWithValue("@about", vrp.About); sqlCommand.Parameters.AddWithValue("@classId", vrp.ClassId); if (sqlCommand.ExecuteNonQuery() > 0) { // MessageBox.Show("Добвленно"); } else { MessageBox.Show("Ошибка при добавлении"); } } }