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") { SageBook sageBook = new SageBook() { idBook = Convert.ToInt32(textBox2.Text), idSage = Convert.ToInt32(textBox3.Text) }; cnt.SageBook.InsertOnSubmit(sageBook); 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(); } if (fromComboBox == "Sage") { var sage = cnt.Sage.Where(x => x.Id == fromSelectedID).FirstOrDefault(); sage.Name = textBox2.Text; sage.Age = DateTime.Parse(textBox3.Text); cnt.SubmitChanges(); } if (fromComboBox == "SageBook") { var sageBook = cnt.SageBook.Where(x => x.Id == fromSelectedID).FirstOrDefault(); sageBook.idBook = Convert.ToInt32(textBox2.Text); sageBook.idSage = Convert.ToInt32(textBox3.Text); cnt.SubmitChanges(); } } } this.Close(); } catch (Exception) { throw; } }
private void detach_SageBook(SageBook entity) { this.SendPropertyChanging(); entity.Book = null; }
private void attach_SageBook(SageBook entity) { this.SendPropertyChanging(); entity.Book = this; }
partial void DeleteSageBook(SageBook instance);
partial void UpdateSageBook(SageBook instance);
partial void InsertSageBook(SageBook instance);