using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.WMS; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using System.Web; using System.Data.Common; using DSWeb.TruckMng.Comm.Cookie; using WebSqlHelper; using HcUtility.Core; using DSWeb.Areas.CommMng.Models; using System.Data.SqlClient; using DSWeb.EntityDA; using DSWeb.Models; namespace DSWeb.MvcShipping.DAL.WMS { public partial class WMSDAL { #region 仓储信息列表 static public List GetDataList(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT [GID],[WMSNO],dbo.trimdate(WMSDATE) WMSDATE,[CUSTOMERNAME],[WMSOP],[STOREMAN] "); strSql.Append(" ,[MODIFIEDUSER],[MODIFIEDTIME],[ISDELETE],[DELETEUSER],[DELETETIME],[TRUCKNAME] "); strSql.Append(" ,[ISLOCK],[LOCKUSER],[LOCKTIME],isnull(GOODSPACK,0) GOODSPACK,isnull(GOODSPACKSTOCK,0) GOODSPACKSTOCK "); strSql.Append(" ,isnull(GOODSRKSL,0) GOODSRKSL,isnull(GOODSSTOCK,0) GOODSSTOCK,isnull(ARFEE,0) ARFEE "); strSql.Append(" ,isnull(APFEE,0) APFEE,[ASSOCIATEDNO],[BLNO],[FREESTORAGEPERIOD],[CONTRACTNO] "); strSql.Append(" ,[GOODSNAME],[GOODSMODEL],[CLIENTCODEOLD],[CLIENTNAMEOLD],[STORAGENAME],[CHARGEUNIT] "); strSql.Append(" ,[CORPID],dbo.trimdate(STARTBILLINGDATE) [STARTBILLINGDATE],[CUSTOMNO],[CUSTNO] "); strSql.Append(" ,[GOODSSTANDARD],[GOODSPACKACTUAL],[GOODSRKSLACTUAL],[ARCLIENT],[FREESTORAGEPERIODAP] "); strSql.Append(" ,dbo.trimdate([STARTBILLINGDATEAP]) STARTBILLINGDATEAP,ISCHANGE "); strSql.Append(" ,[AREANAME],[MARKETVALUE],[BANKVALUE],[BZTCHNO],[CREATEUSER],[CREATETIME],[CLIENTBSNO],[CARGO_GID] "); strSql.Append(" FROM [wms] "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where ISDELETE=0 and " + strCondition.Replace("~", "")); } else { strSql.Append(" where ISDELETE=0 "); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by WMSDATE "); } return SetData(strSql); } static public WMSmb GetData(string condition) { var _t = ""; var list = GetDataList(condition, _t); if (list.Count > 0) return list[0]; return new WMSmb(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSmb data = new WMSmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.WMSNO = Convert.ToString(reader["WMSNO"]); data.WMSDATE = Convert.ToString(reader["WMSDATE"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.WMSOP = Convert.ToString(reader["WMSOP"]); data.STOREMAN = Convert.ToString(reader["STOREMAN"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]); data.ISDELETE = Convert.ToString(reader["ISDELETE"]); data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]); data.DELETETIME = Convert.ToString(reader["DELETETIME"]); data.ARCLIENT = Convert.ToString(reader["ARCLIENT"]); data.TRUCKNAME = Convert.ToString(reader["TRUCKNAME"]); data.ISLOCK = Convert.ToString(reader["ISLOCK"]); data.LOCKTIME = Convert.ToString(reader["LOCKTIME"]); data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]); data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]); data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]); data.GOODSPACKSTOCK = Convert.ToString(reader["GOODSPACKSTOCK"]); data.GOODSRKSL = Convert.ToString(reader["GOODSRKSL"]); data.GOODSSTOCK = Convert.ToString(reader["GOODSSTOCK"]); data.ARFEE = Convert.ToString(reader["ARFEE"]); data.APFEE = Convert.ToString(reader["APFEE"]); data.FREESTORAGEPERIOD = Convert.ToString(reader["FREESTORAGEPERIOD"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.BLNO = Convert.ToString(reader["BLNO"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.CLIENTCODEOLD = Convert.ToString(reader["CLIENTCODEOLD"]); data.CLIENTNAMEOLD = Convert.ToString(reader["CLIENTNAMEOLD"]); data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]); data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]); data.GOODSPACKACTUAL = Convert.ToString(reader["GOODSPACKACTUAL"]); data.GOODSRKSLACTUAL = Convert.ToString(reader["GOODSRKSLACTUAL"]); data.FREESTORAGEPERIODAP = Convert.ToString(reader["FREESTORAGEPERIODAP"]); data.STARTBILLINGDATEAP = Convert.ToString(reader["STARTBILLINGDATEAP"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.AREANAME = Convert.ToString(reader["AREANAME"]); data.MARKETVALUE = Convert.ToString(reader["MARKETVALUE"]); data.BANKVALUE = Convert.ToString(reader["BANKVALUE"]); data.BZTCHNO = Convert.ToString(reader["BZTCHNO"]); data.CLIENTBSNO = Convert.ToString(reader["CLIENTBSNO"]); data.CARGO_GID = Convert.ToString(reader["CARGO_GID"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 入库信息列表 static public List GetWMSINList(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT * "); strSql.Append(" FROM [wms_in] wi "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by wi.LINENUM "); } return SetWMSINData(strSql); } static public WMSINmb GetWMSINData(string condition) { var _t = ""; var list = GetWMSINList(condition, _t); if (list.Count > 0) return list[0]; return new WMSINmb(); } private static List SetWMSINData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSINmb data = new WMSINmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.BLNO = Convert.ToString(reader["BLNO"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.CNTRNO = Convert.ToString(reader["CNTRNO"]); data.SEALNO = Convert.ToString(reader["SEALNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CLIENTCODE = Convert.ToString(reader["CLIENTCODE"]); data.CLIENTNAME = Convert.ToString(reader["CLIENTNAME"]); data.DODATE = Convert.ToString(reader["DODATE"]); data.STORAGECODE = Convert.ToString(reader["STORAGECODE"]); data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]); data.AREACODE = Convert.ToString(reader["AREACODE"]); data.AREANAME = Convert.ToString(reader["AREANAME"]); data.GOODSCODE = Convert.ToString(reader["GOODSCODE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSTYPE = Convert.ToString(reader["GOODSTYPE"]); data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]); data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]); data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]); data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]); data.GOODSRKSL = Convert.ToString(reader["GOODSRKSL"]); data.GOODSSTOCK = Convert.ToString(reader["GOODSSTOCK"]); data.FREESTORAGEPERIOD = Convert.ToString(reader["FREESTORAGEPERIOD"]); data.ISLOCK = Convert.ToString(reader["ISLOCK"]); data.LOCKTIME = Convert.ToString(reader["LOCKTIME"]); data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]); data.ISDELETE = Convert.ToString(reader["ISDELETE"]); data.DELETETIME = Convert.ToString(reader["DELETETIME"]); data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.GOODSPACKSTOCK = Convert.ToString(reader["GOODSPACKSTOCK"]); data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]); data.GOODSKGS = Convert.ToString(reader["GOODSKGS"]); data.CLIENTCODEOLD = Convert.ToString(reader["CLIENTCODEOLD"]); data.CLIENTNAMEOLD = Convert.ToString(reader["CLIENTNAMEOLD"]); data.ARFEE = Convert.ToString(reader["ARFEE"]); data.APFEE = Convert.ToString(reader["APFEE"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); data.GOODSTHICKNESS = Convert.ToString(reader["GOODSTHICKNESS"]); data.GOODSWIDTH = Convert.ToString(reader["GOODSWIDTH"]); data.GOODSLENGTH = Convert.ToString(reader["GOODSLENGTH"]); data.GOODSSLICE = Convert.ToString(reader["GOODSSLICE"]); data.GOODSGRADE = Convert.ToString(reader["GOODSGRADE"]); data.STACKLOCATION = Convert.ToString(reader["STACKLOCATION"]); data.GOODSPACKACTUAL = Convert.ToString(reader["GOODSPACKACTUAL"]); data.GOODSRKSLACTUAL = Convert.ToString(reader["GOODSRKSLACTUAL"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.MARKETVALUE = Convert.ToString(reader["MARKETVALUE"]); data.BANKVALUE = Convert.ToString(reader["BANKVALUE"]); data.LINENUM = Convert.ToString(reader["LINENUM"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 费率区间列表 static public List GetWMSRATE(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT *,case feetype when 1 then '收' when 2 then '付' end as FEETYPEREF "); strSql.Append(" FROM [wms_Rate] "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by FEETYPE,FEEGRADE "); } return SetWMSRATEData(strSql); } static public WMSRATEmb GetWMSRATEData(string condition) { var _t = ""; var list = GetWMSRATE(condition, _t); if (list.Count > 0) return list[0]; return new WMSRATEmb(); } private static List SetWMSRATEData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSRATEmb data = new WMSRATEmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.FEETYPE = Convert.ToString(reader["FEETYPE"]); data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]); data.FEEGRADE = Convert.ToString(reader["FEEGRADE"]); data.FEESCALE = Convert.ToString(reader["FEESCALE"]); data.FEEPRICE = Convert.ToString(reader["FEEPRICE"]); data.FEEUNIT = Convert.ToString(reader["FEEUNIT"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.ADDPRICE = Convert.ToString(reader["ADDPRICE"]); data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]); data.RATETYPE = Convert.ToString(reader["RATETYPE"]); data.FEENAME = Convert.ToString(reader["FEENAME"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.CAPPRICE = Convert.ToString(reader["CAPPRICE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 通过WMS的GID获取业务的BSNO static public string GetBSNOByWMSGID(string WMSGID) { var BSNO=""; Database db = DatabaseFactory.CreateDatabase(); using (DbConnection connection = db.CreateConnection()) { connection.Open(); try { var _BSNO = db.ExecuteScalar(CommandType.Text, "select ASSOCIATEDNO from wms where GID='" + WMSGID + "'"); BSNO = Convert.ToString(BSNO); } catch (Exception) { return ""; } } return BSNO; } #region 费用入账(锁定WMS) static public Resultmb Lock(string WMSGID, string LOCK,string USERID) { var BSNO = GetBSNOByWMSGID(WMSGID); if (LOCK == "0") { Database db = DatabaseFactory.CreateDatabase(); var _sql = "select count(*) from WMS_OUT_Detail where inbsno in(" + WMSGID + ")"; var objcount = db.ExecuteScalar(CommandType.Text, _sql); var _count = Convert.ToString(objcount); if (_count != "0") { var result = new Resultmb(); result.Success = false; result.Message = "存在已经出库的入库记录,无法取消入账"; return result; } var strSql = new StringBuilder(); strSql.Append(" update wms set islock=" + LOCK + " where gid in(" + WMSGID + ")"); return setUnlock(strSql);//ExecuteNonQuery } else { var strSql = new StringBuilder(); strSql.Append(" update wms set islock=" + LOCK + " where gid in(" + WMSGID + ")"); return setLock(strSql);//ExecuteNonQuery } #endregion } private static Resultmb setLock(StringBuilder strSql) { var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); var result = new Resultmb(); result.Success = true; result.Message = "已经费用入账"; return result; } private static Resultmb setUnlock(StringBuilder strSql) { var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); var result = new Resultmb(); result.Success = true; result.Message = "已经取消费用入账"; return result; } #endregion #region 出库信息列表 static public List GetWMSOUTList(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT [GID],[ASSOCIATEDNO],[BSNO],[CLIENTGID],[CLIENTCODE],[CUSTOMERNAME],dbo.trimdate([DODATE]) DODATE,[STORAGECODE] "); strSql.Append(" ,[STORAGENAME],[AREACODE],[AREANAME],[GOODSCODE],[GOODSNAME],[GOODSTYPE],[GOODSMODEL],[GOODSSTANDARD] "); strSql.Append(" ,[GOODSPACK],[GOODSPFSL],[GOODSOUTFEE],[TRUCKNO],[REMARK],[ISDELETE],dbo.trimdate([DELETETIME]) DELETETIME,[DELETEUSER] "); strSql.Append(" ,[CREATEUSER],dbo.trimdate([CREATETIME]) createtime,[MODIFIEDUSER],dbo.trimdate([MODIFIEDTIME]) MODIFIEDTIME,[GOODSPACKPFSL],[TRUCKNAME] "); strSql.Append(" ,[WMSOP],[STOREMAN],[ISLOCK],[LOCKUSER],dbo.trimdate([LOCKTIME]) LOCKTIME,[GOODSOUTFEEAP],[ARFEE],[APFEE],[INSPECTIONNO] "); strSql.Append(" ,[CUSTOMNO],[CORPID],[CLIENTNAMEOLD],dbo.trimdate([OLDCUSTFEEDATE]) OLDCUSTFEEDATE,[CLIENTBSNO],[ARCLIENT],[INGIDNEW],[TOTALNO] "); strSql.Append(" ,[REMARK2],dbo.trimdate([VALIDDATE]) VALIDDATE,[CHARGEUNIT],[MBLNONEW],[ISCHANGE],[MARKETVALUE],[ARCLIENTWMSOUT] "); strSql.Append(" ,[BZTCHNO],[ISCOLLECTING], "); strSql.Append(" (select MBLNO from vw_settlement where bsno=ASSOCIATEDNO) MBLNO "); strSql.Append(" FROM [wms_out] "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where (ISDELETE=0 or ISDELETE is null) and " + strCondition.Replace("~", "")); } else { strSql.Append(" where (ISDELETE=0 or ISDELETE is null) "); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by DODATE "); } return SetWMSOUT(strSql); } static public WMSOUTmb GetWMSOUTData(string condition) { var _t = ""; var list = GetWMSOUTList(condition, _t); if (list.Count > 0) return list[0]; return new WMSOUTmb(); } private static List SetWMSOUT(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSOUTmb data = new WMSOUTmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CLIENTGID = Convert.ToString(reader["CLIENTGID"]); data.CLIENTCODE = Convert.ToString(reader["CLIENTCODE"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.DODATE = Convert.ToString(reader["DODATE"]); data.STORAGECODE = Convert.ToString(reader["STORAGECODE"]); data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]); data.AREACODE = Convert.ToString(reader["AREACODE"]); data.AREANAME = Convert.ToString(reader["AREANAME"]); data.GOODSCODE = Convert.ToString(reader["GOODSCODE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSTYPE = Convert.ToString(reader["GOODSTYPE"]); data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]); data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]); data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]); data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]); data.GOODSPFSL = Convert.ToString(reader["GOODSPFSL"]); data.GOODSOUTFEE = Convert.ToString(reader["GOODSOUTFEE"]); data.GOODSOUTFEEAP = Convert.ToString(reader["GOODSOUTFEEAP"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.ISDELETE = Convert.ToString(reader["ISDELETE"]); data.DELETETIME = Convert.ToString(reader["DELETETIME"]); data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]); data.GOODSPACKPFSL = Convert.ToString(reader["GOODSPACKPFSL"]); data.TRUCKNAME = Convert.ToString(reader["TRUCKNAME"]); data.WMSOP = Convert.ToString(reader["WMSOP"]); data.STOREMAN = Convert.ToString(reader["STOREMAN"]); data.ISLOCK = Convert.ToString(reader["ISLOCK"]); data.LOCKTIME = Convert.ToString(reader["LOCKTIME"]); data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]); data.ARFEE = Convert.ToString(reader["ARFEE"]); data.APFEE = Convert.ToString(reader["APFEE"]); data.INSPECTIONNO = Convert.ToString(reader["INSPECTIONNO"]); data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.CLIENTNAMEOLD = Convert.ToString(reader["CLIENTNAMEOLD"]); data.OLDCUSTFEEDATE = Convert.ToString(reader["OLDCUSTFEEDATE"]); data.CLIENTBSNO = Convert.ToString(reader["CLIENTBSNO"]); data.ARCLIENT = Convert.ToString(reader["ARCLIENT"]); data.INGIDNEW = Convert.ToString(reader["INGIDNEW"]); data.VALIDDATE = Convert.ToString(reader["VALIDDATE"]); data.TOTALNO = Convert.ToString(reader["TOTALNO"]); data.REMARK2 = Convert.ToString(reader["REMARK2"]); data.MBLNONEW = Convert.ToString(reader["MBLNONEW"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.ARCLIENTWMSOUT = Convert.ToString(reader["ARCLIENTWMSOUT"]); data.BZTCHNO = Convert.ToString(reader["BZTCHNO"]); data.ISCOLLECTING = Convert.ToString(reader["ISCOLLECTING"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 出库信息明细列表 static public List GetWMSOUTDetailList(string USERID,string WMSOUTBSNO,string ASSOCIATEDNO, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" select * from ( "); if (!string.IsNullOrEmpty(WMSOUTBSNO)) { strSql.Append(" select * from (SELECT dbo.trimdate(i.wmsdate) i_wmsdate,i.customername i_customername "); strSql.Append(" ,i.goodsname i_goodsname,i.goodsmodel i_goodsmodel,i.goodspackstock i_goodspackstock "); strSql.Append(" ,i.goodsstock i_goodsstock,i.blno i_blno,dbo.trimdate(i.startbillingdate) i_startbillingdate "); strSql.Append(" ,dbo.trimdate(i.STARTBILLINGDATEAP) i_STARTBILLINGDATEAP,i.gid i_INBSNO "); strSql.Append(" ,i.MARKETVALUE i_MARKETVALUE,i.BANKVALUE i_bankvalue,i.ISDELETE i_isdelete "); strSql.Append(" ,od.[GID],od.[INBSNO],od.[OUTBSNO],od.[BSNO],od.[CLIENTGID],od.[CLIENTCODE],od.[CUSTOMERNAME],od.[DODATE],od.[STORAGECODE] "); strSql.Append(" ,od.[STORAGENAME],od.[AREACODE],od.[AREANAME],od.[GOODSCODE],od.[GOODSNAME],od.[GOODSTYPE],od.[GOODSMODEL],od.[GOODSSTANDARD] "); strSql.Append(" ,od.[GOODSPACK],od.[CHARGEUNIT],od.[GOODSPFSL],od.[GOODSOUTFEE],od.[TRUCKNO],od.[CREATEUSER],od.[CREATETIME],od.[REMARK] "); strSql.Append(" ,od.[ASSOCIATEDNO],od.[GOODSPACKPFSL],od.[ARFEE],od.[APFEE],od.[ISLOCK],od.[LOCKUSER],od.[LOCKTIME],od.[GOODSOUTFEEAP],od.[CORPID] "); strSql.Append(" ,od.[CLIENTNAMEOLD],od.[OLDCUSTFEEDATE],od.[STARTBILLINGDATE],od.[ENDBILLINGDATE],od.[FEEDAYS],od.[GOODSSLICE],od.[GOODSGRADE] "); strSql.Append(" ,od.[STARTBILLINGDATEAP],od.[ENDBILLINGDATEAP],od.[FEEDAYSAP],od.[ISCHANGE],od.[MARKETVALUE],od.[BZTCHNO] "); strSql.Append(" FROM [wms] i left join wms_out_detail od on od.INBSNO=i.gid )tt"); strSql.Append(" where OUTBSNO='" + WMSOUTBSNO.Trim()+"' UNION ALL"); } strSql.Append(" SELECT dbo.trimdate(i.wmsdate) i_wmsdate,i.customername i_customername "); strSql.Append(" ,i.goodsname i_goodsname,i.goodsmodel i_goodsmodel,i.goodspackstock i_goodspackstock "); strSql.Append(" ,i.goodsstock i_goodsstock,i.blno i_blno,dbo.trimdate(i.startbillingdate) i_startbillingdate "); strSql.Append(" ,dbo.trimdate(i.STARTBILLINGDATEAP) i_STARTBILLINGDATEAP,i.gid i_INBSNO "); strSql.Append(" ,i.MARKETVALUE i_MARKETVALUE,i.BANKVALUE i_bankvalue,i.ISDELETE i_isdelete "); strSql.Append(" ,'' [GID],i.gid [INBSNO],'' [OUTBSNO],'' [BSNO],'' [CLIENTGID],'' [CLIENTCODE],i.customername [CUSTOMERNAME],getdate() [DODATE],'' [STORAGECODE] "); strSql.Append(" ,i.STORAGENAME [STORAGENAME],'' [AREACODE],i.AREANAME [AREANAME],'' [GOODSCODE],i.goodsname [GOODSNAME],''[GOODSTYPE],i.goodsmodel [GOODSMODEL],'' [GOODSSTANDARD] "); strSql.Append(" ,'' [GOODSPACK],i.CHARGEUNIT [CHARGEUNIT],0 [GOODSPFSL],0 [GOODSOUTFEE],'' [TRUCKNO],'" + USERID.Trim() + "' [CREATEUSER],getdate() [CREATETIME],'' [REMARK] "); strSql.Append(" ,i.ASSOCIATEDNO [ASSOCIATEDNO],0 [GOODSPACKPFSL],0 [ARFEE],0 [APFEE],0 [ISLOCK],'' [LOCKUSER],'' [LOCKTIME],0 [GOODSOUTFEEAP],i.CORPID [CORPID] "); strSql.Append(" ,'' [CLIENTNAMEOLD],'' [OLDCUSTFEEDATE],i.STARTBILLINGDATEAP [STARTBILLINGDATE],'' [ENDBILLINGDATE],0 [FEEDAYS],0 [GOODSSLICE],'' [GOODSGRADE] "); strSql.Append(" ,i.STARTBILLINGDATEAP [STARTBILLINGDATEAP],'' [ENDBILLINGDATEAP],0 [FEEDAYSAP],0 [ISCHANGE],0 [MARKETVALUE],'' [BZTCHNO] "); strSql.Append(" FROM [wms] i where ASSOCIATEDNO='" + ASSOCIATEDNO.Trim() + "' and isdelete=0 and goodspackstock>0 and goodsstock>0 and islock=1 "); if (!string.IsNullOrEmpty(WMSOUTBSNO)) { strSql.Append(" and i.GID not in (select inbsno from wms_out_detail where outbsno='" + WMSOUTBSNO + "') "); } strSql.Append(" )tt1 "); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by DODATE "); } return SetWMSOUTDetail(strSql); } static public List GetWMSOUTDetailList_0(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT [GID],[INBSNO],[OUTBSNO],[BSNO],[CLIENTGID],[CLIENTCODE],[CUSTOMERNAME],[DODATE],[STORAGECODE] "); strSql.Append(" ,[STORAGENAME],[AREACODE],[AREANAME],[GOODSCODE],[GOODSNAME],[GOODSTYPE],[GOODSMODEL],[GOODSSTANDARD] "); strSql.Append(" ,[GOODSPACK],[CHARGEUNIT],[GOODSPFSL],[GOODSOUTFEE],[TRUCKNO],[CREATEUSER],[CREATETIME],[REMARK] "); strSql.Append(" ,[ASSOCIATEDNO],[GOODSPACKPFSL],[ARFEE],[APFEE],[ISLOCK],[LOCKUSER],[LOCKTIME],[GOODSOUTFEEAP],[CORPID] "); strSql.Append(" ,[CLIENTNAMEOLD],[OLDCUSTFEEDATE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[GOODSSLICE],[GOODSGRADE] "); strSql.Append(" ,[STARTBILLINGDATEAP],[ENDBILLINGDATEAP],[FEEDAYSAP],[ISCHANGE],[MARKETVALUE],[BZTCHNO] "); strSql.Append(" FROM [wms_out_detail] "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } else { //strSql.Append(" where (ISDELETE=0 or ISDELETE is null) "); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by DODATE "); } return SetWMSOUTDetail_0(strSql); } static public WMSOUTDetailmb GetWMSOUTDetailData(string condition) { var _t = ""; var list = GetWMSOUTDetailList_0(condition, _t); if (list.Count > 0) return list[0]; return new WMSOUTDetailmb(); } private static List SetWMSOUTDetail(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSOUTDetailmb data = new WMSOUTDetailmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.INBSNO = Convert.ToString(reader["INBSNO"]); data.OUTBSNO = Convert.ToString(reader["OUTBSNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CLIENTGID = Convert.ToString(reader["CLIENTGID"]); data.CLIENTCODE = Convert.ToString(reader["CLIENTCODE"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.DODATE = Convert.ToString(reader["DODATE"]); data.STORAGECODE = Convert.ToString(reader["STORAGECODE"]); data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]); data.AREACODE = Convert.ToString(reader["AREACODE"]); data.AREANAME = Convert.ToString(reader["AREANAME"]); data.GOODSCODE = Convert.ToString(reader["GOODSCODE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSTYPE = Convert.ToString(reader["GOODSTYPE"]); data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]); data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]); data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]); data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]); data.GOODSPFSL = Convert.ToString(reader["GOODSPFSL"]); data.GOODSPACKPFSL = Convert.ToString(reader["GOODSPACKPFSL"]); data.GOODSOUTFEE = Convert.ToString(reader["GOODSOUTFEE"]); data.GOODSOUTFEEAP = Convert.ToString(reader["GOODSOUTFEEAP"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.ARFEE = Convert.ToString(reader["ARFEE"]); data.APFEE = Convert.ToString(reader["APFEE"]); data.ISLOCK = Convert.ToString(reader["ISLOCK"]); data.LOCKTIME = Convert.ToString(reader["LOCKTIME"]); data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.CLIENTNAMEOLD = Convert.ToString(reader["CLIENTNAMEOLD"]); data.OLDCUSTFEEDATE = Convert.ToString(reader["OLDCUSTFEEDATE"]); data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]); data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]); data.FEEDAYS = Convert.ToString(reader["FEEDAYS"]); data.GOODSSLICE = Convert.ToString(reader["GOODSSLICE"]); data.GOODSGRADE = Convert.ToString(reader["GOODSGRADE"]); data.STARTBILLINGDATEAP = Convert.ToString(reader["STARTBILLINGDATEAP"]); data.ENDBILLINGDATEAP = Convert.ToString(reader["ENDBILLINGDATEAP"]); data.FEEDAYSAP = Convert.ToString(reader["FEEDAYSAP"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.MARKETVALUE = Convert.ToString(reader["MARKETVALUE"]); data.BZTCHNO = Convert.ToString(reader["BZTCHNO"]); data.i_WMSDATE = Convert.ToString(reader["i_WMSDATE"]); data.i_CUSTOMERNAME = Convert.ToString(reader["i_CUSTOMERNAME"]); data.i_GOODSNAME = Convert.ToString(reader["i_GOODSNAME"]); data.i_GOODSMODEL = Convert.ToString(reader["i_GOODSMODEL"]); data.i_GOODSPACKSTOCK = Convert.ToString(reader["i_GOODSPACKSTOCK"]); data.i_GOODSSTOCK = Convert.ToString(reader["i_GOODSSTOCK"]); data.i_BLNO = Convert.ToString(reader["i_BLNO"]); data.i_STARTBILLINGDATE = Convert.ToString(reader["i_STARTBILLINGDATE"]); data.i_STARTBILLINGDATEAP = Convert.ToString(reader["i_STARTBILLINGDATEAP"]); data.i_MARKETVALUE = Convert.ToString(reader["i_MARKETVALUE"]); data.i_BANKVALUE = Convert.ToString(reader["i_BANKVALUE"]); data.i_ISDELETE = Convert.ToString(reader["i_ISDELETE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } private static List SetWMSOUTDetail_0(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSOUTDetailmb data = new WMSOUTDetailmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.INBSNO = Convert.ToString(reader["INBSNO"]); data.OUTBSNO = Convert.ToString(reader["OUTBSNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CLIENTGID = Convert.ToString(reader["CLIENTGID"]); data.CLIENTCODE = Convert.ToString(reader["CLIENTCODE"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.DODATE = Convert.ToString(reader["DODATE"]); data.STORAGECODE = Convert.ToString(reader["STORAGECODE"]); data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]); data.AREACODE = Convert.ToString(reader["AREACODE"]); data.AREANAME = Convert.ToString(reader["AREANAME"]); data.GOODSCODE = Convert.ToString(reader["GOODSCODE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSTYPE = Convert.ToString(reader["GOODSTYPE"]); data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]); data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]); data.GOODSPACK = Convert.ToString(reader["GOODSPACK"]); data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]); data.GOODSPFSL = Convert.ToString(reader["GOODSPFSL"]); data.GOODSPACKPFSL = Convert.ToString(reader["GOODSPACKPFSL"]); data.GOODSOUTFEE = Convert.ToString(reader["GOODSOUTFEE"]); data.GOODSOUTFEEAP = Convert.ToString(reader["GOODSOUTFEEAP"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.ARFEE = Convert.ToString(reader["ARFEE"]); data.APFEE = Convert.ToString(reader["APFEE"]); data.ISLOCK = Convert.ToString(reader["ISLOCK"]); data.LOCKTIME = Convert.ToString(reader["LOCKTIME"]); data.LOCKUSER = Convert.ToString(reader["LOCKUSER"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.CLIENTNAMEOLD = Convert.ToString(reader["CLIENTNAMEOLD"]); data.OLDCUSTFEEDATE = Convert.ToString(reader["OLDCUSTFEEDATE"]); data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]); data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]); data.FEEDAYS = Convert.ToString(reader["FEEDAYS"]); data.GOODSSLICE = Convert.ToString(reader["GOODSSLICE"]); data.GOODSGRADE = Convert.ToString(reader["GOODSGRADE"]); data.STARTBILLINGDATEAP = Convert.ToString(reader["STARTBILLINGDATEAP"]); data.ENDBILLINGDATEAP = Convert.ToString(reader["ENDBILLINGDATEAP"]); data.FEEDAYSAP = Convert.ToString(reader["FEEDAYSAP"]); data.ISCHANGE = Convert.ToString(reader["ISCHANGE"]); data.MARKETVALUE = Convert.ToString(reader["MARKETVALUE"]); data.BZTCHNO = Convert.ToString(reader["BZTCHNO"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 出库时费用明细列表 static public List GetWMSRATEDetailList(string strCondition, string sort) { //库存信息 var strSql = new StringBuilder(); strSql.Append(" SELECT *,case feetype when 1 then '收' when 2 then '付' end as FEETYPEREF "); strSql.Append(" FROM [wms_Rate_detail] "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition.Replace("~", "")); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by FEETYPE,FEEGRADE "); } return SetWMSRATEDetailData(strSql); } static public WMSRATEDetailmb GetWMSRATEDetailData(string condition) { var _t = ""; var list = GetWMSRATEDetailList(condition, _t); if (list.Count > 0) return list[0]; return new WMSRATEDetailmb(); } private static List SetWMSRATEDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { WMSRATEDetailmb data = new WMSRATEDetailmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.ASSOCIATEDNO = Convert.ToString(reader["ASSOCIATEDNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.FEETYPE = Convert.ToString(reader["FEETYPE"]); data.FEEGRADE = Convert.ToString(reader["FEEGRADE"]); data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]); data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]); data.FEESCALE = Convert.ToString(reader["FEESCALE"]); data.FEEUNIT = Convert.ToString(reader["FEEUNIT"]); data.FEEPRICE = Convert.ToString(reader["FEEPRICE"]); data.GOODSPFSL = Convert.ToString(reader["GOODSPFSL"]); data.OUTFEE = Convert.ToString(reader["OUTFEE"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]); data.WMSOUTGID = Convert.ToString(reader["WMSOUTGID"]); data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 删除出库信息 static public int DeleteOut(string BSNO) { var strSql = new StringBuilder(); strSql.Append(" delete from wms_rate_detail where ASSOCIATEDNO in( select gid from wms_out_detail where bsno='" + BSNO + "')"); strSql.Append(" delete from wms_out_detail where outbsno='" + BSNO + "'"); return SetDeleteOut(strSql);//ExecuteNonQuery } private static int SetDeleteOut(StringBuilder strSql) { var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } private static int GetCount(StringBuilder strSql) { var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, strSql.ToString())); return _count; } #endregion #region 获取来源于货转的已锁定入库信息数量 static public int GetHZWMSLockCount(string INNEWGID) { var strSql = new StringBuilder(); strSql.Append(" select count(*) from wms where GID='" + INNEWGID + "' and islock=1"); return GetCount(strSql);//ExecuteNonQuery } #endregion #region 删除来源于货转的入库信息 static public int DelHZWMS(string GID) { var strSql = new StringBuilder(); strSql.Append(" delete from wms where gid='" + GID + "'"); strSql.Append(" delete from wms_in where associatedno='" + GID + "'"); //strSql.Append(" delete from wms_rate where BSNO='" + GID + "'"); return SetDeleteOut(strSql);//ExecuteNonQuery } #endregion #region 插入来源于货转的入库信息 static public Resultmb InsertHZWMS(WMSOUTmb head,string WMSGID,string WMSNO,string USERID) { var strSql = new StringBuilder(); strSql.Append(" insert into WMS "); strSql.Append(" ([GID],[WMSNO],[WMSDATE],[CUSTOMERNAME],[WMSOP],[STOREMAN] "); strSql.Append(" ,[MODIFIEDUSER],[MODIFIEDTIME],[ISDELETE],[DELETEUSER], [DELETETIME],[TRUCKNAME],[ISLOCK],[LOCKUSER],[LOCKTIME] "); strSql.Append(" ,[GOODSPACK],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSSTOCK],[ARFEE],[APFEE],[ASSOCIATEDNO] "); strSql.Append(" ,[BLNO],[FREESTORAGEPERIOD],[CONTRACTNO],[GOODSNAME],[GOODSMODEL],[CLIENTCODEOLD] "); strSql.Append(" ,[CLIENTNAMEOLD],[STORAGENAME],[CHARGEUNIT],[CORPID],[STARTBILLINGDATE],[CUSTOMNO],[CUSTNO] "); strSql.Append(" ,[GOODSSTANDARD],[GOODSPACKACTUAL] "); strSql.Append(" ,[GOODSRKSLACTUAL],[ARCLIENT],[FREESTORAGEPERIODAP],[STARTBILLINGDATEAP],[ISCHANGE] "); strSql.Append(" ,[AREANAME],[MARKETVALUE],[BANKVALUE],[BZTCHNO],[CREATEUSER],[CREATETIME],[CLIENTBSNO]) "); strSql.Append(" SELECT TOP 1 '" + WMSGID + "' [GID],'" + WMSNO + "'[WMSNO],getdate() [WMSDATE],CLIENTNAMEOLD [CUSTOMERNAME],(select showname from [user] where gid=wms_out.createuser) [WMSOP],[STOREMAN] "); strSql.Append(" ,'" + USERID + "'[MODIFIEDUSER],getdate() [MODIFIEDTIME] "); strSql.Append(" ,0 [ISDELETE],'' [DELETEUSER],'' [DELETETIME],[TRUCKNAME],0 [ISLOCK],'' [LOCKUSER],'' [LOCKTIME] "); strSql.Append(" ,GOODSPACKPFSL [GOODSPACK],GOODSPACKPFSL [GOODSPACKSTOCK] "); //wms_out的出库件数 计入wms的入库量和剩余件数 strSql.Append(" ,GOODSPFSL [GOODSRKSL],GOODSPFSL [GOODSSTOCK] ");//wms_out的出库量 计入wms的入库量和剩余量 strSql.Append(" ,0 [ARFEE],0 [APFEE],[ASSOCIATEDNO] "); strSql.Append(" ,(select mblno from vw_settlement where bsno=[ASSOCIATEDNO])[BLNO] "); strSql.Append(" ,0 [FREESTORAGEPERIOD] "); strSql.Append(" ,(select contractno from VW_Settlement where bsno=ASSOCIATEDNO) [CONTRACTNO] "); strSql.Append(" ,[GOODSNAME],[GOODSMODEL] "); strSql.Append(" ,'' [CLIENTCODEOLD],'' [CLIENTNAMEOLD],[STORAGENAME],[CHARGEUNIT] "); strSql.Append(" ,[CORPID],OLDCUSTFEEDATE [STARTBILLINGDATE],[CUSTOMNO] "); strSql.Append(" ,(select custno from vw_settlement where bsno=ASSOCIATEDNO) [CUSTNO] "); strSql.Append(" ,[GOODSSTANDARD],GOODSPACKPFSL [GOODSPACKACTUAL] "); strSql.Append(" ,GOODSPFSL [GOODSRKSLACTUAL],CLIENTNAMEOLD [ARCLIENT],0 [FREESTORAGEPERIODAP],OLDCUSTFEEDATE [STARTBILLINGDATEAP],1 [ISCHANGE] "); strSql.Append(" ,'' [AREANAME],0 [MARKETVALUE],0 [BANKVALUE],[BZTCHNO],[CREATEUSER],[CREATETIME],'' [CLIENTBSNO] "); strSql.Append(" FROM [wms_out] where GID='"+head.GID+"'"); strSql.Append(" update wms_out set INGIDNEW='" + WMSGID + "' where GID='" + head.GID + "'"); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); if (_count > 0) { var strSqlWI = new StringBuilder(); strSqlWI.Append(" insert into WMS_IN "); strSqlWI.Append(" ([GID],[ASSOCIATEDNO],[BLNO],[CONTRACTNO],[CNTRNO] "); strSqlWI.Append(" ,[SEALNO],[BSNO],[CLIENTCODE],[CLIENTNAME],[DODATE],[STORAGECODE] "); strSqlWI.Append(" ,[STORAGENAME]"); strSqlWI.Append(" ,[AREACODE],[AREANAME],[GOODSCODE],[GOODSNAME],[GOODSTYPE] "); strSqlWI.Append(" ,[GOODSMODEL],[GOODSSTANDARD] "); strSqlWI.Append(" ,[GOODSPACK],[CHARGEUNIT],[GOODSRKSL] "); strSqlWI.Append(" ,[GOODSSTOCK],[FREESTORAGEPERIOD],[ISLOCK],[LOCKTIME] "); strSqlWI.Append(" ,[LOCKUSER],[ISDELETE],[DELETETIME],[DELETEUSER],[CREATEUSER],[CREATETIME],[MODIFIEDUSER] "); strSqlWI.Append(" ,[MODIFIEDTIME],[REMARK],[GOODSPACKSTOCK],[KINDPKGS],[GOODSKGS],[CLIENTCODEOLD] "); strSqlWI.Append(" ,[CLIENTNAMEOLD],[ARFEE],[APFEE],[CORPID],[CTNALL],[GOODSTHICKNESS],[GOODSWIDTH] "); strSqlWI.Append(" ,[GOODSLENGTH],[GOODSSLICE],[GOODSGRADE],[STACKLOCATION] "); strSqlWI.Append(" ,[GOODSPACKACTUAL],[GOODSRKSLACTUAL],[ISCHANGE] "); strSqlWI.Append(" ,[MARKETVALUE],[BANKVALUE],[LINENUM])"); strSqlWI.Append(" SELECT TOP 1 newid() [GID],'"+WMSGID+"'[ASSOCIATEDNO],[BLNO],[CONTRACTNO],''[CNTRNO] "); strSqlWI.Append(" ,''[SEALNO],'WMSNO'[BSNO],''[CLIENTCODE],CUSTOMERNAME[CLIENTNAME],getdate()[DODATE],''[STORAGECODE] "); strSqlWI.Append(" ,[STORAGENAME] "); strSqlWI.Append(" ,'' [AREACODE],[AREANAME],''[GOODSCODE],GOODSname [GOODSNAME],''[GOODSTYPE] "); strSqlWI.Append(" ,[GOODSMODEL],[GOODSSTANDARD] "); strSqlWI.Append(" ,"+head.GOODSPACKPFSL+" [GOODSPACK],[CHARGEUNIT],"+head.GOODSPFSL+" [GOODSRKSL] "); strSqlWI.Append(" ,"+head.GOODSPFSL+" [GOODSSTOCK],[FREESTORAGEPERIOD],[ISLOCK],[LOCKTIME] "); strSqlWI.Append(" ,[LOCKUSER],[ISDELETE],[DELETETIME],[DELETEUSER],[CREATEUSER],[CREATETIME],[MODIFIEDUSER] "); strSqlWI.Append(" ,[MODIFIEDTIME],'货权转移'[REMARK],"+head.GOODSPACKPFSL+"[GOODSPACKSTOCK],''[KINDPKGS],0 [GOODSKGS],'' [CLIENTCODEOLD] "); strSqlWI.Append(" ,'"+head.CUSTOMERNAME+"' [CLIENTNAMEOLD],0 [ARFEE],0 [APFEE],[CORPID],'' [CTNALL],0[GOODSTHICKNESS],0[GOODSWIDTH] "); strSqlWI.Append(" ,0[GOODSLENGTH],0[GOODSSLICE],''[GOODSGRADE],''[STACKLOCATION] "); strSqlWI.Append(" ,"+head.GOODSPACKPFSL+" [GOODSPACKACTUAL],"+head.GOODSPFSL+" [GOODSRKSLACTUAL],[ISCHANGE] "); strSqlWI.Append(" ,0 [MARKETVALUE],0 [BANKVALUE],0[LINENUM] FROM [wms] where gid='"+WMSGID+"'"); Database db2 = DatabaseFactory.CreateDatabase(); _count = db2.ExecuteNonQuery(CommandType.Text, strSqlWI.ToString()); } var result = new Resultmb(); result.Success = true; result.Message = "生成WMS成功"; return result; } #endregion #region 给一个入库单修改开始计费日期 static public int SetNewWMSBillingDate(string WMSGID, string WMSDATE, string STARTBILLINGDATE, string STARTBILLINGDATEAP, string USERID, string USERNAME) { Database db = DatabaseFactory.CreateDatabase(); var _r = 0; using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand(@"UPDATE WMS SET WMSDATE='" + WMSDATE + "',STARTBILLINGDATE='" + STARTBILLINGDATE + "',STARTBILLINGDATEAP='" + STARTBILLINGDATEAP + "' WHERE GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, WMSGID); db.ExecuteNonQuery(cmdUpdate, tran); } catch { _r++; } finally { conn.Close(); } } //将其下属的出库单明细内的开始计费日期也修改掉 using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand(@"UPDATE WMS_OUT_DETAIL SET OLDCUSTFEEDATE='" + STARTBILLINGDATE + "',STARTBILLINGDATE='" + STARTBILLINGDATE + "',STARTBILLINGDATEAP='" + STARTBILLINGDATEAP + "' WHERE INBSNO=@INBSNO "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@INBSNO", DbType.String, WMSGID); db.ExecuteNonQuery(cmdUpdate, tran); } catch { _r++; } finally { conn.Close(); } } return _r; } #endregion static public SetFeeresult SetFee(SqlTransaction sqlTran, string strSTARTBILLINGDATE, string strOLDCUSTFEEDATE, string strINBSNO , string strCUSTOMERNAME, Decimal outnums, string strASSOCIATEDNO, int strFEETYPE , string strUserID, string strShowName, string sBillno, bool ck_jsfee, bool isKuCun) { string getstr = getWmsRate(sqlTran, strSTARTBILLINGDATE, strOLDCUSTFEEDATE, strINBSNO , strCUSTOMERNAME, outnums, strASSOCIATEDNO, strFEETYPE , strUserID, strShowName, sBillno, ck_jsfee, isKuCun); string[] strls = getstr.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); //sqlTran.Commit(); SetFeeresult sf = new SetFeeresult(); sf.sumfee = strls[0].ToString(); sf.feedays = strls[1].ToString(); return sf; } #region 计算仓储费 /// /// 计算仓储费 /// /// 事务 /// 开始计费日期 /// 上家承担仓储期限 /// 出库明细关联的入库单wms或wms_in的BSNO /// 出库主表的客户名称 /// 出库量 /// 关联wms_out_detail的GID /// 区别费用收、付类型 /// 登陆用户GID /// 登陆用户名 /// 出库单号或其他单据号 /// 是否计算仓储费 /// static public String getWmsRate(SqlTransaction sqlTran, string strSTARTBILLINGDATE, string strOLDCUSTFEEDATE, string strINBSNO, string strCUSTOMERNAME, Decimal outnums, string strASSOCIATEDNO, int strFEETYPE, string strUserID, string strShowName, string sBillno, bool ck_jsfee, bool isKuCun) { string sR = ""; int iState = 0; int result = 0; string Sqlstr = ""; #region 计算仓储费 WmsOutDetailDA WmsOutDetailDA = new EntityDA.WmsOutDetailDA(); IList tempWmsRateDetailEntities = new List(); int totalfeedays = 0;//总计费区间仓储天数 int feedays = 0;//区间仓储数 int prescale = 0;//总计费区间仓储数 int feeMonth = 0;//区间仓储月数 Decimal sumfee = 0;//总仓储费 string strSTARTBILLINGDATE2 = strSTARTBILLINGDATE;//按区间计费的开始计费日期 #region 删除费率出库明细表的区间仓储费 Sqlstr = "delete from wms_rate_detail where ASSOCIATEDNO = '" + strASSOCIATEDNO.Trim() + "' and FEETYPE=" + strFEETYPE; iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null); if (iState < 0) { sqlTran.Rollback(); result = -9; //Clearh(); return result.ToString(); } #endregion if (ck_jsfee)//是否计算仓储费 { #region 如果入库有免仓储期,则出库时插入费率出库明细表 //按仓储费率计算仓储费 Sqlstr = "SELECT top 1 * FROM wms where GID='" + strINBSNO + "' or gid in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')"; DataSet dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null); if (dsrate != null) { if (dsrate.Tables[0].Rows.Count > 0) { string sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIOD"].ToString().Trim(); if (strFEETYPE == 2) { sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIODAP"].ToString().Trim(); } if (sAP != "0") { WmsRateDetailEntity model3 = new WmsRateDetailEntity(); model3.FEEPRICE = 0; model3.GOODSPFSL = outnums; model3.OUTFEE = 0; model3.FEEUNIT = dsrate.Tables[0].Rows[0]["CHARGEUNIT"].ToString().Trim() + "天"; model3.STARTBILLINGDATE = DateTime.Parse(dsrate.Tables[0].Rows[0]["WMSDATE"].ToString().Trim()); DateTime dt = DateTime.Parse(dsrate.Tables[0].Rows[0]["STARTBILLINGDATE"].ToString().Trim()).AddDays(-1); if (DateTime.Parse(strOLDCUSTFEEDATE) < dt) { dt = DateTime.Parse(strOLDCUSTFEEDATE); } model3.ENDBILLINGDATE = dt; model3.FEESCALE = int.Parse(WmsOutDetailDA.GetDaysCount("day", model3.STARTBILLINGDATE.ToString().Trim(), dt.ToString().Trim()).ToString()); model3.FEEGRADE = 0; model3.REMARK = ""; model3.CREATEUSER = strUserID; model3.MODIFIEDUSER = strUserID; model3.ASSOCIATEDNO = strASSOCIATEDNO; model3.CUSTOMERNAME = strCUSTOMERNAME; model3.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model3); } } } #endregion feedays = WmsOutDetailDA.GetDaysCount("day", strSTARTBILLINGDATE, strOLDCUSTFEEDATE.Trim());//WmsOutEntity.DODATE.ToString() 出库-开始计费日期+1 if (feedays > 0) { totalfeedays = feedays; //按仓储费率计算仓储费 Sqlstr = "SELECT GID,FEEGRADE,FEETYPE,FEESCALE,FEEPRICE,ADDPRICE,FEEUNIT,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,REMARK,CREATEUSER,CREATETIME,BSNO,CAPPRICE FROM wms_rate where (BSNO='" + strINBSNO + "' or BSNO in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')) and FEETYPE=" + strFEETYPE + " order by FEEGRADE "; dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null); if (dsrate != null) { if (dsrate.Tables[0].Rows.Count > 0) { int nowscale = 0;//区间计费区间(仓储月数/天数) Decimal price = 0;//计费单价 Decimal gradefee = 0;//区间仓储费 int nowgrade = 1; for (int i = 0; i < dsrate.Tables[0].Rows.Count; i++) { if (isKuCun) { if (DateTime.Parse(strSTARTBILLINGDATE) > DateTime.Parse(dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString())) { continue; } } WmsRateDetailEntity model = new WmsRateDetailEntity(); //nowgrade = int.Parse(dsrate.Tables[0].Rows[i]["FEEGRADE"].ToString());//计费等级 nowscale = int.Parse(dsrate.Tables[0].Rows[i]["FEESCALE"].ToString());//计费区间 price = Decimal.Parse(dsrate.Tables[0].Rows[i]["FEEPRICE"].ToString());//计费单价 Decimal ADDPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["ADDPRICE"].ToString());//增值价 Decimal CAPPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["CAPPRICE"].ToString());// string FEEUNIT = dsrate.Tables[0].Rows[i]["FEEUNIT"].ToString();//计费单位 string ENDBILLINGDATE = dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString();//结束计费日期 //计算区间是按天或按月 string DorM = "day"; if (FEEUNIT.IndexOf("月") > -1) { DorM = "month"; } #region 按区间计算仓储费 feedays = WmsOutDetailDA.GetDaysCount(DorM, strSTARTBILLINGDATE2, strOLDCUSTFEEDATE.Trim());//总仓储月数 if (feedays > nowscale) //总仓储月数 > 区间计费区间(仓储月数/天数) { feeMonth = WmsOutDetailDA.GetDaysCount(DorM, strSTARTBILLINGDATE2, ENDBILLINGDATE.Trim());//i区间仓储月数 if (feeMonth > nowscale)//i区间仓储月数 > 区间计费区间(仓储月数/天数) { int sjMonth = 0;//实际仓储月数 int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数 if (feedays > feeMonth)//总仓储月数 > i区间仓储月数 { sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数 sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数 if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值 { if (ADDPRICE <= 0)//增值价>0,则求增值费率 { sjMonth = feedays;//(feedays - nowscale);//实际仓储月数 ENDBILLINGDATE = strOLDCUSTFEEDATE; } sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数 } } else//总仓储月数 <= i区间仓储月数 { sjMonth = feedays;//(feedays - nowscale);//实际仓储月数 ENDBILLINGDATE = strOLDCUSTFEEDATE; } // #region 增值价>0,则求增值费率 if (ADDPRICE > 0)//增值价>0,则求增值费率 { //int idiv = (int)(sjMonth / nowscale); //int imod = (int)(sjMonth % nowscale); int idiv = (int)(sjMonth2 / nowscale); int imod = (int)(sjMonth2 % nowscale); Decimal dprice = price;//计费单价 for (int j = 0; j < idiv; j++)//循环求增值费率 { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1); int dtDays = sjMonth;// nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1); if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE { if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值 { dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); } else { dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE } } FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//nowscale;//累计天数 // WmsRateDetailEntity model1 = new WmsRateDetailEntity(); model1.FEEPRICE = dprice; model1.GOODSPFSL = outnums; model1.FEESCALE = dtDays;// nowscale; model1.OUTFEE = gradefee; model1.FEEUNIT = FEEUNIT2; model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model1.ENDBILLINGDATE = dtENDBILLINGDATE; //model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1); //if (FEEUNIT.IndexOf("月") > -1) //{ // DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1); // model1.ENDBILLINGDATE = dt; // if (dt > DateTime.Parse(strOLDCUSTFEEDATE)) // { // model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); // } //} model1.FEEGRADE = nowgrade; model1.REMARK = ""; model1.CREATEUSER = strUserID; model1.MODIFIEDUSER = strUserID; model1.ASSOCIATEDNO = strASSOCIATEDNO; model1.CUSTOMERNAME = strCUSTOMERNAME; model1.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model1); // nowgrade++; if (CAPPRICE != 0) { if (dprice < CAPPRICE) { dprice += ADDPRICE; } else { dprice = CAPPRICE; } } else { dprice += ADDPRICE; } strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期 } // if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1); int dtDays = imod;// nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1); if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE { if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值 { dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); } else { dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE } } FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- //dprice += ADDPRICE; gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//imod;//累计天数 // model.FEEPRICE = dprice; model.GOODSPFSL = outnums; model.FEESCALE = dtDays;//imod; model.OUTFEE = gradefee; model.FEEUNIT = FEEUNIT2; model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model.ENDBILLINGDATE = dtENDBILLINGDATE; //model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1); //if (FEEUNIT.IndexOf("月") > -1) //{ // DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1); // model.ENDBILLINGDATE = dt; // if (dt > DateTime.Parse(strOLDCUSTFEEDATE)) // { // model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); // } //} model.FEEGRADE = nowgrade; model.REMARK = ""; model.CREATEUSER = strUserID; model.MODIFIEDUSER = strUserID; model.ASSOCIATEDNO = strASSOCIATEDNO; model.CUSTOMERNAME = strCUSTOMERNAME; model.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model); // nowgrade++; strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期 } } else { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE); int dtDays = sjMonth;// nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- gradefee = outnums * price * dtDays;// sjMonth;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//sjMonth;//累计天数 // model.FEEPRICE = price; model.GOODSPFSL = outnums; model.FEESCALE = dtDays;//sjMonth; model.OUTFEE = gradefee; model.FEEUNIT = FEEUNIT2; model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE); model.FEEGRADE = nowgrade; model.REMARK = ""; model.CREATEUSER = strUserID; model.MODIFIEDUSER = strUserID; model.ASSOCIATEDNO = strASSOCIATEDNO; model.CUSTOMERNAME = strCUSTOMERNAME; model.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model); // nowgrade++; strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期 } #endregion //结束费率区间的循环 if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数 { break;//结束费率区间的循环 } } else//i区间仓储月数 <= 区间计费区间(仓储月数/天数) { int sjMonth = 0;//实际仓储月数 int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数 if (feedays > feeMonth)//总仓储月数 > i区间仓储月数 { sjMonth = feeMonth;//实际仓储月数 sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数 if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值 { if (ADDPRICE <= 0)//增值价>0,则求增值费率 { sjMonth = feedays;// (feedays - nowscale);//实际仓储月数 ENDBILLINGDATE = strOLDCUSTFEEDATE; } sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数,如果是最后一条的判断数 } } else//总仓储月数 <= i区间仓储月数 { sjMonth = feedays;//(feedays - nowscale);//实际仓储月数 ENDBILLINGDATE = strOLDCUSTFEEDATE; } // #region 增值价>0,则求增值费率 if (ADDPRICE > 0)//增值价>0,则求增值费率 { //int idiv = (int)(sjMonth / nowscale); //int imod = (int)(sjMonth % nowscale); int idiv = (int)(sjMonth2 / nowscale); int imod = (int)(sjMonth2 % nowscale); Decimal dprice = price;//计费单价 for (int j = 0; j < idiv; j++)//循环求增值费率 { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1); int dtDays = sjMonth;// nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1); if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE)) { dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); } FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//nowscale;//累计天数 // WmsRateDetailEntity model1 = new WmsRateDetailEntity(); model1.FEEPRICE = dprice; model1.GOODSPFSL = outnums; model1.FEESCALE = dtDays;//nowscale; model1.OUTFEE = gradefee; model1.FEEUNIT = FEEUNIT2; model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model1.ENDBILLINGDATE = dtENDBILLINGDATE; //model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1); //if (FEEUNIT.IndexOf("月") > -1) //{ // DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1); // model1.ENDBILLINGDATE = dt; // if (dt > DateTime.Parse(strOLDCUSTFEEDATE)) // { // model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); // } //} model1.FEEGRADE = nowgrade; model1.REMARK = ""; model1.CREATEUSER = strUserID; model1.MODIFIEDUSER = strUserID; model1.ASSOCIATEDNO = strASSOCIATEDNO; model1.CUSTOMERNAME = strCUSTOMERNAME; model1.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model1); // nowgrade++; if (CAPPRICE != 0) { if (dprice < CAPPRICE) { dprice += ADDPRICE; } else { dprice = CAPPRICE; } } else { dprice += ADDPRICE; } strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期 } // if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1); int dtDays = imod;// nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1); if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE)) { dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); } FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- //dprice += ADDPRICE; gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//imod;//累计天数 // model.FEEPRICE = dprice; model.GOODSPFSL = outnums; model.FEESCALE = dtDays;//imod; model.OUTFEE = gradefee; model.FEEUNIT = FEEUNIT2; model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model.ENDBILLINGDATE = dtENDBILLINGDATE; //model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1); //if (FEEUNIT.IndexOf("月") > -1) //{ // DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1); // model.ENDBILLINGDATE = dt; // if (dt > DateTime.Parse(strOLDCUSTFEEDATE)) // { // model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); // } //} model.FEEGRADE = nowgrade; model.REMARK = ""; model.CREATEUSER = strUserID; model.MODIFIEDUSER = strUserID; model.ASSOCIATEDNO = strASSOCIATEDNO; model.CUSTOMERNAME = strCUSTOMERNAME; model.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model); // nowgrade++; strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期 } } else { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE); int dtDays = sjMonth;//nowscale; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- gradefee = outnums * price * dtDays;//sjMonth;//出库量*计费单价*实际仓储月数 sumfee += gradefee; prescale += dtDays;//sjMonth;//累计天数 // model.FEEPRICE = price; model.GOODSPFSL = outnums; model.FEESCALE = dtDays;//sjMonth; model.OUTFEE = gradefee; model.FEEUNIT = FEEUNIT2; model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE); model.FEEGRADE = nowgrade; model.REMARK = ""; model.CREATEUSER = strUserID; model.MODIFIEDUSER = strUserID; model.ASSOCIATEDNO = strASSOCIATEDNO; model.CUSTOMERNAME = strCUSTOMERNAME; model.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model); // nowgrade++; strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期 } #endregion //结束费率区间的循环 if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数 { break;//结束费率区间的循环 } } } else//总仓储月数 <= 区间计费区间(仓储月数/天数) { //--- BEGIN --- 如果是月则计算开始和结束日期之间的天数 DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); DateTime dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); int dtDays = feedays; string FEEUNIT2 = FEEUNIT; if (FEEUNIT.IndexOf("月") > -1) { FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天"; dtDays = WmsOutDetailDA.GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数 } //--- END --- gradefee = outnums * price * dtDays;//feedays;//出库量*计费单价*仓储区间(//仓储天数-上一个计费区间(0)) sumfee += gradefee; prescale += dtDays;//feedays;//累计天数 // model.FEEPRICE = price; model.GOODSPFSL = outnums; model.FEESCALE = dtDays;//feedays; model.OUTFEE = gradefee; model.FEEUNIT = FEEUNIT2; model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2); model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE); model.FEEGRADE = nowgrade; model.REMARK = ""; model.CREATEUSER = strUserID; model.MODIFIEDUSER = strUserID; model.ASSOCIATEDNO = strASSOCIATEDNO; model.CUSTOMERNAME = strCUSTOMERNAME; model.FEETYPE = strFEETYPE; tempWmsRateDetailEntities.Add(model); // nowgrade++; strSTARTBILLINGDATE2 = (DateTime.Parse(strOLDCUSTFEEDATE).AddDays(1)).ToString();//按区间计费的开始计费日期 break;//结束费率区间的循环 } #endregion } } else { //仓储费率没有设定 //sqlTran.Rollback(); //result = -2; //Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", ""); //Clearh(); //return result; totalfeedays = 0; feedays = 0; sumfee = 0; } } else { totalfeedays = 0; feedays = 0; sumfee = 0; } } else { totalfeedays = 0; feedays = 0; sumfee = 0; } // #region 按区间计算仓储费,插入费率出库明细表 if (tempWmsRateDetailEntities != null)//是否有要入库的仓储费 { if (tempWmsRateDetailEntities.Count > 0) { foreach (WmsRateDetailEntity model2 in tempWmsRateDetailEntities) { Sqlstr = String.Format("insert into wms_rate_detail(GID,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER)" + " values(newid(),'{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')" , model2.FEEPRICE, model2.GOODSPFSL, model2.OUTFEE, model2.REMARK, model2.CREATEUSER, model2.ASSOCIATEDNO, model2.CUSTOMERNAME, model2.FEETYPE, model2.FEEGRADE, model2.STARTBILLINGDATE, model2.ENDBILLINGDATE, model2.FEESCALE, model2.FEEUNIT, model2.MODIFIEDUSER); iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null); if (iState != 1) { sqlTran.Rollback(); result = -1; //Clearh(); return result.ToString(); } // string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('添加出库明细的费率明细信息','INSERT 插入操作','" + strShowName + " 添加 费率明细信息 出库单号:" + sBillno.Trim() + "','" + model2.MODIFIEDUSER.ToString() + "')"; iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, str0, null); if (iState != 1) { sqlTran.Rollback(); result = -1; //Clearh(); return result.ToString(); } } } } #endregion } else { tempWmsRateDetailEntities = null; totalfeedays = 0; feedays = 0; sumfee = 0; } #endregion sR = sumfee.ToString() + "," + totalfeedays.ToString(); return sR; } #endregion #region 参照部分 #endregion } }