Beispiel #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 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();
            }
        }
    }