diff --git a/XLAB/MainWindow.xaml b/XLAB/MainWindow.xaml index fc38f60..691f0bb 100644 --- a/XLAB/MainWindow.xaml +++ b/XLAB/MainWindow.xaml @@ -356,10 +356,14 @@ + diff --git a/XLAB/MainWindow.xaml.cs b/XLAB/MainWindow.xaml.cs index 34caf09..dd9c154 100644 --- a/XLAB/MainWindow.xaml.cs +++ b/XLAB/MainWindow.xaml.cs @@ -35,6 +35,19 @@ namespace XLAB } } + private void DocumentLineRow_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + var row = sender as DataGridRow; + if (row == null) + { + return; + } + + row.IsSelected = true; + row.Focus(); + _viewModel.TryEditVerificationFromDoubleClick(row.Item as PsvDocumentLine); + } + private void DocumentGroupRow_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { var row = sender as DataGridRow; diff --git a/XLAB/MainWindowViewModel.cs b/XLAB/MainWindowViewModel.cs index 3fcc0e5..a3f1ed1 100644 --- a/XLAB/MainWindowViewModel.cs +++ b/XLAB/MainWindowViewModel.cs @@ -54,6 +54,7 @@ namespace XLAB AddDocumentCommand = new RelayCommand(delegate { AddDocument(); }, delegate { return !IsBusy && !ShowClosedDocuments; }); CloneLineVerificationCommand = new RelayCommand(delegate { CloneSelectedLineVerificationAsync(); }, delegate { return CanCloneSelectedLineVerification(); }); DeleteDocumentCommand = new RelayCommand(delegate { DeleteDocumentAsync(); }, delegate { return !IsBusy && SelectedDocument != null; }); + DeleteSelectedLinesCommand = new RelayCommand(delegate { DeleteSelectedLinesAsync(); }, delegate { return CanDeleteSelectedLines(); }); DeleteSelectedGroupsCommand = new RelayCommand(delegate { DeleteSelectedGroupsAsync(); }, delegate { return CanDeleteSelectedGroups(); }); MarkLinePassedCommand = new RelayCommand(delegate { EditLineVerificationAsync(true); }, delegate { return CanEditSelectedLineVerification(); }); MarkLineRejectedCommand = new RelayCommand(delegate { EditLineVerificationAsync(false); }, delegate { return CanEditSelectedLineVerification(); }); @@ -140,6 +141,8 @@ namespace XLAB public ICommand DeleteDocumentCommand { get; private set; } + public ICommand DeleteSelectedLinesCommand { get; private set; } + public ICommand DeleteSelectedGroupsCommand { get; private set; } public string GroupDetailFilterText @@ -389,6 +392,12 @@ namespace XLAB && GetDeleteTargetGroups().Count > 0; } + private bool CanDeleteSelectedLines() + { + return CanModifySelectedDocument() + && GetDeleteTargetLines().Count > 0; + } + private bool CanPrintSelectedDocument() { return !IsBusy @@ -509,6 +518,14 @@ namespace XLAB return true; } + private bool CanEditVerificationFromDoubleClick(PsvDocumentLine line) + { + return CanModifySelectedDocument() + && line != null + && line.IsPassed.HasValue + && HasVerificationData(line); + } + private List GetCheckedDocumentLines() { return DocumentLinesView.Cast() @@ -550,6 +567,19 @@ namespace XLAB : new List { SelectedDocumentLine }; } + private List GetDeleteTargetLines() + { + var checkedLines = GetCheckedDocumentLines(); + if (checkedLines.Count > 0) + { + return checkedLines; + } + + return SelectedDocumentLine == null + ? new List() + : new List { SelectedDocumentLine }; + } + private List GetCheckedCloneTargetLines(PsvDocumentLine sourceLine) { if (sourceLine == null) @@ -1142,6 +1172,22 @@ namespace XLAB EditLineVerificationCoreAsync(targetLines, isPassed); } + public void TryEditVerificationFromDoubleClick(PsvDocumentLine line) + { + if (line == null) + { + return; + } + + SelectedDocumentLine = line; + if (!CanEditVerificationFromDoubleClick(line)) + { + return; + } + + EditLineVerificationCoreAsync(new[] { line }, line.IsPassed.Value); + } + private async void EditLineVerificationCoreAsync(IReadOnlyList targetLines, bool isPassed) { IReadOnlyList documentForms; @@ -1455,6 +1501,114 @@ namespace XLAB }); } + private void DeleteSelectedLinesAsync() + { + if (SelectedDocument == null) + { + return; + } + + var targetLines = GetDeleteTargetLines(); + if (targetLines.Count == 0) + { + return; + } + + if (!_dialogService.Confirm(string.Format( + "Удалить из ПСВ \"{0}\" строк приборов: {1}?", + SelectedDocument.DocumentNumber, + targetLines.Count))) + { + return; + } + + var selectedDocument = SelectedDocument; + var selectedDocumentKey = selectedDocument.DocumentKey; + var selectedDocumentNumber = selectedDocument.DocumentNumber; + + RunBusyOperation(async delegate + { + var pendingLines = GetPendingLines(selectedDocument); + var pendingLinesToRemove = pendingLines + .Where(delegate(PsvDocumentLine line) { return targetLines.Any(delegate(PsvDocumentLine targetLine) { return ReferenceEquals(line, targetLine); }); }) + .ToList(); + + var persistedCardIds = targetLines + .Where(delegate(PsvDocumentLine line) { return !line.IsPendingInsert; }) + .Select(delegate(PsvDocumentLine line) { return line.CardId; }) + .Distinct() + .ToList(); + + foreach (var pendingLine in pendingLinesToRemove) + { + pendingLines.Remove(pendingLine); + } + + var deletedPendingCount = pendingLinesToRemove.Count; + var deletedResult = new DocumentGroupDeleteResult(); + + if (persistedCardIds.Count > 0) + { + deletedResult = await Task.Run(delegate + { + return _service.DeleteDocumentGroups(selectedDocumentNumber, persistedCardIds); + }); + } + + var remainingPendingCount = pendingLines.Count; + var remainingPersistedCount = DocumentLines.Count(delegate(PsvDocumentLine line) { return !line.IsPendingInsert; }) - persistedCardIds.Count; + + if (selectedDocument.IsDraft) + { + UpdateDocumentSummaryFromLines(selectedDocument, pendingLines); + ApplyDocumentLines(pendingLines, SelectedDocumentGroup); + DocumentsView.Refresh(); + DocumentStatusText = BuildDocumentStatusText(Documents.Count); + } + else if (remainingPersistedCount == 0 && remainingPendingCount > 0) + { + if (!_draftDocuments.Any(delegate(PsvDocumentSummary draft) { return draft.DocumentKey == selectedDocumentKey; })) + { + _draftDocuments.Add(selectedDocument); + } + + selectedDocument.IsDraft = true; + UpdateDocumentSummaryFromLines(selectedDocument, pendingLines); + await RefreshDocumentsCoreAsync(selectedDocumentKey, selectedDocumentNumber); + } + else + { + await RefreshDocumentsCoreAsync(selectedDocumentKey, selectedDocumentNumber); + } + + var messages = new List(); + if (deletedPendingCount > 0) + { + messages.Add(string.Format("Удалено черновых строк: {0}.", deletedPendingCount)); + } + + if (deletedResult.DeletedEkzMkFctvlCount > 0) + { + messages.Add(string.Format("Удалено строк EKZMKFCTVL: {0}.", deletedResult.DeletedEkzMkFctvlCount)); + } + + if (deletedResult.DeletedEkzMkCount > 0) + { + messages.Add(string.Format("Удалено строк EKZMK: {0}.", deletedResult.DeletedEkzMkCount)); + } + + if (deletedResult.DeletedDmsCount > 0) + { + messages.Add(string.Format("Удалено связанных DMS: {0}.", deletedResult.DeletedDmsCount)); + } + + if (messages.Count > 0) + { + _dialogService.ShowInfo(string.Join(" ", messages.ToArray())); + } + }); + } + private bool DocumentExistsInCollections(string documentNumber, string excludeDocumentKey) { return Documents.Any(delegate(PsvDocumentSummary document) @@ -2055,6 +2209,7 @@ namespace XLAB ((RelayCommand)AddDocumentCommand).RaiseCanExecuteChanged(); ((RelayCommand)CloneLineVerificationCommand).RaiseCanExecuteChanged(); ((RelayCommand)DeleteDocumentCommand).RaiseCanExecuteChanged(); + ((RelayCommand)DeleteSelectedLinesCommand).RaiseCanExecuteChanged(); ((RelayCommand)DeleteSelectedGroupsCommand).RaiseCanExecuteChanged(); ((RelayCommand)MarkLinePassedCommand).RaiseCanExecuteChanged(); ((RelayCommand)MarkLineRejectedCommand).RaiseCanExecuteChanged(); diff --git a/_codex_build/XLAB.exe b/_codex_build/XLAB.exe index c269676..b0ad73c 100644 Binary files a/_codex_build/XLAB.exe and b/_codex_build/XLAB.exe differ