Ejemplo n.º 1
0
        public void DisableWheelNavigation(ReportViewer r)
        {
            bool fromToolbar = false;

            r.PageNavigation += (obj, ea) => {
                if (fromToolbar)
                {
                    fromToolbar = false;
                }
                else
                {
                    ea.Cancel = true;
                }
            };
            var buttons   = new string[] { "firstPage", "previousPage", "nextPage", "lastPage" };
            var toolstrip = r.Controls.Find("toolStrip1", true).OfType <ToolStrip>().First();

            toolstrip.Items.OfType <ToolStripButton>()
            .Where(button => buttons.Contains(button.Name)).ToList().ForEach(item => {
                var clickEvent   = item.GetType().GetEvent("Click");
                var removeMethod = clickEvent.GetRemoveMethod();
                var d            = Delegate.CreateDelegate(clickEvent.EventHandlerType,
                                                           toolstrip.Parent, "OnPageNavButtonClick");
                removeMethod.Invoke(item, new object[] { d });
                item.Click += (obj, ev) => {
                    var onPageNavigation = toolstrip.Parent.GetType()
                                           .GetMethod("OnPageNavigation",
                                                      BindingFlags.NonPublic | BindingFlags.Instance);
                    Action <int> OnPageNavigation = i => {
                        fromToolbar = true;
                        onPageNavigation.Invoke(toolstrip.Parent, new object[] { i });
                    };
                    if (item.Name == "firstPage")
                    {
                        OnPageNavigation(1);
                    }
                    else if (item.Name == "previousPage")
                    {
                        OnPageNavigation(r.CurrentPage - 1);
                    }
                    else if (item.Name == "nextPage")
                    {
                        OnPageNavigation(r.CurrentPage + 1);
                    }
                    else if (item.Name == "lastPage")
                    {
                        PageCountMode mode;
                        int totalPages = r.GetTotalPages(out mode);
                        if (mode != PageCountMode.Actual)
                        {
                            OnPageNavigation(0x7fffffff);
                        }
                        else
                        {
                            OnPageNavigation(totalPages);
                        }
                    }
                };
            });
        }
Ejemplo n.º 2
0
        private void btnPageSetup_Click(object sender, EventArgs e)
        {
            //--reportViewer1.PageSetupDialog();
            PrintDialog dlg = new PrintDialog();

            dlg.PrinterSettings = reportViewer1.PrinterSettings;
            dlg.CurrentPage     = reportViewer1.CurrentPage;
            dlg.LastPage        = reportViewer1.GetTotalPages();
            DialogResult dres = dlg.ShowDialog();

            ///
            if (dres == DialogResult.Yes || dres == DialogResult.OK) /*-- Print || Apply --*/
            {
                reportViewer1.PrinterSettings = dlg.PrinterSettings;
                reportViewer1.SetPageSettings(dlg.PrinterSettings.DefaultPageSettings);
                reportViewer1.RefreshReport();
                ///
                if (dres == DialogResult.Yes)  /*-- Print --*/
                {
                    this.PrintImmediate();
                }
            }
            else /*--Cancel*/
            {
            }
            ///
            dlg.Dispose();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ReportViewer渲染完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReportView_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)
        {
            if (e.Exception != null)
            {
                var exp = e.Exception;
                while (exp.InnerException != null)
                {
                    exp = exp.InnerException;
                }
                XMessageBox.Error(string.Format("无法打印:{0}", exp.Message));
                return;
            }

            ReportViewer rv = sender as ReportViewer;

            //rv.SetPageSettings(Config.GetPageSettings());
            #region 如果能直接打印了

            if (!PrintData.PrintTemplate.IsAppend || CanPrint != null && CanPrint.Value)
            {
                if (e.Exception == null && rv.LocalReport.DataSources.Count > 0)
                {
                    try
                    {
                        Export(rv.LocalReport);
                        printDocument1.DefaultPageSettings = Config.GetPageSettings();
                        printDocument1.PrinterSettings     = Config.GetPrintSettings();
                        printDocument1.Print();
                        StreamDispose();
                    }
                    catch (Exception exp)
                    {
                        XMessageBox.Warning(string.Format("无法打印:{0}", exp.Message));
                        //XMessageBox.Warning(string.Format("无法打印:{0}", exp.Message));
                    }
                }

                return;
            }

            #endregion

            #region 往页后面追加行
            if (PrintData.PrintTemplate.IsAppend)
            {
                var totalPages = rv.GetTotalPages();

                if (LastPageCount == null)
                {
                    LastPageCount = totalPages;
                }
                var dt = rv.LocalReport.DataSources[0].Value as DataTable;
                if (LastPageCount == totalPages)
                {
                    dt.Rows.Add(dt.NewRow());
                }
                else
                {
                    dt.Rows.RemoveAt(dt.Rows.Count - 1);
                    CanPrint = true;
                }
                rv.RefreshReport();
                return;
            }


            #endregion
        }