public void PrintAsList(DtoBaseViewModel dto) { var doc = GetListFormattedDocument(dto); PostProcess(dto, doc); //DebugDump(doc); PrintToPdf(doc); }
public void Export(DtoBaseViewModel dto) { if (dto is DtoTableViewModel) { ExportTable((DtoTableViewModel)dto); } }
public void PrintAsList(DtoBaseViewModel dto) { var doc = GetListFormattedDocument(dto); PostProcess(dto, doc); //DebugDump(doc); PrintToPdf(doc); }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoColumnViewModel; //other.Parent is left behind //this.Parent == other.Parent; this.Column = other.Column; }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoTableViewModel; DtoBuilder.Merge(this.Rows, other.Rows); DtoBuilder.Merge(this.Columns, other.Columns); DtoBuilder.Merge(this.Cells, other.Cells); }
private static void PostProcess(DtoBaseViewModel dto, Document doc) { var postProc = dto.Data.GetType().GetMethods().Where(mi => mi.GetCustomAttributes(typeof(GuiPrintPostProcessorAttribute), false).Length > 0).SingleOrDefault(); if (postProc != null) { postProc.Invoke(dto.Data, new object[] { dto.Root, doc }); } // else: ignore, nothing to do }
private static void PostProcess(DtoBaseViewModel dto, Document doc) { var postProc = dto.Data.GetType().GetMethods().Where(mi => mi.GetCustomAttributes(typeof(GuiPrintPostProcessorAttribute), false).Length > 0).SingleOrDefault(); if (postProc != null) { postProc.Invoke(dto.Data, new object[] { dto.Root, doc }); } // else: ignore, nothing to do }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoValueViewModel; this.AlternateRepresentation = other.AlternateRepresentation; this.AlternateRepresentationAlignment = other.AlternateRepresentationAlignment; this.ToolTip = other.ToolTip; this.Value = other.Value; this.ValueAlignment = other.ValueAlignment; }
private Document GetListFormattedDocument(DtoBaseViewModel dto) { var result = new Document(); AppendAsList(new DocumentListState() { CurrentDocument = result }, dto); return(result); }
protected internal virtual void ApplyChangesFrom(DtoBaseViewModel otherBase) { if (otherBase == null) { throw new ArgumentNullException("otherBase"); } this.Background = otherBase.Background; this.Data = otherBase.Data; this.DebugInfo = otherBase.DebugInfo; this.Description = otherBase.Description; this.Formatting = otherBase.Formatting; this.IsPrintableRoot = otherBase.IsPrintableRoot; this.Root = otherBase.Root; this.Title = otherBase.Title; }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoGroupedViewModel; this.AlternateBackground = other.AlternateBackground; var selectedIdx = other.Items.IndexOf(other.SelectedItem); DtoBuilder.Merge(this.Items, other.Items); if (selectedIdx >= 0 && selectedIdx < this.Items.Count) { this.SelectedItem = this.Items[selectedIdx]; } else { this.SelectedItem = this.Items.FirstOrDefault(); } }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoCellViewModel; //other.Parent is left behind //this.Parent == other.Parent; //other.Row is left behind //this.Row == other.Row; //other.Column is left behind //this.Column == other.Column; this.Location = other.Location; var thisDtoViewModel = this.Value as DtoBaseViewModel; var otherDtoViewModel = other.Value as DtoBaseViewModel; if (thisDtoViewModel != null && otherDtoViewModel != null) { this.Value = DtoBuilder.Combine(thisDtoViewModel, otherDtoViewModel); } else { this.Value = other.Value; } }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoCellViewModel; //other.Parent is left behind //this.Parent == other.Parent; //other.Row is left behind //this.Row == other.Row; //other.Column is left behind //this.Column == other.Column; this.Location = other.Location; var thisDtoViewModel = this.Value as DtoBaseViewModel; var otherDtoViewModel = other.Value as DtoBaseViewModel; if (thisDtoViewModel != null && otherDtoViewModel != null) { this.Value = DtoBuilder.Combine(thisDtoViewModel, otherDtoViewModel); } else { this.Value = other.Value; } }
protected internal virtual void ApplyChangesFrom(DtoBaseViewModel otherBase) { if (otherBase == null) throw new ArgumentNullException("otherBase"); this.Background = otherBase.Background; this.Data = otherBase.Data; this.DebugInfo = otherBase.DebugInfo; this.Description = otherBase.Description; this.Formatting = otherBase.Formatting; this.IsPrintableRoot = otherBase.IsPrintableRoot; this.Root = otherBase.Root; this.Title = otherBase.Title; }
private void AppendAsList(DocumentListState dls, DtoBaseViewModel dto) { var dtoTable = dto as DtoTableViewModel; if (dtoTable != null) { if (dtoTable.IsDataTable) { AppendAsTable(dls, dtoTable); } else // append contents of structural table as lists { dls.ForceOrientation(Orientation.Portrait); dls.AddHeading(dto.Title, dto.DebugInfo); dls.AddDescription(dto.Description); dls.CurrentHeadingLevel += 1; foreach (var item in dtoTable.Cells) { var baseVM = item.Value as DtoBaseViewModel; if (baseVM != null) { AppendAsList(dls, baseVM); } else if (item.Value != null) { throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as cell contents", item.Value, item.Value.GetType())); } } dls.CurrentHeadingLevel -= 1; } } else if (typeof(DtoGroupedViewModel).IsAssignableFrom(dto.GetType())) { dls.ForceOrientation(Orientation.Portrait); dls.AddHeading(dto.Title, dto.DebugInfo); dls.CurrentHeadingLevel += 1; foreach (var item in ((DtoGroupedViewModel)dto).Items) { AppendAsList(dls, item); } dls.CurrentHeadingLevel -= 1; } else if (typeof(DtoValueViewModel).IsAssignableFrom(dto.GetType())) { var valVM = dto as DtoValueViewModel; if (dls.CurrentTable == null) { dls.CurrentTable = dls.CurrentSection.AddTable(); dls.CurrentTable.AddColumn("8cm"); // title dls.CurrentTable.AddColumn("4cm"); // value dls.CurrentTable.AddColumn("4cm"); // alternate representation } var row = dls.CurrentTable.AddRow(); row.Cells[0].AddParagraph(dto.Title); if (!string.IsNullOrEmpty(valVM.Value)) { row.Cells[1].AddParagraph(valVM.Value).Format.Alignment = ConvertParagraphAlignment(valVM.ValueAlignment); } if (!string.IsNullOrEmpty(valVM.AlternateRepresentation)) { row.Cells[2].AddParagraph(valVM.AlternateRepresentation).Format.Alignment = ConvertParagraphAlignment(valVM.AlternateRepresentationAlignment); } if (!string.IsNullOrEmpty(valVM.Description)) { dls.AddDescription(valVM.Description); dls.CurrentTable = null; // reset table after description } } else if (dto != null) { throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as list", dto, dto.GetType())); } }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoValueViewModel; this.AlternateRepresentation = other.AlternateRepresentation; this.AlternateRepresentationAlignment = other.AlternateRepresentationAlignment; this.ToolTip = other.ToolTip; this.Value = other.Value; this.ValueAlignment = other.ValueAlignment; }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoRowViewModel; //other.Parent is left behind //this.Parent == other.Parent; this.Row = other.Row; }
private Document GetListFormattedDocument(DtoBaseViewModel dto) { var result = new Document(); AppendAsList(new DocumentListState() { CurrentDocument = result }, dto); return result; }
private static DtoBaseViewModel FormatValue(object root, PropertyInfo parentProp, object dto, IViewModelDependencies dependencies, IZetboxContext dataCtx, ViewModel parent, IFileOpener fileOpener, ITempFileService tmpService) { if (dto == null) { throw new ArgumentNullException("dto"); } if (parentProp == null) { throw new ArgumentNullException("parentProp"); } DtoBaseViewModel valueModel = null; var propertyType = dto.GetType(); var title = ExtractTitle(parentProp, dto); var description = ExtractDescription(parentProp, dto); var background = ExtractBackground(parentProp, dto); var asPercent = parentProp.GetCustomAttributes(typeof(GuiFormatAsPercentAttribute), true).Length > 0; var formatString = parentProp.GetCustomAttributes(typeof(GuiFormatStringAttribute), true).OfType <GuiFormatStringAttribute>().Select(gfsa => gfsa.FormatString).SingleOrDefault(); if (typeof(long).IsAssignableFrom(propertyType) || typeof(int).IsAssignableFrom(propertyType) || typeof(short).IsAssignableFrom(propertyType)) { valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto)) { Value = asPercent ? string.Format("{0} %", 100 * Convert.ToInt64(dto)) : string.Format(formatString ?? "{0}", dto), ValueAlignment = ContentAlignment.MiddleRight, Title = title, Description = description, Formatting = ExtractFormatting(parentProp, dto), IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto), Root = root, Data = dto, }; if (!string.IsNullOrEmpty(background)) { valueModel.Background = background; } } else if (typeof(double).IsAssignableFrom(propertyType) || typeof(decimal).IsAssignableFrom(propertyType) || typeof(float).IsAssignableFrom(propertyType)) { valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto)) { Value = asPercent ? string.Format("{0:0.00} %", 100 * Convert.ToDouble(dto)) : string.Format(formatString ?? "{0:0.00}", dto), ValueAlignment = ContentAlignment.MiddleRight, Title = title, Description = description, Formatting = ExtractFormatting(parentProp, dto), IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto), Root = root, Data = dto, }; if (!string.IsNullOrEmpty(background)) { valueModel.Background = background; } } else if (typeof(string).IsAssignableFrom(propertyType)) { valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto)) { Value = (dto ?? string.Empty).ToString(), Title = title, Description = description, Formatting = ExtractFormatting(parentProp, dto), IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto), Root = root, Data = dto, }; if (!string.IsNullOrEmpty(background)) { valueModel.Background = background; } } else if (typeof(DateTime).IsAssignableFrom(propertyType)) { valueModel = new DtoValueViewModel(dependencies, dataCtx, parent, fileOpener, tmpService, string.Format("value:{0}.{1} = {2}", parentProp.DeclaringType, parentProp.Name, dto)) { Value = dto != null ? ((DateTime)dto).ToShortDateString() : string.Empty, Title = title, Description = description, Formatting = ExtractFormatting(parentProp, dto), IsPrintableRoot = ExtractIsPrintableRoot(parentProp, dto), Root = root, Data = dto, }; if (!string.IsNullOrEmpty(background)) { valueModel.Background = background; } } else { valueModel = BuildFrom(root, parentProp, dto, dependencies, dataCtx, parent, fileOpener, tmpService); } if (valueModel == null) { Logging.Client.WarnFormat("Unable to format a value from dto '{0}' of type '{1}' contained in property {2}", dto, dto.GetType().Name, string.Format("{0}.{1}", parentProp.DeclaringType.Name, parentProp.Name)); } return(valueModel); }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoGroupedViewModel; this.AlternateBackground = other.AlternateBackground; var selectedIdx = other.Items.IndexOf(other.SelectedItem); DtoBuilder.Merge(this.Items, other.Items); if (selectedIdx >= 0 && selectedIdx < this.Items.Count) { this.SelectedItem = this.Items[selectedIdx]; } else { this.SelectedItem = this.Items.FirstOrDefault(); } }
protected internal override void ApplyChangesFrom(DtoBaseViewModel otherBase) { base.ApplyChangesFrom(otherBase); var other = otherBase as DtoTableViewModel; DtoBuilder.Merge(this.Rows, other.Rows); DtoBuilder.Merge(this.Columns, other.Columns); DtoBuilder.Merge(this.Cells, other.Cells); }
private void AppendAsList(DocumentListState dls, DtoBaseViewModel dto) { var dtoTable = dto as DtoTableViewModel; if (dtoTable != null) { if (dtoTable.IsDataTable) { AppendAsTable(dls, dtoTable); } else // append contents of structural table as lists { dls.ForceOrientation(Orientation.Portrait); dls.AddHeading(dto.Title, dto.DebugInfo); dls.AddDescription(dto.Description); dls.CurrentHeadingLevel += 1; foreach (var item in dtoTable.Cells) { var baseVM = item.Value as DtoBaseViewModel; if (baseVM != null) { AppendAsList(dls, baseVM); } else if (item.Value != null) { throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as cell contents", item.Value, item.Value.GetType())); } } dls.CurrentHeadingLevel -= 1; } } else if (typeof(DtoGroupedViewModel).IsAssignableFrom(dto.GetType())) { dls.ForceOrientation(Orientation.Portrait); dls.AddHeading(dto.Title, dto.DebugInfo); dls.CurrentHeadingLevel += 1; foreach (var item in ((DtoGroupedViewModel)dto).Items) { AppendAsList(dls, item); } dls.CurrentHeadingLevel -= 1; } else if (typeof(DtoValueViewModel).IsAssignableFrom(dto.GetType())) { var valVM = dto as DtoValueViewModel; if (dls.CurrentTable == null) { dls.CurrentTable = dls.CurrentSection.AddTable(); dls.CurrentTable.AddColumn("8cm"); // title dls.CurrentTable.AddColumn("4cm"); // value dls.CurrentTable.AddColumn("4cm"); // alternate representation } var row = dls.CurrentTable.AddRow(); row.Cells[0].AddParagraph(dto.Title); if (!string.IsNullOrEmpty(valVM.Value)) row.Cells[1].AddParagraph(valVM.Value).Format.Alignment = ConvertParagraphAlignment(valVM.ValueAlignment); if (!string.IsNullOrEmpty(valVM.AlternateRepresentation)) row.Cells[2].AddParagraph(valVM.AlternateRepresentation).Format.Alignment = ConvertParagraphAlignment(valVM.AlternateRepresentationAlignment); if (!string.IsNullOrEmpty(valVM.Description)) { dls.AddDescription(valVM.Description); dls.CurrentTable = null; // reset table after description } } else if (dto != null) { throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as list", dto, dto.GetType())); } }