📄 guesterfindform.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>
/// Customer 的摘要说明。
/// </summary>
public class GuesterFindForm : System.Windows.Forms.Form
{
private string selectStr;
private SqlCommand sqlCommand1=null;
private SqlDataReader sqlDataReader1=null;
private SqlConnection sqlConnection1;
private DataSet ds= null;
HotelManage.CheckInManage clientCheck=new HotelManage.CheckInManage();
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textClientID;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnEmptyRoom;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public GuesterFindForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.sqlConnection1=new SqlConnection(HotelManage.util.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()
{
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.textClientID = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnSearch = new System.Windows.Forms.Button();
this.btnEmptyRoom = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
this.groupBox3.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// groupBox3
//
this.groupBox3.Controls.Add(this.groupBox1);
this.groupBox3.Controls.Add(this.groupBox2);
this.groupBox3.Location = new System.Drawing.Point(8, 8);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(632, 80);
this.groupBox3.TabIndex = 26;
this.groupBox3.TabStop = false;
//
// groupBox1
//
this.groupBox1.BackColor = System.Drawing.SystemColors.Window;
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(8, 16);
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.ForeColor = System.Drawing.SystemColors.Desktop;
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 = "";
//
// groupBox2
//
this.groupBox2.BackColor = System.Drawing.SystemColors.Window;
this.groupBox2.Controls.Add(this.button1);
this.groupBox2.Controls.Add(this.btnSearch);
this.groupBox2.Controls.Add(this.btnEmptyRoom);
this.groupBox2.Controls.Add(this.btnExit);
this.groupBox2.Location = new System.Drawing.Point(248, 16);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(360, 56);
this.groupBox2.TabIndex = 25;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "请选择操作";
//
// btnSearch
//
this.btnSearch.BackColor = System.Drawing.SystemColors.Window;
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.ForeColor = System.Drawing.SystemColors.InfoText;
this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSearch.Location = new System.Drawing.Point(40, 24);
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);
//
// btnEmptyRoom
//
this.btnEmptyRoom.BackColor = System.Drawing.SystemColors.Window;
this.btnEmptyRoom.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnEmptyRoom.ForeColor = System.Drawing.SystemColors.InfoText;
this.btnEmptyRoom.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnEmptyRoom.Location = new System.Drawing.Point(120, 24);
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);
//
// btnExit
//
this.btnExit.BackColor = System.Drawing.SystemColors.Window;
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnExit.ForeColor = System.Drawing.SystemColors.InfoText;
this.btnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnExit.Location = new System.Drawing.Point(192, 24);
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);
//
// dataGrid1
//
this.dataGrid1.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.dataGrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 96);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(632, 240);
this.dataGrid1.TabIndex = 27;
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(264, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 23;
this.button1.Text = "结算";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// GuesterFindForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(642, 349);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox3);
this.Name = "GuesterFindForm";
this.Text = "客户记录查询";
this.groupBox3.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
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 CustomerID 客户ID,CustomerName 客户姓名,RoomID 房间号,RoomTypeName 房间类型,Price 价钱,InDate 入住日期,CheckDate 结算日期,TotalMoney 总金额 from View1_CustomerRecord where CustomerID="+"'"+this.textClientID.Text+"'";
FillDataGrid(selectStr);
}
}
private void FillDataGrid(string sql)
{
if(this.sqlConnection1.State==ConnectionState.Closed)this.sqlConnection1.Open();
Console.WriteLine(sql);
SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlConnection1);
ds = new DataSet("t_user");
adapter.Fill(ds,"t_user");
this.dataGrid1.SetDataBinding(ds,"t_user");
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnEmptyRoom_Click(object sender, System.EventArgs e)
{
this.selectStr="select CustomerID 客户ID,CustomerName 客户姓名,RoomID 房间号,RoomTypeName 房间类型,Price 价钱,InDate 入住日期,CheckDate 结算日期,TotalMoney 总金额 from View1_CustomerRecord";
this.FillDataGrid(this.selectStr);
}
private void button1_Click(object sender, System.EventArgs e)
{
float price=Convert.ToSingle(this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,4].ToString());
System.DateTime bookinDate=Convert.ToDateTime(this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,5].ToString());
System.TimeSpan timespan=System.DateTime.Now.Date.Subtract(bookinDate.Date);
int days=timespan.Days;
float totalmoney=days*price;
CheckInForm clientcheck=new CheckInForm(totalmoney);
clientcheck.ShowDialog();
float ftotal=clientcheck.FactTotalMoney;
string clientID=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,0].ToString();
string roomID=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,2].ToString();
CheckInManage cim=new CheckInManage();
if(cim.ClientCheck(clientID,roomID,bookinDate.ToString(),ftotal)==true)
{
//this.selectStr="select * from View1_CustomerRecord where CustomerID="+"'"+clientID+"'";
this.FillDataGrid(this.selectStr);
}
else
{
MessageBox.Show("有误");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -