Exemplo n.º 1
0
 //answer表插入判断
 protected void DetailsView7_ItemInserting(object sender, DetailsViewInsertEventArgs e)
 {
     StudentManager stu = new StudentManager();
     ProblemManager p = new ProblemManager();
     if (e.Values["student"] == null || e.Values["problem"] == null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中Student,prob字段不能为空');", true);
         e.Cancel = true;
         return;
     }
     if (stu.GetStudent(e.Values["student"].ToString()) == null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中外键student字段不存在');", true);
         e.Cancel = true;
         return;
     }
     if(p.GetProblemById(int.Parse(e.Values["problem"].ToString()))==null)
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "msg1", "alert('插入失败!answer表中外键problem字段不存在');", true);
         e.Cancel = true;
         return;
     }
 }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserRole"] == null || Session["UserRole"].ToString() != "Student")
            {
                Response.Write("<Script language='javascript'>alert('您无权访问此页面,请重新登录!');window.history.go(-1);</Script>");
                return;
            }

            //获取作业id
            id = Request.QueryString["AssignmentId"];
            header_text.Text = Request.QueryString["AssignmentTitle"];
            ProblemManager ProblemMan = new ProblemManager();

            stu = (Student)Session["student"];
            ProblemList = ProblemMan.GetProblem(System.Int32.Parse(id));

            if (ProblemList.Count != 0)
            {
                //动态创建问题及回答区域
                //加载上次答案
                AnswerList = AnswerMan.GetAnswerList(stu.username, System.Int32.Parse(id));
                accessory = AccessoryMan.GetAccessory(stu.username, System.Int32.Parse(id));

                for (int i = 0; i < ProblemList.Count; i++)
                {
                    string pro = "<p>" + ProblemList[i].title + "</p>";
                    Control ct = ParseControl(pro);
                    PlaceHolder1.Controls.Add(ct);

                    string an = "<p><textarea cols='120' rows='15' name='TA' id='TA" + i + "'></textarea></p>";

                    //加载已有答案
                    if (AnswerList != null)
                    {
                        an = "<p><textarea cols='120' rows='15' name='TA' id='TA" + i + "'>" + AnswerList[i].content + "</textarea></p>";
                        submitFlag = false;
                    }

                    Control ct2 = ParseControl(an);
                    PlaceHolder1.Controls.Add(ct2);
                }

                //加载已有附件
                if (accessory != null)
                {
                    fileTips.Text = "已有附件,无需再添加!";
                    FileUpload2.Enabled = false;
                }
            }
            else
            {
                header_text.Text = "   逗你玩呢,哈哈哈哈。";
                submit.Enabled = false;
                submit2.Enabled = false;
                export.Enabled = false;
                export2.Enabled = false;
                fileTips.Enabled = false;
                FileUpload2.Enabled = false;
            }
        }