Example #1
0
        /// <summary>
        /// 根据当前机构获取对应的机构代码  机构代码 2-6-8-10  位
        /// </summary>
        /// <param name="districtEntity"></param>
        /// <returns></returns>
        public string GetDepartmentCode(DistrictEntity districtEntity)
        {
            string maxCode = string.Empty;

            OrganizeEntity oEntity = null;

            DistrictEntity dEntity = null;

            string deptcode = string.Empty;

            if (districtEntity.ParentID == "0")                                                         //选择是机构,没有选择上级区域
            {
                oEntity = new OrganizeService().BaseRepository().FindEntity(districtEntity.OrganizeId); //获取父对象(机构)

                deptcode = oEntity.EnCode;
            }
            else //选择的是部门
            {
                dEntity = this.BaseRepository().FindEntity(districtEntity.ParentID);//获取部门父对象

                deptcode = dEntity.DistrictCode;
            }
            var maxObj = this.BaseRepository().FindList(string.Format("select max(districtcode) as districtcode  from bis_district t where  parentid='{0}' and organizeid='{1}'", districtEntity.ParentID, districtEntity.OrganizeId)).FirstOrDefault();

            if (!string.IsNullOrEmpty(maxObj.DistrictCode))
            {
                maxCode = new OrganizeService().QueryOrganizeCodeByCondition(maxObj.DistrictCode);
            }
            else
            {
                DistrictEntity parentEntity = this.BaseRepository().FindEntity(districtEntity.ParentID);  //获取父对象
                if (parentEntity != null && districtEntity.ParentID != "0")
                {
                    maxCode = parentEntity.DistrictCode + "001";  //固定值,非可变
                }
                else
                {
                    maxCode = deptcode + "001";
                }
            }

            ////确定是否存在上级部门,非部门根节点
            //if (districtEntity.ParentID != "0")
            //{
            //    //存在,则取编码最大的那一个
            //    if (maxObj.Count() > 0)
            //    {
            //        maxCode = maxObj.FirstOrDefault().DistrictCode;  //获取最大的Code
            //        if (!string.IsNullOrEmpty(maxCode))
            //        {
            //            maxCode = new OrganizeService().QueryOrganizeCodeByCondition(maxCode);
            //        }
            //    }
            //    else
            //    {
            //        DistrictEntity parentEntity = this.BaseRepository().FindEntity(districtEntity.ParentID);  //获取父对象

            //        maxCode = parentEntity.DistrictCode + "001";  //固定值,非可变
            //    }
            //}
            //else  //部门根节点的操作
            //{
            //    //do somethings
            //    if (maxObj.Count() > 0)
            //    {
            //        maxCode = maxObj.FirstOrDefault().DistrictCode;  //获取最大的Code

            //        if (!string.IsNullOrEmpty(maxCode))
            //        {
            //            maxCode = new OrganizeService().QueryOrganizeCodeByCondition(maxCode);
            //        }
            //        else
            //        {
            //            maxCode = deptcode + "001";
            //        }
            //    }
            //    else
            //    {
            //        maxCode = deptcode + "001";  //固定值,非可变,加机构编码,组合新编码
            //    }
            //}
            //先判断当前编码是否存在于数据库表中
            return(maxCode);
        }
Example #2
0
        /// <summary>
        /// 根据当前机构获取对应的机构代码  机构代码 2-6-8-10  位
        /// </summary>
        /// <param name="departmentEntity"></param>
        /// <returns></returns>
        public string GetDepartmentCode(DepartmentEntity departmentEntity)
        {
            string maxCode = string.Empty;

            OrganizeEntity oEntity = null;

            DepartmentEntity dEntity = null;

            string deptcode = string.Empty;

            if (departmentEntity.ParentId == "0")                                                         //选择是机构
            {
                oEntity = new OrganizeService().BaseRepository().FindEntity(departmentEntity.OrganizeId); //获取父对象(机构)

                deptcode = oEntity.EnCode;
            }
            else //选择的是部门
            {
                dEntity = this.BaseRepository().FindEntity(departmentEntity.ParentId);//获取部门父对象

                deptcode = dEntity.EnCode;
            }

            //查询是否存在平级部门
            IEnumerable <DepartmentEntity> maxObj = this.BaseRepository().FindList(string.Format("select t.*  from BASE_DEPARTMENT t where t.encode  like '{0}%' and t.encode !='{0}' and t.parentid='" + departmentEntity.ParentId + "' and  encode is not null order by encode desc", deptcode));

            //确定是否存在上级部门,非部门根节点
            if (departmentEntity.ParentId != "0")
            {
                //存在,则取编码最大的那一个
                if (maxObj.Count() > 0)
                {
                    maxCode = maxObj.FirstOrDefault().EnCode;  //获取最大的Code
                    if (!string.IsNullOrEmpty(maxCode))
                    {
                        maxCode = new OrganizeService().QueryOrganizeCodeByCondition(maxCode);
                    }
                }
                else
                {
                    DepartmentEntity parentEntity = this.BaseRepository().FindEntity(departmentEntity.ParentId); //获取父对象

                    maxCode = parentEntity.EnCode + "001";                                                       //固定值,非可变
                }
            }
            else  //部门根节点的操作
            {
                //do somethings
                if (maxObj.Count() > 0)
                {
                    maxCode = maxObj.FirstOrDefault().EnCode;  //获取最大的Code

                    if (!string.IsNullOrEmpty(maxCode))
                    {
                        maxCode = new OrganizeService().QueryOrganizeCodeByCondition(maxCode);
                    }
                    else
                    {
                        maxCode = deptcode + "001";
                    }
                }
                else
                {
                    maxCode = deptcode + "001";  //固定值,非可变,加机构编码,组合新编码
                }
            }
            //先判断当前编码是否存在于数据库表中
            return(maxCode);
        }