public RulerPanel(ReportPageDesigner pd) : base() { FPageDesigner = pd; FPage = pd.Page as ReportPage; FWorkspace = new ReportWorkspace(FPageDesigner); FWorkspace.LocationChanged += new EventHandler(Workspace_LocationChanged); FHorzRuler = new HorzRuler(pd); FHorzRuler.Height = 24; FHorzRuler.Dock = DockStyle.Top; FVertRuler = new VertRuler(pd); FVertRuler.Dock = DockStyle.Left; FVertRuler.Width = 24; btnSwitchView = new Button(); btnSwitchView.Location = new Point(4, 4); btnSwitchView.Size = new Size(16, 16); btnSwitchView.FlatStyle = FlatStyle.Flat; btnSwitchView.FlatAppearance.BorderColor = SystemColors.ButtonFace; btnSwitchView.FlatAppearance.BorderSize = 0; btnSwitchView.Cursor = Cursors.Hand; btnSwitchView.Image = Res.GetImage(81); btnSwitchView.Click += new EventHandler(btnSwitchView_Click); FHorzRuler.Controls.Add(btnSwitchView); FStructure = new BandStructure(FPageDesigner); FStructure.Dock = DockStyle.Fill; FControlContainer = new ControlContainer(FWorkspace); FControlContainer.Dock = DockStyle.Fill; Panel1.Controls.Add(FStructure); Panel2.Controls.AddRange(new Control[] { FControlContainer, FVertRuler, FHorzRuler }); Panel1MinSize = 20; FixedPanel = FixedPanel.Panel1; SplitterDistance = 120; SplitterMoved += new SplitterEventHandler(RulerPanel_SplitterMoved); AdjustOffset(); }
/// <summary> /// Window has been activated /// </summary> /// <param name="sender">sender</param> /// <param name="e">event details</param> private void Window_Activated(object sender, EventArgs e) { /*using (var workspace = new ReportWorkspace(Environment.CurrentDirectory)) * { * var reportDocument = workspace.LoadReport(@"Templates\SimpleReport.xaml"); * ReportData data = new ReportData(); * DataTable table = new DataTable("Ean"); * table.Columns.Add("Position", typeof(string)); * table.Columns.Add("Item", typeof(string)); * table.Columns.Add("EAN", typeof(string)); * table.Columns.Add("Count", typeof(int)); * Random rnd = new Random(1234); * for (int i = 1; i <= 500; i++) * { * table.Rows.Add(new object[] { i, "Item " + i.ToString("0000"), "123456790123", rnd.Next(9) + 1 }); * } * data.DataTables.Add(table); * //the flowDocument no fill table data? * var flowDocument = reportDocument.createFlowDocument(); * }*/ if (!_firstActivated) { return; } _firstActivated = false; Task.Factory.StartNew(() => { try { //Thread.CurrentThread.SetApartmentState(ApartmentState.STA); using (var workspace = new ReportWorkspace(Environment.CurrentDirectory)) { //workspace.DocumentViewer = documentViewer; var reportDocument = workspace.LoadReport(@"Templates\SimpleReport.xaml"); ReportData data = new ReportData(); // set constant document values data.ReportDocumentValues.Add("PrintDate", DateTime.Now); // print date is now // sample table "Ean" DataTable table = new DataTable("Ean"); table.Columns.Add("Position", typeof(string)); table.Columns.Add("Item", typeof(string)); table.Columns.Add("EAN", typeof(string)); table.Columns.Add("Count", typeof(int)); Random rnd = new Random(1234); for (int i = 1; i <= 1500; i++) { // randomly create some items table.Rows.Add(new object[] { i, "Item " + i.ToString("0000"), "123456790123", rnd.Next(9) + 1 }); } data.DataTables.Add(table); DateTime dateTimeStart = DateTime.Now; // start time measure here Dispatcher.Invoke(new Action(() => documentViewer.Document = reportDocument.CreateFlowDocument(data))); /*XpsDocument xps = reportDocument.CreateXpsDocument(data, (page, pagecount) => { Dispatcher.Invoke(new Action(() => busyDecorator.BusyContent = "Rendering Page " + page.ToString() + " of " + pagecount.ToString())); }); * Dispatcher.Invoke(new Action(() => documentViewer.Document = xps.GetFixedDocumentSequence())); * * // show the elapsed time in window title * Dispatcher.Invoke(new Action(() => Title += " - generated in " + (DateTime.Now - dateTimeStart).TotalMilliseconds + "ms"));*/ } } catch (Exception ex) { // show exception MessageBox.Show(ex.Message + "\r\n\r\n" + ex.GetType() + "\r\n" + ex.StackTrace, ex.GetType().ToString(), MessageBoxButton.OK, MessageBoxImage.Stop); } finally { Dispatcher.Invoke(new Action(() => busyDecorator.IsBusy = false)); } }); }