コード例 #1
0
        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))));
        }
コード例 #2
0
        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)).OrderBy(x => x.Key);
                foreach (var @group in groups)
                {
                    var grp           = @group;
                    var gtn           = string.Format("{0} GROUP{1}", GetTargetTag(), grp.Key.Name != null ? ":" + grp.Key.Name : "");
                    var groupTemplate = UpdateGroupTemplateValues(template, gtn, grp);
                    result += ReplaceValues(groupTemplate, grp.ElementAt(0), template) + "\r\n";
                    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 = UpdateGroupTemplateValues(template, ftr, grp);
                    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))));
        }