questionmanager.aspx.cs
来自「本在线考试系统采用了面向对象的分析和设计」· CS 代码 · 共 136 行
CS
136 行
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using ExaminationSystem.BLL.Domain;
using ExaminationSystem.BLL.Service;
using ExaminationSystem.Web;
public partial class Admin_ChapterTree : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
EditTreeView1.DeleteClick+=DeleteChapter;
EditTreeView1.UpdateClick += UpdateChapter;
EditTreeView1.InsertClick += InsertChapter;
EditTreeView1.AddRootClick += AddRootChapter;
EditTreeView1.SelectedNodeChanged += Tree_SelectedNodeChanged;
if (!IsPostBack)
{
ChapterNode root = new ChapterNode(long.Parse(Request.QueryString["SubjectId"].ToString()));
EditTreeView1.CreateTreeView(root);
BindQuestionList();
}
}
#region TreeView
private Subject Subject
{
get
{
return new SubjectService().GetById(long.Parse(Request.QueryString["SubjectId"].ToString()));
}
}
void DeleteChapter(long deleteId)
{
new ChapterService().DeleteById(deleteId);
}
void UpdateChapter(string newText, long updateId)
{
Chapter chapter = new ChapterService().GetById(updateId);
chapter.Name = newText;
new ChapterService().Update(chapter);
}
void InsertChapter(string text, long parentId,out long newId)
{
Chapter chapter = new Chapter();
Chapter parent = new ChapterService().GetById(parentId);
chapter.Name = text;
chapter.Parent = parent;
chapter.Subject = Subject;
new ChapterService().Save(chapter);
newId = chapter.ID;
}
void AddRootChapter(string text, out long rootId)
{
Chapter chapter = new Chapter();
chapter.Subject = Subject;
chapter.Name = EditTreeView1.RootNodeTextBox.Text;
new ChapterService().Save(chapter);
rootId = chapter.ID;
}
#endregion
#region QuestionList
private void BindQuestionList()
{
SetSubject();
Hard hard = GetSelectedHard();
Chapter chapter = GetSelectedChapter();
if (chapter == null)
return;
IList<QuestionContent> sourceQuestionList = chapter.QuestionContents;
IList<QuestionContent> resultQuestionList = new List<QuestionContent>();
foreach (QuestionContent question in sourceQuestionList)
{
if (question.QuestionType==questionTypeDD.SelectedValue && question.Hard == hard)
resultQuestionList.Add(question);
}
GridView1.DataSource = resultQuestionList;
GridView1.DataBind();
questionTypeLB.Text = questionTypeDD.SelectedItem.Text;
}
private void SetSubject()
{
subjectLB.Text = Subject.Name;
}
private Hard GetSelectedHard()
{
hardLB.Text = hardDD.SelectedItem.Text;
return (Hard)int.Parse(hardDD.SelectedValue);
}
private Chapter GetSelectedChapter()
{
chapterLB.Text = "请选择";
if (EditTreeView1.SelectedNode == null)
return null;
else
{
long chapterId = long.Parse(EditTreeView1.SelectedNode.Value);
Chapter chapter = new ChapterService().GetById(chapterId);
chapterLB.Text = chapter.Name;
return chapter;
}
}
protected void Tree_SelectedNodeChanged(object sender, EventArgs e)
{
BindQuestionList();
}
protected void questionTypeDD_SelectedIndexChanged(object sender, EventArgs e)
{
BindQuestionList();
}
protected void hardDD_SelectedIndexChanged(object sender, EventArgs e)
{
BindQuestionList();
}
#endregion
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?