protected void btDelStu_Click(object sender, EventArgs e) { Admin admin = new Admin(); int length = 0; //程军添加 2009-12-03 //string classID = Request.Params["ClassID"];//程军添加,2009-12-03 string classID = Session["DID"].ToString(); int cassID = Convert.ToInt32(classID); for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { //建立模板列中CheckBox控件的引用 CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkCheck"); if (chk.Checked == true) { length++; } } if (length == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('请先选择要删除的用户,再删除用户!')</script>"); return; } int[] iStudentIdArray = new int[length]; int k = 0; int groupNum = 0; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { //建立模板列中CheckBox控件的引用 CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkCheck"); if (chk.Checked == true) { iStudentIdArray[k] = Convert.ToInt32(GridView1.DataKeys[i].Value); k++; } } try { //程军修改,在班级内部删除所有用户后小组和班级都删除.2009-12-03 if (length == GridView1.Rows.Count) { int[] iClassIdArrary = { cassID }; admin.DeleteStudents(iStudentIdArray); admin.DeleteGroupsByClass(iClassIdArrary); admin.DeleteClassesByClass(iClassIdArrary); }//程军修改,2009-12-03 //程军修改,在班级内部删除一部分用户后,用户对应的小组也删掉.2009-12-05 else { admin.DeleteStudents(iStudentIdArray); Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('删除成功!')</script>"); SqlConnection myConn = new SqlConnection(); myConn.ConnectionString = ConfigurationManager.ConnectionStrings["SQLConnStringSTEduSys"].ConnectionString; String sqlStr = "select Max(groupNO) from [Group] where classID='" + classID + "'"; SqlCommand myCmd = new SqlCommand(sqlStr, myConn); myCmd.CommandType = CommandType.Text; myConn.Open(); try { SqlDataReader myReader = myCmd.ExecuteReader(); while (myReader.Read()) { groupNum = Convert.ToInt32(myReader[0]); } myReader.Close(); myCmd.Dispose(); myConn.Close(); } catch { } for (int i = 1; i <= groupNum; i++) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["SQLConnStringSTEduSys"].ConnectionString; String str = "select * from CompleteStuInfo where groupNO =" + i + "and classID = '" + classID + "'"; SqlCommand cmd = new SqlCommand(str, conn); cmd.CommandType = CommandType.Text; conn.Open(); try { SqlDataReader reader = cmd.ExecuteReader(); if(!reader.Read()) { SqlConnection Conn = new SqlConnection(); //String str1 = @"Server=PC2009121916RVZ;User Id=sa;Pwd=111111;DataBase=STEduSys"; //Conn = new SqlConnection(str1); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SQLConnStringSTEduSys"].ConnectionString; try { Conn.Open(); String str2 = "delete from [Group] where groupNO = " + i + "and classID =" + classID; SqlCommand myCmd1 = new SqlCommand(str2, Conn); myCmd1.ExecuteNonQuery(); } catch { Console.WriteLine("没有删除对应的组"); } } } catch { } } } }//程军修改 2009-12-05 catch { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('该学生所在班已被老师激活,请暂勿删除该学生!')</script>"); } GridViewBind(); }
protected void btDelStu_Click(object sender, EventArgs e) { Admin admin = new Admin(); int length = 0; //胡媛媛添加,判断当前有无用户,2010-01-07 if (GridView1.Rows.Count == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('当前已无任何用户!')</script>"); return; } //胡媛媛添加,判断当前有无用户,2010-01-07 else { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { //建立模板列中CheckBox控件的引用 CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkCheck"); if (chk.Checked == true) { length++; } } if (length == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('系统告警:请先选择要删除的用户,再删除用户!')</script>"); return; } int[] iClassIdArray = new int[length]; int k = 0; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { //建立模板列中CheckBox控件的引用 CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkCheck"); if (chk.Checked == true) { iClassIdArray[k] = Convert.ToInt32(GridView1.DataKeys[i].Value); k++; } } try { admin.DeleteStudentsByClass(iClassIdArray); admin.DeleteGroupsByClass(iClassIdArray); admin.DeleteClassesByClass(iClassIdArray); Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('删除成功!')</script>"); GridViewBind(); } catch { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('已有老师激活了该班级,请暂勿删除!')</script>"); } //胡媛媛添加,去掉全选前面的复选框,2010-01-07 finally { if (chkAll.Checked == true) { chkAll.Checked = false; } } //胡媛媛添加,去掉全选前面的复选框,2010-01-07 } }