예제 #1
0
        /// <summary>
        /// Validate the organization access of users according to the role.
        /// </summary>
        /// <param name="_ds"></param>
        /// <returns></returns>
        private List <int> validateUsers(DataSet _ds)
        {
            List <int> users     = new List <int>();
            MRole      role      = new MRole(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[0]["AD_Role_ID"]), null);
            bool       isAllUser = false;

            // if access all organization
            if (role.IsAccessAllOrgs())
            {
                isAllUser = true;
            }
            // if not access user organization access.
            if (!isAllUser && !role.IsUseUserOrgAccess())
            {
                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_Org_ID) FROm AD_Role_OrgAccess WHERE IsActive='Y' AND  AD_Role_ID=" + role.GetAD_Role_ID() + " AND AD_Org_ID IN (" + _req.GetAD_Org_ID() + ",0)")) > 0)
                {
                    isAllUser = true;
                }
                else
                {
                    return(users);
                }
            }
            for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
            {
                if (isAllUser)
                {
                    users.Add(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"]));
                }
                else
                {
                    if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_Org_ID) FROm AD_User_OrgAccess WHERE AD_User_ID=" + Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"]) + " AND  IsActive='Y' AND  AD_Org_ID IN (" + _req.GetAD_Org_ID() + ",0)")) > 0)
                    {
                        users.Add(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"]));
                    }
                }
            }
            return(users);
        }
예제 #2
0
        private void UpdateLoginSettings()
        {
            MRole role = new MRole(GetCtx(), GetAD_Role_ID(), null);

            if (!role.IsUseUserOrgAccess())
            {
                DB.ExecuteQuery("DELETE FROM ad_loginsetting WHERE AD_Org_ID=" + GetAD_Org_ID() + " AND AD_Role_ID=" + GetAD_Role_ID());
            }
            else
            {
                DataSet    ds   = DB.ExecuteDataset("SELECT AD_User_ID FROM ad_user_orgaccess WHERE AD_Org_ID=" + GetAD_Org_ID());
                List <int> UIDs = new List <int>();
                if (ds != null || ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        UIDs.Add(Convert.ToInt32(ds.Tables[0].Rows[i]["AD_User_ID"]));
                    }
                }

                string sql = "SELECT AD_User_ID FROM ad_loginsetting   WHERE AD_Org_ID=" + GetAD_Org_ID() + " AND AD_Role_ID=" + GetAD_Role_ID();
                ds = DB.ExecuteDataset(sql);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i <= ds.Tables[0].Rows.Count; i++)
                    {
                        if (UIDs.IndexOf(Convert.ToInt32(ds.Tables[0].Rows[i]["AD_User_ID"])) == -1)
                        {
                            DB.ExecuteQuery("DELETE FROM ad_loginsetting WHERE AD_User_ID=" + ds.Tables[0].Rows[i]["AD_User_ID"].ToString());
                        }
                    }
                }
                else
                {
                    DB.ExecuteQuery("DELETE FROM ad_loginsetting WHERE AD_Org_ID=" + GetAD_Org_ID() + " AND AD_Role_ID=" + GetAD_Role_ID());
                }
            }
        }