private void Button_Click(object sender, RoutedEventArgs e) { ClientEditor clientEditor = new ClientEditor(new Client(), dataBaseAC); if (clientEditor.ShowDialog() == true) { Client client = clientEditor.Client; dataBaseAC.Clients.Add(client); //client.Id++; //MessageBox.Show(client.Id.ToString()); dataBaseAC.SaveChanges(); } }
private void createClientBtn_Click(object sender, RoutedEventArgs e) { ClientEditor clientEditor = new ClientEditor(new Client(), dataBaseAC); if (clientEditor.ShowDialog() == true) { Client client = clientEditor.Client; dataBaseAC.Clients.Add(client); dataBaseAC.SaveChanges(); selectedClient = client; clientSurnameTxtBox.Content = selectedClient.Surname; clientNameTxtBox.Content = selectedClient.Name; clientMiddleNameTxtBox.Content = selectedClient.Middle_name; clientPassNumberTxtBox.Content = selectedClient.Pass_number; clientPhoneNumberTxtBox.Content = selectedClient.Phone_number; productsStackPanel.IsEnabled = true; } }
private void Button_Click_2(object sender, RoutedEventArgs e) { // если ни одного объекта не выделено, выходим if (ClientListDG.SelectedItem == null) { return; } // получаем выделенный объект Client client = ClientListDG.SelectedItem as Client; ClientEditor clientEditor = new ClientEditor(new Client { Id = client.Id, Name = client.Name, Surname = client.Surname, Middle_name = client.Middle_name, Pass_number = client.Pass_number, Phone_number = client.Phone_number, Phone_number2 = client.Phone_number2, Address = client.Address }, dataBaseAC); clientEditor.isEditMode = true; if (clientEditor.ShowDialog() == true) { // получаем измененный объект client = dataBaseAC.Clients.Find(clientEditor.Client.Id); if (client != null) { client.Name = clientEditor.Client.Name; client.Surname = clientEditor.Client.Surname; client.Middle_name = clientEditor.Client.Middle_name; client.Pass_number = clientEditor.Client.Pass_number; client.Phone_number = clientEditor.Client.Phone_number; client.Phone_number2 = clientEditor.Client.Phone_number2; client.Address = clientEditor.Client.Address; dataBaseAC.Entry(client).State = EntityState.Modified; dataBaseAC.SaveChanges(); } } }