Exemplo n.º 1
0
        public void ChangePanelReportElementHeight(ReportElement element, ReportControlRegionType controlRegionType)
        {
            if (null == element || (element.Tag is PmsPanel) == false ||
                ReportControlRegionType.PageHead == controlRegionType ||
                ReportControlRegionType.PageFoot == controlRegionType)
            {
                return;
            }
            float regionHeight;

            if (controlRegionType == ReportControlRegionType.Data)
            {
                regionHeight = _PageDataRegionHeight;
            }
            else
            {
                regionHeight = _PageDrawRegionHeight;
            }
            //计算控件原始Y轴坐标
            float originalY             = element.Location.Y + regionHeight * (element.Page.PageNumber - 1);
            float elementLocationHeight = originalY + element.Height;
            int   elemenEndPageNo       = (int)(elementLocationHeight / regionHeight);

            if ((elementLocationHeight % regionHeight) > 0)
            {
                elemenEndPageNo = elemenEndPageNo + 1;
            }
            for (int i = PageCount; i < elemenEndPageNo; i++)
            {
                if (controlRegionType == ReportControlRegionType.Data)
                {
                    AddPage(new ReportPage(this, i + 1, ReportPageType.Data));
                }
                else if (controlRegionType == ReportControlRegionType.ReportHead)
                {
                    AddPage(new ReportPage(this, i + 1, ReportPageType.ReportHead));
                }
                else
                {
                    AddPage(new ReportPage(this, i + 1, ReportPageType.ReportFoot));
                }
            }
            if (elemenEndPageNo < element.Page.PageNumber && elemenEndPageNo > 0)//高度缩小
            {
                int pageNumber = element.Page.PageNumber;
                element.Page = _ReportPageList[elemenEndPageNo - 1];
                for (int i = pageNumber; i > elemenEndPageNo; i--)
                {
                    _ReportPageList[i - 1].RemoveReportElement(element);
                    if (_ReportPageList[i - 1].Elements.Count == 0)
                    {
                        _ReportPageList.Remove(_ReportPageList[i - 1]);
                    }
                    string guidtemp = element.Guid;
                    for (int j = 0; j < _ReportPageList.Count; j++)
                    {
                        if (_ReportPageList[j].Elements.Count == 1)
                        {
                            if (_ReportPageList[j].Elements[0].Guid == guidtemp)
                            {
                                //_ReportPageList[j].Elements[0].Height = 0;
                                //_ReportPageList[j].Elements[0].Width = 0;
                                // _ReportPageList.Remove(_ReportPageList[j]);
                            }
                        }
                        else
                        {
                            //_ReportPageList[j].SetGuidPanelElementHeight(guidtemp);
                        }
                    }
                }
            }
            else//高度增加
            {
                for (int i = element.Page.PageNumber + 1; i <= elemenEndPageNo; i++)
                {
                    ReportElement newElement = new ReportElement(element);
                    newElement.Location = new PointF(newElement.Location.X, originalY - regionHeight * (i - 1));
                    int iIndex = 0;
                    for (int j = 0; j < _ReportPageList[i - 1].Elements.Count; j++)
                    {
                        if (_ReportPageList[i - 1].Elements[j].Location.Y > newElement.Location.Y)
                        {
                            iIndex = j;
                            break;
                        }
                    }
                    _ReportPageList[i - 1].AddReportElement(newElement, iIndex);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加报表元素
        /// 在元素跨页并不分割的情况下:
        ///    1.如果元素的高度超过页高,则丢弃元素
        ///    2.如果元素的高度不超过页高,并且 Location 对应的页高度不够的情况下,则增加一页,
        ///      这样会额外增加整个报表的高度,导致后续元素自动后移
        /// </summary>
        /// <param name="element">待添加报表元素</param>
        /// <param name="splitElement">报表元素跨页的情况下是否启用分割</param>
        /// <param name="simulate">模拟添加报表元素标识</param>
        /// <returns>添加元素后,额外增加的高度 /// </returns>
        public float ReportHeadOrFootOrDataReportElement(ref ReportElement element, bool splitElement, ReportControlRegionType controlRegionType, bool simulate)
        {
            if (null == element)
            {
                return(0.0f);
            }
            float addedY = 0.0f;
            float regionHeight;

            if (controlRegionType == ReportControlRegionType.Data)
            {
                regionHeight = _PageDataRegionHeight;
            }
            else
            {
                regionHeight = _PageDrawRegionHeight;
            }
            int elemenStartPageNo = (int)(element.Location.Y / regionHeight);

            if (element.Location.Y % regionHeight > 0)
            {
                elemenStartPageNo = elemenStartPageNo + 1;
            }
            if (elemenStartPageNo <= 0)
            {
                elemenStartPageNo = 1;
            }
            //容器强制分割
            if (splitElement == true)//控件启用分割
            {
                if (true == simulate)
                {
                    return(addedY);
                }

                float elementLocationHeight = element.Location.Y + element.Height;
                int   elemenEndPageNo       = (int)(elementLocationHeight / regionHeight);
                if ((elementLocationHeight % regionHeight) > 0)
                {
                    elemenEndPageNo = elemenEndPageNo + 1;
                }
                for (int i = PageCount; i < elemenEndPageNo; i++)
                {
                    if (controlRegionType == ReportControlRegionType.Data)
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.Data));
                    }
                    else if (controlRegionType == ReportControlRegionType.ReportHead)
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.ReportHead));
                    }
                    else
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.ReportFoot));
                    }
                }
                float originalY = element.Location.Y;
                for (int i = elemenStartPageNo; i <= elemenEndPageNo; i++)
                {
                    if (i == elemenStartPageNo)
                    {
                        element.Location = new PointF(element.Location.X, originalY - regionHeight * (i - 1));
                        _ReportPageList[i - 1].AddReportElement(element);
                    }
                    else
                    {
                        ReportElement newElement = new ReportElement(element);
                        newElement.Location = new PointF(newElement.Location.X, originalY - regionHeight * (i - 1));
                        _ReportPageList[i - 1].AddReportElement(newElement);
                        if (i == elemenEndPageNo)
                        {
                            element = newElement;
                        }
                    }
                }
            }
            else//不启用分割
            {
                if (element.Height > _PageDrawRegionHeight) //超过1页的高度,容器控件解析时已经进行了强制分割
                {
                    return(addedY);
                }

                element.Location = new PointF(element.Location.X, element.Location.Y - regionHeight * (elemenStartPageNo - 1));
                if ((element.Location.Y + element.Height) > regionHeight) //超过当前页的高度
                {
                    addedY            = regionHeight - element.Location.Y;
                    element.Location  = new PointF(element.Location.X, 0.0f);
                    elemenStartPageNo = elemenStartPageNo + 1;
                }

                if (true == simulate)
                {
                    return(addedY);
                }

                for (int i = PageCount; i < elemenStartPageNo; i++)
                {
                    if (controlRegionType == ReportControlRegionType.Data)
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.Data));
                    }
                    else if (controlRegionType == ReportControlRegionType.ReportHead)
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.ReportHead));
                    }
                    else
                    {
                        AddPage(new ReportPage(this, i + 1, ReportPageType.ReportFoot));
                    }
                }
                _ReportPageList[elemenStartPageNo - 1].AddReportElement(element);
            }
            return(addedY);
        }