Exemplo n.º 1
0
        /// <summary>
        /// 根据用户的账号(不包含域名)和职位名获取可交办和传阅的部门的ID以","分隔
        /// </summary>
        /// <param name="strUserID">用户账号</param>
        /// <param name="strPostName">职位名称</param>
        /// <returns></returns>
        private static string GetDeptIDByUser(string strUserID, string strPostName)
        {
            string    strIDS           = string.Empty;
            int       iCount           = 0;
            ViewBase  vbDept           = null;
            string    strDeptIDS       = string.Empty;
            ArrayList arrDepts         = new ArrayList();
            ArrayList strPostNames     = OAUser.GetSupPostNameAarray(strPostName);
            ViewBase  vbCompanyLeaders = OAUser.GetUserByRole(OUConstString.RoleName.COMPANY_LEADER);

            if (vbCompanyLeaders != null && vbCompanyLeaders.Count > 0)
            {
                vbCompanyLeaders.Condition = "a.userid=" + "'" + strUserID + "'";
            }
            if (vbCompanyLeaders != null && vbCompanyLeaders.DtTable != null)
            {
                iCount = vbCompanyLeaders.DtTable.Rows.Count;
            }
            if (iCount == 0)
            {
                User user = OAUser.GetUser(strUserID);
                if (user != null)
                {
                    ViewBase vbDeptPost = user.DeptPosts;
                    if (vbDeptPost != null)
                    {
                        foreach (DeptPost deptpost in vbDeptPost.Ens)
                        {
                            if (deptpost.Dept != null && deptpost.Post != null)
                            {
                                if (strPostNames.Contains(deptpost.Post.Name))
                                {
                                    arrDepts.Add(deptpost.Dept.ID);
                                }
                            }
                        }
                    }
                    ViewBase vbDeptManger = user.ManagerDepts;
                    if (vbDeptManger != null)
                    {
                        foreach (Department dept in vbDeptManger.Ens)
                        {
                            arrDepts.Add(dept.ID);
                        }
                    }
                    ViewBase vbDeptLeader = user.LeaderDepts;
                    if (vbDeptLeader != null)
                    {
                        foreach (Department dept in vbDeptLeader.Ens)
                        {
                            arrDepts.Add(dept.ID);
                        }
                    }
                    strDeptIDS = OADept.GetStringFormatForArrayList(arrDepts, ",");
                    vbDept     = OADept.GetChildDeptsConSelf(strDeptIDS, -1);
                    if (vbDept != null)
                    {
                        strIDS = vbDept.GetFieldVals("ID", ",");
                    }
                    else
                    {
                        strIDS = "-1";
                    }
                }
            }
            return(strIDS);
        }