private void buttonAdd_Click_1(object sender, EventArgs e) { CarsSet carsSet = new CarsSet(); carsSet.Mark = textBoxMarka.Text; carsSet.Model = textBoxModel.Text; carsSet.Kompl = textBoxKompl.Text; carsSet.SerNumber = textBoxSerNomer.Text; carsSet.Price = textBoxPrice.Text; Program.dbmotor.CarsSet.Add(carsSet); Program.dbmotor.SaveChanges(); ShowCars(); }
private void buttonEdit_Click_1(object sender, EventArgs e) { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsset = listViewCars.SelectedItems[0].Tag as CarsSet; carsset.Mark = textBoxMarka.Text; carsset.Model = textBoxModel.Text; carsset.Kompl = textBoxKompl.Text; carsset.SerNumber = textBoxSerNomer.Text; carsset.Price = textBoxPrice.Text; Program.dbmotor.SaveChanges(); ShowCars(); } }
private void listViewCars_SelectedIndexChanged_1(object sender, EventArgs e) { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet; textBoxMarka.Text = carsSet.Mark; textBoxModel.Text = carsSet.Model; textBoxKompl.Text = carsSet.Kompl; textBoxSerNomer.Text = carsSet.SerNumber; textBoxPrice.Text = carsSet.Price; } else { textBoxMarka.Text = ""; textBoxModel.Text = ""; textBoxKompl.Text = ""; textBoxSerNomer.Text = ""; textBoxPrice.Text = ""; } }
private void buttonDel_Click_1(object sender, EventArgs e) { try { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet; Program.dbmotor.CarsSet.Remove(carsSet); Program.dbmotor.SaveChanges(); ShowCars(); } textBoxMarka.Text = ""; textBoxModel.Text = ""; textBoxKompl.Text = ""; textBoxSerNomer.Text = ""; textBoxPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }