//添加或修改事件 protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { if (Page.IsValid) { QuestionProblem questionproblem = new QuestionProblem(); //创建单选题对象 questionproblem.CourseID = int.Parse(ddlCourse.SelectedValue); //为单选题对象各属性赋值 questionproblem.DiffID = int.Parse(ddlDiff.SelectedValue); //为填空题对象各属性赋值 questionproblem.Title = txtTitle.Text; questionproblem.Answer = txtAnswer.Text; if (Request["ID"] != null) //如果是修改题目信息 { questionproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键 if (questionproblem.UpdateByProc(int.Parse(Request["ID"].ToString()))) //调用修改试题方法修改试题 { lblMessage.Text = "成功修改该问答题!"; } else { lblMessage.Text = "修改该问答题失败!"; } } else //如果是添加试题 { if (questionproblem.InsertByProc()) //调用添加试题方法添加试题 { lblMessage.Text = "成功添加该问答题!"; } else { lblMessage.Text = "添加该问答题失败!"; } } } }
//GridView控件绑定数据事件 protected void GridViewBind() { QuestionProblem questionproblem = new QuestionProblem(); //创建单选题对象 DataSet ds = questionproblem.QueryQuestionProblem(int.Parse(ddlCourse.SelectedValue)); //根据试卷科目查询问答题信息 GridView1.DataSource = ds.Tables[0].DefaultView; //为GridView控件指名数据源 GridView1.DataBind(); //绑定数据 }
//删除多条记录 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { QuestionProblem question = new QuestionProblem(); //创建SingleProblem对象 foreach (GridViewRow dr in GridView1.Rows) //对GridView中的每一行进行判断 { if (((CheckBox)dr.FindControl("xuanze")).Checked) //如果选择了进行删除 { int ID = int.Parse(((Label)dr.FindControl("Label1")).Text); question.ID = ID; question.DeleteByProc(ID); } } }
//删除试题事件 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { QuestionProblem questionproblem = new QuestionProblem(); //创建问答题对象 int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值 if (questionproblem.DeleteByProc(ID)) { Response.Write("<script language=javascript>alert('成功删除试题!')</script>"); } else { Response.Write("<script language=javascript>alert('删除试题失败!')</script>"); } GridView1.EditIndex = -1; GridViewBind();//重新绑定数据 }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { QuestionProblem pro = new QuestionProblem(); pro.CourseID = Convert.ToInt32(ddlCourse.SelectedValue); pro.Title = txtTitle.Text; pro.Answer = txtAnswer.Text; if (questionProblemService.QuestionProblemInsert(pro)) { lblMessage.Text = "添加成功!"; txtTitle.Text = string.Empty; txtAnswer.Text = string.Empty; } else { lblMessage.Text = "添加失败!"; } }
//初始化数据 protected void InitData() { int QuestionProblemID = int.Parse(Request["ID"].ToString()); //取出传递过来的试题编号 QuestionProblem questionproblem = new QuestionProblem(); //创建单选题对象 if (questionproblem.LoadData(QuestionProblemID)) //如果取出题目信息,分别放在相应控件显示 { ddlCourse.SelectedValue = questionproblem.CourseID.ToString(); ddlDiff.SelectedValue = questionproblem.DiffID.ToString(); txtTitle.Text = questionproblem.Title; txtAnswer.Text = questionproblem.Answer; } else //查询出错,给出提示 { lblMessage.Text = "加载数据出错!"; } }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { QuestionProblem pro = new QuestionProblem(); pro.ID = int.Parse(Request["ID"].ToString()); pro.CourseID = Convert.ToInt32(ddlCourse.SelectedValue); pro.Title = txtTitle.Text; pro.Answer = txtAnswer.Text; if (questionProblemService.QuestionProblemUpdate(pro)) { lblMessage.Text = "修改成功!"; txtTitle.Text = string.Empty; txtAnswer.Text = string.Empty; } else { lblMessage.Text = "修改失败!"; } }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { QuestionProblem pro = new QuestionProblem(); pro.CourseID = Convert.ToInt32(ddlCourse.SelectedValue); pro.Title = txtTitle.Text; pro.Answer = txtAnswer.Text; if (QuestionProblemManager.QuestionProblemInsert(pro)) { lblMessage.Text = "添加成功!"; txtTitle.Text = string.Empty; txtAnswer.Text = string.Empty; } else { lblMessage.Text = "添加失败!"; } }
public static bool QuestionProblemInsert(QuestionProblem qi) { string sql = "Insert into QuestionProblem(CourseID,Title,Answer) values(@CourseID,@Title,@Answer)"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@CourseID",qi.CourseID), new SqlParameter("@Title",qi.Title), new SqlParameter("@Answer",qi.Answer) }; int i = DBHelp.ExecuteCommand(sql, param); if (i > 0) { return true; } else { return false; } }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { QuestionProblem pro = new QuestionProblem(); pro.ID = int.Parse(Request["ID"].ToString()); pro.CourseID = Convert.ToInt32(ddlCourse.SelectedValue); pro.Title = txtTitle.Text; pro.Answer = txtAnswer.Text; if (QuestionProblemManager.QuestionProblemUpdate(pro)) { lblMessage.Text = "修改成功!"; txtTitle.Text = string.Empty; txtAnswer.Text = string.Empty; } else { lblMessage.Text = "修改失败!"; } }
public static bool QuestionProblemUpdate(QuestionProblem qu) { string sql = "Update QuestionProblem Set CourseID=@CourseID,Title=@Title,Answer=@Answer where ID=@ID"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@CourseID",qu.CourseID), new SqlParameter("@Title",qu.Title), new SqlParameter("@Answer",qu.Answer), new SqlParameter("@ID",qu.ID) }; int i = DBHelp.ExecuteCommand(sql, param); if (i > 0) { return true; } else { return false; } }
public List<QuestionProblem> GetQuestionProblemList(string selectvalue) { using (SqlConnection con = DBHelp.GetConnection()) { string sql = "Select * from QuestionProblem where CourseID='" + selectvalue + "'"; SqlCommand cmd = new SqlCommand(sql,con); con.Open(); List<QuestionProblem> list = new List<QuestionProblem>(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { QuestionProblem ques = new QuestionProblem(); ques.ID = Convert.ToInt32(dr["ID"]); ques.CourseID = Convert.ToInt32(dr["CourseID"]); ques.Title = dr["Title"].ToString(); ques.Answer = dr["Answer"].ToString(); list.Add(ques); } return list; } }
public List<QuestionProblem> selectQuesQuestion(string UserId,int PaperId) { using (SqlConnection con=DBHelp.GetConnection()) { string sql = @"SELECT dbo.UserAnswer.Mark, dbo.UserAnswer.UserAnswer, dbo.UserAnswer.ExamTime, dbo.QuestionProblem.Title, dbo.QuestionProblem.Answer, dbo.Paper.PaperName FROM dbo.UserAnswer INNER JOIN dbo.QuestionProblem ON dbo.UserAnswer.TitleID = dbo.QuestionProblem.ID INNER JOIN dbo.Paper ON dbo.UserAnswer.PaperID = dbo.Paper.PaperID AND dbo.UserAnswer.Type = '�ʴ���' where dbo.UserAnswer.UserID='" + UserId + "' and dbo.UserAnswer.PaperID='" + PaperId + "'"; SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); List<QuestionProblem> list = new List<QuestionProblem>(); while (dr.Read()) { QuestionProblem Ques = new QuestionProblem(); Ques.Mark = Convert.ToInt32(dr["Mark"]); Ques.UserAnswer = dr["UserAnswer"].ToString(); Ques.ExamTime = Convert.ToDateTime(dr["ExamTime"]); Ques.Title = dr["Title"].ToString(); Ques.Answer = dr["Answer"].ToString(); Ques.PaperName = dr["PaperName"].ToString(); list.Add(Ques); } return list; } }
public bool QuestionProblemUpdate(QuestionProblem qu) { return service.QuestionProblemUpdate(qu); }
public bool QuestionProblemInsert(QuestionProblem qi) { return service.QuestionProblemInsert(qi); }