Option Strict Off Imports System.Data.SqlClient 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 Imports Microsoft.Office.Interop.Excel Imports System.Threading Public Class 樣品物料調料單申請 Dim conn As New SqlConnection Dim da As New SqlDataAdapter Dim cmd As New SqlCommand Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet Dim dr As SqlDataReader Dim DTP As String : Dim DTP1 As String : Dim 新項次 As String : Dim NUM1 As Integer Dim xlApp As Application Dim xlBook As Workbook Dim xlSheet As Worksheet Dim 位置1 As String : Dim N1 As Integer Private Sub Set_DGV1載入前設定() DataGridView1.DataSource = Nothing : ds.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If End Sub Private Sub Set_DGV1載入後設定() cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid() End Sub Private Sub Set_清單() Set_DGV1載入前設定() If PA = "" Then SQL1 = "SELECT 樣品物料調料單抬頭.調料單號, 供應商清單.廠商, 樣品物料調料單抬頭.客戶, 樣品物料調料單抬頭.SHOW年, 樣品物料調料單抬頭.SHOW月, 樣品物料調料單抬頭.日期, 樣品物料調料單抬頭.發件人, 樣品物料調料單抬頭.收件人, 樣品物料調料單抬頭.制表人, 樣品物料調料單抬頭.核准簽名, 樣品物料調料單抬頭.供應商編號 FROM 樣品物料調料單抬頭 INNER JOIN 供應商清單 ON 樣品物料調料單抬頭.供應商編號 = 供應商清單.供應商編碼 WHERE (樣品物料調料單抬頭.核准簽名 LIKE '') ORDER BY 樣品物料調料單抬頭.SHOW年, 樣品物料調料單抬頭.SHOW月" Else SQL1 = "SELECT 樣品物料調料單抬頭.調料單號, 供應商清單.廠商, 樣品物料調料單抬頭.客戶, 樣品物料調料單抬頭.SHOW年, 樣品物料調料單抬頭.SHOW月, 樣品物料調料單抬頭.日期, 樣品物料調料單抬頭.發件人, 樣品物料調料單抬頭.收件人, 樣品物料調料單抬頭.制表人, 樣品物料調料單抬頭.核准簽名, 樣品物料調料單抬頭.供應商編號 FROM 樣品物料調料單抬頭 INNER JOIN 供應商清單 ON 樣品物料調料單抬頭.供應商編號 = 供應商清單.供應商編碼 WHERE (樣品物料調料單抬頭.核准簽名 LIKE '') AND ((樣品物料調料單抬頭.調料單號 LIKE N'%" & PA & "%') OR (供應商清單.廠商 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.客戶 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.SHOW年 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.SHOW月 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.日期 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.發件人 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.收件人 LIKE N'%" & PA & "%') OR (樣品物料調料單抬頭.制表人 LIKE N'%" & PA & "%')) ORDER BY 樣品物料調料單抬頭.SHOW年, 樣品物料調料單抬頭.SHOW月" End If Set_DGV1載入後設定() End Sub Private Sub Set_grid() DataGridView1.Columns(0).Width = 110 : DataGridView1.Columns(1).Width = 130 : DataGridView1.Columns(2).Width = 130 : DataGridView1.Columns(3).Width = 70 : DataGridView1.Columns(4).Width = 70 DataGridView1.Columns(5).Visible = False : DataGridView1.Columns(6).Visible = False : DataGridView1.Columns(7).Visible = False : DataGridView1.Columns(8).Visible = False DataGridView1.Columns(9).Visible = False : DataGridView1.Columns(10).Visible = False End Sub Private Sub Set_使用者清單() DataGridView2.DataSource = Nothing : ds1.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False DataGridView2.RowTemplate.Height = 35 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 調料單號, 項次, 名稱, 規格, 顏色, 單位, 數量, 單價, 數量 * 單價 AS 金額, 備註 FROM 樣品物料調料單明細 WHERE 調料單號 LIKE N'" & TextBox1.Text & "' ORDER BY 項次" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1() End Sub Private Sub Set_grid1() DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 80 : DataGridView2.Columns(2).Width = 200 : DataGridView2.Columns(3).Width = 200 : DataGridView2.Columns(4).Width = 200 DataGridView2.Columns(5).Width = 80 : DataGridView2.Columns(6).Width = 80 : DataGridView2.Columns(7).Width = 80 : DataGridView2.Columns(8).Width = 80 : DataGridView2.Columns(9).Width = 305 DataGridView2.Columns(8).DefaultCellStyle.Format = "#,##0.00" : DataGridView2.Columns(6).DefaultCellStyle.Format = "#,##0.00" : DataGridView2.Columns(7).DefaultCellStyle.Format = "#,##0.00" DataGridView2.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView2.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView2.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView2.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView2.EditMode = DataGridViewEditMode.EditOnEnter TextBox5.Text = "0.00" For i As Integer = 0 To DataGridView2.Rows.Count - 1 TextBox5.Text = Val(TextBox5.Text) + DataGridView2.Rows(i).Cells("金額").Value Next i TextBox5.Text = Strings.Format(Val(TextBox5.Text), "#,##0.00") End Sub Private Sub ComboBox1下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 廠商, 供應商編碼 FROM 供應商清單 ORDER BY 廠商" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox1.Items.Clear() : ComboBox2.Items.Clear() While (dr.Read()) : ComboBox1.Items.Add(dr("廠商")) : ComboBox2.Items.Add(dr("供應商編碼")) : End While : conn.Close() End Sub Private Sub ComboBox3下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 姓名 FROM 使用者權限管理表 WHERE (CC49 = 0) ORDER BY 姓名" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox3.Items.Clear() : ComboBox4.Items.Clear() While (dr.Read()) : ComboBox3.Items.Add(dr("姓名")) : ComboBox4.Items.Add(dr("姓名")) : End While : conn.Close() End Sub Private Sub ComboBox5下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 年份 FROM 年份清單 ORDER BY 年份" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox5.Items.Clear() : While (dr.Read()) : ComboBox5.Items.Add(dr("年份")) : End While : conn.Close() End Sub Private Sub ComboBox7下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 ORDER BY 客戶簡稱" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox7.Items.Clear() : While (dr.Read()) : ComboBox7.Items.Add(dr("客戶簡稱")) : End While : conn.Close() End Sub Private Sub Set_日期格式轉換() DTP = Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Strings.Format(Today(), "yyyyMMdd") End Sub Private Sub 樣品物料調料單_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True Set_清單() : ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox5下拉表單資料載入() : ComboBox7下拉表單資料載入() Button2.Enabled = False : Button6.Enabled = False : Button15.Enabled = False : Button3.Enabled = False : Button4.Enabled = False : Button5.Enabled = False TextBox1.Enabled = False : TextBox6.Enabled = False End Sub Private Sub 樣品物料調料單_Unload(sender As Object, e As EventArgs) Handles MyBase.Closing If Button2.Enabled = True Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM 樣品物料調料單抬頭 WHERE (調料單號 LIKE N'" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM 樣品物料調料單明細 WHERE (調料單號 LIKE N'" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close() 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.Rows(e.RowIndex).Cells("調料單號").Value.ToString : Button3.Enabled = True : Button5.Enabled = True ComboBox2.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商編號").Value : ComboBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("發件人").Value ComboBox4.Text = DataGridView1.Rows(e.RowIndex).Cells("收件人").Value : DateTimePicker1.Value = DataGridView1.Rows(e.RowIndex).Cells("日期").Value TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells("制表人").Value : ComboBox7.Text = DataGridView1.Rows(e.RowIndex).Cells("客戶").Value ComboBox5.Text = DataGridView1.Rows(e.RowIndex).Cells("SHOW年").Value : ComboBox6.Text = DataGridView1.Rows(e.RowIndex).Cells("SHOW月").Value Set_使用者清單() End If End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else TextBox6.Text = DataGridView2.Rows(e.RowIndex).Cells("項次").Value End If End Sub Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellEndEdit TextBox5.Text = "0.00" For i As Integer = 0 To DataGridView2.Rows.Count - 1 DataGridView2.Rows(i).Cells("金額").Value = Val(DataGridView2.Rows(i).Cells("數量").Value) * Val(DataGridView2.Rows(i).Cells("單價").Value) TextBox5.Text = Val(TextBox5.Text) + DataGridView2.Rows(i).Cells("金額").Value Next i TextBox5.Text = Strings.Format(Val(TextBox5.Text), "#,##0.00") End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If Label62.Visible = True Then : Label62.Visible = False : Else : Label62.Visible = True : End If End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged ComboBox2.SelectedIndex = ComboBox1.SelectedIndex End Sub Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged ComboBox1.SelectedIndex = ComboBox2.SelectedIndex conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 公司名, 公司電話1, 聯繫人1 FROM 供應商清單 WHERE (供應商編碼 LIKE '" & ComboBox2.Text & "') ORDER BY 廠商" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If dr.Read() Then : TextBox2.Text = dr("公司名") : TextBox3.Text = dr("聯繫人1") : TextBox4.Text = dr("公司電話1") : End If conn.Close() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Timer1.Enabled = True : DataGridView1.Enabled = False Button1.Enabled = False : Button2.Enabled = True : Button6.Enabled = True : Button15.Enabled = True Set_日期格式轉換() : Dim NUM1 As Integer For i As Integer = 1 To 999 NUM1 = 0 + i If NUM1 < 10 Then : TextBox1.Text = "L-" & DTP1 & "-00" & NUM1 ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox1.Text = "L-" & DTP1 & "-0" & NUM1 ElseIf NUM1 > 99 Then : TextBox1.Text = "L-" & DTP1 & "-" & NUM1 End If conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TOP (1) 調料單號 FROM 樣品物料調料單抬頭 WHERE ( 調料單號 LIKE N'" & TextBox1.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then Else i = 999 conn.Close() End If conn.Close() Next If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "INSERT INTO 樣品物料調料單抬頭 (調料單號, 日期, 發件人, 收件人, 客戶, 制表人, 核准簽名, 供應商編號, SHOW年, SHOW月) " & "VALUES (N'" & TextBox1.Text & "',N'" & DTP & "',N'',N'',N'',N'',N'',N'',N'',N'')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() DataGridView2.DataSource = Nothing : ds1.Clear() conn.Close() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click Dim aa As MsgBoxResult aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel) If aa = MsgBoxResult.Ok Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM 樣品物料調料單抬頭 WHERE (調料單號 LIKE N'" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM 樣品物料調料單明細 WHERE (調料單號 LIKE N'" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close() TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox5下拉表單資料載入() : ComboBox7下拉表單資料載入() DataGridView2.DataSource = Nothing : ds1.Clear() Set_清單() End If End Sub Private Sub 存檔1() Set_日期格式轉換() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品物料調料單抬頭 SET 日期 = N'" & DTP & "', 發件人 = N'" & ComboBox3.Text & "', 收件人 = N'" & ComboBox4.Text & "', 客戶 = N'" & ComboBox7.Text & "', 制表人 = N'" & gUserName & "', 供應商編號 = N'" & ComboBox2.Text & "', SHOW年 = N'" & ComboBox5.Text & "', SHOW月 = N'" & ComboBox6.Text & "' WHERE (調料單號 LIKE N'" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() End Sub Private Sub 存檔() For i As Integer = 0 To DataGridView2.Rows.Count - 1 資料數 = DataGridView2.Rows.Count : MyModule1.進度條() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品物料調料單明細 SET 名稱 = N'" & DataGridView2.Rows(i).Cells("名稱").Value & "', 規格 = N'" & DataGridView2.Rows(i).Cells("規格").Value & "', 顏色 = N'" & DataGridView2.Rows(i).Cells("顏色").Value & "', 單位 = N'" & DataGridView2.Rows(i).Cells("單位").Value & "', 數量 = N'" & DataGridView2.Rows(i).Cells("數量").Value & "', 單價 = N'" & DataGridView2.Rows(i).Cells("單價").Value & "', 備註 = N'" & DataGridView2.Rows(i).Cells("備註").Value & "' WHERE (調料單號 LIKE N'" & TextBox1.Text & "' AND 項次 LIKE N'" & DataGridView2.Rows(i).Cells("項次").Value & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click 存檔() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TOP(1) 項次 FROM 樣品物料調料單明細 WHERE 調料單號 LIKE N'" & TextBox1.Text & "' ORDER BY 項次 DESC" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close() NUM1 = Double.Parse(新項次) + 1 If NUM1 < 10 Then : 新項次 = "0" & NUM1 ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 End If If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "INSERT INTO 樣品物料調料單明細 (調料單號, 項次, 名稱, 規格, 顏色, 單位, 數量, 單價, 備註) " & "VALUES (N'" & TextBox1.Text & "',N'" & 新項次 & "',N'',N'',N'',N'',N'0',N'0',N'')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() Set_使用者清單() End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click If TextBox6.Text = "" Then MsgBox("未選擇需要刪除的資料") Else 存檔() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM 樣品物料調料單明細 WHERE (調料單號 LIKE N'" & TextBox1.Text & "' AND 項次 LIKE N'" & TextBox6.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close() Set_使用者清單() Dim NUM1 As Integer = 0 For i As Integer = 0 To DataGridView2.Rows.Count - 1 NUM1 = NUM1 + 1 : If NUM1 < 10 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 : End If If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品物料調料單明細 SET 項次 = N'" & 新項次 & "' WHERE (調料單號 LIKE N'" & TextBox1.Text & "' AND 項次 LIKE N'" & DataGridView2.Rows(i).Cells("項次").Value & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() conn.Close() Next Set_使用者清單() End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click DataGridView1.Enabled = True If ComboBox1.Text = "" Or ComboBox3.Text = "" Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox7.Text = "" Then MsgBox("所有的下拉清單都要選擇,請重新確定資料是否正確。") Else If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Then MsgBox("供應商資料內容有缺失,請先完善供應商資料。") Else Timer1.Enabled = False : Label62.Visible = False Button1.Enabled = True : Button2.Enabled = False : Button6.Enabled = False : Button15.Enabled = False 存檔1() : 存檔() : TextBox7.Text = gUserName MsgBox("申請完成,請通知主管核準。") : Set_清單() End If End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Button3.Enabled = False : Button4.Enabled = True : Button6.Enabled = True : Button15.Enabled = True : Timer1.Enabled = True DataGridView1.Enabled = False End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If ComboBox1.Text = "" Or ComboBox3.Text = "" Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox7.Text = "" Then MsgBox("所有的下拉清單都要選擇,請重新確定資料是否正確。") Else If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Then MsgBox("供應商資料內容有缺失,請先完善供應商資料。") Else DataGridView1.Enabled = True Timer1.Enabled = False : Label62.Visible = False Button3.Enabled = True : Button4.Enabled = False : Button6.Enabled = False : Button15.Enabled = False 存檔1() : 存檔() : TextBox7.Text = gUserName MsgBox("申請完成,請通知主管核準。") : Set_清單() End If End If End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click xlApp = CType(CreateObject("Excel.Application"), Application) xlBook = xlApp.Workbooks.Add xlApp.DisplayAlerts = True xlBook.Activate() xlSheet = NewMethod(xlBook) xlSheet.Activate() xlApp.Visible = True xlApp.Application.WindowState = xlMaximized xlSheet.Cells(1, 1) = "森康鞋業有限公司 SenKang Footwear Ltd." xlSheet.Cells(3, 1) = "廣東東莞市厚街鎮湖景大道南150米 TEL:0769-38851258 FAX:0769-38851259" : xlSheet.Cells(6, 1) = "MATERIALS REQUEST FORM" : xlSheet.Cells(7, 1) = " 物料调料单" xlSheet.Cells(8, 1) = "Purchase NO#" : xlSheet.Cells(8, 3) = TextBox1.Text : xlSheet.Cells(10, 1) = "TO:" : xlSheet.Cells(10, 2) = TextBox2.Text xlSheet.Cells(11, 1) = "ATTN:" : xlSheet.Cells(11, 2) = TextBox3.Text : xlSheet.Cells(12, 1) = "TEL:" : xlSheet.Cells(12, 2) = TextBox4.Text xlSheet.Cells(10, 10) = "DATE:" : xlSheet.Cells(10, 11) = DateTimePicker1.Value : xlSheet.Cells(11, 10) = "FROM:" : xlSheet.Cells(11, 11) = ComboBox3.Text xlSheet.Cells(12, 10) = "EXT:" : xlSheet.Cells(12, 11) = ComboBox4.Text : xlSheet.Cells(14, 1) = "PLS ALWAYS REFER TO OUR PO#请于送货单上注明我们的订单号码" xlSheet.Cells(16, 1) = "Item" : xlSheet.Cells(16, 2) = "Description" : xlSheet.Cells(16, 4) = "Spec" : xlSheet.Cells(16, 6) = "Color" : xlSheet.Cells(16, 7) = "Unit" xlSheet.Cells(16, 8) = "Q'TY" : xlSheet.Cells(16, 9) = "Unit Price" : xlSheet.Cells(16, 10) = "Amount" : xlSheet.Cells(16, 11) = "Remark" : xlSheet.Cells(17, 1) = "项次" xlSheet.Cells(17, 2) = "名称" : xlSheet.Cells(17, 4) = "規格" : xlSheet.Cells(17, 6) = "颜色" : xlSheet.Cells(17, 7) = "单位" : xlSheet.Cells(17, 8) = "数量" xlSheet.Cells(17, 9) = "单价" : xlSheet.Cells(17, 10) = "金额" : xlSheet.Cells(17, 11) = "备注" For i As Integer = 0 To DataGridView2.Rows.Count - 1 xlSheet.Cells(i + 18, 1) = DataGridView2.Rows(i).Cells("項次").Value : xlSheet.Cells(i + 18, 2) = DataGridView2.Rows(i).Cells("名稱").Value xlSheet.Cells(i + 18, 4) = DataGridView2.Rows(i).Cells("規格").Value : xlSheet.Cells(i + 18, 6) = DataGridView2.Rows(i).Cells("顏色").Value xlSheet.Cells(i + 18, 7) = DataGridView2.Rows(i).Cells("單位").Value : xlSheet.Cells(i + 18, 8) = DataGridView2.Rows(i).Cells("數量").Value xlSheet.Cells(i + 18, 9) = DataGridView2.Rows(i).Cells("單價").Value : xlSheet.Cells(i + 18, 10) = DataGridView2.Rows(i).Cells("金額").Value xlSheet.Cells(i + 18, 11) = DataGridView2.Rows(i).Cells("備註").Value With xlApp.Selection .Font.Bold = True End With N1 = i + 18 Next i xlSheet.Cells(N1 + 1, 6) = "TOTAL:" : xlSheet.Cells(N1 + 1, 8) = "=SUM(H18:H" & N1 & ")" : xlSheet.Cells(N1 + 1, 10) = "=SUM(J18:J" & N1 & ")" : xlSheet.Cells(N1 + 2, 4) = "'AMOUNT金额(大写):" xlSheet.Cells(N1 + 2, 8) = "=J" & N1 + 1 : xlSheet.Cells(N1 + 3, 3) = "FOR" : xlSheet.Cells(N1 + 3, 4) = ComboBox7.Text : xlSheet.Cells(N1 + 3, 7) = ComboBox5.Text : xlSheet.Cells(N1 + 3, 9) = "SHOW" xlSheet.Cells(N1 + 3, 8) = ComboBox6.Text : xlSheet.Cells(N1 + 5, 1) = "样品请寄:廣東東莞市厚街鎮湖景大道南150米森康鞋業有限公司 人名 電話 收。" xlSheet.Cells(N1 + 7, 1) = "IMPORTANT: **请回复交期并提供物料报价" : xlSheet.Cells(N1 + 11, 3) = "驗證碼" : xlSheet.Cells(N1 + 11, 4) = "" : xlSheet.Cells(N1 + 12, 3) = "核准:" xlSheet.Cells(N1 + 12, 10) = "制表人:" : xlSheet.Cells(N1 + 12, 11) = TextBox7.Text AA(xlApp, xlSheet) xlSheet.PageSetup.PrintArea = "" xlApp.Cells.Select() xlSheet.Range("B1").Select() xlApp.Application.WindowState = xlMinimized xlApp.ActiveSheet.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="0911274990") xlApp.ActiveSheet.EnableSelection = 1 MsgBox("列印完成") End Sub Private Shared Function NewMethod(xlBook As Workbook) As Worksheet Return CType(xlBook.Worksheets.Add, Worksheet) End Function Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet) xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 5.86 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 8 xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 30 : xlSheet.Columns("D:E").Select : myExcel.Selection.ColumnWidth = 10 xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 20 : xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 6.47 xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 10 : xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 12 xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 12 : xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 25.14 xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 86 : xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 8.25 xlSheet.Rows("4:5").Select : myExcel.Selection.RowHeight = 8.25 : xlSheet.Rows("9:9").Select : myExcel.Selection.RowHeight = 8.25 xlSheet.Rows("13:13").Select : myExcel.Selection.RowHeight = 8.25 : xlSheet.Rows("14:14").Select : myExcel.Selection.RowHeight = 25 xlSheet.Rows("15:15").Select : myExcel.Selection.RowHeight = 8.25 xlSheet.Range("A1:K1").Select() : myExcel.Selection.Merge With myExcel.Selection.Font : .Name = "新細明體" : .Size = 28 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontMinor : End With xlSheet.Range("A3:K3").Select() : myExcel.Selection.Merge : myExcel.Selection.Font.Bold = True xlSheet.Range("A6:K6").Select() : myExcel.Selection.Merge : myExcel.Selection.Font.Bold = True xlSheet.Range("A7:K7").Select() : myExcel.Selection.Merge : myExcel.Selection.Font.Bold = True xlSheet.Range("B10:I10").Select() : myExcel.Selection.Merge With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("B11:I11").Select() : myExcel.Selection.Merge With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("B12:I12").Select() : myExcel.Selection.Merge With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("K10").Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Rows("14:14").Select : myExcel.Selection.Font.Bold = True xlSheet.Range("B16:C16").Select() : myExcel.Selection.Merge : xlSheet.Range("D16:E16").Select() : myExcel.Selection.Merge xlSheet.Range("B17:C17").Select() : myExcel.Selection.Merge : xlSheet.Range("D17:E17").Select() : myExcel.Selection.Merge xlSheet.Range("A16:K17").Select() : myExcel.Selection.Font.Bold = True xlSheet.Rows("8:8").Select : myExcel.Selection.Font.Bold = True 位置1 = "18:" & N1 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 35.25 位置1 = N1 + 5 & ":" & N1 + 5 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 35.25 : 位置1 = N1 + 1 & ":" & N1 + 3 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 20 位置1 = N1 + 4 & ":" & N1 + 4 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 8.5 : 位置1 = N1 + 6 & ":" & N1 + 6 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 8.5 位置1 = N1 + 8 & ":" & N1 + 10 : xlSheet.Range(位置1).Select() : myExcel.Selection.RowHeight = 8.5 For i As Integer = 18 To N1 xlSheet.Range("B" & i & ":C" & i & "").Select() : myExcel.Selection.Merge : xlSheet.Range("D" & i & ":E" & i & "").Select() : myExcel.Selection.Merge xlSheet.Range("H" & i & ":J" & i & "").Select() : myExcel.Selection.Style = "Comma" Next i xlSheet.Rows("18:" & N1 + 2).Select With myExcel.Selection.Font : .Name = "新細明體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontMinor : End With xlSheet.Range("C" & N1 + 3).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Range("D" & N1 + 3 & ":F" & N1 + 3).Select() : myExcel.Selection.Merge xlSheet.Range("A" & N1 + 5 & ":K" & N1 + 5).Select() : myExcel.Selection.Merge With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("A16:K" & N1).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("A4:K4").Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone xlSheet.Range("A9:K9").Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone xlSheet.Range("A12:K12").Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone xlSheet.Range("D" & N1 + 2 & ":G" & N1 + 2).Select() : myExcel.Selection.Merge xlSheet.Range("H" & N1 + 2 & ":J" & N1 + 2).Select() : myExcel.Selection.Merge xlSheet.Range("H" & N1 + 2 & ":J" & N1 + 2).Select() : myExcel.Selection.NumberFormatLocal = "[DBNum2][$-zh-CN]G/通用格式" myExcel.ActiveWindow.Zoom = 80 : myExcel.ActiveWindow.DisplayGridlines = False xlSheet.Range("C" & N1 + 11).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Range("C" & N1 + 12).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Range("A" & N1 + 5 & ":K" & N1 + 5).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 myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone xlSheet.Range("A7:K7").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("A6:K6").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("A3:K3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("A1:K1").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With xlSheet.Range("N12").Select() xlSheet.Range("B18:C" & N1).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : End With xlSheet.Range("D18:F" & N1).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : End With End Sub End Class