Public Class 客戶資料轉移
    Dim 批改行數 As Integer = -1, 批改行數2 As Integer = -1
    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_客戶清單()
        da.Fill(ds1) : 客戶清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        客戶清單_dgv.Columns(0).Visible = False : 客戶清單_dgv.Columns(1).ReadOnly = True : 客戶清單_dgv.Columns(2).ReadOnly = True
        客戶清單_dgv.Columns(2).FillWeight = 50
    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_客戶清單()
        da.Fill(ds1) : 客戶清單比較_dgv.DataSource = ds1.Tables(0) : conn.Close()
        客戶清單比較_dgv.Columns(0).Visible = False : 客戶清單比較_dgv.Columns(1).ReadOnly = True : 客戶清單比較_dgv.Columns(2).ReadOnly = True
        客戶清單比較_dgv.Columns(2).FillWeight = 50
    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_員工清單()
        da.Fill(ds1) : 員工名稱_dgv.DataSource = ds1.Tables(0) : conn.Close()
        員工名稱_dgv.Columns(0).ReadOnly = True
    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_摘要表清單()
        da.Fill(ds1) : 摘要表清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        摘要表清單_dgv.Columns(0).Visible = False : 摘要表清單_dgv.Columns(1).ReadOnly = True : 摘要表清單_dgv.Columns(2).ReadOnly = True
        摘要表清單_dgv.Columns(3).ReadOnly = True
        摘要表清單_dgv.Columns(2).FillWeight = 50 : 摘要表清單_dgv.Columns(3).FillWeight = 50
    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_摘要表清單()
        da.Fill(ds1) : 摘要表比較_dgv.DataSource = ds1.Tables(0) : conn.Close()
        摘要表比較_dgv.Columns(0).Visible = False : 摘要表比較_dgv.Columns(1).ReadOnly = True : 摘要表比較_dgv.Columns(2).ReadOnly = True
        摘要表比較_dgv.Columns(3).ReadOnly = True
        摘要表比較_dgv.Columns(2).FillWeight = 50 : 摘要表比較_dgv.Columns(3).FillWeight = 50
    End Sub
    Private Sub Set_員工清單2()
        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
        SQL_員工清單()
        da.Fill(ds1) : 員工名稱2_dgv.DataSource = ds1.Tables(0) : conn.Close()
        員工名稱2_dgv.Columns(0).ReadOnly = True
    End Sub
    Private Sub 客戶資料轉移_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Set_客戶名稱清單() : Set_客戶名稱比較清單() : Set_員工清單() : Set_摘要表清單() : Set_摘要表比較清單() : Set_員工清單2()
    End Sub
    Private Sub 客戶清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 客戶清單_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 客戶清單_dgv.Rows.Count - 1 Then
            Exit Sub
        Else
            If 客戶清單_dgv("製表人", e.RowIndex).Value.ToString <> 客戶清單_dgv("製表人", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(客戶清單_dgv.RowHeadersVisible, 客戶清單_dgv.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 客戶清單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 客戶清單_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
    End Sub
    Private Sub 摘要表清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 摘要表清單_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 摘要表清單_dgv.Rows.Count - 1 Then
            Exit Sub
        Else
            If 摘要表清單_dgv("製表人", e.RowIndex).Value.ToString <> 摘要表清單_dgv("製表人", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(摘要表清單_dgv.RowHeadersVisible, 摘要表清單_dgv.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 摘要表清單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 摘要表清單_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
    End Sub
    Private Sub 客戶清單_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 客戶清單_dgv.CellClick
        If e.RowIndex = -1 Then : 批改行數 = -1 : Else
            If 批改_ch.Checked Then
                批改行數 = e.RowIndex
            Else
                流水號_tb.Text = 客戶清單_dgv.Rows(e.RowIndex).Cells("流水號").Value.ToString : 客戶名稱_tb.Text = 客戶清單_dgv.Rows(e.RowIndex).Cells("客戶名稱").Value.ToString
                舊員工_tb.Text = 客戶清單_dgv.Rows(e.RowIndex).Cells("製表人").Value.ToString
            End If
        End If
    End Sub
    Private Sub 員工名稱_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 員工名稱_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 批改_ch.Checked And 批改行數 >= 0 Then
                客戶清單_dgv.Rows(批改行數).Cells("製表人").Value = 員工名稱_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString
            Else
                新員工_tb.Text = 員工名稱_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString
            End If
        End If
    End Sub
    Private Sub 批量修改存檔_bt_Click(sender As Object, e As EventArgs) Handles 批量修改存檔_bt.Click
        For i As Integer = 0 To 客戶清單_dgv.Rows.Count - 1
            If 客戶清單_dgv.Rows(i).Cells("製表人").Value.ToString <> 客戶清單比較_dgv.Rows(i).Cells("製表人").Value.ToString Then
                Dim 新員工 As String = 客戶清單_dgv.Rows(i).Cells("製表人").Value.ToString : Dim 流水號 As String = 客戶清單_dgv.Rows(i).Cells("流水號").Value.ToString
                Dim 客戶名稱 As String = 客戶清單_dgv.Rows(i).Cells("客戶名稱").Value.ToString
                SQL_客戶清單_更新(新員工, 流水號, 客戶名稱)
            End If
        Next
        MsgBox("存檔完成") : 批改行數 = -1 : Set_客戶名稱清單() : Set_客戶名稱比較清單()
    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)
            MsgBox("轉移完成") : 新員工_tb.Text = "" : 流水號_tb.Text = "" : 客戶名稱_tb.Text = "" : 舊員工_tb.Text = "" : Set_客戶名稱清單() : Set_客戶名稱比較清單()
        Else
            MsgBox("請先選擇資料")
        End If
    End Sub
    Private Sub 員工名稱2_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 員工名稱2_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 批改2_ch.Checked And 批改行數2 >= 0 Then
                摘要表清單_dgv.Rows(批改行數2).Cells("製表人").Value = 員工名稱2_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString
            Else
                新員工2_tb.Text = 員工名稱2_dgv.Rows(e.RowIndex).Cells("姓名").Value.ToString
            End If
        End If
    End Sub
    Private Sub 批量修改存檔2_bt_Click(sender As Object, e As EventArgs) Handles 批量修改存檔2_bt.Click
        For i As Integer = 0 To 摘要表清單_dgv.Rows.Count - 1
            If 摘要表清單_dgv.Rows(i).Cells("製表人").Value.ToString <> 摘要表比較_dgv.Rows(i).Cells("製表人").Value.ToString Then
                Dim 新員工 As String = 摘要表清單_dgv.Rows(i).Cells("製表人").Value.ToString : Dim 單據編號 As String = 摘要表清單_dgv.Rows(i).Cells("單據編號").Value.ToString
                Dim 地主 As String = 摘要表清單_dgv.Rows(i).Cells("地主").Value.ToString : Dim 地址地號 As String = 摘要表清單_dgv.Rows(i).Cells("地址/地號").Value.ToString
                SQL_摘要表清單_更新(新員工, 單據編號, 地主, 地址地號)
            End If
        Next
        MsgBox("存檔完成") : 批改行數 = -1 : Set_摘要表清單() : Set_摘要表比較清單()
    End Sub
    Private Sub 轉移2_bt_Click(sender As Object, e As EventArgs) Handles 轉移2_bt.Click
        If 單據編號_tb.Text <> "" And 新員工2_tb.Text <> "" Then
            SQL_摘要表清單_更新(新員工2_tb.Text, 單據編號_tb.Text, 地主_tb.Text, 地址地號_tb.Text)
            MsgBox("轉移完成") : 新員工_tb.Text = "" : 單據編號_tb.Text = "" : 地主_tb.Text = "" : 地址地號_tb.Text = "" : 舊員工_tb.Text = "" : Set_摘要表清單() : Set_摘要表比較清單()
        Else
            MsgBox("請先選擇資料")
        End If
    End Sub
    Private Sub 摘要表清單_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 摘要表清單_dgv.CellClick
        If e.RowIndex = -1 Then : 批改行數2 = -1 : Else
            If 批改2_ch.Checked Then
                批改行數2 = e.RowIndex
            Else
                單據編號_tb.Text = 摘要表清單_dgv.Rows(e.RowIndex).Cells("單據編號").Value.ToString : 地址地號_tb.Text = 摘要表清單_dgv.Rows(e.RowIndex).Cells("地址/地號").Value.ToString
                地主_tb.Text = 摘要表清單_dgv.Rows(e.RowIndex).Cells("地主").Value.ToString : 舊員工2_tb.Text = 摘要表清單_dgv.Rows(e.RowIndex).Cells("製表人").Value.ToString
            End If
        End If
    End Sub
    Private Sub 查詢1_tb_TextChanged(sender As Object, e As EventArgs) Handles 查詢1_tb.TextChanged
        查詢DGV中的關鍵字(客戶清單_dgv, 查詢1_tb)
    End Sub
    Private Sub 查詢2_tb_TextChanged(sender As Object, e As EventArgs) Handles 查詢2_tb.TextChanged
        查詢DGV中的關鍵字(摘要表清單_dgv, 查詢2_tb)
    End Sub
    Private Sub 比對關鍵字1_bt_Click(sender As Object, e As EventArgs) Handles 比對關鍵字1_bt.Click
        查詢DGV中的關鍵字(客戶清單_dgv, 查詢1_tb)
    End Sub
    Private Sub 比對關鍵字2_bt_Click(sender As Object, e As EventArgs) Handles 比對關鍵字2_bt.Click
        查詢DGV中的關鍵字(摘要表清單_dgv, 查詢2_tb)
    End Sub
End Class