public JsonResult AddSubject(string ParentID, string ListData) { var result = new List <Dictionary <string, object> >(); Action action = () => { var list = JsonHelper.ToList(ListData); list = list.OrderBy(c => c.GetValue("FullID")).ToList(); var rootNodeDic = this.GetDataDicByID(this.TableName, ParentID); if (rootNodeDic == null) { throw new Formula.Exceptions.BusinessValidationException("没有找到选中的节点,无法新增科目"); } var dt = this.SQLDB.ExecuteDataTable(String.Format("select ID,SubjectID from S_EP_DefineCBSNode with(nolock) where DefineID='{0}' and ParentID='{1}'" , rootNodeDic.GetValue("DefineID"), ParentID)); var defineSql = "select top 1 Type from S_EP_DefineCBSInfo where id = '{0}'"; var cbsType = this.SQLDB.ExecuteScalar(String.Format(defineSql, rootNodeDic.GetValue("DefineID"))); var addedList = new List <Dictionary <string, object> >(); foreach (var item in list) { if (item.GetValue("NodeType") == "Root") { continue; } if (dt.Select("SubjectID='" + item.GetValue("ID") + "'").Length > 0) { continue; } var parentDefineNodeDic = addedList.FirstOrDefault(c => c.GetValue("SubjectID") == item.GetValue("ParentID")); if (parentDefineNodeDic == null) { parentDefineNodeDic = rootNodeDic; } var parentNode = new S_EP_DefineCBSNode(parentDefineNodeDic); var childDic = new Dictionary <string, object>(); childDic.SetValue("ID", FormulaHelper.CreateGuid()); childDic.SetValue("Name", item.GetValue("Name")); childDic.SetValue("Code", item.GetValue("Code")); childDic.SetValue("NodeType", CBSNodeType.Subject.ToString()); childDic.SetValue("CBSType", cbsType.ToString()); childDic.SetValue("SubjectType", item.GetValue("SubjectType")); childDic.SetValue("SubjectID", item.GetValue("ID")); childDic.SetValue("SubjectFullID", item.GetValue("FullID")); childDic.SetValue("SubjectCode", item.GetValue("Code")); childDic.SetValue("SubjectFullCode", item.GetValue("FullCode")); childDic.SetValue("AccountNodeType", AccountNodeType.Account.ToString()); this._createLogic(childDic); var node = parentNode.AddChildNode(childDic); addedList.Add(node.ModelDic); } }; ExecuteAction(action); return(Json(result)); }
public JsonResult AddNode(string NodeID, string AddMode, string DefineID) { var result = new Dictionary <string, object>(); Action action = () => { if (String.IsNullOrEmpty(NodeID)) { //默认增加根节点 result.SetValue("ID", FormulaHelper.CreateGuid()); result.SetValue("Name", "新建节点"); result.SetValue("FullID", result.GetValue("ID")); var sql = "select isnull(max(sortindex),0) from {0} with(nolock) where (ParentID='' or ParentID is null)"; var maxSortIndex = this.SQLDB.ExecuteScalar(String.Format(sql, this.TableName)); var defineSql = "select top 1 Type from S_EP_DefineCBSInfo where id = '{0}'"; var cbsType = this.SQLDB.ExecuteScalar(String.Format(defineSql, DefineID)); result.SetValue("SortIndex", Convert.ToDecimal(maxSortIndex) + 1); result.SetValue("CBSType", cbsType.ToString()); result.SetValue("DefineID", DefineID); result.SetValue("IsDynamic", true.ToString().ToLower()); result.InsertDB(this.SQLDB, this.TableName, result.GetValue("ID")); } else { var node = this.GetDataDicByID(this.TableName, NodeID); if (node == null) { throw new Formula.Exceptions.BusinessValidationException("没有找到ID为【" + NodeID + "】的科目信息,无法新增科目"); } if (node.GetValue("NodeType") == CBSNodeType.Subject.ToString()) { throw new Formula.Exceptions.BusinessValidationException("科目下不能新增CBS节点"); } var subjectNode = new S_EP_DefineCBSNode(node); if (AddMode.ToLower() == "after") { result = subjectNode.AddBrotherNode().ModelDic; } else { result = subjectNode.AddChildNode().ModelDic; } } }; this.ExecuteAction(action); return(Json(result)); }