Exemplo n.º 1
0
        //打印
        public void Print()
        {
            PageIndex = -1;
            Count     = (List.Count % PageRow == 0) ? (List.Count / PageRow) : (List.Count / PageRow) + 1;
            if (Count == 0)
            {
                return;
            }
            if (IsPrintPage)
            {
                PagedObjectList pdl = new PagedObjectList();
                pdl.WebClientInfo = List.WebClientInfo;
                pdl.Path          = List.Path;
                pdl.Count         = List.Count;
                pdl.PageSize      = PageRow;
                List = pdl;
            }
            int           c  = list.Count;
            PrintDocument pd = new PrintDocument();

            pd.PrintPage += (o, e) =>
            {
                PrintDocument pd1 = (PrintDocument)o;
                if (pd1.PrintedPageCount - 1 != PageIndex)
                {
                    return;
                }
                if (List is BasePagedList)
                {
                    PageIndex++;
                    BasePagedList pol = (BasePagedList)List;
                    pol.DataLoaded += (o1, e1) =>
                    {
                        //加载展示数据
                        items.CopyFrom(List, 0, this.pageRow);
                        //StackPanel panel = (Area as FrameworkElement).FindName("pageNoPanel") as StackPanel;
                        //// if (panel.Tag.Equals(""))
                        //// {
                        ////     return;
                        //// }
                        ////else
                        //if (panel.Tag.Equals("showPageNo"))
                        //{
                        //    (panel.FindName("pageNo") as TextBlock).Text = "第" + (PageIndex + 1) + "页" + "共" + Count+"页";
                        //}
                        e.PageVisual = Area;
                        area.UpdateLayout();

                        //打印完成,重置索引
                        if (PageIndex == Count - 1)
                        {
                            //(panel.FindName("pageNo") as TextBlock).Text = "";
                            e.HasMorePages = false;
                        }
                        else
                        {
                            e.HasMorePages = true;
                        }
                    };
                    pol.PageIndex = PageIndex;
                }
                else
                {
                    //计算获取的数据开始,截止行
                    pageIndex = 0;
                    PageIndex++;
                    int startRow = (PageIndex - 1) * pageRow;
                    int endRow   = (PageIndex * pageRow) - 1;
                    endRow = endRow > (List.Count - 1) ? (List.Count - 1) : (PageIndex * pageRow) - 1;
                    items.CopyFrom(List, startRow, endRow);
                    e.PageVisual = Area;
                    area.UpdateLayout();
                    //打印完成,重置索引
                    if (PageIndex == Count)
                    {
                        e.HasMorePages = false;
                        PageIndex      = 0;
                    }
                    else
                    {
                        e.HasMorePages = true;
                    }
                }
            };
            pd.Print("");
        }