?? selecttable.cs
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 酒店管理系統(tǒng)
{
/// <summary>
/// SelectTable 的摘要說明。
/// </summary>
public class SelectTable : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet ds;//數(shù)據(jù)集
private string sql;//用于讀取數(shù)據(jù)的SQL語句
private int formIndex;//標(biāo)示從哪個(gè)窗體中調(diào)用
/// <summary>
/// 必需的設(shè)計(jì)器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public SelectTable(string sqlStr,int Index)//修改構(gòu)造函數(shù)
{
//
// Windows 窗體設(shè)計(jì)器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
this.sql=sqlStr;//通過構(gòu)造函數(shù)傳入SQL語句
this.formIndex=Index;//讀入窗體標(biāo)示
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 0);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(552, 272);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.DoubleClick += new System.EventHandler(this.dataGrid1_DoubleClick);
//
// SelectTable
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 269);
this.Controls.Add(this.dataGrid1);
this.Name = "SelectTable";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SelectTable";
this.Load += new System.EventHandler(this.SelectTable_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
//-------根據(jù)構(gòu)造函數(shù)中的sql語句,讀入數(shù)據(jù)并顯示在表格中---------
private void SelectTable_Load(object sender, System.EventArgs e)
{
string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hotelbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(sql,cn);
da.Fill(ds);
dataGrid1.DataSource=ds.Tables[0];
}
//-------雙擊選擇一行,并將這一條預(yù)定單號(hào)返回到入住單中--------
private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
{
int i=dataGrid1.CurrentRowIndex;
if(formIndex==1)//向入住單中傳送預(yù)定單數(shù)據(jù)
HotelArrival.dRow=ds.Tables[0].Rows[i];
if(formIndex==2)//向消費(fèi)記帳窗體中傳送入住單編號(hào)
ClientConsume.RZid=dataGrid1[i,0].ToString().Trim();
this.Close();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -