AnnualSectionServerFunctions.cs
3.32 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.AnnualSection;
namespace DirRX.Storage.Server
{
partial class AnnualSectionFunctions
{
/// <summary>
/// Сформировать версию документа из отчета.
/// </summary>
/// <returns>Версия документа.</returns>
[Public]
public virtual void GenerateLastVersionFromReport()
{
// Обновить нумерацию дел в описи.
if (!Signatures.Get(_obj).Where(x => x.SignatureType == SignatureType.Approval).Any())
{
var fromNumber = AnnualSections.GetAll().Where(x => x.ConsolidatedInventory.Equals(_obj.ConsolidatedInventory) && x.Year < _obj.Year).Any() ?
AnnualSections.GetAll().Where(x => x.ConsolidatedInventory.Equals(_obj.ConsolidatedInventory) && x.Year < _obj.Year).Select(x => x.ToNumber).Max() : 0;
using (var command = SQL.GetCurrentConnection().CreateCommand())
{
command.CommandText = string.Format(Queries.AnnualSection.UpdateNumberQuery, fromNumber, _obj.ConsolidatedInventory.Id, _obj.Year);
command.ExecuteNonQuery();
}
_obj.FromNumber = fromNumber + 1;
_obj.ToNumber = fromNumber + DirRX.LongTermArchive.CaseFiles
.GetAll(x => x.LTAConsInventoryDirRX != null && x.LTAConsInventoryDirRX.Equals(_obj.ConsolidatedInventory) && x.LTAConsInventoryYearDirRX == _obj.Year)
.Count();
}
Sungero.Reporting.Shared.IInternalReport internalReport = null;
if (_obj.ConsolidatedInventory.Type == DirRX.Storage.ConsolidatedInventory.Type.Permanent)
{
var report = Storage.Reports.GetAnnualSectionPermanentReport();
report.Entity = _obj;
internalReport = (Sungero.Reporting.Shared.IInternalReport)report;
}
else if (_obj.ConsolidatedInventory.Type == DirRX.Storage.ConsolidatedInventory.Type.Temporary ||
_obj.ConsolidatedInventory.Type == DirRX.Storage.ConsolidatedInventory.Type.Personnel)
{
var report = Storage.Reports.GetAnnualSectionTempAndPersonReport();
report.Entity = _obj;
internalReport = (Sungero.Reporting.Shared.IInternalReport)report;
}
else if (_obj.ConsolidatedInventory.Type == DirRX.Storage.ConsolidatedInventory.Type.ElectronicPerm)
{
var report = Storage.Reports.GetAnnualSectionElectronicPermanentReport();
report.Entity = _obj;
internalReport = (Sungero.Reporting.Shared.IInternalReport)report;
}
else if (_obj.ConsolidatedInventory.Type == DirRX.Storage.ConsolidatedInventory.Type.ElectronicTemp)
{
var report = Storage.Reports.GetAnnualSectionElectronicTempReport();
report.Entity = _obj;
internalReport = (Sungero.Reporting.Shared.IInternalReport)report;
}
_obj.Versions.AddNew();
var version = _obj.LastVersion;
if (internalReport != null)
{
using (var reportMS = new System.IO.MemoryStream())
{
internalReport.InternalExecute(reportMS);
version.Body.Write(reportMS);
}
version.Author = Users.Current;
version.AssociatedApplication = Sungero.Content.AssociatedApplications.GetByExtension("docx");
_obj.Save();
}
}
}
}