/// <summary> /// 按照位置整理出每个报表项的左上位置列表 /// 两报表项之间位置关系有三种: /// 1. 无影响 /// 2. 垂直依赖 /// 3. 水平依赖 /// </summary> void SortItems() { RptItemBase item; RptItemInst itemInst; List <RptItemInst> topList = new List <RptItemInst>(); List <RptItemInst> leftList = new List <RptItemInst>(); for (int i = 0; i < _children.Count; i++) { item = _children[i].Item; itemInst = _children[i]; topList.Clear(); leftList.Clear(); // 查找所有上侧左侧的报表项 for (int j = 0; j < _children.Count; j++) { RptItemBase tgt = _children[j].Item; RptItemInst tgtInst = _children[j]; Type tp = tgtInst.GetType(); if ((tgt.Row + tgt.RowSpan - 1) < item.Row && item.IsCrossWithColumns(tgt.Col, tgt.ColSpan)) { topList.Add(tgtInst); } else if ((tgt.Col + tgt.ColSpan - 1) < item.Col && item.IsCrossWithRows(tgt.Row, tgt.RowSpan)) { leftList.Add(tgtInst); } } if (topList.Count > 0) { itemInst.TopItems = GetTopLeftItems(topList, true); } if (leftList.Count > 0) { itemInst.LeftItems = GetTopLeftItems(leftList, false); } } }
/// <summary> /// 是否需要垂直分页 /// </summary> /// <param name="p_item"></param> /// <returns></returns> public bool TestPageBreak(RptItemInst p_item) { RptRegion region = p_item.Region; PageDefine rowPage = Rows[Rows.Count - 1]; int lastRow = rowPage.Start + rowPage.Count; int deltaRow = region.Row + region.RowSpan - lastRow; RptItemBase item = p_item.Item; double topHeight = 0; if (deltaRow > 0) { topHeight = rowPage.Size.Sum(); } else { for (int i = 0; i < region.Row - rowPage.Start; i++) { topHeight += rowPage.Size[i]; } } return(topHeight + item.Height > BodyHeight - TblFooterHeight); }
/// <summary> /// 补充报表项及左上的行列定义,处理分页 /// </summary> /// <param name="p_item"></param> void PrepareItem(RptItemInst p_item) { RptRegion region = p_item.Region; RptItemBase item = p_item.Item; PageDefine rowPage = Rows[Rows.Count - 1]; PageDefine colPage = Cols[Cols.Count - 1]; int lastRow = rowPage.Start + rowPage.Count; int lastCol = colPage.Start + colPage.Count; int deltaRow = region.Row + region.RowSpan - lastRow; int deltaCol = region.Col + region.ColSpan - lastCol; //已经垂直分页 if (region.Row < rowPage.Start && region.Row + region.RowSpan > rowPage.Start) { deltaRow = region.RowSpan - rowPage.Count; region.Row = rowPage.Start; } //已经水平分页 if (region.Col < colPage.Start && region.Col + region.ColSpan > colPage.Start) { deltaCol = region.ColSpan - colPage.Count; region.Col = colPage.Start; } // 无需补充 if (deltaRow <= 0 && deltaCol <= 0) { return; } // 补充行定义 if (deltaRow > 0) { // 页面已有的总高 double topHeight = rowPage.Size.Sum(); int blankRow = deltaRow - region.RowSpan; double heights = 0; if (blankRow < 0) { for (int i = 0; i < deltaRow; i++) { heights += item.Part.GetRowHeight(item.Row + item.RowSpan - deltaRow + i); } //需要分页 if (!_pageEnding && topHeight + heights > (BodyHeight - TblFooterHeight) && region.Row != rowPage.Start) { VerPageBreak(ref rowPage, ref topHeight); //从元素的起始位置开始分页 for (int j = 0; j < region.RowSpan; j++) { double height = item.Part.GetRowHeight(item.Row + j); rowPage.Size.Add(height); topHeight += height; } } else { //不需要分页 for (int i = 0; i < deltaRow; i++) { double height = item.Part.GetRowHeight(item.Row + item.RowSpan - deltaRow + i); if (topHeight + height > (BodyHeight - TblFooterHeight))//元素高度大于页面高度,截断 { height = (BodyHeight - TblFooterHeight - topHeight) < 0 ? 0 : BodyHeight - TblFooterHeight - topHeight; } rowPage.Size.Add(height); topHeight += height; } } } else { for (int i = 0; i < deltaRow; i++) { double height = item.Part.GetRowHeight(item.Row + item.RowSpan - deltaRow + i); if (i == blankRow) { for (int j = i; j < deltaRow; j++) { heights += item.Part.GetRowHeight(item.Row + item.RowSpan - deltaRow + j); } } // 在报表项上 bool inItem = lastRow + i >= region.Row; if (height > BodyHeight - TblFooterHeight) { height = BodyHeight - TblFooterHeight; } if (i == blankRow && heights > BodyHeight - TblFooterHeight) { heights = BodyHeight - TblFooterHeight; } // 需要垂直分页 bool verBreak = (i == blankRow) ? (topHeight + heights > BodyHeight - TblFooterHeight) : (topHeight + height > BodyHeight - TblFooterHeight); if (!_pageEnding && verBreak) { VerPageBreak(ref rowPage, ref topHeight, inItem); } rowPage.Size.Add(height); topHeight += height; } } // 重新计算行位置 region.Row = rowPage.Start + rowPage.Count - region.RowSpan; } //补充列定义 if (deltaCol > 0) { // 页面已有的宽度 double leftWidth = colPage.Size.Sum(); int blankCol = deltaCol - region.ColSpan; double widths = 0; //不需要补充空行 if (blankCol < 0) { for (int i = 0; i < deltaCol; i++) { widths += Info.Root.Cols[item.Col + item.ColSpan - deltaCol + i]; } //需要分页 if (!_pageEnding && leftWidth + widths > BodyWidth && region.Col != colPage.Start) { HorPageBreak(ref colPage, ref leftWidth); //从元素的起始位置开始分页 for (int j = 0; j < region.ColSpan; j++) { double width = Info.Root.Cols[item.Col + j]; colPage.Size.Add(width); leftWidth += width; } } else { //不需要分页 for (int i = 0; i < deltaCol; i++) { double width = Info.Root.Cols[item.Col + item.ColSpan - deltaCol + i]; if (leftWidth + width > BodyWidth)//元素宽度大于页面宽度,截断 { width = (BodyWidth - leftWidth) < 0 ? 0 : BodyWidth - leftWidth; } colPage.Size.Add(width); leftWidth += width; } } } else { //需要空行补充 for (int i = 0; i < deltaCol; i++) { double width = Info.Root.Cols[item.Col + item.ColSpan - deltaCol + i]; if (i == blankCol) { for (int j = i; j < deltaCol; j++) { widths += Info.Root.Cols[item.Col + item.ColSpan - deltaCol + j]; } } // 在报表项上 bool inItem = lastCol + i >= region.Col; // 需要水平分页 bool horBreak = (i == blankCol) ? (leftWidth + widths > BodyWidth) : (leftWidth + width > BodyWidth); if (!_pageEnding && horBreak) { HorPageBreak(ref colPage, ref leftWidth, inItem); } colPage.Size.Add(width); leftWidth += width; } } // 重新计算列位置 region.Col = colPage.Start + colPage.Count - region.ColSpan; } }
/// <summary> /// 添加子项 /// </summary> /// <param name="p_item"></param> public void AddChild(RptItemInst p_item) { _children.Add(p_item); }