using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Text; using DSWeb.MvcShipping.Models.MsChFee; using DSWeb.MvcShipping.Models.MsOpAmend; using HcUtility.Comm; using System.Data.SqlClient; using WebSqlHelper; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.DAL; using DSWeb.TruckMng.Comm.Cookie; using DSWeb.MvcShipping.Models.MsSysParamSet; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.Models.CurrencyExchange;//引用汇率管理的datamodule using System.Web.Configuration; using DotNet4.Utilities; using DSWeb.Areas.MvcShipping.Comm; using DSWeb.MvcShipping.DAL.MsCodeYardDataSet; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using DSWeb.MvcShipping.Models.MsOpBill; using HcUtility.Core; using DSWeb.Areas.SysMng.DAL.SysUser; using DSWeb.MvcShipping.DAL.MsInfoClient; using DSWeb.Areas.Account.Models.BSNOLB; using System.Text.RegularExpressions; using DSWeb.Areas.MvcShipping.DAL; using DSWeb.Common.DB; using System.Linq; namespace DSWeb.MvcShipping.DAL.MsChFeeDAL { public class MsChFeeDAL { #region 费用参数 private const string PARM_FEE_GID = "@gid"; private const string PARM_FEE_BSNO = "@bsno"; private const string PARM_FEE_TYPE = "@fee_type"; private const string PARM_FEE_NAME = "@fee_name"; private const string PARM_FEE_DESCRIPTION = "@fee_description"; private const string PARM_FEE_CUSTOMER_TYPE = "@customer_type"; private const string PARM_FEE_CUSTOMER_NAME = "@customer_name"; private const string PARM_FEE_UNIT = "@unit"; private const string PARM_FEE_UNIT_PRICE = "@unit_price"; private const string PARM_FEE_TAXUNIT_PRICE = "@taxunit_price"; private const string PARM_FEE_QUANTITY = "@quantity"; private const string PARM_FEE_AMOUNT = "@amount"; private const string PARM_FEE_CURRENCY = "@currency"; private const string PARM_FEE_EXCHANGE_RATE = "@exchange_rate"; private const string PARM_FEE_REASON = "@reason"; private const string PARM_FEE_REMARK = "@remark"; private const string PARM_FEE_COMMISSION_RATE = "@comm_rate"; private const string PARM_FEE_SETTLEMENT = "@settlement"; private const string PARM_FEE_INVOICE = "@invoice"; private const string PARM_FEE_ORDER_AMOUNT = "@order_amount"; private const string PARM_FEE_ORDER_INVOCE = "@order_invoice"; private const string PARM_FEE_SUBMIT_DATE = "@submit_date"; private const string PARM_FEE_AUDIT_OPERATOR = "@audit_operator"; private const string PARM_FEE_AUDIT_DATE = "@audit_date"; private const string PARM_FEE_ENTER_OPERATOR = "@enter_operator"; private const string PARM_FEE_ENTER_DATE = "@enter_date"; private const string PARM_FEE_DEBITNO = "@debitno"; private const string PARM_FEE_ISDEBIT = "@is_debit"; private const string PARM_FEE_ISOPEN = "@is_open"; private const string PARM_FEE_ISADVANCEPAY = "@is_advance_pay"; private const string PARM_FEE_SORT = "@sort"; private const string PARM_FEE_ISINVOICE = "@is_invoice"; private const string PARM_FEE_STATUS = "@fee_status"; private const string PARM_FEE_FRT = "@fee_frt"; private const string PARM_FEE_AUDIT_STATUS = "@audit_status"; private const string PARM_FEE_AUDIT_WMSOUTBSNO = "@WMSOUTBSNO"; private const string PARM_FEE_TAXRATE = "@taxrate"; private const string PARM_FEE_NOTAXAMOUNT = "@notaxamount"; private const string PARM_FEE_ACCTAXRATE = "@acctaxrate"; private const string PARM_FEE_LINENUM = "@LINENUM"; private const string PARM_FEE_MODIFIEDUSER = "@MODIFIEDUSER"; private const string PARM_FEE_MODIFIEDTIME = "@MODIFIEDTIME"; private const string PARM_WMSOUTBSNO = "@WMSOUTBSNO"; private const string PARM_PREAMOUNT = "@PREAMOUNT"; private const string PARM_ISINVOICE = "@ISINVOICE"; private const string PARM_INPUTMODE = "@INPUTMODE"; private const string PARM_LOCALCURR = "@LOCALCURR"; private const string PARM_MANAGER = "@MANAGER"; private const string PARM_FEE_ISACC = "@ISACC"; private const string PARM_SALECORP = "@SALECORP"; private const string PARM_FEE_ISCRMORDERFEE = "@ISCRMORDERFEE"; #endregion static private SqlParameter[] GetInsertParms() { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36), new SqlParameter(PARM_FEE_BSNO,SqlDbType.VarChar,60), new SqlParameter(PARM_FEE_TYPE,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_NAME,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_DESCRIPTION,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_CUSTOMER_TYPE,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_UNIT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_UNIT_PRICE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_REASON,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_REMARK,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_ENTER_OPERATOR,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_ENTER_DATE,SqlDbType.SmallDateTime), new SqlParameter(PARM_FEE_ISOPEN,SqlDbType.VarChar,1), new SqlParameter(PARM_FEE_ISADVANCEPAY,SqlDbType.VarChar,1), new SqlParameter(PARM_FEE_SORT,SqlDbType.Int), new SqlParameter(PARM_FEE_STATUS,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_FRT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_TAXRATE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_NOTAXAMOUNT,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_ACCTAXRATE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_LINENUM,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_TAXUNIT_PRICE,SqlDbType.Decimal,18), new SqlParameter(PARM_FEE_MODIFIEDUSER,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_MODIFIEDTIME,SqlDbType.DateTime), new SqlParameter(PARM_WMSOUTBSNO,SqlDbType.VarChar,50), new SqlParameter(PARM_PREAMOUNT,SqlDbType.Decimal,18), new SqlParameter(PARM_ISINVOICE,SqlDbType.VarChar,1), new SqlParameter(PARM_INPUTMODE,SqlDbType.VarChar,40), new SqlParameter(PARM_LOCALCURR,SqlDbType.VarChar,30), new SqlParameter(PARM_MANAGER,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_ISACC,SqlDbType.VarChar,1), new SqlParameter(PARM_SALECORP,SqlDbType.VarChar,60), new SqlParameter(PARM_FEE_ISCRMORDERFEE,SqlDbType.VarChar,1) }; return parms; } private const string SQL_INSERT_FEE = " INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, " + " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, " + " TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC,SALECORP,ISCRMORDERFEE) " + " VALUES " + " (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, " + " @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, " + " @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@ISINVOICE,@INPUTMODE,@LOCALCURR,@MANAGER,@ISACC,@SALECORP,@ISCRMORDERFEE)";//DateTime.Now.ToString() private const string SQL_UPDATE_CH_FE = " UPDATE ch_fee SET FEENAME = @fee_name,FEEDESCRIPTION=@fee_description,CUSTOMERTYPE=@customer_type,CUSTOMERNAME = @customer_name,UNIT = @unit,UNITPRICE = @unit_price,QUANTITY = @quantity,COMMISSIONRATE = @comm_rate," + " AMOUNT = @amount,CURRENCY = @currency,EXCHANGERATE = @exchange_rate,FEEFRT = @fee_frt,REMARK = @remark,ISADVANCEDPAY = @is_advance_pay," + " WMSOUTBSNO=@WMSOUTBSNO,LINENUM=@LINENUM,TaxRate=@TAXRATE,NoTaxAmount=@NOTAXAMOUNT,AccTaxRate=@ACCTAXRATE,TAXUNITPRICE=@TAXUNITPRICE,PREAMOUNT=@PREAMOUNT," + "MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME,ISOPEN = @ISOPEN,IsInvoice=@IsInvoice,INPUTMODE=@INPUTMODE,LOCALCURR=@LOCALCURR,MANAGER=@MANAGER,ISACC=@ISACC,SALECORP=@SALECORP,ISCRMORDERFEE=@ISCRMORDERFEE WHERE GID = @gid "; private const string SQL_INSERT_ORDERFEE = " INSERT INTO ch_fee_order(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, " + " EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, " + " TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE) " + " VALUES " + " (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, " + " @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, " + " @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@ISINVOICE,@INPUTMODE)"; private const string SQL_UPDATE_ORDERCH_FE = " UPDATE ch_fee_order SET FEENAME = @fee_name,FEEDESCRIPTION=@fee_description,CUSTOMERTYPE=@customer_type,CUSTOMERNAME = @customer_name,UNIT = @unit,UNITPRICE = @unit_price,QUANTITY = @quantity,COMMISSIONRATE = @comm_rate," + " AMOUNT = @amount,CURRENCY = @currency,EXCHANGERATE = @exchange_rate,FEEFRT = @fee_frt,REMARK = @remark,ISADVANCEDPAY = @is_advance_pay," + " WMSOUTBSNO=@WMSOUTBSNO,LINENUM=@LINENUM,TaxRate=@TAXRATE,NoTaxAmount=@NOTAXAMOUNT,AccTaxRate=@ACCTAXRATE,TAXUNITPRICE=@TAXUNITPRICE " + " WHERE GID = @gid "; #region 保存或更新“费用信息表”ch_fee,并保存或更新“利润信息”fee_gain,并返回操作结果 static public int SaveUpdateFee(IList tempFeeEntities, string tempBSNO,string tempUserID) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] validParms = new SqlParameter[] { new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36) }; foreach (MsChFee feeEntity in tempFeeEntities) { if (feeEntity.BsNo == "*" || feeEntity.BsNo == "") { SqlParameter[] parms = GetInsertParms(); parms[0].Value = feeEntity.GId; parms[1].Value = tempBSNO; parms[2].Value = feeEntity.FeeType; parms[3].Value = feeEntity.FeeName; parms[4].Value = feeEntity.FeeDescription; parms[5].Value = feeEntity.CustomerType; parms[6].Value = feeEntity.CustomerName; parms[7].Value = feeEntity.Unit; parms[8].Value = feeEntity.UnitPrice; parms[9].Value = feeEntity.Quantity; parms[10].Value = feeEntity.Amount; parms[11].Value = feeEntity.Currency; parms[12].Value = feeEntity.ExChangerate; parms[13].Value = feeEntity.Reason; parms[14].Value = feeEntity.Remark; parms[15].Value = feeEntity.Commissionrate; parms[16].Value = feeEntity.EnteroPerator; parms[17].Value = DateTime.Now; //parms[18].Value = feeEntity.IsOpen; if (feeEntity.IsOpen != null) { if (feeEntity.IsOpen == "0" || feeEntity.IsOpen == "1") { parms[18].Value = feeEntity.IsOpen; } else { if (Convert.ToBoolean(feeEntity.IsOpen)) { parms[18].Value = "1"; } else { parms[18].Value = "0"; } }; } else parms[18].Value = "0"; if (feeEntity.IsAdvancedpay != null) { if (feeEntity.IsAdvancedpay == "0" || feeEntity.IsAdvancedpay == "1") { parms[19].Value = feeEntity.IsAdvancedpay; } else { if (Convert.ToBoolean(feeEntity.IsAdvancedpay)) { parms[19].Value = "1"; } else { parms[19].Value = "0"; } }; } else parms[19].Value = "0"; parms[20].Value = feeEntity.Sort; parms[21].Value = feeEntity.FeeStatus; parms[22].Value = feeEntity.FeeFrt; parms[23].Value = feeEntity.TaxRate; parms[24].Value = feeEntity.NoTaxAmount; parms[25].Value = feeEntity.AccTaxRate; parms[26].Value = feeEntity.LineNum; parms[27].Value = feeEntity.TaxUnitPrice; parms[28].Value = tempUserID; parms[29].Value = DateTime.Now.ToString(); parms[30].Value = feeEntity.WmsOutBsNo.ToString().Trim().Equals(null) ? "" : feeEntity.WmsOutBsNo.ToString().Trim(); parms[31].Value = feeEntity.PreAmount; parms[33].Value = feeEntity.INPUTMODE; parms[34].Value = feeEntity.LOCALCURR; parms[35].Value = feeEntity.MANAGER; if (feeEntity.IsInvoice != null) { if (feeEntity.IsInvoice == "0" || feeEntity.IsInvoice == "1") { parms[32].Value = feeEntity.IsInvoice; } else { if (Convert.ToBoolean(feeEntity.IsInvoice) || feeEntity.IsInvoice == "t") { parms[32].Value = "1"; } else { parms[32].Value = "0"; } }; } else parms[32].Value = "0"; if (feeEntity.ISACC != null) { if (feeEntity.ISACC == "0" || feeEntity.ISACC == "1") { parms[36].Value = feeEntity.ISACC; } else { if (Convert.ToBoolean(feeEntity.ISACC)) { parms[36].Value = "1"; } else { parms[36].Value = "0"; } }; } else parms[36].Value = "0"; parms[37].Value = feeEntity.SALECORP; if (feeEntity.IsCrmOrderFee != null&& feeEntity.IsCrmOrderFee != "") { if (feeEntity.IsCrmOrderFee == "0" || feeEntity.IsCrmOrderFee == "1") { parms[38].Value = feeEntity.IsCrmOrderFee; } else { if (Convert.ToBoolean(feeEntity.IsCrmOrderFee)) { parms[38].Value = "1"; } else { parms[38].Value = "0"; } }; } else parms[38].Value = "0"; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE, parms); } else { SqlParameter[] updateParms = new SqlParameter[] { new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36), new SqlParameter(PARM_FEE_NAME,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_DESCRIPTION,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_CUSTOMER_TYPE,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_UNIT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_UNIT_PRICE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_FRT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_REMARK,SqlDbType.VarChar), new SqlParameter(PARM_FEE_ISADVANCEPAY,SqlDbType.VarChar,1), new SqlParameter(PARM_FEE_AUDIT_WMSOUTBSNO,SqlDbType.VarChar,100), new SqlParameter("@LINENUM",SqlDbType.Int), new SqlParameter("@TAXRATE",SqlDbType.Decimal,20), new SqlParameter("@NOTAXAMOUNT",SqlDbType.Decimal,20), new SqlParameter("@ACCTAXRATE",SqlDbType.Decimal,20), new SqlParameter("@TAXUNITPRICE",SqlDbType.Decimal,20), new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,50), new SqlParameter("@MODIFIEDTIME",SqlDbType.DateTime), new SqlParameter("@ISOPEN",SqlDbType.VarChar,1), new SqlParameter("@PREAMOUNT",SqlDbType.Decimal,20), new SqlParameter("@IsInvoice",SqlDbType.VarChar,1), new SqlParameter("@INPUTMODE",SqlDbType.VarChar,20), new SqlParameter("@LOCALCURR",SqlDbType.VarChar,30), new SqlParameter("@MANAGER",SqlDbType.VarChar,60), new SqlParameter("@ISACC",SqlDbType.VarChar,1), new SqlParameter("@SALECORP",SqlDbType.VarChar,60), new SqlParameter("@ISCRMORDERFEE",SqlDbType.VarChar,1) }; updateParms[0].Value = feeEntity.GId; updateParms[1].Value = feeEntity.FeeName; updateParms[2].Value = feeEntity.FeeDescription; updateParms[3].Value = feeEntity.CustomerType; updateParms[4].Value = feeEntity.CustomerName; updateParms[5].Value = feeEntity.Unit; updateParms[6].Value = feeEntity.UnitPrice; updateParms[7].Value = feeEntity.Quantity; updateParms[8].Value = feeEntity.Commissionrate; updateParms[9].Value = feeEntity.Amount; updateParms[10].Value = feeEntity.Currency; updateParms[11].Value = feeEntity.ExChangerate; updateParms[12].Value = feeEntity.FeeFrt; updateParms[13].Value = feeEntity.Remark; if (feeEntity.IsAdvancedpay != null) { if (feeEntity.IsAdvancedpay == "0" || feeEntity.IsAdvancedpay == "1") { updateParms[14].Value = feeEntity.IsAdvancedpay; } else { if (Convert.ToBoolean(feeEntity.IsAdvancedpay)) { updateParms[14].Value = "1"; } else { updateParms[14].Value = "0"; } } } else updateParms[14].Value = "0"; updateParms[15].Value = feeEntity.WmsOutBsNo.ToString().Trim().Equals(null) ? "" : feeEntity.WmsOutBsNo.ToString().Trim(); updateParms[16].Value = feeEntity.LineNum; updateParms[17].Value = feeEntity.TaxRate; updateParms[18].Value = feeEntity.NoTaxAmount; updateParms[19].Value = feeEntity.AccTaxRate; updateParms[20].Value = feeEntity.TaxUnitPrice; updateParms[21].Value = tempUserID; updateParms[22].Value = DateTime.Now.ToString(); if (feeEntity.IsOpen != null) { if (feeEntity.IsOpen == "0" || feeEntity.IsOpen == "1") { updateParms[23].Value = feeEntity.IsOpen; } else { if (Convert.ToBoolean(feeEntity.IsOpen)) { updateParms[23].Value = "1"; } else { updateParms[23].Value = "0"; } } } else updateParms[23].Value = "0"; updateParms[24].Value = feeEntity.PreAmount; if (feeEntity.IsInvoice != null) { if (feeEntity.IsInvoice == "0" || feeEntity.IsInvoice == "1") { updateParms[25].Value = feeEntity.IsInvoice; } else { if (Convert.ToBoolean(feeEntity.IsInvoice) || feeEntity.IsInvoice == "t") { updateParms[25].Value = "1"; } else { updateParms[25].Value = "0"; } }; } else updateParms[25].Value = "0"; updateParms[26].Value = feeEntity.INPUTMODE; updateParms[27].Value = feeEntity.LOCALCURR; updateParms[28].Value = feeEntity.MANAGER; if (feeEntity.ISACC != null) { if (feeEntity.ISACC == "0" || feeEntity.ISACC == "1") { updateParms[29].Value = feeEntity.ISACC; } else { if (Convert.ToBoolean(feeEntity.ISACC)) { updateParms[29].Value = "1"; } else { updateParms[29].Value = "0"; } } } else updateParms[29].Value = "0"; updateParms[30].Value = feeEntity.SALECORP; if (feeEntity.IsCrmOrderFee != null && feeEntity.IsCrmOrderFee != "") { if (feeEntity.IsCrmOrderFee == "0" || feeEntity.IsCrmOrderFee == "1") { updateParms[31].Value = feeEntity.IsCrmOrderFee; } else { if (Convert.ToBoolean(feeEntity.IsCrmOrderFee)) { updateParms[31].Value = "1"; } else { updateParms[31].Value = "0"; } } } else updateParms[31].Value = "0"; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FE, updateParms); } } //SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "EXEC p_op_aftersavefee '"+ tempBSNO + "'", null); sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } public static DBResult SaveFee(List bodyList, string bsno, string userid,string dbname="",bool isfeestatus=false) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); if (dbname != "") db = DatabaseFactory.CreateDatabase(dbname); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,IsInvoice,LOCALCURR,MANAGER,ISACC) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@IsInvoice,@LOCALCURR,@MANAGER,@ISACC) "); var cmdUpdate = db.GetSqlStringCommand( @"UPDATE ch_fee SET FEENAME = @fee_name,FEEDESCRIPTION=@fee_description,CUSTOMERTYPE=@customer_type,CUSTOMERNAME = @customer_name,UNIT = @unit,UNITPRICE = @unit_price,QUANTITY = @quantity,COMMISSIONRATE = @comm_rate, AMOUNT = @amount,CURRENCY = @currency,EXCHANGERATE = @exchange_rate,FEEFRT = @fee_frt,REMARK = @remark,ISADVANCEDPAY = @is_advance_pay, WMSOUTBSNO=@WMSOUTBSNO,LINENUM=@LINENUM,TaxRate=@taxrate,NoTaxAmount=@notaxamount,AccTaxRate=@acctaxrate,TAXUNITPRICE=@taxunit_price,PREAMOUNT=@PREAMOUNT ,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME,ISOPEN = @is_open,IsInvoice=@IsInvoice,LOCALCURR=@LOCALCURR,MANAGER=@MANAGER,ISACC=@ISACC WHERE GID = @gid "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.BsNo == "*" || enumValue.BsNo == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, bsno); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, enumValue.FeeType); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, enumValue.CustomerType); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, enumValue.CustomerName); db.AddInParameter(cmdInsert, "@unit", DbType.String, enumValue.Unit); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumValue.UnitPrice); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, enumValue.FeeDescription); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, enumValue.Quantity); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@currency", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, enumValue.ExChangerate); db.AddInParameter(cmdInsert, "@reason", DbType.String, enumValue.Reason); db.AddInParameter(cmdInsert, "@remark", DbType.String, enumValue.Remark); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, enumValue.Commissionrate); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, enumValue.IsOpen); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, enumValue.IsAdvancedpay); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, enumValue.Sort); if (isfeestatus) db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, enumValue.FeeStatus); else db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16,1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, enumValue.FeeFrt); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, enumValue.TaxRate); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumValue.NoTaxAmount); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, enumValue.AccTaxRate); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, enumValue.LineNum); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.TaxUnitPrice); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, enumValue.WmsOutBsNo); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, enumValue.PreAmount); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, enumValue.INPUTMODE); db.AddInParameter(cmdInsert, "@IsInvoice", DbType.String, enumValue.IsInvoice); db.AddInParameter(cmdInsert, "@LOCALCURR", DbType.String, enumValue.LOCALCURR); db.AddInParameter(cmdInsert, "@MANAGER", DbType.String, enumValue.MANAGER); db.AddInParameter(cmdInsert, "@ISACC", DbType.String, enumValue.ISACC); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@fee_name", DbType.String, enumValue.FeeName); db.AddInParameter(cmdUpdate, "@fee_description", DbType.String, enumValue.FeeDescription); db.AddInParameter(cmdUpdate, "@customer_type", DbType.String, enumValue.CustomerType); db.AddInParameter(cmdUpdate, "@customer_name", DbType.String, enumValue.CustomerName); db.AddInParameter(cmdUpdate, "@unit", DbType.String, enumValue.Unit); db.AddInParameter(cmdUpdate, "@unit_price", DbType.Decimal, enumValue.UnitPrice); db.AddInParameter(cmdUpdate, "@quantity", DbType.Decimal, enumValue.Quantity); db.AddInParameter(cmdUpdate, "@comm_rate", DbType.Decimal, enumValue.Commissionrate); db.AddInParameter(cmdUpdate, "@amount", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdUpdate, "@currency", DbType.String, enumValue.Currency); db.AddInParameter(cmdUpdate, "@exchange_rate", DbType.Decimal, enumValue.ExChangerate); db.AddInParameter(cmdUpdate, "@fee_frt", DbType.String, enumValue.FeeFrt); db.AddInParameter(cmdUpdate, "@remark", DbType.String, enumValue.Remark); db.AddInParameter(cmdUpdate, "@is_advance_pay", DbType.String, enumValue.IsAdvancedpay); db.AddInParameter(cmdUpdate, "@WMSOUTBSNO", DbType.String, enumValue.WmsOutBsNo); db.AddInParameter(cmdUpdate, "@LINENUM", DbType.Int16, enumValue.LineNum); db.AddInParameter(cmdUpdate, "@taxrate", DbType.Decimal, enumValue.TaxRate); db.AddInParameter(cmdUpdate, "@notaxamount", DbType.Decimal, enumValue.NoTaxAmount); db.AddInParameter(cmdUpdate, "@acctaxrate", DbType.Decimal, enumValue.AccTaxRate); db.AddInParameter(cmdUpdate, "@taxunit_price", DbType.Decimal, enumValue.TaxUnitPrice); db.AddInParameter(cmdUpdate, "@PREAMOUNT", DbType.Decimal, enumValue.PreAmount); db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdUpdate, "@is_open", DbType.String, enumValue.IsOpen); db.AddInParameter(cmdUpdate, "@IsInvoice", DbType.String, enumValue.IsInvoice); db.AddInParameter(cmdUpdate, "@LOCALCURR", DbType.String, enumValue.LOCALCURR); db.AddInParameter(cmdUpdate, "@MANAGER", DbType.String, enumValue.MANAGER); db.AddInParameter(cmdUpdate, "@ISACC", DbType.String, enumValue.ISACC); db.AddInParameter(cmdUpdate, "@gid", DbType.String, enumValue.GId); db.ExecuteNonQuery(cmdUpdate, tran); } } } //db.ExecuteNonQuery(tran, CommandType.Text, "EXEC p_op_aftersavefee '" + bsno + "'"); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } static public int DeleteFee(string tempGId) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { var strSql3 = new StringBuilder(); strSql3.Append("update ch_fee set WmsOutBsNo='',SETTLEMENT=0,INVOICE=0,ORDERAMOUNT=0,ORDERINVOICE=0,FEESTATUS=0,ORDERSETTLEMENT=0,ORDERINVSETTLEMENT=0 where GID IN (SELECT WmsOutBsNo FROM CH_FEE WHERE "); strSql3.Append(" GID in (" + tempGId + "))"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql3.ToString()); var strSql = new StringBuilder(); strSql.Append("Delete from ch_fee where "); strSql.Append(" GId in (" + tempGId + ")"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString()); var strSql2 = new StringBuilder(); strSql2.Append("Delete from ch_fee_do_service where "); strSql2.Append(" FEEID in (" + tempGId + ")"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString()); sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } #endregion public static int p_op_gain(string bsno,string userId) { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_op_gain"); db.AddInParameter(cmd, "@con_no", DbType.String, bsno); db.AddInParameter(cmd, "@userid", DbType.String, userId); db.ExecuteNonQuery(cmd); return 0; } #region 查询费用数据 static public List GetDataList(string strCondition,int type,string optype,string userid,string username,string companyid) { //2017年5月2日14:31:54 需求编号SR2017041800010 -2 //start string rangstr = ""; if (!optype.Equals(string.Empty)) { rangstr=GetRangDAStr(type, optype, userid, username, companyid); } //end var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,FeeStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=ch_fee.FeeStatus) as FeeStatus_Ref"); strSql.Append(",FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee.FeeType) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append("FeeDescription,CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,TAX,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate"); strSql.Append(",Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen"); strSql.Append(",(select ShowName from [user] where GID=ch_fee.EnteroPerator) as OpName"); strSql.Append(",IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum"); strSql.Append(",ChequeNum,WmsOutBsNo,LineNum,(select showname from [user] where gid=ch_fee.MODIFIEDUSER) MODIFIEDUSER,MODIFIEDTIME "); strSql.Append(",isnull(Amount,0)-isnull(INVOICE,0) UNINVOICE,PREAMOUNT,INPUTMODE "); strSql.Append(",(select showname from [user] where gid=ch_fee.Auditoperator) Auditoperatorref,LOCALCURR,MANAGER"); strSql.Append(",(select showname from [user] where gid=ch_fee.MANAGER) MANAGERREF "); strSql.Append(",(select top 1 DESCRIPTION from info_client where SHORTNAME=ch_fee.CustomerName) CustomerFullName,STATEMENTNO,SALECORP "); strSql.Append(",(select TOP 1 VOUALLNO FROM cw_vouno_bs_gl WHERE BSGID=ch_fee.GID AND BSTABLENAME='ch_fee') VOUNO,ISNULL(ISDJY,0) ISDJY,INVLINKGID "); strSql.Append(" from ch_fee "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort,LineNum "); return SetData(strSql); } static public string GetDataListStr(string strCondition, int type, string optype, string userid, string username, string companyid) { //2017年5月2日14:31:54 需求编号SR2017041800010 -2 //start string rangstr = ""; if (!optype.Equals(string.Empty)) { rangstr = GetRangDAStr(type, optype, userid, username, companyid); } //end var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,FeeStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=ch_fee.FeeStatus) as FeeStatus_Ref"); strSql.Append(",FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee.FeeType) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append("FeeDescription,CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,TAX,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate"); strSql.Append(",Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen"); strSql.Append(",(select ShowName from [user] where GID=ch_fee.EnteroPerator) as OpName"); strSql.Append(",IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum"); strSql.Append(",ChequeNum,WmsOutBsNo,LineNum,(select showname from [user] where gid=ch_fee.MODIFIEDUSER) MODIFIEDUSER,MODIFIEDTIME "); strSql.Append(",isnull(Amount,0)-isnull(INVOICE,0) UNINVOICE,PREAMOUNT,INPUTMODE "); strSql.Append(",(select showname from [user] where gid=ch_fee.Auditoperator) Auditoperatorref,LOCALCURR,MANAGER"); strSql.Append(",(select showname from [user] where gid=ch_fee.MANAGER) MANAGERREF "); strSql.Append(",(select top 1 DESCRIPTION from info_client where SHORTNAME=ch_fee.CustomerName) CustomerFullName,STATEMENTNO,SALECORP "); strSql.Append(",(select TOP 1 VOUALLNO FROM cw_vouno_bs_gl WHERE BSGID=ch_fee.GID AND BSTABLENAME='ch_fee') VOUNO,ISNULL(ISDJY,0) ISDJY,INVLINKGID "); strSql.Append(" from ch_fee "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort,LineNum "); return strSql.ToString(); } static public List GetAllDataList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,FeeStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=ch_fee.FeeStatus) as FeeStatus_Ref"); strSql.Append(",FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee.FeeType) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append("FeeDescription,CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,TAX,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate"); strSql.Append(",Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen"); strSql.Append(",(select ShowName from [user] where GID=ch_fee.EnteroPerator) as OpName"); strSql.Append(",IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum"); strSql.Append(",ChequeNum,WmsOutBsNo,LineNum,(select showname from [user] where gid=ch_fee.MODIFIEDUSER) MODIFIEDUSER,MODIFIEDTIME "); strSql.Append(",isnull(Amount,0)-isnull(INVOICE,0) UNINVOICE,PREAMOUNT,INPUTMODE "); strSql.Append(",(select showname from [user] where gid=ch_fee.Auditoperator) Auditoperatorref,LOCALCURR,MANAGER "); strSql.Append(",(select showname from [user] where gid=ch_fee.MANAGER) MANAGERREF "); strSql.Append(",(select top 1 DESCRIPTION from info_client where SHORTNAME=ch_fee.CustomerName) CustomerFullName,STATEMENTNO,SALECORP "); strSql.Append(",(select TOP 1 VOUALLNO FROM cw_vouno_bs_gl WHERE BSGID=ch_fee.GID AND BSTABLENAME='ch_fee') VOUNO,ISNULL(ISDJY,0) ISDJY,INVLINKGID "); strSql.Append(" from ch_fee "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort,LineNum "); return SetData(strSql); } private static List SetData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsChFee data = new MsChFee(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.BsNo = Convert.ToString(reader["BsNo"]); if (reader["FeeStatus"] != DBNull.Value) data.FeeStatus = Convert.ToInt16(reader["FeeStatus"]); data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]); if (reader["FeeType"] != DBNull.Value) data.FeeType = Convert.ToDecimal(reader["FeeType"]); // data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]); data.FeeName = Convert.ToString(reader["FeeName"]); // data.FeeName_Ref = Convert.ToString(reader["FeeName_Ref"]); data.FeeDescription = Convert.ToString(reader["FeeDescription"]); data.CustomerType = Convert.ToString(reader["CustomerType"]); data.CustomerName = Convert.ToString(reader["CustomerName"]); data.CustomerFullName = Convert.ToString(reader["CustomerFullName"]); // data.CustomerName_Ref = Convert.ToString(reader["CustomerName_Ref"]); data.Unit = Convert.ToString(reader["Unit"]); if (reader["UnitPrice"] != DBNull.Value) data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]); if (reader["TaxUnitPrice"] != DBNull.Value) data.TaxUnitPrice = Convert.ToDecimal(reader["TaxUnitPrice"]); if (reader["Quantity"] != DBNull.Value) data.Quantity = Convert.ToDecimal(reader["Quantity"]); if (reader["TaxRate"] != DBNull.Value) data.TaxRate = Convert.ToDecimal(reader["TaxRate"]); if (reader["NoTaxAmount"] != DBNull.Value) data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]); if (reader["Amount"] != DBNull.Value) data.Amount = Convert.ToDecimal(reader["Amount"]); if (reader["AccTaxRate"] != DBNull.Value) data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]); data.Currency = Convert.ToString(reader["Currency"]); if (reader["ExChangerate"] != DBNull.Value) data.ExChangerate = Convert.ToDecimal(reader["ExChangerate"]); if (data.AccTaxRate != 0) { data.AccTax = Math.Round(data.Amount/(1+ data.AccTaxRate / 100) * data.AccTaxRate / 100, 2, MidpointRounding.AwayFromZero); } if (reader["TAX"] != DBNull.Value) data.Tax = Convert.ToDecimal(reader["TAX"]); if (data.Tax==0&&data.TaxRate != 0 && data.NoTaxAmount != 0) { data.Tax = Math.Round(data.Amount-data.NoTaxAmount, 2, MidpointRounding.AwayFromZero); } data.AccAmount = data.Amount - data.AccTax; data.Reason = Convert.ToString(reader["Reason"]); data.Remark = Convert.ToString(reader["Remark"]); if (reader["Commissionrate"] != DBNull.Value) data.Commissionrate = Convert.ToDecimal(reader["Commissionrate"]); if (reader["Settlement"] != DBNull.Value) data.Settlement = Convert.ToDecimal(reader["Settlement"]); if (reader["Invoice"] != DBNull.Value) data.Invoice = Convert.ToDecimal(reader["Invoice"]); if (reader["OrderAmount"] != DBNull.Value) data.OrderAmount = Convert.ToDecimal(reader["OrderAmount"]); if (reader["OrderInvoice"] != DBNull.Value) data.OrderInvoice = Convert.ToDecimal(reader["OrderInvoice"]); if (reader["SubmitDate"] != DBNull.Value) data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.Auditoperator = Convert.ToString(reader["Auditoperatorref"]); if (reader["AuditDate"] != DBNull.Value) data.AuditDate = Convert.ToDateTime(reader["AuditDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.EnteroPerator = Convert.ToString(reader["EnteroPerator"]); data.OpName = Convert.ToString(reader["OpName"]); if (reader["EnterDate"] != DBNull.Value) data.EnterDate = Convert.ToDateTime(reader["EnterDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.DebitNo = Convert.ToString(reader["DebitNo"]); data.IsDebit = Convert.ToString(reader["IsDebit"]); if (reader["IsOpen"] != DBNull.Value && Convert.ToBoolean(reader["IsOpen"]) == true) data.IsOpen ="1"; if (reader["IsAdvancedpay"] != DBNull.Value && Convert.ToBoolean(reader["IsAdvancedpay"]) == true) data.IsAdvancedpay ="1"; if (reader["Sort"] != DBNull.Value) data.Sort = Convert.ToString(reader["Sort"]); if (reader["IsInvoice"] != DBNull.Value) if (Convert.ToBoolean(reader["IsInvoice"]) == true) data.IsInvoice = "1"; data.FeeFrt = Convert.ToString(reader["FeeFrt"]); if (reader["IsCrmOrderFee"] != DBNull.Value) data.IsCrmOrderFee = Convert.ToString(reader["IsCrmOrderFee"]); if (reader["AuditStatus"] != DBNull.Value) data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]); data.InvoiceNum = Convert.ToString(reader["InvoiceNum"]); data.ChequeNum = Convert.ToString(reader["ChequeNum"]); data.WmsOutBsNo = Convert.ToString(reader["WmsOutBsNo"]); if (reader["LineNum"] != DBNull.Value) data.LineNum = Convert.ToDecimal(reader["LineNum"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); if (reader["UNINVOICE"] != DBNull.Value) data.UNINVOICE = Convert.ToDecimal(reader["UNINVOICE"]); if (reader["PREAMOUNT"] != DBNull.Value) data.PreAmount= Convert.ToDecimal(reader["PREAMOUNT"]); //if (reader["PREAMOUNTTTL"] != DBNull.Value) // data.PreAmountttl = Convert.ToDecimal(reader["PREAMOUNTTTL"]); data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]); data.LOCALCURR = Convert.ToString(reader["LOCALCURR"]); data.MANAGER = Convert.ToString(reader["MANAGER"]); data.MANAGERREF = Convert.ToString(reader["MANAGERREF"]); data.STATEMENTNO= Convert.ToString(reader["STATEMENTNO"]); data.VOUALLNO = Convert.ToString(reader["VOUNO"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); if (reader["ISDJY"] != DBNull.Value) data.ISDJY = Convert.ToBoolean(reader["ISDJY"]); data.INVLINKGID = Convert.ToString(reader["INVLINKGID"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } public static List SetYjData(List bodyList, string yffeename) { MsChFee hyfdata = new MsChFee(); MsChFee yjdata = new MsChFee(); foreach (var enumValue in bodyList) { if (enumValue.FeeName == "海运费") { hyfdata = enumValue; } } if (hyfdata.FeeName != "") { foreach (var enumValue in bodyList) { if (enumValue.FeeName == yffeename&&enumValue.IsOpen=="1") { yjdata = enumValue; } } if (yjdata.FeeName != "") { if (yjdata.Currency == hyfdata.Currency&&yjdata.Quantity == hyfdata.Quantity) { var j = 0; foreach (var enumValue in bodyList) { if (enumValue==hyfdata) { bodyList[j].UnitPrice = bodyList[j].UnitPrice + yjdata.UnitPrice; bodyList[j].Amount = bodyList[j].Amount + yjdata.Amount; bodyList[j].NoTaxAmount = bodyList[j].NoTaxAmount + yjdata.NoTaxAmount; bodyList[j].TaxUnitPrice = bodyList[j].TaxUnitPrice + yjdata.TaxUnitPrice; bodyList[j].Tax = bodyList[j].Tax + yjdata.Tax; bodyList[j].Settlement = bodyList[j].Settlement + yjdata.Settlement; bodyList[j].Invoice = bodyList[j].Invoice + yjdata.Invoice; bodyList[j].OrderAmount = bodyList[j].OrderAmount + yjdata.OrderAmount; bodyList[j].OrderInvoice = bodyList[j].OrderInvoice + yjdata.OrderInvoice; } j = j + 1; } bodyList.Remove(yjdata); } else { var j = 0; foreach (var enumValue in bodyList) { if (enumValue == yjdata) { bodyList[j].FeeName = "海运费"; } j = j + 1; } } } } else { var j = 0; foreach (var enumValue in bodyList) { if (enumValue == yjdata) { bodyList[j].FeeName = "海运费"; } j = j + 1; } } return bodyList; } #endregion #region 查询费用数据(进口贸易,增加两个字段,销售单和出库单) static public List GetImportDataList ( string strCondition, int type, string optype, string userid, string username, string companyid ) { var rangstr = GetRangDAStr(type, optype, userid, username, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,FeeStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=ch_fee.FeeStatus) as FeeStatus_Ref"); strSql.Append(",FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee.FeeType) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append("FeeDescription,CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate"); strSql.Append(",Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen"); strSql.Append(",(select ShowName from [user] where GID=ch_fee.EnteroPerator) as OpName"); strSql.Append(",IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum"); strSql.Append(",ChequeNum,WmsOutBsNo,LineNum,(select showname from [user] where gid=ch_fee.MODIFIEDUSER) MODIFIEDUSER,MODIFIEDTIME "); strSql.Append(",isnull(Amount,0)-isnull(INVOICE,0) UNINVOICE,SALESNO,DELIVERYNO "); strSql.Append(" from ch_fee "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort,LineNum "); return SetImportData(strSql); } private static List SetImportData ( StringBuilder strSql ) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsChFeeImport data = new MsChFeeImport(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.BsNo = Convert.ToString(reader["BsNo"]); data.FeeStatus = Convert.ToInt16(reader["FeeStatus"]); data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]); data.FeeType = Convert.ToDecimal(reader["FeeType"]); // data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]); data.FeeName = Convert.ToString(reader["FeeName"]); // data.FeeName_Ref = Convert.ToString(reader["FeeName_Ref"]); data.FeeDescription = Convert.ToString(reader["FeeDescription"]); data.CustomerType = Convert.ToString(reader["CustomerType"]); data.CustomerName = Convert.ToString(reader["CustomerName"]); // data.CustomerName_Ref = Convert.ToString(reader["CustomerName_Ref"]); data.Unit = Convert.ToString(reader["Unit"]); data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]); if (reader["TaxUnitPrice"] != DBNull.Value) data.TaxUnitPrice = Convert.ToDecimal(reader["TaxUnitPrice"]); data.Quantity = Convert.ToDecimal(reader["Quantity"]); if (reader["TaxRate"] != DBNull.Value) data.TaxRate = Convert.ToDecimal(reader["TaxRate"]); if (reader["NoTaxAmount"] != DBNull.Value) data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]); data.Amount = Convert.ToDecimal(reader["Amount"]); if (reader["AccTaxRate"] != DBNull.Value) data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]); data.Currency = Convert.ToString(reader["Currency"]); data.ExChangerate = Convert.ToDecimal(reader["ExChangerate"]); data.Reason = Convert.ToString(reader["Reason"]); data.Remark = Convert.ToString(reader["Remark"]); data.Commissionrate = Convert.ToDecimal(reader["Commissionrate"]); data.Settlement = Convert.ToDecimal(reader["Settlement"]); if (reader["Invoice"] != DBNull.Value) data.Invoice = Convert.ToDecimal(reader["Invoice"]); data.OrderAmount = Convert.ToDecimal(reader["OrderAmount"]); data.OrderInvoice = Convert.ToDecimal(reader["OrderInvoice"]); if (reader["SubmitDate"] != DBNull.Value) data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.Auditoperator = Convert.ToString(reader["Auditoperator"]); if (reader["AuditDate"] != DBNull.Value) data.AuditDate = Convert.ToDateTime(reader["AuditDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.EnteroPerator = Convert.ToString(reader["EnteroPerator"]); data.OpName = Convert.ToString(reader["OpName"]); if (reader["EnterDate"] != DBNull.Value) data.EnterDate = Convert.ToDateTime(reader["EnterDate"]).ToString("yyyy-MM-dd HH:mm:ss"); data.DebitNo = Convert.ToString(reader["DebitNo"]); data.IsDebit = Convert.ToString(reader["IsDebit"]); data.IsOpen = Convert.ToString(reader["IsOpen"]); data.IsAdvancedpay = Convert.ToString(reader["IsAdvancedpay"]); data.Sort = Convert.ToString(reader["Sort"]); data.IsInvoice = Convert.ToString(reader["IsInvoice"]); data.FeeFrt = Convert.ToString(reader["FeeFrt"]); data.IsCrmOrderFee = Convert.ToString(reader["IsCrmOrderFee"]); data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]); data.InvoiceNum = Convert.ToString(reader["InvoiceNum"]); data.ChequeNum = Convert.ToString(reader["ChequeNum"]); data.WmsOutBsNo = Convert.ToString(reader["WmsOutBsNo"]); data.LineNum = Convert.ToDecimal(reader["LineNum"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.UNINVOICE = Convert.ToDecimal(reader["UNINVOICE"]); data.SALESNO = Convert.ToString(reader["SALESNO"]); data.DELIVERYNO = Convert.ToString(reader["DELIVERYNO"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region fee_gain static public List GetDataGainList(string strCondition, string userid, string username, string companyid,string optype) { var rangstr = ""; var FEETOTALRANGESAMEFEEDETAIL = MsSysParamSetDAL.GetData("PARAMNAME='FEETOTALRANGESAMEFEEDETAIL'"); if (FEETOTALRANGESAMEFEEDETAIL.PARAMVALUE == "1") { var rangstrdr = MsChFeeDAL.GetFeeRangeSqlStr(1, optype, userid, username, companyid); rangstrdr = "("+rangstrdr + " and FEETYPE=1 )"; var rangstrcr = MsChFeeDAL.GetFeeRangeSqlStr(2, optype, userid, username, companyid); rangstrcr = "(" + rangstrcr + " and FEETYPE=2 )"; rangstr = "("+ rangstrdr +" or "+ rangstrcr + ")"; } else { rangstr = GetSumRangDAStr(userid, username, companyid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { #region 2018年2月7日15:54:52 李进举 鼎世 if (nopowerOpen.PARAMVALUE == "0") { //配置否,则走正常机密费用逻辑 isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } #endregion } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" '' GId,BsNo,CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN 1 ELSE 0 END),0) AS DRC"); strSql.Append(" from v_ch_fee_gain "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by BsNo,CUSTOMERNAME "); strSql.Append("UNION SELECT "); strSql.Append(" '1' GId,'' BsNo,'合计' CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("100 AS DRC"); strSql.Append(" from v_ch_fee_gain "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } // strSql.Append("Group by BsNo ORDER BY GId,DRC "); return SetGainData(strSql, FeenotPr); } static public List GetDataGainTTLList(string strCondition, string userid, string username, string companyid,string optype) { var rangstr = ""; var FEETOTALRANGESAMEFEEDETAIL = MsSysParamSetDAL.GetData("PARAMNAME='FEETOTALRANGESAMEFEEDETAIL'"); if (FEETOTALRANGESAMEFEEDETAIL.PARAMVALUE == "1") { var rangstrdr = MsChFeeDAL.GetFeeRangeSqlStr(1, optype, userid, username, companyid); rangstrdr = "(" + rangstrdr + " and FEETYPE=1 )"; var rangstrcr = MsChFeeDAL.GetFeeRangeSqlStr(2, optype, userid, username, companyid); rangstrcr = "(" + rangstrcr + " and FEETYPE=2 )"; rangstr = "(" + rangstrdr + " or " + rangstrcr + ")"; } else { rangstr = GetSumRangDAStr(userid, username, companyid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { #region 2018年2月7日15:54:52 李进举 鼎世 if (nopowerOpen.PARAMVALUE == "0") { //配置否,则走正常机密费用逻辑 isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } #endregion } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" '' GId,G.BsNo,G.CUSTOMERNAME+'('+B.OPTYPE+')' AS CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("isnull(SUM(CASE B.OPTYPE WHEN '普通货' THEN 0 ELSE 1 END),0) AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bill B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by G.BsNo,G.CUSTOMERNAME,B.CUSTNO,B.OPTYPE "); strSql.Append("UNION SELECT "); strSql.Append(" '1' GId,B.PARENTID BsNo,'合计' CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("100 AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bill B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by B.PARENTID ORDER BY GId,DRC "); return SetGainData(strSql, FeenotPr); } static public List GetDataAmendGainList(string strCondition, string userid, string username, string companyid) { var rangstr = GetSumRangDAStr(userid, username, companyid); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopenstr = ""; if (isopen == false) { if (nopowerOpen.PARAMVALUE == "0") { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" '' GId,G.BsNo,B.CUSTNO+'('+B.OPTYPE+')' AS CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("isnull(SUM(CASE B.OPTYPE WHEN '普通货' THEN 0 ELSE 1 END),0) AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bill B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by G.BsNo,B.CUSTNO,B.OPTYPE "); strSql.Append("UNION SELECT "); strSql.Append(" '1' GId,'' BsNo,'合计' CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("100 AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bill B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } // strSql.Append("Group by B.PARENTID ORDER BY GId,DRC "); strSql.Append(" ORDER BY GId,DRC "); return SetGainData(strSql, FeenotPr); } static public List GetDataMasterGainList(string strCondition, string userid, string username, string companyid) { var rangstr = GetSumRangDAStr(userid, username, companyid); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopenstr = ""; if (isopen == false) { if (nopowerOpen.PARAMVALUE == "0") { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" '' GId,G.BsNo,B.CUSTNO+'('+B.BLTYPE+')' AS CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("isnull(SUM(CASE WHEN B.BLTYPE IN ('拼箱分票','合票分票') THEN 0 ELSE 1 END),0) AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bs B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by G.BsNo,B.CUSTNO,B.BLTYPE "); strSql.Append("UNION SELECT "); strSql.Append(" '1' GId,B.MASTERNO BsNo,'合计' CUSTOMERNAME,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,"); strSql.Append("100 AS DRC"); strSql.Append(" from v_ch_fee_gain G "); strSql.Append(" left join v_op_bs B on (B.BSNO=G.BSNO) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append("Group by B.MASTERNO ORDER BY GId,DRC "); return SetGainData(strSql, FeenotPr); } private static List SetGainData(StringBuilder strSql,bool isnotpr) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsChFeeGain data = new MsChFeeGain(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.BsNo = Convert.ToString(reader["BsNo"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); data.USDDR = Convert.ToDecimal(reader["USDDR"]); data.USDCR = Convert.ToDecimal(reader["USDCR"]); data.OTDR = Convert.ToDecimal(reader["OTDR"]); data.OTCR = Convert.ToDecimal(reader["OTCR"]); data.TTLDR =Math.Round(Convert.ToDecimal(reader["TTLDR"]),2, MidpointRounding.AwayFromZero); data.TTLCR =Math.Round(Convert.ToDecimal(reader["TTLCR"]),2, MidpointRounding.AwayFromZero); if (isnotpr) { data.RMBPROFIT ="***"; data.USDPROFIT = "***"; data.OTPROFIT = "***"; data.TTLPROFIT = "***"; } else { data.RMBPROFIT = Convert.ToString(data.RMBDR - data.RMBCR); data.USDPROFIT = Convert.ToString(data.USDDR - data.USDCR); data.OTPROFIT = Convert.ToString(data.OTDR - data.OTCR); data.TTLPROFIT = Convert.ToString(data.TTLDR - data.TTLCR); } #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } static public List GetOPGainList(string strCondition, string userid, string username, string companyid,string localcurr,string optype) { var rangstr = ""; var FEETOTALRANGESAMEFEEDETAIL = MsSysParamSetDAL.GetData("PARAMNAME='FEETOTALRANGESAMEFEEDETAIL'"); if (FEETOTALRANGESAMEFEEDETAIL.PARAMVALUE == "1") { var rangstrdr = MsChFeeDAL.GetFeeRangeSqlStr(1, optype, userid, username, companyid); rangstrdr = "(" + rangstrdr + " and FEETYPE=1 )"; var rangstrcr = MsChFeeDAL.GetFeeRangeSqlStr(2, optype, userid, username, companyid); rangstrcr = "(" + rangstrcr + " and FEETYPE=2 )"; rangstr = "(" + rangstrdr + " or " + rangstrcr + ")"; } else { rangstr = GetSumRangDAStr(userid, username, companyid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { #region 2018年2月7日15:54:52 李进举 鼎世 if (nopowerOpen.PARAMVALUE == "0") { //配置否,则走正常机密费用逻辑 isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } #endregion } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" '' BsNo,1 BLCOUNT,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS DRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS CRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXDRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXCRTTL"); strSql.Append(",cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN CASE WHEN ISNULL(ACCTAXRATE, 0) = 0 THEN ISNULL(AMOUNT, 0) ELSE ISNULL(AMOUNT, 0) - cast(round((ISNULL(AMOUNT, 0) / (1 + ACCTAXRATE / 100) * ACCTAXRATE / 100), 2) as numeric(20, 2)) END * ISNULL(EXCHANGERATE, 0) ELSE 0 END), 0), 2) as numeric(20, 2)) AS NOACCTAXTTLDR"); strSql.Append(",cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN CASE WHEN ISNULL(ACCTAXRATE, 0) = 0 THEN ISNULL(AMOUNT, 0) ELSE ISNULL(AMOUNT, 0) - cast(round((ISNULL(AMOUNT, 0) / (1 + ACCTAXRATE / 100) * ACCTAXRATE / 100), 2) as numeric(20, 2)) END * ISNULL(EXCHANGERATE, 0) ELSE 0 END), 0), 2) as numeric(20, 2)) AS NOACCTAXTTLCR"); strSql.Append(" from v_ch_fee_gain "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } //strSql.Append(" GROUP BY BsNo "); return SetOPGainData(strSql, localcurr, FeenotPr); } static public List GetOPGainAMENDList(string strCondition, string userid, string username, string companyid, string localcurr) { var rangstr = GetSumRangDAStr(userid, username, companyid); var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { #region 2018年2月7日15:54:52 李进举 鼎世 if (nopowerOpen.PARAMVALUE == "0") { //配置否,则走正常机密费用逻辑 isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } else { //配置是,则不走机密费用逻辑 rangstr = " 1 = 1 "; } #endregion } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("B.PARENTID BsNo,COUNT(distinct f.bsno) BLCOUNT,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS DRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS CRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE WHEN (CURRENCY='RMB' AND (LOCALCURR='' OR LOCALCURR IS NULL)) OR (CURRENCY=LOCALCURR) THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXDRTTL"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXCRTTL"); strSql.Append(",cast(round(isnull(SUM(CASE FEETYPE WHEN 1 THEN CASE WHEN ISNULL(ACCTAXRATE, 0) = 0 THEN ISNULL(AMOUNT, 0) ELSE ISNULL(AMOUNT, 0) - cast(round((ISNULL(AMOUNT, 0) / (1 + ACCTAXRATE / 100) * ACCTAXRATE / 100), 2) as numeric(20, 2)) END * ISNULL(EXCHANGERATE, 0) ELSE 0 END), 0), 2) as numeric(20, 2)) AS NOACCTAXTTLDR"); strSql.Append(",cast(round(isnull(SUM(CASE FEETYPE WHEN 2 THEN CASE WHEN ISNULL(ACCTAXRATE, 0) = 0 THEN ISNULL(AMOUNT, 0) ELSE ISNULL(AMOUNT, 0) - cast(round((ISNULL(AMOUNT, 0) / (1 + ACCTAXRATE / 100) * ACCTAXRATE / 100), 2) as numeric(20, 2)) END * ISNULL(EXCHANGERATE, 0) ELSE 0 END), 0), 2) as numeric(20, 2)) AS NOACCTAXTTLCR"); strSql.Append(" from v_ch_fee_gain f "); strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" GROUP BY B.PARENTID "); return SetOPGainData(strSql, localcurr, FeenotPr); } private static List SetOPGainData(StringBuilder strSql,string localcurr,bool isnotpr) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpGain data = new MsOpGain(); #region Set DB data to Object data.CURR = localcurr; if (reader["BLCOUNT"] != DBNull.Value) { var blcount = Convert.ToInt32(reader["BLCOUNT"]); if (blcount >= 2) data.AMENDSTR = "包含更改单"; } if (reader["NOTAXRMBDR"] != DBNull.Value) data.NORATEDR = Convert.ToDecimal(reader["NOTAXRMBDR"]); data.DR = Convert.ToDecimal(reader["RMBDR"]); if (reader["NOTAXRMBCR"] != DBNull.Value) data.NORATECR = Convert.ToDecimal(reader["NOTAXRMBCR"]); data.CR = Convert.ToDecimal(reader["RMBCR"]); if (isnotpr) { data.NORATEPR = "***"; data.PR = "***"; } else { data.NORATEPR = Convert.ToString(data.NORATEDR - data.NORATECR); data.PR = Convert.ToString(data.DR - data.CR); } #endregion bodyList.Add(data); MsOpGain dataUsd = new MsOpGain(); #region Set DB data to Object if (reader["BLCOUNT"] != DBNull.Value) { var blcount = Convert.ToInt32(reader["BLCOUNT"]); if (blcount >= 2) dataUsd.AMENDSTR = "包含更改单"; } dataUsd.CURR = "USD"; if (reader["NOTAXUSDDR"] != DBNull.Value) dataUsd.NORATEDR = Convert.ToDecimal(reader["NOTAXUSDDR"]); dataUsd.DR = Convert.ToDecimal(reader["USDDR"]); if (reader["NOTAXUSDCR"] != DBNull.Value) dataUsd.NORATECR = Convert.ToDecimal(reader["NOTAXUSDCR"]); dataUsd.CR = Convert.ToDecimal(reader["USDCR"]); if (isnotpr) { dataUsd.NORATEPR = "***"; dataUsd.PR = "***"; } else { dataUsd.NORATEPR = Convert.ToString(dataUsd.NORATEDR - dataUsd.NORATECR); dataUsd.PR = Convert.ToString(dataUsd.DR - dataUsd.CR); } #endregion bodyList.Add(dataUsd); MsOpGain dataot = new MsOpGain(); #region Set DB data to Object dataot.CURR = "其他币别"; if (reader["BLCOUNT"] != DBNull.Value) { var blcount = Convert.ToInt32(reader["BLCOUNT"]); if (blcount >= 2) dataot.AMENDSTR = "包含更改单"; } if (reader["NOTAXOTDR"] != DBNull.Value) dataot.NORATEDR = Convert.ToDecimal(reader["NOTAXOTDR"]); dataot.DR = Convert.ToDecimal(reader["OTDR"]); if (reader["NOTAXOTCR"] != DBNull.Value) dataot.NORATECR = Convert.ToDecimal(reader["NOTAXOTCR"]); dataot.CR = Convert.ToDecimal(reader["OTCR"]); if (isnotpr) { dataot.NORATEPR = "***"; dataot.PR = "***"; } else { dataot.NORATEPR = Convert.ToString(dataot.NORATEDR - dataot.NORATECR); dataot.PR = Convert.ToString(dataot.DR - dataot.CR); } #endregion bodyList.Add(dataot); MsOpGain datattl = new MsOpGain(); #region Set DB data to Object if (reader["BLCOUNT"] != DBNull.Value) { var blcount = Convert.ToInt32(reader["BLCOUNT"]); if (blcount >= 2) datattl.AMENDSTR = "包含更改单"; } datattl.CURR = "合计"; if (reader["NOTAXDRTTL"] != DBNull.Value) datattl.NORATEDR = Math.Round(Convert.ToDecimal(reader["NOTAXDRTTL"]), 2, MidpointRounding.AwayFromZero); datattl.DR = Math.Round(Convert.ToDecimal(reader["DRTTL"]),2, MidpointRounding.AwayFromZero); if (reader["NOTAXCRTTL"] != DBNull.Value) datattl.NORATECR = Math.Round(Convert.ToDecimal(reader["NOTAXCRTTL"]), 2, MidpointRounding.AwayFromZero); datattl.CR = Math.Round(Convert.ToDecimal(reader["CRTTL"]), 2, MidpointRounding.AwayFromZero); if (reader["NOACCTAXTTLDR"] != DBNull.Value) datattl.NOACCTAXRATEDR = Math.Round(Convert.ToDecimal(reader["NOACCTAXTTLDR"]), 2, MidpointRounding.AwayFromZero); if (reader["NOACCTAXTTLCR"] != DBNull.Value) datattl.NOACCTAXRATECR = Math.Round(Convert.ToDecimal(reader["NOACCTAXTTLCR"]), 2, MidpointRounding.AwayFromZero); datattl.ACCTAXDR = datattl.DR - datattl.NOACCTAXRATEDR; datattl.ACCTAXCR = datattl.CR - datattl.NOACCTAXRATECR; if (isnotpr) { datattl.NORATEPR = "***"; datattl.PR = "***"; datattl.PROFITRATE = 0; } else { datattl.NORATEPR = Convert.ToString(datattl.NORATEDR - datattl.NORATECR); datattl.PR = Convert.ToString(datattl.DR - datattl.CR); if (PROFITRATEDR.PARAMVALUE != "1") { if (datattl.DR == 0) datattl.PROFITRATE = 0; else datattl.PROFITRATE = Math.Round(Convert.ToDecimal(datattl.PR) / datattl.DR * 100, 2, MidpointRounding.AwayFromZero); } else { if (datattl.CR == 0) datattl.PROFITRATE = 0; else datattl.PROFITRATE = Math.Round(Convert.ToDecimal(datattl.PR) / datattl.CR * 100, 2, MidpointRounding.AwayFromZero); } } #endregion bodyList.Add(datattl); } reader.Close(); } if (bodyList.Count == 0) { MsOpGain data = new MsOpGain(); #region Set DB data to Object data.CURR = localcurr; data.NORATEDR =0; data.DR = 0; data.NORATECR =0; data.CR =0; data.NORATEPR ="0"; data.PR ="0"; #endregion bodyList.Add(data); MsOpGain dataUsd = new MsOpGain(); #region Set DB data to Object dataUsd.CURR = "USD"; dataUsd.NORATEDR =0; dataUsd.DR =0; dataUsd.NORATECR =0; dataUsd.CR =0; dataUsd.NORATEPR ="0"; dataUsd.PR ="0"; #endregion bodyList.Add(dataUsd); MsOpGain dataot = new MsOpGain(); #region Set DB data to Object dataot.CURR = "其他币别"; dataot.NORATEDR =0; dataot.DR =0; dataot.NORATECR =0; dataot.CR = 0; dataot.NORATEPR ="0"; dataot.PR ="0"; #endregion bodyList.Add(dataot); MsOpGain datattl = new MsOpGain(); #region Set DB data to Object datattl.CURR = "合计"; datattl.NORATEDR =0; datattl.DR =0; datattl.NORATECR =0; datattl.CR =0; datattl.NORATEPR ="0"; datattl.PR ="0"; #endregion bodyList.Add(datattl); } return bodyList; } static public List GetMBLGainList(string strCondition, string userid, string username, string companyid) { var rangstr = GetSumRangDAStr(userid, username, companyid); var FeenotPr = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotPr", userid); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("CURRENCY,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE ISNULL(-AMOUNT,0) END),0) AS PR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END),0) AS NOTAXDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END),0) AS NOTAXCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) ELSE ISNULL(-NOTAXAMOUNT,0) END),0) AS NOTAXPR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT*EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT*EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END),0) AS BALDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END),0) AS BALCR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL((AMOUNT-SETTLEMENT)*EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR"); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL((AMOUNT-SETTLEMENT)*EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR"); strSql.Append(" from v_ch_fee_gain "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" GROUP BY CURRENCY "); return SetOPGainData2(strSql, FeenotPr); } private static List SetOPGainData2(StringBuilder strSql, bool isnotpr) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); var PROFITRATEDR = MsSysParamSetDAL.GetData("PARAMNAME='PROFITRATEDR'"); decimal ttldr = 0; decimal ttlbaldr = 0; decimal ttlcr = 0; using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpGain data = new MsOpGain(); #region Set DB data to Object data.CURR = Convert.ToString(reader["CURRENCY"]); if (reader["NOTAXDR"] != DBNull.Value) data.NORATEDR = Convert.ToDecimal(reader["NOTAXDR"]); if (reader["DR"] != DBNull.Value) data.DR = Convert.ToDecimal(reader["DR"]); if (reader["NOTAXCR"] != DBNull.Value) data.NORATECR = Convert.ToDecimal(reader["NOTAXCR"]); if (reader["CR"] != DBNull.Value) data.CR = Convert.ToDecimal(reader["CR"]); if (reader["BALDR"] != DBNull.Value) data.BALDR = Convert.ToDecimal(reader["BALDR"]); if (reader["TTLDR"] != DBNull.Value) ttldr =ttldr+ Convert.ToDecimal(reader["TTLDR"]); if (reader["TTLCR"] != DBNull.Value) ttlcr = ttlcr + Convert.ToDecimal(reader["TTLCR"]); if (reader["BALTTLDR"] != DBNull.Value) ttlbaldr = ttlbaldr + Convert.ToDecimal(reader["BALTTLDR"]); if (isnotpr) { data.NORATEPR = "***"; data.PR = "***"; } else { data.PR = Convert.ToString(data.DR - data.CR); data.NORATEPR = Convert.ToString(data.NORATEDR - data.NORATECR); } #endregion data = SetUSDPROFIT(data); bodyList.Add(data); } reader.Close(); MsOpGain dataUsd = new MsOpGain(); #region Set DB data to Object dataUsd.CURR = "TTL"; dataUsd.NORATEDR = 0; dataUsd.DR = ttldr; dataUsd.NORATECR = 0; dataUsd.CR = ttlcr; dataUsd.BALDR = ttlbaldr; if (isnotpr) { dataUsd.PR = "***"; dataUsd.NORATEPR = "***"; } else { dataUsd.PR = Convert.ToString(ttldr - ttlcr); dataUsd.NORATEPR = Convert.ToString(ttldr - ttlcr); } #endregion dataUsd = SetUSDPROFIT(dataUsd); bodyList.Add(dataUsd); } return bodyList; } /// ///20220715 如果这行币别是USD,复制到USEPROFIT ///如果是RMB或TTL 通过汇率折算成美元 无可用汇率则写0 ///如果是其他币别 通过汇率折算成RMB再折美元 无可用汇率则写0 /// /// /// private static MsOpGain SetUSDPROFIT(MsOpGain dataitem) { if (dataitem.CURR == "USD") { dataitem.USDPROFIT = dataitem.PR; }else if (dataitem.CURR == "RMB"|| dataitem.CURR == "TTL") { var _pr = Convert.ToDecimal(dataitem.PR); var rate = GetCurrencyExchangerate("USD"); if (rate == 0) { dataitem.USDPROFIT = "0"; } else { dataitem.USDPROFIT =( _pr / rate).ToString(); } }else { var _pr = Convert.ToDecimal(dataitem.PR); var rate = GetCurrencyExchangerate(dataitem.CURR); var rate2 = GetCurrencyExchangerate("USD"); if (rate == 0|| rate2==0) { dataitem.USDPROFIT = "0"; } else { dataitem.USDPROFIT = (_pr * rate/ rate2).ToString(); } } return dataitem; } private static decimal GetCurrencyExchangerate(string CODENAME, DateTime? dateTime=null) { if (dateTime == null) dateTime = DateTime.Now; var result = 0M; var cdc = new CommonDataContext(); var 符合条件的汇率记录 = cdc.VW_CURRENCY_EXCHANGE.Where(x => x.CODENAME == CODENAME && x.STARTTIME <= dateTime && x.ENDTIME >= dateTime).ToList(); if (符合条件的汇率记录 != null && 符合条件的汇率记录.Count > 0) { result = (decimal)符合条件的汇率记录[0].VALUE; } return result; } #endregion #region 业务核算单费用 static public List GetBLFeeList(string bsno) { var strSql = new StringBuilder(); strSql.Append(" exec GetPrintData '"+bsno+"' "); return SetBLFeeData(strSql); } static public List GetBLMasterFeeList(string bsno) { var strSql = new StringBuilder(); strSql.Append(" exec GetPrintDataMaster '" + bsno + "' "); return SetBLFeeData(strSql); } private static List SetBLFeeData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsBLChFee data = new MsBLChFee(); #region Set DB data to Object data.BsNo = Convert.ToString(reader["BsNo"]); data.AccName = Convert.ToString(reader["AccName"]); data.ObjDr = Convert.ToString(reader["ObjDr"]); data.ObjCr = Convert.ToString(reader["ObjCr"]); data.DR = Convert.ToString(reader["DR"]); data.CR = Convert.ToString(reader["CR"]); data.RemarkDr = Convert.ToString(reader["RemarkDr"]); data.RemarkCr = Convert.ToString(reader["RemarkCr"]); if (reader["USDDR"] != DBNull.Value) data.USDDR = Convert.ToDecimal(reader["USDDR"]); if (reader["RMBDR"] != DBNull.Value) data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); if (reader["OTDR"] != DBNull.Value) data.OTDR = Convert.ToDecimal(reader["OTDR"]); if (reader["TTLDR"] != DBNull.Value) data.TTLDR = Convert.ToDecimal(reader["TTLDR"]); if (reader["USDCR"] != DBNull.Value) data.USDCR = Convert.ToDecimal(reader["USDCR"]); if (reader["RMBCR"] != DBNull.Value) data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); if (reader["OTCR"] != DBNull.Value) data.OTCR = Convert.ToDecimal(reader["OTCR"]); if (reader["TTLCR"] != DBNull.Value) data.TTLCR = Convert.ToDecimal(reader["TTLCR"]); data.RMBPROFIT = data.RMBDR - data.RMBCR; data.USDPROFIT = data.USDDR - data.USDCR; data.TTLPROFIT = data.TTLDR- data.TTLCR; #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 修改新值 static public List GetModifyData(string FeeID,string ApplyType) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,0 as FeeStatus,"); strSql.Append(" '' as FeeStatus_Ref"); strSql.Append(",TYPE as FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee_modify.TYPE) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append(" '' as FeeDescription,'' as CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,TAX,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,0 Settlement,0 Invoice,0 OrderAmount,0 OrderInvoice,null SubmitDate"); strSql.Append(",'' Auditoperator,null AuditDate,'' EnteroPerator,null EnterDate,'' DebitNo,'' IsDebit,0 IsOpen"); strSql.Append(",'' as OpName"); strSql.Append(",0 IsAdvancedpay,0 Sort,0 IsInvoice,Frt FeeFrt,'' IsCrmOrderFee,0 AuditStatus,0 InvoiceNum"); strSql.Append(",'' ChequeNum,'' WmsOutBsNo,0 LineNum"); strSql.Append(",APPLYTIME MODIFIEDTIME,0 UNINVOICE,0 PREAMOUNT,'' INPUTMODE "); strSql.Append(",(select showname from [user] where gid=ch_fee_modify.APPLYUSER) MODIFIEDUSER "); strSql.Append(",'' Auditoperatorref,'' LOCALCURR,MANAGER,(select showname from [user] where gid=ch_fee_modify.MANAGER) MANAGERREF "); strSql.Append(",'' customerFullName,''STATEMENTNO,SALECORP,0 ISDJY"); strSql.Append(",'' VOUNO ,'' INVLINKGID"); strSql.Append(" from ch_fee_modify "); strSql.Append(" where APPLYSTATUS=1 AND APPLYTYPE="+ApplyType+" AND FEEID='" + FeeID + "'"); return SetData(strSql); } static public List GetModifyAllData(string FeeID, string ApplyType) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,0 as FeeStatus,"); strSql.Append(" '' as FeeStatus_Ref"); strSql.Append(",TYPE as FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee_modify.TYPE) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append(" '' as FeeDescription,'' as CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,TAX,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,0 Settlement,0 Invoice,0 OrderAmount,0 OrderInvoice,null SubmitDate"); strSql.Append(",'' Auditoperator,null AuditDate,'' EnteroPerator,null EnterDate,'' DebitNo,0 IsDebit,0 IsOpen"); strSql.Append(",'' as OpName"); strSql.Append(",0 IsAdvancedpay,0 Sort,0 IsInvoice,Frt FeeFrt,0 IsCrmOrderFee,0 AuditStatus,'' InvoiceNum"); strSql.Append(",'' ChequeNum,'' WmsOutBsNo,0 LineNum"); strSql.Append(",APPLYTIME MODIFIEDTIME,0 UNINVOICE,0 PREAMOUNT,'' INPUTMODE"); strSql.Append(",(select showname from [user] where gid=ch_fee_modify.APPLYUSER) MODIFIEDUSER "); strSql.Append(",'' Auditoperatorref,'' LOCALCURR,MANAGER,(select showname from [user] where gid=ch_fee_modify.MANAGER) MANAGERREF "); strSql.Append(",'' customerFullName,''STATEMENTNO, SALECORP,0 ISDJY"); strSql.Append(",'' VOUNO,'' INVLINKGID "); strSql.Append(" from ch_fee_modify "); strSql.Append(" where APPLYTYPE=" + ApplyType + " AND FEEID='" + FeeID + "'"); return SetData(strSql); } static public List GetModifyData(string FeeID) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,APPLYTYPE,CASE APPLYTYPE WHEN 1 THEN '修改旧值' WHEN 2 THEN '修改新值' ELSE '申请删除' END AS APPLYTYPEREF"); strSql.Append(",Reason,TYPE as FeeType"); strSql.Append(",FeeName,CustomerName"); strSql.Append(",Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,Currency,ExChangerate"); strSql.Append(",Remark,Commissionrate,(select showname from [user] where gid=ch_fee_modify.AUDITUSER) AUDITUSERREF,AUDITTIME"); strSql.Append(",(select showname from [user] where gid=ch_fee_modify.APPLYUSER) APPLYUSERREF,APPLYTIME,GROUPID,MANAGER,SALECORP,CUSTOMERTYPE"); strSql.Append(" from ch_fee_modify "); strSql.Append(" where APPLYSTATUS<>6 AND FEEID='" + FeeID + "' ORDER BY APPLYTIME DESC "); return SetModifyData(strSql); } private static List SetModifyData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsChFee data = new MsChFee(); #region Set DB data to Object data.GId = Convert.ToString(reader["GId"]); data.BsNo = Convert.ToString(reader["BsNo"]); data.FeeStatus = Convert.ToInt16(reader["APPLYTYPE"]); data.FeeStatus_Ref = Convert.ToString(reader["APPLYTYPEREF"]); data.FeeType = Convert.ToDecimal(reader["FeeType"]); data.FeeName = Convert.ToString(reader["FeeName"]); data.CustomerType = Convert.ToString(reader["CUSTOMERTYPE"]); data.CustomerName = Convert.ToString(reader["CustomerName"]); data.Unit = Convert.ToString(reader["Unit"]); data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]); data.Quantity = Convert.ToDecimal(reader["Quantity"]); if (reader["TaxRate"] != DBNull.Value) data.TaxRate = Convert.ToDecimal(reader["TaxRate"]); if (reader["NoTaxAmount"] != DBNull.Value) data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]); data.Amount = Convert.ToDecimal(reader["Amount"]); if (reader["AccTaxRate"] != DBNull.Value) data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]); data.Currency = Convert.ToString(reader["Currency"]); data.ExChangerate = Convert.ToDecimal(reader["ExChangerate"]); data.Reason = Convert.ToString(reader["Reason"]); data.Remark = Convert.ToString(reader["Remark"]); data.Commissionrate = Convert.ToDecimal(reader["Commissionrate"]); data.Auditoperator = Convert.ToString(reader["AUDITUSERREF"]); if (reader["AUDITTIME"] != DBNull.Value) data.AuditDate = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.EnteroPerator = Convert.ToString(reader["APPLYUSERREF"]); if (reader["APPLYTIME"] != DBNull.Value) data.EnterDate = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.MANAGER = Convert.ToString(reader["MANAGER"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 更改单数据 static public List GetAmendList(string strCondition,string optype="",string userid = "", string username = "", string companyid = "") { if (optype != ""&& optype !=null) { var rangstr = GetAmendRangDAStr(optype, userid, username, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GID,BSNO,PARENTID,FEESTATUS,ACCDATE,SALE,CREATEUSER,CREATETIME,REASON,REMARKS,AMENDNO,BillFeeStatus,BILLFEESTATUSTIME"); strSql.Append(",(CASE FEESTATUS WHEN 1 THEN '已锁定' else '未锁定' end) as FEESTATUSREF "); strSql.Append(" from op_amend "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by CREATETIME "); return SetAmendData(strSql); } static public MsOpAmend GetAmendData(string strCondition) { var headlist = MsChFeeDAL.GetAmendList(strCondition); if (headlist.Count > 0) return headlist[0]; else return new MsOpAmend(); } private static List SetAmendData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpAmend data = new MsOpAmend(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.PARENTID = Convert.ToString(reader["PARENTID"]); data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]); data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.REASON = Convert.ToString(reader["REASON"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.SALE = Convert.ToString(reader["SALE"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.AMENDNO = Convert.ToString(reader["AMENDNO"]); data.BillFeeStatus = Convert.ToString(reader["BillFeeStatus"]); if (reader["BILLFEESTATUSTIME"] != DBNull.Value) data.BILLFEESTATUSTIME = Convert.ToString(reader["BILLFEESTATUSTIME"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 提交申请 static public List GetCtnUnitList(string bsno,string bstype) { var strSql = new StringBuilder(); var tops = ""; if (bsno.Length >= 7) { tops=bsno.Substring(0, 7); } if (tops == "topseae" || bstype == "op_Seae") { if (!string.IsNullOrEmpty(bsno)) { strSql.Append("SELECT PKGS,KGS,CBM,KGS AS NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL"); strSql.Append(" from op_seae "); strSql.Append(" where bsno='" + bsno + "'"); strSql.Append(" union "); strSql.Append("SELECT 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,"); strSql.Append("P.SIZE,P.CTN,SUM(P.CTNNUM) AS CTNNUM,SUM(P.TEU) AS TEU,P.CTNALL"); strSql.Append(" from OP_CTN P "); strSql.Append(" where p.bsno='" + bsno + "'"); strSql.Append(" GROUP BY P.SIZE,P.CTN,P.CTNALL order by PKGS desc"); } else { strSql.Append("SELECT top 1 1 PKGS,0 KGS,0 CBM,0 AS NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL"); strSql.Append(" from op_seae "); strSql.Append(" union "); strSql.Append("SELECT distinct 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,"); strSql.Append("P.SIZE,P.CTN,0 AS CTNNUM,0 AS TEU,P.CTNALL"); strSql.Append(" from OP_CTN P "); } return SetSeaeCtnUnitData(strSql, bstype); } else if (tops == "topseai" || bstype == "op_Seai") { strSql.Append("SELECT PKGS,KGS,CBM,NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL"); strSql.Append(" from op_seai "); strSql.Append(" where bsno='" + bsno + "'"); strSql.Append(" union "); strSql.Append("SELECT 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,"); strSql.Append("P.SIZE,P.CTN,SUM(P.CTNNUM) AS CTNNUM,SUM(P.TEU) AS TEU,P.CTNALL"); strSql.Append(" from OP_CTN P "); strSql.Append(" where p.bsno='" + bsno + "'"); strSql.Append(" GROUP BY P.SIZE,P.CTN,P.CTNALL order by PKGS desc"); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "apply") { strSql.Append("SELECT PKGS,KGS,CBM,NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL"); strSql.Append(" from op_apply "); strSql.Append(" where bsno='" + bsno + "'"); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "op_SeaeOrder") { strSql.Append("SELECT PKGS,KGS,CBM,0 AS NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL"); strSql.Append(" from crm_seaeorder "); strSql.Append(" where ORDNO='" + bsno + "'"); strSql.Append(" union "); strSql.Append("SELECT 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,"); strSql.Append("'' as SIZE,'' as CTN,SUM(P.CTNNUM) AS CTNNUM,0 AS TEU,P.CTNALL"); strSql.Append(" from crm_seaeorderctn P "); strSql.Append(" where p.ordno='" + bsno + "'"); strSql.Append(" GROUP BY P.CTNALL order by PKGS desc "); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "op_other") { strSql.Append("SELECT PKGS,KGS,CBM,NETWEIGHT,"); strSql.Append("'' as SIZE,CTNALL AS CTN,CTNNUM,0 AS TEU,CTNALL"); strSql.Append(" from op_other "); strSql.Append(" where bsno='" + bsno + "'"); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "op_railway") { strSql.Append("SELECT PKGS,KGS,CBM,KGS as NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,CTNNUM,0 AS TEU,CTNALL"); strSql.Append(" from op_railway "); strSql.Append(" where bsno='" + bsno + "'"); strSql.Append(" union "); strSql.Append("SELECT 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,"); strSql.Append("P.SIZE,P.CTN,SUM(P.CTNNUM) AS CTNNUM,SUM(P.TEU) AS TEU,P.CTNALL"); strSql.Append(" from OP_CTN P "); strSql.Append(" where p.bsno='" + bsno + "'"); strSql.Append(" GROUP BY P.SIZE,P.CTN,P.CTNALL order by PKGS desc"); return SetRailwayCtnUnitData(strSql); } else if (bstype == "op_aire") { strSql.Append("SELECT PKGS,FEEKGS KGS,CBM,FEEKGS NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 CTNNUM,0 AS TEU,'' CTNALL"); strSql.Append(" from op_aire "); strSql.Append(" where bsno='" + bsno + "'"); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "op_airi") { strSql.Append("SELECT PKGS,FEEKGS KGS,CBM,FEEKGS NETWEIGHT,"); strSql.Append("'' as SIZE,'' AS CTN,0 CTNNUM,0 AS TEU,'' CTNALL"); strSql.Append(" from op_airi"); strSql.Append(" where bsno='" + bsno + "'"); return SetSeaeCtnUnitData(strSql, bstype); } else if (bstype == "import_main") { strSql.Append("SELECT sum(weight) KGS"); strSql.Append(" from import_cargo"); strSql.Append(" where contractno='" + bsno + "'"); return SetImportTradeUnitData(strSql); } else if (bstype == "WMSIN") { strSql.Append("SELECT CHARGEUNIT DW,GOODSRKSL SL,GOODSPACK JS"); strSql.Append(" from wms"); strSql.Append(" where ASSOCIATEDNO='" + bsno + "'"); return SetWMSINUnitData(strSql); } else if (bstype == "WMSOUT") { strSql.Append("SELECT CHARGEUNIT DW,goodspfsl SL,goodspackpfsl JS"); strSql.Append(" from wms_out"); strSql.Append(" where ASSOCIATEDNO='" + bsno + "'"); return SetWMSINUnitData(strSql); } else return SetCtnUnitData(strSql); } private static List SetCtnUnitData(StringBuilder strSql) { var bodyList = new List(); var strSqla = new StringBuilder(); strSqla.Append("SELECT CTN from code_ctn"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSqla.ToString())) { while (reader.Read()) { MsFeeUnit Data = new MsFeeUnit(); Data.SUNIT = Convert.ToString(reader["CTN"]); Data.UNIT = Convert.ToString(reader["CTN"]); Data.QUANTITY = 1; bodyList.Add(Data); } reader.Close(); } var data = new MsFeeUnit(); data.SUNIT = "P-单票"; data.UNIT = "单票"; data.QUANTITY = 1; bodyList.Add(data); var data2 = new MsFeeUnit(); data2.SUNIT = "J-件"; data2.UNIT = "件数"; data2.QUANTITY = 0; bodyList.Add(data2); var data4 = new MsFeeUnit(); data4.SUNIT = "Z-重量"; data4.UNIT = "重量"; data4.QUANTITY = 0; bodyList.Add(data4); var data3 = new MsFeeUnit(); data3.SUNIT = "T-TEU"; data3.UNIT = "TEU"; data3.QUANTITY = 0; bodyList.Add(data3); var data5 = new MsFeeUnit(); data5.SUNIT = "C-CBM"; data5.UNIT = "CBM"; data5.QUANTITY = 0; bodyList.Add(data5); var data6 = new MsFeeUnit(); data6.SUNIT = "X-箱型"; data6.UNIT = "箱型"; data6.QUANTITY = 0; bodyList.Add(data6); var data7 = new MsFeeUnit(); data7.SUNIT = "B-BILL"; data7.UNIT = "BILL"; data7.QUANTITY = 0; bodyList.Add(data7); var data8 = new MsFeeUnit(); data8.SUNIT = "V-车"; data8.UNIT = "车"; data8.QUANTITY = 0; bodyList.Add(data8); var data9 = new MsFeeUnit(); data9.SUNIT = "T-天"; data9.UNIT = "天"; data9.QUANTITY = 0; bodyList.Add(data9); var data10 = new MsFeeUnit(); data10.SUNIT = "G-个"; data10.UNIT = "个"; data10.QUANTITY = 0; bodyList.Add(data10); var data11 = new MsFeeUnit(); data11.SUNIT = "S-小时"; data11.UNIT = "小时"; data11.QUANTITY = 0; bodyList.Add(data10); return bodyList; } private static List SetSeaeCtnUnitData(StringBuilder strSql, string bstype) { var bodyList = new List(); decimal TEUNUM; TEUNUM = 0; decimal PKGS; PKGS = 0; decimal KGS; KGS = 0; decimal CBM; CBM = 0; decimal NETWEIGHT = 0; decimal CTNNUM; CTNNUM = 0; int isfirst = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object if (isfirst == 0) { var data = new MsFeeUnit(); data.SUNIT = "P-单票"; data.UNIT = "单票"; data.QUANTITY = 1; bodyList.Add(data); if (reader["PKGS"] != DBNull.Value) PKGS = Convert.ToDecimal(reader["PKGS"]); if (reader["KGS"] != DBNull.Value) KGS = Convert.ToDecimal(reader["KGS"]); if (reader["CBM"] != DBNull.Value) CBM = Convert.ToDecimal(reader["CBM"]); if (reader["NETWEIGHT"] != DBNull.Value) NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); var kgsdata = new MsFeeUnit(); kgsdata.SUNIT = "Z-重量"; kgsdata.UNIT = "重量"; kgsdata.QUANTITY = KGS; bodyList.Add(kgsdata); var cbmdata = new MsFeeUnit(); cbmdata.SUNIT = "C-尺码"; cbmdata.UNIT = "尺码"; cbmdata.QUANTITY = CBM; bodyList.Add(cbmdata); var pkgsdata = new MsFeeUnit(); pkgsdata.SUNIT = "J-件数"; pkgsdata.UNIT = "件数"; pkgsdata.QUANTITY = PKGS; bodyList.Add(pkgsdata); if (bstype == "op_aire" || bstype == "op_airi") { var netkgsdata = new MsFeeUnit(); netkgsdata.SUNIT = "JFZL-计费重量"; netkgsdata.UNIT = "计费重量"; netkgsdata.QUANTITY = NETWEIGHT; bodyList.Add(netkgsdata); } else { var netkgsdata = new MsFeeUnit(); netkgsdata.SUNIT = "N-净重"; netkgsdata.UNIT = "净重"; netkgsdata.QUANTITY = NETWEIGHT; bodyList.Add(netkgsdata); } var Bdata = new MsFeeUnit(); Bdata.SUNIT = "B-BILL"; Bdata.UNIT = "BILL"; Bdata.QUANTITY = 1; bodyList.Add(Bdata); var ton = KGS / 1000; if (ton > CBM) { var jfd = Math.Round(KGS / 1000, 3, MidpointRounding.AwayFromZero); if (jfd < 1) jfd = 1; var feetondata = new MsFeeUnit(); feetondata.SUNIT = "JF-计费吨"; feetondata.UNIT = "计费吨"; feetondata.QUANTITY = jfd; bodyList.Add(feetondata); } else { var jfd = CBM; if (jfd < 1) jfd = 1; var feetondata = new MsFeeUnit(); feetondata.SUNIT = "JF-计费吨"; feetondata.UNIT = "计费吨"; feetondata.QUANTITY = jfd; bodyList.Add(feetondata); } var jzton = Math.Round(NETWEIGHT / 1000, 3, MidpointRounding.AwayFromZero); var feejztondata = new MsFeeUnit(); feejztondata.SUNIT = "JZD-净重吨"; feejztondata.UNIT = "净重吨"; feejztondata.QUANTITY = jzton; bodyList.Add(feejztondata); } if (Convert.ToString(reader["CTNALL"]) != "") { var ctndata = new MsFeeUnit(); ctndata.SUNIT = Convert.ToString(reader["CTNALL"]); ctndata.UNIT = Convert.ToString(reader["CTNALL"]); if (reader["CTNNUM"] != DBNull.Value) ctndata.QUANTITY = Convert.ToDecimal(reader["CTNNUM"]); CTNNUM = CTNNUM + ctndata.QUANTITY; if (reader["TEU"] != DBNull.Value) TEUNUM = TEUNUM + Convert.ToDecimal(reader["TEU"]); bodyList.Add(ctndata); } isfirst = isfirst + 1; #endregion } var teudata = new MsFeeUnit(); teudata.SUNIT = "TEU"; teudata.UNIT = "TEU"; teudata.QUANTITY = TEUNUM; bodyList.Add(teudata); var ctnalldata = new MsFeeUnit(); ctnalldata.SUNIT = "自然箱"; ctnalldata.UNIT = "自然箱"; ctnalldata.QUANTITY = CTNNUM; bodyList.Add(ctnalldata); var data9 = new MsFeeUnit(); data9.SUNIT = "T-天"; data9.UNIT = "天"; data9.QUANTITY = 0; bodyList.Add(data9); var data10 = new MsFeeUnit(); data10.SUNIT = "G-个"; data10.UNIT = "个"; data10.QUANTITY = 0; bodyList.Add(data10); var data11 = new MsFeeUnit(); data11.SUNIT = "S-小时"; data11.UNIT = "小时"; data11.QUANTITY = 0; bodyList.Add(data11); var data12 = new MsFeeUnit(); data12.SUNIT = "S-票"; data12.UNIT = "票"; data12.QUANTITY = 0; bodyList.Add(data12); var data13 = new MsFeeUnit(); data13.SUNIT = "D-吨"; data13.UNIT = "吨"; data13.QUANTITY = 0; bodyList.Add(data13); reader.Close(); } return bodyList; } private static List SetRailwayCtnUnitData(StringBuilder strSql) { var bodyList = new List(); decimal TEUNUM; TEUNUM = 0; decimal PKGS; PKGS = 0; decimal KGS; KGS = 0; decimal CBM; CBM = 0; decimal NETWEIGHT = 0; int isfirst = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object if (isfirst == 0) { var data = new MsFeeUnit(); data.SUNIT = "P-单票"; data.UNIT = "单票"; data.QUANTITY = 1; bodyList.Add(data); PKGS = Convert.ToDecimal(reader["PKGS"]); KGS = Convert.ToDecimal(reader["KGS"]); CBM = Convert.ToDecimal(reader["CBM"]); NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); var kgsdata = new MsFeeUnit(); kgsdata.SUNIT = "Z-重量"; kgsdata.UNIT = "重量"; kgsdata.QUANTITY = KGS; bodyList.Add(kgsdata); var cbmdata = new MsFeeUnit(); cbmdata.SUNIT = "C-尺码"; cbmdata.UNIT = "尺码"; cbmdata.QUANTITY = CBM; bodyList.Add(cbmdata); var pkgsdata = new MsFeeUnit(); pkgsdata.SUNIT = "J-件数"; pkgsdata.UNIT = "件数"; pkgsdata.QUANTITY = PKGS; bodyList.Add(pkgsdata); var netkgsdata = new MsFeeUnit(); netkgsdata.SUNIT = "N-净重"; netkgsdata.UNIT = "净重"; netkgsdata.QUANTITY = NETWEIGHT; bodyList.Add(netkgsdata); var PCsdata = new MsFeeUnit(); PCsdata.SUNIT = "P-棚车"; PCsdata.UNIT = "棚车"; PCsdata.QUANTITY = 1; bodyList.Add(PCsdata); var CCsdata = new MsFeeUnit(); CCsdata.SUNIT = "P-敞车"; CCsdata.UNIT = "敞车"; CCsdata.QUANTITY = 1; bodyList.Add(CCsdata); var GCsdata = new MsFeeUnit(); GCsdata.SUNIT = "G-罐车"; GCsdata.UNIT = "罐车"; GCsdata.QUANTITY = 1; bodyList.Add(GCsdata); var PCCsdata = new MsFeeUnit(); PCCsdata.SUNIT = "P-平车"; PCCsdata.UNIT = "平车"; PCsdata.QUANTITY = 1; bodyList.Add(PCCsdata); var LCRsdata = new MsFeeUnit(); LCRsdata.SUNIT = "LCR"; LCRsdata.UNIT = "LCR"; LCRsdata.QUANTITY = 1; bodyList.Add(LCRsdata); var SHsdata = new MsFeeUnit(); SHsdata.SUNIT = "SH-散货车"; SHsdata.UNIT = "散货车"; SHsdata.QUANTITY = 1; bodyList.Add(SHsdata); var ton = KGS / 1000; if (ton > CBM) { var feetondata = new MsFeeUnit(); feetondata.SUNIT = "JF-计费吨"; feetondata.UNIT = "计费吨"; feetondata.QUANTITY = Math.Round(KGS / 1000, 2, MidpointRounding.AwayFromZero); bodyList.Add(feetondata); } else { var feetondata = new MsFeeUnit(); feetondata.SUNIT = "JF-计费吨"; feetondata.UNIT = "计费吨"; feetondata.QUANTITY = CBM; bodyList.Add(feetondata); } } if (Convert.ToString(reader["CTNALL"]) != "") { var ctndata = new MsFeeUnit(); ctndata.SUNIT = Convert.ToString(reader["CTNALL"]); ctndata.UNIT = Convert.ToString(reader["CTNALL"]); if (reader["CTNNUM"] != DBNull.Value) ctndata.QUANTITY = Convert.ToDecimal(reader["CTNNUM"]); if (reader["TEU"] != DBNull.Value) TEUNUM = TEUNUM + Convert.ToDecimal(reader["TEU"]); bodyList.Add(ctndata); } isfirst = isfirst + 1; #endregion } var teudata = new MsFeeUnit(); teudata.SUNIT = "TEU"; teudata.UNIT = "TEU"; teudata.QUANTITY = TEUNUM; bodyList.Add(teudata); reader.Close(); } return bodyList; } private static List SetSeaiCtnUnitData(StringBuilder strSql) { var bodyList = new List(); decimal TEUNUM; TEUNUM = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { MsFeeUnit data = new MsFeeUnit(); while (reader.Read()) { #region Set DB data to Object data.UNIT = Convert.ToString(reader["CTNALL"]); data.QUANTITY = Convert.ToDecimal(reader["CTNNUM"]); TEUNUM = TEUNUM + Convert.ToDecimal(reader["TEU"]); #endregion bodyList.Add(data); } data.UNIT = "TEU"; data.QUANTITY = TEUNUM; reader.Close(); } return bodyList; } private static List SetImportTradeUnitData(StringBuilder strSql) { var bodyList = new List(); decimal TEUNUM; TEUNUM = 0; decimal PKGS; PKGS = 0; decimal KGS; KGS = 0; decimal CBM; CBM = 0; decimal NETWEIGHT = 0; decimal CTNNUM; CTNNUM = 0; int isfirst = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object if (isfirst == 0) { var data = new MsFeeUnit(); data.SUNIT = "P-单票"; data.UNIT = "单票"; data.QUANTITY = 1; bodyList.Add(data); KGS = Convert.ToDecimal(reader["KGS"]); NETWEIGHT = KGS/1000; var kgsdata = new MsFeeUnit(); kgsdata.SUNIT = "Z-重量"; kgsdata.UNIT = "重量"; kgsdata.QUANTITY = KGS; bodyList.Add(kgsdata); var netkgsdata = new MsFeeUnit(); netkgsdata.SUNIT = "D-重量(吨)"; netkgsdata.UNIT = "重量(吨)"; netkgsdata.QUANTITY = NETWEIGHT; bodyList.Add(netkgsdata); var Bdata = new MsFeeUnit(); Bdata.SUNIT = "B-BILL"; Bdata.UNIT = "BILL"; Bdata.QUANTITY = 1; bodyList.Add(Bdata); } #endregion } reader.Close(); } return bodyList; } private static List SetWMSINUnitData(StringBuilder strSql) { var bodyList = new List(); int isfirst = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { #region Set DB data to Object if (isfirst == 0) { var data = new MsFeeUnit(); data.SUNIT = "P-单票"; data.UNIT = "单票"; data.QUANTITY = 1; bodyList.Add(data); var DW = Convert.ToString(reader["DW"]); var SL = Convert.ToDecimal(reader["SL"]); var Unitdata = new MsFeeUnit(); Unitdata.SUNIT = DW; Unitdata.UNIT = DW; Unitdata.QUANTITY = SL; bodyList.Add(Unitdata); var JS = Convert.ToDecimal(reader["JS"]); var packdata = new MsFeeUnit(); packdata.SUNIT = "件数"; packdata.UNIT = "件数"; packdata.QUANTITY = JS; bodyList.Add(packdata); } #endregion } reader.Close(); } return bodyList; } #region 币别 public static List GetFeeCurrList() { return GetFeeCurrList(String.Empty); } public static List GetFeeCurrList(string sCondition) { var strSql = new StringBuilder(); strSql.Append("Select GID,CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency "); if (!string.IsNullOrEmpty(sCondition)) { strSql.Append(" where " + sCondition); } strSql.Append(" order by CODENAME"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new MsFeeCurr(); evData.GID = Convert.ToString(reader["GID"]); evData.CURR = Convert.ToString(reader["CODENAME"]); evData.DEFRATE = Convert.ToDecimal(reader["DEFAULTRATE"]); evData.CRDEFRATE = Convert.ToDecimal(reader["DEFAULTRATE"]); evList.Add(evData); } reader.Close(); } return evList; } public static List GetFeeDateCurrList(string type, string bsno, string userid,string companyid) { var FEEEXRATEDEF = MsSysParamSetDAL.GetData("PARAMNAME='FEEEXRATEDEF'"); DateTime currdate = DateTime.Now; if (FEEEXRATEDEF.PARAMVALUE == "") { var currset = GetCompanyCurrSet(userid); currdate = GetopDate(currset, bsno); } else if (FEEEXRATEDEF.PARAMVALUE == "BSDATE"|| FEEEXRATEDEF.PARAMVALUE == "ACCDATE" || FEEEXRATEDEF.PARAMVALUE == "CREATETIME") { var currset = "shipping"; if (FEEEXRATEDEF.PARAMVALUE == "BSDATE") currset = "shipping"; if (FEEEXRATEDEF.PARAMVALUE == "ACCDATE") currset = "account"; if (FEEEXRATEDEF.PARAMVALUE == "CREATETIME") currset = "common"; currdate = GetopDate(currset, bsno); } var evList = new List(); if (currdate != DateTime.MinValue) { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE,CRVALUE,"); strSql.Append("(select CodeName from code_currency where GID=currency_exchange.CURRENCYID) as CODENAME"); strSql.Append(" from currency_exchange "); strSql.Append(" where STARTTIME<='" + currdate.ToShortDateString().ToString() + "' and ENDTIME>='" + currdate.ToShortDateString().ToString() + "'"); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new MsFeeCurr(); evData.CURR = Convert.ToString(reader["CODENAME"]); evData.DEFRATE = Convert.ToDecimal(reader["VALUE"]); if (reader["CRVALUE"] != DBNull.Value) evData.CRDEFRATE = Convert.ToDecimal(reader["CRVALUE"]); if (evData.CRDEFRATE == 0) evData.CRDEFRATE = evData.DEFRATE; evList.Add(evData); } reader.Close(); } } if (evList.Count == 0) return GetFeeCurrList(); else return evList; } public static List GetFeeNowCurrList(string companyid,DateTime? _currdate= null) { var evList = new List(); var strSql = new StringBuilder(); strSql.Append("Select GID,CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency "); strSql.Append(" order by CODENAME"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new MsFeeCurr(); evData.GID = Convert.ToString(reader["GID"]); evData.CURR = Convert.ToString(reader["CODENAME"]); evData.DEFRATE = Convert.ToDecimal(reader["DEFAULTRATE"]); evData.CRDEFRATE = Convert.ToDecimal(reader["DEFAULTRATE"]); evList.Add(evData); } reader.Close(); } var isset = false; if(_currdate==null) _currdate = DateTime.Now; var currdate = (DateTime)_currdate; if (currdate != DateTime.MinValue) { var strSql2 = new StringBuilder(); strSql2.Append("Select CURRENCYID,VALUE,CRVALUE,"); strSql2.Append("(select CodeName from code_currency where GID=currency_exchange.CURRENCYID) as CODENAME"); strSql2.Append(" from currency_exchange "); strSql2.Append(" where STARTTIME<='" + currdate.ToShortDateString().ToString() + "' and ENDTIME>="); strSql2.Append(" '" + currdate.ToShortDateString().ToString() + "' "); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql2.ToString())) { while (reader.Read()) { evList.ForEach(i => { if (i.CURR == Convert.ToString(reader["CODENAME"])) { i.DEFRATE = Convert.ToDecimal(reader["VALUE"]); if (reader["CRVALUE"] != DBNull.Value) i.CRDEFRATE = Convert.ToDecimal(reader["CRVALUE"]); } }); } reader.Close(); } } return evList; } public static decimal GetFeeNowCurr(string companyid,string CURR,string currdate,string feetype) { decimal result = 1; if (Convert.ToDateTime(currdate) != DateTime.MinValue) { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE,CRVALUE,"); strSql.Append("(select CodeName from code_currency where GID=currency_exchange.CURRENCYID) as CODENAME"); strSql.Append(" from currency_exchange "); strSql.Append(" where STARTTIME<='" + currdate + "' and ENDTIME>="); strSql.Append(" and CURRENCYID in (select GID from code_currency where CODENAME='" + CURR + "') "); strSql.Append(" '" + currdate + "' "); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { if (feetype=="1") result = Convert.ToDecimal(reader["VALUE"]); else result = Convert.ToDecimal(reader["CRVALUE"]); } reader.Close(); } } return result; } public static List GetFeeNowInvCurrList(string invdate="") { var currdate = DateTime.Now; var evList = new List(); if (currdate != DateTime.MinValue) { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE,"); strSql.Append("(select CodeName from code_currency where GID=currency_exchange_inv.CURRENCYID) as CODENAME"); strSql.Append(" from currency_exchange_inv "); if (string.IsNullOrEmpty(invdate)) { strSql.Append(" where STARTTIME<='" + currdate.ToShortDateString().ToString() + "' and ENDTIME>="); strSql.Append(" '" + currdate.ToShortDateString().ToString() + "' "); } else { strSql.Append(" where STARTTIME<='" + invdate + "' and ENDTIME>="); strSql.Append(" '" + invdate + "' "); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new MsFeeCurr(); evData.CURR = Convert.ToString(reader["CODENAME"]); evData.DEFRATE = Convert.ToDecimal(reader["VALUE"]); evList.Add(evData); } reader.Close(); } } return evList; } public static decimal GetUsdExrate(string currdate, string curr,string companyid) { decimal result = 1; if (currdate == "") { var strSql = new StringBuilder(); strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency where CODENAME='USD'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } else { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE "); strSql.Append(" from currency_exchange "); strSql.Append(" left join code_currency c on (c.GID=currency_exchange.CURRENCYID) "); strSql.Append(" where c.CODENAME='" + curr + "' and STARTTIME<='" + currdate + "' and ENDTIME>='" + currdate + "'"); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["VALUE"]); } reader.Close(); } if (result == -1) { strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency where CODENAME='USD'"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } } return result; } public static decimal GetExrate(string currdate, string companyid, string curr="USD") { decimal result = 1; if (currdate == "") { var strSql = new StringBuilder(); strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append($" from code_currency where CODENAME='{curr}'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } else { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE "); strSql.Append(" from currency_exchange "); strSql.Append(" left join code_currency c on (c.GID=currency_exchange.CURRENCYID) "); strSql.Append(" where c.CODENAME='" + curr + "' and STARTTIME<='" + currdate + "' and ENDTIME>='" + currdate + "'"); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["VALUE"]); } reader.Close(); } if (result == 1) { strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency where CODENAME='USD'"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } } return result; } public static decimal GetExrate(string currdate, string companyid, Database db, DbTransaction tran, string curr = "USD") { decimal result = 1; if (currdate == "") { var strSql = new StringBuilder(); strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append($" from code_currency where CODENAME='{curr}'"); using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } else { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE "); strSql.Append(" from currency_exchange "); strSql.Append(" left join code_currency c on (c.GID=currency_exchange.CURRENCYID) "); strSql.Append(" where c.CODENAME='" + curr + "' and STARTTIME<='" + currdate + "' and ENDTIME>='" + currdate + "'"); var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'"); if (EXCHANGENOTCOMPANY.PARAMVALUE != "1") { strSql.Append(" and COMPANYID='" + companyid + "' "); } using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["VALUE"]); } reader.Close(); } if (result == 1) { strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency where CODENAME='USD'"); using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } } return result; } /// /// 根据传入的分公司ID,和系统日期,查找一条日期区间的汇率信息 /// /// /// public static List GetFeeNowCurrList2 ( string COMPANYID ) { var evList = new List(); var currdate = DateTime.Now; if (currdate != DateTime.MinValue) { var condition = " STARTTIME<='" + currdate.ToShortDateString().ToString() + "' and ENDTIME>="+ " '" + currdate.ToShortDateString().ToString() + "' and COMPANYID='" + COMPANYID + "'"; evList = SetFeeNowCurrList2(condition); } return evList; } private static List SetFeeNowCurrList2(string condition) { var evList = new List(); var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE,CRVALUE,"); strSql.Append("(select CodeName from code_currency where GID=currency_exchange.CURRENCYID) as CODENAME"); strSql.Append(" from currency_exchange "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new MsFeeCurr(); evData.GID = Convert.ToString(reader["CURRENCYID"]); evData.CURR = Convert.ToString(reader["CODENAME"]); evData.DEFRATE = Convert.ToDecimal(reader["VALUE"]); if (reader["CRVALUE"] != DBNull.Value) evData.CRDEFRATE = Convert.ToDecimal(reader["CRVALUE"]); evList.Add(evData); } reader.Close(); } return evList; } public static string GetCompanyCurrSet(string userid) { var CurrSet=""; var strSql = new StringBuilder(); strSql.Append("Select VALUE "); strSql.Append(" from company_attribute "); strSql.Append(" where (ISDELETE=0 or ISDELETE is null) and ATTRIBUTEID in (select GID from attribute where name='refSubCompanyExchangeRate')"); strSql.Append(" and COMPANYID in (select COMPANYID from user_company where userid='" + userid + "')"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CurrSet = Convert.ToString(reader["VALUE"]); } reader.Close(); } return CurrSet; } public static DateTime GetopDate(string datetype,string bsno) { DateTime CurrDate =DateTime.MinValue; //CurrDate = DateTime.Now; var strSql = new StringBuilder(); strSql.Append("Select accdate,opdate,createtime "); strSql.Append(" from opdate "); strSql.Append(" where bsno='"+bsno+"'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { if (datetype == "shipping") { if (reader["opdate"] != DBNull.Value) CurrDate = Convert.ToDateTime(reader["opdate"]); } else if (datetype == "account") { if (reader["accdate"] != DBNull.Value) CurrDate = Convert.ToDateTime(Convert.ToString(reader["accdate"]) + "-01"); } else if (datetype == "common") { if (reader["createtime"] != DBNull.Value) CurrDate = Convert.ToDateTime(reader["createtime"]); } } reader.Close(); } return CurrDate; } public static List GetFeeTypeRefList() { return GetFeeTypeRefList(String.Empty); } public static List GetFeeTypeRefList(string sCondition) { var strSql = GetFeeTypeRefList_Sqlstr(sCondition); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new FeeTypeRefModel(); evData.FeeCode = Convert.ToString(reader["FeeCode"]); evData.Name = Convert.ToString(reader["Name"]); evData.DefaultCurr = Convert.ToString(reader["DEFAULTCURR"]); evData.Description = Convert.ToString(reader["Description"]); evData.CodeAndName = Convert.ToString(reader["CodeAndName"]); evData.DefaultDebit = Convert.ToString(reader["DEFAULTDEBIT"]); evData.DefaultCredit = Convert.ToString(reader["DEFAULTCREDIT"]); evData.DefaultDebitRef = Convert.ToString(reader["DEFAULTDEBITREF"]); evData.DefaultCreditRef = Convert.ToString(reader["DEFAULTCREDITREF"]); evData.DefaultUnit = Convert.ToString(reader["DefaultUnit"]); evData.FEETYPE = Convert.ToString(reader["FEETYPE"]); evData.FEEFRT = Convert.ToString(reader["FEEFRT"]); if (reader["ISADVANCEDPAY"] != DBNull.Value) { if (Convert.ToBoolean(reader["ISADVANCEDPAY"])) evData.ISADVANCEDPAY = "1"; } if (reader["TAXRATE"] != DBNull.Value) evData.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]); evList.Add(evData); } reader.Close(); var evData2 = new FeeTypeRefModel(); evData2.FeeCode =""; evData2.Name =""; evData2.DefaultCurr ="RMB"; evData2.Description =""; evData2.CodeAndName =""; evData2.DefaultDebit =""; evData2.DefaultCredit =""; evData2.DefaultDebitRef = ""; evData2.DefaultCreditRef = ""; evData2.DefaultUnit = ""; evData2.FEETYPE ="1"; evData2.FEEFRT = "PP"; evData2.ISADVANCEDPAY = "0"; evData2.TAXRATE = 0; evList.Add(evData2); } return evList; } public static StringBuilder GetFeeTypeRefList_Sqlstr(string sCondition) { var strSql = new StringBuilder(); strSql.Append("Select FeeCode,Name,FEECODE + '-' + NAME AS CodeAndName,DEFAULTCURR,DEFAULTDEBIT,DEFAULTCREDIT,feetype,Description,DefaultUnit,FeeFRT,ISADVANCEDPAY,TAXRATE "); strSql.Append(",isnull(CASE DEFAULTDEBIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 12 then '船代' when 0 then '其他' end ,'') DEFAULTDEBITREF "); strSql.Append(",isnull(CASE DEFAULTCREDIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 12 then '船代' when 0 then '其他' end ,'') DEFAULTCREDITREF "); strSql.Append(" from code_fee "); if (!string.IsNullOrEmpty(sCondition)) { strSql.Append(" where " + sCondition); } strSql.Append(" order by FeeCode"); return strSql; } public static List GetFeeOpRang(string optype, string userid) { var strSql = new StringBuilder(); strSql.Append(GetRangDASQLStr(optype,userid)); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = new OPCODE(); evData.OPID = Convert.ToString(reader["OPCODE"]); evList.Add(evData); } reader.Close(); } return evList; } public static string GetRangDASQLStr(string tb, string userid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='"+tb+"' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); break; } reader.Close(); } if (operaterange == "4") { str = "select GID AS OPCODE from [user] where 1=2 and GID='"+userid+"'"; } else if (operaterange == "3") { str = "select GID AS OPCODE from [user] where GID='" + userid + "'"; } else if (operaterange == "2") { var rangeDa = new RangeDA(); var deptid = rangeDa.GetDEPTGID(userid); str = " select userid AS OPCODE from vw_user where deptgid='" + deptid + "'"; } else if (operaterange == "1") { var rangeDa = new RangeDA(); var companyid = rangeDa.GetCORPID(userid); str = " select USERID AS OPCODE from user_company where COMPANYID='" + companyid + "'"; } else if (operaterange == "5") { str = " select userid OPCODE from VW_user where COMPANYID in (select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and OPERATERANGE=1)"; } else if (operaterange == "6") { str = " select (select GID from [user] where GID=user_authority_range_op.OPID) OPCODE from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and OPERATERANGE=1"; } else { str = "select GID AS OPCODE from [user] "; } return str; } #endregion // 根据handle类型执行更新操作:更新费用信息ch_fee.feestatus和工作流运行表WorkFlowDo信息 // 费用状态值 费用状态主要有11个状态,分别为审核通过(STATUS=0)录入状态(STATUS=1)提交审核(STATUS=2)申请修改 (STATUS=3) // 取消申请(STATUS=5)驳回提交(STATUS=6)驳回申请(STATUS=7)部分结算(STATUS=8)结算完毕(STATUS=9) internal static DBResult Audit(int newStatus, List chfeeList) { var result = new DBResult(); foreach (var chFee in chfeeList) { var status = chFee.FeeStatus; var canAudit = true; if (newStatus == 2) { canAudit = status == 1 || status == 6; } else if (newStatus == 0) { canAudit = status == 2 || status == 10; } else if (newStatus == 6) { canAudit = status == 0 || status == 2; } else if (newStatus == 8 || newStatus == 9) { canAudit = status == 0 || status == 10; } else if (newStatus == 10) { canAudit = status == 0 || status == 1 || status == 2; } if (!canAudit) { result.Success = false; if (newStatus == 2) result.Message = "只有在'录入状态'和'驳回提交'状态下才能提交审核操作"; else if (newStatus == 0) { result.Message = "只有在‘提交审核’状态下才能进行此操作"; } else if (newStatus == 6) { result.Message = "只有在‘审核通过’或‘提交审核’状态下才能进行此操作"; } else if (newStatus == 8 || newStatus == 9) { result.Message = "只有在‘审核通过’状态下才能进行此操作"; } else if (newStatus == 10) { result.Message = "只有在‘审核通过’或‘提交审核’或‘录入状态’状态下才能进行 提交融资 操作"; } return result; } } var feeBsNoList = new List(); foreach (var msChFee in chfeeList) { var bsNo = msChFee.BsNo; if (!feeBsNoList.Contains(bsNo)) { feeBsNoList.Add(bsNo); } } Database db = DatabaseFactory.CreateDatabase(); //费用锁定后不允许驳回。 foreach (var bsNo in feeBsNoList) { if (newStatus == 6) { string sql = string.Empty; if (bsNo.StartsWith("TMSBS")) { sql = "select FeeStatus from tMsWlBsHead where Gid=@gid"; } else { sql = "select FeeStatus from tMsWlPcHead where Gid=@gid"; ; } var cmdFeeStatus = db.GetSqlStringCommand(sql); db.AddInParameter(cmdFeeStatus, "@gid", DbType.String, bsNo); var feeStatus = Convert.ToString(db.ExecuteScalar(cmdFeeStatus)); if (feeStatus == "1") { result.Success = false; result.Message = "单据的费用已经锁定,不允许驳回费用"; return result; } } } const string selectSql = "select FeeStatus from ch_fee where gid=@gid"; const string updateSql = "update ch_fee set FeeStatus=@FeeStatus, Auditdate=getdate() where gid=@gid"; const string enumSql = "select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=@EnumValueID"; using (DbConnection connection = db.CreateConnection()) { connection.Open(); try { var cmdEnum = db.GetSqlStringCommand(enumSql); db.AddInParameter(cmdEnum, "@EnumValueID", DbType.Int32, newStatus); var newStatusRef = Convert.ToString(db.ExecuteScalar(cmdEnum)); DbTransaction transaction = connection.BeginTransaction(); try { foreach (var msChFee in chfeeList) { var cmdSelect = db.GetSqlStringCommand(selectSql); db.AddInParameter(cmdSelect, "@gid", DbType.String, msChFee.GId); var feeStatus = db.ExecuteScalar(cmdSelect, transaction); if (feeStatus == null) { throw new MsChFeeDealException("'" + msChFee.FeeName + "'数据还没有保存,不想允许提交,请保存后重试!"); } if (Convert.ToInt32(feeStatus) != msChFee.FeeStatus) { throw new MsChFeeDealException("'"+msChFee.FeeName+"'费用状态已经改变,不想允许提交,请刷新后重试!"); } var cmdUpdate = db.GetSqlStringCommand(updateSql); db.AddInParameter(cmdUpdate, "@FeeStatus", DbType.Int32, newStatus); db.AddInParameter(cmdUpdate, "@gid", DbType.String, msChFee.GId); db.ExecuteNonQuery(cmdUpdate, transaction); } transaction.Commit(); result.Success = true; result.Message = "提交成功"; result.Data = newStatusRef; } catch (Exception e) { transaction.Rollback(); result.Success = false; if (e is MsChFeeDealException) result.Message = e.Message; else result.Message = "执行提交发生未知错误,请重试"; } } finally { connection.Close(); } } return result; } private static int GetFeeStatusRecordCount(Database db, string bsNo, int feeStatus, DbTransaction transaction) { var cmdRejectCount = db.GetSqlStringCommand("select count(*) from ch_fee where BsNo=@BsNo and FeeStatus=@FeeStatus"); db.AddInParameter(cmdRejectCount, "@BsNo", DbType.String, bsNo); db.AddInParameter(cmdRejectCount, "@FeeStatus", DbType.Int32, feeStatus); var rejectCount = Convert.ToInt32(db.ExecuteScalar(cmdRejectCount, transaction)); return rejectCount; } public static DBResult CreateDui(string duino, List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @" update ch_fee set STATEMENTNO=@DUINO WHERE Gid=@CH_ID"); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@CH_ID", DbType.String, enumValue.GId); db.AddInParameter(cmdUpdate, "@DUINO", DbType.String, duino); db.ExecuteNonQuery(cmdUpdate, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功!"; result.Data = duino; return result; } public static DBResult SaveFeeSort(List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @" update ch_fee set SORT=@SORT WHERE Gid=@CH_ID"); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@CH_ID", DbType.String, enumValue.GId); db.AddInParameter(cmdUpdate, "@SORT", DbType.String, enumValue.Sort); db.ExecuteNonQuery(cmdUpdate, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功!"; return result; } #endregion #region 查询应收/实收(现金帐目) static public List GetChFeeDo(string condition) { var strSql = new StringBuilder(); strSql.Append(" select fd.gid,f.bsno,f.customername,f.feeid,f.feename,fd.Doamount,f.feetype, "); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref"); strSql.Append(" fd.createtime from ch_fee_do fd "); strSql.Append(" left join ch_fee f on f.gid=fd.feeid "); if (condition.Trim() != String.Empty) { strSql.Append(" where " + condition); } else { strSql.Clear(); }//防止无参数调用 return SetChFeeDo(strSql); } private static List SetChFeeDo(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsChFeeDo data = new MsChFeeDo(); #region Set DB data to Object data.Gid = Convert.ToString(reader["Gid"]); data.bsno = Convert.ToString(reader["bsno"]); data.customername = Convert.ToString(reader["customername"]); data.feeid = Convert.ToString(reader["feeid"]); data.feename = Convert.ToString(reader["feename"]); data.Doamount = Convert.ToString(reader["Doamount"]); data.feetype = Convert.ToString(reader["feetype"]); data.createtime = Convert.ToString(reader["createtime"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion public static DBResult GetGainPrint(string bsno, string oplb) { var AuditPrint = MsSysParamSetDAL.GetData("PARAMNAME='PrintProfitafterAudit'"); var isprint = GetFeeCount(bsno); var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdupdatePrt = db.GetSqlStringCommand("update " + oplb + " set ISPRINTPR='1' where BSNO=@BSNO"); cmdupdatePrt.Parameters.Clear(); db.AddInParameter(cmdupdatePrt, "@BSNO", DbType.String, bsno); db.ExecuteNonQuery(cmdupdatePrt, tran); if (AuditPrint.PARAMVALUE == "1") { if (isprint) { result.Success = false; result.Message = "此票业务存在未审核通过的费用,请审核通过后再打印核算单"; } else { var Closefee = MsSysParamSetDAL.GetData("PARAMNAME='closeafterPrintProfit'"); if (Closefee.PARAMVALUE == "1") { var cmddelete = db.GetSqlStringCommand("update " + oplb + " set FEESTATUS=1 where BSNO=@BSNO"); cmddelete.Parameters.Clear(); db.AddInParameter(cmddelete, "@BSNO", DbType.String,bsno); db.ExecuteNonQuery(cmddelete, tran); } result = new DBResult(); result.Success = true; result.Message = "成功"; } } else { result = new DBResult(); result.Success = true; result.Message = "成功"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = true; result.Message = "成功"; } } return result; } public static DBResult GetFeeLock(string bsno) { var result = new DBResult(); var strSql = new StringBuilder(); strSql.Append("Select FEESTATUS "); strSql.Append(" from v_op_bill "); strSql.Append(" where BSNO='" + bsno + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { if (reader["FEESTATUS"] != DBNull.Value) { result.Success = Convert.ToBoolean(reader["FEESTATUS"]);//费用状态 } else result.Success = false; } reader.Close(); } return result; } public static bool GetFeeCount(string BSNO) { var isfee = false; var strSql = new StringBuilder(); strSql.Append("Select count(*) as count "); strSql.Append(" from ch_fee "); strSql.Append(" where FEESTATUS not in (0,8,9,10,11) and BSNO='" + BSNO + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } public static decimal GetFeeBalAmount(string condition) { decimal feeamount = 0; var strSql = new StringBuilder(); strSql.Append("Select sum((AMOUNT-SETTLEMENT)*EXCHANGERATE) BALAMOUT "); strSql.Append(" from ch_fee "); strSql.Append(" where " + condition); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { if (reader["BALAMOUT"] != DBNull.Value) feeamount = Math.Round(Convert.ToDecimal(reader["BALAMOUT"]),2, MidpointRounding.AwayFromZero); } reader.Close(); } return feeamount; } public static string GetFeeRangeSqlStr(int type, string optype, string userid, string username, string companyid) { var rangstr = GetRangDAStr(type, optype, userid, username, companyid); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } return rangstr; } public static string GetFeeSumRangeSqlStr(bool isopen, string userid, string username, string companyid) { var rangstr = GetSumRangDAStr(userid, username, companyid); //var nopowerOpen = MsSysParamSetDAL.GetData("PARAMNAME='FeeSumIsContentNotOpen'"); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } if (rangstr == "") rangstr = "1=1"; else rangstr = "("+ rangstr + ")"; return rangstr; } public static string GetFeeDrCrRangeSqlStr(int type,string optype,bool isopen,string userid, string username, string companyid) { var rangstr = GetRangDAStr(type, optype, userid, username, companyid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } var isacc = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modISWACC", userid); var isaccstr = ""; if (isacc == false) { isaccstr = " ISNULL(ISACC,0)=0 "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isaccstr; else rangstr = isaccstr; } if (rangstr == "") rangstr = "1=1"; else rangstr = "(" + rangstr + ")"; return rangstr; } public static string GetRangDAStr(int type, string optype, string userid, string username, string companyid) { string str = ""; string modustr = ""; optype = optype.ToLower(); if (type == 1) { if (optype == "op_seae") { modustr = "modRecvFeeManagement"; } else if (optype == "op_apply") { modustr = "modApplyRecvFeeManagement"; } else if (optype == "op_seai") { modustr = "modSeaiRecvFeeManagement"; } else if (optype == "op_aire") { modustr = "modAireRecvFeeManagement"; } else if (optype == "op_airi") { modustr = "modAiriRecvFeeManagement"; } else if (optype == "op_seailcl") { modustr = "modSeaiLCLRecvFeeManagement"; } else if (optype == "op_other" || optype == "tmswlpchead" || optype == "opctnbscard" || optype == "op_airn") { modustr = "modOtherRecvFeeManagement"; } else if (optype == "op_bulk") { modustr = "modBulkRecvFeeManagement"; } else if (optype == "op_railway") { modustr = "modRailwayRecvFeeManagement"; } else if (optype == "import_main") { modustr = "modImport_Fee"; } else if (optype == "wmsmain") { modustr = "modWMSMAIN"; } else if (optype == "op_truckbulk") { modustr = "modTruckRecvFeeManagement"; } else if (optype == "op_internaltrade") { modustr = "modOp_InternalTradeRecvFeeManagement"; } } else if (type== 2) { if (optype == "op_seae") { modustr = "modPayFeeManagement"; } else if (optype == "op_apply") { modustr = "modApplyPayFeeManagement"; } else if (optype == "op_seai") { modustr = "modSeaiPayFeeManagement"; } else if (optype == "op_aire") { modustr = "modAirePayFeeManagement"; } else if (optype == "op_airi") { modustr = "modAiriPayFeeManagement"; } else if (optype == "op_seailcl") { modustr = "modSeaiLCLPayFeeManagement"; } else if (optype == "op_other" || optype == "tmswlpchead" || optype == "opctnbscard" || optype == "op_airn") { modustr = "modOtherPayFeeManagement"; } else if (optype == "op_bulk") { modustr = "modBulkPayFeeManagement"; } else if (optype == "op_railway") { modustr = "modRailwayPayFeeManagement"; } else if (optype == "import_main") { modustr = "modImport_Fee"; } else if (optype == "wmsmain") { modustr = "modWMSMAIN"; } else if (optype == "op_truckbulk") { modustr = "modTruckPayFeeManagement"; } else if (optype == "op_internaltrade") { modustr = "modOp_InternalTradePayFeeManagement"; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='" + modustr+ "' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " ENTEROPERATOR='" + userid + "'"; } else if (visiblerange == "3") { str = " ENTEROPERATOR='" + userid + "'"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') and ENTEROPERATOR in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')"; } else if (visiblerange == "1") { str = " ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else { str = str + " or ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "')"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (ENTEROPERATOR='" + Convert.ToString(reader["OPID"]) + "' "; } else { str = str + " or ENTEROPERATOR='" + Convert.ToString(reader["OPID"]) + "'"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } public static string GetSumRangDAStr(string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modchfeeSum' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " 1=2 "; } else if (visiblerange == "3") { str = " ENTEROPERATOR='" + userid + "'"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') and ENTEROPERATOR in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')"; } else if (visiblerange == "1") { str = " ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else { str = str + " or ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "')"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (ENTEROPERATOR='" + Convert.ToString(reader["OPID"]) + "' "; } else { str = str + " or ENTEROPERATOR='" + Convert.ToString(reader["OPID"]) + "'"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } public static string GetAmendRangDAStr(string optype, string userid, string username, string companyid) { string str = ""; string modustr = ""; optype = optype.ToLower(); if (optype == "op_seae") { modustr = "modRecvFeeManagement"; } else if (optype == "op_apply") { modustr = "modApplyRecvFeeManagement"; } else if (optype == "op_seai") { modustr = "modSeaiRecvFeeManagement"; } else if (optype == "op_aire") { modustr = "modAireRecvFeeManagement"; } else if (optype == "op_airi") { modustr = "modAiriRecvFeeManagement"; } else if (optype == "op_seailcl") { modustr = "modSeaiLCLRecvFeeManagement"; } else if (optype == "op_other" || optype == "tmswlpchead" || optype == "opctnbscard" || optype == "op_airn") { modustr = "modOtherRecvFeeManagement"; } else if (optype == "op_bulk") { modustr = "modBulkRecvFeeManagement"; } else if (optype == "op_railway") { modustr = "modRailwayRecvFeeManagement"; } else if (optype == "import_main") { modustr = "modImport_Fee"; } else if (optype == "wmsmain") { modustr = "modWMSMAIN"; } else if (optype == "op_truckbulk") { modustr = "modTruckRecvFeeManagement"; } else if (optype == "op_internaltrade") { modustr = "modOp_InternalTradeRecvFeeManagement"; } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='" + modustr + "' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " CREATEUSER='" + username + "'"; } else if (visiblerange == "3") { str = " CREATEUSER='" + username + "'"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptid = rangeDa.GetDEPTGID(userid); str = " (CREATEUSER in (select showname from vw_user where deptgid='" + deptid + "') )"; } else if (visiblerange == "1") { str = " CREATEUSER in (select showname from vw_user where COMPANYID='" + companyid + "') "; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (CREATEUSER in (select showname from vw_user where COMPANYID='" + companyid + "') "; } else { str = str + " or CREATEUSER in (select showname from vw_user where COMPANYID='" + companyid + "')"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (CREATEUSER='" + Convert.ToString(reader["SHOWNAME"]) + "' "; } else { str = str + " or CREATEUSER='" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } if (str != "") str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #region 销售订舱费用 static public List GetOrderDataList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("GId,BsNo,FeeStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=ch_fee_order.FeeStatus) as FeeStatus_Ref"); strSql.Append(",FeeType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=ch_fee_order.FeeType) as FeeType_Ref"); strSql.Append(",FeeName,"); strSql.Append("FeeDescription,CustomerType,CustomerName,"); strSql.Append("Unit,UnitPrice,TaxUnitPrice,Quantity,TaxRate,NoTaxAmount,Amount,AccTaxRate,Currency,ExChangerate,Reason"); strSql.Append(",Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate"); strSql.Append(",Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen"); strSql.Append(",(select ShowName from [user] where GID=ch_fee_order.EnteroPerator) as OpName"); strSql.Append(",IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum"); strSql.Append(",ChequeNum,WmsOutBsNo,LineNum"); strSql.Append(",'' MODIFIEDUSER,null MODIFIEDTIME,0 UNINVOICE,0 PREAMOUNT,0 TAX,'' INPUTMODE "); strSql.Append(",'' Auditoperatorref,'' LOCALCURR,'' MANAGER ,'' MANAGERREF "); strSql.Append(",'' customerFullName,''STATEMENTNO,'' SALECORP,0 ISDJY "); strSql.Append(",'' VOUNO,'' INVLINKGID "); strSql.Append(" from ch_fee_order "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by sort,LineNum "); return SetData(strSql); } static public List GetEdiDataList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("CH_ID GId,[编号] BsNo,1 FeeStatus,"); strSql.Append("'录入状态' as FeeStatus_Ref"); strSql.Append(",2 FeeType,"); strSql.Append("'付' as FeeType_Ref"); strSql.Append(",[费用名称] FeeName,"); strSql.Append("[费用英文名称] FeeDescription,'船公司' CustomerType,[客户名称] CustomerName,"); strSql.Append("[标准] Unit,[单价] UnitPrice,[单价] TaxUnitPrice,[数量] Quantity,0 TaxRate,[金额] NoTaxAmount,[金额] Amount,0 AccTaxRate,0 TAX,[币别] Currency,[汇率] ExChangerate,'' Reason"); strSql.Append(",[备注] Remark,0 Commissionrate,0 Settlement,0 Invoice,0 OrderAmount,0 OrderInvoice,null SubmitDate"); strSql.Append(",'' Auditoperator,null AuditDate,'' EnteroPerator,null EnterDate,'' DebitNo,0 IsDebit,0 IsOpen"); strSql.Append(",'' as OpName"); strSql.Append(",0 IsAdvancedpay,0 Sort,0 IsInvoice,'PP' FeeFrt,0 IsCrmOrderFee,0 AuditStatus,[发票号码] InvoiceNum"); strSql.Append(",'' ChequeNum,'' WmsOutBsNo,0 LineNum"); strSql.Append(",'' MODIFIEDUSER,null MODIFIEDTIME,0 UNINVOICE,0 PREAMOUNT,[报文类型] INPUTMODE "); strSql.Append(",'' Auditoperatorref,'' LOCALCURR,'' MANAGER ,'' MANAGERREF "); strSql.Append(",'' customerFullName,''STATEMENTNO,'' SALECORP"); strSql.Append(",'' VOUNO,0 ISDJY,'' INVLINKGID "); strSql.Append(" from t_ch_fee_edi "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by 顺序 "); return SetData(strSql); } static public int SaveUpdateOrderFee(IList tempFeeEntities, string tempBSNO, string tempUserID) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] validParms = new SqlParameter[] { new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36) }; foreach (MsChFee feeEntity in tempFeeEntities) { if (feeEntity.BsNo == "*" || feeEntity.BsNo == "") { SqlParameter[] parms = GetInsertParms(); parms[0].Value = feeEntity.GId; parms[1].Value = tempBSNO; parms[2].Value = feeEntity.FeeType; parms[3].Value = feeEntity.FeeName; parms[4].Value = feeEntity.FeeDescription; parms[5].Value = feeEntity.CustomerType; parms[6].Value = feeEntity.CustomerName; parms[7].Value = feeEntity.Unit; parms[8].Value = feeEntity.UnitPrice; parms[9].Value = feeEntity.Quantity; parms[10].Value = feeEntity.Amount; parms[11].Value = feeEntity.Currency; parms[12].Value = feeEntity.ExChangerate; parms[13].Value = feeEntity.Reason; parms[14].Value = feeEntity.Remark; parms[15].Value = feeEntity.Commissionrate; parms[16].Value = feeEntity.EnteroPerator; parms[17].Value = DateTime.Now; parms[18].Value = feeEntity.IsOpen; if (feeEntity.IsAdvancedpay != null) { if (feeEntity.IsAdvancedpay == "0" || feeEntity.IsAdvancedpay == "1") { parms[19].Value = feeEntity.IsAdvancedpay; } else { if (Convert.ToBoolean(feeEntity.IsAdvancedpay)) { parms[19].Value = "1"; } else { parms[19].Value = "0"; } }; } else parms[19].Value = "0"; parms[20].Value = feeEntity.Sort; parms[21].Value = feeEntity.FeeStatus; parms[22].Value = feeEntity.FeeFrt; parms[23].Value = feeEntity.TaxRate; parms[24].Value = feeEntity.NoTaxAmount; parms[25].Value = feeEntity.AccTaxRate; parms[26].Value = feeEntity.LineNum; parms[27].Value = feeEntity.TaxUnitPrice; parms[28].Value = tempUserID; parms[29].Value = DateTime.Now.ToString(); parms[30].Value = feeEntity.WmsOutBsNo.ToString().Trim().Equals(null) ? "" : feeEntity.WmsOutBsNo.ToString().Trim(); parms[31].Value = feeEntity.PreAmount; parms[33].Value = feeEntity.INPUTMODE; if (feeEntity.IsInvoice != null) { if (feeEntity.IsInvoice == "0" || feeEntity.IsInvoice == "1") { parms[32].Value = feeEntity.IsInvoice; } else { if (Convert.ToBoolean(feeEntity.IsInvoice) || feeEntity.IsInvoice == "t") { parms[32].Value = "1"; } else { parms[32].Value = "0"; } }; } else parms[32].Value = "0"; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_ORDERFEE, parms); } else { SqlParameter[] updateParms = new SqlParameter[] { new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36), new SqlParameter(PARM_FEE_NAME,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_DESCRIPTION,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_CUSTOMER_TYPE,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_CUSTOMER_NAME,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_UNIT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_UNIT_PRICE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal,20), new SqlParameter(PARM_FEE_FRT,SqlDbType.VarChar,20), new SqlParameter(PARM_FEE_REMARK,SqlDbType.VarChar), new SqlParameter(PARM_FEE_ISADVANCEPAY,SqlDbType.VarChar,1), new SqlParameter(PARM_FEE_AUDIT_WMSOUTBSNO,SqlDbType.VarChar,100), new SqlParameter("@LINENUM",SqlDbType.Int), new SqlParameter("@TAXRATE",SqlDbType.Decimal,20), new SqlParameter("@NOTAXAMOUNT",SqlDbType.Decimal,20), new SqlParameter("@ACCTAXRATE",SqlDbType.Decimal,20), new SqlParameter("@TAXUNITPRICE",SqlDbType.Decimal,20) }; updateParms[0].Value = feeEntity.GId; updateParms[1].Value = feeEntity.FeeName; updateParms[2].Value = feeEntity.FeeDescription; updateParms[3].Value = feeEntity.CustomerType; updateParms[4].Value = feeEntity.CustomerName; updateParms[5].Value = feeEntity.Unit; updateParms[6].Value = feeEntity.UnitPrice; updateParms[7].Value = feeEntity.Quantity; updateParms[8].Value = feeEntity.Commissionrate; updateParms[9].Value = feeEntity.Amount; updateParms[10].Value = feeEntity.Currency; updateParms[11].Value = feeEntity.ExChangerate; updateParms[12].Value = feeEntity.FeeFrt; updateParms[13].Value = feeEntity.Remark; if (feeEntity.IsAdvancedpay != null) { if (feeEntity.IsAdvancedpay == "0" || feeEntity.IsAdvancedpay == "1") { updateParms[14].Value = feeEntity.IsAdvancedpay; } else { if (Convert.ToBoolean(feeEntity.IsAdvancedpay)) { updateParms[14].Value = "1"; } else { updateParms[14].Value = "0"; } } } else updateParms[14].Value = "0"; updateParms[15].Value = feeEntity.WmsOutBsNo.ToString().Trim().Equals(null) ? "" : feeEntity.WmsOutBsNo.ToString().Trim(); updateParms[16].Value = feeEntity.LineNum; updateParms[17].Value = feeEntity.TaxRate; updateParms[18].Value = feeEntity.NoTaxAmount; updateParms[19].Value = feeEntity.AccTaxRate; updateParms[20].Value = feeEntity.TaxUnitPrice; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_ORDERCH_FE, updateParms); } } sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } static public int DeleteOrderFee(string tempGId) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { var strSql = new StringBuilder(); strSql.Append("Delete from ch_fee_order where "); strSql.Append(" GId in (" + tempGId + ")"); SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString()); sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } static public List GetOrderGainList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("BsNo,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBDR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDDR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDDR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS NOTAXUSDCR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTDR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) ELSE 0 END),0) AS OTCR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTDR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) ELSE 0 END),0) AS NOTAXOTCR, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS DRTTL,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS CRTTL, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXDRTTL, "); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS NOTAXCRTTL "); strSql.Append(" from ch_fee_order "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" Group by Bsno "); return SetOrderGainData(strSql); } private static List SetOrderGainData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpGain data = new MsOpGain(); #region Set DB data to Object data.CURR = "人民币"; if (reader["NOTAXRMBDR"] != DBNull.Value) data.NORATEDR = Convert.ToDecimal(reader["NOTAXRMBDR"]); data.DR = Convert.ToDecimal(reader["RMBDR"]); if (reader["NOTAXRMBCR"] != DBNull.Value) data.NORATECR = Convert.ToDecimal(reader["NOTAXRMBCR"]); data.CR = Convert.ToDecimal(reader["RMBCR"]); if (reader["NOTAXRMBDR"] != DBNull.Value && reader["NOTAXRMBCR"] != DBNull.Value) data.NORATEPR = Convert.ToString(Convert.ToDecimal(reader["NOTAXRMBDR"]) - Convert.ToDecimal(reader["NOTAXRMBCR"])); data.PR =Convert.ToString(Convert.ToDecimal(reader["RMBDR"]) - Convert.ToDecimal(reader["RMBCR"])); #endregion bodyList.Add(data); MsOpGain dataUsd = new MsOpGain(); #region Set DB data to Object dataUsd.CURR = "美元"; if (reader["NOTAXUSDDR"] != DBNull.Value) dataUsd.NORATEDR = Convert.ToDecimal(reader["NOTAXUSDDR"]); dataUsd.DR = Convert.ToDecimal(reader["USDDR"]); if (reader["NOTAXUSDCR"] != DBNull.Value) dataUsd.NORATECR = Convert.ToDecimal(reader["NOTAXUSDCR"]); dataUsd.CR = Convert.ToDecimal(reader["USDCR"]); if (reader["NOTAXUSDDR"] != DBNull.Value && reader["NOTAXUSDCR"] != DBNull.Value) dataUsd.NORATEPR = Convert.ToString(Convert.ToDecimal(reader["NOTAXUSDDR"]) - Convert.ToDecimal(reader["NOTAXUSDCR"])); dataUsd.PR =Convert.ToString(Convert.ToDecimal(reader["USDDR"]) - Convert.ToDecimal(reader["USDCR"])); #endregion bodyList.Add(dataUsd); MsOpGain dataot = new MsOpGain(); #region Set DB data to Object dataot.CURR = "其他币别"; if (reader["NOTAXOTDR"] != DBNull.Value) dataot.NORATEDR = Convert.ToDecimal(reader["NOTAXOTDR"]); dataot.DR = Convert.ToDecimal(reader["OTDR"]); if (reader["NOTAXOTCR"] != DBNull.Value) dataot.NORATECR = Convert.ToDecimal(reader["NOTAXOTCR"]); dataot.CR = Convert.ToDecimal(reader["OTCR"]); if (reader["NOTAXOTDR"] != DBNull.Value && reader["NOTAXOTCR"] != DBNull.Value) dataot.NORATEPR = Convert.ToString(Convert.ToDecimal(reader["NOTAXOTDR"]) - Convert.ToDecimal(reader["NOTAXOTCR"])); dataot.PR =Convert.ToString(Convert.ToDecimal(reader["OTDR"]) - Convert.ToDecimal(reader["OTCR"])); #endregion bodyList.Add(dataot); MsOpGain datattl = new MsOpGain(); #region Set DB data to Object datattl.CURR = "合计"; if (reader["NOTAXDRTTL"] != DBNull.Value) datattl.NORATEDR = Convert.ToDecimal(reader["NOTAXDRTTL"]); datattl.DR = Convert.ToDecimal(reader["DRTTL"]); if (reader["NOTAXCRTTL"] != DBNull.Value) datattl.NORATECR = Convert.ToDecimal(reader["NOTAXCRTTL"]); datattl.CR = Convert.ToDecimal(reader["CRTTL"]); if (reader["NOTAXDRTTL"] != DBNull.Value && reader["NOTAXCRTTL"] != DBNull.Value) datattl.NORATEPR = Convert.ToString(Convert.ToDecimal(reader["NOTAXDRTTL"]) - Convert.ToDecimal(reader["NOTAXCRTTL"])); datattl.PR =Convert.ToString(Convert.ToDecimal(reader["DRTTL"]) - Convert.ToDecimal(reader["CRTTL"])); #endregion bodyList.Add(datattl); } reader.Close(); } if (bodyList.Count == 0) { MsOpGain data = new MsOpGain(); #region Set DB data to Object data.CURR = "人民币"; data.NORATEDR = 0; data.DR = 0; data.NORATECR = 0; data.CR = 0; data.NORATEPR = "0"; data.PR ="0"; #endregion bodyList.Add(data); MsOpGain dataUsd = new MsOpGain(); #region Set DB data to Object dataUsd.CURR = "美元"; dataUsd.NORATEDR = 0; dataUsd.DR = 0; dataUsd.NORATECR = 0; dataUsd.CR = 0; dataUsd.NORATEPR = "0"; dataUsd.PR = "0"; #endregion bodyList.Add(dataUsd); MsOpGain dataot = new MsOpGain(); #region Set DB data to Object dataot.CURR = "其他币别"; dataot.NORATEDR = 0; dataot.DR = 0; dataot.NORATECR = 0; dataot.CR = 0; dataot.NORATEPR = "0"; dataot.PR = "0"; #endregion bodyList.Add(dataot); MsOpGain datattl = new MsOpGain(); #region Set DB data to Object datattl.CURR = "合计"; datattl.NORATEDR = 0; datattl.DR = 0; datattl.NORATECR = 0; datattl.CR = 0; datattl.NORATEPR = "0"; datattl.PR = "0"; #endregion bodyList.Add(datattl); } return bodyList; } #endregion #region 获取费用名称关联的默认计费单位,以及相关计费单位的数量 static public List GetFeeDefaultUnitList(string BSNO,string FEENAME) { Database db_t = DatabaseFactory.CreateDatabase(); string strCheckRow = " select OPLB from vw_settlement where BSNO= '" + BSNO + "' "; object statusObj = SqlHelper.ExecuteScalar(db_t.ConnectionString, CommandType.Text, strCheckRow, null); var TableName = statusObj.ToString(); var strSql = new StringBuilder(); if (TableName == "op_seae")//海运出口 { strSql.Append(" select 'op_seae' OPLB ,KGS,0 NETWEIGHT,(select isnull(sum(teu),0) from op_ctn where bsno=op_seae.bsno) teu "); strSql.Append(" ,(select top 1 ctnall from op_ctn where bsno='" + BSNO + "') CTNALL,(select feetype from code_fee where name='" + FEENAME + "') FEETYPE"); strSql.Append(" ,(select top 1 CTNNUM from op_ctn where bsno='" + BSNO + "') CTNNUM "); strSql.Append(" from op_seae"); strSql.Append(" where BSNO='" + BSNO + "'"); } else if (TableName == "op_seai")//海运进口 { strSql.Append(" select 'op_seai' OPLB ,KGS,NETWEIGHT,(select isnull(sum(teu),0) from op_ctn where bsno=op_seai.bsno) teu "); strSql.Append(" ,(select top 1 ctnall from op_ctn where bsno='" + BSNO + "') CTNALL,(select feetype from code_fee where name='" + FEENAME + "') FEETYPE"); strSql.Append(" ,(select top 1 CTNNUM from op_ctn where bsno='" + BSNO + "') CTNNUM "); strSql.Append(" from op_seai"); strSql.Append(" where BSNO='" + BSNO + "'"); } else { strSql.Append(" select '" + TableName + "' OPLB ,0 KGS,0 NETWEIGHT,0 teu,(select feetype from code_fee where name='" + FEENAME + "') FEETYPE from op_seai"); }//防止无参数调用 return SetFeeDefaultUnitList(strSql); } private static List SetFeeDefaultUnitList(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { FeeDefaultUnitmb data = new FeeDefaultUnitmb(); #region Set DB data to Object data.OPLB = Convert.ToString(reader["OPLB"]); data.KGS = Convert.ToString(reader["KGS"]); data.WEIGHT = Convert.ToString(reader["NETWEIGHT"]); data.TEU = Convert.ToString(reader["TEU"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.FEETYPE = Convert.ToString(reader["FEETYPE"]); data.CTNNUM = Convert.ToString(reader["CTNNUM"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion public static DBResult ShenNewSALECORP(List FeeList, string NewSALECORP, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"UPDATE CH_FEE SET SALECORP=@SALECORP WHERE GID=@GID "); if (FeeList != null) { foreach (var enumValue in FeeList) { var GROUPID = Guid.NewGuid().ToString(); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GId); db.AddInParameter(cmdUpdate, "@SALECORP", DbType.String, NewSALECORP); db.ExecuteNonQuery(cmdUpdate, tran); } } result = new DBResult(); result.Success = true; result.Message = "修改成功"; tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "申请修改出现错误,请重试或联系系统管理员"+e.Message; return result; } } result.Success = true; result.Message = "申请修改成功"; return result; } static public DBResult GetCarrierInvInterfaceList(string bsno, string userid,string username,string companyid) { var result = new DBResult(); result.Success = true; var opseae = MsOpSeaeDAL.MsOpSeaeDAL.GetData("BSNO='"+bsno+"'"); var mblno = opseae.MBLNO; var carrier = opseae.CARRIER; if (string.IsNullOrEmpty(mblno) || string.IsNullOrEmpty(carrier)) { result.Message = "提单号或船公司为空不能提取数据!"; result.Success = false; } var carrierid = ""; var yarddataset = MsCodeYardDataSetDAL.GetData("YARD='" + carrier + "'", companyid); if (yarddataset == null || yarddataset.YARDCODE == "") { result.Message = "不能提取数据,未设置此船公司提取数据的相关的参数!"; result.Success = false; } carrierid = yarddataset.YARDCODE; string qduname = ""; string qdpwd = ""; string customername = ""; string password = ""; var thirdpartyaccount = MsSysThirdPartyAccount.MsSysThirdPartyAccountDAL.GetData(" THIRDPARTY='" + carrierid + "' and (USERID='" + userid + "' OR ISNULL(USERID,'')='')"); qduname = thirdpartyaccount.ACCOUNT; qdpwd = thirdpartyaccount.ACCOUNTPSW; if (string.IsNullOrEmpty(qduname)) { result.Message = "不能提取数据,为设置船公司网站账号密码,请在系统设置中第三方账号维护中设置!"; result.Success = false; } try { #region 抓取页面 customername = MsSysParamSetDAL.GetData("PARAMNAME='GETDATANAME'").PARAMVALUE; password = MsSysParamSetDAL.GetData("PARAMNAME='GETDATAPASS'").PARAMVALUE; var GetYardDataUrl = ""; try { GetYardDataUrl = WebConfigurationManager.AppSettings["GetInvDataUrl"].ToString(); } catch { } if (GetYardDataUrl == "") GetYardDataUrl = "http://47.104.90.170:9000/invoice"; JObject reqObj = new JObject(); reqObj.Add("yardid", new JValue(carrierid)); reqObj.Add("custname", new JValue(customername)); reqObj.Add("custpwd", new JValue(password)); reqObj.Add("username", new JValue(qduname)); reqObj.Add("pwd", new JValue(qdpwd)); reqObj.Add("billno", new JValue(mblno)); ////Dictionary dicPara = new Dictionary(); ////dicPara.Add("yardid", carrierid); ////dicPara.Add("custname", customername); ////dicPara.Add("custpwd", password); ////dicPara.Add("username", qduname); ////dicPara.Add("pwd", qdpwd); ////dicPara.Add("billno", mblno); var datahtml = WebRequestHelper.DoPost(GetYardDataUrl, reqObj.ToString(Formatting.None),600*1000); #endregion var objRtn = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(datahtml, new { status = "" }); if (objRtn.status == "1") { var objRtn2 = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(datahtml, new JsonMsInvFee()); result = CreateFeeBl(objRtn2.message,bsno, carrier,userid, username,companyid); } else { var objRtn2 = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(datahtml, new { status = "", message = "" }); result.Success = false; result.Message = objRtn2.message; } } catch (Exception e) { result.Success = false; result.Message = "没有提取到需要的数据!" + e.Message; } return result; } public static bool GetIsImp(string bsno,string invno, Database db, DbTransaction tran) { int rst = 0; string sql = "select COUNT(1) CT from ch_fee where BSNO='" + bsno + "' AND CARGO_GID='" + invno + "'"; rst = Convert.ToInt32(db.ExecuteScalar(tran,CommandType.Text, sql)); return rst > 0; } public static string getfeename(string feeename, Database db, DbTransaction tran) { var feename = ""; string sql2 = "select top 1 [FEENAME] from code_fee_edi where [FEEENAME]='" + feeename + "'"; var blno = db.ExecuteScalar(tran,CommandType.Text, sql2); if (blno == DBNull.Value || blno == null) { feename = ""; } else { feename = blno.ToString(); } return feename; } public static DBResult CreateFeeBl(List headList, string bsno,string carrier,string userid, string username,string companyid) { var result = new DBResult(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsertFee = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,CARGO_GID, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC) VALUES(@GID,@BSNO,@FEETYPE,@FEENAME,@FEEDESCRIPTION,@CUSTOMERTYPE,@CUSTOMERNAME,@UNIT,@UNITPRICE,@QUANTITY,@AMOUNT,@CURRENCY, @EXCHANGERATE, @REASON, @REMARK, @COMMISSIONRATE,@ENTEROPERATOR, @ENTERDATE,@ISOPEN, @ISADVANCEDPAY, @SORT, @FEESTATUS, @FEEFRT,@CARGO_GID, @TAXRATE,@NOTAXAMOUNT,@ACCTAXRATE,@LINENUM,@TAXUNITPRICE,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@ISINVOICE,@INPUTMODE,@LOCALCURR,@MANAGER,@ISACC) "); foreach (var headData in headList) { if (!GetIsImp(bsno,headData.invoice_no,db,tran)) foreach (var feeitems in headData.fee) { var CURR = feeitems.amount_c; if (CURR == "CNY") CURR = "RMB"; var FEENAME = getfeename(feeitems.fee_type,db,tran); cmdInsertFee.Parameters.Clear(); db.AddInParameter(cmdInsertFee, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsertFee, "@BSNO", DbType.String, bsno); db.AddInParameter(cmdInsertFee, "@FEETYPE", DbType.Int16, 2); db.AddInParameter(cmdInsertFee, "@UNITPRICE", DbType.Decimal,feeitems.fee_rate); db.AddInParameter(cmdInsertFee, "@AMOUNT", DbType.Decimal, feeitems.vat_sum); db.AddInParameter(cmdInsertFee, "@NOTAXAMOUNT", DbType.Decimal, feeitems.amount); db.AddInParameter(cmdInsertFee, "@TAXUNITPRICE", DbType.Decimal, feeitems.fee_rate); db.AddInParameter(cmdInsertFee, "@FEENAME", DbType.String, FEENAME); db.AddInParameter(cmdInsertFee, "@FEEDESCRIPTION", DbType.String,feeitems.fee_type); db.AddInParameter(cmdInsertFee, "@CUSTOMERTYPE", DbType.String, "船公司"); db.AddInParameter(cmdInsertFee, "@CUSTOMERNAME", DbType.String, carrier); db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, "票"); db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, feeitems.count); db.AddInParameter(cmdInsertFee, "@CURRENCY", DbType.String, CURR); if (CURR=="RMB") db.AddInParameter(cmdInsertFee, "@EXCHANGERATE", DbType.Decimal, 1); else db.AddInParameter(cmdInsertFee, "@EXCHANGERATE", DbType.Decimal, GetExrate(DateTime.Now.ToString(),companyid, db, tran, CURR)); db.AddInParameter(cmdInsertFee, "@REASON", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@REMARK", DbType.String,"发票引入"); db.AddInParameter(cmdInsertFee, "@COMMISSIONRATE", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@ENTEROPERATOR", DbType.String, userid); db.AddInParameter(cmdInsertFee, "@ENTERDATE", DbType.String, DateTime.Now.ToString()); db.AddInParameter(cmdInsertFee, "@ISOPEN", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@ISADVANCEDPAY", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@SORT", DbType.Int16, 1); db.AddInParameter(cmdInsertFee, "@FEESTATUS", DbType.Int16, 1); db.AddInParameter(cmdInsertFee, "@FEEFRT", DbType.String, "PP"); db.AddInParameter(cmdInsertFee, "@CARGO_GID", DbType.String, headData.invoice_no); db.AddInParameter(cmdInsertFee, "@TAXRATE", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@ACCTAXRATE", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@LINENUM", DbType.Int16, 1); db.AddInParameter(cmdInsertFee, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsertFee, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString()); db.AddInParameter(cmdInsertFee, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@PREAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@ISINVOICE", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@INPUTMODE", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@LOCALCURR", DbType.String, "RMB"); db.AddInParameter(cmdInsertFee, "@MANAGER", DbType.String, username); db.AddInParameter(cmdInsertFee, "@ISACC", DbType.Boolean, false); db.ExecuteNonQuery(cmdInsertFee, tran); } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "生成费用出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "生成成功"; return result; } public static DBResult CreateZnjFee(MsOpBillZnj HeadData, string FeeName, string ZNJ, string userid, string username, string companyid) { var result = new DBResult(); result.Success = true; result.Message = "保存成功"; int feestatus = 0; T_ALL_DA T_ALL_DA = new T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var BSNO = ""; if (HeadData.FEESTATUSREF == "锁定") { var head = new MsOpAmend(); head.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); head.CREATEUSER = username; var period = ChMonthCloseDAL.ChMonthCloseDAL.GetData("", companyid); if (Convert.ToDateTime(period.FDAY) > DateTime.Now) { head.ACCDATE = period.PERIOD; } else { head.ACCDATE = DateTime.Now.ToString("yyyy-MM"); } head.PARENTID = HeadData.PARENTID; head.BSNO = Guid.NewGuid().ToString(); head.SALE = HeadData.SALE; head.DbOperationType = DbOperationType.DbotIns; head.REASON = "滞纳金"; head.GID = Guid.NewGuid().ToString(); var modb = new ModelObjectDB(); result = modb.Save(head); BSNO = head.BSNO; } if (BSNO == "") BSNO = HeadData.PARENTID; var cmdInsert = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,IsCrmOrderFee) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@IsCrmOrderFee) "); if (!string.IsNullOrEmpty(ZNJ) && HeadData.USDHYFCR != 0) { var feeamount = HeadData.USDHYFCR * Convert.ToDecimal(ZNJ) / 100; var FEEID = Guid.NewGuid().ToString(); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, FEEID); db.AddInParameter(cmdInsert, "@bsno", DbType.String, BSNO); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, FeeName); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, ""); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, HeadData.CUSTOMERNAME); db.AddInParameter(cmdInsert, "@unit", DbType.String, "票"); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, feeamount); var strDESCRIPTION = T_ALL_DA.GetStrSQL("DESCRIPTION", "select top 1 DESCRIPTION from code_fee where [NAME]='" + FeeName + "'"); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, strDESCRIPTION); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@currency", DbType.String, "USD"); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, MsChFeeDAL.GetExrate(DateTime.Now.ToString(), companyid, db, tran, "USD")); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, ""); // db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 10); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, feestatus); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 10); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "自动生成"); db.AddInParameter(cmdInsert, "@IsCrmOrderFee", DbType.String, "1"); db.ExecuteNonQuery(cmdInsert, tran); } tran.Commit(); result.Success = true; result.Message = "保存成功" + result.Message; } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; } } return result; } public static DBResult CreateDzlxFee(MsOpBillZnj HeadData, string FeeName, string ZNJ, string FeeType, string userid, string username, string companyid) { var result = new DBResult(); result.Success = true; result.Message = "保存成功"; int feestatus = 0; var stllist = GetStlAmountList("d.BSNO='"+HeadData.BSNO+ "' and s.SETTLETIME<'"+HeadData.STLDRDATE+"'"); decimal stlamount = 0; string stlstr = ""; var NewStlList = new List(); if (stllist != null) { foreach (var stlitems in stllist) { var days = (Convert.ToDateTime(HeadData.STLDRDATE) - Convert.ToDateTime(stlitems.SETTLETIME)).Days; stlamount = stlamount + Math.Round(Math.Round(stlitems.STLAMOUNT,2, MidpointRounding.AwayFromZero) * days * Convert.ToDecimal(ZNJ) / 100, 2, MidpointRounding.AwayFromZero); stlstr = stlstr + " "+ stlitems.SETTLETIME+" " + " " + stlitems.CURRENCY + " " + Math.Round(stlitems.ORIGAMOUNT, 2, MidpointRounding.AwayFromZero).ToString()+"*"+days.ToString()+"*"+ZNJ+"%"; var isfind = false; var feeamount = Math.Round(Math.Round(stlitems.ORIGAMOUNT, 2, MidpointRounding.AwayFromZero) * days * Convert.ToDecimal(ZNJ) / 100, 2, MidpointRounding.AwayFromZero); if (feeamount > 0) { NewStlList.ForEach(i => { if (i.CURRENCY == stlitems.CURRENCY) { i.ORIGAMOUNT = i.ORIGAMOUNT + feeamount; isfind = true; } }); if (!isfind) { MsOpBillZnjStl data = new MsOpBillZnjStl(); data.CURRENCY = stlitems.CURRENCY; data.ORIGAMOUNT = feeamount; NewStlList.Add(data); } } } } if (stlamount <= 0) { result.Success = false; result.Message = "垫资利息为0,不需要生成!"; return result; } T_ALL_DA T_ALL_DA = new T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var BSNO = ""; if (HeadData.FEESTATUSREF == "锁定") { var head = new MsOpAmend(); head.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); head.CREATEUSER = username; var period = ChMonthCloseDAL.ChMonthCloseDAL.GetData("", companyid); if (Convert.ToDateTime(period.FDAY) > DateTime.Now) { head.ACCDATE = period.PERIOD; } else { head.ACCDATE = DateTime.Now.ToString("yyyy-MM"); } head.PARENTID = HeadData.PARENTID; head.BSNO = Guid.NewGuid().ToString(); head.SALE = HeadData.SALE; head.DbOperationType = DbOperationType.DbotIns; head.REASON = "垫资利息"; head.GID = Guid.NewGuid().ToString(); var modb = new ModelObjectDB(); result = modb.Save(head); BSNO = head.BSNO; } if (BSNO == "") BSNO = HeadData.PARENTID; var cmdInsert = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,IsCrmOrderFee) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@IsCrmOrderFee) "); var cmdInsertDz = db.GetSqlStringCommand( @"insert into op_dzlx (GID,BSNO,ISZYFEE,ZYFEEREMARK,INPUTDATE,INPUTBY) values (@GID,@BSNO,@ISZYFEE,@ZYFEEREMARK,@INPUTDATE,@INPUTBY) "); var cmddelete = db.GetSqlStringCommand( @"delete from op_dzlx where BSNO=@BSNO "); if (!string.IsNullOrEmpty(ZNJ) && stlamount != 0) { foreach (var stlitems in NewStlList) { var feeamount = stlitems.ORIGAMOUNT; if (feeamount != 0) { var FEEID = Guid.NewGuid().ToString(); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, FEEID); db.AddInParameter(cmdInsert, "@bsno", DbType.String, BSNO); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, FeeName); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, ""); if (FeeType == "1") { db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, HeadData.CUSTOMERNAME); } else { db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 2); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, "青岛鼎程供应链"); } db.AddInParameter(cmdInsert, "@unit", DbType.String, "票"); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, feeamount); var strDESCRIPTION = T_ALL_DA.GetStrSQL("DESCRIPTION", "select top 1 DESCRIPTION from code_fee where [NAME]='" + FeeName + "'"); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, strDESCRIPTION); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@currency", DbType.String, stlitems.CURRENCY); if (stlitems.CURRENCY=="RMB") db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal,1); else db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, MsChFeeDAL.GetExrate(DateTime.Now.ToString(), companyid, db, tran, stlitems.CURRENCY)); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, ""); // db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 10); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, feestatus); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 10); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, feeamount); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "自动生成"); db.AddInParameter(cmdInsert, "@IsCrmOrderFee", DbType.String, "1"); db.ExecuteNonQuery(cmdInsert, tran); } } cmddelete.Parameters.Clear(); db.AddInParameter(cmddelete, "@BSNO", DbType.String, HeadData.BSNO); db.ExecuteNonQuery(cmddelete, tran); cmdInsertDz.Parameters.Clear(); db.AddInParameter(cmdInsertDz, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsertDz, "@BSNO", DbType.String, HeadData.BSNO); db.AddInParameter(cmdInsertDz, "@ISZYFEE", DbType.Boolean, true); db.AddInParameter(cmdInsertDz, "@ZYFEEREMARK", DbType.String, stlstr); db.AddInParameter(cmdInsertDz, "@INPUTDATE", DbType.DateTime, DateTime.Now); db.AddInParameter(cmdInsertDz, "@INPUTBY", DbType.String, userid); db.ExecuteNonQuery(cmdInsertDz, tran); } tran.Commit(); result.Success = true; result.Message = "保存成功" + result.Message; } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; } } return result; } static public List GetStlAmountList(string strCondition) { var strSql = new StringBuilder(); strSql.Append(" select s.SETTLETIME,f.CURRENCY,SUM(d.ORIGAMOUNT) ORIGAMOUNT, sum(d.ORIGAMOUNT*f.EXCHANGERATE) STLAMOUNT "); strSql.Append("from ch_fee_do d"); strSql.Append(" left join ch_fee_settlement s on (s.BILLNO=d.BILLNO) left join ch_fee f on (f.GID=d.FEEID) "); strSql.Append(" where d.CATEGORY in (1,2,3,8,9) AND F.FEETYPE=2 and s.BILLNO is not null "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" GROUP BY S.SETTLETIME,f.CURRENCY "); strSql.Append(" ORDER BY S.SETTLETIME "); return StlAmountSetData(strSql); } private static List StlAmountSetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpBillZnjStl data = new MsOpBillZnjStl(); #region Set DB data to Object //data.BILLNO = Convert.ToString(reader["BILLNO"]); data.SETTLETIME = Convert.ToString(reader["SETTLETIME"]); data.CURRENCY = Convert.ToString(reader["CURRENCY"]); if (reader["STLAMOUNT"] != DBNull.Value) data.STLAMOUNT = Convert.ToDecimal(reader["STLAMOUNT"]); //if (reader["EXCHANGERATE"] != DBNull.Value) // data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]); if (reader["ORIGAMOUNT"] != DBNull.Value) data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #region 上传大简云账单中心 public static DBResult SendToDJY(string bsno,List bodyList, string companyid,string userid) { var result = new DBResult(); var PAYID = ""; var PAYNAME = ""; foreach (var fee in bodyList) { PAYNAME = bodyList[0].CustomerName; PAYID = MsOpSeaeEdiDAL.MsOpSeaeEdiDAL.GetCustEDICode(bodyList[0].CustomerName, "DJY"); //var PAYID ="QDDS"; if (string.IsNullOrEmpty(PAYID)) { result.Success = false; result.Message = "当前费用对象,请先设置大简云代码!"; return result; } } var cust = MsInfoClientDAL.GetData("SHORTNAME='"+ PAYNAME + "'"); var DJYCOMPANYID = MsSysParamSetDAL.GetData("PARAMNAME='DJYCOMPANYID'"); if (string.IsNullOrEmpty(DJYCOMPANYID.PARAMVALUE)) { result.Success = false; result.Message = "请先配置参数设置【大简云公司代码】"; return result; } var user = SysUserDAL.GetData("u.GID='" + userid + "'"); if (string.IsNullOrEmpty(user.EMAIL1)) { result.Success = false; result.Message = "当前用户邮件地址不能为空!"; return result; } var company = DJYCOMPANYID.PARAMVALUE; if (string.IsNullOrEmpty(company)) { var mscompany=MsCompanysDAL.MsCompanysDAL.GetNoPicData("GID='"+companyid+"'"); company = mscompany.FULLNAME; } try { var DJYDEBITURL = MsSysParamSetDAL.GetData("PARAMNAME='DJYDEBITURL'"); string rtn = ""; if (!string.IsNullOrEmpty(DJYDEBITURL.PARAMVALUE)) { var orderlist = CreateEdiDjy(bsno, bodyList, company); var strJson = JsonConvert.SerializeObject(new { UniqueId = Guid.NewGuid().ToString(), CompId = PAYID, UserName = cust.CHIEF, Email = cust.EMAIL, DirectOutput=true, Records = orderlist }); //var strJson = JsonConvert.SerializeObject(new { UniqueId = Guid.NewGuid().ToString(), CompId = "9f3b3526-4dd4-4997-b974-1f2adb2793c7", UserName = "衣国豪", Email = "wanghaomei@myshipping.net", Records = orderlist }); rtn = WebRequestHelper.DoPost(DJYDEBITURL.PARAMVALUE + "/bill/ReceiveBillData", strJson); var objRtn = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(rtn, new { Success = "", Message = "", Code = "" }); if (objRtn.Success == "false") { result.Success = false; result.Message = objRtn.Message + ",CODE" + objRtn.Code; } else { result.Success = true; } } else { result.Success = false; result.Message = "未设置上传接口"; } } catch(Exception ex) { result.Success = false; result.Message = "上传过程出错:"+ex.Message; } return result; } public static List CreateEdiDjy(string bsno,List bodyList,string DJYCOMPANYID) { var bill =MsOpSeaeDAL.MsOpSeaeDAL.GetData("BSNO='" + bsno + "'"); var orderlist = new List(); var order = new MsDjyInvFee(); order.BookingBill = bill.MBLNO; order.HouseBill = bill.HBLNO; order.ShippingCompany = bill.CARRIER; order.PortOfLoading = bill.PORTLOAD; order.Destination = bill.DESTINATION; order.UnloadingPort = bill.PORTDISCHARGE; order.SailingDate = bill.ETD; order.ShipName = bill.VESSEL; order.Voyage = bill.VOYNO; order.PayingFor = "QDDS"; order.PayingFor = DJYCOMPANYID; // order.BillRecipient= decimal usdtotal = 0; decimal rmbtotal = 0; var Feelist = new List(); foreach (var fee in bodyList) { var cntr = new MsDjyInvFeeDetail(); cntr.CostName = fee.FeeName; cntr.UnitPrice = fee.UnitPrice.ToString(); cntr.Quantity = fee.Quantity.ToString(); cntr.Amount = fee.Amount.ToString(); cntr.Currency = fee.Currency.ToString(); cntr.ExchangeRate = fee.ExChangerate.ToString(); cntr.UnitStandard = fee.Unit; cntr.ExchangeRate = fee.ExChangerate.ToString(); cntr.FeeStandard = fee.Unit; if (cntr.Currency == "RMB") rmbtotal = rmbtotal +Convert.ToDecimal(cntr.Amount); if (cntr.Currency == "USD") usdtotal = usdtotal + Convert.ToDecimal(cntr.Amount); Feelist.Add(cntr); } order.TotalRMB = rmbtotal.ToString(); order.TotalUSD = usdtotal.ToString(); order.Details = Feelist; orderlist.Add(order); return orderlist; } #endregion #region 上传大简云发票 public static string GetTelephoneList(string input) { //集合存放提取出来的电话号码 /* * 正则表达式提取 * 分为五种格式,能兼容11位手机号、3位或4位区号-7位或8位电话号、400电话的两种写法(400-ddd-dddd、400ddddddd) */ Regex regex = new Regex(@"(1[3|4|5|6|7|8|9]\d{9})|(0\d{2,3}-\d{7,8})|(400-\d{3}-\d{4})|(400\d{7})"); //Match集合,匹配成功的字符串集合 MatchCollection collection = regex.Matches(input); //遍历Match集合,取出值 string telephone=""; foreach (System.Text.RegularExpressions.Match item in collection) { foreach (Group group in item.Groups) { telephone = group.Value.Trim(); ////偶尔会出现重复提取,所以加了去重判断 //if (!string.IsNullOrEmpty(telephone) && !list.Contains(telephone)) //{ // list.Add(telephone); //} } } return telephone; } public static DBResult SendToDJYINV(List bsnoList, List bodyList, string companyid, string userid) { var result = new DBResult(); var DJYCOMPANYID = MsSysParamSetDAL.GetData("PARAMNAME='DJYCOMPANYID'"); if (string.IsNullOrEmpty(DJYCOMPANYID.PARAMVALUE)) { result.Success = false; result.Message = "请先配置参数设置【大简云公司代码】"; return result; } var DJYINVURL = MsSysParamSetDAL.GetData("PARAMNAME='DJYINVURL'"); if (string.IsNullOrEmpty(DJYINVURL.PARAMVALUE)) { result.Success = false; result.Message = "请先配置参数设置【大简云自助开票接口地址】"; return result; } var defaultPAYEE = MsSysParamSetDAL.GetData("PARAMNAME='INVSKR'").PARAMVALUE; var defaultCHECKER = MsSysParamSetDAL.GetData("PARAMNAME='INVFHR'").PARAMVALUE; var defaultKPR = MsSysParamSetDAL.GetData("PARAMNAME='INVKPR'").PARAMVALUE; if (string.IsNullOrEmpty(defaultPAYEE) || string.IsNullOrEmpty(defaultCHECKER) || string.IsNullOrEmpty(defaultKPR)) { result.Success = false; result.Message = "默认发票收款人或复核人、开票人不能为空,请在参数设置设置!"; return result; } var user = SysUserDAL.GetData("u.GID='" + userid + "'"); var company = DJYCOMPANYID.PARAMVALUE; var mscompany = MsCompanysDAL.MsCompanysDAL.GetNoPicData("GID='" + companyid + "'"); if (string.IsNullOrEmpty(company)) { company = mscompany.FULLNAME; } var InvLinkList = new List(); var MsDjyInvLjList = new List(); foreach (var fee in bodyList) { var newinvlink = InvLinkList.Find(X => X.CURRENCY == fee.Currency && X.CUSTOMERNAME == fee.CustomerName); if (newinvlink == null) { var MsDjyInvLj = new MsDjyInvLjFee(); var InvLink = new Ch_feeInvLink(); InvLink.INVLINKGID = Guid.NewGuid().ToString(); InvLink.CREATETIME = DateTime.Now; InvLink.CREATEUSER = userid; InvLink.CURRENCY = fee.Currency; InvLink.CUSTOMERNAME = fee.CustomerName; InvLinkList.Add(InvLink); var cust = BasicDataRefDAL.GetCustomInvRef("SHORTNAME='" + fee.CustomerName + "'"); MsDjyInvLj.LinkId = InvLink.INVLINKGID; MsDjyInvLj.CompanyId = company; MsDjyInvLj.Email = user.EMAIL1; MsDjyInvLj.BuyerName = cust[0].BillRises1; MsDjyInvLj.BuyerTaxNum = cust[0].TaxNo; MsDjyInvLj.BuyerTel = GetTelephoneList(cust[0].INVADDRTEL); if (!string.IsNullOrEmpty(cust[0].INVADDRTEL)&&!string.IsNullOrEmpty(MsDjyInvLj.BuyerTel)) MsDjyInvLj.BuyerAddress = cust[0].INVADDRTEL.Replace(MsDjyInvLj.BuyerTel, ""); if (fee.Currency == "RMB") MsDjyInvLj.BuyerAccount = cust[0].RMBBank + " " + cust[0].RMBAccount; else MsDjyInvLj.BuyerAccount = cust[0].USDBank + " " + cust[0].USDAccount; if (string.IsNullOrEmpty(MsDjyInvLj.BuyerName)) { result.Success = false; result.Message = "客户发票抬头不能为空!"; return result; } //if (string.IsNullOrEmpty(MsDjyInvLj.BuyerName) || string.IsNullOrEmpty(MsDjyInvLj.BuyerTaxNum) || string.IsNullOrEmpty(MsDjyInvLj.BuyerTel) // || string.IsNullOrEmpty(MsDjyInvLj.BuyerAddress) || string.IsNullOrEmpty(MsDjyInvLj.BuyerAccount)) //{ // result.Success = false; // result.Message = "客户发票抬头、税号、发票地址、电话、银行账户都不能为空!"; // return result; //} var BankList = MsBaseInfoDAL.MsBaseInfoDAL.GetBANKList("CURRENCY='" + fee.Currency + "'", companyid); MsDjyInvLj.SalerName = mscompany.BILLRISES; if (BankList != null && BankList.Count != 0) { foreach (var bank in BankList) { if (bank.ISDEF == "True") MsDjyInvLj.SalerAccount = bank.BANKACCOUNT; } if (string.IsNullOrEmpty(MsDjyInvLj.SalerAccount)) MsDjyInvLj.SalerAccount = BankList[0].BANKACCOUNT; } MsDjyInvLj.SalerAddress = mscompany.ADDRESS; MsDjyInvLj.SalerTaxNum = mscompany.TAXCODE; MsDjyInvLj.SalerTel = mscompany.OFFICEPHONE; if (string.IsNullOrEmpty(MsDjyInvLj.SalerName) || string.IsNullOrEmpty(MsDjyInvLj.SalerTaxNum) || string.IsNullOrEmpty(MsDjyInvLj.SalerTel) || string.IsNullOrEmpty(MsDjyInvLj.SalerAddress) || string.IsNullOrEmpty(MsDjyInvLj.BuyerAccount)) { result.Success = false; result.Message = "公司(我方)发票抬头、税号、发票地址、电话、银行账户都不能为空!"; return result; } MsDjyInvLj.Payee = defaultPAYEE; MsDjyInvLj.Checker = defaultCHECKER; MsDjyInvLj.Clerk = defaultKPR; if (InvLink.CURRENCY == "RMB") MsDjyInvLj.RemarkTemplate = MsSysParamSetDAL.GetData("PARAMNAME='INVREMARKTEMPLATE'").PARAMVALUE; else MsDjyInvLj.RemarkTemplate = MsSysParamSetDAL.GetData("PARAMNAME='USDINVREMARKTEMPLATE'").PARAMVALUE; MsDjyInvLjList.Add(MsDjyInvLj); if (InvLink.BSNOLIST == null) InvLink.BSNOLIST = new List(); if (InvLink.BSNOLIST.Find(X => X.BSNO == fee.BsNo) == null) { var bsnols = new BSNOLB(); bsnols.BSNO = fee.BsNo; InvLink.BSNOLIST.Add(bsnols); } } else { if (newinvlink.BSNOLIST == null) newinvlink.BSNOLIST = new List(); if (newinvlink.BSNOLIST.Find(X => X.BSNO == fee.BsNo) == null) { var bsnols = new BSNOLB(); bsnols.BSNO = fee.BsNo; newinvlink.BSNOLIST.Add(bsnols); } } } var FeeNolist = new List(); var newMsDjyInvLjList = CreateEdiDjyInv(InvLinkList, MsDjyInvLjList, bsnoList, bodyList,out FeeNolist); try { string rtn = ""; var strJson = JsonConvert.SerializeObject(newMsDjyInvLjList); rtn = WebRequestHelper.DoPost(DJYINVURL.PARAMVALUE, strJson); var objRtn = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(rtn, new { data = "", msg = "", code = "", type = "" }); if (objRtn.code == "200") { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); foreach (var item in FeeNolist) { var blUpSQL = "update ch_fee set INVLINKGID='" + item.CUSTNO + "' where GID='" + item.BSNO + "' "; bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL); result.Data = item.CUSTNO; } foreach (var InvLink in InvLinkList) { InvLink.DbOperationType = DbOperationType.DbotIns; var modb = new ModelObjectDB(); modb.Save(InvLink); } result.Success = true; } else { result.Success = false; result.Message = objRtn.msg + ",CODE" + objRtn.code; } } catch (Exception ex) { result.Success = false; result.Message = "上传过程出错:" + ex.Message; } return result; } public static List CreateEdiDjyInv(List InvList,List DjyInvList,List bsnolist, List bodyList,out List FeeNolist) { var NewFeeNolist = new List(); foreach (var Inv in InvList) { var DjyInv = DjyInvList.Find(X => X.LinkId == Inv.INVLINKGID); if (DjyInv != null&& Inv.BSNOLIST!=null) { foreach (var item in Inv.BSNOLIST) { var bill = MsOpBillDAL.GetData("BSNO='" + item.BSNO + "'"); var order = new MsDjyInvLjBill(); order.BSNO = bill.BSNO; order.MBLNO = bill.MBLNO; order.Yard = bill.YARD; order.Vessel = bill.VESSEL; order.Destination = bill.DESTINATION; order.Voyno = bill.VOYNO; order.ETD = bill.ETD; order.PortLoadId = bill.PORTLOADID; order.PortLoad = bill.PORTLOAD; order.PortDischargeId =""; order.PortDischarge = bill.PORTDISCHARGE; order.CntrTotal = bill.CNTRTOTAL; order.PlaceReceiptId =""; order.PlaceReceipt =""; order.PlaceDeliveryId =""; order.PlaceDelivery =""; order.DestinationId = bill.DESTINATIONID; order.Destination = bill.DESTINATION; var Feelist = new List(); foreach (var fee in bodyList) { if (fee.BsNo == item.BSNO && fee.Currency == Inv.CURRENCY && fee.CustomerName == Inv.CUSTOMERNAME) { var cntr = new MsDjyInvLjFeeDetail(); cntr.FeeId = fee.GId; cntr.FeeName = fee.FeeName; cntr.CustomerName = fee.CustomerName; cntr.Unit = fee.Unit; cntr.UnitPrice = fee.UnitPrice.ToString(); cntr.Quantity = fee.Quantity.ToString(); cntr.Amount = fee.Amount.ToString(); cntr.Currency = fee.Currency.ToString(); cntr.ExchangeRate = fee.ExChangerate.ToString(); cntr.Remark = fee.Remark; cntr.ExchangeRate = fee.ExChangerate.ToString(); cntr.TaxRate = fee.TaxRate.ToString(); ; cntr.NoTaxAmount = fee.NoTaxAmount.ToString(); cntr.Tax = fee.Tax.ToString(); Feelist.Add(cntr); var bsnols = new BSNOLB(); bsnols.BSNO = fee.GId; bsnols.CUSTNO = DjyInv.LinkId; NewFeeNolist.Add(bsnols); } } order.FeeList = Feelist; if (DjyInv.BillList == null) DjyInv.BillList = new List(); DjyInv.BillList.Add(order); } } } FeeNolist = NewFeeNolist; return DjyInvList; } #endregion } internal class MsChFeeDealException : Exception { internal MsChFeeDealException(string message) : base(message) {} } }