//一层一层的手工递归绑定一专多能下的KNOWLEDGE节点 private void BindKnowledgeByLevelNum(int levelNum, int parentID, TreeViewNode tvNode, int postID) { KnowledgeBLL knowledgeBLL = new KnowledgeBLL(); string whereClause = String.Format("is_promotion = 1 and level_num = {0} and (parent_id = {1} or {1} = 0)", levelNum, parentID), orderKey = "level_num, order_index"; IList <RailExam.Model.Knowledge> knowledgeList = knowledgeBLL.GetKnowledgesByWhereClause(whereClause, orderKey); foreach (RailExam.Model.Knowledge knowledge in knowledgeList) { TreeViewNode newNode = new TreeViewNode(); newNode.ID = knowledge.KnowledgeId.ToString(); newNode.Text = knowledge.KnowledgeName; newNode.Value = postID.ToString(); string whereClause2 = String.Format("PARENT_ID = {0} and IS_PROMOTION = 1", knowledge.KnowledgeId); string orderKey2 = "LEVEL_NUM, ORDER_INDEX"; IList <RailExam.Model.Knowledge> childKnowledgeList = knowledgeBLL.GetKnowledgesByWhereClause(whereClause2, orderKey2); if (childKnowledgeList.Count > 0) { BindKnowledgeByLevelNum(++levelNum, knowledge.KnowledgeId, newNode, postID); } tvNode.Nodes.Add(newNode); } }
protected void tvKnowledgeChangeCallBack_Callback(object sender, CallBackEventArgs e) { KnowledgeBLL objKnowledgeBll = new KnowledgeBLL(); if (e.Parameters[0] == "Insert") { IList <RailExam.Model.Knowledge> objList = objKnowledgeBll.GetKnowledgesByWhereClause("1=1", "Knowledge_ID desc"); hfMaxID.Value = objList[0].KnowledgeId.ToString(); hfMaxID.RenderControl(e.Output); } else if (e.Parameters[0] == "Delete" || e.Parameters[0] == "Update") { hfMaxID.Value = e.Parameters[1]; hfMaxID.RenderControl(e.Output); } else if (e.Parameters[0] == "UP" || e.Parameters[0] == "DOWN") { hfMaxID.Value = e.Parameters[1]; hfMaxID.RenderControl(e.Output); } tvKnowledge.Nodes.Clear(); BindKnowledgeTree(); tvKnowledge.RenderControl(e.Output); }
protected void fvKnowledge_ItemUpdating(object sender, FormViewUpdateEventArgs e) { string strId = e.Keys["KnowledgeId"].ToString(); bool isTemplate = Convert.ToBoolean(e.NewValues["IsTemplate"]); KnowledgeBLL knowledgeBll = new KnowledgeBLL(); if (isTemplate) { IList <RailExam.Model.Knowledge> objChildList = knowledgeBll.GetKnowledgesByParentID(Convert.ToInt32(strId)); if (objChildList.Count > 0) { SessionSet.PageMessage = "一专多能类别只能为知识体系叶子节点!"; e.Cancel = true; ClientScript.RegisterStartupScript(GetType(), "jsSelectFirstNode", @"setImageBtnVisiblityUpdate()", true); return; } IList <RailExam.Model.Knowledge> objTemplate = knowledgeBll.GetKnowledgesByWhereClause("Is_Template=1 and Knowledge_ID!=" + strId, "Knowledge_ID"); if (objTemplate.Count > 0) { SessionSet.PageMessage = "知识体系中已经存在名为【" + objTemplate[0].KnowledgeName + "】的一专多能类别!"; e.Cancel = true; ClientScript.RegisterStartupScript(GetType(), "jsSelectFirstNode", @"setImageBtnVisiblityUpdate()", true); return; } } }
private void BindTree() { KnowledgeBLL knowledgeBLL = new KnowledgeBLL(); IList <RailExam.Model.Knowledge> knowledgeList = new List <RailExam.Model.Knowledge>(); if (!string.IsNullOrEmpty(Request.QueryString.Get("type"))) { knowledgeList = knowledgeBLL.GetKnowledgesByWhereClause("id_path || '/' like '/790/%'", "LEVEL_NUM, ORDER_INDEX ASC"); TreeViewNode tvn = null; foreach (RailExam.Model.Knowledge obj in knowledgeList) { tvn = new TreeViewNode(); tvn.ID = obj.KnowledgeId.ToString(); tvn.Value = obj.KnowledgeId.ToString(); tvn.Text = obj.KnowledgeName; tvn.ToolTip = obj.KnowledgeName; if (obj.ParentId == 0) { tvKnowledge.Nodes.Add(tvn); } else { try { tvKnowledge.FindNodeById(obj.ParentId.ToString()).Nodes.Add(tvn); } catch { tvKnowledge.Nodes.Clear(); SessionSet.PageMessage = "数据错误!"; return; } } } } else { knowledgeList = knowledgeBLL.GetKnowledges(); Pub.BuildComponentArtTreeView(tvKnowledge, (IList)knowledgeList, "KnowledgeId", "ParentId", "KnowledgeName", "KnowledgeName", "KnowledgeId", null, null, null); } //tvKnowledge.ExpandAll(); }
protected void fvKnowledge_ItemInserting(object sender, FormViewInsertEventArgs e) { bool isTemplate = Convert.ToBoolean(e.Values["IsTemplate"]); KnowledgeBLL knowledgeBll = new KnowledgeBLL(); if (isTemplate) { IList <RailExam.Model.Knowledge> objTemplate = knowledgeBll.GetKnowledgesByWhereClause("Is_Template=1", "Knowledge_ID"); if (objTemplate.Count > 0) { SessionSet.PageMessage = "知识体系中已经存在名为【" + objTemplate[0].KnowledgeName + "】的一专多能类别!"; e.Cancel = true; ClientScript.RegisterStartupScript(GetType(), "jsSelectFirstNode", @"setImageBtnVisiblityInsert()", true); return; } } }
// 手动绑定KNOWLEDGE TreeView private void KnowledgeTreeNodeBind(int?postID, string whereClause, TreeViewNode tvNode) { ComponentArt.Web.UI.TreeView virtualTree = new ComponentArt.Web.UI.TreeView(); KnowledgeBLL knowledgeBLL = new KnowledgeBLL(); IList <RailExam.Model.Knowledge> knowledgeList; if (String.IsNullOrEmpty(whereClause)) { knowledgeList = knowledgeBLL.GetKnowledges(); } else { knowledgeList = knowledgeBLL.GetKnowledgesByWhereClause(whereClause, "level_num, order_index"); } if (knowledgeList.Count > 0) { TreeViewNode tvn = null; foreach (RailExam.Model.Knowledge knowledge in knowledgeList) { tvn = new TreeViewNode(); tvn.ID = knowledge.KnowledgeId.ToString(); tvn.Value = postID == null ? String.Empty : postID.ToString(); tvn.Text = knowledge.KnowledgeName; tvn.ToolTip = knowledge.KnowledgeName; if (knowledge.ParentId == 0) { if (tvNode == null) { this.tvKnowledge.Nodes.Add(tvn); } else { virtualTree.Nodes.Add(tvn); } } else { try { if (tvNode == null) { tvKnowledge.FindNodeById(knowledge.ParentId.ToString()).Nodes.Add(tvn); } else { virtualTree.FindNodeById(knowledge.ParentId.ToString()).Nodes.Add(tvn); } } catch { tvKnowledge.Nodes.Clear(); return; } } } if (tvNode != null) { foreach (TreeViewNode node in virtualTree.Nodes) { tvNode.Nodes.Add(node); } } } }