码迷,mamicode.com
首页 > 其他好文 > 详细

crm操作销售订单实体

时间:2014-07-20 10:24:18      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:crm创建销售订单   crm取消销售订单   crm将销售订单转换为发票   crm完成销售订单   crm锁定销售订单定价   

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

    /// <summary>
    /// 销售订单
    /// </summary>
    public class SoleOrderHelper
    {
        public static readonly string entityName = "salesorder";
        public Guid soleorderId = Guid.Empty;
        public IOrganizationService service;

        /// <summary>
        /// 创建销售订单
        /// </summary>
        public void Create(Guid accountId)
        {
            Entity en = new Entity() { LogicalName = entityName,Id = accountId };
            en["name"] = "销售订单测试";
            en["accountid"] = new EntityReference() { LogicalName = "account" ,Id = accountId };
            soleorderId = service.Create(en);
        }

        /// <summary>
        /// 将销售订单分派给其他用户或团队
        /// </summary>
        /// <param name="assignee">用户或团队引用</param>
        public void Assign(EntityReference assignee)
        {
            AssignRequest request = new AssignRequest();
            request.Target = new EntityReference() { LogicalName = entityName,Id = soleorderId };
            request.Assignee = assignee;
            AssignResponse response = (AssignResponse)service.Execute(request);
        }

        /// <summary>
        /// 取消销售订单
        /// </summary>
        /// <param name="status">取消的状态</param>
        public void CancelSalesOrder(int status)
        {
            CancelSalesOrderRequest request = new CancelSalesOrderRequest();
            request.OrderClose = new Entity() { LogicalName = entityName,Id = soleorderId };
            request.Status = new OptionSetValue(status);
            CancelSalesOrderResponse response = (CancelSalesOrderResponse)service.Execute(request);
        }

        /// <summary>
        /// 将销售订单转换为发票
        /// </summary>
        public void ConvertSalesOrderToInvoice()
        {
            ConvertSalesOrderToInvoiceRequest request = new ConvertSalesOrderToInvoiceRequest();
            request.SalesOrderId = soleorderId;
            request.ColumnSet = new ColumnSet("name","accountid");
            ConvertSalesOrderToInvoiceResponse response = (ConvertSalesOrderToInvoiceResponse)service.Execute(request);
            Entity invoiceEn = response.Entity;
        }

        /// <summary>
        /// 完成销售订单
        /// </summary>
        /// <param name="status">完成的状态</param>
        public void FulfillSalesOrder(int status)
        {
            FulfillSalesOrderRequest request = new FulfillSalesOrderRequest();
            request.OrderClose = new Entity() { LogicalName = entityName,Id = soleorderId };
            request.Status = new OptionSetValue(status);
            FulfillSalesOrderResponse response = (FulfillSalesOrderResponse)service.Execute(request);
        }

        /// <summary>
        /// 从指定商机中检索销售订单的产品组
        /// </summary>
        /// <param name="opportunityId">商机id</param>
        public void GetSalesOrderProductsFromOpportunity(Guid opportunityId)
        {
            GetSalesOrderProductsFromOpportunityRequest request = new GetSalesOrderProductsFromOpportunityRequest();
            request.OpportunityId = opportunityId;
            request.SalesOrderId = soleorderId;
            GetSalesOrderProductsFromOpportunityResponse response =
                (GetSalesOrderProductsFromOpportunityResponse)service.Execute(request);
        }

        /// <summary>
        /// 锁定销售订单定价
        /// </summary>
        public void LockSalesOrderPricing()
        {
            LockSalesOrderPricingRequest request = new LockSalesOrderPricingRequest();
            request.SalesOrderId = soleorderId;
            LockSalesOrderPricingResponse response = (LockSalesOrderPricingResponse)service.Execute(request); 
        }

        /// <summary>
        /// 解锁指定的销售订单(订单)中产品的单价
        /// </summary>
        public void UnlockSalesOrderPricing()
        {
            UnlockSalesOrderPricingRequest request = new UnlockSalesOrderPricingRequest();
            request.SalesOrderId = soleorderId;
            UnlockSalesOrderPricingResponse response = (UnlockSalesOrderPricingResponse)service.Execute(request);
        }

        /// <summary>
        /// 取消指定安全主体(用户或团队)对销售订单的所有访问权限
        /// </summary>
        /// <param name="revokee">用户或团队引用</param>
        public void RevokeAccess(EntityReference revokee)
        {
            RevokeAccessRequest request = new RevokeAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName,Id = soleorderId };
            request.Revokee = revokee;
            RevokeAccessResponse response = (RevokeAccessResponse)service.Execute(request);
        }

        /// <summary>
        /// 删除销售订单
        /// </summary>
        public void Delete()
        {
            service.Delete(entityName, soleorderId);
        }
    }

crm操作销售订单实体

标签:crm创建销售订单   crm取消销售订单   crm将销售订单转换为发票   crm完成销售订单   crm锁定销售订单定价   

原文地址:http://blog.csdn.net/y_f123/article/details/37988279

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!