ModuleClientFunctions.cs
8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
using Sungero.Domain.Shared;
using Sungero.SmartProcessing.Structures.Module;
namespace Sungero.SmartProcessing.Client
{
public class ModuleFunctions
{
#region Задача на верификацию
/// <summary>
/// Определить ведущий документ в комплекте.
/// </summary>
/// <param name="documents">Комплект документов.</param>
/// <returns>Ведущий документ.</returns>
[Public]
public virtual IOfficialDocument GetLeadingDocument(List<IOfficialDocument> documents)
{
var documentPriority = new Dictionary<IOfficialDocument, int>();
var documentTypePriorities = Functions.Module.GetPackageDocumentTypePriorities();
int priority;
foreach (var document in documents)
{
documentTypePriorities.TryGetValue(document.GetType().GetFinalType(), out priority);
documentPriority.Add(document, priority);
}
var leadingDocument = documentPriority
.OrderByDescending(p => p.Value)
.FirstOrDefault().Key;
return leadingDocument;
}
/// <summary>
/// Вызвать диалог удаления документов.
/// </summary>
/// <param name="assignment">Задание на верификацию.</param>
/// <param name="documentList">Документы для удаления.</param>
/// <returns>Список ИД удаленных документов.</returns>
public static List<int> DeleteDocumentsDialogInWeb(IVerificationAssignment assignment, List<IOfficialDocument> documentList)
{
var step = 1;
var successfullyDeletedDocumentIds = new List<int>();
var deleteWithExceptionDocuments = new List<IOfficialDocument>();
var dialog = Dialogs.CreateInputDialog(VerificationAssignments.Resources.DeleteDocumentsDialogTitle);
dialog.HelpCode = Constants.VerificationAssignment.HelpCodes.DeleteDocumentsDialog;
dialog.Height = 80;
var selectedDocuments = dialog
.AddSelectMany(VerificationAssignments.Resources.DeleteDocumentsDialogAttachments, true, OfficialDocuments.Null)
.From(documentList);
selectedDocuments.IsVisible = false;
var deleteButton = dialog.Buttons.AddCustom(Sungero.SmartProcessing.Resources.DeleteDocumentsDialogDeleteButtonName);
deleteButton.IsVisible = false;
Action showTroublesHandler = () =>
{
deleteWithExceptionDocuments.ShowModal();
};
var showTroubles = dialog.AddHyperlink(Sungero.SmartProcessing.Resources.DeleteDocumentDialogDeletingExceptionDocumentsHyperlinkTitle);
showTroubles.SetOnExecute(showTroublesHandler);
showTroubles.IsVisible = false;
var cancelButton = dialog.Buttons.AddCancel();
#region Dialog Refresh Handler
Action<CommonLibrary.InputDialogRefreshEventArgs> refreshDialogHandler = (e) =>
{
if (step == 1)
{
selectedDocuments.IsVisible = true;
deleteButton.IsVisible = true;
dialog.Buttons.Default = deleteButton;
showTroubles.IsVisible = false;
dialog.Text = VerificationAssignments.Resources.DeleteDocumentsDialogText;
cancelButton.Name = Sungero.SmartProcessing.Resources.DeleteDocumentsDialogCancelButtonName1;
}
else
{
selectedDocuments.IsVisible = false;
deleteButton.IsVisible = false;
showTroubles.IsVisible = true;
dialog.Buttons.Default = cancelButton;
var total = selectedDocuments.Value.Count();
var failed = deleteWithExceptionDocuments.Count();
var success = total - failed;
dialog.Text = Sungero.SmartProcessing.Resources.DeleteDocumentsDialogDeletionTotalsFormat(total, Environment.NewLine);
dialog.Text += Sungero.SmartProcessing.Resources.DeleteDocumentsDialogDeletionSuccessFormat(success, Environment.NewLine);
dialog.Text += Sungero.SmartProcessing.Resources.DeleteDocumentsDialogDeletionFailedFormat(failed, Environment.NewLine);
cancelButton.Name = Sungero.SmartProcessing.Resources.DeleteDocumentsDialogCancelButtonName2;
}
};
dialog.SetOnRefresh(refreshDialogHandler);
#endregion
dialog.SetOnButtonClick((e) =>
{
if (e.Button == cancelButton)
e.CloseAfterExecute = true;
if (e.Button == deleteButton)
{
if (!e.IsValid)
{
e.CloseAfterExecute = false;
return;
}
if (assignment.Task.AccessRights.CanUpdate())
deleteWithExceptionDocuments = TryDeleteDocuments(assignment, selectedDocuments.Value.ToList());
else
{
deleteWithExceptionDocuments = selectedDocuments.Value.ToList();
Logger.DebugFormat("Verification Assignment. Action: DeleteDocuments. Failed. No rights to change the task");
}
if (deleteWithExceptionDocuments.Any())
{
e.CloseAfterExecute = false;
step = 2;
}
else
{
e.CloseAfterExecute = true;
Dialogs.NotifyMessage(VerificationAssignments.Resources.DeleteDocumentsDialogNoticeAfterDelete);
}
successfullyDeletedDocumentIds = selectedDocuments.Value
.Where(x => !deleteWithExceptionDocuments.Any(y => y.Id == x.Id))
.Select(x => x.Id)
.ToList();
}
});
dialog.Show();
return successfullyDeletedDocumentIds;
}
/// <summary>
/// Попытаться удалить документы.
/// </summary>
/// <param name="assignment">Задание на верификацию.</param>
/// <param name="documents">Документы для удаления.</param>
/// <returns>Документы, у которых возникли ошибки при удалении.</returns>
public static List<IOfficialDocument> TryDeleteDocuments(IVerificationAssignment assignment, List<IOfficialDocument> documents)
{
var deleteWithExceptionDocuments = new List<IOfficialDocument>();
var idsForRemoveFromAttachments = new List<int>();
foreach (var document in documents)
{
var documentId = document.Id;
try
{
Logger.DebugFormat("Verification Assignment. Action: DeleteDocuments. Try delete document: {0}", documentId);
var removeFromAttachments = Functions.Module.Remote.TryMakeDocumentDeleted(document);
if (removeFromAttachments)
idsForRemoveFromAttachments.Add(documentId);
Logger.DebugFormat("Verification Assignment. Action: DeleteDocuments. Success. Document: {0}", documentId);
}
catch (Exception ex)
{
Logger.DebugFormat("Verification Assignment. Action: DeleteDocuments. Failed. Document: {0}{1}{2}", documentId, Environment.NewLine, ex);
deleteWithExceptionDocuments.Add(document);
}
}
Functions.Module.RemoveAttachmentsFromVerificationTask(assignment, idsForRemoveFromAttachments);
return deleteWithExceptionDocuments;
}
#endregion
}
}