AddendumHandlers.cs
3.89 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.Addendum;
namespace Sungero.Docflow
{
partial class AddendumCreatingFromServerHandler
{
public override void CreatingFrom(Sungero.Domain.CreatingFromEventArgs e)
{
base.CreatingFrom(e);
if (_source.LeadingDocument == null || !_source.LeadingDocument.AccessRights.CanRead())
e.Without(_info.Properties.LeadingDocument);
}
}
partial class AddendumLeadingDocumentPropertyFilteringServerHandler<T>
{
public override IQueryable<T> LeadingDocumentFiltering(IQueryable<T> query, Sungero.Domain.PropertyFilteringEventArgs e)
{
query = base.LeadingDocumentFiltering(query, e);
// Исключить из выбора сам документ, а также черновики из системы обмена.
return query.Where(d => !Equals(d, _obj) && !ExchangeDocuments.Is(d));
}
}
partial class AddendumServerHandlers
{
public override void BeforeSaveHistory(Sungero.Content.DocumentHistoryEventArgs e)
{
base.BeforeSaveHistory(e);
var isCreateAction = e.Action == Sungero.CoreEntities.History.Action.Create;
var documentParams = ((Domain.Shared.IExtendedEntity)_obj).Params;
if (isCreateAction && documentParams.ContainsKey(PublicConstants.Module.AddendumSourceFileNameParamName))
{
e.Comment = documentParams[PublicConstants.Module.AddendumSourceFileNameParamName].ToString();
e.OperationDetailed = Sungero.Content.DocumentHistory.OperationDetailed.FromFile;
}
documentParams.Remove(PublicConstants.Module.AddendumSourceFileNameParamName);
}
public override void BeforeSave(Sungero.Domain.BeforeSaveEventArgs e)
{
var leadingDocumentChanged = !Equals(_obj.LeadingDocument, _obj.State.Properties.LeadingDocument.OriginalValue);
if (leadingDocumentChanged)
{
// Проверить, доступен ли для изменения ведущий документ.
var isLeadingDocumentDisabled = Sungero.Docflow.PublicFunctions.OfficialDocument.NeedDisableLeadingDocument(_obj);
if (isLeadingDocumentDisabled)
e.AddError(Sungero.Docflow.OfficialDocuments.Resources.RelationPropertyDisabled);
if (Functions.OfficialDocument.IsProjectDocument(_obj.LeadingDocument, new List<int>()))
e.Params.AddOrUpdate(Constants.OfficialDocument.GrantAccessRightsToProjectDocument, true);
}
base.BeforeSave(e);
if (_obj.LeadingDocument != null && leadingDocumentChanged && _obj.AccessRights.StrictMode != AccessRightsStrictMode.Enhanced)
{
var accessRightsLimit = Functions.OfficialDocument.GetAvailableAccessRights(_obj);
if (accessRightsLimit != Guid.Empty)
Functions.OfficialDocument.CopyAccessRightsToDocument(_obj.LeadingDocument, _obj, accessRightsLimit);
}
if (_obj.LeadingDocument != null && _obj.LeadingDocument.AccessRights.CanRead() &&
!_obj.Relations.GetRelatedFrom(Constants.Module.AddendumRelationName).Contains(_obj.LeadingDocument))
_obj.Relations.AddFromOrUpdate(Constants.Module.AddendumRelationName, _obj.State.Properties.LeadingDocument.OriginalValue, _obj.LeadingDocument);
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
var isRemainObsoleteAfterTypeChange = e.Params.Contains(string.Format("doc{0}_ConvertingFrom", _obj.Id)) &&
_obj.LifeCycleState == Docflow.OfficialDocument.LifeCycleState.Obsolete;
base.Created(e);
if (_obj.State.IsInserted && _obj.LeadingDocument != null)
_obj.Relations.AddFrom(Constants.Module.AddendumRelationName, _obj.LeadingDocument);
if (!isRemainObsoleteAfterTypeChange)
_obj.LifeCycleState = Docflow.OfficialDocument.LifeCycleState.Active;
}
}
}