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

📄 frm_roominfo.cs

📁 酒店管理,主要从事酒店管理都可以.这可是北大青鸟的程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.Odbc;
using System.Text.RegularExpressions;


namespace HotelApp
{
	/// <summary>
	/// frm_roomInfo 的摘要说明。
	/// </summary>
	public class frm_roomInfo : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cb_roomtype;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox tb_roomNum;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox tb_roomPrice;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox tb_canelDate;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Button b_Excute;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button b_ReSet;
		//
		private frmRoomQuery frmMain;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label8;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frm_roomInfo(frmRoomQuery main)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			this.frmMain=main;
		}

		/// <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.label1 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.cb_roomtype = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.tb_roomNum = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.tb_roomPrice = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.tb_canelDate = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.b_Excute = new System.Windows.Forms.Button();
			this.b_ReSet = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("楷体_GB2312", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(64, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(136, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "新增客房信息";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 56);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 24);
			this.label3.TabIndex = 6;
			this.label3.Text = "客房类型:";
			// 
			// cb_roomtype
			// 
			this.cb_roomtype.Location = new System.Drawing.Point(104, 48);
			this.cb_roomtype.Name = "cb_roomtype";
			this.cb_roomtype.Size = new System.Drawing.Size(88, 20);
			this.cb_roomtype.TabIndex = 7;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 96);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(72, 23);
			this.label4.TabIndex = 8;
			this.label4.Text = "客房数量:";
			// 
			// tb_roomNum
			// 
			this.tb_roomNum.Location = new System.Drawing.Point(104, 88);
			this.tb_roomNum.Name = "tb_roomNum";
			this.tb_roomNum.Size = new System.Drawing.Size(88, 21);
			this.tb_roomNum.TabIndex = 9;
			this.tb_roomNum.Text = "";
			this.tb_roomNum.TextChanged += new System.EventHandler(this.tb_roomNum_TextChanged);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 136);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 10;
			this.label5.Text = "客房价格:";
			// 
			// tb_roomPrice
			// 
			this.tb_roomPrice.Location = new System.Drawing.Point(104, 128);
			this.tb_roomPrice.Name = "tb_roomPrice";
			this.tb_roomPrice.Size = new System.Drawing.Size(88, 21);
			this.tb_roomPrice.TabIndex = 11;
			this.tb_roomPrice.Text = "";
			this.tb_roomPrice.TextChanged += new System.EventHandler(this.tb_roomPrice_TextChanged);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(24, 176);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(32, 23);
			this.label6.TabIndex = 12;
			this.label6.Text = "提前";
			// 
			// tb_canelDate
			// 
			this.tb_canelDate.Location = new System.Drawing.Point(64, 168);
			this.tb_canelDate.Name = "tb_canelDate";
			this.tb_canelDate.Size = new System.Drawing.Size(32, 21);
			this.tb_canelDate.TabIndex = 13;
			this.tb_canelDate.Text = "";
			this.tb_canelDate.TextChanged += new System.EventHandler(this.tb_canelDate_TextChanged);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(104, 176);
			this.label7.Name = "label7";
			this.label7.TabIndex = 14;
			this.label7.Text = "天取消客房预定";
			// 
			// b_Excute
			// 
			this.b_Excute.Location = new System.Drawing.Point(24, 216);
			this.b_Excute.Name = "b_Excute";
			this.b_Excute.Size = new System.Drawing.Size(56, 23);
			this.b_Excute.TabIndex = 15;
			this.b_Excute.Text = "确定(&Y)";
			this.b_Excute.Click += new System.EventHandler(this.b_Excute_Click);
			// 
			// b_ReSet
			// 
			this.b_ReSet.Location = new System.Drawing.Point(104, 216);
			this.b_ReSet.Name = "b_ReSet";
			this.b_ReSet.Size = new System.Drawing.Size(56, 23);
			this.b_ReSet.TabIndex = 16;
			this.b_ReSet.Text = "重写(&R)";
			this.b_ReSet.Click += new System.EventHandler(this.b_ReSet_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(200, 48);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 23);
			this.button1.TabIndex = 17;
			this.button1.Text = "新增(&A)";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(184, 216);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(56, 23);
			this.btnExit.TabIndex = 18;
			this.btnExit.Text = "退出(&X)";
			this.btnExit.Click += new System.EventHandler(this.button2_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(200, 96);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 19;
			this.label2.Text = "间";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(200, 136);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(48, 23);
			this.label8.TabIndex = 20;
			this.label8.Text = "元/间";
			// 
			// frm_roomInfo
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(272, 261);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.b_ReSet);
			this.Controls.Add(this.b_Excute);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.tb_canelDate);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.tb_roomPrice);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.tb_roomNum);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.cb_roomtype);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frm_roomInfo";
			this.Text = "新增客房信息";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frm_roomInfo_Closing);
			this.Load += new System.EventHandler(this.frm_roomInfo_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void frm_roomInfo_Load(object sender, System.EventArgs e)
		{
			bindData();
		}

		private void bindData()
		{
			string tempStr="";
			DBService_2 mycon=new DBService_2();
			DataSet tempds=mycon.executeBySQL("select roomtype from guestroom where hotelID='"+GlobalVars.temp_ID+"'");
			
			if(tempds.Tables[0].Rows.Count>0)
			{
				tempStr=" where typeid not in (";
				for(int i=0;i<tempds.Tables[0].Rows.Count;i++)
				{
					if(i!=0)
					{
						tempStr+=","+tempds.Tables[0].Rows[i][0];
					}	
					else
					{
						tempStr+=tempds.Tables[0].Rows[i][0];
					}

				}
				tempStr+=")";
			}


			DataSet ds=mycon.executeBySQL("select typeid,typename from roomtype"+tempStr);
			this.cb_roomtype.DisplayMember="typename";
			this.cb_roomtype.ValueMember="typeid";
			this.cb_roomtype.DataSource=ds.Tables[0].DefaultView;
		}
		private void button1_Click(object sender, System.EventArgs e)
		{
			frm_roomType ff=new frm_roomType();
			ff.ShowDialog();
			bindData();	
		}

		private void b_Excute_Click(object sender, System.EventArgs e)
		{
			int hotelID=Convert.ToInt32(GlobalVars.temp_ID);
			int typeid=Convert.ToInt32(this.cb_roomtype.SelectedValue);
			DBService_2 mycon=new DBService_2();
			System.Data.Odbc.OdbcTransaction tran;
			OdbcConnection conn=mycon.getCon();
		    OdbcCommand comm=new OdbcCommand();
			comm.Connection=conn;
			conn.Open();
			tran=conn.BeginTransaction();
			comm.Transaction=tran;			
			try
			{				
				if (this.tb_roomNum.Text=="" || this.tb_canelDate.Text=="" || this.tb_roomPrice.Text=="")
				{
					throw new Exception("请把信息填完整!");
				}								
				comm.CommandText="INSERT INTO guestroom(hotelID,roomType,roomNum,roomPrice,cancelDate) VALUES(?,?,?,?,?)";
				comm.Parameters.Clear();
				comm.Parameters.Add("0",hotelID);
				comm.Parameters.Add("1",typeid);
				comm.Parameters.Add("2",this.tb_roomNum.Text);
				comm.Parameters.Add("3",this.tb_roomPrice.Text);
				comm.Parameters.Add("4",this.tb_canelDate.Text);
			    int	query=comm.ExecuteNonQuery();
				tran.Commit();
				MessageBox.Show("保存成功!");
				this.tb_roomNum.Text="";
				this.tb_canelDate.Text="";
				this.tb_roomPrice.Text="";
				this.cb_roomtype.Text="";
			}
			catch(Exception es)
			{
				MessageBox.Show(es.Message);
				tran.Rollback();
			}		
		}

		private void tb_roomNum_TextChanged(object sender, System.EventArgs e)
		{	
			ValueIsInt(this.tb_roomNum,"^[0-9]+$");
		}

		private void tb_roomPrice_TextChanged(object sender, System.EventArgs e)
		{
		ValueIsInt(this.tb_roomPrice,"^[0-9]+(\\.\\d{0,2})?$");
		}

		private void tb_canelDate_TextChanged(object sender, System.EventArgs e)
		{

		ValueIsInt(this.tb_canelDate,"^[0-9]+$");
		}

		private void b_ReSet_Click(object sender, System.EventArgs e)
		{
			this.tb_roomNum.Text="";
			this.tb_canelDate.Text="";
			this.tb_roomPrice.Text="";
			this.cb_roomtype.Text="";
			this.cb_roomtype.Focus();
		}

		private void frm_roomInfo_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			this.frmMain.Show();
		}

		private void ValueIsInt(TextBox tb,string str)
		{
			bool b=Regex.IsMatch(tb.Text,str);
			int len=tb.Text.Length;	
			if (!b && len>0)
			{						
				tb.Text=tb.Text.Remove(len-1,1);
				tb.SelectionStart=len-1;				
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}		
	}
}

⌨️ 快捷键说明

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