123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- 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
- Imports Microsoft.Office.Interop.Excel
- Imports System.IO
- Imports System.Net
-
- Public Class 物料資料庫
- ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
- Dim 資料新增判斷 As Boolean : Dim EDR, N1 As Integer : Dim ESTR As String : Dim 首次開啟 As Boolean = False : Dim str As String
- Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
- Private Sub Set_清單()
- 物料清單_dgv.DataSource = Nothing : ds1.Clear() : 物料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 物料清單_dgv.ColumnHeadersHeight = 40
- 物料清單_dgv.AllowUserToAddRows = False
- 物料清單_dgv.RowTemplate.Height = 30
-
- SQL_物料檔案_清單()
- da.Fill(ds1) : 物料清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
-
- 物料清單_dgv.Columns("料號").FillWeight = 45 : 物料清單_dgv.Columns("廠商").FillWeight = 60 : 物料清單_dgv.Columns("成本").FillWeight = 30
- 物料清單_dgv.Columns("品名").FillWeight = 120 : 物料清單_dgv.Columns("停用").FillWeight = 20 : 物料清單_dgv.Columns("圖片").Visible = False
- 物料清單_dgv.Columns("最低庫存量").Visible = False : 物料清單_dgv.Columns("供應商").Visible = False : 物料清單_dgv.Columns("刪除").FillWeight = 20
- 物料清單_dgv.Columns("廠牌").FillWeight = 25 : 物料清單_dgv.Columns("車種年份").FillWeight = 80 : 物料清單_dgv.Columns("單位").FillWeight = 20
- 物料清單_dgv.Columns("倉庫").FillWeight = 15 : 物料清單_dgv.Columns("狀態").FillWeight = 25
- 物料清單_dgv.Columns("成本").DefaultCellStyle.Format = "#,##0.##"
- 物料清單_dgv.Columns("成本").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
- 物料清單_dgv.Columns("成本").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
-
- 物料清單_dgv.Columns("料號").ReadOnly = True : 物料清單_dgv.Columns("供應商").ReadOnly = True : 物料清單_dgv.Columns("成本").ReadOnly = True
- 物料清單_dgv.Columns("圖片").ReadOnly = True : 物料清單_dgv.Columns("品名").ReadOnly = True : 物料清單_dgv.Columns("廠牌").ReadOnly = True
- 物料清單_dgv.Columns("車種年份").ReadOnly = True : 物料清單_dgv.Columns("單位").ReadOnly = True
- 物料清單_dgv.Columns("倉庫").ReadOnly = True : 物料清單_dgv.Columns("廠商").ReadOnly = True : 物料清單_dgv.Columns("狀態").ReadOnly = True
- 資料筆數_tb.Text = 物料清單_dgv.Rows.Count
- For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
- 物料清單_dgv("刪除", i).Value = False
- Next
-
- End Sub
- Private Sub 單位_cb_下拉表單資料載入()
- SQL_物料資料庫單位_下拉清單() : 單位_cb.Items.Clear()
- 單位_cb.Items.Add("")
- While (dr.Read()) : 單位_cb.Items.Add(dr("單位")) : End While : conn.Close()
- End Sub
-
- Private Sub 物料檔案_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
- Dim type0 As Type = 物料清單_dgv.GetType()
- Dim pi0 As Reflection.PropertyInfo = type0.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
- pi0.SetValue(物料清單_dgv, True, Nothing)
-
- 地區編碼_cb.Enabled = False : 下載檔名_tb.Visible = False : 檔名讀取_tb.Visible = False : 供應商編碼_tb.Visible = False '--------------------控件隱藏、操作許可設定與其他基本顯示設定
- 料號_tb.Enabled = False : 批量存檔_bt.Enabled = False : 批輛停用選擇_ch.Enabled = False : 批量刪除選擇_ch.Enabled = False : 批量刪除_bt.Enabled = False : 狀態_lb.Text = "預覽狀態"
-
- If Val(登入人級別) <= 2 Then '--------------------刪除資料權限
- 刪除_tsm.Enabled = True : 刪除_bt.Enabled = True : 批量刪除_bt.Enabled = False
- Else
- 刪除_tsm.Enabled = False : 刪除_bt.Enabled = False : 批量刪除_bt.Enabled = False
- End If
-
- 首次開啟 = False : Set_清單() : 首次開啟 = True '--------------------資料讀取
-
- If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機資料夾_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If '--------------------讀取本機資料夾位置
- Target1 = Target & AA(1) & "/"
-
- If ICS_ASMS_ERP_SYS.Size.Width > 1440 And ICS_ASMS_ERP_SYS.Size.Height > 900 Then
- 字體_NUD.Value = 12
- ElseIf ICS_ASMS_ERP_SYS.Size.Width <= 1440 And ICS_ASMS_ERP_SYS.Size.Height <= 900 Then
- 字體_NUD.Value = 7.6
- End If
- 單位_cb_下拉表單資料載入()
- SQL_物料資料庫_類別_下拉清單() : 地區_cb.Items.Clear()
- While (dr.Read()) : 地區_cb.Items.Add(dr("類別")) : End While : conn.Close()
- End Sub
- Private Sub 物料檔案_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
- If ICS_ASMS_ERP_SYS.Size.Width > 1440 And ICS_ASMS_ERP_SYS.Size.Height > 900 Then
- 字體_NUD.Value = 12
- ElseIf ICS_ASMS_ERP_SYS.Size.Width <= 1440 And ICS_ASMS_ERP_SYS.Size.Height <= 900 Then
- 字體_NUD.Value = 8
- End If
- End Sub
- Private Sub 供應商資料表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
- If 資料新增判斷 = True Then '--------------------如果再關閉介面時,資料新增判斷是開啟的,就無條件刪除控件上的那筆資料
- PA20 = 料號_tb.Text : SQL_物料檔案_刪除() '--------------------資料刪除
- End If
- End Sub
- Private Sub 物料清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
- If 首次開啟 = True Then
- If e.RowIndex = -1 Then : Else
- 料號_tb.Text = 物料清單_dgv("料號", e.RowIndex).Value.ToString : 供應商編碼_tb.Text = 物料清單_dgv("供應商", e.RowIndex).Value.ToString
- 成本_nud.Value = 物料清單_dgv("成本", e.RowIndex).Value : 品名_tb.Text = 物料清單_dgv("品名", e.RowIndex).Value.ToString
- 停用_ch.Checked = 物料清單_dgv("停用", e.RowIndex).Value : 低量_nud.Value = 物料清單_dgv("最低庫存量", e.RowIndex).Value
- 車種年份_tb.Text = 物料清單_dgv("車種年份", e.RowIndex).Value.ToString : 廠牌_tb.Text = 物料清單_dgv("廠牌", e.RowIndex).Value.ToString
- 單位_cb.Text = 物料清單_dgv("單位", e.RowIndex).Value.ToString : 倉庫_tb.Text = 物料清單_dgv("倉庫", e.RowIndex).Value.ToString
- 物料圖_pb.Image = Nothing : PA1 = 料號_tb.Text : SQL_物料檔案_是否有圖() : 狀態_cb.Text = 物料清單_dgv("狀態", e.RowIndex).Value.ToString
- If dr.Read() Then
- If dr("是否有圖") = True Then
- 物料圖_pb.BackgroundImage = Nothing
- PA = 料號_tb.Text : SQL_物料圖庫_圖片顯示() '--------------------圖片顯示
- While dr.Read() = True
- Dim unused As Byte() = New Byte(-1) {}
- Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
- Dim oStream As New MemoryStream(bytes)
- 物料圖_pb.Image = Bitmap.FromStream(oStream)
- End While
- conn.Close()
- 物料圖_pb.SizeMode = 4
- Else
- '物料圖_pb.BackgroundImage = My.Resources.底圖1 : 物料圖_pb.BackgroundImageLayout = 3
- 物料圖_pb.Image = Nothing
- End If
- End If : conn.Close()
-
- If 批輛停用選擇_ch.Checked = True Then '--------------------批輛停用選擇功能
- If 物料清單_dgv("停用", e.RowIndex).Value = False Then
- 物料清單_dgv("停用", e.RowIndex).Value = True
- ElseIf 物料清單_dgv("停用", e.RowIndex).Value = True Then
- 物料清單_dgv("停用", e.RowIndex).Value = False
- End If
- End If
-
- If 批量刪除選擇_ch.Checked = True Then '--------------------批輛停用選擇功能
- If 物料清單_dgv("刪除", e.RowIndex).Value = False Then
- 物料清單_dgv("刪除", e.RowIndex).Value = True
- ElseIf 物料清單_dgv("刪除", e.RowIndex).Value = True Then
- 物料清單_dgv("刪除", e.RowIndex).Value = False
- End If
- End If
- End If
- End If
- End Sub
- Private Sub 物料清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 物料清單_dgv.RowPostPaint
- Dim linePen As New Pen(Color.Blue, 2)
- If e.RowIndex = 物料清單_dgv.Rows.Count - 1 Then : Exit Sub : Else
- If 物料清單_dgv("供應商", e.RowIndex).Value.ToString <> 物料清單_dgv("供應商", e.RowIndex + 1).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
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
- End If
- For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
- If 物料清單_dgv("圖片", i).Value = True And 物料清單_dgv("停用", i).Value = False Then : 物料清單_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow : End If
- If 物料清單_dgv("圖片", i).Value = False And 物料清單_dgv("停用", i).Value = False Then : 物料清單_dgv.Rows(i).DefaultCellStyle.BackColor = Color.White : End If
- If 物料清單_dgv("停用", i).Value = True Then : 物料清單_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
- If 物料清單_dgv("刪除", i).Value = True Then : 物料清單_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red : End If
- If 物料清單_dgv("刪除", i).Value = False Then : 物料清單_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black : End If
- Next
- End If
- End Sub
- Private Sub 地區_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 地區_cb.SelectedIndexChanged
- If 查詢_tb.Text = "" Then
- 供應商編碼_cb.Items.Clear() : 供應商_cb.Items.Clear() : 供應商_下拉表單資料載入()
- 'ElseIf 地區_cb.Text = "" Then
- ' 查詢_tb.Text = "" : 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
- ' ElseIf 地區_cb.Text <> "" Then
- '查詢_tb.Text = "" :
- End If
-
- End Sub
- Private Sub 供應商_下拉表單資料載入()
- BL1 = False : PA3 = 地區_cb.Text : PA4 = 供應商編碼_cb.Text
- SQL_物料資料庫_供應商_下拉清單()
- While (dr.Read()) : 供應商編碼_cb.Items.Add(dr("供應商編碼")) : 供應商_cb.Items.Add(dr("公司名")) : End While : conn.Close()
- End Sub
- Private Sub 供應商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商_cb.SelectedIndexChanged
- If 地區_cb.Text <> "" Then
- 查詢_tb.Text = "" : 供應商編碼_cb.SelectedIndex = 供應商_cb.SelectedIndex
- Set_清單()
- End If
- End Sub
- Private Sub 供應商編碼_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商編碼_cb.SelectedIndexChanged
- If 地區_cb.Text <> "" Then
- 查詢_tb.Text = "" : 供應商_cb.SelectedIndex = 供應商編碼_cb.SelectedIndex
- Set_清單()
- End If
- End Sub
- Private Sub 清空_bt_Click(sender As Object, e As EventArgs) Handles 清空_bt.Click
- 查詢_tb.Text = "" : Set_清單()
- End Sub
- Private Sub 查詢_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 查詢_tb.KeyPress
- If e.KeyChar = Chr(13) Then
- '供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
- PA = 查詢_tb.Text : Set_清單() ': 地區_cb.Text = ""
- End If
- End Sub
- Private Sub 檔案名稱_tb_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱_tb.DragEnter
- If e.Data.GetDataPresent(DataFormats.FileDrop) Then
- Dim files As String()
- files = CType(e.Data.GetData(DataFormats.FileDrop), String())
- 檔案名稱_tb.Text = files(files.Length - 1)
- End If
- Dim STR2 As Integer = 0
- str = 檔案名稱_tb.Text
- 檔名讀取_tb.Text = 檔案名稱_tb.Text
- If 檔案名稱_tb.Text = "" Then
- Else
- For i As Integer = 0 To 9999
- Dim STR1 As Integer = Strings.Len(檔名讀取_tb.Text)
- If Strings.Right((檔名讀取_tb.Text), 1) <> "\" Then
- STR1 -= 1 : STR2 += 1
- If STR1 = 0 Then
- 檔名讀取_tb.Text = ""
- 檔案名稱_tb.Text = ""
- i = 9999
- Else
- 檔名讀取_tb.Text = Strings.Left((檔名讀取_tb.Text), STR1)
- End If
- Else
- 檔名讀取_tb.Text = Strings.Right((檔案名稱_tb.Text), STR2)
- 檔案名稱_tb.Text = 檔名讀取_tb.Text
- i = 9999
- End If
- Next
- End If
- End Sub
- Private Sub 檔案名稱_tb_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱_tb.DragDrop
- Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
- For Each file As String In files
- 檔案名稱_tb.AppendText(file + Environment.NewLine)
- Next
- End Sub
- Private Sub 讀取資料夾路徑_bt_Click(sender As Object, e As EventArgs) Handles 讀取資料夾路徑_bt.Click
- If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機資料夾_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If
- End Sub
- Private Sub 圖檔入系統_bt_Click(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.Click
- If 料號_tb.Text = "" Then : MsgBox("請先選擇未指定圖片的物料料號") : Else
- Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
- For i As Integer = 1 To 10
- If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
- If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
- End If
- Next
- If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
- PA49 = str : PA = 料號_tb.Text : SQL_物料資料庫_圖檔入系統() : conn.Close() : MsgBox("上傳完畢")
- 物料圖_pb.Image = Nothing : PA = 料號_tb.Text : SQL_物料圖庫_圖片顯示()
- While dr.Read() = True
- Dim unused As Byte() = New Byte(-1) {}
- Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
- Dim oStream As New MemoryStream(bytes)
- 物料圖_pb.Image = Bitmap.FromStream(oStream)
- End While
- conn.Close()
- 物料圖_pb.SizeMode = 4
- Else : MsgBox("上傳文件並非常用圖片格式, 文件已自動刪除, 請專換成常用圖片檔案再行操作。") : End If : 檔案名稱_tb.Text = ""
- Set_清單()
- End If
- End Sub
- Private Sub 下載圖檔_bt_Click(sender As Object, e As EventArgs) Handles 下載圖檔_bt.Click
- If 物料圖_pb.Image Is Nothing Then : MsgBox("所選擇的資料沒有圖片檔案,無法下載。") : Else
- With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
- SaveFileDialog1.FileName = 料號_tb.Text & "-" & Strings.Format(Today(), "yyyyMMdd") & ".jpg"
- Dim result As DialogResult = SaveFileDialog1.ShowDialog()
- 下載檔名_tb.Text = SaveFileDialog1.FileName
- If result = System.Windows.Forms.DialogResult.Cancel Then
- Exit Sub
- End If
-
- conn.Close() : ds2.Clear() : SQL_物料圖庫_圖片下載() : da.Fill(ds2)
- If ds2.Tables(0).Rows.Count > 0 Then
- Dim imgData() As Byte
- imgData = ds2.Tables(0).Rows(0).Item("圖片")
- Dim fs As FileStream
- fs = File.Create(下載檔名_tb.Text, imgData.Length - 1)
- fs.Write(imgData, 0, imgData.Length - 1)
- fs.Close()
- End If : conn.Close() : MsgBox("下載完成")
- End If
- End Sub
- Private Sub 新增準備_bt_Click(sender As Object, e As EventArgs) Handles 新增準備_bt.Click
- If 供應商編碼_cb.Text = "" Then '--------------------設定條件讓業務控件不為空
- MsgBox("沒有選擇供應商")
- Else
- 料號_tb.Text = "" : 供應商編碼_tb.Text = "" : 成本_nud.Value = 0 : 品名_tb.Text = "" : 停用_ch.Checked = False '--------------------控件清空
- 查詢_tb.Text = "" : 車種年份_tb.Text = "" : 廠牌_tb.Text = "" : 單位_cb.Text = "" : 倉庫_tb.Text = ""
- 資料新增判斷 = True '--------------------目前的編輯狀態
- 狀態_lb.Text = "編輯狀態"
- 物料清單_dgv.Enabled = False : 查詢_tb.Enabled = False '--------------------關閉DGV與關鍵字查詢控件的點選控制功能
-
- SQL_物料資料庫_料號_最後一筆()
- If dr.Read() Then : 料號_tb.Text = dr("料號").ToString : Else : 料號_tb.Text = "MT00000000" : End If : conn.Close()
- Dim NUM1 As Integer = Double.Parse(Strings.Right(料號_tb.Text, 8)) + 1
- If NUM1 < 10 Then : 料號_tb.Text = "MT" & "0000000" & NUM1
- ElseIf NUM1 > 9 And NUM1 < 100 Then : 料號_tb.Text = "MT" & "000000" & NUM1
- ElseIf NUM1 > 99 And NUM1 < 1000 Then : 料號_tb.Text = "MT" & "00000" & NUM1
- ElseIf NUM1 > 999 And NUM1 < 10000 Then : 料號_tb.Text = "MT" & "0000" & NUM1
- ElseIf NUM1 > 9999 And NUM1 < 10000 Then : 料號_tb.Text = "MT" & "000" & NUM1
- ElseIf NUM1 > 99999 And NUM1 < 10000 Then : 料號_tb.Text = "MT" & "00" & NUM1
- ElseIf NUM1 > 999999 And NUM1 < 10000 Then : 料號_tb.Text = "MT" & "0" & NUM1
- ElseIf NUM1 > 9999999 Then : 料號_tb.Text = "MT" & NUM1
- End If
- SQL_物料檔案_新增() '--------------------人事資料表中寫入一筆資料
- End If
- End Sub
- Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
- If 品名_tb.Text = "" Then '--------------------設定條件讓地區編碼_cb控件不為空
- MsgBox("物品一定要有名稱。")
- Else
- If 狀態_cb.Text = "" Then '--------------------設定條件讓地區編碼_cb控件不為空
- MsgBox("未選擇狀態。")
- Else
- 資料新增判斷 = False '--------------------目前的編輯狀態
- 狀態_lb.Text = "預覽狀態"
- 物料清單_dgv.Enabled = True : 查詢_tb.Enabled = True '--------------------開啟DGV與關鍵字查詢控件的點選控制功能
- NU1 = 成本_nud.Value : PA1 = 品名_tb.Text : BL1 = 停用_ch.Checked : PA2 = 料號_tb.Text : NU2 = 低量_nud.Value
- SQL_物料檔案_修改() '--------------------資料修改
- Set_清單() '--------------------資料修改後重新讀取清單
- End If
- End If
- End Sub
- Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
- If 料號_tb.Text = "" Then '--------------------設定條件讓流水號控件不為空
- MsgBox("沒有選擇要刪除的資料")
- Else
- Dim aa1 As MsgBoxResult = MsgBox("確定要執行刪除指令嗎?", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- PA20 = 料號_tb.Text : SQL_物料檔案_刪除() '--------------------資料刪除
- Set_清單() '--------------------資料修改後重新讀取清單
- End If
- End If
- End Sub
- Private Sub 啟用批改_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 啟用批改_ch.Click
- If 啟用批改_ch.Checked = True Then
- 批量存檔_bt.Enabled = True : 新增準備_bt.Enabled = False : 存檔_bt.Enabled = False : 刪除_bt.Enabled = False
- 批輛停用選擇_ch.Enabled = True : 啟用批改_ch.Checked = True : 重新整理_tsm.Enabled = False
- 新增準備_tsm.Enabled = False : 存檔_tsm.Enabled = False : 刪除_tsm.Enabled = False : 批量刪除選擇_ch.Enabled = True : 批量刪除_bt.Enabled = True
- 物料清單_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 狀態_lb.Text = "批改狀態" '--------------------控件隱藏、操作許可設定與其他基本顯示設定
- MsgBox("已啟用批改模式。")
- ElseIf 啟用批改_ch.Checked = False Then
- 批量存檔_bt.Enabled = False : 新增準備_bt.Enabled = True : 存檔_bt.Enabled = True : 刪除_bt.Enabled = True
- 批輛停用選擇_ch.Enabled = False : 批輛停用選擇_ch.Checked = False : 啟用批改_ch.Checked = False : 批量刪除選擇_ch.Checked = False : 重新整理_tsm.Enabled = True
- 新增準備_tsm.Enabled = True : 存檔_tsm.Enabled = True : 刪除_tsm.Enabled = True : 批量刪除選擇_ch.Enabled = False : 批量刪除_bt.Enabled = False
- 物料清單_dgv.EditMode = DataGridViewEditMode.EditOnF2 : 狀態_lb.Text = "預覽狀態" '--------------------控件隱藏、操作許可設定與其他基本顯示設定
- End If
- End Sub
- Private Sub 批量存檔_bt_Click(sender As Object, e As EventArgs) Handles 批量存檔_bt.Click
- 批量存檔_bt.Enabled = False : 新增準備_bt.Enabled = True : 存檔_bt.Enabled = True : 刪除_bt.Enabled = True
- 批輛停用選擇_ch.Enabled = False : 批輛停用選擇_ch.Checked = False : 啟用批改_ch.Checked = False : 重新整理_tsm.Enabled = True
- 新增準備_tsm.Enabled = True : 存檔_tsm.Enabled = True : 刪除_tsm.Enabled = True : 批量刪除選擇_ch.Enabled = False : 批量刪除_bt.Enabled = False
- 物料清單_dgv.EditMode = DataGridViewEditMode.EditOnF2 : 狀態_lb.Text = "預覽狀態" '--------------------控件隱藏、操作許可設定與其他基本顯示設定
-
- For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
- 資料數 = 物料清單_dgv.Rows.Count : MyModule1.進度條()
- NU1 = 物料清單_dgv("成本", i).Value : PA1 = 物料清單_dgv("品名", i).Value
- BL1 = 物料清單_dgv("停用", i).Value : PA2 = 物料清單_dgv("料號", i).Value
- NU2 = 物料清單_dgv("最低庫存量", i).Value
- SQL_物料檔案_修改() '--------------------資料修改
- Next : conn.Close() : ICS_ASMS_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("存檔完成。")
- End Sub
- Private Sub 批量刪除_bt_Click(sender As Object, e As EventArgs) Handles 批量刪除_bt.Click
- If 批量刪除選擇_ch.Checked = False Then
- MsgBox("批量刪除選擇的功能要先打勾,並正確選擇要刪除的料號。")
- Else
- Dim aa1 As MsgBoxResult = MsgBox("確定要執行刪除指令嗎?", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- 批量存檔_bt.Enabled = False : 新增準備_bt.Enabled = True : 存檔_bt.Enabled = True : 刪除_bt.Enabled = True
- 批輛停用選擇_ch.Enabled = False : 批輛停用選擇_ch.Checked = False : 啟用批改_ch.Checked = False : 重新整理_tsm.Enabled = True
- 新增準備_tsm.Enabled = True : 存檔_tsm.Enabled = True : 刪除_tsm.Enabled = True : 批量刪除選擇_ch.Enabled = False : 批量刪除_bt.Enabled = False
- 物料清單_dgv.EditMode = DataGridViewEditMode.EditOnF2 : 狀態_lb.Text = "預覽狀態" '--------------------控件隱藏、操作許可設定與其他基本顯示設定
-
- For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
- 資料數 = 物料清單_dgv.Rows.Count : MyModule1.進度條()
- If 物料清單_dgv("刪除", i).Value = True Then
- PA20 = 物料清單_dgv("料號", i).Value : SQL_物料檔案_刪除() '--------------------資料刪除
- End If
- Next : conn.Close() : ICS_ASMS_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
-
- MsgBox("刪除完成。") : Set_清單() '--------------------資料修改後重新讀取清單
- End If
- End If
- End Sub
- Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.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, 3) = "XXXXX-物料清單"
- xlSheet.Cells(2, 1) = "料號" : xlSheet.Cells(2, 2) = "廠商編號" : xlSheet.Cells(2, 3) = "廠商"
- xlSheet.Cells(2, 4) = "品名" : xlSheet.Cells(2, 5) = "盤點數量" : xlSheet.Cells(2, 6) = "備註"
- For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
- xlSheet.Cells(i + 3, 1) = 物料清單_dgv.Rows(i).Cells("料號").Value
- xlSheet.Cells(i + 3, 2) = 物料清單_dgv.Rows(i).Cells("供應商").Value
- xlSheet.Cells(i + 3, 3) = 物料清單_dgv.Rows(i).Cells("廠商").Value
- xlSheet.Cells(i + 3, 4) = 物料清單_dgv.Rows(i).Cells("品名").Value
- N1 = i + 3
- Next
- BB(xlApp, xlSheet)
- xlSheet.PageSetup.PrintArea = ""
- xlApp.Cells.Select()
- xlSheet.Range("B1").Select()
- xlApp.Application.WindowState = xlMinimized
- xlSheet.Cells.Select()
- MsgBox("列印完成。")
- End Sub
- Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
- Return CType(xlBook.Worksheets.Add, Worksheet)
- End Function
- Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
- xlSheet.Cells.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 = xlThemeFontNone
- End With
- '
- xlSheet.Cells.Select()
- With myExcel.Selection.Font
- .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
- .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
- End With
- xlSheet.Columns("A:F").EntireColumn.AutoFit
- xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 20
- xlSheet.Cells.Select() : myExcel.Selection.RowHeight = 25
- xlSheet.Rows("2:2").Select : myExcel.Selection.AutoFilter
- xlSheet.Rows("3:3").Select : myExcel.ActiveWindow.FreezePanes = True
-
- xlSheet.Range("A1:F1").Select()
-
- 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("A1:F" & 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
- End Sub
- '-------------------滑鼠右鍵-------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Private Sub 重新整理_tsm_Click(sender As Object, e As EventArgs) Handles 重新整理_tsm.Click
- 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear() : 查詢_tb.Text = "" : Set_清單()
- End Sub
- Private Sub 新增準備_tsm_Click(sender As Object, e As EventArgs) Handles 新增準備_tsm.Click
- 新增準備_bt.PerformClick()
- End Sub
- Private Sub 存檔_tsm_Click(sender As Object, e As EventArgs) Handles 存檔_tsm.Click
- 存檔_bt.PerformClick()
- End Sub
- Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
- 物料清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
- End Sub
- Private Sub 刪除_tsm_Click(sender As Object, e As EventArgs) Handles 刪除_tsm.Click
- 刪除_bt.PerformClick()
- End Sub
- Private Sub 新增準備_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增準備_bt.MouseEnter
- ToolTip1.SetToolTip(Me.新增準備_bt, "新增準備")
- End Sub
- Private Sub 存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 存檔_bt.MouseEnter
- ToolTip1.SetToolTip(Me.存檔_bt, "存檔")
- End Sub
- Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
- ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
- End Sub
- Private Sub 批量存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 批量存檔_bt.MouseEnter
- ToolTip1.SetToolTip(Me.批量存檔_bt, "新增準備")
- End Sub
- Private Sub 批量刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 批量刪除_bt.MouseEnter
- ToolTip1.SetToolTip(Me.批量刪除_bt, "新增準備")
- End Sub
- Private Sub 列印_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印_bt.MouseEnter
- ToolTip1.SetToolTip(Me.列印_bt, "新增準備")
- End Sub
- Private Sub 新讀取資料夾路徑_bt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取資料夾路徑_bt.MouseEnter
- ToolTip1.SetToolTip(Me.讀取資料夾路徑_bt, "讀取資料夾路徑")
- End Sub
- Private Sub 圖檔入系統_bt_MouseEnter(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.MouseEnter
- ToolTip1.SetToolTip(Me.圖檔入系統_bt, "圖檔入系統或修改")
- End Sub
-
-
-
- Private Sub 下載圖檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 下載圖檔_bt.MouseEnter
- ToolTip1.SetToolTip(Me.下載圖檔_bt, "下載圖檔")
- End Sub
- End Class
|