Exemplo n.º 1
0
    public Data.DataTable GetDataTable(string suffix, WordTemplateLogic.WordContext context)
    {
        var userQuery = Database.Query <UserQueryEntity>().SingleEx(a => a.Guid == Guid.Parse((suffix.TryBefore("\n") ?? suffix).Trim()));

        using (CurrentEntityConverter.SetCurrentEntity(context.GetEntity()))
        {
            var         request = UserQueryLogic.ToQueryRequest(userQuery);
            ResultTable result  = QueryLogic.Queries.ExecuteQuery(request);
            return(result.ToDataTable());
        }
    }
Exemplo n.º 2
0
        public static void Start(SchemaBuilder sb)
        {
            sb.Include <ExcelAttachmentEntity>()
            .WithQuery(() => s => new
            {
                Entity = s,
                s.Id,
                s.FileName,
                s.UserQuery,
                s.Related,
            });

            EmailTemplateLogic.FillAttachmentTokens.Register((ExcelAttachmentEntity ea, EmailTemplateLogic.FillAttachmentTokenContext ctx) =>
            {
                if (ea.FileName != null)
                {
                    TextTemplateParser.Parse(ea.FileName, ctx.QueryDescription, ctx.ModelType).FillQueryTokens(ctx.QueryTokens);
                }

                if (ea.Title != null)
                {
                    TextTemplateParser.Parse(ea.Title, ctx.QueryDescription, ctx.ModelType).FillQueryTokens(ctx.QueryTokens);
                }
            });

            Validator.PropertyValidator((ExcelAttachmentEntity e) => e.FileName).StaticPropertyValidation = ExcelAttachmentFileName_StaticPropertyValidation;
            Validator.PropertyValidator((ExcelAttachmentEntity e) => e.Title).StaticPropertyValidation    = ExcelAttachmentTitle_StaticPropertyValidation;

            EmailTemplateLogic.GenerateAttachment.Register((ExcelAttachmentEntity ea, EmailTemplateLogic.GenerateAttachmentContext ctx) =>
            {
                var finalEntity = ea.Related?.RetrieveAndRemember() ?? (Entity?)ctx.Entity ?? ctx.Model !.UntypedEntity as Entity;

                using (finalEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(finalEntity))
                    using (CultureInfoUtils.ChangeBothCultures(ctx.Culture))
                    {
                        QueryRequest request = UserQueryLogic.ToQueryRequest(ea.UserQuery.RetrieveAndRemember());

                        var title    = GetTemplateString(ea.Title, ref ea.TitleNode, ctx);
                        var fileName = GetTemplateString(ea.FileName, ref ea.FileNameNode, ctx);

                        var bytes = ExcelLogic.ExecutePlainExcel(request, title);

                        return(new List <EmailAttachmentEmbedded>
                        {
                            new EmailAttachmentEmbedded
                            {
                                File = Files.FilePathEmbeddedLogic.SaveFile(new Entities.Files.FilePathEmbedded(EmailFileType.Attachment, fileName, bytes)),
                                Type = EmailAttachmentType.Attachment,
                            }
                        });
                    }
            });
        }
Exemplo n.º 3
0
        public Data.DataTable GetDataTable(string suffix, WordTemplateLogic.WordContext context)
        {
            var userQuery = Database.Query <UserQueryEntity>().SingleOrDefault(a => a.Guid == Guid.Parse(suffix));

            using (CurrentEntityConverter.SetCurrentEntity(context.Entity))
            {
                var         request     = UserQueryLogic.ToQueryRequest(userQuery);
                ResultTable resultTable = DynamicQueryManager.Current.ExecuteQuery(request);
                var         dataTable   = resultTable.ToDataTable();
                return(dataTable);
            }
        }