using System; using System.Collections.Generic; using System.Linq; using System.Net; 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.Navigation; using System.Windows.Shapes; namespace SneakersSkakunov { enum StateOfPage { Create, Update }; /// /// Логика взаимодействия для AddPage.xaml /// public partial class Add : Page { string path; StateOfPage stateOfPage; Sniker DB = new Sniker(); Sneakers snk = new Sneakers(); void addList() { Brands.ItemsSource = DB.Brand.ToList(); Brands.DisplayMemberPath = "Label"; Brands.SelectedValuePath = "id_Brand"; } public Add() { InitializeComponent(); addList(); stateOfPage = StateOfPage.Create; } public Add(int index) { InitializeComponent(); BtnAdd.Content = "Внести изменения"; addList(); stateOfPage = StateOfPage.Update; //stateOfPage = StateOfPage.Update; snk = DB.Sneakers.FirstOrDefault(x => x.id_Sneakers == index); Brand brd = DB.Brand.FirstOrDefault(x => x.id_Brand == snk.id_Brand); Brands.SelectedItem = brd; Clrs.Text = snk.Colors; Prices.Text = snk.Price.ToString(); Sizes.Text = snk.Size; } private void BtnAdd_Click(object sender, RoutedEventArgs e) { //try //{ snk.id_Brand = ((Brand)Brands.SelectedItem).id_Brand; snk.Colors = Clrs.Text; snk.Price = Convert.ToDecimal(Prices.Text); snk.Size = Sizes.Text; if (stateOfPage == StateOfPage.Create) { DB.Sneakers.Add(snk); DB.SaveChanges(); } else { DB.SaveChanges(); } MessageBox.Show("Вы успешно добавили (обновили) список брэндов"); //} //catch //{ // MessageBox.Show("Что-то пошло не так"); // System.Windows.Application.Current.Shutdown(); //} } private void Revert(object sender, RoutedEventArgs e) { MainFrame.mframe.Navigate(new Sneaker()); } } }