ApprovalRulesConsolidatedReportHandlers.cs
8.46 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Company;
using Sungero.Core;
using Sungero.CoreEntities;
namespace Sungero.Docflow
{
partial class ApprovalRulesConsolidatedReportClientHandlers
{
public override void BeforeExecute(Sungero.Reporting.Client.BeforeExecuteEventArgs e)
{
// Диалог.
var dialog = Dialogs.CreateInputDialog(Docflow.Resources.ApprovalRulesConsolidatedReport);
dialog.HelpCode = Constants.ApprovalRulesConsolidatedReport.HelpCode;
var businessUnit = dialog.AddSelect(Docflow.Resources.BusinessUnit, false, Sungero.Company.BusinessUnits.Null)
.From(Company.PublicFunctions.BusinessUnit.Remote.GetBusinessUnits().ToArray());
var department = dialog.AddSelect(Docflow.Resources.Department, false, Sungero.Company.Departments.Null)
.From(this.GetFilteredDepartments(null, false).ToArray());
var includeSubsidiary = dialog.AddBoolean(Reports.Resources.ApprovalRulesConsolidatedReport.IncludeSubsidiary, true);
var filterDepartmentsForBusinessUnits = dialog.AddBoolean(Reports.Resources.ApprovalRulesConsolidatedReport.FilterDepartmentsForBusinessUnitsDialogCheckBox, true);
var availableDocumentFlows = new List<Enumeration?>() { Docflow.DocumentKind.DocumentFlow.Incoming, Docflow.DocumentKind.DocumentFlow.Outgoing,
Docflow.DocumentKind.DocumentFlow.Inner, Docflow.DocumentKind.DocumentFlow.Contracts };
var documentFlows = availableDocumentFlows.Select(a => DocumentKinds.Info.Properties.DocumentFlow.GetLocalizedValue(a)).ToList();
var documentFlow = dialog.AddSelect(Docflow.Resources.Direction, false).From(documentFlows.ToArray());
var documentKind = dialog.AddSelect(Docflow.Resources.DocumentKind, false, Sungero.Docflow.DocumentKinds.Null);
var category = dialog.AddSelect(Docflow.Resources.Category, false, Sungero.Docflow.DocumentGroupBases.Null);
// События.
businessUnit.SetOnValueChanged((arg) =>
{
if (Equals(arg.NewValue, arg.OldValue))
return;
if (department.Value != null && !Equals(arg.NewValue, department.Value.BusinessUnit))
department.Value = Sungero.Company.Departments.Null;
department.From(this.GetFilteredDepartments(arg.NewValue, filterDepartmentsForBusinessUnits.Value));
});
department.SetOnValueChanged((arg) =>
{
if (!Equals(arg.NewValue, arg.OldValue) && arg.NewValue != null)
businessUnit.Value = arg.NewValue.BusinessUnit;
});
documentFlow.SetOnValueChanged((arg) =>
{
if (!Equals(arg.NewValue, arg.OldValue))
{
var docFlow = !string.IsNullOrEmpty(arg.NewValue) ?
availableDocumentFlows[documentFlows.IndexOf(arg.NewValue)] : null;
documentKind.From(this.GetFilteredDocumentKinds(docFlow));
category.From(this.GetFilteredCategories(documentKind.Value, docFlow));
if (documentKind.Value != null && documentKind.Value.DocumentFlow != docFlow)
{
documentKind.Value = Sungero.Docflow.DocumentKinds.Null;
category.Value = Sungero.Docflow.DocumentGroupBases.Null;
}
}
});
documentKind.SetOnValueChanged((arg) =>
{
if (!Equals(arg.NewValue, arg.OldValue))
{
var docFlow = !string.IsNullOrEmpty(documentFlow.Value) ?
availableDocumentFlows[documentFlows.IndexOf(documentFlow.Value)] : null;
category.From(this.GetFilteredCategories(arg.NewValue, docFlow));
if (arg.NewValue != null)
documentFlow.Value = DocumentKinds.Info.Properties.DocumentFlow.GetLocalizedValue(arg.NewValue.DocumentFlow);
if (category.Value != null && category.Value.DocumentKinds.Any() &&
!category.Value.DocumentKinds.Any(x => Equals(x.DocumentKind, arg.NewValue)))
category.Value = Sungero.Docflow.DocumentGroupBases.Null;
}
});
category.SetOnValueChanged((arg) =>
{
if (!Equals(arg.NewValue, arg.OldValue))
{
if (arg.NewValue != null && arg.NewValue.DocumentKinds.Count == 1)
documentKind.Value = arg.NewValue.DocumentKinds.Single().DocumentKind;
}
});
filterDepartmentsForBusinessUnits
.SetOnValueChanged((arg) =>
{
department.From(this.GetFilteredDepartments(businessUnit.Value, arg.NewValue));
});
// Показ диалога.
if (dialog.Show() == DialogButtons.Ok)
{
if (businessUnit.Value != null)
ApprovalRulesConsolidatedReport.BusinessUnit = businessUnit.Value;
if (department.Value != null)
ApprovalRulesConsolidatedReport.Department = department.Value;
if (includeSubsidiary != null)
ApprovalRulesConsolidatedReport.IncludeSubsidiary = includeSubsidiary.Value;
if (filterDepartmentsForBusinessUnits != null)
ApprovalRulesConsolidatedReport.FilterDepartmentsForBusinessUnits = filterDepartmentsForBusinessUnits.Value;
if (!string.IsNullOrEmpty(documentFlow.Value))
ApprovalRulesConsolidatedReport.DocumentFlow = documentFlow.Value;
if (documentKind != null)
ApprovalRulesConsolidatedReport.DocumentKind = documentKind.Value;
if (category != null)
ApprovalRulesConsolidatedReport.Category = category.Value;
}
else
e.Cancel = true;
}
private List<IDepartment> GetFilteredDepartments(IBusinessUnit businessUnit, bool? filterDepartmentsForBusinessUnits)
{
var departments = Sungero.Company.PublicFunctions.Department.Remote.GetDepartments()
.Where(d => d.Status == Sungero.CoreEntities.DatabookEntry.Status.Active);
// Подразделения фильтруются по НОР.
if (filterDepartmentsForBusinessUnits == true && businessUnit != null)
return departments
.Where(d => Equals(d.BusinessUnit, businessUnit))
.ToList();
// Подразделения не фильтруются по НОР.
return departments.ToList();
}
private IDocumentKind[] GetFilteredDocumentKinds(Enumeration? documentFlow)
{
var documentKinds = Functions.DocumentKind.Remote.GetDocumentKinds();
if (documentFlow != null)
documentKinds = documentKinds.Where(k => k.DocumentFlow == documentFlow);
return documentKinds.ToArray();
}
private IDocumentGroupBase[] GetFilteredCategories(IDocumentKind documentKind, Enumeration? documentFlow)
{
var categories = Docflow.PublicFunctions.DocumentGroupBase.Remote.GetDocumentGroups();
if (documentFlow != null)
categories = categories.Where(c => c.DocumentKinds.All(k => k.DocumentKind.DocumentFlow == documentFlow));
if (documentKind != null)
categories = categories.Where(c => c.DocumentKinds.Any(k => Equals(k.DocumentKind, documentKind)) || !c.DocumentKinds.Any());
return categories.ToArray();
}
}
}