Beispiel #1
0
 /// <summary>
 /// 编辑及新增
 /// </summary>
 /// <param name="id"></param>
 /// <param name="pcode"></param>
 /// <returns></returns>
 public ActionResult Edit(int id = 0, int pcode = 0)
 {
     BF_DEPARTMENT.Entity entity = new BF_DEPARTMENT.Entity();
     //加载下拉
     GetSelectData();
     if (id > 0)
     {
         entity = BF_DEPARTMENT.Instance.GetEntityByKey <BF_DEPARTMENT.Entity>(id);
         if (entity == null)
         {
             return(ShowAlert("部门不存在"));
         }
     }
     else
     {
         entity.P_CODE = pcode;
         if (pcode > 0)
         {
             BF_DEPARTMENT.Entity pe = BF_DEPARTMENT.Instance.GetEntityByKey <BF_DEPARTMENT.Entity>(pcode);
             if (pe != null)
             {
                 entity.DEPT_LEVEL = Math.Min(4, pe.DEPT_LEVEL + 1);
             }
         }
     }
     return(View(entity));
 }
Beispiel #2
0
        public ActionResult Edit(BF_DEPARTMENT.Entity entity)
        {
            JsonResultData result = new JsonResultData();

            #region 验证
            if (string.IsNullOrEmpty(entity.NAME))
            {
                result.Message = "部门名称不可为空!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            if (entity.P_CODE != 0 && entity.DEPT_CODE == entity.P_CODE)
            {
                result.IsSuccess = false;
                result.Message   = "父级节点不能与当前目节点为同一级!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            #endregion

            int i = 0;
            try
            {
                #region 验证重复性
                if (entity.DEPT_CODE >= 0)
                {
                    if (BF_DEPARTMENT.Instance.IsDuplicate(entity.ID, "DEPT_CODE", entity.DEPT_CODE.ToString()))
                    {
                        result.IsSuccess = false;
                        result.Message   = "部门编码" + entity.DEPT_CODE + "已存在";
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }
                }
                #endregion

                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("NAME", entity.NAME);
                dic.Add("REMARK", entity.REMARK);
                dic.Add("P_CODE", entity.P_CODE);
                dic.Add("DEPT_CODE", entity.DEPT_CODE);
                dic.Add("DEPT_LEVEL", entity.DEPT_LEVEL);
                dic.Add("DEPT_FLAG", entity.DEPT_FLAG);
                dic.Add("UPDATE_TIME", DateTime.Now);
                dic.Add("UPDATE_UID", SystemSession.UserID);

                //修改
                if (entity.ID > 0) //增加与修改的判断
                {
                    i = BF_DEPARTMENT.Instance.UpdateByKey(dic, entity.ID);
                }
                else
                {
                    //增加
                    dic.Add("CREATE_TIME", DateTime.Now);
                    dic.Add("CREATE_UID", SystemSession.UserID);
                    i = BF_DEPARTMENT.Instance.Add(dic);
                }

                result.IsSuccess = i > 0 ? true : false;
                result.Message   = i > 0 ? "数据提交成功!" : "数据提交失败!";
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }