Exemple #1
0
 private void ButtonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewCar.SelectedItems.Count == 1)
         {
             CarSet car = listViewCar.SelectedItems[0].Tag as CarSet;
             Program.catalog.CarSet.Remove(car);
             Program.catalog.SaveChanges();
             ShowCar();
         }
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #2
0
 private void ListViewCar_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewCar.SelectedItems.Count == 1)
     {
         CarSet car = listViewCar.SelectedItems[0].Tag as CarSet;
         textBoxBrand.Text      = car.CarBrand;
         textBoxCountry.Text    = car.Country;
         comboBoxAutoMaker.Text = car.IdAutomaker.ToString() + "." +
                                  car.Automaker.NameAutomaker + " - " + car.Automaker.Country;
         textBoxYear.Text = car.Year;
     }
     else
     {
         textBoxBrand.Text              = "";
         textBoxCountry.Text            = "";
         comboBoxAutoMaker.SelectedItem = null;
         textBoxYear.Text = "";
     }
 }
Exemple #3
0
 private void ButtonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         CarSet car = new CarSet();
         if (textBoxBrand.Text == "" || textBoxCountry.Text == "" || comboBoxAutoMaker.SelectedItem == null)
         {
             throw new Exception("Обязательные данные не заполнены");
         }
         else
         {
             car.CarBrand    = textBoxBrand.Text;
             car.Country     = textBoxCountry.Text;
             car.IdAutomaker = Convert.ToInt32(comboBoxAutoMaker.SelectedItem.ToString().Split('.')[0]);
         }
         car.Year = textBoxYear.Text;
         Program.catalog.CarSet.Add(car);
         Program.catalog.SaveChanges();
         ShowCar();
     }
     catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); }
 }