FundsSheetServerFunctions.cs 1.18 KB
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.FundsSheet;

namespace DirRX.Storage.Server
{
  partial class FundsSheetFunctions
  {
    /// <summary>
    /// Генерация тела документа.
    /// </summary>
    /// <returns>Версия документа.</returns>
    [Public]
    public virtual Sungero.Content.IElectronicDocumentVersions GenerateLastVersionFromReport()
    {
      var report = Storage.Reports.GetFundsSheetReport();
      report.Entity = _obj;
      
      _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.Note = report.FundsDate.HasValue ? report.FundsDate.Value.Year.ToString() : string.Empty;
      version.Author = Users.Current;
      version.AssociatedApplication = Sungero.Content.AssociatedApplications.GetByExtension("docx");
      _obj.Save();
      
      return version;
    }
  }
}