码迷,mamicode.com
首页 > 其他好文 > 详细

crm操作全局选项集

时间:2014-07-23 13:28:26      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:crm创建全局选项集   crm插入新全局选项集选项   crm更改选项集中选项的相对顺序   crm检索全局选项集   crm删除全局选项集   

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;
    using Microsoft.Xrm.Sdk.Messages;

    /// <summary>
    /// 全局选项集
    /// </summary>
    public class OptionSetMetadataHelper
    {
        public IOrganizationService service = null;
        public Guid optionSetId = Guid.Empty;
        public int languageCode = 2052;

        /// <summary>
        /// 创建全局选项集
        /// </summary>
        public void Create()
        {
            #region OptionMetadataCollection
            OptionMetadataCollection opCollection = new OptionMetadataCollection();
            opCollection.Add(new OptionMetadata(new Label("2000年", languageCode), 2000));
            opCollection.Add(new OptionMetadata(new Label("2001年", languageCode), 2001));
            opCollection.Add(new OptionMetadata(new Label("2002年", languageCode), 2002));
            opCollection.Add(new OptionMetadata(new Label("2003年", languageCode), 2003));
            opCollection.Add(new OptionMetadata(new Label("2004年", languageCode), 2004));
            opCollection.Add(new OptionMetadata(new Label("2005年", languageCode), 2005));
            #endregion

            OptionSetMetadata optionSet = new OptionSetMetadata(opCollection);
            optionSet.Name = "new_year";
            optionSet.Description = new Label("年份", languageCode);
            optionSet.DisplayName = new Label("年份", languageCode);
            optionSet.IsGlobal = true;
            optionSet.OptionSetType = OptionSetType.Picklist;

            CreateOptionSetRequest request = new CreateOptionSetRequest();
            request.OptionSet = optionSet;
            CreateOptionSetResponse response = (CreateOptionSetResponse)service.Execute(request);
            optionSetId = response.OptionSetId;
        }

        /// <summary>
        /// 插入新全局选项集选项
        /// </summary>
        public void InsertOptionValue()
        {
            InsertOptionValueRequest request = new InsertOptionValueRequest();
            request.OptionSetName = "new_year";
            request.Label = new Label("2008年", languageCode);
            request.Value = 2008;
            InsertOptionValueResponse response = (InsertOptionValueResponse)service.Execute(request);
        }

        /// <summary>
        /// 更改选项集中选项的相对顺序
        /// </summary>
        public void OrderOption()
        {
            OrderOptionRequest request = new OrderOptionRequest();
            request.OptionSetName = "new_year";
            request.Values = new int[]{ 2005,2004,2003,2002,2001,2000 };
            OrderOptionResponse response = (OrderOptionResponse)service.Execute(request);
        }

        /// <summary>
        /// 检索所有全局选项集
        /// </summary>
        public void RetrieveAllOptionSets()
        {
            RetrieveAllOptionSetsRequest request = new RetrieveAllOptionSetsRequest();
            request.RetrieveAsIfPublished = true;
            RetrieveAllOptionSetsResponse response = (RetrieveAllOptionSetsResponse)service.Execute(request);
            OptionSetMetadataBase[] optionSetMetadata = response.OptionSetMetadata;
        }

        /// <summary>
        /// 检索全局选项集
        /// </summary>
        /// <param name="name">选项集的名称</param>
        public void RetrieveOptionSet(string name)
        {
            RetrieveOptionSetRequest request = new RetrieveOptionSetRequest();
            request.Name = name;
            request.RetrieveAsIfPublished = true;
            RetrieveOptionSetResponse response = (RetrieveOptionSetResponse)service.Execute(request);
            OptionSetMetadataBase optionSetMetadata = response.OptionSetMetadata;
        }

        /// <summary>
        /// 删除全局选项集中的项
        /// </summary>
        /// <param name="v">值</param>
        public void DeleteItem(int v)
        {
            DeleteOptionValueRequest request = new DeleteOptionValueRequest();
            request.OptionSetName = "new_year";
            request.Value = v;
            DeleteOptionValueResponse response = (DeleteOptionValueResponse)service.Execute(request);
        }

        /// <summary>
        /// 删除全局选项集
        /// </summary>
        public void Delete()
        {
            DeleteOptionSetRequest request = new DeleteOptionSetRequest();
            request.Name = "new_year";
            DeleteOptionSetResponse response = (DeleteOptionSetResponse)service.Execute(request);
        }
    }

crm操作全局选项集

标签:crm创建全局选项集   crm插入新全局选项集选项   crm更改选项集中选项的相对顺序   crm检索全局选项集   crm删除全局选项集   

原文地址:http://blog.csdn.net/y_f123/article/details/38057157

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!