IncomingLetterSharedFunctions.cs
6.17 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
using Sungero.RecordManagement.IncomingLetter;
namespace Sungero.RecordManagement.Shared
{
partial class IncomingLetterFunctions
{
/// <summary>
/// Проверить письмо на дубликаты.
/// </summary>
/// <param name="letter">Входящее письмо.</param>
/// <param name="documentKind">Вид документа.</param>
/// <param name="businessUnit">Наша организация.</param>
/// <param name="correspondentNumber">Номер корреспондента.</param>
/// <param name="dated">Дата письма.</param>
/// <param name="correspondent">Корреспондент.</param>
/// <returns>True, если дубликаты имеются, иначе - false.</returns>
public static bool HaveDuplicates(IIncomingLetter letter,
Sungero.Docflow.IDocumentKind documentKind,
Company.IBusinessUnit businessUnit,
string correspondentNumber,
DateTime? dated,
Parties.ICounterparty correspondent)
{
if (documentKind == null ||
businessUnit == null ||
string.IsNullOrEmpty(correspondentNumber) ||
!dated.HasValue ||
correspondent == null)
return false;
return Functions.IncomingLetter.Remote.GetDuplicates(letter, documentKind, businessUnit, correspondentNumber, dated, correspondent).Any();
}
public override void FillName()
{
// Не автоформируемое имя.
if (_obj != null && _obj.DocumentKind != null && !_obj.DocumentKind.GenerateDocumentName.Value)
{
if (_obj.Name == Docflow.Resources.DocumentNameAutotext)
_obj.Name = string.Empty;
if (_obj.VerificationState != null && string.IsNullOrWhiteSpace(_obj.Name))
_obj.Name = _obj.DocumentKind.ShortName;
}
if (_obj.DocumentKind == null || !_obj.DocumentKind.GenerateDocumentName.Value)
return;
// Автоформируемое имя.
var name = string.Empty;
/* Имя в формате:
<Вид документа> от <корреспондент> №<номер> от <дата> "<содержание>".
*/
using (TenantInfo.Culture.SwitchTo())
{
if (_obj.Correspondent != null)
name += IncomingLetters.Resources.CorrespondentFrom + _obj.Correspondent.DisplayValue;
if (!string.IsNullOrWhiteSpace(_obj.RegistrationNumber))
name += Sungero.Docflow.OfficialDocuments.Resources.Number + _obj.RegistrationNumber;
if (_obj.RegistrationDate != null)
name += Sungero.Docflow.OfficialDocuments.Resources.DateFrom + _obj.RegistrationDate.Value.ToString("d");
if (!string.IsNullOrWhiteSpace(_obj.Subject))
name += " \"" + _obj.Subject + "\"";
}
if (string.IsNullOrWhiteSpace(name))
{
name = _obj.VerificationState == null ? OfficialDocuments.Resources.DocumentNameAutotext : _obj.DocumentKind.ShortName;
}
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="isEnabled">True, если свойства должны быть доступны.</param>
/// <param name="isRepeatRegister">True, если повторная регистрация.</param>
public override void ChangeDocumentPropertiesAccess(bool isEnabled, bool isRepeatRegister)
{
base.ChangeDocumentPropertiesAccess(isEnabled, isRepeatRegister);
var letterProperties = _obj.State.Properties;
var canRegister = _obj.AccessRights.CanRegister();
// Основная группа.
letterProperties.Dated.IsEnabled = isEnabled;
letterProperties.InNumber.IsEnabled = isEnabled;
// Свойства блокируются для всех, кроме делопроизводителей.
if (!canRegister)
{
letterProperties.SignedBy.IsEnabled = isEnabled;
letterProperties.Contact.IsEnabled = isEnabled;
letterProperties.Assignee.IsEnabled = isEnabled;
letterProperties.Addressee.IsEnabled = isEnabled;
}
}
public override void SetRequiredProperties()
{
base.SetRequiredProperties();
// Изменить обязательность полей в зависимости от того, программная или визуальная работа.
var isVisualMode = ((Domain.Shared.IExtendedEntity)_obj).Params.ContainsKey(Sungero.Docflow.PublicConstants.OfficialDocument.IsVisualModeParamName);
// При визуальной работе обязательность содержания и корреспондента как в IncomingLetter.
// При программной работе содержание и корреспондент - необязательные.
// Чтобы сбросить обязательность, если она изменилась в вызове текущего метода в базовой сущности.
_obj.State.Properties.Subject.IsRequired = isVisualMode;
_obj.State.Properties.Correspondent.IsRequired = isVisualMode;
}
#region Интеллектуальная обработка
[Public]
public override bool IsVerificationModeSupported()
{
return true;
}
[Public]
public override bool HasEmptyRequiredProperties()
{
return string.IsNullOrEmpty(_obj.Subject) || _obj.Correspondent == null;
}
#endregion
}
}