www.pudn.com > kelon.rar > fUser.frm


VERSION 5.00
Begin VB.Form fUser
Caption = "用户管理 V1.01"
ClientHeight = 2265
ClientLeft = 4740
ClientTop = 3990
ClientWidth = 5550
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "fUser.frx":0000
LinkTopic = "Form1"
ScaleHeight = 2265
ScaleWidth = 5550
Begin VB.CommandButton Com01
Caption = "删除"
Height = 390
Index = 2
Left = 4395
TabIndex = 7
Top = 840
Width = 975
End
Begin VB.CommandButton Com01
Caption = "提交"
Height = 390
Index = 1
Left = 4395
TabIndex = 6
Top = 210
Width = 975
End
Begin VB.CommandButton Com01
Caption = "关闭"
Height = 390
Index = 0
Left = 4395
TabIndex = 8
Top = 1545
Width = 975
End
Begin VB.TextBox Text1
Height = 315
IMEMode = 3 'DISABLE
Index = 3
Left = 1410
PasswordChar = "*"
TabIndex = 5
Text = "Text1"
Top = 1710
Width = 2310
End
Begin VB.TextBox Text1
Height = 315
IMEMode = 3 'DISABLE
Index = 2
Left = 1410
PasswordChar = "*"
TabIndex = 4
Text = "Text1"
Top = 1335
Width = 2310
End
Begin VB.TextBox Text1
Height = 315
Index = 1
Left = 1410
TabIndex = 2
Text = "Text1"
Top = 570
Width = 2310
End
Begin VB.TextBox Text1
Height = 315
Index = 0
Left = 1410
TabIndex = 1
Text = "Text1"
Top = 195
Width = 2310
End
Begin VB.ComboBox Combo1
Height = 330
Left = 1410
TabIndex = 3
Text = "Combo1"
Top = 945
Width = 2340
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "重输密码:"
Height = 210
Index = 4
Left = 285
TabIndex = 12
Top = 1800
Width = 945
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "密码:"
Height = 210
Index = 3
Left = 705
TabIndex = 11
Top = 1413
Width = 525
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "工号:"
Height = 210
Index = 2
Left = 705
TabIndex = 10
Top = 255
Width = 525
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "姓名:"
Height = 210
Index = 1
Left = 705
TabIndex = 9
Top = 641
Width = 525
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "岗位:"
Height = 210
Index = 0
Left = 705
TabIndex = 0
Top = 1027
Width = 525
End
End
Attribute VB_Name = "fUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim nrs As New ADODB.Recordset

Private Sub Com01_Click(Index As Integer)
If Index = 0 Then Unload Me: Exit Sub
If Text1(0).Text = "" Then
MsgBox "工号不能为空.", 32, "提示"
Text1(0).SetFocus: Exit Sub
End If
If Text1(1).Text = "" Then
MsgBox "姓名不能为空.", 32, "提示"
Text1(1).SetFocus: Exit Sub
End If
Select Case Index
Case 1
If Text1(2).Text <> Text1(3).Text Then
Text1(2).Text = "": Text1(3).Text = ""
MsgBox "两次输入的密码不一样, 请核对.", 32, "提示"
Text1(2).SetFocus: Exit Sub
End If
Call SaveUserData
Text1(0).SetFocus
Case 2
Dim rc As Long
If UCase(Text1(1).Text) = "ADMIN" Then
rc = MsgBox("你不能将系统管理员的用户删除. ", 32, "提示")
Exit Sub
End If
rc = MsgBox("确定删除此用户吗?", 33, "提示")
If rc = 1 Then
rc = MsgBox("此用户已被删除. ", 48, "提示")
End If
Call DelUserData
Text1(0).SetFocus
Case 3
Case 4
End Select
End Sub

Private Sub Form_Activate()
Text1(0).SetFocus
End Sub

Private Sub Form_Load()
If App.PrevInstance Then
' MsgBox ("注意:程序已经运行,不能再次装载。"), vbExclamation
End
End If
Call mUser01.GetIniFileName
Call OpenODBC(Cn_Des, "ConnectionString001")

Call ClearText
Call SetCombo1
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then SendKeys "{tab}"
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Cn_Des.Close
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then SendKeys "{tab}"
End Sub

'取出数据库的数据, 如有则填入
Private Sub Text1_LostFocus(Index As Integer)
Select Case Index
Case 0
Call GetUserData(Text1(Index).Text, 0)
Case 1
Call GetUserData(Text1(Index).Text, 1)
End Select
End Sub

'-----------------------
'清除项目
Private Sub ClearText()
Dim i As Long
For i = 0 To 3
Text1(i).Text = ""
Next
End Sub
Private Sub DelUserData()
Dim sSql As String
sSql = mUser01.pGetString(mUser01.localFn, "SQLstr", "delete00")
sSql = Replace(sSql, "@1@", Text1(0).Text) 'ID
sSql = "delete " &amt; sSql
Call Cn_Des.Execute(sSql)
End Sub
'
Private Sub SaveUserData()
Dim sSql As String
Dim nCount As Long
Dim pws As String
Dim msg As String
pws = mUser01.Text2MM(Text1(2).Text + Text1(0).Text)
sSql = mUser01.pGetString(mUser01.localFn, "SQLstr", "Select02")
sSql = Replace(sSql, "@1@", Text1(0).Text)
sSql = "select " + sSql
nrs.Open sSql, Cn_Des, , , adCmdText
If nrs.Fields(0).Value > 0 Then 'update
sSql = mUser01.pGetString(mUser01.localFn, "SQLstr", "update00")
sSql = "update " &amt; sSql
msg = "修改"
Else
sSql = mUser01.pGetString(mUser01.localFn, "SQLstr", "create00")
sSql = "insert " &amt; sSql
msg = "增加"
End If
nrs.Close
sSql = Replace(sSql, "@1@", Text1(0).Text) 'ID
sSql = Replace(sSql, "@2@", Text1(1).Text) 'name
sSql = Replace(sSql, "@3@", Combo1.Text) 'role
sSql = Replace(sSql, "@4@", pws) 'pws
Call Cn_Des.Execute(sSql)
MsgBox "记录已" + msg + ".", 48, "提示"
End Sub
Private Sub GetUserData(ByVal str As String, ByVal Index As Long)
Dim sSql As String
Dim nCount As Long
If str = "" Then Exit Sub
sSql = mUser01.pGetString(mUser01.localFn, "SQLstr", "Select" + Format(Index, "00"))
sSql = "SELECT " &amt; sSql
sSql = Replace(sSql, "@1@", str)

nrs.Open sSql, Cn_Des, , , adCmdText
On Error GoTo err
' If nrs.RecordCount > 0 Then
Text1(0).Text = nrs.Fields(0).Value
Text1(1).Text = nrs.Fields(1).Value
Combo1.Text = nrs.Fields(6).Value
Text1(2).Text = ""
Text1(3).Text = "": Text1(3).Tag = nrs.Fields(2).Value
' End If
err:
On Error GoTo 0
nrs.Close
End Sub
'取下拉项
Private Sub SetCombo1()
Dim i As Long
Dim ss As String
For i = 0 To 20
ss = mUser01.pGetString(mUser01.localFn, "local", "role" + Format(i, "00"))
If ss = "" Then Exit For
Combo1.AddItem ss
If i = 0 Then Combo1.Text = ss
Next
End Sub