📄 main_jcxx_dzxxsz.frm
字号:
Left = 4365
Style = 1 'Graphical
TabIndex = 22
Top = 180
Width = 855
End
Begin VB.CommandButton CmdModify
BackColor = &H00C0C0C0&
Caption = "[M]修改"
Height = 360
Left = 945
Style = 1 'Graphical
TabIndex = 21
Top = 180
Width = 855
End
End
End
Attribute VB_Name = "main_jcxx_dzxxsz"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i, a, Mat As Integer '声明整型变量
Dim rs1 As New ADODB.Recordset '声明数据集对象
Private Sub view_data() '声明一个显示reads表中数据的过程
With Adodc1.Recordset
'将reads数据表中各字段的值赋给对应的控件
If .Fields("书证号") <> "" Then Text1.text = .Fields("书证号")
If .Fields("姓名") <> "" Then Text2.text = .Fields("姓名")
If .Fields("性别") <> "" Then Combo1.text = .Fields("性别")
If .Fields("身份证") <> "" Then Text3.text = .Fields("身份证")
If .Fields("单位") <> "" Then Text4.text = .Fields("单位")
If .Fields("家庭住址") <> "" Then Text5.text = .Fields("家庭住址")
If .Fields("联系电话") <> "" Then Text6.text = .Fields("联系电话")
If .Fields("读者类别") <> "" Then Combo2.text = .Fields("读者类别")
If .Fields("收费标准") <> "" Then Label3.Caption = .Fields("收费标准")
If .Fields("期限") <> "" Then Combo4.text = .Fields("期限")
If .Fields("办证价格") <> "" Then Label4.Caption = .Fields("办证价格")
If .Fields("办证日期") <> "" Then DTPicker1.Value = .Fields("办证日期")
If .Fields("到期日期") <> "" Then DTPicker2.Value = .Fields("到期日期")
If .Fields("已借书数") <> "" Then jss.Caption = .Fields("已借书数")
If .Fields("相片路径") <> "" Then
Label6.Caption = .Fields("相片路径")
If Dir(.Fields("相片路径")) <> "" Then
Picture1.Picture = LoadPicture(.Fields("相片路径"))
Else
MsgBox "此读者相片路径错误,请更改!"
Picture1.Picture = LoadPicture("")
End If
Else
Label6.Caption = ""
Picture1.Picture = LoadPicture("")
End If
End With
End Sub
Private Sub Ena() '声明一个设置控件有效或无效的过程
If a = 0 Or a = 1 Then '当变量a=0或a=1时
'设置如下控件有效或无效
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Combo1.Enabled = True
Combo2.Enabled = True
Combo4.Enabled = True
DTPicker1.Enabled = True
DTPicker2.Enabled = True
Command1.Enabled = True
CmdSave.Enabled = True
CmdEsc.Enabled = True
CmdAdd.Enabled = False
CmdModify.Enabled = False
CmdDelete.Enabled = False
For i = 0 To 3
CmdMD(i).Enabled = False
Next i
End If
If a = 2 Or a = 3 Then '当变量a=2或a=3时
'设置如下控件有效或无效
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Combo1.Enabled = False
Combo2.Enabled = False
Combo4.Enabled = False
DTPicker1.Enabled = False
DTPicker2.Enabled = False
Command1.Enabled = False
CmdSave.Enabled = False
CmdEsc.Enabled = False
CmdAdd.Enabled = True
CmdModify.Enabled = True
CmdDelete.Enabled = True
For i = 0 To 3
CmdMD(i).Enabled = True
Next i
End If
End Sub
Private Sub Form_Load()
'添加读者类别列表
rs1.Open "select 类别名称 from dzlbb ", Cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
If rs1.BOF = False Then rs1.MoveFirst
For i = 0 To rs1.RecordCount - 1
Combo2.AddItem (Trim(rs1.Fields("类别名称")))
rs1.MoveNext
Next i
End If
rs1.Close
If Combo2.ListCount > 0 Then Combo2.ListIndex = 0
'添加性别列表
Combo1.AddItem ("男")
Combo1.AddItem ("女")
Combo1.ListIndex = 1
'添加查询字段列表
Combo3.AddItem ("书证号")
Combo3.AddItem ("姓名")
Combo3.AddItem ("身份证")
Combo3.AddItem ("单位")
Combo3.AddItem ("读者类别")
Combo3.AddItem ("期限")
Combo3.ListIndex = 0
'添加借书期限列表
Combo4.AddItem ("一年")
Combo4.AddItem ("半年")
Combo4.AddItem ("三个月")
Adodc1.RecordSource = "select * from reads"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Call view_data '调用函数
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True
End Sub
Private Sub Combo2_Click()
'按类别名称查询
rs1.Open "select * from dzlbb where 类别名称='" + Combo2.text + "'", Cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then '当记录大于零时
Label3.Caption = rs1.Fields("收费标准") 'Label3等于收费标准字段的值
End If
rs1.Close
'根据选择的读者类别,设置书证号
Text1.text = Left(Combo2.text, 1) & Right(Text1.text, 5)
End Sub
Private Sub Combo4_Click()
'计算办证价格
If Combo4.text = "一年" Then
Label4.Caption = Val(Label3.Caption)
Mat = 365
End If
If Combo4.text = "半年" Then
Label4.Caption = Val(Label3.Caption) / 2
Mat = 183
End If
If Combo4.text = "三个月" Then
Label4.Caption = (Val(Label3.Caption) / 12) * 3
Mat = 90
End If
'计算到期日期
DTPicker2.Value = DTPicker1.Value + Mat
End Sub
Private Sub DTPicker1_Change()
'根据选择的借书期限,设置Mat变量的值
If Combo4.text = "一年" Then Mat = 365
If Combo4.text = "半年" Then Mat = 183
If Combo4.text = "三个月" Then Mat = 90
'计算到期日期
DTPicker2.Value = DTPicker1.Value + Mat
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text3.SetFocus '回车Text1(2)获得焦点
End Sub
Private Sub Combo3_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text7.SetFocus '回车Text7获得焦点
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Combo1.SetFocus '回车获得焦点
End Sub
Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text4.SetFocus '回车获得焦点
End Sub
Private Sub Text4_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text5.SetFocus '回车获得焦点
End Sub
Private Sub Text5_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Text6.SetFocus '回车获得焦点
End Sub
Private Sub Text6_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Combo2.SetFocus '回车获得焦点
End Sub
Private Sub Combo2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then Combo4.SetFocus
End Sub
Private Sub SSTab1_Click(PreviousTab As Integer)
If Adodc1.Recordset.RecordCount > 0 Then '当记录大于零时
If SSTab1.Tab = 1 And CmdAdd.Enabled = False Then '当选项卡为1,并且【添加】按钮无效时
MsgBox ("您正在处理数据,请取消数据处理,在执行本操作!") '提示用户
SSTab1.Tab = 0 '设置当前选项卡为0
End If
End If
End Sub
Private Sub Command1_Click()
'添加读者相片
With CDialog1
.DialogTitle = "选择要加入的读者相片"
.Filter = "jpg图片|*.jpg"
.ShowOpen '打开对话框
Picture1.Picture = LoadPicture(.FileName)
Label6.Caption = .FileName
End With
End Sub
Private Sub CmdFind_Click() '查询读者信息
Adodc1.RecordSource = "select * from reads where reads." & Combo3.text & " " & "like +'" + Text7.text + "'+ '%'"
Adodc1.Refresh
SSTab1.Tab = 1
Call view_data '调用显示reads表中数据的过程
End Sub
Private Sub CmdPrint_Click() '打印读者书证
If Text7.text = "" Then
DataE1.rsCommand4.Open "select * from reads where 书证号='" + Text1.text + "'", Cnn, adOpenKeyset, adLockOptimistic
Else
DataE1.rsCommand4.Open "select * from reads where reads." & Combo3.text & " " & "like +'" + Text7.text + "'+ '%'", Cnn, adOpenKeyset, adLockOptimistic
End If
DR1_jsz.Show
End Sub
Private Sub CmdMD_Click(Index As Integer)
Select Case Index
Case Is = 0 '移到第一条记录
If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
Case Is = 1 '移到上一条记录
If Adodc1.Recordset.RecordCount > 0 Then
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF = True Then Adodc1.Recordset.MoveFirst
End If
Case Is = 2 '移到下一条记录
If Adodc1.Recordset.RecordCount > 0 Then
If Adodc1.Recordset.EOF = False Then Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
End If
Case Is = 3 '移到最后一条记录
If Adodc1.Recordset.EOF = False Then Adodc1.Recordset.MoveLast
End Select
Call view_data '调用过程
End Sub
Private Sub CmdAdd_Click() '添加
a = 0 '当变量a=0时
Dim bh As Integer '声明一个整型变量
rs1.Open "select * from reads order by right(书证号,5)", Cnn, adOpenKeyset, adLockOptimistic
'创建书证号
If rs1.RecordCount > 0 Then
If rs1.EOF = False Then
rs1.MoveLast
If rs1.Fields("书证号") <> "" Then
bh = Right(Trim(rs1.Fields("书证号")), 5) + 1
Text1.text = Left(Combo2.text, 1) & Format(bh, "00000")
End If
End If
Else
Text1.text = Left(Combo2.text, 1) & "00001"
End If
DTPicker1.Value = Date
Call Ena '调用设置控件有效无无效的过程
rs1.Close
'清空文本框中的数据
Text2.text = ""
Text3.text = ""
Text4.text = ""
Text5.text = ""
Text6.text = ""
Label3.Caption = ""
Label4.Caption = ""
Picture1.Picture = LoadPicture("")
Label6.Caption = ""
Combo2.text = ""
Combo4.text = ""
jss.Caption = "0"
SSTab1.Tab = 0
Text2.SetFocus 'text2获得焦点
End Sub
Private Sub CmdSave_Click()
If a = 0 Then '当变量a=0时
'判断是否有填写不完整的读者信息项
If Text2.text = "" Then
MsgBox ("请输入读者姓名!")
Text2.SetFocus
Exit Sub
End If
If Combo1.text = "" Then
MsgBox ("请输入性别!")
Combo1.SetFocus
Exit Sub
End If
If Text3.text = "" Then
MsgBox ("请输入身份证号!")
Text3.SetFocus
Exit Sub
End If
If Text4.text = "" Then
MsgBox ("请输入单位!")
Text4.SetFocus
Exit Sub
End If
If Combo2.text = "" Then
MsgBox ("请输入读者类别!")
Combo2.SetFocus
Exit Sub
End If
If Picture1.Picture = LoadPicture("") Then
MsgBox ("请输入读者相片!")
Exit Sub
End If
With Adodc1.Recordset
'添加读者信息到reads表中
.AddNew
.Fields("书证号") = Text1.text
.Fields("姓名") = Text2.text
.Fields("性别") = Combo1.text
.Fields("身份证") = Text3.text
.Fields("单位") = Text4.text
.Fields("家庭住址") = Text5.text
.Fields("联系电话") = Text6.text
.Fields("读者类别") = Combo2.text
.Fields("收费标准") = Val(Label3.Caption)
.Fields("期限") = Combo4.text
.Fields("办证价格") = Val(Label4.Caption)
.Fields("办证日期") = DTPicker1.Value
.Fields("到期日期") = DTPicker2.Value
.Fields("相片路径") = Label6.Caption
.Fields("已借书数") = 0
.Update '更新数据表
End With
a = 2 '设置变量a=2
Call Ena '调用设置控件有效或无效的过程
End If
If a = 1 Then
rs1.Open "select * from reads where 书证号='" + Text1.text + "'", Cnn, adOpenKeyset, adLockOptimistic
Myval = MsgBox("是否要修改此记录?", vbYesNo, "修改窗口")
If Myval = vbYes Then
With rs1
.Fields("书证号") = Text1.text
.Fields("姓名") = Text2.text
.Fields("性别") = Combo1.text
.Fields("身份证") = Text3.text
.Fields("单位") = Text4.text
.Fields("家庭住址") = Text5.text
.Fields("联系电话") = Text6.text
.Fields("读者类别") = Combo2.text
.Fields("收费标准") = Val(Label3.Caption)
.Fields("期限") = Combo4.text
.Fields("办证价格") = Val(Label4.Caption)
.Fields("办证日期") = DTPicker1.Value
.Fields("到期日期") = DTPicker2.Value
.Fields("相片路径") = Label6.Caption
.Update '更新数据库
End With
MsgBox "修改数据成功!"
Adodc1.Refresh
a = 2
Call Ena
End If
rs1.Close
End If
End Sub
Private Sub CmdModify_Click() '允许修改读者信息
a = 1 '设置变量a=1
Call Ena '调用设置控件有效或无效的过程
End Sub
Private Sub CmdDelete_Click() '删除读者信息
If Adodc1.Recordset.RecordCount > 0 Then
a = MsgBox("您确实要删除这条数据吗?", vbYesNo)
If a = vbYes Then
'删除当前记录
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
If Adodc1.Recordset.EOF = False Then
Adodc1.Recordset.MoveNext
Else
Adodc1.Recordset.MoveFirst
End If
Call view_data '调用显示reads表中数据的过程
'设置按钮有效或无效
CmdSave.Enabled = False
CmdEsc.Enabled = False
CmdAdd.Enabled = True
CmdModify.Enabled = True
For i = 0 To 3
CmdMD(i).Enabled = True
Next i
End If
End If
End Sub
Private Sub CmdEsc_Click() '取消操作
a = 3 '设置变量a=3
If Not Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
Call view_data '调用显示reads表中数据的过程
End If
Call Ena
End Sub
Private Sub CmdExit_Click()
frm_main.Enabled = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -