コード例 #1
0
        public ActionResult Detail(string id)
        {
            try
            {
                var entity = new Domain.SYS_DEPARTMENT();

                ViewBag.moduleparent = this.DepartmentManage.GetDepartmentByDetail();

                //添加子部门
                string parentId = Request.QueryString["parentId"];

                if (!string.IsNullOrEmpty(parentId))
                {
                    entity.PARENTID = parentId;
                }
                if (!string.IsNullOrEmpty(id))
                {
                    entity = this.DepartmentManage.Get(p => p.ID == id);
                }
                return(View(entity));
            }
            catch (Exception e)
            {
                WriteLog(Common.Enums.enumOperator.Select, "部门管理加载详情页:", e);
                throw e.InnerException;
            }
        }
コード例 #2
0
ファイル: ChatHub.cs プロジェクト: modoli001/weixintv
        /// <summary>
        /// 递归获取一级部门ID
        /// </summary>
        private Domain.SYS_DEPARTMENT GetUserDepart(string departId)
        {
            var DepartMent = DepartmentManage.Get(p => p.ID == departId);

            if (DepartMent != null)
            {
                var ParentId     = DepartMent.PARENTID;
                var ParentDepart = new Domain.SYS_DEPARTMENT();
                for (int?i = DepartMent.BUSINESSLEVEL; i >= 1; i--)
                {
                    ParentDepart = DepartmentManage.Get(p => p.ID == ParentId);
                    if (!string.IsNullOrEmpty(ParentDepart.PARENTID))
                    {
                        ParentId = ParentDepart.PARENTID;
                    }
                    else
                    {
                        break;
                    }
                }

                return(ParentDepart);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public ActionResult Save(Domain.SYS_DEPARTMENT entity)
        {
            bool isEdit = false;
            var  json   = new JsonHelper()
            {
                Msg = "保存成功", Status = "n"
            };

            try
            {
                var _entity = new Domain.SYS_DEPARTMENT();
                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(entity.ID))
                    {
                        #region 修改
                        _entity            = this.DepartmentManage.Get(p => p.ID == entity.ID);
                        entity.CREATEDATE  = _entity.CREATEDATE;
                        entity.CREATEPERID = _entity.CREATEPERID;
                        entity.UPDATEDATE  = DateTime.Now;
                        entity.UPDATEUSER  = this.CurrentUser.Name;
                        if (entity.PARENTID != _entity.PARENTID)
                        {
                            entity.CODE = this.DepartmentManage.CreateCode(entity.PARENTID);
                        }
                        else
                        {
                            entity.CODE = _entity.CODE;
                        }
                        //获取父级记录
                        if (string.IsNullOrEmpty(_entity.PARENTID))
                        {
                            //业务等级
                            entity.BUSINESSLEVEL = 1;
                            entity.PARENTCODE    = null;
                        }
                        else
                        {
                            var parententity = this.DepartmentManage.Get(p => p.ID == entity.PARENTID);
                            entity.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
                            entity.PARENTCODE    = parententity.CODE;
                        }
                        #endregion
                        isEdit  = true;
                        _entity = entity;
                    }
                    else
                    {
                        #region 添加
                        _entity             = entity;
                        _entity.ID          = Guid.NewGuid().ToString();
                        _entity.CREATEDATE  = DateTime.Now;
                        _entity.CREATEPERID = this.CurrentUser.Name;
                        _entity.UPDATEDATE  = DateTime.Now;
                        _entity.UPDATEUSER  = this.CurrentUser.Name;
                        //根据上级部门的ID确定当前部门的CODE
                        _entity.CODE = this.DepartmentManage.CreateCode(entity.PARENTID);
                        //获取父级记录
                        if (string.IsNullOrEmpty(entity.PARENTID))
                        {
                            //业务等级
                            entity.BUSINESSLEVEL = 1;
                            entity.PARENTCODE    = null;
                        }
                        else
                        {
                            var parententity = this.DepartmentManage.Get(p => p.ID == entity.PARENTID);
                            entity.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
                            entity.PARENTCODE    = parententity.CODE;
                        }
                        #endregion
                    }
                    //判断同一个部门下,是否重名
                    var predicate = PredicateBuilder.True <Domain.SYS_DEPARTMENT>();
                    predicate = predicate.And(p => p.PARENTID == _entity.PARENTID);
                    predicate = predicate.And(p => p.NAME == _entity.NAME);
                    predicate = predicate.And(p => p.ID != _entity.ID);
                    if (!this.DepartmentManage.IsExist(predicate))
                    {
                        if (this.DepartmentManage.SaveOrUpdate(_entity, isEdit))
                        {
                            json.Status = "y";
                        }
                        else
                        {
                            json.Msg = "保存失败";
                        }
                    }
                    else
                    {
                        json.Msg = "部门" + entity.NAME + "已存在,不能重复添加";
                    }
                }
                else
                {
                    json.Msg = "未找到需要保存的部门信息";
                }
                if (isEdit)
                {
                    WriteLog(Common.Enums.enumOperator.Edit, "修改部门信息,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
                else
                {
                    WriteLog(Common.Enums.enumOperator.Add, "添加部门信息,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
            }
            catch (Exception e)
            {
                json.Msg = "保存部门信息发生内部错误!";
                WriteLog(Common.Enums.enumOperator.None, "保存部门信息:", e);
            }
            return(Json(json));
        }