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.
DS7/DSWeb/EntityDA/FeePaySettleApplicationDA.cs

1440 lines
83 KiB
C#

3 years ago
using System;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
using System.Collections;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class FeePaySettleApplicationDA
{
//ch_fee_payapplication
private const string PARM_SETTLE_APPL_GID = "@gid";
private const string PARM_SETTLE_APPL_BILL_NO = "@bill_no";
private const string PARM_SETTLE_APPL_BILL_STATUS = "@bill_status";
private const string PARM_SETTLE_APPL_CUSTOMER_NAME = "@customer_name";
private const string PARM_SETTLE_APPL_CHEQUE_PAYABLE = "@cheque_payable";
private const string PARM_SETTLE_APPL_SETTLE_TYPE = "@settle_type";
private const string PARM_SETTLE_APPL_PAYABLE_TIME = "@payable_time";
private const string PARM_SETTLE_APPL_AMOUNT_RMB = "@amount_rmb";
private const string PARM_SETTLE_APPL_RATE = "@rate";
private const string PARM_SETTLE_APPL_AMOUNT_USD = "@amount_usd";
private const string PARM_SETTLE_APPL_SETTLE_RMB = "@settle_rmb";
private const string PARM_SETTLE_APPL_SETTLE_USD = "@settle_usd";
private const string PARM_SETTLE_APPL_SETTLE_RATE = "@settle_rate";
private const string PARM_SETTLE_APPL_APPLICANT = "@applicant";
private const string PARM_SETTLE_APPL_APPLY_TIME = "@apply_time";
private const string PARM_SETTLE_APPL_ENTER_TIME = "@enter_time";
private const string PARM_SETTLE_APPL_SETTLE_USER = "@settle_user";
private const string PARM_SETTLE_APPL_SETTLE_TIME = "@setlle_time";
private const string PARM_SETTLE_APPL_REMARK = "@remark";
private const string PARM_SETTLE_APPL_COMPANY_ID = "@company_id";
private const string PARM_SETTLE_APPL_LIKE = "@like";
private const string PARM_SETTLE_APPL_CHEQUENUMREMARK = "@CHEQUENUMREMARK";
//ch_fee
private const string PARM_FEE_GID = "@gid";
private const string PARM_FEE_STATUS = "@fee_status";
private const string PARM_FEE_SETTLEMENT = "@settlement";
private const string PARM_FEE_ORDER_AMOUNT = "@order_amount";
private const string PARM_FEE_ORDER_INVOCE = "@order_invoice";
//ch_fee_do
private const string PARM_FEE_DO_GID = "@gid";
private const string PARM_FEE_DO_BILL_NO = "@bill_no";
private const string PARM_FEE_DO_BSNO = "@bsno";
private const string PARM_FEE_DO_MBL_NO = "@mbl_no";
private const string PARM_FEE_DO_HBL_NO = "@nbl_no";
private const string PARM_FEE_DO_CUSTOMER_NAME = "@customer_name";
private const string PARM_FEE_DO_BSTYPE = "@bs_type";
private const string PARM_FEE_DO_FEE_ID = "@fee_id";
private const string PARM_FEE_DO_FEE_NAME = "@fee_name";
private const string PARM_FEE_DO_CURRENCY = "@currency";
private const string PARM_FEE_DO_AMOUNT = "@amount";
private const string PARM_FEE_DO_DO_AMOUNT = "@do_amount";
private const string PARM_FEE_DO_FEE_TYPE = "@fee_type";
private const string PARM_FEE_DO_CATEGORY = "@category";
private const string PARM_FEE_DO_BILL_STATUS = "@bill_status";
private const string PARM_FEE_DO_REMARK = "@remark";
private const string PARM_FEE_DO_COMPANY_ID = "@company_id";
private const string PARM_FEE_DO_ORIG_AMOUNT = "@orig_amount";
//ch_fee_settlement
private const string PARM_FEE_SETTLEMENT_GID = "@gid";
private const string PARM_FEE_SETTLEMENT_BILL_NO = "@bill_no";
private const string PARM_FEE_SETTLEMENT_BILL_DATE = "@bill_date";
private const string PARM_FEE_SETTLEMENT_SETTLE_MODE = "@settle_mode";
private const string PARM_FEE_SETTLEMENT_CUSTOMER_NAME = "@customer_name";
private const string PARM_FEE_SETTLEMENT_SETTLE_TYPE = "@settle_type";
private const string PARM_FEE_SETTLEMENT_AMOUNT_RMB = "@amount_rmb";
private const string PARM_FEE_SETTLEMENT_ACCOUNT_RMB = "@account_rmb";
private const string PARM_FEE_SETTLEMENT_RATE = "@rate";
private const string PARM_FEE_SETTLEMENT_AMOUNT_USD = "@amount_usd";
private const string PARM_FEE_SETTLEMENT_ACCOUNT_USD = "@account_usd";
private const string PARM_FEE_SETTLEMENT_BILL_TYPE = "@bill_type";
private const string PARM_FEE_SETTLEMENT_VOUCHER_NO = "@voucher_no";
private const string PARM_FEE_SETTLEMENT_SETTLE_USER = "@settle_user";
private const string PARM_FEE_SETTLEMENT_SETTLE_TIME = "@settle_time";
private const string PARM_FEE_SETTLEMENT_AUDIT_USER = "@audit_user";
private const string PARM_FEE_SETTLEMENT_AUDIT_TIME = "@audit_time";
private const string PARM_FEE_SETTLEMENT_IS_EXPORT = "@is_export";
private const string PARM_FEE_SETTLEMENT_FINANCIAL_VOUCHER = "@financial_voucher";
private const string PARM_FEE_SETTLEMENT_BILL_STATUS = "@bill_status";
private const string PARM_FEE_SETTLEMENT_REMARK = "@remark";
private const string PARM_FEE_SETTLEMENT_APPLICANT = "@applicant";
private const string PARM_FEE_SETTLEMENT_COMPANY_ID = "@company_id";
//结算关联表ch_fee_settle_link
private const string PARM_CH_FEE_SETTLE_LINK = "@gid";
private const string PARM_CH_FEE_SETTLE_SETTLE_ID = "@settle_id";
private const string PARM_CH_FEE_SETTLE_TYPE = "@type";
private const string PARM_CH_FEE_SETTLE_RELATION_SUB_ID = "@relation_sub_id";
private const string PARM_CH_FEE_SETTLE_CREATE_USER = "@create_user";
private const string PARM_CH_FEE_SETTLE_CREATE_TIME = "@create_time";
//run_fee_settlement
private const string PARM_RUN_FEE_SETTLEMENT_GID = "@gid";
private const string PARM_RUN_FEE_SETTLEMENT_BILL_NO = "@bill_no";
private const string PARM_RUN_FEE_SETTLEMENT_APPLICANT = "@applicant";
private const string PARM_RUN_FEE_SETTLEMENT_REMARK = "@remark";
private const string PARM_RUN_FEE_SETTLEMENT_PAYAPP_ID = "@paysettleapp_id";
private const string PARM_RUN_FEE_SETTLEMENT_COMPANY_ID = "@company_id";
//run_fee_do
private const string PARM_RUN_FEE_DO_BILL_NO = "@bill_no";
private const string PARM_RUN_FEE_DO_RUN_SETTLE_ID = "@runsettle_id";
//SQL
public const string SQL_SELECT_SETTLE_APPL_BY_GID = " SELECT GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, PAYABLETIME, AMOUNTRMB, RATE, AMOUNTUSD, SETTLERMB, SETTLERATE, "
+ " SETTLEUSD, APPLICANT, APPLYTIME, ENTERTIME, SETTLEUSER, SETTLETIME, AUDITUSER, AUDITTIME, REMARK,ISDELETE,DELETEUSER,DELETETIME,CHEQUENUMREMARK FROM ch_fee_payapplication WHERE GID = @gid";
private const string SQL_INSERT_FEE_DO = " INSERT INTO ch_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,COMPANYID,ORIGAMOUNT,EXCHANGERATE) "
+ " VALUES(@gid,@bill_no,@bsno,@mbl_no,@nbl_no,@customer_name,@bs_type,@fee_id,@fee_name,@currency,@amount,@do_amount,@fee_type,@category,@bill_status,@remark,@company_id,@orig_amount,@EXCHANGERATE) ";
//private string SQL_UPDATE_CH_FEE_ACCEPT_SETTLE = "UPDATE ch_fee SET SETTLEMENT = SETTLEMENT+@settlement,FEESTATUS = @fee_status WHERE GID = @gid ";
//private const string SQL_UPDATE_CH_FEE_ACCEPT_SETTLE = " UPDATE ch_fee SET ch_fee.SETTLEMENT = ch_fee.SETTLEMENT+@settlement,ch_fee.FEESTATUS = C.FEESTATUS,ch_fee.CHEQUENUM = @CHEQUENUM "
// + " FROM "
// + " (SELECT A.GID,CASE WHEN B.AMOUNT < A.AMOUNT THEN CASE WHEN B.AMOUNT+A.SETTLEMENT = A.AMOUNT THEN 9 ELSE 8 END ELSE "
// + " CASE WHEN B.AMOUNT = A.AMOUNT THEN 9 END END as FEESTATUS FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID WHERE B.GID = @gid) as C "
// + " WHERE C.GID = ch_fee.GID ";
private const string SQL_UPDATE_CH_FEF_PAY_APPLICATION = "UPDATE ch_fee_payapplication SET BILLSTATUS = 4 WHERE BILLNO = @bill_no";
private const string SQL_UPDATE_PAY_APPLICATION_STATUS = "UPDATE ch_fee_payapplication SET BILLSTATUS = @bill_status WHERE BILLNO = @bill_no AND COMPANYID = @company_id ";
//建立付费结算关联信息(生成付费结算和付费申请关联关系)
private const string SQL_INSERT_CH_FEE_SETTLE_LINK = " INSERT INTO ch_fee_settle_link(GID,TYPE,SETTLEID,RELATIONSUBID,CREATEUSER,CREATETIME) "
+ " VALUES(newid(),@type,@settle_id,@relation_sub_id,@create_user,GETDATE()) ";
private const string SQL_DELETE_CH_FEE_DO = "DELETE FROM ch_fee_do WHERE BILLNO = @bill_no";
private const string SQL_UPDATE_CH_FEE = "UPDATE ch_fee SET ORDERAMOUNT = ISNULL(ORDERAMOUNT,0) + @order_amount WHERE GID = @gid";
private const string SQL_UPDATE_CH_FEE_FOR_REJECT = "UPDATE ch_fee SET ORDERAMOUNT = ORDERAMOUNT - @order_amount WHERE GID = @gid";
private const string SQL_INSERT_CH_FEE_PAY_APPLICATION_RUN = " INSERT INTO ch_fee_payapplication (GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, "
+ " PAYABLETIME, AMOUNTRMB, RATE, AMOUNTUSD, APPLICANT, APPLYTIME, ENTERTIME,REMARK,COMPANYID,CHEQUENUMREMARK) "
+ " SELECT @paysettleapp_id,@bill_no,3,CUSTOMERNAME,CHEQUENO,SETTLETYPE,PAYABLETIME,AMOUNTRMB,RATE,AMOUNTUSD,@applicant,GETDATE(),"
+ " CREATETIME,REMARK,@company_id,CHEQUENUMREMARK FROM run_fee_settlement WHERE GID = @gid ";
private const string SQL_INSERT_CH_FEE_FEE_DO_RUN = " INSERT INTO ch_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,"
+ " REMARK,CREATETIME,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO) "
+ " SELECT newid(),@bill_no,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,GETDATE(), "
+ " EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO FROM run_fee_do WHERE RUNSETTLEID = @runsettle_id ";
private const string SQL_SELECT_LAST_BILL_NO = " SELECT TOP 1 BILLNO FROM ch_fee_payapplication WHERE BILLNO LIKE @like AND COMPANYID = @company_id ORDER BY BILLNO DESC ";
private const string SQL_SELECT_GET_SERVERTIME = " SELECT GETDATE() ";
private const string SQL_SELECT_CH_FEE_PAY_APPLICATION_BILLNO = " SELECT BILLNO FROM ch_fee_payapplication WHERE GID = @gid ";
private const string SQL_UPDATE_CH_FEE_BY_RUN_FEE_DO = " UPDATE ch_fee SET ch_fee.ORDERAMOUNT = ISNULL(ch_fee.ORDERAMOUNT,0) + ch_fee_do.ORIGAMOUNT "
+ " FROM ch_fee_do WHERE ch_fee.GID = ch_fee_do.FEEID AND ch_fee_do.BILLNO = @bill_no ";
private const string SQL_DELETE_RUN_FEE_SETTLEMENT_BY_GID = " DELETE FROM run_fee_settlement WHERE GID = @gid ";
private const string SQL_DELETE_RUN_FEE_DO_BY_RUNSETTLE_ID = " DELETE FROM run_fee_do WHERE RUNSETTLEID = @runsettle_id ";
//private const string SQL_SELECT_RUN_FEE_DO_VALID_SAME_FEE = " SELECT * FROM run_fee_do ";
private const string SQL_VALID_EXIST_RUN_FEE_DO = "";
//校验是否ch_fee 具有足够的申请金额
private const string SQL_VALID_CH_FEE_ORDERAMOUNT = " SELECT COUNT(A.GID)-SUM(CASE WHEN C.AMOUNT = C.ORDERAMOUNT THEN -1 ELSE CASE WHEN (C.AMOUNT - C.ORDERAMOUNT) < A.ORIGAMOUNT THEN -1 ELSE "
+ " CASE WHEN (C.AMOUNT - C.ORDERAMOUNT) >= A.ORIGAMOUNT THEN 1 END END END) FROM ch_fee_do as A INNER JOIN ch_fee_payapplication as B "
+ " ON A.BILLNO = B.BILLNO INNER JOIN ch_fee as C ON A.FEEID = C.GID WHERE B.GID = @gid AND B.BILLSTATUS = 6 AND A.ISDELETED = 1 ";
private const string SQL_UPDATE_CH_FEE_PAYAPPLICATION_FOR_REPOST = " UPDATE ch_fee_payapplication SET BILLSTATUS = 3,APPLYTIME = GETDATE() WHERE GID = @gid ";
private const string SQL_UPDATE_CH_FEE_DO_FOR_REPOST = " UPDATE ch_fee_do SET ISDELETED = 0 WHERE BILLNO = (SELECT DISTINCT BILLNO FROM ch_fee_payapplication WHERE GID = @gid) ";
private const string SQL_VALID_CH_FEE_ORDERAMOUNT_BY_RUNFEEDO = " SELECT COUNT(A.GID)-SUM(CASE WHEN C.AMOUNT = C.ORDERAMOUNT THEN -1 ELSE CASE WHEN (C.AMOUNT - C.ORDERAMOUNT) < A.ORIGAMOUNT THEN -1 ELSE "
+ " CASE WHEN (C.AMOUNT - C.ORDERAMOUNT) >= A.ORIGAMOUNT THEN 1 END END END) FROM run_fee_do as A INNER JOIN run_fee_settlement as B "
+ " ON A.RUNSETTLEID = B.GID INNER JOIN ch_fee as C ON A.FEEID = C.GID WHERE B.GID = @gid ";
private const string SQL_UPDATE_CH_FEE_ORDER_AMOUNT_FOR_REPOST = " UPDATE ch_fee SET ch_fee.ORDERAMOUNT = ch_fee.ORDERAMOUNT + ch_fee_do.ORIGAMOUNT "
+ " FROM ch_fee_do WHERE ch_fee.GID = ch_fee_do.FEEID AND ch_fee_do.BILLNO = (SELECT DISTINCT BILLNO FROM ch_fee_payapplication WHERE GID = @gid) ";
private const string SQL_DELETE_CH_FEE_DO_UNCOVER = " DELETE FROM ch_fee_do WHERE BILLNO = (SELECT DISTINCT BILLNO FROM ch_fee_payapplication WHERE GID = @gid)";
private const string SQL_DELETE_CH_FEE_PAYAPPLICATION_UNRECOVER = " DELETE FROM ch_fee_payapplication WHERE GID = @gid ";
#region 获取付费结算申请信息
/// <summary>
/// 获取付费结算申请信息
/// </summary>
/// <param name="tempPayApplicationGID">付费结算申请GID</param>
/// <returns></returns>
public FeePayApplicationEntity GetFeePayApplicationByGID(string tempPayApplicationGID)
{
//初始化返回变量
FeePayApplicationEntity feePayApplicationEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_SETTLE_APPL_GID, SqlDbType.VarChar, 36);
parm.Value = tempPayApplicationGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SETTLE_APPL_BY_GID, parm))
{
try
{
feePayApplicationEntity = new FeePayApplicationEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
feePayApplicationEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
feePayApplicationEntity.BillNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
feePayApplicationEntity.BillStatus = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
feePayApplicationEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
feePayApplicationEntity.ChequePayable = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
feePayApplicationEntity.SettleType = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
feePayApplicationEntity.PayableTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
feePayApplicationEntity.AmountRMB = sqlRead.GetDecimal(7);
}
if (!sqlRead.IsDBNull(8))
{
feePayApplicationEntity.Rate = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
feePayApplicationEntity.AmountUSD = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
feePayApplicationEntity.SettleRMB = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
feePayApplicationEntity.SettleRate = sqlRead.GetDecimal(11);
}
if (!sqlRead.IsDBNull(12))
{
feePayApplicationEntity.SettleUSD = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
feePayApplicationEntity.Applicant = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
feePayApplicationEntity.ApplyTime = sqlRead.GetDateTime(14);
}
if (!sqlRead.IsDBNull(15))
{
feePayApplicationEntity.EnterTime = sqlRead.GetDateTime(15);
}
if (!sqlRead.IsDBNull(16))
{
feePayApplicationEntity.SettleUser = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
feePayApplicationEntity.SettleTime = sqlRead.GetDateTime(17);
}
if (!sqlRead.IsDBNull(18))
{
feePayApplicationEntity.AuditUser = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
feePayApplicationEntity.AuditTime = sqlRead.GetDateTime(19);
}
if (!sqlRead.IsDBNull(20))
{
feePayApplicationEntity.Remark = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
feePayApplicationEntity.IsDelete = sqlRead.GetBoolean(21);
}
if (!sqlRead.IsDBNull(22))
{
feePayApplicationEntity.DeleteUser = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
feePayApplicationEntity.DeleteTime = sqlRead.GetDateTime(23);
}
if (!sqlRead.IsDBNull(24)) { feePayApplicationEntity.CHEQUENUMREMARK = sqlRead.GetString(24); }//支票号备注
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return feePayApplicationEntity;
}
#endregion
#region 获取付费结算申请信息
/// <summary>
/// 通过申请业务编号BILLNO获取付费结算申请信息
/// </summary>
/// <param name="tempPayApplicationGID">付费结算申请GID</param>
/// <returns></returns>
public FeePayApplicationEntity GetFeePayApplicationByBillNO(string tempBillNO,string tempCompanyID)
{
//初始化返回变量
FeePayApplicationEntity feePayApplicationEntity = null;
//初始化参数并赋值
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36)
};
parms[0].Value = tempBillNO;
parms[1].Value = tempCompanyID;
//string SQL_SELECT_SETTLE_APPL_BY_BILLNO = " SELECT GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, PAYABLETIME, AMOUNTRMB, RATE, AMOUNTUSD, isnull(SETTLERMB,0) as SETTLERMB, isnull(SETTLERATE,0) as SETTLERATE, SETTLEUSD, APPLICANT, APPLYTIME, ENTERTIME, SETTLEUSER, SETTLETIME, AUDITUSER, AUDITTIME, REMARK, ISDELETE, DELETEUSER, DELETETIME, CHEQUENUMREMARK, CURRENCY=(select top 1 CURRENCY from ch_fee_do where billno=ch_fee_payapplication.billno) "
//+ " FROM ch_fee_payapplication WHERE BILLNO = @bill_no AND COMPANYID = @company_id";
//2014-08-19 XJ
string SQL_SELECT_SETTLE_APPL_BY_BILLNO = " SELECT GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, PAYABLETIME, AMOUNTRMB, RATE, AMOUNTUSD, isnull(SETTLERMB,0) as SETTLERMB, isnull(SETTLERATE,0) as SETTLERATE, SETTLEUSD, APPLICANT, APPLYTIME, ENTERTIME, SETTLEUSER, SETTLETIME, AUDITUSER, AUDITTIME, REMARK, ISDELETE, DELETEUSER, DELETETIME, CHEQUENUMREMARK, CURRENCY=(case when isnull(AMOUNTUSD,0)=0 then 'RMB' else 'USD' end)"
+ " FROM ch_fee_payapplication WHERE BILLNO = @bill_no AND COMPANYID = @company_id";
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SETTLE_APPL_BY_BILLNO, parms))
{
try
{
feePayApplicationEntity = new FeePayApplicationEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
feePayApplicationEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
feePayApplicationEntity.BillNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
feePayApplicationEntity.BillStatus = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
feePayApplicationEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
feePayApplicationEntity.ChequePayable = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
feePayApplicationEntity.SettleType = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
feePayApplicationEntity.PayableTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
feePayApplicationEntity.AmountRMB = sqlRead.GetDecimal(7);
}
if (!sqlRead.IsDBNull(8))
{
feePayApplicationEntity.Rate = sqlRead.GetDecimal(8);
}
if (!sqlRead.IsDBNull(9))
{
feePayApplicationEntity.AmountUSD = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
feePayApplicationEntity.SettleRMB = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
feePayApplicationEntity.SettleRate = sqlRead.GetDecimal(11);
}
if (!sqlRead.IsDBNull(12))
{
feePayApplicationEntity.SettleUSD = sqlRead.GetDecimal(12);
}
if (!sqlRead.IsDBNull(13))
{
feePayApplicationEntity.Applicant = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
feePayApplicationEntity.ApplyTime = sqlRead.GetDateTime(14);
}
if (!sqlRead.IsDBNull(15))
{
feePayApplicationEntity.EnterTime = sqlRead.GetDateTime(15);
}
if (!sqlRead.IsDBNull(16))
{
feePayApplicationEntity.SettleUser = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
feePayApplicationEntity.SettleTime = sqlRead.GetDateTime(17);
}
if (!sqlRead.IsDBNull(18))
{
feePayApplicationEntity.AuditUser = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
feePayApplicationEntity.AuditTime = sqlRead.GetDateTime(19);
}
if (!sqlRead.IsDBNull(20))
{
feePayApplicationEntity.Remark = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
feePayApplicationEntity.IsDelete = sqlRead.GetBoolean(21);
}
if (!sqlRead.IsDBNull(22))
{
feePayApplicationEntity.DeleteUser = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
feePayApplicationEntity.DeleteTime = sqlRead.GetDateTime(23);
}
if (!sqlRead.IsDBNull(24)) { feePayApplicationEntity.CHEQUENUMREMARK = sqlRead.GetString(24); }//支票号备注
if (!sqlRead.IsDBNull(25)) { feePayApplicationEntity.CURRENCY = sqlRead.GetString(25); }//币别
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return feePayApplicationEntity;
}
#endregion
#region 通过SQL语句获取数据
/// <summary>
/// 通过SQL语句获取数据
/// </summary>
/// <param name="strSql">要执行查询的SQL语句</param>
/// <returns>返回DataSet数据</returns>
public DataSet GetDataSetBySql(string strSql)
{
DataSet dataSet = new DataSet();
dataSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return dataSet;
}
#endregion
#region 插入付费结算申请
/// <summary>
/// 插入付费结算申请
/// </summary>
/// <param name="tempFeePayApplicationEntity">付费结算申请实体类</param>
/// <returns>值1-插入完成 值-1插入失败</returns>
public int InsertFeePayApplication(IList<FeeDoEntity> tempFeeDoEntities,FeePayApplicationEntity tempFeePayApplicationEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strLastBillNo = "";
string strNewBillNo = "";
//先获取SQL SERVER 数据库端服务器时间
DateTime nowServerDateTime = (DateTime)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_GET_SERVERTIME, null);
if (nowServerDateTime == DateTime.MinValue)
{
throw new Exception("未正常获取到服务端时间");
}
//获取分公司的票号头字符
string tempBANKSHEAD = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + tempFeePayApplicationEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"AC", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempFeePayApplicationEntity.CompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD + "AC", 4, strLastBillNo);
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
SqlParameter[] doParms = new SqlParameter[]{
new SqlParameter(PARM_FEE_DO_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_BILL_NO, SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSNO, SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_MBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_HBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSTYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_FEE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_CATEGORY,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_ORIG_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter("@EXCHANGERATE",SqlDbType.Decimal)
};
doParms[0].Value = feeDoEntity.GID;
doParms[1].Value = strNewBillNo;
doParms[2].Value = feeDoEntity.BSNO;
doParms[3].Value = feeDoEntity.MBLNO;
doParms[4].Value = feeDoEntity.HBLNO;
doParms[5].Value = feeDoEntity.CustomerName;
doParms[6].Value = feeDoEntity.BSType;
doParms[7].Value = feeDoEntity.FeeID;
doParms[8].Value = feeDoEntity.FeeName;
doParms[9].Value = feeDoEntity.Currency;
doParms[10].Value = feeDoEntity.OriginalFeeCSTL;
doParms[11].Value = feeDoEntity.DoAmount;
doParms[12].Value = feeDoEntity.FeeType;
doParms[13].Value = feeDoEntity.Category;
doParms[14].Value = feeDoEntity.BillStatus;
doParms[15].Value = feeDoEntity.Remark;
doParms[16].Value = feeDoEntity.CompanyID;
doParms[17].Value = feeDoEntity.OriginalFeeCSTL;
doParms[18].Value = feeDoEntity.ExchangeRate;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
//
SqlParameter[] updateFeeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_ORDER_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36)
};
updateFeeParms[0].Value = feeDoEntity.OriginalFeeCSTL;
updateFeeParms[1].Value = feeDoEntity.FeeID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE, updateFeeParms);
}
if (tempFeePayApplicationEntity.PayableTime != System.DateTime.MinValue)
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_SETTLE_APPL_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_SETTLE_APPL_CHEQUE_PAYABLE,SqlDbType.VarChar,60),
new SqlParameter(PARM_SETTLE_APPL_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_PAYABLE_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_SETTLE_APPL_AMOUNT_RMB,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_AMOUNT_USD,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_SETTLE_APPL_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_CHEQUENUMREMARK,SqlDbType.VarChar,100)//支票号备注
};
parms[0].Value = tempFeePayApplicationEntity.GID;
parms[1].Value = strNewBillNo;
parms[2].Value = tempFeePayApplicationEntity.BillStatus;
parms[3].Value = tempFeePayApplicationEntity.CustomerName;
parms[4].Value = tempFeePayApplicationEntity.ChequePayable;
parms[5].Value = tempFeePayApplicationEntity.SettleType;
parms[6].Value = tempFeePayApplicationEntity.PayableTime;
parms[7].Value = tempFeePayApplicationEntity.AmountRMB;
parms[8].Value = tempFeePayApplicationEntity.Rate;
parms[9].Value = tempFeePayApplicationEntity.AmountUSD;
parms[10].Value = tempFeePayApplicationEntity.Applicant;
parms[11].Value = tempFeePayApplicationEntity.ApplyTime;
parms[12].Value = tempFeePayApplicationEntity.Remark;
parms[13].Value = tempFeePayApplicationEntity.CompanyID;
parms[14].Value = tempFeePayApplicationEntity.CHEQUENUMREMARK;
string SQL_INSERT_SETTLE_APPL = " INSERT INTO ch_fee_payapplication (GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, PAYABLETIME, AMOUNTRMB, RATE, AMOUNTUSD, APPLICANT, APPLYTIME, ENTERTIME,REMARK,COMPANYID,CHEQUENUMREMARK)"
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@cheque_payable,@settle_type,@payable_time,@amount_rmb,@rate,@amount_usd,@applicant,@apply_time,GETDATE(),@remark,@company_id,@CHEQUENUMREMARK)";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_SETTLE_APPL, parms);
}
else
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_SETTLE_APPL_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_SETTLE_APPL_CHEQUE_PAYABLE,SqlDbType.VarChar,60),
new SqlParameter(PARM_SETTLE_APPL_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_AMOUNT_RMB,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_AMOUNT_USD,SqlDbType.Decimal,20),
new SqlParameter(PARM_SETTLE_APPL_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_SETTLE_APPL_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_SETTLE_APPL_CHEQUENUMREMARK,SqlDbType.VarChar,100)//支票号备注
};
parms[0].Value = tempFeePayApplicationEntity.GID;
parms[1].Value = strNewBillNo;
parms[2].Value = tempFeePayApplicationEntity.BillStatus;
parms[3].Value = tempFeePayApplicationEntity.CustomerName;
parms[4].Value = tempFeePayApplicationEntity.ChequePayable;
parms[5].Value = tempFeePayApplicationEntity.SettleType;
parms[6].Value = tempFeePayApplicationEntity.AmountRMB;
parms[7].Value = tempFeePayApplicationEntity.Rate;
parms[8].Value = tempFeePayApplicationEntity.AmountUSD;
parms[9].Value = tempFeePayApplicationEntity.Applicant;
parms[10].Value = tempFeePayApplicationEntity.ApplyTime;
parms[11].Value = tempFeePayApplicationEntity.Remark;
parms[12].Value = tempFeePayApplicationEntity.CompanyID;
parms[13].Value = tempFeePayApplicationEntity.CHEQUENUMREMARK;
string SQL_INSERT_SETTLE_APPL_NO_PAYABLETIME = " INSERT INTO ch_fee_payapplication (GID, BILLNO, BILLSTATUS, CUSTOMERNAME, CHEQUEPAYABLE, SETTLETYPE, AMOUNTRMB, RATE, AMOUNTUSD, APPLICANT, APPLYTIME, ENTERTIME,REMARK,COMPANYID,CHEQUENUMREMARK)"
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@cheque_payable,@settle_type,@amount_rmb,@rate,@amount_usd,@applicant,@apply_time,GETDATE(),@remark,@company_id,@CHEQUENUMREMARK)";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_SETTLE_APPL_NO_PAYABLETIME, parms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 更新付费申请状态信息
/// <summary>
/// 更新付费申请状态信息
/// </summary>
/// <param name="tempBillNO">申请业务编号</param>
/// <param name="tempStatus">状态值</param>
/// <param name="tempCompanyID">分公司GID</param>
/// <returns>值1表示更新成功 值-1表示更新失败</returns>
public int UpdatePayApplicationStatus(string tempBillNO,int tempStatus,string tempCompanyID)
{
int iResult = 0;
//获取参数
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_BILL_NO, SqlDbType.VarChar, 20),
new SqlParameter(PARM_SETTLE_APPL_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36)
};
parms[0].Value = tempBillNO;
parms[1].Value = tempStatus;
parms[2].Value = tempCompanyID;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_PAY_APPLICATION_STATUS, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
public int SettleFeePayApplication(FeeSettlementEntity tempSettlementEntity, FeePayApplicationEntity tempFeePayApplicationEntity, IList<FeeDoEntity> tempFeeDoEntities, string tempCompanyID, string strUserID, IList<FeeEntity> tempFeeEntities, ArrayList alFeeDo)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//插入结算信息
SqlParameter[] settleParms = new SqlParameter[]{
new SqlParameter(PARM_FEE_SETTLEMENT_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_SETTLEMENT_BILL_NO, SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_SETTLEMENT_SETTLE_MODE, SqlDbType.Int),
new SqlParameter(PARM_FEE_SETTLEMENT_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_SETTLEMENT_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_SETTLEMENT_AMOUNT_RMB,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_SETTLEMENT_ACCOUNT_RMB,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_SETTLEMENT_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_SETTLEMENT_AMOUNT_USD,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_SETTLEMENT_ACCOUNT_USD,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_SETTLEMENT_BILL_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_SETTLEMENT_VOUCHER_NO,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_SETTLEMENT_SETTLE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_SETTLEMENT_IS_EXPORT,SqlDbType.Bit),
new SqlParameter(PARM_FEE_SETTLEMENT_FINANCIAL_VOUCHER,SqlDbType.VarChar,50),
new SqlParameter(PARM_FEE_SETTLEMENT_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_SETTLEMENT_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_FEE_SETTLEMENT_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter("@AUDITUSER",SqlDbType.VarChar,36),
new SqlParameter("@ACCOUNTS_CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@ACCOUNTS_RATE", SqlDbType.Decimal,9) ,
new SqlParameter("@ACCOUNTS_MONEY", SqlDbType.Decimal,9) ,
new SqlParameter("@PREPAY_CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@PREPAY_RATE", SqlDbType.Decimal,9) ,
new SqlParameter("@PREPAY_MONEY", SqlDbType.Decimal,9) ,
new SqlParameter("@AHSR_CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@AHSR_RATE", SqlDbType.Decimal,9) ,
new SqlParameter("@AHSR_MONEY", SqlDbType.Decimal,9) ,
new SqlParameter("@FINANCIAL_CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@FINANCIAL_RATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FINANCIAL_MONEY", SqlDbType.Decimal,9) ,
new SqlParameter("@ADVANCE_CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@ADVANCE_RATE", SqlDbType.Decimal,9) ,
new SqlParameter("@ADVANCE_MONEY", SqlDbType.Decimal,9)
};
settleParms[0].Value = tempSettlementEntity.GID;
settleParms[1].Value = tempSettlementEntity.BillNO;
settleParms[2].Value = tempSettlementEntity.SettleMode;
settleParms[3].Value = tempSettlementEntity.CustomerName;
settleParms[4].Value = tempSettlementEntity.SettleType;
settleParms[5].Value = tempSettlementEntity.AmountRMB;
settleParms[6].Value = tempSettlementEntity.AccountRMB;
settleParms[7].Value = tempSettlementEntity.Rate;
settleParms[8].Value = tempSettlementEntity.AmountUSD;
settleParms[9].Value = tempSettlementEntity.AccountUSD;
settleParms[10].Value = tempSettlementEntity.BillType;
settleParms[11].Value = tempSettlementEntity.VoucherNO;
settleParms[12].Value = tempSettlementEntity.SettleUser;
settleParms[13].Value = tempSettlementEntity.IsExport;
settleParms[14].Value = tempSettlementEntity.FinancialVoucher;
settleParms[15].Value = tempSettlementEntity.BillStatus;
settleParms[16].Value = tempSettlementEntity.Remark;
settleParms[17].Value = tempSettlementEntity.CompanyID;
settleParms[18].Value = tempSettlementEntity.AuditUser;
settleParms[19].Value = tempSettlementEntity.ACCOUNTS_CURRENCY;
settleParms[20].Value = tempSettlementEntity.ACCOUNTS_RATE;
settleParms[21].Value = tempSettlementEntity.ACCOUNTS_MONEY;
settleParms[22].Value = tempSettlementEntity.PREPAY_CURRENCY;
settleParms[23].Value = tempSettlementEntity.PREPAY_RATE;
settleParms[24].Value = tempSettlementEntity.PREPAY_MONEY;
settleParms[25].Value = tempSettlementEntity.AHSR_CURRENCY;
settleParms[26].Value = tempSettlementEntity.AHSR_RATE;
settleParms[27].Value = tempSettlementEntity.AHSR_MONEY;
settleParms[28].Value = tempSettlementEntity.FINANCIAL_CURRENCY;
settleParms[29].Value = tempSettlementEntity.FINANCIAL_RATE;
settleParms[30].Value = tempSettlementEntity.FINANCIAL_MONEY;
settleParms[31].Value = tempSettlementEntity.ADVANCE_CURRENCY;
settleParms[32].Value = tempSettlementEntity.ADVANCE_RATE;
settleParms[33].Value = tempSettlementEntity.ADVANCE_MONEY;
//
string SETTLETIME = tempSettlementEntity.SettleTime.ToString().Trim().IndexOf("0001") > -1 ? "GETDATE()," : "'" + tempSettlementEntity.SettleTime.ToString().Trim() + "',";
string SETTLETIME_NAME = tempSettlementEntity.SettleTime.ToString().Trim().IndexOf("0001") > -1 ? "SETTLETIME," : "SETTLETIME,";
string SQL_INSERT_CH_FEE_SETTLEMENT = String.Format("INSERT INTO ch_fee_settlement(GID, BILLNO, BILLDATE, SETTLEMODE, CUSTOMERNAME, SETTLETYPE, AMOUNTRMB, ACCOUNTRMB, RATE, AMOUNTUSD, ACCOUNTUSD,BILLTYPE, VOUCHERNO, SETTLEUSER, {0} ISEXPORT, FINANCIALVOUCHER, BILLSTATUS, REMARK,COMPANYID,AUDITUSER,AUDITTIME,ACCOUNTS_CURRENCY,ACCOUNTS_RATE,ACCOUNTS_MONEY,PREPAY_CURRENCY,PREPAY_RATE,PREPAY_MONEY,AHSR_CURRENCY,AHSR_RATE,AHSR_MONEY,FINANCIAL_CURRENCY,FINANCIAL_RATE,FINANCIAL_MONEY,ADVANCE_CURRENCY,ADVANCE_RATE,ADVANCE_MONEY)"
+ " VALUES(@gid,@bill_no,GETDATE(),@settle_mode,@customer_name,@settle_type,@amount_rmb,@account_rmb,@rate,@amount_usd,@account_usd,@bill_type,@voucher_no,@settle_user,{1}@is_export,@financial_voucher,@bill_status,@remark,@company_id,@AUDITUSER,getdate(),@ACCOUNTS_CURRENCY,@ACCOUNTS_RATE,@ACCOUNTS_MONEY,@PREPAY_CURRENCY,@PREPAY_RATE,@PREPAY_MONEY,@AHSR_CURRENCY,@AHSR_RATE,@AHSR_MONEY,@FINANCIAL_CURRENCY,@FINANCIAL_RATE,@FINANCIAL_MONEY,@ADVANCE_CURRENCY,@ADVANCE_RATE,@ADVANCE_MONEY)", SETTLETIME_NAME, SETTLETIME);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE_SETTLEMENT, settleParms);
//插入一条新的记录到ch_fee_do表
SqlParameter[] doParms = new SqlParameter[]{
new SqlParameter(PARM_FEE_DO_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_BILL_NO, SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSNO, SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_MBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_HBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSTYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_FEE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_CATEGORY,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_ORIG_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter("@EXCHANGERATE",SqlDbType.Decimal)
};
//遍历ch_fee_do与ch_fee表,将ch_fee表AMOUNT和SETTLEMENT字段与ch_fee_do表DOAMOUNT做对比,如果
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
feeDoEntity.GID = Guid.NewGuid().ToString();
doParms[0].Value = feeDoEntity.GID;
doParms[1].Value = tempSettlementEntity.BillNO;//插入新的业务编号
doParms[2].Value = feeDoEntity.BSNO;
doParms[3].Value = feeDoEntity.MBLNO;
doParms[4].Value = feeDoEntity.HBLNO;
doParms[5].Value = feeDoEntity.CustomerName;
doParms[6].Value = feeDoEntity.BSType;
doParms[7].Value = feeDoEntity.FeeID;
doParms[8].Value = feeDoEntity.FeeName;
doParms[9].Value = feeDoEntity.Currency;
doParms[10].Value = feeDoEntity.Amount;
doParms[11].Value = feeDoEntity.DoAmount;
doParms[12].Value = feeDoEntity.FeeType;
doParms[13].Value = 1;
doParms[14].Value = feeDoEntity.BillStatus;
doParms[15].Value = feeDoEntity.Remark;
doParms[16].Value = feeDoEntity.CompanyID == null ? "" : feeDoEntity.CompanyID;
doParms[17].Value = feeDoEntity.OriginalFeeCSTL == 0 ? 0 : feeDoEntity.OriginalFeeCSTL;
doParms[18].Value = feeDoEntity.ExchangeRate == 0 ? 1 : feeDoEntity.ExchangeRate;
//string SQL_INSERT_FEE_DO = " INSERT INTO ch_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,COMPANYID,ORIGAMOUNT,EXCHANGERATE) "
// + " VALUES(@gid,@bill_no,@bsno,@mbl_no,@nbl_no,@customer_name,@bs_type,@fee_id,@fee_name,@currency,@amount,@do_amount,@fee_type,@category,@bill_status,@remark,@company_id,@orig_amount,@EXCHANGERATE) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
//先更新ch_fee费用信息
SqlParameter[] feeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_SETTLEMENT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_DO_GID,SqlDbType.VarChar,36),
new SqlParameter("@CHEQUENUM",SqlDbType.VarChar,200)
};
feeParms[0].Value = feeDoEntity.DoAmount;//.Amount;
feeParms[1].Value = feeDoEntity.GID;
if (feeDoEntity.Currency.ToString().Trim() == "RMB")
{
feeParms[2].Value = tempSettlementEntity.ChequeNo;
}
else
{
feeParms[2].Value = tempSettlementEntity.ChequeNoUsd;
}
string SQL_UPDATE_CH_FEE_ACCEPT_SETTLE = " UPDATE ch_fee SET ch_fee.SETTLEMENT = ch_fee.SETTLEMENT+@settlement,ch_fee.FEESTATUS = C.FEESTATUS,ch_fee.CHEQUENUM = @CHEQUENUM "
+ " FROM "
+ " (SELECT A.GID,CASE WHEN B.DOAMOUNT < A.AMOUNT THEN CASE WHEN B.DOAMOUNT+A.SETTLEMENT = A.AMOUNT THEN 9 ELSE 8 END ELSE "
+ " CASE WHEN B.DOAMOUNT = A.AMOUNT THEN 9 END END as FEESTATUS FROM ch_fee as A INNER JOIN ch_fee_do as B ON A.GID = B.FEEID WHERE B.GID = @gid) as C "
+ " WHERE C.GID = ch_fee.GID ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_ACCEPT_SETTLE, feeParms);
}
//ch_fee 插入 汇率损益
if (tempFeeEntities != null)
{
foreach (FeeEntity feeEntity in tempFeeEntities)
{
SqlParameter[] feeParms2 = new SqlParameter[] {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,50) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@QUANTITY", SqlDbType.Decimal,9) ,
new SqlParameter("@COMMISSIONRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@AMOUNT", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@EXCHANGERATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FEEFRT", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@ISADVANCEDPAY", SqlDbType.Bit,1) ,
new SqlParameter("@FEETYPE", SqlDbType.Int,4) ,
new SqlParameter("@BSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@ENTEROPERATOR", SqlDbType.VarChar,50) ,
new SqlParameter("@FEESTATUS", SqlDbType.Int,4) ,
new SqlParameter("@WMSOUTBSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@LINENUM", SqlDbType.Int,4) ,
new SqlParameter("@SETTLEMENT", SqlDbType.Decimal,9)
};
feeParms2[0].Value = feeEntity.GID;
feeParms2[1].Value = feeEntity.FeeName;
feeParms2[2].Value = feeEntity.CustomerName;
feeParms2[3].Value = feeEntity.Unit;
feeParms2[4].Value = feeEntity.UnitPrice;
feeParms2[5].Value = feeEntity.Quantity;
feeParms2[6].Value = feeEntity.CommissionRate;
feeParms2[7].Value = feeEntity.Amount;
feeParms2[8].Value = feeEntity.Currency;
feeParms2[9].Value = feeEntity.ExchangeRate;
feeParms2[10].Value = feeEntity.FeeFrt;
feeParms2[11].Value = feeEntity.Remark;
feeParms2[12].Value = feeEntity.IsAdvancePay;
feeParms2[13].Value = feeEntity.FeeType;
feeParms2[14].Value = feeEntity.BSNO;
feeParms2[15].Value = feeEntity.EnterOperator;
feeParms2[16].Value = feeEntity.FeeStatus;
feeParms2[17].Value = feeEntity.WMSOUTBSNO;
feeParms2[18].Value = feeEntity.LINENUM;
feeParms2[19].Value = feeEntity.Settlement;
string SQL_INSERT_CH_FEE = " INSERT INTO ch_fee(GID,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,COMMISSIONRATE,AMOUNT,CURRENCY,EXCHANGERATE,FEEFRT,REMARK,ISADVANCEDPAY,FEETYPE,BSNO,ENTEROPERATOR,FEESTATUS,WMSOUTBSNO,LINENUM,SETTLEMENT,ENTERDATE) "
+ " VALUES (@GID,@FEENAME,@CUSTOMERNAME,@UNIT,@UNITPRICE,@QUANTITY,@COMMISSIONRATE,@AMOUNT,@CURRENCY,@EXCHANGERATE,@FEEFRT,@REMARK,@ISADVANCEDPAY,@FEETYPE,@BSNO,@ENTEROPERATOR,@FEESTATUS,@WMSOUTBSNO,@LINENUM,@SETTLEMENT,getdate()) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, feeParms2);
}
}
//遍历ch_fee_do
if (alFeeDo != null)
{
for (int i = 0; i < alFeeDo.Count;i++)
{
string sSQL = alFeeDo[i].ToString();
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
}
//更新申请表
SqlParameter[] appParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_SETTLE_APPL_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter("@SETTLERMB",SqlDbType.Decimal),
new SqlParameter("@SETTLEUSD",SqlDbType.Decimal),
new SqlParameter("@SETTLERATE",SqlDbType.Decimal),
new SqlParameter("@SETTLEUSER",SqlDbType.VarChar,36)
};
appParms[0].Value = tempFeePayApplicationEntity.BillStatus;
appParms[1].Value = tempFeePayApplicationEntity.BillNO;
appParms[2].Value = tempCompanyID;
appParms[3].Value = tempFeePayApplicationEntity.SettleRMB;
appParms[4].Value = tempFeePayApplicationEntity.SettleUSD;
appParms[5].Value = tempFeePayApplicationEntity.SettleRate;
appParms[6].Value = tempFeePayApplicationEntity.SettleUser;
string SETTLETIME_1 = tempSettlementEntity.SettleTime.ToString().Trim().IndexOf("0001") > -1 ? "SETTLETIME=GETDATE()," : "SETTLETIME='" + tempSettlementEntity.SettleTime.ToString().Trim() + "',";
string SQL_UPDATE_PAY_APPLICATION_STATUS_SETTLER = String.Format("UPDATE ch_fee_payapplication SET BILLSTATUS = @bill_status,SETTLERMB=@SETTLERMB,SETTLEUSD=@SETTLEUSD,SETTLERATE=@SETTLERATE,{0}SETTLEUSER=@SETTLEUSER WHERE BILLNO = @bill_no AND COMPANYID = @company_id ", SETTLETIME_1);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_PAY_APPLICATION_STATUS_SETTLER, appParms);//SQL_UPDATE_PAY_APPLICATION_STATUS
//插入 费用结算关联表ch_fee_settle_link
SqlParameter[] insertSettleLinkParms = new SqlParameter[] {
new SqlParameter(PARM_CH_FEE_SETTLE_SETTLE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CH_FEE_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_CH_FEE_SETTLE_RELATION_SUB_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CH_FEE_SETTLE_CREATE_USER,SqlDbType.VarChar,36),
};
insertSettleLinkParms[0].Value = tempSettlementEntity.GID;
insertSettleLinkParms[1].Value = 1;
insertSettleLinkParms[2].Value = tempFeePayApplicationEntity.GID;
insertSettleLinkParms[3].Value = strUserID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE_SETTLE_LINK, insertSettleLinkParms);
//SqlParameter feeDoParm = new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20);
//feeDoParm.Value = tempFeePayApplicationEntity.BillNO;
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_CH_FEE_DO, feeDoParm);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
public int alDo(ArrayList alFeeDo)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//遍历
if (alFeeDo != null)
{
for (int i = 0; i < alFeeDo.Count; i++)
{
string sSQL = alFeeDo[i].ToString();
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#region 将已保存的付费申请提交到付费申请
/// <summary>
/// 将已保存的付费申请提交到付费申请
/// </summary>
/// <param name="tempPaySettleAppID">付费申请GID</param>
/// <param name="tempRunSettleID">运行结算GID</param>
/// <param name="tempOperator">操作人GID</param>
/// <param name="tempRemark">备注</param>
/// <returns>值1表示提交成功 值不等于1表示提交失败</returns>
public int PostSavedPaySettleRequest(string tempPaySettleAppID,string tempRunSettleID,string tempOperator,string tempRemark,string tempCompanyID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strLastBillNo = "";
string strNewBillNo = "";
//先校验费用申请金额是否满足申请要求
int validState = 0;
//先校验是否费用已经做了申请
SqlParameter[] validFeeParms = new SqlParameter[]{
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_GID,SqlDbType.VarChar,36)
};
validFeeParms[0].Value = tempRunSettleID;
validState = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_VALID_CH_FEE_ORDERAMOUNT_BY_RUNFEEDO, validFeeParms);
if (validState == 0)
{
//先获取SQL SERVER 数据库端服务器时间
DateTime nowServerDateTime = (DateTime)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_GET_SERVERTIME, null);
if (nowServerDateTime == DateTime.MinValue)
{
throw new Exception("未正常获取到服务端时间");
}
//获取分公司的票号头字符
string tempBANKSHEAD = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + tempCompanyID.Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"AC", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_SETTLE_APPL_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempCompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD+"AC", 4, strLastBillNo);
SqlParameter[] insertSettleParms = new SqlParameter[]{
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_PAYAPP_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_APPLICANT,SqlDbType.VarChar,36),
//new SqlParameter(PARM_RUN_FEE_SETTLEMENT_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_COMPANY_ID,SqlDbType.VarChar,36)
};
insertSettleParms[0].Value = tempPaySettleAppID;
insertSettleParms[1].Value = tempRunSettleID;
insertSettleParms[2].Value = strNewBillNo;
insertSettleParms[3].Value = tempOperator;
//insertSettleParms[4].Value = tempRemark;
insertSettleParms[4].Value = tempCompanyID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE_PAY_APPLICATION_RUN, insertSettleParms);
SqlParameter[] insertFeeDoParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_DO_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_DO_RUN_SETTLE_ID,SqlDbType.VarChar,36)
};
insertFeeDoParms[0].Value = strNewBillNo;
insertFeeDoParms[1].Value = tempRunSettleID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE_FEE_DO_RUN, insertFeeDoParms);
SqlParameter[] updateFeeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20)
};
updateFeeParms[0].Value = strNewBillNo;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_BY_RUN_FEE_DO, updateFeeParms);
SqlParameter[] deleteRunSettleParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_GID,SqlDbType.VarChar,36)
};
deleteRunSettleParms[0].Value = tempRunSettleID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_RUN_FEE_SETTLEMENT_BY_GID, deleteRunSettleParms);
SqlParameter[] deleteRunDoParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_DO_RUN_SETTLE_ID,SqlDbType.VarChar,36)
};
deleteRunDoParms[0].Value = tempRunSettleID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_RUN_FEE_DO_BY_RUNSETTLE_ID, deleteRunDoParms);
}
//事务提交
sqlTran.Commit();
if (validState == 0)
{
iResult = 1;//状态为1表示插入成功
}
else
{
iResult = -3;//费用表没有足够的申请金额使用,无法提交付费申请
}
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
public string GetBillNoByPaySettleAppID(string tempPaySettleAppID)
{
string result = "";
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter parm = new SqlParameter(PARM_FEE_SETTLEMENT_GID, SqlDbType.VarChar, 36);
parm.Value = tempPaySettleAppID;
result = (String)SqlHelper.ExecuteScalar(conn, CommandType.Text, SQL_SELECT_CH_FEE_PAY_APPLICATION_BILLNO, parm) as String ?? "";
}
catch (Exception error)
{
throw error;
}
}
return result;
}
#region 生成申请编号起始串
/// <summary>
/// 生成申请编号起始串
/// </summary>
/// <param name="tempNowDateTime">当前服务器时间</param>
/// <param name="tempBeginTitle">申请编号起始串头字母</param>
/// <param name="tempCodeLength">申请编号累计编码长度</param>
/// <returns>返回申请编号起始串</returns>
private string CreateBeginTitleCode(DateTime tempNowDateTime, string tempBeginTitle, int tempCodeLength)
{
int CodeLength = tempCodeLength;
string strFeeType = tempBeginTitle;
//解析当前时间
DateTime nowDateTime = tempNowDateTime;
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//获取年+月组合的字符串
string strDateTime = strYear + strMonth;
//将申请编号抬头+日期作为申请编号
string strCodePrefix = strFeeType + strDateTime;
return strCodePrefix;
}
#endregion
#region 生成付费申请编号
/// <summary>
/// 生成付费申请编号
/// </summary>
/// <param name="tempNowDateTime">当前服务器时间</param>
/// <param name="tempBeginTitle">申请编号起始串头字母</param>
/// <param name="tempCodeLength">申请编号累计编码长度</param>
/// <param name="tempLastBillNo">最大申请编号</param>
/// <returns>返回新的申请编号</returns>
private string CreateSettleCode(DateTime tempNowDateTime, string tempBeginTitle, int tempCodeLength,string tempLastBillNo)
{
int CodeLength = tempCodeLength;
string strSettleCode = "";
string strFeeType = tempBeginTitle;
//解析当前时间
DateTime nowDateTime = tempNowDateTime;
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//获取年+月组合的字符串
string strDateTime = strYear + strMonth;
//将申请编号抬头+日期作为申请编号
string strCodePrefix = strFeeType + strDateTime;
//string strSql = "SELECT TOP 1 BILLNO FROM ch_fee_payapplication WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' ORDER BY BILLNO DESC";
//DataTable billTable = feeDoDA.GetExcuteSql(strSql).Tables[0];
ArrayList codeArg = new ArrayList();
for (int i = 0; i < CodeLength; i++)
{
codeArg.Add(0);
}
string strCode = "";//编号
if (tempLastBillNo != "")
{
string oldCode = tempLastBillNo;
if (oldCode.IndexOf(strCodePrefix) >= 0)
{
oldCode = oldCode.Substring(strCodePrefix.Length, oldCode.Length - strCodePrefix.Length);
if (oldCode.Length == CodeLength)
{
for (int i = 0; i < oldCode.Length; i++)
{
if (oldCode[i].ToString().IndexOf("0") == 0)
{
oldCode = oldCode.Remove(i, 1);
i = -1;
continue;
}
else
{
break;
}
}
}
}
int newNum = int.Parse(oldCode);
newNum = newNum + 1;
string strNewNum = newNum.ToString();
int codeArgCount = codeArg.Count - 1;
for (int i = strNewNum.Length - 1; i >= 0; i--)
{
codeArg[codeArgCount] = strNewNum[i];
codeArgCount--;
}
//for (int i = 0; i < strNewNum.Length; i++)
//{
// codeArg[i] = strNewNum[i];
//}
}
else
{
int iOld = int.Parse(codeArg[codeArg.Count - 1].ToString());
codeArg[codeArg.Count - 1] = (iOld + 1).ToString();
}
for (int i = 0; i < codeArg.Count; i++)
{
strCode += codeArg[i].ToString();
}
strSettleCode = strFeeType + strDateTime + strCode;
return strSettleCode;
}
#endregion
public int PostRejectPaySettleApplication(string tempPaySettleAppGID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
int validState = 0;
//先校验是否费用已经做了申请
SqlParameter[] validFeeParms = new SqlParameter[]{
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
validFeeParms[0].Value = tempPaySettleAppGID;
validState = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_VALID_CH_FEE_ORDERAMOUNT, validFeeParms);
if (validState == 0)
{
SqlParameter[] updatePayAppParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
updatePayAppParms[0].Value = tempPaySettleAppGID;
SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_PAYAPPLICATION_FOR_REPOST, updatePayAppParms);
SqlParameter[] updateFeeDoParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
updateFeeDoParms[0].Value = tempPaySettleAppGID;
SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_DO_FOR_REPOST, updateFeeDoParms);
SqlParameter[] updateFeeParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
updateFeeParms[0].Value = tempPaySettleAppGID;
SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_ORDER_AMOUNT_FOR_REPOST, updateFeeParms);
}
//再校验是否已经做了结算
//事务提交
sqlTran.Commit();
if (validState == 0)
{
iResult = 1;//状态为1表示插入成功
}
else
{
iResult = -3;//被驳回的付费申请相关费用申请金额不足,不能申请付费
}
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#region 删除付费申请信息(无法恢复)
/// <summary>
/// 删除付费申请信息(无法恢复)
/// </summary>
/// <param name="tempPaySettleAppID">付费申请GID</param>
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
public int DeletePaySettleApplicationUnCover(string tempPaySettleAppID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] deleteFeeDoParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
deleteFeeDoParms[0].Value = tempPaySettleAppID;
SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_DELETE_CH_FEE_DO_UNCOVER, deleteFeeDoParms);
SqlParameter[] deletPaySettleAppParms = new SqlParameter[] {
new SqlParameter(PARM_SETTLE_APPL_GID,SqlDbType.VarChar,36)
};
deletPaySettleAppParms[0].Value = tempPaySettleAppID;
SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_DELETE_CH_FEE_PAYAPPLICATION_UNRECOVER, deletPaySettleAppParms);
sqlTran.Commit();
iResult = 1;//删除成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
}
}