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

crm操作销售合同实体

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

标签:crm创建销售合同   crm取消合同   crm复制合同   crm续订合同   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 Guid contractId = Guid.Empty;
        public IOrganizationService service;

        /// <summary>
        /// 创建销售合同
        /// </summary>
        public void Create()
        {
            Entity en = new Entity() { LogicalName = entityName };
            en["title"] = "销售合同测试";
            contractId = 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 = contractId };
            request.Assignee = assignee;
            AssignResponse response = (AssignResponse)service.Execute(request);
        }

        /// <summary>
        /// 取消合同
        /// </summary>
        /// <param name="status">取消的状态</param>
        public void CancelContract(int status)
        {
            CancelContractRequest request = new CancelContractRequest();
            request.ContractId = contractId;
            request.CancelDate = DateTime.Now;
            request.Status = new OptionSetValue(status);
            CancelContractResponse response = (CancelContractResponse)service.Execute(request);
        }

        /// <summary>
        /// 复制合同
        /// </summary>
        public void CloneContract()
        {
            CloneContractRequest request = new CloneContractRequest();
            request.ContractId = contractId;
            request.IncludeCanceledLines = true;
            CloneContractResponse response = (CloneContractResponse)service.Execute(request);
            //销售合同
            Entity contractEn = response.Entity;
        }

        /// <summary>
        /// 续订合同
        /// </summary>
        public void RenewContract()
        {
            RenewContractRequest request = new RenewContractRequest();
            request.ContractId = contractId;
            request.IncludeCanceledLines = true;
            //合同的状态
            request.Status = 0;
            RenewContractResponse response = (RenewContractResponse)service.Execute(request);
            //销售合同
            Entity contractEn = response.Entity;
        }

        /// <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 = contractId };
            request.PrincipalAccess = new PrincipalAccess() { AccessMask = accessMask, Principal = principal };
            GrantAccessResponse response = (GrantAccessResponse)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 = contractId };
            request.Revokee = revokee;
            RevokeAccessResponse response = (RevokeAccessResponse)service.Execute(request);
        }

        /// <summary>
        /// 删除销售合同
        /// </summary>
        public void Delete()
        {
            service.Delete(entityName, contractId);
        }
    }

crm操作销售合同实体

标签:crm创建销售合同   crm取消合同   crm复制合同   crm续订合同   crm删除销售合同   

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

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