This commit is contained in:
Курнат Андрей
2026-03-18 20:45:53 +03:00
parent dedd1c5c25
commit ff133e0215
4 changed files with 172 additions and 0 deletions

View File

@@ -356,10 +356,14 @@
<Separator/> <Separator/>
<MenuItem Header="Отменить проверку" <MenuItem Header="Отменить проверку"
Command="{Binding ResetLineVerificationCommand}" /> Command="{Binding ResetLineVerificationCommand}" />
<MenuItem Header="Удалить"
Command="{Binding DeleteSelectedLinesCommand}" />
</ContextMenu> </ContextMenu>
</DataGrid.ContextMenu> </DataGrid.ContextMenu>
<DataGrid.RowStyle> <DataGrid.RowStyle>
<Style TargetType="DataGridRow"> <Style TargetType="DataGridRow">
<EventSetter Event="MouseDoubleClick"
Handler="DocumentLineRow_MouseDoubleClick" />
<EventSetter Event="PreviewMouseRightButtonDown" <EventSetter Event="PreviewMouseRightButtonDown"
Handler="DocumentLineRow_PreviewMouseRightButtonDown" /> Handler="DocumentLineRow_PreviewMouseRightButtonDown" />
</Style> </Style>

View File

@@ -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) private void DocumentGroupRow_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{ {
var row = sender as DataGridRow; var row = sender as DataGridRow;

View File

@@ -54,6 +54,7 @@ namespace XLAB
AddDocumentCommand = new RelayCommand(delegate { AddDocument(); }, delegate { return !IsBusy && !ShowClosedDocuments; }); AddDocumentCommand = new RelayCommand(delegate { AddDocument(); }, delegate { return !IsBusy && !ShowClosedDocuments; });
CloneLineVerificationCommand = new RelayCommand(delegate { CloneSelectedLineVerificationAsync(); }, delegate { return CanCloneSelectedLineVerification(); }); CloneLineVerificationCommand = new RelayCommand(delegate { CloneSelectedLineVerificationAsync(); }, delegate { return CanCloneSelectedLineVerification(); });
DeleteDocumentCommand = new RelayCommand(delegate { DeleteDocumentAsync(); }, delegate { return !IsBusy && SelectedDocument != null; }); 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(); }); DeleteSelectedGroupsCommand = new RelayCommand(delegate { DeleteSelectedGroupsAsync(); }, delegate { return CanDeleteSelectedGroups(); });
MarkLinePassedCommand = new RelayCommand(delegate { EditLineVerificationAsync(true); }, delegate { return CanEditSelectedLineVerification(); }); MarkLinePassedCommand = new RelayCommand(delegate { EditLineVerificationAsync(true); }, delegate { return CanEditSelectedLineVerification(); });
MarkLineRejectedCommand = new RelayCommand(delegate { EditLineVerificationAsync(false); }, 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 DeleteDocumentCommand { get; private set; }
public ICommand DeleteSelectedLinesCommand { get; private set; }
public ICommand DeleteSelectedGroupsCommand { get; private set; } public ICommand DeleteSelectedGroupsCommand { get; private set; }
public string GroupDetailFilterText public string GroupDetailFilterText
@@ -389,6 +392,12 @@ namespace XLAB
&& GetDeleteTargetGroups().Count > 0; && GetDeleteTargetGroups().Count > 0;
} }
private bool CanDeleteSelectedLines()
{
return CanModifySelectedDocument()
&& GetDeleteTargetLines().Count > 0;
}
private bool CanPrintSelectedDocument() private bool CanPrintSelectedDocument()
{ {
return !IsBusy return !IsBusy
@@ -509,6 +518,14 @@ namespace XLAB
return true; return true;
} }
private bool CanEditVerificationFromDoubleClick(PsvDocumentLine line)
{
return CanModifySelectedDocument()
&& line != null
&& line.IsPassed.HasValue
&& HasVerificationData(line);
}
private List<PsvDocumentLine> GetCheckedDocumentLines() private List<PsvDocumentLine> GetCheckedDocumentLines()
{ {
return DocumentLinesView.Cast<object>() return DocumentLinesView.Cast<object>()
@@ -550,6 +567,19 @@ namespace XLAB
: new List<PsvDocumentLine> { SelectedDocumentLine }; : new List<PsvDocumentLine> { SelectedDocumentLine };
} }
private List<PsvDocumentLine> GetDeleteTargetLines()
{
var checkedLines = GetCheckedDocumentLines();
if (checkedLines.Count > 0)
{
return checkedLines;
}
return SelectedDocumentLine == null
? new List<PsvDocumentLine>()
: new List<PsvDocumentLine> { SelectedDocumentLine };
}
private List<PsvDocumentLine> GetCheckedCloneTargetLines(PsvDocumentLine sourceLine) private List<PsvDocumentLine> GetCheckedCloneTargetLines(PsvDocumentLine sourceLine)
{ {
if (sourceLine == null) if (sourceLine == null)
@@ -1142,6 +1172,22 @@ namespace XLAB
EditLineVerificationCoreAsync(targetLines, isPassed); 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<PsvDocumentLine> targetLines, bool isPassed) private async void EditLineVerificationCoreAsync(IReadOnlyList<PsvDocumentLine> targetLines, bool isPassed)
{ {
IReadOnlyList<DocumentFormReference> documentForms; IReadOnlyList<DocumentFormReference> 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<string>();
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) private bool DocumentExistsInCollections(string documentNumber, string excludeDocumentKey)
{ {
return Documents.Any(delegate(PsvDocumentSummary document) return Documents.Any(delegate(PsvDocumentSummary document)
@@ -2055,6 +2209,7 @@ namespace XLAB
((RelayCommand)AddDocumentCommand).RaiseCanExecuteChanged(); ((RelayCommand)AddDocumentCommand).RaiseCanExecuteChanged();
((RelayCommand)CloneLineVerificationCommand).RaiseCanExecuteChanged(); ((RelayCommand)CloneLineVerificationCommand).RaiseCanExecuteChanged();
((RelayCommand)DeleteDocumentCommand).RaiseCanExecuteChanged(); ((RelayCommand)DeleteDocumentCommand).RaiseCanExecuteChanged();
((RelayCommand)DeleteSelectedLinesCommand).RaiseCanExecuteChanged();
((RelayCommand)DeleteSelectedGroupsCommand).RaiseCanExecuteChanged(); ((RelayCommand)DeleteSelectedGroupsCommand).RaiseCanExecuteChanged();
((RelayCommand)MarkLinePassedCommand).RaiseCanExecuteChanged(); ((RelayCommand)MarkLinePassedCommand).RaiseCanExecuteChanged();
((RelayCommand)MarkLineRejectedCommand).RaiseCanExecuteChanged(); ((RelayCommand)MarkLineRejectedCommand).RaiseCanExecuteChanged();

Binary file not shown.