DocumentKindHandlers.cs
5.19 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Sungero.Content;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.DocumentKind;
namespace Sungero.Docflow
{
partial class DocumentKindCreatingFromServerHandler
{
public override void CreatingFrom(Sungero.Domain.CreatingFromEventArgs e)
{
e.Without(_source.Info.Properties.IsDefault);
}
}
partial class DocumentKindDocumentTypePropertyFilteringServerHandler<T>
{
public virtual IQueryable<T> DocumentTypeFiltering(IQueryable<T> query, Sungero.Domain.PropertyFilteringEventArgs e)
{
if (_obj.NumberingType != NumberingType.NotNumerable)
query = query.Where(d => d.IsRegistrationAllowed == true);
return query.Where(d => Equals(d.DocumentFlow, _obj.DocumentFlow));
}
}
partial class DocumentKindServerHandlers
{
public override void BeforeDelete(Sungero.Domain.BeforeDeleteEventArgs e)
{
// Нельзя удалить вид документа МКДО, созданного инициализацией.
if (Functions.DocumentKind.IsExchangeNativeDocumentKind(_obj))
e.AddError(DocumentKinds.Resources.CantDelete);
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
if (!_obj.State.IsCopied)
{
var contractContext = Domain.Shared.CallContextService.CurrentContext.Contains(frame => frame.FolderId != 0);
_obj.DocumentFlow = contractContext ? DocumentFlow.Contracts : DocumentFlow.Inner;
_obj.NumberingType = contractContext ? NumberingType.Registrable : NumberingType.NotNumerable;
_obj.AutoNumbering = false;
_obj.ProjectsAccounting = false;
_obj.GrantRightsToProject = false;
}
_obj.IsDefault = false;
// Для нумеруемых и регистрируемых видов по умолчанию ставим автоимя.
_obj.GenerateDocumentName = _obj.GenerateDocumentName == true || _obj.NumberingType == NumberingType.Registrable || _obj.NumberingType == NumberingType.Numerable;
Functions.DocumentKind.GrantDefaultAccessRightDocumentKind(_obj);
}
public override void BeforeSave(Sungero.Domain.BeforeSaveEventArgs e)
{
// Валидация срока рассмотрения.
if (_obj.DeadlineInDays.HasValue && _obj.DeadlineInDays < 1)
e.AddError(DocumentKinds.Resources.IncorrectDeadline);
if (_obj.DeadlineInHours.HasValue && _obj.DeadlineInHours < 1)
e.AddError(DocumentKinds.Resources.IncorrectDeadline);
if (_obj.NumberingType != NumberingType.Numerable)
_obj.AutoNumbering = false;
// Нельзя изменить тип документа у видов документов МКДО, созданных инициализацией.
if (!Equals(_obj.DocumentType, _obj.State.Properties.DocumentType.OriginalValue) && Functions.DocumentKind.IsExchangeNativeDocumentKind(_obj))
e.AddError(DocumentKinds.Resources.CantChange);
// Обрезать лишние пробелы.
_obj.Name = _obj.Name.Trim();
_obj.ShortName = _obj.ShortName.Trim();
if (!string.IsNullOrWhiteSpace(_obj.Code))
{
_obj.Code = _obj.Code.Trim();
if (Regex.IsMatch(_obj.Code, @"\s"))
e.AddError(_obj.Info.Properties.Code, Docflow.Resources.NoSpacesInCode);
}
// Проверить код на пробелы, если свойство изменено.
if (!string.IsNullOrEmpty(_obj.Code))
{
// При изменении кода e.AddError сбрасывается.
var codeIsChanged = _obj.State.Properties.Code.IsChanged;
_obj.Code = _obj.Code.Trim();
if (codeIsChanged && Regex.IsMatch(_obj.Code, @"\s"))
e.AddError(_obj.Info.Properties.Code, Company.Resources.NoSpacesInCode);
}
// Нельзя закрывать вид документа по умолчанию.
if (_obj.IsDefault == true && _obj.Status == Status.Closed)
e.AddError(DocumentKinds.Resources.ClosedDocumentKindCannotBeDefault);
// Нельзя закрывать вид документа, если по нему есть настройки или правила.
var canClose = !Functions.Module.GetDocumentKindSettings(_obj).Any();
if (_obj.Status == Status.Closed && !canClose)
e.AddError(DocumentKinds.Resources.CantClose, _obj.Info.Actions.ShowSettings);
if (_obj.IsDefault == true)
{
var defaultKinds = DocumentKinds.GetAll(k => k.Status == Status.Active && !Equals(k, _obj) &&
Equals(k.DocumentType, _obj.DocumentType) && k.IsDefault == true);
foreach (var kind in defaultKinds)
{
var lockInfo = Locks.GetLockInfo(kind);
if (lockInfo != null && lockInfo.IsLocked)
{
var error = Commons.Resources.LinkedEntityLockedFormat(
kind.Name,
kind.Id,
lockInfo.OwnerName);
e.AddError(error);
}
kind.IsDefault = false;
}
}
}
}
}