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

        }

    }

crm工作机会实体的更多相关文章

  1. HTPC家庭娱乐和XBOX未来发展畅想<另:创业工作机会>

    微软中国在上海举办新闻发布会,正式宣布Xbox One将于9月23日在中国开始销售,定价3699元起.这款早在2001年就发布的电视游戏机终于在经历了14年的等待后,进军中国大陆市场.此次Xbox O ...

  2. Microsoft Dynamics CRM 2011 新建实体 需要注意的细节

    新建一个实体,需要红色框内的是否勾选的意义,可以进一步加深对CRM的理解.如图: 下面对部分的进行了自我的理解,不对的地方,还请大家指出来.互相学习. 1.CRM2011中,在活动方面加强的新特性包括 ...

  3. Dynamics CRM EntityCollection 根据实体中的某个字段为依据去除重复数据

    CRM中通过QueryExpression查询出了一个EntityCollection集,但有时会存在重复数据,QueryExpression中有个属性distinct,只要设置为true就能过滤 ...

  4. crm操作报价单实体

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

  5. crm操作货币实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages; /// <summary> ...

  6. Dynamics CRM 修改自定义实体名字及属性前缀(架构名称)

    本文章以2013为例(2011同理,4.0比较简单直接在系统设置的自定义中设置即可). 1.设置-->自定义项-->发布者,下图中的红框内的即为需要设置的前缀. 2.设置-->解决方 ...

  7. crm操作产品实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages; /// <summary> ...

  8. crm操作约会实体

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

  9. crm操作发票实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Xrm.Sdk.Query;     using Microsoft.Cr ...

随机推荐

  1. 主从mysql 同步设置

    GRANT REPLICATION SLAVE ON *.* TO 'root'@'%' IDENTIFIED BY 'zhoubt';grant all privileges on *.* to  ...

  2. html ui设计案例

    1.jquery特效:http://www.5icool.org 2. http://www.open-lib.com/Lib/1992.jsp

  3. SpringMVC: web.xml中声明DispatcherServlet时一定要加入load-on-startup标签

    游历SpringMVC源代码后发现,在web.xml中注冊的ContextLoaderListener监听器不过初始化了一个根上下文,只完毕了组件扫描和与容器初始化相关的一些工作,并没有探測到详细每一 ...

  4. dumpbin

    在使用VC时,可以用DUMPBIN.EXE来得到某个DLL中所输出的符号的清单.如下面的 命令:dumpbin -exports Cmpnt1.dll如: C:/WINDOWS/system32> ...

  5. 更改EBSserver域名/IP

    more: 341322.1 : How to change the hostname of an Applications Tier using AutoConfig 338003.1 : How  ...

  6. 纠正一个概念:类就有VMT,各实例不过是共享这个VMT而已

    不是只有实例才有VMT,举个例子,各实例的VMT地址是相同的: Use System.Contnrs; procedure TForm1.BitBtn2Click(Sender: TObject); ...

  7. thinkphp3.2入口文件

    原文:thinkphp3.2入口文件 <?php define('DIR_SECURE_FILENAME', 'default.html');//错误页面 define('APP_PATH',' ...

  8. Android相关

    wifi密码:因为我们安卓系统的手机无线账号数据是储存在一个文件里的,那就是 /data/misc/wifi/wpa_supplicant.conf ,这个是系统文件,权限不够高是无法访问的,而这个文 ...

  9. c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)

    一.单元格内容的操作 *****// 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index ...

  10. 在html中写python代码的语法和特点-----基于webpy的httpserver

    在html文件里写python语法的内容,的注意事项: 1:python程序中的变量通过以下方法传入到html: 1:通过全局变量 :全局变量是不须要用$def with语法实现传递的,仅仅要定义了 ...