计算币别汇率
金蝶云社区-Jaden
Jaden
0人赞赏了该文章 427次浏览 未经作者许可,禁止转载编辑于2020年12月30日 11:14:39
///
/// 获取汇率
///

/// 汇率类型
/// 源币别
/// 目标币别
///
public decimal GetRate(long rateTypeID,long sourceCurrcyID,long targetCurrcyID)
{
if(sourceCurrcyID==targetCurrcyID)
{
return 1;
}
decimal exchangeRate = 0;
//string querySql = @"select t1.FEXCHANGERATE,t1.FREVERSEEXRATE from T_BD_Rate t1 where t1.FUSEORGID=@orgid and t1.FCYFORID=@CYFORID and t1.FCYTOID=@CYTOID and t1.FRATETYPEID=@FRATETYPEID and t1.FBEGDATE<=@date and t1.FENDDATE>=@date and t1.FDOCUMENTSTATUS='C'";
string querySql = @"select t1.FEXCHANGERATE,t1.FREVERSEEXRATE from T_BD_Rate t1 where t1.FCYFORID=@CYFORID and t1.FCYTOID=@CYTOID and t1.FRATETYPEID=@FRATETYPEID and t1.FBEGDATE<=@date and t1.FENDDATE>=@date and t1.FDOCUMENTSTATUS='C' and t1.FFORBIDSTATUS='A'";
SqlParam[] sqlparams = new[]
{
new SqlParam("@CYFORID",KDDbType.Int64,sourceCurrcyID),new SqlParam("@CYTOID",KDDbType.Int64,targetCurrcyID),
new SqlParam("@FRATETYPEID",KDDbType.Int64,rateTypeID),new SqlParam("@date",KDDbType.DateTime,DateTime.Now)
};
//exchangeRate = DBUtils.ExecuteScalar(ctx, querySql, 0, sqlparams); //查询本位币和结算币别之间的换算率
DynamicObjectCollection result = DBUtils.ExecuteDynamicObject(this.Context, strSQL: querySql, paramList: sqlparams); //查询本位币和结算币别之间的换算率
if (result == null || result.Count == 0)
{
sqlparams = new[] {
new SqlParam("@CYFORID",KDDbType.Int64,targetCurrcyID),new SqlParam("@CYTOID",KDDbType.Int64,sourceCurrcyID),
new SqlParam("@FRATETYPEID",KDDbType.Int64,rateTypeID),new SqlParam("@date",KDDbType.DateTime,DateTime.Now) };
result = DBUtils.ExecuteDynamicObject(this.Context, strSQL: querySql, paramList: sqlparams);
if (result != null)
{
exchangeRate = result.Select(t => (decimal)t["FREVERSEEXRATE"]).FirstOrDefault();
}
}
else
{
exchangeRate = result.Select(t => (decimal)t["FEXCHANGERATE"]).FirstOrDefault();
}
return exchangeRate;
}