Beispiel #1
0
 private void listViewCars_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewCars.SelectedItems.Count == 1)
     {
         Cars car = listViewCars.SelectedItems[0].Tag as Cars;
         textBoxModel.Text     = car.Model;
         comboBoxColour.Text   = car.Colour;
         textBoxPrice.Text     = car.Price;
         textBoxGosNumber.Text = car.GosNumber.ToString();
         textBoxYear.Text      = car.Year.ToString();
     }
     else
     {
         textBoxModel.Text     = "";
         comboBoxColour.Text   = "";
         textBoxPrice.Text     = "";
         textBoxGosNumber.Text = "";
         textBoxYear.Text      = "";
     }
 }
Beispiel #2
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewCars.SelectedItems.Count == 1)
         {
             Cars car = listViewCars.SelectedItems[0].Tag as Cars;
             Program.ADb.Cars.Remove(car);
             Program.ADb.SaveChanges();
             ShowCars();
         }
         textBoxModel.Text     = "";
         comboBoxColour.Text   = "";
         textBoxPrice.Text     = "";
         textBoxGosNumber.Text = "";
         textBoxYear.Text      = "";
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #3
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         Cars car = new Cars();
         car.Model     = textBoxModel.Text;
         car.Colour    = comboBoxColour.Text;
         car.Price     = textBoxPrice.Text;
         car.GosNumber = Convert.ToInt32(textBoxGosNumber.Text);
         car.Year      = Convert.ToInt32(textBoxYear.Text);
         if (car.Model == "" || car.Colour == "" || car.Price == "")
         {
             throw new Exception("Не заполнены поля модели, цвета или цены");
         }
         Program.ADb.Cars.Add(car);
         Program.ADb.SaveChanges();
         ShowCars();
     }
     catch (Exception ex)
     {
         MessageBox.Show("" + ex.Message, "Ошибка!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }