public ReportContext(Report r) { report = r; ParameterFieldsDict = r.Parameters.ToDictionary(p=>p.Name); DataFieldsDict = r.DataFields.ToDictionary(df=>df.Name); ExpressionFieldsDict = r.ExpressionFields.ToDictionary(ef=>ef.Name); }
public void ProcessSectionUpToHeightTreshold_BeforeDeailsProcess_HeightLeftIsReportHeightMinusHeadersAndFooters() { Report r = new Report(); double heightBeforeDetails = 0; r.ReportHeaderSection.Height = 50; r.PageHeaderSection.Height = 10; r.PageFooterSection.Height = 25; r.DetailSection.Height = 15; r.DetailSection.OnBeforeControlProcessing += delegate(ReportContext rc, Control c) { //before first detail processing if( heightBeforeDetails == 0 ) { heightBeforeDetails = rc.HeightLeftOnCurrentPage; } }; RendererMock m = new RendererMock(); ReportEngine re = new ReportEngine(r,m); re.Process(); double pageHeaderAndPageFooterHeight = r.Height - ( r.ReportHeaderSection.Height + r.PageHeaderSection.Height + r.PageFooterSection.Height); Assert.AreEqual(pageHeaderAndPageFooterHeight,heightBeforeDetails); }
public void ProcessSectionUpToHeightTreshold_WithNoDatasource_HasAtLeastOnePage() { Report r = new Report(); RendererMock m = new RendererMock(); ReportEngine re = new ReportEngine(r,m); re.Process(); Assert.IsNotEmpty(r.Pages); }
public DesignService(IWorkspaceService workspaceService, CompilerService compilerService,Report report) { this.WorkspaceService = workspaceService; this.compilerService = compilerService; controlViewFactory = new ControlViewFactory (this); PixbufRepository = new PixbufRepository (){ Report = report}; IsDesign = true; Zoom = 1; Render = true; Report = report; }
public static void Main(string[] args) { Report r = new Report(); string json = null; using(StreamReader fs = new StreamReader("data.json")){ json = fs.ReadToEnd(); } string pdf = "example.pdf"; r.Load("example.mrp"); r.ExportToPdf(pdf, new Dictionary<string,object>(){ {"json" , json} }); }
public DesignService(IWorkspaceService workspaceService,ReportRenderer renderer,PixbufRepository pixbufRepository,CompilerService compilerService, Report report) { this.PixbufRepository = pixbufRepository; this.WorkspaceService = workspaceService; this.Compiler = compilerService; this.renderer = renderer; controlViewFactory = new ControlViewFactory (renderer); IsDesign = true; Report = report; Zoom = 1; Render = true; IsDirty = true; }
public SectionView(Report parentReport,IControlViewFactory controlViewFactory,Section section,Cairo.PointD sectionSpan) : base(section) { DesignCrossSectionControlsToAdd = new List<ControlViewBase> (); DesignCrossSectionControlsToRemove = new List<ControlViewBase> (); this.controlViewFactory = controlViewFactory; this.parentReport = parentReport; if (section is DetailSection) AllowCrossSectionControl = false; else { AllowCrossSectionControl = true; } SectionSpan = sectionSpan; controls = new System.Collections.Generic.List<ControlViewBase> (); AddControls (this.section.Controls); SectionGripperColor = sectionHeaderColor1; InvalidateBound (); }
public static void Main(string[] args) { Report r = new Report (); //---------------------- // report header section //---------------------- var invTextTb = new TextBlock (){ Text = "Invoice", Width = r.Width, FontWeight = FontWeight.Bold, Height = 20, FontSize = 18, HorizontalAlignment = HorizontalAlignment.Center, }; r.ReportHeaderSection.Controls.Add (invTextTb); var invNumberTb = new TextBlock (){ FieldName ="invoice.Number", FieldKind = FieldKind.Parameter, Text = "Invoice", Width = r.Width, Height = 20, FontSize = 18, Top = 20, HorizontalAlignment = HorizontalAlignment.Center, FontColor = new Color (1,1,1) }; r.ReportHeaderSection.Height = 50; r.ReportHeaderSection.Controls.Add (invNumberTb); r.ReportHeaderSection.BackgroundColor = new Color (0.8,0.8,0.8); //------------------- //page header section //------------------- var phLine = new Line (){ Location = new Point(0,10), End = new Point(r.Width,10), ExtendToBottom = true, LineWidth = 1}; r.PageHeaderSection.Height = 16; r.PageHeaderSection.Controls.Add (phLine); //index label var indhTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Ind", Width = 40, Height = 14}; r.PageHeaderSection.Controls.Add (indhTb); // description label var deschTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Description", Left = 42, Height = 14}; r.PageHeaderSection.Controls.Add (deschTb); // quantity label var qnthTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Quantity", Left = 170, Height = 14}; r.PageHeaderSection.Controls.Add (qnthTb); // price field var prthTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Price", Left = 230,Width = 60, Height = 14}; r.PageHeaderSection.Controls.Add (prthTb); //--------------- //details section //--------------- //do not allow break detail section across page r.DetailSection.KeepTogether = true; r.DetailSection.Height = 16; //index field var indTb = new TextBlock () { FieldName = "Index", FieldKind = FieldKind.Data, Text = "00", Left = 1.2, Width = 40, Height = 14}; r.DetailSection.Controls.Add (indTb); // description field var descTb = new TextBlock () { FieldName = "Description",FieldKind = FieldKind.Data, Text = "Desc", Left = 42, Width =128, Height = 14}; r.DetailSection.Controls.Add (descTb); // quantity field var qntTb = new TextBlock () { FieldName = "Quantity",FieldKind = FieldKind.Data, Text = "0", Left = 170, Width = 20, Height = 14}; r.DetailSection.Controls.Add (qntTb); // price field var prtTb = new TextBlock () { FieldName = "PricePerUnitGross", FieldTextFormat = "{0:C}", FieldKind = FieldKind.Data, Text = "0", Left = 230,Width = 60, Height = 14}; r.DetailSection.Controls.Add (prtTb); var line = new Line (){ Location = new Point(0,10), End = new Point(r.Width,10), ExtendToBottom = true, LineWidth = 1}; r.DetailSection.Controls.Add (line); //just before processing we can change section properties r.DetailSection.OnBeforeControlProcessing += delegate(ReportContext rc, Control c) { if(rc.RowIndex % 2 == 0) c.BackgroundColor = new Color(0.91,0.91,0.91); else ( (TextBlock) (c as Section).Controls[1]).FontColor = new Color(1,0.7,0.2); }; var lv0 = new Line (){ Location = new Point(0.5,0), End = new Point(0.5,10), ExtendToBottom = true, LineWidth = 1}; r.DetailSection.Controls.Add (lv0); var lineV = new Line (){ Location = new Point(291,0), End = new Point(291,10), LineType = LineType.Dash, ExtendToBottom = true, LineWidth = 1}; r.DetailSection.Controls.Add (lineV); //--------------- //Report footer //--------------- // price field var prtTotalLabelTb = new TextBlock () { FontWeight = FontWeight.Bold, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 22, FieldKind = FieldKind.Parameter, Text = "Total: ", Left = 130, Width = 100 }; r.ReportFooterSection.Controls.Add (prtTotalLabelTb); var prtTotalTb = new TextBlock () { FontWeight = FontWeight.Bold, FieldName = "invoice.TotalGross", FieldTextFormat = "{0:C}", FontSize = 22, FieldKind = FieldKind.Parameter, Text = "0", Left = 230, Width = 150, Height = 14}; r.ReportFooterSection.Controls.Add (prtTotalTb); //--------------- //Page footer //--------------- var fl = new Line (){ Location = new Point(0,1), End = new Point(r.Width,1), LineWidth = 1}; r.PageFooterSection.Controls.Add (fl); var pnTb = new TextBlock () { FieldName = "#PageNumber", FieldTextFormat = "{0:C}", FieldKind = FieldKind.Expression, Text = "0", Left = r.Width-30, Width = 30, HorizontalAlignment = HorizontalAlignment.Right, Top = 2, Height = 14}; r.PageFooterSection.Controls.Add (pnTb); #region example invoice datasource //example invoice class... Invoice invoice = new Invoice () { Number = "01/12/2010", CreationDate = DateTime.Now, Positions = new List<InvoicePosition>() }; for (int i = 0; i < 82; i++) { invoice.Positions.Add ( new InvoicePosition () { Index = i+1, Quantity = 1, Description = "Reporting services " + (i + 1).ToString(), PricePerUnitGross = ((i * 50) / (i + 1)) + 1 } ); } invoice.Positions[11].Description = "here comes longer position text to see if position will extend section height"; //Total gross ... invoice.TotalGross = invoice.Positions.Sum (p => p.PricePerUnitGross * p.Quantity); #endregion r.DataSource = invoice.Positions; r.ExportToPdf ("invoice.pdf", new Dictionary<string,object>{ {"invoice",invoice}}); }
public void CopyToReport(Report r) { r.Title = Title; r.ResourceRepository = ResourceRepository; r.PageHeaderSection = PageHeaderSection; r.PageFooterSection = PageFooterSection; r.ReportHeaderSection = ReportHeaderSection; r.ReportFooterSection = ReportFooterSection; r.DataScript = DataScript; r.DetailSection = DetailSection; r.GroupHeaderSections = GroupHeaderSections; r.GroupFooterSections = GroupFooterSections; r.Height = Height; r.Width = Width; r.Margin = Margin; r.Parameters.AddRange(Parameters); r.DataFields.AddRange(DataFields); r.Totals.AddRange(Totals); r.References.AddRange(References); r.Usings.AddRange(Usings); r.AlternativeReferencedAssembliesPath = AlternativeReferencedAssembliesPath; r.DataSourceType = DataSourceType; foreach (var ef in ExpressionFields) { if(!ef.Name.StartsWith("#")) r.ExpressionFields.Add (ef); } }
public void Load(string path) { Report r = new Report(); r.Load(path); Report = r; }
public void FillFieldsFromDataSource_WithNullDataSource_ShouldThrowException() { Report r = new Report(); r.FillFieldsFromDataSource(); }
public void CopyToReport(Report r) { r.Title = Title; r.ResourceRepository = ResourceRepository; r.PageHeaderSection = PageHeaderSection; r.PageFooterSection = PageFooterSection; r.ReportHeaderSection = ReportHeaderSection; r.ReportFooterSection = ReportFooterSection; r.DataScript = DataScript; r.DetailSection = DetailSection; r.GroupHeaderSections = GroupHeaderSections; r.GroupFooterSections = GroupFooterSections; r.Height = Height; r.Width = Width; r.Margin = Margin; r.Unit = Unit; }
Report newReportTemplate() { Report r = new Report(){ DataScript = @" //datasource have to be IEnumerable<T>. T can be anything - below T is string string[] strings = new string[] { ""my"", ""name"", ""is""}; //creating IDataSource ObjectDataSource<T>. T = is the same T as in the above line. //datasource's name has to be ""ds"" and it has to implement Monoreports.Model.Data.IDataSource ObjectDataSource<string> ds = new ObjectDataSource<string>(strings); //adding Field (""Column"") to datasource. Second param says how to get field's value assuming x is T ds.AddField(""Name"" , x => x); //adding paramaters. parameters type is IDictionary<string,object> parameters.Add(""Price"",242342.545); "}; r.Parameters.Add(new MonoReports.Model.Data.Field(){ FieldKind = MonoReports.Model.Data.FieldKind.Parameter, Name = "Price"}); r.DataFields.Add(new MonoReports.Model.Data.Field(){ FieldType = typeof(string), FieldKind = MonoReports.Model.Data.FieldKind.Data, Name = "Name"}); return r; }
public static void Main(string[] args) { Report r = new Report (); //---------------------- // report header section //---------------------- var invTextTb = new TextBlock (){ Text = "Invoice", Width = r.Width, FontWeight = FontWeight.Bold, FontSize = 14, HorizontalAlignment = HorizontalAlignment.Center, }; r.ReportHeaderSection.Controls.Add (invTextTb); var invNumberTb = new TextBlock (){ FieldName ="invoice.Number", FieldKind = FieldKind.Parameter, Text = "Invoice", Width = r.Width, FontSize = 14, Top = 5.mm(), HorizontalAlignment = HorizontalAlignment.Center, FontColor = Color.White }; r.ReportHeaderSection.Height = 30.mm (); r.ReportHeaderSection.Controls.Add (invNumberTb); r.ReportHeaderSection.BackgroundColor = Color.Silver; //------------------- //page header section //------------------- var phLine = new Line (){ Location = new Point(0,10.mm()), End = new Point(r.Width,10.mm()), ExtendToBottom = true}; r.PageHeaderSection.Controls.Add (phLine); //index label var indhTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Ind", Width = 10.mm()}; r.PageHeaderSection.Controls.Add (indhTb); // description label var deschTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Description", Left = 12.mm(), Width = 20.mm()}; r.PageHeaderSection.Controls.Add (deschTb); // quantity label var qnthTb = new TextBlock () {FontWeight = FontWeight.Bold, Text = "Quantity", Left = 42.mm()}; r.PageHeaderSection.Controls.Add (qnthTb); // price field var prthTb = new TextBlock () {FontWeight = FontWeight.Bold,Text = "Price", Left = 60.mm(),Width = 30.mm()}; r.PageHeaderSection.Controls.Add (prthTb); //--------------- //details section //--------------- //do not allow break detail section across page r.DetailSection.KeepTogether = true; r.DetailSection.Height = 6.mm (); //index field var indTb = new TextBlock () { FieldName = "Index", FieldKind = FieldKind.Data, Text = "00", Left = 1.2.mm(), Width = 10.mm()}; r.DetailSection.Controls.Add (indTb); // description field var descTb = new TextBlock () { FieldName = "Description", FieldKind = FieldKind.Data, Text = "Desc", Left = 12.mm(), Width = 35.mm()}; r.DetailSection.Controls.Add (descTb); // quantity field var qntTb = new TextBlock () { FieldName = "Quantity", FieldKind = FieldKind.Data, Text = "0", Left = 47.mm(), Width = 5.mm(), }; r.DetailSection.Controls.Add (qntTb); // price field var prtTb = new TextBlock () { FieldName = "PricePerUnitGross", FieldTextFormat = "{0:C}", FieldKind = FieldKind.Data, Text = "0", Left = 62.mm(),Width = 20.mm()}; r.DetailSection.Controls.Add (prtTb); var line = new Line (){ Location = new Point(0,2.mm()), End = new Point(r.Width,2.mm()), ExtendToBottom = true}; r.DetailSection.Controls.Add (line); //just before processing we can change section properties r.DetailSection.OnBeforeControlProcessing += delegate(ReportContext rc, Control c) { if (rc.RowIndex % 2 == 0) { c.BackgroundColor = Color.LightGray; } else { ((TextBlock)(c as Section).Controls [1]).FontColor = Color.PaleVioletRed; } }; var lv0 = new Line (){ Location = new Point(1,0), End = new Point(1,2.mm()), ExtendToBottom = true}; r.DetailSection.Controls.Add (lv0); var lineV = new Line (){ Location = new Point(r.Width,2.mm()), End = new Point(r.Width,2.mm()), LineType = LineType.Dash, ExtendToBottom = true}; r.DetailSection.Controls.Add (lineV); //--------------- //Report footer //--------------- // price field var prtTotalLabelTb = new TextBlock () { FontWeight = FontWeight.Bold, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 12, FieldKind = FieldKind.Parameter, Text = "Total: ", Left = 50.mm(), Width = 10.mm() }; r.ReportFooterSection.Controls.Add (prtTotalLabelTb); var prtTotalTb = new TextBlock () { FontWeight = FontWeight.Bold, FieldName = "invoice.TotalGross", FieldTextFormat = "{0:C}", FontSize = 12, FieldKind = FieldKind.Parameter, Text = "0", Left = 62.mm(), Width = 40.mm() }; r.ReportFooterSection.Controls.Add (prtTotalTb); //--------------- //Page footer //--------------- var fl = new Line (){ Location = new Point(0,1), End = new Point(r.Width,1)}; r.PageFooterSection.Controls.Add (fl); var pnTb = new TextBlock () { FieldName = "#PageNumber", FieldTextFormat = "{0:C}", FieldKind = FieldKind.Expression, Text = "0", Left = (r.Width-30).mm(), Width = 10.mm(), HorizontalAlignment = HorizontalAlignment.Right, Top = 2.mm()}; r.PageFooterSection.Controls.Add (pnTb); r.PageFooterSection.BackgroundColor = Color.LightBlue; #region example invoice datasource //example invoice class... Invoice invoice = new Invoice () { Number = "01/12/2010", CreationDate = DateTime.Now, Positions = new List<InvoicePosition>() }; for (int i = 0; i < 82; i++) { invoice.Positions.Add ( new InvoicePosition () { Index = i+1, Quantity = 1, Description = "Reporting services " + (i + 1).ToString(), PricePerUnitGross = ((i * 50) / (i + 1)) + 1 } ); } invoice.Positions [4].Description = "here comes longer position text to see if position will extend section height"; invoice.Positions [11].Description = "another longer position text to see if position will extend section height"; //Total gross ... invoice.TotalGross = invoice.Positions.Sum (p => p.PricePerUnitGross * p.Quantity); #endregion ObjectDataSource<InvoicePosition> objectDataSource = new ObjectDataSource<InvoicePosition>(invoice.Positions); objectDataSource.AddField ("Index",x=>x.Index); objectDataSource.AddField ("Description",x=>x.Description); objectDataSource.AddField ("Quantity",x=>x.Quantity); objectDataSource.AddField ("PricePerUnitGross",x=>x.PricePerUnitGross); r.DataSource = objectDataSource; //we can get cairo context before and after rendering each page //to draw custom shapes, texts (e.g watermarks etc) //here modified example from http://www.mono-project.com/Mono.Cairo r.OnAfterPageRender += delegate(ReportContext rc, Page p) { if (rc.CurrentPageIndex % 2 > 0) { Cairo.Context gr = rc.RendererContext as Cairo.Context; gr.MoveTo (50.mm (), 100.mm ()); gr.CurveTo (50.mm (), 50.mm (), 50.mm (), 50.mm (), 100.mm (), 50.mm ()); gr.CurveTo (100.mm (), 100.mm (), 100.mm (), 100.mm (), 50.mm (), 100.mm ()); gr.ClosePath (); // Save the state to restore it later. That will NOT save the path gr.Save (); Cairo.Gradient pat = new Cairo.LinearGradient (50.mm (),100.mm (), 100.mm (),50.mm ()); pat.AddColorStop (0, new Cairo.Color (0,0,0,0.3)); pat.AddColorStop (1, new Cairo.Color (1,0,0,0.2)); gr.Pattern = pat; // Fill the path with pattern gr.FillPreserve (); // We "undo" the pattern setting here gr.Restore (); // Color for the stroke gr.Color = new Cairo.Color (0,0,0); gr.LineWidth = 1.px (); gr.Stroke (); } }; var parameters = new Dictionary<string,object>{ {"invoice.Number",invoice.Number}, {"invoice.CreationDate",invoice.CreationDate}, {"invoice.TotalGross",invoice.TotalGross}, }; r.ExportToPdf ("invoice.pdf", parameters); r.Save ("report.mrp"); }
public MonoreportsDesignerControl() { Build (); dpi = Gdk.Screen.Default.Resolution; Report startReport = new Report(){ DataScript = @" datasource = new [] { new { Name=""Alfred"", Surname = ""Tarski"", Age = ""82"" }, new { Name=""Saul"", Surname = ""Kripke"", Age = ""70"" }, new { Name=""Gotlob"", Surname = ""Frege"", Age = ""85"" }, new { Name=""Kurt"", Surname = ""Gödel"", Age = ""72"" }, }; parameters.Add(""Title"",new { Title = ""The Logicans"", SubTitle = ""...and philosophers...""}); "}; string template = @" using System; using System.Collections.Generic; {0} public sealed class GenerateDataSource {{ public object Generate() {{ object datasource = null; Dictionary<string,object> parameters = new Dictionary<string,object>(); {1} return new object[] {{datasource,parameters}}; }} }} "; compilerService = new CompilerService(template); workspaceService = new WorkspaceService (this,maindesignview1.DesignDrawingArea,maindesignview1.PreviewDrawingArea,mainPropertygrid, StatusBarLabel); designService = new DesignService (workspaceService,compilerService,startReport); toolBoxService = new ToolBoxService (); designService.ToolBoxService = toolBoxService; maindesignview1.DesignService = designService; maindesignview1.WorkSpaceService = workspaceService; maindesignview1.Compiler = compilerService; var reportRenderer = new ReportRenderer(); reportRenderer.RegisterRenderer(typeof(Controls.TextBlock), new TextBlockRenderer(){ DPI = dpi}); reportRenderer.RegisterRenderer(typeof(Controls.Line), new LineRenderer(){ DPI = dpi}); reportRenderer.RegisterRenderer(typeof(MonoReports.Model.Controls.Image), new ImageRenderer(){ PixbufRepository = designService.PixbufRepository, DPI = dpi}); SectionRenderer sr = new SectionRenderer() { DPI = dpi}; reportRenderer.RegisterRenderer(typeof(Controls.ReportHeaderSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.ReportFooterSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.DetailSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.PageHeaderSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.PageFooterSection), sr); maindesignview1.ReportRenderer = reportRenderer; workspaceService.InvalidateDesignArea (); reportExplorer.DesignService = designService; reportExplorer.Workspace = workspaceService; toolBoxService.AddTool (new ZoomTool (designService)); toolBoxService.AddTool (new LineTool (designService)); toolBoxService.AddTool (new LineToolV (designService)); toolBoxService.AddTool (new LineToolH (designService)); toolBoxService.AddTool (new TextBlockTool (designService)); toolBoxService.AddTool (new SubreportTool (designService)); toolBoxService.AddTool (new SectionTool (designService)); toolBoxService.AddTool (new ImageTool (designService)); toolBoxService.AddTool (new RectTool (designService)); toolBoxService.BuildToolBar (mainToolbar); ToolBarButton exportPdfToolButton = new ToolBarButton ("pdf.png","exportPdf","export to pdf"); exportPdfToolButton.Clicked += delegate(object sender, EventArgs e) { designService.ExportToPdf(); }; mainToolbar.Insert (exportPdfToolButton,7); mainPropertygrid.LoadMonoreportsExtensions(); }
static void updateReportWithParamaters(Report report ) { foreach (KeyValuePair<string, object> kvp in report.ParameterValues) { var f1 = Field.CreateParameterField(kvp.Key,kvp.Value); var param = report.Parameters.FirstOrDefault(pr => pr.Name == kvp.Key); if(param != null){ param.DataProvider = f1.DataProvider; param.FieldType = f1.FieldType; }else { report.Parameters.Add(f1); } } }