示例#1
0
 public void LocateCurrentPage(int x, int y, bool isLocateChild = true)
 {
     if (Pages.Count == 1)
     {
         CurrentPage = Pages.FirstOrDefault(page => 0 <= y && page.Y + page.Height + page.Spacing >= y);
     }
     else
     {
         CurrentPage = Pages.FirstOrDefault(page => page.Y <= y && page.Y + page.Height + page.Spacing >= y);
     }
     if (!isLocateChild) return;
     if (CurrentPage != null) CurrentPage.Locate(x, y);
 }
示例#2
0
        public DPage InsertPage()
        {
            var page = new DPage();
            page.SetDocument(this);

            if (Pages.Count == 0)
            {
                page.Index = 1;
            }
            else
            {
                var lpage = Pages[Pages.Count - 1];
                lpage.NextPage = page;
                page.PrePage = lpage;
                page.X = lpage.X;
                page.SetDocument(lpage.GetDocument());
            }

            page.Initialize();

            Pages.Add(page);
            CurrentPage = page;

            Context.AutoScrollMinSize = new Size(page.MarginLeft + page.Width + page.MarginRight,
                page.MarginTop + (page.Height + page.Spacing) * Pages.Count + page.OffsetY);

            return page;
        }
示例#3
0
        public DPage InsertPageAfter(DPage prePage)
        {
            var index = Pages.IndexOf(prePage);
            if (index < 0) return null;

            var page = new DPage();
            if (prePage.NextPage == null)
            {
                prePage.NextPage = page;
                page.PrePage = prePage;
            }
            else
            {
                page.PrePage = prePage;
                page.NextPage = prePage.NextPage;
                prePage.NextPage.PrePage = page;
                prePage.NextPage = page;
            }

            page.SetDocument(page.PrePage.GetDocument());
            page.X = prePage.X;
            page.Initialize();

            Pages.Add(page);
            CurrentPage = page;

            Context.AutoScrollMinSize = new Size(page.MarginLeft + page.Width + page.MarginRight,
                page.MarginTop + (page.Height + page.Spacing) * Pages.Count + page.OffsetY);

            return page;
        }
示例#4
0
 public void DeleteAfterAllPage(DPage page)
 {
     if (page == null) return;
     var tempPage = page;
     while (tempPage != null)
     {
         var nPage = tempPage.NextPage;
         DeletePage(tempPage);
         tempPage = nPage;
     }
 }
示例#5
0
        public void DeletePage(DPage page)
        {
            var index = Pages.IndexOf(page);
            if (index < 0) return;

            if (page.PrePage != null)
            {
                if (page.NextPage != null)
                {
                    page.PrePage.NextPage = page.NextPage;
                    page.NextPage.PrePage = page.PrePage;
                    page.NextPage = null;
                    page.PrePage = null;
                }
                else
                {
                    page.PrePage.NextPage = null;
                    page.PrePage = null;
                }
            }
            else if (page.NextPage != null)
            {
                page.NextPage.PrePage = null;
                page.NextPage = null;
            }

            Pages.Remove(page);
            if (Pages.Count > 0) CurrentPage = Pages[Pages.Count - 1];

            Context.AutoScrollMinSize = new Size(page.MarginLeft + page.Width + page.MarginRight,
                page.MarginTop + (page.Height + page.Spacing) * Pages.Count + page.OffsetY);
        }
示例#6
0
 /// <summary>
 /// 全选
 /// </summary>
 private void SelectAll()
 {
     var row = FirstRow;
     while (row != null)
     {
         row.IsSelected = true;
         SelectedRows.Add(row);
         row.SelectAllMember();
         row = row.NextDocRow;
     }
     CurrentPage = Pages[0];
     if (SelectedRows.Count > 0)
         Context.HideCursor();
 }
示例#7
0
        /// <summary>
        /// 移动行
        /// </summary>
        private void MoveRow(DDocRow row, DPage currentPage)
        {
            if (row == null) return;

            //该行超出所在页面范围,则移至下一页
            var rowPointer = row;
            var pagePointer = currentPage;

            var maxHeight = pagePointer.Y + pagePointer.Height - pagePointer.PaddingBottom;

            while (rowPointer != null)
            {
                //第一行肯定是页首行,所以不能更改页首行标志
                if (!rowPointer.Equals(FirstRow))
                {
                    rowPointer.IsPageFirst = false;
                }

                //如果该行超出该页高度,则与下一页合并成为首行
                if (rowPointer.Y >= maxHeight ||
                    rowPointer.Y + rowPointer.Height > maxHeight)
                {
                    //下一页为空或者行的高度等于或超过页的高度,则创建新页
                    if (pagePointer.NextPage == null || rowPointer.Height >= pagePointer.Height)
                    {
                        var page = InsertPageAfter(pagePointer);
                        rowPointer.IsPageFirst = true;
                        page.PageBody.Data = rowPointer;
                        page.Resize();
                        Context.AutoScrollPosition = new Point(0, row.Y + row.Height - Context.Height);
                        Context.ForceShowCursor();
                        MoveRow(rowPointer, page);
                        return;
                    }

                    //将指针指向下一页
                    pagePointer = pagePointer.NextPage;

                    //将该行设置为下一页行首
                    rowPointer.IsPageFirst = true;
                    pagePointer.PageBody.Data = rowPointer;
                    pagePointer.Resize();

                    //行指针下移
                    rowPointer = rowPointer.NextDocRow;

                    if (rowPointer == null) break;

                    rowPointer.IsPageFirst = false;

                    MoveRow(rowPointer, pagePointer);

                    return;
                }

                var prePage = pagePointer.PrePage;
                //如果超出上一页则放置在当前页
                if (prePage != null)
                {
                    var maxHeight2 = prePage.Y + prePage.Height - prePage.PaddingBottom;
                    if (rowPointer.Y >= maxHeight2 || rowPointer.Y + rowPointer.Height > maxHeight2)
                    {
                        if (rowPointer.Equals(pagePointer.PageBody.Data))
                        {
                            rowPointer.IsPageFirst = true;
                        }
                        else if (rowPointer.PreDocRow != null &&
                            rowPointer.PreDocRow.Y + rowPointer.PreDocRow.Height <= maxHeight2)
                        {
                            rowPointer.IsPageFirst = true;
                            pagePointer.PageBody.Data = rowPointer;
                            pagePointer.Resize();
                        }
                    }
                }

                //如果已经遍历到最后一行,对最后一行所在页之后的空页进行删除
                if (rowPointer.NextDocRow == null)
                {
                    var page = GetPage(rowPointer.X, rowPointer.Y);
                    DeleteAfterAllPage(pagePointer.NextPage);
                }
                rowPointer = rowPointer.NextDocRow;
            }
        }
示例#8
0
        /// <summary>
        /// 绘制页面边距线
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="page"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void PaintPageEdgeLine(Graphics graphics, DPage page)
        {
            //左上角(横、竖)
            graphics.DrawLine(_mpen, page.PaddingLeft - page.EdgeLineLength,
                              page.PaddingTop, page.PaddingLeft, page.PaddingTop);
            graphics.DrawLine(_mpen, page.PaddingLeft,
                              page.PaddingTop - page.EdgeLineLength, page.PaddingLeft,
                              page.PaddingTop);

            //右上角
            graphics.DrawLine(_mpen, page.Width - page.PaddingRight, page.PaddingTop,
                              page.Width - page.PaddingRight + page.EdgeLineLength, page.PaddingTop);
            graphics.DrawLine(_mpen, page.Width - page.PaddingRight,
                              page.PaddingTop - page.EdgeLineLength,
                              page.Width - page.PaddingRight, page.PaddingTop);

            //左下角
            graphics.DrawLine(_mpen, page.PaddingLeft - page.EdgeLineLength,
                              page.Height - page.PaddingBottom, page.PaddingLeft,
                              page.Height - page.PaddingBottom);
            graphics.DrawLine(_mpen, page.PaddingLeft, page.Height - page.PaddingBottom,
                              page.PaddingLeft, page.Height - page.PaddingBottom + page.EdgeLineLength);

            //右下角
            graphics.DrawLine(_mpen, page.Width - page.PaddingRight, page.Height - page.PaddingBottom,
                              page.Width - page.PaddingRight + page.EdgeLineLength,
                              page.Height - page.PaddingBottom);
            graphics.DrawLine(_mpen, page.Width - page.PaddingRight, page.Height - page.PaddingBottom,
                              page.Width - page.PaddingRight,
                              page.Height - page.PaddingBottom + page.EdgeLineLength);
        }
示例#9
0
        /// <summary>
        /// 绘制页面
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="page"></param>
        private void PaintPage(Graphics graphics, DPage page)
        {
            //graphics.SmoothingMode = SmoothingMode.AntiAlias;

            var radius = (int)(page.Height * .02);

            var lwidth = page.Width + page.OffsetX * 2;
            var lheight = page.Height + page.OffsetY * 2;

            if (_bitmap != null && _bitmap.Width == lwidth && _bitmap.Height == lheight)
            {
                graphics.DrawImage(_bitmap, page.X, page.Y);
                return;
            }

            _bitmap = new Bitmap(lwidth, lheight);
            var bitGraphics = Graphics.FromImage(_bitmap);

            try
            {
                using (var path = new GraphicsPath())
                {
                    path.AddLine(radius, 0, lwidth - (radius * 2), 0);
                    path.AddArc(lwidth - (radius * 2), 0, radius * 2, radius * 2, 270, 90);
                    path.AddLine(lwidth, radius, lwidth, lheight - (radius * 2));
                    path.AddArc(lwidth - (radius * 2), lheight - (radius * 2), radius * 2, radius * 2, 0, 90);
                    path.AddLine(lwidth - (radius * 2), lheight, radius, lheight);
                    path.AddArc(0, lheight - (radius * 2), radius * 2, radius * 2, 90, 90);
                    path.AddLine(0, lheight - (radius * 2), 0, radius);
                    path.AddArc(0, 0, radius * 2, radius * 2, 180, 90);

                    using (var brush = new PathGradientBrush(path))
                    {
                        brush.WrapMode = WrapMode.Clamp;
                        brush.InterpolationColors = _colorBlend;
                        bitGraphics.FillPath(brush, path);
                    }

                    using (var pen = new Pen(Color.White, 1f))
                    {
                        path.Reset();
                        path.AddRectangle(new Rectangle(page.OffsetX, page.OffsetY, page.Width, page.Height));
                        bitGraphics.FillPath(new SolidBrush(Color.White), path);
                    }
                }

                PaintPageEdgeLine(bitGraphics, page);

                graphics.DrawImage(_bitmap, page.X, page.Y);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(GetType().Name + ".PaintShadow() Error: " + ex.Message);
            }
        }
示例#10
0
        private XmlElement ExportPage(XmlDocument xmlDocument, XmlElement docElement, DPage page)
        {
            var pageElement = xmlDocument.CreateElement("page");
            docElement.AppendChild(pageElement);

            var headerElement = xmlDocument.CreateElement("header");
            var footerElement = xmlDocument.CreateElement("footer");
            var bodyElement = xmlDocument.CreateElement("body");
            pageElement.AppendChild(headerElement);
            pageElement.AppendChild(footerElement);
            pageElement.AppendChild(bodyElement);

            //写入页面属性
            pageElement.SetAttribute("bodyWidth", Convert.ToString(page.BodyWidth));
            pageElement.SetAttribute("bodyHeight", Convert.ToString(page.BodyHeight));
            pageElement.SetAttribute("headerWidth", Convert.ToString(page.HeaderWidth));
            pageElement.SetAttribute("headerHeight", Convert.ToString(page.HeaderHeight));
            pageElement.SetAttribute("footerWidth", Convert.ToString(page.FooterWidth));
            pageElement.SetAttribute("footerHeight", Convert.ToString(page.FooterHeight));
            pageElement.SetAttribute("paddingLeft", Convert.ToString(page.PaddingLeft));
            pageElement.SetAttribute("paddingRight", Convert.ToString(page.PaddingRight));
            pageElement.SetAttribute("paddingTop", Convert.ToString(page.PaddingTop));
            pageElement.SetAttribute("paddingBottom", Convert.ToString(page.PaddingBottom));
            pageElement.SetAttribute("edgeLineLength", Convert.ToString(page.EdgeLineLength));
            pageElement.SetAttribute("offsetX", Convert.ToString(page.OffsetX));
            pageElement.SetAttribute("offsetY", Convert.ToString(page.OffsetY));
            pageElement.SetAttribute("width", Convert.ToString(page.Width));
            pageElement.SetAttribute("height", Convert.ToString(page.Height));
            pageElement.SetAttribute("marginLeft", Convert.ToString(page.MarginLeft));
            pageElement.SetAttribute("marginRight", Convert.ToString(page.MarginRight));
            pageElement.SetAttribute("marginTop", Convert.ToString(page.MarginTop));
            pageElement.SetAttribute("marginBottom", Convert.ToString(page.MarginBottom));
            pageElement.SetAttribute("spacing", Convert.ToString(page.Spacing));

            //写入页眉属性
            headerElement.SetAttribute("width", Convert.ToString(page.PageHeader.Width));
            headerElement.SetAttribute("height", Convert.ToString(page.PageHeader.Height));
            headerElement.SetAttribute("paddingLeft", Convert.ToString(page.PageHeader.PaddingLeft));
            headerElement.SetAttribute("paddingRight", Convert.ToString(page.PageHeader.PaddingRight));
            headerElement.SetAttribute("paddingTop", Convert.ToString(page.PageHeader.PaddingTop));
            headerElement.SetAttribute("paddingBottom", Convert.ToString(page.PageHeader.PaddingBottom));
            var headerChildNodes = page.PageHeader.OwnerDocument.Convert2Xml(xmlDocument);
            headerChildNodes.ForEach(data=> headerElement.AppendChild(data));

            //写入页脚属性
            footerElement.SetAttribute("width", Convert.ToString(page.PageFooter.Width));
            footerElement.SetAttribute("height", Convert.ToString(page.PageFooter.Height));
            footerElement.SetAttribute("paddingLeft", Convert.ToString(page.PageFooter.PaddingLeft));
            footerElement.SetAttribute("paddingRight", Convert.ToString(page.PageFooter.PaddingRight));
            footerElement.SetAttribute("paddingTop", Convert.ToString(page.PageFooter.PaddingTop));
            footerElement.SetAttribute("paddingBottom", Convert.ToString(page.PageFooter.PaddingBottom));
            var footerChildNodes = page.PageFooter.OwnerDocument.Convert2Xml(xmlDocument);
            footerChildNodes.ForEach(data => footerElement.AppendChild(data));

            //写入页面body属性
            bodyElement.SetAttribute("width", Convert.ToString(page.PageBody.Width));
            bodyElement.SetAttribute("height", Convert.ToString(page.PageBody.Height));

            return bodyElement;
        }