📄 kfinfo.cs
字号:
"套房",
"双人间",
"总统套房"});
this.cblx.Location = new System.Drawing.Point(272, 8);
this.cblx.Name = "cblx";
this.cblx.Size = new System.Drawing.Size(100, 20);
this.cblx.TabIndex = 42;
//
// cbft
//
this.cbft.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbft.Items.AddRange(new object[] {
"空闲",
"入住",
"维修"});
this.cbft.Location = new System.Drawing.Point(272, 33);
this.cbft.Name = "cbft";
this.cbft.Size = new System.Drawing.Size(100, 20);
this.cbft.TabIndex = 42;
//
// kfinfo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 181);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.fjh);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.label7);
this.Controls.Add(this.cblx);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.cbft);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(384, 208);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(384, 208);
this.Name = "kfinfo";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "客房信息维护";
this.Load += new System.EventHandler(this.kfinfo_Load);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void kfinfo_Load(object sender, System.EventArgs e)
{
textBox6.Text ="";
textBox2.Text ="";
textBox4.Text ="";
textBox5.Text ="";
buttforward.Enabled =false;
buttfirst.Enabled =false;
buttback.Enabled =false;
buttsave.Enabled =false;
buttappend.Enabled =true;
buttdelete.Enabled =true;
buttmodify.Enabled =true;
textBox6.Visible =false;
textBox1.Visible =true;
textBox3.Visible =true;
textBox1.ReadOnly =true;
textBox2.ReadOnly =true;
textBox3.ReadOnly =true;
textBox4.ReadOnly =true;
textBox5.ReadOnly =true;
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
string sql="select 房间号 from tabkfinfo";
SqlDataAdapter adapter=new SqlDataAdapter (sql,conn);
DataSet dataset=new DataSet ();
adapter.Fill (dataset,"tab");
this.fjh .DisplayMember ="房间号";
this.fjh .DataSource =dataset.Tables ["tab"];
dataset.Dispose ();
adapter.Dispose ();
conn.Dispose ();
}
private void fjh_SelectedIndexChanged(object sender, System.EventArgs e)
{
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
string sql="select * from tabkfinfo where 房间号='"+this.fjh .Text +"'";
string sql1="select * from tabkfinfo";
SqlDataAdapter adapter=new SqlDataAdapter (sql,conn);
SqlDataAdapter adapter1=new SqlDataAdapter (sql1,conn);
DataSet dataset=new DataSet ();
adapter.Fill (dataset,"tab");
adapter1.Fill (dataset,"cou");
num=dataset.Tables ["cou"].Rows.Count ;
this.textBox1 .DataBindings.Add (new Binding ("Text",dataset,"tab.客房类型"));
this.textBox2 .DataBindings.Add (new Binding ("Text",dataset,"tab.价格"));
this.textBox3 .DataBindings.Add (new Binding ("Text",dataset,"tab.房态"));
this.textBox4 .DataBindings.Add (new Binding ("Text",dataset,"tab.配置"));
this.textBox5 .DataBindings.Add (new Binding ("Text",dataset,"tab.备注"));
//释放所有绑定
this.textBox1 .DataBindings .Clear ();
this.textBox2 .DataBindings .Clear ();
this.textBox3 .DataBindings .Clear ();
this.textBox4 .DataBindings .Clear ();
this.textBox5 .DataBindings .Clear ();
buttnext.Enabled =true;
buttlast.Enabled =true;
buttforward.Enabled =true;
buttfirst.Enabled =true;
if(fjh.SelectedIndex==0)
{
buttforward.Enabled =false;
buttfirst.Enabled =false;
}
if(fjh.SelectedIndex ==(num-1))
{
buttnext.Enabled =false;
buttlast.Enabled =false;
}
dataset.Dispose ();
adapter.Dispose ();
conn.Dispose ();
}
private void button10_Click(object sender, System.EventArgs e)
{
textBox1.Visible =false;
textBox3.Visible =false;
cblx.Visible =true;
cbft.Visible =true;
this.operchoice =1;
textBox6.Visible =true;
fjh.Text ="";
textBox1.Text ="";
textBox2.Text ="";
textBox3.Text ="";
textBox4.Text ="";
textBox5.Text ="";
textBox1.ReadOnly =false;
textBox2.ReadOnly =false;
textBox3.ReadOnly =false;
textBox4.ReadOnly =false;
textBox5.ReadOnly =false;
buttforward.Enabled =false;
buttfirst.Enabled =false;
buttnext.Enabled =false;
buttlast.Enabled =false;
buttdelete.Enabled =false;
buttmodify.Enabled =false;
buttsave.Enabled =true;
buttback.Enabled =true;
}
private void button9_Click(object sender, System.EventArgs e)
{
operchoice =2;
buttforward.Enabled =false;
buttfirst.Enabled =false;
buttnext.Enabled =false;
buttlast.Enabled =false;
buttappend.Enabled =false;
buttmodify.Enabled =false;
buttsave.Enabled =true;
buttback.Enabled =true;
}
private void button4_Click(object sender, System.EventArgs e)
{
fjh.SelectedIndex =num-1;
}
private void buttexit_Click(object sender, System.EventArgs e)
{
if(MessageBox.Show("真的要退出吗?","注意",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
this.Close ();
}
private void buttfirst_Click(object sender, System.EventArgs e)
{
fjh.SelectedIndex =0;
}
private void buttforward_Click(object sender, System.EventArgs e)
{
fjh.SelectedIndex =fjh.SelectedIndex -1;
}
private void buttnext_Click(object sender, System.EventArgs e)
{
fjh.SelectedIndex =fjh.SelectedIndex +1;
}
private void buttmodify_Click(object sender, System.EventArgs e)
{
cblx.Text =textBox1.Text ;
cbft.Text =textBox3.Text ;
operchoice =3;
buttforward.Enabled =false;
buttfirst.Enabled =false;
buttnext.Enabled =false;
buttlast.Enabled =false;
buttappend.Enabled =false;
buttdelete.Enabled =false;
buttsave.Enabled =true;
buttback.Enabled =true;
textBox1.ReadOnly =false;
textBox2.ReadOnly =false;
textBox3.ReadOnly =false;
textBox4.ReadOnly =false;
textBox5.ReadOnly =false;
textBox1.Visible =false;
textBox3.Visible =false;
cblx.Visible =true;
cbft.Visible =true;
}
private void buttsave_Click(object sender, System.EventArgs e)
{
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
if(operchoice==1)
{
string sql="insert into tabkfinfo values(";
sql=sql+"'"+textBox6.Text +"',";
sql=sql+"'"+cblx.Text +"',";
sql=sql+"'"+textBox2.Text +"',";
sql=sql+"'"+cbft.Text +"',";
sql=sql+"'"+textBox4.Text +"',";
sql=sql+"'"+textBox5.Text +"')";
SqlCommand cmd=new SqlCommand (sql,conn);
if(textBox6.Text .Length >0&cblx.Text .Length >0&cbft.Text .Length >0&textBox2.Text .Length >0&textBox4.Text .Length >0)
{
try
{
conn.Open ();
cmd.ExecuteNonQuery ();
MessageBox.Show ("操作成功!","恭喜",MessageBoxButtons.OK ,MessageBoxIcon.Information);
}
catch
{
MessageBox.Show ("您的输入有误,请仔细检查,重新输入!","注意",MessageBoxButtons.OK ,MessageBoxIcon.Error );
}
}
else
{
MessageBox.Show ("您未输入完整,请仔细检查,重新输入!","注意",MessageBoxButtons.OK ,MessageBoxIcon.Error );
}
cmd.Dispose ();
conn.Close ();
}
//删除
if(operchoice==2)
{
string sql="delete tabkfinfo where 房间号='"+fjh.Text +"'";
SqlCommand cmd=new SqlCommand (sql,conn);
if(MessageBox.Show("真的要删除吗?","注意",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
try
{
conn.Open ();
cmd.ExecuteNonQuery ();
MessageBox.Show ("操作成功!","恭喜",MessageBoxButtons.OK ,MessageBoxIcon.Information);
}
catch
{
MessageBox.Show ("操作失败!");
}
string sql1="select 房间号 from tabkfinfo";
SqlDataAdapter adapter=new SqlDataAdapter (sql1,conn);
DataSet dataset=new DataSet ();
adapter.Fill (dataset,"tab");
this.fjh .DisplayMember ="房间号";
this.fjh .DataSource =dataset.Tables ["tab"];
dataset.Dispose ();
adapter.Dispose ();
}
cmd.Dispose ();
conn.Close ();
}
//修改
if(operchoice==3)
{
string sql="update tabkfinfo set 房间号='"+fjh.Text +"',客房类型='"+cblx.Text +"',价格='"+textBox2.Text +"',房态='"+cbft.Text +"',配置='"+textBox4.Text +"',备注='"+textBox5.Text +"' where 房间号='"+fjh.Text +"'";
SqlCommand cmd=new SqlCommand (sql,conn);
if(MessageBox.Show("真的所做的修改吗?","注意",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
try
{
conn.Open ();
cmd.ExecuteNonQuery ();
MessageBox.Show ("操作成功!","恭喜",MessageBoxButtons.OK ,MessageBoxIcon.Information);
}
catch
{
MessageBox.Show ("操作失败!");
}
}
cmd.Dispose ();
conn.Close ();
}
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
cblx.Text =textBox1.Text ;
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
cbft.Text =textBox3.Text ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -