Imports System.IO
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 Microsoft.Office.Core
Public Class 案件摘要表
    Dim DGVX As Integer
    Dim xlApp As Application
    Dim xlBook As Workbook
    Dim xlSheet As Worksheet
    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 : 案件附件_dgv.Columns(2).Visible = False
        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 : 圖片清單讀取() : 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 : 附件編碼_lb.Text = 附件_dgv.Rows(0).Cells(0).Value.ToString : 圖片清單讀取1() : End If
    End Sub
    Private Sub Set_客戶清單()
        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 = 35
        PA40 = 關鍵字1_tb.Text : PA41 = 分類2_cb.Text : SQL_客戶資料表讀取("%", "%")
        da.Fill(ds1) : 清單2_dgv.DataSource = ds1.Tables(0) : conn.Close()
        清單2_dgv.Columns(0).Visible = False : 清單2_dgv.Columns(1).ReadOnly = True
        For i As Integer = 2 To 24 : 清單2_dgv.Columns(i).Visible = False : Next
    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 清單1_dgv.Columns.Count - 1 : 清單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 = 25
        SQL_案件土地清單()
        da.Fill(ds1) : 土地_dgv.DataSource = ds1.Tables(0) : conn.Close()
        土地_dgv.Columns(0).Visible = False : 土地_dgv.Columns(1).Visible = False : 土地_dgv.Columns(5).ReadOnly = True
        土地_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        土地_dgv.Columns("土地面積(平米)").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        土地_dgv.Columns("坪數").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        For i As Integer = 6 To 土地_dgv.Columns.Count - 1 : 土地_dgv.Columns(i).Visible = False : Next
        For i As Integer = 0 To 土地_dgv.Rows.Count - 1
            If IsDBNull(土地_dgv.Rows(i).Cells("免稅").Value) = True Then : 土地_dgv.Rows(i).Cells("免稅").Value = False : End If
            If 土地_dgv.Rows(i).Cells("土地租期").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("土地租期").Value = 0 : End If
            If 土地_dgv.Rows(i).Cells("土地月租").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("土地月租").Value = 0 : End If
            If 土地_dgv.Rows(i).Cells("每坪月租").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("每坪月租").Value = 0 : End If
            If 土地_dgv.Rows(i).Cells("保證月").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("保證月").Value = 0 : End If
            If 土地_dgv.Rows(i).Cells("押金/保證金").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("押金/保證金").Value = 0 : End If
            If 土地_dgv.Rows(i).Cells("免租興建期").Value.ToString = "" Then : 土地_dgv.Rows(i).Cells("免租興建期").Value = 0 : End If
        Next
        土地計算()
    End Sub
    Private Sub Set_土地_租賃條件()
        If 土地編號_tb.Text <> "" And 流水號_tb.Text <> "" Then
            SQL_案件土地_租賃條件清單(流水號_tb.Text, 土地編號_tb.Text)
            If dr.Read() Then
                Dim 租賃條件1時間 As String = dr("租賃條件1時間").ToString()
                If String.IsNullOrEmpty(租賃條件1時間) OrElse 租賃條件1時間.Substring(0, 5) = "  -  " Then : 租賃條件1開始_dtp.CustomFormat = " " : Else
                    租賃條件1開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件1開始_dtp.Value = Date.ParseExact(租賃條件1時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件1時間) OrElse 租賃條件1時間.Substring(租賃條件1時間.Length - 5) = "  -  " Then : 租賃條件1結束_dtp.CustomFormat = " " : Else
                    租賃條件1結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件1結束_dtp.Value = Date.ParseExact(租賃條件1時間.Substring(租賃條件1時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件2時間 As String = dr("租賃條件2時間").ToString()
                If String.IsNullOrEmpty(租賃條件2時間) OrElse 租賃條件2時間.Substring(0, 5) = "  -  " Then : 租賃條件2開始_dtp.CustomFormat = " " : Else
                    租賃條件2開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件2開始_dtp.Value = Date.ParseExact(租賃條件2時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件2時間) OrElse 租賃條件2時間.Substring(租賃條件2時間.Length - 5) = "  -  " Then : 租賃條件2結束_dtp.CustomFormat = " " : Else
                    租賃條件2結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件2結束_dtp.Value = Date.ParseExact(租賃條件2時間.Substring(租賃條件2時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件3時間 As String = dr("租賃條件3時間").ToString()
                If String.IsNullOrEmpty(租賃條件3時間) OrElse 租賃條件3時間.Substring(0, 5) = "  -  " Then : 租賃條件3開始_dtp.CustomFormat = " " : Else
                    租賃條件3開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件3開始_dtp.Value = Date.ParseExact(租賃條件3時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件3時間) OrElse 租賃條件3時間.Substring(租賃條件3時間.Length - 5) = "  -  " Then : 租賃條件3結束_dtp.CustomFormat = " " : Else
                    租賃條件3結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件3結束_dtp.Value = Date.ParseExact(租賃條件3時間.Substring(租賃條件3時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件4時間 As String = dr("租賃條件4時間").ToString()
                If String.IsNullOrEmpty(租賃條件4時間) OrElse 租賃條件4時間.Substring(0, 5) = "  -  " Then : 租賃條件4開始_dtp.CustomFormat = " " : Else
                    租賃條件4開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件4開始_dtp.Value = Date.ParseExact(租賃條件4時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件4時間) OrElse 租賃條件4時間.Substring(租賃條件4時間.Length - 5) = "  -  " Then : 租賃條件4結束_dtp.CustomFormat = " " : Else
                    租賃條件4結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件4結束_dtp.Value = Date.ParseExact(租賃條件4時間.Substring(租賃條件4時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件5時間 As String = dr("租賃條件5時間").ToString()
                If String.IsNullOrEmpty(租賃條件5時間) OrElse 租賃條件5時間.Substring(0, 5) = "  -  " Then : 租賃條件5開始_dtp.CustomFormat = " " : Else
                    租賃條件5開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件5開始_dtp.Value = Date.ParseExact(租賃條件5時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件5時間) OrElse 租賃條件5時間.Substring(租賃條件5時間.Length - 5) = "  -  " Then : 租賃條件5結束_dtp.CustomFormat = " " : Else
                    租賃條件5結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件5結束_dtp.Value = Date.ParseExact(租賃條件5時間.Substring(租賃條件5時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件6時間 As String = dr("租賃條件6時間").ToString()
                If String.IsNullOrEmpty(租賃條件6時間) OrElse 租賃條件6時間.Substring(0, 5) = "  -  " Then : 租賃條件6開始_dtp.CustomFormat = " " : Else
                    租賃條件6開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件6開始_dtp.Value = Date.ParseExact(租賃條件6時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件6時間) OrElse 租賃條件6時間.Substring(租賃條件6時間.Length - 5) = "  -  " Then : 租賃條件6結束_dtp.CustomFormat = " " : Else
                    租賃條件6結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件6結束_dtp.Value = Date.ParseExact(租賃條件6時間.Substring(租賃條件6時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租賃條件7時間 As String = dr("租賃條件7時間").ToString()
                If String.IsNullOrEmpty(租賃條件7時間) OrElse 租賃條件7時間.Substring(0, 5) = "  -  " Then : 租賃條件7開始_dtp.CustomFormat = " " : Else
                    租賃條件7開始_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件7開始_dtp.Value = Date.ParseExact(租賃條件7時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租賃條件7時間) OrElse 租賃條件7時間.Substring(租賃條件7時間.Length - 5) = "  -  " Then : 租賃條件7結束_dtp.CustomFormat = " " : Else
                    租賃條件7結束_dtp.CustomFormat = "yyyy/MM/dd" : 租賃條件7結束_dtp.Value = Date.ParseExact(租賃條件7時間.Substring(租賃條件7時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                土地租金1_nud.Value = dr("租賃條件1金額") : 土地租金2_nud.Value = dr("租賃條件2金額") : 土地租金3_nud.Value = dr("租賃條件3金額")
                土地租金4_nud.Value = dr("租賃條件4金額") : 土地租金5_nud.Value = dr("租賃條件5金額") : 土地租金6_nud.Value = dr("租賃條件6金額")
                土地租金7_nud.Value = dr("租賃條件7金額")
            Else
                租賃條件1開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1開始_dtp.CustomFormat = " " : 租賃條件1結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1結束_dtp.CustomFormat = " "
                租賃條件2開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2開始_dtp.CustomFormat = " " : 租賃條件2結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2結束_dtp.CustomFormat = " "
                租賃條件3開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3開始_dtp.CustomFormat = " " : 租賃條件3結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3結束_dtp.CustomFormat = " "
                租賃條件4開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4開始_dtp.CustomFormat = " " : 租賃條件4結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4結束_dtp.CustomFormat = " "
                租賃條件5開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5開始_dtp.CustomFormat = " " : 租賃條件5結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5結束_dtp.CustomFormat = " "
                租賃條件6開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6開始_dtp.CustomFormat = " " : 租賃條件6結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6結束_dtp.CustomFormat = " "
                租賃條件7開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7開始_dtp.CustomFormat = " " : 租賃條件7結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7結束_dtp.CustomFormat = " "
                土地租金1_nud.Value = 0 : 土地租金2_nud.Value = 0 : 土地租金3_nud.Value = 0 : 土地租金4_nud.Value = 0 : 土地租金5_nud.Value = 0 : 土地租金6_nud.Value = 0 : 土地租金7_nud.Value = 0
            End If
        Else
            租賃條件1開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1開始_dtp.CustomFormat = " " : 租賃條件1結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1結束_dtp.CustomFormat = " "
            租賃條件2開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2開始_dtp.CustomFormat = " " : 租賃條件2結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2結束_dtp.CustomFormat = " "
            租賃條件3開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3開始_dtp.CustomFormat = " " : 租賃條件3結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3結束_dtp.CustomFormat = " "
            租賃條件4開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4開始_dtp.CustomFormat = " " : 租賃條件4結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4結束_dtp.CustomFormat = " "
            租賃條件5開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5開始_dtp.CustomFormat = " " : 租賃條件5結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5結束_dtp.CustomFormat = " "
            租賃條件6開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6開始_dtp.CustomFormat = " " : 租賃條件6結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6結束_dtp.CustomFormat = " "
            租賃條件7開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7開始_dtp.CustomFormat = " " : 租賃條件7結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7結束_dtp.CustomFormat = " "
            土地租金1_nud.Value = 0 : 土地租金2_nud.Value = 0 : 土地租金3_nud.Value = 0 : 土地租金4_nud.Value = 0 : 土地租金5_nud.Value = 0 : 土地租金6_nud.Value = 0 : 土地租金7_nud.Value = 0
        End If
    End Sub
    Private Sub Set_土地_租金明細()
        If 建坪編號_tb.Text <> "" And 流水號_tb.Text <> "" Then
            SQL_案件承租明細查詢(流水號_tb.Text, 承租編號_tb.Text, 承租編號_tb.Text)
            If dr.Read() Then
                Dim 租金明細1時間 As String = dr("租金明細1時間").ToString()
                If String.IsNullOrEmpty(租金明細1時間) OrElse 租金明細1時間.Substring(0, 5) = "  -  " Then : 租金明細1開始_dtp.CustomFormat = " " : Else
                    租金明細1開始_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細1開始_dtp.Value = Date.ParseExact(租金明細1時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租金明細1時間) OrElse 租金明細1時間.Substring(租金明細1時間.Length - 5) = "  -  " Then : 租金明細1結束_dtp.CustomFormat = " " : Else
                    租金明細1結束_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細1結束_dtp.Value = Date.ParseExact(租金明細1時間.Substring(租金明細1時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租金明細2時間 As String = dr("租金明細2時間").ToString()
                If String.IsNullOrEmpty(租金明細2時間) OrElse 租金明細2時間.Substring(0, 5) = "  -  " Then : 租金明細2開始_dtp.CustomFormat = " " : Else
                    租金明細2開始_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細2開始_dtp.Value = Date.ParseExact(租金明細2時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租金明細2時間) OrElse 租金明細2時間.Substring(租金明細2時間.Length - 5) = "  -  " Then : 租金明細2結束_dtp.CustomFormat = " " : Else
                    租金明細2結束_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細2結束_dtp.Value = Date.ParseExact(租金明細2時間.Substring(租金明細2時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租金明細3時間 As String = dr("租金明細3時間").ToString()
                If String.IsNullOrEmpty(租金明細3時間) OrElse 租金明細3時間.Substring(0, 5) = "  -  " Then : 租金明細3開始_dtp.CustomFormat = " " : Else
                    租金明細3開始_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細3開始_dtp.Value = Date.ParseExact(租金明細3時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租金明細3時間) OrElse 租金明細3時間.Substring(租金明細3時間.Length - 5) = "  -  " Then : 租金明細3結束_dtp.CustomFormat = " " : Else
                    租金明細3結束_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細3結束_dtp.Value = Date.ParseExact(租金明細3時間.Substring(租金明細3時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租金明細4時間 As String = dr("租金明細4時間").ToString()
                If String.IsNullOrEmpty(租金明細4時間) OrElse 租金明細4時間.Substring(0, 5) = "  -  " Then : 租金明細4開始_dtp.CustomFormat = " " : Else
                    租金明細4開始_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細4開始_dtp.Value = Date.ParseExact(租金明細4時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租金明細4時間) OrElse 租金明細4時間.Substring(租金明細4時間.Length - 5) = "  -  " Then : 租金明細4結束_dtp.CustomFormat = " " : Else
                    租金明細4結束_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細4結束_dtp.Value = Date.ParseExact(租金明細4時間.Substring(租金明細4時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                Dim 租金明細5時間 As String = dr("租金明細5時間").ToString()
                If String.IsNullOrEmpty(租金明細5時間) OrElse 租金明細5時間.Substring(0, 5) = "  -  " Then : 租金明細5開始_dtp.CustomFormat = " " : Else
                    租金明細5開始_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細5開始_dtp.Value = Date.ParseExact(租金明細5時間.Substring(0, 10), "yyyy/MM/dd", Nothing)
                End If
                If String.IsNullOrEmpty(租金明細5時間) OrElse 租金明細5時間.Substring(租金明細5時間.Length - 5) = "  -  " Then : 租金明細5結束_dtp.CustomFormat = " " : Else
                    租金明細5結束_dtp.CustomFormat = "yyyy/MM/dd" : 租金明細5結束_dtp.Value = Date.ParseExact(租金明細5時間.Substring(租金明細5時間.Length - 10), "yyyy/MM/dd", Nothing)
                End If
                租金金額1_nud.Value = dr("租金明細1金額") : 租金金額2_nud.Value = dr("租金明細2金額") : 租金金額3_nud.Value = dr("租金明細3金額")
                租金金額4_nud.Value = dr("租金明細4金額") : 租金金額5_nud.Value = dr("租金明細5金額")
            Else
                租金明細1開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細1開始_dtp.CustomFormat = " " : 租金明細1結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細1結束_dtp.CustomFormat = " "
                租金明細2開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細2開始_dtp.CustomFormat = " " : 租金明細2結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細2結束_dtp.CustomFormat = " "
                租金明細3開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細3開始_dtp.CustomFormat = " " : 租金明細3結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細3結束_dtp.CustomFormat = " "
                租金明細4開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細4開始_dtp.CustomFormat = " " : 租金明細4結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細4結束_dtp.CustomFormat = " "
                租金明細5開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細5開始_dtp.CustomFormat = " " : 租金明細5結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細5結束_dtp.CustomFormat = " "
                租金金額1_nud.Value = 0 : 租金金額2_nud.Value = 0 : 租金金額3_nud.Value = 0 : 租金金額4_nud.Value = 0 : 租金金額5_nud.Value = 0
            End If
        Else
            租金明細1開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細1開始_dtp.CustomFormat = " " : 租金明細1結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細1結束_dtp.CustomFormat = " "
            租金明細2開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細2開始_dtp.CustomFormat = " " : 租金明細2結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細2結束_dtp.CustomFormat = " "
            租金明細3開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細3開始_dtp.CustomFormat = " " : 租金明細3結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細3結束_dtp.CustomFormat = " "
            租金明細4開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細4開始_dtp.CustomFormat = " " : 租金明細4結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細4結束_dtp.CustomFormat = " "
            租金明細5開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細5開始_dtp.CustomFormat = " " : 租金明細5結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細5結束_dtp.CustomFormat = " "
            租金金額1_nud.Value = 0 : 租金金額2_nud.Value = 0 : 租金金額3_nud.Value = 0 : 租金金額4_nud.Value = 0 : 租金金額5_nud.Value = 0
        End If
    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 = 25
        SQL_案件建坪清單(流水號_tb.Text)
        da.Fill(ds1) : 區塊_dgv.DataSource = ds1.Tables(0) : conn.Close()
        區塊_dgv.Columns(0).Visible = False : 區塊_dgv.Columns(1).Visible = False ': 區塊_dgv.Columns(4).ReadOnly = True
        區塊_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        區塊_dgv.Columns("坪數").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        區塊_dgv.Columns("面寬(米)").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        區塊_dgv.Columns("深度(米)").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        For i As Integer = 7 To 區塊_dgv.Columns.Count - 1 : 區塊_dgv.Columns(i).Visible = False : Next
        區塊計算()
        SQL_建坪類別(流水號_tb.Text) : 區塊_cb.Items.Clear() : 區塊_cb.Items.Add("") : While (dr.Read()) : 區塊_cb.Items.Add(dr("建坪編號")) : End While : conn.Close()
    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 = 35
        SQL_案件承租讀取(流水號_tb.Text)
        da.Fill(ds1) : 承租_dgv.DataSource = ds1.Tables(0) : conn.Close()
        For i As Integer = 0 To 22 : 承租_dgv.Columns(i).Visible = False : Next : 承租_dgv.Columns(23).ReadOnly = True : 承租_dgv.Columns(24).Visible = False
        For i As Integer = 0 To 承租_dgv.Rows.Count - 1
            If IsDBNull(承租_dgv.Rows(i).Cells("免稅").Value) = True Then : 承租_dgv.Rows(i).Cells("免稅").Value = False : End If
            承租_dgv.Rows(i).Cells("承租").Value = 承租_dgv.Rows(i).Cells("建坪編號").Value.ToString & "-" & 承租_dgv.Rows(i).Cells("客戶名稱").Value.ToString
        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 = 25
        SQL_案件太陽讀取(流水號_tb.Text)
        da.Fill(ds1) : 太陽_dgv.DataSource = ds1.Tables(0) : conn.Close()
        For i As Integer = 0 To 太陽_dgv.Columns.Count - 1 : 太陽_dgv.Columns(i).Visible = False : Next
        太陽_dgv.Columns(1).Visible = True : 太陽_dgv.Columns(1).ReadOnly = True
        For i As Integer = 0 To 太陽_dgv.Rows.Count - 1 : 太陽_dgv.Rows(i).Cells(1).Value = "檔案-" & i + 1 : 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 列印_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 讀取資料夾路徑1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取資料夾路徑1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.讀取資料夾路徑1_bt, "圖片附件導入系統")
    End Sub
    Private Sub 刪除附件1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除附件1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除附件1_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 列印1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.列印1_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
        地址_tb.ReadOnly = True : 附件編碼1_lb.Text = "" : 視窗2_pl.Visible = False : 承租客_tb.BringToFront() : 承租區塊編號_lb.Text = "" : PDF_lb.Text = ""
        Panel8.SendToBack()
    End Sub
    Private Sub 案件摘要表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        SQL_客戶類別() : 分類2_cb.Items.Clear() : 分類2_cb.Items.Add("") : While (dr.Read()) : 分類2_cb.Items.Add(dr("類別")) : End While : conn.Close()
        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 : 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
            流水號_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("單據編號").Value.ToString : 地址_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("地址/地號").Value.ToString
            地址2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("地址/地號").Value.ToString : 地址1_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("地址/地號").Value.ToString
            地址3_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_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("鄰近地址").Value.ToString
            鄰近地址2_tb.Text = 清單1_dgv.Rows(e.RowIndex).Cells("鄰近地址").Value.ToString : 鄰近地址3_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 = "" : 土地編號_tb.Text = "" : 承租編號_tb.Text = "" : 附件編碼1_lb.Text = "" : 承租區塊編號_lb.Text = "" : 附件編碼_lb.Text = ""
            承租狀態_cb.Text = "" : 區塊_cb.Text = "" : 承租客_tb.Text = "" : 客戶流水_tb.Text = "" : 聯絡人1_tb.Text = "" : 電話1_tb.Text = ""
            聯絡人2_tb.Text = "" : 電話2_tb.Text = "" : 聯絡人3_tb.Text = "" : 電話3_tb.Text = "" : 開發窗口_tb.Text = "" : 店長_tb.Text = ""
            租期開始1_dtp.CustomFormat = " " : 租期結束1_dtp.CustomFormat = " " : 免租開始1_dtp.CustomFormat = " " : 免租結束1_dtp.CustomFormat = " "
            租金_nud.Value = 0 : 案件租期_nup.Value = 0 : 押金_nud.Value = 0 : 備註1_tb.Text = "" : 附件_dgv.DataSource = Nothing : 附件_pb.Image = Nothing
            附件1_pb.Image = Nothing : Set_土地清單() : Set_區塊清單() : 計算分流1.Enabled = True : Set_承租清單() : Set_太陽清單()
            If 土地_dgv.Rows.Count > 0 Then : 土地_dgv點擊(0) : Else
                用途_cb.Text = "" : 備註_tb.Text = "" : 土地租期_nud.Value = 0 : 租期開始_dtp.CustomFormat = " " : 租期結束_dtp.CustomFormat = " "
                土地租金_nud.Value = 0 : 月坪租金_nud.Value = 0 : 保證月_nud.Value = 0 : 保證金_nud.Value = 0 : 免租_nud.Value = 0 : 地主_tb.Text = ""
                免租開始_dtp.CustomFormat = " " : 免租結束_dtp.CustomFormat = " " : 執照_dtp.CustomFormat = " " : 建照_dtp.CustomFormat = " "
            End If
            If 太陽_dgv.Rows.Count > 0 Then : 太陽_dgv點擊(0) : Else
                太_出租_tb.Text = "" : 太_承租_tb.Text = "" : KW數_tb.Text = "" : 太陽開始_dtp.CustomFormat = " " : 太陽結束_dtp.CustomFormat = " "
                太_租金比_tb.Text = "" : 太_出租_聯_tb.Text = "" : 太_承租_聯_tb.Text = "" : 饋線狀態_tb.Text = "" : 並聯起組_tb.Text = ""
            End If
            If 區塊_dgv.Rows.Count > 0 Then : 區塊_dgv點擊(0) : Else
                其他約定事項_tb.Text = "" : 面積土地_tb.Text = "" : 面積建物_tb.Text = "" : 高度_tb.Text = "" : 滴水高度_tb.Text = "" : 屋面方向_tb.Text = "" : 建照號碼_tb.Text = ""
                使用執照號碼_tb.Text = "" : 用途_cb.Text = "" : 門牌_tb.Text = "" : 建號_tb.Text = "" : 簽約日_dtp.CustomFormat = " "
            End If
            If 承租_dgv.Rows.Count > 0 Then : 承租_dgv點擊(0) : Else

            End If

        End If
    End Sub
    Private Sub 太陽_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 太陽_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 太陽_dgv點擊(e.RowIndex) : End If
    End Sub
    Private Sub 太陽_dgv點擊(DGVX As Integer)
        綠能編號_tb.Text = 太陽_dgv.Rows(DGVX).Cells("流水號").Value.ToString
        太_出租_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_出租方").Value.ToString : 太_承租_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_承租方").Value.ToString
        KW數_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_KW數").Value.ToString : 太_租金比_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_租金%").Value.ToString
        太_出租_聯_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_出租人").Value.ToString : 太_承租_聯_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_承租人").Value.ToString
        饋線狀態_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_饋線狀態").Value.ToString : 並聯起組_tb.Text = 太陽_dgv.Rows(DGVX).Cells("太陽_並聯起租").Value.ToString

        If 太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString = "" Or 太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString = " - " Then : 太陽開始_dtp.CustomFormat = " " : Else
            If Strings.Left(太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString, 5) = "  -  " Then : 太陽開始_dtp.CustomFormat = " " : Else
                太陽開始_dtp.CustomFormat = "yyyy/MM/dd" : 太陽開始_dtp.Value = Strings.Left(太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString, 10)
            End If
        End If
        If 太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString = "" Or 太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString = " - " Then : 太陽結束_dtp.CustomFormat = " " : Else
            If Strings.Right(太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString, 5) = "  -  " Then : 太陽結束_dtp.CustomFormat = " " : Else
                太陽結束_dtp.CustomFormat = "yyyy/MM/dd" : 太陽結束_dtp.Value = Strings.Right(太陽_dgv.Rows(DGVX).Cells("太陽_租期").Value.ToString, 10)
            End If
        End If
    End Sub
    Private Sub 土地_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 土地_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            For i As Integer = 0 To 土地_dgv.Rows.Count - 1
                If 地主_tb.Text = 土地_dgv.Rows(i).Cells("地主").Value.ToString And 地主_tb.Text <> "" And 地主_tb.Text <> "*" Then : Dim 存檔 As Boolean = False
                    If 備註_tb.Text <> 土地_dgv.Rows(i).Cells("備註").Value.ToString Or 土地租期_nud.Value <> CInt(土地_dgv.Rows(i).Cells("土地租期").Value.ToString) Or
                        土地租金_nud.Value <> CInt(土地_dgv.Rows(i).Cells("土地月租").Value.ToString) Or 月坪租金_nud.Value <> CInt(土地_dgv.Rows(i).Cells("每坪月租").Value.ToString) Or
                        保證月_nud.Value <> CInt(土地_dgv.Rows(i).Cells("保證月").Value.ToString) Or 保證金_nud.Value <> CInt(土地_dgv.Rows(i).Cells("押金/保證金").Value.ToString) Or
                        免租_nud.Value <> CInt(土地_dgv.Rows(i).Cells("免租興建期").Value.ToString) Or 未稅_ch.Checked <> 土地_dgv.Rows(i).Cells("免稅").Value Then
                        存檔 = True
                    End If
                    If 執照_dtp.CustomFormat <> " " Then
                        Dim SA As String = Strings.Format(執照_dtp.Value, "yyyy/MM/dd")
                        If SA <> 土地_dgv.Rows(i).Cells("取得使用執照日").Value.ToString Then : 存檔 = True : End If
                    End If
                    If 建照_dtp.CustomFormat <> " " Then
                        Dim SA As String = Strings.Format(建照_dtp.Value, "yyyy/MM/dd")
                        If SA <> 土地_dgv.Rows(i).Cells("建照核准日").Value.ToString Then : 存檔 = True : End If
                    End If
                    If 存檔 = True Then
                        If 製錶_tb.Text = "" Or 製錶_tb.Text = gUserName Then : 土地編號_tb.Text = 土地_dgv.Rows(i).Cells("流水號").Value.ToString : 確認新增_bt.PerformClick() : Exit For : End If
                    End If
                End If
            Next : 土地_dgv點擊(e.RowIndex)
        End If
    End Sub

    Private Sub 土地_dgv點擊(DGVX As Integer)
        土地編號_tb.Text = 土地_dgv.Rows(DGVX).Cells("流水號").Value.ToString : 地主_tb.Text = 土地_dgv.Rows(DGVX).Cells("地主").Value.ToString
        備註_tb.Text = 土地_dgv.Rows(DGVX).Cells("備註").Value.ToString : 土地區塊_tb.Text = 土地_dgv.Rows(DGVX).Cells("面積編號").Value.ToString
        土地租期_nud.Text = 土地_dgv.Rows(DGVX).Cells("土地租期").Value.ToString : 未稅_ch.Checked = 土地_dgv.Rows(DGVX).Cells("免稅").Value
        Dim 租期備註 As String = 土地_dgv.Rows(DGVX).Cells("租期備註").Value.ToString()
        If String.IsNullOrEmpty(租期備註) OrElse 租期備註.Substring(0, 5) = "  -  " Then : 租期開始_dtp.CustomFormat = " " : Else
            租期開始_dtp.CustomFormat = "yyyy/MM/dd" : 租期開始_dtp.Value = Date.ParseExact(租期備註.Substring(0, 10), "yyyy/MM/dd", Nothing)
        End If
        If String.IsNullOrEmpty(租期備註) OrElse 租期備註.Substring(租期備註.Length - 5) = "  -  " Then : 租期結束_dtp.CustomFormat = " " : Else
            租期結束_dtp.CustomFormat = "yyyy/MM/dd" : 租期結束_dtp.Value = Date.ParseExact(租期備註.Substring(租期備註.Length - 10), "yyyy/MM/dd", Nothing)
        End If

        Dim 暫訂租賃期間 As String = 土地_dgv.Rows(DGVX).Cells("暫訂租賃期間").Value.ToString()
        If String.IsNullOrEmpty(暫訂租賃期間) OrElse 暫訂租賃期間.Substring(0, 5) = "  -  " Then : 暫定租賃期間開始_dtp.CustomFormat = " " : Else
            暫定租賃期間開始_dtp.CustomFormat = "yyyy/MM/dd" : 暫定租賃期間開始_dtp.Value = Date.ParseExact(暫訂租賃期間.Substring(0, 10), "yyyy/MM/dd", Nothing)
        End If
        If String.IsNullOrEmpty(暫訂租賃期間) OrElse 暫訂租賃期間.Substring(暫訂租賃期間.Length - 5) = "  -  " Then : 暫定租賃期間結束_dtp.CustomFormat = " " : Else
            暫定租賃期間結束_dtp.CustomFormat = "yyyy/MM/dd" : 暫定租賃期間結束_dtp.Value = Date.ParseExact(暫訂租賃期間.Substring(暫訂租賃期間.Length - 10), "yyyy/MM/dd", Nothing)
        End If

        Dim 實際租賃期間 As String = 土地_dgv.Rows(DGVX).Cells("實際租賃期間").Value.ToString()
        If String.IsNullOrEmpty(實際租賃期間) OrElse 實際租賃期間.Substring(0, 5) = "  -  " Then : 實際租賃期間開始_dtp.CustomFormat = " " : Else
            實際租賃期間開始_dtp.CustomFormat = "yyyy/MM/dd" : 實際租賃期間開始_dtp.Value = Date.ParseExact(實際租賃期間.Substring(0, 10), "yyyy/MM/dd", Nothing)
        End If
        If String.IsNullOrEmpty(實際租賃期間) OrElse 實際租賃期間.Substring(實際租賃期間.Length - 5) = "  -  " Then : 實際租賃期間結束_dtp.CustomFormat = " " : Else
            實際租賃期間結束_dtp.CustomFormat = "yyyy/MM/dd" : 實際租賃期間結束_dtp.Value = Date.ParseExact(實際租賃期間.Substring(實際租賃期間.Length - 10), "yyyy/MM/dd", Nothing)
        End If


        If 土地_dgv.Rows(DGVX).Cells("土地月租").Value.ToString = "" Then : 土地租金_nud.Value = 0 : Else
            土地租金_nud.Value = 土地_dgv.Rows(DGVX).Cells("土地月租").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("每坪月租").Value.ToString = "" Then : 月坪租金_nud.Value = 0 : Else
            月坪租金_nud.Value = 土地_dgv.Rows(DGVX).Cells("每坪月租").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("保證月").Value.ToString = "" Then : 保證月_nud.Value = 0 : Else
            保證月_nud.Value = 土地_dgv.Rows(DGVX).Cells("保證月").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("押金/保證金").Value.ToString = "" Then : 保證金_nud.Value = 0 : Else
            保證金_nud.Value = 土地_dgv.Rows(DGVX).Cells("押金/保證金").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("興建保證金").Value.ToString = "" Then : 興建保證金_nud.Value = 0 : Else
            興建保證金_nud.Value = 土地_dgv.Rows(DGVX).Cells("興建保證金").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("興建保證月").Value.ToString = "" Then : 興建保證月_nud.Value = 0 : Else
            興建保證月_nud.Value = 土地_dgv.Rows(DGVX).Cells("興建保證月").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("暫訂租賃月").Value.ToString = "" Then : 暫定租賃期間_nud.Value = 0 : Else
            暫定租賃期間_nud.Value = 土地_dgv.Rows(DGVX).Cells("暫訂租賃月").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("實際租賃月").Value.ToString = "" Then : 實際租賃期間_nud.Value = 0 : Else
            實際租賃期間_nud.Value = 土地_dgv.Rows(DGVX).Cells("實際租賃月").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("免租興建期").Value.ToString = "" Then : 免租_nud.Value = 0 : Else
            免租_nud.Value = 土地_dgv.Rows(DGVX).Cells("免租興建期").Value.ToString
        End If
        If 土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString = "" Then : 免租開始_dtp.CustomFormat = " " : Else
            If Strings.Left(土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString, 5) = "  -  " Then : 免租開始_dtp.CustomFormat = " " : Else
                免租開始_dtp.CustomFormat = "yyyy/MM/dd" : 免租開始_dtp.Value = Strings.Left(土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString, 10)
            End If
        End If
        If 土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString = "" Then : 免租結束_dtp.CustomFormat = " " : Else
            If Strings.Right(土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString, 5) = "  -  " Then : 免租結束_dtp.CustomFormat = " " : Else
                免租結束_dtp.CustomFormat = "yyyy/MM/dd" : 免租結束_dtp.Value = Strings.Right(土地_dgv.Rows(DGVX).Cells("建期備註").Value.ToString, 10)
            End If
        End If
        If 土地_dgv.Rows(DGVX).Cells("取得使用執照日").Value.ToString = "" Then : 執照_dtp.CustomFormat = " " : Else
            If 土地_dgv.Rows(DGVX).Cells("取得使用執照日").Value.ToString = " " Then : 執照_dtp.CustomFormat = " " : Else
                執照_dtp.CustomFormat = "yyyy/MM/dd" : 執照_dtp.Value = 土地_dgv.Rows(DGVX).Cells("取得使用執照日").Value.ToString
            End If
        End If
        If 土地_dgv.Rows(DGVX).Cells("建照核准日").Value.ToString = "" Then : 建照_dtp.CustomFormat = " " : Else
            If 土地_dgv.Rows(DGVX).Cells("建照核准日").Value.ToString = " " Then : 建照_dtp.CustomFormat = " " : Else
                建照_dtp.CustomFormat = "yyyy/MM/dd" : 建照_dtp.Value = 土地_dgv.Rows(DGVX).Cells("建照核准日").Value.ToString
            End If
        End If
        If 土地_dgv.Rows(DGVX).Cells("保證金返還日").Value.ToString = "" Then : 保證金返還日_dtp.CustomFormat = " " : Else
            If 土地_dgv.Rows(DGVX).Cells("保證金返還日").Value.ToString = " " Then : 保證金返還日_dtp.CustomFormat = " " : Else
                保證金返還日_dtp.CustomFormat = "yyyy/MM/dd" : 保證金返還日_dtp.Value = 土地_dgv.Rows(DGVX).Cells("保證金返還日").Value.ToString
            End If
        End If
        If 土地_dgv.Rows(DGVX).Cells("興建保證金返還日").Value.ToString = "" Then : 興建保證金返還日_dtp.CustomFormat = " " : Else
            If 土地_dgv.Rows(DGVX).Cells("興建保證金返還日").Value.ToString = " " Then : 興建保證金返還日_dtp.CustomFormat = " " : Else
                興建保證金返還日_dtp.CustomFormat = "yyyy/MM/dd" : 興建保證金返還日_dtp.Value = 土地_dgv.Rows(DGVX).Cells("興建保證金返還日").Value.ToString
            End If
        End If
        Set_土地_租賃條件()
    End Sub
    Private Sub 土地_dgv_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles 土地_dgv.CellEndEdit
        土地計算()
    End Sub
    Private Sub 土地計算()
        Dim NS1, NS2 As Double
        For i As Integer = 0 To 土地_dgv.Rows.Count - 1
            If IsNumeric(土地_dgv.Rows(i).Cells("土地面積(平米)").Value.ToString.Replace(",", "")) = False Then : 土地_dgv.Rows(i).Cells("土地面積(平米)").Value = 0 : End If
            NS1 += CDbl(土地_dgv.Rows(i).Cells("土地面積(平米)").Value.ToString) : 土地_dgv.Rows(i).Cells("坪數").Value = CDbl(土地_dgv.Rows(i).Cells("土地面積(平米)").Value.ToString) / 3.3058
            NS2 += CDbl(土地_dgv.Rows(i).Cells("坪數").Value.ToString)
            土地_dgv.Rows(i).Cells("土地面積(平米)").Value = Strings.Format(CDbl(土地_dgv.Rows(i).Cells("土地面積(平米)").Value.ToString), "#,##0.00")
            土地_dgv.Rows(i).Cells("坪數").Value = Strings.Format(CDbl(土地_dgv.Rows(i).Cells("坪數").Value.ToString), "#,##0.00")
        Next : 總平米_tb.Text = Strings.Format(NS1, "#,##0.00") : 總坪數_tb.Text = Strings.Format(NS2, "#,##0.00")
    End Sub
    Private Sub 區塊_dgv_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles 區塊_dgv.CellEndEdit
        區塊計算()
    End Sub
    Private Sub 區塊計算()
        Dim NS1 As Double
        For i As Integer = 0 To 區塊_dgv.Rows.Count - 1
            If IsNumeric(區塊_dgv.Rows(i).Cells("坪數").Value.ToString.Replace(",", "")) = False Then : 區塊_dgv.Rows(i).Cells("坪數").Value = 0 : End If
            If IsNumeric(區塊_dgv.Rows(i).Cells("面寬(米)").Value.ToString.Replace(",", "")) = False Then : 區塊_dgv.Rows(i).Cells("面寬(米)").Value = 0 : End If
            If IsNumeric(區塊_dgv.Rows(i).Cells("深度(米)").Value.ToString.Replace(",", "")) = False Then : 區塊_dgv.Rows(i).Cells("深度(米)").Value = 0 : End If
            NS1 += CDbl(區塊_dgv.Rows(i).Cells("坪數").Value.ToString)
            區塊_dgv.Rows(i).Cells("面寬(米)").Value = Strings.Format(CDbl(區塊_dgv.Rows(i).Cells("面寬(米)").Value.ToString), "#,##0")
            區塊_dgv.Rows(i).Cells("深度(米)").Value = Strings.Format(CDbl(區塊_dgv.Rows(i).Cells("深度(米)").Value.ToString), "#,##0")
            區塊_dgv.Rows(i).Cells("坪數").Value = Strings.Format(CDbl(區塊_dgv.Rows(i).Cells("坪數").Value.ToString), "#,##0.00")
        Next : 總坪數1_tb.Text = Strings.Format(NS1, "#,##0.00")
    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 圖片清單讀取()
        附件編碼1_lb.Text = 案件附件_dgv.Rows(DGVX).Cells(0).Value.ToString : PA2 = 案件附件_dgv.Rows(DGVX).Cells(0).Value.ToString
        PDF_lb.Text = 案件附件_dgv.Rows(DGVX).Cells("副檔名").Value.ToString
        If 案件附件_dgv.Rows(DGVX).Cells("副檔名").Value.ToString = "PDF" Or 案件附件_dgv.Rows(DGVX).Cells("副檔名").Value.ToString = "pdf" Then
            附件1_pb.Image = My.Resources.Resources.PDF
        Else
            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)
                附件1_pb.Image = Bitmap.FromStream(oStream)
            End While : conn.Close() : 附件1_pb.SizeMode = 4
        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 : 圖片清單讀取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 清單2_dgv_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles 清單2_dgv.CellDoubleClick
        If e.RowIndex = -1 Then : Else
            承租客_tb.Text = 清單2_dgv.Rows(e.RowIndex).Cells("客戶名稱").Value.ToString : 客戶流水_tb.Text = 清單2_dgv.Rows(e.RowIndex).Cells("流水號").Value.ToString
            視窗2_pl.Visible = False
        End If
    End Sub
    Private Sub 土地_dgv_SelectionChanged(sender As Object, e As EventArgs) Handles 土地_dgv.SelectionChanged
        If 土地_dgv.SelectedCells.Count > 0 Then
            Dim selectedRow As DataGridViewRow = 土地_dgv.Rows(土地_dgv.SelectedCells(0).RowIndex)
            If selectedRow IsNot Nothing AndAlso Not selectedRow.IsNewRow Then : 土地編號_tb.Text = selectedRow.Cells("流水號").Value.ToString() : End If
        End If
    End Sub
    Private Sub 區塊_dgv_SelectionChanged(sender As Object, e As EventArgs) Handles 區塊_dgv.SelectionChanged
        If 區塊_dgv.SelectedCells.Count > 0 Then
            Dim selectedRow As DataGridViewRow = 區塊_dgv.Rows(區塊_dgv.SelectedCells(0).RowIndex)
            If selectedRow IsNot Nothing AndAlso Not selectedRow.IsNewRow Then : 建坪編號_tb.Text = selectedRow.Cells("流水號").Value.ToString() : End If
        End If
    End Sub
    Private Sub 承租_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 承租_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 承租_dgv點擊(e.RowIndex) : End If
    End Sub
    Private Sub 承租_dgv點擊(DGVX As Integer)
        承租編號_tb.Text = 承租_dgv.Rows(DGVX).Cells("流水號").Value.ToString : 區塊_cb.Text = 承租_dgv.Rows(DGVX).Cells("建坪編號").Value.ToString
        承租客_tb.Text = 承租_dgv.Rows(DGVX).Cells("客戶名稱").Value.ToString : 未稅1_ch.Checked = 承租_dgv.Rows(DGVX).Cells("免稅").Value
        客戶流水_tb.Text = 承租_dgv.Rows(DGVX).Cells("承租客").Value.ToString : 聯絡人1_tb.Text = 承租_dgv.Rows(DGVX).Cells("聯絡人1").Value.ToString
        聯絡人2_tb.Text = 承租_dgv.Rows(DGVX).Cells("聯絡人2").Value.ToString : 聯絡人3_tb.Text = 承租_dgv.Rows(DGVX).Cells("聯絡人3").Value.ToString
        電話1_tb.Text = 承租_dgv.Rows(DGVX).Cells("電話1").Value.ToString : 電話2_tb.Text = 承租_dgv.Rows(DGVX).Cells("電話2").Value.ToString
        電話3_tb.Text = 承租_dgv.Rows(DGVX).Cells("電話3").Value.ToString : 開發窗口_tb.Text = 承租_dgv.Rows(DGVX).Cells("開發窗口").Value.ToString
        店長_tb.Text = 承租_dgv.Rows(DGVX).Cells("店長/店經理").Value.ToString : 租金_nud.Value = 承租_dgv.Rows(DGVX).Cells("租金").Value.ToString
        押金_nud.Value = 承租_dgv.Rows(DGVX).Cells("押金/保證金").Value.ToString : 備註1_tb.Text = 承租_dgv.Rows(DGVX).Cells("保證金備註").Value.ToString
        If 承租_dgv.Rows(DGVX).Cells("承租狀態").Value.ToString = "S" Then
            承租狀態_cb.Text = "S:已簽正式約"
        ElseIf 承租_dgv.Rows(DGVX).Cells("承租狀態").Value.ToString = "H" Then
            承租狀態_cb.Text = "H:已簽意向書及付訂金"
        ElseIf 承租_dgv.Rows(DGVX).Cells("承租狀態").Value.ToString = "A" Then
            承租狀態_cb.Text = "A:房客開發人員評估確度高,一個月內可簽約"
        ElseIf 承租_dgv.Rows(DGVX).Cells("承租狀態").Value.ToString = "B" Then
            承租狀態_cb.Text = "B:房客開發評估中"
        ElseIf 承租_dgv.Rows(DGVX).Cells("承租狀態").Value.ToString = "F" Then
            承租狀態_cb.Text = "F:房客無意願"
        Else
            承租狀態_cb.Text = ""
        End If

        If 承租_dgv.Rows(DGVX).Cells("租期開始").Value.ToString = " " Then : 租期開始1_dtp.CustomFormat = " " : Else
            租期開始1_dtp.CustomFormat = "yyyy/MM/dd" : 租期開始_dtp.Value = Strings.Left(承租_dgv.Rows(DGVX).Cells("租期開始").Value.ToString, 10)
        End If
        If 承租_dgv.Rows(DGVX).Cells("租期結束").Value.ToString = " " Then : 租期結束1_dtp.CustomFormat = " " : Else
            租期結束1_dtp.CustomFormat = "yyyy/MM/dd" : 租期結束1_dtp.Value = Strings.Left(承租_dgv.Rows(DGVX).Cells("租期結束").Value.ToString, 10)
        End If
        If Strings.Left(承租_dgv.Rows(DGVX).Cells("免租期").Value.ToString, 5) = "  -  " Then : 免租開始1_dtp.CustomFormat = " " : Else
            免租開始1_dtp.CustomFormat = "yyyy/MM/dd" : 免租開始1_dtp.Value = Strings.Left(承租_dgv.Rows(DGVX).Cells("免租期").Value.ToString, 10)
        End If
        If Strings.Right(承租_dgv.Rows(DGVX).Cells("免租期").Value.ToString, 5) = "  -  " Then : 免租結束1_dtp.CustomFormat = " " : Else
            免租結束1_dtp.CustomFormat = "yyyy/MM/dd" : 免租結束1_dtp.Value = Strings.Right(承租_dgv.Rows(DGVX).Cells("免租期").Value.ToString, 10)
        End If : 附件編碼_lb.Text = "" : 附件_pb.Image = Nothing : 計算分流2.Enabled = True
        Set_土地_租金明細()
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        Dim NUM0 As Integer : DTP1 = 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 = "YS-" & DTP1 & "-00" & NUM0
        ElseIf NUM0 > 9 And NUM0 < 100 Then : 流水號_tb.Text = "YS-" & DTP1 & "-0" & NUM0
        ElseIf NUM0 > 99 Then : 流水號_tb.Text = "YS-" & DTP1 & "-" & NUM0
        End If : 地址_tb.ReadOnly = False : 清單1_dgv.Enabled = False
        地址_tb.Text = "" : 地址1_tb.Text = "" : 地址2_tb.Text = "" : 地址3_tb.Text = "" : 地主_tb.Text = "" : 用途_cb.Text = "" : 備註_tb.Text = "" : 土地租期_nud.Value = 0
        土地租金_nud.Value = 0 : 月坪租金_nud.Value = 0 : 保證月_nud.Value = 0 : 保證金_nud.Value = 0 : 太_出租_tb.Text = "" : 太_承租_tb.Text = "" : KW數_tb.Text = ""
        太_租金比_tb.Text = "" : 附件1_pb.Image = Nothing : 附件_pb.Image = Nothing : 案件附件_dgv.DataSource = Nothing : 土地_dgv.DataSource = Nothing
        區塊_dgv.DataSource = Nothing : 承租_dgv.DataSource = Nothing : 附件_dgv.DataSource = Nothing : 區塊_cb.Text = "" : 坪數_nud.Value = 0 : 承租客_tb.Text = ""
        聯絡人1_tb.Text = "" : 聯絡人2_tb.Text = "" : 聯絡人2_tb.Text = "" : 電話1_tb.Text = "" : 電話2_tb.Text = "" : 電話3_tb.Text = "" : 開發窗口_tb.Text = ""
        店長_tb.Text = "" : 面積_tb.Text = "" : 租金_nud.Value = 0 : 案件租期_nup.Value = 0 : 押金_nud.Value = 0 : 聯絡人_tb.Text = "" : 免租_nud.Value = 0 : 製錶_tb.Text = gUserName
        建照_dtp.Format = DateTimePickerFormat.Custom : 建照_dtp.CustomFormat = " " : 執照_dtp.Format = DateTimePickerFormat.Custom : 執照_dtp.CustomFormat = " "
        太陽開始_dtp.Format = DateTimePickerFormat.Custom : 太陽開始_dtp.CustomFormat = " " : 太陽結束_dtp.Format = DateTimePickerFormat.Custom : 太陽結束_dtp.CustomFormat = " "
        免租開始1_dtp.Format = DateTimePickerFormat.Custom : 免租開始1_dtp.CustomFormat = " " : 免租結束1_dtp.Format = DateTimePickerFormat.Custom : 免租結束1_dtp.CustomFormat = " "
        免租開始_dtp.Format = DateTimePickerFormat.Custom : 免租開始_dtp.CustomFormat = " " : 免租結束_dtp.Format = DateTimePickerFormat.Custom : 免租結束_dtp.CustomFormat = " "
        租期開始1_dtp.Format = DateTimePickerFormat.Custom : 租期開始1_dtp.CustomFormat = " " : 租期結束1_dtp.Format = DateTimePickerFormat.Custom : 租期結束1_dtp.CustomFormat = " "
        租期開始_dtp.Format = DateTimePickerFormat.Custom : 租期開始_dtp.CustomFormat = " " : 租期結束_dtp.Format = DateTimePickerFormat.Custom : 租期結束_dtp.CustomFormat = " "
        租賃條件1開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1開始_dtp.CustomFormat = " " : 租賃條件1結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1結束_dtp.CustomFormat = " "
        租賃條件2開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2開始_dtp.CustomFormat = " " : 租賃條件2結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2結束_dtp.CustomFormat = " "
        租賃條件3開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3開始_dtp.CustomFormat = " " : 租賃條件3結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3結束_dtp.CustomFormat = " "
        租賃條件4開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4開始_dtp.CustomFormat = " " : 租賃條件4結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4結束_dtp.CustomFormat = " "
        租賃條件5開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5開始_dtp.CustomFormat = " " : 租賃條件5結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5結束_dtp.CustomFormat = " "
        租賃條件6開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6開始_dtp.CustomFormat = " " : 租賃條件6結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6結束_dtp.CustomFormat = " "
        租賃條件7開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7開始_dtp.CustomFormat = " " : 租賃條件7結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7結束_dtp.CustomFormat = " "
        簽約日_dtp.Format = DateTimePickerFormat.Custom : 簽約日_dtp.CustomFormat = " "
        保證金返還日_dtp.Format = DateTimePickerFormat.Custom : 保證金返還日_dtp.CustomFormat = " " : 興建保證金返還日_dtp.Format = DateTimePickerFormat.Custom : 興建保證金返還日_dtp.CustomFormat = " "
        暫定租賃期間開始_dtp.Format = DateTimePickerFormat.Custom : 暫定租賃期間開始_dtp.CustomFormat = " " : 暫定租賃期間結束_dtp.Format = DateTimePickerFormat.Custom : 暫定租賃期間結束_dtp.CustomFormat = " "
        實際租賃期間開始_dtp.Format = DateTimePickerFormat.Custom : 實際租賃期間開始_dtp.CustomFormat = " " : 實際租賃期間結束_dtp.Format = DateTimePickerFormat.Custom : 實際租賃期間結束_dtp.CustomFormat = " "
        土地租金1_nud.Value = 0 : 土地租金2_nud.Value = 0 : 土地租金3_nud.Value = 0 : 土地租金4_nud.Value = 0 : 土地租金5_nud.Value = 0 : 土地租金6_nud.Value = 0 : 土地租金7_nud.Value = 0
        暫定租賃期間_nud.Value = 0 : 實際租賃期間_nud.Value = 0 : 其他約定事項_tb.Text = "" : 面積土地_tb.Text = "" : 面積建物_tb.Text = "" : 高度_tb.Text = ""
        滴水高度_tb.Text = "" : 屋面方向_tb.Text = "" : 建照號碼_tb.Text = "" : 使用執照號碼_tb.Text = "" : 門牌_tb.Text = "" : 建號_tb.Text = ""

        SQL_資料庫選擇() : If dr.Read() Then : 圖片庫 = dr("文件資料庫").ToString : Else : MsgBox("圖片資料庫已滿，請找系統管理員!!") : Me.Close() : End If
        SQL_案件摘要新增() : Set_案件清單()
    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
                If 製錶_tb.Text = "" Or 製錶_tb.Text = gUserName Then : 確認新增() : Else : If CC(14) = True Then : 確認新增() : End If : End If
                土地存檔() : 建坪存檔()
                SQL_案件摘要太陽修改(太_出租_聯_tb.Text, 太_承租_聯_tb.Text, KW數_tb.Text, 太陽開始_dtp.Text & " - " & 太陽結束_dtp.Text, 太_租金比_tb.Text, 太_出租_tb.Text, 太_承租_tb.Text, 饋線狀態_tb.Text, 並聯起組_tb.Text, 綠能編號_tb.Text)

                SQL_建坪類別(流水號_tb.Text) : 區塊_cb.Items.Clear() : 區塊_cb.Items.Add("") : While (dr.Read()) : 區塊_cb.Items.Add(dr("建坪編號")) : End While : conn.Close()
                地址_tb.ReadOnly = True : 清單1_dgv.Enabled = True : 承租區塊編號_lb.Text = "" : 附件編碼_lb.Text = ""
                承租狀態_cb.Text = "" : 區塊_cb.Text = "" : 承租客_tb.Text = "" : 客戶流水_tb.Text = "" : 聯絡人1_tb.Text = "" : 電話1_tb.Text = ""
                聯絡人2_tb.Text = "" : 電話2_tb.Text = "" : 聯絡人3_tb.Text = "" : 電話3_tb.Text = "" : 開發窗口_tb.Text = "" : 店長_tb.Text = ""
                租期開始1_dtp.CustomFormat = " " : 租期結束1_dtp.CustomFormat = " " : 免租開始1_dtp.CustomFormat = " " : 免租結束1_dtp.CustomFormat = " "
                租金_nud.Value = 0 : 案件租期_nup.Value = 0 : 押金_nud.Value = 0 : 備註1_tb.Text = "" : 附件_dgv.DataSource = Nothing : Set_土地清單() : Set_太陽清單()
                租賃條件存檔_bt.PerformClick()
            End If
        End If
    End Sub
    Private Sub 確認新增()
        If 清單1_dgv.Enabled = False Then : SQL_案件摘要驗證(地址_tb.Text)
            If dr.Read Then : MsgBox("[地址/地號]重複，無法新增[地址/地號]資料!!") : 地址_tb.Text = "" : 地址1_tb.Text = "" : 地址2_tb.Text = "" : 地址3_tb.Text = "" : Exit Sub : End If : End If
        SQL_案件摘要修改(地址_tb.Text, 地主_tb.Text, 聯絡人_tb.Text, 用途_cb.Text, 土地租期_nud.Value, 租期開始_dtp.Text & " - " & 租期結束_dtp.Text, 土地租金_nud.Value,
                   月坪租金_nud.Value, 保證月_nud.Value, 保證金_nud.Value, 免租_nud.Value, 免租開始_dtp.Text & " - " & 免租結束_dtp.Text, 建照_dtp.Text, 執照_dtp.Text,
                   備註_tb.Text, 鄰近地址_tb.Text, 所有權人_tb.Text, 承租公司名_tb.Text, 使用分區_tb.Text, 建蔽容積率_tb.Text, 起造人_tb.Text, 流水號_tb.Text, 郵遞區號_tb.Text)
        Set_案件清單() : MsgBox("存檔完成!!")
    End Sub
    Private Sub 土地存檔()
        For i As Integer = 0 To 土地_dgv.Rows.Count - 1
            Dim 面積編號 As String, 土地面積 As String, 坪數 As String, 地主 As String, 流水號 As String
            面積編號 = 土地_dgv.Rows(i).Cells("面積編號").Value.ToString : 土地面積 = 土地_dgv.Rows(i).Cells("土地面積(平米)").Value.ToString
            坪數 = 土地_dgv.Rows(i).Cells("坪數").Value.ToString : 流水號 = 土地_dgv.Rows(i).Cells("流水號").Value.ToString
            地主 = 土地_dgv.Rows(i).Cells("地主").Value.ToString
            SQL_案件土地修改(面積編號, 土地面積, 坪數, 地主, 流水號)
        Next
        If 土地編號_tb.Text <> "" Then
            SQL_案件土地修改1(興建保證金_nud.Text, 保證金返還日_dtp.Text, 興建保證金返還日_dtp.Text, 暫定租賃期間開始_dtp.Text & " - " & 暫定租賃期間結束_dtp.Text,
                    實際租賃期間開始_dtp.Text & " - " & 實際租賃期間結束_dtp.Text, 興建保證月_nud.Text, 暫定租賃期間_nud.Text, 實際租賃期間_nud.Text)
        End If
    End Sub
    Private Sub 土地新增_bt_Click(sender As Object, e As EventArgs) Handles 土地新增_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇 [案件資料] 或是 [新增案件資料]，才能執行後續動作!!") : Else
            土地存檔() : Dim NUM0 As Integer : DTP1 = 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 = "YT-" & DTP1 & "-00" & NUM0
            ElseIf NUM0 > 9 And NUM0 < 100 Then : 土地編號_tb.Text = "YT-" & DTP1 & "-0" & NUM0
            ElseIf NUM0 > 99 Then : 土地編號_tb.Text = "YT-" & DTP1 & "-" & NUM0
            End If
            SQL_案件土地清單新增(興建保證金_nud.Text, 保證金返還日_dtp.Text, 興建保證金返還日_dtp.Text, 暫定租賃期間開始_dtp.Text & " - " & 暫定租賃期間結束_dtp.Text,
                    實際租賃期間開始_dtp.Text & " - " & 實際租賃期間結束_dtp.Text, 土地區塊_tb.Text, 興建保證月_nud.Text, 暫定租賃期間_nud.Text, 實際租賃期間_nud.Text)
            Set_土地清單()
        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 = "" 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_案件土地刪除() : Set_土地清單() : MsgBox("刪除完成!!") : 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
            建坪存檔() : Dim NUM0 As Integer : DTP1 = 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 = "YS-" & DTP1 & "-00" & NUM0
            ElseIf NUM0 > 9 And NUM0 < 100 Then : 建坪編號_tb.Text = "YS-" & DTP1 & "-0" & NUM0
            ElseIf NUM0 > 99 Then : 建坪編號_tb.Text = "YS-" & DTP1 & "-" & NUM0
            End If : SQL_案件建坪清單新增() : Set_區塊清單()
        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 = "" 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_案件建坪刪除() : Set_區塊清單() : MsgBox("刪除完成!!") : End If
                End If
            End If
        End If
    End Sub
    Private Sub 建坪存檔()
        For i As Integer = 0 To 區塊_dgv.Rows.Count - 1
            Dim 建坪編號 As String, 備註 As String, 坪數 As String, 面寬 As String, 深度 As String, 流水號 As String
            建坪編號 = 區塊_dgv.Rows(i).Cells("建坪編號").Value.ToString : 備註 = 區塊_dgv.Rows(i).Cells("備註").Value.ToString : 坪數 = 區塊_dgv.Rows(i).Cells("坪數").Value.ToString
            面寬 = 區塊_dgv.Rows(i).Cells("面寬(米)").Value.ToString : 深度 = 區塊_dgv.Rows(i).Cells("深度(米)").Value.ToString : 流水號 = 區塊_dgv.Rows(i).Cells("流水號").Value.ToString
            SQL_案件建坪修改(建坪編號, 備註, 坪數, 面寬, 深度, 流水號)
            Set_承租清單()
        Next
    End Sub
    Private Sub 太陽新增_bt_Click(sender As Object, e As EventArgs) Handles 太陽新增_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇 [案件資料] 或是 [新增案件資料]，才能執行後續動作!!") : Else
            Dim NUM0 As Integer : DTP1 = 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 = "SP-" & DTP1 & "-00" & NUM0
            ElseIf NUM0 > 9 And NUM0 < 100 Then : 綠能編號_tb.Text = "SP-" & DTP1 & "-0" & NUM0
            ElseIf NUM0 > 99 Then : 綠能編號_tb.Text = "SP-" & DTP1 & "-" & NUM0
            End If
            SQL_案件太陽清單新增(流水號_tb.Text, 綠能編號_tb.Text, 太_出租_聯_tb.Text, 太_承租_聯_tb.Text, KW數_tb.Text, 太陽開始_dtp.Text & " - " & 太陽結束_dtp.Text,
                         太_租金比_tb.Text, 太_出租_tb.Text, 太_承租_tb.Text, 饋線狀態_tb.Text, 並聯起組_tb.Text)
            Set_太陽清單()
        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 = "" 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_案件太陽刪除(綠能編號_tb.Text) : Set_太陽清單() : MsgBox("刪除完成!!") : End If
                End If
            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|PDF文件 (*.pdf)|*.pdf"
            開啟檔案.Title = "選擇 圖片或PDF 文件"
            開啟檔案.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
            If 開啟檔案.ShowDialog() = DialogResult.OK Then
                Try
                    PA2 = Strings.Right(開啟檔案.FileName, 3)
                    If PA2 <> "PDF" And PA2 <> "pdf" Then : 附件1_pb.Image = Image.FromFile(開啟檔案.FileName) : 附件1_pb.SizeMode = 4 : End If
                    Dim NUM0 As Integer : DTP1 = 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 刪除附件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
                Dim result As DialogResult = MessageBox.Show("請確定是否要刪除選定的案件附件?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    PA11 = InputBox("請輸入大寫 [YES]，並按下確認來刪除資料!!")
                    If PA11 = "YES" Then
                        SQL_連線字串_圖片資料庫() : SQL_案件摘要附件刪除()
                        計算分流1.Enabled = True : MsgBox("刪除完成!!")
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub 區塊_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 區塊_cb.SelectedIndexChanged
        坪數_nud.Value = 0 : 承租區塊編號_lb.Text = "" : 面積_tb.Text = ""
        For i As Integer = 0 To 區塊_dgv.Rows.Count - 1
            If 區塊_cb.Text = 區塊_dgv.Rows(i).Cells("建坪編號").Value.ToString Then
                坪數_nud.Value = CDbl(區塊_dgv.Rows(i).Cells("坪數").Value.ToString)
                承租區塊編號_lb.Text = 區塊_dgv.Rows(i).Cells("流水號").Value.ToString
                面積_tb.Text = 區塊_dgv.Rows(i).Cells("坪數").Value.ToString & " 坪 / 面寬" & 區塊_dgv.Rows(i).Cells("面寬(米)").Value.ToString &
                               " (米) / 深度" & 區塊_dgv.Rows(i).Cells("深度(米)").Value.ToString & " (米)" : Exit Sub
            End If
        Next
    End Sub

    Private Sub 承租新增_bt_Click(sender As Object, e As EventArgs) Handles 承租新增_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇案件資料，才能繼續後續的操作!!") : Else
            If 承租區塊編號_lb.Text = "" Then : MsgBox("請先選擇 [區塊]，才能繼續後續的操作!!") : Else
                If 客戶流水_tb.Text = "" Then : MsgBox("請先選擇 [客戶]，才能繼續後續的操作!!") : Else
                    If 承租狀態_cb.Text = "" Then : MsgBox("請先選擇 [承租狀態]，才能繼續後續的操作!!") : Else
                        Dim NUM0 As Integer : DTP1 = 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 = "YD-" & DTP1 & "-00" & NUM0
                        ElseIf NUM0 > 9 And NUM0 < 100 Then : 承租編號_tb.Text = "YD-" & DTP1 & "-0" & NUM0
                        ElseIf NUM0 > 99 Then : 承租編號_tb.Text = "YD-" & DTP1 & "-" & NUM0
                        End If : Dim 承租狀態 As String = 承租狀態_cb.Text.Substring(0, 1)
                        SQL_案件承租清單新增(承租狀態) : 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 承租區塊編號_lb.Text = "" Then : MsgBox("請先選擇 [區塊]，才能繼續後續的操作!!") : Else
                If 客戶流水_tb.Text = "" Then : MsgBox("請先選擇 [客戶]，才能繼續後續的操作!!") : Else
                    If 承租編號_tb.Text = "" Then : MsgBox("請先選擇 [承租資料] 或是 [新增承租資料]，才能繼續後續的操作!!") : Else
                        If 承租狀態_cb.Text = "" Then : MsgBox("請先選擇 [承租狀態]，才能繼續後續的操作!!") : Else
                            Dim 承租狀態 As String = 承租狀態_cb.Text.Substring(0, 1)
                            SQL_案件承租清單修改(承租狀態) : SQL_案件承租明細查詢(流水號_tb.Text, 建坪編號_tb.Text, 承租編號_tb.Text)
                            If dr.Read() Then
                                Dim 租金明細1時間 As String = 租金明細1開始_dtp.Text & " - " & 租金明細1結束_dtp.Text, 租金明細2時間 As String = 租金明細2開始_dtp.Text & " - " & 租金明細2結束_dtp.Text,
                                    租金明細3時間 As String = 租金明細3開始_dtp.Text & " - " & 租金明細3結束_dtp.Text, 租金明細4時間 As String = 租金明細4開始_dtp.Text & " - " & 租金明細4結束_dtp.Text,
                                    租金明細5時間 As String = 租金明細5開始_dtp.Text & " - " & 租金明細5結束_dtp.Text, 租金明細1金額 As String = 租金金額1_nud.Value.ToString,
                                    租金明細2金額 As String = 租金金額2_nud.Value.ToString, 租金明細3金額 As String = 租金金額3_nud.Value.ToString,
                                    租金明細4金額 As String = 租金金額4_nud.Value.ToString, 租金明細5金額 As String = 租金金額5_nud.Value.ToString
                                SQL_案件承租明細修改(流水號_tb.Text, 建坪編號_tb.Text, dr("流水號"), 租金明細1時間, 租金明細2時間, 租金明細3時間, 租金明細4時間, 租金明細5時間,
                                             租金明細1金額, 租金明細2金額, 租金明細3金額, 租金明細4金額, 租金明細5金額)
                            Else
                                Dim 流水號 As String : SQL_案件土地_租金明細_讀取最後一筆流水號()
                                If dr.Read() Then : 流水號 = dr(0).ToString : Else
                                    流水號 = "YTK-" & Date.Now.Year.ToString.PadLeft(4, "0") & Date.Now.Month.ToString.PadLeft(2, "0") & Date.Now.Day.ToString.PadLeft(2, "0") & "-00000"
                                End If
                                Dim 新流水 As Integer = Integer.Parse(流水號.Substring(流水號.Length - 5)) : 新流水 += 1
                                流水號 = "YTK-" & Date.Now.Year.ToString.PadLeft(4, "0") & Date.Now.Month.ToString.PadLeft(2, "0") & Date.Now.Day.ToString.PadLeft(2, "0") & 新流水.ToString.PadLeft(5, "0")
                                Dim 租金明細1時間 As String = 租金明細1開始_dtp.Text & " - " & 租金明細1結束_dtp.Text, 租金明細2時間 As String = 租金明細2開始_dtp.Text & " - " & 租金明細2結束_dtp.Text,
                                    租金明細3時間 As String = 租金明細3開始_dtp.Text & " - " & 租金明細3結束_dtp.Text, 租金明細4時間 As String = 租金明細4開始_dtp.Text & " - " & 租金明細4結束_dtp.Text,
                                    租金明細5時間 As String = 租金明細5開始_dtp.Text & " - " & 租金明細5結束_dtp.Text, 租金明細1金額 As String = 租金金額1_nud.Value.ToString,
                                    租金明細2金額 As String = 租金金額2_nud.Value.ToString, 租金明細3金額 As String = 租金金額3_nud.Value.ToString,
                                    租金明細4金額 As String = 租金金額4_nud.Value.ToString, 租金明細5金額 As String = 租金金額5_nud.Value.ToString
                                SQL_案件承租明細新增(流水號_tb.Text, 承租編號_tb.Text, 流水號, 租金明細1時間, 租金明細2時間, 租金明細3時間, 租金明細4時間, 租金明細5時間,
                                             租金明細1金額, 租金明細2金額, 租金明細3金額, 租金明細4金額, 租金明細5金額, 承租編號_tb.Text)
                            End If
                            Set_承租清單() : MsgBox("存檔完成!!")
                        End If
                    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 承租區塊編號_lb.Text = "" Then : MsgBox("請先選擇 [區塊]，才能繼續後續的操作!!") : Else
                If 客戶流水_tb.Text = "" Then : MsgBox("請先選擇 [客戶]，才能繼續後續的操作!!") : Else
                    If 承租編號_tb.Text = "" Then : MsgBox("請先選擇 [承租資料] 或是 [新增承租資料]，才能繼續後續的操作!!") : Else
                        If 承租狀態_cb.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_案件承租清單刪除() : Set_承租清單() : MsgBox("刪除完成!!") : 承租區塊編號_lb.Text = "" : 附件編碼_lb.Text = ""
                                    承租狀態_cb.Text = "" : 區塊_cb.Text = "" : 承租客_tb.Text = "" : 客戶流水_tb.Text = "" : 聯絡人1_tb.Text = "" : 電話1_tb.Text = ""
                                    聯絡人2_tb.Text = "" : 電話2_tb.Text = "" : 聯絡人3_tb.Text = "" : 電話3_tb.Text = "" : 開發窗口_tb.Text = "" : 店長_tb.Text = ""
                                    租期開始1_dtp.CustomFormat = " " : 租期結束1_dtp.CustomFormat = " " : 免租開始1_dtp.CustomFormat = " " : 免租結束1_dtp.CustomFormat = " "
                                    租金_nud.Value = 0 : 案件租期_nup.Value = 0 : 押金_nud.Value = 0 : 備註1_tb.Text = "" : 附件_dgv.DataSource = Nothing : MsgBox("刪除完成!!")
                                End If
                            End If
                        End If
                    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 = "" 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
                        附件1_pb.Image = Image.FromFile(開啟檔案.FileName) : 附件1_pb.SizeMode = 4

                        Dim NUM0 As Integer : DTP1 = 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 If
    End Sub
    Private Sub 刪除附件_bt_Click(sender As Object, e As EventArgs) Handles 刪除附件_bt.Click
        If 流水號_tb.Text = "" Then : MsgBox("請先選擇案件資料，才能繼續後續的操作!!") : Else
            If 附件編碼_lb.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_連線字串_圖片資料庫() : SQL_案件承租附件刪除() : 計算分流2.Enabled = True : MsgBox("刪除完成!!") : End If
                End If
            End If
        End If
    End Sub
    Private Sub 清除1_bt_Click(sender As Object, e As EventArgs) Handles 清除1_bt.Click
        租期開始_dtp.Format = DateTimePickerFormat.Custom : 租期開始_dtp.CustomFormat = " " : 租期結束_dtp.Format = DateTimePickerFormat.Custom : 租期結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除2_bt_Click(sender As Object, e As EventArgs) Handles 清除2_bt.Click
        免租開始_dtp.Format = DateTimePickerFormat.Custom : 免租開始_dtp.CustomFormat = " " : 免租結束_dtp.Format = DateTimePickerFormat.Custom : 免租結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除3_bt_Click(sender As Object, e As EventArgs) Handles 清除3_bt.Click
        建照_dtp.Format = DateTimePickerFormat.Custom : 建照_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除4_bt_Click(sender As Object, e As EventArgs) Handles 清除4_bt.Click
        執照_dtp.Format = DateTimePickerFormat.Custom : 執照_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除5_bt_Click(sender As Object, e As EventArgs) Handles 清除5_bt.Click
        太陽開始_dtp.Format = DateTimePickerFormat.Custom : 太陽開始_dtp.CustomFormat = " " : 太陽結束_dtp.Format = DateTimePickerFormat.Custom : 太陽結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除6_bt_Click(sender As Object, e As EventArgs) Handles 清除6_bt.Click
        租期開始1_dtp.Format = DateTimePickerFormat.Custom : 租期開始1_dtp.CustomFormat = " " : 租期結束1_dtp.Format = DateTimePickerFormat.Custom : 租期結束1_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除7_bt_Click(sender As Object, e As EventArgs) Handles 清除7_bt.Click
        免租開始1_dtp.Format = DateTimePickerFormat.Custom : 免租開始1_dtp.CustomFormat = " " : 免租結束1_dtp.Format = DateTimePickerFormat.Custom : 免租結束1_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除8_bt_Click(sender As Object, e As EventArgs) Handles 清除8_bt.Click
        暫定租賃期間開始_dtp.Format = DateTimePickerFormat.Custom : 暫定租賃期間開始_dtp.CustomFormat = " " : 暫定租賃期間結束_dtp.Format = DateTimePickerFormat.Custom : 暫定租賃期間結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除9_bt_Click(sender As Object, e As EventArgs) Handles 清除9_bt.Click
        實際租賃期間開始_dtp.Format = DateTimePickerFormat.Custom : 實際租賃期間開始_dtp.CustomFormat = " " : 實際租賃期間結束_dtp.Format = DateTimePickerFormat.Custom : 實際租賃期間結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除10_bt_Click(sender As Object, e As EventArgs)
        租賃條件1開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1開始_dtp.CustomFormat = " " : 租賃條件1結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件1結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除11_bt_Click(sender As Object, e As EventArgs)
        租賃條件2開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2開始_dtp.CustomFormat = " " : 租賃條件2結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件2結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除12_bt_Click(sender As Object, e As EventArgs)
        租賃條件3開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3開始_dtp.CustomFormat = " " : 租賃條件3結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件3結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除13_bt_Click(sender As Object, e As EventArgs)
        租賃條件4開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4開始_dtp.CustomFormat = " " : 租賃條件4結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件4結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除14_bt_Click(sender As Object, e As EventArgs)
        租賃條件5開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5開始_dtp.CustomFormat = " " : 租賃條件5結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件5結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除15_bt_Click(sender As Object, e As EventArgs)
        租賃條件6開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6開始_dtp.CustomFormat = " " : 租賃條件6結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件6結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除16_bt_Click(sender As Object, e As EventArgs)
        租賃條件7開始_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7開始_dtp.CustomFormat = " " : 租賃條件7結束_dtp.Format = DateTimePickerFormat.Custom : 租賃條件7結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除17_bt_Click(sender As Object, e As EventArgs) Handles 清除17_bt.Click
        簽約日_dtp.Format = DateTimePickerFormat.Custom : 簽約日_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除18_bt_Click(sender As Object, e As EventArgs) Handles 清除18_bt.Click
        租金明細1開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細1開始_dtp.CustomFormat = " " : 租金明細1結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細1結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除19_bt_Click(sender As Object, e As EventArgs) Handles 清除19_bt.Click
        租金明細2開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細2開始_dtp.CustomFormat = " " : 租金明細2結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細2結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除20_bt_Click(sender As Object, e As EventArgs) Handles 清除20_bt.Click
        租金明細3開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細3開始_dtp.CustomFormat = " " : 租金明細3結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細3結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除21_bt_Click(sender As Object, e As EventArgs) Handles 清除21_bt.Click
        租金明細4開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細4開始_dtp.CustomFormat = " " : 租金明細4結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細4結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 清除22_bt_Click(sender As Object, e As EventArgs) Handles 清除22_bt.Click
        租金明細5開始_dtp.Format = DateTimePickerFormat.Custom : 租金明細5開始_dtp.CustomFormat = " " : 租金明細5結束_dtp.Format = DateTimePickerFormat.Custom : 租金明細5結束_dtp.CustomFormat = " "
    End Sub
    Private Sub 暫定租賃期間開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 暫定租賃期間開始_dtp.MouseDown
        暫定租賃期間開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件1開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件1開始_dtp.MouseDown
        租賃條件1開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件2開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件2開始_dtp.MouseDown
        租賃條件2開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件3開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件3開始_dtp.MouseDown
        租賃條件3開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件4開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件4開始_dtp.MouseDown
        租賃條件4開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件5開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件5開始_dtp.MouseDown
        租賃條件5開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件6開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件6開始_dtp.MouseDown
        租賃條件6開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件7開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件7開始_dtp.MouseDown
        租賃條件7開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件1結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件1結束_dtp.MouseDown
        租賃條件1結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件2結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件2結束_dtp.MouseDown
        租賃條件2結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件3結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件3結束_dtp.MouseDown
        租賃條件3結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件4結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件4結束_dtp.MouseDown
        租賃條件4結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件5結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件5結束_dtp.MouseDown
        租賃條件5結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件6結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件6結束_dtp.MouseDown
        租賃條件6結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租賃條件7結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租賃條件7結束_dtp.MouseDown
        租賃條件7結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 暫定租賃期間結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 暫定租賃期間結束_dtp.MouseDown
        暫定租賃期間結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 實際租賃期間開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 實際租賃期間開始_dtp.MouseDown
        實際租賃期間開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 實際租賃期間結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 實際租賃期間結束_dtp.MouseDown
        實際租賃期間結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 簽約日_dtp_MouseDown(sender As Object, e As EventArgs) Handles 簽約日_dtp.MouseDown
        簽約日_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 建照_dtp_MouseDown(sender As Object, e As EventArgs) Handles 建照_dtp.MouseDown
        建照_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 執照_dtp_MouseDown(sender As Object, e As EventArgs) Handles 執照_dtp.MouseDown
        執照_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 太陽開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 太陽開始_dtp.MouseDown
        太陽開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 太陽結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 太陽結束_dtp.MouseDown
        太陽結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 免租開始1_dtp_MouseDown(sender As Object, e As EventArgs) Handles 免租開始1_dtp.MouseDown
        免租開始1_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 免租結束1_dtp_MouseDown(sender As Object, e As EventArgs) Handles 免租結束1_dtp.MouseDown
        免租結束1_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 免租開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 免租開始_dtp.MouseDown
        免租開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 免租結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 免租結束_dtp.MouseDown
        免租結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租期開始1_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租期開始1_dtp.MouseDown
        租期開始1_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租期結束1_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租期結束1_dtp.MouseDown
        租期結束1_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租期開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租期開始_dtp.MouseDown
        租期開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租期結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租期結束_dtp.MouseDown
        租期結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 保證金返還日_dtp_MouseDown(sender As Object, e As EventArgs) Handles 保證金返還日_dtp.MouseDown
        保證金返還日_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 興建保證金返還日_dtp_MouseDown(sender As Object, e As EventArgs) Handles 興建保證金返還日_dtp.MouseDown
        興建保證金返還日_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細1開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細1開始_dtp.MouseDown
        租金明細1開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細2開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細2開始_dtp.MouseDown
        租金明細2開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細3開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細3開始_dtp.MouseDown
        租金明細3開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細4開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細4開始_dtp.MouseDown
        租金明細4開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細5開始_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細5開始_dtp.MouseDown
        租金明細5開始_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細1結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細1結束_dtp.MouseDown
        租金明細1結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細5結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細5結束_dtp.MouseDown
        租金明細5結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細2結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細2結束_dtp.MouseDown
        租金明細2結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細3結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細3結束_dtp.MouseDown
        租金明細3結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租金明細4結束_dtp_MouseDown(sender As Object, e As EventArgs) Handles 租金明細4結束_dtp.MouseDown
        租金明細4結束_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 租期開始_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 租期開始_dtp.ValueChanged
        If 租期開始_dtp.Text = " " Or 租期結束_dtp.Text = " " Then : 土地租期_nud.Value = 0 : Else : 土地租期_nud.Value = Year(租期結束_dtp.Value) - Year(租期開始_dtp.Value) : End If
    End Sub
    Private Sub 租期結束_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 租期結束_dtp.ValueChanged
        If 租期開始_dtp.Text = " " Or 租期結束_dtp.Text = " " Then : 土地租期_nud.Value = 0 : Else : 土地租期_nud.Value = Year(租期結束_dtp.Value) - Year(租期開始_dtp.Value) : End If
    End Sub
    Private Sub 土地租期_nup_ValueChanged(sender As Object, e As EventArgs) Handles 土地租期_nud.ValueChanged
        租期結束_dtp.Value = 租期開始_dtp.Value.AddYears(土地租期_nud.Value)
    End Sub
    Private Sub 租期開始1_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 租期開始1_dtp.ValueChanged
        If 租期開始1_dtp.Text = " " Or 租期結束1_dtp.Text = " " Then : 案件租期_nup.Value = 0 : Else : 案件租期_nup.Value = Year(租期結束1_dtp.Value) - Year(租期開始1_dtp.Value) : End If
    End Sub
    Private Sub 租期結束1_dtpp_ValueChanged(sender As Object, e As EventArgs) Handles 租期結束1_dtp.ValueChanged
        If 租期開始1_dtp.Text = " " Or 租期結束1_dtp.Text = " " Then : 案件租期_nup.Value = 0 : Else : 案件租期_nup.Value = Year(租期結束1_dtp.Value) - Year(租期開始1_dtp.Value) : End If
    End Sub
    Private Sub 案件租期_nup_ValueChanged(sender As Object, e As EventArgs) Handles 案件租期_nup.ValueChanged
        租期結束1_dtp.Value = 租期開始1_dtp.Value.AddYears(案件租期_nup.Value)
    End Sub
    Private Sub 免租開始1_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 免租開始1_dtp.ValueChanged
        If 免租開始1_dtp.Text = " " Or 免租結束1_dtp.Text = " " Then : 免租1_nud.Value = 0 : Else
            免租1_nud.Value = (DateDiff(DateInterval.Day, 免租開始1_dtp.Value, 免租結束1_dtp.Value) + 1) : End If
    End Sub
    Private Sub 免租結束1_dtpp_ValueChanged(sender As Object, e As EventArgs) Handles 免租結束1_dtp.ValueChanged
        If 免租開始1_dtp.Text = " " Or 免租結束1_dtp.Text = " " Then : 免租1_nud.Value = 0 : Else
            免租1_nud.Value = (DateDiff(DateInterval.Day, 免租開始1_dtp.Value, 免租結束1_dtp.Value) + 1) : End If
    End Sub
    Private Sub 免租1_nud_ValueChanged(sender As Object, e As EventArgs) Handles 免租1_nud.ValueChanged
        免租結束1_dtp.Value = 免租開始1_dtp.Value.AddDays(免租1_nud.Value - 1)
    End Sub
    Private Sub 免租開始_dtp_ValueChanged_1(sender As Object, e As EventArgs) Handles 免租開始_dtp.ValueChanged
        Dim startDate As DateTime = 免租開始_dtp.Value : Dim endDate As DateTime = 免租結束_dtp.Value
        Dim monthDifference As Integer = (endDate.Year - startDate.Year) * 12 + endDate.Month - startDate.Month : 免租_nud.Value = monthDifference
    End Sub
    Private Sub 免租結束_dtp_ValueChanged_1(sender As Object, e As EventArgs) Handles 免租結束_dtp.ValueChanged
        Dim startDate As DateTime = 免租開始_dtp.Value : Dim endDate As DateTime = 免租結束_dtp.Value
        Dim monthDifference As Integer = (endDate.Year - startDate.Year) * 12 + endDate.Month - startDate.Month : 免租_nud.Value = monthDifference
    End Sub
    Private Sub 免租_nud_ValueChanged(sender As Object, e As EventArgs) Handles 免租_nud.ValueChanged
        Dim startDate As DateTime = 免租開始_dtp.Value : Dim monthDifference As Integer = CInt(免租_nud.Value)
        Dim endDate As DateTime = startDate.AddMonths(monthDifference) : 免租結束_dtp.Value = endDate
    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((Me.Size.Width - 視窗2_pl.Size.Width) / 2, (Me.Size.Height - 視窗2_pl.Size.Height) / 2)
                視窗2_pl.Visible = True : 視窗2_pl.BringToFront() : Set_客戶清單()
            Else : End If
        End If
    End Sub
    Private Sub 關鍵字1_tb_KeyDown(sender As Object, e As KeyEventArgs) Handles 關鍵字1_tb.KeyDown
        If e.KeyCode = Keys.Enter Then : Set_客戶清單() : End If
    End Sub
    Private Sub 分類2_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 分類2_cb.SelectedIndexChanged
        Set_客戶清單()
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        Set_客戶清單()
    End Sub
    Private Sub 附件1_pb_Click(sender As Object, e As EventArgs) Handles 附件1_pb.Click
        If 附件1_pb.Image IsNot Nothing Then
            If PDF_lb.Text <> "pdf" And PDF_lb.Text <> "PDF" Then
                圖片傳遞 = 附件1_pb.Image : 圖片放大視窗.ShowDialog()
            Else
                Dim Str As String = System.Windows.Forms.Application.StartupPath : conn.Close()
                PA2 = 附件編碼1_lb.Text : SQL_連線字串_圖片資料庫()
                Dim ds1 As New DataSet : ds1.Clear() : SQL_案件摘要附件讀取1() : da.Fill(ds1)
                If ds1.Tables(0).Rows.Count > 0 Then
                    Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("圖片")
                    Dim fs As FileStream : fs = File.Create(Str + "\" & PA2 & ".pdf", imgData.Length - 1)
                    fs.Write(imgData, 0, imgData.Length - 1) : fs.Close()
                End If : conn.Close() : PDF路徑 = Str + "\" & PA2 & ".pdf" : PDF預覽.ShowDialog()
            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 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If CC(12) = False 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_案件摘要總表刪除() : SQL_案件摘要_土地刪除() : SQL_案件摘要_建坪刪除() : SQL_案件摘要_承租刪除() : SQL_案件摘要_太陽刪除()
                        Set_案件清單() : MsgBox("刪除完成!!") : End If
                End If
            End If
        End If
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
        'MsgBox("功能開發中")
        If 流水號_tb.Text = "" Then
            MsgBox("請先選擇一張摘要表!")
        Else
            xlApp = CType(CreateObject("Excel.Application"), Application) : xlBook = xlApp.Workbooks.Add : xlApp.DisplayAlerts = True : xlBook.Activate()
            xlSheet = NewMethod(xlBook) : xlSheet.Activate() : xlApp.Visible = True : xlApp.Application.WindowState = xlMaximized

            xlSheet.Cells(2, 2) = 地址_tb.Text & " - 摘要表" : xlSheet.Cells(3, 18) = 流水號_tb.Text : xlSheet.Cells(4, 2) = "土地資訊"
            xlSheet.Cells(5, 2) = "地　　　號" : xlSheet.Cells(5, 7) = 地址_tb.Text : xlSheet.Cells(5, 12) = "使用分區" : xlSheet.Cells(5, 17) = 使用分區_tb.Text
            xlSheet.Cells(6, 2) = "鄰近地址" : xlSheet.Cells(6, 7) = 鄰近地址_tb.Text : xlSheet.Cells(6, 12) = "建蔽、容積率" : xlSheet.Cells(6, 17) = 建蔽容積率_tb.Text
            xlSheet.Cells(7, 2) = "所有權人" : xlSheet.Cells(7, 7) = 所有權人_tb.Text : xlSheet.Cells(7, 12) = "聯 絡 人" : xlSheet.Cells(7, 17) = 聯絡人_tb.Text
            xlSheet.Cells(8, 2) = "承租公司名" : xlSheet.Cells(8, 7) = 承租公司名_tb.Text : xlSheet.Cells(8, 12) = "起造人" : xlSheet.Cells(8, 17) = 起造人_tb.Text
            Dim 土地行數 As Integer = 9 : Dim 土地使用區塊 As Integer = Math.Ceiling(土地_dgv.Rows.Count / 2)
            For i As Integer = 0 To 土地_dgv.Rows.Count - 1
                Dim 倍率 As Integer = Math.Ceiling((i + 1) / 2) - 1
                If i Mod 2 = 0 Then
                    xlSheet.Cells(土地行數 + 10 * 倍率, 2) = "土地區塊" : xlSheet.Cells(土地行數 + 10 * 倍率, 7) = 土地_dgv.Rows(i).Cells("面積編號").Value.ToString() & " - " & 土地_dgv.Rows(i).Cells("地主").Value.ToString()
                    xlSheet.Cells((土地行數 + 1) + 10 * 倍率, 2) = "土地租期" : xlSheet.Cells((土地行數 + 1) + 10 * 倍率, 7) = 土地_dgv.Rows(i).Cells("土地租期").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("租期備註").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 2) = "租賃條件" : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 3) = "租金(調幅3年4%)" : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 5) = "(未)稅"
                    If IsDBNull(土地_dgv.Rows(i).Cells("免稅").Value) Then : Else
                        If 土地_dgv.Rows(i).Cells("免稅").Value.ToString = "True" Then : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 6) = " V " : End If
                    End If
                    SQL_案件土地_租賃條件清單(土地_dgv.Rows(i).Cells("單據編號").Value.ToString, 土地_dgv.Rows(i).Cells("流水號").Value.ToString())
                    If dr.Read() Then
                        Dim 租賃條件1時間 As String = dr("租賃條件1時間").ToString() : Dim 租賃條件1金額 As String = dr("租賃條件1金額").ToString()
                        If String.IsNullOrEmpty(租賃條件1時間) OrElse 租賃條件1時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件1金額)) : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件1時間
                        End If
                        Dim 租賃條件2時間 As String = dr("租賃條件2時間").ToString() : Dim 租賃條件2金額 As String = dr("租賃條件2金額").ToString()
                        If String.IsNullOrEmpty(租賃條件2時間) OrElse 租賃條件2時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件2金額)) : xlSheet.Cells((土地行數 + 4) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件2時間
                        End If
                        Dim 租賃條件3時間 As String = dr("租賃條件3時間").ToString() : Dim 租賃條件3金額 As String = dr("租賃條件3金額").ToString()
                        If String.IsNullOrEmpty(租賃條件3時間) OrElse 租賃條件3時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件3金額)) : xlSheet.Cells((土地行數 + 5) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件3時間
                        End If
                        Dim 租賃條件4時間 As String = dr("租賃條件4時間").ToString() : Dim 租賃條件4金額 As String = dr("租賃條件4金額").ToString()
                        If String.IsNullOrEmpty(租賃條件4時間) OrElse 租賃條件4時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件4金額)) : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件4時間
                        End If
                        Dim 租賃條件5時間 As String = dr("租賃條件5時間").ToString() : Dim 租賃條件5金額 As String = dr("租賃條件5金額").ToString()
                        If String.IsNullOrEmpty(租賃條件5時間) OrElse 租賃條件5時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件5金額)) : xlSheet.Cells((土地行數 + 7) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件5時間
                        End If
                        Dim 租賃條件6時間 As String = dr("租賃條件6時間").ToString() : Dim 租賃條件6金額 As String = dr("租賃條件6金額").ToString()
                        If String.IsNullOrEmpty(租賃條件6時間) OrElse 租賃條件6時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件6金額)) : xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件6時間
                        End If
                        Dim 租賃條件7時間 As String = dr("租賃條件7時間").ToString() : Dim 租賃條件7金額 As String = dr("租賃條件7金額").ToString()
                        If String.IsNullOrEmpty(租賃條件7時間) OrElse 租賃條件7時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件7金額)) : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 3) = 金額.ToString("#,##0") & ":" & 租賃條件7時間
                        End If
                    End If
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 7) = "押金(保證金)" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 7) = 土地_dgv.Rows(i).Cells("押金/保證金").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 8) = "興建保證金" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 8) = 土地_dgv.Rows(i).Cells("興建保證金").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 9) = "免租興建期" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 9) = 土地_dgv.Rows(i).Cells("免租興建期").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("建期備註").Value.ToString()
                    xlSheet.Cells((土地行數 + 4) + 10 * 倍率, 9) = "暫定租賃期間" : xlSheet.Cells((土地行數 + 5) + 10 * 倍率, 9) = 土地_dgv.Rows(i).Cells("暫訂租賃月").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("暫訂租賃期間").Value.ToString()
                    xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 7) = "屆期7日內返還" : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 8) = "使照核發" & vbCrLf & "3日內交還" : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 9) = "期限內依實際營業日為準"
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 7) = "返還日" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 7) = 土地_dgv.Rows(i).Cells("保證金返還日").Value.ToString()
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 8) = "返還日" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 8) = 土地_dgv.Rows(i).Cells("興建保證金返還日").Value.ToString()
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 9) = "實際租賃期間" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 9) = 土地_dgv.Rows(i).Cells("實際租賃月").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("實際租賃期間").Value.ToString()
                Else
                    xlSheet.Cells(土地行數 + 10 * 倍率, 12) = "土地區塊" : xlSheet.Cells(土地行數 + 10 * 倍率, 17) = 土地_dgv.Rows(i).Cells("面積編號").Value.ToString() & " - " & 土地_dgv.Rows(i).Cells("地主").Value.ToString()
                    xlSheet.Cells((土地行數 + 1) + 10 * 倍率, 12) = "土地租期" : xlSheet.Cells((土地行數 + 1) + 10 * 倍率, 17) = 土地_dgv.Rows(i).Cells("土地租期").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("租期備註").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 12) = "租賃條件" : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 13) = "租金(調幅3年4%)" : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 15) = "(未)稅"
                    If IsDBNull(土地_dgv.Rows(i).Cells("免稅").Value) Then : Else
                        If 土地_dgv.Rows(i).Cells("免稅").Value.ToString = "True" Then : xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 16) = " V " : End If
                    End If
                    SQL_案件土地_租賃條件清單(土地_dgv.Rows(i).Cells("單據編號").Value.ToString, 土地_dgv.Rows(i).Cells("流水號").Value.ToString())
                    If dr.Read() Then
                        Dim 租賃條件1時間 As String = dr("租賃條件1時間").ToString() : Dim 租賃條件1金額 As String = dr("租賃條件1金額").ToString()
                        If String.IsNullOrEmpty(租賃條件1時間) OrElse 租賃條件1時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件1金額)) : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件1時間
                        End If
                        Dim 租賃條件2時間 As String = dr("租賃條件2時間").ToString() : Dim 租賃條件2金額 As String = dr("租賃條件2金額").ToString()
                        If String.IsNullOrEmpty(租賃條件2時間) OrElse 租賃條件2時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件2金額)) : xlSheet.Cells((土地行數 + 4) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件2時間
                        End If
                        Dim 租賃條件3時間 As String = dr("租賃條件3時間").ToString() : Dim 租賃條件3金額 As String = dr("租賃條件3金額").ToString()
                        If String.IsNullOrEmpty(租賃條件3時間) OrElse 租賃條件3時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件3金額)) : xlSheet.Cells((土地行數 + 5) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件3時間
                        End If
                        Dim 租賃條件4時間 As String = dr("租賃條件4時間").ToString() : Dim 租賃條件4金額 As String = dr("租賃條件4金額").ToString()
                        If String.IsNullOrEmpty(租賃條件4時間) OrElse 租賃條件4時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件4金額)) : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件4時間
                        End If
                        Dim 租賃條件5時間 As String = dr("租賃條件5時間").ToString() : Dim 租賃條件5金額 As String = dr("租賃條件5金額").ToString()
                        If String.IsNullOrEmpty(租賃條件5時間) OrElse 租賃條件5時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件5金額)) : xlSheet.Cells((土地行數 + 7) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件5時間
                        End If
                        Dim 租賃條件6時間 As String = dr("租賃條件6時間").ToString() : Dim 租賃條件6金額 As String = dr("租賃條件6金額").ToString()
                        If String.IsNullOrEmpty(租賃條件6時間) OrElse 租賃條件6時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件6金額)) : xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件6時間
                        End If
                        Dim 租賃條件7時間 As String = dr("租賃條件7時間").ToString() : Dim 租賃條件7金額 As String = dr("租賃條件7金額").ToString()
                        If String.IsNullOrEmpty(租賃條件7時間) OrElse 租賃條件7時間.Substring(0, 5) = "  -  " Then : Else
                            Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件7金額)) : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 13) = 金額.ToString("#,##0") & ":" & 租賃條件7時間
                        End If
                    End If
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 17) = "押金(保證金)" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 17) = 土地_dgv.Rows(i).Cells("押金/保證金").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 18) = "興建保證金" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 18) = 土地_dgv.Rows(i).Cells("興建保證金").Value.ToString()
                    xlSheet.Cells((土地行數 + 2) + 10 * 倍率, 19) = "免租興建期" : xlSheet.Cells((土地行數 + 3) + 10 * 倍率, 19) = 土地_dgv.Rows(i).Cells("免租興建期").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("建期備註").Value.ToString()
                    xlSheet.Cells((土地行數 + 4) + 10 * 倍率, 19) = "暫定租賃期間" : xlSheet.Cells((土地行數 + 5) + 10 * 倍率, 19) = 土地_dgv.Rows(i).Cells("暫訂租賃月").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("暫訂租賃期間").Value.ToString()
                    xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 17) = "屆期7日內返還" : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 18) = "使照核發" & vbCrLf & "3日內交還" : xlSheet.Cells((土地行數 + 6) + 10 * 倍率, 19) = "期限內依實際營業日為準"
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 17) = "返還日" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 17) = 土地_dgv.Rows(i).Cells("保證金返還日").Value.ToString()
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 18) = "返還日" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 18) = 土地_dgv.Rows(i).Cells("興建保證金返還日").Value.ToString()
                    xlSheet.Cells((土地行數 + 8) + 10 * 倍率, 19) = "實際租賃期間" : xlSheet.Cells((土地行數 + 9) + 10 * 倍率, 19) = 土地_dgv.Rows(i).Cells("實際租賃月").Value.ToString() & " 年 ," & 土地_dgv.Rows(i).Cells("實際租賃期間").Value.ToString()
                End If
            Next

            Dim 建物開始行數 = Math.Ceiling(土地_dgv.Rows.Count / 2) * 10 + 9 : Dim 建物區塊 As Integer = Math.Ceiling(區塊_dgv.Rows.Count / 5)
            For i As Integer = 0 To 建物區塊 - 1
                xlSheet.Cells(建物開始行數 + 27 * i, 2) = "建物資訊" : xlSheet.Cells(建物開始行數 + 1 + 27 * i, 2) = "編(戶)號" : xlSheet.Cells(建物開始行數 + 2 + 27 * i, 2) = "項     目"
                xlSheet.Cells(建物開始行數 + 3 + 27 * i, 2) = "客  戶  名  稱" : xlSheet.Cells(建物開始行數 + 4 + 27 * i, 2) = "聯    絡    人" : xlSheet.Cells(建物開始行數 + 5 + 27 * i, 2) = "電　　　　　話"
                xlSheet.Cells(建物開始行數 + 6 + 27 * i, 2) = "租賃條件" : xlSheet.Cells(建物開始行數 + 6 + 27 * i, 3) = "簽　約　日" : xlSheet.Cells(建物開始行數 + 7 + 27 * i, 3) = "免租興建期"
                xlSheet.Cells(建物開始行數 + 8 + 27 * i, 3) = "押金(保證金)" : xlSheet.Cells(建物開始行數 + 9 + 27 * i, 3) = "租　金　明　細" : xlSheet.Cells(建物開始行數 + 14 + 27 * i, 3) = "其他約定事項"
                xlSheet.Cells(建物開始行數 + 15 + 27 * i, 2) = "建 物 規 劃" : xlSheet.Cells(建物開始行數 + 15 + 27 * i, 3) = "面積" : xlSheet.Cells(建物開始行數 + 15 + 27 * i, 5) = "土地"
                xlSheet.Cells(建物開始行數 + 16 + 27 * i, 5) = "建物" : xlSheet.Cells(建物開始行數 + 17 + 27 * i, 3) = "面　　　　寬" : xlSheet.Cells(建物開始行數 + 18 + 27 * i, 3) = "深　　　　度"
                xlSheet.Cells(建物開始行數 + 19 + 27 * i, 3) = "高　　　　度" : xlSheet.Cells(建物開始行數 + 20 + 27 * i, 3) = "滴　水　高　度" : xlSheet.Cells(建物開始行數 + 21 + 27 * i, 3) = "屋　面　方　向"
                xlSheet.Cells(建物開始行數 + 22 + 27 * i, 2) = "使　用　用　途" : xlSheet.Cells(建物開始行數 + 23 + 27 * i, 2) = "建　照　號　碼" : xlSheet.Cells(建物開始行數 + 24 + 27 * i, 2) = "使用執照號碼"
                xlSheet.Cells(建物開始行數 + 25 + 27 * i, 2) = "門　　　　牌" : xlSheet.Cells(建物開始行數 + 26 + 27 * i, 2) = "建        號"
            Next
            For i = 0 To 建物區塊 - 1
                Dim 編號 As Integer() = {7, 9, 12, 16, 19}
                For j As Integer = 0 To 4
                    xlSheet.Cells(建物開始行數 + 1 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("建坪編號").Value.ToString
                    xlSheet.Cells(建物開始行數 + 6 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("簽約日").Value.ToString
                    xlSheet.Cells(建物開始行數 + 14 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("其他約定事項").Value.ToString
                    xlSheet.Cells(建物開始行數 + 15 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("面積土地").Value.ToString
                    xlSheet.Cells(建物開始行數 + 16 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("面積建物").Value.ToString
                    xlSheet.Cells(建物開始行數 + 17 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("面寬(米)").Value.ToString
                    xlSheet.Cells(建物開始行數 + 18 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("深度(米)").Value.ToString
                    xlSheet.Cells(建物開始行數 + 19 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("高度").Value.ToString
                    xlSheet.Cells(建物開始行數 + 20 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("滴水高度").Value.ToString
                    xlSheet.Cells(建物開始行數 + 21 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("屋面方向").Value.ToString
                    xlSheet.Cells(建物開始行數 + 22 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("使用用途").Value.ToString
                    xlSheet.Cells(建物開始行數 + 23 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("建照號碼").Value.ToString
                    xlSheet.Cells(建物開始行數 + 24 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("使用執照號碼").Value.ToString
                    xlSheet.Cells(建物開始行數 + 25 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("門牌").Value.ToString
                    xlSheet.Cells(建物開始行數 + 26 + 27 * i, 編號(j Mod 5)) = 區塊_dgv.Rows(j + 5 * i).Cells("建號").Value.ToString
                    For g As Integer = 0 To 承租_dgv.Rows.Count - 1
                        If 承租_dgv.Rows(g).Cells("承租狀態").Value.ToString = "S" And 承租_dgv.Rows(g).Cells("建坪號").Value.ToString = 區塊_dgv.Rows(j + 5 * i).Cells("流水號").Value.ToString Then
                            xlSheet.Cells(建物開始行數 + 3 + 27 * i, 編號(j Mod 5)) = 承租_dgv.Rows(g).Cells("客戶名稱").Value.ToString
                            xlSheet.Cells(建物開始行數 + 4 + 27 * i, 編號(j Mod 5)) = 承租_dgv.Rows(g).Cells("聯絡人1").Value.ToString
                            xlSheet.Cells(建物開始行數 + 5 + 27 * i, 編號(j Mod 5)) = 承租_dgv.Rows(g).Cells("電話1").Value.ToString
                            xlSheet.Cells(建物開始行數 + 7 + 27 * i, 編號(j Mod 5)) = 承租_dgv.Rows(g).Cells("免租期").Value.ToString
                            xlSheet.Cells(建物開始行數 + 8 + 27 * i, 編號(j Mod 5)) = 承租_dgv.Rows(g).Cells("押金/保證金").Value.ToString
                            SQL_案件承租明細查詢(承租_dgv.Rows(g).Cells("單據編號").Value.ToString, 承租_dgv.Rows(g).Cells("流水號").Value.ToString, 承租編號_tb.Text)
                            If dr.Read() Then
                                Dim 租賃條件1時間 As String = dr("租金明細1時間").ToString() : Dim 租賃條件1金額 As String = dr("租金明細1金額").ToString()
                                If String.IsNullOrEmpty(租賃條件1時間) OrElse 租賃條件1時間.Substring(0, 5) = "  -  " Then : Else
                                    Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件1金額)) : xlSheet.Cells(建物開始行數 + 9 + 27 * i, 編號(j Mod 5)) = 金額.ToString("#,##0") & ":" & 租賃條件1時間
                                End If
                                Dim 租賃條件2時間 As String = dr("租金明細2時間").ToString() : Dim 租賃條件2金額 As String = dr("租金明細2金額").ToString()
                                If String.IsNullOrEmpty(租賃條件2時間) OrElse 租賃條件2時間.Substring(0, 5) = "  -  " Then : Else
                                    Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件2金額)) : xlSheet.Cells(建物開始行數 + 10 + 27 * i, 編號(j Mod 5)) = 金額.ToString("#,##0") & ":" & 租賃條件2時間
                                End If
                                Dim 租賃條件3時間 As String = dr("租金明細3時間").ToString() : Dim 租賃條件3金額 As String = dr("租金明細3金額").ToString()
                                If String.IsNullOrEmpty(租賃條件3時間) OrElse 租賃條件3時間.Substring(0, 5) = "  -  " Then : Else
                                    Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件3金額)) : xlSheet.Cells(建物開始行數 + 11 + 27 * i, 編號(j Mod 5)) = 金額.ToString("#,##0") & ":" & 租賃條件3時間
                                End If
                                Dim 租賃條件4時間 As String = dr("租金明細4時間").ToString() : Dim 租賃條件4金額 As String = dr("租金明細4金額").ToString()
                                If String.IsNullOrEmpty(租賃條件4時間) OrElse 租賃條件4時間.Substring(0, 5) = "  -  " Then : Else
                                    Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件4金額)) : xlSheet.Cells(建物開始行數 + 12 + 27 * i, 編號(j Mod 5)) = 金額.ToString("#,##0") & ":" & 租賃條件4時間
                                End If
                                Dim 租賃條件5時間 As String = dr("租金明細5時間").ToString() : Dim 租賃條件5金額 As String = dr("租金明細5金額").ToString()
                                If String.IsNullOrEmpty(租賃條件5時間) OrElse 租賃條件5時間.Substring(0, 5) = "  -  " Then : Else
                                    Dim 金額 As Integer = Math.Round(Single.Parse(租賃條件5金額)) : xlSheet.Cells(建物開始行數 + 13 + 27 * i, 編號(j Mod 5)) = 金額.ToString("#,##0") & ":" & 租賃條件5時間
                                End If
                            End If
                        End If
                    Next
                    If j + 5 * i >= 區塊_dgv.Rows.Count - 1 Then : Exit For : End If
                Next
            Next

            Dim 太陽能開始行數 As Integer = 建物開始行數 + Math.Ceiling(區塊_dgv.Rows.Count / 5) * 27
            For i = 0 To 太陽_dgv.Rows.Count - 1
                xlSheet.Cells(太陽能開始行數 + i * 8, 2) = "太陽能資訊"
                xlSheet.Cells(太陽能開始行數 + 1 + i * 8, 2) = "饋 線 狀 態" : xlSheet.Cells(太陽能開始行數 + 1 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_饋線狀態").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 2 + i * 8, 2) = "出  租  方" : xlSheet.Cells(太陽能開始行數 + 2 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_出租方").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 2 + i * 8, 11) = "聯 絡 人" : xlSheet.Cells(太陽能開始行數 + 2 + i * 8, 12) = 太陽_dgv.Rows(i).Cells("太陽_出租人").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 3 + i * 8, 2) = "承  租  方" : xlSheet.Cells(太陽能開始行數 + 3 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_承租方").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 3 + i * 8, 11) = "聯 絡 人" : xlSheet.Cells(太陽能開始行數 + 3 + i * 8, 12) = 太陽_dgv.Rows(i).Cells("太陽_承租人").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 4 + i * 8, 2) = "KW數" : xlSheet.Cells(太陽能開始行數 + 4 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_KW數").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 5 + i * 8, 2) = "租      期" : xlSheet.Cells(太陽能開始行數 + 5 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_租期").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 6 + i * 8, 2) = "租金條件(%)" : xlSheet.Cells(太陽能開始行數 + 6 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_租金%").Value.ToString
                xlSheet.Cells(太陽能開始行數 + 7 + i * 8, 2) = "並 聯 起 租" : xlSheet.Cells(太陽能開始行數 + 7 + i * 8, 5) = 太陽_dgv.Rows(i).Cells("太陽_並聯起租").Value.ToString
            Next
            Dim 太陽能使用區塊 As Integer = 太陽_dgv.Rows.Count
            AA(xlApp, xlSheet, 土地行數, 建物開始行數, 建物區塊, 太陽能開始行數, 土地使用區塊, 太陽能使用區塊)
            DD(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)
            xlApp.Quit() : Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
            xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect() : GC.WaitForPendingFinalizers()
            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 If
    End Sub
    Private Sub DD(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)

        Dim imagePath As String = System.Windows.Forms.Application.StartupPath & "\YSLOGO2.png"
        Dim cell As Range = xlSheet.Cells(2, 2) : Dim left As Single = CType(cell.Left, Single) : Dim top As Single = CType(cell.Top, Single)
        Dim width As Single = 100 : Dim height As Single = 32 + 16
        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)

    End Sub
    Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet, 土地行數 As Integer, 建物開始行數 As Integer, 建物區塊 As Integer,
                   太陽能開始行數 As Integer, 土地使用區塊 As Integer, 太陽能使用區塊 As Integer)
        myExcel.Columns("B:T").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
        myExcel.Range("B2:T2").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
        With myExcel.Selection.Font
            .Name = "標楷體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        myExcel.Range("Q3:T3").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
        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
        myExcel.Range("B4:T4").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
        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
        myExcel.Selection.Font.Bold = True
        For i As Integer = 5 To 8
            myExcel.Range("B" & i & ":F" & 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
            myExcel.Range("G" & i & ":K" & 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
            myExcel.Range("L" & i & ":P" & 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
            myExcel.Range("Q" & i & ":T" & 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
        For i = 0 To 土地使用區塊 - 1
            myExcel.Range("B" & 土地行數 + 10 * i & ":F" & 土地行數 + 10 * 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
            myExcel.Range("G" & 土地行數 + 10 * i & ":K" & 土地行數 + 10 * 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
            myExcel.Range("L" & 土地行數 + 10 * i & ":P" & 土地行數 + 10 * 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
            myExcel.Range("Q" & 土地行數 + 10 * i & ":T" & 土地行數 + 10 * 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
            myExcel.Range("B" & 土地行數 + 1 + 10 * i & ":F" & 土地行數 + 1 + 10 * 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
            myExcel.Range("G" & 土地行數 + 1 + 10 * i & ":K" & 土地行數 + 1 + 10 * 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
            myExcel.Range("L" & 土地行數 + 1 + 10 * i & ":P" & 土地行數 + 1 + 10 * 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
            myExcel.Range("Q" & 土地行數 + 1 + 10 * i & ":T" & 土地行數 + 1 + 10 * 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
            myExcel.Range("B" & 土地行數 + 2 + 10 * i & ":B" & 土地行數 + 9 + 10 * i).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
            myExcel.Range("L" & 土地行數 + 2 + 10 * i & ":L" & 土地行數 + 9 + 10 * i).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
            myExcel.Range("C" & 土地行數 + 2 + 10 * i & ":D" & 土地行數 + 2 + 10 * 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
            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
            myExcel.Range("M" & 土地行數 + 2 + 10 * i & ":N" & 土地行數 + 2 + 10 * 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
            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
            For j As Integer = 3 To 9
                myExcel.Range("C" & 土地行數 + j + 10 * i & ":F" & 土地行數 + j + 10 * 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
                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
                myExcel.Range("M" & 土地行數 + j + 10 * i & ":P" & 土地行數 + j + 10 * 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
                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
                If j = 8 Or j = 9 Then
                    myExcel.Range("G" & 土地行數 + j + 10 * i & ":H" & 土地行數 + j + 10 * 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.Range("Q" & 土地行數 + j + 10 * i & ":R" & 土地行數 + j + 10 * 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
                End If
            Next
            myExcel.Range("G" & 土地行數 + 3 + 10 * i & ":G" & 土地行數 + 5 + 10 * 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
            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
            myExcel.Range("H" & 土地行數 + 3 + 10 * i & ":H" & 土地行數 + 5 + 10 * 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
            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
            myExcel.Range("Q" & 土地行數 + 3 + 10 * i & ":Q" & 土地行數 + 5 + 10 * 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
            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
            myExcel.Range("R" & 土地行數 + 3 + 10 * i & ":R" & 土地行數 + 5 + 10 * 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
            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
            myExcel.Range("G" & 土地行數 + 6 + 10 * i & ":G" & 土地行數 + 7 + 10 * i).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
            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
            myExcel.Range("H" & 土地行數 + 6 + 10 * i & ":H" & 土地行數 + 7 + 10 * i).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
            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
            myExcel.Range("Q" & 土地行數 + 6 + 10 * i & ":Q" & 土地行數 + 7 + 10 * i).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
            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
            myExcel.Range("R" & 土地行數 + 6 + 10 * i & ":R" & 土地行數 + 7 + 10 * i).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
            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
            For j = 2 To 5
                myExcel.Range("I" & 土地行數 + j + 10 * i & ":K" & 土地行數 + j + 10 * 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
                Dim si As Integer = 0 : If j = 2 Or j = 4 Then : si = 14 : Else : si = 10 : End If
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("S" & 土地行數 + j + 10 * i & ":T" & 土地行數 + j + 10 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
            Next
            myExcel.Range("I" & 土地行數 + 6 + 10 * i & ":K" & 土地行數 + 7 + 10 * 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
            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
            myExcel.Range("S" & 土地行數 + 6 + 10 * i & ":T" & 土地行數 + 7 + 10 * 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
            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
            For j = 8 To 9
                Dim si As Integer = 0 : If j = 8 Then : si = 14 : Else : si = 10 : End If
                myExcel.Range("I" & 土地行數 + j + 10 * i & ":K" & 土地行數 + j + 10 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("S" & 土地行數 + j + 10 * i & ":T" & 土地行數 + j + 10 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
            Next
        Next
        For i = 0 To 建物區塊 - 1
            myExcel.Range("B" & 建物開始行數 + 27 * i & ":T" & 建物開始行數 + 27 * 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
            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 : .Bold = True
            End With
            myExcel.Range("B" & 建物開始行數 + 1 + 27 * i & ":F" & 建物開始行數 + 1 + 27 * 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
            myExcel.Range("B" & 建物開始行數 + 2 + 27 * i & ":F" & 建物開始行數 + 2 + 27 * 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
            myExcel.Range("G" & 建物開始行數 + 1 + 27 * i & ":H" & 建物開始行數 + 2 + 27 * 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
            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 : .Bold = True
            End With
            myExcel.Range("I" & 建物開始行數 + 1 + 27 * i & ":K" & 建物開始行數 + 2 + 27 * 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
            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 : .Bold = True
            End With
            myExcel.Range("L" & 建物開始行數 + 1 + 27 * i & ":O" & 建物開始行數 + 2 + 27 * 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
            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 : .Bold = True
            End With
            myExcel.Range("P" & 建物開始行數 + 1 + 27 * i & ":R" & 建物開始行數 + 2 + 27 * 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
            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 : .Bold = True
            End With
            myExcel.Range("S" & 建物開始行數 + 1 + 27 * i & ":T" & 建物開始行數 + 2 + 27 * 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
            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 : .Bold = True
            End With
            For j = 3 To 5
                myExcel.Range("B" & 建物開始行數 + j + 27 * i & ":F" & 建物開始行數 + j + 27 * 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
            myExcel.Range("B" & 建物開始行數 + 6 + 27 * i & ":B" & 建物開始行數 + 14 + 27 * i).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
            For j = 6 To 8
                myExcel.Range("C" & 建物開始行數 + j + 27 * i & ":F" & 建物開始行數 + j + 27 * 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
            myExcel.Range("C" & 建物開始行數 + 9 + 27 * i & ":F" & 建物開始行數 + 13 + 27 * 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
            myExcel.Range("C" & 建物開始行數 + 14 + 27 * i & ":F" & 建物開始行數 + 14 + 27 * 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
            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
            myExcel.Range("B" & 建物開始行數 + 15 + 27 * i & ":B" & 建物開始行數 + 21 + 27 * i).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
            myExcel.Range("C" & 建物開始行數 + 15 + 27 * i & ":D" & 建物開始行數 + 16 + 27 * 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
            myExcel.Range("E" & 建物開始行數 + 15 + 27 * i & ":F" & 建物開始行數 + 15 + 27 * 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
            myExcel.Range("E" & 建物開始行數 + 16 + 27 * i & ":F" & 建物開始行數 + 16 + 27 * 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
            For j = 17 To 26
                If j <= 21 Then
                    myExcel.Range("C" & 建物開始行數 + j + 27 * i & ":F" & 建物開始行數 + j + 27 * i).Select()
                Else
                    myExcel.Range("B" & 建物開始行數 + j + 27 * i & ":F" & 建物開始行數 + j + 27 * i).Select()
                End If
                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
            For j = 3 To 26
                Dim si As Integer = 0 : If j = 22 Then : si = 14 : ElseIf j = 13 Or j = 9 Or j = 10 Or j = 11 Or j = 12 Then : si = 8 : Else : si = 12 : End If
                myExcel.Range("G" & 建物開始行數 + j + 27 * i & ":H" & 建物開始行數 + j + 27 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("I" & 建物開始行數 + j + 27 * i & ":K" & 建物開始行數 + j + 27 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("L" & 建物開始行數 + j + 27 * i & ":O" & 建物開始行數 + j + 27 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("P" & 建物開始行數 + j + 27 * i & ":R" & 建物開始行數 + j + 27 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
                myExcel.Range("S" & 建物開始行數 + j + 27 * i & ":T" & 建物開始行數 + j + 27 * 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
                With myExcel.Selection.Font
                    .Name = "標楷體" : .Size = si : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
                    .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
                End With
            Next
        Next
        For i = 0 To 太陽能使用區塊 - 1
            myExcel.Range("B" & 太陽能開始行數 + 8 * i & ":T" & 太陽能開始行數 + 8 * 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
            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 : .Bold = True
            End With
            For j = 1 To 7
                myExcel.Range("B" & 太陽能開始行數 + j + 8 * i & ":D" & 太陽能開始行數 + j + 8 * 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
            myExcel.Range("E" & 太陽能開始行數 + 1 + 8 * i & ":T" & 太陽能開始行數 + 1 + 8 * 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
            For j = 2 To 3
                myExcel.Range("E" & 太陽能開始行數 + j + 8 * i & ":J" & 太陽能開始行數 + j + 8 * 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
                myExcel.Range("L" & 太陽能開始行數 + j + 8 * i & ":T" & 太陽能開始行數 + j + 8 * 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
            For j = 4 To 7
                myExcel.Range("E" & 太陽能開始行數 + j + 8 * i & ":T" & 太陽能開始行數 + j + 8 * 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
        Next
        myExcel.Columns("B:B").ColumnWidth = 4 : myExcel.Columns("C:C").ColumnWidth = 8 : myExcel.Columns("D:D").ColumnWidth = 8 : myExcel.Columns("E:E").ColumnWidth = 8
        myExcel.Columns("F:F").ColumnWidth = 8 : myExcel.Columns("G:G").ColumnWidth = 14 : myExcel.Columns("H:H").ColumnWidth = 14 : myExcel.Columns("I:I").ColumnWidth = 4
        myExcel.Columns("J:J").ColumnWidth = 14 : myExcel.Columns("K:K").ColumnWidth = 14 : myExcel.Columns("L:L").ColumnWidth = 4 : myExcel.Columns("M:M").ColumnWidth = 8
        myExcel.Columns("N:N").ColumnWidth = 8 : myExcel.Columns("O:O").ColumnWidth = 8 : myExcel.Columns("P:P").ColumnWidth = 8 : myExcel.Columns("Q:Q").ColumnWidth = 14
        myExcel.Columns("R:R").ColumnWidth = 14 : myExcel.Columns("S:S").ColumnWidth = 14 : myExcel.Columns("T:T").ColumnWidth = 15.13
        myExcel.Columns("A:A").ColumnWidth = 0.54
        myExcel.Range("B2:T" & 太陽能開始行數 - 1 + 8 * 太陽能使用區塊).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

        myExcel.Range("B8:T8").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 = xlDouble : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThick : 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
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        myExcel.Rows("2:" & 太陽能開始行數 + 8 * 太陽能使用區塊).Select : myExcel.Selection.RowHeight = 30
        For i = 0 To 建物區塊 - 1
            myExcel.Rows(建物開始行數 + 1 + 27 * i & ":" & 建物開始行數 + 2 + 27 * i).RowHeight = 19.5
            myExcel.Range("B" & 建物開始行數 + 1 + 27 * i & ":T" & 建物開始行數 + 2 + 27 * i).Select()
            With myExcel.Selection.Interior
                .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314
                .PatternTintAndShade = 0
            End With
        Next
        For i = 0 To 太陽能使用區塊 - 1
            myExcel.Range("B" & 太陽能開始行數 + 8 * i & ":T" & 太陽能開始行數 + 8 * i).Select()
            With myExcel.Selection.Interior
                .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314
                .PatternTintAndShade = 0
            End With
        Next
        myExcel.Range("B2:T3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        myExcel.Range("B2:T3").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


        myExcel.Columns("A:A").ColumnWidth = 0.54
        myExcel.Rows("1:1").RowHeight = 3.75
        '====列印======
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = ""
            .PaperSize = XlPaperSize.xlPaperA4
        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.75)
            .BottomMargin = myExcel.Application.InchesToPoints(0.75)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
            .FooterMargin = myExcel.Application.InchesToPoints(0.3)
            .PrintHeadings = False
            .PrintGridlines = False
            ' .PrintQuality = 600
            .CenterHorizontally = False
            .CenterVertically = False
            .Draft = False
            .FirstPageNumber = xlAutomatic
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = False
            .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
    End Sub

    Private Sub 列印1_bt_Click(sender As Object, e As EventArgs) Handles 列印1_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 租賃條件存檔_bt_Click(sender As Object, e As EventArgs) Handles 租賃條件存檔_bt.Click
        If 土地編號_tb.Text <> "" And 流水號_tb.Text <> "" Then
            SQL_案件土地_租賃條件清單(流水號_tb.Text, 土地編號_tb.Text)
            If dr.Read() Then
                Dim 租賃條件1時間 As String = 租賃條件1開始_dtp.Text & " - " & 租賃條件1結束_dtp.Text, 租賃條件2時間 As String = 租賃條件2開始_dtp.Text & " - " & 租賃條件2結束_dtp.Text,
                    租賃條件3時間 As String = 租賃條件3開始_dtp.Text & " - " & 租賃條件3結束_dtp.Text, 租賃條件4時間 As String = 租賃條件4開始_dtp.Text & " - " & 租賃條件4結束_dtp.Text,
                    租賃條件5時間 As String = 租賃條件5開始_dtp.Text & " - " & 租賃條件5結束_dtp.Text, 租賃條件6時間 As String = 租賃條件6開始_dtp.Text & " - " & 租賃條件6結束_dtp.Text,
                    租賃條件7時間 As String = 租賃條件7開始_dtp.Text & " - " & 租賃條件7結束_dtp.Text, 租賃條件1金額 As String = 土地租金1_nud.Value.ToString,
                    租賃條件2金額 As String = 土地租金2_nud.Value.ToString, 租賃條件3金額 As String = 土地租金3_nud.Value.ToString,
                    租賃條件4金額 As String = 土地租金4_nud.Value.ToString, 租賃條件5金額 As String = 土地租金5_nud.Value.ToString,
                    租賃條件6金額 As String = 土地租金6_nud.Value.ToString, 租賃條件7金額 As String = 土地租金7_nud.Value.ToString
                SQL_案件土地_租賃條件_修改(流水號_tb.Text, 土地編號_tb.Text, dr("流水號"), 租賃條件1時間, 租賃條件2時間, 租賃條件3時間, 租賃條件4時間, 租賃條件5時間,
                            租賃條件6時間, 租賃條件7時間, 租賃條件1金額, 租賃條件2金額, 租賃條件3金額, 租賃條件4金額, 租賃條件5金額, 租賃條件6金額, 租賃條件7金額)
            Else
                Dim 流水號 As String : SQL_案件土地_租賃條件_讀取最後一筆流水號()
                If dr.Read() Then : 流水號 = dr(0).ToString : Else
                    流水號 = "YTJ-" & Date.Now.Year.ToString.PadLeft(4, "0") & Date.Now.Month.ToString.PadLeft(2, "0") & Date.Now.Day.ToString.PadLeft(2, "0") & "-00000"
                End If
                Dim 新流水 As Integer = Integer.Parse(流水號.Substring(流水號.Length - 5)) : 新流水 += 1
                流水號 = "YTJ-" & Date.Now.Year.ToString.PadLeft(4, "0") & Date.Now.Month.ToString.PadLeft(2, "0") & Date.Now.Day.ToString.PadLeft(2, "0") & 新流水.ToString.PadLeft(5, "0")
                Dim 租賃條件1時間 As String = 租賃條件1開始_dtp.Text & " - " & 租賃條件1結束_dtp.Text, 租賃條件2時間 As String = 租賃條件2開始_dtp.Text & " - " & 租賃條件2結束_dtp.Text,
                    租賃條件3時間 As String = 租賃條件3開始_dtp.Text & " - " & 租賃條件3結束_dtp.Text, 租賃條件4時間 As String = 租賃條件4開始_dtp.Text & " - " & 租賃條件4結束_dtp.Text,
                    租賃條件5時間 As String = 租賃條件5開始_dtp.Text & " - " & 租賃條件5結束_dtp.Text, 租賃條件6時間 As String = 租賃條件6開始_dtp.Text & " - " & 租賃條件6結束_dtp.Text,
                    租賃條件7時間 As String = 租賃條件7開始_dtp.Text & " - " & 租賃條件7結束_dtp.Text, 租賃條件1金額 As String = 土地租金1_nud.Value.ToString,
                    租賃條件2金額 As String = 土地租金2_nud.Value.ToString, 租賃條件3金額 As String = 土地租金3_nud.Value.ToString,
                    租賃條件4金額 As String = 土地租金4_nud.Value.ToString, 租賃條件5金額 As String = 土地租金5_nud.Value.ToString,
                    租賃條件6金額 As String = 土地租金6_nud.Value.ToString, 租賃條件7金額 As String = 土地租金7_nud.Value.ToString
                SQL_案件土地_租賃條件_新增(流水號_tb.Text, 土地編號_tb.Text, 流水號, 租賃條件1時間, 租賃條件2時間, 租賃條件3時間, 租賃條件4時間, 租賃條件5時間,
                            租賃條件6時間, 租賃條件7時間, 租賃條件1金額, 租賃條件2金額, 租賃條件3金額, 租賃條件4金額, 租賃條件5金額, 租賃條件6金額, 租賃條件7金額)
            End If : MsgBox("存檔完成!")
        End If
    End Sub
    Private Sub 建物存檔_bt_Click(sender As Object, e As EventArgs) Handles 建物存檔_bt.Click
        If 建坪編號_tb.Text <> "" And 流水號_tb.Text <> "" Then
            SQL_案件建坪_修改(高度_tb.Text, 滴水高度_tb.Text, 屋面方向_tb.Text, 建照號碼_tb.Text, 用途_cb.Text, 使用執照號碼_tb.Text, 門牌_tb.Text, 建號_tb.Text,
                        簽約日_dtp.Text, 其他約定事項_tb.Text, 面積土地_tb.Text, 面積建物_tb.Text, 流水號_tb.Text, 建坪編號_tb.Text)
            MsgBox("存檔完成!")
        End If
    End Sub
    Private Sub 區塊_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 區塊_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 區塊_dgv點擊(e.RowIndex) : End If
    End Sub
    Private Sub 區塊_dgv點擊(DGVX As Integer)
        SQL_案件類別() : 用途_cb.Items.Clear() : 用途_cb.Items.Add("") : While (dr.Read()) : 用途_cb.Items.Add(dr("使用用途")) : End While : conn.Close()
        其他約定事項_tb.Text = 區塊_dgv.Rows(DGVX).Cells("其他約定事項").Value.ToString
        面積土地_tb.Text = 區塊_dgv.Rows(DGVX).Cells("面積土地").Value.ToString : 面積建物_tb.Text = 區塊_dgv.Rows(DGVX).Cells("面積建物").Value.ToString
        高度_tb.Text = 區塊_dgv.Rows(DGVX).Cells("高度").Value.ToString : 滴水高度_tb.Text = 區塊_dgv.Rows(DGVX).Cells("滴水高度").Value.ToString
        屋面方向_tb.Text = 區塊_dgv.Rows(DGVX).Cells("屋面方向").Value.ToString : 建照號碼_tb.Text = 區塊_dgv.Rows(DGVX).Cells("建照號碼").Value.ToString
        使用執照號碼_tb.Text = 區塊_dgv.Rows(DGVX).Cells("使用執照號碼").Value.ToString : 用途_cb.Text = 區塊_dgv.Rows(DGVX).Cells("使用用途").Value.ToString
        門牌_tb.Text = 區塊_dgv.Rows(DGVX).Cells("門牌").Value.ToString : 建號_tb.Text = 區塊_dgv.Rows(DGVX).Cells("建號").Value.ToString

        If 區塊_dgv.Rows(DGVX).Cells("簽約日").Value.ToString = "" Then : 簽約日_dtp.CustomFormat = " " : Else
            If 區塊_dgv.Rows(DGVX).Cells("簽約日").Value.ToString = " " Then : 簽約日_dtp.CustomFormat = " " : Else
                簽約日_dtp.CustomFormat = "yyyy/MM/dd" : 簽約日_dtp.Value = 區塊_dgv.Rows(DGVX).Cells("簽約日").Value.ToString
            End If
        End If
    End Sub
    Private Sub 地址_tb_TextChanged(sender As Object, e As EventArgs) Handles 地址_tb.TextChanged
        地址1_tb.Text = 地址_tb.Text : 地址2_tb.Text = 地址_tb.Text : 地址3_tb.Text = 地址_tb.Text
    End Sub
    Private Sub 鄰近地址_tb_TextChanged(sender As Object, e As EventArgs) Handles 鄰近地址_tb.TextChanged
        鄰近地址1_tb.Text = 鄰近地址_tb.Text : 鄰近地址2_tb.Text = 鄰近地址_tb.Text : 鄰近地址3_tb.Text = 鄰近地址_tb.Text
    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