OutgoingDocumentBaseActions.cs
9.78 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow.OutgoingDocumentBase;
using Sungero.Reporting;
namespace Sungero.Docflow.Client
{
partial class OutgoingDocumentBaseAnyChildEntityCollectionActions
{
public override void DeleteChildEntity(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
base.DeleteChildEntity(e);
}
public override bool CanDeleteChildEntity(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
// Дизейбл грида при резервировании номера/регистрации.
var entity = OutgoingDocumentBases.As(e.RootEntity);
return entity != null && _all == entity.Addressees && Functions.OutgoingDocumentBase.DisableAddresseesOnRegistration(entity, e)
? false
: base.CanDeleteChildEntity(e);
}
}
partial class OutgoingDocumentBaseAnyChildEntityActions
{
public override void CopyChildEntity(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
base.CopyChildEntity(e);
}
public override bool CanCopyChildEntity(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
// Дизейбл грида при резервировании номера/регистрации.
var entity = OutgoingDocumentBases.As(e.RootEntity);
return entity != null && _all == entity.Addressees && Functions.OutgoingDocumentBase.DisableAddresseesOnRegistration(entity, e)
? false
: base.CanCopyChildEntity(e);
}
public override void AddChildEntity(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
base.AddChildEntity(e);
}
public override bool CanAddChildEntity(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
// Дизейбл грида при резервировании номера/регистрации.
var entity = OutgoingDocumentBases.As(e.RootEntity);
return entity != null && _all == entity.Addressees && Functions.OutgoingDocumentBase.DisableAddresseesOnRegistration(entity, e)
? false
: base.CanAddChildEntity(e);
}
}
internal static class OutgoingDocumentBaseAddresseesStaticActions
{
public static bool CanFillFromDistributionList(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
var obj = OutgoingDocumentBases.As(e.Entity);
return obj.IsManyAddressees == true && !Functions.OutgoingDocumentBase.DisableAddresseesOnRegistration(obj, e);
}
public static void FillFromDistributionList(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
var obj = OutgoingDocumentBases.As(e.Entity);
var distributionLists = Functions.Module.Remote.GetDistributionLists();
var distributionList = distributionLists.ShowSelect();
if (distributionList == null)
return;
foreach (var addressee in distributionList.Addressees.OrderBy(a => a.Number))
{
var newAddressee = obj.Addressees.AddNew();
newAddressee.Correspondent = addressee.Correspondent;
newAddressee.Addressee = addressee.Addressee;
newAddressee.DeliveryMethod = addressee.DeliveryMethod;
}
}
public static bool CanSaveToDistributionList(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
var obj = OutgoingDocumentBases.As(e.Entity);
return obj.IsManyAddressees == true && DistributionLists.AccessRights.CanCreate();
}
public static void SaveToDistributionList(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
var obj = OutgoingDocumentBases.As(e.Entity);
var distributionList = Functions.Module.Remote.CreateDistributionList();
foreach (var addressee in obj.Addressees.OrderBy(a => a.Number))
{
var newAddressee = distributionList.Addressees.AddNew();
newAddressee.Correspondent = addressee.Correspondent;
newAddressee.Addressee = addressee.Addressee;
newAddressee.DeliveryMethod = addressee.DeliveryMethod;
}
distributionList.Show();
}
public static bool CanPrintDistributionSheetChild(Sungero.Domain.Client.CanExecuteChildCollectionActionArgs e)
{
var obj = OutgoingDocumentBases.As(e.Entity);
return !obj.State.IsInserted && !obj.State.IsChanged && obj.IsManyAddressees == true;
}
public static void PrintDistributionSheetChild(Sungero.Domain.Client.ExecuteChildCollectionActionArgs e)
{
var report = Docflow.Reports.GetDistributionSheetReport();
report.OutgoingDocument = OutgoingDocumentBases.As(e.Entity);
report.Open();
}
}
partial class OutgoingDocumentBaseActions
{
public virtual void ChangeManyAddressees(Sungero.Domain.Client.ExecuteActionArgs e)
{
if (_obj.IsManyAddressees == false)
Dialogs.NotifyMessage(OutgoingDocumentBases.Resources.FillDistributionListOnAdressesTab);
if (_obj.IsManyAddressees == true && _obj.Addressees.Count(a => a.Correspondent != null) > 1)
{
var addresseeRaw = _obj.Addressees.OrderBy(a => a.Number).FirstOrDefault(a => a.Correspondent != null);
var addresseeName = string.Empty;
var correspondentName = addresseeRaw.Correspondent.Name;
if (addresseeRaw.Addressee != null)
{
if (addresseeRaw.Addressee.Person != null)
{
var person = addresseeRaw.Addressee.Person;
addresseeName = Parties.PublicFunctions.Module.GetSurnameAndInitialsInTenantCulture(person.FirstName, person.MiddleName, person.LastName);
}
else
{
var contactName = CaseConverter.SplitPersonFullName(addresseeRaw.Addressee.Name);
addresseeName = Parties.PublicFunctions.Module.GetSurnameAndInitialsInTenantCulture(contactName.FirstName, contactName.MiddleName, contactName.LastName);
}
addresseeName = string.Format("{0} ({1})", addresseeName, correspondentName);
}
else
addresseeName = correspondentName;
var dialog = Dialogs.CreateTaskDialog(OfficialDocuments.Resources.ChangeManyAddresseesQuestion,
OfficialDocuments.Resources.ChangeManyAddresseesDescriptionFormat(addresseeName), MessageType.Question);
dialog.Buttons.AddYesNo();
if (dialog.Show() == DialogButtons.Yes)
_obj.IsManyAddressees = !_obj.IsManyAddressees;
}
else
_obj.IsManyAddressees = !_obj.IsManyAddressees;
}
public virtual bool CanChangeManyAddressees(Sungero.Domain.Client.CanExecuteActionArgs e)
{
// Смена режима многоадресности доступна только пользователям с правами на изменение документа.
return _obj.AccessRights.CanUpdate() ? _obj.State.Properties.IsManyAddressees.IsEnabled : false;
}
public override void AssignNumber(Sungero.Domain.Client.ExecuteActionArgs e)
{
if (_obj.IsManyAddressees == true && !_obj.Addressees.Any())
{
e.AddError(OutgoingDocumentBases.Resources.NeedFillAddressee);
return;
}
base.AssignNumber(e);
}
public override bool CanAssignNumber(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return base.CanAssignNumber(e);
}
public override void Register(Sungero.Domain.Client.ExecuteActionArgs e)
{
if (_obj.IsManyAddressees == true && !_obj.Addressees.Any())
{
e.AddError(OutgoingDocumentBases.Resources.NeedFillAddressee);
return;
}
base.Register(e);
}
public override bool CanRegister(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return base.CanRegister(e);
}
public virtual void PrintDistributionSheet(Sungero.Domain.Client.ExecuteActionArgs e)
{
if (_obj.IsManyAddressees != true)
{
Dialogs.NotifyMessage(OutgoingDocumentBases.Resources.SpecifyMultipleRecipients);
return;
}
var report = Docflow.Reports.GetDistributionSheetReport();
report.OutgoingDocument = _obj;
report.Open();
}
public virtual bool CanPrintDistributionSheet(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return !_obj.State.IsInserted && !_obj.State.IsChanged;
}
public virtual void PrintEnvelopeCard(Sungero.Domain.Client.ExecuteActionArgs e)
{
Functions.OutgoingDocumentBase.ShowSelectEnvelopeFormatDialog(new List<IOutgoingDocumentBase>() { _obj }, null);
}
public virtual bool CanPrintEnvelopeCard(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return !_obj.State.IsInserted && !_obj.State.IsChanged;
}
}
partial class OutgoingDocumentBaseCollectionActions
{
public virtual bool CanPrintEnvelope(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return !_objs.Any(t => t.State.IsInserted || t.State.IsChanged);
}
public virtual void PrintEnvelope(Sungero.Domain.Client.ExecuteActionArgs e)
{
Functions.OutgoingDocumentBase.ShowSelectEnvelopeFormatDialog(_objs.ToList(), null);
}
public virtual bool CanMailRegister(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return true;
}
public virtual void MailRegister(Sungero.Domain.Client.ExecuteActionArgs e)
{
var report = Docflow.Reports.GetMailRegisterReport();
report.OutgoingDocuments.AddRange(_objs);
report.Open();
}
}
internal static class OutgoingDocumentBaseStaticActions
{
public static bool CanDocumentRegister(Sungero.Domain.Client.CanExecuteActionArgs e)
{
return RecordManagement.PublicFunctions.Module.GetOutgoingDocumentsReport().CanExecute();
}
public static void DocumentRegister(Sungero.Domain.Client.ExecuteActionArgs e)
{
RecordManagement.PublicFunctions.Module.GetOutgoingDocumentsReport().Open();
}
}
}