AddendumSharedFunctions.cs
8.38 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.Addendum;
namespace Sungero.Docflow.Shared
{
partial class AddendumFunctions
{
public override void FillName()
{
if (_obj.DocumentKind != null && !_obj.DocumentKind.GenerateDocumentName.Value && _obj.Name == OfficialDocuments.Resources.DocumentNameAutotext)
_obj.Name = string.Empty;
if (_obj.DocumentKind == null || !_obj.DocumentKind.GenerateDocumentName.Value)
return;
var name = string.Empty;
/* Имя в формате:
<Вид документа> №<номер> "<содержание>" к <имя ведущего документа>.
*/
using (TenantInfo.Culture.SwitchTo())
{
if (!string.IsNullOrWhiteSpace(_obj.RegistrationNumber))
name += OfficialDocuments.Resources.Number + _obj.RegistrationNumber;
if (!string.IsNullOrEmpty(_obj.Subject))
name += " " + _obj.Subject;
if (_obj.LeadingDocument != null)
{
name += OfficialDocuments.Resources.NamePartForLeadDocument;
name += Functions.Module.ReplaceFirstSymbolToLowerCase(GetDocumentName(_obj.LeadingDocument));
}
}
if (string.IsNullOrWhiteSpace(name))
name = OfficialDocuments.Resources.DocumentNameAutotext;
else if (_obj.DocumentKind != null)
name = _obj.DocumentKind.ShortName + name;
name = Docflow.PublicFunctions.Module.TrimSpecialSymbols(name);
_obj.Name = Docflow.PublicFunctions.OfficialDocument.AddClosingQuote(name, _obj);
}
/// <summary>
/// Получить наименование документа.
/// </summary>
/// <param name="document">Документ.</param>
/// <returns>Наименование документа.</returns>
public static string GetDocumentName(IOfficialDocument document)
{
return document.AccessRights.CanRead() ? document.Name : Functions.Addendum.Remote.GetLeadingDocument(document.Id).Name;
}
public override void RefreshDocumentForm()
{
base.RefreshDocumentForm();
var isNotNumerable = _obj.DocumentKind == null || _obj.DocumentKind.NumberingType == Docflow.DocumentKind.NumberingType.NotNumerable;
_obj.State.Properties.BusinessUnit.IsVisible = !isNotNumerable;
_obj.State.Properties.Department.IsVisible = !isNotNumerable;
_obj.State.Properties.OurSignatory.IsVisible = !isNotNumerable || this.GetShowOurSigningReasonParam();
_obj.State.Properties.PreparedBy.IsVisible = !isNotNumerable;
_obj.State.Properties.Assignee.IsVisible = !isNotNumerable;
}
public override void ChangeDocumentPropertiesAccess(bool isEnabled, bool isRepeatRegister)
{
base.ChangeDocumentPropertiesAccess(isEnabled, isRepeatRegister);
_obj.State.Properties.LeadingDocument.IsEnabled = isEnabled || isRepeatRegister;
}
public override string GetLeadDocumentNumber()
{
var doc = _obj.LeadingDocument;
return doc.AccessRights.CanRead() ? doc.RegistrationNumber : Functions.Addendum.Remote.GetLeadingDocument(doc.Id).Number;
}
public override void ChangeRegistrationPaneVisibility(bool needShow, bool repeatRegister)
{
base.ChangeRegistrationPaneVisibility(needShow, repeatRegister);
var notNumerable = _obj.DocumentKind != null && _obj.DocumentKind.NumberingType == Docflow.DocumentKind.NumberingType.NotNumerable;
var needShowRegistrationProperties = !notNumerable && needShow;
var canRegister = _obj.AccessRights.CanRegister();
var caseIsEnabled = notNumerable || !notNumerable && canRegister;
// Может быть уже закрыто от редактирования, если документ зарегистрирован и в формате номера журнала
// присутствует индекс файла.
caseIsEnabled = caseIsEnabled && _obj.State.Properties.CaseFile.IsEnabled;
_obj.State.Properties.RegistrationNumber.IsVisible = needShowRegistrationProperties;
_obj.State.Properties.RegistrationDate.IsVisible = needShowRegistrationProperties;
_obj.State.Properties.CaseFile.IsEnabled = caseIsEnabled;
_obj.State.Properties.PlacedToCaseFileDate.IsEnabled = caseIsEnabled;
}
/// <summary>
/// Проверка на то, что документ является проектным.
/// </summary>
/// <returns>True - если документ проектный, иначе - false.</returns>
[Obsolete("Используйте метод IsProjectDocument(List<int>)")]
public override bool IsProjectDocument()
{
return this.IsProjectDocument(new List<int>());
}
/// <summary>
/// Проверка на то, что документ является проектным.
/// </summary>
/// <param name="leadingDocumentIds">ИД ведущих документов.</param>
/// <returns>True - если документ проектный, иначе - false.</returns>
public override bool IsProjectDocument(List<int> leadingDocumentIds)
{
if (base.IsProjectDocument(leadingDocumentIds))
return true;
// Если текущий документ входит в список ранее вычисленных ведущих документов приложения,
// то есть произошло зацикливание ведущих документов друг с другом,
// и при этом ни один из них не определился как проектный, то значит документ не является проектным.
if (leadingDocumentIds.Any() && leadingDocumentIds.Contains(_obj.Id))
return false;
leadingDocumentIds.Add(_obj.Id);
// Проверить, что ведущий документ является проектным.
return Functions.OfficialDocument.IsProjectDocument(_obj.LeadingDocument, leadingDocumentIds);
}
public override IProjectBase GetProject()
{
return base.GetProject() ?? Functions.OfficialDocument.GetProject(_obj.LeadingDocument);
}
/// <summary>
/// Заполнить обязательные свойства для документа.
/// </summary>
/// <param name="properties">Свойства.</param>
public override void FillRequiredProperties(System.Collections.Generic.IDictionary<string, object> properties)
{
base.FillRequiredProperties(properties);
if (properties.ContainsKey(_obj.Info.Properties.LeadingDocument.Name))
_obj.LeadingDocument = (IOfficialDocument)properties[_obj.Info.Properties.LeadingDocument.Name];
}
/// <summary>
/// Проверка, заполнены ли обязательные и псевдообязательные свойства.
/// </summary>
/// <returns>True - если обязательные и псевдообязательные свойства не заполнены, иначе - false.</returns>
public override bool HasEmptyRequiredProperties()
{
return string.IsNullOrEmpty(_obj.Subject);
}
/// <summary>
/// Установить обязательность свойств в зависимости от заполненных данных.
/// </summary>
public override void SetRequiredProperties()
{
base.SetRequiredProperties();
// Изменить обязательность полей в зависимости от того, программная или визуальная работа.
var isVisualMode = ((Domain.Shared.IExtendedEntity)_obj).Params.ContainsKey(Sungero.Docflow.PublicConstants.OfficialDocument.IsVisualModeParamName);
// При визуальной работе обязательность содержания и корреспондента как в Addendum.
// При программной работе содержание и корреспондент - необязательные.
// Чтобы сбросить обязательность, если она изменилась в вызове текущего метода в базовой сущности.
_obj.State.Properties.Subject.IsRequired = isVisualMode;
}
}
}