博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
crm操作报价单实体
阅读量:6031 次
发布时间:2019-06-20

本文共 4640 字,大约阅读时间需要 15 分钟。

    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);
        }
       
    }

转载地址:http://rczhx.baihongyu.com/

你可能感兴趣的文章
[NOIP2011] 观光公交
查看>>
[洛谷P3203][HNOI2010]弹飞绵羊
查看>>
Google Chrome开发者工具
查看>>
第一阶段冲刺报告(一)
查看>>
使用crontab调度任务
查看>>
ctr预估论文梳理和个人理解
查看>>
【转载】SQL经验小记
查看>>
zookeeper集群搭建 docker+zk集群搭建
查看>>
Vue2.5笔记:Vue的实例与生命周期
查看>>
论JVM爆炸的几种姿势及自救方法
查看>>
联合体、结构体简析
查看>>
使用throw让服务器端与客户端进行数据交互[Java]
查看>>
java反射与代理
查看>>
深度分析Java的ClassLoader机制(源码级别)
查看>>
微服务架构选Java还是选Go - 多用户负载测试
查看>>
我的友情链接
查看>>
Javascript中的异步如何实现回调
查看>>
halcon算子介绍
查看>>
挖掘你不知道的windowsxp中的带宽潜能
查看>>
Software Engineering 招聘要求
查看>>