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)


相关推荐

发表回复

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

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