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 Microsoft.Office.Core
Imports stdole
Imports Telerik.Windows.Documents.Fixed
Public Class 客戶資料表
    Dim DGVX As Integer
    Dim xlApp As Application
    Dim xlBook As Workbook
    Dim xlSheet As Worksheet
    Dim N2 As Integer
    Dim 已開啟 As Boolean = False
    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
        Dim 訪談編號 As String : If 製表_cb.Text = "" Or 製表_cb.Text = "所有人" Then : 訪談編號 = "%" : Else : 訪談編號 = 製表_cb.Text : End If
        Dim 集團 As String : If 集團_cb.Text = "" Then : 集團 = "%" : Else : 集團 = 集團_cb.Text : End If
        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 24 : 清單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("流水號").Visible = False : 訪談紀錄_dgv.Columns("日期").FillWeight = 30 : 訪談紀錄_dgv.Columns("洽談方式").FillWeight = 40
        訪談紀錄_dgv.Columns("訪談內容").FillWeight = 130 : 訪談紀錄_dgv.Columns("洽談時間").Visible = False : 訪談紀錄_dgv.Columns("內容追蹤").Visible = False
        訪談紀錄_dgv.Columns("日期").ReadOnly = True : 訪談紀錄_dgv.Columns("會議").FillWeight = 20 : 訪談紀錄_dgv.Columns("洽談物件").FillWeight = 40
        訪談紀錄_dgv.Columns("洽談方式").ReadOnly = True : 訪談紀錄_dgv.Columns("YS員工").FillWeight = 30 : 訪談紀錄_dgv.Columns("洽談物件").ReadOnly = True
        訪談紀錄_dgv.Columns("YS員工").ReadOnly = True
        訪談紀錄_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        For i As Integer = 5 To 9 : 訪談紀錄_dgv.Columns(i).Visible = False : Next
        訪談紀錄_dgv.Columns("會議").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        For i As Integer = 0 To 訪談紀錄_dgv.Rows.Count - 1
            If 訪談紀錄_dgv.Rows(i).Cells("會議內容").Value.ToString = "" Then : 訪談紀錄_dgv.Rows(i).Cells("會議").Value = "" : Else : 訪談紀錄_dgv.Rows(i).Cells("會議").Value = "V" : End If
            訪談紀錄_dgv.Rows(i).Cells("日期").Value = Strings.Left(訪談紀錄_dgv.Rows(i).Cells("日期").Value.ToString, 5) & " " &
                                                       Strings.Right(訪談紀錄_dgv.Rows(i).Cells("日期").Value.ToString, 5)
        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("流水號").Visible = False : 訪談紀錄大_dgv.Columns("日期").FillWeight = 30 : 訪談紀錄大_dgv.Columns("洽談方式").FillWeight = 40
        訪談紀錄大_dgv.Columns("訪談內容").FillWeight = 230 : 訪談紀錄大_dgv.Columns("洽談時間").Visible = False : 訪談紀錄大_dgv.Columns("內容追蹤").Visible = False
        訪談紀錄大_dgv.Columns("日期").ReadOnly = True : 訪談紀錄大_dgv.Columns("會議").FillWeight = 20 : 訪談紀錄大_dgv.Columns("洽談物件").ReadOnly = True
        訪談紀錄大_dgv.Columns("YS員工").FillWeight = 30 : 訪談紀錄大_dgv.Columns("洽談物件").FillWeight = 40
        訪談紀錄大_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        For i As Integer = 5 To 9 : 訪談紀錄大_dgv.Columns(i).Visible = False : Next
        訪談紀錄大_dgv.Columns("會議").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        For i As Integer = 0 To 訪談紀錄大_dgv.Rows.Count - 1
            If 訪談紀錄大_dgv.Rows(i).Cells("會議內容").Value.ToString = "" Then : 訪談紀錄大_dgv.Rows(i).Cells("會議").Value = "" : Else : 訪談紀錄大_dgv.Rows(i).Cells("會議").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
            If 承租_dgv.Rows(I).Cells("承租狀態").Value.ToString = "S" Then
                承租_dgv.Rows(I).Cells("承租狀態").Value = "S:已簽正式約"
            ElseIf 承租_dgv.Rows(I).Cells("承租狀態").Value.ToString = "H" Then
                承租_dgv.Rows(I).Cells("承租狀態").Value = "H:已簽意向書及付訂金"
            ElseIf 承租_dgv.Rows(I).Cells("承租狀態").Value.ToString = "A" Then
                承租_dgv.Rows(I).Cells("承租狀態").Value = "A:房客開發人員評估確度高,一個月內可簽約"
            ElseIf 承租_dgv.Rows(I).Cells("承租狀態").Value.ToString = "B" Then
                承租_dgv.Rows(I).Cells("承租狀態").Value = "B:房客開發評估中"
            ElseIf 承租_dgv.Rows(I).Cells("承租狀態").Value.ToString = "F" Then
                承租_dgv.Rows(I).Cells("承租狀態").Value = "F:房客無意願"
            End If
        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 放大_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
        已開啟 = False : Me.MdiParent = YS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Panel6.SendToBack() : Panel9.Visible = False
        If CC(11) Then : 客戶名稱_tb.ReadOnly = False : Else : 客戶名稱_tb.ReadOnly = True : End If
        附件編碼_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)
        訪談紀錄大_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()
        SQL_客戶資料表集團下拉() : 集團_cb.Items.Clear() : 客戶集團_cb.Items.Clear() : While (dr.Read()) : 集團_cb.Items.Add(dr("集團")) : 客戶集團_cb.Items.Add(dr("集團")) : End While
        SQL_客戶資料表製表下拉() : 製表_cb.Items.Clear() : 製表1_cb.Items.Clear() : 製表_cb.Items.Add("所有人")
        While (dr.Read()) : 製表_cb.Items.Add(dr("姓名")) : 製表1_cb.Items.Add(dr("姓名")) : End While
        If CInt(登入人級別) > 6 Then : 製表_cb.Text = gUserName : 製表_cb.Enabled = False : Else : 製表_cb.Text = "所有人" : 製表_cb.Enabled = True : End If
        Set_客戶清單()
        已開啟 = True
    End Sub
    Private Sub 客戶資料表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        If 客戶名稱_tb.Text = "" Then : SQL_客戶資料表刪除() : End If : MyModule1.虛擬桌面開啟()
    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
            姓名1_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString : 職務1_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("單位/職稱").Value.ToString
            聯繫方式1_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("聯繫方式").Value.ToString : 負責區域1_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("負責區域").Value.ToString
            姓名2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("姓名1").Value.ToString : 職務2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("單位/職稱1").Value.ToString
            聯繫方式2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("聯繫方式1").Value.ToString : 負責區域2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("負責區域1").Value.ToString
            姓名3_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("姓名2").Value.ToString : 職務3_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("單位/職稱2").Value.ToString
            聯繫方式3_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("聯繫方式2").Value.ToString : 負責區域3_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("負責區域2").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 : 經營模式_cb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("經營模式").Value.ToString
            客戶集團_cb.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_訪談清單大() : Set_承租清單() : 計算分流1.Enabled = True ': Set_附件清單()
        End If
    End Sub
    Private Sub 訪談紀錄_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 訪談紀錄_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 訪談紀錄_dgv.Columns(e.ColumnIndex).Name = "洽談物件" Then
                客戶資料表_洽談物件選擇.舊洽談選擇_tb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("洽談物件").Value.ToString
                客戶資料表_洽談物件選擇.製錶_tb.Text = 製表_cb.Text
                客戶資料表_洽談物件選擇.ShowDialog() : 客戶資料表_洽談物件選擇.BringToFront()
                訪談紀錄_dgv.Rows(e.RowIndex).Cells("洽談物件").Value = 客戶_洽談選擇
            ElseIf 訪談紀錄_dgv.Columns(e.ColumnIndex).Name = "洽談方式" Then
                洽談方式_cb.Text = 訪談紀錄_dgv.Rows(e.RowIndex).Cells("洽談方式").Value.ToString
                CB選擇清單(洽談方式_cb, 洽談方式_cb.Text) : 訪談紀錄_dgv.Rows(e.RowIndex).Cells("洽談方式").Value = 洽談方式_cb.Text
            ElseIf 訪談紀錄_dgv.Columns(e.ColumnIndex).Name = "YS員工" Then
                CB選擇清單(製表_cb, 製表_cb.Text) : 訪談紀錄_dgv.Rows(e.RowIndex).Cells("YS員工").Value = 製表_cb.Text
            End If
            訪談編號_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(sender As Object, e As DataGridViewCellEventArgs) Handles 訪談紀錄大_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 訪談紀錄大_dgv.Columns(e.ColumnIndex).Name = "洽談物件" Then
                客戶_舊洽談選擇 = 訪談紀錄大_dgv.Rows(e.RowIndex).Cells("洽談物件").Value.ToString
                客戶資料表_洽談物件選擇.ShowDialog() : 客戶資料表_洽談物件選擇.BringToFront()
                訪談紀錄大_dgv.Rows(e.RowIndex).Cells("洽談物件").Value = 客戶_洽談選擇
            ElseIf 訪談紀錄大_dgv.Columns(e.ColumnIndex).Name = "洽談方式" Then
                洽談方式_cb.Text = 訪談紀錄大_dgv.Rows(e.RowIndex).Cells("洽談方式").Value.ToString
                CB選擇清單(洽談方式_cb, 洽談方式_cb.Text) : 訪談紀錄大_dgv.Rows(e.RowIndex).Cells("洽談方式").Value = 洽談方式_cb.Text
            Else
            End If
            訪談編號_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 = Microsoft.VisualBasic.Strings.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 : 訪談紀錄_dgv.DataSource = Nothing : 附件_pb.Image = Nothing : 會議附件_pb.Image = Nothing
        客戶名稱_tb.Text = "" : 分類2_cb.Text = "" : 電話_tb.Text = "" : 傳真_tb.Text = "" : 地址_tb.Text = "" : 姓名1_tb.Text = "" : 職務1_tb.Text = ""
        聯繫方式1_tb.Text = "" : 來源_tb.Text = "" : 簽約_tb.Text = "" : 客需_tb.Text = "" : 負責區域1_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 = ""
        經營模式_cb.Text = "" : 集團_cb.Text = ""
        SQL_資料庫選擇() : If dr.Read() Then : 圖片庫 = dr("文件資料庫").ToString : Else : MsgBox("圖片資料庫已滿，請找系統管理員!!") : Me.Close() : End If
        SQL_客戶資料表新增(經營模式_cb.Text, 集團_cb.Text)
    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_客戶資料表修改(經營模式_cb.Text, 客戶集團_cb.Text) : 訪談存檔()
            Else : If CC(21) = True Then : SQL_客戶資料表修改(經營模式_cb.Text, 客戶集團_cb.Text) : End If : 訪談存檔()
            End If
            Dim NUM0 As Integer : DTP1 = Microsoft.VisualBasic.Strings.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_訪談清單大() : Set_客戶清單()
            If CC(11) Then : 客戶名稱_tb.ReadOnly = False : Else : 客戶名稱_tb.ReadOnly = True : End If

            清單1_dgv.Enabled = True : 會議存檔_bt.Enabled = True
        End If
    End Sub
    Private Sub 訪談存檔()
        If 訪談紀錄大_dgv.Visible Then
            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 = 訪談紀錄大_dgv.Rows(I).Cells("訪談內容").Value.ToString
                訪談紀錄_dgv.Rows(I).Cells("洽談時間").Value = 訪談紀錄大_dgv.Rows(I).Cells("洽談時間").Value.ToString
                訪談紀錄_dgv.Rows(I).Cells("內容追蹤").Value = 訪談紀錄大_dgv.Rows(I).Cells("內容追蹤").Value.ToString
                訪談紀錄_dgv.Rows(I).Cells("洽談方式").Value = 訪談紀錄大_dgv.Rows(I).Cells("洽談方式").Value.ToString
                訪談紀錄_dgv.Rows(I).Cells("YS員工").Value = 訪談紀錄大_dgv.Rows(I).Cells("YS員工").Value.ToString
                訪談紀錄_dgv.Rows(I).Cells("洽談物件").Value = 訪談紀錄大_dgv.Rows(I).Cells("洽談物件").Value.ToString
                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
                Dim 訪談人 As String = 訪談紀錄大_dgv.Rows(I).Cells("YS員工").Value.ToString : Dim 洽談物件 As String = 訪談紀錄大_dgv.Rows(I).Cells("洽談物件").Value.ToString
                Dim 洽談時間 As String = 訪談紀錄大_dgv.Rows(I).Cells("洽談時間").Value.ToString
                SQL_訪談表修改(訪談人, 洽談物件, 洽談時間)
            Next
        Else
            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 = 訪談紀錄_dgv.Rows(I).Cells("訪談內容").Value.ToString
                訪談紀錄大_dgv.Rows(I).Cells("洽談時間").Value = 訪談紀錄_dgv.Rows(I).Cells("洽談時間").Value.ToString
                訪談紀錄大_dgv.Rows(I).Cells("內容追蹤").Value = 訪談紀錄_dgv.Rows(I).Cells("內容追蹤").Value.ToString
                訪談紀錄大_dgv.Rows(I).Cells("洽談方式").Value = 訪談紀錄_dgv.Rows(I).Cells("洽談方式").Value.ToString
                訪談紀錄大_dgv.Rows(I).Cells("YS員工").Value = 訪談紀錄_dgv.Rows(I).Cells("YS員工").Value.ToString
                訪談紀錄大_dgv.Rows(I).Cells("洽談物件").Value = 訪談紀錄_dgv.Rows(I).Cells("洽談物件").Value.ToString
                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
                Dim 訪談人 As String = 訪談紀錄_dgv.Rows(I).Cells("YS員工").Value.ToString : Dim 洽談物件 As String = 訪談紀錄_dgv.Rows(I).Cells("洽談物件").Value.ToString
                Dim 洽談時間 As String = 訪談紀錄_dgv.Rows(I).Cells("洽談時間").Value.ToString
                SQL_訪談表修改(訪談人, 洽談物件, 洽談時間)
            Next
        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 = "" 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_客戶資料表修改(經營模式_cb.Text, 客戶集團_cb.Text) : Set_客戶清單()
        If CC(11) Then : 客戶名稱_tb.ReadOnly = False : Else : 客戶名稱_tb.ReadOnly = True : End If
        清單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
                訪談存檔() : Dim 會議內容 As String = ""
                For i As Integer = 0 To 會議內容_dgv.Rows.Count - 1
                    If IsNothing(會議內容_dgv.Rows(i).Cells("流水號").Value) Then
                        Dim 舊流水 As String : SQL_會議內容流水號()
                        If dr.Read() Then : 舊流水 = dr(0).ToString : Else
                            舊流水 = "HINL-" & Today.Year.ToString.PadLeft(4, "0") & Today.Month.ToString.PadLeft(2, "0") & Today.Day.ToString.PadLeft(2, "0") & "-00000000"
                        End If
                        Dim 新流水 As String
                        If 舊流水.Substring(5, 4) = Today.Year.ToString.PadLeft(4, "0") And 舊流水.Substring(9, 2) = Today.Month.ToString.PadLeft(2, "0") And 舊流水.Substring(11, 2) = Today.Day.ToString.PadLeft(2, "0") Then
                            Dim 舊流 As Integer = CInt(舊流水.Substring(15))
                            新流水 = "HINL-" & Today.Year.ToString.PadLeft(4, "0") & Today.Month.ToString.PadLeft(2, "0") & Today.Day.ToString.PadLeft(2, "0") & "-" & (舊流 + 1).ToString.PadLeft(8, "0")
                        Else
                            新流水 = "HINL-" & Today.Year.ToString.PadLeft(4, "0") & Today.Month.ToString.PadLeft(2, "0") & Today.Day.ToString.PadLeft(2, "0") & "-" & "-00000001"
                        End If
                        Dim 會議內容2 As String = ""
                        If IsNothing(會議內容_dgv.Rows(i).Cells("會議內容").Value) Then : Else : 會議內容2 = 會議內容_dgv.Rows(i).Cells("會議內容").Value.ToString : End If
                        SQL_會議內容新增(新流水, 訪談編號_tb.Text, 會議內容2)
                    Else
                        Dim 會議內容2 As String = ""
                        If IsNothing(會議內容_dgv.Rows(i).Cells("會議內容").Value) Then : Else : 會議內容2 = 會議內容_dgv.Rows(i).Cells("會議內容").Value.ToString : End If
                        SQL_會議內容修改(會議內容2, 會議內容_dgv.Rows(i).Cells("流水號").Value.ToString)
                    End If
                    If IsNothing(會議內容_dgv.Rows(i).Cells("會議內容").Value) = False Then : 會議內容 &= 會議內容_dgv.Rows(i).Cells("會議內容").Value.ToString : End If

                Next
                If 會議內容 <> "" Then : 會議內容_tb.Text = 會議內容 : End If : SQL_會議記錄修改()
                MsgBox("會議記錄存檔完成!!") : Set_訪談清單() : 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_訪談清單() : 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 Or CC(13) = True 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 : 訪談紀錄大_dgv.DataSource = Nothing : 會議地點_tb.Text = "" : 會議內容_tb.Text = "" : 會議時間_dtp.Value = Today() : 附件_dgv.DataSource = Nothing
                        客戶名稱_tb.Text = "" : 分類2_cb.Text = "" : 電話_tb.Text = "" : 傳真_tb.Text = "" : 地址_tb.Text = "" : 姓名1_tb.Text = "" : 職務1_tb.Text = ""
                        聯繫方式1_tb.Text = "" : 來源_tb.Text = "" : 簽約_tb.Text = "" : 客需_tb.Text = "" : 負責區域1_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 = Microsoft.VisualBasic.Strings.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 = Microsoft.VisualBasic.Strings.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
                Dim ds1 As New DataSet : 會議內容2_dgv.DataSource = Nothing : ds1.Clear()
                會議內容2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
                會議內容2_dgv.ColumnHeadersHeight = 25 : 會議內容2_dgv.AllowUserToAddRows = False : 會議內容2_dgv.RowTemplate.Height = 25
                SQL_客戶會議內容清單(訪談編號_tb.Text) : da.Fill(ds1) : 會議內容2_dgv.DataSource = ds1.Tables(0) : conn.Close()
                會議內容2_dgv.Columns(0).Visible = True : 會議內容2_dgv.Columns(1).Visible = False
                會議內容2_dgv.Columns(0).FillWeight = 40 : 會議內容2_dgv.Columns(0).ReadOnly = True : 會議內容2_dgv.Columns(2).FillWeight = 400
                會議內容2_dgv.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                會議內容2_dgv.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                For i As Integer = 0 To 會議內容2_dgv.Rows.Count - 1
                    會議內容2_dgv.Rows(i).Cells(0).Value = i + 1
                Next
                會議內容_dgv.Rows.Clear() : 會議內容_dgv.Columns.Clear()
                會議內容_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
                會議內容_dgv.ColumnHeadersHeight = 25 : 會議內容_dgv.AllowUserToAddRows = False : 會議內容_dgv.RowTemplate.Height = 25
                For Each column As DataGridViewColumn In 會議內容2_dgv.Columns
                    會議內容_dgv.Columns.Add(DirectCast(column.Clone(), DataGridViewColumn))
                Next
                For Each row As DataGridViewRow In 會議內容2_dgv.Rows
                    Dim index As Integer = 會議內容_dgv.Rows.Add()
                    For Each cell As DataGridViewCell In row.Cells
                        會議內容_dgv.Rows(index).Cells(cell.ColumnIndex).Value = cell.Value
                    Next
                Next
                列數_lb.Text = ""
                視窗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 System.Drawing.Font("微軟正黑體", 字體大小_nud.Value)
    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

        Dim imagePath As String = System.Windows.Forms.Application.StartupPath & "\YSLOGO2.png"
        Dim cell As Range = xlSheet.Cells(1, 1) : Dim left As Single = CType(cell.Left, Single) : Dim top As Single = CType(cell.Top, Single)
        Dim width As Single = 80 : Dim height As Single = 32
        If Not System.IO.File.Exists(imagePath) Then : MessageBox.Show("圖片文件未找到: " & imagePath) : Return : End If
        xlSheet.Shapes.AddPicture(imagePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, left, top, width, height)
        xlSheet.Cells(1, 4) = "客戶(地主)資料"
        xlSheet.Cells(2, 6) = "編號: " & 流水號_tb.Text
        xlSheet.Cells(3, 1) = "客戶名稱"
        xlSheet.Cells(3, 3) = 客戶名稱_tb.Text
        xlSheet.Cells(3, 6) = "製表: " & gUserName
        xlSheet.Cells(4, 1) = "基本資料"
        xlSheet.Cells(4, 2) = "電話: " & 電話_tb.Text
        xlSheet.Cells(4, 5) = "傳真: " & 傳真_tb.Text
        xlSheet.Cells(5, 2) = "地址: " & 地址_tb.Text
        xlSheet.Cells(6, 1) = "聯絡窗口"
        xlSheet.Cells(6, 2) = "姓名"
        xlSheet.Cells(6, 3) = "職務/職稱"
        xlSheet.Cells(6, 4) = "聯繫方式"
        xlSheet.Cells(6, 5) = "負責區域"
        xlSheet.Cells(7, 2) = 姓名1_tb.Text & " / " & 姓名2_tb.Text & " / " & 姓名3_tb.Text
        xlSheet.Cells(7, 3) = 職務1_tb.Text & " / " & 職務2_tb.Text & " / " & 職務3_tb.Text
        xlSheet.Cells(7, 4) = 聯繫方式1_tb.Text & " / " & 聯繫方式2_tb.Text & " / " & 聯繫方式3_tb.Text
        xlSheet.Cells(7, 5) = 負責區域1_tb.Text & " / " & 負責區域2_tb.Text & " / " & 負責區域3_tb.Text
        xlSheet.Cells(7, 9) = 負責區域1_tb.Text & " / " & 負責區域2_tb.Text & " / " & 負責區域3_tb.Text
        xlSheet.Cells(8, 1) = "來源"
        xlSheet.Cells(8, 2) = 來源_tb.Text : xlSheet.Cells(8, 9) = 來源_tb.Text
        xlSheet.Cells(9, 1) = "簽約"
        xlSheet.Cells(9, 2) = 簽約_tb.Text : xlSheet.Cells(9, 9) = 簽約_tb.Text
        xlSheet.Cells(10, 1) = "客需"
        xlSheet.Cells(10, 2) = 客需_tb.Text : xlSheet.Cells(10, 9) = 客需_tb.Text
        xlSheet.Cells(11, 1) = "日期"
        xlSheet.Cells(11, 3) = "洽談方式"
        xlSheet.Cells(11, 4) = "訪談內容"
        xlSheet.Cells(11, 6) = "內容追蹤"
        xlSheet.Cells(11, 7) = "YS員工"
        xlSheet.Cells(11, 8) = "洽談物件"
        For i As Integer = 0 To 訪談紀錄_dgv.Rows.Count - 1
            xlSheet.Cells(i + 12, 1) = 訪談紀錄_dgv.Rows(i).Cells("日期").Value
            xlSheet.Cells(i + 12, 3) = 訪談紀錄_dgv.Rows(i).Cells("洽談方式").Value
            xlSheet.Cells(i + 12, 4) = 訪談紀錄_dgv.Rows(i).Cells("訪談內容").Value : xlSheet.Cells(i + 12, 10) = 訪談紀錄_dgv.Rows(i).Cells("訪談內容").Value
            xlSheet.Cells(i + 12, 6) = 訪談紀錄_dgv.Rows(i).Cells("內容追蹤").Value
            xlSheet.Cells(i + 12, 7) = 訪談紀錄_dgv.Rows(i).Cells("YS員工").Value
            xlSheet.Cells(i + 12, 8) = 訪談紀錄_dgv.Rows(i).Cells("洽談物件").Value
        Next : N2 = 訪談紀錄_dgv.Rows.Count
        AA1(xlApp, xlSheet)
        xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
        '----轉成PDF-----
        Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & 客戶名稱_tb.Text & "_(基本資料).pdf", XlFixedFormatQuality.xlQualityStandard, True)
        '--------
        xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
        xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
        Try
            Dim pdfFilePath As String = SERT & "\" & 客戶名稱_tb.Text & "_(基本資料).pdf"
            Dim acrobatReaderPath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            If System.IO.File.Exists(acrobatReaderPath) Then : Process.Start(acrobatReaderPath, pdfFilePath)
            Else : Dim chromePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                If System.IO.File.Exists(chromePath) Then : Process.Start(chromePath, pdfFilePath)
                Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                    If System.IO.File.Exists(edgePath) Then : Process.Start(edgePath, pdfFilePath)
                    Else : MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 客戶名稱_tb.Text & "_(基本資料).pdf")
                    End If : End If : End If
        Catch ex As Exception
            MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 客戶名稱_tb.Text & "_(基本資料).pdf")
        End Try
    End Sub
    Private Sub AA1(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        xlSheet.Activate() ' 激活工作表
        myExcel.ActiveWindow.View = XlWindowView.xlPageLayoutView : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25) : .TopMargin = myExcel.Application.InchesToPoints(0.3)
            .BottomMargin = myExcel.Application.InchesToPoints(0.3) : .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False : .FirstPageNumber = xlAutomatic
            .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 0 : .FitToPagesTall = 0 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With : myExcel.Application.PrintCommunication = True

        xlSheet.Columns("A:A").ColumnWidth = 4.75 : xlSheet.Columns("B:B").ColumnWidth = 9.38 : xlSheet.Columns("C:C").ColumnWidth = 14.5 : xlSheet.Columns("D:D").ColumnWidth = 16.63
        xlSheet.Columns("E:E").ColumnWidth = 16.25 : xlSheet.Columns("F:F").ColumnWidth = 14.38 : xlSheet.Columns("G:G").ColumnWidth = 8.25 : xlSheet.Columns("H:H").ColumnWidth = 9.38
        xlSheet.Columns("I:I").ColumnWidth = 92.38 : xlSheet.Columns("J:J").ColumnWidth = 33.38 : xlSheet.Rows(1).RowHeight = 19.5 : xlSheet.Rows(2).RowHeight = 15 : xlSheet.Rows(3).RowHeight = 19.5
        xlSheet.Rows(4).RowHeight = 19.5 : xlSheet.Rows(5).RowHeight = 19.5 : xlSheet.Rows(6).RowHeight = 19.5 : xlSheet.Rows(11).RowHeight = 19.5

        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.Rows("1:1").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
        xlSheet.Rows("2: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 = xlThemeFontNone : End With
        Dim ddd As Integer = 附件_dgv.Rows.Count : Dim dd As Integer = 0
        If ddd > 1 Then : dd = ddd / 2 : ElseIf ddd = 1 Then : dd = ddd : End If

        xlSheet.Range("A3:H" & 11 + dd + N2).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("J:J,K:K,L:L").Select()
        With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A1:H1").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("A2:H2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A3:B3").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("C3:E3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("F3:H3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A4:A5").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B4:D4").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("E4:H4").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B5:H5").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A6:A7").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B6:D6,A8:A10,C11,F11,G11,H11").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("B7:D7").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("E6:H6").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("E7:H7").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B8:H8").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B9:H9").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B10:H10").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A11:B11").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("D11:E11").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

        For i As Integer = 12 To 12 + N2 - 1 : xlSheet.Range("A" & i & ":B" & i).Select()
            With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
            xlSheet.Range("C" & i & ",H" & i).Select()
            With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
            xlSheet.Range("D" & i & ":E" & i).Select()
            With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
            xlSheet.Rows(i).AutoFit()
            If xlSheet.Rows(i).RowHeight + 15 > 409 Then : xlSheet.Rows(i).RowHeight = 409 : Else : xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 15 : End If
        Next
        If dd > 0 Then : dd -= 1
            For i As Integer = 12 + N2 To 12 + N2 + dd : xlSheet.Range("A" & i & ":D" & i).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("E" & i & ":H" & i).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
            Next
        End If

        xlSheet.Rows(7).AutoFit() : If xlSheet.Rows(7).RowHeight + 5 > 409 Then : xlSheet.Rows(7).RowHeight = 409 : Else : xlSheet.Rows(7).RowHeight = xlSheet.Rows(7).RowHeight + 5 : End If
        xlSheet.Rows(8).AutoFit() : If xlSheet.Rows(8).RowHeight + 5 > 409 Then : xlSheet.Rows(8).RowHeight = 409 : Else : xlSheet.Rows(8).RowHeight = xlSheet.Rows(8).RowHeight + 5 : End If
        xlSheet.Rows(9).AutoFit() : If xlSheet.Rows(9).RowHeight + 5 > 409 Then : xlSheet.Rows(9).RowHeight = 409 : Else : xlSheet.Rows(9).RowHeight = xlSheet.Rows(9).RowHeight + 5 : End If
        xlSheet.Rows(10).AutoFit() : If xlSheet.Rows(7).RowHeight + 5 > 409 Then : xlSheet.Rows(10).RowHeight = 409 : Else : xlSheet.Rows(10).RowHeight = xlSheet.Rows(10).RowHeight + 5 : End If

        xlSheet.Columns("I:I").ColumnWidth = 0 : xlSheet.Columns("J:J").ColumnWidth = 0 : xlSheet.Columns("K:K").ColumnWidth = 0
        Dim attachmentCount As Integer = 附件_dgv.Rows.Count : Dim startRow As Integer = 12 + N2 : Dim rowHeight As Integer = 150
        Dim rowsToAdjust As Integer = Math.Ceiling(attachmentCount / 2.0)
        For i As Integer = 0 To rowsToAdjust - 1 : Dim currentRow As Integer = startRow + i : xlSheet.Rows(currentRow).RowHeight = rowHeight : Next
        If 附件_dgv.Rows.Count > 0 Then
            For i As Integer = 0 To 附件_dgv.Rows.Count - 1
                附件編碼_lb.Text = 附件_dgv.Rows(i).Cells(0).Value.ToString : PA2 = 附件_dgv.Rows(i).Cells(0).Value.ToString
                SQL_連線字串_圖片資料庫() : SQL_客戶資料附件讀取()
                While dr.Read() = True
                    Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) : Dim ms As New MemoryStream(bytes) : Dim originalImage As Image = Image.FromStream(ms)
                    ' 计算最大允许的宽度和高度
                    Dim maxRowHeight As Single = 170 : Dim maxColumnWidth As Single = 350
                    ' 计算宽度和高度的比例
                    Dim widthRatio As Single = maxColumnWidth / originalImage.Width : Dim heightRatio As Single = maxRowHeight / originalImage.Height
                    ' 选择较小的比例作为缩放比例，以确保图像可以适应指定的大小范围内
                    Dim scaleFactor As Single = Math.Min(widthRatio, heightRatio)
                    ' 计算调整后的图像大小
                    Dim newWidth As Integer = CInt(originalImage.Width * scaleFactor) : Dim newHeight As Integer = CInt(originalImage.Height * scaleFactor)
                    ' 创建调整后的图像
                    Dim scaledImage As New Bitmap(newWidth, newHeight)
                    Using g As Graphics = Graphics.FromImage(scaledImage)
                        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic : g.DrawImage(originalImage, 0, 0, newWidth, newHeight)
                    End Using : Dim aa As String
                    If i Mod 2 = 0 Then : aa = "A" : Else : aa = "E" : End If
                    Dim rowIndex As Integer = startRow + (i \ 2) : xlSheet.Range(aa & rowIndex).Select()
                    ' 将图片放置到指定单元格   
                    Clipboard.SetImage(scaledImage) : myExcel.ActiveSheet.Pictures.Paste.Select
                    ' 调整图片位置
                    myExcel.Selection.ShapeRange.IncrementLeft(5) : myExcel.Selection.ShapeRange.IncrementTop(5)
                End While : conn.Close()
            Next
        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

        Dim imagePath As String = System.Windows.Forms.Application.StartupPath & "\YSLOGO2.png"
        Dim cell As Range = xlSheet.Cells(1, 1) : Dim left As Single = CType(cell.Left, Single) : Dim top As Single = CType(cell.Top, Single)
        Dim width As Single = 80 : Dim height As Single = 32
        If Not System.IO.File.Exists(imagePath) Then : MessageBox.Show("圖片文件未找到: " & imagePath) : Return : End If
        xlSheet.Shapes.AddPicture(imagePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, left, top, width, height)
        xlSheet.Cells(1, 3) = "有盛務業" & vbCrLf & "會議紀錄"
        xlSheet.Cells(2, 4) = "報表編號: " & 附件編碼1_lb.Text
        xlSheet.Cells(3, 1) = "會議名稱"
        xlSheet.Cells(3, 2) = 會議名稱_tb.Text
        xlSheet.Cells(3, 3) = "會議地點"
        xlSheet.Cells(3, 4) = 會議地點_tb.Text
        xlSheet.Cells(4, 1) = "會議時間"
        xlSheet.Cells(4, 2) = 會議時間_dtp.Text
        xlSheet.Cells(5, 1) = "出席人員"
        xlSheet.Cells(5, 2) = 出席人員_tb.Text
        xlSheet.Cells(6, 1) = "會議內容"
        For i As Integer = 0 To 會議內容_dgv.Rows.Count - 1
            If IsNothing(會議內容_dgv.Rows(i).Cells("會議內容").Value) = False Then
                xlSheet.Cells(7 + i, 1) = 會議內容_dgv.Rows(i).Cells("會議內容").Value.ToString
                xlSheet.Cells(7 + i, 5) = 會議內容_dgv.Rows(i).Cells("會議內容").Value.ToString
            End If
        Next
        AA(xlApp, xlSheet)
        xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
        '----轉成PDF-----
        Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & 客戶名稱_tb.Text & "-" & 會議名稱_tb.Text & "_(會議記錄).pdf", XlFixedFormatQuality.xlQualityStandard, True)
        '--------
        xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
        xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
        Try
            Dim pdfFilePath As String = SERT & "\" & 客戶名稱_tb.Text & "-" & 會議名稱_tb.Text & "_(會議記錄).pdf"
            Dim acrobatReaderPath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            If System.IO.File.Exists(acrobatReaderPath) Then : Process.Start(acrobatReaderPath, pdfFilePath)
            Else : Dim chromePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                If System.IO.File.Exists(chromePath) Then : Process.Start(chromePath, pdfFilePath)
                Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                    If System.IO.File.Exists(edgePath) Then : Process.Start(edgePath, pdfFilePath)
                    Else : MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 客戶名稱_tb.Text & "-" & 會議名稱_tb.Text & "_(會議記錄).pdf")
                    End If : End If : End If
        Catch ex As Exception
            MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 客戶名稱_tb.Text & "-" & 會議名稱_tb.Text & "_(會議記錄).pdf")
        End Try
    End Sub

    Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        xlSheet.Activate() ' 激活工作表
        myExcel.ActiveWindow.View = XlWindowView.xlPageLayoutView : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25) : .TopMargin = myExcel.Application.InchesToPoints(0.3)
            .BottomMargin = myExcel.Application.InchesToPoints(0.3) : .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False : .FirstPageNumber = xlAutomatic
            .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 0 : .FitToPagesTall = 0 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With : myExcel.Application.PrintCommunication = True

        xlSheet.Columns("A:A").ColumnWidth = 19.5 : xlSheet.Columns("B:B").ColumnWidth = 29.5 : xlSheet.Columns("C:C").ColumnWidth = 14.5 : xlSheet.Columns("D:D").ColumnWidth = 34.5
        xlSheet.Columns("E:E").ColumnWidth = 97.88 : xlSheet.Rows(1).RowHeight = 41.5 : xlSheet.Rows(2).RowHeight = 16 : xlSheet.Rows(3).RowHeight = 38.5
        xlSheet.Rows(4).RowHeight = 21 : xlSheet.Rows(5).RowHeight = 21 : xlSheet.Rows(6).RowHeight = 24  'xlSheet.Rows(7).RowHeight = 150

        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.Rows("1:1").Select
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Rows("2: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 = xlThemeFontNone : End With
        xlSheet.Range("6:6").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

        xlSheet.Range("A3:D6").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("A7:D" & 6 + 會議內容_dgv.Rows.Count).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 : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("E1:E" & 6 + 會議內容_dgv.Rows.Count).Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A1:D1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A2:D2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B4:D4").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("B5:D5").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        xlSheet.Range("A6:D6").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 : myExcel.Selection.Font.Bold = True
        For i As Integer = 0 To 會議內容_dgv.Rows.Count - 1

            If xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Contains("插入圖片{") Then
                xlSheet.Range("A" & 7 + i & ":B" & 7 + i).Select()
                With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
                With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
                xlSheet.Range("C" & 7 + i & ":D" & 7 + i).Select()
                With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
                With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
            Else
                xlSheet.Range("A" & 7 + i & ":D" & 7 + i).Select()
                With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
                With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
                    .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
            End If

            If xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Contains("插入圖片{") Then
                xlSheet.Rows(7 + i).RowHeight = 150
                If xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Length > 21 Then
                    '插入圖片{IM-20240618-001}插入圖片{IM-20240618-001}
                    Dim 圖2流 As String = xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Substring(26, 15)
                    SQL_連線字串_圖片資料庫() : SQL_客戶會議附件讀取_改(圖2流)
                    While dr.Read() = True
                        Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) : Dim ms As New MemoryStream(bytes) : Dim originalImage As Image = Image.FromStream(ms)
                        Dim maxRowHeight As Single = 190 : Dim maxColumnWidth As Single = 350
                        Dim widthRatio As Single = maxColumnWidth / originalImage.Width : Dim heightRatio As Single = maxRowHeight / originalImage.Height
                        Dim scaleFactor As Single = Math.Min(widthRatio, heightRatio)
                        Dim newWidth As Integer = CInt(originalImage.Width * scaleFactor) : Dim newHeight As Integer = CInt(originalImage.Height * scaleFactor)
                        Dim scaledImage As New Bitmap(newWidth, newHeight)
                        Using g As Graphics = Graphics.FromImage(scaledImage)
                            g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic : g.DrawImage(originalImage, 0, 0, newWidth, newHeight)
                        End Using
                        xlSheet.Range("C" & 7 + i).Select()
                        Clipboard.SetImage(scaledImage) : myExcel.ActiveSheet.Pictures.Paste.Select
                        myExcel.Selection.ShapeRange.IncrementLeft(5) : myExcel.Selection.ShapeRange.IncrementTop(5)
                    End While : conn.Close()
                    Dim 圖1流 As String = xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Substring(5, 15)
                    SQL_連線字串_圖片資料庫() : SQL_客戶會議附件讀取_改(圖1流)
                    While dr.Read() = True
                        Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) : Dim ms As New MemoryStream(bytes) : Dim originalImage As Image = Image.FromStream(ms)
                        Dim maxRowHeight As Single = 190 : Dim maxColumnWidth As Single = 350
                        Dim widthRatio As Single = maxColumnWidth / originalImage.Width : Dim heightRatio As Single = maxRowHeight / originalImage.Height
                        Dim scaleFactor As Single = Math.Min(widthRatio, heightRatio)
                        Dim newWidth As Integer = CInt(originalImage.Width * scaleFactor) : Dim newHeight As Integer = CInt(originalImage.Height * scaleFactor)
                        Dim scaledImage As New Bitmap(newWidth, newHeight)
                        Using g As Graphics = Graphics.FromImage(scaledImage)
                            g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic : g.DrawImage(originalImage, 0, 0, newWidth, newHeight)
                        End Using
                        xlSheet.Range("A" & 7 + i).Select()
                        Clipboard.SetImage(scaledImage) : myExcel.ActiveSheet.Pictures.Paste.Select
                        myExcel.Selection.ShapeRange.IncrementLeft(5) : myExcel.Selection.ShapeRange.IncrementTop(5)
                    End While : conn.Close()
                Else
                    Dim 圖1流 As String = xlSheet.Cells(7 + i, 1).Formula2R1C1Local.ToString.Substring(5, 15)
                    SQL_連線字串_圖片資料庫() : SQL_客戶會議附件讀取_改(圖1流)
                    While dr.Read() = True
                        Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) : Dim ms As New MemoryStream(bytes) : Dim originalImage As Image = Image.FromStream(ms)
                        Dim maxRowHeight As Single = 190 : Dim maxColumnWidth As Single = 350
                        Dim widthRatio As Single = maxColumnWidth / originalImage.Width : Dim heightRatio As Single = maxRowHeight / originalImage.Height
                        Dim scaleFactor As Single = Math.Min(widthRatio, heightRatio)
                        Dim newWidth As Integer = CInt(originalImage.Width * scaleFactor) : Dim newHeight As Integer = CInt(originalImage.Height * scaleFactor)
                        Dim scaledImage As New Bitmap(newWidth, newHeight)
                        Using g As Graphics = Graphics.FromImage(scaledImage)
                            g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic : g.DrawImage(originalImage, 0, 0, newWidth, newHeight)
                        End Using
                        xlSheet.Range("A" & 7 + i).Select()
                        Clipboard.SetImage(scaledImage) : myExcel.ActiveSheet.Pictures.Paste.Select
                        myExcel.Selection.ShapeRange.IncrementLeft(5) : myExcel.Selection.ShapeRange.IncrementTop(5)
                    End While : conn.Close()
                End If
                xlSheet.Cells(7 + i, 1) = ""
            End If
        Next

        xlSheet.Range("A3,A4,A5,C3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("B3,D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A1:D1").Select() : myExcel.ActiveCell.FormulaR1C1 = "有盛務業" & Chr(10) & "會議紀錄"
        xlSheet.Columns("E:E").ColumnWidth = 0
    End Sub
    Function ImageToPictureDisp(image As Image) As IPictureDisp
        Return CType(PictureDispConverter.Convert(image), IPictureDisp)
    End Function
    Public Class PictureDispConverter
        Inherits System.Windows.Forms.AxHost
        Private Sub New()
            MyBase.New(String.Empty)
        End Sub
        Public Shared Function Convert(image As Image) As Object
            Return GetIPictureDispFromPicture(image)
        End Function
    End Class
    '----------------------自創視窗滑鼠拖曳功能---------------------------------------------------------------------------------------------------------
    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
    Private Sub 放大_bt_Click(sender As Object, e As EventArgs) Handles 放大_bt.Click
        If Panel9.Visible Then : Panel9.Visible = False : Panel9.SendToBack() : Else : Panel9.Visible = True : Panel9.BringToFront() : End If
    End Sub



    Dim OldX2, OldY2 As Long : Dim drag2 As Boolean
    Private Sub 關閉大表_bt_Click(sender As Object, e As EventArgs) Handles 關閉大表_bt.Click
        If Panel9.Visible = False Then : Panel9.Visible = True : Panel9.BringToFront() : Else : Panel9.Visible = False : End If
    End Sub
    Private Sub Panel9_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel9.MouseDown
        If e.Button = MouseButtons.Left Then : OldX2 = e.X : OldY2 = e.Y : drag2 = True : End If
    End Sub
    Private Sub Panel9_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel9.MouseMove
        If drag2 Then : Panel9.Left = Panel9.Left + e.X - OldX2 : Panel9.Top = Panel9.Top + e.Y - OldY2 : End If
    End Sub
    Private Sub 製表_cb_TextChanged(sender As Object, e As EventArgs) Handles 製表_cb.TextChanged
        If 已開啟 Then : Set_客戶清單() : End If
    End Sub
    Private Sub 集團_cb_TextChanged(sender As Object, e As EventArgs) Handles 集團_cb.TextChanged
        If 已開啟 Then : Set_客戶清單() : End If
    End Sub
    Private Sub 會議新增列_bt_Click(sender As Object, e As EventArgs) Handles 會議新增列_bt.Click
        If 列數_lb.Text = "0" Or 列數_lb.Text = "" Then
            會議內容_dgv.Rows.Insert(會議內容_dgv.Rows.Count)

        Else
            會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
        End If
        刷新列數()
    End Sub
    Friend Sub 刷新列數()
        For i As Integer = 0 To 會議內容_dgv.Rows.Count - 1 : 會議內容_dgv.Rows(i).Cells(0).Value = i + 1 : Next
    End Sub
    Private Sub 會議內容_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 會議內容_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            列數_lb.Text = 會議內容_dgv.Rows(e.RowIndex).Cells(0).Value
        End If
    End Sub
    Private Sub 會議刪除列_bt_Click(sender As Object, e As EventArgs) Handles 會議刪除列_bt.Click
        If 列數_lb.Text = "0" Or 列數_lb.Text = "" Then : Else
            If IsNothing(會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells("流水號").Value) Then
            Else : SQL_會議內容刪除(會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells("流水號").Value.ToString)
            End If : 會議內容_dgv.Rows.RemoveAt(CInt(列數_lb.Text) - 1)
        End If
        If 列數_lb.Text <> "" Then : If CInt(列數_lb.Text) > 會議內容_dgv.Rows.Count - 1 Then : 列數_lb.Text = 會議內容_dgv.Rows.Count : End If : End If
        刷新列數()
    End Sub
    Private Sub 插入圖片_bt_Click(sender As Object, e As EventArgs) Handles 插入圖片_bt.Click
        If 附件編碼1_lb.Text = "" Or 附件編碼1_lb.Text = "xxxxxxxxxxxxxxxxx" Then
            MsgBox("請先選擇圖片!")
        Else
            If 列數_lb.Text = "0" Or 列數_lb.Text = "" Then
                會議內容_dgv.Rows.Insert(會議內容_dgv.Rows.Count)
                會議內容_dgv.Rows(會議內容_dgv.Rows.Count - 1).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
            Else
                If IsNothing(會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells(2).Value) Then
                    If CInt(列數_lb.Text) > 會議內容_dgv.Rows.Count - 1 Then
                        會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                        會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                    Else
                        If IsNothing(會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value) Then
                            會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                            會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                        Else
                            If 會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString.Length = 21 And
                       會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString.Contains("插入圖片{") Then
                                Dim 舊 As String = 會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString
                                會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = 舊 & "插入圖片{" & 附件編碼1_lb.Text & "}"
                            Else
                                會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                                會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                            End If
                        End If
                    End If
                Else
                    If 會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells(2).Value.ToString.Length = 21 And
                   會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells(2).Value.ToString.Contains("插入圖片{") Then
                        Dim 舊 As String = 會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells(2).Value.ToString
                        會議內容_dgv.Rows(CInt(列數_lb.Text) - 1).Cells(2).Value = 舊 & "插入圖片{" & 附件編碼1_lb.Text & "}"
                    Else
                        If CInt(列數_lb.Text) > 會議內容_dgv.Rows.Count - 1 Then
                            會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                            會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                        Else
                            If IsNothing(會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value) Then
                                會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                                會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                            Else
                                If 會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString.Length = 21 And
                       會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString.Contains("插入圖片{") Then
                                    Dim 舊 As String = 會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value.ToString
                                    會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = 舊 & "插入圖片{" & 附件編碼1_lb.Text & "}"
                                Else
                                    會議內容_dgv.Rows.Insert(CInt(列數_lb.Text))
                                    會議內容_dgv.Rows(CInt(列數_lb.Text)).Cells(2).Value = "插入圖片{" & 附件編碼1_lb.Text & "}"
                                End If
                            End If
                        End If
                    End If
                End If
            End If
            刷新列數()
        End If
    End Sub
    Private Sub 插入圖片至會議內容()
        Dim 行索引 As Integer = CInt(列數_lb.Text) : Dim 插入內容 As String = "插入圖片{" & 附件編碼1_lb.Text & "}"
        If 行索引 >= 會議內容_dgv.Rows.Count Then : 會議內容_dgv.Rows.Insert(行索引) : End If
        Dim 當前值 As String = If(會議內容_dgv.Rows(行索引).Cells(2).Value, "").ToString()
        If String.IsNullOrEmpty(當前值) OrElse (當前值.Length = 21 AndAlso 當前值.Contains("插入圖片{")) Then
            會議內容_dgv.Rows(行索引).Cells(2).Value = 當前值 & 插入內容
        Else
            會議內容_dgv.Rows.Insert(行索引) : 會議內容_dgv.Rows(行索引).Cells(2).Value = 插入內容
        End If
    End Sub
    Private Sub Panel9_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel9.MouseUp
        drag2 = False
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
End Class