Imports System.IO
Public Class 客戶資料表
    Dim DGVX As Integer
    Private Sub 計算分流1_Tick(sender As Object, e As EventArgs) Handles 計算分流1.Tick
        計算分流1.Enabled = False
        Dim ds1 As New DataSet
        附件_dgv.DataSource = Nothing : ds1.Clear()
        附件_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        附件_dgv.ColumnHeadersHeight = 25 : 附件_dgv.AllowUserToAddRows = False : 附件_dgv.RowTemplate.Height = 25
        SQL_連線字串_圖片資料庫() : SQL_客戶資料附件()
        da.Fill(ds1) : 附件_dgv.DataSource = ds1.Tables(0) : conn.Close()
        附件_dgv.Columns(0).Visible = False : 附件_dgv.Columns(1).ReadOnly = True
        For i As Integer = 0 To 附件_dgv.Rows.Count - 1 : 附件_dgv.Rows(i).Cells(1).Value = "附件-" & i + 1 : Next
        If 附件_dgv.Rows.Count > 0 Then : DGVX = 0 : 附件編碼_lb.Text = 附件_dgv.Rows(0).Cells(0).Value.ToString : 圖片清單讀取() : End If
    End Sub
    Private Sub 計算分流2_Tick(sender As Object, e As EventArgs) Handles 計算分流2.Tick
        計算分流2.Enabled = False
        Dim ds1 As New DataSet
        會議附件_dgv.DataSource = Nothing : ds1.Clear()
        會議附件_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        會議附件_dgv.ColumnHeadersHeight = 25 : 會議附件_dgv.AllowUserToAddRows = False : 會議附件_dgv.RowTemplate.Height = 25
        SQL_連線字串_圖片資料庫() : SQL_客戶會議附件()
        da.Fill(ds1) : 會議附件_dgv.DataSource = ds1.Tables(0) : conn.Close()
        會議附件_dgv.Columns(0).Visible = False : 會議附件_dgv.Columns(1).ReadOnly = True
        For i As Integer = 0 To 會議附件_dgv.Rows.Count - 1 : 會議附件_dgv.Rows(i).Cells(1).Value = "附件-" & i + 1 : Next
        If 會議附件_dgv.Rows.Count > 0 Then : DGVX = 0 : 附件編碼1_lb.Text = 會議附件_dgv.Rows(0).Cells(0).Value.ToString : 圖片清單讀取1() : End If
    End Sub
    Private Sub Set_客戶清單()
        Dim ds1 As New DataSet
        清單1_dgv.DataSource = Nothing : ds1.Clear()
        清單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單1_dgv.ColumnHeadersHeight = 25 : 清單1_dgv.AllowUserToAddRows = False : 清單1_dgv.RowTemplate.Height = 35
        PA40 = 關鍵字_tb.Text : PA41 = 分類1_cb.Text : SQL_客戶資料表讀取()
        da.Fill(ds1) : 清單1_dgv.DataSource = ds1.Tables(0) : conn.Close()
        清單1_dgv.Columns(0).Visible = False : 清單1_dgv.Columns(1).ReadOnly = True
        For i As Integer = 2 To 14 : 清單1_dgv.Columns(i).Visible = False : Next
    End Sub
    Private Sub Set_訪談清單()
        Dim ds1 As New DataSet
        訪談紀錄_dgv.DataSource = Nothing : ds1.Clear()
        訪談紀錄_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        訪談紀錄_dgv.ColumnHeadersHeight = 25 : 訪談紀錄_dgv.AllowUserToAddRows = False : 訪談紀錄_dgv.RowTemplate.Height = 80
        PA40 = 關鍵字_tb.Text : PA41 = 分類1_cb.Text : SQL_客戶訪談表讀取()
        da.Fill(ds1) : 訪談紀錄_dgv.DataSource = ds1.Tables(0) : conn.Close()
        訪談紀錄_dgv.Columns(0).Visible = False : 訪談紀錄_dgv.Columns(1).FillWeight = 40 : 訪談紀錄_dgv.Columns(2).FillWeight = 40 : 訪談紀錄_dgv.Columns(3).FillWeight = 130
        訪談紀錄_dgv.Columns(1).ReadOnly = True : 訪談紀錄_dgv.Columns(10).FillWeight = 20
        訪談紀錄_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        For i As Integer = 5 To 9 : 訪談紀錄_dgv.Columns(i).Visible = False : Next
        訪談紀錄_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        For i As Integer = 0 To 訪談紀錄_dgv.Rows.Count - 1
            If 訪談紀錄_dgv.Rows(i).Cells(9).Value.ToString = "" Then : 訪談紀錄_dgv.Rows(i).Cells(10).Value = "" : Else : 訪談紀錄_dgv.Rows(i).Cells(10).Value = "V" : End If
        Next
    End Sub
    Private Sub Set_承租清單()
        Dim ds1 As New DataSet
        承租_dgv.DataSource = Nothing : ds1.Clear()
        承租_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        承租_dgv.ColumnHeadersHeight = 25 : 承租_dgv.AllowUserToAddRows = False : 承租_dgv.RowTemplate.Height = 60
        SQL_客戶承租表讀取()
        da.Fill(ds1) : 承租_dgv.DataSource = ds1.Tables(0) : conn.Close()
        承租_dgv.Columns("租金").DefaultCellStyle.Format = "#,##0" : 承租_dgv.Columns("租期結束").Visible = False
        承租_dgv.Columns("租金").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        For I As Integer = 0 To 7 : 承租_dgv.Columns(I).ReadOnly = True : Next
        For I As Integer = 0 To 承租_dgv.Rows.Count - 1
            承租_dgv.Rows(I).Cells("租期").Value = 承租_dgv.Rows(I).Cells("租期").Value.ToString & " - " & 承租_dgv.Rows(I).Cells("租期結束").Value.ToString
        Next
    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 刪除訪談_tb_MouseEnter(sender As Object, e As EventArgs) Handles 刪除訪談_tb.MouseEnter
        ToolTip1.SetToolTip(Me.刪除訪談_tb, "刪除訪談內容")
    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 客戶資料表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = YS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Panel6.SendToBack() : 客戶名稱_tb.ReadOnly = True : 附件編碼_lb.Text = "" : 附件編碼1_lb.Text = "" : 視窗2_pl.Visible = False
        清單1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 訪談紀錄_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 10)
    End Sub
    Private Sub 客戶資料表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        SQL_客戶類別() : 分類1_cb.Items.Clear() : 分類1_cb.Items.Add("") : While (dr.Read()) : 分類1_cb.Items.Add(dr("類別")) : End While : conn.Close()
        Set_客戶清單()
    End Sub
    Private Sub 客戶資料表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        If 客戶名稱_tb.Text = "" Then : SQL_客戶資料表刪除() : End If
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : YS_ERP_SYS.Timer1.Enabled = False : YS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : YS_ERP_SYS.Timer1.Enabled = False : YS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 清單1_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 清單1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            SQL_客戶類別() : 分類2_cb.Items.Clear() : 分類2_cb.Items.Add("") : While (dr.Read()) : 分類2_cb.Items.Add(dr("類別")) : End While : conn.Close()
            流水號_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("流水號").Value.ToString : 客戶名稱_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("客戶名稱").Value.ToString
            分類2_cb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("類別").Value.ToString : 電話_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("電話").Value.ToString
            傳真_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("傳真").Value.ToString : 職務_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("單位/職稱").Value.ToString
            姓名_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString : 地址_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("地址").Value.ToString
            聯繫方式_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("聯繫方式").Value.ToString : 負責區域_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("負責區域").Value.ToString
            來源_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("來源").Value.ToString : 簽約_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("簽約").Value.ToString
            客需_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("客需").Value.ToString : 圖片庫 = 清單1_dgv.Rows(e.RowIndex).Cells("文件伺服器").Value.ToString
            製錶_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("訪談編號").Value.ToString : 訪談編號_tb.Text = "" : 訪談編號_tb.Text = "" : 會議名稱_tb.Text = ""
            會議地點_tb.Text = "" : 會議內容_tb.Text = "" : 會議時間_dtp.Value = Today() : 出席人員_tb.Text = "" : 附件_pb.Image = Nothing : 附件編碼_lb.Text = ""
            附件編碼1_lb.Text = "" : 會議附件_pb.Image = Nothing
            Set_訪談清單() : Set_承租清單() : 計算分流1.Enabled = True ': Set_附件清單()
        End If
    End Sub
    Private Sub 訪談紀錄_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 訪談紀錄_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            訪談編號_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("流水號").Value.ToString : 會議名稱_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("會議名稱").Value.ToString
            會議地點_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("會議地點").Value.ToString : 會議內容_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("會議內容").Value.ToString
            If 訪談紀錄_dgv.Rows(e.RowIndex).Cells("會議時間").Value.ToString <> "" Then : 會議時間_dtp.Value = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("會議時間").Value.ToString : End If
            出席人員_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("出席人員").Value.ToString : 計算分流2.Enabled = True : 會議附件_pb.Image = Nothing
        End If
    End Sub
    Private Sub 附件_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 附件_dgv.CellClick
        If e.RowIndex = -1 Then : Else : DGVX = e.RowIndex : 圖片清單讀取() : End If
    End Sub
    Private Sub 圖片清單讀取()
        附件編碼_lb.Text = 附件_dgv.Rows(DGVX).Cells(0).Value.ToString : PA2 = 附件_dgv.Rows(DGVX).Cells(0).Value.ToString
        SQL_連線字串_圖片資料庫() : 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
    End Sub
    Private Sub 會議附件_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 會議附件_dgv.CellClick
        If e.RowIndex = -1 Then : Else : DGVX = e.RowIndex : 圖片清單讀取1() : End If
    End Sub
    Private Sub 圖片清單讀取1()
        附件編碼1_lb.Text = 會議附件_dgv.Rows(DGVX).Cells(0).Value.ToString : PA2 = 會議附件_dgv.Rows(DGVX).Cells(0).Value.ToString
        SQL_連線字串_圖片資料庫() : 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
    End Sub
    Private Sub 關鍵字_tb_KeyDown(sender As Object, e As KeyEventArgs) Handles 關鍵字_tb.KeyDown
        If e.KeyCode = Keys.Enter Then : Set_客戶清單() : End If
    End Sub
    Private Sub 分類1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 分類1_cb.SelectedIndexChanged
        Set_客戶清單()
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        Set_客戶清單()
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        Dim NUM0 As Integer : DTP1 = Format(Today(), "yyyyMMdd")
        SQL_客戶資料表流水() : If dr.Read Then : NUM0 = Strings.Right(dr("流水號").ToString, 3) : Else : NUM0 = 0 : End If
        NUM0 += 1
        If NUM0 < 10 Then : 流水號_tb.Text = "WP-" & DTP1 & "-00" & NUM0
        ElseIf NUM0 > 9 And NUM0 < 100 Then : 流水號_tb.Text = "WP-" & DTP1 & "-0" & NUM0
        ElseIf NUM0 > 99 Then : 流水號_tb.Text = "WP-" & DTP1 & "-" & NUM0
        End If : 客戶名稱_tb.ReadOnly = False : 會議存檔_bt.Enabled = False : 訪談紀錄_dgv.DataSource = Nothing : 附件_pb.Image = Nothing : 會議附件_pb.Image = Nothing
        客戶名稱_tb.Text = "" : 分類2_cb.Text = "" : 電話_tb.Text = "" : 傳真_tb.Text = "" : 地址_tb.Text = "" : 姓名_tb.Text = "" : 職務_tb.Text = ""
        聯繫方式_tb.Text = "" : 來源_tb.Text = "" : 簽約_tb.Text = "" : 客需_tb.Text = "" : 負責區域_tb.Text = "" : 清單1_dgv.Enabled = False : 訪談編號_tb.Text = ""
        製錶_tb.Text = gUserName : 訪談編號_tb.Text = "" : 訪談編號_tb.Text = "" : 會議名稱_tb.Text = "" : 附件_dgv.DataSource = Nothing : 會議附件_dgv.DataSource = Nothing
        會議地點_tb.Text = "" : 會議內容_tb.Text = "" : 會議時間_dtp.Value = Today() : 出席人員_tb.Text = "" : 附件編碼_lb.Text = ""
        SQL_資料庫選擇() : If dr.Read() Then : 圖片庫 = dr("文件資料庫").ToString : Else : MsgBox("圖片資料庫已滿，請找系統管理員!!") : Me.Close() : End If
        SQL_客戶資料表新增()
    End Sub
    Private Sub 新增訪談內容_bt_Click(sender As Object, e As EventArgs) Handles 新增訪談內容_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇客戶資料，才能新增訪談內容!!") : Else
            If 清單1_dgv.Enabled = False Then : SQL_客戶名稱驗證() : If dr.Read Then : MsgBox("客戶名稱重複，無法新增客戶資料!!") : Exit Sub : End If : End If
            If 製錶_tb.Text = "" Or 製錶_tb.Text = gUserName Then : SQL_客戶資料表修改() : 訪談存檔() : Else : If CC(21) = True Then : SQL_客戶資料表修改() : End If : 訪談存檔() : End If
            Dim NUM0 As Integer : DTP1 = Format(Today(), "yyyyMMdd") : Dim 訪談流水 As String = ""
            SQL_客戶訪談表流水() : If dr.Read Then : NUM0 = Strings.Right(dr("流水號").ToString, 3) : Else : NUM0 = 0 : End If
            NUM0 += 1
            If NUM0 < 10 Then : 訪談流水 = "PG-" & DTP1 & "-00" & NUM0
            ElseIf NUM0 > 9 And NUM0 < 100 Then : 訪談流水 = "PG-" & DTP1 & "-0" & NUM0
            ElseIf NUM0 > 99 Then : 訪談流水 = "PG-" & DTP1 & "-" & NUM0
            End If : PA = 訪談流水 : SQL_客戶訪談表新增() : Set_訪談清單() : Set_客戶清單()
            客戶名稱_tb.ReadOnly = True : 清單1_dgv.Enabled = True : 會議存檔_bt.Enabled = True
        End If
    End Sub
    Private Sub 訪談存檔()
        For I As Integer = 0 To 訪談紀錄_dgv.Rows.Count - 1
            PA1 = 訪談紀錄_dgv.Rows(I).Cells("流水號").Value.ToString : PA2 = 訪談紀錄_dgv.Rows(I).Cells("訪談內容").Value.ToString
            PA3 = 訪談紀錄_dgv.Rows(I).Cells("內容追蹤").Value.ToString : PA4 = 訪談紀錄_dgv.Rows(I).Cells("地點").Value.ToString : SQL_訪談表修改()
        Next
    End Sub
    Private Sub 確認新增_bt_Click(sender As Object, e As EventArgs) Handles 確認新增_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇客戶資料，才能新增訪談內容!!") : Else
            If 製錶_tb.Text = "" Or 製錶_tb.Text = gUserName Then : 確認新增() : Else : If CC(21) = True Then : 確認新增() : End If : End If : 訪談存檔() : MsgBox("存檔完成!!")
        End If
    End Sub
    Private Sub 確認新增()
        If 清單1_dgv.Enabled = False Then : SQL_客戶名稱驗證() : If dr.Read Then : MsgBox("客戶名稱重複，無法新增客戶資料!!") : 客戶名稱_tb.Text = "" : Exit Sub : End If : End If
        SQL_客戶資料表修改() : Set_客戶清單()
        客戶名稱_tb.ReadOnly = True : 清單1_dgv.Enabled = True : 會議存檔_bt.Enabled = True
    End Sub
    Private Sub 會議存檔_bt_Click(sender As Object, e As EventArgs) Handles 會議存檔_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇客戶資料，才能繼續後續的操作!!") : Else
            If 訪談編號_tb.Text = "" Then : MsgBox("會議記錄跟隨著訪談紀錄，請先選擇訪談紀錄或是新增訪談紀錄!!") : Else
                訪談存檔() : SQL_會議記錄修改() : MsgBox("會議記錄存檔完成!!") : Set_訪談清單()
            End If
        End If
    End Sub
    Private Sub 刪除訪談_tb_Click(sender As Object, e As EventArgs) Handles 刪除訪談_tb.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇客戶資料，才能繼續後續的操作!!") : Else
            If 訪談編號_tb.Text = "" Then : MsgBox("請先選擇訪談紀錄!!") : Else
                Dim result As DialogResult = MessageBox.Show("請確定是否要刪除選定的訪談紀錄?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    PA11 = InputBox("請輸入大寫 [YES]，並按下確認來刪除資料!!")
                    If PA11 = "YES" Then : 訪談存檔() : SQL_訪談表刪除() : MsgBox("資料刪除完成!!") : Set_訪談清單() : End If
                End If
            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
            If 製錶_tb.Text = gUserName Then
                Dim result As DialogResult = MessageBox.Show("請確定是否要刪除選定的客戶資料?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    PA11 = InputBox("請輸入大寫 [YES]，並按下確認來刪除資料!!")
                    If PA11 = "YES" Then : SQL_客戶資料表刪除() : Set_客戶清單() : MsgBox("刪除完成!!")
                        訪談紀錄_dgv.DataSource = Nothing : 會議地點_tb.Text = "" : 會議內容_tb.Text = "" : 會議時間_dtp.Value = Today() : 附件_dgv.DataSource = Nothing
                        客戶名稱_tb.Text = "" : 分類2_cb.Text = "" : 電話_tb.Text = "" : 傳真_tb.Text = "" : 地址_tb.Text = "" : 姓名_tb.Text = "" : 職務_tb.Text = ""
                        聯繫方式_tb.Text = "" : 來源_tb.Text = "" : 簽約_tb.Text = "" : 客需_tb.Text = "" : 負責區域_tb.Text = "" : 訪談編號_tb.Text = "" : 附件_pb.Image = Nothing
                        製錶_tb.Text = gUserName : 訪談編號_tb.Text = "" : 訪談編號_tb.Text = "" : 會議名稱_tb.Text = "" : 流水號_tb.Text = "" : 出席人員_tb.Text = ""
                        附件編碼_lb.Text = "" : 會議附件_pb.Image = Nothing : 會議附件_dgv.DataSource = Nothing
                    End If
                End If
            Else
                MsgBox("沒有權限修改其他人員建置的客戶資料!!")
            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
            開啟檔案.Filter = "圖片文件 (*.jpg; *.jpeg; *.png; *.bmp)|*.jpg;*.jpeg;*.png;*.bmp"
            開啟檔案.Title = "選擇圖片文件"
            開啟檔案.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
            If 開啟檔案.ShowDialog() = DialogResult.OK Then
                Try
                    附件_pb.Image = Image.FromFile(開啟檔案.FileName) : 附件_pb.SizeMode = 4

                    Dim NUM0 As Integer : DTP1 = Format(Today(), "yyyyMMdd") : Dim 附件流水 As String = ""
                    SQL_連線字串_圖片資料庫() : SQL_客戶資料附件流水驗證() : If dr.Read Then : NUM0 = Strings.Right(dr("流水號").ToString, 3) : Else : NUM0 = 0 : End If
                    NUM0 += 1
                    If NUM0 < 10 Then : 附件流水 = "IM-" & DTP1 & "-00" & NUM0
                    ElseIf NUM0 > 9 And NUM0 < 100 Then : 附件流水 = "IM-" & DTP1 & "-0" & NUM0
                    ElseIf NUM0 > 99 Then : 附件流水 = "IM-" & DTP1 & "-" & NUM0
                    End If : PA1 = 附件流水 : PA49 = 開啟檔案.FileName : SQL_會議圖片入系統()
                    計算分流1.Enabled = True : MsgBox("附件導入系統完成!!")
                Catch ex As Exception
                    MessageBox.Show("無法加載圖片: " & ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
            End If
        End If
    End Sub
    Private Sub 讀取資料夾路徑_rbt_Click(sender As Object, e As EventArgs) Handles 刪除附件_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇客戶資料，才能繼續後續的操作!!") : Else
            If 附件編碼_lb.Text = "" Then : MsgBox("請先選擇附件!!") : Else
                SQL_連線字串_圖片資料庫() : SQL_客戶資料附件刪除() ': Set_附件清單() : MsgBox("刪除完成!!")
                計算分流1.Enabled = True : MsgBox("刪除完成!!")
            End If
        End If
    End Sub
    Private Sub 讀取資料夾路徑1_bt_Click(sender As Object, e As EventArgs) Handles 讀取資料夾路徑1_bt.Click
        If 訪談編號_tb.Text = "" Then : MsgBox("請先選擇訪談資料，才能繼續後續的操作!!") : Else
            開啟檔案.Filter = "圖片文件 (*.jpg; *.jpeg; *.png; *.bmp)|*.jpg;*.jpeg;*.png;*.bmp"
            開啟檔案.Title = "選擇圖片文件"
            開啟檔案.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
            If 開啟檔案.ShowDialog() = DialogResult.OK Then
                Try
                    會議附件_pb.Image = Image.FromFile(開啟檔案.FileName) : 會議附件_pb.SizeMode = 4

                    Dim NUM0 As Integer : DTP1 = Format(Today(), "yyyyMMdd") : Dim 附件流水 As String = ""
                    SQL_連線字串_圖片資料庫() : SQL_客戶會議附件流水驗證() : If dr.Read Then : NUM0 = Strings.Right(dr("流水號").ToString, 3) : Else : NUM0 = 0 : End If
                    NUM0 += 1
                    If NUM0 < 10 Then : 附件流水 = "IM-" & DTP1 & "-00" & NUM0
                    ElseIf NUM0 > 9 And NUM0 < 100 Then : 附件流水 = "IM-" & DTP1 & "-0" & NUM0
                    ElseIf NUM0 > 99 Then : 附件流水 = "IM-" & DTP1 & "-" & NUM0
                    End If : PA1 = 附件流水 : PA49 = 開啟檔案.FileName : SQL_會議附件圖片入系統()
                    計算分流2.Enabled = True : MsgBox("附件導入系統完成!!")
                Catch ex As Exception
                    MessageBox.Show("無法加載圖片: " & ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
            End If
        End If
    End Sub
    Private Sub 刪除附件1_bt_Click(sender As Object, e As EventArgs) Handles 刪除附件1_bt.Click
        If 訪談編號_tb.Text = "" Then : MsgBox("請先選擇訪談資料，才能繼續後續的操作!!") : Else
            If 附件編碼1_lb.Text = "" Then : MsgBox("請先選擇附件!!") : Else
                SQL_連線字串_圖片資料庫() : SQL_客戶會議附件刪除() ': Set_附件清單() : MsgBox("刪除完成!!")
                計算分流2.Enabled = True : MsgBox("刪除完成!!")
            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
            If 視窗2_pl.Visible = False Then
                視窗2_pl.Location = New System.Drawing.Point((Panel1.Size.Width - 視窗2_pl.Size.Width) / 2, (Panel1.Size.Height - 視窗2_pl.Size.Height) / 2)
                視窗2_pl.Visible = True : 視窗2_pl.BringToFront()
            Else : End If
        End If
    End Sub
    Private Sub 附件_pb_Click(sender As Object, e As EventArgs) Handles 附件_pb.Click
        If 附件_pb.Image IsNot Nothing Then : 圖片傳遞 = 附件_pb.Image : 圖片放大視窗.ShowDialog() : End If
    End Sub
    Private Sub 會議附件_pb_Click(sender As Object, e As EventArgs) Handles 會議附件_pb.Click
        If 會議附件_pb.Image IsNot Nothing Then : 圖片傳遞 = 會議附件_pb.Image : 圖片放大視窗.ShowDialog() : End If
    End Sub
    Private Sub 字體大小_nud_ValueChanged(sender As Object, e As EventArgs) Handles 字體大小_nud.ValueChanged
        會議內容_tb.Font = New Font("微軟正黑體", 字體大小_nud.Value)
    End Sub
    Private Sub 列印客戶資料表_bt_Click(sender As Object, e As EventArgs) Handles 列印客戶資料表_bt.Click
        MsgBox("功能開發中!!")
    End Sub
    Private Sub 列印會議記錄_bt_Click(sender As Object, e As EventArgs) Handles 列印會議記錄_bt.Click
        MsgBox("功能開發中!!")
    End Sub
    '----------------------自創視窗滑鼠拖曳功能---------------------------------------------------------------------------------------------------------
    Dim OldX, OldY As Long : Dim drag As Boolean
    Private Sub CanceL2_bt_Click(sender As Object, e As EventArgs) Handles CanceL2_bt.Click
        If 視窗2_pl.Visible = False Then : 視窗2_pl.Visible = True : 視窗2_pl.BringToFront() : Else
            視窗2_pl.Visible = False : End If
    End Sub
    Private Sub 視窗2_pl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub 視窗2_pl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseMove
        If drag Then : 視窗2_pl.Left = 視窗2_pl.Left + e.X - OldX : 視窗2_pl.Top = 視窗2_pl.Top + e.Y - OldY : End If
    End Sub
    Private Sub 視窗2_pl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseUp
        drag = False
    End Sub
End Class