//重绘单元格
        private void InvalidateCell(I3ReportCell cell)
        {
            if (cell == null)
            {
                this.Invalidate();
                return;
            }

            I3PrintArea area = null;

            foreach (I3PrintArea tmpArea in reportDatas.PrintAreas.Dic.Values)
            {
                if (new List <int>(tmpArea.AllRows).IndexOf(cell.Row) >= 0 && new List <int>(tmpArea.AllCols).IndexOf(cell.Col) >= 0)
                {
                    area = tmpArea;
                    break;
                }
            }
            if (area == null)
            {
                this.Invalidate();
                return;
            }

            RectangleF contentRect = GetAreaContentRect(area);
            RectangleF rectF       = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, contentRect, null);
            Rectangle  drawRect    = new Rectangle((int)Math.Ceiling(rectF.X), (int)Math.Ceiling(rectF.Y), (int)Math.Ceiling(rectF.Width), (int)Math.Ceiling(rectF.Height));

            this.Invalidate(drawRect, false);
        }
 /// <summary>
 /// 打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsbPrint_Click(object sender, EventArgs e)
 {
     try
     {
         int start = (int)startPage.Value;
         start = start < 1 ? 1 : start;
         start = start > reportDatas.PrintAreas.Dic.Count ? reportDatas.PrintAreas.Dic.Count : start;
         int end = (int)endPage.Value;
         end = end < 1 ? 1 : end;
         end = end > reportDatas.PrintAreas.Dic.Count ? reportDatas.PrintAreas.Dic.Count : end;
         end = end < start ? start : end;
         int count = (int)printCount.Value;
         I3ReportPrintController.PrintToPrinter(cbbPrinter.Text, documentName, reportDatas, start, end, count, rpc.PaintPageIndex2);
     }
     catch (Exception ex)
     {
         I3MessageHelper.ShowError("打印失败,原因:\r\n" + ex.Message);
     }
 }
        /// <summary>
        /// 测试单元格
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private I3ReportCell TestCell(int pageIndex, int x, int y)
        {
            if (reportDatas == null || CellItemEventMode == ReportPrint.I3CellItemEventMode.None)
            {
                return(null);
            }

            I3ReportData reportData = reportDatas.GetReportDataByAreaIndex(pageIndex);
            int          row        = TestRow(pageIndex, x, y);
            int          col        = TestCol(pageIndex, x, y);

            if (row < 0 || col < 0)
            {
                return(null);
            }

            I3ReportCell cell = reportData[row][col];

            cell = cell.MergState == I3MergeState.Merged ? reportData.GetMergedStartedCell(row, col) : cell;
            switch (CellItemEventMode)
            {
            case I3CellItemEventMode.CellRect:
                return(cell);

            case I3CellItemEventMode.ContentRect:
                I3PrintArea     area        = reportDatas.PrintAreas.Dic[pageIndex];
                RectangleF      fullRect    = GetAreaPaperRect(area);
                RectangleF      dataRect    = GetAreaContentRect(area);
                RectangleF      rect        = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, dataRect, null);
                II3CellRenderer renderer    = I3CellRendererBuilder.GetRenderer(cell);
                RectangleF      contentRect = renderer.DrawContent(this.CreateGraphics(), Scale, reportData, cell, rect, reportData.GetCellStyle(cell.StyleName), area, false);
                RectangleF      testRect    = new RectangleF(x, y, 1, 1);
                return(contentRect.IntersectsWith(testRect) ? cell : null);

            default:
                return(null);
            }
        }
        /// <summary>
        /// 测试列
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int TestCol(int pageIndex, int x, int y)
        {
            if (reportDatas == null || pageIndex < 0)
            {
                return(-1);
            }

            I3PrintArea area     = reportDatas.PrintAreas.Dic[pageIndex];
            RectangleF  fullRect = GetAreaPaperRect(area);
            RectangleF  dataRect = GetAreaContentRect(area);

            foreach (int col in area.AllCols)
            {
                int          firstRow = area.AllRows[0];
                I3ReportCell cell     = area.ReportData[firstRow][col];
                RectangleF   rect     = I3ReportPrintController.CalCellClipRect_Scale(reportDatas, cell, area, Scale, dataRect, fullRect);
                if (x >= rect.Left && x <= rect.Right)
                {
                    return(col);
                }
            }

            return(-1);
        }
        /// <summary>
        /// 测试行
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private int TestRow(int pageIndex, int x, int y)
        {
            if (reportDatas == null || pageIndex < 0)
            {
                return(-1);
            }

            I3PrintArea area     = reportDatas.PrintAreas.Dic[pageIndex];
            RectangleF  fullRect = GetAreaPaperRect(area);
            RectangleF  dataRect = GetAreaContentRect(area);

            foreach (int row in area.AllRows)
            {
                int          firstCol = area.AllCols[0];
                I3ReportCell cell     = area.ReportData[row][firstCol];
                RectangleF   rect     = I3ReportPrintController.CalCellClipRect_Scale(reportDatas, cell, area, Scale, dataRect, fullRect);
                if (y >= rect.Top && y <= rect.Bottom)
                {
                    return(row);
                }
            }

            return(-1);
        }
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (Brush brush = new SolidBrush(this.BackColor))
            {
                e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this.Width, this.Height));
            }
            if (this.DesignMode || reportDatas == null)
            {
                return;
            }
            RectangleF oldClip = e.Graphics.ClipBounds;

            RectangleF clientRect      = new RectangleF(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight);
            bool       firstPageShowed = false;

            for (int index = 0; index < reportDatas.PrintAreas.Dic.Count; index++)
            {
                #region 纸张区域
                I3PrintArea area      = reportDatas.PrintAreas.Dic[index];
                RectangleF  paperRect = GetAreaPaperRect(area);
                if (!paperRect.IntersectsWith(oldClip) || !paperRect.IntersectsWith(clientRect))
                {
                    continue;
                }
                if (!firstPageShowed)
                {
                    firstPageShowed = true;
                    CurPageIndex    = index;
                }
                #endregion

                #region 内容区域
                RectangleF contentRect = GetAreaContentRect(area);
                //内容区域不用作剪切区域判断,(非内容区域也需要绘制)
                #endregion

                #region 绘制
                I3ReportPrintController.PrintAreaToGraphics(e.Graphics, Scale, paperRect, contentRect, reportDatas, area, PaintPageIndex2, index);
                e.Graphics.SetClip(oldClip);
                #endregion

                #region 缩略图页码
                if (PaintPageIndex)
                {
                    string text = string.Format("{0}/{1}", index + 1, reportDatas.PrintAreas.Dic.Count);
                    //缩略图页面还是显示本数据的
                    //string text = string.Format("{0}/{1}", index + 1 + reportData.PageIndexStart - 1, reportData.TotalPageCount);
                    e.Graphics.SetClip(paperRect);
                    using (Font font = new Font("宋体", 10))
                    {
                        StringFormat stringFormat = StringFormat.GenericDefault;
                        stringFormat.Alignment     = StringAlignment.Near;
                        stringFormat.LineAlignment = StringAlignment.Near;
                        stringFormat.Trimming      = StringTrimming.None;
                        stringFormat.FormatFlags   = (StringFormatFlags)0;
                        SizeF      sizeF    = e.Graphics.MeasureString(text, font, 200, stringFormat);
                        RectangleF textRect = new RectangleF(0, 0, sizeF.Width, sizeF.Height);
                        textRect.Y = paperRect.Y + paperRect.Height - 2 - sizeF.Height;
                        textRect.X = paperRect.X + paperRect.Width - 2 - sizeF.Width;
                        e.Graphics.SetClip(textRect);
                        e.Graphics.DrawString(text, font, Brushes.Red, textRect);
                    }
                }
                #endregion


                #region FoucesedCell、MouseOnCell
                if (HighlightFoucesedCell && this.FoucesedCell != null)
                {
                    if (new List <int>(area.AllRows).IndexOf(this.FoucesedCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.FoucesedCell.Col) >= 0)
                    {
                        RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.FoucesedCell, area, Scale, contentRect, null);
                        e.Graphics.SetClip(rect);
                        Pen pen = new Pen(Brushes.Red, 6);
                        e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    }
                }

                if (HighlightMouseOnCell && this.MouseOnCell != null)
                {
                    if (new List <int>(area.AllRows).IndexOf(this.MouseOnCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.MouseOnCell.Col) >= 0)
                    {
                        RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.MouseOnCell, area, Scale, contentRect, null);
                        e.Graphics.SetClip(rect);
                        Pen pen = new Pen(Brushes.Blue, 6);
                        e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    }
                }
                #endregion

                e.Graphics.SetClip(oldClip);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// 重置合并单元格位于多页的情况(分解成多个格子)
 /// </summary>
 private void ReSetMergeCellsInDifPage()
 {
     I3ReportPrintController.ReSetMergeCellsInDifPage(this);
 }
Esempio n. 8
0
 /// <summary>
 /// 重新计算报表大小和分页信息
 /// </summary>
 public void ReCalSizeAndPageInfo()
 {
     I3ReportPrintController.RePaging(this);
     ReSetMergeCellsInDifPage();
 }