/// <summary> /// Add Date time model /// </summary> /// <param name="context"></param> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static ContextModel AddBase64Content(this ContextModel context, string key, string value) { var element = new Base64ContentModel(value); context.AddItem(key, element); return(context); }
/// <summary> /// Add Date time model /// </summary> /// <param name="context"></param> /// <param name="key"></param> /// <param name="value"></param> /// <param name="renderPattern"></param> /// <returns></returns> public static ContextModel AddDateTime(this ContextModel context, string key, DateTime value, string renderPattern) { var element = new DateTimeModel(value, renderPattern); context.AddItem(key, element); return(context); }
/// <summary> /// Add double model /// </summary> /// <param name="context"></param> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static ContextModel AddBoolean(this ContextModel context, string key, bool value) { var element = new BooleanModel(value); context.AddItem(key, element); return(context); }
/// <summary> /// Add a list of elements as a DataSource /// </summary> /// <param name="context"></param> /// <param name="key"></param> /// <param name="elements"></param> /// <returns></returns> public static ContextModel AddCollection(this ContextModel context, string key, params ContextModel[] elements) { var element = new DataSourceModel() { Items = elements.ToList() }; context.AddItem(key, element); return(context); }
/// <summary> /// Add automatic keys for the foreach item /// </summary> /// <param name="item"></param> /// <param name="forEach"></param> /// <param name="i"></param> /// <param name="datasource"></param> private static void AddAutoContextAddItemsPrefix(this ContextModel item, ForEach forEach, int i, DataSourceModel datasource) { if (forEach == null) { return; } if (!string.IsNullOrWhiteSpace(forEach.AutoContextAddItemsPrefix)) { // We add automatic keys : // Is first item item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IsFirstItem#", new BooleanModel(i == 0)); item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IsNotFirstItem#", new BooleanModel(i > 0)); // Is last item item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IsLastItem#", new BooleanModel(i == datasource.Items.Count - 1)); // Index of the element (Based on 0, and based on 1) item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IndexBaseZero#", new StringModel(i.ToString())); item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IndexBaseOne#", new StringModel((i + 1).ToString())); item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IsOdd#", new BooleanModel(i % 2 == 1)); item.AddItem("#" + forEach.AutoContextAddItemsPrefix + "_ForEach_IsEven#", new BooleanModel(i % 2 == 0)); } }
/// <summary> /// Generate the context for the generated template /// </summary> /// <returns></returns> private static ContextModel GetContext() { // Classic generation ContextModel row2 = new ContextModel(); row2.AddItem("#Cell1#", new StringModel("Col 2 Row 1")); row2.AddItem("#Cell2#", new StringModel("Col 2 Row 2")); row2.AddItem("#Label#", new StringModel("Label 2")); ContextModel row3 = new ContextModel(); row3.AddItem("#Cell1#", new StringModel("Col 1 Row 3")); row3.AddItem("#Cell2#", new StringModel("Col 2 Row 3")); row3.AddItem("#Label#", new StringModel("Label 1")); ContextModel row4 = new ContextModel(); row4.AddItem("#Cell1#", new StringModel("Col 2 Row 4")); row4.AddItem("#Cell2#", new StringModel("Col 2 Row 4")); row4.AddItem("#Label#", new StringModel("Label 2")); // Fluent samples ContextModel row1 = new ContextModel() .AddString("#Cell1#", "Col 1 Row 1") .AddString("#Cell2#", "Col 2 Row 1") .AddString("#Label#", "Label 1"); ContextModel context = new ContextModel() .AddBoolean("#NoRow#", false) .AddString("#ParagraphShading#", "00FF00") .AddString("#ParagraphBorderColor#", "105296") .AddString("#BorderColor#", "00FF00") .AddString("#KeyTest1#", "Key 1") .AddString("#KeyTest2#", "Key 2") .AddBoolean("#BoldKey#", true) .AddString("#FontColorTestRed#", "993333") .AddString("#ParagraphStyleIdTestYellow#", "Yellow") .AddCollection("#Datasource#", row1, row2) .AddCollection("#DatasourcePrefix#", row1, row2, row3, row4); ContextModel row11 = new ContextModel(); row11.AddItem("#IsInGroup#", new BooleanModel(true)); row11.AddItem("#IsNotFirstLineGroup#", new BooleanModel(false)); row11.AddItem("#Cell1#", new StringModel("Col 1 Row 1")); row11.AddItem("#Cell2#", new StringModel("Col 2 Row 1")); row11.AddItem("#Label#", new StringModel("Label 1")); ContextModel row12 = new ContextModel(); row12.AddItem("#IsInGroup#", new BooleanModel(true)); row12.AddItem("#IsNotFirstLineGroup#", new BooleanModel(true)); row12.AddItem("#Cell1#", new StringModel("Col 1 Row 1")); row12.AddItem("#Cell2#", new StringModel("Col 2 Row 1")); row12.AddItem("#Label#", new StringModel("Label 1")); ContextModel row13 = new ContextModel(); row13.AddItem("#IsInGroup#", new BooleanModel(true)); row13.AddItem("#IsNotFirstLineGroup#", new BooleanModel(true)); row13.AddItem("#Cell1#", new StringModel("Col 1 Row 1")); row13.AddItem("#Cell2#", new StringModel("Col 2 Row 1")); row13.AddItem("#Label#", new StringModel("Label 1")); ContextModel row22 = new ContextModel(); row22.AddItem("#IsInGroup#", new BooleanModel(true)); row22.AddItem("#IsNotFirstLineGroup#", new BooleanModel(false)); row22.AddItem("#Cell1#", new StringModel("Col 2 Row 1")); row22.AddItem("#Cell2#", new StringModel("Col 2 Row 2")); row22.AddItem("#Label#", new StringModel("Label 2")); ContextModel row23 = new ContextModel(); row23.AddItem("#IsInGroup#", new BooleanModel(true)); row23.AddItem("#IsNotFirstLineGroup#", new BooleanModel(true)); row23.AddItem("#Cell1#", new StringModel("Col 2 Row 1")); row23.AddItem("#Cell2#", new StringModel("Col 2 Row 2")); row23.AddItem("#Label#", new StringModel("Label 2")); context.AddItem("#DatasourceTableFusion#", new DataSourceModel() { Items = new List <ContextModel>() { row11, row12, row13, row22, row23 } }); List <ContextModel> cellsContext = new List <ContextModel>(); for (int i = 0; i < DateTime.Now.Day; i++) { ContextModel uniformGridContext = new ContextModel(); uniformGridContext.AddItem("#CellUniformGridTitle#", new StringModel("Item number " + (i + 1))); cellsContext.Add(uniformGridContext); } context.AddItem("#UniformGridSample#", new DataSourceModel() { Items = cellsContext }); context.AddItem("#GrahSampleData#", new BarChartModel() { BarChartContent = new OpenXMLSDK.Engine.ReportEngine.DataContext.Charts.BarModel() { Categories = new List <BarCategoryModel>() { new BarCategoryModel() { Name = "Category 1" }, new BarCategoryModel() { Name = "Category 2" }, new BarCategoryModel() { Name = "Category 3" }, new BarCategoryModel() { Name = "Category 4" }, new BarCategoryModel() { Name = "Category 5" }, new BarCategoryModel() { Name = "Category 6" } }, Series = new List <BarSerieModel>() { new BarSerieModel() { Values = new List <double?>() { 0, 1, 2, 3, 6, null }, Name = "Bar serie 1" }, new BarSerieModel() { Values = new List <double?>() { 5, null, 7, 8, 0, 10 }, Name = "Bar serie 2" }, new BarSerieModel() { Values = new List <double?>() { 9, 10, 11, 12, 13, 14 }, Name = "Bar serie 3" }, new BarSerieModel() { Values = new List <double?>() { 9, 10, 11, 12, 15, 25 }, Name = "Bar serie 4" } } } }); return(context); }