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

Quote Helper的更多相关文章

  1. [C#] 简单的 Helper 封装 -- RegularExpressionHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. handlebars自定义helper的写法

    handlebars相对来讲算一个轻量级.高性能的模板引擎,因其简单.直观.不污染HTML的特性,我个人特别喜欢.另一方面,handlebars作为一个logicless的模板,不支持特别复杂的表达式 ...

  3. 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": { " ...

  4. 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 ...

  5. JavaScript模板引擎artTemplate.js——template.helper()方法

    上一篇文章我们已经讲到了helper()方法,但是上面的例子只是一个参数的写法,如果是多个参数,写法就另有区别了. <div id="user_info"></d ...

  6. [ASP.NET MVC 小牛之路]13 - Helper Method

    我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 System.Web.Mvc 命名空间下的 HtmlHelper,习惯上我们把 ...

  7. asp.net MVC helper 和自定义函数@functions小结

    asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...

  8. C# random helper class

      项目中经常需要模拟些假数据,来做测试.这个随机生成数据的helper类就应用而生: using System; using System.Text; using System.Windows.Me ...

  9. Qt在pro文件中加入带空格的路径(使用$$quote关键字)

    LIBS += -L$$quote(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib) INCLUDEPATH += $$quote(C: ...

随机推荐

  1. python 小词云

    # Author:Alex.wang# Date:2017.06.02# Version:3.6.0 import matplotlib.pyplot as pltfrom wordcloud imp ...

  2. Java任务调度框架Quartz入门

    Quartz[kwɔːts]:石英,其框架和名字一样简单朴素又不失魅力,在Java程序界,Quartz大名鼎鼎,很多Java应用几乎都集成或构建了一个定时任务调度系统,Quartz是一个定时任务调度框 ...

  3. Useful WCF Behaviors - IErrorHandler

    Behaviors in WCF are so stinking useful, and once you get past the basics of WCF they're arguably a ...

  4. 【Leetcode】【Medium】Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  5. IERS-OSPF基本工作原理

    IERS-OSPF基本工作原理 一.邻居建立建立过程 1.Router ID 用于在自治系统中唯一标识一台运行OSPF的路由器,每台运行OSPF的路由器都有一个ROUTER ID Route ID 是 ...

  6. linux中进入mysql时报错Access denied for user 'root'@'localhost' (using password: YES)解决方案

    之前在linux中装完mysql后直接在命令行窗口输入mysql就会进入数据库了,但是今天输入mysql命令后直接报错,如下图: 之后输入:mysql -uroot -p 提示输入密码:***** 还 ...

  7. ZT UML 类与类之间的关系

    1.聚合关系是关联关系的一种,是强的关联关系.     2.聚合是整体和部分之间的关系,例如汽车由引擎.轮胎以及其它零件组成. 3.聚合关系也是通过成员变量来实现的.但是,关联关系所涉及的两个类处在同 ...

  8. 全新Chrome Devtool Performance使用指南

    运行时性能表现(runtime performance)指的是当你的页面在浏览器运行时的性能表现,而不是在下载页面的时候的表现.这篇指南将会告诉你怎么用Chrome DevToos Performan ...

  9. MATLAB入门学习(整合)

    整合一下,都是链接地址: MATLAB入门学习(一):初次使用.. MATLAB入门学习(二):矩阵相关 MATLAB入门学习(三):矩阵常用函数 MATLAB入门学习(四):编写简单.m文件和函数文 ...

  10. was缓存以致web.xml更改无效

    was缓存导致web.xml更改无效 在项目中经常遇见这样的问题:修改应用的配置文件web.xml后,无论重启应用还是重启WebSphere服务器,都不能重新加载web.xml,导致修改的内容无效. ...