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

📄 room.cs

📁 宾馆信息管理系统: 采用C#编写
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(56, 24);
			this.btnSave.TabIndex = 17;
			this.btnSave.Text = "保存";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnExit
			// 
			this.btnExit.BackColor = System.Drawing.Color.LightGray;
			this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnExit.Location = new System.Drawing.Point(456, 280);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(56, 23);
			this.btnExit.TabIndex = 15;
			this.btnExit.Text = "退出";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnStart
			// 
			this.btnStart.BackColor = System.Drawing.Color.LightGray;
			this.btnStart.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnStart.Location = new System.Drawing.Point(384, 17);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(56, 23);
			this.btnStart.TabIndex = 23;
			this.btnStart.Text = "开始";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// label7
			// 
			this.label7.BackColor = System.Drawing.Color.White;
			this.label7.Location = new System.Drawing.Point(104, 16);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(72, 25);
			this.label7.TabIndex = 22;
			this.label7.Text = "输入房间号";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textSearch
			// 
			this.textSearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textSearch.Location = new System.Drawing.Point(184, 18);
			this.textSearch.Multiline = true;
			this.textSearch.Name = "textSearch";
			this.textSearch.Size = new System.Drawing.Size(68, 20);
			this.textSearch.TabIndex = 21;
			this.textSearch.Text = "";
			// 
			// btnSearch
			// 
			this.btnSearch.BackColor = System.Drawing.Color.LightGray;
			this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnSearch.Location = new System.Drawing.Point(280, 16);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(56, 24);
			this.btnSearch.TabIndex = 20;
			this.btnSearch.Text = "查找";
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			// 
			// btnDelete
			// 
			this.btnDelete.BackColor = System.Drawing.Color.LightGray;
			this.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnDelete.Location = new System.Drawing.Point(176, 280);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.Size = new System.Drawing.Size(56, 23);
			this.btnDelete.TabIndex = 19;
			this.btnDelete.Text = "删除";
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// btnNew
			// 
			this.btnNew.BackColor = System.Drawing.Color.LightGray;
			this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnNew.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnNew.Location = new System.Drawing.Point(96, 280);
			this.btnNew.Name = "btnNew";
			this.btnNew.Size = new System.Drawing.Size(56, 23);
			this.btnNew.TabIndex = 18;
			this.btnNew.Text = "新建";
			this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
			// 
			// Room
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.White;
			this.ClientSize = new System.Drawing.Size(642, 466);
			this.Controls.Add(this.listView1);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnNew);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.btnDelete);
			this.Controls.Add(this.btnSearch);
			this.Controls.Add(this.btnStart);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.textSearch);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Room";
			this.Text = "客房信息管理";
			this.Load += new System.EventHandler(this.Room_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
	//	static void Main() 
	//	{
	//		Application.Run(new Room());
	//	}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void SearchControl(bool visible)
		{
			if(visible)
			{
				this.label7.Visible=true;
				this.textSearch.Visible=true;
				this.btnStart.Visible=true;
			}
			else
			{
				this.label7.Visible=false;
				this.textSearch.Visible=false;
				this.btnStart.Visible=false;
			}
		}


		private void Room_Load(object sender, System.EventArgs e)
		{			
			this.SearchControl(false);
			this.UpdateListView();
			
		}

		private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			
			for(int i=0;i<this.listView1.Items.Count;i++)
			{
				this.listView1.Items[i].BackColor=Color.White;
			}

			foreach(int i in this.listView1.SelectedIndices)
				{
					this.textRoomID.Text=this.listView1.Items[i].SubItems[0].Text.ToString();
					this.comboRoomType.Text=this.listView1.Items[i].SubItems[1].Text.ToString();
					this.comboRoomPosition.Text=this.listView1.Items[i].SubItems[2].Text.ToString();
					this.comboPeopleNum.Text=this.listView1.Items[i].SubItems[3].Text.ToString();
					this.comboBedNum.Text=this.listView1.Items[i].SubItems[4].Text.ToString();
					this.textRemark.Text=this.listView1.Items[i].SubItems[5].Text.ToString();
					this.listView1.Items[i].BackColor=Color.Silver;
				}			
			
			this.textRoomID.Refresh();
			this.comboRoomPosition.Refresh();
		
		}		

		private void btnNew_Click(object sender, System.EventArgs e)
		{
			this.add=true;
			this.textRoomID.Enabled=true;
			this.textRoomID.Clear();
			this.comboRoomPosition.Text="请选择";			
			this.comboBedNum.Text="请选择";
			this.comboPeopleNum.Text="请选择";
			this.comboRoomType.Text="请选择";	
			this.textRemark.Clear();		
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			this.textRoomID.Enabled=false;
			string roomid=this.textRoomID.Text;
			string roomtype=this.comboRoomType.Text;
			string roomposition=this.comboRoomPosition.Text;
			int bednum=Convert.ToInt32(this.comboBedNum.Text);
			int peoplenum=Convert.ToInt32(this.comboPeopleNum.Text);
			string roomremark=this.textRemark.Text;
			if(this.add)
			{
				//this.selectStr="insert into Room values("+"'"+this.textRoomID.Text+"',"+"'"+this.comboRoomType.Text+"',"+"'"+this.comboRoomPosition.Text+"',"+"'"+this.comboBedNum.Text+"',"+"'"+this.comboPeopleNum.Text+"',"+"'"+this.textRemark.Text+"'"+")";
				if(this.roomManage.Room_Add(roomid,roomtype,roomposition,bednum,peoplenum,roomremark)==true)
				{
					this.UpdateListView();
				}
				else
				{
					MessageBox.Show("添加新记录有误");
				}
				
			}
			else
			{
		//		this.selectStr="update Room set RoomType="+"'"+this.comboRoomType.Text+"',"+"RoomPosition="+"'"+this.comboRoomPosition.Text+"',"+"BedNum="+"'"+this.comboBedNum.Text+"',"+"PeopleNum="+"'"+this.comboPeopleNum.Text+"',"+"Remark="+"'"+this.textRemark.Text+"'"+" where RoomID="+this.textRoomID.Text;		
				if(this.roomManage.Room_Modify(roomid,roomtype,roomposition,bednum,peoplenum,roomremark)==true)
				{
					this.UpdateListView();
				}
				else
				{
					MessageBox.Show("保存记录有误");
				}				

			}
			this.add=false;
			/*this.sqlCommand1.CommandText=this.selectStr;			
			try
			{
				this.sqlConnection1.Open();
				this.sqlCommand1.ExecuteNonQuery();
				this.UpdateListView();
			}
			catch(System.Exception E)
			{
				MessageBox.Show(E.ToString());
			}
			finally
			{
				this.sqlConnection1.Close();
			}*/
			

		}

		private void UpdateListView()
		{
			this.listView1.Items.Clear();
			this.listView1.Refresh();
			this.selectStr="select * from Room";			
			this.sqlCommand1.CommandText=this.selectStr;			
			try
			{
				if(this.sqlConnection1.State==ConnectionState.Closed)this.sqlConnection1.Open();
				this.sqlDataReader1=this.sqlCommand1.ExecuteReader();
				while(this.sqlDataReader1.Read())
				{
					ListViewItem li = new ListViewItem ( ) ;
					li.SubItems.Clear ( ) ;
					li.SubItems[0].Text = sqlDataReader1["RoomID"].ToString ( ) ;
					li.SubItems.Add ( sqlDataReader1["RoomTypeName"].ToString ( ) ) ;
					li.SubItems.Add ( sqlDataReader1["RoomPosition"].ToString ( ) ) ;
					li.SubItems.Add (sqlDataReader1["BedNum"].ToString ( ) ) ;
					li.SubItems.Add (sqlDataReader1["PeopleNum"].ToString ( ) ) ;
					li.SubItems.Add ( sqlDataReader1["Remark"].ToString ( ) ) ;
					this.listView1.Items.Add ( li ) ;
				}
			}
			catch(System.Exception E)
			{
				MessageBox.Show(E.ToString());

			}
			finally
			{
				this.sqlDataReader1.Close();			
				this.sqlConnection1.Close();
			}	
			if(this.listView1.Items.Count==0)
			{
				MessageBox.Show("没有记录存在","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}

		private void TextChangeWithList(int i)
		{			
			this.textRoomID.Text=this.listView1.Items[i].SubItems[0].Text.ToString();
			this.comboRoomType.Text=this.listView1.Items[i].SubItems[1].Text.ToString();
			this.comboRoomPosition.Text=this.listView1.Items[i].SubItems[2].Text.ToString();
			this.comboPeopleNum.Text=this.listView1.Items[i].SubItems[3].Text.ToString();
			this.comboBedNum.Text=this.listView1.Items[i].SubItems[4].Text.ToString();
			this.textRemark.Text=this.listView1.Items[i].SubItems[5].Text.ToString();

		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{	
			int i;	
			if(MessageBox.Show("真的要删除吗?","删除记录",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{				
				for(i=0;i<this.listView1.Items.Count;i++)
				{
					if(this.listView1.Items[i].Selected==true)
						break;
				}

				if(this.roomManage.Room_Delete(this.textRoomID.Text)==true)
				{
					MessageBox.Show("删除成功");
					this.UpdateListView();
					if(i>this.listView1.Items.Count-1)
						i=0;
					this.listView1.Items[i].Selected=true;
				}
				else
				{
					MessageBox.Show("操作失误");
					return;
				}				
			}

			else
			{
				return;
			}

		}
		/*this.selectStr="delete from Room where RoomID="+"'"+this.textRoomID.Text+"'";
				this.sqlCommand1.CommandText=this.selectStr;
				try
				{
					this.sqlConnection1.Open();
					this.sqlCommand1.ExecuteNonQuery();
					this.UpdateListView();
				}
				catch(System.Exception E)
				{
					MessageBox.Show(E.ToString());
				}
				finally
				{
					this.sqlConnection1.Close();
				}*/

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			this.textSearch.Clear();
			this.SearchControl(true);
		}

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			
			for(int i=0;i<this.listView1.Items.Count;i++)
			{
				if(this.listView1.Items[i].SubItems[0].Text==this.textSearch.Text)
				{
					this.listView1.Items[i].Selected=true;
					this.SearchControl(false);
					return;
				}
			}
			MessageBox.Show("没有找到该记录","没有找到");		
		}
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.add=false;
			foreach(int i in this.listView1.SelectedIndices)
			{
                this.TextChangeWithList(i);				
				this.listView1.Items[i].BackColor=Color.Silver;
			}						
		
		}
	}
}

⌨️ 快捷键说明

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