protected void BindTimu()//绑定知识点题目 { string tixing = DropDownList1.SelectedValue.Trim(); if (TreeView1.CheckedNodes.Count > 0) { try { List <string> zhishidianids = TreeView1.CheckedNodesAndChildrenIds;//选择的知识点及其子孙知识点的id DataTable dt = TimuInfo.GetTimuOnZhishidian(zhishidianids, tixing); grvw_timu.DataSource = dt; ViewState["timutable"] = dt; grvw_timu.DataBind(); } catch { ScriptManager.RegisterClientScriptBlock(this, typeof(string), "", "<script language='javascript'>alert('获取题目失败!');</script>", false); } } else { int zuoyeid = int.Parse(Request.QueryString["zuoyeid"]); string kechengid = ZuoyeInfo.getZuoye_Kechengid(zuoyeid); DataTable dt = TimuInfo.GetTimuOnKecheng(kechengid, tixing); grvw_timu.DataSource = dt; ViewState["timutable"] = dt; grvw_timu.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["zuoyeid"] != null) { //绑定课程知识树 int zuoyeid = int.Parse(Request.QueryString["zuoyeid"]); string kechengid = ZuoyeInfo.getZuoye_Kechengid(zuoyeid); TreeView1.ConnectionString = ConfigurationManager.ConnectionStrings[TreeView1.ConnectionStringName].ConnectionString; TreeView1.kechengid = int.Parse(kechengid); Hylk_buzhi.NavigateUrl = "zuoye_id_buzhi01.aspx?zuoyeid=" + zuoyeid.ToString(); } else { Response.Redirect("zuoyeyuzhi.aspx"); } } }
protected void btn_buzhizuoye_Click(object sender, EventArgs e)//将作业布置给某个班 { lbl_fankui.Text = ""; string zuoyeid = Request.QueryString["zuoyeid"]; if (ZuoyeInfo.GetTimuCount(zuoyeid) <= 0)//判断作业中有无题目 { lbl_fankui.Text = "该作业中没有题目,无法布置该作业。"; return; } string banjiid = DropDownList1.SelectedValue.Trim(); if (BanjiInfo.GetStudentCount(int.Parse(banjiid)) <= 0) { lbl_fankui.Text = DropDownList1.SelectedItem.Text + "班没有学生,无法布置作业。"; return; } string shangjiaoqixian = TextBox1.Text; string yunxu = RadioButtonList1.SelectedValue; string yunxuchakan = RadioButtonList2.SelectedValue; string kechengid = ZuoyeInfo.getZuoye_Kechengid(int.Parse(zuoyeid)); DataTable studt = BanjiInfo.GetStudentUserName(int.Parse(banjiid)); DataTable ZuoyeTimuTb = ZuoyeInfo.GetZuoyeTimuIdAndFenzhi(int.Parse(zuoyeid)); SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString; SqlCommand comm = conn.CreateCommand(); conn.Open(); SqlTransaction st = conn.BeginTransaction(); comm.Transaction = st; comm.CommandText = "insert into tb_zuoyebuzhi(zuoyeid,banjiid,yunxuzuoti,yunxuchakan,buzhishijian,shangjiaoqixian,teacherusername,shuoming,kechengid) values(@zuoyeid,@banjiid,@yunxuzuoti,@yunxuchakan,@buzhishijian,@shangjiaoqixian,@teacherusername,@shuoming,@kechengid)"; comm.Parameters.AddWithValue("@zuoyeid", zuoyeid); comm.Parameters.AddWithValue("@banjiid", banjiid); comm.Parameters.AddWithValue("@yunxuzuoti", yunxu); comm.Parameters.AddWithValue("@yunxuchakan", yunxuchakan); comm.Parameters.AddWithValue("@buzhishijian", DateTime.Now); comm.Parameters.AddWithValue("@shangjiaoqixian", TextBox1.Text); comm.Parameters.AddWithValue("@teacherusername", ((FormsIdentity)HttpContext.Current.User.Identity).Ticket.Name); comm.Parameters.AddWithValue("@shuoming", TextBox2.Text); comm.Parameters.AddWithValue("@kechengid", kechengid); try { comm.ExecuteNonQuery(); //将作业分发给学生,写入学生作业表 //删除以前布置给学生的该作业 //comm.CommandText = "delete from tb_studentzuoye where zuoyeid=@zuoyeid and studentusername in(select studentusername from tb_banjistudent where banjiid=@banjiid)"; //comm.ExecuteNonQuery(); //删除题目 //comm.CommandText = "delete from tb_stuzuoyetimu where zuoyeid=@zuoyeid and studentusername in(select studentusername from tb_banjistudent where banjiid=@banjiid)"; //comm.ExecuteNonQuery(); //写入学生作业表 comm.CommandText = "insert into tb_studentzuoye(zuoyeid,kechengid,studentusername,wancheng,zongfen,buzhishijian,shangjiaoqixian,shuoming,yunxuzuoti,yunxuchakan,teacherusername) values(@zuoyeid,@kechengid,@studentusername,'未完成',0,@buzhishijian,@shangjiaoqixian,@shuoming,@yunxuzuoti,@yunxuchakan,@teacherusername)"; comm.Parameters.Add("@studentusername", SqlDbType.VarChar); foreach (DataRow sdr in studt.Rows) { comm.Parameters[9].Value = sdr[0].ToString(); comm.ExecuteNonQuery(); } //将题目写入学生作业题目表 comm.Parameters.Clear(); comm.CommandText = "insert into tb_stuzuoyetimu(zuoyeid,studentusername,questionid,defen,fenzhi) values(@zuoyeid,@studentusername,@questionid,0,@fenzhi)"; comm.Parameters.AddWithValue("@zuoyeid", zuoyeid); comm.Parameters.Add("@studentusername", SqlDbType.VarChar); comm.Parameters.Add("@questionid", SqlDbType.Int); comm.Parameters.Add("@fenzhi", SqlDbType.Int); foreach (DataRow sdr in studt.Rows) { comm.Parameters[1].Value = sdr[0].ToString(); foreach (DataRow dr in ZuoyeTimuTb.Rows) { comm.Parameters[2].Value = Convert.ToInt32(dr[0]); comm.Parameters[3].Value = Convert.ToInt32(dr[1]); comm.ExecuteNonQuery(); } } st.Commit(); lbl_fankui.Text = "将作业布置给" + DropDownList1.SelectedItem.Text + ", 成功!"; } catch { st.Rollback(); lbl_fankui.Text = "布置失败!您是否已经给该班布置过该作业?"; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }