Option Strict Off
Imports System.IO
Public Class 供應商類別管理
    ReadOnly ds As New DataSet
    Dim RI As Integer = -1
    Dim SK As String = "要查找的 KEY"
    Dim Str As String = Application.StartupPath
    Dim 對話框(8) As String
    Private Sub 清單1()
        類別清單_dgv.DataSource = Nothing : ds.Clear()
        類別清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        類別清單_dgv.ColumnHeadersHeight = 25
        類別清單_dgv.AllowUserToAddRows = False
        類別清單_dgv.RowTemplate.Height = 35

        SQL_供應商類別()
        列印用SQL = SQL1 : da.Fill(ds) : 類別清單_dgv.DataSource = ds.Tables(0)

        類別清單_dgv.Columns(0).FillWeight = 50 : 類別清單_dgv.Columns(1).FillWeight = 50 : 類別清單_dgv.Columns(2).FillWeight = 200
    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 PnlTitleBar_Paint(sender As Object, e As PaintEventArgs)
    End Sub
    Private Sub 供應商類別管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        清單1() : ToolTip1.ToolTipTitle = "系統說明"
    End Sub
    Private Sub Cancel_bt_Click(sender As Object, e As EventArgs)
        Me.Close()
    End Sub
    Private Sub 類別清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 類別清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            類別編號_tb.Text = 類別清單_dgv(0, e.RowIndex).Value.ToString
            For i As Integer = 0 To 類別清單_dgv.Rows.Count - 1
                If 類別清單_dgv(0, i).Value.ToString = 類別編號_tb.Text And 類別清單_dgv(1, i).Value.ToString = A1_lb.Text Then : 類別1_tb.Text = 類別清單_dgv(2, i).Value.ToString
                ElseIf 類別清單_dgv(0, i).Value.ToString = 類別編號_tb.Text And 類別清單_dgv(1, i).Value.ToString = A2_lb.Text Then : 類別2_tb.Text = 類別清單_dgv(2, i).Value.ToString
                ElseIf 類別清單_dgv(0, i).Value.ToString = 類別編號_tb.Text And 類別清單_dgv(1, i).Value.ToString = A3_lb.Text Then : 類別3_tb.Text = 類別清單_dgv(2, i).Value.ToString
                End If
            Next
        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(0, e.RowIndex).Value.ToString <> 類別清單_dgv(0, 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 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        SQL_供應商類別管理_最後一筆資料()
        If dr.Read() Then : 類別編號_tb.Text = dr("編碼").ToString : Else : 類別編號_tb.Text = "N0000" : End If : conn.Close()
        Dim NUM1 As Integer = Double.Parse(Strings.Right(類別編號_tb.Text, 4)) + 1
        If NUM1 < 10 Then : 類別編號_tb.Text = "N" & "000" & NUM1
        ElseIf NUM1 > 9 And NUM1 < 100 Then : 類別編號_tb.Text = "N" & "00" & NUM1
        ElseIf NUM1 > 99 And NUM1 < 1000 Then : 類別編號_tb.Text = "N" & "0" & NUM1
        ElseIf NUM1 > 999 Then : 類別編號_tb.Text = "N" & NUM1 : End If
        For I As Integer = 0 To 2
            PA1 = 類別編號_tb.Text
            If I = 0 Then
                PA2 = A1_lb.Text : PA3 = 類別1_tb.Text : ElseIf I = 1 Then : PA2 = A2_lb.Text : PA3 = 類別2_tb.Text : ElseIf I = 2 Then : PA2 = A3_lb.Text : PA3 = 類別3_tb.Text
            End If : SQL_供應商類別管理_新增()
        Next : MsgBox("新增完成!!")
        清單1()
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If 類別編號_tb.Text = "" Then : MsgBox("沒有選擇資料!!") : Else
            For I As Integer = 0 To 2 : PA1 = 類別編號_tb.Text
                If I = 0 Then : PA2 = A1_lb.Text : PA3 = 類別1_tb.Text
                ElseIf I = 1 Then : PA2 = A2_lb.Text : PA3 = 類別2_tb.Text
                ElseIf I = 2 Then : PA2 = A3_lb.Text : PA3 = 類別3_tb.Text
                End If : SQL_供應商類別管理_修改()
            Next
            清單1() : MsgBox("存檔完成!!")
        End If
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 類別編號_tb.Text = "" Then : MsgBox("沒有選擇資料!!") : Else
            PA1 = 類別編號_tb.Text : SQL_供應商類別管理_刪除() : 清單1() : MsgBox("刪除完成!!")
        End If
    End Sub
    Private Sub 類別1_tb_TextChanged(sender As Object, e As EventArgs) Handles 類別1_tb.TextChanged
        類別3_tb.Text = 類別1_tb.Text : 類別2_tb.Text = 類別1_tb.Text
    End Sub
End Class