/// <summary>
/// 上移
/// </summary>
protected void btnUp_Click(object sender, EventArgs e)
{
if (treeChapters.SelectedNode != null)
{
TreeNode sourceNode = treeChapters.SelectedNode;
int intIndex = treeChapters.Nodes.IndexOf(treeChapters.SelectedNode);
if (intIndex > 0)
{
treeChapters.Nodes.AddAt(intIndex - 1, sourceNode);
}
else if (intIndex != 0)
{
TreeNode tnParent = treeChapters.SelectedNode.Parent;
int index = tnParent.ChildNodes.IndexOf(treeChapters.SelectedNode);
foreach (TreeNode tnNode in tnParent.ChildNodes)
{
if (treeChapters.SelectedNode.Value == tnNode.Value && index != 0)
{
TreeNode tnTemp = new TreeNode();
tnTemp = tnNode;
tnParent.ChildNodes.Remove(treeChapters.SelectedNode);
tnParent.ChildNodes.AddAt(index - 1, tnTemp);
//设置移动后要选择的节点
tnParent.ChildNodes[index - 1].Select();
//更新要往上移动的章节:ChapterId = treeChapters.SelectedNode.Value 的顺序为:index - 1
UpdateChapterOrderNo(CourseId, Convert.ToInt32(treeChapters.SelectedNode.Value), index - 1);
//更新往下移动的章节:tnParent.ChildNodes[index].value 的顺序为:index
UpdateChapterOrderNo(CourseId, Convert.ToInt32(tnParent.ChildNodes[index].Value), index);
break;
}
}
}
}
}
/// <summary>
/// 下移
/// </summary>
protected void btnDown_Click(object sender, EventArgs e)
{
if (treeChapters.SelectedNode != null)
{
TreeNode sourceNode = treeChapters.SelectedNode;
int intCount = treeChapters.Nodes.Count;
if (treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) < intCount - 1 && treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) >= 0)
{
int intIndex = treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) + 1;
treeChapters.Nodes.AddAt(intIndex, sourceNode);
}
else if (treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) != intCount && treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) < 0)
{
TreeNode tnParent = treeChapters.SelectedNode.Parent;
int nodeCount = tnParent.ChildNodes.Count;
TreeNode tnSelectedNode = new TreeNode();
bool count = false;
int index = tnParent.ChildNodes.IndexOf(treeChapters.SelectedNode);
foreach (TreeNode tnNode in tnParent.ChildNodes)
{
if (treeChapters.SelectedNode.Value == tnNode.Value)
{
count = true;
tnSelectedNode = tnNode;
}
if (treeChapters.SelectedNode.Value != tnNode.Value && count == true)
{
tnParent.ChildNodes.Remove(treeChapters.SelectedNode);
tnParent.ChildNodes.AddAt(index + 1, tnSelectedNode);
//设置移动后要选择的节点
if (index + 1 >= nodeCount)
{
tnParent.ChildNodes[nodeCount - 1].Select();
}
else
{
tnParent.ChildNodes[index + 1].Select();
}
//TODO:更新当前要移动的章节:ChapterId = treeChapters.SelectedNode.Value 的顺序为:index + 1
UpdateChapterOrderNo(CourseId, Convert.ToInt32(treeChapters.SelectedNode.Value), index + 1);
// 更新从下往上移动的章节:tnParent.ChildNodes[index+1].value 的顺序为:index
UpdateChapterOrderNo(CourseId, Convert.ToInt32(tnParent.ChildNodes[index].Value), index );
break;
}
}
}
}
}
/// <summary>
/// 更新章节排序
/// </summary>
/// <param name="courseID">课程ID</param>
/// <param name="chapterId">章节ID</param>
/// <param name="orderNo">顺序</param>
private void UpdateChapterOrderNo(int courseID, int chapterId, int orderNo)
{
oU_Chapter.ChapterId = chapterId;
oU_Chapter.CourseID = courseID;
oU_Chapter.OrderNo = orderNo;
oU_ChapterLogic.UpdateChapterOrderNo(oU_Chapter);
}
/// 上移
/// </summary>
protected void btnUp_Click(object sender, EventArgs e)
{
if (treeChapters.SelectedNode != null)
{
TreeNode sourceNode = treeChapters.SelectedNode;
int intIndex = treeChapters.Nodes.IndexOf(treeChapters.SelectedNode);
if (intIndex > 0)
{
treeChapters.Nodes.AddAt(intIndex - 1, sourceNode);
}
else if (intIndex != 0)
{
TreeNode tnParent = treeChapters.SelectedNode.Parent;
int index = tnParent.ChildNodes.IndexOf(treeChapters.SelectedNode);
foreach (TreeNode tnNode in tnParent.ChildNodes)
{
if (treeChapters.SelectedNode.Value == tnNode.Value && index != 0)
{
TreeNode tnTemp = new TreeNode();
tnTemp = tnNode;
tnParent.ChildNodes.Remove(treeChapters.SelectedNode);
tnParent.ChildNodes.AddAt(index - 1, tnTemp);
//设置移动后要选择的节点
tnParent.ChildNodes[index - 1].Select();
//更新要往上移动的章节:ChapterId = treeChapters.SelectedNode.Value 的顺序为:index - 1
UpdateChapterOrderNo(CourseId, Convert.ToInt32(treeChapters.SelectedNode.Value), index - 1);
//更新往下移动的章节:tnParent.ChildNodes[index].value 的顺序为:index
UpdateChapterOrderNo(CourseId, Convert.ToInt32(tnParent.ChildNodes[index].Value), index);
break;
}
}
}
}
}
/// <summary>
/// 下移
/// </summary>
protected void btnDown_Click(object sender, EventArgs e)
{
if (treeChapters.SelectedNode != null)
{
TreeNode sourceNode = treeChapters.SelectedNode;
int intCount = treeChapters.Nodes.Count;
if (treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) < intCount - 1 && treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) >= 0)
{
int intIndex = treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) + 1;
treeChapters.Nodes.AddAt(intIndex, sourceNode);
}
else if (treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) != intCount && treeChapters.Nodes.IndexOf(treeChapters.SelectedNode) < 0)
{
TreeNode tnParent = treeChapters.SelectedNode.Parent;
int nodeCount = tnParent.ChildNodes.Count;
TreeNode tnSelectedNode = new TreeNode();
bool count = false;
int index = tnParent.ChildNodes.IndexOf(treeChapters.SelectedNode);
foreach (TreeNode tnNode in tnParent.ChildNodes)
{
if (treeChapters.SelectedNode.Value == tnNode.Value)
{
count = true;
tnSelectedNode = tnNode;
}
if (treeChapters.SelectedNode.Value != tnNode.Value && count == true)
{
tnParent.ChildNodes.Remove(treeChapters.SelectedNode);
tnParent.ChildNodes.AddAt(index + 1, tnSelectedNode);
//设置移动后要选择的节点
if (index + 1 >= nodeCount)
{
tnParent.ChildNodes[nodeCount - 1].Select();
}
else
{
tnParent.ChildNodes[index + 1].Select();
}
//TODO:更新当前要移动的章节:ChapterId = treeChapters.SelectedNode.Value 的顺序为:index + 1
UpdateChapterOrderNo(CourseId, Convert.ToInt32(treeChapters.SelectedNode.Value), index + 1);
// 更新从下往上移动的章节:tnParent.ChildNodes[index+1].value 的顺序为:index
UpdateChapterOrderNo(CourseId, Convert.ToInt32(tnParent.ChildNodes[index].Value), index );
break;
}
}
}
}
}
/// <summary>
/// 更新章节排序
/// </summary>
/// <param name="courseID">课程ID</param>
/// <param name="chapterId">章节ID</param>
/// <param name="orderNo">顺序</param>
private void UpdateChapterOrderNo(int courseID, int chapterId, int orderNo)
{
oU_Chapter.ChapterId = chapterId;
oU_Chapter.CourseID = courseID;
oU_Chapter.OrderNo = orderNo;
oU_ChapterLogic.UpdateChapterOrderNo(oU_Chapter);
}
另附广告:女朋友的淘宝网店,为她做宣传,希望大家别介意,http://iyseek.taobao.com 欢迎大家逛逛,嘿嘿!
欢迎大家一起交流,如有疑问,请联系zheng331773812@hotmail.com !