using System; using System.Data; using System.Data.SqlClient; using System.Collections; using System.Collections.Generic; using DSWeb.Models; using WebSqlHelper; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Text; namespace DSWeb.EntityDA { public class WmsFeeDA { /// /// 增加一条数据 /// public int Add(WmsFeeEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wms_fee("); strSql.Append("GID,APFEE,REMARK,ISLOCK,LOCKTIME,LOCKUSER,CREATEUSER,MODIFIEDUSER,FEEYEAR,FEEMONTH,CLIENTNAME,STORAGENAME,AREANAME,UNITPRICE,ACREAGE,ARFEE,CREATETIME,MODIFIEDTIME,UNIT"); strSql.Append(") values ("); strSql.Append("@GID,@APFEE,@REMARK,0,getdate(),'',@CREATEUSER,@MODIFIEDUSER,@FEEYEAR,@FEEMONTH,@CLIENTNAME,@STORAGENAME,@AREANAME,@UNITPRICE,@ACREAGE,@ARFEE,@CREATETIME,getdate(),@UNIT"); strSql.Append(") "); // SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,100) , new SqlParameter("@APFEE", SqlDbType.Decimal,9) , new SqlParameter("@REMARK", SqlDbType.VarChar,1024) , //new SqlParameter("@ISLOCK", SqlDbType.Bit,1) , //new SqlParameter("@LOCKTIME", SqlDbType.DateTime) , //new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36) , new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) , new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) , new SqlParameter("@FEEYEAR", SqlDbType.Int,4) , new SqlParameter("@FEEMONTH", SqlDbType.Int,4) , new SqlParameter("@CLIENTNAME", SqlDbType.VarChar,20) , new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100) , new SqlParameter("@AREANAME", SqlDbType.VarChar,100) , new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) , new SqlParameter("@ACREAGE", SqlDbType.Decimal,9) , new SqlParameter("@ARFEE", SqlDbType.Decimal,9) , new SqlParameter("@CREATETIME", SqlDbType.DateTime) , new SqlParameter("@UNIT", SqlDbType.VarChar,20) //new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) }; parameters[0].Value = model.GID; parameters[1].Value = model.APFEE; parameters[2].Value = model.REMARK; //parameters[3].Value = model.ISLOCK; //parameters[4].Value = model.LOCKTIME; //parameters[5].Value = model.LOCKUSER; parameters[3].Value = model.CREATEUSER; parameters[4].Value = model.MODIFIEDUSER; parameters[5].Value = model.FEEYEAR; parameters[6].Value = model.FEEMONTH; parameters[7].Value = model.CLIENTNAME; parameters[8].Value = model.STORAGENAME; parameters[9].Value = model.AREANAME; parameters[10].Value = model.UNITPRICE; parameters[11].Value = model.ACREAGE; parameters[12].Value = model.ARFEE; parameters[13].Value = model.CREATETIME; parameters[14].Value = model.UNIT; //parameters[14].Value = model.MODIFIEDTIME; // int iResult = 0; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters); if (existVal > 0) { iResult = 1; // //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } /// /// 更新一条数据 /// public int Update(WmsFeeEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wms_fee set "); //strSql.Append(" GID = @GID , "); //strSql.Append(" APFEE = @APFEE , "); strSql.Append(" REMARK = @REMARK , "); //strSql.Append(" ISLOCK = @ISLOCK , "); //strSql.Append(" LOCKTIME = @LOCKTIME , "); //strSql.Append(" LOCKUSER = @LOCKUSER , "); //strSql.Append(" CREATEUSER = @CREATEUSER , "); //strSql.Append(" CREATETIME = @CREATETIME , "); strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER , "); strSql.Append(" MODIFIEDTIME = getdate() , "); //strSql.Append(" FEEYEAR = @FEEYEAR , "); //strSql.Append(" FEEMONTH = @FEEMONTH , "); strSql.Append(" CLIENTNAME = @CLIENTNAME , "); strSql.Append(" STORAGENAME = @STORAGENAME , "); strSql.Append(" AREANAME = @AREANAME , "); strSql.Append(" UNITPRICE = @UNITPRICE , "); strSql.Append(" ACREAGE = @ACREAGE , "); strSql.Append(" ARFEE = @ARFEE , "); strSql.Append(" UNIT = @UNIT "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,100) , //new SqlParameter("@APFEE", SqlDbType.Decimal,9) , new SqlParameter("@REMARK", SqlDbType.VarChar,1024) , //new SqlParameter("@ISLOCK", SqlDbType.Bit,1) , //new SqlParameter("@LOCKTIME", SqlDbType.DateTime) , //new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36) , //new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) , //new SqlParameter("@CREATETIME", SqlDbType.DateTime) , new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) , //new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) , //new SqlParameter("@FEEYEAR", SqlDbType.Int,4) , //new SqlParameter("@FEEMONTH", SqlDbType.Int,4) , new SqlParameter("@CLIENTNAME", SqlDbType.VarChar,20) , new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100) , new SqlParameter("@AREANAME", SqlDbType.VarChar,100) , new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) , new SqlParameter("@ACREAGE", SqlDbType.Decimal,9) , new SqlParameter("@ARFEE", SqlDbType.Decimal,9) , new SqlParameter("@UNIT", SqlDbType.VarChar,20) }; parameters[0].Value = model.GID; //parameters[1].Value = model.APFEE; parameters[1].Value = model.REMARK; //parameters[3].Value = model.ISLOCK; //parameters[4].Value = model.LOCKTIME; //parameters[5].Value = model.LOCKUSER; //parameters[6].Value = model.CREATEUSER; //parameters[7].Value = model.CREATETIME; parameters[2].Value = model.MODIFIEDUSER; //parameters[9].Value = model.MODIFIEDTIME; //parameters[4].Value = model.FEEYEAR; //parameters[5].Value = model.FEEMONTH; parameters[3].Value = model.CLIENTNAME; parameters[4].Value = model.STORAGENAME; parameters[5].Value = model.AREANAME; parameters[6].Value = model.UNITPRICE; parameters[7].Value = model.ACREAGE; parameters[8].Value = model.ARFEE; parameters[9].Value = model.UNIT; // int iResult = 0; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters); if (existVal > 0) { iResult = 1; // //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } #region 更新账户列表信息 /// /// 更新账户列表信息 /// /// 更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0 public int UpdateFromGrid(List WmsFeeEntities) { int result = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { foreach (WmsFeeEntity model in WmsFeeEntities) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wms_fee set "); //strSql.Append(" GID = @GID , "); //strSql.Append(" APFEE = @APFEE , "); strSql.Append(" REMARK = @REMARK , "); //strSql.Append(" ISLOCK = @ISLOCK , "); //strSql.Append(" LOCKTIME = @LOCKTIME , "); //strSql.Append(" LOCKUSER = @LOCKUSER , "); //strSql.Append(" CREATEUSER = @CREATEUSER , "); //strSql.Append(" CREATETIME = @CREATETIME , "); strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER , "); strSql.Append(" MODIFIEDTIME = getdate() , "); //strSql.Append(" FEEYEAR = @FEEYEAR , "); //strSql.Append(" FEEMONTH = @FEEMONTH , "); strSql.Append(" CLIENTNAME = @CLIENTNAME , "); strSql.Append(" STORAGENAME = @STORAGENAME , "); strSql.Append(" AREANAME = @AREANAME , "); strSql.Append(" UNITPRICE = @UNITPRICE , "); strSql.Append(" ACREAGE = @ACREAGE , "); strSql.Append(" ARFEE = @ARFEE , "); strSql.Append(" UNIT = @UNIT "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,100) , //new SqlParameter("@APFEE", SqlDbType.Decimal,9) , new SqlParameter("@REMARK", SqlDbType.VarChar,1024) , //new SqlParameter("@ISLOCK", SqlDbType.Bit,1) , //new SqlParameter("@LOCKTIME", SqlDbType.DateTime) , //new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36) , //new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) , //new SqlParameter("@CREATETIME", SqlDbType.DateTime) , new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) , //new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) , //new SqlParameter("@FEEYEAR", SqlDbType.Int,4) , //new SqlParameter("@FEEMONTH", SqlDbType.Int,4) , new SqlParameter("@CLIENTNAME", SqlDbType.VarChar,20) , new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100) , new SqlParameter("@AREANAME", SqlDbType.VarChar,100) , new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) , new SqlParameter("@ACREAGE", SqlDbType.Decimal,9) , new SqlParameter("@ARFEE", SqlDbType.Decimal,9) , new SqlParameter("@UNIT", SqlDbType.VarChar,20) }; parameters[0].Value = model.GID; //parameters[1].Value = model.APFEE; parameters[1].Value = model.REMARK; //parameters[3].Value = model.ISLOCK; //parameters[4].Value = model.LOCKTIME; //parameters[5].Value = model.LOCKUSER; //parameters[6].Value = model.CREATEUSER; //parameters[7].Value = model.CREATETIME; parameters[2].Value = model.MODIFIEDUSER; //parameters[9].Value = model.MODIFIEDTIME; //parameters[4].Value = model.FEEYEAR; //parameters[5].Value = model.FEEMONTH; parameters[3].Value = model.CLIENTNAME; parameters[4].Value = model.STORAGENAME; parameters[5].Value = model.AREANAME; parameters[6].Value = model.UNITPRICE; parameters[7].Value = model.ACREAGE; parameters[8].Value = model.ARFEE; parameters[9].Value = model.UNIT; // int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), parameters); } sqlTran.Commit(); result = 1;//状态为1表示更新成功 } catch (Exception execError) { result = -1;//有异常,更新失败 sqlTran.Rollback(); result = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return result; } #endregion /// /// 删除一条数据 /// public int Delete(string GID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from wms_fee "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,100)}; parameters[0].Value = GID; // int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters); iResult = 1;//状态为1表示删除成功 sqlTran.Commit(); } catch (Exception execError) { iResult = -1;//有异常,删除失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } /// /// 得到一个对象实体 /// public WmsFeeEntity GetModel(string GID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select GID, APFEE, REMARK, ISLOCK, LOCKTIME, LOCKUSER, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, FEEYEAR, FEEMONTH, CLIENTNAME, STORAGENAME, AREANAME, UNITPRICE, ACREAGE, ARFEE, UNIT "); strSql.Append(" from wms_fee "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,100)}; parameters[0].Value = GID; WmsFeeEntity model = new WmsFeeEntity(); DataSet ds = SqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.GID = ds.Tables[0].Rows[0]["GID"].ToString(); if (ds.Tables[0].Rows[0]["APFEE"].ToString() != "") { model.APFEE = decimal.Parse(ds.Tables[0].Rows[0]["APFEE"].ToString()); } model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString(); if (ds.Tables[0].Rows[0]["ISLOCK"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISLOCK"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISLOCK"].ToString().ToLower() == "true")) { model.ISLOCK = true; } else { model.ISLOCK = false; } } if (ds.Tables[0].Rows[0]["LOCKTIME"].ToString() != "") { model.LOCKTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LOCKTIME"].ToString()); } model.LOCKUSER = ds.Tables[0].Rows[0]["LOCKUSER"].ToString(); model.CREATEUSER = ds.Tables[0].Rows[0]["CREATEUSER"].ToString(); if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "") { model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString()); } model.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString(); if (ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString() != "") { model.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString()); } if (ds.Tables[0].Rows[0]["FEEYEAR"].ToString() != "") { model.FEEYEAR = int.Parse(ds.Tables[0].Rows[0]["FEEYEAR"].ToString()); } if (ds.Tables[0].Rows[0]["FEEMONTH"].ToString() != "") { model.FEEMONTH = int.Parse(ds.Tables[0].Rows[0]["FEEMONTH"].ToString()); } model.CLIENTNAME = ds.Tables[0].Rows[0]["CLIENTNAME"].ToString(); model.STORAGENAME = ds.Tables[0].Rows[0]["STORAGENAME"].ToString(); model.AREANAME = ds.Tables[0].Rows[0]["AREANAME"].ToString(); if (ds.Tables[0].Rows[0]["UNITPRICE"].ToString() != "") { model.UNITPRICE = decimal.Parse(ds.Tables[0].Rows[0]["UNITPRICE"].ToString()); } if (ds.Tables[0].Rows[0]["ACREAGE"].ToString() != "") { model.ACREAGE = decimal.Parse(ds.Tables[0].Rows[0]["ACREAGE"].ToString()); } if (ds.Tables[0].Rows[0]["ARFEE"].ToString() != "") { model.ARFEE = decimal.Parse(ds.Tables[0].Rows[0]["ARFEE"].ToString()); } model.UNIT = ds.Tables[0].Rows[0]["UNIT"].ToString(); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM wms_fee "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } // DataSet DS = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString()); try { if (DS.Tables[0].Rows.Count <= 0) { DS = null; } } catch { DS = null; } return DS; } #region 根据SQL语句查询入库数据集 /// /// 根据SQL语句查询数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return userSet; } #endregion /// /// 仓储费入账,并锁定入库信息 /// public int setislock(string sGids, string strUserID) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { string[] items = sGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < items.Length; i++) { string strISLOCK = "SELECT ISLOCK FROM wms_fee WHERE GID = '" + items[i].ToString().Trim() + "' and ISLOCK=1"; object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strISLOCK, null); if (statusObj != null) { if (statusObj.ToString().Trim() == "True") { continue; } } // string strSql = "update wms_fee set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where GID = '" + items[i].ToString().Trim() + "'"; iResult = -3;// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null); // #region 费用参数 string PARM_FEE_GID = "@gid"; string PARM_FEE_BSNO = "@bsno"; string PARM_FEE_TYPE = "@fee_type"; string PARM_FEE_NAME = "@fee_name"; string PARM_FEE_REMARK = "@remark"; string PARM_FEE_FRT = "@fee_frt"; string PARM_FEE_AMOUNT = "@amount"; string PARM_FEE_CURRENCY = "@currency"; string PARM_FEE_QUANTITY = "@quantity"; string PARM_FEE_STATUS = "@fee_status"; string PARM_FEE_UNIT = "@unit"; string PARM_FEE_UNIT_PRICE = "@unit_price"; string PARM_FEE_COMMISSION_RATE = "@comm_rate"; string PARM_FEE_CUSTOMER_NAME = "@customer_name"; string PARM_FEE_EXCHANGE_RATE = "@exchange_rate"; string PARM_FEE_ISADVANCEPAY = "@is_advance_pay"; string PARM_FEE_ENTER_OPERATOR = "@enter_operator"; string PARM_FEE_AUDIT_WMSOUTBSNO = "@WMSOUTBSNO"; // int isFeeGain = 0; #endregion // #region 应收费用合计入ch_fee表 //应收 string strCUSTOMERNAME = "SELECT CLIENTNAME FROM wms_fee WHERE GID = '" + items[i].ToString().Trim() + "'"; statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strCUSTOMERNAME, null); if (statusObj == null) { strCUSTOMERNAME = ""; } else { strCUSTOMERNAME = statusObj.ToString().Trim(); } // string strUNIT = "SELECT UNIT FROM wms_fee WHERE GID = '" + items[i].ToString().Trim() + "'"; statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strUNIT, null); if (statusObj == null) { strUNIT = ""; } else { strUNIT = statusObj.ToString().Trim(); } // string strENTERDATE = "SELECT isnull(CREATETIME,getdate()) as ENTERDATE FROM wms_fee WHERE GID = '" + items[i].ToString().Trim() + "'"; statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strENTERDATE, null); if (statusObj == null) { strENTERDATE = ""; } else { strENTERDATE = statusObj.ToString().Trim(); } // string feehj = "SELECT isnull(ARFEE,0) as hj FROM wms_fee WHERE GID = '" + items[i].ToString().Trim() + "'"; statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, feehj, null); if (statusObj == null) { feehj = "0"; } else { feehj = statusObj.ToString().Trim(); } // if (decimal.Parse(feehj) != 0) { isFeeGain = 1; string SQL_INSERT_CH_FEE = " INSERT INTO ch_fee (GID,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,COMMISSIONRATE,AMOUNT,CURRENCY,EXCHANGERATE,FEEFRT,REMARK,ISADVANCEDPAY,FEETYPE,BSNO,ENTEROPERATOR,FEESTATUS,WMSOUTBSNO,ENTERDATE) VALUES(@gid,@fee_name,@customer_name,@unit,@unit_price,@quantity,@comm_rate,@amount,@currency,@exchange_rate,@fee_frt,@remark,@is_advance_pay,@fee_type,@bsno,@enter_operator,@fee_status,@WMSOUTBSNO,@ENTERDATE) "; SqlParameter[] insertParms = new SqlParameter[] { new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36), new SqlParameter(PARM_FEE_NAME,SqlDbType.VarChar,100), 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.Bit), new SqlParameter(PARM_FEE_TYPE,SqlDbType.Int), new SqlParameter(PARM_FEE_BSNO,SqlDbType.VarChar,100), new SqlParameter(PARM_FEE_ENTER_OPERATOR,SqlDbType.VarChar,50), new SqlParameter(PARM_FEE_STATUS,SqlDbType.Int), new SqlParameter(PARM_FEE_AUDIT_WMSOUTBSNO,SqlDbType.VarChar,100), new SqlParameter("@ENTERDATE",SqlDbType.DateTime) }; insertParms[0].Value = Guid.NewGuid().ToString(); insertParms[1].Value = "仓储费"; insertParms[2].Value = strCUSTOMERNAME.Trim(); insertParms[3].Value = strUNIT.Trim(); insertParms[4].Value = decimal.Parse(feehj); insertParms[5].Value = 1; insertParms[6].Value = 1; insertParms[7].Value = decimal.Parse(feehj); insertParms[8].Value = "RMB"; insertParms[9].Value = 1; insertParms[10].Value = ""; insertParms[11].Value = ""; insertParms[12].Value = false; insertParms[13].Value = 1; insertParms[14].Value = items[i].ToString().Trim(); insertParms[15].Value = strUserID; insertParms[16].Value = 0; insertParms[17].Value = items[i].ToString().Trim(); insertParms[18].Value = DateTime.Parse(strENTERDATE); iResult = -5;// int ff = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms); } #endregion // #region 保存利润信息 if (isFeeGain == 1) { string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + items[i].ToString().Trim() + "' "; object bsnoObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_FEE_PROFIT_BY_BSNO, null); if (bsnoObj == null)//如果没有相关利润信息,则插入新的利润信息 { SqlParameter[] insertProfitParms = new SqlParameter[] { new SqlParameter("@bsno",SqlDbType.VarChar,100),//委托编号 new SqlParameter("@create_user",SqlDbType.VarChar,36)//创建人 }; insertProfitParms[0].Value = items[i].ToString().Trim(); insertProfitParms[1].Value = strUserID; // string SQL_INSERT_FEE_GAIN_RECALCULATE = " INSERT INTO fee_gain(BSNO,RMBDR,USDDR,OTDR,RMBCR,USDCR,OTCR,STLDRRMB,STLDRUSD, " + " STLDROT,STLCRRMB,STLCRUSD,STLCROT,STLDRTTL,STLCRTTL,RMBPROFIT,USDPROFIT,OTPROFIT, " + " DRTTL,CRTTL,TTLPROFIT,PROFITRATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME) " + " SELECT * FROM (" + " SELECT BSNO,SUM(RMBDR) AS RMBDR,SUM(USDDR) AS USDDR,0 AS OTDR,SUM(RMBCR) AS RMBCR,SUM(USDCR) AS USDCR,0 AS OTCR, " + " 0 AS STLDRRMB,0 AS STLDRUSD,0 AS STLDROT,0 AS STLCRRMB,0 AS STLCRUSD,0 AS STLCROT,0 AS STLDRTTL,0 AS STLCRTTL,SUM(RMBDR) - SUM(RMBCR) AS RMBPROFIT, " + " SUM(USDDR) - SUM(USDCR) AS USDPROFIT,0 AS OTPROFIT FROM " + " (SELECT CURRENCY,BSNO,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR, " + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE,BSNO ) AS D GROUP BY BSNO) AS B, " + " (SELECT SUM(RMBDR+USDTORMBDR) as DRTTL,SUM(RMBCR+USDTORMBCR) as CRTTL," + " SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR) as TTLPROFIT," //+ " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND((case when SUM(RMBDR+USDTORMBDR)=0 then 0 else (SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBDR+USDTORMBDR) END),2))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE," + " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND(((SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBCR+USDTORMBCR)),4))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE," + " @create_user as CREATEUSER,GETDATE() as CREATETIME,@create_user as MODIFIEDUSER,GETDATE() as MODIFIEDTIME " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS C) AS A "; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_GAIN_RECALCULATE, insertProfitParms); } else { SqlParameter[] updateProfitParms = new SqlParameter[] { new SqlParameter("@bsno",SqlDbType.VarChar,100),//委托编号 new SqlParameter("@modified_user",SqlDbType.VarChar,36)//创建人 }; updateProfitParms[0].Value = items[i].ToString().Trim(); updateProfitParms[1].Value = strUserID; // string SQL_UPDATE_FEE_GAIN_RECALCULATE = " UPDATE fee_gain SET RMBDR = B.RMBDR,RMBCR = B.RMBCR,USDDR = B.USDDR,USDCR = B.USDCR,RMBPROFIT = A.RMBPROFIT," + " USDPROFIT = A.USDPROFIT,TTLPROFIT = A.TTLPROFIT,DRTTL = A.DRTTL,CRTTL = A.CRTTL,MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE(),PROFITRATE = A.PROFITRATE " + " FROM (SELECT SUM(RMBDR) AS RMBDR,SUM(RMBCR) AS RMBCR,SUM(USDDR) AS USDDR,SUM(USDCR) AS USDCR " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " FEETYPE FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS D) AS B, " + " (SELECT SUM(RMBDR) - SUM(RMBCR) AS RMBPROFIT,SUM(USDDR) - SUM(USDCR) AS USDPROFIT,SUM(RMBDR+USDTORMBDR) as DRTTL, " + " SUM(RMBCR+USDTORMBCR) as CRTTL,SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR) as TTLPROFIT, " //+ " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND((case when SUM(RMBDR+USDTORMBDR)=0 then 0 else (SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBDR+USDTORMBDR) END),2))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE " + " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND(((SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBCR+USDTORMBCR)),4))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS C) AS A" + " WHERE fee_gain.BSNO = @bsno "; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FEE_GAIN_RECALCULATE, updateProfitParms); } } #endregion } // //事务提交 sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } /// /// 仓储费取消入账,并解除锁定入库信息 /// public int setnotlock(string strgids, string strUserID) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { string sGids = "'" + strgids.Replace(",", "','") + "'"; string strSql = "update wms_fee set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where gid in (" + sGids + ")"; iResult = -3;// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null); strSql = "delete from ch_fee where BSNO in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")"; iResult = -5;// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null); // string[] items = strgids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < items.Length; i++) { #region 保存利润信息 string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + items[i].ToString().Trim() + "' "; object bsnoObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_FEE_PROFIT_BY_BSNO, null); if (bsnoObj == null)//如果没有相关利润信息,则插入新的利润信息 { SqlParameter[] insertProfitParms = new SqlParameter[] { new SqlParameter("@bsno",SqlDbType.VarChar,100),//委托编号 new SqlParameter("@create_user",SqlDbType.VarChar,36)//创建人 }; insertProfitParms[0].Value = items[i].ToString().Trim(); insertProfitParms[1].Value = strUserID; // string SQL_INSERT_FEE_GAIN_RECALCULATE = " INSERT INTO fee_gain(BSNO,RMBDR,USDDR,OTDR,RMBCR,USDCR,OTCR,STLDRRMB,STLDRUSD, " + " STLDROT,STLCRRMB,STLCRUSD,STLCROT,STLDRTTL,STLCRTTL,RMBPROFIT,USDPROFIT,OTPROFIT, " + " DRTTL,CRTTL,TTLPROFIT,PROFITRATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME) " + " SELECT * FROM (" + " SELECT BSNO,SUM(RMBDR) AS RMBDR,SUM(USDDR) AS USDDR,0 AS OTDR,SUM(RMBCR) AS RMBCR,SUM(USDCR) AS USDCR,0 AS OTCR, " + " 0 AS STLDRRMB,0 AS STLDRUSD,0 AS STLDROT,0 AS STLCRRMB,0 AS STLCRUSD,0 AS STLCROT,0 AS STLDRTTL,0 AS STLCRTTL,SUM(RMBDR) - SUM(RMBCR) AS RMBPROFIT, " + " SUM(USDDR) - SUM(USDCR) AS USDPROFIT,0 AS OTPROFIT FROM " + " (SELECT CURRENCY,BSNO,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR, " + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE,BSNO ) AS D GROUP BY BSNO) AS B, " + " (SELECT SUM(RMBDR+USDTORMBDR) as DRTTL,SUM(RMBCR+USDTORMBCR) as CRTTL," + " SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR) as TTLPROFIT," //+ " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND((case when SUM(RMBDR+USDTORMBDR)=0 then 0 else (SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBDR+USDTORMBDR) END),2))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE," + " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND(((SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBCR+USDTORMBCR)),4))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE," + " @create_user as CREATEUSER,GETDATE() as CREATETIME,@create_user as MODIFIEDUSER,GETDATE() as MODIFIEDTIME " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS C) AS A "; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_GAIN_RECALCULATE, insertProfitParms); } else { SqlParameter[] updateProfitParms = new SqlParameter[] { new SqlParameter("@bsno",SqlDbType.VarChar,100),//委托编号 new SqlParameter("@modified_user",SqlDbType.VarChar,36)//创建人 }; updateProfitParms[0].Value = items[i].ToString().Trim(); updateProfitParms[1].Value = strUserID; // string SQL_UPDATE_FEE_GAIN_RECALCULATE = " UPDATE fee_gain SET RMBDR = B.RMBDR,RMBCR = B.RMBCR,USDDR = B.USDDR,USDCR = B.USDCR,RMBPROFIT = A.RMBPROFIT," + " USDPROFIT = A.USDPROFIT,TTLPROFIT = A.TTLPROFIT,DRTTL = A.DRTTL,CRTTL = A.CRTTL,MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE(),PROFITRATE = A.PROFITRATE " + " FROM (SELECT SUM(RMBDR) AS RMBDR,SUM(RMBCR) AS RMBCR,SUM(USDDR) AS USDDR,SUM(USDCR) AS USDCR " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " FEETYPE FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS D) AS B, " + " (SELECT SUM(RMBDR) - SUM(RMBCR) AS RMBPROFIT,SUM(USDDR) - SUM(USDCR) AS USDPROFIT,SUM(RMBDR+USDTORMBDR) as DRTTL, " + " SUM(RMBCR+USDTORMBCR) as CRTTL,SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR) as TTLPROFIT, " //+ " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND((case when SUM(RMBDR+USDTORMBDR)=0 then 0 else (SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBDR+USDTORMBDR) END),2))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE " + " (CAST(CAST(CASE WHEN SUM(RMBCR+USDTORMBCR) = 0 THEN 100 ELSE (ROUND(((SUM(RMBDR+USDTORMBDR)- SUM(RMBCR+USDTORMBCR))/SUM(RMBCR+USDTORMBCR)),4))*100 END as decimal(18,2)) as varchar(20))+'%') AS PROFITRATE " + " FROM (SELECT CURRENCY,SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as RMBDR," + " SUM(CASE WHEN CURRENCY='RMB' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as RMBCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT ELSE 0 END) as USDDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT ELSE 0 END) as USDCR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 1 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBDR, " + " SUM(CASE WHEN CURRENCY='USD' AND FEETYPE = 2 THEN AMOUNT*EXCHANGERATE ELSE 0 END) as USDTORMBCR,FEETYPE " + " FROM ch_fee WHERE BSNO = @bsno and FEENAME in (select [name] from code_fee where FEETYPE='普通') GROUP BY CURRENCY,EXCHANGERATE,FEETYPE ) AS C) AS A" + " WHERE fee_gain.BSNO = @bsno "; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FEE_GAIN_RECALCULATE, updateProfitParms); } #endregion } //事务提交 sqlTran.Commit(); iResult = 1;//状态为1表示插入成功 } catch (Exception execError) { iResult = -1;//有异常,插入失败 sqlTran.Rollback(); iResult = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } // } }