面向对象程序设计考试步骤.docx
《面向对象程序设计考试步骤.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计考试步骤.docx(16页珍藏版)》请在冰豆网上搜索。
面向对象程序设计考试步骤
面向对象程序设计考试步骤
1、系统登录
(1)画面板:
注意点:
修改窗体的icon属性、窗体的Maximize属性为Flase、按钮的FlatStyle属性为Flat、textbox2的Passwordchar改为“*”
(2)新建窗体MDIForm1
(3)连接数据库:
工具—>选择工具箱项,加入OleDbConnection1空间,新建连接,数据源选择MicrosoftAccess数据库、项目添加引用,加入adodb
(4)写入button1、button2的代码
(5)在MDIForm1中创建状态栏,并传入用户名
2、界面设计
(1)新建Form2、Form3、Form4窗体
(2)将MDIForm1的Ismdicainter设置为True
(3)将Form2、Form3、Form4的Load事件写为:
Me.MdiParent=MDIForm1
(4)做菜单Menustrip、Toolstrip(TextImageRelationship、DisplayStyle)
(5)做连接,使窗体居中
3、公式计算
(1)文本框(Name)txtAnswer1、txtAnswer2;命令按钮(Name)Command1、Command2
4、工资卡类
(1)新建类SalaryCard,并写入代码
(2)做登陆界面form3,新建存取款界面form5,form5的text改为:
ATM
ATM的passwordchar改为:
“*”
注意:
取款时必须再次核实密码!
5、数据库操作
(1)在form4中添加BindingSource1(Datemember、DateSource)、BindingNavigator1(BindingSource)控件
(2)画界面
(2)新建窗体MDIForm1
(3)连接数据库:
工具—>选择工具箱项,加入OleDbConnection1空间,新建连接,数据源选择MicrosoftAccess数据库、项目添加引用,加入adodb
(4)写入button1、button2的代码
6、报表
(1)报表中的表头添加、日期移动位置、统计供应商个数
(2)报表创建时的选择Attention
详细代码
Form1(登陆界面):
PublicClassForm1
DimcountAsInteger
登陆按钮代码PrivateSubButton1_Click()HandlesButton1.Click
Dimstr1AsString="select*fromSwhereSno='"+Trim(TextBox1.Text)+"'"
Dimstr2AsString="select*fromSwhereSname='"+Trim(TextBox2.Text)+"'andSno='"+Trim(TextBox1.Text)+"'"
DimstrAsNewADODB.Recordset
Withstr
.Open(str1,OleDbConnection1.ConnectionString,ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockReadOnly)
If.EOF=FalseThen
.Close()
.Open(str2,OleDbConnection1.ConnectionString,ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockReadOnly)
If.EOF=FalseThen
Me.Hide()
MDIForm1.Show()
Else
count+=1
Ifcount>2Then
MessageBox.Show("您的输入错误次数已达三次,系统将自动退出,"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
End
EndIf
MessageBox.Show("登陆信息错误,请检查后重新输入","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
TextBox2.SelectAll()
TextBox2.Focus()
EndIf
Else
count+=1
Ifcount>2Then
MessageBox.Show("您的输入错误次数已达三次,系统将自动退出?
","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
End
EndIf
MessageBox.Show("登陆信息错误,请检查后重新输入","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
TextBox1.SelectAll()
TextBox1.Focus()
EndIf
EndWith
Ifcount>2Then
MessageBox.Show("您的输入错误次数已达三次,系统将自动¡退出","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
EndIf
EndSub
取消按钮代码PrivateSubButton2_Click()HandlesButton2.Click
End
EndSub
账号输入框代码PrivateSubTextBox1_KeyPress()HandlesTextBox1.KeyPress
Ife.KeyChar=Chr(13)Then
TextBox2.Focus()
ElseIfe.KeyChar=Chr(8)Then
e.Handled=False
ElseIfe.KeyChar<"A"Ore.KeyChar>"Z"Then
e.Handled=True
EndIf
EndSub
密码输入框代码PrivateSubTextBox2_KeyPress()HandlesTextBox2.KeyPress
Ife.KeyChar=Chr(13)Then
Button1_Click(sender,e)
EndIf
EndSub
EndClass
MDIForm1(主界面):
PublicClassMDIForm1
DimCurrTimeAsDate
状态栏一:
PrivateSubToolStripStatusLabel1_Paint()ToolStripStatusLabel1.Paint
ToolStripStatusLabel1.Text="用户名"&Form1.TextBox1.Text
EndSub
状态栏三:
PrivateSubToolStripStatusLabel3_PaintToolStripStatusLabel3.Text=Now.Date
EndSub
菜单栏一:
PrivateSub试题¬a2ToolStripMenuItem_Click(oolStripMenuItem.Click
Form2.Show()
EndSub
菜单栏二:
PrivateSub试º?
题¬a3ToolStripMenuItem_Click
Form3.Show()
EndSub
菜单栏三:
PrivateSub试º?
题¬a5ToolStripMenuItem_Click
Form4.Show()
EndSub
图文框一:
PrivateSubToolStripButton1_Click
Form2.Show()
EndSub
图文框二:
PrivateSubToolStripButton2_Click
Form3.Show()
EndSub
图文框三PrivateSubToolStripButton3_Click
Form4.Show()
EndSub
图文框四:
PrivateSubToolStripButton4_Click
IfMsgBox("你?
确¨¡¤实º¦Ì要°a退ª?
出?
吗e?
ê?
",MsgBoxStyle.OkCancel,"退ª?
出?
")=MsgBoxResult.OkThen
End
EndIf
EndSub
SubDisplayTime()
IfCurrTime<>"00:
00:
00"Then
CurrTime=CurrTime.AddSeconds(-1)
Me.ToolStripStatusLabel2.Text="距¨¤离¤?
考?
试º?
结¨¢束º?
还1有®D:
êo"&Microsoft.VisualBasic.Format(CurrTime,"HH:
mm:
ss")&""
Else
MsgBox("考?
试º?
结¨¢束º?
时º¡À间?
到Ì?
,ê?
请?
交?
卷¨ª!
ê?
")
EndIf
EndSub
窗体登陆:
PrivateSubMDIForm1_Load()HandlesMyBase.Load
CurrTime=CDate(Today.Date&"23:
00:
00")
CurrTime=CDate(CurrTime.Subtract(Now).ToString)
EndSub
退出菜单栏:
PrivateSub退ª?
出?
EToolStripMenuItem_Click
IfMsgBox("你?
确¨¡¤实º¦Ì要°a退ª?
出?
吗e?
ê?
",MsgBoxStyle.OkCancel,"退ª?
出?
")=MsgBoxResult.OkThen
End
EndIf
EndSub
EndClass
时间一:
PrivateSubTimer1_Tick()HandlesTimer1.Tick
CallDisplayTime()
EndSub
时间二:
ivateSubTimer2_Tick()HandlesTimer2.Tick
IfMy.Computer.Keyboard.NumLockThen
Me.ToolStripStatusLabel4.Text="Num"
Else
Me.ToolStripStatusLabel4.Text=""
EndIf
EndSub
Form2(计算题界面):
PublicClassForm2
窗体登陆:
PrivateSubForm2_Load
Me.MdiParent=MDIForm1
Me.Left=MDIForm1.Left+(MDIForm1.Width-Me.Width)/2
Me.Top=MDIForm1.Left+(MDIForm1.Height-Me.Height)/2
EndSub
按钮一:
PrivateSubCommand1_Click
DimresultAsDouble=1
DimiAsInteger
Fori=1To50
result