using System; using System.Collections.Generic; using System.Linq; using Comindware.Data.Entity; using Comindware.TeamNetwork.Api.Data.UserCommands; using Comindware.TeamNetwork.Api.Data; class Script {     public static UserCommandResult Main(UserCommandContext userCommandContext, Comindware.Entities entities)     { List Photo_1_Images = new List(); List Table_1_Data = new List(); List Table_2_Data = new List(); var data_ = Api.TeamNetwork.ObjectService.GetPropertyValues(userCommandContext.ObjectIds, // массив из одного ID записи или неск.записей new[] { "Photo_1_Atr", // здесь и ниже системные имена нужных атрибутов "Table_1_Atr", "Table_2_Atr" }); Dictionary data = data_.FirstOrDefault().Value; foreach (byte[] _Image in getImages("Photo_1_Atr", data)) { var temp = new IMG             { Image_data = _Image,             }; Photo_1_Images.Add(temp); } var Table_IdS = getterListSTR("Table_1_Atr", data); foreach (string Table_Id in Table_IdS) { var Table_Data = GetData(Table_Id); string Faktor_ = getByRef("Nazvanie", getString("Faktor", Table_Data)); // переход по ссылке "Faktor" и получение атрибута "Nazvanie" string Parametr_ = getByRef("Nazvanie", getString("Parametr", Table_Data)); // переход по ссылке "Parametr" и получение атрибута "Nazvanie" string Value_ = getNumber("Value", Table_Data); var temp = new TBL_1             { Faktor = Faktor_, Parametr = Parametr_, Value = Value_,             };             Table_1_Data.Add(temp); } Table_IdS = getterListSTR("Table_2_Atr", data); foreach (string Table_Id in Table_IdS) { var Table_Data = GetData(Table_Id); var Responsible_ = Api.Base.AccountService.Get(getString("Responsible", Table_Data)); // получение атрибута типа "Пользователь" string Date_ = getString("Date", Table_Data); if (DateTime.TryParse(Date_, out var temp_Date)) { Date_ = temp_Date.ToString("dd.MM.yyyy HH:mm"); } var temp = new TBL_2             { Destination = getString("Destination", Table_Data), Order = getNumber("Order", Table_Data), Date = Date_, Responsible = Responsible_.FullName, // получение ФИО из атрибута типа "Пользователь"             };             Table_2_Data.Add(temp); } var dataToExport = new RESULT { Table_1 = Table_1_Data, Table_2 = Table_2_Data, Photo_1 = Photo_1_Images, };         var res = Api.TeamNetwork.ObjectAppExportService.ExecuteWordExportTemplate(userCommandContext.DocumentTemplateId, dataToExport, true);         var result = new UserCommandResult         {             Success = true,             Commited = true,             File=new UserCommandFileResult(){                 Content = res,                 Name = userCommandContext.ExportAsPdf ? "File" + ".pdf" : userCommandContext.FileName + ".docx",                 Type = userCommandContext.ExportAsPdf ? "PDF" : "Word"             },             ResultType = UserCommandResultType.Notificate,             Messages = new[]             {                 new UserCommandMessage                 {                     Severity = SeverityLevel.Normal,                     Text = "Документ сформирован"                 }             }         };         return result;     } public static string getString(string key, IDictionary dictionary = null) { if (dictionary == null || key == null) { return null; } if (dictionary.TryGetValue(key, out var result)) { if (result == null) return null; return result.ToString(); } else { return null; } } public static string getNumber(string key, IDictionary dictionary = null) { if (dictionary == null || key == null) { return null; } if (dictionary.TryGetValue(key, out var result)) { string result_STR = "-"; if (result == null) return null; if (float.TryParse(result.ToString(), out float result_NUM)) { result_STR = result_NUM.ToString(); } return result_STR; } else { return null; } } public static string getByRef(string key, string objectId = null) { if (objectId == null || objectId.Contains("account") || objectId == "tempID") { return null; } var container = Api.TeamNetwork.ObjectAppService.GetByObject(objectId); var result = Api.TeamNetwork.ObjectService.GetWithAlias(container.Alias, objectId); return getString(key, result); } public static List getImages(string key, IDictionary dictionary = null) { List listImages = new List(); if (dictionary == null || key == null) { return listImages; } if (dictionary.TryGetValue(key, out var result)) { if (result == null) { return listImages; } try { var documentsList = (object[])result; foreach (var documentId in documentsList) { string FileName = (Api.TeamNetwork.DocumentService.GetContent((string)documentId)).Name; if (FileName.EndsWith("png") || FileName.EndsWith("PNG") || FileName.EndsWith("jpeg") || FileName.EndsWith("jpg") || FileName.EndsWith("JPG")) { byte[] content = (Api.TeamNetwork.DocumentService.GetContent((string)documentId)).Data; listImages.Add(content); } } } catch { try { string FileName = (Api.TeamNetwork.DocumentService.GetContent((string)result)).Name; if (FileName.EndsWith("png") || FileName.EndsWith("PNG") || FileName.EndsWith("jpeg") || FileName.EndsWith("jpg") || FileName.EndsWith("JPG")) { byte[] content = (Api.TeamNetwork.DocumentService.GetContent((string)result)).Data; listImages.Add(content); } } catch {} } return listImages; } else { return listImages; } } public static IList getterListSTR(string key, IDictionary dictionary = null) { var result = new List(); if (dictionary != null && key != null) { if (dictionary.TryGetValue(key, out var objectData)) { var objectDataArray = objectData as object[]; foreach (var singlObject in objectDataArray) { if (singlObject == null) continue; result.Add(singlObject.ToString()); } } } return result; } public static IDictionary GetData(string objectId = null) { if (objectId == null || objectId.Contains("account") || objectId == "tempID") { return null; } var container = Api.TeamNetwork.ObjectAppService.GetByObject(objectId); var result = Api.TeamNetwork.ObjectService.GetWithAlias(container.Alias, objectId); return result; } } public class IMG { public byte[] Image_data { get; set; } } public class TBL_1 { public string Faktor { get; set; } public string Parametr { get; set; } public string Value { get; set; } } public class TBL_2 { public string Destination { get; set; } public string Order { get; set; } public string Date { get; set; } public string Responsible { get; set; } } public class RESULT { public List Photo_1 { get; set; } public List Table_1 { get; set; } public List Table_2 { get; set; } }