📄 roomstatus.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
namespace 酒店管理系统
{
/// <summary>
/// RoomStatus 的摘要说明。
/// </summary>
public class RoomStatus : System.Windows.Forms.Form
{
private DataTable roomTable;//一个空的4行16列的表
private DataTable statusTable=new DataTable();//保存客房信息
private int formType=0;//确定窗体是用于显示房态还是选择房间,以及由哪个窗体调用选择房间
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.RadioButton rb1;
private System.Windows.Forms.RadioButton rb2;
private System.Windows.Forms.RadioButton rb3;
private System.Windows.Forms.RadioButton rb4;
private System.Windows.Forms.RadioButton rb5;
private System.Windows.Forms.RadioButton rb6;
private System.Windows.Forms.Button btnModify;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox cmb1;
private System.ComponentModel.IContainer components;
public RoomStatus(int useType)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
formType=useType;//由构造函数参数确定是否为双击选择房间而用
//formType=0代表正常房态图显示,1表示由客房预定窗体调用,2表示由客房入住窗体调用
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(RoomStatus));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.cmb1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.txt1 = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.rb1 = new System.Windows.Forms.RadioButton();
this.rb2 = new System.Windows.Forms.RadioButton();
this.rb3 = new System.Windows.Forms.RadioButton();
this.rb4 = new System.Windows.Forms.RadioButton();
this.rb5 = new System.Windows.Forms.RadioButton();
this.rb6 = new System.Windows.Forms.RadioButton();
this.btnRefresh = new System.Windows.Forms.Button();
this.btnModify = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.dataGrid1);
this.groupBox1.Location = new System.Drawing.Point(144, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(576, 400);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "房态显示";
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.ColumnHeadersVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.PreferredColumnWidth = 32;
this.dataGrid1.PreferredRowHeight = 32;
this.dataGrid1.ReadOnly = true;
this.dataGrid1.RowHeadersVisible = false;
this.dataGrid1.RowHeaderWidth = 32;
this.dataGrid1.Size = new System.Drawing.Size(560, 368);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseUp);
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(32, 32);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.cmb1);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Controls.Add(this.txt1);
this.groupBox2.Controls.Add(this.groupBox3);
this.groupBox2.Controls.Add(this.btnRefresh);
this.groupBox2.Controls.Add(this.btnModify);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Location = new System.Drawing.Point(0, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(144, 400);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "控制区";
//
// cmb1
//
this.cmb1.Location = new System.Drawing.Point(40, 72);
this.cmb1.Name = "cmb1";
this.cmb1.Size = new System.Drawing.Size(96, 20);
this.cmb1.TabIndex = 7;
this.cmb1.SelectionChangeCommitted += new System.EventHandler(this.cmb1_SelectionChangeCommitted);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 50);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 14);
this.label1.TabIndex = 6;
this.label1.Text = "房号";
//
// txt1
//
this.txt1.Location = new System.Drawing.Point(40, 48);
this.txt1.Name = "txt1";
this.txt1.ReadOnly = true;
this.txt1.Size = new System.Drawing.Size(96, 21);
this.txt1.TabIndex = 5;
this.txt1.Text = "";
this.txt1.DoubleClick += new System.EventHandler(this.txt1_DoubleClick);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.rb1);
this.groupBox3.Controls.Add(this.rb2);
this.groupBox3.Controls.Add(this.rb3);
this.groupBox3.Controls.Add(this.rb4);
this.groupBox3.Controls.Add(this.rb5);
this.groupBox3.Controls.Add(this.rb6);
this.groupBox3.Location = new System.Drawing.Point(8, 96);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(128, 272);
this.groupBox3.TabIndex = 4;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "房态选择";
//
// rb1
//
this.rb1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb1.ImageIndex = 2;
this.rb1.ImageList = this.imageList1;
this.rb1.Location = new System.Drawing.Point(24, 24);
this.rb1.Name = "rb1";
this.rb1.Size = new System.Drawing.Size(84, 32);
this.rb1.TabIndex = 3;
this.rb1.Text = "空房";
//
// rb2
//
this.rb2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb2.ImageIndex = 4;
this.rb2.ImageList = this.imageList1;
this.rb2.Location = new System.Drawing.Point(24, 64);
this.rb2.Name = "rb2";
this.rb2.Size = new System.Drawing.Size(84, 32);
this.rb2.TabIndex = 3;
this.rb2.Text = "住房";
//
// rb3
//
this.rb3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb3.ImageIndex = 5;
this.rb3.ImageList = this.imageList1;
this.rb3.Location = new System.Drawing.Point(24, 104);
this.rb3.Name = "rb3";
this.rb3.Size = new System.Drawing.Size(84, 32);
this.rb3.TabIndex = 3;
this.rb3.Text = "自用";
//
// rb4
//
this.rb4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb4.ImageIndex = 3;
this.rb4.ImageList = this.imageList1;
this.rb4.Location = new System.Drawing.Point(24, 144);
this.rb4.Name = "rb4";
this.rb4.Size = new System.Drawing.Size(84, 32);
this.rb4.TabIndex = 3;
this.rb4.Text = "维修";
//
// rb5
//
this.rb5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb5.ImageIndex = 0;
this.rb5.ImageList = this.imageList1;
this.rb5.Location = new System.Drawing.Point(24, 184);
this.rb5.Name = "rb5";
this.rb5.Size = new System.Drawing.Size(84, 32);
this.rb5.TabIndex = 3;
this.rb5.Text = "将到";
//
// rb6
//
this.rb6.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.rb6.ImageIndex = 1;
this.rb6.ImageList = this.imageList1;
this.rb6.Location = new System.Drawing.Point(24, 224);
this.rb6.Name = "rb6";
this.rb6.Size = new System.Drawing.Size(84, 32);
this.rb6.TabIndex = 3;
this.rb6.Text = "将离";
//
// btnRefresh
//
this.btnRefresh.Location = new System.Drawing.Point(24, 16);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(96, 23);
this.btnRefresh.TabIndex = 3;
this.btnRefresh.Text = "刷新房态信息";
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// btnModify
//
this.btnModify.Location = new System.Drawing.Point(24, 372);
this.btnModify.Name = "btnModify";
this.btnModify.Size = new System.Drawing.Size(88, 23);
this.btnModify.TabIndex = 3;
this.btnModify.Text = "更改房间状态";
this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 75);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(31, 14);
this.label2.TabIndex = 6;
this.label2.Text = "类型";
//
// RoomStatus
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 413);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "RoomStatus";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "房态管理";
this.Load += new System.EventHandler(this.RoomStatus_Load);
this.Activated += new System.EventHandler(this.RoomStatus_Activated);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//---------窗体初始化时的处理-------
private void RoomStatus_Load(object sender, System.EventArgs e)
{
if(this.formType!=0)
{
groupBox1.Text+=" 双击左边的【房号】文本框选择房间";
}
dataGrid1.Paint+=new PaintEventHandler(dataGrid1_Paint);
this.DataGridStateControl();
this.AutoSizeGrid();
this.RefreshStatus("select * from 客房信息");//读入所有类型房间的数据
//读入所有客房的类型
cmb1.Items.Clear();
cmb1.Items.Add("全部");
string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hotelbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="select distinct 类型名称 from 客房类型";
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
cmb1.Items.Add(dr.GetValue(0).ToString().Trim());
}
//焦点集中到【房号】文本框上
txt1.Focus();
}
//----------设置dataGrid中的行宽度--------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -