protected void btn_clear_Click(object sender, EventArgs e)
{
//删除某院系的一项分数
if (GridView1.Rows[0].Cells.Count > 1)
{
CheckBox checkBox;
Session["count"] = "";
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
checkBox = gridViewRow.FindControl("CheckBox1") as CheckBox;
if (checkBox.Checked)
{
Session["count"] = "check";
}
}
if (Session["count"].ToString() == "")
{
Response.Write("<script>alert('对不起,你没有选中任何记录,请进行选择!');history.go(-1);</script>");
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open();
int count1 = 0, count2 = 0;//count1为删除成功数,count2为删除未成功的数
for (int i = 0; i < GridView1.Rows.Count; i++)
{
checkBox = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
if (checkBox.Checked)
{
comm.Parameters.Clear();
//comm.CommandText = "delete from T_Score where Score_Faculty_id='" + GridView1.DataKeys[i].Value + "'";
comm.CommandText = "delete from T_Score where Score_Faculty_id=@Score_Faculty_id and Score_item_id=@Score_item_id and Score_semester=@Score_semester";
comm.Parameters.Add(new SqlParameter("Score_Faculty_id", Convert.ToInt32(GridView1.DataKeys[i].Value)));
comm.Parameters.Add(new SqlParameter("Score_item_id", Convert.ToInt64(DDL_evaluationItem.SelectedValue)));
comm.Parameters.Add(new SqlParameter("Score_semester", Convert.ToInt64(DDL_semester.SelectedValue)));
if (comm.ExecuteNonQuery() == 1)
{
count1 = count1 + 1;
}
else
{
count2 = count2 + 1;
}
}
}
conn.Close();
if (count2 != 0)
{
Response.Write("<script>alert('" + count2 + "条记录未成功删除!');history.go(-1);</script>");
}
else
{
Response.Write("<script>alert('成功删除" + count1 + "条记录!');location.href='SetScore_evaluationItem.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('对不起,没有数据可进行删除!');history.go(-1);</script>");
}
gridviewDataBind("all");
}
{
//删除某院系的一项分数
if (GridView1.Rows[0].Cells.Count > 1)
{
CheckBox checkBox;
Session["count"] = "";
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
checkBox = gridViewRow.FindControl("CheckBox1") as CheckBox;
if (checkBox.Checked)
{
Session["count"] = "check";
}
}
if (Session["count"].ToString() == "")
{
Response.Write("<script>alert('对不起,你没有选中任何记录,请进行选择!');history.go(-1);</script>");
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
conn.Open();
int count1 = 0, count2 = 0;//count1为删除成功数,count2为删除未成功的数
for (int i = 0; i < GridView1.Rows.Count; i++)
{
checkBox = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
if (checkBox.Checked)
{
comm.Parameters.Clear();
//comm.CommandText = "delete from T_Score where Score_Faculty_id='" + GridView1.DataKeys[i].Value + "'";
comm.CommandText = "delete from T_Score where Score_Faculty_id=@Score_Faculty_id and Score_item_id=@Score_item_id and Score_semester=@Score_semester";
comm.Parameters.Add(new SqlParameter("Score_Faculty_id", Convert.ToInt32(GridView1.DataKeys[i].Value)));
comm.Parameters.Add(new SqlParameter("Score_item_id", Convert.ToInt64(DDL_evaluationItem.SelectedValue)));
comm.Parameters.Add(new SqlParameter("Score_semester", Convert.ToInt64(DDL_semester.SelectedValue)));
if (comm.ExecuteNonQuery() == 1)
{
count1 = count1 + 1;
}
else
{
count2 = count2 + 1;
}
}
}
conn.Close();
if (count2 != 0)
{
Response.Write("<script>alert('" + count2 + "条记录未成功删除!');history.go(-1);</script>");
}
else
{
Response.Write("<script>alert('成功删除" + count1 + "条记录!');location.href='SetScore_evaluationItem.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('对不起,没有数据可进行删除!');history.go(-1);</script>");
}
gridviewDataBind("all");
}