Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

系統對應電腦註冊.vb 5.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_DGV1載入前設定()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. DataGridView1.RowTemplate.Height = 35
  15. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  16. End Sub
  17. Private Sub Set_DGV1載入後設定()
  18. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  19. End Sub
  20. Private Sub Set_使用者清單()
  21. Set_DGV1載入前設定()
  22. SQL1 = "SELECT MAC碼, 硬碟ID, 硬碟序列, 磁盘型態 FROM 系統綁定電腦資訊"
  23. Set_DGV1載入後設定()
  24. End Sub
  25. Private Sub Set_grid()
  26. DataGridView1.Columns(0).Width = 325 : DataGridView1.Columns(1).Width = 325 : DataGridView1.Columns(2).Width = 325 : DataGridView1.Columns(3).Width = 325
  27. End Sub
  28. Private Sub 系統測試_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  29. Me.MdiParent = GCM_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  30. Set_使用者清單()
  31. End Sub
  32. Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
  33. timeNow = 0
  34. GCM_ERP_SYS.Timer1.Enabled = False
  35. GCM_ERP_SYS.Timer1.Enabled = True
  36. End Sub
  37. Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
  38. timeNow = 0
  39. GCM_ERP_SYS.Timer1.Enabled = False
  40. GCM_ERP_SYS.Timer1.Enabled = True
  41. End Sub
  42. Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  43. If e.RowIndex = -1 Then : Else
  44. TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells("MAC碼").Value.ToString : TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells("硬碟ID").Value
  45. TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("硬碟序列").Value : TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells("磁盘型態").Value
  46. End If
  47. End Sub
  48. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  49. '-----MAC碼----------------------------------------------------------------------------------------------
  50. Dim Wmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
  51. For Each WmiObj As Management.ManagementObject In Wmi.Get
  52. If CBool(WmiObj("IPEnabled")) Then
  53. TextBox1.Text = WmiObj("MACAddress")
  54. End If
  55. Next
  56. '-----硬碟資料----------------------------------------------------------------------------------------------
  57. Dim cmicWmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
  58. Dim diskId As String '数字ID
  59. Dim diskSerialNumber As String '这个我们暂且称其为序列号码
  60. Dim diskModel As String '序列号
  61. For Each cmicWmiObj As Management.ManagementObject In cmicWmi.Get
  62. diskId = cmicWmiObj("signature")
  63. diskSerialNumber = cmicWmiObj("serialnumber")
  64. diskModel = cmicWmiObj("Model")
  65. TextBox2.Text = diskId
  66. TextBox3.Text = diskSerialNumber
  67. TextBox4.Text = diskModel
  68. Next
  69. End Sub
  70. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  71. conn.Close()
  72. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  73. SQL1 = "SELECT MAC碼 FROM 系統綁定電腦資訊 WHERE MAC碼 LIKE N'" & TextBox1.Text & "' AND 硬碟ID LIKE N'" & TextBox2.Text & "' AND 硬碟序列 LIKE N'" & TextBox3.Text & "' AND
  74. 磁盘型態 LIKE N'" & TextBox4.Text & "'"
  75. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  76. If dr.Read() Then
  77. conn.Close()
  78. MsgBox("該電腦以綁定過")
  79. Else
  80. conn.Close()
  81. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  82. SQL1 = "INSERT INTO 系統綁定電腦資訊 (MAC碼, 硬碟ID, 硬碟序列, 磁盘型態) " &
  83. "VALUES (N'" & TextBox1.Text & "',N'" & TextBox2.Text & "',N'" & TextBox3.Text & "',N'" & TextBox4.Text & "')"
  84. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  85. MsgBox("新增完成") : Set_使用者清單()
  86. End If
  87. End Sub
  88. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  89. SQL1 = "DELETE FROM 系統綁定電腦資訊 WHERE MAC碼 LIKE N'" & TextBox1.Text & "' AND 硬碟ID LIKE N'" & TextBox2.Text & "' AND 硬碟序列 LIKE N'" & TextBox3.Text & "' AND
  90. 磁盘型態 LIKE N'" & TextBox4.Text & "'"
  91. cmd.CommandText = SQL1 : cmd.Connection = conn
  92. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  93. Dim aa As MsgBoxResult
  94. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  95. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  96. conn.Close() : Set_使用者清單()
  97. End Sub
  98. End Class