using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace SSS { /// /// Логика взаимодействия для AddCar.xaml /// public partial class AddCar : Page { Entities DB = new Entities(); bool flag = false; public AddCar() { InitializeComponent(); Mark.ItemsSource = DB.CarBrand.ToList(); Mark.DisplayMemberPath = "CarBrand1"; Worker.ItemsSource = DB.Teem.ToList(); Worker.DisplayMemberPath = "Surname_Teem"; TypeService.ItemsSource = DB.Service.ToList(); TypeService.DisplayMemberPath = "name_Service"; Client.ItemsSource = DB.Client.ToList(); Client.DisplayMemberPath = "Surname"; } public AddCar(int id) { InitializeComponent(); flag = true; Car OldCar = DB.Car.Find(id); Mark.ItemsSource = DB.CarBrand.ToList(); Mark.DisplayMemberPath = "CarBrand1"; Worker.ItemsSource = DB.Teem.ToList(); Worker.DisplayMemberPath = "Surname_Teem"; TypeService.ItemsSource = DB.Service.ToList(); TypeService.DisplayMemberPath = "name_Service"; Client.ItemsSource = DB.Client.ToList(); Client.DisplayMemberPath = "Surname"; CarBrand cr = DB.CarBrand.Where(x => x.id_CarBrand == OldCar.id_CarBrand).FirstOrDefault(); Client client = DB.Client.Where(x => x.id_Client == OldCar.id_Client).FirstOrDefault(); Mark.SelectedItem = cr; Worker.SelectedItem = DB.Teem.Where(x => x.id_Teem == OldCar.id_Teem).FirstOrDefault(); TypeService.SelectedItem = DB.Service.Where(x => x.id_Service == OldCar.id_Service).FirstOrDefault(); Client.SelectedItem = client; Mileage.Text = Convert.ToString(OldCar.Car_mileage); } private void AddRed(object sender, RoutedEventArgs e) { Car NewCar = new Car() { id_Teem = ((Teem)Worker.SelectedItem).id_Teem, id_Service = ((Service)TypeService.SelectedItem).id_Service, id_Client = ((Client)Client.SelectedItem).id_Client, id_CarBrand = ((CarBrand)Mark.SelectedItem).id_CarBrand, Car_mileage = Convert.ToInt32(Mileage.Text) }; if(flag) { DB.SaveChanges(); } else { DB.Car.Add(NewCar); DB.SaveChanges(); } MessageBox.Show("Вы добавил/отредактировали машину"); } private void GoBack(object sender, RoutedEventArgs e) { ClassF.Mfrm.Navigate(new CarsData()); } } }