예제 #1
0
        public void CreateNodes()
        {
            foreach (var root in document.AllRootElements())
            {
                var lists = root.Descendants <MatchNode>().ToList();

                foreach (var matchNode in lists)
                {
                    var m = matchNode.Match;

                    var expr     = m.Groups["expr"].Value;
                    var keyword  = m.Groups["keyword"].Value;
                    var variable = m.Groups["dec"].Value;

                    switch (keyword)
                    {
                    case "":
                        var s = TemplateUtils.SplitToken(expr);
                        if (s == null)
                        {
                            AddError(true, "{0} has invalid format".FormatWith(expr));
                        }
                        else
                        {
                            var vp = ValueProviderBase.TryParse(s.Value.Token, variable, this);

                            matchNode.Parent.ReplaceChild(new TokenNode(matchNode.NodeProvider, vp !, s.Value.Format !)
                            {
                                RunProperties = (OpenXmlCompositeElement?)matchNode.RunProperties?.CloneNode(true)
                            }, matchNode);

                            DeclareVariable(vp);
                        }
                        break;
예제 #2
0
 private static void FixDocument(OpenXmlPackage document)
 {
     foreach (var root in document.AllRootElements())
     {
         foreach (var cell in root.Descendants <W.TableCell>().ToList())
         {
             if (!cell.ChildElements.Any(c => !(c is W.TableCellProperties)))
             {
                 cell.AppendChild(new W.Paragraph());
             }
         }
     }
 }
        internal void ExecuteQuery()
        {
            List <QueryToken> tokens = new List <QueryToken>();

            foreach (var root in document.AllRootElements())
            {
                foreach (var item in root.Descendants <BaseNode>())
                {
                    item.FillTokens(tokens);
                }
            }

            if (this.fileNameBlock != null)
            {
                this.fileNameBlock.FillQueryTokens(tokens);
            }

            var columns = tokens.NotNull().Distinct().Select(qt => new Signum.Entities.DynamicQuery.Column(qt, null)).ToList();

            var filters = model != null?model.GetFilters(this.queryDescription) :
                              entity != null ? new List <Filter>
            {
                new FilterCondition(QueryUtils.Parse("Entity", this.queryDescription, 0), FilterOperation.EqualTo, this.entity.ToLite())
            }

                                                                                                                                                                               :
            throw new InvalidOperationException($"Impossible to create a Word report if '{nameof(entity)}' and '{nameof(model)}' are both null");

            filters.AddRange(template.Filters.ToFilterList());

            var orders = model?.GetOrders(this.queryDescription) ?? new List <Order>();

            orders.AddRange(template.Orders.Select(qo => new Order(qo.Token.Token, qo.OrderType)).ToList());

            this.table = QueryLogic.Queries.ExecuteQuery(new QueryRequest
            {
                QueryName    = this.queryDescription.QueryName,
                GroupResults = template.GroupResults,
                Columns      = columns,
                Pagination   = model?.GetPagination() ?? new Pagination.All(),
                Filters      = filters,
                Orders       = orders,
            });

            var dt = this.table.ToDataTable();

            this.dicTokenColumn = table.Columns.ToDictionary(rc => rc.Column.Token);
        }
예제 #4
0
        internal void MakeQuery()
        {
            List <QueryToken> tokens = new List <QueryToken>();

            foreach (var root in document.AllRootElements())
            {
                foreach (var item in root.Descendants <BaseNode>())
                {
                    item.FillTokens(tokens);
                }
            }

            var columns = tokens.NotNull().Distinct().Select(qt => new Signum.Entities.DynamicQuery.Column(qt, null)).ToList();

            var filters = systemWordTemplate != null?systemWordTemplate.GetFilters(this.queryDescription) :
                              entity != null ? new List <Filter>
            {
                new Filter(QueryUtils.Parse("Entity", this.queryDescription, 0), FilterOperation.EqualTo, this.entity.ToLite())
            }

                                                                                                                                                                      :
            throw new InvalidOperationException($"Impossible to create a Word report if '{nameof(entity)}' and '{nameof(systemWordTemplate)}' are both null");

            this.table = DynamicQueryManager.Current.ExecuteQuery(new QueryRequest
            {
                QueryName  = this.queryDescription.QueryName,
                Columns    = columns,
                Pagination = systemWordTemplate?.GetPagination() ?? new Pagination.All(),
                Filters    = filters,
                Orders     = systemWordTemplate?.GetOrders(this.queryDescription) ?? new List <Order>(),
            });

            var dt = this.table.ToDataTable();

            this.dicTokenColumn = table.Columns.ToDictionary(rc => rc.Column.Token);
        }
예제 #5
0
        public void CreateNodes()
        {
            foreach (var root in document.AllRootElements())
            {
                var lists = root.Descendants <MatchNode>().ToList();

                foreach (var matchNode in lists)
                {
                    var m = matchNode.Match;

                    var type    = m.Groups["type"].Value;
                    var token   = m.Groups["token"].Value;
                    var keyword = m.Groups["keyword"].Value;
                    var dec     = m.Groups["dec"].Value;

                    switch (keyword)
                    {
                    case "":
                        var s = TemplateUtils.SplitToken(token);
                        if (s == null)
                        {
                            AddError(true, "{0} has invalid format".FormatWith(token));
                        }
                        else
                        {
                            var vp = TryParseValueProvider(type, s.Value.Token, dec);

                            matchNode.Parent.ReplaceChild(new TokenNode(matchNode.NodeProvider, vp, s.Value.Format)
                            {
                                RunProperties = (OpenXmlCompositeElement)matchNode.RunProperties?.CloneNode(true)
                            }, matchNode);

                            DeclareVariable(vp);
                        }
                        break;

                    case "declare":
                    {
                        var vp = TryParseValueProvider(type, token, dec);

                        matchNode.Parent.ReplaceChild(new DeclareNode(matchNode.NodeProvider, vp, this.AddError)
                            {
                                RunProperties = (OpenXmlCompositeElement)matchNode.RunProperties?.CloneNode(true)
                            }, matchNode);

                        DeclareVariable(vp);
                    }
                    break;

                    case "any":
                    {
                        AnyNode           any;
                        ValueProviderBase vp;
                        var filter = TemplateUtils.TokenOperationValueRegex.Match(token);
                        if (!filter.Success)
                        {
                            vp  = TryParseValueProvider(type, token, dec);
                            any = new AnyNode(matchNode.NodeProvider, vp)
                            {
                                AnyToken = new MatchNodePair(matchNode)
                            };
                        }
                        else
                        {
                            vp = TryParseValueProvider(type, filter.Groups["token"].Value, dec);
                            var comparer = filter.Groups["comparer"].Value;
                            var value    = filter.Groups["value"].Value;
                            any = new AnyNode(matchNode.NodeProvider, vp, comparer, value, this.AddError)
                            {
                                AnyToken = new MatchNodePair(matchNode)
                            };
                        }

                        PushBlock(any);

                        DeclareVariable(vp);
                        break;
                    }

                    case "notany":
                    {
                        var an = PeekBlock <AnyNode>();
                        if (an != null)
                        {
                            an.NotAnyToken = new MatchNodePair(matchNode);
                        }
                        break;
                    }

                    case "endany":
                    {
                        var an = PopBlock <AnyNode>();
                        if (an != null)
                        {
                            an.EndAnyToken = new MatchNodePair(matchNode);

                            an.ReplaceBlock();
                        }
                        break;
                    }

                    case "if":
                    {
                        IfNode            ifn;
                        ValueProviderBase vpb;
                        var filter = TemplateUtils.TokenOperationValueRegex.Match(token);
                        if (!filter.Success)
                        {
                            vpb = TryParseValueProvider(type, token, dec);
                            ifn = new IfNode(matchNode.NodeProvider, vpb)
                            {
                                IfToken = new MatchNodePair(matchNode)
                            };
                        }
                        else
                        {
                            vpb = TryParseValueProvider(type, filter.Groups["token"].Value, dec);
                            var comparer = filter.Groups["comparer"].Value;
                            var value    = filter.Groups["value"].Value;
                            ifn = new IfNode(matchNode.NodeProvider, vpb, comparer, value, this.AddError)
                            {
                                IfToken = new MatchNodePair(matchNode)
                            };
                        }

                        PushBlock(ifn);

                        DeclareVariable(vpb);

                        break;
                    }

                    case "else":
                    {
                        var an = PeekBlock <IfNode>();
                        if (an != null)
                        {
                            an.ElseToken = new MatchNodePair(matchNode);
                        }
                        break;
                    }

                    case "endif":
                    {
                        var ifn = PopBlock <IfNode>();
                        if (ifn != null)
                        {
                            ifn.EndIfToken = new MatchNodePair(matchNode);

                            ifn.ReplaceBlock();
                        }
                        break;
                    }

                    case "foreach":
                    {
                        var vp = TryParseValueProvider(type, token, dec);
                        var fn = new ForeachNode(matchNode.NodeProvider, vp)
                        {
                            ForeachToken = new MatchNodePair(matchNode)
                        };
                        PushBlock(fn);

                        DeclareVariable(vp);
                        break;
                    }

                    case "endforeach":
                    {
                        var fn = PopBlock <ForeachNode>();
                        if (fn != null)
                        {
                            fn.EndForeachToken = new MatchNodePair(matchNode);

                            fn.ReplaceBlock();
                        }
                        break;
                    }

                    default:
                        AddError(true, "'{0}' is deprecated".FormatWith(keyword));
                        break;
                    }
                }
            }
        }