Example #1
0
        public static DepartmentLogic GetInstance()
        {
            if (instance == null)
            {
                instance = new DepartmentLogic();
            }

            return(instance);
        }
Example #2
0
        /// <summary>
        /// 指定部门是否为我的后代
        /// </summary>
        /// <param name="dep">指定部门</param>
        /// <param name="recursion">是否递归判断后代,默认为true,只找下一代为false</param>
        /// <returns></returns>
        public static bool IsMyChildren(this int thisDep, int depId, bool recursion = true)
        {
            int parentId = DepartmentLogic.GetInstance().GetDepartmentParentId(depId);

            if (parentId > 0)
            {
                if (parentId == thisDep)                          //dep=1.2,this=1
                {
                    return(true);                                 //dep.parent=1
                }
                if (recursion)                                    //dep=1.2.3
                {
                    return(thisDep.IsMyChildren(parentId, true)); //dep=1.2.3,this=1.2
                }
            }
            return(false);
        }
Example #3
0
        public static List <int> GetDepartmentIds(string deps, DepartmentLogic dl = null)
        {
            List <int> depts = new List <int>();

            string[] ids = deps.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (dl == null)
            {
                dl = DepartmentLogic.GetInstance();
            }
            foreach (string id in ids)
            {
                int I;
                if (int.TryParse(id, out I))
                {
                    depts.Add(I);
                }
            }
            return(depts);
        }
Example #4
0
        public List <User> GetAllUsers()
        {
            List <User> users = new List <User>();
            string      sql   = "select * from [User]";
            DataTable   dt    = sqlHelper.Query(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                DepartmentLogic dl = DepartmentLogic.GetInstance();
                RoleLogic       rl = RoleLogic.GetInstance();
                UserGroupLogic  ul = UserGroupLogic.GetInstance();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    User user = new User();
                    user.ID          = Convert.ToInt32(dt.Rows[i]["ID"]);
                    user.Username    = dt.Rows[i]["Username"].ToString();
                    user.Departments = Common.GetDepartments(dt.Rows[i]["Depart"].ToString(), dl);
                    user.Flag        = Convert.ToInt32(dt.Rows[i]["Flag"]);
                    if (dt.Rows[i]["Password"] != null && dt.Rows[i]["Password"] != DBNull.Value)
                    {
                        user.Password = dt.Rows[i]["Password"].ToString();
                    }
                    else
                    {
                        user.Password = "";
                    }
                    if (dt.Rows[i]["Roles"] != null && dt.Rows[i]["Roles"] != DBNull.Value)
                    {
                        user.Roles = Common.GetRoles(dt.Rows[i]["Roles"].ToString(), rl);
                    }
                    if (dt.Rows[i]["Usergroup"] != null && dt.Rows[i]["Usergroup"] != DBNull.Value)
                    {
                        user.Usergroups = Common.GetUserGroups(dt.Rows[i]["Usergroup"].ToString(), ul);
                    }
                    if (dt.Rows[i]["Remark"] != null && dt.Rows[i]["Remark"] != DBNull.Value)
                    {
                        user.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    users.Add(user);
                }
            }
            return(users);
        }