} //ShowSupliersWindow private void AddContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { Suppliers supplier = SuppliersDataGrid.SelectedItem as Suppliers; if (supplier == null) { return; } AddContactWindow scw = new AddContactWindow(supplier); if (scw.ShowDialog() == true) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { Contacts newContacts = new Contacts(); newContacts.contact = scw.newContact.contact; newContacts.ContactTypeID = scw.newContact.ContactTypeID; newContacts.description = scw.newContact.description; newContacts.employeeID = scw.newContact.employeeID; newContacts.supplierID = scw.newContact.supplierID; context.Contacts.Add(newContacts); context.SaveChanges(); MessageBox.Show("Контакт добавлен"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
} //SerchByContactVelueTextBox_TextChanged private void ChengeContactTextBlock_MouseDown(object sender, MouseButtonEventArgs e) { if (ContactsDataGrid.SelectedItem is SimpleContact contact) { AddContactWindow acw = new AddContactWindow(contact); if (acw.ShowDialog() == true) { Contacts newcont = acw.newContact; if (newcont.contact != contact.contact || newcont.description != contact.description) { try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { var ppp = context.Contacts.FirstOrDefault(s => s.ContactID == contact.ContactID); ppp.contact = newcont.contact; ppp.description = newcont.description; context.SaveChanges(); MessageBox.Show("Изменения сохранены"); contact.contact = newcont.contact;; contact.description = newcont.description; ContactsDataGrid.Items.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if } //if } //if }