Dim dt As DataTable '数据集
Dim cyMgr As CyManagement = New CyManagement()
Private Sub DeskOrderEfficiencyForm2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
dt = cyMgr.CyAgent()
DataGridView1.DataSource = dt
End Sub
Dim pageCount = 0 '总页数
Dim currePage = 0 '当前页数
Dim pageSize = 0 '每页显示数目
' 打印订单
Private Sub orderPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim printFontTitle As New Font("微软雅黑", 18)
Dim printFont As New Font("微软雅黑", 14)
Dim printFontBold As New Font("微软雅黑", 14, FontStyle.Bold)
Dim printFontVerySmall As New Font("微软雅黑", 8)
Dim printFontSmall As New Font("微软雅黑", 9)
Dim printPen As Pen = New Pen(Color.Black, 2)
e.Graphics.DrawString("MUSE CLUB营业部每日订座表", printFontTitle, printPen.Brush, 430, 20) '标题
e.Graphics.DrawLine(Pens.Black, 100, 60, 1050, 60) '画线 画表格
Try
'表头
e.Graphics.DrawLine(Pens.Black, 100, 60, 100, 745) '画线
e.Graphics.DrawString("营业人员", printFont, printPen.Brush, 100, 80)
e.Graphics.DrawLine(Pens.Black, 200, 60, 200, 745) '画线
e.Graphics.DrawString("星期一", printFont, printPen.Brush, 200, 80)
e.Graphics.DrawLine(Pens.Black, 270, 60, 270, 745) '画线
e.Graphics.DrawString("星期二", printFont, printPen.Brush, 275, 80)
e.Graphics.DrawLine(Pens.Black, 340, 60, 340, 745) '画线
e.Graphics.DrawString("星期三", printFont, printPen.Brush, 345, 80)
e.Graphics.DrawLine(Pens.Black, 410, 60, 410, 745) '画线
e.Graphics.DrawString("星期四", printFont, printPen.Brush, 415, 80)
e.Graphics.DrawLine(Pens.Black, 480, 60, 480, 745) '画线
e.Graphics.DrawString("星期五", printFont, printPen.Brush, 485, 80)
e.Graphics.DrawLine(Pens.Black, 550, 60, 550, 745) '画线
e.Graphics.DrawString("星期六", printFont, printPen.Brush, 555, 80)
e.Graphics.DrawLine(Pens.Black, 620, 60, 620, 745) '画线
e.Graphics.DrawString("星期天", printFont, printPen.Brush, 625, 80)
e.Graphics.DrawLine(Pens.Black, 720, 60, 720, 745) '画线
e.Graphics.DrawString("周总台数", printFont, printPen.Brush, 720, 80)
e.Graphics.DrawLine(Pens.Black, 810, 60, 810, 745) '画线
e.Graphics.DrawString("上周总台数", printFont, printPen.Brush, 820, 80)
e.Graphics.DrawLine(Pens.Black, 940, 60, 940, 745) '画线
e.Graphics.DrawString("两周对比", printFont, printPen.Brush, 950, 80)
e.Graphics.DrawLine(Pens.Black, 1050, 60, 1050, 745) '画线
e.Graphics.DrawLine(Pens.Black, 100, 130, 1050, 130) '画线
'内容
Dim detailStartY = 150
For i = currePage * pageSize To currePage * pageSize + pageSize - 1 '填充数据
If i > dt.Rows.Count - 1 Then
Exit For
End If
e.Graphics.DrawString(dt.Rows(i).Item("linkMan"), printFontSmall, printPen.Brush, 105, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Monday"), printFontSmall, printPen.Brush, 210, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Tuesday"), printFontSmall, printPen.Brush, 280, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Wednesday"), printFontSmall, printPen.Brush, 350, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Thursday"), printFontSmall, printPen.Brush, 420, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Friday"), printFontSmall, printPen.Brush, 490, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Saturday"), printFontSmall, printPen.Brush, 560, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Sunday"), printFontSmall, printPen.Brush, 630, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("Week"), printFontSmall, printPen.Brush, 730, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("PreWeek"), printFontSmall, printPen.Brush, 825, detailStartY)
e.Graphics.DrawString(dt.Rows(i).Item("compare"), printFontSmall, printPen.Brush, 955, detailStartY)
e.Graphics.DrawLine(Pens.Black, 100, detailStartY + 27, 1050, detailStartY + 27) '画线
detailStartY += 30
Next
'页尾
e.Graphics.DrawLine(Pens.Black, 100, 745, 1050, 745) '画线
Dim saleTip = "* 以上数字单位为台"
e.Graphics.DrawString(saleTip, printFontVerySmall, printPen.Brush, 100, 790)
currePage += 1
If currePage < pageCount Then
e.HasMorePages = True '多页
Else
e.HasMorePages = False '最后一页
currePage = 0
Return
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
'打印按钮事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
pageCount = 0
currePage = 0
pageSize = 20
Dim orderPrintDocument As New PrintDocument()
orderPrintPreviewDialog.Document = orderPrintDocument
orderPrintDocument.DefaultPageSettings.Landscape = True ' //横向打印
AddHandler orderPrintDocument.PrintPage, AddressOf Me.orderPrintDocument_PrintPage
'orderPrintPreviewDialog.PrintPreviewControl.Zoom = 0.7 ’显示比率
orderPrintPreviewDialog.WindowState = FormWindowState.Normal
pageCount = dt.Rows.Count / pageSize
orderPrintPreviewDialog.ShowDialog()
End Sub
VB.net PDF格式打印多页
最新推荐文章于 2023-11-04 01:32:19 发布