OutgoingDocumentBaseHandlers.cs
5.81 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.OutgoingDocumentBase;
namespace Sungero.Docflow
{
partial class OutgoingDocumentBaseAddresseesSharedCollectionHandlers
{
public virtual void AddresseesAdded(Sungero.Domain.Shared.CollectionPropertyAddedEventArgs e)
{
_added.Number = (_obj.Addressees.Max(a => a.Number) ?? 0) + 1;
}
public virtual void AddresseesDeleted(Sungero.Domain.Shared.CollectionPropertyDeletedEventArgs e)
{
if (_obj.IsManyAddressees == true && _obj.InResponseTo != null && !_obj.Addressees.Any(x => Equals(x.Correspondent, _obj.InResponseTo.Correspondent)))
_obj.InResponseTo = null;
}
}
partial class OutgoingDocumentBaseAddresseesSharedHandlers
{
public virtual void AddresseesAddresseeChanged(Sungero.Docflow.Shared.OutgoingDocumentBaseAddresseesAddresseeChangedEventArgs e)
{
if (e.NewValue != null && !Equals(e.NewValue, e.OldValue) && !Equals(e.NewValue.Company, _obj.Correspondent))
_obj.Correspondent = e.NewValue.Company;
}
public virtual void AddresseesCorrespondentChanged(Sungero.Docflow.Shared.OutgoingDocumentBaseAddresseesCorrespondentChangedEventArgs e)
{
if (!Equals(e.NewValue, e.OldValue))
{
if (_obj.Addressee != null && !Equals(_obj.Addressee.Company, e.NewValue))
_obj.Addressee = null;
if (_obj.OutgoingDocumentBase.InResponseTo != null && !_obj.OutgoingDocumentBase.Addressees.Any(x => Equals(x.Correspondent, _obj.OutgoingDocumentBase.InResponseTo.Correspondent)))
_obj.OutgoingDocumentBase.InResponseTo = null;
}
}
}
partial class OutgoingDocumentBaseSharedHandlers
{
public override void DeliveryMethodChanged(Sungero.Docflow.Shared.OfficialDocumentDeliveryMethodChangedEventArgs e)
{
base.DeliveryMethodChanged(e);
if (!Equals(e.NewValue, e.OldValue))
this.SyncAddressees();
}
public virtual void IsManyAddresseesChanged(Sungero.Domain.Shared.BooleanPropertyChangedEventArgs e)
{
if (_obj.IsManyAddressees == true)
{
var inResponseTo = _obj.InResponseTo;
Functions.OutgoingDocumentBase.ClearAndFillFirstAddressee(_obj);
// Восстановление ссылки на входящее письмо после очистки и заполнения адресатов.
if (inResponseTo != null && _obj.Addressees.Any(x => Equals(x.Correspondent, inResponseTo.Correspondent)))
_obj.InResponseTo = inResponseTo;
_obj.Correspondent = Parties.PublicFunctions.Counterparty.Remote.GetDistributionListCounterparty();
_obj.DistributionCorrespondent = _obj.Correspondent.Name;
_obj.DeliveryMethod = null;
_obj.Addressee = null;
}
else if (_obj.IsManyAddressees == false)
{
var addressee = _obj.Addressees.OrderBy(a => a.Number).FirstOrDefault(a => a.Correspondent != null);
if (addressee != null)
{
_obj.Correspondent = addressee.Correspondent;
_obj.DeliveryMethod = addressee.DeliveryMethod;
_obj.Addressee = addressee.Addressee;
}
else
{
_obj.Correspondent = null;
_obj.DeliveryMethod = null;
_obj.Addressee = null;
}
Functions.OutgoingDocumentBase.ClearAndFillFirstAddressee(_obj);
}
}
public virtual void InResponseToChanged(Sungero.Docflow.Shared.OutgoingDocumentBaseInResponseToChangedEventArgs e)
{
if (Equals(e.NewValue, e.OldValue))
return;
_obj.Relations.AddFromOrUpdate(Constants.Module.ResponseRelationName, e.OldValue, e.NewValue);
if (e.NewValue == null)
return;
if (_obj.IsManyAddressees == false && !Equals(_obj.Correspondent, e.NewValue.Correspondent))
_obj.Correspondent = e.NewValue.Correspondent;
if (_obj.IsManyAddressees == true && !_obj.Addressees.Any())
{
var newAddressee = _obj.Addressees.AddNew();
newAddressee.Correspondent = e.NewValue.Correspondent;
}
Functions.OfficialDocument.CopyProjects(e.NewValue, _obj);
}
public virtual void AddresseeChanged(Sungero.Docflow.Shared.OutgoingDocumentBaseAddresseeChangedEventArgs e)
{
if (e.NewValue != null && !Equals(e.NewValue, e.OldValue) && !Equals(e.NewValue.Company, _obj.Correspondent))
_obj.Correspondent = e.NewValue.Company;
if (!Equals(e.NewValue, e.OldValue))
this.SyncAddressees();
}
public virtual void CorrespondentChanged(Sungero.Docflow.Shared.OutgoingDocumentBaseCorrespondentChangedEventArgs e)
{
if (!Equals(e.NewValue, e.OldValue))
{
_obj.State.Properties.Addressee.IsEnabled = Sungero.Parties.CompanyBases.Is(e.NewValue) || e.NewValue == null;
if (!_obj.State.Properties.Addressee.IsEnabled ||
(_obj.Addressee != null && !Equals(_obj.Addressee.Company, e.NewValue)))
_obj.Addressee = null;
if (_obj.IsManyAddressees == false && _obj.InResponseTo != null && _obj.InResponseTo.Correspondent != _obj.Correspondent)
_obj.InResponseTo = null;
}
if (!Equals(e.NewValue, e.OldValue))
this.SyncAddressees();
}
public override void SubjectChanged(Sungero.Domain.Shared.StringPropertyChangedEventArgs e)
{
base.SubjectChanged(e);
}
private void SyncAddressees()
{
if (_obj.IsManyAddressees == true)
{
_obj.Correspondent = Parties.PublicFunctions.Counterparty.Remote.GetDistributionListCounterparty();
_obj.DeliveryMethod = null;
_obj.Addressee = null;
}
else if (_obj.IsManyAddressees == false)
Functions.OutgoingDocumentBase.ClearAndFillFirstAddressee(_obj);
}
}
}