DestructionActServerFunctions.cs
2.99 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.DestructionAct;
namespace DirRX.Storage.Server
{
partial class DestructionActFunctions
{
// Получить список дел акта.
[Public, Remote(IsPure=true)]
public virtual IQueryable<DirRX.LongTermArchive.ICaseFile> GetCaseFiles()
{
return DirRX.LongTermArchive.CaseFiles.GetAll(x => x.LTADestructionActDirRX != null && x.LTADestructionActDirRX.Equals(_obj));
}
/// <summary>
/// Исключить все дела из акта.
/// </summary>
/// <returns>Сообщение об ошибке, либо пустая строка.</returns>
[Public, Remote]
public string RemoveAllCaseFiles()
{
try
{
foreach (var cf in PublicFunctions.DestructionAct.Remote.GetCaseFiles(_obj))
{
if (!DirRX.LongTermArchive.PublicFunctions.CaseFile.UpdateDestructionAct(cf, null, null))
{
throw new ApplicationException(string.Format("Не удалось исключить дело ИД {0}.", cf.Id));
}
}
Functions.DestructionAct.UpdatePeriod(_obj);
_obj.Save();
return string.Empty;
}
catch (Exception e)
{
Logger.Debug(e.ToString());
return e.Message;
}
}
/// <summary>
/// Сформировать тело документа из отчета.
/// </summary>
/// <returns>Версия документа.</returns>
[Public]
public virtual void GenerateLastVersionFromReport()
{
var report = Storage.Reports.GetDestructionActMainReport();
report.Entity = _obj;
if (!_obj.HasVersions)
_obj.Versions.AddNew();
var version = _obj.LastVersion;
using (var reportMS = new System.IO.MemoryStream())
{
var internalReport = (Sungero.Reporting.Shared.IInternalReport)report;
internalReport.InternalExecute(reportMS);
version.Body.Write(reportMS);
}
version.Author = Users.Current;
version.AssociatedApplication = Sungero.Content.AssociatedApplications.GetByExtension("docx");
_obj.Save();
}
/// <summary>
/// Получить следующий по порядку номер акта.
/// </summary>
/// <returns>Номер акта.</returns>
public virtual int GetNextDocumentNumber()
{
var result = 1;
AccessRights.AllowRead(
() =>
{
// Предполагается, что все ключевые свойства заполнены (необходимо проверить до вызова).
var lastDocument = DestructionActs.GetAll(x => x.Id != _obj.Id && x.DocumentNumber.HasValue).OrderByDescending(x => x.Id).FirstOrDefault();
if (lastDocument != null)
result += lastDocument.DocumentNumber.Value;
});
return result;
}
}
}