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

📄 changeform.cs

📁 一个很好的宾馆管理系统 VC++和SQL做的
💻 CS
字号:
//文件名:ChangeForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyHotel
{
    public partial class ChangeForm : Form
    {
        public ChangeForm()
        {
            InitializeComponent();
        }

        private void ChangeForm_Load(object sender, EventArgs e)
        {
            SqlConnection MyConnection = new SqlConnection();
            MyConnection.ConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            MyConnection.Open();
            SqlCommand MyCommand = new SqlCommand("Select DISTINCT 类别  From 酒店房间", MyConnection);
            SqlDataReader MyReader = MyCommand.ExecuteReader();
            while (MyReader.Read())
            {
                this.酒店房间类别ComboBox.Items.Add(MyReader.GetString(0));
            }
            this.酒店房间类别ComboBox.Items.Add("所有房间");
            this.酒店房间类别ComboBox.Text = "所有房间";
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }            
        }

        private void 酒店房间类别ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取未完全入住房间信息
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            string MySQL = "Select 房号,单价,可容纳人数-已入住人数 as 可入住人数,楼层,类别,说明,可容纳人数,已入住人数 From 酒店房间 Where 类别='" + this.酒店房间类别ComboBox.Text + "'";
            if (this.酒店房间类别ComboBox.Text == "所有房间")
            {
                MySQL = "Select 房号,单价,可容纳人数-已入住人数 as 可入住人数,楼层,类别,说明,可容纳人数,已入住人数 From 酒店房间 ";
            }
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            DataTable MyTable = new DataTable();
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyTable);
            this.酒店客房信息DataGridView.DataSource = MyTable;
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            } 
        }

        private void 旅客登记信息Button_Click(object sender, EventArgs e)
        {
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            string MySQL = "Select * From 客房入住单 Where 入住编号 LIKE '" + this.入住编号TextBox.Text + "' AND 入住编号 NOT IN (Select 入住编号 FROM 客房结帐单)";
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            DataTable MyTable = new DataTable();
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyTable);
            this.客房入住单DataGridView.DataSource = MyTable;
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            } 
        }

        private void 根据当前选择换房Button_Click(object sender, EventArgs e)
        {
            int My住宿人数 = Convert.ToInt16(this.客房入住单DataGridView.CurrentRow.Cells[10].Value.ToString());
            int My可入住人数 = Convert.ToInt16(this.酒店客房信息DataGridView.CurrentRow.Cells[2].Value.ToString());
            if (My住宿人数 > My可入住人数)
            {
                MessageBox.Show("没有足够的床位进行换房操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string My入住编号 = this.客房入住单DataGridView.CurrentRow.Cells[0].Value.ToString();
            string My原房号 = this.客房入住单DataGridView.CurrentRow.Cells[1].Value.ToString();
            string My新房号 = this.酒店客房信息DataGridView.CurrentRow.Cells[0].Value.ToString();
            string MyInfo = "是否确定将" + My入住编号 + "中的客人从" + My原房号 + "号房换到" + My新房号 + "号房?";
            if (MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            SqlCommand MyCommand = MyConnection.CreateCommand();
            string MySQL = "Update 酒店房间 Set 已入住人数=已入住人数+" + My住宿人数 + " WHERE 房号='" + My新房号 + "';";
            MySQL += "Update 酒店房间 Set 已入住人数=已入住人数-" + My住宿人数 + " WHERE 房号='" + My原房号 + "';";
            MySQL += "Update 客房入住单 Set 房号='" + My新房号 + "' WHERE 入住编号='" + My入住编号 + "';";
            MyCommand.CommandText = MySQL;
            MyCommand.ExecuteNonQuery();
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            酒店房间类别ComboBox_SelectedIndexChanged(null, null);
            旅客登记信息Button_Click(null, null);
        }
       
    }
}

⌨️ 快捷键说明

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