/// <summary>
        /// 右上角
        /// </summary>
        /// <param name="text"></param>
        private void DrawString2(string text, Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StringFormat sf    = GetStringFormat(cell, style);
            Brush        brush = new SolidBrush(style.FontColor);
            Font         font  = GetFont(scale, cell, style);

            try
            {
                #region 计算文本绘制区域
                SizeF      sizeF = g.MeasureString(text, font, (int)rect.Width, sf);
                RectangleF r     = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
                r.X     += r.Width - 3 - sizeF.Width; //居右
                r.Width  = sizeF.Width;
                r.Y     += 5;                         //居上
                r.Height = sizeF.Height;
                #endregion

                if (!r.IsEmpty)
                {
                    g.DrawString(text, font, brush, r, sf);
                }
            }
            finally
            {
                font.Dispose();
                brush.Dispose();
                sf.Dispose();
            }
        }
Esempio n. 2
0
 public virtual void DrawBackground(Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style)
 {
     using (Brush brush = new SolidBrush(style.BackColor))
     {
         g.FillRectangle(brush, rect);
     }
 }
        /// <summary>
        /// 适应页宽
        /// </summary>
        public void FullWidth()
        {
            if (reportDatas == null)
            {
                return;
            }
            //先假设没有垂直滚动条
            //I3ReportData reportData = reportDatas.Datas[0];//取第1个报表的页面设置
            float paperWidthPX = 0;

            for (int i = 0; i < reportDatas.PrintAreas.Dic.Count; i++)
            {
                I3ReportData  rd = reportDatas.GetReportDataByAreaIndex(i);
                I3PageSetting p  = rd.PageSetting;
                if (p.PaperWidthPX > paperWidthPX)
                {
                    paperWidthPX = p.PaperWidthPX;
                }
            }
            Scale = ((float)this.Width - 0 - pageInterval * 2) / paperWidthPX - 0.01F;
            if (VScrollVisible)  //如果有,再加上
            {
                Scale = ((float)this.Width - (float)SystemInformation.VerticalScrollBarWidth - pageInterval * 2) / paperWidthPX - 0.01F;
            }
        }
        public override RectangleF DrawContent(Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area, bool draw)
        {
            string text = GetText(cell, area);

            if (!draw || string.IsNullOrEmpty(text))
            {
                return(RectangleF.Empty);
            }

            string[] values = text.Split(new char[] { '|', ',', ';' });


            if (values.Length > 2)
            {
                DrawLine2(g, rect);
                DrawString1(values[0], g, scale, reportData, cell, rect, style, area);
                DrawString2(values[1], g, scale, reportData, cell, rect, style, area);
                DrawString3(values[2], g, scale, reportData, cell, rect, style, area);
            }
            else
            {
                DrawLine1(g, rect);
                DrawString1(values[0], g, scale, reportData, cell, rect, style, area);
                if (values.Length > 1)
                {
                    DrawString2(values[1], g, scale, reportData, cell, rect, style, area);
                }
            }

            return(RectangleF.Empty);
        }
Esempio n. 5
0
        /// <summary>
        /// 按纸张尺寸分页
        /// </summary>
        /// <param name="reportData"></param>
        private static I3PrintAreas CalPrintAreas(I3ReportData reportData)
        {
            I3PrintAreas rowPringAreas = CalPrintAreasByRows(reportData);
            I3PrintAreas printAreas    = CalPrintAreasByCols(reportData, rowPringAreas);

            return(printAreas);
        }
Esempio n. 6
0
        static void document_QueryPageSettings(object sender, QueryPageSettingsEventArgs e)
        {
            I3PrintDocument document   = sender as I3PrintDocument;
            I3ReportData    reportData = document.ReportDatas.GetReportDataByAreaIndex(document.NextPage - 1);

            e.PageSettings.Landscape = reportData.PageSetting.PaperOrientation == PaperOrientation.横向;
            e.PageSettings.Margins   = new Margins(0, 0, 0, 0);
        }
Esempio n. 7
0
        static void document_PrintPage(object sender, PrintPageEventArgs e)
        {
            //float scale = (100F / 96F) * (600F / e.Graphics.DpiX);  //打印机600DPI对应屏幕96DPI  //这个转换与dpi无关
            float scale = (100F / 96F);

            float  phyOffsetX = 0;
            float  phyOffsetY = 0;
            IntPtr hdc        = e.Graphics.GetHdc();

            try
            {
                float width  = I3Win32PrintHelper.GetPaperWidth(hdc);  //纸张的宽度(打印机单位)
                float height = I3Win32PrintHelper.GetPaperHeight(hdc);

                phyOffsetX  = I3Win32PrintHelper.GetPaperPhyOffsetX(hdc); //纸张的X偏移(打印机单位)
                phyOffsetX  = phyOffsetX * e.PageBounds.Width / width;    //转换为 1/100 英寸
                phyOffsetX *= scale;                                      //转换为像素

                phyOffsetY  = I3Win32PrintHelper.GetPaperPhyOffsetY(hdc);
                phyOffsetY  = phyOffsetY * e.PageBounds.Height / height;
                phyOffsetY *= scale;
            }
            finally
            {
                e.Graphics.ReleaseHdc(hdc);
            }

            I3PrintDocument document   = sender as I3PrintDocument;
            I3ReportData    reportData = document.ReportDatas.GetReportDataByAreaIndex(document.NextPage - 1);
            I3PageSetting   setting    = reportData.PageSetting;

            if (document.NextPage > 0 && document.NextPage <= document.EndPage)
            {
                RectangleF rect = new RectangleF(e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
                rect.X -= phyOffsetX;
                rect.Y -= phyOffsetY;
                RectangleF contentRect = new RectangleF(setting.PaperContentRect.X * scale, setting.PaperContentRect.Y * scale,
                                                        setting.PaperContentRect.Width * scale, setting.PaperContentRect.Height * scale);
                contentRect.X -= phyOffsetX;
                contentRect.Y -= phyOffsetY;
                PrintAreaToGraphics(e.Graphics, scale, rect, contentRect, document.ReportDatas,
                                    document.ReportDatas.PrintAreas.Dic[document.NextPage - 1], document.PaintPageIndex, document.NextPage - 1);
                if (document.NextPage < document.EndPage)
                {
                    document.NextPage += 1;
                    e.HasMorePages     = true;
                }
                else
                {
                    document.NextPage = -1;
                    e.HasMorePages    = false;
                }
            }
            else
            {
                e.HasMorePages = false;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// 重新计算大小和分页信息
 /// prepareNarrow:第一次传false,不计算缩小的字体、图像大小,第2次传ture,才进行计算(考虑后面有调大单元格的情况)
 /// </summary>
 private static void ReCalCellsSize(I3ReportData reportData, bool needCalFontSize)
 {
     for (int i = 0; i < reportData.RowCount; i++)
     {
         for (int j = 0; j < reportData.ColCount; j++)
         {
             ReCalCellSize(reportData, i, j, needCalFontSize);
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 将此单元格的位置用I3MergeRange表示
        /// 为合并单元格的第一个单元格时,返回整个合并区间
        /// 为合并单元格的其他单元格时,只返回单元格本身
        /// </summary>
        public I3MergeRange GetRange_Mode2(I3ReportData reportData)
        {
            I3MergeRange range = this.MergState == I3MergeState.FirstCell ? reportData.GetMergeRange(row, col) : null;

            if (range == null)
            {
                range = new I3MergeRange((short)row, (short)col, (short)row, (short)col);
            }
            return(range);
        }
Esempio n. 10
0
        private static I3PrintAreas CalPrintAreasByCols(I3ReportData reportData, I3PrintAreas rowAreas)
        {
            I3PageSetting setting    = reportData.PageSetting;
            float         paperWidth = setting.PaperContentRect.Width;

            I3PrintAreas printAreas = new I3PrintAreas();

            foreach (int row in rowAreas.Dic.Keys)
            {
                I3PrintArea rowArea    = rowAreas.Dic[row];
                float       totalWidth = rowArea.Width;
                List <int>  cols       = new List <int>();
                for (int j = 0; j < reportData.ColCount; j++)
                {
                    if (reportData.Cols[j].Type != I3RowColType.数据 || reportData.Cols[j].Type == I3RowColType.None)
                    {
                        continue;
                    }
                    int colWidth = reportData.Cols[j].Width;

                    #region 在此列前分页
                    //列后分页,条件:已有列被添加,前面一列的列后分页属性=true,已有列的总宽度>0
                    bool breakBeforeThisCol = cols.Count > 0 && reportData.Cols[cols[cols.Count - 1]].PageBreak && totalWidth > rowArea.Width;
                    //尺寸超过
                    breakBeforeThisCol = breakBeforeThisCol || (setting.ColsPagerStyle == PagerStyle.纸张尺寸分页 && totalWidth + colWidth > paperWidth);
                    //列数超过
                    breakBeforeThisCol = breakBeforeThisCol || (setting.ColsPagerStyle == PagerStyle.数据行列数分页 && cols.Count >= setting.ColsPerPage);

                    if (breakBeforeThisCol)
                    {
                        I3PrintArea area = rowArea.Clone().AddCols(cols);
                        area.Width = totalWidth;
                        printAreas.Add(printAreas.Dic.Count, area);
                        totalWidth = rowArea.Width + colWidth;
                        cols.Clear();
                        cols.Add(j);
                        continue;
                    }
                    #endregion

                    //不分页
                    totalWidth += colWidth;
                    cols.Add(j);
                }

                //最后有些列未能分页
                if (cols.Count > 0)
                {
                    I3PrintArea area = rowArea.Clone().AddCols(cols);
                    area.Height = totalWidth;
                    printAreas.Add(printAreas.Dic.Count, area);
                }
            }
            return(printAreas);
        }
Esempio n. 11
0
        /// <summary>
        /// 拆分单个合并单元格
        /// </summary>
        /// <param name="m"></param>
        /// <param name="reportData"></param>
        /// <returns></returns>
        private static I3MergeRange[] splitMemrgeRangeInDifPage(I3MergeRange m, I3ReportData reportData)
        {
            List <I3MergeRange> list = new List <I3MergeRange>();

            I3PrintArea startArea = getPrintAreaByRowIndex(m.StartRow, reportData);
            I3PrintArea endArea   = getPrintAreaByRowIndex(m.EndRow, reportData);

            //不在数据区,不做处理
            if (startArea == null || endArea == null)
            {
                list.Add(m);
                return(list.ToArray());
            }

            //在同一页,不做处理
            if (startArea.Index == endArea.Index)
            {
                list.Add(m);
                return(list.ToArray());
            }

            //开始拆分
            I3MergeRange m1 = new I3MergeRange(m.StartRow, m.StartCol, startArea.MaxDataAreaRowIndex, m.EndCol);

            if (m1.EndRow > m1.StartRow || m1.EndCol > m1.StartCol)//判断是否是一个有效的合并单元格
            {
                list.Add(m1);
            }
            I3MergeRange m2 = new I3MergeRange(endArea.MinDataAreaRowIndex, m.StartCol, m.EndRow, m.EndCol);
            //m2的样式同m
            I3ReportCell mCell  = reportData.Rows[m.StartRow][m.StartCol];
            I3ReportCell m2Cell = reportData.Rows[m2.StartRow][m2.StartCol];

            m2Cell.MergState = I3MergeState.FirstCell;
            m2Cell.StyleName = mCell.StyleName;
            if (!string.IsNullOrEmpty(mCell.Text))
            {
                m2Cell.Text = "...";
            }
            if (m2.EndRow - m2.StartRow > 0)                                       //后面的部分超过了一行
            {
                I3MergeRange[] newArr = splitMemrgeRangeInDifPage(m2, reportData); //继续拆分
                list.AddRange(newArr);
            }
            else//后面的部分只有一行
            {
                if (m2.EndCol > m2.StartCol)//存在列的合并
                {
                    list.Add(m2);
                }
            }

            return(list.ToArray());
        }
Esempio n. 12
0
        private static I3PrintAreas CalPrintAreasByRows(I3ReportData reportData)
        {
            I3PageSetting setting     = reportData.PageSetting;
            float         paperHeight = setting.PaperContentRect.Height;
            I3PrintArea   defaultArea = GetDefaultRowPrintArea(reportData);

            //先按行划分
            I3PrintAreas rowPrintAreas = new I3PrintAreas();
            float        totalHeight   = defaultArea.Height;
            List <int>   rows          = new List <int>();

            for (int i = 0; i < reportData.RowCount; i++)
            {
                if (reportData[i].Type != I3RowColType.数据 || reportData[i].Type == I3RowColType.None)
                {
                    continue;
                }
                int rowHeight = reportData[i].Height;

                #region 在此行前分页
                //已有行被添加,前面一行的行后分页属性=true,已有行的总高度>0
                bool breakBeforeThisRow = rows.Count > 0 && reportData[rows[rows.Count - 1]].PageBreak && totalHeight > defaultArea.Height;
                //尺寸超过  条件:加上当前行后超过
                breakBeforeThisRow = breakBeforeThisRow || (setting.RowsPagerStyle == PagerStyle.纸张尺寸分页 && totalHeight + rowHeight > paperHeight);
                //行数超过
                breakBeforeThisRow = breakBeforeThisRow || (setting.RowsPagerStyle == PagerStyle.数据行列数分页 && rows.Count >= setting.RowsPerPage);

                if (breakBeforeThisRow)
                {
                    I3PrintArea area = defaultArea.Clone().AddRows(rows);
                    area.Height = totalHeight;
                    rowPrintAreas.Add(rowPrintAreas.Dic.Count, area);
                    totalHeight = defaultArea.Height + rowHeight;
                    rows.Clear();
                    rows.Add(i);  //不能用i--,如果某行大于整页宽度,会死循环
                    continue;
                }
                #endregion

                //不分页
                totalHeight += rowHeight;
                rows.Add(i);
            }

            //最后有些行未能分页
            if (rows.Count > 0)
            {
                I3PrintArea area = defaultArea.Clone().AddRows(rows);
                area.Height = totalHeight;
                rowPrintAreas.Add(rowPrintAreas.Dic.Count, area);
            }

            return(rowPrintAreas);
        }
Esempio n. 13
0
        private static I3PrintArea getPrintAreaByRowIndex(int rowIndex, I3ReportData reportData)
        {
            foreach (I3PrintArea area in reportData.PrintAreas.Dic.Values)
            {
                if (area.DataRows.ContainsKey(rowIndex))
                {
                    return(area);
                }
            }

            return(null);
        }
        /// <summary>
        /// 适应页高
        /// </summary>
        public void FullHeight()
        {
            if (reportDatas == null)
            {
                return;
            }
            //先假设没有水平滚动条
            I3ReportData reportData = reportDatas.Datas[0];//取第1个报表的页面设置

            Scale = ((float)this.Height - 0 - pageInterval * 2) / reportData.PageSetting.PaperHeightPX - 0.01F;
            if (HScrollVisible)  //如果有,再加上
            {
                Scale = ((float)this.Height - (float)SystemInformation.HorizontalScrollBarHeight - pageInterval * 2) / reportData.PageSetting.PaperHeightPX - 0.01F;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 重置合并单元格位于多页的情况(分解成多个格子)  注意,只针对数据区的内容
        /// 2018.05.30暂时只考虑纵向分解的情况
        /// </summary>
        /// <param name="reportData"></param>
        public static void ReSetMergeCellsInDifPage(I3ReportData reportData)
        {
            foreach (I3PrintArea area in reportData.PrintAreas.Dic.Values)
            {
                area.UpdateMinAndMaxDataRowIndex(reportData);
            }

            I3MergeRange[]      merges = reportData.MergeRanges;
            List <I3MergeRange> list   = new List <I3MergeRange>();

            foreach (I3MergeRange merge in merges)
            {
                I3MergeRange[] arr = splitMemrgeRangeInDifPage(merge, reportData);
                list.AddRange(arr);
            }
            reportData.MergeRanges = list.ToArray();
        }
Esempio n. 16
0
        /// <summary>
        /// 重新计算单元格的大小,借以调整行、列的大小
        /// prepareNarrow:是否处理内容缩放
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        private static void ReCalCellSize(I3ReportData reportData, int row, int col, bool prepareNarrow)
        {
            #region 获取单元格、样式、合并区域对象
            I3ReportCell cell = reportData.GetCellItem(row, col);
            if (cell == null || cell.MergState == I3MergeState.Merged)  //单元格为空,或者是被合并的,不需要重新计算
            {
                return;
            }
            I3ReportCellStyle style = reportData.GetCellStyle(cell.StyleName); //没有样式设置,不用重新计算
            if (style == null)
            {
                return;
            }
            I3MergeRange range = cell.MergState == I3MergeState.FirstCell ? reportData.GetMergeRange(row, col) : null;
            if (range == null)
            {
                range = new I3MergeRange((short)row, (short)col, (short)row, (short)col);
            }
            #endregion

            #region 得到默认宽度、高度
            int width  = 0;
            int height = 0;
            for (int i = range.StartRow; i <= range.EndRow; i++)
            {
                height += reportData[i].Height;
            }
            for (int i = range.StartCol; i <= range.EndCol; i++)
            {
                width += reportData.Cols[i].Width;
            }
            if (width == 0 || height == 0)
            {
                return;
            }
            #endregion


            II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(reportData[row][col]);
            SizeF           needSize = renderer.CalCellNeedSize(width, height, style, cell);
            if (needSize != SizeF.Empty)
            {
                renderer.AdjustCellSize(width, height, needSize, style, cell, range, reportData, prepareNarrow);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// 更新最小最大的数据区行号(注意,DataRows中实际存储的还包含标题、表头、表尾,这里排除之)
        /// </summary>
        public void UpdateMinAndMaxDataRowIndex(I3ReportData reportData)
        {
            int min = int.MaxValue;
            int max = int.MinValue;

            foreach (int rowIndex in DataRows.Keys)
            {
                if (reportData.Rows[rowIndex].Type != I3RowColType.数据)
                {
                    continue;
                }
                min = Math.Min(min, rowIndex);
                max = Math.Max(max, rowIndex);
            }

            MinDataAreaRowIndex = min;
            MaxDataAreaRowIndex = max;
        }
Esempio n. 18
0
        public override RectangleF DrawContent(Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, System.Drawing.RectangleF rect, I3ReportCellStyle style, I3PrintArea area, bool draw)
        {
            I3ReportImageCell imageCell = cell as I3ReportImageCell;

            if (imageCell.ImageData == null)
            {
                return(RectangleF.Empty);
            }

            try
            {
                using (MemoryStream stream = new MemoryStream(imageCell.ImageData))
                {
                    using (Bitmap bitmap = new Bitmap(stream))
                    {
                        float width = imageCell.CalWidth > 0 ? imageCell.CalWidth : imageCell.Width;
                        width *= scale;
                        float heigth = imageCell.CalHeight > 0 ? imageCell.CalHeight : imageCell.Height;
                        heigth *= scale;

                        RectangleF destRect = new RectangleF((float)rect.X + (float)rect.Width / 2F - (float)width / 2F,
                                                             (float)rect.Y + (float)rect.Height / 2F - (float)heigth / 2F,
                                                             width,
                                                             heigth);

                        RectangleF srcRect = new RectangleF(0F, 0F, (float)bitmap.Width, (float)bitmap.Height);
                        if (draw && !destRect.IsEmpty)
                        {
                            g.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
                        }

                        return(destRect);
                    }
                }
            }
            catch
            {
                RectangleF destRect = new RectangleF((float)rect.X + (float)rect.Width / 2F - (float)100 / 2F,
                                                     (float)rect.Y + (float)rect.Height / 2F - (float)100 / 2F,
                                                     100,
                                                     100);
                return(destRect);
            }
        }
        /// <summary>
        /// 斜中间
        /// </summary>
        /// <param name="text"></param>
        private void DrawString3(string text, Graphics g, float scale, I3ReportData reportData, I3ReportCell cell, RectangleF rect, I3ReportCellStyle style, I3PrintArea area)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StringFormat sf    = GetStringFormat(cell, style);
            Brush        brush = new SolidBrush(style.FontColor);
            Font         font  = GetFont(scale, cell, style);

            try
            {
                char[] chars       = text.ToCharArray();
                float  posx        = rect.Right - 3;
                float  xsplit      = 1;
                float  posy        = rect.Bottom;
                float  totalHeigth = GetTotalHeight(chars, g, font, sf);
                float  ysplit      = chars.Length == 0 ? 0 : (rect.Height / 2 - totalHeigth) / (chars.Length - 1);

                for (int i = chars.Length - 1; i >= 0; i--)
                {
                    string     str   = chars[i].ToString();
                    SizeF      sizeF = g.MeasureString(str, font, (int)rect.Width, sf);
                    RectangleF r     = new RectangleF(posx - sizeF.Width, posy - sizeF.Height, sizeF.Width, sizeF.Height);

                    if (!r.IsEmpty)
                    {
                        g.DrawString(str, font, brush, r, sf);
                    }

                    posx = posx - sizeF.Width - xsplit;
                    posy = posy - sizeF.Height - ysplit;
                }
            }
            finally
            {
                font.Dispose();
                brush.Dispose();
                sf.Dispose();
            }
        }
        /// <summary>
        /// 设置当前显示的页数  从页顶开始显示
        /// </summary>
        /// <param name="value"></param>
        public void SetCurPageIndex(int value)
        {
            if (reportDatas == null)
            {
                return;
            }
            value = value > reportDatas.PrintAreas.Dic.Count ? reportDatas.PrintAreas.Dic.Count : value;
            value = value < 0 ? 0 : value;
            I3ReportData reportData   = reportDatas.Datas[0];//取第1个报表的页面设置
            float        singleHeight = reportData.PageSetting.PaperHeightPX * Scale + pageInterval;
            float        curHeight    = value * singleHeight + pageInterval;
            int          oldValue     = vScrollBar.Value;

            curHeight        = curHeight > vScrollBar.Maximum - vScrollBar.LargeChange ? vScrollBar.Maximum - vScrollBar.LargeChange : curHeight;
            curHeight        = curHeight < 0 ? 0 : curHeight;
            vScrollBar.Value = (int)curHeight;
            ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, oldValue, (int)curHeight);

            OnVerticalScroll(vScrollBar, args);
            CurPageIndex = value;
        }
Esempio n. 21
0
        /// <summary>
        /// 将此单元格的位置用I3MergeRange表示
        /// 为合并单元格时,返回合并区域
        /// </summary>
        public I3MergeRange GetRange_Mode1(I3ReportData reportData)
        {
            I3MergeRange range = null;

            switch (this.MergState)
            {
            case I3MergeState.Merged:
                I3ReportCell startCell = reportData.GetMergedStartedCell(this.Row, this.Col);
                range = reportData.GetMergeRange(startCell.Row, startCell.Col);
                break;

            case I3MergeState.FirstCell:
                range = reportData.GetMergeRange(this.Row, this.Col);
                break;

            default:
                range = new I3MergeRange((short)this.Row, (short)this.Col, (short)this.Row, (short)this.Col);
                break;
            }

            return(range);
        }
        /// <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);
            }
        }
 public override void AdjustCellSize(int width, int height, SizeF needSizeF, I3ReportCellStyle style, I3ReportCell cell, I3MergeRange range, I3ReportData reportData, bool prepareNarrow)
 {
     //不做处理
 }
Esempio n. 24
0
 public I3ReportDatas(I3ReportData data)
     : this(new I3ReportData[] { data })
 {
 }
Esempio n. 25
0
 public void Init(I3ReportData reportData, string documentName)
 {
     Init(new I3ReportDatas(reportData), documentName);
 }
        private RectangleF GetAreaContentRect(I3PrintArea area)
        {
            I3ReportData  reportData  = reportDatas.GetReportDataByAreaIndex(area.Index);
            I3PageSetting setting     = reportData.PageSetting;
            float         offsetY     = vScrollBar.Value;
            float         offsetX     = hScrollBar.Value;
            RectangleF    contentRect = new RectangleF(setting.PaperContentRect.X * scale, setting.PaperContentRect.Y * scale, setting.PaperContentRect.Width * scale, setting.PaperContentRect.Height * scale);

            //调整y位置
            for (int i = 0; i < area.Index; i++)
            {
                I3ReportData  rd = reportDatas.GetReportDataByAreaIndex(i);
                I3PageSetting s  = rd.PageSetting;
                contentRect.Y = contentRect.Y + s.PaperRect.Height * scale + pageInterval;
            }
            contentRect.Y = contentRect.Y + pageInterval - offsetY;
            if (!VScrollVisible && !alignTop)
            {
                float totalHeight = 0;
                for (int i = 0; i < reportDatas.PrintAreas.Dic.Count; i++)
                {
                    I3ReportData  rd = reportDatas.GetReportDataByAreaIndex(i);
                    I3PageSetting s  = rd.PageSetting;
                    totalHeight = totalHeight + s.PaperRect.Height * scale + pageInterval;
                }
                contentRect.Y += (int)((this.Height - HScrollHeight - totalHeight) / 2);
            }

            //调整x位置
            contentRect.X = contentRect.X + pageInterval - offsetX;
            //if (!HScrollVisible)
            {
                float totalWidth = setting.PaperRect.Width * scale + pageInterval;
                contentRect.X += (int)((this.Width - VScrollWidth - totalWidth) / 2);
            }

            return(contentRect);

            #region 111
            //I3ReportData reportData = reportDatas.Datas[0];//取第1个报表的页面设置
            //I3PageSetting setting = reportData.PageSetting;
            //float singleHeight = setting.PaperHeightPX * Scale + pageInterval;
            //float singleWidth = setting.PaperWidthPX * Scale + pageInterval;
            //float offsetY = vScrollBar.Value;
            //float offsetX = hScrollBar.Value;

            //RectangleF contentRect = new RectangleF(setting.PaperContentRect.X * scale, setting.PaperContentRect.Y * scale, setting.PaperContentRect.Width * scale, setting.PaperContentRect.Height * scale);
            //contentRect.Y = contentRect.Y + pageInterval + area.Index * singleHeight - offsetY;
            //contentRect.X = contentRect.X + pageInterval - offsetX;
            //if (!VScrollVisible && !alignTop)
            //{
            //    float totalHeight = singleHeight * reportDatas.PrintAreas.Dic.Count + pageInterval;
            //    contentRect.Y += (int)((this.Height - HScrollHeight - totalHeight) / 2);
            //}
            //if (!HScrollVisible)
            //{
            //    float totalWidth = singleWidth + pageInterval;
            //    contentRect.X += (int)((this.Width - VScrollWidth - totalWidth) / 2);
            //}

            //return contentRect;
            #endregion
        }
        /// <summary>
        /// 重新计算
        /// </summary>
        private void ReCal()
        {
            if (reportDatas == null)
            {
                return;
            }

            float curPositionYPecent = (vScrollBar.Maximum - vScrollBar.LargeChange) == 0 ? 0 : (float)vScrollBar.Value / ((float)vScrollBar.Maximum - (float)vScrollBar.LargeChange);

            curPositionYPecent = curPositionYPecent < 0 ? 0 : curPositionYPecent;
            float curPositionXPecent = (hScrollBar.Maximum - hScrollBar.LargeChange) == 0 ? 0 : (float)hScrollBar.Value / ((float)hScrollBar.Maximum - (float)hScrollBar.LargeChange);

            curPositionXPecent = curPositionXPecent < 0 ? 0 : curPositionXPecent;

            I3ReportData reportData   = reportDatas.Datas[0];//取第1个报表的页面设置
            float        singleHeight = reportData.PageSetting.PaperHeightPX * scale + pageInterval;

            vScrollBar.Maximum     = (int)singleHeight + 1; //便于正确设置LargeChange
            vScrollBar.LargeChange = (int)singleHeight;
            //vScrollBar.SmallChange = (int)(singleHeight / SmallChange);
            vScrollBar.SmallChange = SmallChange;
            float singleWidth = reportData.PageSetting.PaperWidthPX * Scale + pageInterval;

            hScrollBar.Maximum     = (int)singleWidth + 1;
            hScrollBar.LargeChange = (int)singleWidth;
            //hScrollBar.SmallChange = (int)(singleWidth / SmallChange);
            hScrollBar.SmallChange = SmallChange;

            //先假没有垂直滚动条
            float totalWidth = singleWidth + pageInterval;

            hScrollBar.Minimum = 0;
            int maxX = (int)totalWidth - (this.Width - 0);

            maxX = maxX < 0 ? 0 : maxX;
            hScrollBar.Maximum = maxX + hScrollBar.LargeChange - 1;
            int valueX = curPositionXPecent.Equals(0) ? 0 : (int)(maxX * curPositionXPecent);

            valueX           = valueX < 0 ? 0 : valueX;
            hScrollBar.Value = valueX;

            //设置垂直滚动条
            //float totalHeight = singleHeight * (float)reportDatas.PrintAreas.Dic.Count + pageInterval;
            float totalHeight = 0;

            for (int i = 0; i < reportDatas.PrintAreas.Dic.Count; i++)
            {
                totalHeight = totalHeight + reportDatas.PrintAreas.Dic[i].ReportData.PageSetting.PaperHeightPX * scale + pageInterval;
            }
            totalHeight        = totalHeight + pageInterval;
            vScrollBar.Minimum = 0;
            int maxY = (int)totalHeight - (this.Height - HScrollHeight);

            maxY = maxY < 0 ? 0 : maxY;
            vScrollBar.Maximum = maxY + vScrollBar.LargeChange - 1;
            int valueY = curPositionYPecent.Equals(0) ? 0 : (int)(maxY * curPositionYPecent);

            valueY           = valueY < 0 ? 0 : valueY;
            vScrollBar.Value = valueY;

            //再次检查是否需要水平滚动条(垂直滚动条的出现可能导致原本不需要水平滚动条,而当前需要了)
            maxX = (int)totalWidth - (this.Width - VScrollWidth);
            maxX = maxX < 0 ? 0 : maxX;
            hScrollBar.Maximum = maxX + hScrollBar.LargeChange - 1;
            valueX             = curPositionXPecent.Equals(0) ? 0 : (int)(maxX * curPositionXPecent);
            valueX             = valueX < 0 ? 0 : valueX;
            hScrollBar.Value   = valueX;

            ResetScrollBarPosition();
            this.Invalidate();
        }
Esempio n. 28
0
        /// <summary>
        /// 获取默认打印区域信息(包含标题行、表头、表尾、页眉、页脚)
        /// </summary>
        /// <param name="area"></param>
        /// <param name="reportData"></param>
        private static I3PrintArea GetDefaultRowPrintArea(I3ReportData reportData)
        {
            I3PrintArea area = new I3PrintArea();

            #region 行
            for (int i = 0; i < reportData.RowCount; i++)
            {
                switch (reportData[i].Type)
                {
                case I3RowColType.页眉:
                    area.HeaderRows.Add(i, i);
                    break;

                case I3RowColType.页脚:
                    area.FooterRows.Add(i, i);
                    break;

                case I3RowColType.标题:
                case I3RowColType.表头:
                case I3RowColType.表尾:
                    area.DataRows.Add(i, i);
                    area.Height += reportData[i].Height;
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region 列
            for (int i = 0; i < reportData.ColCount; i++)
            {
                switch (reportData.Cols[i].Type)
                {
                case I3RowColType.页眉:
                    area.HeaderCols.Add(i, i);
                    break;

                case I3RowColType.页脚:
                    area.FooterCols.Add(i, i);
                    break;

                case I3RowColType.标题:
                case I3RowColType.表头:
                case I3RowColType.表尾:
                    area.DataCols.Add(i, i);
                    area.Width += reportData.Cols[i].Width;
                    break;

                default:
                    break;
                }
            }
            #endregion

            #region 检查
            I3PageSetting setting = reportData.PageSetting;
            if (setting.RowsPagerStyle == PagerStyle.纸张尺寸分页)
            {
                if (area.Width > setting.PaperContentRect.Width)
                {
                    throw new Exception("标题列、表头列、表尾列宽度之和大于纸张可用区域,无法分页!");
                }
                if (area.Height > setting.PaperContentRect.Height)
                {
                    throw new Exception("标题行、表头行、表尾行高度之和大于纸张可用区域,无法分页!");
                }
            }
            #endregion

            return(area);
        }
Esempio n. 29
0
 /// <summary>
 /// 重新计算报表大小和分页信息
 /// </summary>
 /// <param name="reportData"></param>
 public static void RePaging(I3ReportData reportData)
 {
     ReCalCellsSize(reportData, false);
     ReCalCellsSize(reportData, true);   //重新计算一次,有的单元格被其他行列影响调大了,缩小的字体要重新计算
     reportData.SetPrintAreas(CalPrintAreas(reportData));
 }
Esempio n. 30
0
        public override void AdjustCellSize(int width, int height, SizeF needSizeF, I3ReportCellStyle style, I3ReportCell cell, I3MergeRange range, I3ReportData reportData, bool prepareNarrow)
        {
            I3ReportImageCell imageCell = cell as I3ReportImageCell;
            int doubleSplit             = ImageSplit * 2;

            if (needSizeF.Width > width - doubleSplit || needSizeF.Height > height - doubleSplit)
            {
                switch (style.AdjustSize)
                {
                case I3AdjustSize.扩大单元格:
                    #region 扩大单元格
                    if (needSizeF.Width > width - doubleSplit)
                    {
                        float pro = (needSizeF.Width + doubleSplit) / width;
                        for (int i = range.StartCol; i <= range.EndCol; i++)
                        {
                            reportData.Cols[i].Width = (int)(reportData.Cols[i].Width * pro);
                        }
                    }
                    if (needSizeF.Height > height - doubleSplit)
                    {
                        float pro = (needSizeF.Height + doubleSplit) / height;
                        for (int i = range.StartRow; i <= range.EndRow; i++)
                        {
                            reportData[i].Height = (int)(reportData[i].Height * pro);
                        }
                    }
                    cell.StringTrimming = StringTrimming.None;
                    #endregion
                    break;

                case I3AdjustSize.缩小内容:
                    #region 缩小内容
                    if (prepareNarrow)
                    {
                        //先使宽度一致
                        imageCell.CalWidth  = width - doubleSplit;
                        imageCell.CalHeight = imageCell.Height * imageCell.CalWidth / imageCell.Width;
                        //如果高度太大,则使高度一致
                        if (imageCell.CalHeight > height - doubleSplit)
                        {
                            imageCell.CalHeight = height - doubleSplit;
                            imageCell.CalWidth  = imageCell.Width * imageCell.CalHeight / imageCell.Height;
                        }
                    }
                    #endregion
                    break;

                default:       //都不变,调整为图片不按比例缩小
                    #region 图片不按比例缩小
                    imageCell.CalWidth  = width - doubleSplit;
                    imageCell.CalHeight = height - doubleSplit;
                    #endregion
                    break;
                }
            }
        }