第12章 实验报告.docx
《第12章 实验报告.docx》由会员分享,可在线阅读,更多相关《第12章 实验报告.docx(36页珍藏版)》请在冰豆网上搜索。
第12章实验报告
第12章
12.4.2
DimtrytimesAsInteger'尝试登陆次数
‘命令按钮“确定”的Click事件
PrivateSubcmdCancel_Click()
IfMsgBox("你选择了退出登陆,是否退出?
",_
vbYesNo+vbInformation,"用户登陆")=vbYesThen
End
Else
ExitSub
EndIf
EndSub
‘命令按钮“确定”的Click事件
PrivateSubcmdOK_Click()
DimsNameAsString,sPasAsString
DimmrsAsADODB.Recordset,strSQLAsString
sName=Trim(txtUserName.Text):
sPas=Trim(txtPassword.Text)
'数据有效性检查
IfsName=""Then
MsgBox"请输入用户名!
",vbCritical,"用户登陆验证"
txtUserName.SetFocus
‘若用户名为空,则提示输入用户名,并将定位在用户名文本框
ExitSub
EndIf
IfsPas=""Then
MsgBox"请输入密码!
",vbCritical,"用户登陆验证"
txtPassword.SetFocus
‘若用户密码为空,则提示输入密码,并将定位在密码文本框
ExitSub
EndIf
'检查用户名是否正确
strSQL="select*from用户表where用户名='"&sName&"'"
Setmrs=conn.Execute(strSQL)
Ifmrs.EOF=TrueThen
MsgBox"用户名不存在!
",vbCritical,"用户登陆验证"
try_times=try_times+1
Iftry_times>=3Then
MsgBox"您已经三次尝试进入本系统,均不成功,系统将关闭!
",_
vbCritical,"用户登陆验证"
End
Else
txtUserName.SetFocus
txtUserName.SelStart=0
txtUserName.SelLength=Len(txtUserName.Text)
ExitSub
EndIf
EndIf
strSQL="select*from用户表where用户名='"&sName&"'"&_
"and密码='"&sPas&"'"
Setmrs=conn.Execute(strSQL)
Ifmrs.EOF=TrueThen
MsgBox"密码错误!
",vbCritical,"用户登陆验证"
try_times=try_times+1
Iftry_times>=3Then
MsgBox"您已经三次尝试进入本系统,均不成功,系统将关闭!
",_
vbCritical,"用户登陆验证"
End
Else
txtPassword.SetFocus
txtPassword.SelStart=0
txtPassword.SelLength=Len(txtPassword.Text)
ExitSub
EndIf
EndIf
MsgBox"登陆成功!
",vbInformation,"用户登陆验证"
'保存当前登陆的权限
bolAuthority=mrs.Fields("权限")
'加载MDI主窗体
MDI.Show
'卸载登陆窗体
UnloadMe
EndSub
PrivateSubForm_Load()
CallScreenCenter(Me)
‘调用标准模块中的ScreenCenter过程,将本窗体置于屏幕中心
‘连接d:
\VB\CH12\Mydata.mdb,连接对象为conn。
DimconnsAsString
conns="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=d:
\VB\CH12\Mydata.mdb"
conn.Openconns
EndSub
PrivateSubtxtPassword_KeyPress(KeyAsciiAsInteger)
'用于在输入完密码后并按回车键后跳到确定命令按钮
IfKeyAscii=13ThencmdOK.SetFocus
EndSub
PrivateSubtxtUserName_KeyPress(KeyAsciiAsInteger)
'用于在输入完用户名后并按回车键后跳到输入密码文本框
IfKeyAscii=13ThentxtPassword.SetFocus
EndSub
12.4.3
PrivateSubAdd_user_Click()
Adduser.Show‘调入“新建用户”窗体
EndSub
PrivateSubck_Click()
crk1.Caption="出库"
crk1.Show‘调入“出入库”窗体
EndSub
PrivateSubckhwmx_Click()
sqlfind="select*from出入库"
rs_data1.Opensqlfind,conn,adOpenKeyset,adLockPessimistic
hwckmx.Show‘调入“查看货物明细”窗体
EndSub
PrivateSubhwcx_Click()
cxhw.Show‘调入“查询货物”窗体
EndSub
PrivateSubHz_date_Click()
hz_menu="date"
hzhw.Show‘调入“汇总货物”窗体,并按日期汇总
EndSub
PrivateSubHz_hdh_Click()
hz_menu="hdh"
hzhw.Show‘调入“汇总货物”窗体,并按货单号汇总
EndSub
PrivateSubquit_Click()
UnloadMe
EndSub
PrivateSubrk_Click()
crk1.Caption="入库"
crk1.Show‘调入“出入库”窗体
EndSub
PrivateSubHz_kh_Click()
hz_menu="kh"
hzhw.Show‘调入“汇总货物”窗体,并按客户汇总
EndSub
PrivateSubXGMM_Click()
pwsxg.Show‘调入“修改密码”窗体
EndSub
12.4.4
PrivateSubCommand1_Click()
DimsqlAsString
Dimrs_addAsNewADODB.Recordset
IfTrim(Text1.Text)=""Then
MsgBox"用户名不能为空",vbOKOnly+vbExclamation,""
ExitSub
Text1.SetFocus
Else
IfTrim(Text2.Text)=""Then
MsgBox"密码不能为空",vbOKOnly+vbExclamation,""
ExitSub
Text2.SetFocus
Else
sql="select*from用户表"
rs_add.Opensql,conn,adOpenKeyset,adLockPessimistic
While(rs_add.EOF=False)
IfTrim(rs_add.Fields(0))=Trim(Text1.Text)Then
MsgBox"已有这个用户",vbOKOnly+vbExclamation,""
Text1.SetFocus
Text1.Text=""
Text2.Text=""
Text3.Text=""
Combo1.Text=""
ExitSub
Else
rs_add.MoveNext
EndIf
Wend
IfTrim(Text2.Text)<>Trim(Text3.Text)Then
MsgBox"两次密码不一致",vbOKOnly+vbExclamation,""
Text2.SetFocus
Text2.Text=""
Text3.Text=""
ExitSub
ElseIfTrim(Combo1.Text)<>"system"AndTrim(Combo1.Text)<>"user"Then
MsgBox"请选择正确的用户权限",vbOKOnly+vbExclamation,""
Combo1.SetFocus
Combo1.Text=""
ExitSub
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"添加用户成功",vbOKOnly+vbExclamation,""
UnloadMe
EndIf
EndIf
EndIf
EndSub
PrivateSubCommand2_Click()
UnloadMe
EndSub
12.4.5
PrivateSubCommand1_Click()
IfTrim(Text1.Text="")Then
MsgBox"旧密码不能为空,请重新输入!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
Text1.Text=""
ExitSub
EndIf
IfTrim(Text2.Text="")Then
MsgBox"新密码不能为空,请重新输入!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
Text2.Text=""
ExitSub
EndIf
IfText2.Text<>Text3.TextThen
MsgBox"两次输入的新密码不同,请重新输入!
",vbOKOnly+vbExclamation,"警告"
Text2.SetFocus
Text2.Text=""
Text3.Text=""
ExitSub
EndIf
DimstrSqlAsString
DimrsAsNewADODB.Recordset
strSql="Select*from用户表where用户名='"&userid&"'"
rs.OpenstrSql,conn,adOpenForwardOnly,adLockReadOnly
IfTrim(rs.Fields("密码"))<>Trim(Text1.Text)Then
MsgBox"旧密码不对,请重新输入!
",vbOKOnly+vbExclamation,"警告"
Text1.SetFocus
Text1.Text=""
Else
strSql="Update用户表set密码='"&Text2&"'where用户名='"&userid&"'"
conn.ExecutestrSql
MsgBox"密码修改成功!
",vbOKOnly+vbInformation,"提示"
Text3.Text=""
Text1.Text=""
Text2.Text=""
UnloadMe
EndIf
rs.Close
Setrs=Nothing
EndSub
PrivateSubCommand2_Click()
UnloadMe
EndSub
12.4.6
OptionExplicit
Constrow_num=10'表格行数
Constcol_num=6'表格列数
PrivateSubCombo2_Click()
MSFlexGrid1.Text=Combo2.Text
MSFlexGrid1.Row=MSFlexGrid1.Row+1
MSFlexGrid1.Col=0
Combo2.Visible=False
Text5.Visible=True
nextpositionMSFlexGrid1.Row,MSFlexGrid1.Col
EndSub
PrivateSubCommand1_Click()
Dimrs_saveAsNewADODB.Recordset
DimsqlAsString
DimiAsInteger
DimsAsString'转化数据用
OnErrorGoTosaveerror
IfTrim(Text1.Text)=""Then
MsgBox"货单不能为空!
",vbOKOnly+vbExclamation,""
Text1.SetFocus
ExitSub
EndIf
IfCombo1.Text=""Then
MsgBox"请选择货源地!
",vbOKOnly+vbExclamation,""
Combo1.SetFocus
ExitSub
EndIf
Ifcomboy.Text=""Then
MsgBox"请选择年份!
",vbOKOnly+vbExclamation,""
comboy.SetFocus
ExitSub
EndIf
Ifcombom.Text=""Then
MsgBox"请选择月份!
",vbOKOnly+vbExclamation,""
combom.SetFocus
ExitSub
EndIf
Ifcombod.Text=""Then
MsgBox"请选择日期!
",vbOKOnly+vbExclamation,""
combod.SetFocus
ExitSub
EndIf
IfText2.Text=""Then
MsgBox"请填写凭证号!
",vbOKOnly+vbExclamation,""
Text2.SetFocus
ExitSub
EndIf
IfText3.Text=""Then
MsgBox"请填写经手人!
",vbOKOnly+vbExclamation,""
Text3.SetFocus
ExitSub
EndIf
IfMSFlexGrid1.Col<>0Then
MsgBox"请输入完整的物品信息!
",vbOKOnly+vbExclamation,""
MSFlexGrid1.SetFocus
ExitSub
EndIf
sql="select*from出入库where货单号='"&Text1.Text&"'"
rs_save.Opensql,conn,adOpenKeyset,adLockPessimistic
Ifrs_save.EOFThen
rs_save.AddNew
rs_save.Fields(0)=Trim(Text1.Text)
rs_save.Fields
(1)=CDate(Trim(comboy.Text)&"-"&Trim(combom.Text)&"-"&Trim(combod.Text))
rs_save.Fields
(2)=Trim(Combo1.Text)
rs_save.Fields(3)=Trim(Text2.Text)
rs_save.Fields(4)=Trim(Text3.Text)
rs_save.Fields(5)=Trim(Text4.Text)
Ifcrk1.Caption="入库"Then'出入库标记
rs_save.Fields(6)=True
Else
rs_save.Fields(6)=False
EndIf
rs_save.Update
rs_save.Close
Else
MsgBox"货单号重复!
",vbOKOnly+vbExclamation,""
Text1.SetFocus
Text1.Text=""
rs_save.Close
ExitSub
EndIf
sql="select*from货物明细"
rs_save.Opensql,conn,adOpenKeyset,adLockPessimistic
Fori=1ToMSFlexGrid1.Row-1
rs_save.AddNew
rs_save.Fields(0)=Trim(Text1.Text)
rs_save.Fields
(1)=CDate(Trim(comboy.Text)&"-"&Trim(combom.Text)&"-"&Trim(combod.Text))
rs_save.Fields
(2)=Trim(Combo1.Text)
MSFlexGrid1.Row=i
MSFlexGrid1.Col=0
rs_save.Fields(3)=Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col=1
Ifcrk1.Caption="出库"Then
s="-"&Trim(MSFlexGrid1.Text)
rs_save.Fields(4)=CDbl(s)
Else
rs_save.Fields(4)=CDbl(Trim(MSFlexGrid1.Text))
EndIf
MSFlexGrid1.Col=2
rs_save.Fields(5)=Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col=3
rs_save.Fields(6)=Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col=4
Ifcrk1.Caption="出库"Then
s="-"&Trim(MSFlexGrid1.Text)
rs_save.Fields(7)=CDbl(s)
Else
rs_save.Fields(7)=CDbl(Trim(MSFlexGrid1.Text))
EndIf
MSFlexGrid1.Col=5
rs_save.Fields(8)=Trim(MSFlexGrid1.Text)
Nexti
rs_save.Update
rs_save.Close
MsgBox"添加成功!
",vbOKOnly+vbExclamation,""
UnloadMe
ExitSub
saveerror:
MsgBoxErr.Description
EndSub
PrivateSubCommand2_Click()
UnloadMe
EndSub
PrivateSubForm_Load()
DimsqlAsString
DimiAsInteger
OnErrorGoToloaderror
Combo1.AddItem("北京")
Combo1.AddItem("上海")
Combo1.AddItem("天津")
Combo1.AddItem("武汉")
Combo1.AddItem("广州")
Combo1.AddItem("南京")
Combo2.AddItem("微利公司")
Combo2.AddItem("火星公司")
Combo2.AddItem("南山公司")
Combo2.AddItem("长虹公司")
Combo2.AddItem("利得公司")
Fori=2007To2020'添加月份
comboy.AddItemi
Nexti
Fori=1To12'添加月份
combom.AddItemi
Nexti
Fori=1To31'添加日期
combod.AddItemi
Nexti
setgrid
setgrid_head
Text5.Visible=False
clear_grid
ExitSub
loaderror:
MsgBoxErr.Description
EndSub
PrivateSubForm_Unload(CancelAsInteger)
'关闭数据对象
'rs_checkname.Close
'rs_custom.Close
EndSub
PublicSubsetgrid()'设置表格子程序
DimiAsInteger
OnErrorGoToseterror
MSFlexGrid1.ScrollBars=flexScrollBarBoth
MSFlexGrid1.FixedCols=0
MSFlexGrid1.Rows=row_num
MSFlexGrid1.Cols=col_num
MSFlexGrid1.SelectionMode=flexSelectionByRow
Fori=0Torow_num-1
MSFlexGrid1.RowHeight(i)=315
Next
Fori=0Tocol_num-1
MSFlexGrid1.ColWidth(i)=1300
Nexti
ExitSub
seterror:
MsgBoxErr.Description
EndSub
PublicSubsetgrid_head()
OnErrorGoTosetheaderror
MSFlexGrid1.Row=0
MSFlexGrid1.Col=0
MSFlexGrid1.Text="物品名称"
MSFlexGrid1.Col=1
M