private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet; if (textBoxModel.Text == "" || textBoxPrice.Text == "" || textBoxNumberState.Text == "" || textBoxYear.Text == "") { throw new Exception("Обязательные данные не заполнены"); } else { carsSet.Price = Convert.ToInt32(textBoxPrice.Text); carsSet.Model = textBoxModel.Text; carsSet.NumberState = textBoxNumberState.Text; carsSet.Year = textBoxYear.Text; } if (comboBoxColor.SelectedItem != null) { carsSet.Color = Convert.ToString(comboBoxColor.SelectedItem.ToString().Split('.')[0]); } else { throw new Exception("Обязательные данные не заполнены"); } Program.cGG.SaveChanges(); ShowCars(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewCars_SelectedIndexChanged(object sender, EventArgs e) { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet; textBoxPrice.Text = carsSet.Price.ToString(); comboBoxColor.Text = carsSet.Color.ToString(); textBoxModel.Text = carsSet.Model; textBoxNumberState.Text = carsSet.NumberState; textBoxYear.Text = carsSet.Year; } else { comboBoxColor.SelectedItem = null; textBoxModel.Text = ""; textBoxNumberState.Text = ""; textBoxPrice.Text = ""; textBoxYear.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewCars.SelectedItems.Count == 1) { CarsSet carsSet = listViewCars.SelectedItems[0].Tag as CarsSet; Program.cGG.CarsSet.Remove(carsSet); Program.cGG.SaveChanges(); ShowCars(); } comboBoxColor.SelectedItem = null; textBoxModel.Text = ""; textBoxNumberState.Text = ""; textBoxPrice.Text = ""; textBoxYear.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);; } }