[此贴子已经被作者于2007-8-4 10:12:03编辑过]
我把整个窗体的代码发你看
Option Explicit
Dim rcdset '窗体级变量,存放ADO控件的当前记录
Dim i As Integer
'***********窗体事件*******************
Private Sub Form_Load()
loadmdb Adodc1 '连接数据库
End Sub
'***************操作********************
'确定借书人借阅状况,已经设定为每人最多可借阅3本书籍
'借阅书籍时确定借书人情况并设置相应控件
Private Sub Image1_Click()
For i = 0 To 2
Text2(i).Enabled = False
Text2(i).Text = ""
Label8(i).Visible = False
Next i
Command1(0).Enabled = False
If Text1.Enabled = False Then
Text1.Enabled = True
Else
lockrecord Adodc1, "学生总表", "学号", Text1.Text
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
MsgBox "学号输入有误!!!"
Exit Sub
Else
lockrecord Adodc1, "借阅总表", "学号", Text1.Text '从借阅表中读取学生借阅信息
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
Text1.Enabled = False
For i = 0 To 2
Text2(i).Enabled = True
Next i
Command1(0).Enabled = True
Else
If rcdset.RecordCount > 3 Then
MsgBox "数据记录出现错误!!!"
Exit Sub
End If
'确定可借阅书籍数目并设置窗体中可用控件
rcdset.MoveFirst
i = 0
Do While Not rcdset.EOF
Text2(i).Text = rcdset!书号
Text2(i).Enabled = False
Label8(i).Visible = True
rcdset.MoveNext
i = i + 1
Loop
For i = 0 To 2
If Text2(i).Text = "" Then
Text2(i).Enabled = True
Label8(i).Visible = False
End If
Next i
Command1(0).Enabled = True
Text1.Enabled = False
End If
End If
End If
End Sub
'归还书籍时确定借书人情况并设置相应控件
Private Sub Image2_Click()
For i = 0 To 2
Text4(i).Enabled = False
Text4(i).Text = ""
Check1(i).Enabled = False
Check1(i).Value = False
Next i
Command1(2).Enabled = False
If Text3.Enabled = False Then
Text3.Enabled = True
Else
lockrecord Adodc1, "学生总表", "学号", Text3.Text
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
MsgBox "学号输入有误。"
Exit Sub
Else
lockrecord Adodc1, "借阅总表", "学号", Text3.Text
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
Text3.Enabled = False
Exit Sub
Else
rcdset.MoveFirst
i = 0
Do While Not rcdset.EOF
Text4(i).Text = rcdset!书号
Check1(i).Enabled = True
rcdset.MoveNext
i = i + 1
Loop
Text3.Enabled = False
Command1(1).Enabled = True
End If
End If
End If
End Sub
'续借书籍时确定借书人情况并设置相应控件
Private Sub Image3_Click()
For i = 0 To 2
Text6(i).Enabled = False
Text6(i).Text = ""
Check2(i).Enabled = False
Check2(i).Value = False
Next i
Command1(2).Enabled = False
If Text5.Enabled = False Then
Text5.Enabled = True
Else
lockrecord Adodc1, "学生总表", "学号", Text5.Text
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
MsgBox "学号输入有误。"
Exit Sub
Else
lockrecord Adodc1, "借阅总表", "学号", Text5.Text
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
Text5.Enabled = False
Exit Sub
Else
rcdset.MoveFirst
i = 0
Do While Not rcdset.EOF
Text6(i).Text = rcdset!书号
Check2(i).Enabled = True
rcdset.MoveNext
i = i + 1
Loop
Text5.Enabled = False
Command1(2).Enabled = True
End If
End If
End If
End Sub
'执行操作
Private Sub Command1_Click(Index As Integer)
Dim j As Integer
j = 0
Select Case Index
Case 0 '借阅书籍确定按钮
'判断要借书籍是否借出,书号是否正确,符合条件后执行操作
For i = 0 To 2
If Text2(i).Enabled = True And Text2(i).Text <> "" Then
lockrecord Adodc1, "书籍总表", "书号", Text2(i).Text '读取要借书籍的信息
Set rcdset = Adodc1.Recordset
If rcdset.RecordCount = 0 Then
MsgBox "书号" & Text2(i).Text & "操作中断,借阅书籍!!!" & Str(j) & "本"
Exit Sub
Else
If rcdset!是否借出 = "是" Then
MsgBox "书籍" & Text2(i).Text & "操作成功,借阅书籍!!!" & Str(j) & "本"
Exit Sub
Else
'符合后更新书籍记录并添加借阅记录
rcdset!是否借出 = "是" '更新书籍记录
rcdset.update
Adodc1.Refresh
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "借阅总表"
Adodc1.Refresh
Set rcdset = Adodc1.Recordset
rcdset.AddNew '添加新的借阅记录
rcdset!学号 = Text1.Text
rcdset!书号 = Text2(i).Text
rcdset.update
Adodc1.Refresh
j = j + 1
End If
End If
End If
Next i
MsgBox "所有操作完成,借阅书籍" & Str(j) & "本"
Command1(0).Enabled = False
Text1.Enabled = True
'窗体数据显示同步更新
Image1_Click
If Text3.Text = Text1.Text Then
Text3.Enabled = True
Image2_Click
End If
If Text5.Text = Text1.Text Then
Text5.Enabled = True
Image3_Click
End If
Case 1 '归还书籍确定按钮
For i = 0 To 2
If Check1(i).Value = 1 Then
lockrecord Adodc1, "书籍总表", "书号", Text4(i).Text
Set rcdset = Adodc1.Recordset
rcdset!是否借出 = "否" '更新书籍记录
rcdset.update
Adodc1.Refresh
lockrecord Adodc1, "借阅总表", "书号", Text4(i).Text
Adodc1.Recordset.Delete '删除相应的借阅记录
Adodc1.Refresh
j = j + 1
End If
Next i
MsgBox "操作完成,归还书籍" & Str(j)
Command1(1).Enabled = False
Text3.Enabled = True
'窗体数据显示同步更新
Image2_Click
If Text1.Text = Text3.Text Then
Text1.Enabled = True
Image1_Click
End If
If Text5.Text = Text3.Text Then
Text5.Enabled = True
Image3_Click
End If
Case 2
For i = 0 To 2
If Check2(i).Value = 1 Then
lockrecord Adodc1, "借阅总表", "书号", Text4(i).Text
Set rcdset = Adodc1.Recordset
rcdset!截止日期 = DateAdd("m", 1, rcdset!截止日期) '更新借阅记录中截止日期字段
rcdset.update
Adodc1.Refresh
j = j + 1
End If
Next i
MsgBox "操作完成,续借书籍" & Str(j) & "本"
Command1(2).Enabled = False
Text5.Enabled = True
'窗体数据显示同步更新
Image3_Click
If Text1.Text = Text5.Text Then
Text1.Enabled = True
Image1_Click
End If
If Text3.Text = Text5.Text Then
Text3.Enabled = True
Image2_Click
End If
End Select
End Sub
Private Sub Command2_Click(Index As Integer)
Unload Me
End Sub
Private Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image2.BorderStyle = 1
End Sub
Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image2.BorderStyle = 0
End Sub
Private Sub Image3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image3.BorderStyle = 1
End Sub
Private Sub Image3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image3.BorderStyle = 0
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.BorderStyle = 1
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.BorderStyle = 0
End Sub
[此贴子已经被作者于2007-8-4 10:46:38编辑过]