|
|
|
วิธีการ แนวทาง โค้ด VB.NET PRINT TEXT ด้วย พรินเตอร์ แบบ ด็อทเมตริกซ์ |
|
|
|
|
|
|
|
Code (VB.NET)
Private Sub btn_print_Click(sender As System.Object, e As System.EventArgs) Handles btn_print.Click
' MsgBox(DataGridView1.CurrentRow.Cells(0).Value)
Dim ds As New DataSet
Dim dt As New DataTable
Dim sql As String
sql = "SELECT A.LOCATION_NO , CONVERT(VARCHAR,A.PROD_DATE,103) PROD_DATE , CONVERT(VARCHAR,A.EXP_DATE,103) EXP_DATE , A.GODOWN_NO , cast(convert(varchar, A.PRODUCT_NO) as char(10)) PRODUCT_NO , " _
& "B.FAC_PRODUCT_NO FAC_NO , A.RECV_DATE ,cast(convert(varchar, A.DOC_NO) as char(15)) DOC_NO , A.DOOR_NO , A.ITEM_STATUS ,cast(convert(varchar,B.PALLET_ROW) as char(2)) + 'X' + cast(convert(varchar,B.PALLET_LEVEL) as char(2)) PALLET , " _
& "B.TOTAL_PALLET, A.QTY_CASE, cast(convert(varchar, B.PRODUCT_NAME) as char(100)) PRODUCT_NAME, A.SUPP_NO FROM ICC_RCV A LEFT JOIN ICC_PRODUCT_MAST B ON A.PRODUCT_NO = B.PRODUCT_NO AND A.GODOWN_NO = B.GODOWN_NO " _
& "WHERE A.DOC_NO = '" & DataGridView1.CurrentRow.Cells(1).Value & "'"
da = New SqlDataAdapter(sql, frm_main.conn)
da.Fill(ds, "ss")
If ds.Tables(0).Rows.Count > 0 Then
Dim filePath As String = String.Format("C:\test\rcv_tmp.txt")
Dim MyFile As New FileInfo(filePath) 'เช็คไฟล์ txt ซ้ำ
'*** Create Folder ***'
Dim DirInfo As New DirectoryInfo("C:\test")
If Not DirInfo.Exists Then
DirInfo.Create()
Else
MyFile.Delete()
End If
For k = 0 To ds.Tables(0).Rows.Count - 1
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim t_str As String
Dim t_str2 As String
str1 = ""
str2 = ""
str3 = ""
t_str2 = ""
For j = 0 To Len(ds.Tables(0).Rows(k).Item(0)) - 1
t_str = ds.Tables(0).Rows(k).Item(0).Substring(j, 1)
If IsNumeric(t_str) = True Or t_str = "-" Then
str1 = str1 & """" & ds.Tables(0).Rows(k).Item(0).Substring(j, 1) & ""","
Else
str1 = str1 & ds.Tables(0).Rows(k).Item(0).Substring(j, 1) & ","
End If
str2 = str2 & "'" & ds.Tables(0).Rows(k).Item(0).Substring(j, 1) & "',"
If t_str2.Split(t_str).Length - 1 = 0 Then
If IsNumeric(t_str) = True Or t_str = "-" Then
t_str2 = t_str2 & """" & ds.Tables(0).Rows(k).Item(0).Substring(j, 1) & ""","
Else
t_str2 = t_str2 & ds.Tables(0).Rows(k).Item(0).Substring(j, 1) & ","
End If
End If
Next j
str1 = str1.Substring(0, Len(str1) - 1)
str2 = str2.Substring(0, Len(str2) - 1)
str3 = t_str2.Substring(0, Len(t_str2) - 1)
'--------------
Dim ds2 As New DataSet
Dim sql2 As String
Dim i As Integer = 0
Using writer As New StreamWriter(filePath, True, System.Text.Encoding.Default)
sql2 = " select " & str1 & " from (select * from char_map where char_key in (" & str2 & ")) as tb_char pivot (max(char_col) for char_key in (" & str3 & ")) p "
da2 = New SqlDataAdapter(sql2, frm_main.conn)
da2.Fill(ds2, "ss")
If ds2.Tables(0).Rows.Count > 0 Then
writer.WriteLine(" ")
writer.WriteLine(" ")
writer.WriteLine(" ")
For i = 1 To 13
'writer.WriteLine(ds2.Tables(0).Rows(i - 1).Item(0) & " " & ds2.Tables(0).Rows(i - 1).Item(1) & " " & ds2.Tables(0).Rows(i - 1).Item(2) & " " & ds2.Tables(0).Rows(i - 1).Item(3) & " " & ds2.Tables(0).Rows(i - 1).Item(4) & " " & ds2.Tables(0).Rows(i - 1).Item(5) & " " & ds2.Tables(0).Rows(i - 1).Item(6) & " " & ds2.Tables(0).Rows(i - 1).Item(7))
writer.WriteLine(ds2.Tables(0).Rows(i - 1).Item(0) & " " & ds2.Tables(0).Rows(i - 1).Item(1) & ds2.Tables(0).Rows(i - 1).Item(2) & ds2.Tables(0).Rows(i - 1).Item(3) & " " & ds2.Tables(0).Rows(i - 1).Item(4) & ds2.Tables(0).Rows(i - 1).Item(5) & ds2.Tables(0).Rows(i - 1).Item(6) & " " & ds2.Tables(0).Rows(i - 1).Item(7))
Next i
writer.WriteLine(" ")
writer.WriteLine(" ")
writer.WriteLine("PROD.DATE " & ds.Tables(0).Rows(k).Item(1) & vbTab & vbTab & vbTab & " EXP.DATE " & ds.Tables(0).Rows(k).Item(2) & vbTab & vbTab & vbTab & vbTab & " GODOWN " & ds.Tables(0).Rows(k).Item(3))
writer.WriteLine(" ")
writer.WriteLine("PROD.NO " & ds.Tables(0).Rows(k).Item(4) & vbTab & vbTab & vbTab & " FAC.NO ")
writer.WriteLine(" ")
writer.WriteLine("RECV.DATE " & ds.Tables(0).Rows(k).Item(6) & vbTab & vbTab & vbTab & " REF.NO " & ds.Tables(0).Rows(k).Item(7) & vbTab & vbTab & vbTab & vbTab & " DOOR.NO " & ds.Tables(0).Rows(k).Item(8) & " STS. " & ds.Tables(0).Rows(k).Item(9))
writer.WriteLine(" ")
writer.WriteLine("PALLET " & ds.Tables(0).Rows(k).Item(10) & " = " & ds.Tables(0).Rows(k).Item(11) & vbTab & vbTab & vbTab & " QTY.IN PALLET " & ds.Tables(0).Rows(k).Item(12) & vbTab & vbTab & vbTab & vbTab & " STICKER NO " & k + 1)
writer.WriteLine(" ")
writer.WriteLine("PRODUCT NAME " & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & " SUPP.NAME " & ds.Tables(0).Rows(k).Item(14))
writer.WriteLine(" ")
writer.WriteLine(ds.Tables(0).Rows(k).Item(13))
writer.WriteLine(" ")
'----------- end page
writer.WriteLine(" ")
writer.WriteLine(" ")
writer.WriteLine(" ")
End If
writer.Dispose()
writer.Close()
End Using
Next k
Shell("print /d:LPT2 C:\test\rcv_tmp.txt", AppWinStyle.Hide)
End If
End Sub
|
|
|
|
|
Date :
2014-10-29 16:16:10 |
By :
jaypang |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|