public AddOrChangeForm() { InitializeComponent(); Title = "Добавить сервис"; newServis = new Database.Service(); newServis.MainImagePath = "no-image.png"; mainGrid.DataContext = newServis as Database.Service; btSave.Content = "add"; }
public ServiceW(Database.Service service) { ID = service.ID; Name = service.Title; Cost1 = GetCost1(service); Cost2 = GetCose2(service); Time = GetTime(service); CostString = GetCostString(service); ImagePath = GetImagePath(service); btn_delete = "Visible"; btn_edit = "Visible"; btn_write = "Visible"; }
protected virtual void Button_Click(object sender, RoutedEventArgs e) { try { Database.masterEntities entities = new Database.masterEntities(); newServis = mainGrid.DataContext as Database.Service; entities.Service.AddOrUpdate(newServis); entities.SaveChanges(); MessageBox.Show("OK"); this.DialogResult = true; this.Close(); } catch (Exception ex) { MessageBox.Show("Ошибка " + ex.Message, "error", MessageBoxButton.OK, MessageBoxImage.Error); } }