private DigitalInfoStrategyOutputModel PrepareStrategyOutput() { var outputModel = new DigitalInfoStrategyOutputModel(); outputModel.ShowLogos = _digitalInfo.ShowLogo; var totals = new List <string>(); if (_digitalInfo.ShowTotalInvestemt && _digitalInfo.TotalInvestment.HasValue) { totals.Add(String.Format("Total Investment: {0}", _digitalInfo.TotalInvestment.Value.ToString("$#,##0.00"))); } if (_digitalInfo.ShowMonthlyInvestemt && _digitalInfo.MonthlyInvestment.HasValue) { totals.Add(String.Format("Monthly Investment: {0}", _digitalInfo.MonthlyInvestment.Value.ToString("$#,##0.00"))); } outputModel.Total1 = totals.ElementAtOrDefault(0); outputModel.Total2 = totals.ElementAtOrDefault(1); foreach (var digitalInfoRecord in _digitalInfo.Records) { var recordOutputModel = new DigitalInfoStrategyRecordOutputModel(); recordOutputModel.Logo = digitalInfoRecord.Logo; var values = new List <string>(); if (_digitalInfo.ShowCategory && !String.IsNullOrEmpty(digitalInfoRecord.Category)) { values.Add(digitalInfoRecord.Category); } if (_digitalInfo.ShowSubCategory && !String.IsNullOrEmpty(digitalInfoRecord.SubCategory)) { values.Add(digitalInfoRecord.SubCategory); } recordOutputModel.Text1 = String.Join(" - ", values); values.Clear(); if (_digitalInfo.ShowProduct && !String.IsNullOrEmpty(digitalInfoRecord.Name)) { values.Add(digitalInfoRecord.Name); } if (_digitalInfo.ShowInfo && !String.IsNullOrEmpty(digitalInfoRecord.Info)) { values.Add(digitalInfoRecord.Info); } recordOutputModel.Text2 = String.Join(" | ", values); outputModel.Records.Add(recordOutputModel); } outputModel.GetLogos(); return(outputModel); }
public static void PrepareStrategyEmail(this PowerPointProcessor target, string fileName, DigitalInfoStrategyOutputModel dataModel, Theme selectedTheme) { target.PreparePresentation(fileName, presentation => target.AppendStrategy(dataModel, selectedTheme, presentation)); }
public static void AppendStrategy(this PowerPointProcessor target, DigitalInfoStrategyOutputModel source, Theme theme, Presentation destinationPresentation = null) { try { var thread = new Thread(delegate() { var presentationTemplatePath = source.TemplatePath; if (string.IsNullOrEmpty(presentationTemplatePath)) { return; } if (!File.Exists(presentationTemplatePath)) { return; } MessageFilter.Register(); var presentation = target.PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { var shapeTagName = shape.Tags.Name(i); switch (shapeTagName) { case "MONTHDIGINV": shape.TextFrame.TextRange.Text = source.Total2; break; case "TOTALDIGINV": shape.TextFrame.TextRange.Text = source.Total1; break; default: for (var j = 0; j < BaseDigitalInfoOneSheetOutputModel.MaxRecords; j++) { if (shapeTagName.Equals(String.Format("DIGITAL_GRAPHIC{0}", j + 1))) { var fileName = source.Logos.Length > j ? source.Logos[j] : String.Empty; if (!String.IsNullOrEmpty(fileName) && File.Exists(fileName)) { var newShape = slide.Shapes.AddPicture(fileName, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); newShape.Top = shape.Top; newShape.Left = shape.Left; newShape.Width = shape.Width; newShape.Height = shape.Height; } shape.Visible = MsoTriState.msoFalse; } if (shapeTagName.Equals(String.Format("DIGITAL_TAG{0}", j + 1))) { shape.TextFrame.TextRange.Text = source.Records.Count > j ? source.Records[j].Text1 : String.Empty; } if (shapeTagName.Equals(String.Format("DIGITAL_DETAILS{0}", j + 1))) { shape.TextFrame.TextRange.Text = source.Records.Count > j ? source.Records[j].Text2 : String.Empty; } } break; } } } } if (theme != null) { presentation.ApplyTheme(theme.GetThemePath()); } target.AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }