Visual Basic 2010 数据库开发之酒店管理系统04预定管理

本文详细介绍了使用Visual Basic 2010进行酒店管理系统开发中的预定管理部分,包括如何设计数据库交互、实现预定流程及用户界面操作,旨在帮助开发者理解数据库应用开发的基本技巧。
摘要由CSDN通过智能技术生成

Imports System.Data.SqlClient
Public Class frmYuDing
    Dim flag As String = ""

    Private Sub SetControlDisable()
        GroupBox1.Enabled = False
    End Sub
    Private Sub SetControlEnable()
        GroupBox1.Enabled = True
    End Sub
    Private Sub SetControlEmpty()
        txtName.Text = ""
        cmbSex.Text = ""
        txtPhone.Text = ""
        cmbLeiXing.Text = ""
        cmbBianHao.Text = ""
        txtDays.Text = ""
        txtCount.Text = ""
    End Sub
    Private Sub SetControlDebug()
        txtName.Text = "李雷"
        cmbSex.Text = "男"
        txtPhone.Text = "13688888888"
        cmbLeiXing.Text = "套房"
        cmbBianHao.Text = "2001"
        txtDays.Text = "2"
        txtCount.Text = "1"
    End Sub

    Dim conn As SqlConnection = GetConnection()
    Dim strSql As String = "Select * From 预定信息"
    Dim myda As New SqlDataAdapter(strSql, conn)
    Dim mydt As DataTable
    Dim mydv As DataView
    Dim bmdata As CurrencyManager
    Private Sub FillDataAndView()
        mydt = New DataTable
        myda.Fill(mydt)
        mydv = New DataView(mydt)
        bmdata = Me.BindingContext(mydv)
    End Sub

    Private Sub BindFields()
        txtName.DataBindings.Clear()
        cmbSex.DataBindings.Clear()
        txtPhone.DataBindings.Clear()
        cmbLeiXing.DataBindings.Clear()
        cmbBianHao.DataBindings.Clear()
        DateTimePicker1.DataBindings.Clear()
        DateTimePicker2.DataBindings.Clear()
        txtDays.DataBindings.Clear()
        txtCount.DataBindings.Clear()

        txtName.DataBindings.Add("text", mydv, "姓名")
        cmbSex.DataBindings.Add("text", mydv, "性别")
        txtPhone.DataBindings.Add("text", mydv, "电话号码")
        cmbLeiXing.DataBindings.Add("text", mydv, "房间类型")
        cmbBianHao.DataBindings.Add("text", mydv, "房间编号")
        DateTimePicker1.DataBindings.Add("value", mydv, "预定日期")
        DateTimePicker2.DataBindings.Add("value", mydv, "抵店日期")
        txtDays.DataBindings.Add("text", mydv, "预定天数")
        txtCount.DataBindings.Add("text", mydv, "预定人数")
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim intIndex As Integer = e.RowIndex
        Try
            txtName.Text = DataGridView1.Rows(intIndex).Cells(0).Value
            cmbSex.Text = DataGridView1.Rows(intIndex).Cells(2).Value
            txtPhone.Text = DataGridView1.Rows(intIndex).Cells(3).Value
            cmbLeiXing.Text = DataGridView1.Rows(intIndex).Cells(4).Value
            cmbBianHao.Text = DataGridView1.Rows(intIndex).Cells(5).Value
            DateTimePicker1.Value = DataGridView1.Rows(intIndex).Cells(6).Value
            DateTimePicker2.Value = DataGridView1.Rows(intIndex).Cells(7).Value
            txtDays.Text = DataGridView1.Rows(intIndex).Cells(8).Value
            txtCount.Text = DataGridView1.Rows(intIndex).Cells(9).Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmYuDing_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        Me.Close()
        frmMain.Show()
    End Sub

    Private Sub frmYuDing_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetControlDisable()

        FillDataAndView()
        BindFields()

        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        DataGridView1.DataSource = mydt
    End Sub

 
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        flag = "Add"
        SetControlEnable()
        'SetControlEmpty()
        SetControlDebug()
    End Sub

    Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click
        flag = "modify"
        SetControlEnable
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim conn As SqlConnection = GetConnection()
        conn.Open()
        If flag = "Add" Then
            Dim strSql As String = _
                "Insert into 预定信息 " _
              & "Values(@姓名,@性别,@电话号码,@房间类型,@房间编号,@预定日期,@抵店日期," _
              & "@预定天数,@预定人数)"
            Dim comm As New SqlCommand(strSql, conn)
            comm.CommandType = CommandType.Text
            comm.Parameters.AddWithValue("@姓名", txtName.Text)
            comm.Parameters.AddWithValue("@性别", cmbSex.Text)
            comm.Parameters.AddWithValue("@电话号码", txtPhone.Text)
            comm.Parameters.AddWithValue("@房间类型", cmbLeiXing.Text)
            comm.Parameters.AddWithValue("@房间编号", cmbBianHao.Text)
            comm.Parameters.AddWithValue("@预定日期", DateTimePicker1.Value)
            comm.Parameters.AddWithValue("@抵店日期", DateTimePicker2.Value)
            comm.Parameters.AddWithValue("@预定天数", txtDays.Text)
            comm.Parameters.AddWithValue("@预定人数", txtCount.Text)
            comm.ExecuteNonQuery()

        ElseIf flag = "modify" Then
            Dim strSql As String = _
                "Update 预定信息 " _
              & "Set 姓名=@姓名,性别=@性别,电话号码=@电话号码,房间类型=@房间类型," _
              & "房间编号=@房间编号,预定日期=@预定日期,抵店日期=@抵店日期," _
              & "预定天数=@预定天数,预定人数=@预定人数 " _
              & "Where 姓名='{0}'"
            strSql = String.Format(strSql, txtName.Text)
            Dim comm As New SqlCommand(strSql, conn)
            comm.CommandType = CommandType.Text
            comm.Parameters.AddWithValue("@姓名", txtName.Text)
            comm.Parameters.AddWithValue("@性别", cmbSex.Text)
            comm.Parameters.AddWithValue("@电话号码", txtPhone.Text)
            comm.Parameters.AddWithValue("@房间类型", cmbLeiXing.Text)
            comm.Parameters.AddWithValue("@房间编号", cmbBianHao.Text)
            comm.Parameters.AddWithValue("@预定日期", DateTimePicker1.Value)
            comm.Parameters.AddWithValue("@抵店日期", DateTimePicker2.Value)
            comm.Parameters.AddWithValue("@预定天数", txtDays.Text)
            comm.Parameters.AddWithValue("@预定人数", txtCount.Text)
            comm.ExecuteNonQuery()

        Else
            Exit Sub
        End If
        conn.Close()
        SetControlDisable()

        FillDataAndView()
        BindFields()

        DataGridView1.DataSource = mydt
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        Dim intPosition As Integer
        intPosition = Me.BindingContext(mydv).Position - 1

        If MessageBox.Show("确定删除吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = DialogResult.Yes Then

            If intPosition < 0 Then
                intPosition = 0
            End If

            Dim conn As SqlConnection = GetConnection()
            conn.Open()
            Dim strSql As String = _
                "DELETE FROM 预定信息 " _
              & "WHERE 姓名=@姓名"
            Dim comm As SqlCommand = New SqlCommand(strSql, conn)
            comm.CommandType = CommandType.Text
            comm.Parameters.AddWithValue _
                ("@姓名", BindingContext(mydv).Current("姓名").ToString)
            comm.ExecuteNonQuery()

            conn.Close()

        End If
        Me.BindingContext(mydv).Position = intPosition

        FillDataAndView()
        BindFields()

        DataGridView1.DataSource = mydt
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
        frmMain.Show()
    End Sub
End Class

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ngbshzhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值