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.

641 lines
37 KiB
C#

12 months ago
using System;
using System.Data;
using System.Data.SqlClient;
using WebSqlHelper;
using DSWeb.Models;
using System.Collections;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class RunFeeDoDA
{
private string PARM_RUN_FEE_DO_GID = "@gid";
private string PARM_RUN_FEE_DO_BSNO = "@bsno";
private string PARM_RUN_FEE_DO_MBL_NO = "@mbl_no";
private string PARM_RUN_FEE_DO_HBL_NO = "@nbl_no";
private string PARM_RUN_FEE_DO_CUSTOMER_NAME = "@customer_name";
private string PARM_RUN_FEE_DO_BSTYPE = "@bs_type";
private string PARM_RUN_FEE_DO_FEE_ID = "@fee_id";
private string PARM_RUN_FEE_DO_FEE_NAME = "@fee_name";
private string PARM_RUN_FEE_DO_CURRENCY = "@currency";
private string PARM_RUN_FEE_DO_AMOUNT = "@amount";
private string PARM_RUN_FEE_DO_DO_AMOUNT = "@do_amount";
private string PARM_RUN_FEE_DO_FEE_TYPE = "@fee_type";
private string PARM_RUN_FEE_DO_CATEGORY = "@category";
private string PARM_RUN_FEE_DO_BILL_STATUS = "@bill_status";
private string PARM_RUN_FEE_DO_REMARK = "@remark";
private string PARM_RUN_FEE_DO_INVOICE_SETTLE_NO = "@invoice_settle_no";
private string PARM_RUN_FEE_DO_RUN_SETTLE_ID = "@runsettle_id";
private string PARM_RUN_FEE_DO_ORIG_AMOUNT = "@orig_amount";
private string PARM_RUN_FEE_DO_EXCHANGE_RATE = "@exchange_rate";
private string PARM_RUN_FEE_DO_ORIG_CURRENCY = "@orig_currency";
private string PARM_RUN_FEE_DO_CREATE_USER = "@create_user";
private string PARM_RUN_FEE_DO_COMPANY_ID = "@company_id";
private string PARM_RUN_FEE_SETTLEMENT_GID = "@gid";
private string PARM_RUN_FEE_SETTLEMENT_SETTLE_MODE = "@settle_mode";
private string PARM_RUN_FEE_SETTLEMENT_CUSTOMER_NAME = "@customer_name";
private string PARM_RUN_FEE_SETTLEMENT_SETTLE_TYPE = "@settle_type";
private string PARM_RUN_FEE_SETTLEMENT_AMOUNT_RMB = "@amount_rmb";
private string PARM_RUN_FEE_SETTLEMENT_ACCOUNT_RMB = "@account_rmb";
private string PARM_RUN_FEE_SETTLEMENT_RATE = "@rate";
private string PARM_RUN_FEE_SETTLEMENT_AMOUNT_USD = "@amount_usd";
private string PARM_RUN_FEE_SETTLEMENT_ACCOUNT_USD = "@account_usd";
private string PARM_RUN_FEE_SETTLEMENT_BILL_TYPE = "@bill_type";
private string PARM_RUN_FEE_SETTLEMENT_VOUCHER_NO = "@voucher_no";
private string PARM_RUN_FEE_SETTLEMENT_IS_EXPORT = "@is_export";
private string PARM_RUN_FEE_SETTLEMENT_FINANCIAL_VOUCHER = "@financial_voucher";
private string PARM_RUN_FEE_SETTLEMENT_BILL_STATUS = "@bill_status";
private string PARM_RUN_FEE_SETTLEMENT_REMARK = "@remark";
private string PARM_RUN_FEE_SETTLEMENT_TYPE = "@type";
private string PARM_RUN_FEE_SETTLEMENT_CREATE_USER = "@create_user";
//private string PARM_RUN_FEE_SETTLEMENT_CREATE_TIME = "@create_time";
private string PARM_RUN_FEE_SETTLEMENT_PAYABLE_TIME = "@payable_time";
private string PARM_RUN_FEE_SETTLEMENT_COMPANY_ID = "@company_id";
private string PARM_RUN_FEE_SETTLEMENT_SERIAL_NO = "@serial_no";
private string PARM_RUN_FEE_SETTLEMENT_LIKE = "@like";
//private string PARM_FEE_GID = "@gid";
//private string PARM_FEE_STATUS = "@fee_status";
//private string PARM_FEE_SETTLEMENT = "@settlement";
//private string PARM_FEE_CHEQUE_NUM = "@cheque_num";
private string SQL_SELECT_GETDATE = "SELECT GETDATE()";
//private string SQL_SELECT_RUN_FEE_SETTLEMENT_BY_GID = " SELECT GID, BILLNO, BILLDATE, SETTLEMODE, CUSTOMERNAME, SETTLETYPE, AMOUNTRMB, ACCOUNTRMB, RATE, AMOUNTUSD, ACCOUNTUSD, BILLTYPE, VOUCHERNO, SETTLEUSER, SETTLETIME, AUDITUSER, AUDITTIME, ISEXPORT, FINANCIALVOUCHER, BILLSTATUS, REMARK FROM run_fee_settlement WHERE GID = @gid";
//private string SQL_INSERT_FEE_DO = " INSERT INTO run_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,INVOICESETTLENO,RUNSETTLEID) "
//+ " 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,@invoice_settle_no,@runsettle_id) ";
//private string SQL_INSERT_FEE_SETTLEMENT = " INSERT INTO ch_fee_settlement(GID, BILLNO, BILLDATE, SETTLEMODE, CUSTOMERNAME, SETTLETYPE, AMOUNTRMB, ACCOUNTRMB, RATE, AMOUNTUSD, ACCOUNTUSD, BILLTYPE, VOUCHERNO, SETTLEUSER, SETTLETIME, ISEXPORT, FINANCIALVOUCHER, BILLSTATUS, REMARK)"
//+ " 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, GETDATE(),@is_export,@financial_voucher,@bill_status,@remark)";
private string SQL_SELECT_FEE_DO_BY_RUN_SETTLE_ID = " SELECT GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,"
+ " BILLSTATUS,REMARK,ORIGCURRENCY,EXCHANGERATE,ISDELETE,DELETEUSER,DELETETIME,ORIGAMOUNT,INVOICESETTLENO,RUNSETTLEID "
+ " FROM ch_fee_do WHERE RUNSETTLEID = @runsettle_id ";
private string SQL_INSERT_RUN_FEE_DO = " INSERT INTO run_fee_do(GID, BSNO,MBLNO, HBLNO, CUSTOMERNAME, BSTYPE, FEEID, FEENAME, CURRENCY, AMOUNT, DOAMOUNT, FEETYPE, CATEGORY, BILLSTATUS, "
+ " REMARK, CREATEUSER, CREATETIME, EXCHANGERATE, ORIGCURRENCY, ORIGAMOUNT, INVOICESETTLENO, RUNSETTLEID,COMPANYID ) "
+ " VALUES(@gid,@bsno,@mbl_no,@nbl_no,@customer_name,@bs_type,@fee_id,@fee_name,@currency,@amount,@do_amount,@fee_type,@category, "
+ " @bill_status,@remark,@create_user,GETDATE(),@exchange_rate,@orig_currency,@orig_amount,@invoice_settle_no,@runsettle_id,@company_id) ";
private const string SQL_SELECT_LAST_SERIAL_NO = " SELECT TOP 1 SERIALNO FROM run_fee_settlement WHERE SERIALNO LIKE @like AND CREATEUSER = @create_user ORDER BY SERIALNO DESC ";
#region 获取服务端时间
/// <summary>
/// 获取服务端时间
/// </summary>
/// <returns></returns>
public DateTime getServerDateTime()
{
DateTime nowDateTime = new DateTime();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_GETDATE, null))
{
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
nowDateTime = sqlRead.GetDateTime(0);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return nowDateTime;
}
#endregion
#region 根据Sql语句获取相关数据集
/// <summary>
/// 根据Sql语句获取相关数据集
/// </summary>
/// <param name="strSql">执行查询Sql语句</param>
/// <returns>返回查询的数据集</returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet tempSet = new DataSet();
tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return tempSet;
}
#endregion
#region 插入运行结算信息
/// <summary>
/// 插入运行结算信息
/// </summary>
/// <param name="tempRunFeeDoEntities">运行结算费用明细数据集</param>
/// <param name="tempRunFeeSettlementEntities">运行结算数据集</param>
/// <param name="tempOperatorShowName">运行结算操作人GID</param>
/// <param name="tempOperatorShowName">运行结算操作人中文名称</param>
/// <returns>值1表示插入成功 值不等于1表示插入失败</returns>
public int InsertRunSettle(IList<RunFeeDoEntity> tempRunFeeDoEntities, RunFeeSettlementEntity tempRunFeeSettlementEntity,string tempOperatorID,string tempOperatorShowName,string tempSerialTypeName)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strLastSerialNo = "";
string strNewSerialNo = "";
//先获取SQL SERVER 数据库端服务器时间
DateTime nowServerDateTime = (DateTime)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_GETDATE, null);
if (nowServerDateTime == DateTime.MinValue)
{
throw new Exception("未正常获取到服务端时间");
}
string strSpellName = GetChineseSpell(tempOperatorShowName);
//获取分公司的票号头字符
string tempBANKSHEAD = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + tempRunFeeSettlementEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strSerialNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD + tempSerialTypeName, 4, strSpellName);
SqlParameter[] getLastSerialParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_CREATE_USER,SqlDbType.VarChar,36)
};
getLastSerialParms[0].Value = strSerialNoProfix + "%";
getLastSerialParms[1].Value = tempOperatorID;
//获取最大的编号
string tempLastSerialNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_SERIAL_NO, getLastSerialParms) as string;
strLastSerialNo = tempLastSerialNo ?? "";
//生成付费申请编号
strNewSerialNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD + tempSerialTypeName, 4, strLastSerialNo, strSpellName);
if (tempRunFeeSettlementEntity.PayableTime != DateTime.MinValue)
{
//插入运行结算信息表
SqlParameter[] insertRunSettleParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SETTLE_MODE, SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_AMOUNT_RMB,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_ACCOUNT_RMB,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_AMOUNT_USD,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_ACCOUNT_USD,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_BILL_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_VOUCHER_NO,SqlDbType.VarChar,50),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_IS_EXPORT,SqlDbType.Bit),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_FINANCIAL_VOUCHER,SqlDbType.VarChar,50),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_REMARK,SqlDbType.VarChar,100),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_PAYABLE_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SERIAL_NO,SqlDbType.VarChar,100),
new SqlParameter("@ChequeNo",SqlDbType.VarChar,200),
new SqlParameter("@ChequeNoUsd",SqlDbType.VarChar,200),
new SqlParameter("@CHEQUENUMREMARK",SqlDbType.VarChar,100)
};
insertRunSettleParms[0].Value = tempRunFeeSettlementEntity.GID;
insertRunSettleParms[1].Value = tempRunFeeSettlementEntity.SettleMode;
insertRunSettleParms[2].Value = tempRunFeeSettlementEntity.CustomerName;
insertRunSettleParms[3].Value = tempRunFeeSettlementEntity.SettleType;
insertRunSettleParms[4].Value = tempRunFeeSettlementEntity.AmountRMB;
insertRunSettleParms[5].Value = tempRunFeeSettlementEntity.AccountRMB;
insertRunSettleParms[6].Value = tempRunFeeSettlementEntity.Rate;
insertRunSettleParms[7].Value = tempRunFeeSettlementEntity.AmountUSD;
insertRunSettleParms[8].Value = tempRunFeeSettlementEntity.AccountUSD;
insertRunSettleParms[9].Value = tempRunFeeSettlementEntity.BillType;
insertRunSettleParms[10].Value = tempRunFeeSettlementEntity.VoucherNO;
insertRunSettleParms[11].Value = tempRunFeeSettlementEntity.IsExport;
insertRunSettleParms[12].Value = tempRunFeeSettlementEntity.FinancialVoucher;
insertRunSettleParms[13].Value = tempRunFeeSettlementEntity.BillStatus;
insertRunSettleParms[14].Value = tempRunFeeSettlementEntity.Remark;
insertRunSettleParms[15].Value = tempRunFeeSettlementEntity.Type;
insertRunSettleParms[16].Value = tempRunFeeSettlementEntity.CreateUser;
insertRunSettleParms[17].Value = tempRunFeeSettlementEntity.PayableTime;
insertRunSettleParms[18].Value = tempRunFeeSettlementEntity.CompanyID;
insertRunSettleParms[19].Value = strNewSerialNo;
insertRunSettleParms[20].Value = tempRunFeeSettlementEntity.ChequeNo;
insertRunSettleParms[21].Value = tempRunFeeSettlementEntity.ChequeNoUsd;
insertRunSettleParms[22].Value = tempRunFeeSettlementEntity.CHEQUENUMREMARK;
//
string SETTLETIME = tempRunFeeSettlementEntity.CreateTime.ToString().Trim().IndexOf("0001") > -1 ? "GETDATE()," : "'" + tempRunFeeSettlementEntity.CreateTime.ToString().Trim() + "',";
string SETTLETIME_NAME = tempRunFeeSettlementEntity.CreateTime.ToString().Trim().IndexOf("0001") > -1 ? "CREATETIME," : "CREATETIME,";
string SQL_INSERT_RUN_FEE_SETTLMENT = String.Format("INSERT run_fee_settlement(GID, SETTLEMODE, CUSTOMERNAME, SETTLETYPE, AMOUNTRMB, ACCOUNTRMB, RATE, AMOUNTUSD, ACCOUNTUSD, BILLTYPE, VOUCHERNO, ISEXPORT, FINANCIALVOUCHER, BILLSTATUS, REMARK, TYPE, CREATEUSER, {0} PAYABLETIME, COMPANYID,SERIALNO,CHEQUENO,CHEQUENOUSD,CHEQUENUMREMARK) "
+ " VALUES(@gid,@settle_mode,@customer_name,@settle_type,@amount_rmb,@account_rmb,@rate,@amount_usd,@account_usd,@bill_type,@voucher_no, @is_export,@financial_voucher,@bill_status,@remark,@type,@create_user,{1}@payable_time,@company_id,@serial_no,@ChequeNo,@ChequeNoUsd,@CHEQUENUMREMARK) ", SETTLETIME_NAME, SETTLETIME);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_RUN_FEE_SETTLMENT, insertRunSettleParms);
}
else
{
//插入运行结算信息表
SqlParameter[] insertRunSettleParms = new SqlParameter[] {
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SETTLE_MODE, SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_AMOUNT_RMB,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_ACCOUNT_RMB,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_AMOUNT_USD,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_ACCOUNT_USD,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_BILL_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_VOUCHER_NO,SqlDbType.VarChar,50),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_IS_EXPORT,SqlDbType.Bit),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_FINANCIAL_VOUCHER,SqlDbType.VarChar,50),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_REMARK,SqlDbType.VarChar,100),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_SETTLEMENT_SERIAL_NO,SqlDbType.VarChar,100),
new SqlParameter("@ChequeNo",SqlDbType.VarChar,200),
new SqlParameter("@ChequeNoUsd",SqlDbType.VarChar,200),
new SqlParameter("@CHEQUENUMREMARK",SqlDbType.VarChar,100)
};
insertRunSettleParms[0].Value = tempRunFeeSettlementEntity.GID;
insertRunSettleParms[1].Value = tempRunFeeSettlementEntity.SettleMode;
insertRunSettleParms[2].Value = tempRunFeeSettlementEntity.CustomerName;
insertRunSettleParms[3].Value = tempRunFeeSettlementEntity.SettleType;
insertRunSettleParms[4].Value = tempRunFeeSettlementEntity.AmountRMB;
insertRunSettleParms[5].Value = tempRunFeeSettlementEntity.AccountRMB;
insertRunSettleParms[6].Value = tempRunFeeSettlementEntity.Rate;
insertRunSettleParms[7].Value = tempRunFeeSettlementEntity.AmountUSD;
insertRunSettleParms[8].Value = tempRunFeeSettlementEntity.AccountUSD;
insertRunSettleParms[9].Value = tempRunFeeSettlementEntity.BillType;
insertRunSettleParms[10].Value = tempRunFeeSettlementEntity.VoucherNO;
insertRunSettleParms[11].Value = tempRunFeeSettlementEntity.IsExport;
insertRunSettleParms[12].Value = tempRunFeeSettlementEntity.FinancialVoucher;
insertRunSettleParms[13].Value = tempRunFeeSettlementEntity.BillStatus;
insertRunSettleParms[14].Value = tempRunFeeSettlementEntity.Remark;
insertRunSettleParms[15].Value = tempRunFeeSettlementEntity.Type;
insertRunSettleParms[16].Value = tempRunFeeSettlementEntity.CreateUser;
insertRunSettleParms[17].Value = tempRunFeeSettlementEntity.CompanyID;
insertRunSettleParms[18].Value = strNewSerialNo;
insertRunSettleParms[19].Value = tempRunFeeSettlementEntity.ChequeNo;
insertRunSettleParms[20].Value = tempRunFeeSettlementEntity.ChequeNoUsd;
insertRunSettleParms[21].Value = tempRunFeeSettlementEntity.CHEQUENUMREMARK;
//
string SETTLETIME = tempRunFeeSettlementEntity.CreateTime.ToString().Trim().IndexOf("0001") > -1 ? "GETDATE()," : "'" + tempRunFeeSettlementEntity.CreateTime.ToString().Trim() + "',";
string SETTLETIME_NAME = tempRunFeeSettlementEntity.CreateTime.ToString().Trim().IndexOf("0001") > -1 ? "CREATETIME," : "CREATETIME,";
string SQL_INSERT_RUN_FEE_SETTLMENT_NO_PAYABLETIME = String.Format("INSERT run_fee_settlement(GID, SETTLEMODE, CUSTOMERNAME, SETTLETYPE, AMOUNTRMB, ACCOUNTRMB, RATE, AMOUNTUSD, ACCOUNTUSD, BILLTYPE, VOUCHERNO, ISEXPORT, FINANCIALVOUCHER, BILLSTATUS, REMARK, TYPE, CREATEUSER, {0} COMPANYID,SERIALNO,CHEQUENO,CHEQUENOUSD,CHEQUENUMREMARK) "
+ " VALUES(@gid,@settle_mode,@customer_name,@settle_type,@amount_rmb,@account_rmb,@rate,@amount_usd,@account_usd,@bill_type,@voucher_no, @is_export,@financial_voucher,@bill_status,@remark,@type,@create_user,{1}@company_id,@serial_no,@ChequeNo,@ChequeNoUsd,@CHEQUENUMREMARK) ", SETTLETIME_NAME, SETTLETIME);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_RUN_FEE_SETTLMENT_NO_PAYABLETIME, insertRunSettleParms);
}
//插入运行结算费用明细信息
foreach (RunFeeDoEntity runFeeDoEntity in tempRunFeeDoEntities)
{
SqlParameter[] insertRunDoParms = new SqlParameter[]{
new SqlParameter(PARM_RUN_FEE_DO_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_DO_BSNO, SqlDbType.VarChar,100),
new SqlParameter(PARM_RUN_FEE_DO_MBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_RUN_FEE_DO_HBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_RUN_FEE_DO_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_DO_BSTYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_DO_FEE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_DO_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_RUN_FEE_DO_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_RUN_FEE_DO_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_RUN_FEE_DO_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_DO_CATEGORY,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_DO_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_RUN_FEE_DO_REMARK,SqlDbType.VarChar,100),
new SqlParameter(PARM_RUN_FEE_DO_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_DO_EXCHANGE_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_DO_ORIG_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_DO_ORIG_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_RUN_FEE_DO_INVOICE_SETTLE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_RUN_FEE_DO_RUN_SETTLE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_RUN_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36),
};
insertRunDoParms[0].Value = runFeeDoEntity.GID;
insertRunDoParms[1].Value = runFeeDoEntity.BSNO;
insertRunDoParms[2].Value = runFeeDoEntity.MBLNO;
insertRunDoParms[3].Value = runFeeDoEntity.HBLNO;
insertRunDoParms[4].Value = runFeeDoEntity.CustomerName;
insertRunDoParms[5].Value = runFeeDoEntity.BSType;
insertRunDoParms[6].Value = runFeeDoEntity.FeeID;
insertRunDoParms[7].Value = runFeeDoEntity.FeeName;
insertRunDoParms[8].Value = runFeeDoEntity.Currency;
insertRunDoParms[9].Value = runFeeDoEntity.OriginalFeeCSTL;
insertRunDoParms[10].Value = runFeeDoEntity.DoAmount;
insertRunDoParms[11].Value = runFeeDoEntity.FeeType;
insertRunDoParms[12].Value = runFeeDoEntity.Category;
insertRunDoParms[13].Value = runFeeDoEntity.BillStatus;
insertRunDoParms[14].Value = runFeeDoEntity.Remark;
insertRunDoParms[15].Value = runFeeDoEntity.CreateUser;
insertRunDoParms[16].Value = runFeeDoEntity.ExchangeRate;
insertRunDoParms[17].Value = runFeeDoEntity.OrigCurrency;
insertRunDoParms[18].Value = runFeeDoEntity.OriginalFeeCSTL;
insertRunDoParms[19].Value = runFeeDoEntity.InvoiceSettleNO;
insertRunDoParms[20].Value = runFeeDoEntity.RunSettleID;
insertRunDoParms[21].Value = runFeeDoEntity.CompanyID == null ? "" : runFeeDoEntity.CompanyID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_RUN_FEE_DO, insertRunDoParms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 根据运行费用结算表GID获取运行结算费用明细表信息
/// <summary>
/// 根据运行费用结算表GID获取运行结算费用明细表信息
/// </summary>
/// <param name="tempRunSettlementGID">运行结算表GID</param>
/// <returns>返回所有运行结算表GID相关的运行费用明细实体类集合</returns>
public IList<RunFeeDoEntity> GetRunFeeDoByRunSettlementID(string tempRunSettlementGID)
{
//初始化返回变量
IList<RunFeeDoEntity> runFeeDoEntities = new List<RunFeeDoEntity>();
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_RUN_FEE_DO_RUN_SETTLE_ID, SqlDbType.VarChar, 36);
parm.Value = tempRunSettlementGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_FEE_DO_BY_RUN_SETTLE_ID, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
RunFeeDoEntity runFeeDoEntity = new RunFeeDoEntity();
if (!sqlRead.IsDBNull(0))
{
runFeeDoEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
runFeeDoEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
runFeeDoEntity.MBLNO = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
runFeeDoEntity.HBLNO = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
runFeeDoEntity.CustomerName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
runFeeDoEntity.BSType = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
runFeeDoEntity.FeeID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
runFeeDoEntity.FeeName = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
runFeeDoEntity.Currency = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
runFeeDoEntity.Amount = sqlRead.GetDecimal(9);
}
if (!sqlRead.IsDBNull(10))
{
runFeeDoEntity.DoAmount = sqlRead.GetDecimal(10);
}
if (!sqlRead.IsDBNull(11))
{
runFeeDoEntity.FeeType = sqlRead.GetInt32(11);
}
if (!sqlRead.IsDBNull(12))
{
runFeeDoEntity.Category = sqlRead.GetInt32(12);
}
if (!sqlRead.IsDBNull(13))
{
runFeeDoEntity.BillStatus = sqlRead.GetInt32(13);
}
if (!sqlRead.IsDBNull(14))
{
runFeeDoEntity.Remark = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
runFeeDoEntity.OrigCurrency = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
runFeeDoEntity.ExchangeRate = sqlRead.GetDecimal(16);
}
if (!sqlRead.IsDBNull(17))
{
runFeeDoEntity.RunSettleID = sqlRead.GetString(17);
}
runFeeDoEntities.Add(runFeeDoEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return runFeeDoEntities;
}
#endregion
private string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
}
return myStr;
}
//取首字母方法
static public string getSpell(string myChar)
{
byte[] arrCN = System.Text.Encoding.Default.GetBytes(myChar);
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
return System.Text.Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "*";
}
else return myChar;
}
#region 生成付费结算编号起始串
/// <summary>
/// 生成付费结算编号起始串
/// </summary>
/// <param name="tempNowDateTime">当前服务器时间</param>
/// <param name="tempBeginTitle">结算编号起始串头字母</param>
/// <param name="tempCodeLength">结算编号累计编码长度</param>
/// <param name="tempSpellName">登录人中文名称首字母拼接串</param>
/// <returns>返回结算编号起始串</returns>
private string CreateBeginTitleCode(DateTime tempNowDateTime, string tempBeginTitle, int tempCodeLength, string tempSpellName)
{
int CodeLength = tempCodeLength;
string strFeeType = tempBeginTitle + tempSpellName;
//解析当前时间
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, string tempSpellName)
{
int CodeLength = tempCodeLength;
string strSettleCode = "";
string strFeeType = tempBeginTitle + tempSpellName;
//解析当前时间
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--;
}
}
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
}
}