如何通过MultiRow来实现套打功能

套打是发票类应用的一个很常见的用例,MultiRow能够实现精确的套打功能,下面我们看看它是怎么实现的。

发布于 2012/11/14 00:00

套打是发票类应用的一个很常见的用例,MultiRow能够实现精确的套打功能,下面我们看看它是怎么实现的。
我们以下面的发票为例:
设计器就会打开,从工具箱里就可以拖拽你所需要的Cell到模板设计器上了,在【属性】窗口,你可以根据你的需求设计Cell的样式
(请参考下面的视频来设计你的模板,视频地址如下:)

http://gcdn.grapecity.com/showtopic-785.html

11. 最后,在你的工程里添加下面的代码,在代码里详细的描述了如何实现套打。
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.gcMultiRow1.AllowUserToAddRows = false;
            this.gcMultiRow1.RowCount = 5;
            this.gcMultiRow1.Document = new System.Drawing.Printing.PrintDocument();
            
            //因为模板比较宽,所以设置Landscape为True
            this.gcMultiRow1.Document.DefaultPageSettings.Landscape = true;
            
            //用这个事件来判断在套打的时候,哪些Cell需要打印,哪些Cell不需要打印
            this.gcMultiRow1.CellFormatting += new EventHandler<GrapeCity.Win.MultiRow.CellFormattingEventArgs>(gcMultiRow1_CellFormatting);
        }

        void gcMultiRow1_CellFormatting(object sender, GrapeCity.Win.MultiRow.CellFormattingEventArgs e)
        {
            //检测Row上的Cells
            if (isPrinting && e.Scope== GrapeCity.Win.MultiRow.CellScope.Row)
            {
                object temp = this.gcMultiRow1[e.RowIndex, e.CellName].Style.Tag;
                
                //检测预先设置好的Tag标记,如果为NotPrint,把Value改为Null,这样就不打印这个Cell了。
                if (temp != null && temp.ToString() == "NotPrint")
                {
                    e.Value = null;
                }
            }
            //检测ColumnHeader区域的Cells
            if (isPrinting && e.Scope == GrapeCity.Win.MultiRow.CellScope.ColumnHeader)
            {
                object temp= this.gcMultiRow1.ColumnHeaders[e.SectionIndex].Cells[e.CellIndex].Style.Tag;
                if (temp != null && temp.ToString() == "NotPrint")
                {
                    e.Value = null;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
           //把发票的样子打印出来,这个时候,里面的Cells不需要填值
            this.gcMultiRow1.Document.Print();

        }
        bool isPrinting;
        private void button2_Click(object sender, EventArgs e)
        {
            //这个标记告诉Control,现在准备开始打印
            isPrinting = true;
            //设置PrintStyle为Content模式,这样我们就只打印内容,从而实现了套打功能。
          this.gcMultiRow1.PrintSettings.PrintStyle= GrapeCity.Win.MultiRow.PrintStyle.Content;
            this.gcMultiRow1.Document.Print();
            isPrinting = false;
        }
    }
}
复制代码
你也可以直接编译附加的工程,点击第一个Button,就可以打印发票的样子,然后输入一些值,就实现了套打功能。
 

zip(2010-10-29 16:34:25 上传)

关于葡萄城

葡萄城是专业的软件开发技术和低代码平台提供商,以“赋能开发者”为使命,致力于通过表格控件、低代码和BI等各类软件开发工具和服务,一站式满足开发者需求,帮助企业提升开发效率并创新开发模式。葡萄城开发技术始于1980年,40余年来始终聚焦软件开发技术,有深厚的技术积累和丰富的产品线。是业界能够同时赋能软件开发和低代码开发的企业。凭借过硬的产品能力、活跃的用户社区和丰富的伙伴生态,与超过3000家合作伙伴紧密合作,产品广泛应用于信息和软件服务、制造、交通运输、建筑、金融、能源、教育、公共管理等支柱产业。

推荐相关案例
推荐相关资源
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态