Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. CRM. SDK. messages;
/// <Summary>
/// Currency
/// </Summary>
Public class transactioncurrencyhelper
{
Public static readonly string entityname = "transactioncurrency ";
Public guid transactioncurrencyid = guid. empty;
/// <Summary>
/// Create a currency
/// </Summary>
/// <Param name = "service"> service </param>
Public void create (iorganizationservice Service)
{
Entity en = new entity () {logicalname = entityname };
// Currency code
En ["isocurrencycode"] = "CNY ";
// Currency name
En ["currencyname"] = "coins for life ";
// Currency precision
En ["currencyprecision"] = 2;
// Currency conformity
En ["currencysymbol"] = "¥ ";
// Conversion Rate
En [& quot; exchangerate & quot;] = 1.0;
Transactioncurrencyid = service. Create (en );
}
/// <Summary>
/// Modify the currency
/// </Summary>
/// <Param name = "service"> service </param>
Public void Update (iorganizationservice Service)
{
Entity en = new entity () {logicalname = entityname, id = transactioncurrencyid };
// Currency name
En ["currencyname"] = "aliyun.com-2000 ";
Service. Update (en );
}
/// <Summary>
/// Retrieve the Exchange Rate
/// </Summary>
/// <Param name = "service"> 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>
/// Disable and enable currency
/// </Summary>
Public void updatetransactioncurrencystate (iorganizationservice Service)
{
// Deprecated currency
Updatestate (entityname, transactioncurrencyid, 1, 2, Service );
// Enable currency
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>
/// Delete currency
/// </Summary>
/// <Param name = "service"> service </param>
Public void Delete (iorganizationservice Service)
{
Service. Delete (entityname, transactioncurrencyid );
}
}
CRM operation currency entity