用vb做了登陆界面和数据库连接,之后要做修改密码,录入数据,怎么在vb种实现,。修改密码???
3个回答
展开全部
参考一下吧:
Public Modify As Boolean
Public OriUser As String
Private Sub Cmd_cancle_Click()
Unload Me
End Sub
Private Sub Cmd_OK_Click()
If Trim(txtUserName) = "" Then
MsgBox "请输入用户名"
txtUserName.SetFocus
Exit Sub
End If
If Trim(TxtPsw) = "" Then
MsgBox "请输入密码"
TxtPsw.SetFocus
Exit Sub
End If
If TxtPsw <> TxtPsw2 Then
MsgBox "密码和确认密码不相同,请重新确认"
TxtPsw2.SetFocus
TxtPsw2.SelLength = Len(TxtPsw2)
Exit Sub
End If
With MyUser
If Modify = False Or OriUser <> Trim(txtUserName) Then
If .In_DB(Trim(txtUserName)) = True Then
MsgBox "用户名已经存在,请重新输入"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName)
Exit Sub
End If
End If
'将用户数据赋值到MyUser对象中
.UserName = MakeStr(txtUserName)
.Pwd = MakeStr(TxtPsw)
Select Case ComboType.Text
Case "系统管理员"
.User_type = 1
Case "普通用户"
.User_type = 2
End Select
'保存用户数据
If Modify = False Then
.Insert
Else
.Update (OriUser)
'如果修改自身用户名,则更新CurUser对象
If OriUser = CurUser.UserName And Trim(txtUserName) <> OriUser Then
CurUser.UserName = Trim(txtUserName)
CurUser.GetInfo (CurUser.UserName)
End If
End If
End With
MsgBox "数据保存成功"
Unload Me
End Sub
Private Sub ComboType_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Cmd_OK_Click
End If
End Sub
Private Sub Form_Load()
txtUserName.Enabled = False
End Sub
Private Sub TxtPsw_KeyPress(KeyAscii As Integer)
EnterTAB (KeyAscii)
End Sub
Private Sub TxtPsw2_KeyPress(KeyAscii As Integer)
EnterTAB (KeyAscii)
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If In_Int(KeyAscii) = False Then
KeyAscii = 0
Else
EnterTAB (KeyAscii)
End If
End Sub
Private Sub txtUserName_LostFocus()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
+ App.Path + "\" + DATABASE + ";"
Adodc1.RecordSource = "select * from sporterinfo "
Adodc1.Refresh
If txtUserName.Text = "" Then
MsgBox "请输入用户名"
Else
Adodc1.Recordset.Find "sid = '" & txtUserName.Text & "'"
End If
If Adodc1.Recordset.EOF Then
MsgBox "该用户尚未报名,不能添加为用户"
txtUserName.SetFocus
End If
End Sub
Public Modify As Boolean
Public OriUser As String
Private Sub Cmd_cancle_Click()
Unload Me
End Sub
Private Sub Cmd_OK_Click()
If Trim(txtUserName) = "" Then
MsgBox "请输入用户名"
txtUserName.SetFocus
Exit Sub
End If
If Trim(TxtPsw) = "" Then
MsgBox "请输入密码"
TxtPsw.SetFocus
Exit Sub
End If
If TxtPsw <> TxtPsw2 Then
MsgBox "密码和确认密码不相同,请重新确认"
TxtPsw2.SetFocus
TxtPsw2.SelLength = Len(TxtPsw2)
Exit Sub
End If
With MyUser
If Modify = False Or OriUser <> Trim(txtUserName) Then
If .In_DB(Trim(txtUserName)) = True Then
MsgBox "用户名已经存在,请重新输入"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName)
Exit Sub
End If
End If
'将用户数据赋值到MyUser对象中
.UserName = MakeStr(txtUserName)
.Pwd = MakeStr(TxtPsw)
Select Case ComboType.Text
Case "系统管理员"
.User_type = 1
Case "普通用户"
.User_type = 2
End Select
'保存用户数据
If Modify = False Then
.Insert
Else
.Update (OriUser)
'如果修改自身用户名,则更新CurUser对象
If OriUser = CurUser.UserName And Trim(txtUserName) <> OriUser Then
CurUser.UserName = Trim(txtUserName)
CurUser.GetInfo (CurUser.UserName)
End If
End If
End With
MsgBox "数据保存成功"
Unload Me
End Sub
Private Sub ComboType_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Cmd_OK_Click
End If
End Sub
Private Sub Form_Load()
txtUserName.Enabled = False
End Sub
Private Sub TxtPsw_KeyPress(KeyAscii As Integer)
EnterTAB (KeyAscii)
End Sub
Private Sub TxtPsw2_KeyPress(KeyAscii As Integer)
EnterTAB (KeyAscii)
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If In_Int(KeyAscii) = False Then
KeyAscii = 0
Else
EnterTAB (KeyAscii)
End If
End Sub
Private Sub txtUserName_LostFocus()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
+ App.Path + "\" + DATABASE + ";"
Adodc1.RecordSource = "select * from sporterinfo "
Adodc1.Refresh
If txtUserName.Text = "" Then
MsgBox "请输入用户名"
Else
Adodc1.Recordset.Find "sid = '" & txtUserName.Text & "'"
End If
If Adodc1.Recordset.EOF Then
MsgBox "该用户尚未报名,不能添加为用户"
txtUserName.SetFocus
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询