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

📄 checkinform.cs

📁 一个很好的宾馆管理系统 VC++和SQL做的
💻 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 CheckInForm : Form
    {
        public CheckInForm()
        {
            InitializeComponent();
        }
        private void CheckInForm_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“myHotelDataSet.客房入住单”中。您可以根据需要移动或移除它。
            this.客房入住单TableAdapter.Fill(this.myHotelDataSet.客房入住单);
            //添加酒店房间类别ToolStripComboBox控件的列表项
            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.酒店房间类别ToolStripComboBox.Items.Add(MyReader.GetString(0));                
            }
            this.酒店房间类别ToolStripComboBox.Items.Add("所有房间");
            this.酒店房间类别ToolStripComboBox.Text="所有房间";                
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
        }
        ////记录当前操作用户的操作行为
        public string MyOperator;
        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.客房入住单TableAdapter.FillBy(this.myHotelDataSet.客房入住单, 入住编号ToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            //自动计算入住编号
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.CommandText = "Select max(入住编号) 最大编号 From 客房入住单";
            object MyResult = MyCommand.ExecuteScalar();
            Int64 MyID = 1;
            if (MyResult != System.DBNull.Value)
            {
                String MyMaxID = MyResult.ToString().Trim();
                MyMaxID = MyMaxID.Substring(2, MyMaxID.Length - 2);
                MyID = Convert.ToInt64(MyMaxID) + 1;
            }
            int MyLength = MyID.ToString().Length;
            string MyNewID = "";
            switch (MyLength)
            {
                case 1:
                    MyNewID = "RZ0000000" + MyID.ToString();
                    break;
                case 2:
                    MyNewID = "RZ000000" + MyID.ToString();
                    break;
                case 3:
                    MyNewID = "RZ00000" + MyID.ToString();
                    break;
                case 4:
                    MyNewID = "RZ0000" + MyID.ToString();
                    break;
                case 5:
                    MyNewID = "RZ000" + MyID.ToString();
                    break;
                case 6:
                    MyNewID = "RZ00" + MyID.ToString();
                    break;
                case 7:
                    MyNewID = "RZ0" + MyID.ToString();
                    break;
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            this.入住编号TextBox.Text = MyNewID;          
        }
        private bool UpdateRoomStatus()
        {//更新酒店房间的已入住人数信息
            int My可容纳人数 = 0;
            int My已入住人数 = 0;
            int My新入住人数 =0;
            int My单张入住单入住人数 = 0;
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            String MyQuerySQL = "Select 可容纳人数,已入住人数 From 酒店房间  Where 房号='" + this.房号TextBox.Text + "'";
            MyConnection.Open();
            DataTable MyTable = new DataTable();
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MyQuerySQL, MyConnection);
            MyAdapter.Fill(MyTable);
            if (MyTable.Rows.Count > 0)
            {
                My可容纳人数 = Convert.ToInt16(MyTable.Rows[0][0].ToString());
                My已入住人数 = Convert.ToInt16(MyTable.Rows[0][1].ToString());
            }
            MyQuerySQL = "Select 住宿人数 From 客房入住单  Where 入住编号='" + this.入住编号TextBox.Text + "'";
            MyTable = new DataTable();
            MyAdapter = new SqlDataAdapter(MyQuerySQL, MyConnection);
            MyAdapter.Fill(MyTable);
            if (MyTable.Rows.Count > 0)
            {
                My单张入住单入住人数 = Convert.ToInt16(MyTable.Rows[0][0].ToString());
            }
            My新入住人数 = My已入住人数 - My单张入住单入住人数 + Convert.ToInt16(this.住宿人数ComboBox.Text);
            if (My可容纳人数 < My新入住人数)
            {
                MessageBox.Show("已经超过房间的正常容纳能力,请注意检查!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }            
            string MyUpdateSQL = "Update 酒店房间 Set 已入住人数=" + My新入住人数.ToString() + " WHERE 房号='" + this.房号TextBox.Text + "'";
            SqlCommand MyCommand = new SqlCommand(MyUpdateSQL, MyConnection);
            MyCommand.ExecuteNonQuery();      
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            酒店房间类别ToolStripComboBox_SelectedIndexChanged(null, null);
            return true;
        }
        private void 客房入住单BindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            //更新酒店房间的已入住人数信息
            if (UpdateRoomStatus() == false)
            {
                return;
            }
            this.操作人员TextBox.Text = this.MyOperator;
            this.Validate();
            this.客房入住单BindingSource.EndEdit();
            this.客房入住单TableAdapter.Update(this.myHotelDataSet.客房入住单);
        }

        private void 酒店房间类别ToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取未完全入住房间信息
            this.酒店可用房间DataGridView.GridColor = Color.Blue;            
            String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
            string MySQL = "Select 房号,单价,可容纳人数-已入住人数 as 可入住人数,楼层,类别,说明,可容纳人数,已入住人数 From 酒店房间 Where 类别='" + this.酒店房间类别ToolStripComboBox.Text + "'";
            if (this.酒店房间类别ToolStripComboBox.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 打印入住单ToolStripButton_Click(object sender, EventArgs e)
        {
            this.printDialog1.Document = this.printDocument1;
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {
                this.printDocument1.Print();
            }
        }
        public string MyCompany;       
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {//打印入住单
            e.Graphics.DrawString(this.MyCompany+"旅客入住单", new Font("宋体", 20), Brushes.Black, 220, 80);
            e.Graphics.DrawString("入住编号:" + this.客房入住单DataGridView.CurrentRow.Cells[0].Value.ToString(), new Font("宋体", 12), Brushes.Black, 100, 150);
            DateTime MyPrintTime = DateTime.Now;
            e.Graphics.DrawString("打印日期:" + MyPrintTime.ToLongDateString() + MyPrintTime.ToLongTimeString(), new Font("宋体", 12), Brushes.Black, 450, 150);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 180, 720, 180);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 220, 720, 220);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 260, 720, 260);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 300, 720, 300);
            e.Graphics.DrawLine(new Pen(Color.Black), 100, 340, 720, 340);

            e.Graphics.DrawLine(new Pen(Color.Black), 100, 180, 100, 340);
            e.Graphics.DrawLine(new Pen(Color.Black), 220, 180, 220, 340);
            e.Graphics.DrawLine(new Pen(Color.Black), 400, 180, 400, 340);
            e.Graphics.DrawLine(new Pen(Color.Black), 720, 180, 720, 340);

            e.Graphics.DrawString("房号:" + this.客房入住单DataGridView.CurrentRow.Cells[1].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 190);
            e.Graphics.DrawString("姓名:" + this.客房入住单DataGridView.CurrentRow.Cells[6].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 230);
            e.Graphics.DrawString("性别:" + this.客房入住单DataGridView.CurrentRow.Cells[11].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 270);
            e.Graphics.DrawString("人数:" + this.客房入住单DataGridView.CurrentRow.Cells[10].Value.ToString(), new Font("宋体", 12), Brushes.Black, 105, 310);

            e.Graphics.DrawString("折扣价格:" + this.客房入住单DataGridView.CurrentRow.Cells[2].Value.ToString(), new Font("宋体", 12), Brushes.Black, 225, 190);
            e.Graphics.DrawString("预收押金:" + this.客房入住单DataGridView.CurrentRow.Cells[3].Value.ToString(), new Font("宋体", 12), Brushes.Black, 225, 230);
            if (this.客房入住单DataGridView.CurrentRow.Cells[4].Value.ToString().Length > 0)
            {
                e.Graphics.DrawString("入住日期:" + this.客房入住单DataGridView.CurrentRow.Cells[4].Value.ToString().Remove(10), new Font("宋体", 12), Brushes.Black, 225, 270);
            }
            if (this.客房入住单DataGridView.CurrentRow.Cells[5].Value.ToString().Length > 0)
            {
                e.Graphics.DrawString("离开日期:" + this.客房入住单DataGridView.CurrentRow.Cells[5].Value.ToString().Remove(10), new Font("宋体", 12), Brushes.Black, 225, 310);
            }
            e.Graphics.DrawString("证件名称:" + this.客房入住单DataGridView.CurrentRow.Cells[7].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 190);
            e.Graphics.DrawString("证件编号:" + this.客房入住单DataGridView.CurrentRow.Cells[8].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 230);
            e.Graphics.DrawString("证件地址:" + this.客房入住单DataGridView.CurrentRow.Cells[9].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 270);
            e.Graphics.DrawString("联系电话:" + this.客房入住单DataGridView.CurrentRow.Cells[12].Value.ToString(), new Font("宋体", 12), Brushes.Black, 405, 310);

            e.Graphics.DrawString("操作员:" + this.客房入住单DataGridView.CurrentRow.Cells[13].Value.ToString(), new Font("宋体", 12), Brushes.Black, 600, 350);

            e.Graphics.DrawString("温馨提示:为了维护您及他人的合法权益,请不要带未经登记的人员进出您的房间。", new Font("宋体", 12), Brushes.Black, 100, 380);
            e.Graphics.DrawString("警察提示:请保管好您的物品,重要物品请寄存于酒店寄存处,免费寄存!", new Font("宋体", 12), Brushes.Black, 100, 420);
            e.Graphics.DrawString("谢谢合作!", new Font("宋体", 20), Brushes.Black, 550, 460);
        }
        private void 酒店可用房间DataGridView_Click(object sender, EventArgs e)
        {//确定是否设置房号和住宿人数信息

            this.房号TextBox.Text = this.酒店可用房间DataGridView.CurrentRow.Cells[0].Value.ToString();
            int MyCount=Convert.ToInt16(this.酒店可用房间DataGridView.CurrentRow.Cells[2].Value.ToString());
            this.住宿人数ComboBox.Items.Clear();
            for(int i=1;i<=MyCount;i++)
            {
                this.住宿人数ComboBox.Items.Add(i.ToString());
            }
            this.住宿人数ComboBox.Text = MyCount.ToString();
        }

    
    }
}

⌨️ 快捷键说明

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