Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

系統使用者管理.vb 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 系統使用者管理
  4. Dim conn As New SqlConnection
  5. Dim da As New SqlDataAdapter
  6. Dim cmd As New SqlCommand
  7. Dim ds As New DataSet
  8. Dim dr As SqlDataReader
  9. Private Sub Set_使用者清單()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  15. SQL1 = "SELECT 姓名, 帳號, 密碼 FROM 使用者"
  16. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  17. Set_grid()
  18. End Sub
  19. Private Sub Set_grid()
  20. DataGridView1.Columns(0).Width = 70 : DataGridView1.Columns(1).Width = 70 : DataGridView1.Columns(2).Width = 70
  21. End Sub
  22. Private Sub 系統使用者管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23. Me.MdiParent = 楠晉鞋業AAS : Me.AutoScroll = True
  24. Button1.Enabled = False
  25. Set_使用者清單()
  26. End Sub
  27. Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  28. TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells("姓名").Value.ToString : TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells("帳號").Value
  29. TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("密碼").Value
  30. End Sub
  31. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  32. TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : Button4.Enabled = False : Button1.Enabled = True
  33. End Sub
  34. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  35. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  36. SQL1 = "INSERT INTO 使用者 (姓名, 帳號, 密碼) " &
  37. "VALUES (N'" & TextBox1.Text & "',N'" & TextBox2.Text & "',N'" & TextBox3.Text & "')"
  38. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  39. MsgBox("新增完成")
  40. Set_使用者清單() : Set_grid() : Button1.Enabled = False : Button4.Enabled = True
  41. End Sub
  42. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  43. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  44. MsgBox("輸入資料有誤")
  45. Else
  46. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  47. SQL1 = "UPDATE 使用者 SET 姓名 = N'" & TextBox1.Text & "', 密碼 = N'" & TextBox3.Text & "' WHERE (帳號 = '" & TextBox2.Text & "')"
  48. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() : conn.Close()
  49. MsgBox("新增完成")
  50. End If
  51. Set_使用者清單() : Set_grid()
  52. End Sub
  53. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  54. SQL1 = "DELETE FROM 使用者 WHERE (帳號 = '" & TextBox2.Text & "')"
  55. cmd.CommandText = SQL1 : cmd.Connection = conn
  56. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  57. Dim aa As MsgBoxResult
  58. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  59. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  60. conn.Close() : conn.Close()
  61. TextBox1.Text = "" : TextBox2.Text = "" : TextBox2.Text = ""
  62. Set_使用者清單() : Set_grid()
  63. End Sub
  64. End Class