Option Strict Off Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle Imports Microsoft.Office.Interop.Excel.Constants Imports Microsoft.Office.Interop.Excel.XlBordersIndex Imports Microsoft.Office.Interop.Excel.XlLineStyle Imports Microsoft.Office.Interop.Excel.XlBorderWeight Imports Microsoft.Office.Interop.Excel.XlThemeFont Imports Microsoft.Office.Interop.Excel.XlThemeColor Imports Microsoft.Office.Interop.Excel.XlWindowState Public Class 機構組件零件BOM表 ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6, ds7 As New DataSet Dim 條件 As String Dim 加總1 As String = "0" : Dim 加總2 As String = "0" : Dim 加總3 As String = "0" Dim KE As Integer Private Sub 機構科目清單() DataGridView4.DataSource = Nothing : ds3.Clear() DataGridView4.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView4.ColumnHeadersHeight = 25 DataGridView4.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 品牌, 供應商, 科目, 類型 FROM 機構組件成本紀錄表 WHERE (科目 LIKE N'%" & ComboBox3.Text & "%') GROUP BY 品牌, 供應商, 科目, 類型 ORDER BY 類型" CmdSet_For_DGV() : da.Fill(ds3) : DataGridView4.DataSource = ds3.Tables(0) : conn.Close() If ComboBox3.Text <> "-請選擇-" Then : Set_grid4() : End If End Sub Private Sub 機構名稱清單() DataGridView5.DataSource = Nothing : ds4.Clear() DataGridView5.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView5.ColumnHeadersHeight = 25 DataGridView5.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 流水碼, 供應商, 品名 FROM 機構組件成本紀錄表 WHERE (類型 LIKE N'%" & ComboBox4.Text & "%') ORDER BY 流水碼" CmdSet_For_DGV() : da.Fill(ds4) : DataGridView5.DataSource = ds4.Tables(0) : conn.Close() Set_grid5() End Sub Private Sub 零組件清單() DataGridView6.DataSource = Nothing : ds5.Clear() DataGridView6.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView6.ColumnHeadersHeight = 25 DataGridView6.AllowUserToAddRows = False ConnOpen() If 條件 = "" Then SQL1 = "SELECT 機構組件零件BOM表.機構碼, 機構組件成本紀錄表.科目, 機構組件成本紀錄表.類型, 機構組件成本紀錄表.品名 FROM 機構組件零件BOM表 INNER JOIN 機構組件成本紀錄表" & " ON 機構組件零件BOM表.機構碼 = 機構組件成本紀錄表.流水碼 GROUP BY 機構組件零件BOM表.機構碼, 機構組件成本紀錄表.科目, 機構組件成本紀錄表.類型, " & "機構組件成本紀錄表.品名 ORDER BY 機構組件成本紀錄表.科目" Else SQL1 = "SELECT 機構組件零件BOM表.機構碼, 機構組件成本紀錄表.科目, 機構組件成本紀錄表.類型, 機構組件成本紀錄表.品名 FROM 機構組件零件BOM表 INNER JOIN 機構組件成本紀錄表 ON " & "機構組件零件BOM表.機構碼 = 機構組件成本紀錄表.流水碼 WHERE (機構組件成本紀錄表.流水碼 LIKE N'%" & 條件 & "%') OR (機構組件成本紀錄表.品牌 LIKE N'%" & 條件 & "%') " & "OR (機構組件成本紀錄表.供應商 LIKE N'%" & 條件 & "%') OR (機構組件成本紀錄表.科目 LIKE N'%" & 條件 & "%') OR (機構組件成本紀錄表.類型 LIKE N'%" & 條件 & "%') OR " & "(機構組件成本紀錄表.品名 LIKE N'%" & 條件 & "%') GROUP BY 機構組件零件BOM表.機構碼, 機構組件成本紀錄表.科目, 機構組件成本紀錄表.類型, 機構組件成本紀錄表.品名 ORDER BY " & "機構組件成本紀錄表.科目" End If CmdSet_For_DGV() : da.Fill(ds5) : DataGridView6.DataSource = ds5.Tables(0) : conn.Close() Set_grid6() : 條件 = "" End Sub Private Sub DGV2寫入前設定() DataGridView2.DataSource = Nothing : ds.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False ConnOpen() End Sub Private Sub DGV2寫入後設定() CmdSet_For_DGV() : da.Fill(ds) : DataGridView2.DataSource = ds.Tables(0) : conn.Close() Set_grid1() End Sub Private Sub 讀取零件清單() If PA = "" Then DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 零件成本紀錄表 ORDER BY 科目" Else DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 零件成本紀錄表 WHERE 品牌 like N'%" & PA & "%' OR 供應商 like N'%" & PA & "%' OR 科目 like N'%" & PA & "%' OR 品名 like N'%" & PA & "%' OR 型號及備註 like N'%" & PA & "%' OR 幣別 like N'%" & PA & "%' ORDER BY 科目" End If DGV2寫入後設定() End Sub Private Sub 讀取零組件清單() If PA = "" Then DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 零組件成本紀錄表 ORDER BY 科目" Else DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 零組件成本紀錄表 WHERE 品牌 like N'%" & PA & "%' OR 供應商 like N'%" & PA & "%' OR 科目 like N'%" & PA & "%' OR 品名 like N'%" & PA & "%' OR 型號及備註 like N'%" & PA & "%' OR 幣別 like N'%" & PA & "%' ORDER BY 科目" End If DGV2寫入後設定() End Sub Private Sub 讀取機構件清單() If PA = "" Then DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 機構件成本紀錄表 ORDER BY 科目" Else DGV2寫入前設定() SQL1 = "SELECT 流水碼, 品牌, 供應商, 科目, 品名, 型號及備註, 進貨單價, 幣別 FROM 機構件成本紀錄表 WHERE 品牌 like N'%" & PA & "%' OR 供應商 like N'%" & PA & "%' OR 科目 like N'%" & PA & "%' OR 品名 like N'%" & PA & "%' OR 型號及備註 like N'%" & PA & "%' OR 幣別 like N'%" & PA & "%' ORDER BY 科目" End If DGV2寫入後設定() End Sub Private Sub 讀取機構組件零件BOM表() DataGridView1.DataSource = Nothing : ds1.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 機構組件零件BOM表.機構碼, 機構組件零件BOM表.零件流水碼, 零件成本紀錄表.科目, 零件成本紀錄表.品名, 機構組件零件BOM表.數量, 零件成本紀錄表.型號及備註," & "ROUND(Convert(float, 機構組件零件BOM表.數量) * Convert(float, 零件成本紀錄表.進貨單價),2) AS 成本, 零件成本紀錄表.幣別, 零件成本紀錄表.品牌 FROM 機構組件零件BOM表 INNER JOIN 零件成本紀錄表 " & "ON 機構組件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 WHERE 機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "' ORDER BY 零件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds1) : DataGridView1.DataSource = ds1.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 機構組件零件BOM表.機構碼, 機構組件零件BOM表.零件流水碼, 零組件成本紀錄表.科目, 零組件成本紀錄表.品名, 機構組件零件BOM表.數量, 零組件成本紀錄表.型號及備註," & "ROUND(Convert(float, 機構組件零件BOM表.數量) * Convert(float, 零組件成本紀錄表.進貨單價),2) AS 成本, 零組件成本紀錄表.幣別, 零組件成本紀錄表.品牌 FROM 機構組件零件BOM表 INNER JOIN 零組件成本紀錄表 " & "ON 機構組件零件BOM表.零件流水碼 = 零組件成本紀錄表.流水碼 WHERE 機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "' ORDER BY 零組件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds1) : DataGridView1.DataSource = ds1.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 機構組件零件BOM表.機構碼, 機構組件零件BOM表.零件流水碼, 機構件成本紀錄表.科目, 機構件成本紀錄表.品名, 機構組件零件BOM表.數量, 機構件成本紀錄表.型號及備註," & "ROUND(Convert(float, 機構組件零件BOM表.數量) * Convert(float, 機構件成本紀錄表.進貨單價),2) AS 成本, 機構件成本紀錄表.幣別, 機構件成本紀錄表.品牌 FROM 機構組件零件BOM表 INNER JOIN 機構件成本紀錄表 " & "ON 機構組件零件BOM表.零件流水碼 = 機構件成本紀錄表.流水碼 WHERE 機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "' ORDER BY 機構件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds1) : DataGridView1.DataSource = ds1.Tables(0) : conn.Close() : dr.Close() DataGridView3.DataSource = Nothing : ds2.Clear() DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView3.ColumnHeadersHeight = 25 DataGridView3.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 零件成本紀錄表_1.科目, ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 零件成本紀錄表_1.進貨單價)), 2) AS 成本, " & "ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 零件成本紀錄表_1.進貨單價)) / (SELECT SUM(CONVERT(float, 機構組件零件BOM表.數量) * " & "CONVERT(float, 零件成本紀錄表.進貨單價)) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 零件成本紀錄表 ON 機構組件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 " & "WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')), 4) * 100 AS 百分比 FROM 機構組件零件BOM表 AS 機構組件零件BOM表_1 INNER JOIN 零件成本紀錄表 AS " & "零件成本紀錄表_1 ON 機構組件零件BOM表_1.零件流水碼 = 零件成本紀錄表_1.流水碼 WHERE (機構組件零件BOM表_1.機構碼 = '" & ComboBox1.Text & "') GROUP BY " & "零件成本紀錄表_1.科目 ORDER BY 零件成本紀錄表_1.科目" CmdSet_For_DGV() : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 零組件成本紀錄表_1.科目, ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 零組件成本紀錄表_1.進貨單價)), 2) AS 成本, " & "ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 零組件成本紀錄表_1.進貨單價)) / (SELECT SUM(CONVERT(float, 機構組件零件BOM表.數量) * " & "CONVERT(float, 零組件成本紀錄表.進貨單價)) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 零組件成本紀錄表 ON 機構組件零件BOM表.零件流水碼 = 零組件成本紀錄表.流水碼 " & "WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')), 4) * 100 AS 百分比 FROM 機構組件零件BOM表 AS 機構組件零件BOM表_1 INNER JOIN 零組件成本紀錄表 AS " & "零組件成本紀錄表_1 ON 機構組件零件BOM表_1.零件流水碼 = 零組件成本紀錄表_1.流水碼 WHERE (機構組件零件BOM表_1.機構碼 = '" & ComboBox1.Text & "') GROUP BY " & "零組件成本紀錄表_1.科目 ORDER BY 零組件成本紀錄表_1.科目" CmdSet_For_DGV() : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 機構件成本紀錄表_1.科目, ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 機構件成本紀錄表_1.進貨單價)), 2) AS 成本, " & "ROUND(SUM(CONVERT(float, 機構組件零件BOM表_1.數量) * CONVERT(float, 機構件成本紀錄表_1.進貨單價)) / (SELECT SUM(CONVERT(float, 機構組件零件BOM表.數量) * " & "CONVERT(float, 機構件成本紀錄表.進貨單價)) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 機構件成本紀錄表 ON 機構組件零件BOM表.零件流水碼 = 機構件成本紀錄表.流水碼 " & "WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')), 4) * 100 AS 百分比 FROM 機構組件零件BOM表 AS 機構組件零件BOM表_1 INNER JOIN 機構件成本紀錄表 AS " & "機構件成本紀錄表_1 ON 機構組件零件BOM表_1.零件流水碼 = 機構件成本紀錄表_1.流水碼 WHERE (機構組件零件BOM表_1.機構碼 = '" & ComboBox1.Text & "') GROUP BY " & "機構件成本紀錄表_1.科目 ORDER BY 機構件成本紀錄表_1.科目" CmdSet_For_DGV() : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT ROUND(SUM(CONVERT(float, 機構組件零件BOM表.數量) * CONVERT(float, 零件成本紀錄表.進貨單價)), 2) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 零件成本紀錄表 ON " & "機構組件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')" CmdSet_For_dr() If dr.Read() Then : 加總1 = dr("成本").ToString : End If : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT ROUND(SUM(CONVERT(float, 機構組件零件BOM表.數量) * CONVERT(float, 零組件成本紀錄表.進貨單價)), 2) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 零組件成本紀錄表 ON " & "機構組件零件BOM表.零件流水碼 = 零組件成本紀錄表.流水碼 WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')" CmdSet_For_dr() If dr.Read() Then : 加總2 = dr("成本").ToString : End If : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT ROUND(SUM(CONVERT(float, 機構組件零件BOM表.數量) * CONVERT(float, 機構件成本紀錄表.進貨單價)), 2) AS 成本 FROM 機構組件零件BOM表 INNER JOIN 機構件成本紀錄表 ON " & "機構組件零件BOM表.零件流水碼 = 機構件成本紀錄表.流水碼 WHERE (機構組件零件BOM表.機構碼 = '" & ComboBox1.Text & "')" CmdSet_For_dr() If dr.Read() Then : 加總3 = dr("成本").ToString : End If : conn.Close() : dr.Close() If 加總1 = "" Then : 加總1 = "0" : End If : If 加總2 = "" Then : 加總2 = "0" : End If : If 加總3 = "" Then : 加總3 = "0" : End If TextBox6.Text = CStr(Math.Round((Double.Parse(加總1) + Double.Parse(加總2) + Double.Parse(加總3)), 2)) If TextBox6.Text <> "" Or TextBox6.Text <> "0" Or TextBox6.Text <> "0.0" Or TextBox6.Text <> "0.00" Then If InStr(TextBox6.Text, ".") = 0 Then If Len(TextBox6.Text) <= 3 Then TextBox9.Text = TextBox6.Text & ".00" ElseIf Len(TextBox6.Text) <= 4 Then TextBox9.Text = Strings.Left(TextBox6.Text, 1) & "," & Mid(TextBox6.Text, 2, 10) & ".00" ElseIf Len(TextBox6.Text) <= 5 Then TextBox9.Text = Strings.Left(TextBox6.Text, 2) & "," & Mid(TextBox6.Text, 3, 10) & ".00" ElseIf Len(TextBox6.Text) <= 6 Then TextBox9.Text = Strings.Left(TextBox6.Text, 3) & "," & Mid(TextBox6.Text, 4, 10) & ".00" ElseIf Len(TextBox6.Text) <= 7 Then TextBox9.Text = Strings.Left(TextBox6.Text, 1) & "," & Mid(TextBox6.Text, 2, 3) & "," & Mid(TextBox6.Text, 5, 10) & ".00" End If Else If InStr(TextBox6.Text, ".") <= 4 Then TextBox9.Text = TextBox6.Text ElseIf InStr(TextBox6.Text, ".") = 5 Then TextBox9.Text = Strings.Left(TextBox6.Text, 1) & "," & Mid(TextBox6.Text, 2, 10) ElseIf InStr(TextBox6.Text, ".") = 6 Then TextBox9.Text = Strings.Left(TextBox6.Text, 2) & "," & Mid(TextBox6.Text, 3, 10) ElseIf InStr(TextBox6.Text, ".") = 7 Then TextBox9.Text = Strings.Left(TextBox6.Text, 3) & "," & Mid(TextBox6.Text, 4, 10) ElseIf InStr(TextBox6.Text, ".") = 8 Then TextBox9.Text = Strings.Left(TextBox6.Text, 1) & "," & Mid(TextBox6.Text, 2, 3) & "," & Mid(TextBox6.Text, 5, 10) End If End If End If Set_grid2() If TextBox6.Text = "" Then TextBox9.Text = "" End If End Sub Private Sub ComboBox4下拉表單資料載入() conn.Close() If ComboBox3.Text = "" Or ComboBox3.Text = "-請選擇-" Then ComboBox3.Text = "-請選擇-" ConnOpen() SQL1 = "SELECT 類型 FROM 機構成本科目類型表 ORDER BY 類型" Else ConnOpen() SQL1 = "SELECT 類型 FROM 機構成本科目類型表 WHERE (科目 ='" & ComboBox3.Text & "') ORDER BY 類型" End If cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox4.Items.Clear() While (dr.Read()) ComboBox4.Items.Add(dr("類型")) End While conn.Close() End Sub Private Sub ComboBox1下拉表單資料載入() conn.Close() If ComboBox4.Text = "" Or ComboBox4.Text = "-請選擇-" Or ComboBox3.Text = "" Or ComboBox3.Text = "-請選擇-" Then ComboBox4.Text = "-請選擇-" ConnOpen() SQL1 = "SELECT 流水碼 FROM 機構組件成本紀錄表 ORDER BY 流水碼 DESC" Else ConnOpen() SQL1 = "SELECT 流水碼 FROM 機構組件成本紀錄表 WHERE 科目 like N'%" & ComboBox3.Text & "%' AND 類型 like N'%" & ComboBox4.Text & "%' ORDER BY 流水碼 DESC" End If cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox1.Items.Clear() While (dr.Read()) ComboBox1.Items.Add(dr("流水碼")) End While conn.Close() End Sub Private Sub 格式設定() TextBox1.Text = "" : TextBox2.Text = "" : TextBox4.Text = "" ComboBox1.Enabled = True : Button3.Enabled = True : Button7.Enabled = False : Button2.Enabled = False : Button4.Enabled = False : Button5.Enabled = False Button8.Enabled = True : Button9.Enabled = False : Button10.Enabled = True : Button11.Enabled = False Button12.Enabled = False : Button13.Enabled = False End Sub Private Sub Set_grid1() DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 55 : DataGridView2.Columns(2).Width = 80 DataGridView2.Columns(3).Width = 110 : DataGridView2.Columns(4).Width = 230 : DataGridView2.Columns(5).Width = 120 DataGridView2.Columns(6).Visible = False : DataGridView2.Columns(7).Visible = False End Sub Private Sub Set_grid2() DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Width = 80 : DataGridView1.Columns(2).Width = 80 DataGridView1.Columns(3).Width = 250 : DataGridView1.Columns(4).Width = 70 : DataGridView1.Columns(5).Width = 120 DataGridView1.Columns(6).Width = 60 : DataGridView1.Columns(7).Width = 50 : DataGridView1.Columns(8).Visible = False End Sub Private Sub Set_grid4() DataGridView4.Columns(0).Width = 60 : DataGridView4.Columns(1).Width = 60 : DataGridView4.Columns(2).Width = 70 DataGridView4.Columns(3).Width = 115 End Sub Private Sub Set_grid5() DataGridView5.Columns(0).Width = 80 : DataGridView5.Columns(1).Width = 60 : DataGridView5.Columns(2).Width = 170 End Sub Private Sub Set_grid6() DataGridView6.Columns(0).Width = 65 : DataGridView6.Columns(1).Width = 70 : DataGridView6.Columns(2).Width = 70 DataGridView6.Columns(3).Width = 100 End Sub Private Sub Set_grid7() DataGridView7.Columns(0).Visible = False : DataGridView7.Columns(1).Width = 80 : DataGridView7.Columns(2).Width = 80 DataGridView7.Columns(3).Width = 250 : DataGridView7.Columns(4).Width = 70 : DataGridView7.Columns(5).Width = 120 DataGridView7.Columns(6).Width = 60 : DataGridView7.Columns(7).Width = 50 : DataGridView7.Columns(8).Visible = False End Sub Private Sub Set_grid8() DataGridView8.Columns(0).Visible = False : DataGridView8.Columns(1).Width = 80 : DataGridView8.Columns(2).Width = 80 DataGridView8.Columns(3).Width = 250 : DataGridView8.Columns(4).Width = 70 : DataGridView8.Columns(5).Width = 120 DataGridView8.Columns(6).Width = 60 : DataGridView8.Columns(7).Width = 50 : DataGridView8.Columns(8).Visible = False End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else TextBox1.Text = DataGridView2(0, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView2(4, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then : Else TextBox1.Text = DataGridView1(1, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView4_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView4.CellClick If e.RowIndex = -1 Then : Else ComboBox4.Text = DataGridView4(3, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView5_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView5.CellClick If e.RowIndex = -1 Then : Else ComboBox1.Text = DataGridView5(0, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView6_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView6.CellClick If e.RowIndex = -1 Then : Else ComboBox3.Text = DataGridView6(1, e.RowIndex).Value.ToString : ComboBox4.Text = DataGridView6(2, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView7_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView7.CellClick If e.RowIndex = -1 Then : Else TextBox7.Text = DataGridView7(1, e.RowIndex).Value.ToString End If End Sub Private Sub 機構組件零件BOM表_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = GCM_ERP_SYS Me.WindowState = 2 ComboBox3.Items.AddRange(科目清單) If CheckBox1.Checked = True Then 讀取零件清單() ElseIf CheckBox2.Checked = True Then 讀取零組件清單() ElseIf CheckBox3.Checked = True Then 讀取機構件清單() End If ComboBox4下拉表單資料載入() : ComboBox1下拉表單資料載入() : 格式設定() 機構科目清單() : 機構名稱清單() : 零組件清單() ComboBox1.SelectedIndex = 0 End Sub Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PA = InputBox("請輸入要查詢零件的資料") If CheckBox1.Checked = True Then 讀取零件清單() ElseIf CheckBox2.Checked = True Then 讀取零組件清單() ElseIf CheckBox3.Checked = True Then 讀取機構件清單() End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If TextBox1.Text = "" Then MsgBox("請選擇零件") Else ConnOpen() SQL1 = "SELECT 零件流水碼 FROM 機構組件零件BOM表 WHERE 機構碼 = '" & ComboBox1.Text & "' AND 零件流水碼 = '" & TextBox1.Text & "'" CmdSet_For_dr() If dr.Read() Then : TextBox3.Text = dr("零件流水碼").ToString : End If conn.Close() : dr.Close() If TextBox3.Text = "" Then Dim a As String = InputBox("請輸入數量") ConnOpen() SQL1 = "INSERT INTO 機構組件零件BOM表 (機構碼, 零件流水碼, 數量) VALUES ('" & ComboBox1.Text & "','" & TextBox1.Text & "','" & a & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() conn.Close() Else MsgBox("零件已有選擇,如需增加請修改數量") End If End If TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" 讀取機構組件零件BOM表() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If TextBox1.Text = "" Then MsgBox("請選擇零件") Else ConnOpen() SQL1 = "SELECT 零件流水碼 FROM 機構組件零件BOM表 WHERE 機構碼 = '" & ComboBox1.Text & "' AND 零件流水碼 = '" & TextBox1.Text & "'" CmdSet_For_dr() If dr.Read() Then : TextBox3.Text = dr("零件流水碼").ToString : End If conn.Close() : dr.Close() If TextBox3.Text <> "" Then Dim a As String = InputBox("請輸入修改數量") ConnOpen() SQL1 = "UPDATE 機構組件零件BOM表 SET 機構碼 = '" & ComboBox1.Text & "', 數量 = '" & a & "' WHERE (零件流水碼 = '" & TextBox1.Text & "') and (機構碼 = '" & ComboBox1.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Else MsgBox("請正確選擇") End If End If TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" 讀取機構組件零件BOM表() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click If TextBox1.Text = "" Then MsgBox("請選擇零件") Else SQL1 = "DELETE FROM 機構組件零件BOM表 WHERE (零件流水碼 = '" & TextBox1.Text & "') and (機構碼 = '" & ComboBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn ConnOpen() cmd.ExecuteNonQuery() : MsgBox("刪除完成") conn.Close() End If TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" 讀取機構組件零件BOM表() End Sub Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged ComboBox4下拉表單資料載入() : 機構科目清單() End Sub Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged ComboBox1下拉表單資料載入() : 機構名稱清單() End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 品名, 型號及備註, 幣別 FROM 機構組件成本紀錄表 WHERE 流水碼 = '" & ComboBox1.Text & "'" CmdSet_For_dr() If dr.Read() Then TextBox2.Text = dr("品名").ToString : TextBox5.Text = dr("型號及備註").ToString : ComboBox2.Text = dr("幣別").ToString End If conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 科目 FROM 機構組件成本紀錄表 WHERE 流水碼 = '" & ComboBox1.Text & "'" CmdSet_For_dr() If dr.Read() Then ComboBox3.Text = dr("科目").ToString End If conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 類型 FROM 機構組件成本紀錄表 WHERE 流水碼 = '" & ComboBox1.Text & "'" CmdSet_For_dr() If dr.Read() Then ComboBox4.Text = dr("類型").ToString End If conn.Close() : dr.Close() 讀取機構組件零件BOM表() End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click If ComboBox3.Text = "-請選擇-" Or ComboBox4.Text = "-請選擇-" Then MsgBox("科目或類型欄位不可空白") Else Dim NUM1 As Integer For NUM1 = 0 To 99999 If NUM1 < 10 Then TextBox1.Text = "GS" & "0000" & NUM1 ElseIf NUM1 > 9 And NUM1 < 100 Then TextBox1.Text = "GS" & "000" & NUM1 ElseIf NUM1 > 99 And NUM1 < 1000 Then TextBox1.Text = "GS" & "00" & NUM1 ElseIf NUM1 > 999 And NUM1 < 10000 Then TextBox1.Text = "GS" & "0" & NUM1 ElseIf NUM1 > 9999 Then TextBox1.Text = "GS" & NUM1 End If ConnOpen() SQL1 = "SELECT 流水碼 FROM 機構組件成本紀錄表 WHERE (流水碼 ='" & TextBox1.Text & "')" CmdSet_For_dr() If dr.Read() Then ComboBox1.Text = dr("流水碼").ToString Else ComboBox1.Text = "" End If conn.Close() If ComboBox1.Text = "" Then ComboBox1.Text = TextBox1.Text : TextBox1.Text = "可用" TextBox1.Text = "" : TextBox2.Text = "" : TextBox5.Text = "" : ComboBox2.Text = "" ComboBox1.Enabled = False : Button3.Enabled = False : Button7.Enabled = True : Button12.Enabled = True NUM1 = 99999 End If Next Button2.Enabled = True : Button4.Enabled = True : Button5.Enabled = True 讀取機構組件零件BOM表() End If End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click If ComboBox1.Enabled = True Or ComboBox3.Text = "-請選擇-" Or ComboBox4.Text = "-請選擇-" Or TextBox2.Text = "" Or TextBox6.Text = "" Or ComboBox2.Text = "" Then MsgBox("資料不足請檢查後重新確認") Else ConnOpen() SQL1 = "INSERT INTO 機構組件成本紀錄表 (流水碼, 品牌, 供應商, 科目, 類型, 型號及備註, 品名, 供應商成本, 進貨單價, 幣別) VALUES ('" & ComboBox1.Text & "','工巧明','工巧明','" & ComboBox3.Text & "','" & ComboBox4.Text & "','" & TextBox5.Text & "','" & TextBox2.Text & "','','" & TextBox6.Text & "','" & ComboBox2.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() MsgBox("新增完成") conn.Close() 格式設定() : ComboBox1下拉表單資料載入() : 讀取機構組件零件BOM表() : 機構科目清單() : 機構名稱清單() : 零組件清單() ComboBox1.Enabled = True End If End Sub Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click ComboBox1.Text = "" 格式設定() : ComboBox1下拉表單資料載入() : 讀取機構組件零件BOM表() ComboBox1.SelectedIndex = 0 End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click Button2.Enabled = True : Button4.Enabled = True : Button5.Enabled = True : Button8.Enabled = False : Button9.Enabled = True : ComboBox1.Enabled = False Button13.Enabled = True End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click If ComboBox1.Enabled = True Or ComboBox3.Text = "-請選擇-" Or ComboBox4.Text = "-請選擇-" Or TextBox2.Text = "" Or TextBox6.Text = "" Or ComboBox2.Text = "" Then MsgBox("資料不足請檢查後重新確認") Else ConnOpen() SQL1 = "UPDATE 機構組件成本紀錄表 SET 品牌 = '工巧明', 供應商 = '工巧明', 科目 = '" & ComboBox3.Text & "', 類型 = '" & ComboBox4.Text & "', 型號及備註 = '" & TextBox5.Text & "', 品名 = '" & TextBox2.Text & "', 供應商成本 = '', 進貨單價 = '" & TextBox6.Text & "', 幣別 = '" & ComboBox2.Text & "' WHERE (流水碼 = '" & ComboBox1.Text & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() MsgBox("修改完成") conn.Close() 格式設定() : ComboBox1下拉表單資料載入() : 讀取機構組件零件BOM表() End If End Sub Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click 格式設定() : ComboBox1下拉表單資料載入() : 讀取機構組件零件BOM表() End Sub Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click Button10.Enabled = False : Button11.Enabled = True End Sub Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click SQL1 = "DELETE FROM 機構組件成本紀錄表 WHERE (流水碼 = '" & ComboBox1.Text & "')" SQL1 = "DELETE FROM 機構組件零件BOM表 WHERE (機構碼 = '" & ComboBox1.Text & "')" cmd.CommandText = SQL : cmd.Connection = conn cmd.CommandText = SQL1 : cmd.Connection = conn ConnOpen() ConnOpen() Dim aa As MsgBoxResult aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel) If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If conn.Close() : conn.Close() 格式設定() : ComboBox1下拉表單資料載入() : 讀取機構組件零件BOM表() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim xlApp As Microsoft.Office.Interop.Excel.Application Dim xlBook As Microsoft.Office.Interop.Excel.Workbook Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application) xlBook = xlApp.Workbooks.Add xlApp.DisplayAlerts = True xlBook.Activate() xlSheet = NewMethod(xlBook) xlSheet.Activate() xlApp.Visible = True xlApp.Application.WindowState = xlMaximized xlSheet.Cells(2, 2) = "工巧明智能設備有限公司 機構組件-零件BOM表" xlSheet.Cells(3, 2) = "客戶名稱:" xlSheet.Cells(4, 2) = "機購編號:" xlSheet.Cells(5, 2) = "機構名稱:" xlSheet.Cells(6, 2) = "型號及備註:" xlSheet.Cells(3, 10) = "機構科目:" xlSheet.Cells(4, 10) = "機構類型:" xlSheet.Cells(5, 10) = "技術開發課確認者:" xlSheet.Cells(6, 10) = "修改日期:" xlSheet.Cells(6, 11) = String.Format("{0:d}", Now) xlSheet.Cells(7, 2) = "項次" : xlSheet.Cells(7, 5) = "零件流水碼" : xlSheet.Cells(7, 6) = "品牌" : xlSheet.Cells(7, 7) = "科目" : xlSheet.Cells(7, 8) = "品名" xlSheet.Cells(7, 9) = "型號及備註" : xlSheet.Cells(7, 11) = "數量" : xlSheet.Cells(7, 14) = "說明" xlSheet.Cells(4, 5) = ComboBox1.Text : xlSheet.Cells(5, 5) = TextBox2.Text : xlSheet.Cells(6, 5) = TextBox5.Text xlSheet.Cells(3, 11) = ComboBox3.Text : xlSheet.Cells(4, 11) = ComboBox4.Text Dim i As Integer : Dim ii As Integer : Dim iii As Integer : Dim ni1 As Integer = -1 : Dim ni1s As Integer = 0 For ni1 = ni1 + 1 To DataGridView1.Rows.Count - 1 xlSheet.Cells(i + 8, 2) = ni1s + 1 xlSheet.Cells(i + 8, 5) = DataGridView1.Rows(ni1).Cells("零件流水碼").Value xlSheet.Cells(i + 8, 6) = DataGridView1.Rows(ni1).Cells("品牌").Value xlSheet.Cells(i + 8, 7) = DataGridView1.Rows(ni1).Cells("科目").Value xlSheet.Cells(i + 8, 8) = DataGridView1.Rows(ni1).Cells("品名").Value xlSheet.Cells(i + 8, 9) = DataGridView1.Rows(ni1).Cells("型號及備註").Value xlSheet.Cells(i + 8, 11) = DataGridView1.Rows(ni1).Cells("數量").Value With xlApp.Selection .Font.Bold = True End With i += 1 : ni1s += 1 TextBox1.Text = DataGridView1.Rows(ni1).Cells("零件流水碼").Value If Strings.Left(TextBox1.Text, 2) = "MS" Or Strings.Left(TextBox1.Text, 2) = "MP" Then Dim ni2 As Integer = -1 : Dim ni2s As Integer = 0 : ii = i For ni2 = ni2 + 1 To DataGridView7.Rows.Count - 1 xlSheet.Cells(ii + 8, 3) = ni1s & "_" & ni2s + 1 xlSheet.Cells(ii + 8, 5) = DataGridView7.Rows(ni2).Cells("零件流水碼").Value xlSheet.Cells(ii + 8, 6) = DataGridView7.Rows(ni2).Cells("品牌").Value xlSheet.Cells(ii + 8, 7) = DataGridView7.Rows(ni2).Cells("科目").Value xlSheet.Cells(ii + 8, 8) = DataGridView7.Rows(ni2).Cells("品名").Value xlSheet.Cells(ii + 8, 9) = DataGridView7.Rows(ni2).Cells("型號及備註").Value xlSheet.Cells(ii + 8, 12) = DataGridView7.Rows(ni2).Cells("數量").Value With xlApp.Selection .Font.Bold = True End With ii += 1 : ni2s += 1 TextBox7.Text = DataGridView7.Rows(ni2).Cells("零件流水碼").Value If Strings.Left(TextBox7.Text, 2) = "MS" Then Dim ni3 As Integer = -1 : Dim ni3s As Integer = 0 : iii = ii For ni3 = ni3 + 1 To DataGridView8.Rows.Count - 1 xlSheet.Cells(iii + 8, 4) = ni1s & "_" & ni2s & "_" & ni3s + 1 xlSheet.Cells(iii + 8, 5) = DataGridView8.Rows(ni3).Cells("零件流水碼").Value xlSheet.Cells(iii + 8, 6) = DataGridView8.Rows(ni3).Cells("品牌").Value xlSheet.Cells(iii + 8, 7) = DataGridView8.Rows(ni3).Cells("科目").Value xlSheet.Cells(iii + 8, 8) = DataGridView8.Rows(ni3).Cells("品名").Value xlSheet.Cells(iii + 8, 9) = DataGridView8.Rows(ni3).Cells("型號及備註").Value xlSheet.Cells(iii + 8, 13) = DataGridView8.Rows(ni3).Cells("數量").Value With xlApp.Selection .Font.Bold = True End With iii += 1 : ni3s += 1 Next ni3 ii = iii + 1 End If Next ni2 i = ii + 1 End If KE = i Next ni1 AA(xlApp, xlSheet) xlSheet.PageSetup.PrintArea = "" xlApp.Cells.Select() xlSheet.Range("B1").Select() xlApp.Application.WindowState = xlMinimized MsgBox("列印完成") End Sub Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet) End Function Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet) Dim 位置 As String xlSheet.Columns("A:A").ColumnWidth = 1 xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 3 xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 6 xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 8 xlSheet.Columns("E:G").Select : myExcel.Selection.ColumnWidth = 12 xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 40 xlSheet.Columns("I:J").Select : myExcel.Selection.ColumnWidth = 20 xlSheet.Columns("K:M").Select : myExcel.Selection.ColumnWidth = 4 xlSheet.Columns("N:N").Select : myExcel.Selection.ColumnWidth = 40 xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 5 xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 30 xlSheet.Rows("3:6").Select : myExcel.Selection.RowHeight = 15 xlSheet.Rows("7:7").Select : myExcel.Selection.RowHeight = 25 xlSheet.Range("B2:N2,B3:D3,B4:D4,B5:D5,B6:D6,B7:D7,E3:I3,E4:I4,E5:I5,E6:I6,K3:N3,K4:N4,K5:N5,K6:N6,K7:M7").Select() xlSheet.Range("K7").Activate() With myExcel.Selection .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With myExcel.Selection.Merge xlSheet.Range("B3:N6").Select() With myExcel.Selection .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : xlSheet.Cells.Select() End With With myExcel.Selection.Font .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With xlSheet.Range("B2:N2").Select() With myExcel.Selection.Font .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With 位置 = "B2:N" & KE + 8 xlSheet.Range(位置).Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With xlSheet.Range("B2:N6").Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With xlSheet.Rows("7:7").Select myExcel.Selection.AutoFilter : myExcel.ActiveWindow.DisplayGridlines = False xlSheet.Range("B2:N2").Select() xlSheet.Rows("8:8").Select : myExcel.ActiveWindow.FreezePanes = True 位置 = "I8:J" & KE + 8 xlSheet.Range(位置).Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With xlSheet.Range("B7:N7").Select() With myExcel.Selection.Interior .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent5 : .TintAndShade = 0.399975585192419 : .PatternTintAndShade = 0 End With xlSheet.Range("B7:N7").Select() With myExcel.Selection .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext End With xlSheet.Cells.Select() With myExcel.Selection : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : End With xlSheet.Range("B1").Select() End Sub Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click If My.Application.OpenForms.Item("機構組件零件成本建檔") IsNot Nothing Then 機構組件零件成本建檔.BringToFront() Else 機構組件零件成本建檔.Show() End If End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click 條件 = InputBox("請輸入要查詢的零組件編號或類別、科目") 零組件清單() End Sub Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click CheckBox1.Checked = True : CheckBox2.Checked = False : CheckBox3.Checked = False End Sub Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click CheckBox2.Checked = True : CheckBox1.Checked = False : CheckBox3.Checked = False End Sub Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click CheckBox2.Checked = False : CheckBox1.Checked = False : CheckBox3.Checked = True End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged DataGridView7.DataSource = Nothing : ds6.Clear() DataGridView7.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView7.ColumnHeadersHeight = 25 DataGridView7.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 機構件零件BOM表.機構碼, 機構件零件BOM表.零件流水碼, 零組件成本紀錄表.科目, 零組件成本紀錄表.品名, 機構件零件BOM表.數量, 零組件成本紀錄表.型號及備註," & "ROUND(Convert(float, 機構件零件BOM表.數量) * Convert(float, 零組件成本紀錄表.進貨單價),2) AS 成本, 零組件成本紀錄表.幣別, 零組件成本紀錄表.品牌 FROM 機構件零件BOM表 INNER JOIN 零組件成本紀錄表 " & "ON 機構件零件BOM表.零件流水碼 = 零組件成本紀錄表.流水碼 WHERE 機構件零件BOM表.機構碼 = '" & TextBox1.Text & "' ORDER BY 零組件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds6) : DataGridView7.DataSource = ds6.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 機構件零件BOM表.機構碼, 機構件零件BOM表.零件流水碼, 零件成本紀錄表.科目, 零件成本紀錄表.品名, 機構件零件BOM表.數量, 零件成本紀錄表.型號及備註," & "ROUND(Convert(float, 機構件零件BOM表.數量) * Convert(float, 零件成本紀錄表.進貨單價),2) AS 成本, 零件成本紀錄表.幣別, 零件成本紀錄表.品牌 FROM 機構件零件BOM表 INNER JOIN 零件成本紀錄表 " & "ON 機構件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 WHERE 機構件零件BOM表.機構碼 = '" & TextBox1.Text & "' ORDER BY 零件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds6) : DataGridView7.DataSource = ds6.Tables(0) : conn.Close() : dr.Close() ConnOpen() SQL1 = "SELECT 零組件零件BOM表.機構碼, 零組件零件BOM表.零件流水碼, 零件成本紀錄表.科目, 零件成本紀錄表.品名, 零組件零件BOM表.數量, 零件成本紀錄表.型號及備註," & "ROUND(Convert(float, 零組件零件BOM表.數量) * Convert(float, 零件成本紀錄表.進貨單價),2) AS 成本, 零件成本紀錄表.幣別, 零件成本紀錄表.品牌 FROM 零組件零件BOM表 INNER JOIN 零件成本紀錄表 " & "ON 零組件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 WHERE 零組件零件BOM表.機構碼 = '" & TextBox1.Text & "' ORDER BY 零件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds6) : DataGridView7.DataSource = ds6.Tables(0) : conn.Close() : dr.Close() Set_grid7() End Sub Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged DataGridView8.DataSource = Nothing : ds7.Clear() DataGridView8.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView8.ColumnHeadersHeight = 25 DataGridView8.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 零組件零件BOM表.機構碼, 零組件零件BOM表.零件流水碼, 零件成本紀錄表.科目, 零件成本紀錄表.品名, 零組件零件BOM表.數量, 零件成本紀錄表.型號及備註," & "ROUND(Convert(float, 零組件零件BOM表.數量) * Convert(float, 零件成本紀錄表.進貨單價),2) AS 成本, 零件成本紀錄表.幣別, 零件成本紀錄表.品牌 FROM 零組件零件BOM表 INNER JOIN 零件成本紀錄表 " & "ON 零組件零件BOM表.零件流水碼 = 零件成本紀錄表.流水碼 WHERE 零組件零件BOM表.機構碼 = '" & TextBox7.Text & "' ORDER BY 零件成本紀錄表.科目" CmdSet_For_DGV() : da.Fill(ds7) : DataGridView8.DataSource = ds7.Tables(0) : conn.Close() : dr.Close() Set_grid8() End Sub End Class