crm操作报价单实体

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

}

}

时间: 2024-10-24 09:27:30

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> /// 创建商机 /// </sum

crm操作约会实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; /// <summary> /// 约会 /// </summary> public class AppointmentHelper { public static readonly string entityName = "appointment"; pu

crm操作案例实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; /// <summary> /// 案例 /// </summary> public class IncidentHelper { public static readonly string entityName = "incident"; public G

crm操作发票实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; /// <summary> /// 发票 /// </summary> public class InvoiceHelper { public static readonly string entityName = "invoice"; public Gui

crm操作销售合同实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; /// <summary> /// 销售合同 /// </summary> public class ContractHelper { public static readonly string entityName = "contract"; public

crm操作货币实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> /// 货币 /// </summary> public class TransactionCurrencyHelper { public static readonly string entityName = "transactioncurrency"; public Guid trans

crm操作传真实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; /// <summary> /// 传真 /// </summary> public class FaxHelper { public static readonly string entityName = "fax"; public Guid faxId

crm操作产品实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> /// 产品 /// </summary> public class ProductHelper { public static readonly string entityName = "product"; public Guid productId = Guid.Empty; publi

crm操作权限

using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using System.Collections.Generic; using Microsoft.Crm.Sdk.Messages; /// <summary> /// 权限 /// </summary> public class PrivilegeHelper { public static readonly string entityNa