Example #1
0
    /// <summary>
    /// 将作业分发给某班的所有学生
    /// </summary>
    /// <param name="zuoyeid">作业id</param>
    /// <param name="banjiid">班级id</param>
    /// <returns></returns>
    //public static void ZuoyeFenfaToBanji(string zuoyeid, string banjiid)//将作业分发给某班的所有学生
    //{
    //    //找到班级学生
    //    //将作业布置信息写入学生作业表
    //    //将作业题目写入学生作业题目表
    //    DataTable stuTb = BanjiInfo.GetStudentUserName(int.Parse(banjiid));//班级学生信息表
    //    string kechengid = ZuoyeInfo.getZuoye_Kechengid(int.Parse(zuoyeid));
    //    DataTable BuzhiTb = ZuoyeInfo.GetZuoyeBuzhiInfo(zuoyeid, banjiid);//作业布置信息
    //    DataTable ZuoyeTimuTb = ZuoyeInfo.GetTeacherZuoyeTimuOrderByTixing(int.Parse(zuoyeid));//作业题目
    //    try
    //    {
    //        foreach (DataRow dr in stuTb.Rows)
    //        {
    //            //将作业布置给学生
    //            ZuoyeInfo.ZuoyeFenfaToStudent(zuoyeid, dr[0].ToString(), BuzhiTb, ZuoyeTimuTb, kechengid);
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        throw ex;
    //    }
    //}

    /// <summary>
    /// 将作业分发给某个学生
    /// </summary>
    /// <param name="zuoyeid">作业id</param>
    /// <param name="studentusername">学生用户名——学号</param>
    /// <param name="BuzhiTb">作业布置信息</param>
    /// <param name="ZuoyeTimuTb">作业题目信息</param>
    /// <param name="kechengid">课程id</param>
    /// <returns></returns>
    public static void ZuoyeFenfaToStudent(string zuoyeid, string studentusername, string kechengid, string banjiid)
    {
        DataTable     timudt  = ZuoyeInfo.GetZuoyeTimuIdAndFenzhi(int.Parse(zuoyeid)); //作业题目信息
        DataTable     buzhidt = ZuoyeInfo.GetZuoyeBuzhiInfo(zuoyeid, banjiid);         //作业布置信息
        SqlConnection conn    = new SqlConnection();

        conn.ConnectionString = ConfigurationManager.ConnectionStrings["kecheng2012ConnectionString"].ConnectionString;
        conn.Open();
        SqlTransaction st   = conn.BeginTransaction();
        SqlCommand     comm = conn.CreateCommand();

        comm.Transaction = st;
        try
        {
            //布置信息写入学生作业表
            comm.CommandText = "insert into tb_studentzuoye(zuoyeid,studentusername,wancheng,shangjiaoqixian,zongfen,kechengid,buzhishijian,shuoming,yunxuzuoti,yunxuchakan,teacherusername) values(@zuoyeid,@studentusername,'未完成',@shangjiaoqixian,0,@kechengid,@buzhishijian,@shuoming,@yunxuzuoti,@yunxuchakan,@teacherusername)";
            comm.Parameters.AddWithValue("@zuoyeid", zuoyeid);
            comm.Parameters.AddWithValue("@studentusername", studentusername);
            comm.Parameters.AddWithValue("@kechengid", kechengid);
            comm.Parameters.AddWithValue("@buzhishijian", buzhidt.Rows[0][5].ToString());    //布置时间
            comm.Parameters.AddWithValue("@shangjiaoqixian", buzhidt.Rows[0][6].ToString()); //上交期限
            comm.Parameters.AddWithValue("@shuoming", buzhidt.Rows[0][7].ToString());
            comm.Parameters.AddWithValue("@yunxuzuoti", buzhidt.Rows[0][3].ToString());      //允许做题
            comm.Parameters.AddWithValue("@yunxuchakan", buzhidt.Rows[0][4].ToString());     //允许查看结果
            comm.Parameters.AddWithValue("@teacherusername", buzhidt.Rows[0][8].ToString()); //教师
            comm.ExecuteNonQuery();
            comm.Parameters.Clear();
            comm.CommandText = "insert into tb_stuzuoyetimu(zuoyeid,questionid,studentusername,defen,fenzhi) values(@zuoyeid,@questionid,@studentusername,0,@fenzhi)";
            comm.Parameters.AddWithValue("@zuoyeid", zuoyeid);
            comm.Parameters.AddWithValue("@studentusername", studentusername);
            comm.Parameters.Add("@questionid", SqlDbType.Int);
            comm.Parameters.Add("@fenzhi", SqlDbType.Int);
            //comm.Parameters["@zuoyeid"].Value =int.Parse(zuoyeid);
            //comm.Parameters["@studentusername"].Value = studentusername.ToString();
            foreach (DataRow dr in timudt.Rows)
            {
                comm.Parameters["@questionid"].Value = Convert.ToInt32(dr[0]);
                comm.Parameters["@fenzhi"].Value     = Convert.ToInt32(dr[1]);
                comm.ExecuteNonQuery();
            }
            st.Commit();
        }
        catch (Exception ex)
        {
            st.Rollback();
            throw ex;
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
        }
    }
 protected void HyperLinkzuoyejbxx_Click(object sender, EventArgs e)//作业基本信息及修改
 {
     if (ListBoxzuoye.SelectedIndex >= 0 && ListBoxbanji.SelectedIndex >= 0)
     {
         string    zuoyeid      = ListBoxzuoye.SelectedValue;
         string    banjiid      = ListBoxbanji.SelectedValue;
         DataTable zy           = ZuoyeInfo.GetZuoyeBuzhiInfo(zuoyeid, banjiid);
         string    zuoyebuzhiid = zy.Rows[0][0].ToString();
         string    urlx         = "zuoye_editbuzhi.aspx?zuoyebuzhiid=" + zuoyebuzhiid;
         string    URL          = "<script  language= 'javascript'> window.open('" + urlx + "','_blank');</script>";
         ScriptManager.RegisterClientScriptBlock(this, typeof(string), "zyxx", URL, false);
     }
     else
     {
         ScriptManager.RegisterClientScriptBlock(this, typeof(string), "zyxx", "<script language='javascript'>alert('请选择班级、作业!');</script>", false);
     }
 }