You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/EntityDA/WmsOutDA.cs

2023 lines
134 KiB
C#

3 years ago
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
/// <summary>
/// 数据访问类:WmsOutDA
/// </summary>
public partial class WmsOutDA
{
public WmsOutDA()
{ }
#region Method
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(string GID)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from wms_out");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) };
parameters[0].Value = GID;
//return DbHelperSQL.Exists(strSql.ToString(), parameters);
try
{
return bool.Parse(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters).ToString());
}
catch
{
return false;
}
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(WmsOutEntity model)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into wms_out(");
strSql.Append("GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP)");
strSql.Append(" values (");
strSql.Append("@GID,@AssociatedNO,@BSNO,@CLIENTGID,@CLIENTCODE,@CUSTOMERNAME,@DODATE,@STORAGECODE,@STORAGENAME,@AREACODE,@AREANAME,@GOODSCODE,@GOODSNAME,@GOODSTYPE,@GOODSMODEL,@GOODSSTANDARD,@GOODSPACK,@GOODSPFSL,@GOODSOUTFEE,@REMARK,@ISDELETE,@DELETETIME,@DELETEUSER,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),@GOODSPACKPFSL,@GOODSOUTFEEAP)");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100),
new SqlParameter("@AssociatedNO", SqlDbType.VarChar,50),
new SqlParameter("@BSNO", SqlDbType.VarChar,100),
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,36),
new SqlParameter("@CLIENTCODE", SqlDbType.VarChar,20),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@DODATE", SqlDbType.DateTime),
new SqlParameter("@STORAGECODE", SqlDbType.VarChar,50),
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100),
new SqlParameter("@AREACODE", SqlDbType.VarChar,50),
new SqlParameter("@AREANAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSCODE", SqlDbType.VarChar,50),
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSTYPE", SqlDbType.VarChar,50),
new SqlParameter("@GOODSMODEL", SqlDbType.VarChar,100),
new SqlParameter("@GOODSSTANDARD", SqlDbType.VarChar,100),
new SqlParameter("@GOODSPACK", SqlDbType.VarChar,50),
new SqlParameter("@GOODSPFSL", SqlDbType.Decimal),
new SqlParameter("@GOODSOUTFEE", SqlDbType.Decimal),
new SqlParameter("@REMARK", SqlDbType.VarChar,1024),
new SqlParameter("@ISDELETE", SqlDbType.Bit,1),
new SqlParameter("@DELETETIME", SqlDbType.DateTime),
new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36),
//new SqlParameter("@CREATETIME", SqlDbType.DateTime),
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36),
new SqlParameter("@GOODSPACKPFSL", SqlDbType.Decimal),
new SqlParameter("@GOODSOUTFEEAP", SqlDbType.Decimal)
//,new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime
};
parameters[0].Value = model.GID;
parameters[1].Value = model.ASSOCIATEDNO;
parameters[2].Value = model.BSNO;
parameters[3].Value = model.CLIENTGID;
parameters[4].Value = model.CLIENTCODE;
parameters[5].Value = model.CUSTOMERNAME;
parameters[6].Value = model.DODATE;
parameters[7].Value = model.STORAGECODE;
parameters[8].Value = model.STORAGENAME;
parameters[9].Value = model.AREACODE;
parameters[10].Value = model.AREANAME;
parameters[11].Value = model.GOODSCODE;
parameters[12].Value = model.GOODSNAME;
parameters[13].Value = model.GOODSTYPE;
parameters[14].Value = model.GOODSMODEL;
parameters[15].Value = model.GOODSSTANDARD;
parameters[16].Value = model.GOODSPACK;
parameters[17].Value = model.GOODSPFSL;
parameters[18].Value = model.GOODSOUTFEE;
parameters[19].Value = model.REMARK;
parameters[20].Value = model.ISDELETE;
parameters[21].Value = model.DELETETIME;
parameters[22].Value = model.DELETEUSER;
parameters[23].Value = model.CREATEUSER;
//parameters[23].Value = model.CREATETIME;
parameters[24].Value = model.MODIFIEDUSER;
parameters[25].Value = model.GOODSPACKPFSL;
parameters[26].Value = model.GOODSOUTFEEAP;
//parameters[25].Value = model.MODIFIEDTIME;
//int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(WmsOutEntity model)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update wms_out set MODIFIEDTIME=getdate(),");
strSql.Append("AssociatedNO=@AssociatedNO,");
strSql.Append("BSNO=@BSNO,");
strSql.Append("CLIENTGID=@CLIENTGID,");
strSql.Append("CLIENTCODE=@CLIENTCODE,");
strSql.Append("CUSTOMERNAME=@CUSTOMERNAME,");
strSql.Append("DODATE=@DODATE,");
strSql.Append("STORAGECODE=@STORAGECODE,");
strSql.Append("STORAGENAME=@STORAGENAME,");
strSql.Append("AREACODE=@AREACODE,");
strSql.Append("AREANAME=@AREANAME,");
strSql.Append("GOODSCODE=@GOODSCODE,");
strSql.Append("GOODSNAME=@GOODSNAME,");
strSql.Append("GOODSTYPE=@GOODSTYPE,");
strSql.Append("GOODSMODEL=@GOODSMODEL,");
strSql.Append("GOODSSTANDARD=@GOODSSTANDARD,");
strSql.Append("GOODSPACK=@GOODSPACK,");
strSql.Append("GOODSPFSL=@GOODSPFSL,");
strSql.Append("GOODSOUTFEE=@GOODSOUTFEE,");
strSql.Append("REMARK=@REMARK,");
strSql.Append("ISDELETE=@ISDELETE,");
strSql.Append("DELETETIME=@DELETETIME,");
strSql.Append("DELETEUSER=@DELETEUSER,");
//strSql.Append("CREATEUSER=@CREATEUSER,");
//strSql.Append("CREATETIME=@CREATETIME,");
strSql.Append("MODIFIEDUSER=@MODIFIEDUSER,");
strSql.Append("GOODSPACKPFSL=@GOODSPACKPFSL,");
strSql.Append("GOODSOUTFEEAP=@GOODSOUTFEEAP");
//strSql.Append("MODIFIEDTIME=@MODIFIEDTIME");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@AssociatedNO", SqlDbType.VarChar,50),
new SqlParameter("@BSNO", SqlDbType.VarChar,100),
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,36),
new SqlParameter("@CLIENTCODE", SqlDbType.VarChar,20),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@DODATE", SqlDbType.DateTime),
new SqlParameter("@STORAGECODE", SqlDbType.VarChar,50),
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100),
new SqlParameter("@AREACODE", SqlDbType.VarChar,50),
new SqlParameter("@AREANAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSCODE", SqlDbType.VarChar,50),
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSTYPE", SqlDbType.VarChar,50),
new SqlParameter("@GOODSMODEL", SqlDbType.VarChar,100),
new SqlParameter("@GOODSSTANDARD", SqlDbType.VarChar,100),
new SqlParameter("@GOODSPACK", SqlDbType.VarChar,50),
new SqlParameter("@GOODSPFSL", SqlDbType.Decimal),
new SqlParameter("@GOODSOUTFEE", SqlDbType.Decimal),
new SqlParameter("@REMARK", SqlDbType.VarChar,1024),
new SqlParameter("@ISDELETE", SqlDbType.Bit,1),
new SqlParameter("@DELETETIME", SqlDbType.DateTime),
new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36),
//new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36),
//new SqlParameter("@CREATETIME", SqlDbType.DateTime),
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36),
new SqlParameter("@GOODSPACKPFSL", SqlDbType.Decimal),
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime),
new SqlParameter("@GID", SqlDbType.VarChar,100),
new SqlParameter("@GOODSOUTFEEAP", SqlDbType.Decimal)};
parameters[0].Value = model.ASSOCIATEDNO;
parameters[1].Value = model.BSNO;
parameters[2].Value = model.CLIENTGID;
parameters[3].Value = model.CLIENTCODE;
parameters[4].Value = model.CUSTOMERNAME;
parameters[5].Value = model.DODATE;
parameters[6].Value = model.STORAGECODE;
parameters[7].Value = model.STORAGENAME;
parameters[8].Value = model.AREACODE;
parameters[9].Value = model.AREANAME;
parameters[10].Value = model.GOODSCODE;
parameters[11].Value = model.GOODSNAME;
parameters[12].Value = model.GOODSTYPE;
parameters[13].Value = model.GOODSMODEL;
parameters[14].Value = model.GOODSSTANDARD;
parameters[15].Value = model.GOODSPACK;
parameters[16].Value = model.GOODSPFSL;
parameters[17].Value = model.GOODSOUTFEE;
parameters[18].Value = model.REMARK;
parameters[19].Value = model.ISDELETE;
parameters[20].Value = model.DELETETIME;
parameters[21].Value = model.DELETEUSER;
//parameters[22].Value = model.CREATEUSER;
//parameters[23].Value = model.CREATETIME;
parameters[22].Value = model.MODIFIEDUSER;
//parameters[25].Value = model.MODIFIEDTIME;
parameters[23].Value = model.GOODSPACKPFSL;
parameters[24].Value = model.GID;
parameters[25].Value = model.GOODSOUTFEEAP;
//int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(WmsOutEntity model,string addmodel)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into wms_out(");
strSql.Append("GID,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,REMARK,CREATEUSER,CREATETIME,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL)");
strSql.Append(" values (");
strSql.Append("@GID,@BSNO,@CUSTOMERNAME,getdate(),@STORAGENAME,@GOODSNAME,@GOODSMODEL,@GOODSPFSL,@REMARK,@CREATEUSER,getdate(),@TRUCKNO,@ASSOCIATEDNO,@GOODSPACKPFSL)");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100),
new SqlParameter("@BSNO", SqlDbType.VarChar,100),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
//new SqlParameter("@DODATE", SqlDbType.DateTime),
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,100),
new SqlParameter("@GOODSMODEL", SqlDbType.VarChar,100),
new SqlParameter("@GOODSPFSL", SqlDbType.Decimal),
new SqlParameter("@REMARK", SqlDbType.VarChar,1024),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36),
new SqlParameter("@TRUCKNO", SqlDbType.VarChar,50),
new SqlParameter("@ASSOCIATEDNO", SqlDbType.VarChar,100),
new SqlParameter("@GOODSPACKPFSL", SqlDbType.Decimal)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.BSNO;
parameters[2].Value = model.CUSTOMERNAME;
//parameters[3].Value = model.DODATE;
parameters[3].Value = model.STORAGENAME;
parameters[4].Value = model.GOODSNAME;
parameters[5].Value = model.GOODSMODEL;
parameters[6].Value = model.GOODSPFSL;
parameters[7].Value = model.REMARK;
parameters[8].Value = model.CREATEUSER;
parameters[9].Value = model.TRUCKNO;
parameters[10].Value = model.ASSOCIATEDNO;
parameters[11].Value = model.GOODSPACKPFSL;
//int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(WmsOutEntity model, string updatemodel)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update wms_out set ");
strSql.Append("GOODSOUTFEE=@GOODSOUTFEE");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GOODSOUTFEE", SqlDbType.Decimal),
new SqlParameter("@GID", SqlDbType.VarChar,100)};
parameters[0].Value = model.GOODSOUTFEE;
parameters[1].Value = model.GID;
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(string GID)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from wms_out ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) };
parameters[0].Value = GID;
//int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 批量删除数据
/// </summary>
public bool DeleteList(string GIDlist)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from wms_out ");
strSql.Append(" where GID in (" + GIDlist + ") ");
//int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
int rows = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public WmsOutEntity GetModel(string Gid,string mode)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP,INGIDNEW,ISCHANGE from wms_out ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) };
parameters[0].Value = Gid;
WmsOutEntity model = new WmsOutEntity();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters))
{
try
{
while (sqlRead.Read())
{
if (sqlRead["GID"] != null && sqlRead["GID"].ToString() != "")
{
model.GID = sqlRead["GID"].ToString();
}
if (sqlRead["ASSOCIATEDNO"] != null && sqlRead["ASSOCIATEDNO"].ToString() != "")
{
model.ASSOCIATEDNO = sqlRead["ASSOCIATEDNO"].ToString();
}
if (sqlRead["BSNO"] != null && sqlRead["BSNO"].ToString() != "")
{
model.BSNO = sqlRead["BSNO"].ToString();
}
if (sqlRead["CLIENTGID"] != null && sqlRead["CLIENTGID"].ToString() != "")
{
model.CLIENTGID = sqlRead["CLIENTGID"].ToString();
}
if (sqlRead["CLIENTCODE"] != null && sqlRead["CLIENTCODE"].ToString() != "")
{
model.CLIENTCODE = sqlRead["CLIENTCODE"].ToString();
}
if (sqlRead["CUSTOMERNAME"] != null && sqlRead["CUSTOMERNAME"].ToString() != "")
{
model.CUSTOMERNAME = sqlRead["CUSTOMERNAME"].ToString();
}
if (sqlRead["DODATE"] != null && sqlRead["DODATE"].ToString() != "")
{
model.DODATE = DateTime.Parse(sqlRead["DODATE"].ToString());
}
if (sqlRead["STORAGECODE"] != null && sqlRead["STORAGECODE"].ToString() != "")
{
model.STORAGECODE = sqlRead["STORAGECODE"].ToString();
}
if (sqlRead["STORAGENAME"] != null && sqlRead["STORAGENAME"].ToString() != "")
{
model.STORAGENAME = sqlRead["STORAGENAME"].ToString();
}
if (sqlRead["AREACODE"] != null && sqlRead["AREACODE"].ToString() != "")
{
model.AREACODE = sqlRead["AREACODE"].ToString();
}
if (sqlRead["AREANAME"] != null && sqlRead["AREANAME"].ToString() != "")
{
model.AREANAME = sqlRead["AREANAME"].ToString();
}
if (sqlRead["GOODSCODE"] != null && sqlRead["GOODSCODE"].ToString() != "")
{
model.GOODSCODE = sqlRead["GOODSCODE"].ToString();
}
if (sqlRead["GOODSNAME"] != null && sqlRead["GOODSNAME"].ToString() != "")
{
model.GOODSNAME = sqlRead["GOODSNAME"].ToString();
}
if (sqlRead["GOODSTYPE"] != null && sqlRead["GOODSTYPE"].ToString() != "")
{
model.GOODSTYPE = sqlRead["GOODSTYPE"].ToString();
}
if (sqlRead["GOODSMODEL"] != null && sqlRead["GOODSMODEL"].ToString() != "")
{
model.GOODSMODEL = sqlRead["GOODSMODEL"].ToString();
}
if (sqlRead["GOODSSTANDARD"] != null && sqlRead["GOODSSTANDARD"].ToString() != "")
{
model.GOODSSTANDARD = sqlRead["GOODSSTANDARD"].ToString();
}
if (sqlRead["GOODSPACK"] != null && sqlRead["GOODSPACK"].ToString() != "")
{
model.GOODSPACK = sqlRead["GOODSPACK"].ToString();
}
if (sqlRead["GOODSPFSL"] != null && sqlRead["GOODSPFSL"].ToString() != "")
{
model.GOODSPFSL = decimal.Parse(sqlRead["GOODSPFSL"].ToString());
}
if (sqlRead["GOODSOUTFEE"] != null && sqlRead["GOODSOUTFEE"].ToString() != "")
{
model.GOODSOUTFEE = decimal.Parse(sqlRead["GOODSOUTFEE"].ToString());
}
if (sqlRead["REMARK"] != null && sqlRead["REMARK"].ToString() != "")
{
model.REMARK = sqlRead["REMARK"].ToString();
}
if (sqlRead["ISDELETE"] != null && sqlRead["ISDELETE"].ToString() != "")
{
if ((sqlRead["ISDELETE"].ToString() == "1") || (sqlRead["ISDELETE"].ToString().ToLower() == "true"))
{
model.ISDELETE = true;
}
else
{
model.ISDELETE = false;
}
}
if (sqlRead["DELETETIME"] != null && sqlRead["DELETETIME"].ToString() != "")
{
model.DELETETIME = DateTime.Parse(sqlRead["DELETETIME"].ToString());
}
if (sqlRead["DELETEUSER"] != null && sqlRead["DELETEUSER"].ToString() != "")
{
model.DELETEUSER = sqlRead["DELETEUSER"].ToString();
}
if (sqlRead["CREATEUSER"] != null && sqlRead["CREATEUSER"].ToString() != "")
{
model.CREATEUSER = sqlRead["CREATEUSER"].ToString();
}
if (sqlRead["CREATETIME"] != null && sqlRead["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(sqlRead["CREATETIME"].ToString());
}
if (sqlRead["MODIFIEDUSER"] != null && sqlRead["MODIFIEDUSER"].ToString() != "")
{
model.MODIFIEDUSER = sqlRead["MODIFIEDUSER"].ToString();
}
if (sqlRead["MODIFIEDTIME"] != null && sqlRead["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(sqlRead["MODIFIEDTIME"].ToString());
}
if (sqlRead["GOODSPACKPFSL"] != null && sqlRead["GOODSPACKPFSL"].ToString() != "")
{
model.GOODSPACKPFSL = decimal.Parse(sqlRead["GOODSPACKPFSL"].ToString());
}
if (sqlRead["GOODSOUTFEEAP"] != null && sqlRead["GOODSOUTFEEAP"].ToString() != "")
{
model.GOODSOUTFEEAP = decimal.Parse(sqlRead["GOODSOUTFEEAP"].ToString());
}
if (sqlRead["INGIDNEW"] != null && sqlRead["INGIDNEW"].ToString() != "")
{
model.INGIDNEW = sqlRead["INGIDNEW"].ToString();
}
if (sqlRead["ISCHANGE"] != null && sqlRead["ISCHANGE"].ToString() != "")
{
if ((sqlRead["ISCHANGE"].ToString() == "1") || (sqlRead["ISCHANGE"].ToString().ToLower() == "true"))
{
model.ISCHANGE = true;
}
else
{
model.ISCHANGE = false;
}
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public WmsOutEntity GetModel(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP,INGIDNEW,ISCHANGE from wms_out ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) };
parameters[0].Value = GID;
WmsOutEntity model = new WmsOutEntity();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters))
{
try
{
while (sqlRead.Read())
{
if (sqlRead["GID"] != null && sqlRead["GID"].ToString() != "")
{
model.GID = sqlRead["GID"].ToString();
}
if (sqlRead["ASSOCIATEDNO"] != null && sqlRead["ASSOCIATEDNO"].ToString() != "")
{
model.ASSOCIATEDNO = sqlRead["ASSOCIATEDNO"].ToString();
}
if (sqlRead["BSNO"] != null && sqlRead["BSNO"].ToString() != "")
{
model.BSNO = sqlRead["BSNO"].ToString();
}
if (sqlRead["CLIENTGID"] != null && sqlRead["CLIENTGID"].ToString() != "")
{
model.CLIENTGID = sqlRead["CLIENTGID"].ToString();
}
if (sqlRead["CLIENTCODE"] != null && sqlRead["CLIENTCODE"].ToString() != "")
{
model.CLIENTCODE = sqlRead["CLIENTCODE"].ToString();
}
if (sqlRead["CUSTOMERNAME"] != null && sqlRead["CUSTOMERNAME"].ToString() != "")
{
model.CUSTOMERNAME = sqlRead["CUSTOMERNAME"].ToString();
}
if (sqlRead["DODATE"] != null && sqlRead["DODATE"].ToString() != "")
{
model.DODATE = DateTime.Parse(sqlRead["DODATE"].ToString());
}
if (sqlRead["STORAGECODE"] != null && sqlRead["STORAGECODE"].ToString() != "")
{
model.STORAGECODE = sqlRead["STORAGECODE"].ToString();
}
if (sqlRead["STORAGENAME"] != null && sqlRead["STORAGENAME"].ToString() != "")
{
model.STORAGENAME = sqlRead["STORAGENAME"].ToString();
}
if (sqlRead["AREACODE"] != null && sqlRead["AREACODE"].ToString() != "")
{
model.AREACODE = sqlRead["AREACODE"].ToString();
}
if (sqlRead["AREANAME"] != null && sqlRead["AREANAME"].ToString() != "")
{
model.AREANAME = sqlRead["AREANAME"].ToString();
}
if (sqlRead["GOODSCODE"] != null && sqlRead["GOODSCODE"].ToString() != "")
{
model.GOODSCODE = sqlRead["GOODSCODE"].ToString();
}
if (sqlRead["GOODSNAME"] != null && sqlRead["GOODSNAME"].ToString() != "")
{
model.GOODSNAME = sqlRead["GOODSNAME"].ToString();
}
if (sqlRead["GOODSTYPE"] != null && sqlRead["GOODSTYPE"].ToString() != "")
{
model.GOODSTYPE = sqlRead["GOODSTYPE"].ToString();
}
if (sqlRead["GOODSMODEL"] != null && sqlRead["GOODSMODEL"].ToString() != "")
{
model.GOODSMODEL = sqlRead["GOODSMODEL"].ToString();
}
if (sqlRead["GOODSSTANDARD"] != null && sqlRead["GOODSSTANDARD"].ToString() != "")
{
model.GOODSSTANDARD = sqlRead["GOODSSTANDARD"].ToString();
}
if (sqlRead["GOODSPACK"] != null && sqlRead["GOODSPACK"].ToString() != "")
{
model.GOODSPACK = sqlRead["GOODSPACK"].ToString();
}
if (sqlRead["GOODSPFSL"] != null && sqlRead["GOODSPFSL"].ToString() != "")
{
model.GOODSPFSL = decimal.Parse(sqlRead["GOODSPFSL"].ToString());
}
if (sqlRead["GOODSOUTFEE"] != null && sqlRead["GOODSOUTFEE"].ToString() != "")
{
model.GOODSOUTFEE = decimal.Parse(sqlRead["GOODSOUTFEE"].ToString());
}
if (sqlRead["REMARK"] != null && sqlRead["REMARK"].ToString() != "")
{
model.REMARK = sqlRead["REMARK"].ToString();
}
if (sqlRead["ISDELETE"] != null && sqlRead["ISDELETE"].ToString() != "")
{
if ((sqlRead["ISDELETE"].ToString() == "1") || (sqlRead["ISDELETE"].ToString().ToLower() == "true"))
{
model.ISDELETE = true;
}
else
{
model.ISDELETE = false;
}
}
if (sqlRead["DELETETIME"] != null && sqlRead["DELETETIME"].ToString() != "")
{
model.DELETETIME = DateTime.Parse(sqlRead["DELETETIME"].ToString());
}
if (sqlRead["DELETEUSER"] != null && sqlRead["DELETEUSER"].ToString() != "")
{
model.DELETEUSER = sqlRead["DELETEUSER"].ToString();
}
if (sqlRead["CREATEUSER"] != null && sqlRead["CREATEUSER"].ToString() != "")
{
model.CREATEUSER = sqlRead["CREATEUSER"].ToString();
}
if (sqlRead["CREATETIME"] != null && sqlRead["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(sqlRead["CREATETIME"].ToString());
}
if (sqlRead["MODIFIEDUSER"] != null && sqlRead["MODIFIEDUSER"].ToString() != "")
{
model.MODIFIEDUSER = sqlRead["MODIFIEDUSER"].ToString();
}
if (sqlRead["MODIFIEDTIME"] != null && sqlRead["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(sqlRead["MODIFIEDTIME"].ToString());
}
if (sqlRead["GOODSPACKPFSL"] != null && sqlRead["GOODSPACKPFSL"].ToString() != "")
{
model.GOODSPACKPFSL = decimal.Parse(sqlRead["GOODSPACKPFSL"].ToString());
}
if (sqlRead["GOODSOUTFEEAP"] != null && sqlRead["GOODSOUTFEEAP"].ToString() != "")
{
model.GOODSOUTFEEAP = decimal.Parse(sqlRead["GOODSOUTFEEAP"].ToString());
}
if (sqlRead["INGIDNEW"] != null && sqlRead["INGIDNEW"].ToString() != "")
{
model.INGIDNEW = sqlRead["INGIDNEW"].ToString();
}
if (sqlRead["ISCHANGE"] != null && sqlRead["ISCHANGE"].ToString() != "")
{
if ((sqlRead["ISCHANGE"].ToString() == "1") || (sqlRead["ISCHANGE"].ToString().ToLower() == "true"))
{
model.ISCHANGE = true;
}
else
{
model.ISCHANGE = false;
}
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP,INGIDNEW ");
strSql.Append(" FROM wms_out ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//return DbHelperSQL.Query(strSql.ToString());
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP,INGIDNEW ");
strSql.Append(" FROM wms_out ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
//return DbHelperSQL.Query(strSql.ToString());
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获取记录总数
/// </summary>
public int GetRecordCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) FROM wms_out ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//object obj = DbHelperSQL.GetSingle(strSql.ToString());
object obj = SqlHelper.GetSingle(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
strSql.Append("order by T.GID desc");
}
strSql.Append(")AS Row, T.* from wms_out T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
//return DbHelperSQL.Query(strSql.ToString());
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "wms_out";
parameters[1].Value = "GID";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
//return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
return SqlHelper.RunProcedure(SqlHelper.ConnectionStringLocalTransaction, "UP_GetRecordByPage", parameters, "ds");
}
#region 根据SQL语句查询仓储费率数据集
/// <summary>
/// 根据SQL语句查询仓储费率数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetWmsOutListByCondition(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
/// <summary>
/// 资通装卸费入账,并锁定出库信息
/// </summary>
public int setislock(string sGids, string strUserID, string strislockdate)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strgids = "'" + sGids.Replace(",", "','") + "'";
string strSql = "update wms_out set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME='" + strislockdate.Trim() + "' where gid in (" + strgids + ")";
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out_detail set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME='" + strislockdate.Trim() + "' where OUTBSNO in (select BSNO from wms_out where gid in (" + strgids + "))";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//
string[] items = sGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Length; i++)
{
#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";
//
string strCUSTOMERNAME = "SELECT CUSTOMERNAME FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strCUSTOMERNAME, null);
if (statusObj == null)
{
strCUSTOMERNAME = "";
}
else
{
strCUSTOMERNAME = statusObj.ToString().Trim();
}
//
string strTRUCKNAME = "SELECT TRUCKNAME FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strTRUCKNAME, null);
if (statusObj == null)
{
strTRUCKNAME = "";
}
else
{
strTRUCKNAME = statusObj.ToString().Trim();
}
//
//string strASSOCIATEDNO = "SELECT ASSOCIATEDNO FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
string strASSOCIATEDNO = "select top 1 ASSOCIATEDNO from wms_in where gid in(select top 1 inbsno from wms_out_detail where outbsno in(SELECT bsno FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'))";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strASSOCIATEDNO, null);
if (statusObj == null)
{
strASSOCIATEDNO = "";
}
else
{
strASSOCIATEDNO = statusObj.ToString().Trim();
}
#endregion
//
#region 应收费用合计入ch_fee表
//应收
string feehj = "SELECT isnull(sum(ARFEE),0) as hj FROM wms_out_detail WHERE OUTBSNO in (select BSNO from wms_out where gid in ('" + 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 && strCUSTOMERNAME != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,@ENTERDATE,@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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("@ENTERDATE",SqlDbType.DateTime),
new SqlParameter(PARM_FEE_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_AUDIT_WMSOUTBSNO,SqlDbType.VarChar,100)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储装卸费";
insertParms[2].Value = strCUSTOMERNAME.Trim();
insertParms[3].Value = "重量";
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 = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = DateTime.Parse(strislockdate.Trim());
insertParms[17].Value = 0;
insertParms[18].Value = items[i].ToString().Trim();
iResult = -5;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
//
#region 应付费用合计入ch_fee表
//应付
feehj = "SELECT isnull(sum(APFEE),0) as hj FROM wms_out_detail WHERE OUTBSNO in (select BSNO from wms_out where gid in ('" + 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 && strTRUCKNAME != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,@ENTERDATE,@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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("@ENTERDATE",SqlDbType.DateTime),
new SqlParameter(PARM_FEE_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_AUDIT_WMSOUTBSNO,SqlDbType.VarChar,100)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储装卸费";
insertParms[2].Value = strTRUCKNAME.Trim();
insertParms[3].Value = "重量";
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 = 2;
insertParms[14].Value = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = DateTime.Parse(strislockdate.Trim());
insertParms[17].Value = 0;
insertParms[18].Value = items[i].ToString().Trim();
iResult = -6;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
//
#region 保存利润信息
string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + strASSOCIATEDNO + "' ";
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 = strASSOCIATEDNO;
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 = strASSOCIATEDNO;
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;
}
/// <summary>
/// 资通装卸费取消入账,并解除锁定出库信息
/// </summary>
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_out set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where gid in (" + sGids + ")";
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out_detail set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where OUTBSNO in (select BSNO from wms_out where gid in (" + sGids + "))";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "delete from ch_fee where BSNO in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//
string[] items = strgids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Length; i++)
{
string strASSOCIATEDNO = "SELECT ASSOCIATEDNO FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strASSOCIATEDNO, null);
if (statusObj == null)
{
strASSOCIATEDNO = "";
}
else
{
strASSOCIATEDNO = statusObj.ToString().Trim();
}
//
#region 保存利润信息
string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + strASSOCIATEDNO + "' ";
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 = strASSOCIATEDNO;
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 = strASSOCIATEDNO;
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;
}
/// <summary>
/// 业务装卸费入账,并锁定出库信息
/// </summary>
public int setislock2(string sGids, string strUserID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strgids = "'" + sGids.Replace(",", "','") + "'";
string strSql = "update wms_out set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where gid in (" + strgids + ")";
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out_detail set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where OUTBSNO in (select BSNO from wms_out where gid in (" + strgids + "))";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//
string[] items = sGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Length; i++)
{
#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";
//
string strARCLIENTWMSOUT = "SELECT (case when isnull(ARCLIENTWMSOUT,'')='' then CUSTOMERNAME else ARCLIENTWMSOUT end) as ARCLIENTWMSOUT FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strARCLIENTWMSOUT, null);
if (statusObj == null)
{
strARCLIENTWMSOUT = "";
}
else
{
strARCLIENTWMSOUT = statusObj.ToString().Trim();
}
//
string strARCLIENT = "SELECT (case when isnull(ARCLIENT,'')='' then CUSTOMERNAME else ARCLIENT end) as ARCLIENT FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strARCLIENT, null);
if (statusObj == null)
{
strARCLIENT = "";
}
else
{
strARCLIENT = statusObj.ToString().Trim();
}
//
string strTRUCKNAME = "SELECT (case when isnull(TRUCKNAME,'')='' then STORAGENAME else TRUCKNAME end) as TRUCKNAME FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strTRUCKNAME, null);
if (statusObj == null)
{
strTRUCKNAME = "";
}
else
{
strTRUCKNAME = statusObj.ToString().Trim();
}
//
string strASSOCIATEDNO = "SELECT ASSOCIATEDNO FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strASSOCIATEDNO, null);
if (statusObj == null)
{
strASSOCIATEDNO = "";
}
else
{
strASSOCIATEDNO = statusObj.ToString().Trim();
}
//
string strREMARK = "SELECT REMARK FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strREMARK, null);
if (statusObj == null)
{
strREMARK = "";
}
else
{
strREMARK = statusObj.ToString().Trim();
}
//
int isFeeGain = 0;
#endregion
//
#region 生成仓储费/出入库费
//仓储费
string lssql = "select * from wms_out_detail where OUTBSNO in (select BSNO from wms_out where gid in ('" + items[i].ToString().Trim() + "')and gid not in (select LINKGID from wms_settlement_date where TABLENAME='wms_out' and ISDELETE=0) )";
DataSet ds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, lssql, null);
if(ds!=null)
{
if(ds.Tables[0].Rows.Count>0)
{
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
#region 应收费用合计入ch_fee表 仓储装卸费
string feehj = "SELECT isnull(sum(ARFEE),0) as hj FROM wms_out_detail WHERE gid='" + ds.Tables[0].Rows[j]["GID"].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 && strARCLIENT.Trim() != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,GETDATE(),@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储装卸费";
insertParms[2].Value = strARCLIENT.Trim();
insertParms[3].Value = "重量";
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 = strREMARK;
insertParms[12].Value = false;
insertParms[13].Value = 1;
insertParms[14].Value = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = 1;
insertParms[17].Value = items[i].ToString().Trim();
iResult = -5;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
//
#region 应付费用合计入ch_fee表
feehj = "SELECT isnull(sum(APFEE),0) as hj FROM wms_out_detail WHERE gid='" + ds.Tables[0].Rows[j]["GID"].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 && strTRUCKNAME.Trim() != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,GETDATE(),@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储装卸费";
insertParms[2].Value = strTRUCKNAME.Trim();
insertParms[3].Value = "重量";
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 = strREMARK;
insertParms[12].Value = false;
insertParms[13].Value = 2;
insertParms[14].Value = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = 1;
insertParms[17].Value = items[i].ToString().Trim();
iResult = -6;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
//
#region 应收仓储费合计入ch_fee表 仓储费
feehj = "SELECT isnull(GOODSOUTFEE,0) as hj FROM wms_out_detail WHERE gid='" + ds.Tables[0].Rows[j]["GID"].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 && strARCLIENT.Trim() != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,GETDATE(),@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储费";
insertParms[2].Value = strARCLIENTWMSOUT.Trim();
insertParms[3].Value = "重量";
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 = strREMARK;
insertParms[12].Value = false;
insertParms[13].Value = 1;
insertParms[14].Value = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = 1;
insertParms[17].Value = items[i].ToString().Trim();
iResult = -5;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
//
#region 应付仓储费合计入ch_fee表
feehj = "SELECT isnull(GOODSOUTFEEAP,0) as hj FROM wms_out_detail WHERE gid='" + ds.Tables[0].Rows[j]["GID"].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 && strTRUCKNAME.Trim() != "")
{
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,ENTERDATE,FEESTATUS,WMSOUTBSNO) 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,GETDATE(),@fee_status,@WMSOUTBSNO) ";
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),
new SqlParameter(PARM_FEE_QUANTITY,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_COMMISSION_RATE,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_AMOUNT,SqlDbType.Decimal),
new SqlParameter(PARM_FEE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_EXCHANGE_RATE,SqlDbType.Decimal),
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)
};
insertParms[0].Value = Guid.NewGuid().ToString();
insertParms[1].Value = "仓储费";
insertParms[2].Value = strTRUCKNAME.Trim();
insertParms[3].Value = "重量";
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 = strREMARK;
insertParms[12].Value = false;
insertParms[13].Value = 2;
insertParms[14].Value = strASSOCIATEDNO.Trim();
insertParms[15].Value = strUserID;
insertParms[16].Value = 1;
insertParms[17].Value = items[i].ToString().Trim();
iResult = -6;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE, insertParms);
}
#endregion
}
}
}
#endregion
//
#region 更新op_seai表的出库数和差额字段
string strLS = "SELECT bsno FROM op_seai where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
object statusObjLS = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strLS, null);
if (statusObjLS == null)
{
strSql = "update op_seai set WMSOUTKGS=0 where BSNO = '" + strASSOCIATEDNO + "'";
}
else
{
strSql = "update op_seai set WMSOUTKGS=isnull((select isnull(sum(GOODSPFSL),0) from wms_out where ASSOCIATEDNO=op_seai.BSNO and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1),0) where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
}
iResult = -8;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update op_seai set DIFFERENCEKGS=isnull((isnull(DRAFTKGS,0)-isnull(WMSOUTKGS,0)),0) where BSNO = '" + strASSOCIATEDNO + "'";
iResult = -9;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
#endregion
//
#region 保存利润信息
if (isFeeGain == 1)
{
string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + strASSOCIATEDNO + "' ";
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 = strASSOCIATEDNO;
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 = strASSOCIATEDNO;
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;
}
/// <summary>
/// 业务装卸费取消入账,并解除锁定出库信息
/// </summary>
public int setnotlock2(string strgids, string strUserID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string sGids = "'" + strgids.Replace(",", "','") + "'";
//
string strSql = "delete from ch_fee where BSNO in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out_detail set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where OUTBSNO in (select BSNO from wms_out where gid in (" + sGids + "))";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where gid in (" + sGids + ")";
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//
string[] items = strgids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Length; i++)
{
string strASSOCIATEDNO = "SELECT ASSOCIATEDNO FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strASSOCIATEDNO, null);
if (statusObj == null)
{
strASSOCIATEDNO = "";
}
else
{
strASSOCIATEDNO = statusObj.ToString().Trim();
}
//
#region 更新op_seai表的出库数和差额字段
string strLS = "SELECT bsno FROM op_seai where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
object statusObjLS = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strLS, null);
if (statusObjLS == null)
{
strSql = "update op_seai set WMSOUTKGS=0 where BSNO = '" + strASSOCIATEDNO + "'";
}
else
{
strSql = "update op_seai set WMSOUTKGS=isnull((select isnull(sum(GOODSPFSL),0) from wms_out where ASSOCIATEDNO=op_seai.BSNO and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1),0) where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
}
iResult = -8;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update op_seai set DIFFERENCEKGS=isnull((isnull(DRAFTKGS,0)-isnull(WMSOUTKGS,0)),0) where BSNO = '" + strASSOCIATEDNO + "'";
iResult = -9;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
#endregion
//
#region 保存利润信息
string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + strASSOCIATEDNO + "' ";
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 = strASSOCIATEDNO;
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 = strASSOCIATEDNO;
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 setnotlock3 ( string strgids, string strUserID )
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string sGids = "'" + strgids.Replace(",", "','") + "'";
//
string strSql = "delete from ch_fee where BSNO in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")";
iResult = -4;//
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out_detail set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where OUTBSNO in (select BSNO from wms_out where gid in (" + sGids + "))";
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update wms_out set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where gid in (" + sGids + ")";
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
//
string[] items = strgids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Length; i++)
{
string strASSOCIATEDNO = "SELECT ASSOCIATEDNO FROM wms_out WHERE GID = '" + items[i].ToString().Trim() + "'";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strASSOCIATEDNO, null);
if (statusObj == null)
{
strASSOCIATEDNO = "";
}
else
{
strASSOCIATEDNO = statusObj.ToString().Trim();
}
//
#region 更新op_seai表的出库数和差额字段
string strLS = "SELECT bsno FROM op_seai where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
object statusObjLS = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strLS, null);
if (statusObjLS == null)
{
strSql = "update op_seai set WMSOUTKGS=0 where BSNO = '" + strASSOCIATEDNO + "'";
}
else
{
strSql = "update op_seai set WMSOUTKGS=isnull((select isnull(sum(GOODSPFSL),0) from wms_out where ASSOCIATEDNO=op_seai.BSNO and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1),0) where BSNO in (select ASSOCIATEDNO from wms_out where ASSOCIATEDNO = '" + strASSOCIATEDNO + "' and CLIENTNAMEOLD<>'盘亏处理' and ISLOCK=1)";
}
iResult = -8;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
strSql = "update op_seai set DIFFERENCEKGS=isnull((isnull(DRAFTKGS,0)-isnull(WMSOUTKGS,0)),0) where BSNO = '" + strASSOCIATEDNO + "'";
iResult = -9;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
#endregion
//
#region 保存利润信息
string SQL_SELECT_FEE_PROFIT_BY_BSNO = "SELECT BSNO FROM fee_gain WHERE BSNO = '" + strASSOCIATEDNO + "' ";
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 = strASSOCIATEDNO;
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 = strASSOCIATEDNO;
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;
}
#endregion Method
}
}