我的代码获取作业的所有数据,然后打印出该作业的托盘标签。现在,它只是通过For Each语句并打印出第一个标签。我在想,也许我需要一个Do while循环,但是不确定。
Private Sub PrintDocument2_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim JobNum = CInt(getJobNumSTR)
Dim AssemblyText = "Assembly#"
Dim PalletQtyText = "Pallet Qty"
Dim Cup_Part As String
Dim Serial As String
Dim Cup_Mfg_Date As String
Dim Pallet As String
Dim PalletQty As String
Dim sqlcon As String = My.Settings.New_Assembly_AccessConnectionString
Dim rh As Integer
rh = 0
Dim BC2 As String
Using con = New SqlConnection(sqlcon)
Dim cmd As SqlCommand
Dim sql = "SELECT j.assembly#, p.Serial, p.Cup_Mfg_Date, p.job, p.Pallet, sum(count(p.serial)) over (partition by pallet) as PalletAmount " & _
" FROM new_assembly_Access.dbo.tbl_pallet p inner join new_assembly_access.dbo.tbl_job j on j.job# = p.job where p.job = @JobNum " & _
" group by j.assembly#, p.Serial, p.Cup_Mfg_Date, p.job, p.Pallet"
cmd = New SqlCommand(sql, con)
Dim da As New SqlDataAdapter(cmd)
da.SelectCommand.Parameters.AddWithValue("@JobNum", JobNum)
Dim ds As New DataSet
con.Open()
da.Fill(ds, "data")
Cup_Part = ds.Tables("data").Rows(0).Item("Assembly#")
Pallet = ds.Tables("data").Rows(0).Item("Pallet")
PalletQty = ds.Tables("data").Rows(0).Item("PalletAmount")
Serial = ds.Tables("Data").Rows(0).Item("Serial")
Cup_Mfg_Date = ds.Tables("Data").Rows(0).Item("Cup_Mfg_Date")
con.Close()
BC2 = "*" & Cup_Mfg_Date & Serial & "*"
Dim BC As New STROKESCRIBECLSLib.StrokeScribeClass
BC.Alphabet = CODE128
BC.Text = Cup_Part
Dim QtyBC As New STROKESCRIBECLSLib.StrokeScribeClass
QtyBC.Alphabet = CODE128
QtyBC.Text = PalletQty
Dim BCW As Integer = BC.BitmapW
Dim BCH As Integer = BCW / 4
Dim BCWQ As Integer = QtyBC.BitmapW
Dim BCHQ As Integer = BCWQ / 4
Dim olepicture As stdole.StdPicture
olepicture = BC.GetPictureHandle(BMP, BCW, 34)
Dim olepictureQty As stdole.StdPicture
olepictureQty = QtyBC.GetPictureHandle(BMP, BCWQ, 34)
Dim HLabelFont As System.Drawing.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)
Dim LabelFont As System.Drawing.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)
Dim LabelFont25 As System.Drawing.Font = New System.Drawing.Font("Arial", 8, FontStyle.Regular)
Dim LabelBold As System.Drawing.Font = New System.Drawing.Font("Arial", 10, FontStyle.Bold)
Dim PalletFont As System.Drawing.Font = New System.Drawing.Font("Arial", 20, FontStyle.Bold)
Dim MyPen As New Pen(Color.Black, 3)
Using HLabelFont
e.Graphics.DrawString(AssemblyText, HLabelFont, Brushes.Black, 20, 20)
e.Graphics.DrawString("PalletQty:", HLabelFont, Brushes.Black, 235, 65)
End Using
Using LabelBold
e.Graphics.DrawString("Cup", LabelBold, Brushes.Black, 20, 52)
e.Graphics.DrawString("Date", LabelBold, Brushes.Black, 20, 65)
e.Graphics.DrawString("Serial #", LabelBold, Brushes.Black, 70, 65)
e.Graphics.DrawString("Pallet #:", LabelBold, Brushes.Black, 320, 130)
End Using
Using PalletFont
e.Graphics.DrawString(Pallet, PalletFont, Brushes.Black, 290, 155)
End Using
If PalletQty <= 16 Then
For Each row As DataRow In ds.Tables(0).Rows
Serial = row("Serial")
Cup_Mfg_Date = row("Cup_Mfg_Date")
'Using LabelFont
e.Graphics.DrawString(Cup_Mfg_Date, LabelFont, Brushes.Black, 20, (80 + rh))
e.Graphics.DrawString(Serial, LabelFont, Brushes.Black, 70, (80 + rh))
Dim LongBC As New STROKESCRIBECLSLib.StrokeScribeClass
LongBC.Alphabet = CODE128
LongBC.Text = Cup_Mfg_Date & "Z" & Serial
LongBC.ShowText = False
Dim BCWL As Integer = LongBC.BitmapW
Dim BCHL As Integer = BCWL / 10
Dim olepictureLong As stdole.StdPicture
olepictureLong = LongBC.GetPictureHandle(BMP, BCWL, BCHL)
Dim imgl As Image
imgl = Image.FromHbitmap(olepictureLong.Handle)
e.Graphics.DrawImage(imgl, 140, (80 + rh))
rh = rh + 25
Next
Else
For Each row As DataRow In ds.Tables("Data").Rows
Serial = row("Serial")
Cup_Mfg_Date = row("Cup_Mfg_Date")
e.Graphics.DrawString(Cup_Mfg_Date, LabelFont25, Brushes.Black, 20, (80 + rh))
e.Graphics.DrawString(Serial, LabelFont25, Brushes.Black, 70, (80 + rh))
Dim LongBC As New STROKESCRIBECLSLib.StrokeScribeClass
LongBC.Alphabet = CODE128
LongBC.Text = Cup_Mfg_Date & "Z" & Serial
LongBC.ShowText = False
Dim BCWL As Integer = LongBC.BitmapW
Dim BCHL As Integer = BCWL / 16
Dim olepictureLong As stdole.StdPicture
olepictureLong = LongBC.GetPictureHandle(BMP, BCWL, BCHL)
Dim imgl As Image
imgl = Image.FromHbitmap(olepictureLong.Handle)
e.Graphics.DrawImage(imgl, 140, (80 + rh))
rh = rh + 16
Next
End If
Dim img As Image
img = Image.FromHbitmap(olepicture.Handle)
e.Graphics.DrawImage(img, 90, 20)
Dim QtyImg As Image
QtyImg = Image.FromHbitmap(olepictureQty.Handle)
e.Graphics.DrawImage(QtyImg, 315, 60)
End Using
End Sub
答案 0 :(得分:0)
为什么不尝试:
LongBC.Text = row("Cup_Mfg_Date").ToString.Trim() & "Z" & row("Serial").ToString.Trim()