using System;
using System.Data;
using WebSqlHelper;
using DSWeb.Models;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class CrmOrderFeeDA
{
#region 订舱费用参数
//crm_orderfee
private const string PARM_CRM_ORDER_FEE_GID = "@gid";
private const string PARM_CRM_ORDER_FEE_BSNO = "@bsno";
private const string PARM_CRM_ORDER_FEE_TYPE = "@fee_type";
private const string PARM_CRM_ORDER_FEE_NAME = "@fee_name";
private const string PARM_CRM_ORDER_FEE_DESCRIPTION = "@fee_description";
private const string PARM_CRM_ORDER_FEE_CUSTOMER_TYPE = "@customer_type";
private const string PARM_CRM_ORDER_FEE_CUSTOMER_NAME = "@customer_name";
private const string PARM_CRM_ORDER_FEE_UNIT = "@unit";
private const string PARM_CRM_ORDER_FEE_UNIT_PRICE = "@unit_price";
private const string PARM_CRM_ORDER_FEE_QUANTITY = "@quantity";
private const string PARM_CRM_ORDER_FEE_AMOUNT = "@amount";
private const string PARM_CRM_ORDER_FEE_CURRENCY = "@currency";
private const string PARM_CRM_ORDER_FEE_EXCHANGE_RATE = "@exchange_rate";
private const string PARM_CRM_ORDER_FEE_REASON = "@reason";
private const string PARM_CRM_ORDER_FEE_REMARK = "@remark";
private const string PARM_CRM_ORDER_FEE_COMMISSION_RATE = "@comm_rate";
private const string PARM_CRM_ORDER_FEE_SETTLEMENT = "@settlement";
private const string PARM_CRM_ORDER_FEE_INVOICE = "@invoice";
private const string PARM_CRM_ORDER_FEE_ORDER_AMOUNT = "@order_amount";
private const string PARM_CRM_ORDER_FEE_ORDER_INVOCE = "@order_invoice";
private const string PARM_CRM_ORDER_FEE_SUBMIT_DATE = "@submit_date";
private const string PARM_CRM_ORDER_FEE_AUDIT_OPERATOR = "@audit_operator";
private const string PARM_CRM_ORDER_FEE_AUDIT_DATE = "@audit_date";
private const string PARM_CRM_ORDER_FEE_ENTER_OPERATOR = "@enter_operator";
private const string PARM_CRM_ORDER_FEE_ENTER_DATE = "@enter_date";
private const string PARM_CRM_ORDER_FEE_DEBITNO = "@debitno";
private const string PARM_CRM_ORDER_FEE_ISDEBIT = "@is_debit";
private const string PARM_CRM_ORDER_FEE_ISOPEN = "@is_open";
private const string PARM_CRM_ORDER_FEE_ISADVANCEPAY = "@is_advance_pay";
private const string PARM_CRM_ORDER_FEE_SORT = "@sort";
private const string PARM_CRM_ORDER_FEE_ISINVOICE = "@is_invoice";
private const string PARM_CRM_ORDER_FEE_STATUS = "@fee_status";
private const string PARM_CRM_ORDER_FEE_FRT = "@fee_frt";
private const string PARM_CRM_ORDER_FEE_AUDIT_STATUS = "@audit_status";
private const string PARM_CRM_ORDER_FEE_IS_SUBMIT2_FEE = "@is_submit2fee";
//ch_fee
private const string PARM_FEE_GID = "@gid";
private const string PARM_FEE_BSNO = "@bsno";
private const string PARM_FEE_TYPE = "@fee_type";
private const string PARM_FEE_NAME = "@fee_name";
private const string PARM_FEE_DESCRIPTION = "@fee_description";
private const string PARM_FEE_CUSTOMER_TYPE = "@customer_type";
private const string PARM_FEE_CUSTOMER_NAME = "@customer_name";
private const string PARM_FEE_UNIT = "@unit";
private const string PARM_FEE_UNIT_PRICE = "@unit_price";
private const string PARM_FEE_QUANTITY = "@quantity";
private const string PARM_FEE_AMOUNT = "@amount";
private const string PARM_FEE_CURRENCY = "@currency";
private const string PARM_FEE_EXCHANGE_RATE = "@exchange_rate";
private const string PARM_FEE_REASON = "@reason";
private const string PARM_FEE_REMARK = "@remark";
private const string PARM_FEE_COMMISSION_RATE = "@comm_rate";
private const string PARM_FEE_SETTLEMENT = "@settlement";
private const string PARM_FEE_INVOICE = "@invoice";
private const string PARM_FEE_ORDER_AMOUNT = "@order_amount";
private const string PARM_FEE_ORDER_INVOCE = "@order_invoice";
private const string PARM_FEE_SUBMIT_DATE = "@submit_date";
private const string PARM_FEE_AUDIT_OPERATOR = "@audit_operator";
private const string PARM_FEE_AUDIT_DATE = "@audit_date";
private const string PARM_FEE_ENTER_OPERATOR = "@enter_operator";
private const string PARM_FEE_ENTER_DATE = "@enter_date";
private const string PARM_FEE_DEBITNO = "@debitno";
private const string PARM_FEE_ISDEBIT = "@is_debit";
private const string PARM_FEE_ISOPEN = "@is_open";
private const string PARM_FEE_ISADVANCEPAY = "@is_advance_pay";
private const string PARM_FEE_SORT = "@sort";
private const string PARM_FEE_ISINVOICE = "@is_invoice";
private const string PARM_FEE_STATUS = "@fee_status";
private const string PARM_FEE_FRT = "@fee_frt";
private const string PARM_FEE_IS_CRM_ORDER_FEE = "@is_crm_orderfee";
#endregion
#region 费用利润
//fee_gain
private const string PARM_FEEPROFIT_GID = "@gid";//惟一标识
private const string PARM_FEEPROFIT_BSNO = "@bsno";//委托编号
private const string PARM_FEEPROFIT_RMB_DR = "@rmb_dr";//应收人民币
private const string PARM_FEEPROFIT_USD_DR = "@usd_dr";//应收美元
private const string PARM_FEEPROFIT_OTHER_DR = "@other_dr";//应收其他币别
private const string PARM_FEEPROFIT_RMB_CR = "@rmb_cr";//应付人民币
private const string PARM_FEEPROFIT_USD_CR = "@usd_cr";//应付美元
private const string PARM_FEEPROFIT_OTHER_CR = "@other_cr";//应付其他币别
private const string PARM_FEEPROFIT_DR_TOTAL = "@dr_total";//应收合计
private const string PARM_FEEPROFIT_CR_TOTAL = "@cr_total";//应付合计
private const string PARM_FEEPROFIT_STL_DR_RMB = "@stl_dr_rmb";//应收RMB结算
private const string PARM_FEEPROFIT_STL_DR_USD = "@stl_dr_usd";//应收USB结算
private const string PARM_FEEPROFIT_STL_DR_OTHER = "@stl_dr_other";//应收其他币别结算
private const string PARM_FEEPROFIT_STL_CR_RMB = "@stl_cr_rmb";//应收RMB结算
private const string PARM_FEEPROFIT_STL_CR_USD = "@stl_cr_usd";//应收USB结算
private const string PARM_FEEPROFIT_STL_CR_OTHER = "@stl_cr_other";//应收其他币别结算
private const string PARM_FEEPROFIT_STL_DR_TOTAL = "@stl_dr_total";//应收结算合计
private const string PARM_FEEPROFIT_STL_CR_TOTAL = "@stl_cr_total";//应付结算合计
private const string PARM_FEEPROFIT_RMB_PROFIT = "@rmb_profit";//RMB利润
private const string PARM_FEEPROFIT_USD_PROFIT = "@usd_profit";//USD利润
private const string PARM_FEEPROFIT_OTHER_PROFIT = "@other_profit";//其他币别利润
private const string PARM_FEEPROFIT_PROFIT_TOTAL = "@profit_total";//合计利润
private const string PARM_FEEPROFIT_PROFIT_RATE = "@profit_rate";//利润率
private const string PARM_FEEPROFIT_CREATE_USER = "@create_user";//创建人
private const string PARM_FEEPROFIT_CREATE_TIME = "@create_time";//创建时间
private const string PARM_FEEPROFIT_MODIFIED_USER = "@modified_user";//最后一次更新操作人GID
private const string PARM_FEEPROFIT_MODIFIED_TIME = "@modified_time";//最后一次更新时间
#endregion
private const string SQL_SELECT_FEE_BY_GID = " SELECT GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE, SETTLEMENT, INVOICE, ORDERAMOUNT, ORDERINVOICE, SUBMITDATE, AUDITOPERATOR, "
+ " AUDITDATE, ENTEROPERATOR, ENTERDATE, DEBITNO, ISDEBIT, ISOPEN, ISADVANCEDPAY, SORT, ISINVOICE, FEESTATUS, FEEFRT,AUDITSTATUS,ISSUBMIT2FEE "
+ " FROM crm_orderfee WHERE GID = @gid ";
private const string SQL_SELECT_FEE_BY_BSNO = " SELECT GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE, SETTLEMENT, INVOICE, ORDERAMOUNT, ORDERINVOICE, SUBMITDATE, AUDITOPERATOR, "
+ " AUDITDATE, ENTEROPERATOR, ENTERDATE, DEBITNO, ISDEBIT, ISOPEN, ISADVANCEDPAY, SORT, ISINVOICE, FEESTATUS, FEEFRT,AUDITSTATUS,ISSUBMIT2FEE "
+ " FROM crm_orderfee WHERE BSNO = @bsno ";
private const string SQL_INSERT_CH_FEE = " INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE, SETTLEMENT, INVOICE, ORDERAMOUNT, ORDERINVOICE, SUBMITDATE, AUDITOPERATOR, "
+ " AUDITDATE, ENTEROPERATOR, ENTERDATE, DEBITNO, ISDEBIT, ISOPEN, ISADVANCEDPAY, SORT, ISINVOICE, FEESTATUS, FEEFRT,ISCRMORDERFEE ) "
+ " VALUES "
+ " (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, "
+ " @exchange_rate,@reason,@remark,@comm_rate,@settlement,@invoice,@order_amount,@order_invoice,@submit_date,@audit_operator, "
+ " @audit_date,@debitno,@is_debit,@is_open,@is_advance_pay,@sort,@is_invoice,@fee_status,@fee_frt,@is_crm_orderfee)";
private const string SQL_INSERT_CRM_ORDER_FEE = " INSERT INTO crm_orderfee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE, SETTLEMENT, INVOICE, ORDERAMOUNT, ORDERINVOICE, SUBMITDATE, AUDITOPERATOR, "
+ " AUDITDATE, ENTEROPERATOR, ENTERDATE, DEBITNO, ISDEBIT, ISOPEN, ISADVANCEDPAY, SORT, ISINVOICE, FEESTATUS, FEEFRT,AUDITSTATUS,ISSUBMIT2FEE) "
+ " VALUES "
+ " (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, "
+ " @exchange_rate,@reason,@remark,@comm_rate,@settlement,@invoice,@order_amount,@order_invoice,@submit_date,@audit_operator, "
+ " @audit_date,@debitno,@is_debit,@is_open,@is_advance_pay,@sort,@is_invoice,@fee_status,@fee_frt,@audit_status,@is_submit2fee)";
private const string SQL_UPDATE_CRM_ORDER_FEE_IS_SUBMIT = "UPDATE crm_orderfee SET ISSUBMIT2FEE = @is_submit2fee WHERE GID = @gid ";
private const string SQL_DELETE_CRM_ORDER_FEE = "DELETE FROM crm_orderfee WHERE GID = @gid ";
private const string SQL_UPDATE_CRM_FEE_STATUS_BY_GID = "UPDATE crm_orderfee SET FEESTATUS = @fee_status WHERE GID = @gid";
private const string SQL_INSERT_CRM_ORDER_FEE_OPERATE = " INSERT INTO crm_orderfee(GID,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,COMMISSIONRATE,AMOUNT,CURRENCY,EXCHANGERATE,FEEFRT,REMARK,ISADVANCEDPAY,FEETYPE,BSNO,ENTEROPERATOR,ENTERDATE,FEESTATUS) "
+ " VALUES(@gid,@fee_name,@customer_name,@unit,@unit_price,@quantity,@comm_rate,@amount,@currency,@exchange_rate,@fee_frt,@remark,@is_advance_pay,@fee_type,"
+ " @bsno,@enter_operator,GETDATE(),@fee_status) ";
private const string SQL_UPDATE_CRM_ORDER_FEE_OPERATE = " UPDATE crm_orderfee SET FEENAME = @fee_name,CUSTOMERNAME = @customer_name,UNIT = @unit,UNITPRICE = @unit_price,QUANTITY = @quantity,COMMISSIONRATE = @comm_rate,"
+ " AMOUNT = @amount,CURRENCY = @currency,EXCHANGERATE = @exchange_rate,FEEFRT = @fee_frt,REMARK = @remark,ISADVANCEDPAY = @is_advance_pay WHERE GID = @gid ";
private const string SQL_SELECT_CRM_ORDER_FEE_STATUS = "SELECT FEESTATUS FROM crm_orderfee WHERE GID = @gid";
private const string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = @bsno ";
private const string SQL_INSERT_FEE_PROFIT = " INSERT INTO fee_gain(GID, BSNO, RMBDR, USDDR, OTDR, RMBCR, USDCR, OTCR, DRTTL, CRTTL,RMBPROFIT, USDPROFIT,OTPROFIT, TTLPROFIT, PROFITRATE,CREATEUSER,CREATETIME )"
+ " VALUES (@gid, @bsno, @rmb_dr, @usd_dr, @other_dr, @rmb_cr, @usd_cr, @other_cr, @dr_total, @cr_total, @rmb_profit, @usd_profit, @other_profit, @profit_total, @profit_rate, @create_user, GETDATE())";
private const string SQL_UPDATE_FEE_PROFIT_BY_BSNO = " UPDATE fee_gain SET RMBDR = @rmb_dr,USDDR = @usd_dr,OTDR = @other_dr,RMBCR = @rmb_cr,USDCR = @usd_cr,OTCR = @other_cr, DRTTL = @dr_total,CRTTL = @cr_total,RMBPROFIT = @rmb_profit,USDPROFIT = @usd_profit,OTPROFIT = @other_profit,TTLPROFIT = @profit_total, PROFITRATE = @profit_rate,MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE() WHERE BSNO = @bsno ";
private const string SQL_UPDATE_FEE_PROFIT_PRECENT = " UPDATE fee_gain SET PROFITRATE = A.PROFITRATE FROM ("
+ " SELECT BSNO,(CAST(CAST(CASE WHEN CRTTL = 0 THEN 0 ELSE (ROUND(TTLPROFIT/CRTTL,4))*100 END as decimal(18,2)) as varchar(20))+'%')as PROFITRATE FROM fee_gain WHERE BSNO = @bsno"
+ " ) as A WHERE fee_gain.BSNO = A.BSNO";
#region 通过费用GID获取费用信息
///
/// 通过费用GID获取费用信息
///
///
///
public CrmOrderFeeEntity GetFeeByID(string strGID)
{
CrmOrderFeeEntity crmOrderFeeEntity = null;
SqlParameter parm = new SqlParameter(PARM_CRM_ORDER_FEE_GID, SqlDbType.VarChar, 36);
parm.Value = strGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEE_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
crmOrderFeeEntity = new CrmOrderFeeEntity();
if (!sqlRead.IsDBNull(0))
{
crmOrderFeeEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
crmOrderFeeEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
crmOrderFeeEntity.FeeType = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
crmOrderFeeEntity.FeeName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
crmOrderFeeEntity.FeeDescription = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
crmOrderFeeEntity.CustomerType = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
crmOrderFeeEntity.CustomerName = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
crmOrderFeeEntity.Unit = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
crmOrderFeeEntity.UnitPrice = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
crmOrderFeeEntity.Quantity = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
crmOrderFeeEntity.Amount = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
crmOrderFeeEntity.Currency = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
crmOrderFeeEntity.ExchangeRate = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
crmOrderFeeEntity.Reason = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
crmOrderFeeEntity.Remark = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
crmOrderFeeEntity.CommissionRate = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
crmOrderFeeEntity.Settlement = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
crmOrderFeeEntity.Invoice = sqlRead.GetDecimal(17);
}
if (!sqlRead.IsDBNull(18))
{
crmOrderFeeEntity.OrderAmount = sqlRead.GetDecimal(18);
}
if (!sqlRead.IsDBNull(19))
{
crmOrderFeeEntity.OrderInvoice = sqlRead.GetDecimal(19);
}
if (!sqlRead.IsDBNull(20))
{
crmOrderFeeEntity.SubmitDate = sqlRead.GetDateTime(20);
}
if (!sqlRead.IsDBNull(21))
{
crmOrderFeeEntity.AuditOperator = sqlRead.GetString(21);
}
if (!sqlRead.IsDBNull(22))
{
crmOrderFeeEntity.AuditDate = sqlRead.GetDateTime(22);
}
if (!sqlRead.IsDBNull(23))
{
crmOrderFeeEntity.EnterOperator = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
crmOrderFeeEntity.EnterDate = sqlRead.GetDateTime(24);
}
if (!sqlRead.IsDBNull(25))
{
crmOrderFeeEntity.DebitNO = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
crmOrderFeeEntity.IsDebit = sqlRead.GetBoolean(26);
}
if (!sqlRead.IsDBNull(27))
{
crmOrderFeeEntity.IsOpen = sqlRead.GetBoolean(27);
}
if (!sqlRead.IsDBNull(28))
{
crmOrderFeeEntity.IsAdvancePay = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
crmOrderFeeEntity.Sort = sqlRead.GetInt32(29);
}
if (!sqlRead.IsDBNull(30))
{
crmOrderFeeEntity.IsInvoice = sqlRead.GetBoolean(30);
}
if (!sqlRead.IsDBNull(31))
{
crmOrderFeeEntity.FeeStatus = sqlRead.GetInt32(31);
}
if (!sqlRead.IsDBNull(32))
{
crmOrderFeeEntity.FeeFrt = sqlRead.GetString(32);
}
if (!sqlRead.IsDBNull(33))
{
crmOrderFeeEntity.AuditStatus = sqlRead.GetInt32(33);
}
if (!sqlRead.IsDBNull(34))
{
crmOrderFeeEntity.IsSubmitToFee = sqlRead.GetBoolean(34);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return crmOrderFeeEntity;
}
#endregion
#region 通过订舱编号BSNO获取订舱费用信息
///
/// 通过订舱编号BSNO获取订舱费用信息
///
///
///
public IList GetFeeByBSNO(string strBSNO)
{
IList crmOrderFeeEntities = new List();
SqlParameter parm = new SqlParameter(PARM_CRM_ORDER_FEE_BSNO, SqlDbType.VarChar, 100);
parm.Value = strBSNO;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEE_BY_BSNO, parm))
{
try
{
while (sqlRead.Read())
{
CrmOrderFeeEntity crmOrderFeeEntity = new CrmOrderFeeEntity();
if (!sqlRead.IsDBNull(0))
{
crmOrderFeeEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
crmOrderFeeEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
crmOrderFeeEntity.FeeType = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
crmOrderFeeEntity.FeeName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
crmOrderFeeEntity.FeeDescription = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
crmOrderFeeEntity.CustomerType = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
crmOrderFeeEntity.CustomerName = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
crmOrderFeeEntity.Unit = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
crmOrderFeeEntity.UnitPrice = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
crmOrderFeeEntity.Quantity = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
crmOrderFeeEntity.Amount = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
crmOrderFeeEntity.Currency = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
crmOrderFeeEntity.ExchangeRate = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
crmOrderFeeEntity.Reason = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
crmOrderFeeEntity.Remark = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
crmOrderFeeEntity.CommissionRate = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
crmOrderFeeEntity.Settlement = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
crmOrderFeeEntity.Invoice = sqlRead.GetDecimal(17);
}
if (!sqlRead.IsDBNull(18))
{
crmOrderFeeEntity.OrderAmount = sqlRead.GetDecimal(18);
}
if (!sqlRead.IsDBNull(19))
{
crmOrderFeeEntity.OrderInvoice = sqlRead.GetDecimal(19);
}
if (!sqlRead.IsDBNull(20))
{
crmOrderFeeEntity.SubmitDate = sqlRead.GetDateTime(20);
}
if (!sqlRead.IsDBNull(21))
{
crmOrderFeeEntity.AuditOperator = sqlRead.GetString(21);
}
if (!sqlRead.IsDBNull(22))
{
crmOrderFeeEntity.AuditDate = sqlRead.GetDateTime(22);
}
if (!sqlRead.IsDBNull(23))
{
crmOrderFeeEntity.EnterOperator = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
crmOrderFeeEntity.EnterDate = sqlRead.GetDateTime(24);
}
if (!sqlRead.IsDBNull(25))
{
crmOrderFeeEntity.DebitNO = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
crmOrderFeeEntity.IsDebit = sqlRead.GetBoolean(26);
}
if (!sqlRead.IsDBNull(27))
{
crmOrderFeeEntity.IsOpen = sqlRead.GetBoolean(27);
}
if (!sqlRead.IsDBNull(28))
{
crmOrderFeeEntity.IsAdvancePay = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
crmOrderFeeEntity.Sort = sqlRead.GetInt32(29);
}
if (!sqlRead.IsDBNull(30))
{
crmOrderFeeEntity.IsInvoice = sqlRead.GetBoolean(30);
}
if (!sqlRead.IsDBNull(31))
{
crmOrderFeeEntity.FeeStatus = sqlRead.GetInt32(31);
}
if (!sqlRead.IsDBNull(32))
{
crmOrderFeeEntity.FeeFrt = sqlRead.GetString(32);
}
if (!sqlRead.IsDBNull(33))
{
crmOrderFeeEntity.AuditStatus = sqlRead.GetInt32(33);
}
if (!sqlRead.IsDBNull(34))
{
crmOrderFeeEntity.IsSubmitToFee = sqlRead.GetBoolean(34);
}
crmOrderFeeEntities.Add(crmOrderFeeEntity);
}
}
catch (Exception execError)
{
throw execError;
}
}
return crmOrderFeeEntities;
}
#endregion
#region 将订舱费用信息插入到ch_fee表
///
/// 将订舱费用信息插入到ch_fee表
///
/// 订舱费用信息
/// 值1表示 插入完成 值小于1表示插入异常
public int InsertOpSeaeFee(CrmOrderFeeEntity tempCrmOrderFeeEntity)
{
int iResult = 0;
#region 获取参数
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_BSNO,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_TYPE,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DESCRIPTION,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_CUSTOMER_TYPE,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_UNIT,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_UNIT_PRICE,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_REASON,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_REMARK,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_SETTLEMENT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_INVOICE,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_ORDER_AMOUNT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_ORDER_INVOCE,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEE_SUBMIT_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_FEE_AUDIT_OPERATOR,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_AUDIT_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_FEE_ENTER_OPERATOR,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_ENTER_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_FEE_DEBITNO,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_ISDEBIT,SqlDbType.Bit),
new SqlParameter(PARM_FEE_ISOPEN,SqlDbType.Bit),
new SqlParameter(PARM_FEE_ISADVANCEPAY,SqlDbType.Bit),
new SqlParameter(PARM_FEE_SORT,SqlDbType.Int),
new SqlParameter(PARM_FEE_ISINVOICE,SqlDbType.Bit),
new SqlParameter(PARM_FEE_STATUS,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_IS_CRM_ORDER_FEE,SqlDbType.Bit)
};
parms[0].Value = tempCrmOrderFeeEntity.GID;
parms[1].Value = tempCrmOrderFeeEntity.BSNO;
parms[2].Value = tempCrmOrderFeeEntity.FeeType;
parms[3].Value = tempCrmOrderFeeEntity.FeeName;
parms[4].Value = tempCrmOrderFeeEntity.FeeDescription;
parms[5].Value = tempCrmOrderFeeEntity.CustomerType;
parms[6].Value = tempCrmOrderFeeEntity.CustomerName;
parms[7].Value = tempCrmOrderFeeEntity.Unit;
parms[8].Value = tempCrmOrderFeeEntity.UnitPrice;
parms[9].Value = tempCrmOrderFeeEntity.Quantity;
parms[10].Value = tempCrmOrderFeeEntity.Amount;
parms[11].Value = tempCrmOrderFeeEntity.Currency;
parms[12].Value = tempCrmOrderFeeEntity.ExchangeRate;
parms[13].Value = tempCrmOrderFeeEntity.Reason;
parms[14].Value = tempCrmOrderFeeEntity.Remark;
parms[15].Value = tempCrmOrderFeeEntity.CommissionRate;
parms[16].Value = tempCrmOrderFeeEntity.Settlement;
parms[17].Value = tempCrmOrderFeeEntity.Invoice;
parms[18].Value = tempCrmOrderFeeEntity.OrderAmount;
parms[19].Value = tempCrmOrderFeeEntity.OrderInvoice;
parms[20].Value = tempCrmOrderFeeEntity.SubmitDate;
parms[21].Value = tempCrmOrderFeeEntity.AuditOperator;
parms[22].Value = tempCrmOrderFeeEntity.AuditDate;
parms[23].Value = tempCrmOrderFeeEntity.EnterOperator;
parms[24].Value = tempCrmOrderFeeEntity.EnterDate;
parms[25].Value = tempCrmOrderFeeEntity.DebitNO;
parms[26].Value = tempCrmOrderFeeEntity.IsDebit;
parms[27].Value = tempCrmOrderFeeEntity.IsOpen;
parms[28].Value = tempCrmOrderFeeEntity.IsAdvancePay;
parms[29].Value = tempCrmOrderFeeEntity.Sort;
parms[30].Value = tempCrmOrderFeeEntity.IsInvoice;
parms[31].Value = tempCrmOrderFeeEntity.FeeStatus;
parms[32].Value = 1;//True
#endregion
SqlParameter[] updateOrderParms = new SqlParameter[] {
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_IS_SUBMIT2_FEE,SqlDbType.Bit)
};
updateOrderParms[0].Value = tempCrmOrderFeeEntity.GID;
updateOrderParms[1].Value = 1;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//将crm_orderfee中的费用信息插入到ch_fee表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, updateOrderParms);
//更新crm_orderfee字段 ISSUBMIT2FEE 标识是否已经提交到ch_fee表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CRM_ORDER_FEE_IS_SUBMIT, updateOrderParms);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 插入订舱费用信息
///
/// 插入订舱费用信息
///
/// 订舱费用信息
/// 值1表示插入完成 值小于1表示插入异常
public int InsertCrmOrderFee(CrmOrderFeeEntity tempCrmOrderFeeEntity)
{
int iResult = 0;
#region 获取参数
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_BSNO,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_TYPE,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_DESCRIPTION,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_CUSTOMER_TYPE,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT_PRICE,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_QUANTITY,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_AMOUNT,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_EXCHANGE_RATE,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_REASON,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_REMARK,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_COMMISSION_RATE,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_SETTLEMENT,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_INVOICE,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_ORDER_AMOUNT,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_ORDER_INVOCE,SqlDbType.Decimal,18),
new SqlParameter(PARM_CRM_ORDER_FEE_SUBMIT_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_CRM_ORDER_FEE_AUDIT_OPERATOR,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_AUDIT_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_CRM_ORDER_FEE_ENTER_OPERATOR,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_ENTER_DATE,SqlDbType.SmallDateTime),
new SqlParameter(PARM_CRM_ORDER_FEE_DEBITNO,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_ISDEBIT,SqlDbType.Bit),
new SqlParameter(PARM_CRM_ORDER_FEE_ISOPEN,SqlDbType.Bit),
new SqlParameter(PARM_CRM_ORDER_FEE_ISADVANCEPAY,SqlDbType.Bit),
new SqlParameter(PARM_CRM_ORDER_FEE_SORT,SqlDbType.Int),
new SqlParameter(PARM_CRM_ORDER_FEE_ISINVOICE,SqlDbType.Bit),
new SqlParameter(PARM_CRM_ORDER_FEE_STATUS,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_FRT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_AUDIT_STATUS,SqlDbType.Int),
new SqlParameter(PARM_CRM_ORDER_FEE_IS_SUBMIT2_FEE,SqlDbType.Bit)
};
parms[0].Value = tempCrmOrderFeeEntity.GID;
parms[1].Value = tempCrmOrderFeeEntity.BSNO;
parms[2].Value = tempCrmOrderFeeEntity.FeeType;
parms[3].Value = tempCrmOrderFeeEntity.FeeName;
parms[4].Value = tempCrmOrderFeeEntity.FeeDescription;
parms[5].Value = tempCrmOrderFeeEntity.CustomerType;
parms[6].Value = tempCrmOrderFeeEntity.CustomerName;
parms[7].Value = tempCrmOrderFeeEntity.Unit;
parms[8].Value = tempCrmOrderFeeEntity.UnitPrice;
parms[9].Value = tempCrmOrderFeeEntity.Quantity;
parms[10].Value = tempCrmOrderFeeEntity.Amount;
parms[11].Value = tempCrmOrderFeeEntity.Currency;
parms[12].Value = tempCrmOrderFeeEntity.ExchangeRate;
parms[13].Value = tempCrmOrderFeeEntity.Reason;
parms[14].Value = tempCrmOrderFeeEntity.Remark;
parms[15].Value = tempCrmOrderFeeEntity.CommissionRate;
parms[16].Value = tempCrmOrderFeeEntity.Settlement;
parms[17].Value = tempCrmOrderFeeEntity.Invoice;
parms[18].Value = tempCrmOrderFeeEntity.OrderAmount;
parms[19].Value = tempCrmOrderFeeEntity.OrderInvoice;
parms[20].Value = tempCrmOrderFeeEntity.SubmitDate;
parms[21].Value = tempCrmOrderFeeEntity.AuditOperator;
parms[22].Value = tempCrmOrderFeeEntity.AuditDate;
parms[23].Value = tempCrmOrderFeeEntity.EnterOperator;
parms[24].Value = tempCrmOrderFeeEntity.EnterDate;
parms[25].Value = tempCrmOrderFeeEntity.DebitNO;
parms[26].Value = tempCrmOrderFeeEntity.IsDebit;
parms[27].Value = tempCrmOrderFeeEntity.IsOpen;
parms[28].Value = tempCrmOrderFeeEntity.IsAdvancePay;
parms[29].Value = tempCrmOrderFeeEntity.Sort;
parms[30].Value = tempCrmOrderFeeEntity.IsInvoice;
parms[31].Value = tempCrmOrderFeeEntity.FeeStatus;
parms[32].Value = tempCrmOrderFeeEntity.FeeFrt;
parms[33].Value = tempCrmOrderFeeEntity.AuditStatus;
parms[34].Value = tempCrmOrderFeeEntity.IsSubmitToFee;
#endregion
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_CRM_ORDER_FEE, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
#region 根据SQL语句查询费用数据集
///
/// 根据SQL语句查询费用数据集
///
///
///
public DataSet GetFeeListByCondition(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
#region 更新费用列表信息
///
/// 更新费用列表信息
///
/// 更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作
/// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0
public int UpdateFeeFromGrid(ArrayList sqlList)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
for (int i = 0; i < sqlList.Count; i++)
{
string strUpdateSql = sqlList[i].ToString();
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
}
sqlTran.Commit();
result = 1;//状态为1表示更新成功
}
catch (Exception execError)
{
result = -1;//有异常,更新失败
sqlTran.Rollback();
result = -2;//更新异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 插入费用列表信息
///
/// 插入费用列表信息
///
/// 插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作
/// 返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0
public int InsertFeeFromGrid(ArrayList sqlList)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
for (int i = 0; i < sqlList.Count; i++)
{
string strUpdateSql = sqlList[i].ToString();
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
}
sqlTran.Commit();
result = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 通过费用GID删除单条费用
///
/// 通过费用GID删除单条费用
///
/// 订舱费用GID
/// 值1删除成功 值小于1删除失败
public int DeleteFeeByGid(string tempGid, string tempCurrency, int tempFeeType, decimal tempAmount, decimal tempRate, string tempBSNO)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//先将费用利润表中费用金额减兑
string strSql = "";
if (tempFeeType == 1)
{
if (tempCurrency == "RMB")
{
strSql = String.Format(" UPDATE fee_gain SET RMBDR = RMBDR - {0},DRTTL = DRTTL - {0},RMBPROFIT = RMBPROFIT - {0},TTLPROFIT = TTLPROFIT - {0} WHERE BSNO = '{1}' ", tempAmount, tempBSNO);
}
else
{
strSql = String.Format(" UPDATE fee_gain SET USDDR = USDDR - {0},DRTTL = DRTTL - {1},USDPROFIT = USDPROFIT - {0},TTLPROFIT = TTLPROFIT - {1} WHERE BSNO = '{2}' ", tempAmount, (tempAmount * tempRate), tempBSNO);
}
}
else
{
if (tempCurrency == "RMB")
{
strSql = String.Format(" UPDATE fee_gain SET RMBCR = RMBCR - {0},CRTTL = CRTTL - {0},RMBPROFIT = RMBPROFIT + {0},TTLPROFIT = TTLPROFIT + {0} WHERE BSNO = '{1}' ", tempAmount, tempBSNO);
}
else
{
strSql = String.Format(" UPDATE fee_gain SET USDCR = USDCR - {0},CRTTL = CRTTL - {1},USDPROFIT = USDPROFIT + {0},TTLPROFIT = TTLPROFIT + {1} WHERE BSNO = '{2}' ", tempAmount, (tempAmount * tempRate), tempBSNO);
}
}
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//重新计算百分率(利润总和/应付费用总和)
SqlParameter[] precentParms = new SqlParameter[] {
new SqlParameter(PARM_FEEPROFIT_BSNO,SqlDbType.VarChar,100)
};
precentParms[0].Value = tempBSNO;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FEE_PROFIT_PRECENT, precentParms);
//删除费用
SqlParameter parm = new SqlParameter(PARM_CRM_ORDER_FEE_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_CRM_ORDER_FEE, parm);
result = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 根据SQL语句更新费用信息
///
/// 根据SQL语句更新费用信息
///
///
///
public int UpdateFeeStatus(int iStatus, string strGID)
{
int result = 0;
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_CRM_ORDER_FEE_STATUS,SqlDbType.Int),
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36)
};
parms[0].Value = iStatus;
parms[1].Value = strGID;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_UPDATE_CRM_FEE_STATUS_BY_GID, parms);
result = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 通过委托编号BSNO与费用类型获取订舱费用信息
///
/// 通过委托编号BSNO与费用类型获取订舱费用信息
///
///
///
public CrmOrderFeeEntity GetCrmOrderFeeByBSNOAndType(string strBSNO, int iType)
{
CrmOrderFeeEntity crmOrderFeeEntity = null;
string strSql = " SELECT TOP 1 GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, "
+ " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE, SETTLEMENT, INVOICE, ORDERAMOUNT, ORDERINVOICE, SUBMITDATE, AUDITOPERATOR, "
+ " AUDITDATE, ENTEROPERATOR, ENTERDATE, DEBITNO, ISDEBIT, ISOPEN, ISADVANCEDPAY, SORT, ISINVOICE, FEESTATUS, FEEFRT,ISSUBMIT2FEE "
+ " FROM crm_orderfee WHERE BSNO = '" + strBSNO + "' AND FEETYPE = " + iType;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
while (sqlRead.Read())
{
crmOrderFeeEntity = new CrmOrderFeeEntity();
if (!sqlRead.IsDBNull(0))
{
crmOrderFeeEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
crmOrderFeeEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
crmOrderFeeEntity.FeeType = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
crmOrderFeeEntity.FeeName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
crmOrderFeeEntity.FeeDescription = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
crmOrderFeeEntity.CustomerType = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
crmOrderFeeEntity.CustomerName = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
crmOrderFeeEntity.Unit = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
crmOrderFeeEntity.UnitPrice = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
crmOrderFeeEntity.Quantity = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
crmOrderFeeEntity.Amount = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
crmOrderFeeEntity.Currency = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
crmOrderFeeEntity.ExchangeRate = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
crmOrderFeeEntity.Reason = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
crmOrderFeeEntity.Remark = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
crmOrderFeeEntity.CommissionRate = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
crmOrderFeeEntity.Settlement = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
crmOrderFeeEntity.Invoice = sqlRead.GetDecimal(17);
}
if (!sqlRead.IsDBNull(18))
{
crmOrderFeeEntity.OrderAmount = sqlRead.GetDecimal(18);
}
if (!sqlRead.IsDBNull(19))
{
crmOrderFeeEntity.OrderInvoice = sqlRead.GetDecimal(19);
}
if (!sqlRead.IsDBNull(20))
{
crmOrderFeeEntity.SubmitDate = sqlRead.GetDateTime(20);
}
if (!sqlRead.IsDBNull(21))
{
crmOrderFeeEntity.AuditOperator = sqlRead.GetString(21);
}
if (!sqlRead.IsDBNull(22))
{
crmOrderFeeEntity.AuditDate = sqlRead.GetDateTime(22);
}
if (!sqlRead.IsDBNull(23))
{
crmOrderFeeEntity.EnterOperator = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
crmOrderFeeEntity.EnterDate = sqlRead.GetDateTime(24);
}
if (!sqlRead.IsDBNull(25))
{
crmOrderFeeEntity.DebitNO = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
crmOrderFeeEntity.IsDebit = sqlRead.GetBoolean(26);
}
if (!sqlRead.IsDBNull(27))
{
crmOrderFeeEntity.IsOpen = sqlRead.GetBoolean(27);
}
if (!sqlRead.IsDBNull(28))
{
crmOrderFeeEntity.IsAdvancePay = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
crmOrderFeeEntity.Sort = sqlRead.GetInt32(29);
}
if (!sqlRead.IsDBNull(30))
{
crmOrderFeeEntity.IsInvoice = sqlRead.GetBoolean(30);
}
if (!sqlRead.IsDBNull(31))
{
crmOrderFeeEntity.FeeStatus = sqlRead.GetInt32(31);
}
if (!sqlRead.IsDBNull(32))
{
crmOrderFeeEntity.FeeFrt = sqlRead.GetString(32);
}
if (!sqlRead.IsDBNull(33))
{
crmOrderFeeEntity.IsSubmitToFee = sqlRead.GetBoolean(33);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return crmOrderFeeEntity;
}
#endregion
public int DoFee(IList tempCrmOrderFeeEntities, FeeProfitEntity feeProfitEntity, string tempBSNO)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] validParms = new SqlParameter[] {
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36)
};
foreach (CrmOrderFeeEntity crmOrderFeeEntity in tempCrmOrderFeeEntities)
{
int iFeeStatus = 0;
validParms[0].Value = crmOrderFeeEntity.GID;
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_CRM_ORDER_FEE_STATUS, validParms);
if (statusObj == null)
{
iFeeStatus = -1;
}
else
{
iFeeStatus = (int)statusObj;
}
if (iFeeStatus == 1)
{
//只更新FEESTATUS = 1状态的费用信息(其他状态不能编辑,所以其他状态不做更新操作)
SqlParameter[] updateParms = new SqlParameter[] {
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT_PRICE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_QUANTITY,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_COMMISSION_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_FRT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_REMARK,SqlDbType.VarChar),
new SqlParameter(PARM_CRM_ORDER_FEE_ISADVANCEPAY,SqlDbType.Bit)
};
updateParms[0].Value = crmOrderFeeEntity.GID;
updateParms[1].Value = crmOrderFeeEntity.FeeName;
updateParms[2].Value = crmOrderFeeEntity.CustomerName;
updateParms[3].Value = crmOrderFeeEntity.Unit;
updateParms[4].Value = crmOrderFeeEntity.UnitPrice;
updateParms[5].Value = crmOrderFeeEntity.Quantity;
updateParms[6].Value = crmOrderFeeEntity.CommissionRate;
updateParms[7].Value = crmOrderFeeEntity.Amount;
updateParms[8].Value = crmOrderFeeEntity.Currency;
updateParms[9].Value = crmOrderFeeEntity.ExchangeRate;
updateParms[10].Value = crmOrderFeeEntity.FeeFrt;
updateParms[11].Value = crmOrderFeeEntity.Remark;
updateParms[12].Value = crmOrderFeeEntity.IsAdvancePay;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CRM_ORDER_FEE_OPERATE, updateParms);
}
else if (iFeeStatus < 0)
{
SqlParameter[] insertParms = new SqlParameter[] {
new SqlParameter(PARM_CRM_ORDER_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CRM_ORDER_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_UNIT_PRICE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_QUANTITY,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_COMMISSION_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_CRM_ORDER_FEE_FRT,SqlDbType.VarChar,20),
new SqlParameter(PARM_CRM_ORDER_FEE_REMARK,SqlDbType.VarChar),
new SqlParameter(PARM_CRM_ORDER_FEE_ISADVANCEPAY,SqlDbType.Bit),
new SqlParameter(PARM_CRM_ORDER_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_CRM_ORDER_FEE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_CRM_ORDER_FEE_ENTER_OPERATOR,SqlDbType.VarChar,50),
new SqlParameter(PARM_CRM_ORDER_FEE_STATUS,SqlDbType.Int)
};
insertParms[0].Value = crmOrderFeeEntity.GID;
insertParms[1].Value = crmOrderFeeEntity.FeeName;
insertParms[2].Value = crmOrderFeeEntity.CustomerName;
insertParms[3].Value = crmOrderFeeEntity.Unit;
insertParms[4].Value = crmOrderFeeEntity.UnitPrice;
insertParms[5].Value = crmOrderFeeEntity.Quantity;
insertParms[6].Value = crmOrderFeeEntity.CommissionRate;
insertParms[7].Value = crmOrderFeeEntity.Amount;
insertParms[8].Value = crmOrderFeeEntity.Currency;
insertParms[9].Value = crmOrderFeeEntity.ExchangeRate;
insertParms[10].Value = crmOrderFeeEntity.FeeFrt;
insertParms[11].Value = crmOrderFeeEntity.Remark;
insertParms[12].Value = crmOrderFeeEntity.IsAdvancePay;
insertParms[13].Value = crmOrderFeeEntity.FeeType;
insertParms[14].Value = crmOrderFeeEntity.BSNO;
insertParms[15].Value = crmOrderFeeEntity.EnterOperator;
insertParms[16].Value = crmOrderFeeEntity.FeeStatus;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CRM_ORDER_FEE_OPERATE, insertParms);
}
}
SqlParameter[] validProfitParms = new SqlParameter[] {
new SqlParameter(PARM_FEEPROFIT_BSNO,SqlDbType.VarChar,100)
};
validProfitParms[0].Value = tempBSNO;
//保存利润信息
object bsnoObj = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEE_PROFIT_BY_BSNO, validProfitParms);
if (bsnoObj == null)
{
//如果没有与BSNO关联的费用利润信息,则插入新的费用利润
SqlParameter[] insertProfitParms = new SqlParameter[] {
new SqlParameter(PARM_FEEPROFIT_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEEPROFIT_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEEPROFIT_RMB_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_RMB_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_DR_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_CR_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_RMB_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_PROFIT_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_PROFIT_RATE,SqlDbType.VarChar,12),
new SqlParameter(PARM_FEEPROFIT_CREATE_USER,SqlDbType.VarChar,12)
};
insertProfitParms[0].Value = Guid.NewGuid().ToString();
insertProfitParms[1].Value = tempBSNO;
insertProfitParms[2].Value = feeProfitEntity.RMBDR;
insertProfitParms[3].Value = feeProfitEntity.USDDR;
insertProfitParms[4].Value = feeProfitEntity.OTHERDR;
insertProfitParms[5].Value = feeProfitEntity.RMBCR;
insertProfitParms[6].Value = feeProfitEntity.USDCR;
insertProfitParms[7].Value = feeProfitEntity.OTHERCR;
insertProfitParms[8].Value = feeProfitEntity.DRTTL;
insertProfitParms[9].Value = feeProfitEntity.CRTTL;
insertProfitParms[10].Value = feeProfitEntity.RMBProfit;
insertProfitParms[11].Value = feeProfitEntity.USDProfit;
insertProfitParms[12].Value = feeProfitEntity.OTHERProfit;
insertProfitParms[13].Value = feeProfitEntity.TTLProfit;
insertProfitParms[14].Value = feeProfitEntity.ProfitRate;
insertProfitParms[15].Value = feeProfitEntity.CreateUser;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_PROFIT, insertProfitParms);
}
else
{
//如果存在记录,则更新费用利润表
//如果没有与BSNO关联的费用利润信息,则插入新的费用利润
SqlParameter[] upateProfitParms = new SqlParameter[] {
new SqlParameter(PARM_FEEPROFIT_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEEPROFIT_RMB_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_DR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_RMB_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_CR,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_DR_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_CR_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_RMB_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_USD_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_OTHER_PROFIT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_PROFIT_TOTAL,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEEPROFIT_PROFIT_RATE,SqlDbType.VarChar,12),
new SqlParameter(PARM_FEEPROFIT_MODIFIED_USER,SqlDbType.VarChar,12)
};
upateProfitParms[0].Value = tempBSNO;
upateProfitParms[1].Value = feeProfitEntity.RMBDR;
upateProfitParms[2].Value = feeProfitEntity.USDDR;
upateProfitParms[3].Value = feeProfitEntity.OTHERDR;
upateProfitParms[4].Value = feeProfitEntity.RMBCR;
upateProfitParms[5].Value = feeProfitEntity.USDCR;
upateProfitParms[6].Value = feeProfitEntity.OTHERCR;
upateProfitParms[7].Value = feeProfitEntity.DRTTL;
upateProfitParms[8].Value = feeProfitEntity.CRTTL;
upateProfitParms[9].Value = feeProfitEntity.RMBProfit;
upateProfitParms[10].Value = feeProfitEntity.USDProfit;
upateProfitParms[11].Value = feeProfitEntity.OTHERProfit;
upateProfitParms[12].Value = feeProfitEntity.TTLProfit;
upateProfitParms[13].Value = feeProfitEntity.ProfitRate;
upateProfitParms[14].Value = feeProfitEntity.ModifiedUser;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FEE_PROFIT_BY_BSNO, upateProfitParms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
}
}