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.

518 lines
21 KiB
C#

10 months ago
using System;
using System.Data;
using DSWeb.Models;
using System.Data.SqlClient;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class FeeProfitDA
{
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";//最后一次更新时间
private const string SQL_SELECT_FEEPROFIT_ALL = " SELECT GID, BSNO, RMBDR, USDDR, OTDR, RMBCR, USDCR, OTCR, DRTTL, CRTTL, STLDRRMB, STLDRUSD, STLDROT, STLCRRMB, STLCRUSD, STLCROT, STLDRTTL, STLCRTTL, RMBPROFIT, USDPROFIT, OTPROFIT, TTLPROFIT, PROFITRATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM fee_gain";
private const string SQL_SELECT_FEEPROFIT_BY_GID = " SELECT GID, BSNO, RMBDR, USDDR, OTDR, RMBCR, USDCR, OTCR, DRTTL, CRTTL, STLDRRMB, STLDRUSD, STLDROT, STLCRRMB, STLCRUSD, STLCROT, STLDRTTL, STLCRTTL, RMBPROFIT, USDPROFIT,OTPROFIT, TTLPROFIT, PROFITRATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM fee_gain WHERE GID = @gid ";
private const string SQL_SELECT_FEEPROFIT_BY_BSNO = " SELECT GID, BSNO, RMBDR, USDDR, OTDR, RMBCR, USDCR, OTCR, DRTTL, CRTTL, STLDRRMB, STLDRUSD, STLDROT, STLCRRMB, STLCRUSD, STLCROT, STLDRTTL, STLCRTTL, RMBPROFIT, USDPROFIT, OTPROFIT, TTLPROFIT, PROFITRATE ,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM fee_gain WHERE BSNO = @bsno ";
private const string SQL_INSERT_FEEPROFIT_BY_FEE = " 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())";
#region 根据费用利润表GID获取利润信息
/// <summary>
/// 根据费用利润表GID获取利润信息
/// </summary>
/// <param name="tempGid">费用利润表GID</param>
/// <returns>返回 利润表实体类</returns>
public FeeProfitEntity GetFeeProfitByGID(string tempGid)
{
FeeProfitEntity feeProfitEntity = null;
SqlParameter parm = new SqlParameter(PARM_FEEPROFIT_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEEPROFIT_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
feeProfitEntity = new FeeProfitEntity();
if (!sqlRead.IsDBNull(0))
{
feeProfitEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
feeProfitEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
feeProfitEntity.RMBDR = sqlRead.GetDecimal(2);
}
if (!sqlRead.IsDBNull(3))
{
feeProfitEntity.USDDR = sqlRead.GetDecimal(3);
}
if (!sqlRead.IsDBNull(4))
{
feeProfitEntity.OTHERDR = sqlRead.GetDecimal(4);
}
if (!sqlRead.IsDBNull(5))
{
feeProfitEntity.RMBCR = sqlRead.GetDecimal(5);
}
if (!sqlRead.IsDBNull(6))
{
feeProfitEntity.USDCR = sqlRead.GetDecimal(6);
}
if (!sqlRead.IsDBNull(7))
{
feeProfitEntity.OTHERCR = sqlRead.GetDecimal(7);
}
if (!sqlRead.IsDBNull(8))
{
feeProfitEntity.DRTTL = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
feeProfitEntity.CRTTL = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
feeProfitEntity.STLDRRMB = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
feeProfitEntity.STLDRUSD = sqlRead.GetDecimal(11);
}
if (!sqlRead.IsDBNull(12))
{
feeProfitEntity.STLDROTHER = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
feeProfitEntity.STLCRRMB = sqlRead.GetDecimal(13);
}
if (!sqlRead.IsDBNull(14))
{
feeProfitEntity.STLCRUSD = sqlRead.GetDecimal(14);
}
if (!sqlRead.IsDBNull(15))
{
feeProfitEntity.STLCROTHER = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
feeProfitEntity.STLDRTTL = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
feeProfitEntity.STLCRTTL = sqlRead.GetDecimal(17);
}
if (!sqlRead.IsDBNull(18))
{
feeProfitEntity.RMBProfit = sqlRead.GetDecimal(18);
}
if (!sqlRead.IsDBNull(19))
{
feeProfitEntity.USDProfit = sqlRead.GetDecimal(19);
}
if (!sqlRead.IsDBNull(20))
{
feeProfitEntity.OTHERProfit = sqlRead.GetDecimal(20);
}
if (!sqlRead.IsDBNull(21))
{
feeProfitEntity.TTLProfit = sqlRead.GetDecimal(21);
}
if (!sqlRead.IsDBNull(22))
{
feeProfitEntity.ProfitRate = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
feeProfitEntity.CreateUser = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
feeProfitEntity.CreateTime = sqlRead.GetDateTime(24);
}
if (!sqlRead.IsDBNull(25))
{
feeProfitEntity.ModifiedUser = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
feeProfitEntity.ModifiedTime = sqlRead.GetDateTime(26);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return feeProfitEntity;
}
#endregion
#region 根据委托编号BSNO获取利润信息
/// <summary>
/// 根据委托编号BSNO获取利润信息
/// </summary>
/// <param name="tempGid">委托编号</param>
/// <returns>返回 利润表实体类</returns>
public FeeProfitEntity GetFeeProfitByBSNO(string tempBSNO)
{
FeeProfitEntity feeProfitEntity = null;
SqlParameter parm = new SqlParameter(PARM_FEEPROFIT_BSNO, SqlDbType.VarChar, 100);
parm.Value = tempBSNO;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEEPROFIT_BY_BSNO, parm))
{
try
{
while (sqlRead.Read())
{
feeProfitEntity = new FeeProfitEntity();
if (!sqlRead.IsDBNull(0))
{
feeProfitEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
feeProfitEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
feeProfitEntity.RMBDR = sqlRead.GetDecimal(2);
}
if (!sqlRead.IsDBNull(3))
{
feeProfitEntity.USDDR = sqlRead.GetDecimal(3);
}
if (!sqlRead.IsDBNull(4))
{
feeProfitEntity.OTHERDR = sqlRead.GetDecimal(4);
}
if (!sqlRead.IsDBNull(5))
{
feeProfitEntity.RMBCR = sqlRead.GetDecimal(5);
}
if (!sqlRead.IsDBNull(6))
{
feeProfitEntity.USDCR = sqlRead.GetDecimal(6);
}
if (!sqlRead.IsDBNull(7))
{
feeProfitEntity.OTHERCR = sqlRead.GetDecimal(7);
}
if (!sqlRead.IsDBNull(8))
{
feeProfitEntity.DRTTL = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
feeProfitEntity.CRTTL = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
feeProfitEntity.STLDRRMB = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
feeProfitEntity.STLDRUSD = sqlRead.GetDecimal(11);
}
if (!sqlRead.IsDBNull(12))
{
feeProfitEntity.STLDROTHER = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
feeProfitEntity.STLCRRMB = sqlRead.GetDecimal(13);
}
if (!sqlRead.IsDBNull(14))
{
feeProfitEntity.STLCRUSD = sqlRead.GetDecimal(14);
}
if (!sqlRead.IsDBNull(15))
{
feeProfitEntity.STLCROTHER = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
feeProfitEntity.STLDRTTL = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
feeProfitEntity.STLCRTTL = sqlRead.GetDecimal(17);
}
if (!sqlRead.IsDBNull(18))
{
feeProfitEntity.RMBProfit = sqlRead.GetDecimal(18);
}
if (!sqlRead.IsDBNull(19))
{
feeProfitEntity.USDProfit = sqlRead.GetDecimal(19);
}
if (!sqlRead.IsDBNull(20))
{
feeProfitEntity.OTHERProfit = sqlRead.GetDecimal(20);
}
if (!sqlRead.IsDBNull(21))
{
feeProfitEntity.TTLProfit = sqlRead.GetDecimal(21);
}
if (!sqlRead.IsDBNull(22))
{
feeProfitEntity.ProfitRate = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
feeProfitEntity.CreateUser = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
feeProfitEntity.CreateTime = sqlRead.GetDateTime(24);
}
if (!sqlRead.IsDBNull(25))
{
feeProfitEntity.ModifiedUser = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
feeProfitEntity.ModifiedTime = sqlRead.GetDateTime(26);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return feeProfitEntity;
}
#endregion
#region 更新利润信息
/// <summary>
/// 更新利润信息
/// </summary>
/// <param name="strSql">更新SQL语句</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateFeeProfit(string strSql)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null);
sqlTran.Commit();
result = 1;//状态为1表示更新成功
}
catch (Exception execError)
{
result = -1;//有异常,更新失败
sqlTran.Rollback();
result = -2;//更新异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 插入利润信息
/// <summary>
/// 插入利润信息
/// </summary>
/// <param name="strSql">插入SQL语句</param>
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
public int InsertFeeProfit(FeeProfitEntity tempProfitEntity)
{
int result = 0;
if (tempProfitEntity.GID != null)
{
SqlParameter[] parms = 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,18),
new SqlParameter(PARM_FEEPROFIT_USD_DR,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_OTHER_DR,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_RMB_CR,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_USD_CR,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_OTHER_CR,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_DR_TOTAL,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_CR_TOTAL,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_RMB_PROFIT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_USD_PROFIT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_OTHER_PROFIT,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_PROFIT_TOTAL,SqlDbType.Decimal,18),
new SqlParameter(PARM_FEEPROFIT_PROFIT_RATE,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEEPROFIT_CREATE_USER,SqlDbType.VarChar,36)
};
parms[0].Value = tempProfitEntity.GID;
parms[1].Value = tempProfitEntity.BSNO;
parms[2].Value = tempProfitEntity.RMBDR;
parms[3].Value = tempProfitEntity.USDDR;
parms[4].Value = tempProfitEntity.OTHERDR;
parms[5].Value = tempProfitEntity.RMBCR;
parms[6].Value = tempProfitEntity.USDCR;
parms[7].Value = tempProfitEntity.OTHERCR;
parms[8].Value = tempProfitEntity.DRTTL;
parms[9].Value = tempProfitEntity.CRTTL;
parms[10].Value = tempProfitEntity.RMBProfit;
parms[11].Value = tempProfitEntity.USDProfit;
parms[12].Value = tempProfitEntity.OTHERProfit;
parms[13].Value = tempProfitEntity.TTLProfit;
parms[14].Value = tempProfitEntity.ProfitRate;
parms[15].Value = tempProfitEntity.CreateUser;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_INSERT_FEEPROFIT_BY_FEE, parms);
sqlTran.Commit();
result = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
}
return result;
}
#endregion
#region 根据SQL语句查询费用利润记录
/// <summary>
/// 根据SQL语句查询费用利润记录
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetProfitistByCondition(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
}
}