//本示例需要通用表格打印1或2,以及接口和Code128条码生成一起使用
sing System;
using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using cyh.General; namespace DemoTableXReport{ public partial class Form1 : Form { private DataSet dataSet1; public Form1() { InitializeComponent();}
private void Form1_Load(object sender, EventArgs e)
{//读入数据到dataSet
dataSet1 = new DataSet(); dataSet1.ReadXml(Application.StartupPath+ "\\testReport.xml", System.Data.XmlReadMode.ReadSchema); dataGridView1.DataSource = dataSet1; dataGridView1.DataMember = dataSet1.Tables[0].TableName; }private void button1_Click(object sender, EventArgs e)
{ iTableReport xtr = new ctlTableReport(); xtr.AddReportTitle("测试上1(center)", true, null, StringAlignment.Center, Size.Empty); xtr.AddReportTitle("测试上2(far)", true, null, StringAlignment.Far, Size.Empty); xtr.AddReportTitle("测试下1(center)", false, null, StringAlignment.Center, Size.Empty); xtr.AddReportTitle("测试下2(near){0}", false); xtr.AddReportField("编 号", null, "药品目录", StringAlignment.Near, null, false, string.Empty, true, string.Empty, Size.Empty); xtr.AddReportField("名 称", "名称"); xtr.AddReportField("规 格2", null, "规格", StringAlignment.Near, null, false, "合计", false, string.Empty, Size.Empty); xtr.AddReportField("零 售 价3", null, "零售价", StringAlignment.Far, null, false, "", true, "{0:#0.00}", Size.Empty); xtr.SetReportBarCode("A202010", new Point(100, 0), new Size(500, 100), true, string.Empty); //int r = xtr.GetAutoRow(dataSet1.Tables[0].Rows.Count, 40); //xtr.SetReportMain(100, r, ReportGridLine.Nothing, StringAlignment.Center, false, new System.Drawing.Printing.Margins(80, 80, 100, 80), System.Drawing.Printing.PaperKind.Custom, Size.Empty, 1, 0, "", true, 1); xtr.SetReportMain(100, 20, ReportGridLine.Nothing, StringAlignment.Center, false, new System.Drawing.Printing.Margins(80, 80, 100, 80), System.Drawing.Printing.PaperKind.Custom, Size.Empty, 1, 0, "", false , 1); xtr.UnitAfterPrint += new ReportUnitAfterPrint(xtr_UnitAfterPrint); xtr.DataSource = dataSet1.Tables[0]; xtr.ShowDialog(); } void xtr_UnitAfterPrint(object sender, ReportBandType source, int PageIndex, int RowIndex, string Caption, string Field, ref string Value, EventArgs e) {//if (source == ReportBandType.PageFooder)
// Value = string.Format("{0}",PageIndex+1); //throw new NotImplementedException(); } void xtr_UnitAfterPrint(object sender, int source, int PageIndex, int RowIndex, string Caption, string Field, ref string Value, EventArgs e) { //在此可以校正打印的内容和格式}
}}