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

📄 frmaddroom.frm

📁 数据库课程设计
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmAddRoom 
   Caption         =   "添加客房信息"
   ClientHeight    =   2850
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7635
   LinkTopic       =   "Form1"
   ScaleHeight     =   2850
   ScaleWidth      =   7635
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdAdd 
      Caption         =   "添加 (&A)"
      Height          =   375
      Left            =   2040
      TabIndex        =   8
      Top             =   2280
      Width           =   1215
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "取消 (&X)"
      Height          =   375
      Left            =   3720
      TabIndex        =   7
      Top             =   2280
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "客房信息"
      Height          =   1935
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   7215
      Begin VB.TextBox txtMemo 
         Height          =   1200
         Left            =   4440
         MaxLength       =   5
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   10
         Top             =   480
         Width           =   2535
      End
      Begin VB.ComboBox cboType 
         Height          =   315
         Left            =   1200
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   960
         Width           =   2175
      End
      Begin VB.TextBox txtName 
         Height          =   270
         Left            =   1200
         MaxLength       =   5
         TabIndex        =   2
         Top             =   480
         Width           =   2175
      End
      Begin VB.TextBox txtPrice 
         Enabled         =   0   'False
         Height          =   270
         Left            =   1200
         MaxLength       =   10
         TabIndex        =   1
         Top             =   1440
         Width           =   1692
      End
      Begin VB.Label Label1 
         Caption         =   "备       注:"
         Height          =   255
         Left            =   3600
         TabIndex        =   11
         Top             =   480
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "元/每天"
         Height          =   255
         Index           =   4
         Left            =   3000
         TabIndex        =   9
         Top             =   1440
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "房间类型:"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   6
         Top             =   960
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "房  间  号:"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   5
         Top             =   480
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "房间价格:"
         Height          =   255
         Index           =   3
         Left            =   240
         TabIndex        =   4
         Top             =   1440
         Width           =   975
      End
   End
End
Attribute VB_Name = "frmAddRoom"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public sqlStr As String
Public msgText As String



Private Sub cboType_Click()

    Dim rstType As ADODB.Recordset
 
    sqlStr = "select typename,price from roomtype where typename='" & Trim(cboType) & "'"
    Set rstType = ExecuteSQL(sqlStr, msgText)
    
    If Not rstType.EOF Then
        txtPrice = rstType!price
        
        cmdAdd.Enabled = True
    Else
        MsgBox "请先添加客房类型!", vbOKOnly + vbExclamation, "警告"
        cmdAdd.Enabled = False
        Exit Sub
    End If
    rstType.Close
    
    

End Sub


Private Sub cmdAdd_Click()
   Dim rstRoom As ADODB.Recordset
   Dim roomNo As String
   Dim roomType As String
   Dim roomPrice As String
   Dim roomMemo As String
   '获取数据
   roomNo = Trim(txtName.Text)
   roomType = Trim(cboType.Text)
   roomPrice = Trim(txtPrice.Text)
   roomMemo = Trim(txtMemo.Text)
   
   If roomNo = "" Then
   
      MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"

      Exit Sub
   
   End If
     
   
    '添加新记录
    sqlStr = "select * from roomInfo"
    Set rstRoom = ExecuteSQL(sqlStr, msgText)
    rstRoom.AddNew
    rstRoom.Fields("roomNO") = roomNo
    rstRoom.Fields("roomType") = roomType
    rstRoom.Fields("roomPrice") = roomPrice
    rstRoom.Fields("roomMemo") = roomMemo
    
    
    rstRoom.Update
    rstRoom.Close
    
        
    MsgBox "房间添加完成!", vbOKOnly + vbExclamation, "警告"
    
    initForm
    

End Sub

Private Sub cmdExit_Click()
Me.Visible = False

End Sub

Private Sub Form_Load()

'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2

initForm
               
End Sub

Sub initForm()
    Dim rstType As ADODB.Recordset
    
    txtName = ""
    txtPrice = ""
    txtMemo = ""
    cboType.Clear
    
    '初始化房间类型
    sqlStr = "select DISTINCT typename from roomtype"
    Set rstType = ExecuteSQL(sqlStr, msgText)
    
    If Not rstType.EOF Then
        
            Do While Not rstType.EOF
                cboType.AddItem Trim(rstType.Fields(0))
                rstType.MoveNext
            Loop
            cboType.ListIndex = 0
        
    Else
        MsgBox "请添加客房类型!", vbOKOnly + vbExclamation, "警告"
        cmdAdd.Enabled = False
        Exit Sub
    End If
    rstType.Close

End Sub

⌨️ 快捷键说明

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