public ActionResult SaveTreeForm(string keyValue, SafeInstitutionTreeEntity entity) { entity.ParentId = !string.IsNullOrWhiteSpace(entity.ParentId) ? entity.ParentId : "-1"; var parent = safeinstitutiontreebll.GetEntity(keyValue); if (parent == null) { entity.TreeCode = GetDepartmentCode(entity); } entity.TreeName = entity.TreeName.Replace("\\", "╲"); safeinstitutiontreebll.SaveForm(keyValue, entity); return(Success("操作成功。")); }
/// <summary> /// 根据当前机构获取对应的机构代码 机构代码 2-6-8-10 位 /// </summary> /// <param name="Entity"></param> /// <returns></returns> public string GetDepartmentCode(SafeInstitutionTreeEntity Entity) { string maxCode = string.Empty; var user = ERCHTMS.Code.OperatorProvider.Provider.Current(); var maxObj = deptBll.GetDataTable(string.Format("select max(TreeCode) as TreeCode from bis_safeinstitutiontree t where parentid='{0}' and CreateUserOrgCode='{1}' and datatype='{2}' ", Entity.ParentId, user.OrganizeCode, Entity.DataType)); if (maxObj != null && maxObj.Rows.Count > 0 && !string.IsNullOrEmpty(maxObj.Rows[0][0].ToString())) { string newCode = string.Empty; string maxValue = (Convert.ToDecimal(maxObj.Rows[0][0].ToString()) + 1).ToString(); for (int i = 1; i <= 30; i++) { if (maxValue.ToString().Length == i) { newCode = maxObj.Rows[0][0].ToString().Substring(0, maxObj.Rows[0][0].ToString().Length - i) + maxValue; break; } } maxCode = newCode; } else { SafeInstitutionTreeEntity parentEntity = safeinstitutiontreebll.GetEntity(Entity.ParentId); //获取父对象 if (parentEntity != null) { maxCode = parentEntity.TreeCode + "001"; //固定值,非可变 } else { maxCode = "001"; } } return(maxCode); }