Exit Sub End If End If
strSQL = \用户表 where 用户名='\ \密码='\ Set mrs = conn.Execute(strSQL) If mrs.EOF = True Then
MsgBox \密码错误!\用户登陆验证\ try_times = try_times + 1 If try_times >= 3 Then
MsgBox \您已经三次尝试进入本系统,均不成功,系统将关闭!\ vbCritical, \用户登陆验证\ End Else
txtPassword.SetFocus txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text) Exit Sub End If End If
MsgBox \登陆成功!\用户登陆验证\ '保存当前登陆的权限
bolAuthority = mrs.Fields(\权限\ '加载MDI主窗体 MDI.Show '卸载登陆窗体 Unload Me End Sub
Private Sub Form_Load() Call ScreenCenter(Me)
‘调用标准模块中的ScreenCenter过程,将本窗体置于屏幕中心 ‘连接d:\\VB\\CH12\\Mydata.mdb,连接对象为conn。 Dim conns As String
conns = \conn.Open conns End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
'用于在输入完密码后并按回车键后跳到确定命令按钮 If KeyAscii = 13 Then cmdOK.SetFocus End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
'用于在输入完用户名后并按回车键后跳到输入密码文本框 If KeyAscii = 13 Then txtPassword.SetFocus End Sub
41
12.4.3
Private Sub Add_user_Click()
Adduser.Show ‘调入“新建用户”窗体 End Sub
Private Sub ck_Click() crk1.Caption = \出库\
crk1.Show ‘调入“出入库”窗体 End Sub
Private Sub ckhwmx_Click() sqlfind = \出入库\
rs_data1.Open sqlfind, conn, adOpenKeyset, adLockPessimistic hwckmx.Show ‘调入“查看货物明细”窗体 End Sub
Private Sub hwcx_Click()
cxhw.Show ‘调入“查询货物”窗体 End Sub
Private Sub Hz_date_Click() hz_menu = \
hzhw.Show ‘调入“汇总货物”窗体,并按日期汇总 End Sub
Private Sub Hz_hdh_Click() hz_menu = \
hzhw.Show ‘调入“汇总货物”窗体,并按货单号汇总End Sub
Private Sub quit_Click() Unload Me End Sub
Private Sub rk_Click() crk1.Caption = \入库\
crk1.Show ‘调入“出入库”窗体 End Sub
Private Sub Hz_kh_Click() hz_menu = \
hzhw.Show ‘调入“汇总货物”窗体,并按客户汇总 End Sub
42
Private Sub XGMM_Click()
pwsxg.Show ‘调入“修改密码”窗体 End Sub
12.4.4
Private Sub Command1_Click() Dim sql As String
Dim rs_add As New ADODB.Recordset If Trim(Text1.Text) = \
MsgBox \用户名不能为空\ Exit Sub
Text1.SetFocus Else
If Trim(Text2.Text) = \
MsgBox \密码不能为空\ Exit Sub
Text2.SetFocus Else
sql = \用户表\
rs_add.Open sql, conn, adOpenKeyset, adLockPessimistic While (rs_add.EOF = False)
If Trim(rs_add.Fields(0)) = Trim(Text1.Text) Then
MsgBox \已有这个用户\ Text1.SetFocus Text1.Text = \ Text2.Text = \ Text3.Text = \ Combo1.Text = \ Exit Sub Else
rs_add.MoveNext End If Wend
If Trim(Text2.Text) <> Trim(Text3.Text) Then
MsgBox \两次密码不一致\ Text2.SetFocus Text2.Text = \ Text3.Text = \ Exit Sub
ElseIf Trim(Combo1.Text) <> \ MsgBox \请选择正确的用户权限\ Combo1.SetFocus Combo1.Text = \
43
Exit Sub Else
rs_add.AddNew
rs_add.Fields(0) = Text1.Text rs_add.Fields(1) = Text2.Text rs_add.Fields(2) = Combo1.Text rs_add.Update rs_add.Close
MsgBox \添加用户成功\ Unload Me End If End If End If End Sub
Private Sub Command2_Click() Unload Me End Sub 12.4.5
Private Sub Command1_Click() If Trim(Text1.Text = \
MsgBox \旧密码不能为空,请重新输入!\警告\ Text1.SetFocus Text1.Text = \ Exit Sub End If
If Trim(Text2.Text = \
MsgBox \新密码不能为空,请重新输入!\警告\ Text2.SetFocus Text2.Text = \ Exit Sub End If
If Text2.Text <> Text3.Text Then
MsgBox \两次输入的新密码不同,请重新输入!\警告\ Text2.SetFocus Text2.Text = \ Text3.Text = \ Exit Sub End If
Dim strSql As String
Dim rs As New ADODB.Recordset
strSql = \用户表 where 用户名 = '\ rs.Open strSql, conn, adOpenForwardOnly, adLockReadOnly If Trim(rs.Fields(\密码\
44
MsgBox \旧密码不对,请重新输入!\警告\ Text1.SetFocus Text1.Text = \Else
strSql = \用户表 set 密码='\用户名= '\ conn.Execute strSql
MsgBox \密码修改成功!\提示\ Text3.Text = \ Text1.Text = \ Text2.Text = \ Unload Me End If rs.Close
Set rs = Nothing End Sub
Private Sub Command2_Click() Unload Me End Sub
12.4.6
Option Explicit
Const row_num = 10 '表格行数 Const col_num = 6 '表格列数
Private Sub Combo2_Click()
MSFlexGrid1.Text = Combo2.Text
MSFlexGrid1.Row = MSFlexGrid1.Row + 1 MSFlexGrid1.Col = 0 Combo2.Visible = False Text5.Visible = True
nextposition MSFlexGrid1.Row, MSFlexGrid1.Col End Sub
Private Sub Command1_Click()
Dim rs_save As New ADODB.Recordset Dim sql As String Dim i As Integer
Dim s As String '转化数据用 On Error GoTo saveerror If Trim(Text1.Text) = \
MsgBox \货单不能为空!\ Text1.SetFocus Exit Sub
45