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)))); }
public string GetValue(PrinterTemplate template, T model) { var modelName = GetModelName(model); var templateName = GetTargetTag() + (!string.IsNullOrEmpty(modelName) ? ":" + modelName : ""); var templatePart = template.GetPart(templateName); return(!string.IsNullOrEmpty(templatePart) ? ReplaceValues(templatePart, model, template) : ""); }
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); }
public string GetValue(PrinterTemplate template, T model) { var filters = template.GetFilters(GetTargetTag()); var templateName = filters.FirstOrDefault(x => FilterMatch(model, x.Key)).Value; if (string.IsNullOrEmpty(templateName)) { var modelName = GetModelName(model); templateName = GetTargetTag() + (!string.IsNullOrEmpty(modelName) ? ":" + modelName : ""); } var templatePart = template.GetPart(templateName); return(!string.IsNullOrEmpty(templatePart) ? ReplaceValues(templatePart, model, template) : ""); }