我需要在程序中实现实时打印,例如磅道,没过一车,就将计重数据打印出来,并等待下一车,直至到该纸的底部或者打够一定的数目,用控件printDocument 的Print,会打完一条数据后就退纸。有没有什么办法实现我需要的功能啊?
解决方案 »
- LayoutMdi(MdiLayout.Cascade);//MDI窗口布局方式
- c# EventHandler EventArgs的中文意思是?
- 关于datarow的问题和类型转换的问题,谢谢大家~
- 关于《程序员》这本杂志的想法,进来走走哦!
- 求助各位大虾:C#数据库知识方面的困惑<毕业设计>
- C# 结构
- 在winform初始化后DataGrid为什么有一行0,null,null,null
- datagrid的简单问题,走过的来看看
- ★★★非常诚肯的请教一个难题★★★怎样为类写这样一个属性:可以返回类实例的名称( return classInstance.Name)??
- 请问下面的小程序为什么有这个错误?谢谢,在线等
- C#下httpwebrequest()超时的问题,本人C#菜鸟,请高手帮忙!
- 新人求助,关于Gridview控件增删改查
{
printDocument1.PrintPage += new PrintPageEventHandler(MyPrintDoc_PrintPage);
try
{
//printPreviewDialog1.Document = printDocument1;
//printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D;
//printPreviewDialog1.ShowDialog();
printDocument1.Print();
}
catch
{
MessageBox.Show("请安装打印机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
protected void MyPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
//字体 颜色 格式 坐标
drawFont = new Font("Arial", 8);
TitledrawFont = new Font("宋体", 15);
drawBrush = new SolidBrush(Color.Black);
x = 0F;
y = 0F;
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
//线条长度
Pen line = new Pen(drawBrush, 1);
line.DashStyle = DashStyle.Dot; //虚线
float leftbianJu = 120;
float topbianJu = titleHeight + rowHeight * 5 + 1;
float tableWidth = 690;
float tableHeight = 387;
float cellwidth = 30;
float cellwidth1 = 66;
count++;
if (count == 1)
{
printTop(e, leftbianJu, topbianJu, tableWidth, tableHeight, cellwidth, cellwidth1, line);
printMiddle(count, e, leftbianJu, topbianJu, tableWidth, tableHeight, cellwidth, cellwidth1, line);
}
else if (count < 22)
{
printMiddle(count, e, leftbianJu, topbianJu, tableWidth, tableHeight, cellwidth, cellwidth1, line);
}
else
{
printMiddle(count, e, leftbianJu, topbianJu, tableWidth, tableHeight, cellwidth, cellwidth1, line);
// 尾
printLow(count, e, leftbianJu, topbianJu, tableWidth, tableHeight, cellwidth, cellwidth1, line);
} }
private void tbtnPrint_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定打印吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
printDocument.Print();
}
} private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string strSql = "select * from adm_branch where branch_level='0' and parent_code=branch_code";
DataTable dt = myDataLayer.getQueryResult("", strSql); strSql = "select * from v_transport_land_subbill where transport_no='" + strTransportNo + "'";
strSql += " ORDER BY id";
DataTable dtTransportLand = myDataLayer.getQueryResult("", strSql); try
{
string strpage = "";
if (dtTransportLand.Rows.Count % 40 != 0 && (dtTransportLand.Rows.Count + 40) % 40 != 0 && dtTransportLand.Rows.Count!=0)
{
strpage = ((int)(intPageIndex / 40 + 1) + "/" + (int)(dtTransportLand.Rows.Count / 40 + 1));
}
else
{
strpage = ((int)(intPageIndex / 40 + 1) + "/" + (int)(dtTransportLand.Rows.Count / 40 ));
}
e.Graphics.DrawString(dt.Rows[0]["branch_name"].ToString() + "汽运专线配货清单", new Font("宋体", 14, FontStyle.Bold), Brushes.Black, 260, 70);
e.Graphics.DrawString(strpage+"页", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 760, 70); e.Graphics.DrawString("专线名:" + dtTransportLand.Rows[0]["line_name"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 60, 100);
e.Graphics.DrawString("起运地:" + dtTransportLand.Rows[0]["from_site"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 210, 100);
e.Graphics.DrawString("目的地:" + dtTransportLand.Rows[0]["to_site"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 360, 100);
e.Graphics.DrawString("发车时间:" + dtTransportLand.Rows[0]["transport_date"].ToString().Trim() + " " + dtTransportLand.Rows[0]["departure_time"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 510, 100); e.Graphics.DrawString("车牌号:" + dtTransportLand.Rows[0]["vehicle_no"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 60, 130);
int intqyt = 0;
int intbills = 0;
double dweight = 0;
e.Graphics.DrawString("票数:" + dtTransportLand.Rows[0]["total_bills"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 210, 130);
e.Graphics.DrawString("总件数:" + dtTransportLand.Rows[0]["total_qty"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 360, 130);
e.Graphics.DrawString("总重量:" + dtTransportLand.Rows[0]["total_weight"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 510, 130); e.Graphics.DrawString("司机:" + dtTransportLand.Rows[0]["driver_name1"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 60, 160);
e.Graphics.DrawString("手机:" + dtTransportLand.Rows[0]["driver_mobile1"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 210, 160);
e.Graphics.DrawString("司机:" + dtTransportLand.Rows[0]["driver_name2"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 360, 160);
e.Graphics.DrawString("手机:" + dtTransportLand.Rows[0]["driver_mobile2"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 510, 160); e.Graphics.DrawString("序号", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 60, 200);
e.Graphics.DrawString("单号", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 120, 200);
e.Graphics.DrawString("目的地", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 190, 200);
e.Graphics.DrawString("件数", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 260, 200);
e.Graphics.DrawString("重量", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 320, 200);
e.Graphics.DrawString("体积", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 380, 200);
e.Graphics.DrawString("收货人", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 440, 200);
e.Graphics.DrawString("备注", new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 620, 200); int y = 40;
foreach (DataRow dr in dtTransportLand.Rows)
{
if (intPageIndex > dtTransportLand.Rows.Count-1) return;
e.Graphics.DrawString((intPageIndex + 1).ToString(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 65, 200 + y);
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["subbill_no"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 100, 200+y);
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["to_site"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 200, 200 + y);
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["packing_qty"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 270, 200 + y);
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["cargo_weight"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 320, 200 + y);
if (Convert.ToDouble(dtTransportLand.Rows[intPageIndex]["cargo_size"]) > 0)
{
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["cargo_size"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 380, 200 + y);
}
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["receive_name"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 440, 200 + y);
e.Graphics.DrawString(dtTransportLand.Rows[intPageIndex]["transport_re"].ToString().Trim(), new Font("宋体", 10, FontStyle.Bold), Brushes.Black, 620, 200 + y);
if (intPageIndex%40==0&&(intPageIndex+40)%40==0&&intPageIndex!=0)
{
intPageIndex++;
e.HasMorePages = true;
return;
}
y += 20;
intPageIndex++;
}
}
catch (Exception ex)
{
}
}