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. SpringMVC学习(五)——拦截器示例

    部分内容摘自开涛的<跟我学SpringMVC.PDF> 拦截器,本质类似于AOP,主要的应用场景: 1.日志记录:记录请求信息的日志,以便进行信息监控.信息统计.计算PV等. 2.权限检查 ...

  2. named 快速部署及主机记录普及

    实验环境centos7.2,仅供参考 yum -y install epel-release    --安装最新yum配置源 cd /etc/yum.repos.d/ # wget http://re ...

  3. RESTful架构及SOA架构简单解析

    1.RESTful架构 本人也是刚接触ASP.NET开发,以下为自己简单的理解,并做了一些记录,表述不当或者错误之处还请指正,在此谢过. 首先,REST(REpresentational State  ...

  4. Mysql 系统学习梳理_【All】

    0.Linux学习---CentOS 7编译安装MySQL 8.0 1.Mysql学习---SQL语言的四大分类 2.Mysql学习---基础操作学习 3.Mysql学习---基础操作学习2 4.My ...

  5. 合并两个数组 以KEY 作为键

    <?php     $a= array(         array(             'ID'=> 2         ) );   $b= array(         arr ...

  6. ADB命令详解及大全( 声明:此文是参考大佬博客所做的笔记!)

    adb是什么? adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具.a ...

  7. 如何删除Word 2010中的“向下箭头”

    原文:https://jingyan.baidu.com/article/e75aca85552916142edac614.html 在日常办公中,如果从网站复制了一段文字,直接粘贴到Word中时,常 ...

  8. 谁把我的表给drop了?

    今天生产上有人把几张表给DROP了,一通折腾.恢复备份导数回来数据,重建索引. 但是,我就想知道是谁给干掉了. 到你被删除表数据库中找日志吧.其它的也想不到更好办法了 USE '被删表数据库' --查 ...

  9. mxnet导入图像数据

    图像的标签在一个json文件中. %matplotlib inline import json import gluonbook as gb import mxnet as mx from mxnet ...

  10. thinkphp清除缓存

    前台 //清除缓存 $(function(){ $("#cache").click(function(){ layer.confirm('你确定要清除缓存吗?', {icon: 3 ...