Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Frm_01_retan_chem_to_k3.vb 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Public Class Frm_01_retan_chem_to_k3
  2. Private Sub Frm_01_retan_chem_to_k3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3. Me.MdiParent = FrmMDI : Me.WindowState = 2 : Me.AutoScroll = True
  4. FrmMDI.WindowState = FormWindowState.Maximized
  5. End Sub
  6. Private Sub Frm_01_retan_chem_to_k3_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  7. Dim Str As String = Application.StartupPath : Application.DoEvents()
  8. Dim filePath As String = Str & "\HFK3MCL.xlsx"
  9. If IO.File.Exists(filePath) Then : Else : My.Computer.Network.DownloadFile(Target & "HFK3MCL.xlsx", filePath, "", "", False, 10000, True) : End If
  10. End Sub
  11. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 水场查询_bt.Click
  12. Dim ds1 As New DataSet
  13. 主表_dgv.DataSource = Nothing : ds1.Clear()
  14. 主表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  15. 主表_dgv.ColumnHeadersHeight = 30 : 主表_dgv.AllowUserToAddRows = False : 主表_dgv.RowTemplate.Height = 25
  16. SQL_染色領料清單(String.Format("{0:d}", 開始_dtp.Value), String.Format("{0:d}", 結束_dtp.Value))
  17. da.Fill(ds1) : 主表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  18. 主表_dgv.Columns(0).FillWeight = 100 : 主表_dgv.Columns(1).FillWeight = 100 : 主表_dgv.Columns(2).FillWeight = 80
  19. 主表_dgv.Columns(3).FillWeight = 250 : 主表_dgv.Columns(4).FillWeight = 80
  20. End Sub
  21. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 涂饰查询_bt.Click
  22. MsgBox("系统建置中!!") : Exit Sub
  23. Dim ds1 As New DataSet
  24. 主表_dgv.DataSource = Nothing : ds1.Clear()
  25. 主表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  26. 主表_dgv.ColumnHeadersHeight = 30 : 主表_dgv.AllowUserToAddRows = False : 主表_dgv.RowTemplate.Height = 25
  27. SQL_塗飾領料清單(String.Format("{0:d}", 開始_dtp.Value), String.Format("{0:d}", 結束_dtp.Value))
  28. da.Fill(ds1) : 主表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  29. 主表_dgv.Columns(0).FillWeight = 150 : 主表_dgv.Columns(1).FillWeight = 200 : 主表_dgv.Columns(2).FillWeight = 120
  30. 主表_dgv.Columns(3).FillWeight = 300 : 主表_dgv.Columns(4).FillWeight = 120
  31. End Sub
  32. Private Sub dgv1_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles 主表_dgv.CellMouseUp
  33. Dim ds1 As New DataSet
  34. 明細_dgv.DataSource = Nothing : ds1.Clear()
  35. 明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  36. 明細_dgv.ColumnHeadersHeight = 30 : 明細_dgv.AllowUserToAddRows = False : 明細_dgv.RowTemplate.Height = 25
  37. SQL_染色領料明細清單(主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("工艺").Value, 主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("日期").Value,
  38. 主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("卡号").Value)
  39. da.Fill(ds1) : 明細_dgv.DataSource = ds1.Tables(0) : conn.Close()
  40. 明細_dgv.Columns(0).FillWeight = 80 : 明細_dgv.Columns(1).FillWeight = 200 : 明細_dgv.Columns(2).FillWeight = 120
  41. 明細_dgv.Columns(3).FillWeight = 80 : 明細_dgv.Columns(4).FillWeight = 80 : 明細_dgv.Columns(5).FillWeight = 80
  42. 明細_dgv.Columns(6).FillWeight = 200 : 明細_dgv.Columns("系统品名").FillWeight = 200
  43. 明細_dgv.Columns("系统代码").FillWeight = 100
  44. 明細_dgv.Columns("d1").Visible = False : 明細_dgv.Columns("d2").Visible = False
  45. 明細_dgv.Columns("d3").Visible = False : 明細_dgv.Columns("d4").Visible = False
  46. 明細_dgv.Columns("d5").Visible = False : 明細_dgv.Columns("d6").Visible = False
  47. 明細_dgv.Columns("d7").Visible = False : 明細_dgv.Columns("d8").Visible = False
  48. 明細_dgv.Columns("d9").Visible = False : 明細_dgv.Columns("filename").Visible = False
  49. End Sub
  50. Private Sub 明細_dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles 明細_dgv.RowPostPaint
  51. If e.RowIndex + 1 > 明細_dgv.Rows.Count - 1 Then Exit Sub
  52. If 明細_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "PF" Then : Dim aa As String : aa = "" : End If
  53. If 明細_dgv.Rows(e.RowIndex + 1).Cells("化料名称").Value Is Nothing Then Exit Sub
  54. Dim linePen As New Pen(Color.Red, 2)
  55. If e.RowIndex = 明細_dgv.Rows.Count - 1 Then
  56. Dim startX As Integer = IIf(明細_dgv.RowHeadersVisible, 明細_dgv.RowHeadersWidth, 0)
  57. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  58. Dim endX As Integer = startX + 明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 明細_dgv.HorizontalScrollingOffset - 10
  59. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  60. End If
  61. If 明細_dgv.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  62. Dim startX As Integer = IIf(明細_dgv.RowHeadersVisible, 明細_dgv.RowHeadersWidth, 0)
  63. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  64. Dim endX As Integer = startX + 明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 明細_dgv.HorizontalScrollingOffset - 10
  65. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  66. End If
  67. End Sub
  68. Private Sub 水场导出_tb_Click(sender As Object, e As EventArgs) Handles 水场导出_tb.Click
  69. Dim aa As String = 起始單號_tb.Text : Dim my_card As String = ""
  70. If aa = "" Then : MsgBox("请输入起始单号") : Exit Sub : End If
  71. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  72. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  73. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  74. Dim file_name As String = "" : Dim file_name1 As String = ""
  75. Dim my_weight As Double = 0 : Dim a As Integer = 0 : Dim my_count As Integer = 0 : Dim my_x As Integer = 0
  76. xlApp = CreateObject("Excel.Application") : xlApp.Visible = True : xlApp.DisplayAlerts = False
  77. Dim excelFilePath As String = System.IO.Path.Combine(Application.StartupPath, "HFK3MCL.xlsx")
  78. xlBook = xlApp.Workbooks.Open(excelFilePath, , True) : xlBook.Activate()
  79. Dim dt2 As New DataTable
  80. For i = 1 To xlApp.Worksheets.Count
  81. If xlApp.Workbooks(1).Worksheets(i).name = "sheet1" Then : xlSheet = xlApp.Workbooks(1).Worksheets(i) : xlSheet.Activate() : Exit For : End If
  82. Next
  83. Dim my_no As String = "SCLL-2099-00000" : Dim dt_out As New DataTable
  84. SQL1 = "SELECT outdate, card FROM HT_Retan_Chem_Out
  85. WHERE (outdate BETWEEN '" & String.Format("{0:d}", 開始_dtp.Value) & "' AND '" & String.Format("{0:d}", 結束_dtp.Value) & "')
  86. GROUP BY outdate, card ORDER BY outdate, card"
  87. cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out) : Dim no As Integer = 0
  88. For x = 0 To dt_out.Rows.Count - 1 '-----------loop
  89. Dim dt_out_detail As New DataTable
  90. SQL1 = "SELECT outdate, chem_code, chem_name, chem_weight, RCP_NAME, SUBSTRING(CARD, 1, CHARINDEX(' ', CARD) - 1) AS CARD
  91. FROM HT_Retan_Chem_Out
  92. WHERE outdate = '" & dt_out.Rows(x).Item("outdate") & "' AND card = '" & dt_out.Rows(x).Item("card") & "' AND chem_code IS NOT NULL
  93. ORDER BY item"
  94. cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out_detail)
  95. xlSheet.Cells(no + 4, 1) = my_no & x + 1 + Val(起始單號_tb.Text) : xlSheet.Cells(no + 4, 2) = dt_out.Rows(x).Item("outdate")
  96. For y = 0 To dt_out_detail.Rows.Count - 1
  97. xlSheet.Cells(no + 4, 5) = dt_out_detail.Rows(y).Item("RCP_NAME")
  98. xlSheet.Cells(no + 4, 6) = dt_out_detail.Rows(y).Item("chem_code")
  99. xlSheet.Cells(no + 4, 7) = dt_out_detail.Rows(y).Item("chem_name")
  100. xlSheet.Cells(no + 4, 8) = "'化料水场仓" : xlSheet.Cells(no + 4, 9) = "'kg"
  101. xlSheet.Cells(no + 4, 10) = dt_out_detail.Rows(y).Item("chem_weight")
  102. xlSheet.Cells(no + 4, 11) = dt_out_detail.Rows(y).Item("card") : no += 1
  103. Next
  104. Next
  105. Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) ' 取得桌面路徑
  106. Dim newFileName As String = "K3領料單-染色-" & DateTime.Now.ToString("yyyyMMdd") & ".xlsx" ' 產生新檔案名稱,例如:K3領料單-20250315.xlsx
  107. Dim newFilePath As String = System.IO.Path.Combine(desktopPath, newFileName)
  108. xlBook.SaveAs(newFilePath) ' 另存新檔
  109. xlBook.Close(False) : xlApp.Quit() ' 關閉 Excel
  110. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' 釋放 COM 物件
  111. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  112. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  113. MsgBox("已另存新檔:" & newFilePath, MsgBoxStyle.Information)
  114. End Sub
  115. Private Sub 涂饰导出_bt_Click(sender As Object, e As EventArgs) Handles 涂饰导出_bt.Click
  116. MsgBox("系统建置中!!") : Exit Sub
  117. Dim aa As String = 起始單號_tb.Text : Dim my_card As String = ""
  118. If aa = "" Then : MsgBox("请输入起始单号") : Exit Sub : End If
  119. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  120. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  121. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  122. Dim file_name As String = "" : Dim file_name1 As String = "" : Dim my_weight As Double = 0
  123. Dim a As Integer = 0 : Dim my_count As Integer = 0 : Dim my_x As Integer = 0
  124. xlApp = CreateObject("Excel.Application") : xlApp.Visible = True : xlApp.DisplayAlerts = False
  125. Dim excelFilePath As String = System.IO.Path.Combine(Application.StartupPath, "HFK3MCL.xlsx")
  126. xlBook = xlApp.Workbooks.Open(excelFilePath, , True) : xlBook.Activate()
  127. Dim dt2 As New DataTable
  128. For i = 1 To xlApp.Worksheets.Count
  129. If xlApp.Workbooks(1).Worksheets(i).name = "sheet1" Then : xlSheet = xlApp.Workbooks(1).Worksheets(i) : xlSheet.Activate() : Exit For : End If
  130. Next
  131. Dim my_no As String = "SCLL-2099-10000" : Dim dt_out As New DataTable
  132. SQL1 = "SELECT date,out_no FROM HT_finish_out
  133. WHERE (date BETWEEN '" & String.Format("{0:d}", 開始_dtp.Value) & "' AND '" & String.Format("{0:d}", 結束_dtp.Value) & "')
  134. GROUP BY date, out_no ORDER BY date, out_no"
  135. cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out) : Dim no As Integer = 0
  136. For x = 0 To dt_out.Rows.Count - 1 '-----------loop
  137. Dim dt_out_detail As New DataTable
  138. SQL1 = "SELECT * FROM HT_finish_out WHERE date = '" & dt_out.Rows(x).Item("date") & "' AND out_no = '" & dt_out.Rows(x).Item("card") & "' AND chem_name <> N'水'"
  139. cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out_detail)
  140. xlSheet.Cells(no + 4, 1) = my_no & x + 1 + Val(起始單號_tb.Text)
  141. xlSheet.Cells(no + 4, 2) = dt_out.Rows(x).Item("date")
  142. For y = 0 To dt_out_detail.Rows.Count - 1
  143. xlSheet.Cells(no + 4, 5) = dt_out_detail.Rows(y).Item("RCP_NAME")
  144. xlSheet.Cells(no + 4, 6) = dt_out_detail.Rows(y).Item("chem_code")
  145. xlSheet.Cells(no + 4, 7) = dt_out_detail.Rows(y).Item("chem_name")
  146. xlSheet.Cells(no + 4, 8) = "'化料涂饰仓" : xlSheet.Cells(no + 4, 9) = "'kg"
  147. xlSheet.Cells(no + 4, 10) = dt_out_detail.Rows(y).Item("chem_weight")
  148. xlSheet.Cells(no + 4, 11) = dt_out_detail.Rows(y).Item("card") : no += 1
  149. Next
  150. Next
  151. Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) ' 取得桌面路徑
  152. Dim newFileName As String = "K3领料单-涂饰-" & DateTime.Now.ToString("yyyyMMdd") & ".xlsx" ' 產生新檔案名稱,例如:K3領料單-20250315.xlsx
  153. Dim newFilePath As String = System.IO.Path.Combine(desktopPath, newFileName)
  154. xlBook.SaveAs(newFilePath) ' 另存新檔
  155. xlBook.Close(False) : xlApp.Quit() ' 關閉 Excel
  156. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' 釋放 COM 物件
  157. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  158. System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  159. MsgBox("已另存新檔:" & newFilePath, MsgBoxStyle.Information)
  160. End Sub
  161. End Class