ProjectServer代码自动添加资源,用户

首先我们要引用

Resource Web Service:

http://yourserver/pwa/_vti_bin/psi/resource.asmx

添加资源代码如下:

 

private Guid AddResource(string Name, PSLibrary.Resource.Type ResType )

        {

            try

            {

                resDs = new ResourceWS.ResourceDataSet();

                ResourceWS.ResourceDataSet.ResourcesRow resourceRow = resDs.Resources.NewResourcesRow();

                Guid NewResGuid = Guid.NewGuid();

                resourceRow.RES_UID = NewResGuid;

                resourceRow.RES_NAME = Name;

                resourceRow.RES_INITIALS = Name.Substring(0, 1) +

                                 (Name.IndexOf(" ") > 0 ? Name.Substring(Name.IndexOf(" ") + 1, 1) : "");

                resourceRow.RES_TYPE = (int)ResType;

                resourceRow.RES_GROUP = "Team Members";

                resourceRow.WRES_EMAIL = String.Format("{0}@{1}.com", Name.Substring(0, Name.IndexOf(" ")),

                    textBoxName.Text.Substring(Name.LastIndexOf(" ") + 1, Name.Length - Name.LastIndexOf(" ") - 1));

                resDs.Resources.AddResourcesRow(resourceRow);



                ResSvc.CreateResources(resDs, false, true);

                return NewResGuid;



            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);

                return Guid.Empty;

            }



        }

 

  如果要将该资源添加成登陆用户,仅上面的代码是不够的,需要添加如下代码:

private bool AddAuthorization(Guid resourceUid, string Account, bool WindowsUser)

        {

            try

            {

                ResourceWS.ResourceAuthorizationDataSet resourceAuthDs = new ResourceWS.ResourceAuthorizationDataSet();

                ResourceWS.ResourceAuthorizationDataSet.ResourcesRow resourceAuthRow = resourceAuthDs.Resources.NewResourcesRow();

                resourceAuthRow.RES_UID = resourceUid;

                resourceAuthRow.RES_IS_WINDOWS_USER = WindowsUser;

                resourceAuthRow.WRES_ACCOUNT = Account;

                resourceAuthDs.Resources.AddResourcesRow(resourceAuthRow);

                ResSvc.SetResourceAuthorization(resourceAuthDs);

                return true;

            }

            catch

            {

                return false;

            }

        }

  

 

你可能感兴趣的:(project)