private string GetValue(PrinterTemplate template, IEnumerable <T> models)
        {
            var groupSwitchValue = template.GetSwitch(GetTargetTag() + " GROUP");

            if (groupSwitchValue != null)
            {
                var result = "";
                var groups = models.GroupBy(x => GetGroupSelector(x, groupSwitchValue));
                foreach (var @group in groups.OrderBy(x => x.Key))
                {
                    IGrouping <GroupingKey, T> grp = @group;
                    var gtn           = string.Format("{0} GROUP{1}", GetTargetTag(), grp.Key.Name != null ? ":" + grp.Key.Name : "");
                    var groupTemplate = (template.GetPart(gtn) ?? "");
                    groupTemplate = Helper.FormatDataIf(grp.Key != null, groupTemplate, "{GROUP KEY}", () => (grp.Key.Name ?? ""));
                    groupTemplate = Helper.FormatDataIf(grp.Key != null, groupTemplate, "{GROUP SUM}", () => grp.Sum(x => GetSumSelector(x)).ToString("#,#0.00"));
                    result       += ReplaceValues(groupTemplate, grp.ElementAt(0), template) + "\r\n";
                    group.ToList().ForEach(x => ProcessItem(x, groupSwitchValue));
                    result += string.Join("\r\n", grp.SelectMany(x => GetValue(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
                    var ftr         = string.Format("{0} FOOTER{1}", GetTargetTag(), grp.Key.Name != null ? ":" + grp.Key.Name : "");
                    var ftrTemplate = template.GetPart(ftr) ?? "";
                    ftrTemplate = Helper.FormatDataIf(grp.Key != null, ftrTemplate, "{GROUP KEY}", () => (grp.Key.Name ?? ""));
                    ftrTemplate = Helper.FormatDataIf(grp.Key != null, ftrTemplate, "{GROUP SUM}", () => grp.Sum(x => GetSumSelector(x)).ToString("#,#0.00"));
                    result     += "\r\n" + ftrTemplate + "\r\n";
                }
                return(result);
            }
            return(string.Join("\r\n", models.SelectMany(x => GetValue(template, x).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))));
        }
        private string UpdateGroupTemplateValues(PrinterTemplate template, string templateKey, IGrouping <GroupingKey, T> grouping)
        {
            var groupKeyName = grouping.Key.Name ?? "";
            var templateStr  = template.GetPart(templateKey) ?? "";

            templateStr = Helper.FormatDataIf(grouping.Key != null, templateStr, "{GROUP KEY}", () => (groupKeyName));
            templateStr = Helper.FormatDataIf(grouping.Key != null, templateStr, "{GROUP SUM}",
                                              () => grouping.Sum(x => GetSumSelector(x)).ToString(LocalSettings.CurrencyFormat));
            templateStr = Helper.FormatDataIf(grouping.Key != null, templateStr, "{QUANTITY SUM}",
                                              () => grouping.Sum(x => GetQuantitySelector(x)).ToString(LocalSettings.QuantityFormat));
            return(templateStr);
        }
Exemple #3
0
        public string GetResult(T model, string currentData, PrinterTemplate template)
        {
            var t        = Tag;
            var tagValue = "";

            if (Tag.Contains(":") && Regex.IsMatch(currentData, Tag))
            {
                var m = Regex.Match(currentData, Tag);
                tagValue = m.Groups[1].Value.Trim();
                t        = m.Groups[0].Value;
            }

            while (currentData.Contains(t))
            {
                currentData = Helper.FormatDataIf(Condition == null || Condition.Invoke(model), currentData, t, () => Func.Invoke(model, tagValue));
            }
            return(currentData);
        }