SignatureSettingHandlers.cs
7.12 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
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.SignatureSetting;
namespace Sungero.Docflow
{
partial class SignatureSettingSharedHandlers
{
public virtual void SigningReasonChanged(Sungero.Domain.Shared.StringPropertyChangedEventArgs e)
{
Functions.SignatureSetting.FillName(_obj);
}
public virtual void BusinessUnitsChanged(Sungero.Domain.Shared.CollectionPropertyChangedEventArgs e)
{
Functions.SignatureSetting.ChangePropertiesAccess(_obj);
_obj.Certificate = null;
}
public virtual void DocumentKindsChanged(Sungero.Domain.Shared.CollectionPropertyChangedEventArgs e)
{
var categories = Functions.SignatureSetting.GetPossibleCashedCategories(_obj);
var objCategories = _obj.Categories.Select(c => c.Category).Where(c => categories.Contains(c)).ToList();
if (objCategories.Count < _obj.Categories.Count())
{
Docflow.PublicFunctions.Module.TryToShowNotifyMessage(SignatureSettings.Resources.IncompatibleCategoriesExcluded);
_obj.Categories.Clear();
foreach (var category in objCategories)
_obj.Categories.AddNew().Category = category;
}
_obj.State.Properties.Categories.IsEnabled = categories.Any();
}
public virtual void DocumentFlowChanged(Sungero.Domain.Shared.EnumerationPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue && e.NewValue != null && e.NewValue != SignatureSetting.DocumentFlow.All)
{
var suitableDocumentKinds = _obj.DocumentKinds.Where(dk => dk.DocumentKind.DocumentFlow == e.NewValue).Select(k => k.DocumentKind).ToList();
if (suitableDocumentKinds.Count < _obj.DocumentKinds.Count())
{
Functions.Module.TryToShowNotifyMessage(SignatureSettings.Resources.IncompatibleDocumentKindsExcluded);
_obj.DocumentKinds.Clear();
foreach (var documentKind in suitableDocumentKinds)
_obj.DocumentKinds.AddNew().DocumentKind = documentKind;
}
}
var categories = Functions.SignatureSetting.GetPossibleCashedCategories(_obj);
_obj.State.Properties.Categories.IsEnabled = categories.Any();
if (!_obj.State.Properties.Categories.IsEnabled && _obj.Categories.Any())
{
Docflow.PublicFunctions.Module.TryToShowNotifyMessage(SignatureSettings.Resources.IncompatibleCategoriesExcluded);
_obj.Categories.Clear();
}
}
public virtual void DocumentChanged(Sungero.Docflow.Shared.SignatureSettingDocumentChangedEventArgs e)
{
if (e.NewValue != null && !Equals(e.NewValue, e.OldValue) && (_obj.Reason == Docflow.SignatureSetting.Reason.PowerOfAttorney ||
_obj.Reason == Docflow.SignatureSetting.Reason.FormalizedPoA))
{
if (PowerOfAttorneyBases.Is(e.NewValue))
{
var powerOfAttorneyBase = PowerOfAttorneyBases.As(e.NewValue);
_obj.Recipient = powerOfAttorneyBase.IssuedTo;
_obj.ValidFrom = powerOfAttorneyBase.ValidFrom ?? powerOfAttorneyBase.RegistrationDate;
_obj.ValidTill = powerOfAttorneyBase.ValidTill;
_obj.BusinessUnits.Clear();
var newBusinessUnit = _obj.BusinessUnits.AddNew();
newBusinessUnit.BusinessUnit = powerOfAttorneyBase.BusinessUnit;
if (PowerOfAttorneys.Is(powerOfAttorneyBase))
{
var powerOfAttorney = PowerOfAttorneys.As(powerOfAttorneyBase);
_obj.SigningReason = Functions.SignatureSetting.GetPowerOfAttorneySigningReason(_obj, powerOfAttorney);
}
if (FormalizedPowerOfAttorneys.Is(powerOfAttorneyBase))
{
var formalizedPowerOfAttorney = FormalizedPowerOfAttorneys.As(powerOfAttorneyBase);
_obj.SigningReason = Functions.SignatureSetting.GetFormalizedPowerOfAttorneySigningReason(_obj, formalizedPowerOfAttorney);
}
}
else
{
_obj.Recipient = null;
_obj.ValidTill = null;
_obj.BusinessUnits.Clear();
}
}
if (e.NewValue != null && !Equals(e.NewValue, e.OldValue) && _obj.Reason == Docflow.SignatureSetting.Reason.Other)
{
_obj.SigningReason = Functions.Module.TrimSpecialSymbols(_obj.Document.Name);
_obj.ValidTill = null;
_obj.ValidFrom = null;
}
if (e.NewValue == null)
{
_obj.SigningReason = null;
_obj.ValidTill = null;
_obj.ValidFrom = null;
}
}
public virtual void RecipientChanged(Sungero.Docflow.Shared.SignatureSettingRecipientChangedEventArgs e)
{
if (e.NewValue != null && !Sungero.Company.Employees.Is(e.NewValue))
{
if (_obj.Reason == Sungero.Docflow.SignatureSetting.Reason.PowerOfAttorney ||
_obj.Reason == Sungero.Docflow.SignatureSetting.Reason.FormalizedPoA)
{
_obj.Reason = null;
_obj.Document = null;
_obj.SigningReason = null;
_obj.ValidFrom = null;
_obj.ValidTill = null;
}
}
// При изменении подписывающего почистить документ.
if (_obj.Reason == Docflow.SignatureSetting.Reason.PowerOfAttorney &&
_obj.Document != null && Docflow.PowerOfAttorneys.Is(_obj.Document) && !Equals(e.NewValue, PowerOfAttorneys.As(_obj.Document).IssuedTo))
{
_obj.Document = null;
_obj.ValidFrom = null;
_obj.ValidTill = null;
}
if (!Equals(e.NewValue, e.OldValue))
{
_obj.Certificate = null;
_obj.JobTitle = e.NewValue != null && Sungero.Company.Employees.Is(e.NewValue) ? Sungero.Company.Employees.As(e.NewValue).JobTitle : null;
}
Functions.SignatureSetting.ChangePropertiesAccess(_obj);
}
public virtual void ReasonChanged(Sungero.Domain.Shared.EnumerationPropertyChangedEventArgs e)
{
if (!Equals(e.NewValue, e.OldValue))
{
_obj.Document = null;
if (e.NewValue == SignatureSetting.Reason.Duties)
_obj.SigningReason = Sungero.Docflow.SignatureSettings.Resources.Statute;
else
_obj.SigningReason = null;
}
Functions.SignatureSetting.FillName(_obj);
}
public virtual void AmountChanged(Sungero.Domain.Shared.DoublePropertyChangedEventArgs e)
{
if (e.NewValue == null)
return;
// Подставить по умолчанию валюту рубль.
if (_obj.Currency == null)
{
var defaultCurrency = Commons.PublicFunctions.Currency.Remote.GetDefaultCurrency();
if (defaultCurrency != null)
_obj.Currency = defaultCurrency;
}
}
public virtual void LimitChanged(Sungero.Domain.Shared.EnumerationPropertyChangedEventArgs e)
{
// При смене типа ограничения очистить поля с суммой и валютой.
if (e.NewValue != e.OldValue)
{
_obj.Amount = null;
_obj.Currency = null;
}
Functions.SignatureSetting.ChangePropertiesAccess(_obj);
}
}
}