?? frmuser.vb
字號:
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 24)
Me.Label1.TabIndex = 14
Me.Label1.Text = "密 碼:"
'
'txtID
'
Me.txtID.Location = New System.Drawing.Point(119, 28)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(177, 26)
Me.txtID.TabIndex = 0
Me.txtID.Text = ""
'
'frmUser
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btnExt
Me.ClientSize = New System.Drawing.Size(680, 480)
Me.Controls.Add(Me.dgdUser)
Me.Controls.Add(Me.btnDel)
Me.Controls.Add(Me.grbUser)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.btnExt)
Me.Controls.Add(Me.btnSav)
Me.Controls.Add(Me.btnEdt)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "frmUser"
Me.Text = "用戶管理"
CType(Me.dgdUser, System.ComponentModel.ISupportInitialize).EndInit()
Me.grbUser.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
'標(biāo)志變量,用于標(biāo)志是對增加進行保存還是對編輯進行保存
Dim SavAsAdd As Boolean
Dim odb As New DB.DB
Dim sqlSel As String
Private Sub frmUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlSel = "select id as 用戶帳號,pwd as 用戶密碼,role as 用戶權(quán)限 from users"
Me.WindowState = FormWindowState.Maximized
Dim m, n As Integer
m = Me.Height
n = Me.Width
Me.WindowState = FormWindowState.Normal
Me.Width = n
Me.Height = m - 25
Me.Top = 0
Me.Left = 0
dgdUser.Left = 0
dgdUser.Top = 25
dgdUser.Width = Me.Width
dgdUser.Height = 2 * Me.Height / 5
dgdUser.RowHeaderWidth = 5
dgdUser.PreferredColumnWidth = (Me.Width - 10) / 3
grbUser.Left = 20
grbUser.Top = dgdUser.Height + 50
grbUser.Width = Me.Width - 40
grbUser.Height = 2 * Me.Height / 5
btnAdd.Left = 250
btnAdd.Top = dgdUser.Height + grbUser.Height + 70
btnAdd.Height = 40
btnAdd.Width = 80
btnDel.Left = 350
btnDel.Top = dgdUser.Height + grbUser.Height + 70
btnDel.Height = 40
btnDel.Width = 80
btnEdt.Left = 450
btnEdt.Top = dgdUser.Height + grbUser.Height + 70
btnEdt.Height = 40
btnEdt.Width = 80
btnSav.Left = 550
btnSav.Top = dgdUser.Height + grbUser.Height + 70
btnSav.Height = 40
btnSav.Width = 80
btnExt.Left = 650
btnExt.Top = dgdUser.Height + grbUser.Height + 70
btnExt.Height = 40
btnExt.Width = 80
dgdUser.DataSource = odb.CreateDataTable(sqlSel)
FreshFrm(0)
End Sub
Private Sub FreshFrm(ByVal n As Integer)
btnAdd.Enabled = True
btnSav.Enabled = False
txtID.ReadOnly = True
txtPwd.ReadOnly = True
cmbRole.Enabled = False
btnDel.Enabled = True
btnEdt.Enabled = True
txtID.Text = dgdUser.Item(n, 0)
txtPwd.Text = dgdUser.Item(n, 1)
cmbRole.Text = IIf(dgdUser.Item(n, 2) = "admi", "管理人員", "標(biāo)準(zhǔn)用戶")
End Sub
Private Sub btnExt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExt.Click
Me.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
txtID.ReadOnly = False
txtID.Text = ""
txtPwd.ReadOnly = False
txtPwd.Text = ""
cmbRole.Enabled = True
cmbRole.Text = "標(biāo)準(zhǔn)用戶"
btnAdd.Enabled = False
btnDel.Enabled = False
btnEdt.Enabled = False
btnSav.Enabled = True
SavAsAdd = True
End Sub
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If MsgBox("刪除的記錄不能恢復(fù),確定要刪除么?", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
' 請用戶確認(rèn)是否刪除,如果用戶選擇Yes,則接著向下處理;否則,不進行任何操作
Try
Dim strDel As String = "delete from users where ID = '" & Trim(txtID.Text) & "'"
odb.UpdateDataBase(strDel)
dgdUser.DataSource = odb.CreateDataTable(sqlSel)
MsgBox("刪除成功!", MsgBoxStyle.Information)
Catch mm As Exception
MsgBox(mm.Message)
Exit Sub
End Try
End If
FreshFrm(0)
End Sub
Private Sub btnEdt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdt.Click
txtPwd.ReadOnly = False
cmbRole.Enabled = True
btnAdd.Enabled = False
btnDel.Enabled = False
btnEdt.Enabled = False
btnSav.Enabled = True
SavAsAdd = False
End Sub
Private Sub btnSav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSav.Click
If SavAsAdd = True Then '''''''''''''''''''''對增加進行保存
If txtID.Text = "" Then
MsgBox("用戶帳號是需要要輸入的!", MsgBoxStyle.Exclamation)
txtID.Focus()
Exit Sub
Else
If txtPwd.Text = "" Then
MsgBox("用戶密碼是需要要輸入的!", MsgBoxStyle.Exclamation)
txtPwd.Focus()
Exit Sub
Else
' 輸入檢測無誤后可以提交數(shù)據(jù)
Try
Dim strSql = "insert into Users " & _
"values ('" & Trim(txtID.Text) & "','" & Trim(txtPwd.Text) & "','" _
& IIf(cmbRole.Text = "管理人員", "admi", "user") & "')"
' 按照順序?qū)⒂脩糨斎氲臄?shù)據(jù)插入到相應(yīng)的字段中
odb.UpdateDataBase(strsql)
dgdUser.DataSource = odb.CreateDataTable(sqlSel)
MsgBox("增加操作成功!", MsgBoxStyle.Information)
Catch mm As Exception
' 捕捉異常
MsgBox(mm.Message)
Exit Sub
End Try
End If
End If
Else ''''''''''''''''''''''對編輯進行保存
If txtPwd.Text = "" Then
MsgBox("用戶密碼是需要要輸入的!", MsgBoxStyle.Exclamation)
txtPwd.Focus()
Exit Sub
Else
' 輸入檢測無誤后可以提交數(shù)據(jù)
Try
Dim strSql As String = "update Users set Pwd='" _
& Trim(txtPwd.Text) & "',Role='" & IIf(cmbRole.Text = "管理人員", "admi", "user") _
& "' where ID='" & Trim(txtID.Text) & "'"
' 按照順序?qū)⒂脩糨斎氲臄?shù)據(jù)插入到相應(yīng)的字段中
odb.UpdateDataBase(strsql)
dgdUser.DataSource = odb.CreateDataTable(sqlSel)
MsgBox("編輯操作成功!", MsgBoxStyle.Information)
Catch mm As Exception
' 捕捉異常
MsgBox(mm.Message)
Exit Sub
End Try
End If
End If
FreshFrm(dgdUser.CurrentRowIndex)
End Sub
Private Sub dgdUser_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgdUser.CurrentCellChanged
FreshFrm(dgdUser.CurrentCell.RowNumber)
End Sub
End Class
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -