You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7HYRD/DSWeb/FeeCodes/CurrencyCodeService.aspx.cs

1081 lines
51 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using DSWeb.EntityDA;
using DSWeb.Attributes;
namespace DSWeb.FeeCodes
{
public partial class CurrencyCodeService : System.Web.UI.Page
{
private string strCurrencyCode;//币别编码 CODENAME
private string strFeeGid;//委托编号
private const int iResult = -1;
private const int iSetting = 2;//测试使用数据 值1-默认系统设置为以开船日期为准 值2-默认系统设置为会计期间为准
private int iType;//费用类型 1-海运出口委托 2-海运出口销售订舱 3-费用模板
private string strUserID;
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strBSNO;
private string strhandle="";//seae\seai\
private string stroplb = "";//业务类别
protected void Page_Load(object sender, EventArgs e)
{
//strCurrencyCode = (String)Request.QueryString["currency"] as String;
//strFeeGid = (String)Request.QueryString["gid"] as String;
//strBSNO = (String)Request.QueryString["bsno"] as String;
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strhandle = Request.QueryString["handle"].ToString();
}
if (Request.QueryString["oplb"] != null)
{
stroplb = Request.QueryString["oplb"].ToString();
}
if (Request.QueryString["currency"] != null)
{
strCurrencyCode = Request.QueryString["currency"].ToString();
}
if (Request.QueryString["gid"] != null)
{
strFeeGid = Request.QueryString["gid"].ToString();
}
if (Request.QueryString["bsno"] != null)
{
strBSNO = Request.QueryString["bsno"].ToString();
}
if (Request.QueryString["type"] != null)
{
iType = int.Parse(Request.QueryString["type"].ToString());
}
else
{
iType = 0;
}
if (strBSNO != null && strCurrencyCode != null && iType != 0)
{
//获取海运出口委托op_seae/op_seai或销售订舱crm_seaeorder费用汇率
Response.Write(GetExchangeRateByCurrencyAndBSNO(strCurrencyCode, strBSNO, iType));
}
if (strCurrencyCode != null && strFeeGid != null)
{
Response.Write(getExchangeRateByCurCode(strCurrencyCode, strFeeGid));
}
}
#region 获取海运出口委托op_seae/op_seai或销售订舱crm_seaeorder费用汇率
/// <summary>
/// 获取海运出口委托或销售订舱费用汇率
/// </summary>
/// <param name="tempCurrencyCodeName">币别COD</param>
/// <param name="tempBSNO">bsno</param>
/// <param name="tempType">费用类型</param>
/// <returns>销售订舱费用汇率</returns>
private string GetExchangeRateByCurrencyAndBSNO(string tempCurrencyCodeName, string tempBSNO, int tempType)
{
decimal dExchangeRate = 0;
//币别实体类
CurrencyEntity currencyEntity = new CurrencyEntity();
//根据币别CODE获取币别信息
CurrencyDA currencyDA = new CurrencyDA();
currencyEntity = currencyDA.GetCurrencyByCodeName(strCurrencyCode);
if (currencyEntity.GID==null)
{
return dExchangeRate.ToString();
}
//汇率表
ExchangeRateDA exchangeDA = new ExchangeRateDA();
IList<ExchangeRateEntity> exchangeRateEntities = new List<ExchangeRateEntity>();
//通过币别GID获取相关汇率所有信息
exchangeRateEntities = exchangeDA.GetExchangeRateByCurrencyID(currencyEntity.GID,strCompanyID);
if (stroplb == "op_Seae" && tempType == 1)
{
#region 海运出口委托
SeaExportInfoDA seaExportDA = new SeaExportInfoDA();
//海运出口委托
TopSeaeEntity topSeaeEntity = new TopSeaeEntity();
//根据委托编号获取海运业务主表信息
topSeaeEntity = seaExportDA.GetID(tempBSNO);
//先获取分公司汇率参数设置
AttributeManage attributeManager = new AttributeManage();
//根据属性Name、属性type、分公司ID返回分公司属性信息(company_attribute和attribute)
AttributeCompanyEntity attributeCompanyEntity = (AttributeCompanyEntity)attributeManager.FindAttributeByName("refSubCompanyExchangeRate", AttributeType.COMPANYATTRIBUTE, strCompanyID) as AttributeCompanyEntity;
if (attributeCompanyEntity != null)
{
if (attributeCompanyEntity.GID != null)
{
dExchangeRate = CheckExchangeRateOpSeae(topSeaeEntity, attributeCompanyEntity.AttributeValue, exchangeRateEntities, currencyEntity.DefaultRate);
}
else
{
dExchangeRate = CheckExchangeRateOpSeae(topSeaeEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
}
}
else
{
dExchangeRate = CheckExchangeRateOpSeae(topSeaeEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
}
#endregion
}
else if (stroplb == "op_Seai" && tempType == 1)
{
#region 海运出口委托
SeaImportInfoDA seaImportDA = new SeaImportInfoDA();
//海运出口委托
TopSeaiEntity topSeaiEntity = new TopSeaiEntity();
//根据委托编号获取海运业务主表信息
topSeaiEntity = seaImportDA.GetID(tempBSNO);
//先获取分公司汇率参数设置
AttributeManage attributeManager = new AttributeManage();
//根据属性Name、属性type、分公司ID返回分公司属性信息(company_attribute和attribute)
AttributeCompanyEntity attributeCompanyEntity = (AttributeCompanyEntity)attributeManager.FindAttributeByName("refSubCompanyExchangeRate", AttributeType.COMPANYATTRIBUTE, strCompanyID) as AttributeCompanyEntity;
if (attributeCompanyEntity != null)
{
if (attributeCompanyEntity.GID != null)
{
dExchangeRate = CheckExchangeRateOpSeai(topSeaiEntity, attributeCompanyEntity.AttributeValue, exchangeRateEntities, currencyEntity.DefaultRate);
}
else
{
dExchangeRate = CheckExchangeRateOpSeai(topSeaiEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
}
}
else
{
dExchangeRate = CheckExchangeRateOpSeai(topSeaiEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
}
#endregion
}
else if (stroplb == "op_Sean" && tempType == 1)
{
Opsean seanDA = new Opsean();
OpseanEntity seanEntity = new OpseanEntity();
seanEntity = seanDA.GetAllSeanInfo(tempBSNO);
AttributeManage attributeManager = new AttributeManage();
AttributeCompanyEntity attributeCompanyEntity = (AttributeCompanyEntity)attributeManager.FindAttributeByName("refSubCompanyExchangeRate", AttributeType.COMPANYATTRIBUTE, strCompanyID) as AttributeCompanyEntity;
if (attributeCompanyEntity != null)
{
if (attributeCompanyEntity.GID != null)
{
dExchangeRate = checkExchangeRateOpSean(seanEntity, attributeCompanyEntity.AttributeValue, exchangeRateEntities, currencyEntity.DefaultRate);
}
else
{
dExchangeRate = checkExchangeRateOpSean(seanEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
}
}
else
{
dExchangeRate = checkExchangeRateOpSean(seanEntity,"account",exchangeRateEntities,currencyEntity.DefaultRate);
}
}
#region 出库单
//else if (stroplb == "wms_out" && tempType == 1)
//{
//
// WmsOutDA WmsOutDA = new WmsOutDA();
// //出库单
// WmsOutEntity WmsOutEntity = new WmsOutEntity();
// //根据委托编号获取海运业务主表信息
// WmsOutEntity = WmsOutDA.GetModel(tempBSNO,"");
// //先获取分公司汇率参数设置
// AttributeManage attributeManager = new AttributeManage();
// //根据属性Name、属性type、分公司ID返回分公司属性信息(company_attribute和attribute)
// AttributeCompanyEntity attributeCompanyEntity = (AttributeCompanyEntity)attributeManager.FindAttributeByName("refSubCompanyExchangeRate", AttributeType.COMPANYATTRIBUTE, strCompanyID) as AttributeCompanyEntity;
// if (attributeCompanyEntity != null)
// {
// if (attributeCompanyEntity.GID != null)
// {
// dExchangeRate = CheckExchangeRateWmsOut(WmsOutEntity, attributeCompanyEntity.AttributeValue, exchangeRateEntities, currencyEntity.DefaultRate);
// }
// else
// {
// dExchangeRate = CheckExchangeRateWmsOut(WmsOutEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
// }
// }
// else
// {
// dExchangeRate = CheckExchangeRateWmsOut(WmsOutEntity, "account", exchangeRateEntities, currencyEntity.DefaultRate);
// }
//
//}
#endregion
else if (tempType == 2)
{
#region 海运出口销售订舱
//海运出口销售订舱
CrmSeaeorderDA crmSeaeOrderDA = new CrmSeaeorderDA();
//海运出口委托
CrmSeaeorderEntity crmSeaeOrderEntity = new CrmSeaeorderEntity();
//根据委托编号获取海运出口销售主表crm_seaeorder信息
crmSeaeOrderEntity = crmSeaeOrderDA.GetID(tempBSNO);
//先获取分公司汇率参数设置
AttributeManage attributeManager = new AttributeManage();
AttributeCompanyEntity attributeCompanyEntity = (AttributeCompanyEntity)attributeManager.FindAttributeByName("refSubCompanyExchangeRate", AttributeType.COMPANYATTRIBUTE, strCompanyID) as AttributeCompanyEntity;
if (attributeCompanyEntity != null)
{
if (attributeCompanyEntity.GID != null)
{ //获取销售订舱费用汇率
dExchangeRate = CheckExchangeRateCrmOrder(crmSeaeOrderEntity, attributeCompanyEntity.AttributeValue, exchangeRateEntities, currencyEntity.DefaultRate);
}
else
{ //获取销售订舱费用汇率
dExchangeRate = CheckExchangeRateCrmOrder(crmSeaeOrderEntity, "shipping", exchangeRateEntities, currencyEntity.DefaultRate);
}
}
else
{ //获取销售订舱费用汇率
dExchangeRate = CheckExchangeRateCrmOrder(crmSeaeOrderEntity, "shipping", exchangeRateEntities, currencyEntity.DefaultRate);
}
#endregion
}
else if (tempType == 3)
{
}
return dExchangeRate.ToString();
}
#endregion
/// <summary>
/// 获取内贸海运委托费用汇率
/// </summary>
/// <param name="seanEntity">内贸海运委实体</param>
/// <param name="tempRateType">汇率类型</param>
/// <param name="tempExchangeRateEntity">货币币种汇率实体</param>
/// <param name="dDefaultRate">默认汇率</param>
/// <returns></returns>
private decimal checkExchangeRateOpSean(OpseanEntity seanEntity, string tempRateType, IList<ExchangeRateEntity> tempExchangeRateEntity, decimal dDefaultRate)
{
decimal dExchangeRate = 0;
DateTime tempEqualtime = DateTime.MinValue;
string strRecycleType = tempRateType;
int iFirstCount = 0;
while (dExchangeRate == 0)
{
#region
switch(strRecycleType)
{
case "common":
if (seanEntity.INPUTTIME != null)
{
if (!seanEntity.INPUTTIME.ToString().Trim().Equals(""))
{
tempEqualtime = DateTime.Parse(seanEntity.INPUTTIME.ToString().Trim());
}
}
break;
case "shipping":
if (seanEntity.ETD != null)
{
if (!seanEntity.ETD.ToString().Trim().Equals(""))
{
tempEqualtime = DateTime.Parse(seanEntity.ETD.ToString().Trim());
}
}
break;
case "account":
if (seanEntity.ACCDATE != null)
{
if (!seanEntity.ACCDATE.ToString().Trim().Equals(""))
{
tempEqualtime = DateTime.Parse(seanEntity.ACCDATE.ToString().Trim());
}
}
break;
default:
if (seanEntity.INPUTTIME != null)
{
if (!seanEntity.INPUTTIME.ToString().Equals(""))
{
tempEqualtime = DateTime.Parse(seanEntity.INPUTTIME.ToString().Trim());
}
}
break;
}
#endregion
for (int i = 0; i < tempExchangeRateEntity.Count; i++)
{
if (tempExchangeRateEntity[i].Type.Trim().ToLower().Equals(strRecycleType))
{
if (tempEqualtime != DateTime.MinValue && tempExchangeRateEntity[i].StartTime != DateTime.MinValue && tempExchangeRateEntity[i].EndTime != DateTime.MinValue)
{
DateTime etdtime = tempEqualtime;//获取开船时间
DateTime starttime = tempExchangeRateEntity[i].StartTime;//获取汇率开始时间
DateTime endtime = tempExchangeRateEntity[i].EndTime;//获取汇率结束时间
if (etdtime >= starttime && etdtime <= endtime)
{
dExchangeRate = tempExchangeRateEntity[i].Value;//如果获取到汇率值则结束查询
break;
}
}
if (iFirstCount == 0 && strRecycleType == "common" && tempExchangeRateEntity[i].StartTime == DateTime.MinValue && tempExchangeRateEntity[i].EndTime == DateTime.MinValue)
{
dExchangeRate = tempExchangeRateEntity[i].Value;
break;
}
}
}
if (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "account":
strRecycleType = "shipping";
break;
case "shipping":
strRecycleType = "common";
break;
case "common":
dExchangeRate = dDefaultRate;
break;
default:
dExchangeRate = dDefaultRate;
break;
}
}
iFirstCount++;
}
return dExchangeRate;
}
#region 获取海运出口委托费用汇率
/// <summary>
/// 获取海运出口委托费用汇率
/// </summary>
/// <param name="tempTopSeaeEntity">海运出口委托实体类</param>
/// <param name="tempRateType">汇率类型(string)</param>
/// <param name="tempExchangeRateEntities">币别汇率实体类</param>
/// <param name="dDefaultRate">默认汇率</param>
/// <returns>返回汇率</returns>
private decimal CheckExchangeRateOpSeae(TopSeaeEntity tempTopSeaeEntity, string tempRateType, IList<ExchangeRateEntity> tempExchangeRateEntities,decimal dDefaultRate)
{
decimal dExchangeRate = 0;
DateTime tempEqualTime = DateTime.MinValue;
string strRecycleType = tempRateType;
int iFirstCount = 0;
while (dExchangeRate == 0)
{
#region
switch (strRecycleType)
{
case "common"://如果是普通汇率
if (tempTopSeaeEntity.CREATETIME != null)
{
if (!tempTopSeaeEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaeEntity.CREATETIME.ToString().Trim());
}
}
break;
case "shipping":
if (tempTopSeaeEntity.ETD != null)
{
if (!tempTopSeaeEntity.ETD.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaeEntity.ETD.ToString().Trim());
}
}
break;
case "account":
if (tempTopSeaeEntity.ACCDATE != null)
{
if (!tempTopSeaeEntity.ACCDATE.Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaeEntity.ACCDATE.ToString().Trim());
}
}
break;
default:
if (tempTopSeaeEntity.CREATETIME != null)
{
if (!tempTopSeaeEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaeEntity.CREATETIME.ToString().Trim());
}
}
break;
}
#endregion
for (int i = 0; i < tempExchangeRateEntities.Count; i++)
{
if (tempExchangeRateEntities[i].Type.Trim().ToLower().Equals(strRecycleType))
{
if (tempEqualTime != DateTime.MinValue && tempExchangeRateEntities[i].StartTime != DateTime.MinValue && tempExchangeRateEntities[i].EndTime != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = tempEqualTime;
//汇率起始时间
DateTime startTime = tempExchangeRateEntities[i].StartTime;
//汇率结束时间
DateTime endTime = tempExchangeRateEntities[i].EndTime;
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
if (iFirstCount == 0 && strRecycleType == "common" && tempExchangeRateEntities[i].StartTime == DateTime.MinValue && tempExchangeRateEntities[i].EndTime == DateTime.MinValue)
{
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
}
if (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "account":
strRecycleType = "shipping";
break;
case "shipping":
strRecycleType = "common";
break;
case "common":
dExchangeRate = dDefaultRate;
break;
default:
dExchangeRate = dDefaultRate;
break;
}
}
iFirstCount++;
}
return dExchangeRate;
}
#endregion
#region 获取海运进口委托费用汇率
/// <summary>
/// 获取海运进口委托费用汇率
/// </summary>
/// <param name="tempTopSeaeEntity">海运进口委托实体类</param>
/// <param name="tempRateType">汇率类型(string)</param>
/// <param name="tempExchangeRateEntities">币别汇率实体类</param>
/// <param name="dDefaultRate">默认汇率</param>
/// <returns>返回汇率</returns>
private decimal CheckExchangeRateOpSeai(TopSeaiEntity tempTopSeaiEntity, string tempRateType, IList<ExchangeRateEntity> tempExchangeRateEntities, decimal dDefaultRate)
{
decimal dExchangeRate = 0;
DateTime tempEqualTime = DateTime.MinValue;
string strRecycleType = tempRateType;
int iFirstCount = 0;
while (dExchangeRate == 0)
{
#region
switch (strRecycleType)
{
case "common"://如果是普通汇率
if (tempTopSeaiEntity.CREATETIME != null)
{
if (!tempTopSeaiEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaiEntity.CREATETIME.ToString().Trim());
}
}
break;
case "shipping":
if (tempTopSeaiEntity.ETD != null)
{
if (!tempTopSeaiEntity.ETD.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaiEntity.ETD.ToString().Trim());
}
}
break;
case "account":
if (tempTopSeaiEntity.ACCDATE != null)
{
if (!tempTopSeaiEntity.ACCDATE.Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaiEntity.ACCDATE.ToString().Trim());
}
}
break;
default:
if (tempTopSeaiEntity.CREATETIME != null)
{
if (!tempTopSeaiEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempTopSeaiEntity.CREATETIME.ToString().Trim());
}
}
break;
}
#endregion
for (int i = 0; i < tempExchangeRateEntities.Count; i++)
{
if (tempExchangeRateEntities[i].Type.Trim().ToLower().Equals(strRecycleType))
{
if (tempEqualTime != DateTime.MinValue && tempExchangeRateEntities[i].StartTime != DateTime.MinValue && tempExchangeRateEntities[i].EndTime != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = tempEqualTime;
//汇率起始时间
DateTime startTime = tempExchangeRateEntities[i].StartTime;
//汇率结束时间
DateTime endTime = tempExchangeRateEntities[i].EndTime;
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
if (iFirstCount == 0 && strRecycleType == "common" && tempExchangeRateEntities[i].StartTime == DateTime.MinValue && tempExchangeRateEntities[i].EndTime == DateTime.MinValue)
{
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
}
if (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "account":
strRecycleType = "shipping";
break;
case "shipping":
strRecycleType = "common";
break;
case "common":
dExchangeRate = dDefaultRate;
break;
default:
dExchangeRate = dDefaultRate;
break;
}
}
iFirstCount++;
}
return dExchangeRate;
}
#endregion
#region 获取出库单费用汇率
/// <summary>
/// 获取出库单费用汇率
/// </summary>
/// <param name="tempTopSeaeEntity">出库单实体类</param>
/// <param name="tempRateType">汇率类型(string)</param>
/// <param name="tempExchangeRateEntities">币别汇率实体类</param>
/// <param name="dDefaultRate">默认汇率</param>
/// <returns>返回汇率</returns>
private decimal CheckExchangeRateWmsOut(WmsOutEntity tempWmsOutEntity, string tempRateType, IList<ExchangeRateEntity> tempExchangeRateEntities, decimal dDefaultRate)
{
decimal dExchangeRate = 0;
DateTime tempEqualTime = DateTime.MinValue;
string strRecycleType = tempRateType;
int iFirstCount = 0;
while (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "common"://如果是普通汇率
if (tempWmsOutEntity.CREATETIME != null)
{
if (!tempWmsOutEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempWmsOutEntity.CREATETIME.ToString().Trim());
}
}
break;
//case "shipping":
// if (tempWmsOutEntity.ETD != null)
// {
// if (!tempWmsOutEntity.ETD.ToString().Trim().Equals(""))
// {
// tempEqualTime = DateTime.Parse(tempWmsOutEntity.ETD.ToString().Trim());
// }
// }
// break;
//case "account":
// if (tempWmsOutEntity.ACCDATE != null)
// {
// if (!tempWmsOutEntity.ACCDATE.Trim().Equals(""))
// {
// tempEqualTime = DateTime.Parse(tempWmsOutEntity.ACCDATE.ToString().Trim());
// }
// }
// break;
default:
if (tempWmsOutEntity.CREATETIME != null)
{
if (!tempWmsOutEntity.CREATETIME.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(tempWmsOutEntity.CREATETIME.ToString().Trim());
}
}
break;
}
for (int i = 0; i < tempExchangeRateEntities.Count; i++)
{
if (tempExchangeRateEntities[i].Type.Trim().ToLower().Equals(strRecycleType))
{
if (tempEqualTime != DateTime.MinValue && tempExchangeRateEntities[i].StartTime != DateTime.MinValue && tempExchangeRateEntities[i].EndTime != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = tempEqualTime;
//汇率起始时间
DateTime startTime = tempExchangeRateEntities[i].StartTime;
//汇率结束时间
DateTime endTime = tempExchangeRateEntities[i].EndTime;
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
if (iFirstCount == 0 && strRecycleType == "common" && tempExchangeRateEntities[i].StartTime == DateTime.MinValue && tempExchangeRateEntities[i].EndTime == DateTime.MinValue)
{
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
}
if (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "account":
strRecycleType = "shipping";
break;
case "shipping":
strRecycleType = "common";
break;
case "common":
dExchangeRate = dDefaultRate;
break;
default:
dExchangeRate = dDefaultRate;
break;
}
}
iFirstCount++;
}
return dExchangeRate;
}
#endregion
#region 获取销售订舱费用汇率
/// <summary>
/// 获取销售订舱费用汇率
/// </summary>
/// <param name="crmSeaeOrderEntity">销售订舱信息</param>
/// <param name="tempRateType">汇率类型(string)</param>
/// <param name="tempExchangeRateEntities">币别汇率实体类组</param>
/// <param name="dDefaultRate">默认汇率</param>
/// <returns>返回汇率值</returns>
private decimal CheckExchangeRateCrmOrder(CrmSeaeorderEntity crmSeaeOrderEntity, string tempRateType, IList<ExchangeRateEntity> tempExchangeRateEntities, decimal dDefaultRate)
{
decimal dExchangeRate = 0;
DateTime tempEqualTime = DateTime.MinValue;
string strRecycleType = tempRateType;
int iFirstCount = 0;
while (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "common"://如果是普通汇率
if (crmSeaeOrderEntity.BSDATE != null)
{
if (!crmSeaeOrderEntity.BSDATE.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(crmSeaeOrderEntity.BSDATE.ToString().Trim());
}
}
break;
case "shipping":
if (crmSeaeOrderEntity.ETD != null)
{
if (!crmSeaeOrderEntity.ETD.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(crmSeaeOrderEntity.ETD.ToString().Trim());
}
}
break;
case "account":
//if (crmSeaeOrderEntity.ACCDATE != null)
//{
// if (!crmSeaeOrderEntity.ACCDATE.Trim().Equals(""))
// {
// tempEqualTime = DateTime.Parse(crmSeaeOrderEntity.ACCDATE.ToString().Trim());
// }
//}
break;
default:
if (crmSeaeOrderEntity.BSDATE != null)
{
if (!crmSeaeOrderEntity.BSDATE.ToString().Trim().Equals(""))
{
tempEqualTime = DateTime.Parse(crmSeaeOrderEntity.BSDATE.ToString().Trim());
}
}
break;
}
for (int i = 0; i < tempExchangeRateEntities.Count; i++)
{
if (tempExchangeRateEntities[i].Type.Trim().ToLower().Equals(strRecycleType))
{
if (tempEqualTime != DateTime.MinValue && tempExchangeRateEntities[i].StartTime != DateTime.MinValue && tempExchangeRateEntities[i].EndTime != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = tempEqualTime;
//汇率起始时间
DateTime startTime = tempExchangeRateEntities[i].StartTime;
//汇率结束时间
DateTime endTime = tempExchangeRateEntities[i].EndTime;
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
if (iFirstCount == 0 && strRecycleType == "common" && tempExchangeRateEntities[i].StartTime == DateTime.MinValue && tempExchangeRateEntities[i].EndTime == DateTime.MinValue)
{
dExchangeRate = tempExchangeRateEntities[i].Value;
break;
}
}
}
if (dExchangeRate == 0)
{
switch (strRecycleType)
{
case "account":
strRecycleType = "shipping";
break;
case "shipping":
strRecycleType = "common";
break;
case "common":
dExchangeRate = dDefaultRate;
break;
default:
dExchangeRate = dDefaultRate;
break;
}
}
iFirstCount++;
}
return dExchangeRate;
}
#endregion
#region 根据费用信息表GID和币别CodeName值获取汇率值
/// <summary>
/// 根据费用信息表GID和币别CodeName值获取汇率值
/// </summary>
/// <param name="tempCurCodeName">币别CodeName</param>
/// <param name="tempFeeGid">费用信息表GID</param>
/// <returns>返回汇率值</returns>
private string getExchangeRateByCurCode(string tempCurCodeName,string tempFeeGid)
{
decimal dExchangeRate = 0;
//通过费用信息获取委托编号
FeeDA feeDA = new FeeDA();
FeeEntity feeEntity = new FeeEntity();
feeEntity = feeDA.GetFeeByID(strFeeGid);
//币别实体类
CurrencyEntity currencyEntity = new CurrencyEntity();
//获取币别信息
CurrencyDA currencyDA = new CurrencyDA();
ExchangeRateDA exchangeDA = new ExchangeRateDA();
//SeaExportInfoDA seaExportDA = new SeaExportInfoDA();
//通过币别CODENAME值获取
IList<ExchangeRateEntity> exchangeRateEntities = new List<ExchangeRateEntity>();
currencyEntity = currencyDA.GetCurrencyByCodeName(strCurrencyCode);
if (currencyEntity.GID==null)
{
return dExchangeRate.ToString();
}
//是否获取了币别信息
if (currencyEntity != null)
{
//通过币别GID获取相关汇率所有信息
exchangeRateEntities = exchangeDA.GetExchangeRateByCurrencyID(currencyEntity.GID,strCompanyID);
if (feeEntity != null)
{
if (exchangeRateEntities.Count > 0)
{
if (strhandle == "")
{
#region 海运出口
SeaExportInfoDA seaExportDA = new SeaExportInfoDA();
foreach (ExchangeRateEntity rate in exchangeRateEntities)
{
//如果设置为以开船时间为准,则自动过滤掉iType = "account"的汇率记录
if (iSetting == 1 && rate.Type.ToLower().Equals("shipping"))
{
TopSeaeEntity topSeaeEntity = new TopSeaeEntity();
//根据委托编号获取海运业务主表信息op_seae
topSeaeEntity = seaExportDA.GetID(feeEntity.BSNO);
if (topSeaeEntity.ETD != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = topSeaeEntity.ETD;
//汇率起始时间
DateTime startTime = rate.StartTime;
//汇率结束时间
DateTime endTime = rate.EndTime;
//如果开船日期在汇率起始与结束时间段内,则返回汇率值
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
//如果设置为以会计期间为准,则自动过滤掉iType = "shipping"的汇率记录
if (iSetting == 2 && rate.Type.ToLower().Equals("account"))
{
TopSeaeEntity topSeaeEntity = new TopSeaeEntity();
//根据委托编号获取海运业务主表信息
topSeaeEntity = seaExportDA.GetID(feeEntity.BSNO);
string strAccountDate = topSeaeEntity.ACCDATE;
if (!strAccountDate.Trim().Equals(""))
{
DateTime AccountDate = DateTime.Parse(strAccountDate);
//汇率起始时间
DateTime startTime = rate.StartTime;
//汇率结束时间
DateTime endTime = rate.EndTime;
//如果开船日期在汇率起始与结束时间段内,则返回汇率值
if (AccountDate >= startTime && AccountDate <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
}
#endregion
}
else if (strhandle == "seai")
{
#region 海运进口
SeaImportInfoDA seaImportDA = new SeaImportInfoDA();
foreach (ExchangeRateEntity rate in exchangeRateEntities)
{
//如果设置为以开船时间为准,则自动过滤掉iType = "account"的汇率记录
if (iSetting == 1 && rate.Type.ToLower().Equals("shipping"))
{
TopSeaiEntity topSeaiEntity = new TopSeaiEntity();
//根据委托编号获取海运业务主表信息op_seae
topSeaiEntity = seaImportDA.GetID(feeEntity.BSNO);
if (topSeaiEntity.ETD != DateTime.MinValue)
{
//获取开船日期
DateTime etdTime = topSeaiEntity.ETD;
//汇率起始时间
DateTime startTime = rate.StartTime;
//汇率结束时间
DateTime endTime = rate.EndTime;
//如果开船日期在汇率起始与结束时间段内,则返回汇率值
if (etdTime >= startTime && etdTime <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
//如果设置为以会计期间为准,则自动过滤掉iType = "shipping"的汇率记录
if (iSetting == 2 && rate.Type.ToLower().Equals("account"))
{
TopSeaiEntity topSeaiEntity = new TopSeaiEntity();
//根据委托编号获取海运业务主表信息
topSeaiEntity = seaImportDA.GetID(feeEntity.BSNO);
string strAccountDate = topSeaiEntity.ACCDATE;
if (!strAccountDate.Trim().Equals(""))
{
DateTime AccountDate = DateTime.Parse(strAccountDate);
//汇率起始时间
DateTime startTime = rate.StartTime;
//汇率结束时间
DateTime endTime = rate.EndTime;
//如果开船日期在汇率起始与结束时间段内,则返回汇率值
if (AccountDate >= startTime && AccountDate <= endTime)
{
//如果获取到汇率值,则结束查询
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
}
#endregion
}
else if (strhandle == "sean")
{
#region 内贸海运委托
Opsean opseanDA = new Opsean();
OpseanEntity opseanEntity = new OpseanEntity();
opseanEntity = opseanDA.GetAllSeanInfo(feeEntity.BSNO);
foreach (ExchangeRateEntity rate in exchangeRateEntities)
{
//如果设置为以开船时间为准,则自动过滤掉iType = "account"的汇率记录
if (iSetting == 1 && rate.Type.ToLower().Equals("shipping"))
{
if (opseanEntity.ETD != DateTime.MinValue)
{
DateTime etdtime = opseanEntity.ETD;//获取开船时间
DateTime startime = rate.StartTime;//获取汇率开始时间
DateTime endtime = rate.EndTime;//获取汇率结束时间
if (etdtime >= startime && etdtime <= endtime) //如果开船日期在汇率起始与结束时间段内,则返回汇率值
{
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
else if (iSetting == 2 && rate.Type.ToLower().Equals("account"))
{
if (!opseanEntity.ACCDATE.ToString().Equals(""))
{
DateTime accDatetime = DateTime.Parse(opseanEntity.ACCDATE.ToString());
DateTime startime = rate.StartTime;
DateTime endtime = rate.EndTime;
if (accDatetime >= startime && accDatetime <= endtime)
{
dExchangeRate = rate.Value;
break;
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
break;
}
}
}
#endregion
}
}
}
else
{
dExchangeRate = currencyEntity.DefaultRate;
}
}
if (dExchangeRate == 0)
{
//如果没有匹配到相关汇率信息,则去默认汇率值
dExchangeRate = currencyEntity.DefaultRate;
}
return dExchangeRate.ToString();
}
#endregion
}
}