/// <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;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算纸张的大小  单位像素
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        public static PaperSizeF GetPaperSizePX(I3PageSetting setting)
        {
            PaperSizeF size = GetPaperSizeMM(setting);

            size.Width  = PaperSizeHelper.MM2PX(size.Width);
            size.Height = PaperSizeHelper.MM2PX(size.Height);
            return(size);
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
        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
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 计算纸张的大小  单位mm
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        public static PaperSizeF GetPaperSizeMM(I3PageSetting setting)
        {
            PaperSizeF size = null;

            #region 根据纸张类型获取大小
            switch (setting.PaperType)
            {
            case PaperType.Custom:
                size = new PaperSizeF(setting.CustomPaperWidthMM, setting.CustomPaperHeightMM);
                break;

            case PaperType.A1:
                size = new PaperSizeF(594, 841);
                break;

            case PaperType.A2:
                size = new PaperSizeF(420, 594);
                break;

            case PaperType.A3:
                size = new PaperSizeF(297, 420);
                break;

            case PaperType.A4:
                size = new PaperSizeF(210, 297);
                break;

            case PaperType.A5:
                size = new PaperSizeF(148, 210);
                break;

            case PaperType.B1:
                size = new PaperSizeF(707, 1000);
                break;

            case PaperType.B2:
                size = new PaperSizeF(500, 707);
                break;

            case PaperType.B3:
                size = new PaperSizeF(353, 500);
                break;

            case PaperType.B4:
                size = new PaperSizeF(250, 353);
                break;

            case PaperType.B5:
                size = new PaperSizeF(176, 250);
                break;

            case PaperType.A0:
                size = new PaperSizeF(841, 1189);
                break;

            case PaperType.B0:
                size = new PaperSizeF(1000, 1414);
                break;

            case PaperType.B4JIS:
                size = new PaperSizeF(257, 364);
                break;

            case PaperType.B5JIS:
                size = new PaperSizeF(182, 257);
                break;

            default:      //默认A4
                size = new PaperSizeF(210, 297);
                break;
            }
            #endregion

            //横向调换
            if (setting.PaperOrientation == PaperOrientation.横向)
            {
                float tmp = size.Height;
                size.Height = size.Width;
                size.Width  = tmp;
            }

            return(size);
        }