123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- Public Class Frm_01_retan_chem_to_k3
- Private Sub Frm_01_retan_chem_to_k3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.MdiParent = FrmMDI : Me.WindowState = 2 : Me.AutoScroll = True
- FrmMDI.WindowState = FormWindowState.Maximized
- End Sub
- Private Sub Frm_01_retan_chem_to_k3_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
- Dim Str As String = Application.StartupPath : Application.DoEvents()
- Dim filePath As String = Str & "\HFK3MCL.xlsx"
- If IO.File.Exists(filePath) Then : Else : My.Computer.Network.DownloadFile(Target & "HFK3MCL.xlsx", filePath, "", "", False, 10000, True) : End If
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 水场查询_bt.Click
- Dim ds1 As New DataSet
- 主表_dgv.DataSource = Nothing : ds1.Clear()
- 主表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 主表_dgv.ColumnHeadersHeight = 30 : 主表_dgv.AllowUserToAddRows = False : 主表_dgv.RowTemplate.Height = 25
- SQL_染色領料清單(String.Format("{0:d}", 開始_dtp.Value), String.Format("{0:d}", 結束_dtp.Value))
- da.Fill(ds1) : 主表_dgv.DataSource = ds1.Tables(0) : conn.Close()
- 主表_dgv.Columns(0).FillWeight = 100 : 主表_dgv.Columns(1).FillWeight = 100 : 主表_dgv.Columns(2).FillWeight = 80
- 主表_dgv.Columns(3).FillWeight = 250 : 主表_dgv.Columns(4).FillWeight = 80
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 涂饰查询_bt.Click
- MsgBox("系统建置中!!") : Exit Sub
- Dim ds1 As New DataSet
- 主表_dgv.DataSource = Nothing : ds1.Clear()
- 主表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 主表_dgv.ColumnHeadersHeight = 30 : 主表_dgv.AllowUserToAddRows = False : 主表_dgv.RowTemplate.Height = 25
- SQL_塗飾領料清單(String.Format("{0:d}", 開始_dtp.Value), String.Format("{0:d}", 結束_dtp.Value))
- da.Fill(ds1) : 主表_dgv.DataSource = ds1.Tables(0) : conn.Close()
- 主表_dgv.Columns(0).FillWeight = 150 : 主表_dgv.Columns(1).FillWeight = 200 : 主表_dgv.Columns(2).FillWeight = 120
- 主表_dgv.Columns(3).FillWeight = 300 : 主表_dgv.Columns(4).FillWeight = 120
- End Sub
- Private Sub dgv1_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles 主表_dgv.CellMouseUp
- Dim ds1 As New DataSet
- 明細_dgv.DataSource = Nothing : ds1.Clear()
- 明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 明細_dgv.ColumnHeadersHeight = 30 : 明細_dgv.AllowUserToAddRows = False : 明細_dgv.RowTemplate.Height = 25
- SQL_染色領料明細清單(主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("工艺").Value, 主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("日期").Value,
- 主表_dgv.Rows(主表_dgv.CurrentRow.Index).Cells("卡号").Value)
- da.Fill(ds1) : 明細_dgv.DataSource = ds1.Tables(0) : conn.Close()
- 明細_dgv.Columns(0).FillWeight = 80 : 明細_dgv.Columns(1).FillWeight = 200 : 明細_dgv.Columns(2).FillWeight = 120
- 明細_dgv.Columns(3).FillWeight = 80 : 明細_dgv.Columns(4).FillWeight = 80 : 明細_dgv.Columns(5).FillWeight = 80
- 明細_dgv.Columns(6).FillWeight = 200 : 明細_dgv.Columns("系统品名").FillWeight = 200
- 明細_dgv.Columns("系统代码").FillWeight = 100
- 明細_dgv.Columns("d1").Visible = False : 明細_dgv.Columns("d2").Visible = False
- 明細_dgv.Columns("d3").Visible = False : 明細_dgv.Columns("d4").Visible = False
- 明細_dgv.Columns("d5").Visible = False : 明細_dgv.Columns("d6").Visible = False
- 明細_dgv.Columns("d7").Visible = False : 明細_dgv.Columns("d8").Visible = False
- 明細_dgv.Columns("d9").Visible = False : 明細_dgv.Columns("filename").Visible = False
- End Sub
- Private Sub 明細_dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles 明細_dgv.RowPostPaint
- If e.RowIndex + 1 > 明細_dgv.Rows.Count - 1 Then Exit Sub
- If 明細_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "PF" Then : Dim aa As String : aa = "" : End If
- If 明細_dgv.Rows(e.RowIndex + 1).Cells("化料名称").Value Is Nothing Then Exit Sub
- Dim linePen As New Pen(Color.Red, 2)
- If e.RowIndex = 明細_dgv.Rows.Count - 1 Then
- Dim startX As Integer = IIf(明細_dgv.RowHeadersVisible, 明細_dgv.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + 明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 明細_dgv.HorizontalScrollingOffset - 10
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
- End If
- If 明細_dgv.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
- Dim startX As Integer = IIf(明細_dgv.RowHeadersVisible, 明細_dgv.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + 明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 明細_dgv.HorizontalScrollingOffset - 10
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- End Sub
- Private Sub 水场导出_tb_Click(sender As Object, e As EventArgs) Handles 水场导出_tb.Click
- Dim aa As String = 起始單號_tb.Text : Dim my_card As String = ""
- If aa = "" Then : MsgBox("请输入起始单号") : Exit Sub : End If
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
- Dim file_name As String = "" : Dim file_name1 As String = ""
- Dim my_weight As Double = 0 : Dim a As Integer = 0 : Dim my_count As Integer = 0 : Dim my_x As Integer = 0
- xlApp = CreateObject("Excel.Application") : xlApp.Visible = True : xlApp.DisplayAlerts = False
- Dim excelFilePath As String = System.IO.Path.Combine(Application.StartupPath, "HFK3MCL.xlsx")
- xlBook = xlApp.Workbooks.Open(excelFilePath, , True) : xlBook.Activate()
- Dim dt2 As New DataTable
- For i = 1 To xlApp.Worksheets.Count
- If xlApp.Workbooks(1).Worksheets(i).name = "sheet1" Then : xlSheet = xlApp.Workbooks(1).Worksheets(i) : xlSheet.Activate() : Exit For : End If
- Next
- Dim my_no As String = "SCLL-2099-00000" : Dim dt_out As New DataTable
- SQL1 = "SELECT outdate, card FROM HT_Retan_Chem_Out
- WHERE (outdate BETWEEN '" & String.Format("{0:d}", 開始_dtp.Value) & "' AND '" & String.Format("{0:d}", 結束_dtp.Value) & "')
- GROUP BY outdate, card ORDER BY outdate, card"
- cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out) : Dim no As Integer = 0
- For x = 0 To dt_out.Rows.Count - 1 '-----------loop
- Dim dt_out_detail As New DataTable
- SQL1 = "SELECT outdate, chem_code, chem_name, chem_weight, RCP_NAME, SUBSTRING(CARD, 1, CHARINDEX(' ', CARD) - 1) AS CARD
- FROM HT_Retan_Chem_Out
- WHERE outdate = '" & dt_out.Rows(x).Item("outdate") & "' AND card = '" & dt_out.Rows(x).Item("card") & "' AND chem_code IS NOT NULL
- ORDER BY item"
- cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out_detail)
- xlSheet.Cells(no + 4, 1) = my_no & x + 1 + Val(起始單號_tb.Text) : xlSheet.Cells(no + 4, 2) = dt_out.Rows(x).Item("outdate")
- For y = 0 To dt_out_detail.Rows.Count - 1
- xlSheet.Cells(no + 4, 5) = dt_out_detail.Rows(y).Item("RCP_NAME")
- xlSheet.Cells(no + 4, 6) = dt_out_detail.Rows(y).Item("chem_code")
- xlSheet.Cells(no + 4, 7) = dt_out_detail.Rows(y).Item("chem_name")
- xlSheet.Cells(no + 4, 8) = "'化料水场仓" : xlSheet.Cells(no + 4, 9) = "'kg"
- xlSheet.Cells(no + 4, 10) = dt_out_detail.Rows(y).Item("chem_weight")
- xlSheet.Cells(no + 4, 11) = dt_out_detail.Rows(y).Item("card") : no += 1
- Next
- Next
- Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) ' 取得桌面路徑
- Dim newFileName As String = "K3領料單-染色-" & DateTime.Now.ToString("yyyyMMdd") & ".xlsx" ' 產生新檔案名稱,例如:K3領料單-20250315.xlsx
- Dim newFilePath As String = System.IO.Path.Combine(desktopPath, newFileName)
- xlBook.SaveAs(newFilePath) ' 另存新檔
- xlBook.Close(False) : xlApp.Quit() ' 關閉 Excel
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' 釋放 COM 物件
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
- MsgBox("已另存新檔:" & newFilePath, MsgBoxStyle.Information)
- End Sub
- Private Sub 涂饰导出_bt_Click(sender As Object, e As EventArgs) Handles 涂饰导出_bt.Click
- MsgBox("系统建置中!!") : Exit Sub
- Dim aa As String = 起始單號_tb.Text : Dim my_card As String = ""
- If aa = "" Then : MsgBox("请输入起始单号") : Exit Sub : End If
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
- Dim file_name As String = "" : Dim file_name1 As String = "" : Dim my_weight As Double = 0
- Dim a As Integer = 0 : Dim my_count As Integer = 0 : Dim my_x As Integer = 0
- xlApp = CreateObject("Excel.Application") : xlApp.Visible = True : xlApp.DisplayAlerts = False
- Dim excelFilePath As String = System.IO.Path.Combine(Application.StartupPath, "HFK3MCL.xlsx")
- xlBook = xlApp.Workbooks.Open(excelFilePath, , True) : xlBook.Activate()
- Dim dt2 As New DataTable
- For i = 1 To xlApp.Worksheets.Count
- If xlApp.Workbooks(1).Worksheets(i).name = "sheet1" Then : xlSheet = xlApp.Workbooks(1).Worksheets(i) : xlSheet.Activate() : Exit For : End If
- Next
- Dim my_no As String = "SCLL-2099-10000" : Dim dt_out As New DataTable
- SQL1 = "SELECT date,out_no FROM HT_finish_out
- WHERE (date BETWEEN '" & String.Format("{0:d}", 開始_dtp.Value) & "' AND '" & String.Format("{0:d}", 結束_dtp.Value) & "')
- GROUP BY date, out_no ORDER BY date, out_no"
- cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out) : Dim no As Integer = 0
- For x = 0 To dt_out.Rows.Count - 1 '-----------loop
- Dim dt_out_detail As New DataTable
- 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'水'"
- cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(dt_out_detail)
- xlSheet.Cells(no + 4, 1) = my_no & x + 1 + Val(起始單號_tb.Text)
- xlSheet.Cells(no + 4, 2) = dt_out.Rows(x).Item("date")
- For y = 0 To dt_out_detail.Rows.Count - 1
- xlSheet.Cells(no + 4, 5) = dt_out_detail.Rows(y).Item("RCP_NAME")
- xlSheet.Cells(no + 4, 6) = dt_out_detail.Rows(y).Item("chem_code")
- xlSheet.Cells(no + 4, 7) = dt_out_detail.Rows(y).Item("chem_name")
- xlSheet.Cells(no + 4, 8) = "'化料涂饰仓" : xlSheet.Cells(no + 4, 9) = "'kg"
- xlSheet.Cells(no + 4, 10) = dt_out_detail.Rows(y).Item("chem_weight")
- xlSheet.Cells(no + 4, 11) = dt_out_detail.Rows(y).Item("card") : no += 1
- Next
- Next
- Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) ' 取得桌面路徑
- Dim newFileName As String = "K3领料单-涂饰-" & DateTime.Now.ToString("yyyyMMdd") & ".xlsx" ' 產生新檔案名稱,例如:K3領料單-20250315.xlsx
- Dim newFilePath As String = System.IO.Path.Combine(desktopPath, newFileName)
- xlBook.SaveAs(newFilePath) ' 另存新檔
- xlBook.Close(False) : xlApp.Quit() ' 關閉 Excel
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' 釋放 COM 物件
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
- MsgBox("已另存新檔:" & newFilePath, MsgBoxStyle.Information)
- End Sub
- End Class
|