Opportunity Helper
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();
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();
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); }
}
Opportunity Helper的更多相关文章
- [C#] 简单的 Helper 封装 -- RegularExpressionHelper
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- handlebars自定义helper的写法
handlebars相对来讲算一个轻量级.高性能的模板引擎,因其简单.直观.不污染HTML的特性,我个人特别喜欢.另一方面,handlebars作为一个logicless的模板,不支持特别复杂的表达式 ...
- Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'
project.json 配置: { "version": "1.0.0-*", "compilationOptions": { " ...
- VS2015突然报错————Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value 'Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper
Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with ...
- JavaScript模板引擎artTemplate.js——template.helper()方法
上一篇文章我们已经讲到了helper()方法,但是上面的例子只是一个参数的写法,如果是多个参数,写法就另有区别了. <div id="user_info"></d ...
- [ASP.NET MVC 小牛之路]13 - Helper Method
我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 System.Web.Mvc 命名空间下的 HtmlHelper,习惯上我们把 ...
- asp.net MVC helper 和自定义函数@functions小结
asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...
- C# random helper class
项目中经常需要模拟些假数据,来做测试.这个随机生成数据的helper类就应用而生: using System; using System.Text; using System.Windows.Me ...
- @helper函数使用方法
这个函数方法,我也是通过别人博客看到的,感觉不错和大家一起学习分享一下. 1.自定义函数方法,只在同一个view视图文件里调用 Controller public ActionResult Index ...
随机推荐
- xlwings: Write Excel macro using python instead of VBA
i want to write Excel macros to deal with the data, but i am not familiar with VBA language. so i de ...
- less @import and extend及mixin详解
在less中,通过 @import (keyword) "filename"的方式引入其他的文件,这个keyword可以是以下6种: referrence referrence这个 ...
- 给Docker武士们的正式邀请,赶紧收哦!
亲爱的Docker武士,Docker大师们喊你来参加Docker的定期聚啦~收好时间.地点,快来相见.切磋Docker吧!5月17日,微软上海港汇办公室,我们与你不见不散! 点击阅读原文,或直接进入注 ...
- SQL Server ->> Online Index Rebuilding(联机索引重建)
SQL Server的Enterprise Edition是支持联机索引重建的.那么联机索引重建是怎么工作的以及对我们的查询有什么影响呢? 既然是联机,SQL Server保持了现有索引对于用户的可用 ...
- LeetCode-Maximal Rectangle[code]
code: #include <iostream> #include <vector> #include <stack> #include <algorith ...
- order by注入点利用方式分析
漏洞分析 使用sqli-lab中的lesson-52作为测试目标.关键代码为: error_reporting(0); $id=$_GET['sort']; if(isset($id)) { //lo ...
- lua之m进制转换为n进制-任意进制转换算法
够无聊的写这个,为防止需要的人也无聊一遍,写个吧 算法有n种,但是,咱们一种就够用了 --数组倒序排列 local function orderByDesc( input ) local output ...
- 阿里云免费ssl,https证书的申请和校验
其实写这个之前一直在考虑要不要写出来 ,真的官方文档实在太强大了,连视频都给你录好了,配不好的,是不是可以考虑不用写程序了, 忽然想到第一次使用微信测试号,进行域名认证的时候,因为后台返回“echar ...
- Intellij IDEA设置注释作者名字
方法一:File >> Settings >> Editor >>Code Style >> File and Code Templates>&g ...
- hdu1579 Function Run Fun(深搜+记忆化)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/37076755 转载请注明出处 ...