Exemple #1
0
        private void editButton_Click(object sender, RoutedEventArgs e)
        {
            using (UserContext db = new UserContext())
            {
                List <Car> cars = new List <Car>();
                cars = db.Cars.ToList();

                try
                {
                    Add_Car car = new Add_Car();
                    car.Show();
                    car.nameTextbox.Text  = cars[carsDatagrid.SelectedIndex].Name;
                    car.modelTextbox.Text = cars[carsDatagrid.SelectedIndex].Model;
                    car.dateOfReleasePicker.SelectedDate = Convert.ToDateTime(cars[carsDatagrid.SelectedIndex].ReleaseDate);
                    car.engineVolumeTextbox.Text         = cars[carsDatagrid.SelectedIndex].EngineVolume.ToString();
                    car.categoryCombobox.Text            = cars[carsDatagrid.SelectedIndex].Category;
                    car.colorTextbox.Text   = cars[carsDatagrid.SelectedIndex].Color;
                    car.mileageTextbox.Text = cars[carsDatagrid.SelectedIndex].Mileage.ToString();
                    car.priceTextbox.Text   = cars[carsDatagrid.SelectedIndex].Price.ToString();

                    Car caaaar = db.Cars.Where(c => c.Name == car.nameTextbox.Text && c.Model == car.modelTextbox.Text).FirstOrDefault();
                    db.Cars.Remove(caaaar);
                    db.SaveChanges();
                    carsDatagrid.Items.Refresh();
                }

                catch
                {
                    MessageBox.Show("Выберите машину");
                }
            }
        }
Exemple #2
0
        private void addCarButton_Click(object sender, RoutedEventArgs e)
        {
            Add_Car car = new Add_Car();

            car.Owner = this;
            car.Show();
        }