110,545
社区成员
发帖
与我相关
我的任务
分享
string sqlstr = "insert into lkinfo (outtime) values('" + OutTime + "') where outtime = '" + OutTimeDb + "' and room_id = '" + Room_id + "' and LKName = '" + LkName + "'";
private void button1_Click(object sender, EventArgs e)
{
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
if (comboBox1.Text == "")
{
MessageBox.Show("请选择需要退房的房号,否则无法退房!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
string Constr = "server=(local);Integrated Security=true;database=userdb";
SqlConnection SqlCon = new SqlConnection(Constr);
string Room_id = comboBox1.SelectedItem.ToString();
string OutTime = textBox1.Text;
string LkName = textBox2.Text;
string OutTimeDb = null;
if (OutTime == "")
{
MessageBox.Show("请输入退房时间,否则无法退房!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (LkName == "")
{
MessageBox.Show("请输入登记入住的旅客姓名,否则无法退房!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
SqlDataReader dr;
SqlCon.Open();
SqlCommand cmd = new SqlCommand("select * from lkinfo where room_id = '"
+ Room_id + "'and LKName = '" + LkName + "' and outtime = '" + OutTimeDb + "'", SqlCon);
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
//Room_id = null;
OutTimeDb = null;
//LkName = null;
if (dr.Read())
{
Room_id = dr["room_id"].ToString();
OutTimeDb = dr["outtime"].ToString();
LkName = dr["LKName"].ToString();
}
SqlCon.Close();
if (LkName != null && OutTimeDb != null && Room_id != null)
{
MessageBox.Show("您要退的房间本身就是空房间,无法退房!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string sqlstr = "update lkinfo set outtime = '" + OutTime + "' where LKName = '" + LkName + "' and room_id = '" + Room_id + "' and outtime = '" + OutTimeDb + "'";
SqlCon.Open();
SqlCommand cmd1 = SqlCon.CreateCommand();
cmd1.CommandText = sqlstr;
int result = cmd1.ExecuteNonQuery();
MessageBox.Show("退房成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboBox1.Text = "";
textBox1.Text = "";
this.Close();
}
}
catch (Exception ty)
{
MessageBox.Show(ty.Message);
}
}
"UPDATE lkinfo SET outtime='" + OutTime + "'
where outtime = '" + OutTimeDb + "' and room_id = '" + Room_id + "' and LKName = '" + LkName + "'";
//insert into A a,b,c,d select a,b,c,d from B where a<=b
string sqlstr = "insert into lkinfo outtime select outtime from lkinfo where outtime = '" + OutTimeDb + "' and room_id = '" + Room_id + "' and LKName = '" + LkName + "'";
insert into A
a,b,c,d
select a,b,c,d
from B
where a<=b