private void ContractList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (ContractList.SelectedValue != null) { ContractAndEstimate contract = (ContractAndEstimate)ContractList.SelectedValue; EstimateForContractWindow estimateForContractWindow = new EstimateForContractWindow(_context, contract.ContractID); estimateForContractWindow.ShowDialog(); } }
//private void EditButton_Click(object sender, RoutedEventArgs e) //{ // if(ContractList.SelectedValue != null) // { // ContractAndEstimate contractAndEstimate = (ContractAndEstimate)ContractList.SelectedValue; // EditContractWindow editContractWindow = new EditContractWindow(_context, contractAndEstimate.ContractID); // var result = editContractWindow.ShowDialog(); // if(result == true) // { // //EditEstimateWindow editEstimateWindow = new EditEstimateWindow(_context, contractAndEstimate.ContractID); // //result = editEstimateWindow.ShowDialog(); // if(result == true) // { // //доделать редактирование // ContractAndServices.Remove(ContractAndServices.Where(c => c.ClientID == contractAndEstimate.ClientID).FirstOrDefault()); // ContractAndServices.Add(_context.Contracts.Where(c => c.ClientID == contractAndEstimate.ClientID).Select(p => new ContractAndEstimate // { // ContractID = p.ID, // ClientID = (int)p.ClientID, // FirstName = p.Client.FirstName, // LastName = p.Client.LastName, // DateConclusionContract = p.DateConclusionContract, // DateOfCompletion = p.DateOfCompletion, // TotalAmount = p.TotalAmount // }).FirstOrDefault()); // } // } // else // { // ContractAndServices.Remove(ContractAndServices.Where(c => c.ClientID == contractAndEstimate.ClientID).FirstOrDefault()); // ContractAndServices.Add(_context.Contracts.Where(c => c.ClientID == contractAndEstimate.ClientID).Select(p => new ContractAndEstimate // { // ContractID = p.ID, // ClientID = (int)p.ClientID, // FirstName = p.Client.FirstName, // LastName = p.Client.LastName, // DateConclusionContract = p.DateConclusionContract, // DateOfCompletion = p.DateOfCompletion, // TotalAmount = p.TotalAmount // }).FirstOrDefault()); // } // } //} private void DeleteButton_Click(object sender, RoutedEventArgs e) { if (ContractList.SelectedValue != null) { ContractAndEstimate contract = (ContractAndEstimate)ContractList.SelectedValue; var result = MessageBox.Show($"Данный договор {contract.ContractID} будет удален, продолжить?", "Удаление договора", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { ContractAndEstimate contractAndEstimate = (ContractAndEstimate)ContractList.SelectedValue; _context.Contracts.Remove(_context.Contracts.Where(c => c.ID == contractAndEstimate.ContractID).FirstOrDefault()); _context.SaveChanges(); ContractAndServices.Remove(ContractAndServices.Where(c => c.ContractID == contractAndEstimate.ContractID).FirstOrDefault()); } } }