示例#1
0
        private Top _top; //�򵥵�һ�����д�ӡ��ʽ,��һ�о���,�����о���,�м��о���

        #endregion Fields

        #region Constructors

        //�����Խ��˳�����΢�޸�,��һ���������,��̬���ش�ӡ����,�γ�����������������,��ӡ���⸴�ӵ�����
        public MisPrinter()
        {
            mCurrentPageIndex = 1;
            _rowsPerPage = 0;
            mCurrentRowIndex = 0;
            mCurrentRowIndexForFooter = 0;
            _isSewingLine = false;
            _isPrinterMargins = false;
            _isSubTotalPerPage = false;
            _subTotalCol = "";

            _sewing = new Sewing(0,SewingDirectionFlag.Left);
            mPrintDocument = new PrintDocument();
            _body = new Body();			//��Ҫ��������ʵ����
            _gridBorder = GridBorderFlag.Double;
        }
示例#2
0
        //*****��δ���ȷʵ̫���ˣ�Ӧ�����ع����ַ����д������������������Ҫ���ô�Ҵ�ͷ��β��˳���Ŀ���ȥ
        //*****����һ���汾��Դ�������һ���������Ҳ������һ�ԡ�
        private bool Draw(Graphics g)
        {
            bool blnHasMorePage = false;		//�Ƿ�����һҳ���

            if (this._body.Rows < 0)
            {
                throw new Exception("��ӡ��Ҫ������Ϊ�գ�����Body���ã�");
            }

            Printer printer = new Printer();
            printer.Graphics = g;
            printer.PrintDocument = this.mPrintDocument;
            printer.Sewing = this.Sewing;

            //�����ӡ������꼰��ӡ����Ŀ�
            Y = printer.PrinterMargins.Top;
            X = printer.PrinterMargins.Left;
            Width = printer.PrinterMargins.Width;
            //MessageBox.Show(Width.ToString());
            #region ����ӡ����װ����
            if (IsPrinterMargins)
            {
                printer.DrawPrinterMargins();
            }
            if (IsSewingLine && _sewing.Margin > 0)
            {
                //������߳�С��0���Զ�����
                if (this._sewing.LineLen < 0)
                {
                    if (this._sewing.SewingDirection == SewingDirectionFlag.Left)
                    {
                        this._sewing.LineLen = printer.PageHeight;
                    }
                    else if (this._sewing.SewingDirection == SewingDirectionFlag.Top)
                    {
                        this._sewing.LineLen = printer.PageWidth;
                    }

                }
                printer.Sewing = this._sewing;
                printer.DrawSewing();
            }
            #endregion

            //������ÿҳ���ظ���ӡ�������ж�
            if (_title != null)
            {
                OutObject(_title);
            }

            if (mCurrentPageIndex == 1 || _caption.IsDrawAllPage)
            {
                if (_caption != null)
                {
                    if (_title != null)
                    {
                        _caption.MoveY = this._title.Height + 5;
                    }
                    OutObject(_caption);
                }
            }

            if (_title != null || _caption != null)
            {
                Y += 20;	//������������һ������
            }
            if (_top != null)
            {
                if (mCurrentPageIndex == 1 || _top.IsDrawAllPage)
                {
                    OutObject(_top);
                }
            }
            if (_header != null)
            {
                if (mCurrentPageIndex == 1 || _header.IsDrawAllPage)
                {
                    OutObject(_header);
                }
            }
            if (_top != null || _header != null)
            {
                if (_title != null || _caption != null || _top.IsDrawAllPage || _header.IsDrawAllPage)
                {
                    Y += 5;	//������ҳͷ����
                }
            }
            if (_multiHeader != null)
            {
                if (mCurrentPageIndex == 1 || _multiHeader.IsDrawAllPage)
                {
                    OutObject(_multiHeader);
                }
            }

            #region ������������

            //������Ч�߶ȣ����ڷ�ҳ
            float validHeight = printer.PrinterMargins.Height - (Y - printer.PrinterMargins.Top);
            if(_footer != null && _footer.IsDrawAllPage)
            {
                validHeight -= this._footer.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--;
            }

            //************��Body��************
            string[,] mArrGridText;			//�����ǰҳ�ı�������ҳС��
            DayReport.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);
            }
            mbody.ColsAlignString = this._body.ColsAlignString;

            //�浱ǰҳ�Ķ�ά�ı�
            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++;
            }

            mbody.GridText = mArrGridText;
            OutObject(mbody);

            //�ж��Ƿ�Ҫ��ҳ��ֻҪ�������������ݴ�������������ָ�룬������һҳ
            if (mCurrentRowIndex < this._body.Rows)
            {
                blnHasMorePage = true;
            }

            #endregion

            Y += 5;	//������ҳ�׾���

            //��ӡҳ�������
            if (_footer != null)
            {
                if (blnHasMorePage == false || _footer.IsDrawAllPage)
                {
                    OutObject(_footer);
                }

            }
            if (_bottom != null)
            {
                if (blnHasMorePage == false || _bottom.IsDrawAllPage)
                {
                    if (_bottom.IsDrawAllPage)
                    {
                        OutObject(_bottom);
                    }
                    else
                    {
                        //������Ч�߶�
                        validHeight = printer.PrinterMargins.Height - (Y - printer.PrinterMargins.Top);
                        if (validHeight < _bottom.Height)
                        {
                            blnHasMorePage = true;
                        }
                        else
                        {
                            OutObject(_bottom);
                        }

                    }
                }
            }
            //���߿�
            DrawBorder(g,this._multiHeader,mbody);

            mbody = null;

            return blnHasMorePage;
        }
示例#3
0
        private void DrawBorder(Graphics g,MultiHeader multiHeader,Body body)
        {
            //����߿����
            RectangleF mrecGridBorder;
            float x,y,width,height;

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

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

            GoldPrinter.DrawRectangle dr = new DrawRectangle();
            dr.Graphics = g;
            dr.RectangleF = 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.RectangleF = body.RectangleF;
                        dr.DrawTopLine();
                    }
                    break;
                case GridBorderFlag.Double:
                    dr.Draw();
                    mrecGridBorder = new RectangleF(x-2,y-2,width+4,height+4);
                    dr.RectangleF = mrecGridBorder;
                    dr.Draw();
                    break;
                case GridBorderFlag.DoubleBold:
                    dr.Draw();
                    mrecGridBorder = new RectangleF(x-2,y-2,width+4,height+4);
                    dr.RectangleF = mrecGridBorder;
                    dr.Pen.Width = 2;
                    dr.Draw();
                    break;
            }
        }
示例#4
0
        public void Print(bool print)
        {
            string[] leader = getLeaders();
            XmlDocument doc = new XmlDocument();
            doc.Load(Application.StartupPath.ToString() + "\\leader.xml");
            string TableName = string.Empty;
            string s = string.Empty;
            string kuozhan = string.Empty;
            try
            {
                s = doc.SelectSingleNode("Config/Table").InnerText.ToString();
                TableName = doc.SelectSingleNode("Config/TableName").InnerText.ToString();
                kuozhan = doc.SelectSingleNode("Config/Kuozhan").InnerText.ToString();
            }
            catch
            {
                s = "";
                TableName = "";
                kuozhan = "";
            }
            MisPrinter webmis = new MisPrinter();

            webmis.GridBorder = GoldPrinter.GridBorderFlag.SingleBold;

            Title title = new Title();
            //title.Text = "平煤股份六矿人员定位系统综合日报表 "
            webmis.Title = null;

            webmis.Caption = TableName;

            webmis.Top = kuozhan + "|统计时间:" + label1.Text + "|" + s;

            webmis.Header = null;

            //MultiHeader multiHeader = new MultiHeader(1, 6);
            //multiHeader.SetText(0, 0, "部门");
            //multiHeader.SetText(0, 1, "零点班");
            //multiHeader.SetText(0, 2, "八点班");
            //multiHeader.SetText(0, 3, "四点班");
            //multiHeader.SetText(0, 4, "合计");
            //multiHeader.SetText(0, 5, "备注");

            //webmis.MultiHeader = multiHeader;

            Body body = new Body();
            body.ColsAlignString = "LCCCCC";
            body.DataSource = GetDataTable();

            int mcols = 6;

            webmis.Body = body;
            webmis.IsSubTotalPerPage = false;				//这是打印本页小计
            webmis.SubTotalCol = (mcols - 2).ToString() + ";" + (mcols - 1).ToString();		//用分号分隔的要求小计的列
            if (leader != null && leader.Length - 1 > 0)
            {
                Footer footer = new Footer(1, leader.Length - 1);
                for (int l = 0; l < leader.Length - 1; l++)
                {
                    footer.SetText(0, l, leader[l].ToString() + ":");
                }
                footer.IsDrawAllPage = false;
                webmis.Footer = footer;
            }
            else
            {
                webmis.Footer = null;
            }
            DayReport.Bottom bottom = new Bottom();		//Top/Bottom的另一种方式
            bottom.Text = "";
            webmis.Bottom = bottom;

            //将注释去掉试试看
            Sewing sewing = new Sewing(20, SewingDirectionFlag.Left);
            webmis.Sewing = sewing;
            webmis.IsSewingLine = false;			//打印装订线

            webmis.IsSubTotalPerPage = false;	//每页加小计

            //webmis.PageSetup();
            if (print)
            {
                webmis.Print();
            }
            else
            {
                webmis.Preview();
            }

            webmis.Dispose();
            webmis = null;
        }