⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmnewcustreserveinfo.frm

📁 酒店课房管理系统。完成酒店的客房入住
💻 FRM
📖 第 1 页 / 共 2 页
字号:
                    cboDate.AddItem i
                Next i
            End If
        Case 4, 6, 9, 11
            For i = 1 To 30
                cboDate.AddItem i
            Next i
    End Select
    cboDate.Text = 1
End Sub

Private Sub cboYear_LostFocus()
    Dim i As Integer, str As String, Leap As Boolean
    str = Val(cboYear.Text)
    If (str Mod 4 = 0) And (str Mod 100 <> 0) Or (str Mod 400 = 0) Then  '如果当前年份为闰年
        Leap = True
    End If
    For i = 0 To cboDate.ListCount - 1
        cboDate.Clear       '清空cboDate的下拉列表项
    Next i
    Select Case Val(cboMonth.Text)
        Case 1, 3, 5, 7, 8, 10, 12
            For i = 1 To 31
                cboDate.AddItem i
            Next i
        Case 2
            If Leap Then   '如果是闰年
                For i = 1 To 29
                    cboDate.AddItem i
                Next i
            Else        '如果不是闰年
                For i = 1 To 28
                    cboDate.AddItem i
                Next i
            End If
        Case 4, 6, 9, 11
            For i = 1 To 30
                cboDate.AddItem i
            Next i
    End Select
    cboDate.Text = 1
End Sub

Private Sub cmdCancel_Click()
    Dim msg
    msg = MsgBox("要取消输入新客户预定信息吗?", vbOKCancel + vbQuestion, "取消输入客户预定信息")
    If msg = vbOK Then
        rsCustReserveInfo.CancelUpdate  '取消修改
        Unload frmNewCustReserveInfo
    End If
End Sub

Private Sub cmdOk_Click()
    Dim msg, i As Integer
    If txtCustName.Text = "" Then     '当顾客姓名为空时
        MsgBox "顾客姓名不能为空!", vbInformation, "请重新输入"
        txtCustName.SetFocus
        Exit Sub
    ElseIf txtCustAddress.Text = "" Then    '当顾客地址为空时
        MsgBox "顾客地址不能为空!", vbInformation, "请重新输入"
        txtCustAddress.SetFocus
        Exit Sub
    ElseIf txtCustPhoneNo.Text = "" Or Not IsNumeric(txtCustPhoneNo.Text) Then   '当顾客电话号码为空或为非数值字符时
        MsgBox "顾客电话号码应为数字且不能为空!", vbInformation, "请重新输入"
        txtCustPhoneNo.SetFocus
        Exit Sub
    ElseIf txtCustCreditNo.Text = "" Then    '当顾客信用卡号为空时
        MsgBox "顾客信用卡号不能为空!", vbInformation, "请重新输入"
        txtCustCreditNo.SetFocus
        Exit Sub
    ElseIf Not ValidateRoomNo Then '如果没有正确输入顾客预定的房间号
        MsgBox "顾客预定房间号输入错误或该房间已经被预定!" + Chr(13) + "请在下拉列表中选择房间号或输入正确的房间号", vbInformation, "请重新输入"
        cboRoomNo.SetFocus
        Exit Sub
    ElseIf ValidateReserveDate Then
        Exit Sub
    ElseIf Val(txtPrice.Text) < 10 Then '当顾客预定房间所付定金小于10元时
        MsgBox "顾客预定房间所付定金至少为10元!", vbInformation, "请重新输入"
        txtPrice.SetFocus
        Exit Sub
    End If
   
    cnnHotel.BeginTrans
    rsCustReserveInfo.Update "顾客姓名", txtCustName
    rsCustReserveInfo.Update "顾客地址", txtCustAddress
    rsCustReserveInfo.Update "顾客电话号码", txtCustPhoneNo
    rsCustReserveInfo.Update "顾客信用卡号", txtCustCreditNo
    rsCustReserveInfo.Update "顾客预定房间号", cboRoomNo
    rsCustReserveInfo.Update "顾客预定房间日期", cboYear.Text & "年" & cboMonth.Text & "月" & cboDate.Text & "日"
    rsCustReserveInfo.Update "顾客预定房间所付定金", txtPrice
    cnnHotel.CommitTrans
    
    rsRooms.Open "SELECT * FROM Rooms WHERE 房间号=" & "'" & cboRoomNo & "'", cnnHotel, adOpenKeyset, adLockOptimistic   '打开新记录集
    cnnHotel.BeginTrans
    rsRooms.Update "房间预定日期", cboYear.Text & "年" & cboMonth.Text & "月" & cboDate.Text & "日"
    rsRooms.Update "房间状态", "已预定"          '修改房间状态
    rsRooms.Update "顾客姓名", txtCustName.Text
    cnnHotel.CommitTrans
    rsRooms.Close  '关闭记录集
    
    msg = MsgBox("新顾客预定信息已经成功保存!" + Chr(13) + "要继续输入下一个新客户预定信息吗?", vbInformation + vbOKCancel + vbDefaultButton2, "新客户信息输入成功")
    If msg = vbCancel Then
        Unload frmNewCustReserveInfo
    Else
        VacancyRoomNum = VacancyRoomNum - 1 '当前可用房间数减 1
        labVacancyRoomNum.Caption = "目前有" & VacancyRoomNum & "个空闲房间"
        For i = 0 To VacancyRoomNum - 1       '从cboRoomNo下拉列表项中删除已经被预定的房间号
            If cboRoomNo.Text = cboRoomNo.List(i) Then
                cboRoomNo.RemoveItem i
                Exit For
            End If
        Next i
        rsCustReserveInfo.AddNew    '添加一条新记录
    End If
End Sub
Private Sub Form_Load()
    cnnHotel.Provider = "Microsoft.Jet.OLEDB.3.51"
    cnnHotel.Open "User ID=admin;Data Source=" & GetDBPath() '建立与数据库的连接
    rsCustReserveInfo.Open "SELECT * FROM CustReserveInfo", cnnHotel, adOpenKeyset, adLockOptimistic '打开记录集
    rsRooms.Open "SELECT 房间号,房间状态 FROM Rooms WHERE 房间状态='空闲'", cnnHotel, adOpenKeyset, adLockOptimistic   '打开新记录集
    Set txtCustName.DataSource = rsCustReserveInfo
    txtCustName.DataField = "顾客姓名"
    Set txtCustAddress.DataSource = rsCustReserveInfo
    txtCustAddress.DataField = "顾客地址"
    Set txtCustPhoneNo.DataSource = rsCustReserveInfo
    txtCustPhoneNo.DataField = "顾客电话号码"
    Set txtCustCreditNo.DataSource = rsCustReserveInfo
    txtCustCreditNo.DataField = "顾客信用卡号"
    Set cboRoomNo.DataSource = rsCustReserveInfo
    cboRoomNo.DataField = "顾客预定房间号"
    Set txtPrice.DataSource = rsCustReserveInfo
    txtPrice.DataField = "顾客预定房间所付定金"
    AddYear    '在cboYear下拉列表框中添加年份
    AddMonth   '在cboMonth下拉列表框中添加月份
    AddDate    '在cbodate下拉列表框中添加日期
    Do While Not rsRooms.BOF And Not rsRooms.EOF  '当rsRooms.BOF,rsRooms.EOF都为False 时
        cboRoomNo.AddItem rsRooms.Fields("房间号")  '在cboRoomNo 的下拉列表选项中加如当前的空闲房间号
        rsRooms.MoveNext   '移到下一条记录
        VacancyRoomNum = VacancyRoomNum + 1
    Loop
    rsRooms.Close
    If VacancyRoomNum = 0 Then   '如果没有空闲房间
        rsCustReserveInfo.AddNew
        labVacancyRoomNum.ForeColor = RGB(255, 0, 0) '设置标签的颜色为红色
        labVacancyRoomNum.Caption = "对不起,已经没有空闲房间!"
        txtCustName.Enabled = False
        txtCustAddress.Enabled = False
        txtCustPhoneNo.Enabled = False
        txtCustCreditNo.Enabled = False
        cboRoomNo.Enabled = False
        cboYear.Enabled = False
        cboMonth.Enabled = False
        cboDate.Enabled = False
        txtPrice.Enabled = False
        cmdOk.Enabled = False
    Else                            '如果有空闲房间
        labVacancyRoomNum.ForeColor = RGB(50, 220, 100) '设置标签的颜色
        labVacancyRoomNum.Caption = "目前有" & VacancyRoomNum & "个空闲房间"
        rsCustReserveInfo.AddNew '添加一条新记录
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    VacancyRoomNum = 0   '使空闲房间的个数为0
    cnnHotel.Close    '关闭连接
End Sub

Private Function ValidateRoomNo()  'ValidateRoomNo 用来验证输入的顾客预定房间号是否正确
    Dim i As Integer, wrong As Boolean
    ValidateRoomNo = False
    For i = 0 To VacancyRoomNum - 1
        If cboRoomNo.Text = cboRoomNo.List(i) Then    '如果cboRoomNo.Text的值是cboRoomNo的下拉列项
            ValidateRoomNo = True
            Exit Function      '如果输入的房间号正确则从函数中退出
        End If
    Next i
End Function

Private Sub AddYear()   '在cboYear 的下拉列表中添加年份
    Dim i As Integer
    cboYear.Text = Year(Date)    '获取当前年份
    For i = 0 To 9
        cboYear.AddItem Year(Date) + i
    Next i
End Sub

Private Sub AddMonth()  '在cboMonth 的下拉列表中添加月份
    Dim i As Integer
    For i = 1 To 12
        cboMonth.AddItem i
    Next i
    cboMonth.Text = Month(Date)   '获取当前月份
End Sub

Private Sub AddDate()
    Dim i As Integer, str As String, Leap As Boolean
    str = Year(Date)  '获取当前年份
    If (str Mod 4 = 0) And (str Mod 100 <> 0) Or (str Mod 400 = 0) Then  '如果当前年份为闰年
        Leap = True
    End If
    Select Case Val(Month(Date))
        Case 1, 3, 5, 7, 8, 10, 12
            For i = 1 To 31
                cboDate.AddItem i
            Next i
        Case 2
            If Leap Then   '如果是闰年
                For i = 1 To 29
                    cboDate.AddItem i
                Next i
            Else        '如果不是闰年
                For i = 1 To 28
                    cboDate.AddItem i
                Next i
            End If
        Case 4, 6, 9, 11
            For i = 1 To 30
                cboDate.AddItem i
            Next i
    End Select
    cboDate.Text = Day(Date)  '获取当前日期
End Sub

Private Function ValidateReserveDate() 'ValidateReserveDate 用来检查输入的客户预定日期是否正确
    Dim s
    s = Val(cboYear.Text)
    If s < Year(Date) Then    '如果输入年份小于当前年份
        ValidateReserveDate = True
        MsgBox "年份输入错误!", vbInformation, "请重新输入"
        cboYear.SetFocus
        Exit Function
    ElseIf Val(cboMonth.Text) < 1 Or Val(cboMonth.Text) > 12 Then '如果输入的月份是1月到12月之间的月份
        MsgBox "月份输入错误!", vbInformation, "请重新输入"
        cboMonth.SetFocus
        ValidateReserveDate = True
        Exit Function
    ElseIf ((s Mod 4 = 0) And (s Mod 100 <> 0) Or (s Mod 400 = 0)) And cboMonth.Text = 2 And Not (Val(cboDate.Text) > 1 And Val(cboDate.Text) < 29) Then '如果闰年,月份为2月且输入的日期不在1号到29号之间
        MsgBox "日期输入错误!", vbInformation, "请重新输入"
        cboDate.SetFocus
        ValidateReserveDate = True
        Exit Function
    ElseIf Not ((s Mod 4 = 0) And (s Mod 100 <> 0) Or (s Mod 400 = 0)) And cboMonth.Text = 2 And Not (Val(cboDate.Text) > 1 Or Val(cboDate.Text) < 28) Then '如果闰年,月份为2月且输入的日期不在1号到28号之间
        MsgBox "日期输入错误!", vbInformation, "请重新输入"
        cboDate.SetFocus
        ValidateReserveDate = True
        Exit Function
    ElseIf (cboMonth.Text = 1 Or cboMonth.Text = 3 Or cboMonth.Text = 5 Or cboMonth.Text = 7 Or cboMonth.Text = 8 Or cboMonth.Text = 10 Or cboMonth.Text = 12) And Not (cboDate.Text > 0 And cboDate.Text < 32) Then '如果月份为大且输入的日期号不在1号到31号之间
        MsgBox "日期输入错误!", vbInformation, "请重新输入"
        cboDate.SetFocus
        ValidateReserveDate = True
        Exit Function
    ElseIf (cboMonth.Text = 4 Or cboMonth.Text = 6 Or cboMonth.Text = 9 Or cboMonth.Text = 11) And Not (cboDate.Text > 0 And cboDate.Text < 31) Then  '如果月份为小且输入的日期号不在1号到30号之间
        MsgBox "日期输入错误!", vbInformation, "请重新输入"
        cboDate.SetFocus
        ValidateReserveDate = True
        Exit Function
    End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -