crm工作机会实体

crm工作机会实体

大家好,又见面了,我是全栈君。

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

    public class OpportunityHelper
    {
        public static readonly string entityName = “opportunity”;
        public Guid opportunityId = Guid.Empty;

        /// <summary>
        /// 创建商机
        /// </summary>
        /// <param name=”service”>服务</param>
        /// <param name=”accountId”>潜在客户</param>
        public void Create(IOrganizationService service,Guid accountId)
        {
            Entity en = new Entity() { LogicalName = entityName };
            //主题
            en[“name”] = “測试商机”;
            //潜在客户
            en[“customerid”] = new EntityReference() { LogicalName = entityName,Id = accountId };

            opportunityId = service.Create(en);
        }

        /// <summary>
        /// 计算商机的值
        /// </summary>
        /// <param name=”service”>服务</param>
        public decimal CalculateActualValueOpportunity(IOrganizationService service)
        {
            CalculateActualValueOpportunityRequest request = new CalculateActualValueOpportunityRequest();
            request.OpportunityId = opportunityId;

            CalculateActualValueOpportunityResponse response =
                (CalculateActualValueOpportunityResponse)service.Execute(request);

            return response.Value;

        }

        /// <summary>
        /// 更改商机为赢单
        /// 1: 正在进行,2: 暂候,3: 赢单,4: 已取消,5: 售完
        /// </summary>
        public void WinOpportunity(IOrganizationService service)
        {
            WinOpportunityRequest request = new WinOpportunityRequest();
            request.OpportunityClose = new Entity() { LogicalName = entityName,Id = opportunityId };
            request.Status = new OptionSetValue(3);
            service.Execute(request);
        }

        /// <summary>
        /// 更改商机为丢单
        /// 1: 正在进行,2: 暂候,3: 赢单,4: 已取消,5: 售完
        /// </summary>
        public void LoseOpportunity(IOrganizationService service)
        {
            LoseOpportunityRequest request = new LoseOpportunityRequest();
            request.OpportunityClose = new Entity() { LogicalName = entityName, Id = opportunityId };
            request.Status = new OptionSetValue(4);
            service.Execute(request);
        }

        /// <summary>
        /// 商机生成报价单
        /// </summary>
        /// <param name=”service”>服务</param>
        public void ToQuote(IOrganizationService service)
        {
            GenerateQuoteFromOpportunityRequest request = new GenerateQuoteFromOpportunityRequest();
            request.OpportunityId = opportunityId;
            //这些字段将会转换
            request.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(“name”, “customerid”);
            GenerateQuoteFromOpportunityResponse response = (GenerateQuoteFromOpportunityResponse)service.Execute(request);
            //报价单实体
            Entity quoteEn = response.Entity;
        }

        /// <summary>
        /// 商机生成销售订单
        /// </summary>
        /// <param name=”service”>服务</param>
        public void ToSaleOrder(IOrganizationService service)
        {
            GenerateSalesOrderFromOpportunityRequest request = new GenerateSalesOrderFromOpportunityRequest();
            request.OpportunityId = opportunityId;
            //这些字段将会转换
            request.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(“name”, “customerid”);
            GenerateSalesOrderFromOpportunityResponse response = (GenerateSalesOrderFromOpportunityResponse)service.Execute(request);
            //销售订单
            Entity saloorderEn = response.Entity;
        }

        /// <summary>
        /// 商机生成发票
        /// </summary>
        /// <param name=”service”>服务</param>
        public void ToInvoiceFrom(IOrganizationService service)
        {
            GenerateInvoiceFromOpportunityRequest request = new GenerateInvoiceFromOpportunityRequest();
            request.OpportunityId = opportunityId;
            //这些字段将会转换
            request.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(“name”, “customerid”);
            GenerateInvoiceFromOpportunityResponse response = (GenerateInvoiceFromOpportunityResponse)service.Execute(request);
            //发票
            Entity invoiceFromEn = response.Entity;
        }

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

        /// <summary>
        /// 检索指定安全主体(用户或团队)对商机拥有的訪问权限
        /// </summary>
        /// <param name=”service”>服务</param>
        /// <param name=”principal”>用户或团队</param>
        public AccessRights RetrievePrincipalAccess(IOrganizationService service,EntityReference principal)
        {
            RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName, Id = opportunityId };
            request.Principal = principal;
            RetrievePrincipalAccessResponse response = (RetrievePrincipalAccessResponse)service.Execute(request);
            return response.AccessRights;
        }

        /// <summary>
        /// 检索有权訪问商机的安全主体(用户或团队)及其对商机所拥有的訪问权限
        /// </summary>
        public void RetrieveSharedPrincipalsAndAccess(IOrganizationService service)
        {
            RetrieveSharedPrincipalsAndAccessRequest request = new RetrieveSharedPrincipalsAndAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName, Id = opportunityId };
            RetrieveSharedPrincipalsAndAccessResponse response =
                (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(request);
            if (response != null && response.PrincipalAccesses != null)
            {
               foreach(PrincipalAccess pa in response.PrincipalAccesses)
               {
                   //訪问权限
                   AccessRights accessRights = pa.AccessMask;
                   //用户或者团队的引用
                   EntityReference Principal = pa.Principal;
               }
            }

        }

        /// <summary>
        /// 移除指定安全主体(用户或团队)对商机拥有的全部訪问权限。

        /// </summary>
        /// <param name=”service”>服务</param>
        /// <param name=”revokee”>用户或者团队</param>
        public void RevokeAccess(IOrganizationService service,EntityReference revokee)
        {
            RevokeAccessRequest request = new RevokeAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName, Id = opportunityId };
            request.Revokee = revokee;
            service.Execute(request);
        }

        /// <summary>
        /// 删除商机
        /// </summary>
        public void Delete(IOrganizationService service)
        {
            service.Delete(entityName, opportunityId);
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116659.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 数组转为list java_思考与实践并行的俗语

    数组转为list java_思考与实践并行的俗语不曾想到,“Java数组转List”竟然有这么多的学问,震撼之余夹带些许不堪。

  • 聚集索引和非聚集索引的区别[通俗易懂]

    聚集索引和非聚集索引的区别[通俗易懂]一、深入浅出理解索引结构实际上,可以把索引理解为一种特殊的目录。微软的SQLSERVER提供了两种索引:聚集索引(clusteredindex,也称聚类索引、簇集索引)和非聚集索引(nonclusteredindex,也称非聚类索引、非簇集索引)。下面,我们举例来说明一下聚集索引和非聚集索引的区别:其实,我们的汉语字典的正文本身就是一个聚集索引。比如,我们要查“安”字,因为“安”的拼音是…

  • Redis lock_lock锁机制原理

    Redis lock_lock锁机制原理Redisson分布式锁原理1.工具类packagecom.meta.mall.common.utils;importlombok.extern.slf4j.Slf4j;importorg.redisson.api.RLock;importorg.redisson.api.RedissonClient;importorg.springframework.stereotype.Component;importjavax.annotation.Resource;import

    2022年10月15日
  • 谷歌chrome浏览器被hao123 360等劫持问题解决方案

    谷歌chrome浏览器被hao123 360等劫持问题解决方案1.先chrome://version能看到下面这一串“C:\ProgramFiles\Google\Chrome\Application\chrome.exe”–flag-switches-begin–flag-switches-end–origin-trial-disabled-features=SecurePaymentConfirmationhttp://hao.360.com/?src=lm&ls=n4e1d7e8c992.复制上面这一串3.打开4.在标记处粘贴刚

  • 滤波算法(四)—— 卡尔曼滤波算法

    滤波算法(四)—— 卡尔曼滤波算法一、算法介绍卡尔曼滤波是一个神奇的滤波算法,应用非常广泛,它是一种结合先验经验、测量更新的状态估计算法。1、状态估计首先,对于一个我们关心的物理量,我们假设它符合下面的规律其中,为该物理量本周期的实际值,为该物理量上一个周期的实际值,当然这个物理量可能不符合这个规律,我们只是做了一个假设。不同的物理量符合的规律不同,是我们的经验,我们根据这个规律…

  • matlab 累加合,matlab循环语句for累加[通俗易懂]

    matlab 累加合,matlab循环语句for累加[通俗易懂]Matlabfor循环语句没仔细研究你那个拟合函数的用法。不过像这种需要分段处理数据的情况很多,有种在matlab里很常用的技巧感觉你可以学学:假设原始数据(xdata)是一列100个数,你需要一次处理13个,那么下面这段代码先将这100数“折叠”成一个13行的矩阵(x)。我这个例子里是折叠成13*8的矩阵了。因为100不能整除13,所以会在最后补零。如果你…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号