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
    Private ReadOnly 對話框(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 Set_語言()
        語言_dgv.DataSource = Nothing
        語言_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        語言_dgv.ColumnHeadersHeight = 25
        語言_dgv.AllowUserToAddRows = False
        For i As Integer = 0 To 語言_dgv.Rows.Count - 1 : 語言_dgv.Rows.RemoveAt(0) : Next
        If File.Exists(Str + "\LANGUAGE_FILE.csv") Then
            Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\LANGUAGE_FILE.csv", System.Text.Encoding.Default)
            Dim line As String = filereader.ReadLine()
            While Not (line Is Nothing)
                line = filereader.ReadLine()
                If line <> Nothing Then
                    line = line.Replace("""", "")
                    If Strings.Left(line, 4) = "G000" Or Strings.Left(line, 4) = 介面 Then
                        If 系統語言 = "繁體中文" Then
                            If Strings.Mid(line, 10, 2) = "CH" Then : 語言_dgv.Rows.Insert(0)
                                語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11)
                                If Strings.Mid(line, 13, 300).EndsWith(",") Then
                                    語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1)
                                Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If
                            End If
                        ElseIf 系統語言 = "English" Then
                            If Strings.Mid(line, 10, 2) = "EN" Then : 語言_dgv.Rows.Insert(0)
                                語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11)
                                If Strings.Mid(line, 13, 300).EndsWith(",") Then
                                    語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1)
                                Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If
                            End If
                        ElseIf 系統語言 = "Indonesian" Then
                            If Strings.Mid(line, 10, 2) = "IN" Then : 語言_dgv.Rows.Insert(0)
                                語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11)
                                If Strings.Mid(line, 13, 300).EndsWith(",") Then
                                    語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1)
                                Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If
                            End If
                        End If
                    End If
                End If
            End While
            filereader.Close()
        End If
    End Sub
    Private Sub Set_語言查詢()
        RI = -1 : For Each row As DataGridViewRow In 語言_dgv.Rows
            If Strings.Left(row.Cells(0).Value.ToString(), 8) = SK Then
                RI = row.Index : Exit For
            End If
        Next
    End Sub
    Private Sub 語言轉換讀取()
        Set_語言()
        SK = "G000-108" : Set_語言查詢() : ToolTip1.ToolTipTitle = 語言_dgv(1, RI).Value.ToString
        SK = "H213-100" : Set_語言查詢() : 主題_lb.Text = 語言_dgv(1, RI).Value.ToString : SK = "H213-101" : Set_語言查詢() : GroupBox1.Text = 語言_dgv(1, RI).Value.ToString
        SK = "H213-102" : Set_語言查詢() : Label1.Text = 語言_dgv(1, RI).Value.ToString : SK = "G000-109" : Set_語言查詢() : 對話框(0) = 語言_dgv(1, RI).Value.ToString
        SK = "G000-111" : Set_語言查詢() : 對話框(1) = 語言_dgv(1, RI).Value.ToString : SK = "G000-112" : Set_語言查詢() : 對話框(2) = 語言_dgv(1, RI).Value.ToString
        SK = "G000-117" : Set_語言查詢() : 對話框(3) = 語言_dgv(1, RI).Value.ToString : SK = "G000-118" : Set_語言查詢() : 對話框(4) = 語言_dgv(1, RI).Value.ToString
        SK = "G000-119" : Set_語言查詢() : 對話框(5) = 語言_dgv(1, RI).Value.ToString : SK = "G000-120" : Set_語言查詢() : 對話框(6) = 語言_dgv(1, RI).Value.ToString
    End Sub
    Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增_bt, 對話框(0))
    End Sub
    Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改_bt, 對話框(1))
    End Sub
    Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除_bt, 對話框(2))
    End Sub
    Private Sub PnlTitleBar_Paint(sender As Object, e As PaintEventArgs) Handles PnlTitleBar.Paint
    End Sub
    Private Sub 供應商類別管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        語言_dgv.SendToBack() : H(213) = True : 介面 = "H213" : 語言轉換讀取() : 顯示說明(999, False) : 清單1()
    End Sub
    Private Sub Cancel_bt_Click(sender As Object, e As EventArgs) Handles Cancel_bt.Click
        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 : MGB(對話框(4), 1)
        清單1()
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If 類別編號_tb.Text = "" Then : MGB(對話框(3), 1) : 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() : MGB(對話框(5), 1)
        End If
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 類別編號_tb.Text = "" Then : MGB(對話框(3), 1) : Else
            PA1 = 類別編號_tb.Text : SQL_供應商類別管理_刪除() : 清單1() : MGB(對話框(6), 1)
        End If
    End Sub
    Private Sub 語轉扭_bt_Click(sender As Object, e As EventArgs) Handles 語轉扭_bt.Click
        介面 = "H213" : 語言轉換讀取() : 清單1()
    End Sub

    Dim nOldWndLeft, nOldWndTop, nClickX, nClickY As Integer
    Private Sub PnlTitleBar_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PnlTitleBar.MouseDown
        '紀錄滑鼠點選時的視窗位置與滑鼠點選位置
        nOldWndLeft = Me.Left : nOldWndTop = Me.Top : nClickX = e.X : nClickY = e.Y
    End Sub
    Private Sub PnlTitleBar_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PnlTitleBar.MouseMove
        If PnlTitleBar.Capture = True Then        '如果滑鼠按著拖曳
            Me.Top = e.Y + nOldWndTop - nClickY : Me.Left = e.X + nOldWndLeft - nClickX   '設定新的視窗位置
            nOldWndLeft = Me.Left : nOldWndTop = Me.Top   '更新紀錄的視窗位置
        End If
    End Sub
    Private Sub 主題_lb_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 主題_lb.MouseDown
        '紀錄滑鼠點選時的視窗位置與滑鼠點選位置
        nOldWndLeft = Me.Left : nOldWndTop = Me.Top : nClickX = e.X : nClickY = e.Y
    End Sub
    Private Sub 主題_lb_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 主題_lb.MouseMove
        If 主題_lb.Capture = True Then        '如果滑鼠按著拖曳
            Me.Top = e.Y + nOldWndTop - nClickY : Me.Left = e.X + nOldWndLeft - nClickX   '設定新的視窗位置
            nOldWndLeft = Me.Left : nOldWndTop = Me.Top   '更新紀錄的視窗位置
        End If
    End Sub
End Class