private void btnOk_Click(object sender, RoutedEventArgs e) { try { if (fromSelectedID == -1) { using (DataClasses1DataContext cnt = new DataClasses1DataContext()) { if (fromComboBox == "Book") { Book book = new Book() { Title = textBox2.Text }; cnt.Book.InsertOnSubmit(book); cnt.SubmitChanges(); } if (fromComboBox == "Sage") { Sage sage = new Sage() { Name = textBox2.Text, Age = DateTime.Parse(textBox3.Text) }; cnt.Sage.InsertOnSubmit(sage); cnt.SubmitChanges(); } if (fromComboBox == "SageBook") { Book book = new Book() { Title = textBox2.Text }; cnt.Book.InsertOnSubmit(book); cnt.SubmitChanges(); } } } else { using (DataClasses1DataContext cnt = new DataClasses1DataContext()) { if (fromComboBox == "Book") { var book = cnt.Book.Where(x => x.Id == fromSelectedID).FirstOrDefault(); book.Title = textBox2.Text; cnt.SubmitChanges(); } } } this.Close(); } catch (Exception) { throw; } }
partial void UpdateSage(Sage instance);
partial void DeleteSage(Sage instance);
partial void InsertSage(Sage instance);