vb.net下打印清单示例(连续纸和固定纸张打印)
来源:互联网 发布:星图软件 编辑:程序博客网 时间:2024/05/20 03:42
清单按类别打印
Private Sub print_doc(ByVal sender As Object, ByVal e As PrintPageEventArgs) Dim m_arg As New drawArg(m_printArg.m_title_font, Brushes.Black, New Pen(Color.Blue, 2)) Dim m_arg1 As New drawArg(m_printArg.m_title1_font, Brushes.Black, New Pen(Color.Blue, 1)) Dim m_arg2 As New drawArg(m_printArg.m_text_font, Brushes.Black, New Pen(Color.Blue, 1)) Dim m_arg3 As New drawArg(m_printArg.m_footer_font, Brushes.Black, New Pen(Color.Blue, 1)) 'Dim h As Single = Format(m_arg2.m_font.GetHeight(e.Graphics) + m_printArg.row_height.row3 + 0.005, "0.000") '设置行高 Dim t_height As Single = m_arg.m_font.GetHeight(e.Graphics) + m_printArg.row_height.row1 Dim t_height1 As Single = m_arg1.m_font.GetHeight(e.Graphics) + m_printArg.row_height.row2 Dim m_height As Single = m_arg2.m_font.GetHeight(e.Graphics) + m_printArg.row_height.row3 Dim f_height As Single = m_arg3.m_font.GetHeight(e.Graphics) + m_printArg.row_height.row4 Dim strformat As New StringFormat(StringFormat.GenericDefault)'居中 strformat.LineAlignment = StringAlignment.Center strformat.Alignment = StringAlignment.Center strformat.FormatFlags = StringFormatFlags.NoWrap Dim strformatleft As New StringFormat(StringFormat.GenericDefault) strformatleft.Alignment = StringAlignment.Near strformatleft.LineAlignment = StringAlignment.Center strformatleft.FormatFlags = StringFormatFlags.NoWrap Dim i As Single = printText(e, "*****医院", m_arg, e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, _ t_height, strformat, New m_Line_Style(False, False, False, False)) <span style="font-family: Arial, Helvetica, sans-serif;">'</span>i返回行高 i = printText(e, "病人住院费用一日清单", m_arg, e.MarginBounds.Left, i, e.MarginBounds.Width, _ t_height, strformat, New m_Line_Style(False, False, False, False)) Dim t_item(3) As m_item t_item(0) = New m_item("病人ID:" & dt(0)(2).ToString, 260 * 0.3937008, _ strformatleft, New m_Line_Style(False, False, False, False)) t_item(1) = New m_item("病人姓名:" & dt(0)(12).ToString, 320 * 0.3937008, _ strformat, New m_Line_Style(False, False, False, False)) t_item(2) = New m_item("性别:" & dt(0)(19).ToString, 200 * 0.3937008, _ strformat, New m_Line_Style(False, False, False, False)) t_item(3) = New m_item("年龄:" & dt(0)(20).ToString, 200 * 0.3937008, _ strformat, New m_Line_Style(False, False, False, False)) i = printLine(e, m_arg1, t_item, e.MarginBounds.Left, i, t_height1) t_item(0) = New m_item("科室:" & dt(0)(4).ToString, 260 * 0.3937008, _ strformatleft, New m_Line_Style(False, True, False, False)) t_item(1) = New m_item("床位:" & dt(0)(5).ToString & "床", 130 * 0.3937008, _ strformat, New m_Line_Style(False, True, False, False)) t_item(2) = New m_item("费别:" & dt(0)(16).ToString, 210 * 0.3937008, _ strformat, New m_Line_Style(False, True, False, False)) t_item(3) = New m_item("入院日期:" & dt(0)(6).ToString, 405 * 0.3937008, _ strformat, New m_Line_Style(False, True, False, False)) i = printLine(e, m_arg1, t_item, e.MarginBounds.Left, i, t_height1) Dim m_item(5) As m_item m_item(0) = New m_item("代码", m_printArg.col_width.col1 * 100 * 0.3937008, _ strformatleft, New m_Line_Style(CBool(m_printArg.col_line1.col1), CBool(m_printArg.col_line2.col1), CBool(m_printArg.col_line3.col1), CBool(m_printArg.col_line4.col1))) m_item(1) = New m_item("项目名称", m_printArg.col_width.col2 * 100 * 0.3937008, _ strformatleft, New m_Line_Style(CBool(m_printArg.col_line1.col2), CBool(m_printArg.col_line2.col2), CBool(m_printArg.col_line3.col2), CBool(m_printArg.col_line4.col2))) m_item(2) = New m_item("单位", m_printArg.col_width.col3 * 100 * 0.3937008, _ strformat, New m_Line_Style(CBool(m_printArg.col_line1.col3), CBool(m_printArg.col_line2.col3), CBool(m_printArg.col_line3.col3), CBool(m_printArg.col_line4.col3))) m_item(3) = New m_item("数量", m_printArg.col_width.col4 * 100 * 0.3937008, _ strformat, New m_Line_Style(CBool(m_printArg.col_line1.col4), CBool(m_printArg.col_line2.col4), CBool(m_printArg.col_line3.col4), CBool(m_printArg.col_line4.col4))) m_item(4) = New m_item("单价", m_printArg.col_width.col5 * 100 * 0.3937008, _ strformat, New m_Line_Style(CBool(m_printArg.col_line1.col5), CBool(m_printArg.col_line2.col5), CBool(m_printArg.col_line3.col5), CBool(m_printArg.col_line4.col5))) m_item(5) = New m_item("金额", m_printArg.col_width.col6 * 100 * 0.3937008, _ strformat, New m_Line_Style(CBool(m_printArg.col_line1.col6), CBool(m_printArg.col_line2.col6), CBool(m_printArg.col_line3.col6), CBool(m_printArg.col_line4.col6))) i = printLine(e, m_arg2, m_item, e.MarginBounds.Left, i, m_height) If dt.Rows.Count > 0 Then Static page As Integer = 0 Static j As Integer = 0 '项目 Static k As Integer = 0 '类别 Static p As Integer = 0 ' 已打印条目数 Dim col_name(0) As String col_name(0) = "class_on_reckoning" Dim dt_t As DataTable = New DataView(dt).ToTable(True, col_name) Dim dv As DataView = dt.DefaultView Dim t_rows_num As Integer = dt.Rows.Count '项目总条数 Dim c_rows_num As Integer = dt_t.Rows.Count '类别总条数 Do While k <= dt_t.Rows.Count - 1 '类别循环开始 dv.RowFilter = "class_on_reckoning='" & dt_t.Rows(k)(0).ToString & "'" Dim dt_t1 As DataTable = dv.ToTable() If e.MarginBounds.Height + e.MarginBounds.Top - i > m_height Then '类别行高小于可打印行高,打印类别 i = printText(e, dt_t.Rows(k)(0).ToString, m_arg2, e.MarginBounds.Left, i, e.MarginBounds.Width, m_height, strformatleft, New m_Line_Style(True, True, False, False)) 'Debug.Print(i) p = p + 1 Else page = page + 1 printText(e, "第" & page & "页", m_arg3, _ e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height, _ e.MarginBounds.Width, f_height, _ strformat) e.Graphics.DrawLine(m_arg2.m_pen, e.MarginBounds.Left, i, e.MarginBounds.Width + e.MarginBounds.Left, i) '//////重设纸张 If CBool(m_printArg.m_PaperKind) Then '如果设为链式纸 Dim pageHeight As Single 'Dim t_height As Single = Format(m_arg.m_font.GetHeight(e.Graphics) + 0.05, "0.00") 'Dim t_height1 As Single = Format(m_arg1.m_font.GetHeight(e.Graphics) + 0.05, "0.00") 'Dim m_height As Single = Format(h + 0.05, "0.00") pageHeight = t_height * 2 + 2 * t_height1 + (1 + t_rows_num + c_rows_num - p) * m_height + e.PageSettings.Margins.Top + e.PageSettings.Margins.Bottom If pageHeight <= m_printArg.m_PaperHeight * 100 * 0.3937008 Then '当所有打印内容大于预设页高,以预设页高为纸张页高 e.PageSettings.PaperSize = New PaperSize("aaa", m_printArg.m_PaperWidth * 100 * 0.3937008, Format(pageHeight + 0.5, "0")) End If End If '///// e.HasMorePages = True Exit Sub End If Do If e.MarginBounds.Height + e.MarginBounds.Top - i >= m_height Then m_item(0).item = dt_t1(j)(14).ToString m_item(1).item = dt_t1(j)(13).ToString m_item(2).item = dt_t1(j)(15).ToString m_item(3).item = dt_t1(j)(22).ToString m_item(4).item = String.Format("{0:f2}", dt_t1(j)(21)) m_item(5).item = String.Format("{0:f2}", dt_t1(j)(23)) i = printLine(e, m_arg2, m_item, e.MarginBounds.Left, i, m_height) 'Debug.Print(i) p = p + 1 j = j + 1 If j = dt_t1.Rows.Count Then '某类别打印完后,跳出循环进入下一类别 j = 0 'If k = dt_t.Rows.Count - 1 Then '最后一个类别,打印横线封闭表格 ' e.Graphics.DrawLine(Pens.Coral, e.MarginBounds.Left, i, e.MarginBounds.Width + e.MarginBounds.Left, i) 'End If Exit Do End If Else '当前页不够打印一行,打印页码和最后一个横线 page += 1 printText(e, "第" & page & "页", m_arg3, _ e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height, _ e.MarginBounds.Width, f_height, _ strformat) If j < dt_t1.Rows.Count Then '如果不是类别的最后一个项目,因为下次还要打类别,要减掉已打印类别占用的个数1 p = p - 1 End If '不足一页,最后一个项目画上横线 e.Graphics.DrawLine(m_arg2.m_pen, e.MarginBounds.Left, i, e.MarginBounds.Width + e.MarginBounds.Left, i) '//////重设纸张 If CBool(m_printArg.m_PaperKind) Then '如果设为链式纸 Dim pageHeight As Single pageHeight = t_height * 2 + 2 * t_height1 + (1 + t_rows_num + c_rows_num - p) * m_height + e.PageSettings.Margins.Top + e.PageSettings.Margins.Bottom If pageHeight <= m_printArg.m_PaperHeight * 100 * 0.3937008 Then '当所有打印内容大于预设页高,以预设页高为纸张页高 e.PageSettings.PaperSize = New PaperSize("aaa", m_printArg.m_PaperWidth * 100 * 0.3937008, Format(pageHeight + 0.5, "0")) End If End If '///// e.HasMorePages = True Exit Sub End If Loop k = k + 1 Loop page += 1 printText(e, "第" & page & "页" & "(共" & page & "页)", m_arg3, _ e.MarginBounds.Left, e.MarginBounds.Top + e.MarginBounds.Height, _ e.MarginBounds.Width, f_height, _ strformat) e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left, i, e.MarginBounds.Width + e.MarginBounds.Left, i)'最后一个项目封线 k = 0 p = 0 page = 0 End If End Sub
0 0
- vb.net下打印清单示例(连续纸和固定纸张打印)
- [VB.NET]打印和打印预览功能
- Silverlight打印全套解决方案--支持打印预览、页面设置(横向纵向,页边距,纸张大小、字体大小)、自动分页和多页连续打印
- c#下crystalreport自定义纸张报表打印
- 98、2000和XP系统自定义打印纸张的VB代码
- 98、2000和XP系统自定义打印纸张的VB代码
- .NET 横向打印,自定义纸张的横向打印
- [转]关于打印机打印连续纸的准备工作及特殊尺寸纸张的问题
- [VB.NET源码]实现打印DataGrid列表的示例
- [VB.NET源码]实现打印DataGrid列表的示例
- 免费DataGridView打印及.NET轻松打印控件(VB打印,C#打印)
- 打印自定义纸张大小
- 打印自定义纸张大小
- 按纸张打印地图
- VC++自定义纸张打印
- 打印自定义纸张大小
- A4纸张打印尺寸
- 打印纸张的尺寸
- Objc-C 知识点回顾 九 Property
- chown命令
- 采用cmd打印输出调试信息
- 数据结构C++语言描述专题系列 (三) 队列
- Java双缓冲
- vb.net下打印清单示例(连续纸和固定纸张打印)
- The method getTabHost() is undefined问题解决
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
- opencv-Mat
- 【android】drawable和Bitmap转换
- nova---12.8日志
- C#基础
- Objc-C 知识点回顾 十 MemoryManagement
- java 基础之一 泛型(Generic)