- VERSION 5.00
- Begin VB.Form AddAdmin
- Caption = "添加"
- ClientHeight = 3135
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 4680
- LinkTopic = "Form1"
- ScaleHeight = 3135
- ScaleWidth = 4680
- StartUpPosition = 3 'Windows Default
- Begin VB.Frame Frame1
- Caption = "添加管理员"
- Height = 2895
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 4455
- Begin VB.CommandButton Command2
- Cancel = -1 'True
- Caption = "取消"
- Height = 495
- Left = 2280
- TabIndex = 6
- Top = 2160
- Width = 1695
- End
- Begin VB.CommandButton Command1
- Caption = "确定"
- Default = -1 'True
- Height = 495
- Left = 240
- TabIndex = 5
- Top = 2160
- Width = 1695
- End
- Begin VB.TextBox Pass
- Appearance = 0 'Flat
- Height = 375
- IMEMode = 3 'DISABLE
- Left = 240
- PasswordChar = "#"
- TabIndex = 4
- Top = 1440
- Width = 3735
- End
- Begin VB.TextBox User
- Appearance = 0 'Flat
- Height = 375
- Left = 240
- TabIndex = 2
- Top = 600
- Width = 3735
- End
- Begin VB.Label Label2
- Caption = "管理员密码"
- Height = 255
- Left = 240
- TabIndex = 3
- Top = 1080
- Width = 1335
- End
- Begin VB.Label Label1
- Caption = "管理员ID"
- Height = 255
- Left = 240
- TabIndex = 1
- Top = 360
- Width = 1215
- End
- End
- End
- Attribute VB_Name = "AddAdmin"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub Command1_Click()
- Dim sql As String
- Dim rs As New ADODB.Recordset
- If User.Text = "" Then '判断管理员ID输入框不为空
- MsgBox "管理员ID不能为空!", vbCritical
- User.SetFocus
- Exit Sub
- End If
- If Pass.Text = "" Then '判断管理员密码输入框不为空
- MsgBox "管理员密码不能为空!", vbCritical
- Pass.SetFocus
- Exit Sub
- End If
- If DbHandle.DbConnection Then '打开数据库连接
- sql = "TBL_ADMIN" '对TBL_ADMIN进行操作
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = "ADMIN_ID='" & User.Text & "'" '选择条件是符合User.Text的管理员记录
- rs.Open sql, DbFinance
- If DbHandle.resultcount(rs) = 1 Then '如果找到一条存在的管理员记录就报错
- MsgBox "管理员ID已经存在!", vbExclamation
- rs.Close
- DbHandle.DbClose
- Exit Sub
- Else '否则新建一条管理员记录完成添加
- rs.Close
- rs.Filter = ""
- rs.Open sql, DbFinance
- rs.AddNew
- rs("ADMIN_ID") = User.Text
- rs("ADMIN_PASSWORD") = Pass.Text
- rs.Update
- rs.Close
- End If
- MsgBox "管理员成功添加!"
- Unload Me
- Else '当数据库连接打不开时候报错
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- End Sub
- Private Sub Command2_Click()
- Me.Hide '取消按钮返回主窗体
- End Sub
- Private Sub Form_Load()
- Me.Left = (Screen.Width - Me.ScaleWidth) / 2 '把窗体定位居中显示
- Me.Top = (Screen.Height - Me.ScaleHeight) / 2
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- On Error Resume Next '窗体关闭时候关闭数据库连接
- DbHandle.DbClose
- End Sub