📄 zscx.cs
字号:
this.dg.ForeColor = System.Drawing.Color.MidnightBlue;
this.dg.GridLineColor = System.Drawing.Color.RoyalBlue;
this.dg.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dg.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.dg.HeaderForeColor = System.Drawing.Color.Lavender;
this.dg.LinkColor = System.Drawing.Color.Teal;
this.dg.Location = new System.Drawing.Point(8, 80);
this.dg.Name = "dg";
this.dg.ParentRowsBackColor = System.Drawing.Color.Lavender;
this.dg.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dg.ReadOnly = true;
this.dg.SelectionBackColor = System.Drawing.Color.Teal;
this.dg.SelectionForeColor = System.Drawing.Color.PaleGreen;
this.dg.Size = new System.Drawing.Size(368, 160);
this.dg.TabIndex = 20;
//
// zscx
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(480, 283);
this.Name = "zscx";
this.Text = "住宿查询";
this.Load += new System.EventHandler(this.zscx_Load);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dg)).EndInit();
} #endregion
DataConn dc=new DataConn ();
string opername;//传递操作员姓名
int order=0;//指示查询类型
private void zscx_Load(object sender, System.EventArgs e)
{
this.AcceptButton =this.button2 ;
this.label2 .Text ="查询日期:"+System.DateTime .Today.Date.ToShortDateString();
this.label1 .Text ="操 作 员:"+this.opername ;
this.tb .Visible =false;
this.dt.Visible =false;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.comboBox1.SelectedIndex==2)
{
this.dt.Visible =true;
this.tb.Visible =false;
}
if(this.comboBox1.SelectedIndex==0|this.comboBox1.SelectedIndex==1)
{
this.dt.Visible =false;
this.tb.Visible =true;
}
if(this.comboBox1 .SelectedIndex ==3)
{
this.dt.Visible =false;
this.tb.Visible =false;
}
}
private void comboBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.comboBox1 .Text ="";
}
private void button2_Click(object sender, System.EventArgs e)
{
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
DataSet dataset=new DataSet ();
int order1=0;
//查询已结帐的所有记录
if((order==1&this.comboBox1 .Text =="")|(this.rb1 .Checked ==true&(this.comboBox1 .SelectedIndex ==3)))
{
order1=1;
string sql1="select * from tabdjb where 是否结帐='1'";
SqlDataAdapter a1=new SqlDataAdapter (sql1,conn);
a1.Fill (dataset,"t1");
}
//查询未结帐的所有记录
if((order==2&this.comboBox1 .Text =="")|(this.rb2 .Checked ==true&(this.comboBox1 .SelectedIndex ==3)))
{
order1=2;
string sql2="select * from tabdjb where 是否结帐='0'";
SqlDataAdapter a2=new SqlDataAdapter (sql2,conn);
a2.Fill (dataset,"t2");
}
//查询所有记录
if((order==3&this.comboBox1 .Text =="")|(this.rb3 .Checked ==true&(this.comboBox1 .SelectedIndex ==3)))
{
order1=3;
string sql3="select * from tabdjb";
SqlDataAdapter a3=new SqlDataAdapter (sql3,conn);
a3.Fill (dataset,"t3");
}
//按姓名查询已结帐记录
if(order==1&this.comboBox1.SelectedIndex==0)
{
order1=4;
string sql4="select * from tabdjb where 是否结帐='1'and 姓名='"+this.tb .Text +"'";
SqlDataAdapter a4=new SqlDataAdapter (sql4,conn);
a4.Fill (dataset,"t4");
}
//按姓名查询未结帐记录
if(order==2&this.comboBox1.SelectedIndex==0)
{
order1=5;
string sql5="select * from tabdjb where 是否结帐='0'and 姓名='"+this.tb .Text +"'";
SqlDataAdapter a5=new SqlDataAdapter (sql5,conn);
a5.Fill (dataset,"t5");
}
//按姓名查询所有记录
if(order==3&this.comboBox1.SelectedIndex==0)
{
order1=6;
string sql6="select * from tabdjb where 姓名='"+this.tb .Text +"'";
SqlDataAdapter a6=new SqlDataAdapter (sql6,conn);
a6.Fill (dataset,"t6");
}
//按证件号码查询已结帐记录
if(order==1&this.comboBox1.SelectedIndex==1)
{
order1=7;
string sql7="select * from tabdjb where 是否结帐='1'and 证件号码='"+this.tb .Text +"'";
SqlDataAdapter a7=new SqlDataAdapter (sql7,conn);
a7.Fill (dataset,"t7");
}
//按证件号码查询未结帐记录
if(order==2&this.comboBox1.SelectedIndex==1)
{
order1=8;
string sql8="select * from tabdjb where 是否结帐='0'and 证件号码='"+this.tb .Text +"'";
SqlDataAdapter a8=new SqlDataAdapter (sql8,conn);
a8.Fill (dataset,"t8");
}
//按证件号码查询所有记录
if(order==3&this.comboBox1.SelectedIndex==1)
{
order1=9;
string sql9="select * from tabdjb where 证件号码='"+this.tb .Text +"'";
SqlDataAdapter a9=new SqlDataAdapter (sql9,conn);
a9.Fill (dataset,"t9");
}
//按住宿日期查询已结帐记录
if(order==1&this.comboBox1.SelectedIndex==2)
{
order1=10;
string sql10="select * from tabdjb where 是否结帐='1'and 住宿日期='"+this.dt.Value .ToShortDateString ()+"'";
SqlDataAdapter a10=new SqlDataAdapter (sql10,conn);
a10.Fill (dataset,"t10");
}
//按住宿日期查询未结帐记录
if(order==2&this.comboBox1.SelectedIndex==2)
{
order1=11;
string sql11="select * from tabdjb where 是否结帐='0'and 住宿日期='"+this.dt.Value .ToShortDateString ()+"'";
SqlDataAdapter a11=new SqlDataAdapter (sql11,conn);
a11.Fill (dataset,"t11");
}
//按住宿日期查询所有记录
if(order==3&this.comboBox1.SelectedIndex==2)
{
order1=12;
string sql12="select * from tabdjb where 住宿日期='"+this.dt.Value .ToShortDateString ()+"'";
SqlDataAdapter a12=new SqlDataAdapter (sql12,conn);
a12.Fill (dataset,"t12");
}
switch(order1)
{
case 1:
dg.DataSource =dataset.Tables ["t1"];
break;
case 2:
dg.DataSource =dataset.Tables ["t2"];
break;
case 3:
dg.DataSource =dataset.Tables ["t3"];
break;
case 4:
dg.DataSource =dataset.Tables ["t4"];
break;
case 5:
dg.DataSource =dataset.Tables ["t5"];
break;
case 6:
dg.DataSource =dataset.Tables ["t6"];
break;
case 7:
dg.DataSource =dataset.Tables ["t7"];
break;
case 8:
dg.DataSource =dataset.Tables ["t8"];
break;
case 9:
dg.DataSource =dataset.Tables ["t9"];
break;
case 10:
dg.DataSource =dataset.Tables ["t10"];
break;
case 11:
dg.DataSource =dataset.Tables ["t11"];
break;
case 12:
dg.DataSource =dataset.Tables ["t12"];
break;
}
dataset.Dispose ();
conn.Dispose ();
}
private void rb1_Click(object sender, System.EventArgs e)
{
order=1;
}
private void rb2_Click(object sender, System.EventArgs e)
{
order=2;
}
private void rb3_Click(object sender, System.EventArgs e)
{
order=3;
}
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -