示例#1
0
        /// <summary>
        /// 将用户移动到组(chenl)
        /// </summary>
        /// <param name="cn"></param>
        /// <param name="group"></param>
        /// <param name="ds"></param>
        public int MoveUserToGroup(string cn, string group, out string errStr)
        {
            int result = 0;

            errStr = "";

            if (!Iadch.CheckUser(cn))
            {
                errStr = "该用户已在本组内";
                return(2);
            }
            DirectoryEntry oUser = Iads.GetUserEntry(cn);

            try
            {
                DirectoryEntry oGroup = Iads.GetGroupEntry(group);
                if (oGroup != null)
                {
                    if (!oGroup.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value))
                    {
                        oGroup.Properties["member"].Add(oUser.Properties["distinguishedName"].Value);
                        //					oUser.MoveTo(oGroup);
                        //					oUser.CommitChanges();
                        //					oGroup.CommitChanges();
                        //oUser.Properties["l"].Value="4";
                        //oUser.CommitChanges();
                        oGroup.CommitChanges();
                        result = 1;
                    }
                    else
                    {
                        errStr = "该用户已在本组内";
                        result = 3;
                    }
                }
                else
                {
                    AD_Group adgroup = new AD_Group();
                    adgroup.CreateGroupToUnit(group, "", "", out errStr);
                    oGroup = Iads.GetGroupEntry(group);
                    if (!oGroup.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value))
                    {
                        oGroup.Properties["member"].Add(oUser.Properties["distinguishedName"].Value);
                        oUser.Properties["l"].Value = "4";
                        oUser.CommitChanges();
                        oGroup.CommitChanges();
                        result = 1;
                    }
                    else
                    {
                        errStr = "该用户已在本组内";
                        result = 3;
                    }
                }
            }
            catch (Exception err)
            {
                result = 0;
                errStr = "系统错误";
            }
            finally
            {
                oUser.Close();
            }

            return(result);
        }
示例#2
0
文件: AD_Users.cs 项目: JuRogn/OA
		/// <summary>
		/// 将用户移动到组(chenl)
		/// </summary>
		/// <param name="cn"></param>
		/// <param name="group"></param>
		/// <param name="ds"></param>
		public  int MoveUserToGroup(string cn ,string group,out string errStr)
		{
			int result=0;
			errStr="";

			if(!Iadch.CheckUser(cn))
			{
				errStr="该用户已在本组内";
				return 2;
			}
			DirectoryEntry oUser=Iads.GetUserEntry(cn);
			
			try
			{
				
				
				DirectoryEntry oGroup=Iads.GetGroupEntry(group);
				if(oGroup!=null)
				{
					if(!oGroup.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value))
					{
						oGroup.Properties["member"].Add(oUser.Properties["distinguishedName"].Value);
						//					oUser.MoveTo(oGroup);
						//					oUser.CommitChanges();
						//					oGroup.CommitChanges();
						//oUser.Properties["l"].Value="4";
						//oUser.CommitChanges();
						oGroup.CommitChanges();
						result=1;
					}
					else
					{
						errStr="该用户已在本组内";
						result=3;					
					}
				}
				else
				{
					AD_Group adgroup=new AD_Group();
					adgroup.CreateGroupToUnit(group,"","",out errStr);
					oGroup=Iads.GetGroupEntry(group);
					if(!oGroup.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value))
					{
						oGroup.Properties["member"].Add(oUser.Properties["distinguishedName"].Value);
						oUser.Properties["l"].Value="4";
						oUser.CommitChanges();
						oGroup.CommitChanges();
						result=1;
					}
					else
					{
						errStr="该用户已在本组内";
						result=3;					
					}
				}
			}
			catch(Exception err)
			{
				result=0;
				errStr="系统错误";
			}
			finally
			{
				oUser.Close();
			}

			return result;
			
		}