public override void Subprint()//套表打印
{
//Subprint();调用此方法即可
printDS = new DataSet(); if (printDS.Tables.Count <= 0)
{
printDS.Tables.Add(DS.ToTable().Copy());
printDS.Tables.Add(DsDetail.Tables[tablenamedetail].Copy());
}
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
} private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
int n = 0;
//打印头表资料
StringFormat drawFormat = new StringFormat();
ev.Graphics.DrawString(printDS.Tables[0].Rows[0]["PoNum"].ToString(),new Font("宋体", 12),new SolidBrush(Color.Black),Conn.GetXPoint("PoNum","pohead","XPoint"),Conn.GetXPoint("PoNum","pohead","YPoint"),drawFormat);
ev.Graphics.DrawString(printDS.Tables[0].Rows[0]["SupplierID"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("SupplierID", "pohead", "XPoint"), Conn.GetXPoint("SupplierID", "pohead", "YPoint"), drawFormat);
ev.Graphics.DrawString(printDS.Tables[0].Rows[0]["CompanyName"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("CompanyName", "pohead", "XPoint"), Conn.GetXPoint("CompanyName", "pohead", "YPoint"), drawFormat);
ev.Graphics.DrawString(printDS.Tables[0].Rows[0]["DeliveryDate"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("DeliveryDate", "pohead", "XPoint"), Conn.GetXPoint("DeliveryDate", "pohead", "YPoint"), drawFormat);
ev.Graphics.DrawString(printDS.Tables[0].Rows[0]["cuscode"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("cuscode", "pohead", "XPoint"), Conn.GetXPoint("cuscode", "pohead", "YPoint"), drawFormat);
for (int j = 0; j < printDS.Tables[1].Rows.Count ; j++)
{
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["MaterialCode"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("MaterialCode", "pohead", "XPoint"), Conn.GetXPoint("MaterialCode", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["MaterialChineseName"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("MaterialChineseName", "pohead", "XPoint"), Conn.GetXPoint("MaterialChineseName", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["Materialchinesespec"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("Materialchinesespec", "pohead", "XPoint"), Conn.GetXPoint("Materialchinesespec", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["unit"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("unit", "pohead", "XPoint"), Conn.GetXPoint("unit", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(decimal.Parse(printDS.Tables[1].Rows[j]["UnitPrice"].ToString()).ToString("G"), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("UnitPrice", "pohead", "XPoint"), Conn.GetXPoint("UnitPrice", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["Quantity"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("Quantity", "pohead", "XPoint"), Conn.GetXPoint("Quantity", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["WastageQty"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("WastageQty", "pohead", "XPoint"), Conn.GetXPoint("WastageQty", "pohead", "YPoint") + (n * 30), drawFormat);
ev.Graphics.DrawString(printDS.Tables[1].Rows[j]["SumMoney"].ToString(), new Font("宋体", 12), new SolidBrush(Color.Black), Conn.GetXPoint("SumMoney", "pohead", "XPoint"), Conn.GetXPoint("SumMoney", "pohead", "YPoint") + (n * 30), drawFormat); //明細資料要用(n * 30)來調間距
printDS.Tables[1].Rows.RemoveAt(j);
n++;
if (n % 5 == 0 && printDS.Tables[1].Rows.Count>0)
{
ev.HasMorePages = true;
} }這樣不行,打印出來的好像是奇數行的,偶數行的都沒有打印出來,另外怎樣增加一個打印機對話框出來,因為現在他調用的是預設的打印機
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货