zoukankan      html  css  js  c++  java
  • Currency Helper

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;
    
    /// <summary>
    /// 货币
    /// </summary>
    public class TransactionCurrencyHelper
    {
        public static readonly string entityName = "transactioncurrency";
        public Guid transactionCurrencyId = Guid.Empty;
    
        /// <summary>
        /// 创建货币
        /// </summary>
        /// <param name="service">服务</param>
        public void Create(IOrganizationService service)
        {
            Entity en = new Entity() { LogicalName = entityName };
            //货币代码
            en["isocurrencycode"] = "CNY";
            //货币名称
            en["currencyname"] = "人民币";
            //货币精度
            en["currencyprecision"] = 2;
            //货币符合
            en["currencysymbol"] = "";
            //换算比率
            en["exchangerate"] = 1.0;
    
            transactionCurrencyId = service.Create(en);
        }
    
        /// <summary>
        /// 修改货币
        /// </summary>
        /// <param name="service">服务</param>
        public void Update(IOrganizationService service)
        {
            Entity en = new Entity() { LogicalName = entityName, Id = transactionCurrencyId };
            //货币名称
            en["currencyname"] = "人民币-2000";
    
            service.Update(en);
        }
    
        /// <summary>
        /// 检索汇率
        /// </summary>
        /// <param name="service">服务</param> 
        public decimal SearchRateById(IOrganizationService service)
        {
            decimal value = 0;
            RetrieveExchangeRateRequest request = new RetrieveExchangeRateRequest();
            request.TransactionCurrencyId = transactionCurrencyId;
            RetrieveExchangeRateResponse response = (RetrieveExchangeRateResponse)service.Execute(request);
            value = response.ExchangeRate;
            return value;
        }
    
        /// <summary>
        /// 停用和启用货币
        /// </summary>
        public void UpdateTransactionCurrencyState(IOrganizationService service)
        {
            //停用货币
            UpdateState(entityName, transactionCurrencyId, 1, 2, service);
            //启用货币
            UpdateState(entityName, transactionCurrencyId, 0, 1, service);
        }
    
        private void UpdateState(string enName, Guid id, int state, int status, IOrganizationService service)
        {
            SetStateRequest setState = new SetStateRequest()
            {
                EntityMoniker = new EntityReference()
                {
                    Id = id,
                    LogicalName = enName
                },
                State = new OptionSetValue(state),
                Status = new OptionSetValue(status)
            };
            service.Execute(setState);
        }
    
        /// <summary>         /// 
        /// 删除货币         /// 
        /// </summary>         /// 
        /// <param name="service">服务</param>         
        public void Delete(IOrganizationService service) { service.Delete(entityName, transactionCurrencyId); }
    }
  • 相关阅读:
    springboot注册为win服务特别简单
    mybatis-generator 自动生成代码
    springboot_+jpa 控制台输出sql
    java实现pdf转word(文字)
    Springboot项目使用aop添加日志
    利用chrome浏览器调试Web网页程序
    ORACLE 两表关联更新三种方式
    oracle有关函数 rank(),row_number(),dense_rank(),over()使用小结
    标量子查询要注意的坑
    Oracle分析函数KEEP、DENSE_RANK的使用
  • 原文地址:https://www.cnblogs.com/bennylam/p/9920900.html
Copyright © 2011-2022 走看看