gpt4 book ai didi

c# - 禁用复选框时不应进行更新

转载 作者:太空狗 更新时间:2023-10-29 21:53:43 24 4
gpt4 key购买 nike

我有两个页面,一个是管理员页面,另一个是教职工页面。管理员将主题分配给教师。教师只想选择所需的时间。我的问题是我不想对禁用的复选框执行更新查询。我试过下面的代码,但它也在更新禁用复选框。

  using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString))
{
foreach (GridViewRow r in Gv1.Rows){
if ((((
(((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour1"))).Checked == true
|| ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour1"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour2"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour2"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour3"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour3"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour4"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour4"))).Checked == false)
|| (((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour5"))).Checked == true || ((CheckBox)(Gv1.Rows[r.RowIndex].FindControl("chkHour5"))).Checked == false)
))))
{
SqlCommand comm;
CheckBox aa;
bool hour1 = (r.FindControl("chkHour1") as CheckBox).Checked;
bool hour2 = (r.FindControl("chkHour2") as CheckBox).Checked;
bool hour3 = (r.FindControl("chkHour3") as CheckBox).Checked;
bool hour4 = (r.FindControl("chkHour4") as CheckBox).Checked;
bool hour5 = (r.FindControl("chkHour5") as CheckBox).Checked;
string subject1 = ddlsubj.SelectedValue;
string subject2 = ddlsubj.SelectedValue;
string subject3 = ddlsubj.SelectedValue;
string subject4 = ddlsubj.SelectedValue;
string subject5 = ddlsubj.SelectedValue;
string datedif = r.Cells[0].Text;
aa=(CheckBox)sender;
con2.Open();
comm = new SqlCommand();
comm.Connection = con2;
comm.CommandType = CommandType.Text;
if (aa.Enabled==false)
{
comm = new SqlCommand("UPDATE test
SET aa=false
when subject1=CASE WHEN (@hour1)= 'false' THEN NULL
ELSE @subject1 END,
subject2=CASE WHEN (@hour2)= 'false' THEN NULL
ELSE @subject2 END,
subject3=CASE WHEN (@hour3)= 'false' THEN NULL
ELSE @subject3 END,
subject4=CASE WHEN (@hour4)= 'false' THEN NULL
ELSE @subject4 END,
subject5=CASE WHEN (@hour5)='false' THEN NULL
ELSE @subject5 END,
hour1 = CASE WHEN (@hour1)= 'false' THEN 'false'
ELSE 'true' END,
hour2 = CASE WHEN (@hour2)= 'false' THEN 'false'
ELSE 'true' END,
hour3 = CASE WHEN (@hour3)= 'false' THEN 'false'
ELSE 'true' END ,
hour4 = CASE WHEN (@hour4)= 'false' THEN 'false'
ELSE 'true' END ,
hour5 = CASE WHEN (@hour5)= 'false' THEN 'false'
ELSE 'true' END where datedif=@datedif", con2);
}
else
{
comm = new SqlCommand("update test set aa=true
when subject1=CASE WHEN (@hour1)= 'false' THEN NULL
ELSE @subject1 END,
subject2=CASE WHEN (@hour2)= 'false' THEN NULL
ELSE @subject2 END,
subject3=CASE WHEN (@hour3)= 'false' THEN NULL
ELSE @subject3 END,
subject4=CASE WHEN (@hour4)= 'false' THEN NULL
ELSE @subject4 END,
subject5=CASE WHEN (@hour5)='false' THEN NULL
ELSE @subject5 END,
hour1 = CASE WHEN (@hour1)= 'false' THEN 'false'
ELSE 'true' END,
hour2 = CASE WHEN (@hour2)= 'false' THEN 'false'
ELSE 'true' END,
hour3 = CASE WHEN (@hour3)= 'false' THEN 'false'
ELSE 'true' END ,
hour4 = CASE WHEN (@hour4)= 'false' THEN 'false'
ELSE 'true' END ,
hour5 = CASE WHEN (@hour5)= 'false' THEN 'false'
ELSE 'true' END where datedif=@datedif", con2);
}
comm.Parameters.AddWithValue("@subject1",subject1);
comm.Parameters.AddWithValue("@subject2", subject2);
comm.Parameters.AddWithValue("@subject3", subject3);
comm.Parameters.AddWithValue("@subject4", subject4);
comm.Parameters.AddWithValue("@subject5", subject5);
comm.Parameters.AddWithValue("@hour1", hour1);
comm.Parameters.AddWithValue("@datedif", datedif);
comm.Parameters.AddWithValue("@hour2", hour2);
comm.Parameters.AddWithValue("@hour3", hour3);
comm.Parameters.AddWithValue("@hour4", hour4);
comm.Parameters.AddWithValue("@hour5", hour5);
comm.ExecuteNonQuery();
con2.Close();
}
}
}

最佳答案

您可能希望先删除 IF 语句,因为它不需要。正如其他人所说,它正在检查 true OR (||) false 并且它将始终为 true。

其次,看不到任何检查 .Enabled == False 的地方这可能正是您正在寻找的。

关于c# - 禁用复选框时不应进行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30319411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com