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

📄 clientsearch.cs

📁 宾馆信息管理系统: 采用C#编写
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Data;
using System.Data.SqlClient;


namespace HotelManage
{
	/// <summary>
	/// Client 的摘要说明。
	/// </summary>
	public class ClientSearch : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnEmptyRoom;
		private System.Windows.Forms.Button btnSearch;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		private System.Windows.Forms.ColumnHeader columnHeader4;
		private System.Windows.Forms.ColumnHeader columnHeader5;
		private System.Windows.Forms.ColumnHeader columnHeader6;
		private System.Windows.Forms.ColumnHeader columnHeader7;
		private System.Windows.Forms.ColumnHeader columnHeader8;
		private System.Windows.Forms.TextBox textClientID;
		private string selectStr;
		private SqlCommand sqlCommand1=null;
		private SqlDataReader sqlDataReader1=null;
		private SqlConnection sqlConnection1;
		private System.Windows.Forms.Button btnCheck;
		HotelManage.ClientCheckManage clientCheck=new HotelManage.ClientCheckManage();
		private System.Windows.Forms.Button btnInRoom;

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

		public ClientSearch()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.sqlConnection1=new SqlConnection(HotelManage.Connection.ConnString);
			this.sqlCommand1=new SqlCommand();
			this.sqlCommand1.Connection=this.sqlConnection1;

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClientSearch));
			this.btnInRoom = new System.Windows.Forms.Button();
			this.btnCheck = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnEmptyRoom = new System.Windows.Forms.Button();
			this.btnSearch = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.textClientID = new System.Windows.Forms.TextBox();
			this.listView1 = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnInRoom
			// 
			this.btnInRoom.BackColor = System.Drawing.Color.LightGray;
			this.btnInRoom.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnInRoom.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnInRoom.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnInRoom.Location = new System.Drawing.Point(432, 424);
			this.btnInRoom.Name = "btnInRoom";
			this.btnInRoom.Size = new System.Drawing.Size(56, 24);
			this.btnInRoom.TabIndex = 23;
			this.btnInRoom.Text = "在住";
			this.btnInRoom.Click += new System.EventHandler(this.btnInRoom_Click);
			// 
			// btnCheck
			// 
			this.btnCheck.BackColor = System.Drawing.Color.LightGray;
			this.btnCheck.Enabled = false;
			this.btnCheck.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnCheck.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnCheck.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnCheck.Location = new System.Drawing.Point(512, 384);
			this.btnCheck.Name = "btnCheck";
			this.btnCheck.Size = new System.Drawing.Size(56, 24);
			this.btnCheck.TabIndex = 21;
			this.btnCheck.Text = "结帐";
			this.btnCheck.Click += new System.EventHandler(this.btnCheck_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(512, 424);
			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);
			// 
			// btnEmptyRoom
			// 
			this.btnEmptyRoom.BackColor = System.Drawing.Color.LightGray;
			this.btnEmptyRoom.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnEmptyRoom.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnEmptyRoom.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnEmptyRoom.Location = new System.Drawing.Point(360, 424);
			this.btnEmptyRoom.Name = "btnEmptyRoom";
			this.btnEmptyRoom.Size = new System.Drawing.Size(56, 24);
			this.btnEmptyRoom.TabIndex = 22;
			this.btnEmptyRoom.Text = "全部";
			this.btnEmptyRoom.Click += new System.EventHandler(this.btnEmptyRoom_Click);
			// 
			// btnSearch
			// 
			this.btnSearch.BackColor = System.Drawing.Color.LightGray;
			this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnSearch.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnSearch.Location = new System.Drawing.Point(432, 384);
			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);
			// 
			// btnCancel
			// 
			this.btnCancel.BackColor = System.Drawing.Color.LightGray;
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnCancel.Location = new System.Drawing.Point(360, 384);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(56, 23);
			this.btnCancel.TabIndex = 16;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textClientID);
			this.groupBox1.ForeColor = System.Drawing.SystemColors.Desktop;
			this.groupBox1.Location = new System.Drawing.Point(56, 376);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(232, 56);
			this.groupBox1.TabIndex = 23;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "输入查询条件";
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.White;
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 25);
			this.label1.TabIndex = 1;
			this.label1.Text = "客户号";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textClientID
			// 
			this.textClientID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textClientID.Location = new System.Drawing.Point(64, 24);
			this.textClientID.Multiline = true;
			this.textClientID.Name = "textClientID";
			this.textClientID.Size = new System.Drawing.Size(136, 20);
			this.textClientID.TabIndex = 0;
			this.textClientID.Text = "";
			// 
			// listView1
			// 
			this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						this.columnHeader1,
																						this.columnHeader2,
																						this.columnHeader3,
																						this.columnHeader4,
																						this.columnHeader5,
																						this.columnHeader6,
																						this.columnHeader7,
																						this.columnHeader8});
			this.listView1.ForeColor = System.Drawing.SystemColors.Desktop;
			this.listView1.FullRowSelect = true;
			this.listView1.GridLines = true;
			this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.listView1.Location = new System.Drawing.Point(8, 8);
			this.listView1.MultiSelect = false;
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(618, 353);
			this.listView1.TabIndex = 24;
			this.listView1.View = System.Windows.Forms.View.Details;
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "客户ID";
			this.columnHeader1.Width = 100;
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "客户姓名";
			// 
			// columnHeader3
			// 
			this.columnHeader3.Text = "房间号";
			// 
			// columnHeader4
			// 
			this.columnHeader4.Text = "房间类型";
			// 
			// columnHeader5
			// 
			this.columnHeader5.Text = "价钱";
			// 
			// columnHeader6
			// 
			this.columnHeader6.Text = "入住日期";
			this.columnHeader6.Width = 100;
			// 
			// columnHeader7
			// 
			this.columnHeader7.Text = "结算日期";
			this.columnHeader7.Width = 100;
			// 
			// columnHeader8
			// 
			this.columnHeader8.Text = "总金额";
			this.columnHeader8.Width = 70;
			// 
			// ClientSearch
			// 
			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.groupBox1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnSearch);
			this.Controls.Add(this.btnEmptyRoom);
			this.Controls.Add(this.btnInRoom);
			this.Controls.Add(this.btnCheck);
			this.Controls.Add(this.btnExit);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ClientSearch";
			this.Text = "客户记录查询";
			this.Load += new System.EventHandler(this.ClientSearch_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			if(this.textClientID.Text=="")
			{
				MessageBox.Show("请先输入客户号","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
			}
			else
			{
				this.selectStr="select * from View1_ClientRecord where ClientID="+"'"+this.textClientID.Text+"'";			
				this.UpdateListView(this.selectStr);
			}
		  
		
		}
		private void UpdateListView(string selectstr)
		{
			this.listView1.Items.Clear();
			this.listView1.Refresh();			
			this.sqlCommand1.CommandText=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["ClientID"].ToString ( ); 
					li.SubItems.Add ( sqlDataReader1["ClientName"].ToString ( ) );;
					li.SubItems.Add ( sqlDataReader1["RoomID"].ToString ( ) ) ;
					li.SubItems.Add ( sqlDataReader1["RoomTypeName"].ToString ( ) ) ;
					li.SubItems.Add ( sqlDataReader1["Price"].ToString ( ) ) ;
					li.SubItems.Add ( sqlDataReader1["InDate"].ToString ( ) ) ;					
					li.SubItems.Add (sqlDataReader1["CheckDate"].ToString ( ) );
					li.SubItems.Add (sqlDataReader1["TotalMoney"].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);
				return;
			}
			else
			{
				this.listView1.Items[0].Selected=true;
			}
		}

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

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.textClientID.Clear();
		}

		private void btnEmptyRoom_Click(object sender, System.EventArgs e)
		{
			this.selectStr="select * from View1_ClientRecord";			
			this.UpdateListView(this.selectStr);
		
		}

		private void btnCheck_Click(object sender, System.EventArgs e)
		{
			int i;
			for(i=0;i<this.listView1.Items.Count;i++)
			{
				if(this.listView1.Items[i].Selected==true)
					break;
			}
			float price=Convert.ToSingle(this.listView1.Items[i].SubItems[4].Text);
			System.DateTime bookinDate=Convert.ToDateTime(this.listView1.Items[i].SubItems[5].Text);
			System.TimeSpan timespan=System.DateTime.Now.Date.Subtract(bookinDate.Date);
			int days=timespan.Days;
			float totalmoney=days*price;
			ClientCheck clientcheck=new ClientCheck(totalmoney);
			clientcheck.ShowDialog();
			float facttotalmoney=clientcheck.FactTotalMoney;
			string clientID=this.listView1.Items[i].SubItems[0].Text;
			string roomID=this.listView1.Items[i].SubItems[2].Text;			
			if(this.clientCheck.ClientCheck(clientID,roomID,bookinDate.ToString(),facttotalmoney)==true)
			{
			
				this.selectStr="select * from View1_ClientRecord where ClientID="+"'"+clientID+"'";
				this.UpdateListView(this.selectStr);			
			}
			else
			{
				MessageBox.Show("有误");
			}
			this.btnCheck.Enabled=false;
			
		}

		private void btnInRoom_Click(object sender, System.EventArgs e)
		{
			this.selectStr="select * from View1_ClientRecord where TotalMoney=0";
			this.UpdateListView(this.selectStr);
			this.btnCheck.Enabled=true;
		}

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

⌨️ 快捷键说明

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