Option Strict Off
Imports System.Data.SqlClient
Public Class FTP資料夾管理
    Dim conn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim ds As New DataSet
    Dim dr As SqlDataReader
    Private Sub Set_使用者清單()
        DataGridView1.DataSource = Nothing : ds.Clear()
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView1.ColumnHeadersHeight = 25
        DataGridView1.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 資料夾名稱, 指定頁面, 備註, 指定 FROM FTP資料夾管理"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Width = 70 : DataGridView1.Columns(1).Width = 200 : DataGridView1.Columns(2).Width = 200 : DataGridView1.Columns(3).Width = 70
    End Sub
    Private Sub FTP資料夾管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Set_使用者清單()
        Target1 = Target
        WebBrowser1.Url = New Uri(Target1)
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString : TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString
            TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "INSERT INTO FTP資料夾管理 (資料夾名稱, 指定頁面, 備註, 指定) " &
               "VALUES (N'" & TextBox1.Text & "',N'" & TextBox2.Text & "',N'" & TextBox3.Text & "',N'" & TextBox4.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
        conn.Close()
        Set_使用者清單()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE FTP資料夾管理 SET 指定頁面 = N'" & TextBox2.Text & "', 備註 = N'" & TextBox3.Text & "', 指定 = N'" & TextBox4.Text & "' WHERE (資料夾名稱 = N'" & TextBox1.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
        conn.Close()
        Set_使用者清單()
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        SQL1 = "DELETE FROM FTP資料夾管理 WHERE (資料夾名稱 = N'" & TextBox1.Text & "')"
        cmd.CommandText = SQL1 : cmd.Connection = conn
        If conn.State = ConnectionState.Closed Then : conn.Open() : End If
        Dim aa As MsgBoxResult
        aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
        If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : End If
        conn.Close()
        Set_使用者清單()
    End Sub
End Class