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.

1066 lines
53 KiB
C#

12 months ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using JsonHelper;
using DSWeb.Models;
using DSWeb.EntityDA;
using DSWeb.Authority;
using DSWeb.Log;
namespace DSWeb.Shipping
{
public partial class CrmOrderFee : PageBase
{
private string strUserID;//操作人GID
private string recvJSON;//应收费用
private string payJSON;//应付费用
private string strSeaBSNO;//销售订舱BSNO
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
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["id"] != null)
{
strSeaBSNO = Request.QueryString["id"].ToString().Trim();
this.h_bsno.Value = strSeaBSNO;
}
int iAuthorityStatus = 0;
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modSeaeOrderList");
if (userAuthorityManage.OperateType != AuthorityType.NULL)
{
iAuthorityStatus = userAuthorityManage.CheckOperateRange(ModuleType.SEAEORDERLIST, userAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strSeaBSNO, "", strUserID);
h_authority.Value = iAuthorityStatus.ToString();
}
else
{
h_authority.Value = "-1";
}
recvJSON = "";
payJSON = "";
recvJSON = this.recvContainer.Value.Trim();
payJSON = this.payContainer.Value.Trim();
if (this.h_post.Value.Trim() != "")
{
//保存操作
if (this.h_post.Value.Trim() == "1")
{
if (!recvJSON.Trim().Equals("") || !payJSON.Trim().Equals(""))
{
SaveFeeAction();
}
}
}
GetSeaInfo();
}
private void SaveFeeAction()
{
IList<CrmOrderFeeEntity> crmOrderFeeEntities = new List<CrmOrderFeeEntity>();
if (!recvJSON.Trim().Equals(""))
{
crmOrderFeeEntities = ResolveFeeJSON(recvJSON.Trim(), crmOrderFeeEntities);
recvContainer.Value = "";
}
if (!payJSON.Trim().Equals(""))
{
crmOrderFeeEntities = ResolveFeeJSON(payJSON.Trim(), crmOrderFeeEntities);
payContainer.Value = "";
}
FeeProfitEntity feeProfitEntity = new FeeProfitEntity();
feeProfitEntity = GetRequestProfit();
CrmOrderFeeDA crmOrderFeeDA = new CrmOrderFeeDA();
int iRecvState = crmOrderFeeDA.DoFee(crmOrderFeeEntities, feeProfitEntity, strSeaBSNO);
if (iRecvState == 1)
{
gainContainer.Value = "";
//if (Session[strCacheName] != null)
//{
// Session.Remove(strCacheName);
//}
}
h_post.Value = "";//请求状态清空
}
#region 页面加载主委托信息
/// <summary>
/// 页面加载主委托信息
/// </summary>
private void GetSeaInfo()
{
CrmSeaeorderDA crmSeaeOrderDA = new CrmSeaeorderDA();
CrmSeaeorderEntity crmSeaeOrderEntity = crmSeaeOrderDA.GetID(strSeaBSNO);
if (crmSeaeOrderEntity.BSNO != null)
{
//委托业务编号
dvOrderNumVal.Value = crmSeaeOrderEntity.BSNO;
//委托编号
dvCUSTNO.InnerHtml = "";//crmSeaeOrderEntity.CUSTNO;
//主提单号
dvOrderPrimaryVal.InnerHtml = crmSeaeOrderEntity.MBLNO;
//箱型箱量
dvContainerVal.InnerHtml = crmSeaeOrderEntity.CNTRTOTAL;
//付费方式
dvPaymentVal.InnerHtml = "";//crmSeaeOrderEntity.BLFRT;
//揽货人
dvChannelSaleVal.InnerHtml = crmSeaeOrderEntity.SALE;
//委托单位
dvOrderCellVal.InnerHtml = crmSeaeOrderEntity.CUSTOMERNAME;
//卸货港
dvDischargePortVal.InnerHtml = crmSeaeOrderEntity.PORTDISCHARGE;
//MBL付费方式
dvPaymentMBLVAL.InnerHtml = "";//crmSeaeOrderEntity.MBLFRT;
h_crmstatus.Value = crmSeaeOrderEntity.ORSTATUS.Trim();
}
}
#endregion
#region 保存应收费用列表更改结果
/// <summary>
/// 保存应收费用列表更改结果
/// </summary>
/// <param name="tempGroupEntity"></param>
private void SaveRecvFee(JsonFeeGroupEntity tempGroupEntity)
{
if (tempGroupEntity != null)
{
List<JsonFeeEntity> feeEntities = new List<JsonFeeEntity>();
feeEntities = tempGroupEntity.JsonFeeEntities;
FeeDA feeDA = new FeeDA();
DataTable feeTable = new DataTable();
string strInitSql = "";
if (tempGroupEntity.JsonFeeEntities.Count > 0)
{
string bsno = tempGroupEntity.JsonFeeEntities[0].fee15.Trim();
strInitSql = " SELECT GID, FEETYPE, FEENAME, CUSTOMERNAME, UNIT, UNITPRICE, COMMISSIONRATE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, FEEFRT,REMARK,ISADVANCEDPAY FROM crm_orderfee WHERE 1> 0 AND BSNO = '" + bsno + "'";
}
else
{
return;
}
feeTable = feeDA.GetExcuteSql(strInitSql).Tables[0];
//更新操作SQL语句
ArrayList sqlList = new ArrayList();
//日志操作SQL语句
ArrayList logList = new ArrayList();
//日志记录
Logger log = Logger.Instance;
for (int i = 0; i < feeTable.Rows.Count; i++)
{
foreach (JsonFeeEntity fee in feeEntities)
{
if (feeTable.Rows[i]["GID"].ToString().Trim().Equals(fee.fee1.Trim()))
{
string strSql = "";
string LogContent = "";
LogEntity logEntity = new LogEntity();
#region 更改前后信息对比
//费用名称
string strFeeName = fee.fee3.Trim().ToLower().Equals("null") ? "" : fee.fee3.Trim();
if (!feeTable.Rows[i]["FEENAME"].ToString().Trim().Equals(strFeeName))
{
strSql += String.Format(" FEENAME = '{0}'", strFeeName);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收费用名称", feeTable.Rows[i]["FEENAME"].ToString().Trim(), strFeeName);
}
//结算单位
string strCustomer = fee.fee4.Trim().ToLower().Equals("null") ? "" : fee.fee4.Trim();
if (!feeTable.Rows[i]["CUSTOMERNAME"].ToString().Trim().Equals(strCustomer))
{
strSql += String.Format(" ,CUSTOMERNAME = '{0}'", strCustomer);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "结算单位", feeTable.Rows[i]["CUSTOMERNAME"].ToString().Trim(), strCustomer);
}
//计费标准
string strUnit = fee.fee5.Trim().ToLower().Equals("null") ? "" : fee.fee5.Trim();
if (!feeTable.Rows[i]["UNIT"].ToString().Trim().Equals(strUnit))
{
strSql += String.Format(" ,UNIT = '{0}'", strUnit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "计费标准", feeTable.Rows[i]["UNIT"].ToString().Trim(), strUnit);
}
//计费单价
decimal unitPrice = decimal.Parse(feeTable.Rows[i]["UNITPRICE"].ToString().Trim());
if (unitPrice != fee.fee6)
{
strSql += String.Format(" ,UNITPRICE = {0}", fee.fee6.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "计费单价", unitPrice.ToString(), fee.fee6.ToString());
}
//数量
decimal Quantity = decimal.Parse(feeTable.Rows[i]["QUANTITY"].ToString().Trim());
if (Quantity != fee.fee7)
{
strSql += String.Format(" ,QUANTITY = {0}", fee.fee7.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "数量", Quantity.ToString(), fee.fee7.ToString());
}
//佣金比率
decimal CommissionRate = decimal.Parse(feeTable.Rows[i]["COMMISSIONRATE"].ToString().Trim());
if (CommissionRate != fee.fee8)
{
strSql += String.Format(" ,COMMISSIONRATE = {0}", fee.fee8.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "佣金比率", CommissionRate.ToString(), fee.fee8.ToString());
}
//金额
decimal Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString().Trim());
if (Amount != fee.fee9)
{
strSql += String.Format(" ,AMOUNT = {0}", fee.fee9.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "金额", Amount.ToString(), fee.fee9.ToString());
}
//币别
if (!feeTable.Rows[i]["CURRENCY"].ToString().Trim().Equals(fee.fee10.Trim()))
{
strSql += String.Format(" ,CURRENCY = '{0}'", fee.fee10.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "金额", feeTable.Rows[i]["CURRENCY"].ToString().Trim(), fee.fee10.Trim());
}
//汇率
decimal ExchangeRate = decimal.Parse(feeTable.Rows[i]["EXCHANGERATE"].ToString().Trim());
if (ExchangeRate != fee.fee11)
{
strSql += String.Format(" ,EXCHANGERATE = {0}", fee.fee11.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "汇率", ExchangeRate.ToString(), fee.fee11.ToString());
}
//FRT运费支付方式
if (!feeTable.Rows[i]["FEEFRT"].ToString().Trim().Equals(fee.fee12.Trim()))
{
strSql += String.Format(" ,FEEFRT = '{0}'", fee.fee12.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "FRT", feeTable.Rows[i]["FEEFRT"].ToString().Trim(), fee.fee12.Trim());
}
//备注
string strRemark = fee.fee13.Trim() == "null" ? "" : fee.fee13.Trim();
if (!feeTable.Rows[i]["REMARK"].ToString().Trim().Equals(strRemark))
{
strSql += String.Format(" ,REMARK = '{0}'", fee.fee13.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "备注", feeTable.Rows[i]["REMARK"].ToString().Trim(), fee.fee13.Trim());
}
//是否垫付
bool IsAdvancePay = feeTable.Rows[i]["ISADVANCEDPAY"].ToString().Trim().ToLower().Equals("true") ? true : false;
if (IsAdvancePay != fee.fee14)
{
strSql += String.Format(" ,ISADVANCEDPAY = {0}", fee.fee14 ? 1 : 0);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "是否垫付", IsAdvancePay ? "是" : "否", fee.fee14 ? "是" : "否");
}
#endregion
//如果有字段内容更新则执行更新操作
if (LogContent.Trim().Length > 1)
{
if (strSql.Trim().StartsWith(","))
{
strSql = strSql.Trim().Substring(1);
}
string strUpdateSql = String.Format("UPDATE {0} SET {1} WHERE GID = '{2}'", "crm_orderfee", strSql, fee.fee1.Trim());
sqlList.Add(strUpdateSql);
logList.Add(String.Format("更新费用标识 {0} {1}", fee.fee1.Trim(), LogContent));
}
feeEntities.Remove(fee);
break;
}
}
}
if (sqlList.Count > 0)
{
int iResult = feeDA.UpdateFeeFromGrid(sqlList);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
if (iResult == 1)
{
#region 日志记录操作
// INSERT-"INSERT INTO {0} ({1}) VALUES ({2})" @{0}-所要插入记录的表;{1}记录字段值;{2}-记录新值@
if (logList.Count > 0)
{
for (int i = 0; i < logList.Count; i++)
{
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "更新销售订舱应收费用列表";
logEntity.LogType = "UPDATE 更新操作";
logEntity.CreateUserID = strUserID;//测试使用数据,正式发布请删除
logEntity.LogContent = logList[i].ToString();
log.WriteLog(logEntity);
}
}
#endregion
}
}
//如果遍历完所有费用表数据,没有相对应的费用信息,则将剩余的费用信息插入到费用表中
if (feeEntities.Count > 0)
{
//插入新的应收费用信息
InsertFee(feeEntities, 1);
}
recvJSON = "";
this.recvContainer.Value = "";
}
else
{
recvJSON = "";
this.recvContainer.Value = "";
return;
}
}
#endregion
#region 保存应付费用列表更改结果
/// <summary>
/// 保存应付费用列表更改结果
/// </summary>
/// <param name="tempGroupEntity"></param>
private void SavePayFee(JsonFeeGroupEntity tempGroupEntity)
{
if (tempGroupEntity != null)
{
List<JsonFeeEntity> feeEntities = new List<JsonFeeEntity>();
feeEntities = tempGroupEntity.JsonFeeEntities;
FeeDA feeDA = new FeeDA();
DataTable feeTable = new DataTable();
string strInitSql = "";
if (tempGroupEntity.JsonFeeEntities.Count > 0)
{
string bsno = tempGroupEntity.JsonFeeEntities[0].fee15.Trim();
strInitSql = " SELECT GID, FEETYPE, FEENAME, CUSTOMERNAME, UNIT, UNITPRICE, COMMISSIONRATE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, FEEFRT,REMARK,ISADVANCEDPAY FROM crm_orderfee WHERE 1> 0 AND BSNO = '" + bsno + "'";
}
else
{
return;
}
feeTable = feeDA.GetExcuteSql(strInitSql).Tables[0];
//更新操作SQL语句
ArrayList sqlList = new ArrayList();
//日志操作SQL语句
ArrayList logList = new ArrayList();
//日志记录
Logger log = Logger.Instance;
for (int i = 0; i < feeTable.Rows.Count; i++)
{
foreach (JsonFeeEntity fee in feeEntities)
{
if (feeTable.Rows[i]["GID"].ToString().Trim().Equals(fee.fee1.Trim()))
{
string strSql = "";
string LogContent = "";
LogEntity logEntity = new LogEntity();
#region 更改前后信息对比
//费用名称
string strFeeName = fee.fee3.Trim().ToLower().Equals("null") ? "" : fee.fee3.Trim();
if (!feeTable.Rows[i]["FEENAME"].ToString().Trim().Equals(strFeeName))
{
strSql += String.Format(" FEENAME = '{0}'", strFeeName);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收费用名称", feeTable.Rows[i]["FEENAME"].ToString().Trim(), strFeeName);
}
//结算单位
string strCustomer = fee.fee4.Trim().ToLower().Equals("null") ? "" : fee.fee4.Trim();
if (!feeTable.Rows[i]["CUSTOMERNAME"].ToString().Trim().Equals(strCustomer))
{
strSql += String.Format(" ,CUSTOMERNAME = '{0}'", strCustomer);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "结算单位", feeTable.Rows[i]["CUSTOMERNAME"].ToString().Trim(), strCustomer);
}
//计费标准
string strUnit = fee.fee5.Trim().ToLower().Equals("null") ? "" : fee.fee5.Trim();
if (!feeTable.Rows[i]["UNIT"].ToString().Trim().Equals(strUnit))
{
strSql += String.Format(" ,UNIT = '{0}'", strUnit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "计费标准", feeTable.Rows[i]["UNIT"].ToString().Trim(), strUnit);
}
//计费单价
decimal unitPrice = decimal.Parse(feeTable.Rows[i]["UNITPRICE"].ToString().Trim());
if (unitPrice != fee.fee6)
{
strSql += String.Format(" ,UNITPRICE = {0}", fee.fee6.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "计费单价", unitPrice.ToString(), fee.fee6.ToString());
}
//数量
decimal Quantity = decimal.Parse(feeTable.Rows[i]["QUANTITY"].ToString().Trim());
if (Quantity != fee.fee7)
{
strSql += String.Format(" ,QUANTITY = {0}", fee.fee7.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "数量", Quantity.ToString(), fee.fee7.ToString());
}
//佣金比率
decimal CommissionRate = decimal.Parse(feeTable.Rows[i]["COMMISSIONRATE"].ToString().Trim());
if (CommissionRate != fee.fee8)
{
strSql += String.Format(" ,COMMISSIONRATE = {0}", fee.fee8.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "佣金比率", CommissionRate.ToString(), fee.fee8.ToString());
}
//金额
decimal Amount = decimal.Parse(feeTable.Rows[i]["AMOUNT"].ToString().Trim());
if (Amount != fee.fee9)
{
strSql += String.Format(" ,AMOUNT = {0}", fee.fee9.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "金额", Amount.ToString(), fee.fee9.ToString());
}
//币别
if (!feeTable.Rows[i]["CURRENCY"].ToString().Trim().Equals(fee.fee10.Trim()))
{
strSql += String.Format(" ,CURRENCY = '{0}'", fee.fee10.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "金额", feeTable.Rows[i]["CURRENCY"].ToString().Trim(), fee.fee10.Trim());
}
//汇率
decimal ExchangeRate = decimal.Parse(feeTable.Rows[i]["EXCHANGERATE"].ToString().Trim());
if (ExchangeRate != fee.fee11)
{
strSql += String.Format(" ,EXCHANGERATE = {0}", fee.fee11.ToString());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "汇率", ExchangeRate.ToString(), fee.fee11.ToString());
}
//FRT运费支付方式
if (!feeTable.Rows[i]["FEEFRT"].ToString().Trim().Equals(fee.fee12.Trim()))
{
strSql += String.Format(" ,FEEFRT = '{0}'", fee.fee12.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "FRT", feeTable.Rows[i]["FEEFRT"].ToString().Trim(), fee.fee12.Trim());
}
//备注
string strRemark = fee.fee13.Trim() == "null" ? "" : fee.fee13.Trim();
if (!feeTable.Rows[i]["REMARK"].ToString().Trim().Equals(strRemark))
{
strSql += String.Format(" ,REMARK = '{0}'", fee.fee13.Trim());
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "备注", feeTable.Rows[i]["REMARK"].ToString().Trim(), fee.fee13.Trim());
}
//是否垫付
bool IsAdvancePay = feeTable.Rows[i]["ISADVANCEDPAY"].ToString().Trim().ToLower().Equals("true") ? true : false;
if (IsAdvancePay != fee.fee14)
{
strSql += String.Format(" ,ISADVANCEDPAY = {0}", fee.fee14 ? 1 : 0);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "是否垫付", IsAdvancePay ? "是" : "否", fee.fee14 ? "是" : "否");
}
#endregion
//如果有字段内容更新则执行更新操作
if (LogContent.Trim().Length > 1)
{
if (strSql.Trim().StartsWith(","))
{
strSql = strSql.Trim().Substring(1);
}
string strUpdateSql = String.Format("UPDATE {0} SET {1} WHERE GID = '{2}'", "crm_orderfee", strSql, fee.fee1.Trim());
sqlList.Add(strUpdateSql);
logList.Add(String.Format("更新费用标识 {0} {1}", fee.fee1.Trim(), LogContent));
}
feeEntities.Remove(fee);
break;
}
}
}
//遍历完所有数据有,进行统一更新
if (sqlList.Count > 0)
{
int iResult = feeDA.UpdateFeeFromGrid(sqlList);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
if (iResult == 1)
{
#region 日志记录操作
// INSERT-"INSERT INTO {0} ({1}) VALUES ({2})" @{0}-所要插入记录的表;{1}记录字段值;{2}-记录新值@
if (logList.Count > 0)
{
for (int i = 0; i < logList.Count; i++)
{
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "更新销售订舱应付费用列表";
logEntity.LogType = "UPDATE 更新操作";
logEntity.CreateUserID = strUserID;
logEntity.LogContent = logList[i].ToString();
log.WriteLog(logEntity);
}
}
#endregion
}
}
if (feeEntities.Count > 0)
{
//插入新的应收费用信息
InsertFee(feeEntities, 2);
}
payJSON = "";
this.payContainer.Value = "";
}
else
{
payJSON = "";
this.payContainer.Value = "";
return;
}
}
#endregion
#region 插入费用信息记录
/// <summary>
/// 插入费用信息记录
/// </summary>
/// <param name="feeEntities">需要插入费用表的费用实体类</param>
/// <param name="iType">如果iType值为1则记录费用类型为收/否则记录为付</param>
public void InsertFee(List<JsonFeeEntity> feeEntities, int iType)
{
ArrayList sqlInsertList = new ArrayList();
FeeDA feeDA = new FeeDA();
foreach (JsonFeeEntity fee in feeEntities)
{
string strItemSql = "";
string strValueSql = "";
string strInsertSql = "";
//GID
strItemSql += "GID";
strValueSql += String.Format("'{0}'", fee.fee1.Trim().Equals("null") ? "" : fee.fee1.Trim());
//费用状态
string strFeeStatus = fee.fee2.Trim();
int iFeeStatus = 1;
switch (strFeeStatus)
{
case "审核通过":
iFeeStatus = 0;
break;
case "录入状态":
iFeeStatus = 1;
break;
case "提交审核":
iFeeStatus = 2;
break;
case "申请修改":
iFeeStatus = 3;
break;
case "申请删除":
iFeeStatus = 4;
break;
case "取消申请":
iFeeStatus = 5;
break;
case "驳回提交":
iFeeStatus = 6;
break;
case "驳回申请":
iFeeStatus = 7;
break;
case "部分结算":
iFeeStatus = 8;
break;
case "结算完毕":
iFeeStatus = 9;
break;
default:
break;
}
strItemSql += ",FEESTATUS";
strValueSql += String.Format(",'{0}'", fee.fee2.Trim().Equals("null") ? "" : iFeeStatus.ToString());
//费用名称
strItemSql += ",FEENAME";
strValueSql += String.Format(",'{0}'", fee.fee3.Trim().Equals("null") ? "" : fee.fee3.Trim());
//结算单位
strItemSql += ",CUSTOMERNAME";
strValueSql += String.Format(",'{0}'", fee.fee4.Trim().Equals("null") ? "" : fee.fee4.Trim());
//计费标准
strItemSql += ",UNIT";
strValueSql += String.Format(",'{0}'", fee.fee5.Trim().Equals("null") ? "" : fee.fee5.Trim());
//计费单价
strItemSql += ",UNITPRICE";
strValueSql += String.Format(",{0}", fee.fee6);
//数量
strItemSql += ",QUANTITY";
strValueSql += String.Format(",{0}", fee.fee7);
//佣金比率
strItemSql += ",COMMISSIONRATE";
strValueSql += String.Format(",{0}", fee.fee8);
//金额
strItemSql += ",AMOUNT";
strValueSql += String.Format(",{0}", fee.fee9);
//币别
strItemSql += ",CURRENCY";
strValueSql += String.Format(",'{0}'", fee.fee10.Trim().Equals("null") ? "" : fee.fee10.Trim());
//汇率
strItemSql += ",EXCHANGERATE";
strValueSql += String.Format(",{0}", fee.fee11);
//FRT运费支付方式
strItemSql += ",FEEFRT";
strValueSql += String.Format(",'{0}'", fee.fee12);
//备注
strItemSql += ",REMARK";
strValueSql += String.Format(",'{0}'", fee.fee13.Trim().Equals("null") ? "" : fee.fee13.Trim());
//是否垫付
strItemSql += ",ISADVANCEDPAY";
strValueSql += String.Format(",{0}", fee.fee14 ? 1 : 0);
//如果iType值为1则记录费用类型为收/否则记录为付
if (iType == 1)
{
strItemSql += ",FEETYPE";
strValueSql += String.Format(",'{0}'", "1");
}
else
{
strItemSql += ",FEETYPE";
strValueSql += String.Format(",'{0}'", "2");
}
//委托编号
strItemSql += ",BSNO";
strValueSql += String.Format(",'{0}'", fee.fee15);
if (!strItemSql.Trim().Equals("") && !strValueSql.Trim().Equals(""))
{
if (strItemSql.Trim().StartsWith(","))
{
strItemSql = strItemSql.Trim().Substring(1);
}
if (strValueSql.Trim().StartsWith(","))
{
strValueSql = strValueSql.Trim().Substring(1);
}
strInsertSql = String.Format("INSERT INTO {0} ({1}) VALUES({2})", "crm_orderfee", strItemSql, strValueSql);
sqlInsertList.Add(strInsertSql);
}
}
if (sqlInsertList.Count > 0)
{
int iResult = feeDA.InsertFeeFromGrid(sqlInsertList);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
//if (iResult == 1)
//{
//}
}
}
#endregion
#region 获取费用客户保存的费用信息
/// <summary>
/// 获取费用客户保存的费用信息
/// </summary>
/// <param name="tempValue"></param>
/// <returns></returns>
public JsonFeeGroupEntity GetPostEntity(string tempValue)
{
JsonFeeGroupEntity feeGroupEntity = (JsonFeeGroupEntity)JSON.Instance.ToObject(tempValue);
return feeGroupEntity;
}
#endregion
private void RecordFeeGain(string tempBSNO)
{
//费用利润实体类
FeeProfitEntity feeProfitEntity = new FeeProfitEntity();
FeeProfitDA feeProfitDA = new FeeProfitDA();
feeProfitEntity = feeProfitDA.GetFeeProfitByBSNO(tempBSNO);
//先判断费用利润表是否有与委托编号相关联的信息
if (feeProfitEntity != null)
{
FeeProfitEntity newProfitEntity = GetRequestProfit();
string strSql = "";
string LogContent = "";
//日志记录
Logger log = Logger.Instance;
if (feeProfitEntity.RMBDR != newProfitEntity.RMBDR)
{
strSql += String.Format(" RMBDR = {0}", newProfitEntity.RMBDR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收RMB", feeProfitEntity.RMBDR.ToString(), newProfitEntity.RMBDR.ToString());
}
if (feeProfitEntity.USDDR != newProfitEntity.USDDR)
{
strSql += String.Format(" ,USDDR = {0}", newProfitEntity.USDDR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收USD", feeProfitEntity.USDDR.ToString(), newProfitEntity.USDDR.ToString());
}
if (feeProfitEntity.OTHERDR != newProfitEntity.OTHERDR)
{
strSql += String.Format(" ,OTDR = {0}", newProfitEntity.OTHERDR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收其他币别", feeProfitEntity.OTHERDR.ToString(), newProfitEntity.OTHERDR.ToString());
}
if (feeProfitEntity.RMBCR != newProfitEntity.RMBCR)
{
strSql += String.Format(" ,RMBCR = {0}", newProfitEntity.RMBCR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应付RMB", feeProfitEntity.RMBCR.ToString(), newProfitEntity.RMBCR.ToString());
}
if (feeProfitEntity.USDCR != newProfitEntity.USDCR)
{
strSql += String.Format(" ,USDCR = {0}", newProfitEntity.USDCR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应付USD", feeProfitEntity.USDCR.ToString(), newProfitEntity.USDCR.ToString());
}
if (feeProfitEntity.OTHERCR != newProfitEntity.OTHERCR)
{
strSql += String.Format(" ,OTCR = {0}", newProfitEntity.OTHERCR);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应付其他币别", feeProfitEntity.OTHERCR.ToString(), newProfitEntity.OTHERCR.ToString());
}
if (feeProfitEntity.DRTTL != newProfitEntity.DRTTL)
{
strSql += String.Format(" ,DRTTL = {0}", newProfitEntity.DRTTL);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收合计", feeProfitEntity.DRTTL.ToString(), newProfitEntity.DRTTL.ToString());
}
if (feeProfitEntity.CRTTL != newProfitEntity.CRTTL)
{
strSql += String.Format(" ,CRTTL = {0}", newProfitEntity.CRTTL);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "应收合计", feeProfitEntity.CRTTL.ToString(), newProfitEntity.CRTTL.ToString());
}
if (feeProfitEntity.RMBProfit != newProfitEntity.RMBProfit)
{
strSql += String.Format(" ,RMBPROFIT = {0}", newProfitEntity.RMBProfit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "RMB利润", feeProfitEntity.RMBProfit.ToString(), newProfitEntity.RMBProfit.ToString());
}
if (feeProfitEntity.USDProfit != newProfitEntity.USDProfit)
{
strSql += String.Format(" ,USDPROFIT = {0}", newProfitEntity.USDProfit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "USD利润", feeProfitEntity.USDProfit.ToString(), newProfitEntity.USDProfit.ToString());
}
if (feeProfitEntity.OTHERProfit != newProfitEntity.OTHERProfit)
{
strSql += String.Format(" ,OTPROFIT = {0}", newProfitEntity.OTHERProfit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "其他币别利润", feeProfitEntity.OTHERProfit.ToString(), newProfitEntity.OTHERProfit.ToString());
}
if (feeProfitEntity.TTLProfit != newProfitEntity.TTLProfit)
{
strSql += String.Format(" ,TTLPROFIT = {0}", newProfitEntity.TTLProfit);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "合计利润", feeProfitEntity.TTLProfit.ToString(), newProfitEntity.TTLProfit.ToString());
}
if (feeProfitEntity.ProfitRate != newProfitEntity.ProfitRate)
{
strSql += String.Format(" ,PROFITRATE = '{0}'", newProfitEntity.ProfitRate);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "利润率", feeProfitEntity.ProfitRate, newProfitEntity.ProfitRate);
}
if (strSql.Trim().Length > 1)
{
strSql += String.Format(" ,MODIFIEDUSER = '{0}',MODIFIEDTIME = GETDATE() ", strUserID);
if (strSql.Trim().StartsWith(","))
{
strSql = strSql.Trim().Substring(1);
}
strSql = String.Format(" UPDATE fee_gain SET {0} WHERE BSNO = '{1}'", strSql, strSeaBSNO);
int iResult = feeProfitDA.UpdateFeeProfit(strSql);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
if (iResult == 1)
{
LogEntity logEntity = new LogEntity();
logEntity.GID = Guid.NewGuid().ToString();
logEntity.Name = "更新利润信息";
logEntity.LogType = "UPDATE 更新操作";
logEntity.CreateUserID = strUserID;
logEntity.LogContent = String.Format(" 更新委托 {0} {1}", tempBSNO, LogContent);
log.WriteLog(logEntity);
}
}
}
else
{
FeeProfitEntity newProfitEntity = GetRequestProfit();
newProfitEntity.GID = Guid.NewGuid().ToString();
newProfitEntity.BSNO = strSeaBSNO;
newProfitEntity.CreateUser = strUserID;
int iResult = feeProfitDA.InsertFeeProfit(newProfitEntity);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
//if (iResult == 1)
//{
//}
}
}
#region 将页面post获取的利润值读入到利润实体类中
/// <summary>
/// 将页面post获取的利润值读入到利润实体类中
/// </summary>
/// <returns>返回利润实体类 FeeProfitEntity</returns>
private FeeProfitEntity GetRequestProfit()
{
FeeProfitEntity tempFeeProfitEntity = new FeeProfitEntity();
#region 保留
//tempFeeProfitEntity.RMBDR = Decimal.Parse(dvRecvRMBVal.InnerText.Trim());
//tempFeeProfitEntity.USDDR = Decimal.Parse(dvUSRecvVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERDR = Decimal.Parse(dvOtherCurrencyRecvVal.InnerHtml.Trim());
//tempFeeProfitEntity.RMBCR = Decimal.Parse(dvPayRMBVal.InnerHtml.Trim());
//tempFeeProfitEntity.USDCR = Decimal.Parse(dvUSPayVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERCR = Decimal.Parse(dvOtherCurrencyPayVal.InnerHtml.Trim());
//tempFeeProfitEntity.DRTTL = Decimal.Parse(dvRecvTotalVal.InnerHtml.Trim());
//tempFeeProfitEntity.CRTTL = Decimal.Parse(dvPaySumVal.InnerHtml.Trim());
//tempFeeProfitEntity.RMBProfit = Decimal.Parse(dvRMBProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.USDProfit = Decimal.Parse(dvUSProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERProfit = Decimal.Parse(dvOtherCurrencyProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.TTLProfit = Decimal.Parse(dvProfitTotalVal.InnerHtml.Trim());
//tempFeeProfitEntity.ProfitRate = dvProfitRateVal.InnerHtml.Trim();
#endregion
if (!gainContainer.Value.Trim().Equals(""))
{
string[] gainList = gainContainer.Value.Trim().Split(new char[] { ',' });
if (!gainList[0].ToString().Trim().Equals(""))
{
tempFeeProfitEntity.RMBDR = Decimal.Parse(gainList[0].ToString().Trim());
tempFeeProfitEntity.USDDR = Decimal.Parse(gainList[1].ToString().Trim());
tempFeeProfitEntity.OTHERDR = Decimal.Parse(gainList[2].ToString().Trim());
tempFeeProfitEntity.RMBCR = Decimal.Parse(gainList[3].ToString().Trim());
tempFeeProfitEntity.USDCR = Decimal.Parse(gainList[4].ToString().Trim());
tempFeeProfitEntity.OTHERCR = Decimal.Parse(gainList[5].ToString().Trim());
tempFeeProfitEntity.DRTTL = Decimal.Parse(gainList[6].ToString().Trim());
tempFeeProfitEntity.CRTTL = Decimal.Parse(gainList[7].ToString().Trim());
tempFeeProfitEntity.RMBProfit = Decimal.Parse(gainList[8].ToString().Trim());
tempFeeProfitEntity.USDProfit = Decimal.Parse(gainList[9].ToString().Trim());
tempFeeProfitEntity.OTHERProfit = Decimal.Parse(gainList[10].ToString().Trim());
tempFeeProfitEntity.TTLProfit = Decimal.Parse(gainList[11].ToString().Trim());
tempFeeProfitEntity.ProfitRate = gainList[12].ToString().Trim();
tempFeeProfitEntity.CreateUser = this.strUserID;
tempFeeProfitEntity.ModifiedUser = this.strUserID;
}
else
{
tempFeeProfitEntity.RMBDR = 0;
tempFeeProfitEntity.USDDR = 0;
tempFeeProfitEntity.OTHERDR = 0;
tempFeeProfitEntity.RMBCR = 0;
tempFeeProfitEntity.USDCR = 0;
tempFeeProfitEntity.OTHERCR = 0;
tempFeeProfitEntity.DRTTL = 0;
tempFeeProfitEntity.CRTTL = 0;
tempFeeProfitEntity.RMBProfit = 0;
tempFeeProfitEntity.USDProfit = 0;
tempFeeProfitEntity.OTHERProfit = 0;
tempFeeProfitEntity.TTLProfit = 0;
tempFeeProfitEntity.ProfitRate = "0%";
tempFeeProfitEntity.CreateUser = this.strUserID;
tempFeeProfitEntity.ModifiedUser = this.strUserID;
}
}
return tempFeeProfitEntity;
}
#endregion
private IList<CrmOrderFeeEntity> ResolveFeeJSON(string tempJSON, IList<CrmOrderFeeEntity> tempCrmOrderFeeEntities)
{
string strFilter = "";
if (tempJSON.IndexOf("[") >= 0 && tempJSON.IndexOf("]") > 0)
{
strFilter = tempJSON.Substring(tempJSON.IndexOf("[") + 1, tempJSON.IndexOf("]") - tempJSON.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
CrmOrderFeeEntity crmOrderFeeEntity = new CrmOrderFeeEntity();
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "id":
crmOrderFeeEntity.GID = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "type":
crmOrderFeeEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "bsno":
crmOrderFeeEntity.BSNO = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "status":
break;
case "fname":
crmOrderFeeEntity.FeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cust":
crmOrderFeeEntity.CustomerName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "unit":
crmOrderFeeEntity.Unit = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "price":
crmOrderFeeEntity.UnitPrice = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "quant":
crmOrderFeeEntity.Quantity = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "com":
crmOrderFeeEntity.CommissionRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "amount":
crmOrderFeeEntity.Amount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cur":
crmOrderFeeEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "rate":
crmOrderFeeEntity.ExchangeRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "frt":
crmOrderFeeEntity.FeeFrt = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "remark":
crmOrderFeeEntity.Remark = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "isadv":
crmOrderFeeEntity.IsAdvancePay = strArg[1].ToString().Replace("\"", "").Trim().Equals("1") ? true : false;
break;
default:
break;
}
}
crmOrderFeeEntity.EnterOperator = this.strUserID;
crmOrderFeeEntity.FeeStatus = 1;
tempCrmOrderFeeEntities.Add(crmOrderFeeEntity);
}
}
}
}
return tempCrmOrderFeeEntities;
}
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
}
}