VB航空公司管理信息系统 第8页
图9-14 显示客机信息列表窗体
7.2 添加客机信息窗体的创建
单击客机信息列表中的“添加”按钮,将出现如图9-15所示的窗体。
图9-15 添加客机信息列表
输入内容完毕,单击“保存”按钮,将首先判断输入内容是否满足要求,然后将记录添加到数据库中,代码如下:
Private Sub cmdSave_Click()
Dim intCount As Integer
Dim sMeg As String
Dim MsgText As String
‘判断输入内容是否为空
For intCount = 0 To 6
If Trim(txtItem(intCount) & " ") = "" Then
Select Case intCount
Case 0
sMeg = "客机编号"
Case 1
sMeg = "客机型号"
Case 2
sMeg = "购买时间"
Case 3
sMeg = "服役时间"
Case 4
sMeg = "经济舱座位数量"
Case 5
sMeg = "公务舱座位数量"
Case 6
sMeg = "头等舱座位数量"
End Select
sMeg = sMeg & "不能为空!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
Next intCount
‘判断输入内容为数字
For intCount = 4 To 6
If Not IsNumeric(Trim(txtItem(intCount))) Then
sMeg = "座位数量"
sMeg = sMeg & "请输入数字!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
End If
Next intCount
‘判断输入内容是否为日期
For intCount = 2 To 3
If IsDate(txtItem(intCount)) Then
txtItem(intCount) = Format(txtItem(intCount), "yyyy-mm-dd")
Else
MsgBox "时间应输入日期(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
txtItem(intCount).SetFocus
Exit Sub
End If
Next intCount
'添加判断是否有相同的ID记录
If gintPmode = 1 Then
txtSQL = "select * from planeInfo where planeNO='" & Trim(txtItem(0)) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "已经存在此编号的记录!", vbOKOnly + vbExclamation, "警告"
txtItem(0).SetFocus
Exit Sub
End If
mrc.Close
End If
'先删除已有记录
txtSQL = "delete from planeInfo where planeNO='" & Trim(txtItem(0)) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'再加入新记录
txtSQL = "select * from planeInfo"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
For intCount = 0 To 7
mrc.Fields(intCount) = Trim(txtItem(intCount))
Next intCount
‘更新数据集
mrc.Update
‘关闭数据集对象
mrc.Close
If gintPmode = 1 Then
MsgBox "添加记录成功!", vbOKOnly + vbExclamation, "添加记录"
For intCount = 0 To 7
txtItem(intCount) = ""
Next intCount
mblChange = False
Unload frmPlane
frmPlane.txtSQL = "select * from planeInfo"
frmPlane.Show
ElseIf gintPmode = 2 Then
Unload Me
Unload frmPlane
frmPlane.txtSQL = "select * from planeInfo"
frmPlane.Show
End If
End Sub
7.3 修改客机信息
在客机信息列表中选择记录,然后单击“修改”按钮。当前记录将显示在如图9-15所示的窗体中,可以进行修改。代码如下:
Private Sub cmdModify_Click()
Dim intCount As Integer
‘判断列表内容是否为空
If frmPlane.msgList.Rows > 1 Then
gintPmode = 2
‘记载选择记录的位置
intCount = msgList.Row
If intCount > 0 Then
frmPlane1.txtSQL = "select * from planeInfo where planeNO ='" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
frmPlane1.Show 1
Else
MsgBox "警告", vbOKOnly + vbExclamation, "请首先选择需要修改的记录!"
End If
End If
End Sub
7.4 删除客机信息
在客机信息列表中选择记录,然后单击“删除”按钮,当前记录将被删除。代码如下:
Private Sub cmdDelete_Click()
Dim txtSQL As String
Dim intCount As Integer
Dim mrc As ADODB.Recordset
Dim MsgText As String
‘判断列表内容是否为空
If msgList.Rows > 1 Then
If MsgBox("真的要删除客机编号为" & Trim(msgList.TextMatrix(msgList.Row, 1)) & "的型号为" & Trim(msgList.TextMatrix(msgList.Row, 2)) & "的客机记录吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
‘记载选择记录的位置
intCount = msgList.Row
txtSQL = "delete from planeInfo where planeNO ='" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Unload frmPlane
‘重新载入所有记录,并显示出来
frmPlane.txtSQL = "select * from planeInfo"
frmPlane.Show
End If
End If
End Sub
7.5 查询客机信息
在客机信息列表中单击“查询”按钮,将出现如图9-16所示的窗体。
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
VB航空公司管理信息系统 第8页下载如图片无法显示或论文不完整,请联系qq752018766