public JsonResult AddDept(string PID, string DeptName) { string selectCode = "select max(code) from t_dept where PID = @PID"; DeptRule rule = new DeptRule(); string code = rule.GetDeptCode(selectCode, new string[] { "PID" }, new string[] { PID }); string selectPCode = "select code from t_dept where ID = @ID"; string PCode = rule.GetDeptCode(selectPCode, new string[] { "ID" }, new string[] { PID }); if (string.IsNullOrEmpty(code)) { code = PCode + "0001"; } else { code = code.Substring(0, code.Length - 4) + (Convert.ToInt32(code.Substring(code.Length - 4)) + 1).ToString().PadLeft(4, '0'); } string id = Guid.NewGuid().ToString().Replace("-", ""); Dept dept = new Dept() { ID = id, PY = Pinyin.GetPinyin(DeptName), Status = 1, Code = code, PID = PID, Name = DeptName }; rule.Add(dept); string sql = "select id,pid,name,code,status,case status when 0 then '在用' else '停用' end as statusName from t_dept where id=@ID"; return(Json(rule.GetDeptDynamic(sql, new string[] { "ID" }, new string[] { id }), JsonRequestBehavior.AllowGet)); }