ModuleClientFunctions.cs
9 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
namespace DirRX.CaseArchiving.Client
{
public class ModuleFunctions
{
/// <summary>
/// Отобразить диалог для создания описей электронных дел.
/// </summary>
[Public]
public virtual void ShowCaseInventoryCreationDialog()
{
// Проверить наличие завершенных дел для включения в описи.
var caseFiles = CaseArchiving.PublicFunctions.Module.Remote.GetCaseFiles(DirRX.LongTermArchive.CaseFile.LTAStageDirRX.CompletedDirRX);
var isCreateByDepartments = CaseArchiving.PublicFunctions.Module.Remote.IsCreateCaseInventoryByDepartments();
if (isCreateByDepartments)
caseFiles = caseFiles.Where(x => x.Department != null);
if (!caseFiles.Any())
{
Dialogs.ShowMessage(CaseArchiving.Resources.CreateInventoriesDialogCaseFileNotFoundWarning, MessageType.Warning);
return;
}
// Запросить критерии формирования описей.
var dialog = Dialogs.CreateInputDialog(CaseArchiving.Resources.CreateInventoriesDialogTitle);
var yearSelector = dialog.AddString(CaseArchiving.Resources.CreateInventoriesDialogYearLabel, true, Calendar.Now.Year.ToString());
var caseInventoryKindList = caseFiles.Where(x => x.LTAInventoryKindDirRX != null).Select(x => x.LTAInventoryKindDirRX).Distinct();
var documentKinds = dialog.AddSelectMany(CaseArchiving.Resources.CreateInventoriesDialogKindsLabel, false, caseInventoryKindList.First()).From(caseInventoryKindList);
var registrationGroups = dialog.AddSelectMany(Sungero.Docflow.RegistrationGroups.Info.LocalizedPluralName, false, Sungero.Docflow.RegistrationGroups.Null)
.From(caseFiles.Where(x => x.RegistrationGroup != null).Select(x => x.RegistrationGroup).Distinct().ToArray());
var departments = dialog.AddSelectMany(Sungero.Company.Departments.Info.LocalizedPluralName, false, Sungero.Company.Departments.Null);
if (isCreateByDepartments)
departments.From(caseFiles.Select(x => x.Department).Distinct());
else
departments.IsVisible = false;
var caseInventoryResponsibleList = caseFiles.Where(x => x.LTAResponsibleDirRX != null).Select(x => x.LTAResponsibleDirRX).Distinct();
var responsibles = dialog.AddSelectMany(CaseArchiving.Resources.CreateInventoriesDialogResponsibleLabel, false, Sungero.Company.Employees.Null).From(caseInventoryResponsibleList);
var curentUserEmployee = Storage.PublicFunctions.Module.Remote.GetEmployeeForCurentUser();
if (curentUserEmployee != null)
responsibles.Value = caseInventoryResponsibleList.AsEnumerable().Where(x => x.Equals(curentUserEmployee));
var archivists = CaseArchiving.PublicFunctions.Module.Remote.GetEmployeesForArchivistRole();
var archivist = dialog.AddSelect(CaseArchiving.Resources.CreateInventoriesDialogArchivistLabel, true, archivists.FirstOrDefault()).From(archivists);
dialog.SetOnButtonClick((e) =>
{
if (e.Button == DialogButtons.Ok)
{
int tmp;
if (!(int.TryParse(yearSelector.Value, out tmp) && tmp > 1990))
e.AddError("Неверно указан год.");
}
});
if (dialog.Show() == DialogButtons.Ok)
{
var year = int.Parse(yearSelector.Value);
// Наложить полученные в диалоге фильтры на список завершенных дел.
caseFiles = caseFiles.Where(x => (x.StartDate.HasValue ? x.StartDate.Value.Year : 0) <= year && (x.EndDate.HasValue ? x.EndDate.Value.Year : 5000) >= year);
if (documentKinds.Value.Any())
caseFiles = caseFiles.Where(x => x.LTAInventoryKindDirRX != null && documentKinds.Value.Contains(x.LTAInventoryKindDirRX));
if (departments.Value.Any())
caseFiles = caseFiles.Where(x => x.Department != null && departments.Value.Contains(x.Department));
if (registrationGroups.Value.Any())
caseFiles = caseFiles.Where(x => x.RegistrationGroup != null && registrationGroups.Value.Contains(x.RegistrationGroup));
if (responsibles.Value.Any())
{
var responsibleIds = responsibles.Value.Select(x => x.Id).ToList();
caseFiles = caseFiles.Where(x => x.LTAResponsibleDirRX != null && responsibleIds.Contains(x.LTAResponsibleDirRX.Id));
}
if (!caseFiles.Any())
{
Dialogs.ShowMessage(CaseArchiving.Resources.CreateInventoriesDialogCaseFileNotFoundWarning, MessageType.Warning);
return;
}
// Создать и отобразить описи дел.
var emptyCaseInventories = CaseArchiving.PublicFunctions.Module.Remote.CreateCaseInventories(year, caseFiles.ToList(), archivist.Value).ToList();
var filledCaseInventories = FillCaseInventories(emptyCaseInventories);
filledCaseInventories.Show();
}
}
/// <summary>
/// Заполнить описи отчётом и отправить на проверку.
/// </summary>
/// <param name="emptyCaseInventories">Пустые описи.</param>
/// <returns>Заполненные описи.</returns>
public virtual List<CaseArchiving.ICaseInventory> FillCaseInventories(List<CaseArchiving.ICaseInventory> emptyCaseInventories)
{
var filledCaseInventories = new List<CaseArchiving.ICaseInventory>();
foreach (var caseInventory in emptyCaseInventories)
{
// Сформировать тело документа из отчета.
CaseArchiving.PublicFunctions.CaseInventory.GenerateLastVersionFromReport(caseInventory);
filledCaseInventories.Add(caseInventory);
// Отправить опись на верификацию.
CaseArchiving.PublicFunctions.Module.SendCaseInventoryForVerification(caseInventory);
}
return filledCaseInventories;
}
/// <summary>
/// Отобразить настройки модуля "Описи электронных дел".
/// </summary>
[Public]
public virtual void ShowCaseInventorySettingsDialog()
{
var createInventoryByDepartments = CaseArchiving.PublicFunctions.Module.Remote.IsCreateCaseInventoryByDepartments();
var useInventoryInSource = CaseArchiving.PublicFunctions.Module.Remote.IsCaseInventoryUsedInSourceSystem();
var useInventoryInArchive = CaseArchiving.PublicFunctions.Module.Remote.IsCaseInventoryUsedInArchiveSystem();
var dialog = Dialogs.CreateInputDialog(Resources.CaseInventorySettingsDialogTitle);
var useInSourceSelector = dialog.AddBoolean(Resources.CaseInventorySettingsUseInSourceLabel, useInventoryInSource);
var useInArchiveSelector = dialog.AddBoolean(Resources.CaseInventorySettingsUseInArchiveLabel, useInventoryInArchive);
var createByDepartmentSelector = dialog.AddBoolean(Resources.CaseInventorySettingsCreateByDepartmentsLabel, createInventoryByDepartments);
// Сделать настройки места использования описей взаимоисключающими.
useInArchiveSelector.SetOnValueChanged((m) =>
{
if (m.NewValue == true)
useInSourceSelector.Value = false;
});
useInSourceSelector.SetOnValueChanged((m) =>
{
if (m.NewValue == true)
useInArchiveSelector.Value = false;
});
if (dialog.Show() == DialogButtons.Ok)
{
if (createByDepartmentSelector.Value.Value != createInventoryByDepartments)
CaseArchiving.PublicFunctions.Module.Remote.SetDocflowParam(CaseArchiving.PublicConstants.Module.DocflowParams.CreateCaseInventoryByDepartmentsKey, createByDepartmentSelector.Value.Value.ToString().ToLower());
if (useInSourceSelector != null)
{
if (useInSourceSelector.Value.Value != useInventoryInSource)
CaseArchiving.PublicFunctions.Module.Remote.SetDocflowParam(CaseArchiving.PublicConstants.Module.DocflowParams.UseCaseInventoryInSourceSystemKey, useInSourceSelector.Value.Value.ToString().ToLower());
if (useInArchiveSelector.Value.Value != useInventoryInArchive)
CaseArchiving.PublicFunctions.Module.Remote.SetDocflowParam(CaseArchiving.PublicConstants.Module.DocflowParams.UseCaseInventoryInArchiveSystemKey, useInArchiveSelector.Value.Value.ToString().ToLower());
}
}
}
}
}