IncomingDocumentBaseServerFunctions.cs
4.32 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.IncomingDocumentBase;
namespace Sungero.Docflow.Server
{
partial class IncomingDocumentBaseFunctions
{
/// <summary>
/// Заполнить текстовое отображение адресатов.
/// </summary>
public virtual void SetManyAddresseesLabel()
{
var addressees = _obj.Addressees
.Where(x => x.Addressee != null)
.Select(x => x.Addressee)
.ToList();
var maxLength = _obj.Info.Properties.ManyAddresseesLabel.Length;
var label = Functions.Module.BuildManyAddresseesLabel(addressees, maxLength);
if (_obj.ManyAddresseesLabel != label)
_obj.ManyAddresseesLabel = label;
}
/// <summary>
/// Преобразовать документ в PDF с наложением отметки о поступлении в новую версию.
/// </summary>
/// <param name="rightIndent">Значение отступа справа.</param>
/// <param name="bottomIndent">Значение отступа снизу.</param>
/// <returns>Результат преобразования.</returns>
[Remote]
public virtual Structures.OfficialDocument.СonversionToPdfResult AddRegistrationStamp(double rightIndent, double bottomIndent)
{
var versionId = _obj.LastVersion.Id;
var result = Structures.OfficialDocument.СonversionToPdfResult.Create();
result.HasErrors = true;
// Проверки возможности преобразования и наложения отметки.
var lastVersionExtension = _obj.LastVersion.AssociatedApplication.Extension.ToLower();
if (!PublicFunctions.OfficialDocument.CheckPdfConvertibilityByExtension(_obj, lastVersionExtension))
return Functions.OfficialDocument.GetExtensionValidationError(_obj, lastVersionExtension);
// Выбор способа преобразования.
var isInteractive = Functions.OfficialDocument.CanConvertToPdfInteractively(_obj);
if (isInteractive)
{
// Способ преобразования: интерактивно.
var registrationStamp = this.GetRegistrationStampAsHtml();
result = this.ConvertToPdfAndAddRegistrationStamp(versionId, registrationStamp, rightIndent, bottomIndent);
result.IsFastConvertion = true;
result.ErrorTitle = OfficialDocuments.Resources.ConvertionErrorTitleBase;
}
else
{
var asyncAddRegistrationStamp = Docflow.AsyncHandlers.AddRegistrationStamp.Create();
asyncAddRegistrationStamp.DocumentId = _obj.Id;
asyncAddRegistrationStamp.VersionId = versionId;
asyncAddRegistrationStamp.RightIndent = rightIndent;
asyncAddRegistrationStamp.BottomIndent = bottomIndent;
var startedNotificationText = OfficialDocuments.Resources.ConvertionInProgress;
var completedNotificationText = IncomingDocumentBases.Resources.AddRegistrationStampCompleteNotificationFormat(Hyperlinks.Get(_obj));
asyncAddRegistrationStamp.ExecuteAsync(startedNotificationText, completedNotificationText);
result.IsOnConvertion = true;
result.HasErrors = false;
}
Logger.DebugFormat("Registration stamp. Added {5}. Document id - {0}, kind - {6}, format - {1}, application - {2}, right indent - {3}, bottom indent - {4}.",
_obj.Id, _obj.AssociatedApplication.Extension, _obj.AssociatedApplication, rightIndent, bottomIndent,
isInteractive ? "interactively" : "async", _obj.DocumentKind.DisplayValue);
return result;
}
/// <summary>
/// Проверить, что можно сменить тип документа на простой.
/// </summary>
/// <returns>True - если можно сменить, иначе - false.</returns>
[Remote(IsPure = true)]
public override bool HasSpecifiedTypeRelations()
{
var hasSpecifiedTypeRelations = false;
AccessRights.AllowRead(
() =>
{
hasSpecifiedTypeRelations = OutgoingDocumentBases.GetAll().Any(x => Equals(x.InResponseTo, _obj));
});
return base.HasSpecifiedTypeRelations() || hasSpecifiedTypeRelations;
}
}
}