/// <summary> /// 学生提交作业 /// </summary> /// <param name="ans"></param> /// <returns></returns> public int SubmitHw(Answer_Stu ans) { string sql = "insert into Answer_Stu (StuId ,HwId,Answer,Time ) Values(@StuId ,@HwId,@Answer,@Time )"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@StuId", ans.StuId), new SqlParameter("@HwId", ans.HwId), new SqlParameter("@Answer", ans.Answer), new SqlParameter("@Time", ans.Time) }; return(new Helper.SQLHelper().update(sql, param, false)); }
/// <summary> /// 学生提交作业 /// </summary> /// <param name="ans"></param> /// <returns></returns> public int SubmitHw(Answer_Stu ans) { int res = new HomeworkService().queryHasSubmited(ans.StuId, ans.HwId); if (res > 0) { return(-1); } int result = new HomeworkService().SubmitHw(ans); if (result > 0) { return(new HomeworkService().alterFinishNum(ans.HwId)); } return(result); }
protected void Button1_Click(object sender, EventArgs e) { Answer_Stu ans = new Answer_Stu() { Time = DateTime.Now, StuId = Convert.ToInt32(((Model.Login)Session["CurrentUser"]).UserName), HwId = Convert.ToInt32(Request.Params["HwId"]), Answer = editor1.Text }; int result = new HomeworkManage().SubmitHw(ans); if (result > 0) { Response.Write("<script>window.alert('作业已提交!');history.go(-2)</script>"); } else if (result == -1) { Response.Write("<script>window.alert('请勿重复提交!');</script>"); } else { Response.Write("<script>window.alert('提交失败!');</script>"); } }
/// <summary> /// 查看学生作业 /// </summary> /// <param name="StuId"></param> /// <param name="HwId"></param> /// <returns></returns> public Answer_Stu queryStuAnsByStuId(int StuId, int HwId) { string sql = "select StuId,HwId,Answer,Grade,Resist,Time,HwState from Answer_Stu where StuId=@StuId and HwId = @HwId "; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@StuId", StuId), new SqlParameter("@HwId", HwId) }; Answer_Stu ans = new Answer_Stu(); SqlDataReader result = new Helper.SQLHelper().queryAllResult(sql, param, false); while (result.Read()) { ans.StuId = Convert.ToInt32(result["StuId"]); ans.HwId = Convert.ToInt32(result["HwId"]); ans.Answer = result["Answer"].ToString(); ans.Grade = result["Grade"].ToString(); ans.Resist = result["Resist"].ToString(); ans.Time = Convert.ToDateTime(result["Time"]); ans.HwState = result["HwState"].ToString(); } return(ans); }