public void serialize(OutputArchive archive, string tag)
        {
            archive.startRecord(this, tag);
            foreach (Op op in ops)
            {
                MultiHeader h = new MultiHeader(op.get_Type(), false, -1);
                ((Record)h).serialize(archive, tag);
                ZooDefs.OpCode opCode = EnumUtil <ZooDefs.OpCode> .DefinedCast(op.get_Type());

                switch (opCode)
                {
                case ZooDefs.OpCode.create:
                    op.toRequestRecord().serialize(archive, tag);
                    break;

                case ZooDefs.OpCode.delete:
                    op.toRequestRecord().serialize(archive, tag);
                    break;

                case ZooDefs.OpCode.setData:
                    op.toRequestRecord().serialize(archive, tag);
                    break;

                case ZooDefs.OpCode.check:
                    op.toRequestRecord().serialize(archive, tag);
                    break;

                default:
                    throw new IOException("Invalid type of op");
                }
            }
            ((Record) new MultiHeader(-1, true, -1)).serialize(archive, tag);
            archive.endRecord(this, tag);
        }
Beispiel #2
0
        public void deserialize(InputArchive archive, string tag)
        {
            results = new List <OpResult>();

            archive.startRecord(tag);
            MultiHeader h = new MultiHeader();

            ((Record)h).deserialize(archive, tag);
            while (!h.getDone())
            {
                ZooDefs.OpCode opcode = EnumUtil <ZooDefs.OpCode> .DefinedCast(h.get_Type());

                switch (opcode)
                {
                case ZooDefs.OpCode.create:
                    CreateResponse cr = new CreateResponse();
                    ((Record)cr).deserialize(archive, tag);
                    results.Add(new OpResult.CreateResult(cr.getPath()));
                    break;

                case ZooDefs.OpCode.delete:
                    results.Add(new OpResult.DeleteResult());
                    break;

                case ZooDefs.OpCode.setData:
                    SetDataResponse sdr = new SetDataResponse();
                    ((Record)sdr).deserialize(archive, tag);
                    results.Add(new OpResult.SetDataResult(sdr.getStat()));
                    break;

                case ZooDefs.OpCode.check:
                    results.Add(new OpResult.CheckResult());
                    break;

                case ZooDefs.OpCode.error:
                    //FIXME: need way to more cleanly serialize/deserialize exceptions
                    ErrorResponse er = new ErrorResponse();
                    ((Record)er).deserialize(archive, tag);
                    results.Add(new OpResult.ErrorResult(er.getErr()));
                    break;

                default:
                    throw new IOException("Invalid type " + h.get_Type() + " in MultiResponse");
                }
                ((Record)h).deserialize(archive, tag);
            }
            archive.endRecord(tag);
        }
        public void deserialize(InputArchive archive, string tag)
        {
            archive.startRecord(tag);
            MultiHeader h = new MultiHeader();

            ((Record)h).deserialize(archive, tag);

            while (!h.getDone())
            {
                ZooDefs.OpCode opCode = EnumUtil <ZooDefs.OpCode> .DefinedCast(h.get_Type());

                switch (opCode)
                {
                case ZooDefs.OpCode.create:
                    CreateRequest cr = new CreateRequest();
                    ((Record)cr).deserialize(archive, tag);
                    add(Op.create(cr.getPath(), cr.getData(), cr.getAcl(), cr.getFlags()));
                    break;

                case ZooDefs.OpCode.delete:
                    DeleteRequest dr = new DeleteRequest();
                    ((Record)dr).deserialize(archive, tag);
                    add(Op.delete(dr.getPath(), dr.getVersion()));
                    break;

                case ZooDefs.OpCode.setData:
                    SetDataRequest sdr = new SetDataRequest();
                    ((Record)sdr).deserialize(archive, tag);
                    add(Op.setData(sdr.getPath(), sdr.getData(), sdr.getVersion()));
                    break;

                case ZooDefs.OpCode.check:
                    CheckVersionRequest cvr = new CheckVersionRequest();
                    ((Record)cvr).deserialize(archive, tag);
                    add(Op.check(cvr.getPath(), cvr.getVersion()));
                    break;

                default:
                    throw new IOException("Invalid type of op");
                }
                ((Record)h).deserialize(archive, tag);
            }
            archive.endRecord(tag);
        }
        /// <summary>
        /// 绘制过程
        /// </summary>
        /// <param name="g"></param>
        /// <returns>一页没绘制完返回false</returns>
        private bool Draw(Graphics g)
        {
            bool blnHasMorePage = false;        //是否还有下一页标记

            if (this._body.Rows < 0)
            {
                throw new Exception("打印主要网格不能为空,请用Body设置!");
            }

            mPrinter.Graphics       = g;
            mPrinter.PrintDocument  = this.mPrintDocument;
            mPrinter.Sewing         = this.Sewing;
            mPrinter.PrinterMargins = this.mPrinterMargins;


            //初起打印起点坐标及打印区域的宽
            Y     = mPrinter.PrinterMargins.Top;
            X     = mPrinter.PrinterMargins.Left - 50;
            Width = mPrinter.PrinterMargins.Width + 100;

            //画打印区域及装订线
            this.DrawPrinterMargins(mPrinter);
            this.DrawSewing(mPrinter);

            //正标题每页必重复打印,无需判断(改了,更多选择吧)
            if (_title != null && (mCurrentPageIndex == 1 || _title.IsDrawAllPage))
            {
                _title.PrinterMargins = mPrinterMargins;
                OutObject(_title);
            }

            if (_caption != null && (mCurrentPageIndex == 1 || _caption.IsDrawAllPage))
            {
                _caption.MoveY = 0;
                if (_title != null && (mCurrentPageIndex == 1 || _title.IsDrawAllPage))
                {
                    _caption.MoveY = (int)this._title.Height + CON_SPACE_TITLE_CAPTION;
                }
                _caption.PrinterMargins = mPrinterMargins;
                OutObject(_caption);
            }

            if (_title != null || _caption != null)
            {
                Y += CON_SPACE_CAPTION_TOP;         //标题与下面有一定距离
            }

            //启用实际宽度
            int lngInfactWidth = 0;

            if (!this._body.IsAverageColsWidth)
            {
                for (int i = 0; i < _body.ColsWidth.Length; i++)
                {
                    lngInfactWidth += _body.ColsWidth[i];
                }

                if (lngInfactWidth > this.mPrinterMargins.Width)
                {
                    //缩放
                    Scale = this.mPrinterMargins.Width / lngInfactWidth;
                }
                else
                {
                    Width = lngInfactWidth;
                    X    += (this.mPrinterMargins.Width - Width) / 2;
                }
            }


            if (_top != null && (mCurrentPageIndex == 1 || _top.IsDrawAllPage))
            {
                OutObject(_top);
            }

            if (_header != null && (mCurrentPageIndex == 1 || _header.IsDrawAllPage))
            {
                OutObject(_header);
            }

            if ((_top != null || _header != null) && (mCurrentPageIndex == 1 || (_top != null && _top.IsDrawAllPage) || (_header != null && _header.IsDrawAllPage)))
            {
                Y += CON_SPACE_HEADER_BODY; //网格与页头距离
            }

            if (_multiHeader != null && (mCurrentPageIndex == 1 || _multiHeader.IsDrawAllPage))
            {
                OutObject(_multiHeader);
            }


            #region 主体数据网格

            //TimeDef.Start();

            //计算有效高度,便于分页
            float validHeight = mPrinter.PrinterMargins.Height - (Y - mPrinter.PrinterMargins.Top);
            if (_footer != null && _footer.IsDrawAllPage)
            {
                validHeight -= this._footer.Height;
            }
            if (_bottomFooter != null && _bottomFooter.IsDrawAllPage)
            {
                validHeight -= this._bottomFooter.Height;
            }
            if (_bottom != null && _bottom.IsDrawAllPage)
            {
                validHeight -= this._bottom.Height;
            }
            if (validHeight < 0)
            {
                throw new Exception("预留给打印主要网格的空间太小,请适当调整!");
            }

            //有效高度中当前页行数
            int mRowsInCurPage = 0;
            mRowsInCurPage = (int)(validHeight / (float)(this._body.RowHeight));

            //如果指定每页行数,则以其为主
            if (this.RowsPerPage > 0 && this.RowsPerPage < mRowsInCurPage)
            {
                mRowsInCurPage = this.RowsPerPage;
            }

            if (this.IsSubTotalPerPage)
            {
                mRowsInCurPage--;
            }

            //TimeDef.End();

            //************以Body为主************

            //TimeDef.Start();

            string[,] mArrGridText;         //保留当前页文本,用于页小计
            GoldPrinter.Body mbody;

            //如果指定每页行数,则以其为主
            if (this.RowsPerPage > 0 && this.RowsPerPage < mRowsInCurPage)
            {
                mbody = new Body(mRowsInCurPage, this._body.Cols);
            }
            else
            {
                //否则自适应
                if (mRowsInCurPage > (this._body.Rows - this.mCurrentRowIndex))
                {
                    mRowsInCurPage = this._body.Rows - this.mCurrentRowIndex;
                }
                mbody = new Body(mRowsInCurPage, this._body.Cols);
            }

            //存当前页的二维文本
            mArrGridText = new string[mRowsInCurPage, this._body.Cols];
            for (int i = 0; i < mRowsInCurPage && mCurrentRowIndex < this._body.Rows; i++)
            {
                for (int j = 0; j < this._body.Cols; j++)
                {
                    mArrGridText[i, j] = this._body.GetText(mCurrentRowIndex, j);
                }
                mCurrentRowIndex++;
                FooterCurRow = mCurrentRowIndex;
            }
            mbody.GridText        = mArrGridText;
            mbody.ColsAlignString = this._body.ColsAlignString;
            mbody.ColsWidth       = this._body.ColsWidth;
            // mbody.DataSource = this._body.DataSource;
            mbody.IsAverageColsWidth = this._body.IsAverageColsWidth;
            mbody.Font = (Font)(this._body.Font.Clone());

            //TimeDef.End();

            //TimeDef.Start();
            OutObject(mbody);

            //TimeDef.End();
            //mArrGridText = null;


            //判断是否要分页,只要数据网格行数据大于数据网格行指针,则还有下一页
            if (mCurrentRowIndex < this._body.Rows)
            {
                blnHasMorePage = true;
            }



            #region 打印每页小计,只需要将当前数组用循环累计就OK了,这段程序应专门重构为一个函数,读者可以自己试一试

            if (_isSubTotalPerPage && _subTotalColsList != "")
            {
                try
                {
                    GoldPrinter.MultiHeader mhSubTotal = new MultiHeader(1, this._body.Cols);
                    mhSubTotal.ColsWidth     = this._body.ColsWidth;
                    mhSubTotal.Graphics      = g;
                    mhSubTotal.PrintDocument = this.mPrintDocument;
                    mhSubTotal.Sewing        = this._sewing;

                    mhSubTotal.Rectangle = new Rectangle(X, Y, Width, mhSubTotal.Height);
                    //循环
                    //....
                    mhSubTotal.SetText(0, 0, "本页小计");
                    mhSubTotal.SetText(0, 1, "本页小计");
                    //   mhSubTotal.SetText(0, 2, "本页小计");

                    string[] marrSubTotalCol = this._subTotalColsList.Split(';');
                    Double   mdblSubTotal    = 0f;
                    int      mintCol         = 0;

                    for (int i = 0; i < marrSubTotalCol.Length; i++)
                    {
                        mintCol = int.Parse(marrSubTotalCol[i]);

                        for (int j = 0; j < mArrGridText.GetLength(0); j++)
                        {
                            mdblSubTotal += Double.Parse(mArrGridText[j, mintCol]);
                        }
                        mhSubTotal.SetText(0, mintCol, mdblSubTotal.ToString());

                        mdblSubTotal = 0;
                    }


                    mhSubTotal.Draw();

                    Y += mhSubTotal.Height;
                }
                catch
                {
                }
            }


            #endregion



            try
            {
                GoldPrinter.MultiHeader mhEndSubTotal = new MultiHeader(1, this._body.Cols);
                mhEndSubTotal.ColsWidth     = this._body.ColsWidth;
                mhEndSubTotal.Graphics      = g;
                mhEndSubTotal.PrintDocument = this.mPrintDocument;
                mhEndSubTotal.Sewing        = this._sewing;
                //   mhEndSubTotal.IsDrawAllPage = _istotalIsDrawAllPage;

                mhEndSubTotal.Rectangle = new Rectangle(X, Y, Width, mhEndSubTotal.Height);
                //循环
                //....
                mhEndSubTotal.SetText(0, 0, "合计(大写)");
                mhEndSubTotal.SetText(0, 1, "合计(大写)");
                // mhEndSubTotal.SetText(0, 1, "本页小计");
                //   mhSubTotal.SetText(0, 2, "本页小计");

                string[] marrSubTotalCol = _endSubTotalColsList.Split(':');
                Double   mdblSubTotal    = 0f;
                int      mintCol         = 0;
                if (_endSubTotalColsList != null && marrSubTotalCol.Length == 2)
                {
                    if (this._body.Cols > 6)
                    {
                        mhEndSubTotal.SetText(0, 2, marrSubTotalCol[0]);
                        mhEndSubTotal.SetText(0, 3, marrSubTotalCol[0]);
                        mhEndSubTotal.SetText(0, 4, marrSubTotalCol[0]);

                        mhEndSubTotal.SetText(0, this._body.Cols - 2, "合计(小写)");
                        mhEndSubTotal.SetText(0, this._body.Cols - 1, marrSubTotalCol[1]);
                    }
                    else if (this._body.Cols >= 4)
                    {
                        mhEndSubTotal.SetText(0, 1, marrSubTotalCol[0]);
                        mhEndSubTotal.SetText(0, 2, "合计(小写)");
                        mhEndSubTotal.SetText(0, 3, marrSubTotalCol[1]);
                    }
                    else
                    {
                        mhEndSubTotal.SetText(0, 0, "合计(大写):" + marrSubTotalCol[0] + "    " + "合计(小写):" + marrSubTotalCol[1]);
                    }
                }
                if (blnHasMorePage == false || _istotalIsDrawAllPage)
                {
                    mhEndSubTotal.Draw();
                }

                Y += mhEndSubTotal.Height;
            }
            catch
            {
            }



            #endregion

            /*  if ((_footer != null || _bottom != null) && (mCurrentPageIndex == 1 || (_top != null && _top.IsDrawAllPage) || (_header != null && _header.IsDrawAllPage)))
             * {*/
            Y += CON_SPACE_BODY_FOOTER;         //网格与页底距离
                                                // }

            //打印页脚与最底
            if (_footer != null)
            {
                //最后一页必打
                if (blnHasMorePage == false || _footer.IsDrawAllPage)
                {
                    //如果每页都打印,对_footer分页失去了意义
                    if (_footer.IsDrawAllPage)
                    {
                        OutObject(_footer);

                        /*   _footer.ColsWidth = this._body.ColsWidth;
                         * _footer.Graphics = g;
                         * _footer.PrintDocument = this.mPrintDocument;
                         * _footer.Sewing = this._sewing;
                         *
                         * _footer.Rectangle = new Rectangle(X, Y + 100, Width, _footer.Height);     //(int)Math.Ceiling(_body.Rows / RowsPerPage)
                         * _footer.SetText(0, this._body.Cols/2, "第" + mCurrentPageIndex + "页/共" + (int)Math.Ceiling((decimal)_body.Rows / (RowsPerPage-1)) + "页"
                         *    // + this._body.PageWidth+ "Width=" + Width
                         *     );
                         * _footer.Draw();*/
                    }
                    else
                    {
                        //不是每都打,但是最后一页必打_footer,这时要做分页处理
                        //与Body同样的处理
                        //...

                        OutObjectFooter(_footer);
                    }
                }
            }

            if (_bottomFooter != null)
            {
                //最后一页必打
                if (blnHasMorePage == false || _bottomFooter.IsDrawAllPage)
                {
                    //如果每页都打印,对_footer分页失去了意义
                    if (_bottomFooter.IsDrawAllPage)
                    {
                        OutObject(_bottomFooter);

                        /* _bottomFooter.ColsWidth = this._body.ColsWidth;
                         * _bottomFooter.Graphics = g;
                         * _bottomFooter.PrintDocument = this.mPrintDocument;
                         * _bottomFooter.Sewing = this._sewing;
                         *
                         * _bottomFooter.Rectangle = new Rectangle(X, Y + 100, Width, _bottomFooter.Height);     //(int)Math.Ceiling(_body.Rows / RowsPerPage)
                         * _bottomFooter.SetText(0, this._body.Cols / 2, "");
                         * _bottomFooter.Draw();*/
                    }
                    else
                    {
                        //不是每都打,但是最后一页必打_footer,这时要做分页处理
                        //与Body同样的处理
                        //...
                    }
                }
            }

            /*
             *        Y += _bottom.Height;
             *
             *       _bottom.SetText("总行数="+PageNum + "当前行号="+mCurrentPageIndex);
             *         _bottom.Draw();
             *         Y += _bottom.Height;*/
            if (_bottom != null)
            {
                if (blnHasMorePage == false || _bottom.IsDrawAllPage)
                {
                    if (_bottom.IsDrawAllPage)
                    {
                        // OutObjectBottom(_bottom);
                        _bottom.Graphics      = g;
                        _bottom.PrintDocument = this.mPrintDocument;
                        _bottom.Sewing        = this._sewing;
                        int newY = Y + 50;
                        _bottom.Rectangle = new Rectangle(X, newY, Width, 50);     //(int)Math.Ceiling(_body.Rows / RowsPerPage)
                        _bottom.SetText("@第" + mCurrentPageIndex + "页/共" + (int)Math.Ceiling((decimal)_body.Rows / (RowsPerPage - 1)) + "页@", '@');
                        // _footer.SetText(0, this._body.Cols / 2, "第" + mCurrentPageIndex + "页/共" + (int)Math.Ceiling((decimal)_body.Rows / (RowsPerPage - 1)) + "页"
                        // + this._body.PageWidth+ "Width=" + Width
                        // );
                        //  bottom.SetText(curBottomText + "@合计:" + item.RetailOrder.TotalMoneyReceived, '@');
                        //  _bottom.Text = "第" + mCurrentPageIndex + "页/共" + (int)Math.Ceiling((decimal)_body.Rows / RowsPerPage + 1) + "页";
                        _bottom.Draw();
                    }
                    else
                    {
                        //计算有效高度
                        validHeight = mPrinter.PrinterMargins.Height - (Y - mPrinter.PrinterMargins.Top);
                        if (validHeight < _bottom.Height)
                        {
                            blnHasMorePage = true;
                        }
                        else
                        {
                            _bottom.Graphics      = g;
                            _bottom.PrintDocument = this.mPrintDocument;
                            _bottom.Sewing        = this._sewing;
                            int newY = Y + 50;
                            _bottom.Rectangle = new Rectangle(X, newY, Width, 50);
                            _bottom.SetText("@第" + mCurrentPageIndex + "页/共" + (int)Math.Ceiling((decimal)_body.Rows / (RowsPerPage - 1)) + "页@", '@');
                            _bottom.Draw();
                        }
                    }
                }
            }


            //画边框
            DrawBorder(g, this._multiHeader, mbody);

            mbody.Dispose();
            mbody = null;

            return(blnHasMorePage);
        }
        /// <summary>
        /// 画边框
        /// </summary>
        private void DrawBorder(Graphics g, MultiHeader multiHeader, Body body)
        {
            #region 实现...

            //网格边框矩阵
            Rectangle mrecGridBorder;
            int       x, y, width, height;

            width  = body.Rectangle.Width;
            height = body.Rectangle.Height;
            if (multiHeader != null)
            {
                x       = multiHeader.Rectangle.X;
                y       = multiHeader.Rectangle.Y;
                height += multiHeader.Rectangle.Height;
            }
            else
            {
                x = body.Rectangle.X;
                y = body.Rectangle.Y;
            }
            if (this.IsSubTotalPerPage)
            {
                GoldPrinter.MultiHeader m = new MultiHeader(1, 1);
                height += m.RowHeight;
                m       = null;
            }

            mrecGridBorder = new Rectangle(x, y, width, height);
            Pen pen = new Pen(Color.Black, 1);

            GoldPrinter.DrawRectangle dr = new DrawRectangle();
            dr.Graphics  = g;
            dr.Rectangle = mrecGridBorder;
            dr.Pen       = pen;

            switch (GridBorder)
            {
            case GridBorderFlag.Single:
                dr.Draw();
                break;

            case GridBorderFlag.SingleBold:
                dr.Pen.Width = 2;
                dr.Draw();
                if (multiHeader != null)
                {
                    dr.Rectangle = body.Rectangle;
                    dr.DrawTopLine();
                }
                break;

            case GridBorderFlag.Double:
                dr.Draw();
                mrecGridBorder = new Rectangle(x - 2, y - 2, width + 4, height + 4);
                dr.Rectangle   = mrecGridBorder;
                dr.Draw();
                break;

            case GridBorderFlag.DoubleBold:
                dr.Draw();
                mrecGridBorder = new Rectangle(x - 2, y - 2, width + 4, height + 4);
                dr.Rectangle   = mrecGridBorder;
                dr.Pen.Width   = 2;
                dr.Draw();
                break;
            }

            #endregion
        }
Beispiel #6
0
        private static void setPrintDataGridView(RefundCostume item, DataGridView dataGridView2, PrintTemplateType type)
        {
            InteractResult <PrintTemplateInfo> result = CommonGlobalCache.ServerProxy.GetPrintTemplateInfo(type);

            //行列数基本不受限制,但超过一页失去意义,因为以Body为主,以其它为辅
            //   Header header = new Header(4, 2);
            //可以指定每页是否重复打印
            if (result.ExeResult == ExeResult.Success)
            {
                PrintTemplateInfo CurrentPTemplate = result.Data;
                for (int c = 0; c < CurrentPTemplate.PrintCount; c++)
                {
                    MisGoldPrinterOfReWrite misGoldPrinter = new MisGoldPrinterOfReWrite(false, new PrinterMargins(20, 20, 20, 20, 800, 1129));


                    misGoldPrinter.Title = CurrentPTemplate.OrderName; //主标题(C#用\n表示换行)	}

                    misGoldPrinter.Caption = "";

                    double headRow = Math.Round(Convert.ToSingle(CurrentPTemplate.SystemVariables.Count / 2));

                    Header header = new Header(Convert.ToInt32(headRow) + 1, 2);
                    // CommonGlobalUtil.WriteLog("变量总数=" + CurrentPTemplate.SystemVariables.Count + "\r\n" + "应显示行号=" + headRow);
                    header.IsDrawAllPage = true;
                    #region
                    Member _member = null;
                    if (item.RefundOrder.MemeberID != null)
                    {
                        _member = CommonGlobalCache.ServerProxy.GetOneMember(item.RefundOrder.MemeberID);
                    }
                    for (int i = 0; i < CurrentPTemplate.SystemVariables.Count; i++)
                    {
                        int curR = 0;
                        if (i < 2)
                        {
                            curR = 0;
                        }
                        else
                        {
                            double resRow = i / 2;
                            curR = Convert.ToInt32(Math.Round(resRow));
                        }
                        string KeyStr = "";
                        if (CurrentPTemplate.SystemVariables[i] == "销售单号")
                        {
                            KeyStr = "销售单号:";
                            header.SetText(curR, i % 2, CurrentPTemplate.SystemVariables[i] + ":" + item.RefundOrder.ID);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "单据日期")
                        {
                            KeyStr = "单据日期:";
                            header.SetText(curR, i % 2, KeyStr + item.RefundOrder.CreateTime.GetDateTimeFormats('f')[0].ToString());
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户名称")
                        {
                            KeyStr = "客户名称:";
                            string userName = string.Empty;
                            if (_member != null)
                            {
                                userName = _member.Name;
                            }
                            header.SetText(curR, i % 2, KeyStr + userName);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户电话")
                        {
                            KeyStr = "客户电话:";
                            string tel = string.Empty;
                            if (_member != null)
                            {
                                tel = _member.PhoneNumber;
                            }
                            header.SetText(curR, i % 2, KeyStr + tel);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户地址")
                        {
                            KeyStr = "客户地址:";

                            string address = string.Empty;
                            if (_member != null)
                            {
                                address = _member.DetailAddress;
                            }
                            header.SetText(curR, i % 2, KeyStr + address);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "操作人")
                        {
                            KeyStr = "操 作 人:";
                            header.SetText(curR, i % 2, KeyStr + CommonGlobalCache.GetUserName(item.RefundOrder.GuideID));
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "单据备注")
                        {
                            KeyStr = "备    注:";
                            header.SetText(curR, i % 2, KeyStr + item.RefundOrder.Remarks.ToString());
                        }
                    }
                    #endregion

                    misGoldPrinter.Header = header;

                    // List<PrintColumnInfo> dataGV = CurrentPTemplate.PrintColumnInfos;


                    List <PrintColumnInfo> dataGV           = new List <PrintColumnInfo>();
                    PrintColumnInfo        prinAutoIDColumn = new PrintColumnInfo();
                    prinAutoIDColumn.Name = "序列号";
                    prinAutoIDColumn.Rate = 5;
                    dataGV.Add(prinAutoIDColumn);
                    dataGV.AddRange(CurrentPTemplate.PrintColumnInfos);

                    string ColumnsList = string.Empty;
                    foreach (PrintColumnInfo itemC in dataGV)
                    {
                        ColumnsList += itemC.Name + ",";
                    }
                    CommonGlobalUtil.WriteLog("模板设置打印列表头为=" + ColumnsList + "\r\n");
                    //表格是否为零条记录
                    bool isflag = false;
                    if (dataGV.Count == 0)
                    {
                        isflag = true;
                    }

                    List <int> columnCount         = new List <int>();
                    int        pinrtColNum         = 0;
                    string     dataGridColumnsList = string.Empty;
                    if (dataGridView2.Columns.Count > 0)
                    {
                        for (int i = 0; i < dataGridView2.Columns.Count; i++)
                        {
                            DataGridViewColumn column = dataGridView2.Columns[i];

                            if (dataGV.FindAll(t => t.Name == column.HeaderText).Count > 0)
                            {
                                columnCount.Add(i);
                                dataGridColumnsList += column.HeaderText + ",";
                                pinrtColNum++;
                            }
                            else
                            {
                                if (dataGV.FindAll(t => t.Name == column.DataPropertyName).Count > 0)
                                {
                                    columnCount.Add(i);
                                    column.HeaderText    = column.HeaderText.Replace("\r\n", " ");
                                    dataGridColumnsList += column.DataPropertyName + ",";
                                    pinrtColNum++;
                                }
                                else
                                {
                                    if (column.DataPropertyName.Contains("XL"))
                                    {
                                        string name = column.DataPropertyName;  //XL3
                                                                                //3XL
                                        string newname  = name.Replace("XL", "");
                                        string checkstr = newname + "XL";
                                        if (dataGV.FindAll(t => t.Name == checkstr).Count > 0)
                                        {
                                            columnCount.Add(i);
                                            column.HeaderText    = column.HeaderText.Replace("\r\n", " ");
                                            dataGridColumnsList += column.DataPropertyName + ",";
                                            pinrtColNum++;
                                        }
                                        else
                                        {
                                            column.Visible = false;
                                        }
                                    }
                                    else
                                    {
                                        column.Visible = false;
                                    }
                                }
                            }
                            if (isflag)
                            {
                                if (i == 0)
                                {
                                    //打印设置模板不设置任何列,但由于MisGoldPrinter这个类的打印主体为DataGridView,所有必须设置一列默认空的
                                    columnCount.Add(i);
                                    column.Visible    = true;
                                    column.HeaderText = "";

                                    DataTable  dt = new DataTable();
                                    DataColumn c1 = new DataColumn();
                                    c1.ColumnName = "HeaderText";

                                    dt.Columns.Add(c1);
                                    dataGridView2.DataSource = null;
                                    dataGridView2.DataSource = dt;
                                }
                            }
                            //}
                        }

                        CommonGlobalUtil.WriteLog("DataGridView能打印的列为=" + dataGridColumnsList);


                        MultiHeader multiHeader = new MultiHeader(1, dataGV.Count);
                        for (int a = 0; a < dataGV.Count; a++)
                        {
                            multiHeader.SetText(0, a, dataGV[a].Name);
                        }


                        misGoldPrinter.DataSource        = DataGridViewUtil.ToStringArray(dataGridView2, false, true);
                        misGoldPrinter.RowsPerPage       = CurrentPTemplate.Rows + 1; //根据设置传值
                        misGoldPrinter.IsSubTotalPerPage = true;
                        int footerRowsNum = 0;
                        if (((GoldPrinter.Body)(misGoldPrinter.Body)).Rows >= 2)
                        {
                            footerRowsNum = ((GoldPrinter.Body)(misGoldPrinter.Body)).Rows;
                        }
                        else
                        {
                            footerRowsNum = 2;
                        }

                        Footer footer         = new Footer(footerRowsNum, dataGV.Count);
                        int    colIndex       = -1;
                        int    colIndexSecond = -1;
                        for (int b = 0; b < dataGV.Count; b++)
                        {
                            if (dataGV[b].Name == "金额")
                            {
                                colIndex = b;
                            }
                            if (dataGV[b].Name == "数量")
                            {
                                colIndexSecond = b;
                            }
                        }
                        string addressStr = string.Empty;
                        for (int a = 0; a < CurrentPTemplate.SystemVariables.Count; a++)
                        {
                            //if (dataGridView2.Rows.Count >= 2)
                            //{
                            if (CurrentPTemplate.SystemVariables[a] == "店铺地址")
                            {
                                Shop curShop = CommonGlobalCache.GetShop(item.RefundOrder.ShopID);
                                if (curShop != null)
                                {
                                    footer.SetText(0, 0, "店铺地址:" + curShop.Address);
                                }
                            }
                            if (CurrentPTemplate.SystemVariables[a] == "联系电话")
                            {
                                Shop curShop = CommonGlobalCache.GetShop(item.RefundOrder.ShopID);
                                if (curShop != null)
                                {
                                    footer.SetText(1, 0, "联系电话:" + curShop.PhoneNumber);
                                }
                            }
                            //}
                            //else if(dataGridView2.Rows.Count >= 1)
                            //{

                            //    if (CurrentPTemplate.SystemVariables[a] == "店铺地址")
                            //    {
                            //        if (item.RefundOrder.ShopID != null && item.RefundOrder.ShopID != "_online")
                            //        {
                            //            addressStr += "店铺地址:" + CommonGlobalCache.GetShop(item.RefundOrder.ShopID).Address;
                            //        }
                            //    }
                            //    if (CurrentPTemplate.SystemVariables[a] == "联系电话")
                            //    {
                            //        if (addressStr != string.Empty)
                            //        {
                            //            addressStr += "       ";
                            //        }
                            //        if (item.RefundOrder.ShopID != null && item.RefundOrder.ShopID != "_online")
                            //        {
                            //            addressStr += "联系电话:" + CommonGlobalCache.GetShop(item.RefundOrder.ShopID).PhoneNumber;
                            //        }
                            //    }

                            //}
                        }

                        //if (dataGridView2.Rows.Count == 1)
                        //{
                        //    footer.SetText(0, 0, addressStr);
                        //}
                        MoneyConvertChinese MConvertC = new MoneyConvertChinese();
                        //if (dataGridView2.Rows.Count > 1)
                        //{
                        //    footer.SetText(0, 0, "合计 金额大写 " + MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()));

                        //}
                        //else
                        //{
                        //    footer.SetText(0, 0, addressStr+ " 合计 金额大写 " + MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()));

                        //}

                        misGoldPrinter.EndSubTotalColsList = MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()) + ":" + item.RefundOrder.TotalMoneyReceived.ToString();
                        //  footer.SetText(0, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);

                        /*  if (dataGridView2.Rows.Count > 1 )
                         * {
                         *    //if (dataGV.Count >= 2)
                         *    //{
                         *
                         *        footer.SetText(1, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         *    //else
                         *    //{
                         *
                         *    //    footer.SetText(1, dataGV.Count, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         * }
                         * else
                         * {
                         *    //if (dataGV.Count >= 2)
                         *    //{
                         *        footer.SetText(0, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         *    //else
                         *    //{
                         *
                         *    //    footer.SetText(0, dataGV.Count, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         * }*/

                        // PrinterBase pbase = footer.CalculatePageInfo();

                        //if (Math.Ceiling((decimal)dataGridView2.Rows.Count / CurrentPTemplate.Rows) > 1)
                        //{
                        //    footer.IsDrawAllPage = false;
                        //}
                        //else
                        //{

                        //    footer.IsDrawAllPage = true;
                        //}


                        misGoldPrinter.IsTotalIsDrawAllPage = false;
                        footer.IsDrawAllPage = false;


                        Bottom bottom = new Bottom();

                        bottom.IsDrawAllPage = true;

                        // bottom.TopMargin
                        // bottom.SetText("联系电话:"+CommonGlobalCache.GetShop(item.RetailOrder.ShopID).PhoneNumber);

                        misGoldPrinter.SubTotalColsList = (colIndex).ToString() + ";" + (colIndexSecond).ToString();      //用分号分隔的要求小计的列

                        /*   if (!Directory.Exists(CommonGlobalUtil.SystemDir + "EXPORTS\\"))
                         * {
                         * Directory.CreateDirectory(CommonGlobalUtil.SystemDir + "EXPORTS\\");
                         * }
                         * misGoldPrinter.FileName = CommonGlobalUtil.SystemDir + "EXPORTS\\" + item.RetailOrder.ID + ".jpg";*/
                        ((GoldPrinter.Body)(misGoldPrinter.Body)).Font = dataGridView2.Font;


                        int[] widths = new int[dataGV.Count];
                        for (int j = 0; j < dataGV.Count; j++)
                        {
                            widths[j] = Convert.ToInt32(dataGV[j].Rate);
                        }

                        List <int> widthList = new List <int>();

                        /*   for (int i = 0; i < CurrentPTemplate.PrintColumnInfos.Count; i++)
                         * {
                         *     DataGridViewColumn column = dataGridView2.Columns[columnCount[i]];
                         *     if (column.Visible && !String.IsNullOrEmpty(column.HeaderText))
                         *     {
                         *         widthList.Add(widths[i]);
                         *     }
                         *
                         * }*/
                        if (isflag)
                        {
                            widths    = new int[1];
                            widths[0] = 100;
                            // widthList.Add(widths[0]);
                        }

                        //   widths = widthList.ToArray();
                        int newWidth = 800;

                        /*  int totalWidth = 0;
                         * for (int i = 0; i < widths.Length; i++)
                         * {
                         *    totalWidth += widths[i];
                         * }*/
                        //if (dataGridView2.Columns.Count > 0)
                        //{
                        for (int i = 0; i < widths.Length; i++)
                        {
                            widths[i] = decimal.ToInt32(Math.Round((widths[i] * newWidth * (decimal)0.1), 0, MidpointRounding.AwayFromZero));
                            // widths[i] = decimal.ToInt32(Math.Round((widths[i] * newWidth * (decimal)1.0 / totalWidth), 0, MidpointRounding.AwayFromZero));
                        }
                        CommonGlobalUtil.WriteLog("实际打印数量=" + pinrtColNum + "\r\n" + "设置能打印的列数量=" + widths.Length.ToString());

                        /*    bottomFooter.ColsWidth = widths;*/
                        footer.ColsWidth      = widths;
                        misGoldPrinter.Footer = footer;
                        /* misGoldPrinter.BottomFooter = bottomFooter;*/
                        misGoldPrinter.Bottom      = bottom;
                        multiHeader.ColsWidth      = widths;
                        misGoldPrinter.MultiHeader = multiHeader;
                        multiHeader.ColsWidth      = widths;

                        ((GoldPrinter.Body)(misGoldPrinter.Body)).IsAverageColsWidth = false;
                        ((GoldPrinter.Body)(misGoldPrinter.Body)).ColsWidth          = widths;
                        misGoldPrinter.Preview();
                        misGoldPrinter.Dispose();
                        misGoldPrinter = null;
                    }
                }
            }
        }