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

crm操作报价单实体

时间:2014-07-19 11:32:44      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:crm创建报价单   crm结束报价单   crm将报价单转换为销售订单   crm把报价单设置为草稿   crm删除报价单   

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

    /// <summary>
    /// 报价单
    /// </summary>
    public class QuoteHelper
    {
        public static readonly string entityName = "quote";
        public Guid quoteId = Guid.Empty;
        public IOrganizationService service;

        /// <summary>
        /// 创建报价单
        /// </summary>
        public void Create(Guid accountId)
        {
            Entity en = new Entity() { LogicalName = entityName };
            en["name"] = "报价单测试";
            en["accountid"] = new EntityReference() { LogicalName = "account",Id = accountId };
            quoteId = service.Create(en);
        }

        /// <summary>
        /// 创建报价单及其相关报价单详细信息
        /// </summary>
        /// <param name="childEn">报价单详细信息</param>
        public void CompoundCreate(EntityCollection childEn)
        {
            CompoundCreateRequest request = new CompoundCreateRequest();
            request.Entity = new Entity() { LogicalName = entityName };
            request.ChildEntities = childEn;
            CompoundCreateResponse response = (CompoundCreateResponse)service.Execute(request);
            quoteId = response.Id;
        }

        /// <summary>
        /// 将报价单分派给其他用户或团队
        /// </summary>
        /// <param name="assignee">用户或团队引用</param>
        public void Assign(EntityReference assignee)
        {
            AssignRequest request = new AssignRequest();
            request.Target = new EntityReference() { LogicalName = entityName,Id = quoteId };
            request.Assignee = assignee;
            AssignResponse response = (AssignResponse)service.Execute(request);
        }

        /// <summary>
        /// 指定结束报价单
        /// </summary>
        /// <param name="status">结束的状态值</param>
        public void CloseQuote(int status)
        {
            CloseQuoteRequest request = new CloseQuoteRequest();
            request.QuoteClose = new Entity() { LogicalName = entityName,Id = quoteId };
            request.Status = new OptionSetValue(status);
            CloseQuoteResponse response = (CloseQuoteResponse)service.Execute(request);
        }

        /// <summary>
        /// 将报价单转换为销售订单
        /// </summary>
        public Entity ConvertQuoteToSalesOrder()
        {
            ConvertQuoteToSalesOrderRequest request = new ConvertQuoteToSalesOrderRequest();
            request.QuoteId = quoteId;
            request.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("name","accountid");
            ConvertQuoteToSalesOrderResponse response = (ConvertQuoteToSalesOrderResponse)service.Execute(request);
            //销售订单
            Entity solrorderEn = response.Entity;
            return solrorderEn;
        }

        /// <summary>
        /// 为目标值中指定的实体获取产品的数量小数值
        /// </summary>
        /// <param name="productId">产品id</param>
        /// <param name="uoMId">单位id</param>
        public int GetQuantityDecimal(Guid productId, Guid uoMId)
        {
            GetQuantityDecimalRequest request = new GetQuantityDecimalRequest();
            request.Target = new EntityReference() { LogicalName = entityName,Id = quoteId };
            request.ProductId = productId;
            request.UoMId = uoMId;
            GetQuantityDecimalResponse response = (GetQuantityDecimalResponse)service.Execute(request);
            return response.Quantity;
        }

        /// <summary>
        /// 从商机中检索产品并将其复制到报价单
        /// </summary>
        /// <param name="opportunityId">商机id</param>
        public void GetQuoteProductsFromOpportunity(Guid opportunityId)
        {
            GetQuoteProductsFromOpportunityRequest request = new GetQuoteProductsFromOpportunityRequest();
            request.OpportunityId = opportunityId;
            request.QuoteId = quoteId;
            GetQuoteProductsFromOpportunityResponse response =
                (GetQuoteProductsFromOpportunityResponse)service.Execute(request);
        }

        /// <summary>
        /// 与其他安全主体(用户或团队)共享报价单
        /// </summary>
        /// <param name="accessMask">访问权限</param>
        /// <param name="principal">用户或团队引用</param>
        public void GrantAccessRequest(AccessRights accessMask,EntityReference principal)
        {
            GrantAccessRequest request = new GrantAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName,Id = quoteId };
            request.PrincipalAccess = new PrincipalAccess() { AccessMask = accessMask,Principal = principal };
            GrantAccessResponse response = (GrantAccessResponse)service.Execute(request);
        }

        /// <summary>
        /// 将报价单的状态设置为“草稿”
        /// </summary>
        public void ReviseQuote()
        {
            ReviseQuoteRequest request = new ReviseQuoteRequest();
            request.QuoteId = quoteId;
            request.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet("name","accountid");
            ReviseQuoteResponse response = (ReviseQuoteResponse)service.Execute(request);
            //草稿状态的报价单
            Entity quoteEn = response.Entity;
        }

        /// <summary>
        /// 汇总或检索与指定的记录(客户或联系人)相关的所有报价单
        /// </summary>
        /// <param name="target">客户或联系人引用</param>
        /// <param name="query">查询条件</param>
        /// <param name="rollupType">关联类型</param>
        public void Rollup(EntityReference target, QueryBase query, RollupType rollupType)
        {
            RollupRequest request = new RollupRequest();
            request.Target = target;
            request.Query = query;
            request.RollupType = rollupType;
            RollupResponse response = (RollupResponse)service.Execute(request);
            EntityCollection entityCollection = response.EntityCollection;
        }

        /// <summary>
        /// 删除报价单
        /// </summary>
        public void Delete()
        {
            service.Delete(entityName, quoteId);
        }
       
    }

crm操作报价单实体

标签:crm创建报价单   crm结束报价单   crm将报价单转换为销售订单   crm把报价单设置为草稿   crm删除报价单   

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

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