using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using NetLibrary; using NetLibrary.Data; using NetLibrary.Express; using TradeModel; namespace TradeData { public class DD_OrderData { #region 订单导出查询 public DataTable GetExcelDT_OrderInfo(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, string Sort) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare,b.RevPostCode,b.TrackCode"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); //ser.PageIndex = PageIndex; // ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); // where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; // List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); // RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); //ListModel = tb.ToList(); return tb; } #endregion #region 订单导出查询 public static DataTable GetExcelDT_OrderInfo2(int ShopId, DateTime? SDate,DateTime? EDate) { string tsql = @" select a.OrderId,ShopName='retailer',a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.OrderName,a.OrderDate,a.InDate,a.MoneyDate,a.TotalPrice,a.MoneyCode,GoodsNum2=a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,b.RevCity,b.RevProvince,b.RevPhone,b.RevPostCode,b.BuyRemark,c.GoodsSKU,c.GoodsName,c.GoodsPrice,TrackInfo='',carrier='Carrier Post',address_2='',company='',c.GoodsNum,Provider='',Note='' from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on b.OrderId=c.OrderId where a.ShopId=@ShopId and a.InDate>=@SDate and a.InDate<=@EDate order by a.OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); // RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); //ListModel = tb.ToList(); return tb; } #endregion #region 订单导出查询 public static DataTable GetExcelDT_OrderInfo4(int ShopId, DateTime? SDate, DateTime? EDate) { string tsql = @" select a.OrderId,ShopName='retailer',a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.OrderName,a.OrderDate,a.InDate,a.MoneyDate,a.TotalPrice,a.MoneyCode,GoodsNum2=a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,b.RevCity,b.RevProvince,b.RevPhone,b.RevPostCode,b.BuyRemark,c.GoodsSKU,c.GoodsName,c.GoodsPrice,TrackInfo='',carrier='Carrier Post',address_2='',company='',c.GoodsNum,Provider='',Note='',Days='15-45' from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on b.OrderId=c.OrderId where a.ShopId=@ShopId and a.PostDate>=@SDate and a.PostDate<=@EDate order by a.OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); // RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); //ListModel = tb.ToList(); return tb; } #endregion #region 订单导出查询 public static DataTable GetExcelDT_OrderInfo3(int ShopId, DateTime? SDate, DateTime? EDate) { string tsql = @" select a.OrderId,ShopName='retailer',purchase_order=a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.OrderName,a.OrderDate,a.InDate,a.MoneyDate,a.TotalPrice,a.MoneyCode,GoodsNum2=a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,b.RevCity,b.RevProvince,b.RevPhone,b.RevPostCode,b.BuyRemark,c.GoodsSKU,c.GoodsName,c.GoodsPrice,TrackInfo='',carrier='Carrier Post',address_2='',company='',c.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on b.OrderId=c.OrderId where a.ShopId=@ShopId and a.InDate>=@SDate and a.InDate<=@EDate order by a.OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); // RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); //ListModel = tb.ToList(); return tb; } #endregion #region 分页查询 public List GetListDT_OrderInfo(int CompanyId,string GoodsName,string SKU,int IsSku,RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct OrderId from (select a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; if (SKU!="") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1=="") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1+" a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1!="") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM6(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (sql1 == "") { sql1 = @"select distinct OrderId into #OrderTemp FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()"; } else { sql1 += " and a.OrderId IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()"; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,PlatId=c.PlatType,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql ; //tsql += " and OrderId IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()))"; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM7(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (sql1 == "") { sql1 = @"select distinct OrderId into #OrderTemp FROM DT_OrderInfo where OrderId not in (select OrderId from dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate())"; } else { sql1 += " and a.OrderId not IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()"; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,PlatId=c.PlatType,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 0 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 0 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; // else // if (IsSku == 0 && SKU != "") // sql1 = sql1 + " a.DetailId=0"; // else if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId>0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1 + " a.DetailId>0"; if (sql1 == "" && (IsDH >-1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM1(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && (IsDH >-1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,PlatId=c.PlatType,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_OrdersNew a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_OrdersNew a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM2(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,b.CustomID,ErrorInfo='', b.OrderState,c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.TrackState,a.IsSpare,a.IsSDan,a.BuyDate"; if (sql1 != "") ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderInfoForTM3(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,b.CustomID,ErrorInfo='', b.OrderState,c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.TrackState,a.IsSpare,a.IsSDan,a.BuyDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo union select * from DT_OrderInfoNew) a inner join (select * from DT_OrderXXInfo union select * from DT_OrderXXInfoNew) b on a.OrderId=b.OrderId inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"(select * from DT_OrderInfo union select * from DT_OrderInfoNew) a inner join (select * from DT_OrderXXInfo union select * from DT_OrderXXInfoNew) b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询订单 public List GetListDT_OrderInfoForTMBak(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct OrderId from (select a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 0 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 0 && GoodsName != "") sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; else if (IsSku == 0 && SKU != "") sql1 = sql1 + " a.DetailId=0"; else if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId>0"; else if (IsSku == 1 && GoodsName != "") sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; else if (IsSku == 1 && SKU != "") sql1 = sql1 + " a.DetailId>0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,a.IsBlank,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare,a.IsSDan,a.BuyDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_PrintOrderInfo(int CompanyId, string GoodsName, int IsWeight, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (IsWeight == 1 && sql1 == "") sql1 = @"select distinct orderid from ( select aa.OrderId,Weight=(select sum(a.GoodsNum*isnull(b.Weight,0)) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=aa.OrderId) from DT_OrderInfo aa where aa.CompanyId=@CompanyId)a where Weight>2000"; else if (IsWeight == 1 && sql1 != "") sql1 = sql1 + @" and a.orderid in (select distinct orderid from ( select aa.OrderId,Weight=(select sum(a.GoodsNum*isnull(b.Weight,0)) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=aa.OrderId) from DT_OrderInfo aa where aa.CompanyId=@CompanyId)a where Weight>2000)"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintDate,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_PrintOrderInfoForTM(int CompanyId,string TrackCode, string GoodsName, int IsWeight, string Code,string PostionCode, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId into #printlist from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%')"; if (GoodsName != "" && Code != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsCode='" + GoodsName + "' or c.GoodsOldCode='" + GoodsName + "') and b.TypeCode='" + Code + "'"; if (sql1 == "" && PostionCode != "") { sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%'"; } else if (sql1 != "" && PostionCode != "") { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where a.orderid in (select OrderId from #printlist) and c.PostionCode like '" + PostionCode + "%'"; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintDate,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo,ErrorInfo='',b.OrderState,b.FeeType,b.Post,TrackCode='', b.LogisticsId,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.RevPostCode,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1 != "") ser.Tables = @"DT_OrderInfo a with (nolock) inner join #printlist d on a.OrderId=d.OrderId inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_PrintOrderInfoForTM2(int CompanyId, string TrackCode, string GoodsName, int IsWeight, string Code, string PostionCode, int IsSku, int GM, int PrintState, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select distinct OrderId into #printlist from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%')"; if (GoodsName != "" && Code != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsCode='" + GoodsName + "' or c.GoodsOldCode='" + GoodsName + "') and b.TypeCode='" + Code + "'"; if (sql1 == "" && PostionCode != "") { if (PrintState == 0) sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; else sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%'"; } else if (sql1 != "" && PostionCode != "") { if (PrintState==0) sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; else { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%'"; } } if (GM == 1) { if (sql1 != "") { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where OldTypeCode is not null and OldTypeCode<>'' and a.OrderId not in (select OrderId from #printlist) "; } else { sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where OldTypeCode is not null and OldTypeCode<>''"; } } else if (GM == 0) { if (sql1 != "") { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where (OldTypeCode is null or OldTypeCode='') and a.OrderId not in (select OrderId from #printlist) "; } else { sql1 = @" select distinct a.OrderId into #printlist from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where (OldTypeCode is null or OldTypeCode='')"; } } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintDate,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo,ErrorInfo='',b.OrderState,b.FeeType,b.Post,TrackCode='', b.LogisticsId,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.RevPostCode,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1 != "") ser.Tables = @"DT_OrderInfoNew a with (nolock) inner join #printlist d on a.OrderId=d.OrderId inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfoNew a with (nolock) inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = 1; ser.PageSize = 1000; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询空包裹 public List GetListDT_OrderBlank(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.InName,a.InDate,a.State,a.RevName,a.RevCountry,a.RevAddr,a.RevPhone,a.RevMoblie,a.RevPostCode,a.PrintDate,a.PostDate,a.RevProvince,a.RevCity,a.RevArea,a.CountryName,a.RevMail,a.CountryCode,TrackCode=isnull(a.TrackCode,''),c.ShopName,StateName=case when a.State=1 then '未打印' when a.State=2 then '已打印' else '已发货' end,b.PlatOrderCode,PostInfo=[dbo].[GetPostName](a.Post)"; ser.Tables = @"DT_OrderBlank a inner join DT_OrderInfo b on a.orderId=b.orderId inner join jc_shop c on b.ShopId=c.shopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfo(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfoForTM(int CompanyId, int IsNoGoods, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsNoGoods == 1) NoGoodsSql = " and (b.NoGoods=1 or c.NoGoods=1)"; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId " + NoGoodsSql + " and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId=0"; if (sql1 == "" && IsNoGoods == 1) sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,ErrorInfo='', b.OrderState,b.Post,b.PostFee,b.PostInfo,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfoForTM2(int CompanyId, int IsNoGoods, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsNoGoods == 1) NoGoodsSql = " and isnull(c.NoGoods,0)=1"; else if (IsNoGoods == 2) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (GoodsName != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join DT_OrderInfonew b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId " + NoGoodsSql + " and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId=0"; if (sql1 == "" && (IsNoGoods == 1|| IsNoGoods == 2)) sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=a.OrderId,a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,ErrorInfo='', b.OrderState,b.Post,b.PostFee,b.PostInfo,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"DT_OrderInfonew a with (nolock) inner join #nogoods d on a.orderid=d.OrderId inner join DT_OrderXXInfonew b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfonew a with (nolock) inner join DT_OrderXXInfonew b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfoForTM3(int CompanyId, int IsNoGoods, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsNoGoods == 1) NoGoodsSql = " and (b.NoGoods=1 or c.NoGoods=1)"; if (GoodsName != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join DT_OrderInfonew b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId " + NoGoodsSql + " and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId=0"; if (sql1 == "" && IsNoGoods == 1 ) sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=a.OrderId,a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,ErrorInfo='', b.OrderState,b.Post,b.PostFee,b.PostInfo,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo aa with (nolock) where EXISTS (select orderid from #nogoods a where aa.orderid=a.OrderId) and PlatOrderCode IN (SELECT orderId FROM dbo.API_OrderIssue))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"(select * from DT_OrderInfo where PlatOrderCode IN (SELECT orderId FROM dbo.API_OrderIssue)) a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfoForTM4(int CompanyId, int IsNoGoods, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsNoGoods == 1) NoGoodsSql = " and (b.NoGoods=1 or c.NoGoods=1)"; if (GoodsName != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join DT_OrderInfonew b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId " + NoGoodsSql + " and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId=0"; if (sql1 == "" && IsNoGoods == 1) sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=a.OrderId,a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,ErrorInfo='', b.OrderState,b.Post,b.PostFee,b.PostInfo,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo aa with (nolock) where EXISTS (select orderid from #nogoods a where aa.orderid=a.OrderId) and OrderId IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"(select * from DT_OrderInfo where OrderId IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate())) a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderErrorInfoForTM5(int CompanyId, int IsNoGoods, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsNoGoods == 1) NoGoodsSql = " and (b.NoGoods=1 or c.NoGoods=1)"; if (GoodsName != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a with (nolock) inner join DT_OrderInfonew b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId " + NoGoodsSql + " and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId=0"; if (sql1 == "" && IsNoGoods == 1) sql1 = @"select distinct a.OrderId into #nogoods from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=a.OrderId,a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,ErrorInfo='', b.OrderState,b.Post,b.PostFee,b.PostInfo,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.OrderOutDate"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo aa with (nolock) where EXISTS (select orderid from #nogoods a where aa.orderid=a.OrderId) and OrderId not IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"(select * from DT_OrderInfo where OrderId not IN (SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate())) a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderTrackInfo(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join (select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'') b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join (select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'')b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderTrackInfoForTM(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,TrackCode='',PostInfo=d.Name,ShopName=c.ShopName,TrackStateName=case when b.TrackDate is null then '未填单' else '已填单' end,b.CountryName,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''),b.Post"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId inner join JC_Express d with (nolock) on b.Post=d.ExpressID"; else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId inner join JC_Express d with (nolock) on b.Post=d.ExpressID "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderTrackInfoForTM2(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfonew b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,TrackCode='',PostInfo=d.Name,ShopName=c.ShopName,TrackStateName=case when b.TrackDate is null then '未填单' else '已填单' end,b.CountryName,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''),b.TrackState,b.Post"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfonew with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfonew b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId inner join JC_Express d with (nolock) on b.Post=d.ExpressID"; else ser.Tables = @"DT_OrderInfonew a with (nolock) inner join DT_OrderXXInfonew b with (nolock)on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId inner join JC_Express d with (nolock) on b.Post=d.ExpressID "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_OrderSendInfo(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId),StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 不分页查询 public List GetAllListDT_OrderInfo(int CompanyId, string GoodsName, string SKU, int IsSku, RefParameterCollection where, string Sort) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and a.DetailId=0"; if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '是' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo,SimpErrorInfo=case when len(b.ErrorInfo)>15 then substring(b.ErrorInfo,1,15)+'...' else b.ErrorInfo end,b.ErrorInfo,b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,ShopName=[dbo].[GetShopName](a.ShopId)"; if (sql1 != "") ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; else ser.Tables = @"DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListDT_PostInfo(string GoodsName, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; // if (TrackCode != "") // { // sql1 = @"select OrderId into #printlist from DT_TrackCodeApply // where state=1 and TrackCode ='" + TrackCode + "' "; // } // else // if (GoodsName != "") // sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) // inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId // inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId // where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%')"; // if (GoodsName != "" && Code != "") // sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) // inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId // inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId // where (c.GoodsCode='" + GoodsName + "' or c.GoodsOldCode='" + GoodsName + "') and b.TypeCode='" + Code + "'"; // if (sql1 == "" && PostionCode != "") // { // sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) // inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId // inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId // where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; // } // else if (sql1 != "" && PostionCode != "") // { // sql1 += @" // insert into #printlist // select distinct a.OrderId from DT_OrderGoods a with (nolock) // inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId // inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId // where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; // } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.PostId,a.NowState,a.InDate,a.UpdateTime,a.InName,a.ScanDate,a.PostDate1,a.PostDate2,a.PostDate3,a.PostDate4,a.DoneDate,a.Days,a.CountryName,a.OrderCode,a.JoinOrderCode,a.ShopId,a.State,a.Remark,b.ShopName,PostName=c.Name"; // if (sql1 != "") // ser.Tables = @"WL_PostInfo a with (nolock) inner join #printlist d on a.OrderId=d.OrderId inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; // else ser.Tables = @"WL_PostInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId inner join JC_Express c with (nolock) on a.PostId=c.ExpressID"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询某条订单的合并订单 public List GetHBOrder(string PlatOrderCode) { List list = null; string tsql = @" select a.OrderId,a.OrderLevel,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.IsJoin=1 and a.JoinOrderCode=@PlatOrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, PlatOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询当前可以合并的订单 public List GetCanHBOrder(int CompanyId, DateTime? SDate) { List list = null; string tsql = @" select a.OrderId,a.OrderLevel,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.IsJoin=0 and a.State=1 and a.OrderDate>=@SDate and b.RevAddr is not null and b.RevAddr<>'' and b.RevAddr in ( select b.RevAddr from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.IsJoin=0 and a.State=1 and a.OrderDate>=@SDate group by b.RevAddr having count(0)>1) order by b.RevAddr "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询当前可以合并的订单 public List GetCanHBOrderForTM(int CompanyId, DateTime? SDate, int ShopId) { List list = null; string tsql = @" select b.OrderId,b.OrderLevel,b.PlatOrderCode,b.OrderName,b.OrderDate,b.GoodsName,b.TotalPrice,b.MoneyCode,b.GoodsNum,a.RevName,a.RevAddr,a.RevCountry from ( select ShopId=@ShopId,b.RevName,b.RevCountry,b.RevAddr from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.ShopId=@ShopId and a.IsJoin=0 and a.State=1 and a.MateState=0 group by b.RevName,b.RevCountry,b.RevAddr having count(0)>1)a inner join DT_OrderInfo b on a.ShopId=b.ShopId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId and a.RevName=c.RevName and a.RevCountry=c.RevCountry and a.RevAddr=c.RevAddr where b.CompanyId=@CompanyId and b.ShopId=@ShopId and b.IsJoin=0 and b.State=1 and b.MateState=0 order by a.RevAddr "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询当前可以合并的订单 public List GetCanHBOrderForTM2(int CompanyId, DateTime? SDate, int ShopId) { List list = null; string tsql = @" select b.OrderId,b.OrderLevel,b.PlatOrderCode,b.OrderName,b.OrderDate,b.GoodsName,b.TotalPrice,b.MoneyCode,b.GoodsNum,a.RevName,a.RevAddr,a.RevCountry from ( select ShopId=@ShopId,b.RevName,b.RevCountry,b.RevAddr from DT_OrderInfoNew a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.ShopId=@ShopId and ISNULL(a.IsJoin,0)=0 and a.State=1 and a.MateState=0 group by b.RevName,b.RevCountry,b.RevAddr having count(0)>1)a inner join DT_OrderInfoNew b on a.ShopId=b.ShopId inner join DT_OrderXXInfoNew c on b.OrderId=c.OrderId and a.RevName=c.RevName and a.RevCountry=c.RevCountry and a.RevAddr=c.RevAddr where b.CompanyId=@CompanyId and b.ShopId=@ShopId and ISNULL(b.IsJoin,0)=0 and b.State=1 and b.MateState=0 order by a.RevAddr "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页查询扫描记录 public List GetListDT_TrackCodeScan(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.PostId,a.TrackCode,a.InDate,a.InName,a.OrderCode,a.OrderId,a.BagUserId,a.Weight,a.PostFee,a.IsSure,a.SureDate,a.SureUserId,a.ScanUserId,a.Count,a.OldPostFee,b.PlatOrderCode,c.CountryName,c.RevCountry,c.RevName,PostName=d.Name"; ser.Tables = @"DT_TrackCodeScan a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId inner join JC_Express d on a.PostId=d.ExpressID "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询需要匹配的订单 public List GetListDT_OrderInfoMate(string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%' or b.Sku1 like '%" + GoodsName + "%' "; //if (SKU != "") // sql1 = "select distinct OrderId from DT_OrderGoods where GoodsSKU like '%" + SKU + "%'"; //if (IsSku == 1 && sql1 == "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0"; //else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId>0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.RevCountry, ErrorInfo='',b.OrderState,b.Post,b.PostFee,b.PostInfo,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,c.ShopName"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfo WITH(NOLOCK) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfo a WITH(NOLOCK) inner join DT_OrderXXInfo b WITH(NOLOCK) on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询需要匹配的订单 public List GetListDT_OrderInfoMate2(string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%' or b.Sku1 like '%" + GoodsName + "%' "; //if (SKU != "") // sql1 = "select distinct OrderId from DT_OrderGoods where GoodsSKU like '%" + SKU + "%'"; //if (IsSku == 1 && sql1 == "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0"; //else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId>0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.RevCountry, ErrorInfo='',b.OrderState,b.Post,b.PostFee,b.PostInfo,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,c.ShopName"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfoNew WITH(NOLOCK) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfoNew a WITH(NOLOCK) inner join DT_OrderXXInfoNew b WITH(NOLOCK) on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询物流的订单 public List GetListDT_OrderInfoExpress(int SortId, int IsTrack, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%'"; if (SKU != "") sql1 = "select distinct OrderId from DT_OrderGoods WITH(NOLOCK) where SKU1 like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = "select distinct OrderId from DT_OrderGoods WITH(NOLOCK) where DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and DetailId=0"; else if (IsSku == 0 && sql1 == "" && SortId > 0) sql1 = @"select distinct a.OrderId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.SortId=@SortId"; else if (IsSku == 0 && sql1 != "" && SortId > 0) sql1 = sql1 + @" and DetailId in (select distinct a.DetailId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.SortId=@SortId)"; string sql2 = "DT_OrderXXInfo"; if (IsTrack == 0) sql2 = "(select * from DT_OrderXXInfo WITH(NOLOCK) where TrackCode is null or TrackCode='')"; else if (IsTrack == 1) sql2 = "(select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'')"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,ShopName=[dbo].[GetShopName](a.ShopId),a.IsSpare"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join " + sql2 + " b on a.OrderId=b.OrderId left join jc_shop c on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfo a inner join " + sql2 + " b on a.OrderId=b.OrderId left join jc_shop c on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询物流的订单 public List GetListDT_OrderInfoExpressForTM(int SortId, int IsTrack, string TrackCode, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; else if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (b.SKU1 like '%" + SKU + "%' or b.SKU2 like '%" + SKU + "%' or b.SKU3 like '%" + SKU + "%')"; // if (IsSku == 0 && sql1 == "") // sql1 = "select distinct OrderId from DT_OrderGoods a where DetailId=0"; // else // if (IsSku == 0 && sql1 != "") // sql1 = sql1 + " and DetailId=0"; // else if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId>0"; // else if (IsSku == 1 && sql1 == "") // sql1 = sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0"; // else if (sql1 == "" && SortId > 0) sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.SortId=@SortId"; else if (sql1 != "" && SortId > 0) sql1 = sql1 + @" and c.SortId=@SortId"; string sql2 = "DT_OrderXXInfo"; //if (IsTrack == 0) // sql2 = "(select * from DT_OrderXXInfo where TrackCode is null or TrackCode='')"; // else if (IsTrack == 1) // sql2 = "(select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'')"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax, ErrorInfo='',b.OrderState,b.Post,b.PostFee,PostInfo='',b.LogisticsId,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,ShopName=c.ShopName,a.IsSpare,LocalPost='',b.CountryCode"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfo with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询物流的订单 public List GetListDT_OrderInfoExpressForTM2(int SortId, int IsTrack, string TrackCode, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; else if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (b.SKU1 like '%" + SKU + "%' or b.SKU2 like '%" + SKU + "%' or b.SKU3 like '%" + SKU + "%')"; // if (IsSku == 0 && sql1 == "") // sql1 = "select distinct OrderId from DT_OrderGoods a where DetailId=0"; // else // if (IsSku == 0 && sql1 != "") // sql1 = sql1 + " and DetailId=0"; // else if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId>0"; // else if (IsSku == 1 && sql1 == "") // sql1 = sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0"; // else if (sql1 == "" && SortId > 0) sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.SortId=@SortId"; else if (sql1 != "" && SortId > 0) sql1 = sql1 + @" and c.SortId=@SortId"; string sql2 = "DT_OrderXXInfoNew"; //if (IsTrack == 0) // sql2 = "(select * from DT_OrderXXInfo where TrackCode is null or TrackCode='')"; // else if (IsTrack == 1) // sql2 = "(select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'')"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax, ErrorInfo='',b.OrderState,b.Post,b.PostFee,b.PostInfo,b.LogisticsId,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,ShopName=c.ShopName,a.IsSpare,LocalPost='',b.CountryCode"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfoNew with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfoNew a with (nolock) inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询线上发货的订单 public List GetOnlineDT_OrderInfoExpress(int SortId, int IsTrack, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%'"; if (SKU != "") sql1 = "select distinct OrderId from DT_OrderGoods where SKU1 like '%" + SKU + "%'"; if (IsSku == 1 && sql1 == "") sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0"; else if (IsSku == 1 && sql1 != "") sql1 = sql1 + " and DetailId=0"; else if (IsSku == 0 && sql1 == "" && SortId > 0) sql1 = @"select distinct a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.SortId=@SortId"; else if (IsSku == 0 && sql1 != "" && SortId > 0) sql1 = sql1 + @" and DetailId in (select distinct a.DetailId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.SortId=@SortId)"; string sql2 = "DT_OrderXXInfo"; if (IsTrack == 0) sql2 = "(select * from DT_OrderXXInfo where TrackCode is null or TrackCode='')"; else if (IsTrack == 1) sql2 = "(select * from DT_OrderXXInfo where TrackCode is not null and TrackCode<>'')"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo, SimpErrorInfo=case when len(isnull(b.ErrorInfo,'')+isnull(b.PostError,''))>15 then substring(isnull(b.ErrorInfo,'')+isnull(b.PostError,''),1,15)+'...' else isnull(b.ErrorInfo,'')+isnull(b.PostError,'') end,ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''), b.BuyRemark,b.OrderState,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,ShopName=[dbo].[GetShopName](a.ShopId),a.IsSpare,b.InnerPost,b.OnlinePostId"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfo where OrderId in (" + sql1 + "))a inner join " + sql2 + " b on a.OrderId=b.OrderId left join jc_shop c on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfo a inner join " + sql2 + " b on a.OrderId=b.OrderId left join jc_shop c on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询邮局导出数据 public DataTable GetPostDataOrderNew(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = @" select * from ( select IndexNo=0,e.CompanyName,aa.PlatOrderCode, b.TrackCode,CountryCN=b.CountryName,b.RevName,RevCompany='', b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,CountryEN=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),price='10',GoodsName=(select top 1 c.GoodsName from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=aa.OrderId),aa.PostDate,b.TotalWeight from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join JC_Company e on d.CompanyId=e.CompanyId where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select IndexNo=0,e.CompanyName,PlatOrderCode=case when (select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id0 then aa.PlatOrderCode+'-'+cast((select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id=@SDate and aa.PostDate<=@EDate )f order by PostDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局导出数据 public DataTable GetPostDataOrderForTM(string Ids, int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = ""; if (Ids != "") { tsql = @" select c.OrderId,PlatOrderCode=a.OrderCode, a.TrackCode,CountryCN=b.CountryName,CountryCode=case when b.CountryCode='UK' then 'GB' else b.CountryCode end,b.RevName,RevCompany='',b.RevMail,b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,CountryEN=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),c.PostDate,a.Weight, GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),GoodsEnglisgName=(select top 1 GoodsEnglisgName=isnull(b.GoodsEnglisgName,'') from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId), c.GoodsNum,Price=case when c.GoodsNum<=0 or c.TotalPrice/c.GoodsNum>22 then 21.6 else c.TotalPrice/c.GoodsNum end,CompanyName='甜蜜时空',IndexNo=0, SKU=(select top 1 sku=isnull(b.GoodsCode,b.GoodsOldCode)+'-'+aa.TypeCode from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),c.MoneyCode,Blank='' from DT_TrackCodeScan a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express d on b.Post=d.ExpressID where a.Id in (" + Ids + ") order by c.PostDate"; } else { tsql = @" select c.OrderId,PlatOrderCode=a.OrderCode, a.TrackCode,CountryCN=b.CountryName,CountryCode=case when b.CountryCode='UK' then 'GB' else b.CountryCode end,b.RevName,b.RevMail,RevCompany='',b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,CountryEN=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),c.PostDate,a.Weight, GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),GoodsEnglisgName=(select top 1 GoodsEnglisgName=isnull(b.GoodsEnglisgName,'') from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId), c.GoodsNum,Price=case when c.GoodsNum<=0 or c.TotalPrice/c.GoodsNum>22 then 21.6 else c.TotalPrice/c.GoodsNum end,CompanyName='甜蜜时空',IndexNo=0, SKU=(select top 1 sku=isnull(b.GoodsCode,b.GoodsOldCode)+'-'+aa.TypeCode from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),c.MoneyCode,Blank='' from DT_TrackCodeScan a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express d on b.Post=d.ExpressID where c.PostDate>=@SDate and c.PostDate<=@EDate and c.PostState=1 and b.Post=@PostId order by c.PostDate"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局导出数据 public DataTable GetPostDataOrderForTM2(string Ids, int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = ""; if (Ids != "") { tsql = @" select PlatOrderCode=a.OrderCode, a.TrackCode,CountryCN=b.CountryName,CountryCode=case when b.CountryCode='UK' then 'GB' else b.CountryCode end,b.RevName,RevCompany='',b.RevMail,b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,CountryEN='',c.PostDate,a.Weight, GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),GoodsEnglisgName='', c.GoodsNum,Price=0,CompanyName='甜蜜时空',IndexNo=0, SKU='',c.MoneyCode,Blank='' from DT_TrackCodeScan a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express d on b.Post=d.ExpressID where a.Id in (" + Ids + ") order by c.PostDate"; } else { tsql = @" select PlatOrderCode=a.OrderCode, a.TrackCode,CountryCN=b.CountryName,CountryCode=case when b.CountryCode='UK' then 'GB' else b.CountryCode end,b.RevName,b.RevMail,RevCompany='',b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,CountryEN='',c.PostDate,a.Weight, GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail aa on c.DetailId=aa.DetailId inner join HW_GoodsInfo b on aa.GoodsId=b.GoodsId where c.OrderId=a.OrderId),GoodsEnglisgName='', c.GoodsNum,Price=0,CompanyName='甜蜜时空',IndexNo=0, SKU='',c.MoneyCode,Blank='' from DT_TrackCodeScan a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express d on b.Post=d.ExpressID where c.PostDate>=@SDate and c.PostDate<=@EDate and c.PostState=1 and b.Post=@PostId order by c.PostDate"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局导出数据 public DataTable GetPostDataOrder(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = @" select * from ( select aa.PostDate,b.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,c.EnglishAddress,c.SendName,c.Phone,b.TotalWeight,b.RevPostCode,GoodsType=1,GoodsName=(select top 1 c.GoodsName from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where d.CompanyId=@CompanyId and aa.IsSpare=0 and aa.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select aa.PostDate,e.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,b.RevPhone,c.EnglishAddress,c.SendName,c.Phone,e.TotalWeight,b.RevPostCode,GoodsType=1,GoodsName=(select top 1 c.GoodsName from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join DT_OrderSpare e on aa.OrderId=e.OrderId where d.CompanyId=@CompanyId and aa.IsSpare=1 and aa.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate)f order by PostDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局导出小包数据 public DataSet GetPostDataOrderXB(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataSet dt = null; string tsql = @" select * from ( select aa.PostDate,b.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,c.EnglishAddress,SendName=c.SendEnglishName,c.Phone,b.TotalWeight,b.RevPostCode,GoodsType=1 from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select aa.PostDate,e.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,b.RevPhone,c.EnglishAddress,SendName=c.SendEnglishName,c.Phone,e.TotalWeight,b.RevPostCode,GoodsType=1 from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join DT_OrderSpare e on aa.OrderId=e.OrderId where aa.CompanyId=@CompanyId and aa.IsSpare=1 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate)f order by PostDate select * from ( select aa.PostDate,b.TrackCode,GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where c.OrderId=aa.OrderId),GoodsEnglisgName='Home Garden',GoodsNum=1,Price='10',CN='China',Weight=(select top 1 a.Weight from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId where c.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select aa.PostDate, e.TrackCode,GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where c.OrderId=aa.OrderId),GoodsEnglisgName='Home Garden',GoodsNum=1,Price='10',CN='China',Weight=(select top 1 a.Weight from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId where c.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join DT_OrderSpare e on aa.OrderId=e.OrderId where aa.CompanyId=@CompanyId and aa.IsSpare=1 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate)f order by PostDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataSet(cmd); return dt; } #endregion #region 查询邮局导出杭州小包数据 public DataSet GetPostDataOrderHZXB(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataSet dt = null; string tsql = @" select * from ( select aa.PostDate,b.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,c.EnglishAddress,SendName=c.SendEnglishName,c.Phone,b.TotalWeight,b.RevPostCode,GoodsType=1 from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select aa.PostDate,e.TrackCode,b.CountryName,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),b.RevProvince,b.RevCity,b.RevAddr,b.RevName,b.RevPhone,c.EnglishAddress,SendName=c.SendEnglishName,c.Phone,e.TotalWeight,b.RevPostCode,GoodsType=1 from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join DT_OrderSpare e on aa.OrderId=e.OrderId where aa.CompanyId=@CompanyId and aa.IsSpare=1 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate)f order by PostDate select * from ( select aa.PostDate,b.TrackCode,GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where c.OrderId=aa.OrderId),GoodsEnglisgName='clothes',GoodsNum=1,Price='5',CN='China',Weight=(select top 1 a.Weight from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId where c.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select aa.PostDate, e.TrackCode,GoodsName=(select top 1 b.GoodsName from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where c.OrderId=aa.OrderId),GoodsEnglisgName='clothes',GoodsNum=1,Price='5',CN='China',Weight=(select top 1 a.Weight from DT_OrderGoods c inner join HW_GoodsDetail a on c.DetailId=a.DetailId where c.OrderId=aa.OrderId) from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join DT_OrderSpare e on aa.OrderId=e.OrderId where aa.CompanyId=@CompanyId and aa.IsSpare=1 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate)f order by PostDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataSet(cmd); return dt; } #endregion #region 查询邮局杭州平邮导出数据 public DataTable GetHZPostDataOrder(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = @" select IndexNo=0,* from ( select postname='平邮',aa.PlatOrderCode, b.TrackCode,b.CountryName,b.RevName,RevCompany='', b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),aa.PostDate,b.TotalWeight from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select postname='平邮',PlatOrderCode=case when (select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id0 then aa.PlatOrderCode+'-'+cast((select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id=@SDate and aa.PostDate<=@EDate )f order by PostDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局杭州平邮导出数据 public DataTable GetHZPostDataOrderForTM(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = @" select IndexNo=0,* from ( select postname='平邮',aa.PlatOrderCode, b.TrackCode,b.CountryName,b.RevName,RevCompany='', b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),aa.PostDate,b.TotalWeight from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select postname='平邮',PlatOrderCode=case when (select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id0 then aa.PlatOrderCode+'-'+cast((select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id=@SDate and aa.PostDate<=@EDate )f order by PostDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询邮局南京小包导出数据 public DataTable GetNJPostDataOrder(int CompanyId, int PostId, DateTime SDate, DateTime EDate) { DataTable dt = null; string tsql = @" select * from ( select postname='南京航空小包',e.CompanyName,aa.OrderCode, b.TrackCode,b.CountryName,b.RevName,RevCompany='', b.RevAddr,b.RevPostCode,b.RevCity,b.RevProvince,RevPhone=case when b.RevMoblie is null or b.RevMoblie='' then b.RevPhone else b.RevMoblie end,RevCountry=(select top 1 EnglishName from JC_Country where Code=b.CountryCode),bz='',ckh='',bgh='',sl=1,price='10',GoodsName=(select top 1 c.GoodsName from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=aa.OrderId),aa.PostDate,b.TotalWeight from DT_OrderInfo aa inner join DT_OrderXXInfo b on aa.OrderId=b.OrderId inner join JC_ExpressPost d on b.Post=d.ExpressID inner join JC_PostAddress c on d.DefaultAddr=c.Id inner join JC_Company e on d.CompanyId=e.CompanyId where aa.CompanyId=@CompanyId and aa.IsSpare=0 and d.CompanyId=@CompanyId and c.CompanyId=@CompanyId and aa.State=2 and b.Post=@PostId and aa.PostDate>=@SDate and aa.PostDate<=@EDate union select postname='南京航空小包',e.CompanyName,OrderCode=case when (select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id0 then aa.OrderCode+'-'+cast((select COUNT(0) from DT_OrderSpare where OrderId=aa.OrderId and id=@SDate and aa.PostDate<=@EDate )f order by PostDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 查询已经合并的订单 public List GetNowHBOrder(int CompanyId, DateTime SDate) { List list = null; string tsql = @" select a.OrderId,a.OrderLevel,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.IsJoin=1 and a.State=1 and a.OrderDate>=@SDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询已经合并的订单 public List GetNowHBOrderForTM(int CompanyId, DateTime SDate, string OrderCode) { List list = null; string tsql = @" select a.OrderId,a.JoinOrderCode,a.OrderLevel,a.JoinDate,a.IsJoinAddr,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.IsJoin=1 and a.State=1 and a.OrderDate>=@SDate and (@OrderCode='' or a.JoinOrderCode like '%'+@OrderCode+'%' or a.PlatOrderCode like '%'+@OrderCode+'%') order by JoinOrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询已经合并的订单 public List GetNowHBOrderForTM2(int ShopId, DateTime SDate, string OrderCode) { List list = null; string tsql = @" if @OrderCode<>'' begin select a.OrderId,a.JoinOrderCode,a.OrderLevel,a.JoinDate,a.IsJoinAddr,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,a.MateState from DT_OrderInfonew a inner join DT_OrderXXInfonew b on a.OrderId=b.OrderId where (@ShopId=0 or a.ShopId=@ShopId) and a.IsJoin=1 and a.State=1 and a.PrintState=0 and a.JoinOrderCode in ( select distinct JoinOrderCode from DT_OrderInfonew where (@ShopId=0 or ShopId=@ShopId) and IsJoin=1 and State=1 and PrintState=0 and (JoinOrderCode like '%'+@OrderCode+'%' or PlatOrderCode like '%'+@OrderCode+'%')) order by JoinOrderCode end else begin select a.OrderId,a.JoinOrderCode,a.OrderLevel,a.JoinDate,a.IsJoinAddr,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,a.MateState from DT_OrderInfonew a inner join DT_OrderXXInfonew b on a.OrderId=b.OrderId where (@ShopId=0 or a.ShopId=@ShopId) and a.IsJoin=1 and a.State=1 and a.PrintState=0 order by JoinOrderCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询已经合并的订单 public List GetNowHBOrderForTM(string OrderCode) { List list = null; string tsql = @" select a.OrderId,a.JoinOrderCode,a.PlatOrderCode from DT_OrderInfo a where a.JoinOrderCode=@OrderCode order by JoinOrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 合并订单 public void HBOrder(int OrderId, string JoinId) { string tsql = @" update DT_OrderInfo set JoinOrderCode=@JoinId,IsJoin=1,state=0 where OrderId=@OrderId INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo]) select [OrderId]=@JoinId,[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo] from [DT_OrderGoods] where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinId", DbType.String, JoinId); db.ExecuteNonQuery(cmd); } #endregion #region 合并订单 public void HBOrderForTM(int OrderId, string JoinOrderCode, int IsJoinAddr) { string tsql = @" update DT_OrderInfo set JoinOrderCode=@JoinOrderCode,JoinDate=getdate(),IsJoin=1,IsJoinAddr=@IsJoinAddr where OrderId=@OrderId update DT_OrderInfoNew set JoinOrderCode=@JoinOrderCode,JoinDate=getdate(),IsJoin=1,IsJoinAddr=@IsJoinAddr where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@IsJoinAddr", DbType.Int32, IsJoinAddr); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 合并订单 public void HBOrderForTM2(int OrderId, string JoinOrderCode, int IsJoinAddr) { string tsql = @" update DT_OrderInfo set JoinOrderCode=@JoinOrderCode,JoinDate=getdate(),IsJoin=1,IsJoinAddr=@IsJoinAddr where OrderId=@OrderId update DT_OrderInfonew set JoinOrderCode=@JoinOrderCode,JoinDate=getdate(),IsJoin=1,IsJoinAddr=@IsJoinAddr where OrderId=@OrderId update DT_TrackCodeApply set OrderCode=@JoinOrderCode where OrderId=@OrderId and state=1 and TrackType<3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@IsJoinAddr", DbType.Int32, IsJoinAddr); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 匹配货物 public void MateGoods(int CompanyId, int OrderId, int MateSate) { CK_HouseData obj = new CK_HouseData(); var list = obj.GetUseStoreHouse(CompanyId); if (list == null || list.Count == 0) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("MateOrderGoods"); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@MateSate", DbType.Int32, MateSate); db.ExecuteNonQuery(cmd); } else if (list != null && list.Count > 0) { MateGoodsDetail(OrderId); } } #endregion #region 匹配货物多个仓库 public void MateGoodsDetail(int OrderId) { var list = GetOrderGoods(OrderId); if (list != null) { foreach (var md in list) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("MateOrderGoodsForDetail"); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId.Value); db.ExecuteNonQuery(cmd); } } } #endregion #region 查询要自动分配库存的订单 public List GetLockOrderList(int CompanyId, int orderstate, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.State=1 and a.MateState<=1 and ((@orderstate=0 and a.poststate<>1) or (a.poststate in (0,3))) order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动分配库存的订单 public List GetLockOrderListForTM(int CompanyId, int orderstate, int IsFBA, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState=0 and ((@orderstate=0 and a.poststate<>1) or (a.poststate in (0,3))) order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动分配库存的订单 public List GetLockOrderListForTM3(int CompanyId, int orderstate, int IsFBA, string OrderBy) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState=0 and a.poststate=0 order by " + OrderBy; } else { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState=0 order by " + OrderBy; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动分配库存的订单 public List GetLockOrderListForTM4(int CompanyId, int orderstate, int StoreId, string OrderBy) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and b.StoreId=@StoreId and a.State=1 and a.MateState=0 and a.poststate=0 order by " + OrderBy; } else { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and b.StoreId=@StoreId and a.State=1 and a.MateState=0 order by " + OrderBy; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 调整仓库 public void SetStore() { string tsql = @" update a set a.storeid=b.storeid from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where a.StoreId<>b.StoreId and a.CKDetailId=0 and KCNum>0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 查询未分配合并订单 public List GetNoFPOrderList() { List list = null; string tsql = @" select a.JoinOrderCode from DT_OrderInfo a left join DT_OrderGoods b on a.OrderId=b.OrderId and b.DetailId>0 where a.State=1 and a.IsJoin=1 and (b.Id is null or a.PostState=2)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询未分配合并订单 public List GetNoFPOrderList2(int CompanyId) { List list = null; string tsql = @" select a.JoinOrderCode from DT_OrderInfo a left join DT_OrderGoods b on a.OrderId=b.OrderId and b.DetailId>0 where CompanyId=@CompanyId and a.State=1 and a.IsJoin=1 and (b.Id is null or a.PostState=2)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分分配库存的订单 public List GetLockPartOrderList(int CompanyId, string OrderIds, int orderstate, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.OrderId in (" + OrderIds + ") and a.State=1 and a.MateState<=1 order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分分配库存的订单 public List GetLockPartOrderListForTM(int CompanyId, string OrderIds, string JoinOrderCodes, int orderstate, int IsFBA, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.IsFBA=@IsFBA and a.OrderId in (" + OrderIds + ") and a.State=1 and a.MateState<=1 order by " + OrderBy; if (JoinOrderCodes != "") tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.IsFBA=@IsFBA and (a.OrderId in (" + OrderIds + ") or JoinOrderCode in (" + JoinOrderCodes + ")) and a.State=1 and a.MateState<=1 order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分分配库存的订单 public List GetLockPartOrderListForTM2(int CompanyId, string OrderIds, string JoinOrderCodes, int orderstate, int StoreId, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and b.StoreId=@StoreId and a.OrderId in (" + OrderIds + ") and a.State=1 and a.MateState<=1 order by " + OrderBy; if (JoinOrderCodes != "") tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and b.StoreId=@StoreId and (a.OrderId in (" + OrderIds + ") or JoinOrderCode in (" + JoinOrderCodes + ")) and a.State=1 and a.MateState<=1 order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物 public List GetLockOrderGoods(int CompanyId, int orderstate) { List list = null; string tsql = @" select c.* from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and c.DetailId>0 and a.State=1 and a.MateState<=1 and ((@orderstate=0 and a.poststate<>1) or (a.poststate in (0,3)))"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物 public List GetLockOrderGoodsForTM(int CompanyId, int IsFBA, int orderstate) { List list = null; string tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState<=1 and ((@orderstate=0 and a.poststate<>1) or (a.poststate in (0,3)))"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物 public List GetLockOrderGoodsForTM3(int CompanyId, int IsFBA, int orderstate) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState=0 and a.poststate=0"; } else { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and isnull(a.IsFBA,0)=@IsFBA and a.State=1 and a.MateState=0"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物 public List GetLockOrderGoodsForTM4(int CompanyId, int StoreId, int orderstate) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and b.StoreId=@StoreId and a.State=1 and a.MateState=0 and a.poststate=0"; } else { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and b.StoreId=@StoreId and a.State=1 and a.MateState=0"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分匹配的订单货物 public List GetLockPartOrderGoods(int CompanyId, string OrderIds, int orderstate) { List list = null; string tsql = @" select c.* from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and c.DetailId>0 and c.LockNum(); return list; } #endregion #region 查询要部分匹配的订单货物 public List GetLockPartOrderGoodsForTM(int CompanyId, string OrderIds, string JoinOrderCodes, int IsFBA, int orderstate) { List list = null; string tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.IsFBA=@IsFBA and c.DetailId>0 and a.State=1 and a.OrderId in (" + OrderIds + ") and a.MateState<=1"; if (JoinOrderCodes != "") tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.IsFBA=@IsFBA and c.DetailId>0 and a.State=1 and (a.OrderId in (" + OrderIds + ") or a.JoinOrderCode in (" + JoinOrderCodes + ")) and a.MateState<=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分匹配的订单货物 public List GetLockPartOrderGoodsForTM2(int CompanyId, string OrderIds, string JoinOrderCodes, int StoreId, int orderstate) { List list = null; string tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and b.StoreId=@StoreId and c.DetailId>0 and a.State=1 and a.OrderId in (" + OrderIds + ") and a.MateState<=1"; if (JoinOrderCodes != "") tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and b.StoreId=@StoreId and c.DetailId>0 and a.State=1 and (a.OrderId in (" + OrderIds + ") or a.JoinOrderCode in (" + JoinOrderCodes + ")) and a.MateState<=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetAllOrderGoodsInList(int CompanyId, int orderstate) { List list = null; string tsql = @" select b.*,c.UseShop,c.UseCountry,c.StoreType from HW_GoodsDetail a inner join HW_GoodsInList b on a.DetailId=b.DetailId inner join CK_StoreHouse c on b.StoreId=c.StoreId where a.DetailId in (select distinct c.DetailId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.State=1 and a.MateState=0 and ((@orderstate=0 and a.poststate<>1) or (a.poststate=0))) and b.GoodsNum>0 order by c.LevelGrade desc,c.StoreId,b.InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInList(int OrderId, int DetailId) { List list = null; string tsql = @" select b.*,c.UseShop,c.UseCountry,c.StoreType from HW_GoodsDetail a inner join HW_GoodsInList b on a.DetailId=b.DetailId inner join DT_OrderGoods d on a.DetailId=d.DetailId inner join CK_StoreHouse c on b.StoreId=c.StoreId where d.orderid=@OrderId and d.DetailId=@DetailId and b.GoodsNum>0 order by c.LevelGrade desc,c.StoreId,b.InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInListNew(int OrderId, int DetailId) { List list = null; string tsql = @" select b.*,c.UseShop,c.UseCountry,c.StoreType from HW_GoodsDetail a inner join HW_GoodsInDetail b on a.DetailId=b.DetailId inner join DT_OrderGoods d on a.DetailId=d.DetailId inner join CK_StoreHouse c on b.StoreId=c.StoreId where d.orderid=@OrderId and d.DetailId=@DetailId and b.OrderGoodsId=0 order by c.LevelGrade desc,c.StoreId,b.InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的库存 public List GetNowKCGoods(int orderstate) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=1) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and isnull(c.IsFba,0)=0 and c.FPDate is not null)"; } else { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=1) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.State=1 and isnull(c.IsFba,0)=0 and c.FPDate is not null)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的库存 public List GetNowKCGoods2(int orderstate, int IsFBA) { List list = null; string tsql = ""; if (orderstate == 1) { if(IsFBA==1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=2) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and c.IsFba=1 and c.FPDate is not null)"; } else tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=1) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and isnull(c.IsFba,0)=0 and c.FPDate is not null)"; } else { if (IsFBA == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=2) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.State=1 and c.IsFba=1 and c.FPDate is not null)"; } else tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId in (select StoreId from CK_StoreHouse where StoreType=1) and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.MateState=0 and c.State=1 and isnull(c.IsFba,0)=0 and c.FPDate is not null)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的库存 public List GetNowKCGoods4(int orderstate, int StoreId) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null)"; } else { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId from HW_GoodsInDetail a where OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的库存 public List GetNowKCGoods5(int orderstate, int StoreId) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null) order by b.SortNo,a.KCNum desc"; } else { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null) order by b.SortNo,a.KCNum desc"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM2(int DetailId, int StoreId) { List list = null; string tsql = @" select * from HW_GoodsInDetail where DetailId=@DetailId and StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM22(int DetailId, int IsFba) { List list = null; string tsql = @" select * from HW_GoodsInDetail where DetailId=@DetailId and StoreId in (select StoreId from CK_StoreHouse where StoreType=1) and OrderGoodsId=0 and KCNum>0 order by InId desc "; if(IsFba==1) tsql = @" select * from HW_GoodsInDetail where DetailId=@DetailId and StoreId in (select StoreId from CK_StoreHouse where StoreType=2) and OrderGoodsId=0 and KCNum>0 order by InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM33(int DetailId, int StoreId) { List list = null; string tsql = @" select * from HW_GoodsInDetail where DetailId=@DetailId and StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by InId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM34(int DetailId, int StoreId) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where DetailId=@DetailId and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by b.SortNo,a.KCNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForHWC(int DetailId, int StoreId) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetailHWC a inner join CK_StorePostion b on a.PostionId=b.PostionId where DetailId=@DetailId and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by b.SortNo,a.KCNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM35(int DetailId, int StoreId,string ShopName) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where DetailId=@DetailId and b.PostionCode=@ShopName and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by b.SortNo,a.KCNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@ShopName", DbType.String, ShopName); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public List GetMateOrderGoodsInForTM(int OrderId, int DetailId, int StoreId, string JoinOrderCode) { List list = null; string tsql = @" if @JoinOrderCode<>'' begin select b.* from HW_GoodsInDetail b inner join DT_OrderGoods d on b.DetailId=d.DetailId inner join DT_OrderInfo e on d.OrderId=e.OrderId where e.JoinOrderCode=@JoinOrderCode and e.state=1 and b.StoreId=@StoreId and d.DetailId=@DetailId and b.OrderGoodsId=0 order by b.InId desc end else begin select b.* from HW_GoodsInDetail b inner join DT_OrderGoods d on b.DetailId=d.DetailId where d.orderid=@OrderId and b.StoreId=@StoreId and d.DetailId=@DetailId and b.OrderGoodsId=0 order by b.InId desc end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLock(int OrderId, decimal GoodsFee, decimal PostFee, List list1, List list2) { //return; string tsql = @" update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId --update a set a.GoodsNum=a.GoodsNum-c.GoodsNum,a.GoodsLockNum=isnull(a.GoodsLockNum,0)+c.GoodsNum from HW_GoodsDetail a --inner join DT_OrderGoods c on a.DetailId=c.DetailId --where c.OrderId=@OrderId --update a set a.GoodsNum=a.GoodsNum-c.GoodsNum,a.GoodsLockNum=isnull(a.GoodsLockNum,0)+c.GoodsNum from HW_GoodsInfo a --inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId --inner join DT_OrderGoods c on b.DetailId=c.DetailId --where c.OrderId=@OrderId "; if (list1 != null) { foreach (var md1 in list1) { tsql += "update DT_OrderGoods set LockNum=GoodsNum where Id=" + md1.Id + " "; } } if (list2 != null) { foreach (var md2 in list2) { tsql += @"INSERT INTO [DT_OrderGoodsOutList]([OrderId],[OrderGoodsId],[LockNum],[InId],[OutNum]) values(" + md2.OrderId + "," + md2.OrderGoodsId + "," + md2.LockNum + "," + md2.InId + ",0) update HW_GoodsInList set GoodsNum=GoodsNum-" + md2.LockNum + ",GoodsLockNum=GoodsLockNum+" + md2.LockNum + " where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockNew(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, List list1, List list2) { //return; string tsql = @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=isnull(GoodsFee,0)+@GoodsFee+@PostFee where OrderId=@OrderId "; if (list1 != null) { foreach (var md1 in list1) { tsql += "update DT_OrderGoods set LockNum=isnull(LockNum,0)+" + md1.LockNum + " where Id=" + md1.Id + " "; } } if (list2 != null) { foreach (var md2 in list2) { tsql += @"INSERT INTO [DT_OrderGoodsOutList]([OrderId],[OrderGoodsId],[LockNum],[InId],[OutNum]) values(" + md2.OrderId + "," + md2.OrderGoodsId + "," + md2.LockNum + "," + md2.InId + ",0) update HW_GoodsInList set GoodsNum=GoodsNum-" + md2.LockNum + ",GoodsLockNum=GoodsLockNum+" + md2.LockNum + " where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockNew2(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, List list1, List list2) { //return; string tsql = @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId "; if (list1 != null) { foreach (var md1 in list1) { tsql += "update DT_OrderGoods set LockNum=isnull(LockNum,0)+" + md1.LockNum + " where Id=" + md1.Id + " "; } } if (list2 != null) { foreach (var md2 in list2) { tsql += @" update HW_GoodsInDetail set OrderGoodsId=" + md2.OrderGoodsId + ",UpDateTime=getdate() where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, string JoinOrderCode, List list) { //return; string tsql = ""; if (JoinOrderCode != "") { tsql = @" if(select count(0) from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode and a.DetailId<=0)=0 begin update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode update b set b.GoodsFee=@GoodsFee+@PostFee from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.JoinOrderCode=@JoinOrderCode update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode update a set a.LockNum=a.GoodsNum from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end "; } else tsql = @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId "; if (list != null) { foreach (var md2 in list) { tsql += @" update HW_GoodsInDetail set OrderGoodsId=" + md2.OrderGoodsId + ",UpDateTime=getdate() where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM2(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId] from [HW_GoodsInDetail] where InId=" + md2.InId + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode --update b set b.GoodsFee=@GoodsFee+@PostFee from DT_OrderInfo a --inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --where a.JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=@MateState where JoinOrderCode=@JoinOrderCode --update b set b.GoodsFee=@GoodsFee+@PostFee from DT_OrderInfoNew a --inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId --where a.JoinOrderCode=@JoinOrderCode --update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a --inner join HW_GoodsDetail b on a.DetailId=b.DetailId --inner join DT_OrderInfo c on a.OrderId=c.OrderId --where c.JoinOrderCode=@JoinOrderCode --update a set a.LockNum=a.GoodsNum from DT_OrderGoods a --inner join DT_OrderInfo c on a.OrderId=c.OrderId --where c.JoinOrderCode=@JoinOrderCode "; } else tsql += @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId --update DT_OrderXXInfo set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId update DT_OrderInfoNew set MateState=@MateState where OrderId=@OrderId --update DT_OrderXXInfoNew set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId --update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a --inner join HW_GoodsDetail b on a.DetailId=b.DetailId --where a.OrderId=@OrderId --update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForHWC(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],HWCFee,CompanyId) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId],HWCFee,CompanyId from [HW_GoodsInDetailHWC] where InId=" + md2.InId + @" update HW_GoodsInDetailHWC set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetailHWC set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode "; } else tsql += @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM3(int OrderId, int MateState,string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId] from [HW_GoodsInDetail] where InId=" + md2.InId + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=@MateState where JoinOrderCode=@JoinOrderCode "; } else tsql += @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderInfoNew set MateState=@MateState where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM4(int OrderId, int MateState, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId] from [HW_GoodsInDetail] where InId=" + md2.InId + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + @" update DT_OrderGoods set LockNum=isnull(LockNum,0)+" + md2.KCNum + " where Id=" + md2.OrderGoodsId + @" update HW_OrderMate set IsMate=1 where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM8(List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_KCMate]([InId],[OrderNum],OrderGoodsId) VALUES( " + md2.InId + "," + md2.OrderNum + "," + md2.OrderGoodsId + ")"; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM3(int OrderId, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.OrderNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId] from [HW_GoodsInDetail] where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.OrderNum + " where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != null && JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set MateState=2 where JoinOrderCode=@JoinOrderCode "; } else if (OrderId > 0) { tsql += @" update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfonew set MateState=2 where OrderId=@OrderId "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public void UpdateOrderGoodsLockForTM31(string OrderIds, string JoinOrderCodes) { //return; string tsql = ""; if (JoinOrderCodes != "") { tsql += @" update DT_OrderInfo set MateState=2 where JoinOrderCode in (" + JoinOrderCodes + @") update DT_OrderInfonew set MateState=2 where JoinOrderCode in (" + JoinOrderCodes + @") "; } if (OrderIds != "") tsql += @" update DT_OrderInfo set MateState=2 where OrderId in (" + OrderIds + @") update DT_OrderInfonew set MateState=2 where OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 海外仓自动匹配的订单货物 public void UpdateOrderFBAGoodsLockForTM(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, List list) { //return; string tsql = @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=@GoodsFee+@PostFee where OrderId=@OrderId update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId "; if (list != null) { foreach (var md2 in list) { tsql += @" update HW_GoodsInDetail set OrderGoodsId=" + md2.OrderGoodsId + ",UpDateTime=getdate() where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 查询订单货物 public List GetOrderGoods(int OrderId) { List list = null; string tsql = @" select * from DT_OrderGoods where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询退货订单货物 public List GetBackOrderGoods(string OrderIds) { List list = null; string tsql = @" select a.Id,c.OrderId,b.DetailId,a.GoodsNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询退货订单货物 public List GetBackOrderGoods2(string Code, int TJ) { List list = null; string tsql = @" declare @OrderId int,@JoinOrderCode nvarchar(50) set @OrderId=0 set @JoinOrderCode='' if @TJ=1 begin select top 1 @OrderId=OrderId,@JoinOrderCode=JoinOrderCode from DT_OrderInfo where state<3 and PrintState=1 and PlatOrderCode=@Code end else if @TJ=2 begin select top 1 @OrderId=a.OrderId,@JoinOrderCode=a.JoinOrderCode from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.State<3 and a.PrintState=1 and b.State=1 and b.TrackType<3 and b.TrackCode=@Code end if @JoinOrderCode is not null or @JoinOrderCode<>'' begin select a.Id,OrderCode=d.PlatOrderCode,d.OrderId,b.DetailId,a.GoodsNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode end else begin select a.Id,OrderCode=d.PlatOrderCode,d.OrderId,b.DetailId,a.GoodsNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@TJ", DbType.Int32, TJ); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询退货订单货物库位 public List GetBackGoodsPostion(int OrderId, int DetailId) { List list = null; string tsql = @" select distinct c.PostionCode from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join CK_StorePostion c on a.PostionId=c.PostionId where b.OrderId=@OrderId and a.DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询仓库入库货物记录 public List GetGoodsInList(int DetailId) { List list = null; string tsql = @" select b.* from HW_GoodsDetail a inner join HW_GoodsInList b on a.DetailId=b.DetailId inner join CK_StoreHouse c on b.StoreId=c.StoreId where a.DetailId=@DetailId and b.GoodsNum>0 order by c.LevelGrade desc,c.StoreId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 匹配货物 public void MateGoodsNew(int OrderId, int MateSate) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("MateOrderGoods"); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@MateSate", DbType.Int32, MateSate); db.ExecuteNonQuery(cmd); } #endregion #region 取消匹配货物 public void UpdateMateGoods(int OrderId) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("CancelMateOrderGoods"); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 已发货修改成未发货 public void UpdateOrderNoPost(int OrderId) { string tsql = @" update a set a.OutNum=0,a.LockNum=a.OutNum from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update DT_OrderInfo set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderSpare set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderGoods set OutNum=0 where OrderId=@OrderId update a set a.GoodsNum=a.GoodsNum+c.GoodsNum,a.GoodsPlanNum=a.GoodsPlanNum+c.GoodsNum from HW_GoodsDetail a inner join DT_OrderGoods c on a.DetailId=c.DetailId where c.OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 已发货修改成未发货 public void UpdateOrderNoPostNew(int OrderId) { string tsql = @" update DT_OrderInfo set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderSpare set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderGoods set OutNum=0 where OrderId=@OrderId update a set a.GoodsNum=a.GoodsNum+c.GoodsNum,a.GoodsPlanNum=a.GoodsPlanNum+c.GoodsNum from HW_GoodsDetail a inner join DT_OrderGoods c on a.DetailId=c.DetailId where c.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 已发货修改成未发货 public void UpdateOrderNoPostForTM(int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where JoinOrderCode=@JoinOrderCode if(select count(0) from DT_OrderInfoNew where JoinOrderCode=@JoinOrderCode)>0 begin update DT_OrderInfoNew set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where JoinOrderCode=@JoinOrderCode end else begin INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate] from DT_OrderInfo where JoinOrderCode=@JoinOrderCode INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId]) select a.OrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId] from [DT_OrderXXInfo] a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end delete from DT_TrackCodeScan where OrderCode=@JoinOrderCode update DT_TrackCodeApply set ScanState=0 where OrderCode=@JoinOrderCode --update b set b.PostFee=0,b.TotalWeight=0 from DT_OrderInfo a --inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --where a.JoinOrderCode=@JoinOrderCode --update b set b.OutNum=0 from DT_OrderInfo a --inner join DT_OrderGoods b on a.OrderId=b.OrderId --where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where OrderId=@OrderId if(select count(0) from DT_OrderInfoNew where OrderId=@OrderId)>0 begin update DT_OrderInfoNew set State=1,UpdateDate=getdate(),PostState=0,PostDate=null where OrderId=@OrderId end else begin INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate] from DT_OrderInfo where OrderId=@OrderId INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId]) select [OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId] from [DT_OrderXXInfo] where OrderId=@OrderId end delete from DT_TrackCodeScan where OrderId=@OrderId update DT_TrackCodeApply set ScanState=0 where OrderId=@OrderId --update DT_OrderXXInfo set PostFee=0,TotalWeight=0 where OrderId=@OrderId --update DT_OrderGoods set OutNum=0 where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 未发货取消匹配货物 public void UpdateMateGoodsNew(int OrderId) { string tsql = @" update a set a.GoodsNum=a.GoodsNum+b.LockNum,a.GoodsLockNum=a.GoodsLockNum-b.LockNum from HW_GoodsInList a inner join DT_OrderGoodsOutList b on a.InId=b.InId inner join DT_OrderGoods c on b.OrderGoodsId=c.Id where c.OrderId=@OrderId delete a from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderGoods set LockNum=0 where OrderId=@OrderId --update a set a.GoodsNum=a.GoodsNum+isnull(c.OutNum,0),a.GoodsPlanNum=a.GoodsPlanNum+isnull(c.OutNum,0) from HW_GoodsDetail a --inner join DT_OrderGoods c on a.DetailId=c.DetailId --where c.OrderId=@OrderId --update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a --inner join HW_GoodsDetail b on a.DetailId=b.DetailId --inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId --where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 未发货取消匹配货物 public void UpdateMateGoodsNew2(int OrderId) { string tsql = @" update a set a.OrderGoodsId=0,UpDateTime=getdate(),CKDetailId=0 from HW_GoodsInDetail a inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderGoods set LockNum=0 where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 未发货取消匹配货物 public void UpdateMateGoodsForTM(int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update a set a.OrderGoodsId=0,UpDateTime=getdate() from HW_GoodsInDetail a inner join DT_OrderGoods c on a.OrderGoodsId=c.Id inner join DT_OrderInfo d on c.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where JoinOrderCode=@JoinOrderCode update a set a.LockNum=0 from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode --update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a --inner join HW_GoodsDetail b on a.DetailId=b.DetailId --inner join DT_OrderInfo c on a.OrderId=c.OrderId --where c.JoinOrderCode=@JoinOrderCode end else begin update a set a.OrderGoodsId=0,UpDateTime=getdate() from HW_GoodsInDetail a inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderInfoNew set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderGoods set LockNum=0 where OrderId=@OrderId --update b set b.GoodsLockNum=dbo.GetLockGoodsNum(a.DetailId) from [DT_OrderGoods] a --inner join HW_GoodsDetail b on a.DetailId=b.DetailId --where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 已发货取消匹配货物 public void UpdateMateGoodsNewPost(int OrderId) { string tsql = @" update a set a.GoodsNum=a.GoodsNum+b.LockNum,a.GoodsLockNum=a.GoodsLockNum-b.LockNum from HW_GoodsInList a inner join DT_OrderGoodsOutList b on a.InId=b.InId inner join DT_OrderGoods c on b.OrderGoodsId=c.Id where c.OrderId=@OrderId delete a from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderSpare set PostFee=0,TotalWeight=0 where OrderId=@OrderId update a set a.GoodsNum=a.GoodsNum+c.GoodsNum,a.GoodsPlanNum=a.GoodsPlanNum+c.GoodsNum from HW_GoodsDetail a inner join DT_OrderGoods c on a.DetailId=c.DetailId where c.OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 已发货取消匹配货物 public void UpdateMateGoodsNewPost2(int OrderId) { string tsql = @" update a set a.OrderGoodsId=0 from HW_GoodsInDetail a inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId update a set a.GoodsNum=a.GoodsNum+c.GoodsNum,a.GoodsPlanNum=a.GoodsPlanNum+c.GoodsNum from HW_GoodsDetail a inner join DT_OrderGoods c on a.DetailId=c.DetailId where c.OrderId=@OrderId update DT_OrderInfo set MateState=0,State=1,UpdateDate=getdate(),PrintState=0,PostState=0 where OrderId=@OrderId update DT_OrderGoods set LockNum=0 where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单级别 public void UpdateOrderLevel(int OrderId, int AddNum) { string tsql = @" update DT_OrderInfo set OrderLevel=isnull(OrderLevel,0)+@AddNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@AddNum", DbType.Int32, AddNum); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单级别 public int UpdateOrderLevelForTM(int OrderId, int AddNum, int MaxLevel, int UserId) { string tsql = @" declare @OrderLevel int,@JoinOrderCode nvarchar(50) select top 1 @OrderLevel=isnull(OrderLevel,1),@JoinOrderCode=JoinOrderCode from DT_OrderInfoNew where OrderId=@OrderId if(@AddNum>0 and @OrderLevel<@MaxLevel) begin if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set OrderLevel=isnull(OrderLevel,0)+@AddNum where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set OrderLevel=isnull(OrderLevel,0)+@AddNum where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set OrderLevel=isnull(OrderLevel,0)+@AddNum where OrderId=@OrderId update DT_OrderInfoNew set OrderLevel=isnull(OrderLevel,0)+@AddNum where OrderId=@OrderId end select 1 end else if(@AddNum<0 and @OrderLevel>0) begin if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set OrderLevel=isnull(OrderLevel,0)+@AddNum where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set OrderLevel=isnull(OrderLevel,0)+@AddNum where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set OrderLevel=isnull(OrderLevel,0)+@AddNum where OrderId=@OrderId update DT_OrderInfoNew set OrderLevel=isnull(OrderLevel,0)+@AddNum where OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@AddNum", DbType.Int32, AddNum); db.AddInParameter(cmd, "@MaxLevel", DbType.Int32, MaxLevel); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单运费 public void ImportOrderWeight(string OrderCode, decimal PostFee, decimal Weight) { string tsql = @" if @PostFee>=0 and @Weight>=0 begin update a set a.PostFee=@PostFee,a.TotalWeight=@Weight from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.PlatOrderCode=@OrderCode end else if @PostFee>=0 begin update a set a.PostFee=@PostFee from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.PlatOrderCode=@OrderCode end else if @Weight>=0 begin update a set a.TotalWeight=@Weight from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.PlatOrderCode=@OrderCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单运费 public void ImportOrderWeight(int OrderId, decimal PostFee, decimal Weight) { string tsql = @" if @PostFee>=0 and @Weight>=0 begin update DT_OrderXXInfo set PostFee=@PostFee,TotalWeight=@Weight where OrderId=@OrderId end else if @PostFee>=0 begin update DT_OrderXXInfo set PostFee=@PostFee where OrderId=@OrderId end else if @Weight>=0 begin update DT_OrderXXInfo set TotalWeight=@Weight where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单线上发货 public void UpdateOrderOnline(int OrderId, int InnerPost, string FontTrackCode, decimal InnerPostFee, string OnlinePostId) { string tsql = @" update DT_OrderXXInfo set Post=9,InnerPost=@InnerPost,FontTrackCode=@FontTrackCode,InnerPostFee=@InnerPostFee,OnlinePostId=@OnlinePostId,TrackDate=getdate(),TrackCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InnerPost", DbType.Int32, InnerPost); db.AddInParameter(cmd, "@FontTrackCode", DbType.String, FontTrackCode); db.AddInParameter(cmd, "@InnerPostFee", DbType.Decimal, InnerPostFee); db.AddInParameter(cmd, "@OnlinePostId", DbType.String, OnlinePostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单线上发货 public void UpdateOrderOnlineForTM(int OrderId, int InnerPost, string FontTrackCode, decimal InnerPostFee, int LogisticsId, int OnlinePostId) { string tsql = @" update DT_OrderXXInfo set LogisticsId=@LogisticsId,Post=@OnlinePostId,InnerPost=@InnerPost,FontTrackCode=@FontTrackCode,InnerPostFee=@InnerPostFee,OnlinePostId=@OnlinePostId,TrackDate=getdate(),TrackCode=null where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,Post=@OnlinePostId,InnerPost=@InnerPost,FontTrackCode=@FontTrackCode,InnerPostFee=@InnerPostFee,OnlinePostId=@OnlinePostId,TrackDate=getdate(),TrackCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InnerPost", DbType.Int32, InnerPost); db.AddInParameter(cmd, "@FontTrackCode", DbType.String, FontTrackCode); db.AddInParameter(cmd, "@InnerPostFee", DbType.Decimal, InnerPostFee); db.AddInParameter(cmd, "@OnlinePostId", DbType.String, OnlinePostId); db.AddInParameter(cmd, "@LogisticsId", DbType.String, LogisticsId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单线上发货 public void UpdateOrderOnlineForTM(int OrderId, int InnerPost, string FontTrackCode, decimal InnerPostFee, string OnlinePostId) { string tsql = @" update DT_OrderXXInfo set LogisticsId=9,Post=@OnlinePostId,InnerPost=@InnerPost,FontTrackCode=@FontTrackCode,InnerPostFee=@InnerPostFee,OnlinePostId=@OnlinePostId,TrackDate=getdate(),TrackCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InnerPost", DbType.Int32, InnerPost); db.AddInParameter(cmd, "@FontTrackCode", DbType.String, FontTrackCode); db.AddInParameter(cmd, "@InnerPostFee", DbType.Decimal, InnerPostFee); db.AddInParameter(cmd, "@OnlinePostId", DbType.String, OnlinePostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单线上发货 public void UpdateOrderOnlineTrackNo(int OrderId, string TrackCode) { string tsql = @" update DT_OrderXXInfo set TrackCode=@TrackCode,TrackDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单合并 public void CancelHBOrder(int HbOrderId) { string tsql = @" update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,state=1,updatedate=getdate() where JoinOrderCode=@HbOrderId update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,state=0,updatedate=getdate() where OrderId=@HbOrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@HbOrderId", DbType.Int32, HbOrderId); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单合并 public void CancelHBOrderForTM(string JoinOrderCode, int OrderId) { string tsql = @" if(select count(0) from DT_OrderInfo where JoinOrderCode=@JoinOrderCode)<=2 begin update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where JoinOrderCode=@JoinOrderCode and IsJoin=1 end else begin update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where OrderId=@OrderId and IsJoin=1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单合并 public void CancelHBOrderForTM2(string JoinOrderCode, int OrderId) { string tsql = @" if(select count(0) from DT_OrderInfonew where JoinOrderCode=@JoinOrderCode)>2 begin update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where OrderId=@OrderId and IsJoin=1 update DT_OrderInfoNew set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where OrderId=@OrderId and IsJoin=1 update a set a.OrderCode=b.PlatOrderCode from DT_TrackCodeApply a inner join DT_OrderInfonew b on a.OrderId=b.OrderId where a.OrderId=@OrderId update a set a.TrackState=0 from DT_OrderXXInfonew a left join DT_TrackCodeApply b on a.OrderId=b.OrderId and b.State=1 where a.OrderId=@OrderId and b.Id is null update a set a.TrackState=0 from DT_OrderXXInfo a left join DT_TrackCodeApply b on a.OrderId=b.OrderId and b.State=1 where a.OrderId=@OrderId and b.Id is null end else begin update DT_OrderInfo set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where JoinOrderCode=@JoinOrderCode and IsJoin=1 update DT_OrderInfoNew set JoinOrderCode=null,IsJoin=0,updatedate=getdate() where JoinOrderCode=@JoinOrderCode and IsJoin=1 update a set a.OrderCode=b.PlatOrderCode from DT_TrackCodeApply a inner join DT_OrderInfonew b on a.OrderId=b.OrderId where a.OrderCode=@JoinOrderCode update a set a.TrackState=0 from DT_OrderXXInfonew a inner join DT_OrderInfo c on a.OrderId=c.OrderId left join DT_TrackCodeApply b on a.OrderId=b.OrderId and b.State=1 where c.IsJoin=0 and c.JoinOrderCode=@JoinOrderCode and b.Id is null update a set a.TrackState=0 from DT_OrderXXInfo a inner join DT_OrderInfo c on a.OrderId=c.OrderId left join DT_TrackCodeApply b on a.OrderId=b.OrderId and b.State=1 where c.IsJoin=0 and c.JoinOrderCode=@JoinOrderCode and b.Id is null end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 删除订单 public void DeleteOrder(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=0,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 删除订单 public void DeleteOrderForTM(string OrderIds) { string tsql = @" delete from DT_OrderXXInfo where OrderId in (" + OrderIds + @") update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + @") delete from API_OrderInfo where OrderCode in (select distinct PlatOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @")) delete from DT_OrderGoods where OrderId in (" + OrderIds + @") delete from DT_OrderInfo where OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 删除订单 public void DeleteOrderForTM2(string OrderIds) { string tsql = @" if(select count(1) from DT_OrderInfo where OrderId in (" + OrderIds + @") and MateState>0)=0 begin delete from DT_OrderXXInfo where OrderId in (" + OrderIds + @") delete from DT_OrderXXInfoNew where OrderId in (" + OrderIds + @") update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + @") delete from API_OrderInfo where OrderCode in (select distinct PlatOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @")) delete from DT_OrderGoods where OrderId in (" + OrderIds + @") delete from DT_OrderInfo where OrderId in (" + OrderIds + @") delete from DT_OrderInfoNew where OrderId in (" + OrderIds + @") delete from DT_TrackCodeApply where OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单 public void DeleteCancelOrder(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=3,updatedate=getdate(),MateState=0,PrintState=0,InUserId=@InUserId,IsJoin=0,IsJoinAddr=0,JoinOrderCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 订单状态 public int IsOrderState(int OrderId) { string tsql = @" select top 1 MateState=isnull(MateState,0) from DT_OrderInfo where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 订单状态 public int IsOrderStates(string OrderIds) { string tsql = @" declare @MateState int set @MateState=0 select top 1 @MateState=isnull(TrackState,0) from DT_OrderXXInfo where TrackState=1 and OrderId in (" + OrderIds + @") if @MateState=0 begin select top 1 @MateState=isnull(MateState,0) from DT_OrderInfo where MateState>0 and OrderId in (" + OrderIds + @") end select MateState=@MateState "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 订单状态 public int IsOrderStates2(string JoinOrderCode) { string tsql = @" declare @MateState int set @MateState=0 select top 1 @MateState=isnull(TrackState,0) from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where TrackState=1 and JoinOrderCode=@JoinOrderCode if @MateState=0 begin select top 1 @MateState=isnull(MateState,0) from DT_OrderInfo where MateState>0 and JoinOrderCode=@JoinOrderCode end select MateState=@MateState "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 取消订单 public void DeleteCancelOrder2(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=3,updatedate=getdate(),MateState=0,PrintState=0,InUserId=@InUserId,IsJoin=0,IsJoinAddr=0,JoinOrderCode=null where OrderId=@OrderId update DT_OrderInfoNew set state=3,updatedate=getdate(),MateState=0,PrintState=0,InUserId=@InUserId,IsJoin=0,IsJoinAddr=0,JoinOrderCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 恢复订单 public void CancelBackOrder(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=1,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 恢复订单 public void CancelBackOrder2(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=1,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId if(select count(0) from DT_OrderInfoNew where OrderId=@OrderId)>0 begin update DT_OrderInfoNew set state=1,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId end else begin INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate] from DT_OrderInfo where OrderId=@OrderId INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId]) select [OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[InnerPost],[InnerPostFee],[FontTrackCode],[OnlinePostId],[PostOneCode],[TrackCode2],[LogisticsId] from [DT_OrderXXInfo] where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 查询打印订单 public List GetPrintOrderList(int OrderId, string JoinOrderCode) { List list = null; string tsql = @" if @JoinOrderCode<>'' begin select OrderId,PrintState from DT_OrderInfo where JoinOrderCode=@JoinOrderCode and State=1 and PrintState=0 end else begin select OrderId,PrintState from DT_OrderInfo where OrderId=@OrderId and State=1 and PrintState=0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询打印订单 public List GetPrintOrderList2(string OrderIds, string JoinOrderCodes) { List list = null; string tsql = ""; if (JoinOrderCodes != "") { tsql = @" select OrderId,PrintState,GoodsNum from DT_OrderInfoNew where JoinOrderCode in (" + JoinOrderCodes + @") and State=1 and PrintState=0"; } if (OrderIds != "") { if (tsql != "") { tsql += @" union select OrderId,PrintState,GoodsNum from DT_OrderInfoNew where OrderId in (" + OrderIds + @") and State=1 and PrintState=0"; } else { tsql = @" select OrderId,PrintState,GoodsNum from DT_OrderInfoNew where OrderId in (" + OrderIds + @") and State=1 and PrintState=0"; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询打印订单 public List GetPrintOrderList3(string OrderIds, string JoinOrderCodes) { List list = null; string tsql = ""; if (JoinOrderCodes != "") { tsql = @" select OrderId,PrintState,GoodsNum from DT_OrderInfo where JoinOrderCode in (" + JoinOrderCodes + @") and State=1 and PrintState=0"; } if (OrderIds != "") { if (tsql != "") { tsql = @" union select OrderId,PrintState,GoodsNum from DT_OrderInfo where OrderId in (" + OrderIds + @") and State=1 and PrintState=0"; } else { tsql = @" select OrderId,PrintState,GoodsNum from DT_OrderInfo where OrderId in (" + OrderIds + @") and State=1 and PrintState=0"; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsList(int OrderId) { List list = null; string tsql = @" select *,SpareNum=GoodsNum from DT_OrderGoods where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsDetailList(int OrderId) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,b.Weight,b.Solid,c.GoodsName,c.GoodsEnglisgName,b.BGPrice,b.TypeDesc,b.TypeCode,c.GoodsCode from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsDetailListForJoin(string JoinOrderCode) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,b.Weight,b.Solid,c.GoodsName,c.GoodsEnglisgName,b.BGPrice,b.TypeDesc,b.TypeCode,c.GoodsCode from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsList22(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,Weight=c.Weight2,c.Long2,c.Width2,c.height2,b.Solid,c.GoodsName,c.GoodsEnglisgName,b.BGPrice,c.GoodsCode,b.TypeDesc,b.TypeCode from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsListNew(int OrderId) { List list = null; string tsql = @" select a.Id,a.OrderId,d.PlatId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,SKUState=case when a.DetailId>0 then '已经分配' else '未分配' end,GoodsName=case when c.GoodsName is null then a.GoodsName else c.GoodsName end,productImgUrl=case when productImgUrl is not null and productImgUrl<>'' then productImgUrl else '../images/no.jpg' end,TypeDesc=a.GoodsDesc,GoodsDesc=case when a.detailid<=0 then '' when a.detailid>0 and c.GoodsCode is not null and c.GoodsCode<>'' then c.GoodsCode+' '+b.TypeCode+'['+b.TypeDesc+']' else c.GoodsOldCode+' '+b.TypeCode+'['+b.TypeDesc+']' end,a.OldNum,a.GoodsCode,GoodsId=isnull(c.GoodsId,0),OldTypeDesc=case when a.OldTypeDesc is not null and a.OldTypeDesc<>'' then '改为'+a.OldTypeDesc+'发' else '' end,a.OldTypeCode,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0),c.Solid from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId left join HW_GoodsDetail b on a.DetailId=b.DetailId left join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsPostionCode(int OrderId) { List list = null; string tsql = @" select d.PlatId,b.Id,c.PostionCode,Price=isnull(a.Price,0),PostPrice=isnull(a.PostPrice,0),HWCFee=isnull(a.HWCFee,0) from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join CK_StorePostion c on a.PostionId=c.PostionId inner join DT_OrderInfo d on b.OrderId=d.OrderId where b.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物匹配 public List GetOrderGoodsMateDetail(int OrderGoodsId, int DetailId) { List list = null; string tsql = @" select a.GoodsNum,c.LockNum,b.StoreName,HwPostionId=a.Id,b.StoreId,a.PostionId from HW_GoodsPostion a inner join CK_StoreHouse b on a.StoreId=b.StoreId left join DT_OrderGoodsMate c on a.Id=c.HwPostionId and c.OrderGoodsId=@OrderGoodsId where a.DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, OrderGoodsId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsDetail(int OrderId) { List list = null; string tsql = @" select a.*,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-a.GoodsNum from DT_OrderGoods a left join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public List GetOrderGoodsDetailCD(string OrderId) { List list = null; string tsql = @" SELECT b.GoodsSKU FROM dbo.API_OrderInfo a LEFT JOIN dbo.API_OrderGoods b ON b.OrderId=a.OrderId WHERE a.OrderCode=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.String, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public List GetOrderGoodsList(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsInNum2=isnull(b.GoodsInNum2,0),GoodsInNum3=case when isnull(b.GoodsInNum,0)-isnull(b.GoodsInNum2,0)>0 then isnull(b.GoodsInNum,0)-isnull(b.GoodsInNum2,0) else 0 end,GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,d.PlatId,productImgUrl2=a.productImgUrl,productImgUrl=case when d.PlatId<>2 and a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc,a.GoodsFee,a.TCFee,GoodsPrice=b.InPrice,b.Solid2 from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.*,c.InPrice,Solid2=c.Solid from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public List GetOrderGoodsListHWC(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,productImgUrl= case when a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.* from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public List GetOrderGoodsList2(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,f.GoodsName,f.GoodsCode,Weight=case when e.Weight is not null then e.Weight else f.Weight end,f.Height,f.Long,f.Width from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配库位 public List GetOrderGoodsPostionList22(string OrderIds) { List list = null; string tsql = @" select c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,OldTypeDesc=b.SKU1 from ( select a.DetailId,b.PostionId,Num=sum(b.KCNum) from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") group by a.DetailId,b.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId order by d.SortNo"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细未匹配库位 public List GetOrderGoodsNoPostionList(string OrderIds) { List list = null; string tsql = @" select a.OrderId,a.OldTypeDesc,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,PostionCode='NO',GoodsNum=a.GoodsNum,c.GoodsId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + OrderIds + @")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetTrackCodeApplyList(string OrderIds) { List list = null; string tsql = @" select a.OrderId,a.TrackCode,b.Weight,a.OrderCode,a.TrackType,ScanDate=b.InDate from DT_TrackCodeApply a with (nolock) left join DT_TrackCodeScan b with (nolock) on a.TrackCode=b.TrackCode and b.OrderId in (" + OrderIds + @") where a.State=1 and a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetTrackCodeApplyList2(string OrderIds) { List list = null; string tsql = @" select a.OrderId,a.TrackCode,a.OrderCode,a.TrackType from DT_TrackCodeApply a where a.State=1 and a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion public List GetOrderGoodsPostionList(string OrderIds) { string query = @" select a.OrderId,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,c.GoodsId,OldTypeDesc=b.SKU1,LockNum=d.SortNo from (select a.OrderId,a.DetailId,b.PostionId,Num=sum(b.KCNum) from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") group by a.OrderId,a.DetailId,b.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderGoods e on a.OrderId=e.OrderId and a.DetailId=e.DetailId inner join CK_StorePostion d on a.PostionId=d.PostionId order by d.SortNo,d.PostionCode"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@OrderIds", DbType.String, OrderIds); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } #region 查询订单跟踪码 public List GetTrackCodeApplyList22(string OrderIds) { List list = null; string tsql = @" select a.OrderId,a.TrackCode,a.OrderCode,a.TrackType,b.Joom from DT_TrackCodeApply a inner join JC_Express b on a.PostId=b.ExpressID where a.State=1 and a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单异常 public List GetErrorList(string OrderIds) { List list = null; string tsql = @" select ErrorInfo=isnull(ErrorInfo,'')+isnull(PostError,''),OrderId from DT_OrderXXInfo where OrderId in (" + OrderIds + ") and (ErrorInfo is not null or PostError is not null)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetOrderTracks(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,LockNum=isnull(a.LockNum,0),a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end,GoodsSKU=case when b.DetailId is not null then b.sku1+'['+b.TypeDesc+']' else a.GoodsSKU end, CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0),OutNum=isnull(a.OutNum,0),a.productImgUrl,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode from DT_OrderGoods a left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,d.* from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存合并订单 public int SaveHBOrder(DT_HBOrder Model, int OldOrderId) { string tsql = @" if @OrderId>0 begin Update [DT_OrderInfo] set [PlatOrderCode]=@PlatOrderCode,[IsJoin]=1,[GoodsName]=@GoodsName,[GoodsNum]=@GoodsNum,[TotalPrice]=@TotalPrice,UpdateDate=getdate() where OrderId=@OrderId end else begin INSERT INTO [DT_OrderInfo](PlatId,[OrderCode],[PlatOrderCode], [IsJoin],[GoodsName],[GoodsNum],[TotalPrice],[InDate],UpdateDate,[InUserId],[OrderLevel],[ShopId],[JoinOrderCode],[OrderName],[GoodsCode],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[MateState],[State],[OrderDate],[SaleUserId],[CompanyId]) select PlatId,[OrderCode]=@PlatOrderCode,[PlatOrderCode]=@PlatOrderCode, [IsJoin]=1,[GoodsName]=@GoodsName,[GoodsNum]=@GoodsNum,[TotalPrice]=@TotalPrice,[InDate],getdate(),[InUserId],[OrderLevel],[ShopId],[JoinOrderCode],[OrderName],[GoodsCode],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[MateState],[State],[OrderDate],[SaleUserId],[CompanyId] from [DT_OrderInfo] where OrderId=@OldOrderId set @OrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[FontTrackCode],[StoreId],[PostInfo]) select [OrderId]=@OrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[FontTrackCode],[StoreId],[PostInfo] from [DT_OrderXXInfo] where [OrderId]=@OldOrderId end select @OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OldOrderId", DbType.Int32, OldOrderId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 新增合并订单 public int SaveAddHBOrder(DT_HBOrder Model) { string tsql = @" Update [DT_OrderInfo] set [GoodsNum]=GoodsNum+@GoodsNum,[TotalPrice]=TotalPrice+@TotalPrice,UpdateDate=getdate() where OrderId=@OrderId select @OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询某条未合并的订单 public List GetNoHBOrder(int CompanyId, string PlatOrderCode, string RevName, string ShopName) { List list = null; string tsql = @" select top 10 a.OrderId,a.OrderLevel,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry,s.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.CompanyId=@CompanyId and a.IsJoin=0 and a.State=1 and (@PlatOrderCode='' or a.PlatOrderCode=@PlatOrderCode) and (@RevName='' or b.RevName like '%'+@RevName+'%' or b.RevAddr like '%'+@RevName+'%') and (@ShopName='' or s.ShopName like '%'+@ShopName+'%') "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, PlatOrderCode); db.AddInParameter(cmd, "@RevName", DbType.String, RevName); db.AddInParameter(cmd, "@ShopName", DbType.String, ShopName); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询某条未合并的订单 public List GetNoHBOrder2(int CompanyId, string PlatOrderCode, string RevName, int ShopId) { List list = null; string tsql = @" select top 10 a.OrderId,a.OrderLevel,a.PlatOrderCode,a.OrderName,a.OrderDate,a.GoodsName,a.TotalPrice,a.MoneyCode,a.GoodsNum,b.RevName,b.RevAddr,b.RevCountry from DT_OrderInfonew a inner join DT_OrderXXInfonew b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and ISNULL(a.IsJoin,0) =0 and a.State=1 and a.MateState=0 and (@PlatOrderCode='' or a.PlatOrderCode=@PlatOrderCode) and (@RevName='' or b.RevName like '%'+@RevName+'%' or b.RevAddr like '%'+@RevName+'%') and (@ShopId=0 or a.shopid=@ShopId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, PlatOrderCode); db.AddInParameter(cmd, "@RevName", DbType.String, RevName); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询合并的订单 public List GetHBOrderList(int OrderId) { List list = null; string tsql = @" select PlatOrderCode from DT_OrderInfo where JoinOrderCode=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询合并的订单 public List GetHBOrderListForTM(int OrderId) { List list = null; string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from OrderId=@OrderId select PlatOrderCode,OrderCode from DT_OrderInfo where JoinOrderCode=@JoinOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存匹配等级 public int SaveLevelConfig(DT_LevelConfig Model) { string tsql = @" if @Id>0 begin Update [DT_LevelConfig] set [CompanyId]=@CompanyId,[SortType]=@SortType,[SortName]=@SortName,[SortNo]=@SortNo,[InUserId]=@InUserId where Id=@Id end else begin INSERT INTO [DT_LevelConfig]([CompanyId],[SortType],[SortName],[SortNo],[InUserId])values(@CompanyId,@SortType,@SortName,@SortNo,@InUserId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@SortType", DbType.Int32, Model.SortType); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SortNo", DbType.Int32, Model.SortNo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询匹配等级 public List GetLevelConfig(int CompanyId, int UserId) { List list = null; string tsql = @" if(select count(0) from DT_LevelConfig where CompanyId=@CompanyId)=0 begin INSERT INTO [DT_LevelConfig]([CompanyId],[SortType],[SortName],[SortNo],[InUserId]) select [CompanyId]=@CompanyId,[SortType],[SortName],[SortNo],[InUserId]=@UserId from DT_LevelConfig where CompanyId=0 end select * from DT_LevelConfig where CompanyId=@CompanyId order by SortNo "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改匹配等级 public void UpdateLevelConfig(int UpId, int DownId) { string tsql = @" update DT_LevelConfig set SortNo=SortNo-1 where Id=@UpId update DT_LevelConfig set SortNo=SortNo+1 where Id=@DownId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UpId", DbType.Int32, UpId); db.AddInParameter(cmd, "@DownId", DbType.Int32, DownId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单物流 public void UpdateOrderExpress(int OrderId, int PostId) { string tsql = @" update DT_OrderXXInfo set Post=@PostId where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印状态 public void UpdatePrint(int OrderId, int PrintState) { string tsql = @" update DT_OrderInfo set PrintState=@PrintState where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PrintState", DbType.Int32, PrintState); db.ExecuteNonQuery(cmd); } #endregion #region 查询拆分的订单 public List GetSpareOrderList(int OrderId) { List list = null; string tsql = @" update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update DT_OrderSpare set PrintState=1 where OrderId=@OrderId select c.Id,a.*,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,TrackCode=c.TrackCode,b.FontTrackCode,b.StoreId,b.Post,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,ShopName=[dbo].[GetShopName](a.ShopId) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderSpare c on a.OrderId=c.OrderId where c.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询拆分的订单 public List GetSpareOrderListNew(int OrderId) { List list = null; string tsql = @" select * from DT_OrderSpare where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回订单Model public DT_OrderModel GetOrderPrintModel(int OrderId) { DT_OrderModel model = null; string tsql = @" --update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId select top 1 a.*,d.ShopName,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,RevCountry=case when c.EnglishName is null then b.RevCountry else c.EnglishName end,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,ShopName=[dbo].[GetShopName](a.ShopId),a.IsSpare from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop d on a.ShopId=d.ShopId left join JC_Country c on b.CountryCode=c.Code where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回订单Model public List GetOrderPrintModelForTM(int OrderId, int PrintType) { List list = null; string tsql = @" declare @IsJoin int,@JoinOrderCode nvarchar(50),@IsJoinAddr int select top 1 @JoinOrderCode=JoinOrderCode,@IsJoin=IsJoin,@IsJoinAddr=IsJoinAddr from DT_OrderInfo where OrderId=@OrderId if @PrintType=0 begin if @IsJoin=1 and @IsJoinAddr>0 begin select a.OrderId,d.ShopName,b.RevName,RevCountry=dbo.GetCountryName(b.CountryCode,b.RevCountry),b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId=@IsJoinAddr end else begin select a.OrderId,d.ShopName,b.RevName,RevCountry=dbo.GetCountryName(b.CountryCode,b.RevCountry),b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId=@OrderId end end else begin select a.OrderId,d.ShopName,b.RevName,RevCountry=dbo.GetCountryName(b.CountryCode,b.RevCountry),b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevPostCode,Post=e.PostId,b.RevProvince,b.RevCity,b.RevArea,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,b.CountryCode,b.CountryName,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderBlank b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType=3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId=@OrderId end if @PrintType=0 begin if @IsJoin=1 begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode and IsJoin=1 end else begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId end end else begin if @IsJoin=1 begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode and IsJoin=1 end else begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) { foreach (var md in list) { md.GoodsList = ds.Tables[1].ToList(); } } return list; } #endregion #region 返回订单Model public List GetOrderPrintListForTM(string OrderIds, int PrintType) { List list = null; string tsql = @" if @PrintType=0 begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") and isnull(a.IsJoin,0)=0 union select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1) select a.Id,a.OrderId,GoodsNum=e.kcnum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=f.PostionCode,bb.TypeCode,a.OldTypeCode,a.OldTypeDesc from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId inner join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId inner join CK_StorePostion f on e.PostionId=f.PostionId where d.OrderId in (" + OrderIds + @") and isnull(d.IsJoin,0)=0 union select a.Id,a.OrderId,GoodsNum=e.kcnum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=f.PostionCode,bb.TypeCode,a.OldTypeCode,a.OldTypeDesc from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId inner join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId inner join CK_StorePostion f on e.PostionId=f.PostionId where d.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1) end else begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevPostCode,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode from DT_OrderInfo a inner join DT_OrderBlank b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType=3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") select a.OrderId,a.GoodsNum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,c.BGPrice,PostionDesc='' from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) { var glist = ds.Tables[1].ToList(); if (glist != null && list != null && list.Count > 0) { foreach (var md in list) { if (md.JoinOrderCode != null && md.JoinOrderCode != "") { var GoodsList = glist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); md.GoodsList = GoodsList; } else { var GoodsList = glist.FindAll(n => n.OrderId == md.OrderId); md.GoodsList = GoodsList; } } } } return list; } #endregion #region 返回订单Model public List GetOrderPrintListForTM2(string OrderIds, int PrintType) { List list = null; string tsql = @" if @PrintType=0 begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") and isnull(a.IsJoin,0)=0 union select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1) select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.OrderId in (" + OrderIds + @") and isnull(d.IsJoin,0)=0 union select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1) end else begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevPostCode,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode from DT_OrderInfo a inner join DT_OrderBlank b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType=3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") select a.OrderId,a.GoodsNum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,c.BGPrice,PostionDesc='',GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) { var glist = ds.Tables[1].ToList(); if (glist != null && list != null && list.Count > 0) { foreach (var md in list) { if (md.JoinOrderCode != null && md.JoinOrderCode != "") { var GoodsList = glist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); md.GoodsList = GoodsList; } else { var GoodsList = glist.FindAll(n => n.OrderId == md.OrderId); md.GoodsList = GoodsList; } } } } return list; } #endregion #region 返回订单Model public List GetOrderPrintListForFedex(string OrderIds, int PrintType) { List list = null; string tsql = @" if @PrintType=0 begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") and isnull(a.IsJoin,0)=0 union select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1) select * from ( select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end,f.SortNo from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.OrderId in (" + OrderIds + @") and isnull(d.IsJoin,0)=0 union select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end,f.SortNo from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1))a order by a.SortNo,a.PostionDesc end else begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevPostCode,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode from DT_OrderInfo a inner join DT_OrderBlank b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType=3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") select a.OrderId,a.GoodsNum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,c.BGPrice,PostionDesc='',GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) { var glist = ds.Tables[1].ToList(); if (glist != null && list != null && list.Count > 0) { foreach (var md in list) { if (md.JoinOrderCode != null && md.JoinOrderCode != "") { var GoodsList = glist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); md.GoodsList = GoodsList; } else { var GoodsList = glist.FindAll(n => n.OrderId == md.OrderId); md.GoodsList = GoodsList; } } } } return list; } #endregion #region 返回订单跟踪码 public List GetOrderTrackTM(string OrderIds) { List list = null; string tsql = @" select a.OrderCode,a.OrderId,b.JoinOrderCode,a.TrackCode,a.TrackCode2 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderCode=b.JoinOrderCode where b.IsJoin=1 and a.TrackType<3 and a.State=1 and b.OrderId in (" + OrderIds + @") union select a.OrderCode,a.OrderId,b.JoinOrderCode,a.TrackCode,a.TrackCode2 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.IsJoin=0 and a.TrackType<3 and a.State=1 and b.OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回国家 public List GetOrderCountry() { List list = null; string tsql = @" select * from JC_Country "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回订单Model public DataTable GetOrderPrintTB(int OrderId) { string tsql = @" --update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId select top 1 a.*,d.ShopName,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,RevCountry=case when c.EnglishName is null then b.RevCountry else c.EnglishName end,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,ShopName=[dbo].[GetShopName](a.ShopId),a.IsSpare from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop d on a.ShopId=d.ShopId left join JC_Country c on b.CountryCode=c.Code where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 修改订单打印 public void UpdateOrderPrint(int OrderId) { string tsql = @" update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set PrintState=1,PrintDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单打印发票 public void UpdateOrderBilPrint(string OrderIds) { string tsql = @" update DT_OrderInfo set BillPrint=1 where OrderId in (" + OrderIds + @") update DT_OrderInfoNew set BillPrint=1 where OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); db.ExecuteNonQuery(cmd); } #endregion #region 修改空包裹打印 public void UpdateBlankOrderPrint(int Id) { string tsql = @" update DT_OrderBlank set State=2,PrintDate=getdate() where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 打印订单Model public void UpdatePrintOrder(int OrderId) { string tsql = @" update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改店铺匹配等级 public void UpdateShopLevel(int ShopId, int LevelGrade) { string tsql = @" update JC_Shop set LevelGrade=@LevelGrade where ShopId=@ShopId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@LevelGrade", DbType.Int32, LevelGrade); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单物流 public void UpdateTrackPost(int PostId, int OrderId) { string tsql = @" update a set a.IsUse=0 from JC_ExpressCode a inner join DT_OrderInfo b on a.CompanyId=b.CompanyId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId and a.ExpressId=c.Post and a.PostCode=c.TrackCode where b.OrderId=@OrderId update a set a.IsUse=0 from JC_ExpressCode a inner join DT_OrderInfo b on a.CompanyId=b.CompanyId inner join DT_OrderSpare c on b.OrderId=c.OrderId and a.ExpressId=c.Post and a.PostCode=c.TrackCode where b.OrderId=@OrderId update DT_OrderXXInfo set Post=@PostId,TrackCode=null where OrderId=@OrderId update DT_OrderSpare set Post=@PostId,TrackCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单物流 public void UpdateTrackPostEbay(int PostId, int OrderId, int logid) { string tsql = @" update a set a.IsUse=0 from JC_ExpressCode a inner join DT_OrderInfo b on a.CompanyId=b.CompanyId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId and a.ExpressId=c.Post and a.PostCode=c.TrackCode where b.OrderId=@OrderId update a set a.IsUse=0 from JC_ExpressCode a inner join DT_OrderInfo b on a.CompanyId=b.CompanyId inner join DT_OrderSpare c on b.OrderId=c.OrderId and a.ExpressId=c.Post and a.PostCode=c.TrackCode where b.OrderId=@OrderId update DT_OrderXXInfo set Post=@PostId,TrackCode=null,LogisticsId=1 where OrderId=@OrderId update DT_OrderSpare set Post=@PostId,TrackCode=null where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单物流 public void UpdateTrackPostForTM(int PostId, int LogisticsId, int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set IsSpare=0 where JoinOrderCode=@JoinOrderCode update DT_TrackCodeApply set State=0,UpdateTime=getdate() where OrderCode=@JoinOrderCode and state=1 and TrackType<3 update a set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set IsSpare=0 where OrderId=@OrderId update DT_TrackCodeApply set State=0,UpdateTime=getdate() where OrderId=@OrderId and state=1 and TrackType<3 update DT_OrderXXInfo set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, LogisticsId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单物流 public void UpdateTrackPostForTM2(int PostId, int LogisticsId, int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_TrackCodeApply set State=0,UpdateTime=getdate() where OrderCode=@JoinOrderCode and state=1 and TrackType<3 update a set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 from DT_OrderXXInfonew a inner join DT_OrderInfonew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update DT_TrackCodeApply set State=0,UpdateTime=getdate() where OrderId=@OrderId and state=1 and TrackType<3 update DT_OrderXXInfo set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,Post=@PostId,TrackCode=null,TrackState=0 where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, LogisticsId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单跟踪码 public void UpdateTrackCode(string TrackCode, int PostId, int OrderId, string PostError) { string tsql = @" update DT_OrderXXInfo set TrackCode=@TrackCode,Post=@PostId,PostError=@PostError where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@PostError", DbType.String, PostError); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单跟踪码错误 public void UpdateTrackCodeError(int OrderId, int PostId, string PostError) { string tsql = @" update DT_OrderXXInfo set PostError=@PostError where OrderId=@OrderId --update DT_OrderInfo set PostState=2 where OrderId=@OrderId --不允许发货 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@PostError", DbType.String, PostError); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单跟踪码错误 public void UpdateTrackCodeError2(int OrderId, int PostId, string PostError) { string tsql = @" update DT_OrderXXInfo set PostError=@PostError where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=@PostError where OrderId=@OrderId --update DT_OrderInfo set PostState=2 where OrderId=@OrderId --不允许发货 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@PostError", DbType.String, PostError); db.ExecuteNonQuery(cmd); } #endregion #region 查询历史销售记录 public DT_HisGoods GetHisOrderGoods(int CompanyId, DateTime? SDate, DateTime? EDate) { DT_HisGoods model = null; string tsql = @" declare @GoodsNum int,@OrderNum int select @OrderNum=count(0) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and b.OrderDate>=@SDate and b.OrderDate<@EDate and b.state=2 select @GoodsNum=isnull(sum(a.goodsnum),0) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and b.OrderDate>=@SDate and b.OrderDate<@EDate and b.state=2 select OrderNum=@OrderNum,GoodsNum=@GoodsNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回订单Model public DT_OrderModel GetOrderModel(int OrderId) { DT_OrderModel model = null; string tsql = @"select a.*, b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.BoxFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,ShopName=[dbo].[GetShopName](a.ShopId),b.CountryCode,b.CountryName,b.PostError,b.SendAddr,b.PostOneCode,b.LogisticsId,b.RevProvinceCode,a.Fee6,a.Fee7,a.Fee8 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回订单Model public List GetOrderModelList(string OrderIds) { List list = null; string tsql = @"select a.OrderId,a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.TotalPrice,a.MoneyCode,b.RevAddr,b.RevMail,b.RevCountry,b.RevPhone,b.RevMoblie,ISNULL(b.RevProvinceCode,b.RevProvince) RevProvince,b.RevPhone,b.CountryCode,b.RevCity,b.RevArea,b.Post,b.RevMail,b.LogisticsId,b.RevName,b.RevPostCode,b.CountryName,a.State,b.CustomID,a.PlatId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回订单Model public List GetOrdernoModel(string PlatOrderCode) { List ListModel = null; ; string tsql = @"select * from DT_OrderInfo where PlatOrderCode=@PlatOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, PlatOrderCode); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回订单Model public List GetjoOrderModel(string JoinOrderCode) { List ListModel = null; string tsql = @"select * from DT_OrderInfo where JoinOrderCode=@JoinOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回订单货物Model public DataTable GetPrintGoodsTB(int OrderId) { List list = null; string tsql = @"select a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 返回订单货物Model public List GetPrintGoodsModel(int OrderId) { List list = null; string tsql = @"select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回订单货物Model public List GetPrintGoodsModelForTM(int OrderId, int PrintType) { List list = null; string tsql = @" declare @IsJoin int,@JoinOrderCode nvarchar(50) select top 1 @JoinOrderCode=JoinOrderCode,@IsJoin=IsJoin from DT_OrderInfo where OrderId=@OrderId if @PrintType=0 begin if @IsJoin=1 begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode and IsJoin=1 end else begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInDetail a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where a1.OrderGoodsId=a.Id and a1.PostionId>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId end end else begin if @IsJoin=1 begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc='' from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.JoinOrderCode=@JoinOrderCode and IsJoin=1 end else begin select a.OrderId,a.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc='' from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回拆分订单货物Model public List GetPrintSpareGoodsModel(int OrderId) { List list = null; string tsql = @"select e.SpareId,e.GoodsNum,a.GoodsPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=(select top 1 b1.PostionDesc from HW_GoodsInList a1 inner join CK_StorePostion b1 on a1.PostionId=b1.PostionId where b1.PostionId>0 and a1.GoodsNum>0 and a1.DetailId=bb.DetailId) from DT_OrderGoods a inner join DT_OrderSpareDetail e on a.Id=e.OrderDetailId inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回订单货物Model public List GetWeightGoodsModel(int OrderId) { List list = null; string tsql = @"select a.GoodsNum,a.GoodsPrice,b.Weight,b.SKU1,b.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回拆分订单货物Model public List GetSparePrintGoodsModel(int SpareId) { List list = null; string tsql = @"select a.GoodsNum,a.GoodsPrice,b.Weight,b.SKU1,b.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,PostionDesc=isnull(d.PostionDesc,'') from DT_OrderSpareDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId left join (select distinct b.PostionCode,b.PostionDesc,a.DetailId from HW_GoodsInList a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join DT_OrderSpareDetail c on a.DetailId=c.DetailId where a.PostionId>0 and c.SpareId=@SpareId)d on a.DetailId=d.DetailId where a.SpareId=@SpareId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SpareId", DbType.Int32, SpareId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回拆分订单货物Model public List GetSpareWeightGoodsModel(int SpareId) { List list = null; string tsql = @"select a.GoodsNum,a.GoodsPrice,b.Weight,b.SKU1,b.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName from DT_OrderSpareDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.SpareId=@SpareId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SpareId", DbType.Int32, SpareId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询匹配明细 public List GetMateGoodsDetail(int Id) { List list = null; string tsql = @" select d.ChaseCode,c.Price,a.LockNum,a.OutNum from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join HW_GoodsInList c on a.InId=c.InId inner join CG_Purchase d on c.ChaseId=d.ChaseId where b.Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public List GetDefaultCountListFromDay(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State>0 and State<3 and PlatId in (" + Ids + @") and CompanyId=@CompanyId and orderDate>=@SDate and orderDate<@EDate group by PlatId,convert(nvarchar(10),OrderDate,120)"; } else { tsql = @"select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and orderDate>=@SDate and orderDate<@EDate group by ShopId,convert(nvarchar(10),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public List GetDefaultCountListFromDay2(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State>0 and State<3 and CompanyId=@CompanyId and orderDate>=@SDate and orderDate<@EDate group by PlatId,convert(nvarchar(10),OrderDate,120)"; } else if (PlatType == 3) { tsql = @"select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(totalprice,moneycode,1)) from DT_OrderInfo where State>0 and State<3 and orderDate>=@SDate and orderDate<@EDate group by ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (PlatType == 4) { tsql = @"select PlatId=0,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(totalprice,moneycode,1)) from DT_OrderInfo where State>0 and State<3 and orderDate>=@SDate and orderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else { tsql = @"select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State>0 and State<3 and orderDate>=@SDate and orderDate<@EDate group by ShopId,convert(nvarchar(10),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public List GetDefaultCountListHWC(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select OrderDate=convert(nvarchar(10),PostDate,120),Num=COUNT(0) from DT_OrderInfo where state=2 and PostState=1 and CompanyId=@CompanyId and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按日期返回货物销量 public List GetGoodsCount(int PlatType, int GoodsId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId=d.GoodsId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=SUM(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where d.GoodsId=@GoodsId and a.orderDate>=@SDate and a.orderDate<@EDate and a.State>0 and a.State<3 group by d.GoodsId,convert(nvarchar(10),a.OrderDate,120)"; } else { tsql = @"select PlatId=b.DetailId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=SUM(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where b.DetailId=@GoodsId and a.orderDate>=@SDate and a.orderDate<@EDate and a.State>0 and a.State<3 group by b.DetailId,convert(nvarchar(10),a.OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按日期返回订单数 public List GetCountListFromDay(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State=2 and PlatId in (" + Ids + @") and CompanyId=@CompanyId and orderDate>=@SDate and orderDate<@EDate group by PlatId,convert(nvarchar(10),OrderDate,120)"; } else { tsql = @"select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and orderDate>=@SDate and orderDate<@EDate group by ShopId,convert(nvarchar(10),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按月返回订单数 public List GetCountListFromMonth(int PlatType, string Ids, string months, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,MonthId=DATEPART(month,orderDate),Num=COUNT(0) from DT_OrderInfo where State=2 and CompanyId=@CompanyId and PlatId in (" + Ids + @") and DATEPART(month,OrderDate) in (" + months + @") group by PlatId,DATEPART(month,orderDate)"; } else { tsql = @"select PlatId=ShopId,MonthId=DATEPART(month,orderDate),Num=COUNT(0) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and DATEPART(month,OrderDate) in (" + months + @") group by ShopId,DATEPART(month,orderDate)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按季度返回订单数 public List GetCountListFromQuarter(int PlatType, string Ids, int SMonth, int EMonth, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,Num=COUNT(0) from DT_OrderInfo where State=2 and CompanyId=@CompanyId and PlatId in (" + Ids + @")and DATEPART(month,OrderDate)>=@SMonth and DATEPART(month,OrderDate)<=@EMonth group by PlatId"; } else { tsql = @"select PlatId=ShopId,Num=COUNT(0) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @")and DATEPART(month,OrderDate)>=@SMonth and DATEPART(month,OrderDate)<=@EMonth group by ShopId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@SMonth", DbType.Int32, SMonth); db.AddInParameter(cmd, "@EMonth", DbType.Int32, EMonth); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按日期返回订单金额 public List GetCountPriceFromDay(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and PlatId in (" + Ids + @") and CompanyId=@CompanyId and orderDate>=@SDate and orderDate<=@EDate group by PlatId,convert(nvarchar(10),OrderDate,120)"; } else { tsql = @"select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and orderDate>=@SDate and orderDate<=@EDate group by ShopId,convert(nvarchar(10),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按月返回订单金额 public List GetCountPriceFromMonth(int PlatType, string Ids, string months, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,MonthId=DATEPART(month,orderDate),Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and CompanyId=@CompanyId and PlatId in (" + Ids + @") and DATEPART(month,OrderDate) in (" + months + @") group by PlatId,DATEPART(month,orderDate)"; } else { tsql = @"select PlatId=ShopId,MonthId==DATEPART(month,orderDate),Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and DATEPART(month,OrderDate) in (" + months + @") group by ShopId,DATEPART(month,orderDate)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按季度返回订单金额 public List GetCountPriceFromQuarter(int PlatType, string Ids, int SMonth, int EMonth, int CompanyId) { string tsql = ""; List list = null; if (PlatType == 1) { tsql = @"select PlatId,Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and CompanyId=@CompanyId and PlatId in (" + Ids + @") and DATEPART(month,OrderDate)>=@SMonth and DATEPART(month,OrderDate)<=@EMonth group by PlatId"; } else { tsql = @"select PlatId=ShopId,Price=SUM(TotalPrice) from DT_OrderInfo where State=2 and ShopId in (" + Ids + @") and DATEPART(month,OrderDate)>=@SMonth and DATEPART(month,OrderDate)<=@EMonth group by ShopId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); db.AddInParameter(cmd, "@SMonth", DbType.Int32, SMonth); db.AddInParameter(cmd, "@EMonth", DbType.Int32, EMonth); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回扫描订单Model public DT_OrderModel GetScanOrderModel(int CompanyId, string OrderCode) { DT_OrderModel model = null; string tsql = @" declare @WeightRate int,@IsSpare int,@OrderId int set @OrderId=0 select @WeightRate=isnull(WeightRate,20) from JC_Company where CompanyId=@CompanyId select top 1 @OrderId=a.OrderId,@IsSpare=isnull(IsSpare,0) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId left join DT_OrderSpare d on a.OrderId=d.OrderId where a.CompanyId=@CompanyId and a.state>0 and a.state<3 and a.PostState<2 and a.MateState=2 and (b.TrackCode=@OrderCode or d.TrackCode=@OrderCode or a.PlatOrderCode=@OrderCode or a.OrderCode=@OrderCode) if @IsSpare=1 begin declare @State int select @State=count(0) from DT_OrderSpare where PostState=0 and OrderId=@OrderId select top 1 State=@State,d.PostState,d.Id,a.IsSpare,a.OrderId,a.PlatOrderCode,b.TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,PostInfo=c.Name,b.CountryCode,WeightRate=@WeightRate from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express c on b.Post=c.ExpressID inner join DT_OrderSpare d on a.OrderId=d.OrderId where a.OrderId=@OrderId and (d.TrackCode=@OrderCode or d.OrderCode=@OrderCode or a.PlatOrderCode=@OrderCode or a.OrderCode=@OrderCode) and d.PostState=0 end else begin select top 1 State=0,a.PostState,Id=0,IsSpare=isnull(a.IsSpare,0),a.OrderId,a.PlatOrderCode,b.TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,PostInfo=c.Name,b.CountryCode,WeightRate=@WeightRate from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express c on b.Post=c.ExpressID where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询未扫描记录缓存 public List GetNoTrackCodeApply() { List list = null; string tsql = @"select top 1000 Id,TrackCode,a.OrderCode,b.JoinOrderCode,a.PostId,b.OrderId,weight= (select isnull(SUM(a.GoodsNum*isnull(c.Weight,0)),0) from DT_OrderGoods a inner join HW_GoodsDetail c on a.DetailId=c.DetailId where a.OrderId=b.OrderId) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and isnull(ScanState,0)=0 and b.PostState=0 order by Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回扫描订单Model public DT_OrderScanModel GetScanOrderModelForTM2(string OrderCode) { DT_OrderScanModel model = null; string tsql = @" declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int set @OrderId=0 select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and TrackCode=@OrderCode order by Id desc if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=0 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and isnull(ScanState,0)=1 and a.OrderCode=@OrderCode order by Id desc end if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and a.OrderCode=@OrderCode order by Id desc end --select @JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=State from DT_OrderInfo --where OrderId=@OrderId if @OrderId>0 and @PrintState=1 and @State>0 and @State<3 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode from DT_OrderGoods a inner join DT_OrderInfo e on a.OrderId=e.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where e.JoinOrderCode=@JoinOrderCode select Id,TrackCode,ScanState=isnull(ScanState,0) from DT_TrackCodeApply where State=1 and OrderCode=@JoinOrderCode end else begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId select a.Id,a.TrackCode,ScanState=isnull(ScanState,0),ScanDate=b.InDate,b.Weight from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.TrackCode=b.TrackCode where a.State=1 and a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model public DT_OrderScanModel GetScanOrderModelForTM3(string OrderCode) { DT_OrderScanModel model = null; string tsql = @" declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int set @OrderId=0 select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and TrackCode=@OrderCode order by Id desc if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=0 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and isnull(ScanState,0)=1 and a.OrderCode=@OrderCode order by Id desc end if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and a.OrderCode=@OrderCode order by Id desc end --select @JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=State from DT_OrderInfo --where OrderId=@OrderId if @OrderId>0 and @PrintState=1 and @State>0 and @State<3 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode from DT_OrderGoods a inner join DT_OrderInfo e on a.OrderId=e.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where e.JoinOrderCode=@JoinOrderCode select Id,TrackCode,ScanState=isnull(ScanState,0) from DT_TrackCodeApply where State=1 and OrderCode=@JoinOrderCode end else begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode,FirstImgUrl=case when c.FirstImgUrl is not null and c.FirstImgUrl<>'' then c.FirstImgUrl else '../images/notp.png' end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId select a.Id,a.TrackCode,ScanState=isnull(ScanState,0),ScanDate=b.InDate,b.Weight from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.TrackCode=b.TrackCode where a.State=1 and a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model public DT_OrderScanModel GetScanOrderModelForTM(int CompanyId, string OrderCode) { DT_OrderScanModel model = null; string tsql = @" declare @WeightRate int,@IsSpare int,@OrderId int,@TrackCode nvarchar(50),@OrderState int,@JoinOrderCode nvarchar(50),@TrackId int set @OrderId=0 set @WeightRate=20 --select @WeightRate=isnull(WeightRate,20) from JC_Company where CompanyId=@CompanyId select top 1 @OrderId=a.OrderId,@TrackCode=b.TrackCode,@OrderState=0,@JoinOrderCode=a.JoinOrderCode,@TrackId=b.Id from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and isnull(b.ScanState,0)=0 and b.State=1 and a.state=1 and a.MateState=2 and a.PostState=0 and a.PrintState=1 and a.MateState=2 and b.TrackCode=@OrderCode and b.TrackType<3 if @OrderId=0 --拆分包裹 begin select top 1 @OrderId=a.OrderId,@TrackCode=b.TrackCode,@OrderState=0,@JoinOrderCode=a.JoinOrderCode,@TrackId=b.Id from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and isnull(b.ScanState,0)=0 and b.State=1 and a.state=2 and a.PrintState=1 and a.MateState=2 and b.TrackCode=@OrderCode and b.TrackType<3 end if @OrderId=0 --扫描订单号 begin select top 1 @OrderId=a.OrderId,@TrackCode=b.TrackCode,@OrderState=0,@JoinOrderCode=a.JoinOrderCode,@TrackId=b.Id from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.State=1 and a.state=1 and isnull(b.ScanState,0)=0 and a.PrintState=1 and a.MateState=2 and (a.PlatOrderCode=@OrderCode or a.OrderCode=@OrderCode or b.OrderCode=@OrderCode or a.JoinOrderCode=@OrderCode) end if @OrderId=0 --重复扫描 begin select top 1 @OrderId=a.OrderId,@TrackCode=b.TrackCode,@OrderState=1,@JoinOrderCode=a.JoinOrderCode,@TrackId=0 from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.State=1 and a.state=2 and a.PrintState=1 and a.MateState=2 and (b.TrackCode=@OrderCode or a.PlatOrderCode=@OrderCode or a.OrderCode=@OrderCode or b.OrderCode=@OrderCode or a.JoinOrderCode=@OrderCode) end if @OrderId>0 begin select a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,PostInfo=c.Name,b.CountryCode,WeightRate=@WeightRate,a.State,a.JoinOrderCode,OrderState=@OrderState,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Express c on b.Post=c.ExpressID inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum from DT_OrderGoods a inner join DT_OrderInfo e on a.OrderId=e.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where e.JoinOrderCode=@JoinOrderCode end else begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); } return model; } #endregion #region 返回扫描订单Model public DT_OrderScanModel GetScanBlankModelForTM(int CompanyId, string OrderCode) { DT_OrderScanModel model = null; string tsql = @" declare @WeightRate int,@IsSpare int,@OrderId int,@TrackCode nvarchar(50),@OrderState int,@JoinOrderCode nvarchar(50),@TrackId int set @OrderId=0 set @WeightRate=20 --select @WeightRate=isnull(WeightRate,20) from JC_Company where CompanyId=@CompanyId select top 1 @OrderId=a.OrderId,@TrackCode=b.TrackCode,@OrderState=2,@TrackId=b.Id from DT_OrderBlank a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.state=2 and b.TrackCode=@OrderCode and b.TrackType=3 if @OrderId>0 begin select a.OrderId,PostState,a.OrderId,d.PlatOrderCode,TrackCode=@TrackCode,TotalWeight=0.0,PostFee=0.0,a.RevName,a.RevCountry,a.RevAddr,a.RevPhone,a.RevPostCode,a.Post,PostInfo=c.Name,a.CountryCode,WeightRate=@WeightRate,a.State,JoinOrderCode='',OrderState=@OrderState,TrackId=@TrackId,a.PrintDate from DT_OrderBlank a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join JC_Express c on a.Post=c.ExpressID where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); } return model; } #endregion #region 验证是否要发票 public int IsCountryFP(string CountryCode) { string tsql = @" select count(0) from JC_Country where (EnglishName=@CountryCode or Code=@CountryCode) and IsFP=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CountryCode", DbType.String, CountryCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 根据sku查询货物 public HW_GoodsSKUModel GetGoodsModelFromSku(int CompanyId, string Sku) { HW_GoodsSKUModel model = null; string tsql = @"select top 1 a.DetailId,a.TypeDesc,b.GoodsName,a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.state=1 and a.sku1=@Sku"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Sku", DbType.String, Sku); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 根据sku查询货物 public List GetGoodsModelFromGoodsCode(int TJ, int CompanyId, string GoodsCode, string TypeCode) { List list = null; string tsql = @" if @TJ=1 and @TypeCode<>'' begin select top 50 a.DetailId,a.TypeCode,a.TypeDesc,a.GoodsId,b.GoodsCode,b.GoodsOldCode,b.GoodsName,a.GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or b.GoodsOldCode=@GoodsCode) and a.TypeCode=@TypeCode order by b.GoodsId,a.TypeCode end else if @TJ=1 and @TypeCode='' begin select top 300 a.DetailId,a.TypeCode,a.TypeDesc,a.GoodsId,b.GoodsCode,b.GoodsOldCode,b.GoodsName,a.GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or b.GoodsOldCode=@GoodsCode) order by b.GoodsId,a.TypeCode end else if @TJ=2 begin select top 300 a.DetailId,a.TypeCode,a.TypeDesc,a.GoodsId,b.GoodsCode,b.GoodsOldCode,b.GoodsName,a.GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.GoodsName like '%'+@GoodsCode+'%' order by b.GoodsId,a.TypeCode end else if @TJ=3 begin select top 300 a.DetailId,a.TypeCode,a.TypeDesc,a.GoodsId,b.GoodsCode,b.GoodsOldCode,b.GoodsName,a.GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (a.SKU1 like '%'+@GoodsCode+'%' or a.SKU2 like '%'+@GoodsCode+'%' or a.SKU3 like '%'+@GoodsCode+'%' or a.SKU4 like '%'+@GoodsCode+'%' or a.SKU5 like '%'+@GoodsCode+'%' or a.SKU6 like '%'+@GoodsCode+'%' or a.SKU7 like '%'+@GoodsCode+'%' or a.SKU8 like '%'+@GoodsCode+'%' or a.SKU9 like '%'+@GoodsCode+'%' or a.SKU10 like '%'+@GoodsCode+'%') order by b.GoodsId,a.TypeCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@TJ", DbType.Int32, TJ); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@TypeCode", DbType.String, TypeCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 根据sku查询货物 public List GetGoodsModelFromSku1(int CompanyId, string Sku) { List list = null; string tsql = @"select top 30 a.detailid,a.sku1,b.GoodsName,a.TypeDesc from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and sku1 like @Sku+'%' order by sku1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Sku", DbType.String, Sku); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 根据sku查询货物 public List GetGoodsModelFromType(int CompanyId, int Type, string Sku) { List list = null; string tsql = ""; if (Type == 1) { tsql = @"select top 30 GoodsName=a.sku1 from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and sku1 like @Sku+'%' order by sku1 "; } else if (Type == 2) { tsql = @"select top 30 GoodsName from ( select distinct GoodsName=GoodsCode from HW_GoodsInfo where CompanyId=@CompanyId and GoodsCode like @Sku+'%')a order by GoodsName"; } else { tsql = @"select top 30 GoodsName from ( select distinct GoodsName from HW_GoodsInfo where CompanyId=@CompanyId and GoodsName like @Sku+'%')a order by GoodsName"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Sku", DbType.String, Sku); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 订单发货 public void UpdateOrderGoods(int OrderId, Decimal Weight, Decimal PostFee) { string tsql = @" update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId update a set a.OutNum=a.LockNum from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update b set b.GoodsLockNum=b.GoodsLockNum-a.LockNum from DT_OrderGoodsOutList a inner join HW_GoodsInList b on a.InId=b.InId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 订单发货 public void UpdateOrderGoodsNew(int OrderId, Decimal Weight, Decimal PostFee) { string tsql = @" update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update [DT_OrderGoods] set OutNum=LockNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 订单发货重复扫描 public void UpdateOrderGoodsAgin(int OrderId, Decimal Weight, Decimal PostFee) { string tsql = @" update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 订单扫描发货 public void UpdateOrderGoodsForTM(int OrderId, Decimal Weight, Decimal PostFee, string JoinOrderCode) { string tsql = @" if @JoinOrderCode<>'' begin select @Weight=sum(Weight),@PostFee=sum(PostFee) from DT_TrackCodeScan where OrderCode=@JoinOrderCode update a set a.TotalWeight=@Weight,a.PostFee=@PostFee from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where JoinOrderCode=@JoinOrderCode --update a set OutNum=LockNum from DT_OrderGoods a --inner join DT_OrderInfo b on a.OrderId=b.OrderId --where b.JoinOrderCode=@JoinOrderCode end else begin select @Weight=sum(Weight),@PostFee=sum(PostFee) from DT_TrackCodeScan where orderid=@orderid update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId --update [DT_OrderGoods] set OutNum=LockNum --where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 空包裹扫描发货 public void UpdateBlankBagForTM(int OrderId, Decimal Weight, Decimal PostFee) { string tsql = @" update DT_OrderBlank set state=3,PostDate=getdate(),Weight=@Weight,PostFee=@PostFee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(购买) public void UpdateBuyOrderGoods(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(购买) public void UpdateBuyOrderGoodsForTM(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(购买) public void UpdateBuyOrderGoodsForTM2(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(发货) public void UpdateDelOrderGoods(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update [DT_OrderGoods] set OutNum=LockNum where OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(发货) public void UpdateDelSpareOrderGoods(int OrderId) { string tsql = @" update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update [DT_OrderGoods] set OutNum=LockNum where OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId update b set b.GoodsLockNum=b.GoodsLockNum-a.LockNum from DT_OrderGoodsOutList a inner join HW_GoodsInList b on a.InId=b.InId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(发货) public void UpdateDelSpareOrderGoodsNew(int OrderId) { string tsql = @" update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update [DT_OrderGoods] set OutNum=LockNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物的订单数量(打印) public void UpdateOrderGoodsForPrint(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId --update [DT_OrderGoods] set OutNum=LockNum --where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印状态(打印) public void UpdateOrderPrintState(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId --update [DT_OrderGoods] set OutNum=LockNum --where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单数量 public void UpdateCancelOrderGoods(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update b set b.OrderGoodsId=0 from [DT_OrderGoods] a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单数量 public void UpdateCancelOrderGoodsForTM(int OrderId, string InName, int CompanyId) { string tsql = @" update b set b.OrderGoodsId=0,CKDetailId=0 from [DT_OrderGoods] a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId=@OrderId update DT_OrderGoods set LockNum=0,OutNum=0 where OrderId=@OrderId INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) select @InName,0,DetailId,getdate(),@OrderId,GoodsNum,0,@CompanyId from DT_OrderGoods where OrderId=@OrderId and DetailId>0 update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InName", DbType.String, InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单数量 public void UpdateCancelOrderGoodsForTM2(int OrderId, string InName, int CompanyId) { string tsql = @" INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) select @InName,0,DetailId,getdate(),@OrderId,GoodsNum,0,@CompanyId from DT_OrderGoods where OrderId=@OrderId and DetailId>0 update b set b.GoodsPlanNum=b.GoodsPlanNum-a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InName", DbType.String, InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 复制订单 public int CopyOrder(int OrderId) { string tsql = @" declare @NewOrderId int INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate]) select [OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate] from DT_OrderInfo where OrderId=@OrderId set @NewOrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[FontTrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[FontTrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr] from DT_OrderXXInfo where OrderId=@OrderId select @NewOrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 复制订单 public int CopyOrderForTM(int OrderId) { string tsql = @" declare @NewOrderId int INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select [OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],0,0,[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],0,0,[logisticsAmount],[escrowFee],0,null,null,null,null,0,[FPDate] from DT_OrderInfo where OrderId=@OrderId set @NewOrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[LogisticsId]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],0,null,IsLeaveWord,LogisticsId from DT_OrderXXInfo where OrderId=@OrderId INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum]) select OrderId=@NewOrderId,[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],0,0,[GoodsSKU],[GoodsName],[PostInfo],0,[productImgUrl],[GoodsDesc],[GoodsCode],0 from DT_OrderGoods where OrderId=@OrderId select @NewOrderId update b set b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@NewOrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 复制订单 public int CopyOrderForTM2(int OrderId) { string tsql = @" declare @NewOrderId int INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select [OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],0,0,[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],0,0,[logisticsAmount],escrowFee=0,0,null,null,null,null,0,[FPDate] from DT_OrderInfo where OrderId=@OrderId set @NewOrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[LogisticsId]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],0,null,0,LogisticsId from DT_OrderXXInfo where OrderId=@OrderId INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select @NewOrderId,[OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],0,0,[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],0,0,[logisticsAmount],escrowFee=0,0,null,null,null,null,0,[FPDate] from DT_OrderInfo where OrderId=@OrderId INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[LogisticsId]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],0,null,0,LogisticsId from DT_OrderXXInfo where OrderId=@OrderId INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum]) select OrderId=@NewOrderId,[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],0,0,[GoodsSKU],[GoodsName],[PostInfo],0,[productImgUrl],[GoodsDesc],[GoodsCode],0 from DT_OrderGoods where OrderId=@OrderId select @NewOrderId update b set b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@NewOrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 判断重复单是否存在 public int CheckCopyOrder(int OrderId) { string tsql = @" SELECT COUNT(*) FROM dbo.DT_OrderInfo WHERE OrderCode=(SELECT 'C'+OrderCode FROM dbo.DT_OrderInfo WHERE OrderId=@OrderId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单 public void UpdateOrderInfo(DT_OrderModel Model, List GoodsList, List DelGoodsList) { string tsql = @" Update [DT_OrderXXInfo] set [TotalWeight]=@TotalWeight,[RevName]=@RevName,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,[SendInfo]=@SendInfo,[ErrorInfo]=@ErrorInfo,[Post]=@Post,[PostFee]=@PostFee,[TrackCode]=@TrackCode,[OrderState]=@OrderState,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName,PostError=null where OrderId=@OrderId Update [DT_OrderInfo] set [OrderLevel]=@OrderLevel,PostState=@PostState,[TotalPrice]=@TotalPrice,[RMBPrice]=dbo.[MoneyChange](TotalPrice,isnull(@MoneyCode,'USD'),CompanyId) where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderLevel", DbType.Int32, Model.OrderLevel); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@RMBPrice", DbType.Decimal, Model.RMBPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@TotalWeight", DbType.Decimal, Model.TotalWeight); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@SendInfo", DbType.String, Model.SendInfo); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@FontTrackCode", DbType.String, Model.FontTrackCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.ExecuteNonQuery(cmd); if (GoodsList != null) { foreach (var md in GoodsList) { string tsql1 = @" if @Id=0 begin INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo]) values(@OrderId,@DetailId,@GoodsNum,@GoodsPrice,@RMBMoney,@MoneyCode,0,null,@GoodsSKU,@GoodsName,null) set @Id=SCOPE_IDENTITY() --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+@GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId where a.DetailId=@DetailId end else begin declare @OldDetailId int,@OldGoodsNum int select @OldDetailId=DetailId,@OldGoodsNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId<>@DetailId or @OldGoodsNum<>@GoodsNum --物品换了或者数量变了 begin if @OldDetailId>0 --减去之前的产品购买 begin update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)-@OldGoodsNum where DetailId=@OldDetailId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-@OldGoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId where a.DetailId=@OldDetailId end --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+@GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId where a.DetailId=@DetailId end Update [DT_OrderGoods] set [DetailId]=@DetailId,[GoodsSKU]=@GoodsSKU,[GoodsName]=@GoodsName,GoodsNum=@GoodsNum where Id=@Id end "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, md.OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, md.GoodsPrice); db.AddInParameter(cmd, "@RMBMoney", DbType.Decimal, md.RMBMoney); db.AddInParameter(cmd, "@MoneyCode", DbType.String, md.MoneyCode); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } if (DelGoodsList != null) { foreach (var md in DelGoodsList) { string tsql1 = @" declare @OldDetailId int,@OldGoodsNum int select @OldDetailId=DetailId,@OldGoodsNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId>0 --减去之前的产品购买 begin update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)-@OldGoodsNum where DetailId=@OldDetailId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-@OldGoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId where a.DetailId=@OldDetailId end delete from [DT_OrderGoods] where Id=@Id "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } } #endregion #region 修改订单 public void UpdateOrderInfoNew(DT_OrderModel Model, List GoodsList, List DelGoodsList) { string tsql = @" Update [DT_OrderXXInfo] set [TotalWeight]=@TotalWeight,[RevName]=@RevName,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,[SendInfo]=@SendInfo,[ErrorInfo]=@ErrorInfo,[Post]=@Post,[PostFee]=@PostFee,[TrackCode]=@TrackCode,[OrderState]=@OrderState,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName,PostError=null where OrderId=@OrderId Update [DT_OrderInfo] set [OrderLevel]=@OrderLevel,PostState=@PostState,[TotalPrice]=@TotalPrice,[RMBPrice]=dbo.[MoneyChange](TotalPrice,isnull(@MoneyCode,'USD'),CompanyId) where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderLevel", DbType.Int32, Model.OrderLevel); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@RMBPrice", DbType.Decimal, Model.RMBPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@TotalWeight", DbType.Decimal, Model.TotalWeight); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@SendInfo", DbType.String, Model.SendInfo); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@FontTrackCode", DbType.String, Model.FontTrackCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.ExecuteNonQuery(cmd); if (GoodsList != null) { foreach (var md in GoodsList) { string tsql1 = @" if @Id=0 begin INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo]) values(@OrderId,@DetailId,@GoodsNum,@GoodsPrice,@RMBMoney,@MoneyCode,0,null,@GoodsSKU,@GoodsName,null) set @Id=SCOPE_IDENTITY() --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end else begin declare @OldDetailId int,@OldGoodsNum int select @OldDetailId=DetailId,@OldGoodsNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId<>@DetailId or @OldGoodsNum<>@GoodsNum --物品换了或者数量变了 begin if @OldDetailId>0 --减去之前的产品购买 begin update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)-@OldGoodsNum where DetailId=@OldDetailId end --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end Update [DT_OrderGoods] set [DetailId]=@DetailId,[GoodsSKU]=@GoodsSKU,[GoodsName]=@GoodsName,GoodsNum=@GoodsNum where Id=@Id end "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, md.OrderId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, md.GoodsPrice); db.AddInParameter(cmd, "@RMBMoney", DbType.Decimal, md.RMBMoney); db.AddInParameter(cmd, "@MoneyCode", DbType.String, md.MoneyCode); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } if (DelGoodsList != null) { foreach (var md in DelGoodsList) { string tsql1 = @" declare @OldDetailId int,@OldGoodsNum int select @OldDetailId=DetailId,@OldGoodsNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId>0 --减去之前的产品购买 begin update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)-@OldGoodsNum where DetailId=@OldDetailId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-@OldGoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId where a.DetailId=@OldDetailId end delete from [DT_OrderGoods] where Id=@Id "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } } #endregion #region 修改订单地址 public void UpdateOrderAddr(DT_OrderModel Model) { string tsql = @" Update [DT_OrderXXInfo] set [RevName]=@RevName,CustomID=@CustomID,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单地址 public void UpdateOrderAddr2(DT_OrderModel Model) { string tsql = @" Update [DT_OrderXXInfo] set [RevName]=@RevName,CustomID=@CustomID,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [RevName]=@RevName,CustomID=@CustomID,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单基本信息 public void UpdateOrderBaseInfo(DT_OrderModel Model) { string tsql = @" if @JoinOrderCode<>'' begin Update DT_OrderInfo set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin Update [DT_OrderInfo] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfo] set [ErrorInfo]=@ErrorInfo where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单基本信息 public void UpdateOrderBaseInfo2(DT_OrderModel Model) { string tsql = @" if @JoinOrderCode<>'' begin Update DT_OrderInfo set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode Update DT_OrderInfoNew set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin Update [DT_OrderInfo] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfo] set [ErrorInfo]=@ErrorInfo where OrderId=@OrderId Update [DT_OrderInfoNew] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [ErrorInfo]=@ErrorInfo where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单基本信息 public void UpdateOrderBaseInfo22(DT_OrderModel Model) { string tsql = @" if @JoinOrderCode<>'' begin Update DT_OrderInfo set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode Update DT_OrderInfoNew set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin Update [DT_OrderInfo] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfo] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId Update [DT_OrderInfoNew] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单基本信息 public void UpdateOrderBaseInfo23(DT_OrderModel Model) { string tsql = @" if @JoinOrderCode<>'' begin Update DT_OrderInfo set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState,IsSyncToWMS=@IsSyncToWMS where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode Update DT_OrderInfoNew set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin Update [DT_OrderInfo] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState,IsSyncToWMS=@IsSyncToWMS where OrderId=@OrderId Update [DT_OrderXXInfo] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId Update [DT_OrderInfoNew] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId end update DT_OrderInfo set escrowFee=@escrowFee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, Model.escrowFee); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@IsSyncToWMS", DbType.Int32, Model.IsSyncToWMS); db.ExecuteNonQuery(cmd); } #endregion #region 按店铺日期统计利润 public DataSet GetDayCountPriceCount(string ShopIds, DateTime? SDate, DateTime? EDate) { string tsql = @" select PostDate=convert(nvarchar(10),PostDate,120),shopid,OrderNum=COUNT(0) from DT_OrderInfo where ShopId in (" + ShopIds + @") and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120),shopid select PostDate=convert(nvarchar(10),PostDate,120),shopid,TotalPrice=sum(dbo.PlatMoneyChange(TotalPrice,moneycode,PlatId,CompanyId)) from DT_OrderInfo where ShopId in (" + ShopIds + @") and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120),shopid select PostDate=convert(nvarchar(10),PostDate,120),shopid,Price=sum(isnull(b.Price,0)) from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where c.ShopId in (" + ShopIds + @") and c.State=2 and c.PostDate>=@SDate and c.PostDate<@EDate group by convert(nvarchar(10),c.PostDate,120),c.shopid select PostDate=convert(nvarchar(10),PostDate,120),shopid,PostPrice=sum(isnull(b.PostFee,0)*ISNULL(e.OffNum,1)/10) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner JOIN dbo.JC_ExpressPost e ON e.ExpressID=b.Post where a.ShopId in (" + ShopIds + @") and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (a.IsJoin=0 or (IsJoinAddr=1 and a.IsJoin=1)) group by convert(nvarchar(10),PostDate,120),shopid select PostDate=convert(nvarchar(10),PostDate,120),shopid,BackMoney=sum(dbo.PlatMoneyChange(b.BackMoney,b.BackMoneyCode,a.PlatId,a.CompanyId)) from DT_OrderInfo a inner join DT_OrderSaleBack b on a.OrderId=b.OrderId and b.SaleType=2 where a.ShopId in (" + ShopIds + @") and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.IsJoin=1 group by convert(nvarchar(10),PostDate,120),shopid select PostDate=convert(nvarchar(10),PostDate,120),shopid,PostFee=sum(isnull(b.PostPrice,0)) from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where c.ShopId in (" + ShopIds + @") and c.State=2 and c.PostDate>=@SDate and c.PostDate<@EDate group by convert(nvarchar(10),c.PostDate,120),c.shopid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); return ds; } #endregion #region 按部门日期统计利润 public DataSet GetDayDeptCountPriceCount(string DeptIds, DateTime? SDate, DateTime? EDate) { string tsql = @" select PostDate=convert(nvarchar(10),PostDate,120),DeptId,OrderNum=COUNT(0) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where b.DeptId in (" + DeptIds + @") and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120),DeptId select PostDate=convert(nvarchar(10),PostDate,120),DeptId,TotalPrice=sum(dbo.PlatMoneyChange(a.TotalPrice,a.moneycode,a.PlatId,a.CompanyId)) from DT_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where DeptId in (" + DeptIds + @") and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120),DeptId select PostDate=convert(nvarchar(10),PostDate,120),DeptId,Price=sum(isnull(b.Price,0)) from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join JC_Shop d on c.ShopId=d.ShopId where DeptId in (" + DeptIds + @") and c.State=2 and c.PostDate>=@SDate and c.PostDate<@EDate group by convert(nvarchar(10),c.PostDate,120),DeptId select PostDate=convert(nvarchar(10),PostDate,120),DeptId,PostPrice=sum(isnull(b.PostFee,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId=c.ShopId where DeptId in (" + DeptIds + @") and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (a.IsJoin=0 or (IsJoinAddr=1 and a.IsJoin=1)) group by convert(nvarchar(10),PostDate,120),DeptId select PostDate=convert(nvarchar(10),PostDate,120),DeptId,BackMoney=sum(dbo.PlatMoneyChange(b.BackMoney,b.BackMoneyCode,a.PlatId,a.CompanyId)) from DT_OrderInfo a inner join DT_OrderSaleBack b on a.OrderId=b.OrderId and b.SaleType=2 inner join JC_Shop c on a.ShopId=c.ShopId where DeptId in (" + DeptIds + @") and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.IsJoin=1 group by convert(nvarchar(10),PostDate,120),DeptId select PostDate=convert(nvarchar(10),PostDate,120),DeptId,PostFee=sum(isnull(b.PostFee,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId=c.ShopId where DeptId in (" + DeptIds + @") and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (a.IsJoin=0 or (IsJoinAddr=1 and a.IsJoin=1)) group by convert(nvarchar(10),PostDate,120),DeptId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); return ds; } #endregion #region 按公司日期统计利润 public DataSet GetDayCompanyCountPriceCount(int CompanyId, DateTime? SDate, DateTime? EDate) { string tsql = @" select PostDate=convert(nvarchar(10),PostDate,120),OrderNum=COUNT(0) from DT_OrderInfo a where a.CompanyId=@CompanyId and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120) select PostDate=convert(nvarchar(10),PostDate,120),TotalPrice=sum(dbo.PlatMoneyChange(a.TotalPrice,a.moneycode,a.PlatId,a.CompanyId)) from DT_OrderInfo a where a.CompanyId=@CompanyId and State=2 and PostDate>=@SDate and PostDate<@EDate group by convert(nvarchar(10),PostDate,120) select PostDate=convert(nvarchar(10),PostDate,120),Price=sum(isnull(b.Price,0)) from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where c.CompanyId=@CompanyId and c.State=2 and c.PostDate>=@SDate and c.PostDate<@EDate group by convert(nvarchar(10),c.PostDate,120) select PostDate=convert(nvarchar(10),PostDate,120),PostPrice=sum(isnull(b.PostFee,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (a.IsJoin=0 or (IsJoinAddr=1 and a.IsJoin=1)) group by convert(nvarchar(10),PostDate,120) select PostDate=convert(nvarchar(10),PostDate,120),BackMoney=sum(dbo.PlatMoneyChange(b.BackMoney,b.BackMoneyCode,a.PlatId,a.CompanyId)) from DT_OrderInfo a inner join DT_OrderSaleBack b on a.OrderId=b.OrderId and b.SaleType=2 where a.CompanyId=@CompanyId and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.IsJoin=1 group by convert(nvarchar(10),PostDate,120) select PostDate=convert(nvarchar(10),PostDate,120),PostFee=sum(isnull(b.PostFee,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (a.IsJoin=0 or (IsJoinAddr=1 and a.IsJoin=1)) group by convert(nvarchar(10),PostDate,120) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); return ds; } #endregion #region 按日期返回利润 public List GetDTPriceFromDay(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate) { List list = null; string tsql = ""; tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),TotalPrice=isnull(sum(a.TotalPrice),0),GoodsFee=isnull(sum(b.GoodsFee),0),PostFee=isnull(sum(b.PostFee),0) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where State=2 and (@PlatId=0 or PlatId=@PlatId) and (@ShopId=0 or ShopId=@ShopId) and orderDate>=@SDate and orderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按月返回订单金额 public List GetDTPriceFromMonth(int PlatId, int ShopId, string months) { string tsql = ""; List list = null; tsql = @"select DayId=DATEPART(month,orderDate),TotalPrice=isnull(sum(a.TotalPrice),0),GoodsFee=isnull(sum(b.GoodsFee),0),PostFee=isnull(sum(b.PostFee),0) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where State=2 and (@PlatId=0 or PlatId=@PlatId) and (@ShopId=0 or ShopId=@ShopId) and DATEPART(month,OrderDate) in (" + months + @") group by DATEPART(month,orderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按季度返回订单金额 public List GetDTPriceFromQuarter(int PlatId, int ShopId, int SMonth, int EMonth) { string tsql = ""; List list = null; tsql = @"select TotalPrice=isnull(sum(a.TotalPrice),0),GoodsFee=isnull(sum(b.GoodsFee),0),PostFee=isnull(sum(b.PostFee),0) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where State=2 and (@PlatId=0 or PlatId=@PlatId) and (@ShopId=0 or ShopId=@ShopId) and DATEPART(month,OrderDate)>=@SMonth and DATEPART(month,OrderDate)<=@EMonth"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SMonth", DbType.Int32, SMonth); db.AddInParameter(cmd, "@EMonth", DbType.Int32, EMonth); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存订单 public int SaveOrder(DT_SaveOrderInfo Model, List GoodsList) { string tsql = @" INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[GoodsNum],[TotalPrice],RMBPrice,[MoneyCode],MoneyState,[PostState],[PrintState],[MateState],[State],[OrderDate],[InDate],[InUserId],[CompanyId],[IsFba],[OrderOutDate]) values(@OrderLevel,@PlatId,@ShopId,@OrderCode,@PlatOrderCode,@GoodsNum,@TotalPrice,dbo.[MoneyChange](@TotalPrice,isnull(@MoneyCode,'USD'),@CompanyId),@MoneyCode,@MoneyState,@PostState,@PrintState,@MateState,@State,@OrderDate,@InDate,@InUserId,@CompanyId,@IsFba,@OrderOutDate) set @OrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[RevName],[RevCountry],[RevAddr],[RevPhone],RevMoblie,[RevMail],[RevPostCode],[ErrorInfo],[BuyRemark],[LeaveWord],[Post],[PostFee],[TrackCode],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],CountryCode,CountryName) values(@OrderId,@TotalWeight,@TotalSoild,@RevName,@RevCountry,@RevAddr,@RevPhone,@RevMoblie,@RevMail,@RevPostCode,@ErrorInfo,@BuyRemark,@LeaveWord,@Post,@PostFee,@TrackCode,@PostInfo,@OrderState,@RevProvince,@RevCity,@RevArea,@CountryCode,@CountryName) select @OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderLevel", DbType.Int32, Model.OrderLevel); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@PrintState", DbType.Int32, Model.PrintState); db.AddInParameter(cmd, "@MateState", DbType.Int32, Model.MateState); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@OrderOutDate", DbType.DateTime, Model.OrderOutDate); db.AddInParameter(cmd, "@TotalWeight", DbType.Decimal, Model.TotalWeight); db.AddInParameter(cmd, "@TotalSoild", DbType.Decimal, Model.TotalSoild); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@BuyRemark", DbType.String, Model.BuyRemark); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (GoodsList != null) { foreach (var md in GoodsList) { string tsql1 = @" INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[LockNum],[GoodsSKU],[GoodsName]) values(@OrderId,@DetailId,@GoodsNum,@GoodsPrice,@LockNum,@GoodsSKU,@GoodsName) set @Id=SCOPE_IDENTITY() --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId --update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+@GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId --where a.DetailId=@DetailId "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, a); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, md.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, md.MoneyCode); db.AddInParameter(cmd, "@LockNum", DbType.Int32, md.LockNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } return a; } #endregion #region 保存订单 public int SaveOrderForTM(DT_SaveOrderInfo Model, List GoodsList) { string tsql = @" declare @trackstate int set @trackstate=0 if @TrackCode is not null and @TrackCode<>'' begin set @trackstate=1 end INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[GoodsNum],[TotalPrice],RMBPrice,[MoneyCode],MoneyState,[PostState],[PrintState],[MateState],[State],[OrderDate],[InDate],[InUserId],[CompanyId],[IsFba],[OrderOutDate]) values(@OrderLevel,@PlatId,@ShopId,@OrderCode,@PlatOrderCode,@GoodsNum,@TotalPrice,dbo.[MoneyChange](@TotalPrice,isnull(@MoneyCode,'USD'),@CompanyId),@MoneyCode,@MoneyState,@PostState,@PrintState,@MateState,@State,@OrderDate,@InDate,@InUserId,@CompanyId,@IsFba,@OrderOutDate) set @OrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[RevName],[RevCountry],[RevAddr],[RevPhone],RevMoblie,[RevMail],[RevPostCode],[ErrorInfo],[BuyRemark],[LeaveWord],[Post],[PostFee],[TrackCode],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],CountryCode,CountryName,trackstate) values(@OrderId,@TotalWeight,@TotalSoild,@RevName,@RevCountry,@RevAddr,@RevPhone,@RevMoblie,@RevMail,@RevPostCode,@ErrorInfo,@BuyRemark,@LeaveWord,@Post,@PostFee,@TrackCode,@PostInfo,@OrderState,@RevProvince,@RevCity,@RevArea,@CountryCode,@CountryName,@trackstate) select @OrderId INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[GoodsNum],[TotalPrice],RMBPrice,[MoneyCode],MoneyState,[PostState],[PrintState],[MateState],[State],[OrderDate],[InDate],[InUserId],[CompanyId],[IsFba],[OrderOutDate]) values(@OrderId,@OrderLevel,@PlatId,@ShopId,@OrderCode,@PlatOrderCode,@GoodsNum,@TotalPrice,dbo.[MoneyChange](@TotalPrice,isnull(@MoneyCode,'USD'),@CompanyId),@MoneyCode,@MoneyState,@PostState,@PrintState,@MateState,@State,@OrderDate,@InDate,@InUserId,@CompanyId,@IsFba,@OrderOutDate) INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[RevName],[RevCountry],[RevAddr],[RevPhone],RevMoblie,[RevMail],[RevPostCode],[ErrorInfo],[BuyRemark],[LeaveWord],[Post],[PostFee],[TrackCode],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],CountryCode,CountryName,trackstate) values(@OrderId,@TotalWeight,@TotalSoild,@RevName,@RevCountry,@RevAddr,@RevPhone,@RevMoblie,@RevMail,@RevPostCode,@ErrorInfo,@BuyRemark,@LeaveWord,@Post,@PostFee,@TrackCode,@PostInfo,@OrderState,@RevProvince,@RevCity,@RevArea,@CountryCode,@CountryName,@trackstate) if @TrackCode is not null and @TrackCode<>'' begin INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode]) values(@Post,2,@TrackCode,null,getdate(),null,@OrderId,1,null,@PlatOrderCode) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderLevel", DbType.Int32, Model.OrderLevel); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@PrintState", DbType.Int32, Model.PrintState); db.AddInParameter(cmd, "@MateState", DbType.Int32, Model.MateState); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@OrderOutDate", DbType.DateTime, Model.OrderOutDate); db.AddInParameter(cmd, "@TotalWeight", DbType.Decimal, Model.TotalWeight); db.AddInParameter(cmd, "@TotalSoild", DbType.Decimal, Model.TotalSoild); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@BuyRemark", DbType.String, Model.BuyRemark); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (GoodsList != null) { foreach (var md in GoodsList) { string tsql1 = @" INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[LockNum],[GoodsSKU],[GoodsName]) values(@OrderId,@DetailId,@GoodsNum,@GoodsPrice,@LockNum,@GoodsSKU,@GoodsName) set @Id=SCOPE_IDENTITY() --修改货物购买数量 update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId update DT_OrderInfo set fpdate=getdate() where OrderId=@OrderId update DT_OrderInfonew set fpdate=getdate() where OrderId=@OrderId --update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+@GoodsNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=a.GoodsId --where a.DetailId=@DetailId "; cmd = db.GetSqlStringCommand(tsql1); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, a); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, md.GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, md.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, md.MoneyCode); db.AddInParameter(cmd, "@LockNum", DbType.Int32, md.LockNum); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, md.GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.ExecuteNonQuery(cmd); } } return a; } #endregion #region 验证订单号 public int IsOrderCode(int CompanyId, string OrderCode) { string tsql = "select count(0) from DT_OrderInfo where CompanyId=@CompanyId and PlatOrderCode=@OrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); int num = Convert.ToInt32(db.ExecuteScalar(cmd)); return num; } #endregion #region 查询要生成跟踪码的订单 public void GetOrderTrackCode() { List list = null; string tsql = @" select a.OrderId,b.Post,a.CompanyId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where State=1 and b.Post>0 and PostState=0 and b.TrackCode is null and DATEDIFF(day,a.OrderDate,getdate())<30"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (list != null) { for (int i = 0; i < list.Count; i++) { GetOrderPostCode(list[i].OrderId.Value, list[i].Post.Value, list[i].CompanyId.Value); } } } #endregion #region 获取物流单号 public string GetOrderPostCode(int OrderId, int PostId, int CompanyId) { var obj = new DD_OrderData(); var companymd = new JC_PostAddress(); var obj1 = new JC_ExpressService(); var obj11 = new BaseService(); var ordermd = obj.GetOrderModel(OrderId); var goodslist = obj.GetOrderGoodsDetailList(OrderId); var md = obj1.GetExpressModel(CompanyId, PostId); if (md != null && md.PostType == 4) //线上发货 { obj.UpdateTrackCode("", PostId, OrderId, ""); return ""; } string ErrorInfo = ""; string PostCode = ""; var obj2 = new BaseService(); if (ordermd.CountryCode == null || ordermd.CountryCode == "") { ErrorInfo = ordermd.PlatOrderCode + "的订单国家代码没对应;"; return ErrorInfo; } if (obj2.IsExpress(CompanyId, PostId, ordermd.RevCountry, ordermd.CountryCode) <= 0) { ErrorInfo = ordermd.PlatOrderCode + "的订单国家不支持该物流发送;"; return ErrorInfo; } if (md != null && ordermd != null) { int AddrId = 0; if (ordermd.SendAddr != null) { AddrId = ordermd.SendAddr.Value; } companymd = obj11.GetAddressModel(AddrId); if (ordermd.RevPostCode == null || ordermd.RevPostCode == "") { ErrorInfo = "邮编没填;"; } else if (ordermd.CountryCode == "US" && ordermd.RevPostCode.Length != 5) { ErrorInfo = "美国邮编位数不对;"; } else if (ordermd.CountryCode == "RU" && ordermd.RevPostCode.Length != 6) { ErrorInfo = "俄罗斯编位数不对;"; } else if (md.PostType == 1) //EUB { if (md.CheckCode != null && md.CheckCode != "" && goodslist != null && goodslist.Count > 0) { if (companymd == null) { ErrorInfo = "发货地址没选择;"; return ErrorInfo; } EubApi eub = new EubApi(); Eub_Order model = new Eub_Order(); model.Orderid = ordermd.PlatOrderCode; if (md.operationtype != null) model.operationtype = md.operationtype.Value; else model.operationtype = 0; //model.operationtype = 0; model.customercode = md.customercode; model.vipcode = md.vipcode; if (md.clcttype != null) model.clcttype = md.clcttype.Value; else model.clcttype = 1; model.pod = false; model.untread = "Returned"; if (goodslist != null && goodslist.Count > 0 && goodslist[0].Solid != null) model.volweight = Convert.ToInt32(goodslist[0].Solid / 6000); else model.volweight = 0; model.startdate = DateTime.Now; model.enddate = DateTime.Now.AddDays(15); model.sku1 = goodslist[0].GoodsSKU; model.printcode = "03"; model.barcode = ordermd.PlatOrderCode; Eub_Person sendmd = new Eub_Person(); sendmd.company = companymd.CompanyEnglishName; sendmd.email = companymd.Email; sendmd.name = companymd.SendEnglishName; sendmd.phone = companymd.Phone; sendmd.province = companymd.province; sendmd.city = companymd.city; sendmd.country = "CN"; sendmd.county = companymd.county; sendmd.street = companymd.EnglishAddress; //"Guangyuan Road 69 (Asia Tiger Park Building 4),Jiangbei District,Ningbo,China"; sendmd.postcode = companymd.PostCode; model.sender = sendmd; Eub_Person revmodel = new Eub_Person(); revmodel.name = ordermd.RevName; revmodel.phone = ordermd.RevPhone; if (ordermd.RevProvince == null || ordermd.RevProvince == "") revmodel.province = ordermd.RevProvince; else revmodel.province = " "; revmodel.county = ordermd.RevArea; revmodel.city = ordermd.RevCity; revmodel.country = ordermd.CountryCode; revmodel.street = ordermd.RevAddr; revmodel.postcode = ordermd.RevPostCode; model.receiver = revmodel; Eub_Person collmodel = new Eub_Person(); collmodel.company = companymd.CompanyName; collmodel.email = companymd.Email; collmodel.name = companymd.SendName; collmodel.phone = companymd.Phone; collmodel.province = companymd.province; collmodel.country = "CN"; collmodel.city = companymd.city; collmodel.county = companymd.county; collmodel.street = companymd.Address; collmodel.postcode = companymd.PostCode; model.collect = collmodel; List ListGoods = new List(); if (goodslist != null) { foreach (var goodsmodel in goodslist) { var ListGoodsmd = new Eub_Goods(); ListGoodsmd.cnname = goodsmodel.GoodsName; if (goodsmodel.GoodsEnglisgName == null || goodsmodel.GoodsEnglisgName == "") ListGoodsmd.enname = goodsmodel.GoodsName; else ListGoodsmd.enname = goodsmodel.GoodsEnglisgName; ListGoodsmd.count = goodsmodel.GoodsNum.Value; ListGoodsmd.unit = "件"; if (goodsmodel.GoodsPrice != null && goodsmodel.GoodsNum != null) ListGoodsmd.delcarevalue = goodsmodel.GoodsPrice.Value * goodsmodel.GoodsNum.Value; if (goodsmodel.Weight != null) ListGoodsmd.weight = goodsmodel.Weight.Value / 1000; ListGoodsmd.origin = "CN"; ListGoodsmd.description = ""; ListGoods.Add(ListGoodsmd); } } model.ListGoods = ListGoods; PostCode = eub.SendGoods(model, md.CheckCode, out ErrorInfo); } if (PostCode == null || PostCode == "") { PostCode = obj1.GetInnerExpressCode(CompanyId, PostId); } } else if (md.PostType == 2) //比利时邮政 { if (md.CheckCode != null && md.CheckCode != "" && goodslist != null && goodslist.Count > 0) { if (companymd == null) { ErrorInfo = "发货地址没选择;"; return ErrorInfo; } BelgiumApi Belgium = new BelgiumApi(); Belgium_Order model = new Belgium_Order(); model.ContractId = 1; model.RecipientZipCode = ordermd.RevPostCode; model.RecipientName = ordermd.RevName; model.RecipientStreet = ordermd.RevAddr; model.OrderNumber = ordermd.PlatOrderCode; model.RecipientCity = ordermd.RevCity; model.RecipientState = ordermd.RevProvince; model.RecipientCountry = ordermd.CountryCode; model.PhoneNumber = ordermd.RevPhone; model.Email = ordermd.RevMail; model.SenderName = companymd.SendEnglishName; model.SenderAddress = companymd.EnglishAddress; List ListGoods = new List(); if (goodslist != null) { foreach (var goodsmodel in goodslist) { var ListGoodsmd = new Belgium_Goods(); ListGoodsmd.Sku = goodsmodel.GoodsSKU; ListGoodsmd.ChineseContentDescription = goodsmodel.GoodsName; ListGoodsmd.ItemContent = goodsmodel.GoodsEnglisgName; ListGoodsmd.ItemCount = goodsmodel.GoodsNum.Value; if (goodsmodel.GoodsPrice != null && goodsmodel.GoodsNum != null) ListGoodsmd.Value = Convert.ToInt32(goodsmodel.GoodsPrice.Value * goodsmodel.GoodsNum.Value); ListGoodsmd.Currency = goodsmodel.MoneyCode; if (goodsmodel.Weight != null) ListGoodsmd.Weight = Convert.ToInt32(goodsmodel.Weight.Value); ListGoods.Add(ListGoodsmd); } } model.Customs = ListGoods; PostCode = Belgium.SendGoods(model, md.CheckCode, out ErrorInfo); } if (PostCode == null || PostCode == "") { PostCode = obj1.GetInnerExpressCode(CompanyId, PostId); } } else if (md.PostType == 3) //顺丰 { if (md.CheckCode != null && md.CheckCode != "" && goodslist != null && goodslist.Count > 0) { if (companymd == null) { ErrorInfo = "发货地址没选择;"; return ErrorInfo; } sfApi sfobj = new sfApi(); sf_Order model = new sf_Order(); if (md.operationtype != null) model.express_type = md.operationtype.Value.ToString(); else model.express_type = "1"; model.d_tel = ordermd.RevPhone; model.d_company = ordermd.RevName; model.d_contact = ordermd.RevName; model.d_address = ordermd.RevAddr; model.orderid = ordermd.PlatOrderCode; model.d_county = ordermd.RevArea; model.d_city = ordermd.RevCity; model.d_post_code = ordermd.RevPostCode; model.d_deliverycode = ordermd.CountryCode; model.d_province = ordermd.RevProvince; model.d_country = ordermd.RevCountry; model.cargo_total_weight = Convert.ToDecimal(0.0052); model.j_tel = companymd.Phone; model.j_company = companymd.CompanyEnglishName; model.j_province = companymd.province;// "zhejiang province"; model.j_city = companymd.city; //"Ningbo"; model.j_county = companymd.county; model.j_contact = companymd.SendEnglishName; model.j_address = companymd.EnglishAddress; model.j_post_code = companymd.PostCode; model.declared_value = ordermd.TotalPrice; model.declared_value_currency = ordermd.MoneyCode; model.parcel_quantity = 1; model.pay_method = 1; model.custid = md.customercode;//"7551878519"; model.cargo_length = 60; model.cargo_width = 60; model.cargo_height = 60; List ListGoods = new List(); if (goodslist != null) { foreach (var goodsmodel in goodslist) { var ListGoodsmd = new sf_Goods(); ListGoodsmd.name = goodsmodel.GoodsSKU; ListGoodsmd.count = goodsmodel.GoodsNum.Value; ListGoodsmd.unit = "piece"; if (goodsmodel.Weight != null) ListGoodsmd.weight = goodsmodel.Weight.Value; if (goodsmodel.GoodsPrice != null) ListGoodsmd.amount = goodsmodel.GoodsPrice.Value; ListGoodsmd.currency = ordermd.MoneyCode; ListGoodsmd.source_area = "China"; ListGoods.Add(ListGoodsmd); } } model.ListGoods = ListGoods; sfobj.UserCode = md.UserCode; sfobj.CheckCode = md.CheckCode; PostCode = sfobj.SendGoods(model, out ErrorInfo); } if (PostCode == null || PostCode == "") { PostCode = obj1.GetInnerExpressCode(CompanyId, PostId); } } else { PostCode = obj1.GetInnerExpressCode(CompanyId, PostId); } } if (PostCode != null && PostCode != "") { obj.UpdateTrackCode(PostCode, PostId, OrderId, ErrorInfo); } else { ErrorInfo += "未获取到跟踪码"; obj.UpdateTrackCodeError(OrderId, PostId, ErrorInfo); } if (PostCode != null && PostCode != "") return ""; else return ordermd.PlatOrderCode + "的订单" + ErrorInfo; } #endregion #region 计算一个月销量 public void MonthOrderGoodsNum() { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("MonthOrderGoodsNum"); db.ExecuteNonQuery(cmd); } #endregion #region 修改发货地址 public void UpdateOrderAddr(int OrderId, int AddrId) { string tsql = @" update DT_OrderXXInfo set SendAddr=@AddrId where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@AddrId", DbType.Int32, AddrId); db.ExecuteNonQuery(cmd); } #endregion #region 修改声明发货状态 public void UpdateOrderTrack(int OrderId) { string tsql = @" update DT_OrderXXInfo set TrackState=1,TrackDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改声明发货状态 public void UpdateOrderTrackForTM(int OrderId) { string tsql = @" update DT_OrderXXInfo set TrackDate=getdate() where OrderId=@OrderId update DT_OrderXXInfoNew set TrackDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改声明发货状态 public void UpdateOrderTrackForCD(string OrderId) { string tsql = @" update DT_OrderXXInfo set TrackDate=getdate() where OrderId in (SELECT OrderId FROM dbo.DT_OrderInfo WHERE PlatOrderCode IN (" + OrderId + @")) update DT_OrderXXInfoNew set TrackDate=getdate() where OrderId in (SELECT OrderId FROM dbo.DT_OrderInfo WHERE PlatOrderCode IN (" + OrderId + @")) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 分拆订单 public List GetOrderSpareList(int OrderId) { string tsql = ""; List list = null; tsql = @"select * from DT_OrderSpare where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存拆分订单 public int SaveOrderSpare(DT_OrderSpare Model) { string tsql = @" if @Id>0 begin Update [DT_OrderSpare] set [OrderCode]=@OrderCode,[OrderId]=@OrderId,[Post]=@Post,[TrackCode]=@TrackCode,[PostFee]=@PostFee,[PostState]=@PostState,[PrintState]=@PrintState where Id=@Id end else begin INSERT INTO [DT_OrderSpare]([OrderCode],[OrderId],[Post],[TrackCode],[PostFee],[PostState],[PrintState])values(@OrderCode,@OrderId,@Post,@TrackCode,@PostFee,@PostState,@PrintState) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@PrintState", DbType.Int32, Model.PrintState); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单拆分状态 public void UpdateOrderSpare(int OrderId, string TrackCode, int Post) { string tsql = @" update DT_OrderInfo set IsSpare=1 where OrderId=@OrderId update DT_OrderXXInfo set TrackCode=@TrackCode,Post=@Post where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Post", DbType.Int32, Post); db.ExecuteNonQuery(cmd); } #endregion #region 取消订单拆分状态 public void CancelOrderSpare(int OrderId) { string tsql = @" update DT_OrderInfo set IsSpare=0 where OrderId=@OrderId delete from DT_OrderSpareDetail where SpareId in (select Id from DT_OrderSpare where OrderId=@OrderId) delete from DT_OrderSpare where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 拆分订单发货 public void UpdateOrderSparePost(int Id, int OrderId, Decimal Weight, Decimal PostFee) { string tsql = @" update DT_OrderSpare set PostState=1,TotalWeight=@Weight,PostFee=@PostFee where Id=@Id update DT_OrderXXInfo set TotalWeight=(select SUM(isnull(TotalWeight,0)) from DT_OrderSpare where OrderId=@OrderId),PostFee=(select SUM(isnull(PostFee,0)) from DT_OrderSpare where OrderId=@OrderId) where orderid=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.ExecuteNonQuery(cmd); } #endregion #region 保存拆分订单明细 public int SaveOrderSpareDetail(DT_OrderSpareDetail Model) { string tsql = @" if @Id>0 begin Update [DT_OrderSpareDetail] set [SpareId]=@SpareId,[OrderDetailId]=@OrderDetailId,[DetailId]=@DetailId,[GoodsNum]=@GoodsNum where Id=@Id end else begin INSERT INTO [DT_OrderSpareDetail]([SpareId],[OrderDetailId],[DetailId],[GoodsNum])values(@SpareId,@OrderDetailId,@DetailId,@GoodsNum) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@SpareId", DbType.Int32, Model.SpareId); db.AddInParameter(cmd, "@OrderDetailId", DbType.Int32, Model.OrderDetailId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改允许发货 public void UpdatePostState(int OrderId) { string tsql = @" update DT_OrderInfo set PostState=0,UpdateDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改设置海外仓 public void UpdateHWC(int OrderId,int IsFBA) { string tsql = @" update DT_OrderInfo set IsFba=@IsFBA,UpdateDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set IsFba=@IsFBA,UpdateDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@IsFBA", DbType.Int32, IsFBA); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印状态 public void UpdatePrintStateNew(int OrderId) { string tsql = @" update DT_OrderInfo set PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null,UpdateDate=getdate() where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0 where OrderId=@OrderId update DT_OrderGoods set OutNum=0 where OrderId=@OrderId update a set a.OutNum=0,a.LockNum=a.OutNum from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update a set a.GoodsNum=a.GoodsNum+c.GoodsNum,a.GoodsPlanNum=a.GoodsPlanNum+c.GoodsNum from HW_GoodsDetail a inner join DT_OrderGoods c on a.DetailId=c.DetailId where c.OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印状态 public void UpdatePrintStateForTM(int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50),@PrintState int select @JoinOrderCode=JoinOrderCode,@PrintState=PrintState from DT_OrderInfo where OrderId=@OrderId if @PrintState=1 begin if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null,UpdateDate=getdate() where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null,UpdateDate=getdate() where JoinOrderCode=@JoinOrderCode update a set a.CKDetailId=0 from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join DT_OrderInfo d on b.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) delete from HW_GoodsOutList where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) if(@PrintState>0) begin update b set b.GoodsNum=b.GoodsNum+a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end end else begin update DT_OrderInfo set PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null,UpdateDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null,UpdateDate=getdate() where OrderId=@OrderId update a set a.CKDetailId=0 from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join DT_OrderInfo d on b.OrderId=d.OrderId where b.OrderId=@OrderId delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList where OrderId=@OrderId) delete from HW_GoodsOutList where OrderId=@OrderId if(@PrintState>0) begin update b set b.GoodsNum=b.GoodsNum+a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId end end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印库存匹配状态 public void UpdatePrintMateStateForTM(int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50),@MateState int,@PrintState int select @JoinOrderCode=JoinOrderCode,@MateState=MateState,@PrintState=PrintState from DT_OrderInfo where OrderId=@OrderId if @MateState>0 begin if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set MateState=0,PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=0,PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null where JoinOrderCode=@JoinOrderCode update a set a.CKDetailId=0,a.OrderGoodsId=0 from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join DT_OrderInfo d on b.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode if @PrintState>0 begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsNum=b.GoodsNum+a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) delete from HW_GoodsOutList where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) end end else begin update DT_OrderInfo set MateState=0,PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null where OrderId=@OrderId update DT_OrderInfoNew set MateState=0,PrintState=0,PrintDate=null,State=1,PostState=0,PostDate=null where OrderId=@OrderId update a set a.CKDetailId=0,a.OrderGoodsId=0 from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join DT_OrderInfo d on b.OrderId=d.OrderId where d.OrderId=@OrderId if @PrintState>0 begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsNum=b.GoodsNum+a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList where OrderId=@OrderId) delete from HW_GoodsOutList where OrderId=@OrderId end end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改取消状态 public void UpdateCancelStateForTM(int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50),@MateState int,@PrintState int select @JoinOrderCode=JoinOrderCode,@MateState=MateState,@PrintState=PrintState from DT_OrderInfo where OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set MateState=0,PrintState=0,PrintDate=null,State=3,PostState=0,PostDate=null,UpdateDate=getdate() where JoinOrderCode=@JoinOrderCode update b set b.PostFee=0,b.TotalWeight=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode update b set b.OutNum=0 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode update a set a.CKDetailId=0,a.OrderGoodsId=0 from HW_GoodsInDetail a inner join HW_GoodsOutDetail b on a.CKDetailId=b.Id inner join HW_GoodsOutList c on b.OutId=c.OutId inner join DT_OrderInfo d on c.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) delete from HW_GoodsOutList where OutId in (select OutId from HW_GoodsOutList a inner join DT_OrderInfo b on a.OrderId=b.OrderId where JoinOrderCode=@JoinOrderCode) if(@MateState>0) begin if(@PrintState>0) begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsNum=b.GoodsNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end else begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum-a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end end end else begin update DT_OrderInfo set MateState=0,PrintState=0,PrintDate=null,State=3,PostState=0,PostDate=null,UpdateDate=getdate() where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0,TotalWeight=0 where OrderId=@OrderId update DT_OrderGoods set OutNum=0 where OrderId=@OrderId update a set a.CKDetailId=0,a.OrderGoodsId=0 from HW_GoodsInDetail a inner join HW_GoodsOutDetail b on a.CKDetailId=b.Id inner join HW_GoodsOutList c on b.OutId=c.OutId where c.OrderId=@OrderId delete from HW_GoodsOutDetail where OutId in (select OutId from HW_GoodsOutList where OrderId=@OrderId) delete from HW_GoodsOutList where OrderId=@OrderId if(@MateState>0) begin if(@PrintState>0) begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsNum=b.GoodsNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId end else begin update b set b.GoodsLockNum=b.GoodsLockNum-a.GoodsNum,b.GoodsPlanNum=b.GoodsPlanNum-a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId end end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改打印状态 public void UpdatePrintState(int OrderId) { string tsql = @" update DT_OrderInfo set PrintState=0,State=1,UpdateDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改发货状态 public void UpdateSendState(int OrderId, int MateState) { string tsql = @" if @MateState=2 begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId end else if @MateState=1 begin update DT_OrderInfo set state=1,poststate=3,PostDate=getdate() where orderid=@OrderId --部分发货 end update a set a.OutNum=a.LockNum from DT_OrderGoodsOutList a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId update b set b.GoodsLockNum=b.GoodsLockNum-a.LockNum from DT_OrderGoodsOutList a inner join HW_GoodsInList b on a.InId=b.InId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OrderId=@OrderId update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update c set c.GoodsPlanNum=(select SUM(isnull(GoodsPlanNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId),c.GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=c.GoodsId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId update DT_OrderGoods set OutNum=LockNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.ExecuteNonQuery(cmd); } #endregion #region 修改发货状态 public void UpdateSendStateNew(int OrderId, int MateState) { string tsql = @" if @MateState=2 begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate() where orderid=@OrderId end else if @MateState=1 begin update DT_OrderInfo set state=1,poststate=3,PostDate=getdate() where orderid=@OrderId --部分发货 end update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0),b.GoodsNum=ISNULL(b.GoodsNum,0)-isnull(a.LockNum,0)+isnull(a.OutNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update DT_OrderGoods set OutNum=LockNum where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.ExecuteNonQuery(cmd); } #endregion #region 结束部分发货订单状态 public void UpdateSendDoneState(int OrderId) { string tsql = @" update DT_OrderInfo set state=2,poststate=3,PostDate=getdate() where orderid=@OrderId update c set c.GoodsPlanNum=c.GoodsPlanNum-b.GoodsNum+ISNULL(b.outnum,0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 结束部分发货订单状态 public void UpdateSendDoneStateNew(int OrderId) { string tsql = @" update DT_OrderInfo set state=2,poststate=3,PostDate=getdate() where orderid=@OrderId update c set c.GoodsPlanNum=c.GoodsPlanNum-b.GoodsNum+ISNULL(b.outnum,0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 导入订单 public int ExcelOrderAdd(DT_ExcelOrderInfo Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelAdd"); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; ExcelOrderGoodsAdd(md); } } return a; } public int ExcelOrderAdd2(DT_ExcelOrderInfo Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelAdd2"); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; ExcelOrderGoodsAdd2(md); } } return a; } #region 分页查询 public List GetListDT_OrderHWC(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.PlatOrderCode,a.JoinOrderCode,a.InDate,a.HGDate,a.TotalPrice,a.MoneyCode,a.RMBPrice,a.GoodsNum,b.RevName,b.RevCountry,b.CountryCode,b.CountryName,b.RevAddr,b.RevMoblie,b.RevPhone,b.RevProvince,b.RevCity,b.RevArea,b.RevMail,b.RevPostCode,HWCStateName=case when a.HWCState=1 then '已上报' when a.HWCState=2 then '上报失败' else '未上报' end,a.HWCMess,a.HWCState,c.ShopName,b.FontTrackCode"; ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion public int ExcelOrderAdd3(DT_ExcelOrderInfo Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelAdd3"); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderName", DbType.String, Model.OrderName); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; ExcelOrderGoodsAdd3(md); } } return a; } public int ExcelOrderAdd4(DT_ExcelOrderInfo Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelAdd3"); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderName", DbType.String, Model.OrderName); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@StoreId", DbType.String, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; ExcelOrderGoodsAdd4(md); } } return a; } public int ExcelOrderAdd5(DT_ExcelOrderInfo Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelAdd3"); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderName", DbType.String, Model.OrderName); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@StoreId", DbType.String, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; ExcelOrderGoodsAdd5(md); } } return a; } #endregion #region 导入订单货物 public void ExcelOrderGoodsAdd(DT_OrderExcelGoods Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelGoodsAdd"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsPrice", DbType.String, Model.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@CompanyId", DbType.String, Model.CompanyId); db.ExecuteNonQuery(cmd); } public void ExcelOrderGoodsAdd2(DT_OrderExcelGoods Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelGoodsAdd2"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsPrice", DbType.String, Model.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@CompanyId", DbType.String, Model.CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.ExecuteNonQuery(cmd); } public void ExcelOrderGoodsAdd3(DT_OrderExcelGoods Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelGoodsAdd3"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsPrice", DbType.String, Model.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@CompanyId", DbType.String, Model.CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.ExecuteNonQuery(cmd); } #endregion #region 导入订单货物 public void ExcelOrderGoodsAdd4(DT_OrderExcelGoods Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelGoodsAdd4"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsPrice", DbType.String, Model.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@CompanyId", DbType.String, Model.CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.ExecuteNonQuery(cmd); } #endregion #region 导入订单货物 public void ExcelOrderGoodsAdd5(DT_OrderExcelGoods Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderExcelGoodsAdd5"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsPrice", DbType.String, Model.GoodsPrice); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@CompanyId", DbType.String, Model.CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单需求数量 public void UpdateOrderGoodsNum() { string tsql = @" update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNum<>b.GoodsNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 暂不采购 public void UpdateOrderNoBuy(int OrderId) { string tsql = @" update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update DT_OrderInfo set NoBuy=1,UpdateDate=getdate() where OrderId=@OrderId --update a set a.OrderGoodsId=0 from HW_GoodsInDetail a --inner join DT_OrderGoods b on a.OrderGoodsId=b.Id --where b.OrderId=@OrderId update DT_OrderGoods set DetailId=0 where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 暂不采购 public int UpdateOrderNoBuyForTM(int OrderId) { string tsql = @" update DT_OrderInfo set FPDate=null where OrderId=@OrderId update DT_OrderInfoNew set FPDate=null where OrderId=@OrderId update b set b.GoodsPlanNum=b.GoodsPlanNum-a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId update DT_OrderGoods set DetailId=0 where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteNonQuery(cmd)); return a; } #endregion #region 恢复采购 public void UpdateOrderBuy(int OrderId, int CompanyId) { string tsql = @" update DT_OrderInfo set NoBuy=0,UpdateDate=getdate() where OrderId=@OrderId declare @OldDetailId int set @OldDetailId=0 if(select count(0) from DT_OrderGoods where OrderId=@OrderId and DetailId>0)>0 begin set @OldDetailId=1 end update DT_OrderGoods set DetailId=dbo.MateSKU(GoodsSKU,@CompanyId) where OrderId=@OrderId if @OldDetailId=0 begin update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)+isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 恢复采购 public int UpdateOrderBuyForTM(int OrderId, int CompanyId) { string tsql = @" update DT_OrderGoods set DetailId=dbo.MateSKUForTM(GoodsSKU,GoodsCode,@CompanyId) where OrderId=@OrderId if(select count(0) from DT_OrderGoods where OrderId=@OrderId and DetailId=0)=0 begin update DT_OrderInfo set NoBuy=0,UpdateDate=getdate() where OrderId=@OrderId update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(b.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId select 1 end else begin update DT_OrderGoods set DetailId=0 where OrderId=@OrderId select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改货物 public void UpdateOrderGoodsSKU(int Id, int OrderId, decimal? GoodsPrice, int GoodsNum, int DetailId, string GoodsSKU, string GoodsName) { string tsql = @" if @Id>0 begin declare @OldDetailId int,@OldNum int select @OldDetailId=isnull(DetailId,0),@OldNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId<>@DetailId --改分配 begin update HW_GoodsDetail set ISNULL(GoodsPlanNum,0)-@OldNum where OldDetailId=@OldDetailId update HW_GoodsDetail set ISNULL(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end else if @OldNum<>@GoodsNum --改数量 begin update HW_GoodsDetail set ISNULL(GoodsPlanNum,0)+@GoodsNum-@OldNum where DetailId=@DetailId end update DT_OrderGoods set productImgUrl=null,GoodsNum=@GoodsNum,DetailId=@DetailId,GoodsSKU=@GoodsSKU,GoodsName=@GoodsName where Id=@Id end else begin INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum]) values(@OrderId,@DetailId,@GoodsNum,@GoodsPrice,null,'USD',0,null,@GoodsSKU,@GoodsName,null,0,null,null,null,0) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, GoodsPrice); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, GoodsName); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物 public void UpdateOrderGoodsSKUForTM(int Id, int CompanyId, string InName, int OrderId, decimal? GoodsPrice, int GoodsNum, int DetailId, string GoodsSKU, string GoodsName, string OldTypeCode, string OldTypeDesc) { string tsql = @" if @Id>0 begin declare @OldDetailId int,@OldNum int select @OldDetailId=isnull(DetailId,0),@OldNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId<>@DetailId --改分配 begin update DT_OrderGoods set productImgUrl=null,GoodsNum=@GoodsNum,DetailId=@DetailId,GoodsSKU=@GoodsSKU,GoodsName=@GoodsName,OldTypeCode=@OldTypeCode,OldTypeDesc=@OldTypeDesc where Id=@Id INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) values(@InName,@DetailId,@OldDetailId,getdate(),@OrderId,@OldNum,@GoodsNum,@CompanyId) update HW_GoodsDetail set GoodsPlanNum=dbo.GetOrderGoodsNum(DetailId) where DetailId=@OldDetailId end else if @OldDetailId=@DetailId and @OldNum<>@GoodsNum --改数量 begin update DT_OrderGoods set GoodsNum=@GoodsNum,OldNum=@OldNum where Id=@Id INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) values(@InName,@DetailId,@OldDetailId,getdate(),@OrderId,@OldNum,@GoodsNum,@CompanyId) end end else begin select top 1 @Id=Id from DT_OrderGoods where OrderId=@OrderId and DetailId=@DetailId if @Id>0 begin update DT_OrderGoods set GoodsNum=GoodsNum+@GoodsNum where Id=@Id end else begin INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum],OldTypeCode,OldTypeDesc) values(@OrderId,@DetailId,@GoodsNum,0,null,@GoodsSKU,@GoodsName,null,0,null,null,null,0,@OldTypeCode,@OldTypeDesc) end end if(select count(0) from DT_OrderGoods where OrderId=@OrderId and DetailId=0)=0 begin update DT_OrderInfo set FPDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set FPDate=getdate() where OrderId=@OrderId end update HW_GoodsDetail set GoodsPlanNum=dbo.GetOrderGoodsNum(DetailId) where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, GoodsPrice); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, GoodsName); db.AddInParameter(cmd, "@InName", DbType.String, InName); db.AddInParameter(cmd, "@OldTypeCode", DbType.String, OldTypeCode); db.AddInParameter(cmd, "@OldTypeDesc", DbType.String, OldTypeDesc); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物 public void UpdateOrderGoodsSKUForTM2(int Id, int CompanyId, string InName, int OrderId, decimal? GoodsPrice, int GoodsNum, int DetailId, string GoodsSKU, string GoodsName, string GoodsCode, string OldTypeCode, string OldTypeDesc) { string tsql = @" if @Id>0 begin declare @OldDetailId int,@OldNum int select @OldDetailId=isnull(DetailId,0),@OldNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId<>@DetailId --改分配 begin update DT_OrderGoods set GoodsNum=@GoodsNum,DetailId=@DetailId,GoodsSKU=@GoodsSKU,GoodsName=@GoodsName,GoodsCode=@GoodsCode,OldTypeCode=@OldTypeCode,OldTypeDesc=@OldTypeDesc where Id=@Id INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) values(@InName,@DetailId,@OldDetailId,getdate(),@OrderId,@OldNum,@GoodsNum,@CompanyId) update HW_GoodsDetail set GoodsPlanNum=isnull(GoodsPlanNum,0)-@OldNum where DetailId=@OldDetailId update HW_GoodsDetail set GoodsPlanNum=isnull(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end else if @OldDetailId=@DetailId and @OldNum<>@GoodsNum --改数量 begin update DT_OrderGoods set GoodsNum=@GoodsNum,OldNum=@OldNum,OldTypeCode=@OldTypeCode,OldTypeDesc=@OldTypeDesc where Id=@Id INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) values(@InName,@DetailId,@OldDetailId,getdate(),@OrderId,@OldNum,@GoodsNum,@CompanyId) update HW_GoodsDetail set GoodsPlanNum=isnull(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end else begin update DT_OrderGoods set OldTypeCode=@OldTypeCode,OldTypeDesc=@OldTypeDesc where Id=@Id end end else begin select top 1 @Id=Id from DT_OrderGoods where OrderId=@OrderId and DetailId=@DetailId if @Id>0 begin update DT_OrderGoods set GoodsNum=GoodsNum+@GoodsNum where Id=@Id end else begin INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum],OldTypeCode,OldTypeDesc) values(@OrderId,@DetailId,@GoodsNum,0,null,@GoodsSKU,@GoodsName,null,0,null,null,0,@GoodsCode,@OldTypeCode,@OldTypeDesc) end update HW_GoodsDetail set GoodsPlanNum=isnull(GoodsPlanNum,0)+@GoodsNum where DetailId=@DetailId end if(select count(0) from DT_OrderGoods where OrderId=@OrderId and DetailId=0)=0 begin update DT_OrderInfo set FPDate=getdate() where OrderId=@OrderId update DT_OrderInfonew set FPDate=getdate() where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, GoodsPrice); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsSKU", DbType.String, GoodsSKU); db.AddInParameter(cmd, "@GoodsName", DbType.String, GoodsName); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@InName", DbType.String, InName); db.AddInParameter(cmd, "@OldTypeCode", DbType.String, OldTypeCode); db.AddInParameter(cmd, "@OldTypeDesc", DbType.String, OldTypeDesc); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单采购时间 public void UpdateOrderBuyDate(int OrderId) { string tsql = @" if(select COUNT(0) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId and b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum>0)>0 begin update DT_OrderInfo set BuyDate=GETDATE(),FPDate=getdate() where OrderId=@OrderId and BuyDate is null end else begin update DT_OrderInfo set BuyDate=null,FpDate=getdate() where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单采购时间 public void UpdateOrderBuyDateForTM(int OrderId, int GoodsNum) { string tsql = @" if(select COUNT(0) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId and b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum>0)>0 begin update DT_OrderInfo set BuyDate=GETDATE(),GoodsNum=@GoodsNum where OrderId=@OrderId and BuyDate is null end else begin update DT_OrderInfo set BuyDate=null,GoodsNum=@GoodsNum where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单采购时间 public void UpdateOrderBuyDateForTM2(int OrderId, int GoodsNum) { string tsql = @" if(select COUNT(0) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId and b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum>0)>0 begin update DT_OrderInfo set BuyDate=GETDATE(),GoodsNum=@GoodsNum where OrderId=@OrderId and BuyDate is null update DT_OrderInfonew set BuyDate=GETDATE(),GoodsNum=@GoodsNum where OrderId=@OrderId and BuyDate is null end else begin update DT_OrderInfo set BuyDate=null,GoodsNum=@GoodsNum where OrderId=@OrderId update DT_OrderInfonew set BuyDate=null,GoodsNum=@GoodsNum where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.ExecuteNonQuery(cmd); } #endregion #region 删除订单货物 public void DeleteOrderGoodsSKU(int Id) { string tsql = @" declare @OldDetailId int,@OldNum int select @OldDetailId=isnull(DetailId,0),@OldNum=GoodsNum from DT_OrderGoods where Id=@Id if @OldDetailId>0 and @OldNum>0 begin update HW_GoodsDetail set GoodsPlanNum=ISNULL(GoodsPlanNum,0)-@OldNum where OldDetailId=@OldDetailId end delete from DT_OrderGoods where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 删除订单货物 public void DeleteOrderGoodsSKUForTM(int Id, int CompanyId, string InName) { string tsql = @" declare @OldDetailId int,@OrderId int,@OldNum int select @OldDetailId=isnull(DetailId,0),@OrderId=OrderId,@OldNum=GoodsNum from DT_OrderGoods where Id=@Id delete from DT_OrderGoods where Id=@Id INSERT INTO [DT_OrderGoodsChange]([InName],[NowDetailId],[OldDetailId],[InDate],[OrderId],[OldNum],[NowNum],[CompanyId]) values(@InName,0,@OldDetailId,getdate(),@OrderId,@OldNum,0,@CompanyId) declare @DId int set @DId=0 select @DId=Id from DT_OrderGoods where DetailId=0 and OrderId=@OrderId if @DId=0 begin update DT_OrderInfoNew set FPDate=getdate() where OrderId=@OrderId and FPDate is null update DT_OrderInfo set FPDate=getdate() where OrderId=@OrderId and FPDate is null end else begin update DT_OrderInfoNew set FPDate=null where OrderId=@OrderId and FPDate is not null update DT_OrderInfo set FPDate=null where OrderId=@OrderId and FPDate is not null end if @OldDetailId>0 begin update HW_GoodsDetail set GoodsPlanNum=dbo.GetOrderGoodsNum(DetailId) where DetailId=@OldDetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@InName", DbType.String, InName); db.ExecuteNonQuery(cmd); } #endregion #region 查询改分配货物 public List GetOrderChangeGoods(int OrderId, int Id) { List list = null; string tsql = @" select a.DetailId,b.TypeCode,b.TypeDesc,GoodsCode=isnull(c.GoodsCode,c.GoodsOldCode) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.DetailId>0 and a.OrderId=@OrderId and (@Id=0 or a.Id=@Id)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询改分配货物提醒 public List GetOrderChangeNotice(int DetailId) { List list = null; string tsql = @" select UserId=a.InUserId from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c on b.GoodsDetailId=c.DetailId where c.DetailId=@DetailId and a.GoodsState<2 and a.State<3 and (c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum)>0 and c.GoodsInNum>0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要订单货物 public List GetOrderGoods(int OrderId, int CompanyId) { List list = null; string tsql = @" select a.Id,b.DetailId,c.GoodsName,c.GoodsCode,GoodsSKU=b.SKU1,b.TypeDesc,a.GoodsNum,OutNum=isnull(a.OutNum,0),LeftOutNum=a.GoodsNum-ISNULL(a.OutNum,0),NowNum=null from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and c.CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要订单对应库存货物 public List GetOrderStoreGoods(int OrderId) { List list = null; string tsql = @" select a.* from HW_GoodsInList a inner join DT_OrderGoods b on a.DetailId=b.DetailId where b.OrderId=@OrderId and a.GoodsNum>0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 利润报表 public List GetOrderSaleMoney(DateTime? SDate, DateTime? EDate, string ShopIds, int CompanyId) { List list = null; string tsql = @" update DT_OrderInfo set RMBPrice=dbo.MoneyChange(TotalPrice,moneycode,CompanyId) where CompanyId=@CompanyId and (RMBPrice=0 or RMBPrice is null) select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,a.RMBPrice,TotalPrice=case when a.PlatId=1 then TotalPrice*0.95 else TotalPrice end,MoneyRate=dbo.MoneyRate(a.moneycode,a.CompanyId),f.OffNum,c.GoodsNum,b.TrackCode,b.TotalWeight,PostFee=b.PostFee*ISNULL(f.OffNum,10)*0.1,b.GoodsFee,FactMoney=case when a.PlatId=1 then dbo.MoneyChange(TotalPrice*0.95,a.moneycode,a.CompanyId)-b.PostFee*ISNULL(f.OffNum,10)*0.1 else dbo.MoneyChange(TotalPrice,a.moneycode,a.CompanyId)-b.PostFee*ISNULL(f.OffNum,10)*0.1 end,b.ErrorInfo,PostName=f.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId left join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=@CompanyId where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.PlatOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 利润报表 public List GetOrderSaleMoneyForTM(DateTime? SDate, DateTime? EDate, string ShopIds, int CompanyId) { List list = null; string tsql = @" --update DT_OrderInfo set RMBPrice=dbo.PlatMoneyChange(TotalPrice,moneycode,PlatId,CompanyId) where CompanyId=@CompanyId and (RMBPrice=0 or RMBPrice is null) select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,RMBPrice=dbo.PlatMoneyChange(a.TotalPrice,a.moneycode,a.PlatId,a.CompanyId),a.TotalPrice,MoneyRate=dbo.PlatMoneyRate(a.moneycode,a.PlatId,a.CompanyId),OffNum=isnull(f.OffNum,10),c.GoodsNum,TrackCode=dbo.getOrderTrackCode(a.OrderId,1),b.TotalWeight,PostFee=b.PostFee*ISNULL(f.OffNum,10)*0.1,b.GoodsFee,FactMoney=0.00,b.ErrorInfo,PostName=f.Name,escrowFee=isnull(dbo.PlatMoneyChange(a.escrowFee,a.moneycode,a.PlatId,a.CompanyId),0),PersonFee=isnull(g.PersonFee,2),a.JoinOrderCode,g.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=@CompanyId inner join jc_shop g on a.shopid=g.shopid where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.JoinOrderCode,a.PlatOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 利润报表 public List GetOrderSaleMoneyForTM2(DateTime? SDate, DateTime? EDate, string ShopIds, string GoodsCode, int CompanyId) { string tsql = ""; List list = null; if (GoodsCode != "") { tsql = @" select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,a.TotalPrice,OffNum=isnull(f.OffNum,10),c.GoodsNum,TrackCode='',b.TotalWeight,b.PostFee,b.GoodsFee,b.ErrorInfo,PostName=f.Name,PersonFee=isnull(g.PersonFee,2),a.JoinOrderCode,g.ShopName,a.MoneyCode,a.PlatId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=@CompanyId inner join jc_shop g on a.shopid=g.shopid where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (e.GoodsCode=@GoodsCode or e.GoodsOldCode=@GoodsCode) and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.JoinOrderCode,a.PlatOrderCode"; } else tsql = @" select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,a.TotalPrice,OffNum=isnull(f.OffNum,10),c.GoodsNum,TrackCode='',b.TotalWeight,b.PostFee,b.GoodsFee,b.ErrorInfo,PostName=f.Name,PersonFee=isnull(g.PersonFee,2),a.JoinOrderCode,g.ShopName,a.MoneyCode,a.PlatId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=@CompanyId inner join jc_shop g on a.shopid=g.shopid where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.JoinOrderCode,a.PlatOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 利润报表 public List GetOrderSaleMoneyForTM3(DateTime? SDate, DateTime? EDate, string ShopIds, string GoodsCode, int CompanyId) { string tsql = ""; List list = null; if (GoodsCode != "") { tsql = @" select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,a.TotalPrice,OffNum=isnull(f.OffNum,10),c.GoodsNum,TrackCode='',b.TotalWeight,b.PostFee,b.GoodsFee,b.ErrorInfo,PostName=f.Name,PersonFee=isnull(g.PersonFee,2),a.JoinOrderCode,g.ShopName,a.MoneyCode,a.PlatId,ZJFee=isnull(h.ZJFee,0.3)*c.GoodsNum,a.BuyDate from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=1 inner join jc_shop g on a.shopid=g.shopid inner join HW_GoodsSort h on e.SortId=h.SortId where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and (e.GoodsCode=@GoodsCode or e.GoodsOldCode=@GoodsCode) and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.JoinOrderCode,a.PlatOrderCode"; } else tsql = @" select c.Id,a.PostDate,a.PlatOrderCode,e.GoodsCode,e.GoodsName,b.CountryName,d.TypeDesc,a.TotalPrice,OffNum=isnull(f.OffNum,10),c.GoodsNum,TrackCode='',b.TotalWeight,b.PostFee,b.GoodsFee,b.ErrorInfo,PostName=f.Name,PersonFee=isnull(g.PersonFee,2),a.JoinOrderCode,g.ShopName,a.MoneyCode,a.PlatId,ZJFee=isnull(h.ZJFee,0.3)*c.GoodsNum,a.BuyDate from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join JC_ExpressPost f on b.Post=f.ExpressID and f.CompanyId=1 inner join jc_shop g on a.shopid=g.shopid inner join HW_GoodsSort h on e.SortId=h.SortId where a.State=2 and a.PostDate>=@SDate and a.PostDate<@EDate and a.ShopId in (" + ShopIds + ") and a.PostState=1 and a.CompanyId=@CompanyId order by a.PostDate,a.JoinOrderCode,a.PlatOrderCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询汇率 public List GetMoneyList(int ShopId) { List list = null; string tsql = @" select a.* from JC_Money a inner join JC_Shop b on a.PlatId=b.PlatType where b.ShopId=@ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetTrackCodeList(string ShopIds, DateTime? SDate, DateTime? EDate) { List list = null; string tsql = @" select b.TrackCode,OrderCode=a.PlatOrderCode,a.JoinOrderCode from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where a.PostState=1 and b.State=1 and a.PostDate>=@SDate and a.PostDate<@EDate and a.ShopId in (" + ShopIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改利润 public void UpdateOrderSale(int Id, decimal? PostFee, decimal? escrowFee, decimal? GNPostFee, decimal? Price) { string tsql = @" if @PostFee>0 begin update b set b.PostFee=@PostFee from DT_OrderGoods a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.Id=@Id end --if @escrowFee>0 --begin --update b set b.escrowFee=@escrowFee from DT_OrderGoods a --inner join DT_OrderInfo b on a.OrderId=b.OrderId --where a.Id=@Id --end if @PostPrice>0 or @Price>0 begin update b set b.PostPrice=@PostPrice,b.Price=@Price from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.Id=@Id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, escrowFee); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, GNPostFee); db.AddInParameter(cmd, "@Price", DbType.Decimal, Price); db.ExecuteNonQuery(cmd); } #endregion #region 采购成本 public List GetBuyMoney(DateTime? SDate, DateTime? EDate, string ShopIds, int CompanyId) { List list = null; string tsql = @" select b.Price,b.PostPrice,Id=a.OrderGoodsId from DT_OrderGoodsOutList a inner join HW_GoodsInList b on a.InId=b.InId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id inner join DT_OrderInfo d on c.OrderId=d.OrderId where d.State=2 and d.PostState=1 and d.CompanyId=@CompanyId and d.PostDate>=@SDate and d.PostDate<@EDate and d.ShopId in (" + ShopIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 采购成本 public List GetBuyMoneyNew(DateTime? SDate, DateTime? EDate, string ShopIds, int CompanyId) { List list = null; string tsql = @" select a.Price,a.PostPrice,Id=a.OrderGoodsId from HW_GoodsInDetail a inner join DT_OrderGoods c on a.OrderGoodsId=c.Id inner join DT_OrderInfo d on c.OrderId=d.OrderId where d.State=2 and d.PostState=1 and d.CompanyId=@CompanyId and d.PostDate>=@SDate and d.PostDate<@EDate and d.ShopId in (" + ShopIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 部分发货货物 public void UpdateOrderPartGoods(int OrderId, decimal GoodsFee, decimal PostFee, List list1, List list2) { //return; string tsql = @" update DT_OrderInfo set MateState=1 where OrderId=@OrderId update DT_OrderXXInfo set GoodsFee=isnull(GoodsFee,0)+@GoodsFee+@PostFee where OrderId=@OrderId "; if (list1 != null) { foreach (var md1 in list1) { tsql += @"update DT_OrderGoods set LockNum=" + md1.OutNum + ",OutNum=" + md1.OutNum + " where Id=" + md1.Id + @" update HW_GoodsDetail set GoodsNum=GoodsNum-" + md1.OutNum + ",GoodsPlanNum=GoodsPlanNum-" + md1.OutNum + " where DetailId=" + md1.DetailId + @" update b set b.GoodsNum=b.GoodsNum-" + md1.OutNum + ",b.GoodsPlanNum=b.GoodsPlanNum-" + md1.OutNum + " from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where DetailId=" + md1.DetailId + ""; } } if (list2 != null) { foreach (var md2 in list2) { tsql += @"INSERT INTO [DT_OrderGoodsOutList]([OrderId],[OrderGoodsId],[LockNum],[InId],[OutNum]) values(" + md2.OrderId + "," + md2.OrderGoodsId + "," + md2.OutNum + "," + md2.InId + "," + md2.OutNum + ") update HW_GoodsInList set GoodsNum=GoodsNum-" + md2.OutNum + ",GoodsLockNum=GoodsLockNum+" + md2.LockNum + " where InId=" + md2.InId + ""; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 统计货物销量 public List GetOrderGoodsNumCount(string SKU, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select c.GoodsName,b.SKU1,b.TypeDesc,a.GoodsNum from ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.State>0 and b.State<3 and b.CompanyId=@CompanyId and b.OrderDate>@SDate and b.OrderDate<@EDate group by a.DetailId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where b.SKU1=@SKU or c.GoodsName=@SKU or c.GoodsCode=@SKU"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改拆分订单跟踪码 public void UpdateSpareOrderTrackCode(int Id, string TrackCode) { string tsql = @" update DT_OrderSpare set TrackCode=@TrackCode where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.ExecuteNonQuery(cmd); } #endregion #region 查询留言 public List GetListDT_Leaveword(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.wordContent,a.orderId,a.isRead,a.senderName,a.senderLoginId,a.receiverLoginId,a.fileUrl,a.wordCreate,a.wordCreateCN,a.wId,a.typeId,a.indate,a.CompanyId,a.isBack,a.ShopId,ShopName=[dbo].[GetShopName](b.ShopId),StateName=case when b.State=1 and PostState=0 then '未发货' when b.State=2 then '已发货' when b.State=3 then '已取消' when b.State=1 and PostState=2 then '不允许发货' end,c.CountryName,readimg=case when a.isRead=1 then '../image/reader.gif' else '../image/unread.gif' end,readstate=case when a.isRead=1 then '已读' else '未读' end,backstate=case when a.isBack=1 then '已回复' else '未回复' end,Oid=b.OrderId"; ser.Tables = @"DT_Leaveword a inner join DT_OrderInfo b on a.orderId=b.PlatOrderCode inner join DT_OrderXXInfo c on b.OrderId=c.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询订单留言 public List GetLeavewordFromOrder(string OrderCode) { List list = null; string tsql = @" select * from DT_Leaveword where OrderId=@OrderCode order by wordCreateCN"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询订单留言 public List GetLeavewordFromOrderNoRead(string OrderCode) { List list = null; string tsql = @" select * from DT_Leaveword where OrderId=@OrderCode and isRead=0 order by wordCreateCN"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 修改订单留言状态 public void UpdateLeavewordState(int Id) { string tsql = @" update DT_Leaveword set isRead=1,readdate=getdate() where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单留言状态 public void UpdateLeavewordStateForOrder(string orderId) { string tsql = @" update DT_Leaveword set isRead=1,readdate=getdate() where orderId=@orderId and isRead=0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderId", DbType.String, orderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单留言回复状态 public void UpdateLeavewordBackState(string orderId) { string tsql = @" update DT_Leaveword set isBack=1,backdate=getdate() where orderId=@orderId and isBack is null"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderId", DbType.String, orderId); db.ExecuteNonQuery(cmd); } #endregion #region 保存物流唯一码 public void UpdateOrderPostOneCode(int OrderId, int PostId, int OId, string PostOneCode, string TrackCode) { string tsql = @"update DT_OrderXXInfo set Post=@PostId,OnlinePostId=@OId,PostOneCode=@PostOneCode,TrackCode=@TrackCode,TrackState=1,TrackDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostOneCode", DbType.String, PostOneCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@OId", DbType.Int32, OId); db.ExecuteNonQuery(cmd); } #endregion #region 保存物流唯一码 public void UpdateOrderPostOneCode2(int OrderId, int PostId, int OId, string PostOneCode) { string tsql = @"update DT_OrderXXInfo set Post=@PostId,OnlinePostId=@OId,PostOneCode=@PostOneCode where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostOneCode", DbType.String, PostOneCode); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@OId", DbType.Int32, OId); db.ExecuteNonQuery(cmd); } #endregion #region 保存物流跟踪码 public void UpdateOrderTrackCode(int OrderId, string TrackCode) { string tsql = @"update DT_OrderXXInfo set TrackCode=@TrackCode,TrackState=1,TrackDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.ExecuteNonQuery(cmd); } #endregion #region 验证物流跟踪码 public int IsTrackCode(int OrderId, string TrackCode) { string tsql = @"select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and State=1 and OrderId<>@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存邮局数据模板 public int SavePostExcelTemp(DT_PostExcelTemp Model) { string tsql = @" if @ExcelId>0 begin Update [DT_PostExcelTemp] set [ExpressId]=@ExpressId,[Pages]=@Pages,[CompanyId]=@CompanyId where ExcelId=@ExcelId end else begin INSERT INTO [DT_PostExcelTemp]([ExpressId],[Pages],[CompanyId])values(@ExpressId,@Pages,@CompanyId) set @ExcelId=SCOPE_IDENTITY() end select @ExcelId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExcelId", DbType.Int32, Model.ExcelId); db.AddInParameter(cmd, "@ExpressId", DbType.Int32, Model.ExpressId); db.AddInParameter(cmd, "@Pages", DbType.Int32, Model.Pages); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存邮局数据模板明细 public int SavePostExcelTempDetail(DT_PostExcelTempDetail Model) { string tsql = @" if @Id>0 begin Update [DT_PostExcelTempDetail] set [ExcelId]=@ExcelId,[PageNo]=@PageNo,[ColName]=@ColName,[ColValue]=@ColValue,[ColData]=@ColData,[SortNo]=@SortNo where Id=@Id end else begin INSERT INTO [DT_PostExcelTempDetail]([ExcelId],[PageNo],[ColName],[ColValue],[ColData],[SortNo])values(@ExcelId,@PageNo,@ColName,@ColValue,@ColData,@SortNo) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ExcelId", DbType.Int32, Model.ExcelId); db.AddInParameter(cmd, "@PageNo", DbType.Int32, Model.PageNo); db.AddInParameter(cmd, "@ColName", DbType.String, Model.ColName); db.AddInParameter(cmd, "@ColValue", DbType.String, Model.ColValue); db.AddInParameter(cmd, "@ColData", DbType.String, Model.ColData); db.AddInParameter(cmd, "@SortNo", DbType.Int32, Model.SortNo); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回Model public DT_PostExcelTemp GetExcelTempModel(int ExpressId) { DT_PostExcelTemp model = null; string tsql = "select * from DT_PostExcelTemp where ExpressId=@ExpressId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExpressId", DbType.Int32, ExpressId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询邮局模板 public List GetPostExcelTemp(int CompanyId) { List list = null; string tsql = @" select a.*,ExpressName=b.Name from DT_PostExcelTemp a inner join JC_Express b on a.ExpressID=b.ExpressID where a.CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询邮局模板明细 public List GetPostExcelTempDetail(int ExpressId) { List list = null; string tsql = @" select * from DT_PostExcelTempDetail a inner join DT_PostExcelTemp b on a.ExcelId=b.ExcelId where b.ExpressId=@ExpressId order by PageNo,SortNo"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExpressId", DbType.Int32, ExpressId); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 删除邮局模板 public void DeletePostExcelTemp(int ExcelId) { string tsql = @" delete from DT_PostExcelTemp where ExcelId=@ExcelId delete from DT_PostExcelTempDetail where ExcelId=@ExcelId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExcelId", DbType.Int32, ExcelId); db.ExecuteNonQuery(cmd); } #endregion #region 删除邮局模板 public void DeleteExcelTempDetail(int ExcelId) { string tsql = @" delete from DT_PostExcelTempDetail where ExcelId=@ExcelId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExcelId", DbType.Int32, ExcelId); db.ExecuteNonQuery(cmd); } #endregion #region 删除邮局模板明细 public void DeletePostExcelTempDetail(int Id) { string tsql = @" delete from DT_PostExcelTempDetail where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 查询邮局模板列 public List GetPostExcelTempRow() { List list = null; string tsql = @" select * from DT_PostExcelRow"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 修改wish订单号 public void UpdateOrderCode(int OrderId, string OrderCode) { string tsql = @" update DT_OrderInfo set OrderCode=@OrderCode where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public void SaveTrackCodeApply(DT_TrackCodeApply Model) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin if @TrackType<3 begin update DT_OrderInfo set IsSpare=@IsSpare where JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1 from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set IsSpare=@IsSpare where JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1 from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end end else begin if @TrackType<3 begin update DT_OrderXXInfo set PostError=null,TrackState=1 where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1 where OrderId=@OrderId end end if @TrackType=3 begin select @Id=Id from DT_TrackCodeApply where OrderId=@OrderId and TrackType=3 update DT_OrderBlank set TrackCode=@TrackCode where OrderId=@OrderId end if @Id>0 begin Update [DT_TrackCodeApply] set [PostId]=@PostId,[TrackType]=@TrackType,[TrackCode]=@TrackCode,[TrackCode2]=@TrackCode2,[GetDate]=@GetDate,[InName]=@InName,[OrderId]=@OrderId,[State]=@State,[UpdateTime]=@UpdateTime,[OrderCode]=@OrderCode ,[SKU]=@SKU, [Weight]=@Weight,[Long]=@Long,[Width]=@Width,[Height]=@Height where Id=@Id end else begin INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode],[SKU], [Weight],[Long],[Width],[Height])values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode,@SKU, @Weight,@Long,@Width,@Height) set @Id=SCOPE_IDENTITY() end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@Weight", DbType.String, Model.Weight.HasValue?Model.Weight.ToString():""); db.AddInParameter(cmd, "@Long", DbType.String, Model.Long); db.AddInParameter(cmd, "@Width", DbType.String, Model.Width); db.AddInParameter(cmd, "@Height", DbType.String, Model.Height); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public void SaveTrackCodeApply2(DT_TrackCodeApply Model) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin if @TrackType<3 begin update DT_OrderInfo set IsSpare=@IsSpare where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set IsSpare=@IsSpare where JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1 from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1 from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end end else begin if @TrackType<3 update DT_OrderInfo set IsSpare=@IsSpare where OrderId=@OrderId update DT_OrderInfoNew set IsSpare=@IsSpare where OrderId=@OrderId update DT_OrderXXInfo set PostError=null,TrackState=1 where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1 where OrderId=@OrderId end if @TrackType=3 begin select @Id=Id from DT_TrackCodeApply where OrderId=@OrderId and TrackType=3 update DT_OrderBlank set TrackCode=@TrackCode where OrderId=@OrderId end if @Id>0 begin Update [DT_TrackCodeApply] set [PostId]=@PostId,[TrackType]=@TrackType,[TrackCode]=@TrackCode,[TrackCode2]=@TrackCode2,[GetDate]=@GetDate,[InName]=@InName,[OrderId]=@OrderId,[State]=@State,[UpdateTime]=@UpdateTime,[OrderCode]=@OrderCode where Id=@Id end else begin INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode])values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode) set @Id=SCOPE_IDENTITY() end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public void SaveTrackCodeApply3(int LogisticsId, int CGPostId, DT_TrackCodeApply Model) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin if @PostError is not null and @PostError<>'' begin update a set a.PostError=@PostError from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.PostError=@PostError from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update a set a.PostError=null,a.TrackState=1,a.LogisticsId=@LogisticsId,a.Post=@CGPostId from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1,a.LogisticsId=@LogisticsId,a.Post=@CGPostId from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end end else begin if @PostError is not null and @PostError<>'' begin update DT_OrderXXInfo set PostError=@PostError where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=@PostError where OrderId=@OrderId end else begin update DT_OrderXXInfo set PostError=null,TrackState=1,LogisticsId=@LogisticsId,Post=@CGPostId where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1,LogisticsId=@LogisticsId,Post=@CGPostId where OrderId=@OrderId end end INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode],LabelUrl)values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode,@LabelUrl) set @Id=SCOPE_IDENTITY() "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, LogisticsId); db.AddInParameter(cmd, "@CGPostId", DbType.Int32, CGPostId); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.AddInParameter(cmd, "@LabelUrl", DbType.String, Model.LabelUrl); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public void SaveTrackCodeApply4(DT_TrackCodeApply Model) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin if @PostError is not null and @PostError<>'' begin update a set a.PostError=@PostError,Post=@PostId from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.PostError=@PostError,Post=@PostId from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update a set a.PostError=null,a.TrackState=1,Post=@PostId from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.PostError=null,a.TrackState=1,Post=@PostId from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end end else begin if @PostError is not null and @PostError<>'' begin update DT_OrderXXInfo set PostError=@PostError,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=@PostError,Post=@PostId where OrderId=@OrderId end else begin update DT_OrderXXInfo set PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId end end INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode])values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode) set @Id=SCOPE_IDENTITY() "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.ExecuteNonQuery(cmd); } #endregion #region 更新异常 public void SaveTrackError(int OrderId, string ErrorInfo) { string tsql = @" UPDATE dbo.DT_OrderXXInfo SET ErrorInfo=@ErrorInfo WHERE OrderId=@OrderId UPDATE dbo.DT_OrderXXInfoNew SET ErrorInfo=@ErrorInfo WHERE OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, ErrorInfo); db.ExecuteNonQuery(cmd); } #endregion #region 保存店铺活动 public int SaveShopActive(DT_ShopActive Model) { string tsql = @" if @Id>0 begin Update [DT_ShopActive] set [ShopId]=@ShopId,[GoodsCode]=@GoodsCode,[GoodsId]=@GoodsId,[ActiveName]=@ActiveName,[Price]=@Price,[StartDate]=@StartDate,[InName]=@InName,[InDate]=@InDate where Id=@Id end else begin INSERT INTO [DT_ShopActive]([ShopId],[GoodsCode],[GoodsId],[ActiveName],[Price],[StartDate],[InName],[InDate])values(@ShopId,@GoodsCode,@GoodsId,@ActiveName,@Price,@StartDate,@InName,@InDate) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ActiveName", DbType.String, Model.ActiveName); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@StartDate", DbType.DateTime, Model.StartDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除店铺活动 public void DeleteShopActive(int Id) { string tsql = @" delete from DT_ShopActive where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询店铺活动 public List GetListDT_ShopActive(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.ShopId,a.GoodsCode,a.GoodsId,a.ActiveName,a.Price,a.StartDate,a.InName,a.InDate,b.ShopName"; ser.Tables = @"DT_ShopActive a inner join jc_shop b on a.ShopId=b.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询订单跟踪码 public List GetOrderTrackCode(int OrderId, string JoinOrderCode) { List list = null; string tsql = @" if @JoinOrderCode<>'' begin select a.*,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,b.Weight,b.PostFee,ScanDate=b.InDate from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode where a.OrderCode=@JoinOrderCode and state=1 and TrackType<3 end else begin select a.*,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,b.Weight,b.PostFee,ScanDate=b.InDate from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode where a.OrderId=@OrderId and state=1 and TrackType<3 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetOrderTrackCode2(int OrderId, string JoinOrderCode) { List list = null; string tsql = @" if @JoinOrderCode<>'' begin select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,b.Weight,b.PostFee,ScanDate=b.InDate from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode where a.OrderCode=@JoinOrderCode and state=1 end else begin select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,b.Weight,b.PostFee,ScanDate=b.InDate from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode where a.OrderId=@OrderId and state=1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List GetTrackCodeScan(int OrderId) { List list = null; string tsql = @" select * from DT_TrackCodeScan where OrderId=@OrderId and state=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 验证跟踪码 public int IsOrderTrackCode(int OrderId, string TrackCode) { string tsql = @" select Num=count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and State=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证跟踪码 public int IsOrderTrackCode(int OrderId) { string tsql = @" select Num=count(0) from DT_TrackCodeApply where OrderId=@OrderId and State=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证跟踪码 public int IsOrderTrackCode2(int OrderId, string JoinOrderCode) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select Num=count(0) from DT_TrackCodeApply where OrderCode=@JoinOrderCode and State=1 and TrackType<3 end else begin select Num=count(0) from DT_TrackCodeApply where OrderId=@OrderId and State=1 and TrackType<3 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 拆分订单 public int UpdateOrderSpare(int OrderId, int IsSpare) { string tsql = @" update DT_OrderInfo set IsSpare=@IsSpare where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, IsSpare); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存订单差评赔款 public int SaveOrderSaleBack(DT_OrderSaleBack Model) { string tsql = @" SELECT @id=Id FROM dbo.DT_OrderSaleBack WHERE OrderId=@OrderId AND SaleType=@SaleType if @Id>0 begin Update [DT_OrderSaleBack] set [OrderId]=@OrderId,[InName]=@InName,[InDate]=@InDate,[BackMoney]=@BackMoney,[BackMoneyCode]=@BackMoneyCode,[BackType]=@BackType,[BackRemark]=@BackRemark,[ImageIds]=@ImageIds,[InUserId]=@InUserId,[BadType]=@BadType,[BadReason]=@BadReason,[ChangeBad]=@ChangeBad,[BackDate]=@BackDate,[BadDate]=@BadDate,[BackReason1]=@BackReason1,[BackReason2]=@BackReason2,[BackReason3]=@BackReason3,[BadRemark]=@BadRemark,GoodsCode=@GoodsCode,GoodsUrl=@GoodsUrl where Id=@Id end else begin INSERT INTO [DT_OrderSaleBack]([OrderId],[InName],[InDate],[BackMoney],[BackMoneyCode],[BackType],[BackRemark],[ImageIds],[InUserId],[BadType],[BadReason],[ChangeBad],[BackDate],[BadDate],[BackReason1],[BackReason2],[BackReason3],[BadRemark],SaleType,GoodsCode,GoodsUrl)values(@OrderId,@InName,@InDate,@BackMoney,@BackMoneyCode,@BackType,@BackRemark,@ImageIds,@InUserId,@BadType,@BadReason,@ChangeBad,@BackDate,@BadDate,@BackReason1,@BackReason2,@BackReason3,@BadRemark,@SaleType,@GoodsCode,@GoodsUrl) set @Id=SCOPE_IDENTITY() if @SaleType=1 begin update DT_OrderInfo set SaleState=2 where OrderId=@OrderId end else begin update DT_OrderInfo set SaleState=3 where OrderId=@OrderId update b set b.BackPrice=@BackMoney,b.MoneyCode4=@BackMoneyCode from DT_OrderInfo a inner join DT_OrderBackMoneyApply b on a.PlatOrderCode=b.OrderCode where a.OrderId=@OrderId end end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@SaleType", DbType.Int32, Model.SaleType); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@BackMoney", DbType.Decimal, Model.BackMoney); db.AddInParameter(cmd, "@BackMoneyCode", DbType.String, Model.BackMoneyCode); db.AddInParameter(cmd, "@BackType", DbType.String, Model.BackType); db.AddInParameter(cmd, "@BackRemark", DbType.String, Model.BackRemark); db.AddInParameter(cmd, "@ImageIds", DbType.String, Model.ImageIds); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@BadType", DbType.String, Model.BadType); db.AddInParameter(cmd, "@BadReason", DbType.String, Model.BadReason); db.AddInParameter(cmd, "@ChangeBad", DbType.String, Model.ChangeBad); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@BadDate", DbType.DateTime, Model.BadDate); db.AddInParameter(cmd, "@BackReason1", DbType.String, Model.BackReason1); db.AddInParameter(cmd, "@BackReason2", DbType.String, Model.BackReason2); db.AddInParameter(cmd, "@BackReason3", DbType.String, Model.BackReason3); db.AddInParameter(cmd, "@BadRemark", DbType.String, Model.BadRemark); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsUrl", DbType.String, Model.GoodsUrl); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回Model public DT_OrderSaleBack GetSaleBackModel(int OrderId, int SaleType) { DT_OrderSaleBack model = null; string tsql = "select top 1 * from DT_OrderSaleBack where OrderId=@OrderId and SaleType=@SaleType"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@SaleType", DbType.Int32, SaleType); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回Model public List GetSaleBackModelList(string OrderIds) { List list = null; string tsql = "select * from DT_OrderBackMoneyApply where OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回扫描记录 public List Get_TrackScanList(int PostId, DateTime? SDate, DateTime? EDate) { List list = null; string tsql = @" select * from DT_TrackCodeScan where isnull(IsSure,0)=0 and PostId=@PostId and (@SDate is null or InDate>=@SDate) and (@EDate is null or InDate<=@EDate) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回扫描记录 public DataTable Get_TrackYesScanList(int PostId, DateTime? SDate, DateTime? EDate) { string tsql = @" select * from DT_TrackCodeScan where IsSure=1 and (@PostId=0 or PostId=@PostId) and (@SDate is null or InDate>=@SDate) and (@EDate is null or InDate<=@EDate) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable ds = db.ExecuteDataTable(cmd); return ds; } #endregion #region 返回扫描记录 public DataTable Get_TrackNoScanList(int PostId, DateTime? SDate, DateTime? EDate) { string tsql = @" select * from DT_TrackCodeScan where isnull(IsSure,0)=0 and (@PostId=0 or PostId=@PostId) and (@SDate is null or InDate>=@SDate) and (@EDate is null or InDate<=@EDate) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable ds = db.ExecuteDataTable(cmd); return ds; } #endregion #region 扫描确认 public int UpdateTrackScanSure(string TrackCode, int UserId) { string tsql = @" declare @Id int,@IsSure int set @Id=0 select top 1 @Id=Id,@IsSure=IsSure from DT_TrackCodeScan where TrackCode=@TrackCode if @Id=0 begin select top 1 @Id=Id from DT_TrackCodeScan where OrderCode=@TrackCode end if @Id>0 begin Update [DT_TrackCodeScan] set [IsSure]=1,[SureDate]=getdate(),[SureUserId]=@SureUserId where Id=@Id end select @Id if @IsSure=1 begin select -1 end else begin select Id=@Id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, UserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回空包裹Model public DT_OrderBlank GetOrderBlankModel(int Id) { DT_OrderBlank model = null; string tsql = "select a.Id,a.OrderId,a.InName,a.InDate,a.State,a.RevName,a.RevCountry,a.RevAddr,a.RevPhone,a.RevMoblie,a.RevPostCode,a.PrintDate,a.PostDate,a.RevProvince,a.RevCity,a.RevArea,a.CountryName,a.RevMail,a.CountryCode,a.LogisticsId,a.Post,a.TrackCode,b.PlatOrderCode,b.OrderDate,OrderInDate=b.InDate,b.OrderId,ShopName=[dbo].[GetShopName](b.ShopId) from DT_OrderBlank a inner join DT_OrderInfo b on a.OrderId=b.OrderId where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 删除空包裹 public void DeleteBlankOrder(int Id) { string tsql = @" delete from DT_OrderBlank where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 保存空包裹 public int SaveOrderBlank(DT_OrderBlank Model) { string tsql = @" if @Id>0 begin Update [DT_OrderBlank] set [OrderId]=@OrderId,[RevName]=@RevName,[RevCountry]=@RevCountry,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,[RevProvince]=@RevProvince,[RevCity]=@RevCity,[RevArea]=@RevArea,[CountryName]=@CountryName,[RevMail]=@RevMail,[CountryCode]=@CountryCode,[LogisticsId]=@LogisticsId,[Post]=@Post,[TrackCode]=@TrackCode where Id=@Id if(select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and TrackType=3)=0 --不存在 begin update DT_TrackCodeApply set state=0 where TrackType=3 and OrderId=@OrderId INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode]) values(@Post,3,@TrackCode,null,getdate(),@InName,@OrderId,1,null,@PlatOrderCode) end end else begin if @TrackCode<>'' and (select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and TrackType<3)>0 --已给订单用 begin update DT_TrackCodeApply set OrderId=@OrderId,TrackType=3 where TrackCode=@TrackCode and TrackType<3 update a set a.TrackState=0 from DT_OrderXXInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where b.TrackCode=@TrackCode update a set a.TrackState=0 from DT_OrderXXInfonew a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId where b.TrackCode=@TrackCode end else if @TrackCode<>'' begin INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode]) values(@Post,3,@TrackCode,null,getdate(),@InName,@OrderId,1,null,@PlatOrderCode) end INSERT INTO [DT_OrderBlank]([OrderId],[InName],[InDate],[State],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevPostCode],[PrintDate],[PostDate],[RevProvince],[RevCity],[RevArea],[CountryName],[RevMail],[CountryCode],[LogisticsId],[Post],[TrackCode])values(@OrderId,@InName,@InDate,@State,@RevName,@RevCountry,@RevAddr,@RevPhone,@RevMoblie,@RevPostCode,@PrintDate,@PostDate,@RevProvince,@RevCity,@RevArea,@CountryName,@RevMail,@CountryCode,@LogisticsId,@Post,@TrackCode) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@PrintDate", DbType.DateTime, Model.PrintDate); db.AddInParameter(cmd, "@PostDate", DbType.DateTime, Model.PostDate); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, Model.LogisticsId); db.AddInParameter(cmd, "@Post", DbType.Int32, Model.Post); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存订单扫描记录 public int SaveTrackCodeScan(DT_TrackCodeScan Model) { string tsql = @" select top 1 @Id=Id from DT_TrackCodeScan where TrackCode=@TrackCode if @TrackId>0 begin update DT_TrackCodeApply set ScanState=1 where Id=@TrackId end if @Id>0 begin Update [DT_TrackCodeScan] set [PostId]=@PostId,[TrackCode]=@TrackCode,[InDate]=@InDate,[InName]=@InName,[OrderCode]=@OrderCode,[OrderId]=@OrderId,[BagUserId]=@BagUserId,[Weight]=@Weight,[PostFee]=@PostFee,OldPostFee=@OldPostFee,[ScanUserId]=@ScanUserId,Count=isnull(Count,0)+1 where Id=@Id end else begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[Weight],[PostFee],[IsSure],[SureDate],[SureUserId],[ScanUserId],OldPostFee,Count)values(@PostId,@TrackCode,@InDate,@InName,@OrderCode,@OrderId,@BagUserId,@Weight,@PostFee,@IsSure,@SureDate,@SureUserId,@ScanUserId,@OldPostFee,@Count) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, Model.BagUserId); db.AddInParameter(cmd, "@Weight", DbType.Int32, Model.Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, Model.OldPostFee); db.AddInParameter(cmd, "@Count", DbType.Int32, Model.Count); db.AddInParameter(cmd, "@IsSure", DbType.Int32, Model.IsSure); db.AddInParameter(cmd, "@SureDate", DbType.DateTime, Model.SureDate); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@TrackId", DbType.Int32, Model.TrackId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存订单扫描记录 public void SaveTrackCodeScan2(DT_TrackCodeScan Model) { string tsql = @" select top 1 @Id=Id from DT_TrackCodeScan where TrackCode=@TrackCode if @TrackId>0 begin update DT_TrackCodeApply set ScanState=1 where Id=@TrackId end if @Id>0 begin Update [DT_TrackCodeScan] set [PostId]=@PostId,[TrackCode]=@TrackCode,[InDate]=@InDate,[InName]=@InName,[OrderCode]=@OrderCode,[OrderId]=@OrderId,[BagUserId]=@BagUserId,[Weight]=@Weight,[PostFee]=@PostFee,OldPostFee=@OldPostFee,[ScanUserId]=@ScanUserId,Count=isnull(Count,0)+1 where Id=@Id end else begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[Weight],[PostFee],[IsSure],[SureDate],[SureUserId],[ScanUserId],OldPostFee,Count)values(@PostId,@TrackCode,@InDate,@InName,@OrderCode,@OrderId,@BagUserId,@Weight,@PostFee,@IsSure,@SureDate,@SureUserId,@ScanUserId,@OldPostFee,@Count) end if @JoinOrderCode<>'' begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end update a set a.TotalWeight=@Weight,a.PostFee=@PostFee from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, Model.BagUserId); db.AddInParameter(cmd, "@Weight", DbType.Int32, Model.Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, Model.OldPostFee); db.AddInParameter(cmd, "@Count", DbType.Int32, Model.Count); db.AddInParameter(cmd, "@IsSure", DbType.Int32, Model.IsSure); db.AddInParameter(cmd, "@SureDate", DbType.DateTime, Model.SureDate); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@TrackId", DbType.Int32, Model.TrackId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@IsCSM", DbType.String, Model.IsCSM); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单扫描记录 public void SaveTrackCodeScan3(DT_TrackCodeScan Model) { string tsql = @" select top 1 @Id=Id from DT_TrackCodeScan where TrackCode=@TrackCode if @TrackId>0 begin update DT_TrackCodeApply set ScanState=1 where Id=@TrackId end if @Id>0 begin Update [DT_TrackCodeScan] set [PostId]=@PostId,[TrackCode]=@TrackCode,[InDate]=@InDate,[InName]=@InName,[OrderCode]=@OrderCode,[OrderId]=@OrderId,[BagUserId]=@BagUserId,[Weight]=@Weight,[PostFee]=@PostFee,OldPostFee=@OldPostFee,[ScanUserId]=@ScanUserId,Count=isnull(Count,0)+1 where Id=@Id end else begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[Weight],[PostFee],[IsSure],[SureDate],[SureUserId],[ScanUserId],OldPostFee,Count)values(@PostId,@TrackCode,@InDate,@InName,@OrderCode,@OrderId,@BagUserId,@Weight,@PostFee,@IsSure,@SureDate,@SureUserId,@ScanUserId,@OldPostFee,@Count) set @Id=SCOPE_IDENTITY() end update DT_OrderBlank set state=3,PostDate=getdate(),Weight=@Weight,PostFee=@PostFee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, Model.BagUserId); db.AddInParameter(cmd, "@Weight", DbType.Int32, Model.Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, Model.OldPostFee); db.AddInParameter(cmd, "@Count", DbType.Int32, Model.Count); db.AddInParameter(cmd, "@IsSure", DbType.Int32, Model.IsSure); db.AddInParameter(cmd, "@SureDate", DbType.DateTime, Model.SureDate); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@TrackId", DbType.Int32, Model.TrackId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@IsCSM", DbType.String, Model.IsCSM); db.ExecuteNonQuery(cmd); } #endregion #region 查询退件订单 public List Get_TrackBackList(string Code, int DHType) { List list = null; string tsql = @" declare @OrderId int,@JoinOrderCode nvarchar(50) set @OrderId=0 if @DHType=1 begin select top 1 @OrderId=a.OrderId,@JoinOrderCode=b.JoinOrderCode from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.TrackCode=@Code and a.state=1 if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select TrackCode,TrackCode2,OrderId,JoinOrderCode=@JoinOrderCode from DT_TrackCodeApply where state=1 and TrackType<3 and OrderCode=@JoinOrderCode end else begin select TrackCode,TrackCode2,OrderId,JoinOrderCode=@JoinOrderCode from DT_TrackCodeApply where state=1 and TrackType<3 and OrderId=@OrderId end end else begin select top 1 @OrderId=a.OrderId,@JoinOrderCode=b.JoinOrderCode from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.state=2 and a.state=1 and (b.PlatOrderCode=@Code or a.OrderCode=@Code) if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select OrderCode,OrderId,JoinOrderCode=@JoinOrderCode from DT_TrackCodeApply where OrderCode=@JoinOrderCode and state=1 and TrackType<3 end else begin select OrderCode,OrderId,JoinOrderCode=@JoinOrderCode from DT_TrackCodeApply where OrderId=@OrderId and state=1 and TrackType<3 end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@DHType", DbType.Int32, DHType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询退件订单 public List Get_TrackBackScan(string Code, int DHType) { List list = null; string tsql = @" select top 1 a.TrackCode,a.Weight,OrderCode=b.PlatOrderCode,a.InDate,d.CountryName,c.ShopName from DT_TrackCodeScan a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderXXInfo d on b.OrderId=d.OrderId left join JC_Shop c on b.ShopId=c.ShopId where a.TrackCode=@Code "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@DHType", DbType.Int32, DHType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询退件订单 public List Get_TrackBackScan2(string Code, int DHType) { List list = null; string tsql = @" select top 1 a.TrackCode,weight=null,OrderCode=b.PlatOrderCode,InDate=null,d.CountryName,c.ShopName from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderXXInfo d on b.OrderId=d.OrderId left join JC_Shop c on b.ShopId=c.ShopId where a.State=1 and a.TrackCode=@Code "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@DHType", DbType.Int32, DHType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存退件记录 public int SaveOrderBagBack(DT_OrderBagBack Model) { string tsql = @" if @Id>0 begin Update [DT_OrderBagBack] set [OrderId]=@OrderId,[TrackCode]=@TrackCode,[OrderCode]=@OrderCode,[PostId]=@PostId,[BackReason]=@BackReason,[InDate]=@InDate,[InName]=@InName,[IsRK]=@IsRK,[PostionId]=@PostionId,[CompanyId]=@CompanyId,[CancelReason]=@CancelReason,[State]=@State,[BackNum]=@BackNum where Id=@Id end else begin INSERT INTO [DT_OrderBagBack]([OrderId],[TrackCode],[OrderCode],[PostId],[BackReason],[InDate],[InName],[IsRK],[PostionId],[CompanyId],[CancelReason],[State],[BackNum])values(@OrderId,@TrackCode,@OrderCode,@PostId,@BackReason,@InDate,@InName,@IsRK,@PostionId,@CompanyId,@CancelReason,@State,@BackNum) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@BackReason", DbType.String, Model.BackReason); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@IsRK", DbType.Int32, Model.IsRK); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@CancelReason", DbType.String, Model.CancelReason); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@BackNum", DbType.Int32, Model.BackNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 退件入库 public int SaveBackBag(int ComapnyId, int OrderId, string PostionCode, int BackState, string JoinOrderCode) { string tsql = @" declare @StoreId int,@PostionId int set @PostionId=0 if @PostionCode<>'' begin select top 1 @StoreId=a.StoreId,@PostionId=PostionId from CK_StorePostion a inner join CK_StoreHouse b on a.StoreId=b.StoreId where b.CompanyId=@ComapnyId and a.PostionCode=@PostionCode end if @JoinOrderCode is not null and @JoinOrderCode<>'' begin if @PostionId>0 begin update b set b.OrderGoodsId=0,b.CKDetailId=0,StoreId=@StoreId,PostionId=@PostionId,b.InDate=getdate() from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end else begin update b set b.OrderGoodsId=0,b.CKDetailId=0,b.InDate=getdate() from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end update DT_OrderInfo set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where JoinOrderCode=@JoinOrderCode update a set a.ErrorInfo=isnull(a.ErrorInfo,'')+'退件' from DT_OrderXXInfo a inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where JoinOrderCode=@JoinOrderCode update a set a.ErrorInfo=isnull(a.ErrorInfo,'')+'退件' from DT_OrderXXInfoNew a inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode --update a set a.LockNum=0,a.OutNum=0 from DT_OrderGoods a --inner join DT_OrderInfo c on a.OrderId=c.OrderId --where c.JoinOrderCode=@JoinOrderCode update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderInfo c on a.OrderId=c.OrderId where c.JoinOrderCode=@JoinOrderCode end else begin if @PostionId>0 begin update b set b.OrderGoodsId=0,b.CKDetailId=0,b.StoreId=@StoreId,b.PostionId=@PostionId,b.InDate=getdate() from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId=@OrderId end else begin update b set b.OrderGoodsId=0,b.CKDetailId=0,b.InDate=getdate() from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId=@OrderId end update DT_OrderInfo set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfo set ErrorInfo=isnull(ErrorInfo,'')+'退件' where OrderId=@OrderId update DT_OrderInfoNew set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set ErrorInfo=isnull(ErrorInfo,'')+'退件' where OrderId=@OrderId --update DT_OrderGoods set LockNum=0,OutNum=0 where OrderId=@OrderId update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ComapnyId", DbType.Int32, ComapnyId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 部分退件入库 public int SavePartBackBag(int ComapnyId, int OrderId, int OrderGoodsId, string PostionCode, int BackState) { string tsql = @" declare @StoreId int,@PostionId int set @PostionId=0 if @PostionCode<>'' begin select top 1 @StoreId=a.StoreId,@PostionId=PostionId from CK_StorePostion a inner join CK_StoreHouse b on a.StoreId=b.StoreId where b.CompanyId=@ComapnyId and a.PostionCode=@PostionCode end if @PostionId>0 begin update b set b.OrderGoodsId=0,b.CKDetailId=0,StoreId=@StoreId,PostionId=@PostionId from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.Id=@OrderGoodsId end else begin update b set b.OrderGoodsId=0,b.CKDetailId=0 from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.Id=@OrderGoodsId end update DT_OrderGoods set LockNum=0,OutNum=0 where Id=@OrderGoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ComapnyId", DbType.Int32, ComapnyId); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, OrderGoodsId); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 部分退件入库修改库存 public void UpdateBackBagGoods(int OrderId, int BackState) { string tsql = @" update DT_OrderInfo set State=@BackState,PrintState=0,PostState=0,MateState=0 where OrderId=@OrderId update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); db.ExecuteNonQuery(cmd); } #endregion #region 退件入库原库位修改库存 public void UpdateBackBagGoodsIn(int OrderId, int BackState) { string tsql = @" update DT_OrderInfo set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfo set ErrorInfo=isnull(ErrorInfo,'')+'退件' where OrderId=@OrderId update DT_OrderInfoNew set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set ErrorInfo=isnull(ErrorInfo,'')+'退件' where OrderId=@OrderId --delete from HW_GoodsOutDetail where id in (select b.Id from HW_GoodsOutList a --inner join HW_GoodsOutDetail b on a.OutId=b.OutId --where a.OrderId=@OrderId) --delete from HW_GoodsOutList where OrderId=@OrderId --update DT_OrderGoods set LockNum=0,OutNum=0 where OrderId=@OrderId update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); db.ExecuteNonQuery(cmd); } #endregion #region 退件入库原库位修改库存 public void UpdateBackBagGoodsIn2(int OrderId, int BackState, string Reason) { string tsql = @" update DT_OrderInfo set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfo set ErrorInfo=isnull(ErrorInfo,'')+@Reason where OrderId=@OrderId update DT_OrderInfoNew set State=@BackState,PrintState=0,PrintDate=null,PostState=0,PostDate=null,MateState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set ErrorInfo=isnull(ErrorInfo,'')+@Reason where OrderId=@OrderId update b set b.GoodsPlanNum=dbo.GetOrderGoodsNum(a.DetailId),b.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); db.AddInParameter(cmd, "@Reason", DbType.String, Reason); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询包裹退件 public List GetListDT_OrderBagBack(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.OrderCode,a.PostId,a.BackReason,a.InDate,a.InName,a.IsRK,a.PostionId,a.CompanyId,a.CancelReason,a.State,a.BackNum,b.PlatOrderCode,b.JoinOrderCode,c.ShopName,StateName=case when b.State=3 then '取消订单' when b.State=1 then '未发货' when b.State=2 then '已经发货' end,b.TotalPrice"; ser.Tables = @"DT_OrderBagBack a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join jc_shop c on b.shopid=c.shopid"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 删除跟踪码 public void DeleteTrackCode(int Id, int OrderId) { string tsql = @" declare @JoinOrderCode nvarchar(50),@Num int select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId if @Id=0 begin update DT_TrackCodeApply set State=0,UpdateTime=getdate() where OrderId=@OrderId and TrackType<3 end else begin update DT_TrackCodeApply set State=0,UpdateTime=getdate() where Id=@Id end if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select @Num=count(0) from DT_TrackCodeApply where OrderCode=@JoinOrderCode and State=1 and TrackType<3 if @Num<=1 begin update DT_OrderInfo set IsSpare=0 where JoinOrderCode=@JoinOrderCode end if @Num<1 begin update a set a.TrackState=0 from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode update a set a.TrackState=0 from DT_OrderXXInfoNew a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end end else begin select @Num=count(0) from DT_TrackCodeApply where OrderId=@OrderId and State=1 and TrackType<3 if @Num<=1 begin update DT_OrderInfo set IsSpare=0 where OrderId=@OrderId end if @Num<1 begin update DT_OrderXXInfo set TrackState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set TrackState=0 where OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 查询订单重量 public int Get_OrderWeight(int OrderId) { string tsql = @" declare @Weight int set @Weight=0 select @Weight=SUM(Isnull(b.Weight,0)*a.GoodsNum) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId select Weight=Isnull(@Weight,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询订单物流费用 public List Get_PostFeeList(int Weight, int CompanyId, string Country) { List list = null; string tsql = @" declare @QCCountry nvarchar(100),@CountryName nvarchar(150) set @QCCountry='' select top 1 @QCCountry=EnglishName,@CountryName=Name from JC_Country where Code=@Country and IsUse=1 select distinct Name,OffNum,Fee*OffNum/10, Fee=case when Fee=-1 then 0 else dbo.MoneyChange(Fee,MoneyCode,@CompanyId) end,OffFee=case when Fee=-1 then 0 else dbo.MoneyChange(Fee,MoneyCode,@CompanyId)*OffNum/10 end,OffNumName=case when Fee=-1 then '根据面单计费' when OffNum=10 then '无折扣' else CAST(OffNum as nvarchar(10))+'折' end from ( select c.Name, Fee=case when b.FeePrice=-1 then -1 when b.FeeRate is null or b.FeeRate<=0 then ISNULL(b.FeePrice,0)*ISNULL(b.PostOff,10)/10+ISNULL(b.CodeFee,0) else ISNULL(b.FeePrice,0)+@Weight*b.FeeRate*ISNULL(b.PostOff,10)/10+ISNULL(b.CodeFee,0) end,OffNum=isnull(c.OffNum,10),MoneyCode=isnull(b.MoneyCode,'CNY') from JC_PostFee a inner join JC_PostFeeDetail b on a.Id=b.FeeId inner join JC_ExpressPost c on a.ExpressID=c.ExpressID where c.CompanyId=@CompanyId and (b.Country=@QCCountry or b.CountryName=@CountryName or b.Country='0') and b.SWeight<@Weight and (EWeight=0 or EWeight>=@Weight))a order by Fee*OffNum/10 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Weight", DbType.Int32, Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Country", DbType.String, Country); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 验证关键字 public int Iskeyword(string keyword) { string tsql = @" SELECT * FROM dbo.DT_KeyWords WHERE KeyWords=@keyword "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@KeyWords", DbType.String, keyword); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询订单账单信息 public DT_OrderBill Get_OrderBillList(int OrderId) { DT_OrderBill model = null; string tsql = @" declare @JoinOrderCode nvarchar(50) select @JoinOrderCode=JoinOrderCode from DT_OrderInfo where OrderId=@OrderId select OrderCode=a.PlatOrderCode,RevAddr=b.RevName+','+b.RevAddr+' '+isnull(b.RevArea,'')+' '+isnull(b.RevCity,'')+' '+isnull(b.RevProvince,'')+','+isnull(b.RevPostCode,'')+','+b.RevCountry,RevName,a.MoneyCode,a.TotalPrice,a.RMBPrice,a.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select top 3 a.GoodsNum,GoodsName=case when GoodsEnglisgName is null or GoodsEnglisgName='' then 'Clothes' else GoodsEnglisgName end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode end else begin select top 3 a.GoodsNum,GoodsName=case when GoodsEnglisgName is null or GoodsEnglisgName='' then 'Clothes' else GoodsEnglisgName end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) model = ds.Tables[0].Rows[0].ToModel(); model.BillGoodsList = ds.Tables[1].ToList(); return model; } #endregion #region 查询导入跟踪码 public List Get_OrderTrackCodeScan(string TrackCode, string OrderCode) { List list = null; string tsql = @" select * from DT_TrackCodeScan where TrackCode=@TrackCode or OrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List Get_OrderTrackList(string OrderIds) { List list = null; string tsql = @" select a.TrackCode,b.OrderId,OrderCode=b.JoinOrderCode from DT_TrackCodeScan a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List Get_OrderTrackList2(string OrderIds) { List list = null; string tsql = @" select a.TrackCode,b.OrderId,OrderCode=b.JoinOrderCode from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.state=1 and b.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单跟踪码 public List Get_OrderTrackList3(string JoinOrderCodes) { List list = null; string tsql = @" select TrackCode,OrderId,OrderCode from DT_TrackCodeApply where state=1 and OrderCode in (" + JoinOrderCodes + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页查询订单 public List GetListForBlank(string OrderIds) { List list = null; string tsql = @" select a.OrderId,a.PlatOrderCode,a.JoinOrderCode,RevCountry=isnull(b.RevCountry,''),RevAddr=isnull(b.RevAddr,''),RevName=isnull(b.RevName,''),RevPhone=isnull(b.RevPhone,''),RevCity=isnull(b.RevCity,''),RevArea=isnull(b.RevArea,''),RevProvince=isnull(b.RevProvince,''),RevPostCode=isnull(b.RevPostCode,''),RevMoblie=isnull(b.RevMoblie,''),RevMail=isnull(b.RevMail,''),b.LogisticsId,b.Post,c.ShopName,TrackCode=(select top 1 TrackCode from DT_TrackCodeApply where ((OrderId=a.OrderId) or (OrderCode is not null and OrderCode=a.JoinOrderCode)) and State=1) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId=c.ShopId where b.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页亚马逊导出 public DataTable GetYMXOrder(string OrderIds) { string tsql = @" select a.PlatOrderCode,b.GoodsDesc,b.GoodsNum,RQ=CONVERT(varchar(100), GETDATE(), 111),Code='Other',wl= case when c.LogisticsId=1 then 'EMS' else 'China Post Air Mail' end,TrackCode=(select top 1 TrackCode from DT_TrackCodeApply where State=1 and OrderId=a.OrderId and TrackType<3) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable ds = db.ExecuteDataTable(cmd); return ds; } #endregion #region 验证赔款申请 public int IsOrderBackMoney(string OrderCode) { string tsql = @" select Num=count(0) from DT_OrderBackMoneyApply where OrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证赔款申请 public int IsOrderBackMoney2(string OrderCode) { string tsql = @" declare @OrderId int set @OrderId=0 select top 1 @OrderId=OrderId from DT_OrderInfo where PlatOrderCode=@OrderCode select OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存赔款申请 public int SaveBackMoneyApply(DT_OrderBackMoneyApply Model) { string tsql = @" if @Id>0 begin Update [DT_OrderBackMoneyApply] set [OrderId]=@OrderId,[OrderCode]=@OrderCode,[GoodsCode]=@GoodsCode,[BackReason1]=@BackReason1,[BackReason2]=@BackReason2,[BackReason3]=@BackReason3,[Remark]=@Remark,[OrderPrice]=@OrderPrice,[BackPrice]=@BackPrice,[PlanPrice]=@PlanPrice,[FactPrice]=@FactPrice,[InName]=@InName,[InUserId]=@InUserId,[DeptName]=@DeptName,[DeptRemark]=@DeptRemark,[ShopId]=@ShopId,[MoneyCode1]=@MoneyCode1,[MoneyCode2]=@MoneyCode2,[MoneyCode3]=@MoneyCode3,[MoneyCode4]=@MoneyCode4,ImageIds=@ImageIds where Id=@Id end else begin INSERT INTO [DT_OrderBackMoneyApply]([OrderId],[OrderCode],[GoodsCode],[BackReason1],[BackReason2],[BackReason3],[Remark],[OrderPrice],[BackPrice],[PlanPrice],[FactPrice],[InName],[InUserId],[DeptName],[DeptRemark],[CompanyRemark],[CompanyRemark2],[CompanyName1],[Indate],[CompanyDate1],[CompanyDate2],[CompanyAgree1],[CompanyAgree2],[ShopId],[MoneyCode1],[MoneyCode2],[MoneyCode3],[MoneyCode4],CompanyUserId,ImageIds)values(@OrderId,@OrderCode,@GoodsCode,@BackReason1,@BackReason2,@BackReason3,@Remark,@OrderPrice,@BackPrice,@PlanPrice,@FactPrice,@InName,@InUserId,@DeptName,@DeptRemark,@CompanyRemark,@CompanyRemark2,@CompanyName1,@Indate,@CompanyDate1,@CompanyDate2,@CompanyAgree1,@CompanyAgree2,@ShopId,@MoneyCode1,@MoneyCode2,@MoneyCode3,@MoneyCode4,@CompanyUserId,@ImageIds) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@BackReason1", DbType.String, Model.BackReason1); db.AddInParameter(cmd, "@BackReason2", DbType.String, Model.BackReason2); db.AddInParameter(cmd, "@BackReason3", DbType.String, Model.BackReason3); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OrderPrice", DbType.Decimal, Model.OrderPrice); db.AddInParameter(cmd, "@BackPrice", DbType.Decimal, Model.BackPrice); db.AddInParameter(cmd, "@PlanPrice", DbType.Decimal, Model.PlanPrice); db.AddInParameter(cmd, "@FactPrice", DbType.Decimal, Model.FactPrice); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); db.AddInParameter(cmd, "@CompanyName1", DbType.String, Model.CompanyName1); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Model.Indate); db.AddInParameter(cmd, "@CompanyDate1", DbType.DateTime, Model.CompanyDate1); db.AddInParameter(cmd, "@CompanyDate2", DbType.DateTime, Model.CompanyDate2); db.AddInParameter(cmd, "@CompanyAgree1", DbType.String, Model.CompanyAgree1); db.AddInParameter(cmd, "@CompanyAgree2", DbType.String, Model.CompanyAgree2); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@MoneyCode1", DbType.String, Model.MoneyCode1); db.AddInParameter(cmd, "@MoneyCode2", DbType.String, Model.MoneyCode2); db.AddInParameter(cmd, "@MoneyCode3", DbType.String, Model.MoneyCode3); db.AddInParameter(cmd, "@MoneyCode4", DbType.String, Model.MoneyCode4); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@CompanyUserId", DbType.String, Model.CompanyUserId); db.AddInParameter(cmd, "@ImageIds", DbType.String, Model.ImageIds); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存订单状态 public void SaveBackMoneyForOrder(int OrderId,int OrderState) { string tsql = @" Update [DT_OrderInfo] set OrderState2=@OrderState where OrderId=@OrderId Update [DT_OrderInfoNew] set OrderState2=@OrderState where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); db.ExecuteNonQuery(cmd); } #endregion #region 保存赔款申请 public int SaveBackMoneyApply2(int BackState, DT_OrderBackMoneyApply Model) { string tsql = @" declare @BackAdvise3 nvarchar(1000),@BackAdvise4 nvarchar(1000),@IsRead int set @IsRead=1 select top 1 @Id=Id,@BackAdvise3=isnull(BackAdvise,''),@BackAdvise4=isnull(BackAdvise2,'') from DT_OrderBackMoneyApply where OrderId=@OrderId if @BackAdvise<>'' and @BackAdvise3<>@BackAdvise begin set @IsRead=0 end if @BackAdvise2<>'' and @BackAdvise3<>@BackAdvise2 begin set @IsRead=2 end if @Id>0 begin Update [DT_OrderBackMoneyApply] set [GoodsCode]=@GoodsCode,[BackReason1]=@BackReason1,[BackReason2]=@BackReason2,[BackReason3]=@BackReason3,[Remark]=@Remark,[OrderPrice]=@OrderPrice,[BackPrice]=@BackPrice,[PlanPrice]=@PlanPrice,[FactPrice]=@FactPrice,[DeptName]=@DeptName,[DeptRemark]=@DeptRemark,[ShopId]=@ShopId,[MoneyCode1]=@MoneyCode1,[MoneyCode2]=@MoneyCode2,[MoneyCode3]=@MoneyCode3,[MoneyCode4]=@MoneyCode4,BackDate=@BackDate,ImageIds=@ImageIds,[PostCode]=@PostCode,[PostFee]=@PostFee,[BackState]=@BackState,[PostFee2]=@PostFee2,[BackState2]=@BackState2,[BackType]=@BackType,[OrderState]=@OrderState,[GoodState]=@GoodState,[BackAdvise]=@BackAdvise,[BackAdvise2]=@BackAdvise2,IsRead=@IsRead where Id=@Id end else begin INSERT INTO [DT_OrderBackMoneyApply]([OrderId],[OrderCode],[GoodsCode],[BackReason1],[BackReason2],[BackReason3],[Remark],[OrderPrice],[BackPrice],[PlanPrice],[FactPrice],[InName],[InUserId],[DeptName],[DeptRemark],[CompanyRemark],[CompanyRemark2],[CompanyName1],[Indate],[CompanyDate1],[CompanyDate2],[CompanyAgree1],[CompanyAgree2],[CompanyUserId],[ShopId],[MoneyCode1],[MoneyCode2],[MoneyCode3],[MoneyCode4],[ImageIds],[BackDate],[PostCode],[PostFee],[PostFee2],[BackState],[BackState2],[BackType],[OrderState],[GoodState],[BackAdvise],[BackAdvise2])values(@OrderId,@OrderCode,@GoodsCode,@BackReason1,@BackReason2,@BackReason3,@Remark,@OrderPrice,@BackPrice,@PlanPrice,@FactPrice,@InName,@InUserId,@DeptName,@DeptRemark,@CompanyRemark,@CompanyRemark2,@CompanyName1,@Indate,@CompanyDate1,@CompanyDate2,@CompanyAgree1,@CompanyAgree2,@CompanyUserId,@ShopId,@MoneyCode1,@MoneyCode2,@MoneyCode3,@MoneyCode4,@ImageIds,@BackDate,@PostCode,@PostFee,@PostFee2,@BackState,@BackState2,@BackType,@OrderState,@GoodState,@BackAdvise,@BackAdvise2) set @Id=SCOPE_IDENTITY() end select @Id"; if (BackState == 0) { tsql = @" delete from DT_OrderBackMoneyApply where OrderId=@OrderId select 1 "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@BackReason1", DbType.String, Model.BackReason1); db.AddInParameter(cmd, "@BackReason2", DbType.String, Model.BackReason2); db.AddInParameter(cmd, "@BackReason3", DbType.String, Model.BackReason3); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OrderPrice", DbType.Decimal, Model.OrderPrice); db.AddInParameter(cmd, "@BackPrice", DbType.Decimal, Model.BackPrice); db.AddInParameter(cmd, "@PlanPrice", DbType.Decimal, Model.PlanPrice); db.AddInParameter(cmd, "@FactPrice", DbType.Decimal, Model.FactPrice); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); db.AddInParameter(cmd, "@CompanyName1", DbType.String, Model.CompanyName1); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Model.Indate); db.AddInParameter(cmd, "@CompanyDate1", DbType.DateTime, Model.CompanyDate1); db.AddInParameter(cmd, "@CompanyDate2", DbType.DateTime, Model.CompanyDate2); db.AddInParameter(cmd, "@CompanyAgree1", DbType.String, Model.CompanyAgree1); db.AddInParameter(cmd, "@CompanyAgree2", DbType.String, Model.CompanyAgree2); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@MoneyCode1", DbType.String, Model.MoneyCode1); db.AddInParameter(cmd, "@MoneyCode2", DbType.String, Model.MoneyCode2); db.AddInParameter(cmd, "@MoneyCode3", DbType.String, Model.MoneyCode3); db.AddInParameter(cmd, "@MoneyCode4", DbType.String, Model.MoneyCode4); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@CompanyUserId", DbType.String, Model.CompanyUserId); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@PostCode", DbType.String, Model.PostCode); db.AddInParameter(cmd, "@BackState", DbType.Int32, Model.BackState); db.AddInParameter(cmd, "@ImageIds", DbType.String, Model.ImageIds); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, Model.PostFee2); db.AddInParameter(cmd, "@BackState2", DbType.Int32, Model.BackState2); db.AddInParameter(cmd, "@BackType", DbType.Int32, Model.BackType); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@GoodState", DbType.Int32, Model.GoodState); db.AddInParameter(cmd, "@BackAdvise", DbType.String, Model.BackAdvise); db.AddInParameter(cmd, "@BackAdvise2", DbType.String, Model.BackAdvise2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存赔款申请 public int SaveBackMoneyApply3(DT_OrderBackMoneyApply Model) { string tsql = @" select top 1 @Id=Id from DT_OrderBackMoneyApply where OrderId=@OrderId if @Id>0 begin Update [DT_OrderBackMoneyApply] set [FactPrice]=@FactPrice,[PostCode]=@PostCode,[PostFee]=@PostFee,[BackState]=@BackState,[PostFee2]=@PostFee2,[BackType]=@BackType,[OrderState]=@OrderState,[GoodState]=@GoodState,[BackAdvise]=@BackAdvise,[BackAdvise2]=@BackAdvise2,State=@State where Id=@Id end else begin INSERT INTO [DT_OrderBackMoneyApply]([OrderId],[OrderCode],[GoodsCode],[BackReason1],[BackReason2],[BackReason3],[Remark],[OrderPrice],[BackPrice],[PlanPrice],[FactPrice],[InName],[InUserId],[DeptName],[DeptRemark],[CompanyRemark],[CompanyRemark2],[CompanyName1],[Indate],[CompanyDate1],[CompanyDate2],[CompanyAgree1],[CompanyAgree2],[CompanyUserId],[ShopId],[MoneyCode1],[MoneyCode2],[MoneyCode3],[MoneyCode4],[ImageIds],[BackDate],[PostCode],[PostFee],[PostFee2],[BackState],[BackState2],[BackType],[OrderState],[GoodState],[BackAdvise],[BackAdvise2])values(@OrderId,@OrderCode,@GoodsCode,@BackReason1,@BackReason2,@BackReason3,@Remark,@OrderPrice,@BackPrice,@PlanPrice,@FactPrice,@InName,@InUserId,@DeptName,@DeptRemark,@CompanyRemark,@CompanyRemark2,@CompanyName1,@Indate,@CompanyDate1,@CompanyDate2,@CompanyAgree1,@CompanyAgree2,@CompanyUserId,@ShopId,@MoneyCode1,@MoneyCode2,@MoneyCode3,@MoneyCode4,@ImageIds,@BackDate,@PostCode,@PostFee,@PostFee2,@BackState,@BackState2,@BackType,@OrderState,@GoodState,@BackAdvise,@BackAdvise2) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@BackReason1", DbType.String, Model.BackReason1); db.AddInParameter(cmd, "@BackReason2", DbType.String, Model.BackReason2); db.AddInParameter(cmd, "@BackReason3", DbType.String, Model.BackReason3); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OrderPrice", DbType.Decimal, Model.OrderPrice); db.AddInParameter(cmd, "@BackPrice", DbType.Decimal, Model.BackPrice); db.AddInParameter(cmd, "@PlanPrice", DbType.Decimal, Model.PlanPrice); db.AddInParameter(cmd, "@FactPrice", DbType.Decimal, Model.FactPrice); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); db.AddInParameter(cmd, "@CompanyName1", DbType.String, Model.CompanyName1); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Model.Indate); db.AddInParameter(cmd, "@CompanyDate1", DbType.DateTime, Model.CompanyDate1); db.AddInParameter(cmd, "@CompanyDate2", DbType.DateTime, Model.CompanyDate2); db.AddInParameter(cmd, "@CompanyAgree1", DbType.String, Model.CompanyAgree1); db.AddInParameter(cmd, "@CompanyAgree2", DbType.String, Model.CompanyAgree2); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@MoneyCode1", DbType.String, Model.MoneyCode1); db.AddInParameter(cmd, "@MoneyCode2", DbType.String, Model.MoneyCode2); db.AddInParameter(cmd, "@MoneyCode3", DbType.String, Model.MoneyCode3); db.AddInParameter(cmd, "@MoneyCode4", DbType.String, Model.MoneyCode4); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@CompanyUserId", DbType.String, Model.CompanyUserId); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@PostCode", DbType.String, Model.PostCode); db.AddInParameter(cmd, "@BackState", DbType.Int32, Model.BackState); db.AddInParameter(cmd, "@ImageIds", DbType.String, Model.ImageIds); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, Model.PostFee2); db.AddInParameter(cmd, "@BackState2", DbType.Int32, Model.BackState2); db.AddInParameter(cmd, "@BackType", DbType.Int32, Model.BackType); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@GoodState", DbType.Int32, Model.GoodState); db.AddInParameter(cmd, "@BackAdvise", DbType.String, Model.BackAdvise); db.AddInParameter(cmd, "@BackAdvise2", DbType.String, Model.BackAdvise2); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存赔款批注 public int SaveBackMoneyCheck(DT_OrderBackMoneyApply Model) { string tsql = @" if @CompanyRemark<>'' begin Update [DT_OrderBackMoneyApply] set CompanyRemark=@CompanyRemark,CompanyDate1=getdate() where Id=@Id end else begin Update [DT_OrderBackMoneyApply] set CompanyRemark2=@CompanyRemark2,CompanyDate2=getdate() where Id=@Id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存赔款批注 public int SaveBackMoneyCheck2(DT_OrderBackMoneyApply Model) { string tsql = @" if @CompanyAgree1<>'' begin Update [DT_OrderBackMoneyApply] set CompanyAgree1=@CompanyAgree1,CompanyRemark=@CompanyRemark,CompanyDate1=getdate() where Id=@Id end else begin Update [DT_OrderBackMoneyApply] set CompanyAgree2=@CompanyAgree2,CompanyRemark2=@CompanyRemark2,CompanyDate2=getdate() where Id=@Id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@CompanyAgree1", DbType.String, Model.CompanyAgree1); db.AddInParameter(cmd, "@CompanyAgree2", DbType.String, Model.CompanyAgree2); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存处理状态 public void SaveBackMoneyState(int Id, int State, int BackState) { string tsql = @" Update [DT_OrderBackMoneyApply] set State=@State,BackState=@BackState where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@State", DbType.Int32, State); db.AddInParameter(cmd, "@BackState", DbType.Int32, BackState); db.ExecuteNonQuery(cmd); } #endregion #region 保存最终赔款 public int SaveBackMoneyFact(DT_OrderBackMoneyApply Model) { string tsql = @" --Update [DT_OrderBackMoneyApply] set FactPrice=@FactPrice,MoneyCode4=@MoneyCode4,BackDate=@BackDate where Id=@Id declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where PlatOrderCode=@OrderCode if @OrderId>0 and (select count(0) from DT_OrderSaleBack where OrderId=@OrderId and SaleType=2)=0 begin INSERT INTO [DT_OrderSaleBack]([OrderId],[InName],[InDate],[BackMoney],[BackMoneyCode],[BackType],[BackRemark],[ImageIds],[InUserId],[BackDate],[BackReason1],[BackReason2],[BackReason3],SaleType,GoodsCode,GoodsUrl) select @OrderId,InName,GETDATE(),FactPrice,MoneyCode4,'纠纷赔款',Remark,ImageIds,InUserId,@BackDate,BackReason1,BackReason2,BackReason3,2,GoodsCode,null from DT_OrderBackMoneyApply where OrderCode=@OrderCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@FactPrice", DbType.Decimal, Model.FactPrice); db.AddInParameter(cmd, "@MoneyCode4", DbType.String, Model.MoneyCode4); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListOrderBackMoneyApply(string Ids) { //string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,a.OrderPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,a.State from DT_OrderBackMoneyApply"; string tsql = "select * from DT_OrderBackMoneyApply where OrderId in (" + Ids + ") order by OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListOrderTrackCodeApply(string Ids) { //string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,a.OrderPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,a.State from DT_OrderBackMoneyApply"; string tsql = "select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,a.ScanDate,a.LabelUrl,a.SKU,a.OrderCode2 from DT_TrackCodeApply a where state=1 and OrderId in (" + Ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询赔款 public List GetListDT_OrderBackMoneyApply(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,a.OrderPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,b.ShopName,DName=c.DeptName,BackStateName=case when a.BackState=2 then '外箱破损重新包装入库' when a.BackState=1 then '正常入库' when a.BackState=3 then '破损报废' when a.BackState=4 then '丢失' else '未到货' end,a.PostCode,a.PostFee,a.BackState,OrderStateName=case when OrderState=0 then '取消订单取消佣金' when OrderState=1 then '订单和佣金正常' else '' end,BackTypeName=case when BackType=0 then '退款退货' when OrderState=1 then '退款不退货' when OrderState=1 then '赔款不退货' when OrderState=1 then '赔款退货' else '' end"; ser.Tables = @"DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId left join JC_DepartMent c on b.DeptId=c.deptId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询赔款 public List GetListDT_OrderBackMoneyApply2(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),c.PlatId,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,OrderPrice=c.TotalPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,b.ShopName,BackStateName=case when a.BackState=2 then '外箱破损重新包装入库' when a.BackState=1 then '正常入库' when a.BackState=3 then '破损报废' when a.BackState=4 then '丢失' when a.BackState=0 then '无' else '未到货' end,a.PostCode,a.PostFee,a.BackState,a.OrderState,OrderStateName=case when a.OrderState=0 then '取消订单收取佣金20%' when a.OrderState=1 then '订单和佣金正常' else '' end,BackTypeName=case when BackType=0 then '退款/退货' when BackType=1 then '退款/不退货' when BackType=2 then '部分赔款/不退货' when BackType=3 then '赔款退货' when BackType=6 then '补发配件' else '' end,c.OrderDate,a.BackAdvise,a.BackAdvise2,StateName=case when a.State=1 then '已结束' else '未结束' end,a.BackDate,escrowFee=isnull(c.escrowFee,0)"; ser.Tables = @"DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId inner join DT_OrderInfo c on a.OrderId=c.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询赔款 public List GetListDT_OrderBackUnRead() { List list = null; string tsql = @" SELECT * FROM dbo.DT_OrderBackMoneyApply WHERE isnull(IsRead,0)=0 order by Indate desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询赔款 public List GetListDT_OrderBackUnRead2() { List list = null; string tsql = @" SELECT * FROM dbo.DT_OrderBackMoneyApply WHERE isnull(IsRead,0)=2 order by Indate desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 修改赔款 public void UpdateOrderBackMoneyRead(int Id) { string tsql = @" update DT_OrderBackMoneyApply set IsRead=1 where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询赔款 public DT_OrderBackMoneyApply GetListDT_OrderBackMoneyApply2(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @" PlanPrice=case when MoneyCode3='USD' then PlanPrice else dbo.MoneyUSDChange(PlanPrice,MoneyCode3,1) end "; ser.Tables = @"DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); DT_OrderBackMoneyApply ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select PlanPrice=SUM(PlanPrice) from (" + tsql + " )a"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.Rows[0].ToModel(); return ListModel; } #endregion #region 分页查询赔款 public List GetListDT_OrderBackMoneyApply3(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @" a.BackReason1,PlanPrice=case when MoneyCode3='USD' then PlanPrice else dbo.MoneyUSDChange(PlanPrice,MoneyCode3,1) end "; ser.Tables = @"DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select BackReason1,PlanPrice=SUM(PlanPrice) from (" + tsql + " )a group by a.BackReason1"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询赔款 public List GetListDT_OrderBackMoneyApply4(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @" a.BackReason3,PlanPrice=case when MoneyCode3='USD' then PlanPrice else dbo.MoneyUSDChange(PlanPrice,MoneyCode3,1) end "; ser.Tables = @"DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select BackReason3,PlanPrice=SUM(PlanPrice) from (" + tsql + " )a group by a.BackReason3"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回赔款Model public DT_OrderBackMoneyApply GetOrderBackMoneyModel(int Id) { DT_OrderBackMoneyApply model = null; string tsql = "select a.*,BackStateName=case when a.BackState=2 then '外箱破损重新包装入库' when a.BackState=1 then '正常入库' when a.BackState=3 then '破损报废' when a.BackState=4 then '丢失' else '未到货' end,b.ShopName from DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回赔款Model public DT_OrderBackMoneyApply GetOrderBackMoneyModel22(int Id) { DT_OrderBackMoneyApply model = null; string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,OrderPrice=c.TotalPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,c.OrderDate,BackStateName=case when a.BackState=2 then '外箱破损重新包装入库' when a.BackState=1 then '正常入库' when a.BackState=3 then '破损报废' when a.BackState=4 then '丢失' else '未到货' end,a.State,b.ShopName from DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId inner join DT_OrderInfo c on a.OrderId=c.OrderId where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回赔款Model public DT_OrderBackMoneyApply GetOrderBackMoneyModel2(int OrderId) { DT_OrderBackMoneyApply model = null; string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,OrderPrice=c.TotalPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,c.OrderDate,BackStateName=case when a.BackState=2 then '外箱破损重新包装入库' when a.BackState=1 then '正常入库' when a.BackState=3 then '破损报废' when a.BackState=4 then '丢失' else '未到货' end,b.ShopName from DT_OrderBackMoneyApply a inner join jc_shop b on a.ShopId=b.ShopId inner join DT_OrderInfo c on a.OrderId=c.OrderId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 删除赔款 public void DeleteOrderBackMoney(int Id) { string tsql = @" delete from DT_OrderBackMoneyApply where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 赔款 public void UpdateOrderBackMoney(int UserId) { string tsql = @" if @UserId=1 begin update DT_OrderBackMoneyApply set CompanyAgree2=1 where CompanyAgree2 is null end else begin update DT_OrderBackMoneyApply set CompanyAgree1=1 where CompanyUserId=@UserId and CompanyAgree1 is null end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.ExecuteNonQuery(cmd); } #endregion #region 返回未审批数量 public DT_OrderBackNum GetOrderBackNum(int UserId) { DT_OrderBackNum model = null; string tsql = @"declare @NoXPNum int,@NoPKNum int select @NoXPNum=COUNT(0) from XP_GoodsSelect where (CheckUId1=@UserId or CheckUId2=@UserId) and CheckState2=0 if @UserId=1 begin select @NoPKNum=COUNT(0) from DT_OrderBackMoneyApply where isnull(CompanyAgree2,'')='' and datediff(day,Indate,getdate())=0 end else begin select @NoPKNum=COUNT(0) from DT_OrderBackMoneyApply where isnull(CompanyAgree1,'')='' and isnull(CompanyAgree2,'')='' and companyuserid=@UserId end select NoXPNum=@NoXPNum,NoPKNum=@NoPKNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询物流跟踪信息 public List GetPostInfoList(string Ids) { List list = null; string tsql = @" select Id,PostInfo,PostInfo1,PostInfo2 from WL_PostInfo where Id in (" + Ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页查询物流 public List GetListDT_PostInfo(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.PostId,a.NowState,a.InDate,a.UpdateTime,a.InName,a.ScanDate,a.PostDate1,a.PostDate2,a.PostDate3,a.PostDate4,a.DoneDate,a.Days,a.CountryName,a.OrderCode,a.JoinOrderCode,a.ShopId,a.State,b.ShopName"; ser.Tables = @"WL_PostInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId inner join JC_Express c with (nolock) on a.PostId=c.ExpressID"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select NowState,Num=count(0) from (" + tsql + " )a group by a.NowState"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询平均寄达天数 public WL_PostInfo GetListDT_PostInfo2(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.PostId,a.NowState,a.InDate,a.UpdateTime,a.InName,a.ScanDate,a.PostDate1,a.PostDate2,a.PostDate3,a.PostDate4,a.DoneDate,a.Days,a.CountryName,a.OrderCode,a.JoinOrderCode,a.ShopId,a.State,b.ShopName"; ser.Tables = @"WL_PostInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId inner join JC_Express c with (nolock) on a.PostId=c.ExpressID"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); WL_PostInfo ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select Days=avg(Days) from (" + tsql + " )a"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); if (tb!=null&&tb.Rows.Count>0) ListModel = tb.Rows[0].ToModel(); return ListModel; } #endregion #region 分页查询物流 public List GetListDT_PostInfo3(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.PostId,a.NowState,a.InDate,a.UpdateTime,a.InName,a.ScanDate,a.PostDate1,a.PostDate2,a.PostDate3,a.PostDate4,a.DoneDate,a.Days,a.CountryName,a.OrderCode,a.JoinOrderCode,a.ShopId,a.State,b.ShopName,PostName=c.Name"; ser.Tables = @"WL_PostInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId inner join JC_Express c with (nolock) on a.PostId=c.ExpressID"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select PostName,Num=count(0) from (" + tsql + " )a group by PostName"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询物流 public List GetListDT_PostInfo4(RefParameterCollection where) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"Id=cast(a.Id as int),a.OrderId,a.TrackCode,a.PostId,a.NowState,a.InDate,a.UpdateTime,a.InName,a.ScanDate,a.PostDate1,a.PostDate2,a.PostDate3,a.PostDate4,a.DoneDate,a.Days,a.CountryName,a.OrderCode,a.JoinOrderCode,a.ShopId,a.State,b.ShopName,PostName=d.LogisticsName"; ser.Tables = @"WL_PostInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId inner join JC_Express c with (nolock) on a.PostId=c.ExpressID inner join JC_ExpressType d with (nolock) on c.LogisticsId=d.LogisticsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); string tsql = ser.GetText2(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); if (tsql != "") tsql = "select PostName,Num=count(0) from (" + tsql + " )a group by PostName"; DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询提交留言留言 public List GetLY_Content() { List list = null; string tsql = @" SELECT OrderId FROM dbo.LY_Content WHERE InDate between dateadd(mm,-3,getdate()) and getdate()"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 分页查询 public List GetPack(DateTime? SDate, DateTime? EDate) { string sql1 = "SELECT InName,Count=Count(InName) FROM dbo.DT_TrackCodeScan WHERE InDate>@SDate AND InDate< @EDate +'23: 59' GROUP BY InName"; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql1); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 扫描匹配 public DT_OrderScanMate Get_ScanMateOrder(int DetailId) { DT_OrderScanMate model = null; string tsql = @" declare @orderid int,@JoinOrderCode nvarchar(50) select top 1 @orderid=b.orderid,@JoinOrderCode=b.JoinOrderCode from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId inner join DT_OrderXXInfoNew d on b.OrderId=d.OrderId left join (select GoodsOrderId,DetailId,Num=SUM(num) from HW_OrderMate where isnull(IsMate,0)=0 group by DetailId,GoodsOrderId)c on a.Id=c.GoodsOrderId and a.DetailId=c.DetailId where b.State=1 and b.MateState<=1 and isnull(a.LockNum,0)+isnull(c.Num,0) 0 and b.MoneyState=1 and b.PostState=0 order by b.OrderLevel desc,b.InDate if @orderid>0 begin select a.OrderId,a.OrderLevel,a.PlatOrderCode,a.IsJoin,a.JoinOrderCode,a.InDate,a.OrderDate,a.MateState,a.MoneyState,a.PostState,a.State,a.PrintState,a.PrintDate,b.CountryName,b.ErrorInfo,b.PostError,c.ShopName,PostName=d.Name from DT_OrderInfo a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId inner join Jc_Shop c on a.ShopId=c.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@orderid if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select a.Id,c.GoodsId,a.DetailId,c.GoodsName,c.GoodsCode,b.TypeDesc,b.TypeCode,a.OldTypeDesc,GoodsNum=isnull(a.GoodsNum,0),LockNum=isnull(a.LockNum,0),productImgUrl=case when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfoNew d on a.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode end else begin select a.Id,c.GoodsId,a.DetailId,c.GoodsName,c.GoodsCode,b.TypeDesc,b.TypeCode,a.OldTypeDesc,GoodsNum=isnull(a.GoodsNum,0),LockNum=isnull(a.LockNum,0),productImgUrl=case when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.orderid=@orderid end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); if (ds != null && ds.Tables.Count>0 && ds.Tables[0].Rows.Count > 0) model = ds.Tables[0].Rows[0].ToModel(); if (model!=null&&ds.Tables[1] != null) { model.GoodsList = ds.Tables[1].ToList(); } return model; } #endregion #region 扫描匹配采购单 public List Get_ScanChaseCode(string PostCode) { List list = null; string tsql = @" select d.PlatOrderCode,d.JoinOrderCode,a.ChaseCode,f.GoodsCode,f.GoodsName,e.TypeCode,e.SKU1,e.TypeDesc,b.GoodsNum,BuyNum=b.GoodsNum-isnull(b.InGoodsNum,0),e.DetailId,a.ChaseId,d.OrderId,a.BuyDate,a.BuyCode,c.PostCode,b.InGoodsNum,Price=b.GoodsPrice,PostPrice=a.PostFee from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId inner join CG_PurchasePost c on a.ChaseId=c.ChaseId inner join DT_OrderInfoNew d on b.OrderId=d.OrderId inner join HW_GoodsDetail e on b.GoodsDetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where c.PostCode=@PostCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostCode", DbType.String, PostCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 扫描匹配采购单 public List Get_ScanOrders(string OrderIds) { List list = null; string tsql = @" select e.TrackState,OrderGoodsId=b.Id,a.ShopId,b.DetailId,a.PlatOrderCode,a.OrderId,d.GoodsCode,d.GoodsName,c.TypeCode,c.TypeDesc,b.GoodsNum,StateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintState,e.Post from DT_OrderInfoNew a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId inner join DT_OrderxxInfoNew e on a.OrderId=e.OrderId where a.OrderId in (" + OrderIds + ") order by a.OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 扫描匹配 public DT_OrderScanMate Get_ScanMateOrder2(string OrderCode) { DT_OrderScanMate model = null; string tsql = @" declare @orderid int,@JoinOrderCode nvarchar(50) select top 1 @orderid=orderid,@JoinOrderCode=JoinOrderCode from DT_OrderInfoNew where platordercode=@OrderCode or JoinOrderCode=@OrderCode if @orderid>0 begin select a.OrderId,a.OrderLevel,a.PlatOrderCode,a.IsJoin,a.JoinOrderCode,a.InDate,a.OrderDate,a.MateState,a.MoneyState,a.PostState,a.PrintState,a.PrintDate,a.State,b.CountryName,b.ErrorInfo,b.PostError,c.ShopName,PostName=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join Jc_Shop c on a.ShopId=c.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@orderid if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select a.Id,c.GoodsId,a.DetailId,c.GoodsName,c.GoodsCode,b.TypeDesc,b.TypeCode,a.OldTypeDesc,GoodsNum=isnull(a.GoodsNum,0),LockNum=isnull(a.LockNum,0),productImgUrl=case when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderInfo d on a.OrderId=d.OrderId where d.JoinOrderCode=@JoinOrderCode end else begin select a.Id,c.GoodsId,a.DetailId,c.GoodsName,c.GoodsCode,b.TypeDesc,b.TypeCode,a.OldTypeDesc,GoodsNum=isnull(a.GoodsNum,0),LockNum=isnull(a.LockNum,0),productImgUrl=case when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.orderid=@orderid end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet ds = db.ExecuteDataSet(cmd); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) model = ds.Tables[0].Rows[0].ToModel(); if (model != null && ds.Tables[1] != null) { model.GoodsList = ds.Tables[1].ToList(); } return model; } #endregion #region 验证是否扫描过 public HW_BarCode GetOrderBarCode(string Code) { HW_BarCode model = null; string tsql = "select * from HW_BarCode where BarCode=@Code and IsDelete=0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 验证是否扫描过 public HW_BarCode GetOrderBarCode2(int Code) { HW_BarCode model = null; string tsql = @" update a set a.MateState=b.MateState from HW_BarCode a inner join DT_OrderInfo b on a.OrderCode=b.PlatOrderCode where a.Id=@Code update a set a.MateState=b.MateState from HW_BarCode a inner join DT_OrderInfo b on a.OrderCode=b.JoinOrderCode where a.Id=@Code update c set c.lockNum=0 from HW_BarCode a inner join DT_OrderInfo b on a.OrderCode=b.PlatOrderCode inner join DT_OrderGoods c on b.OrderId=c.OrderId where a.Id=@Code and b.MateState=0 update c set c.lockNum=0 from HW_BarCode a inner join DT_OrderInfo b on a.OrderCode=b.JoinOrderCode inner join DT_OrderGoods c on b.OrderId=c.OrderId where a.Id=@Code and b.MateState=0 select * from HW_BarCode where Id=@Code and IsDelete=0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Code); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 保存扫描记录 public int SaveBarCode(HW_BarCode Model) { string tsql = @" if @Id>0 begin Update [HW_BarCode] set IsScan=@IsScan,MateState=@MateState,InDate=getdate(),InName=isnull(InName,'')+@InName,OrderCode=@OrderCode,InId=@InId where Id=@Id end else begin INSERT INTO [HW_BarCode]([ChaseId],[DetailId],[Code],[BarCode],[IsDelete],[InDate],[InName],MateState,OrderCode,IsScan)values(@ChaseId,@DetailId,@Code,@BarCode,@IsDelete,@InDate,@InName,@MateState,@OrderCode,@IsScan) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@Code", DbType.Int32, Model.Code); db.AddInParameter(cmd, "@BarCode", DbType.String, Model.BarCode); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@MateState", DbType.Int32, Model.MateState); db.AddInParameter(cmd, "@IsScan", DbType.Int32, Model.IsScan); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改匹配 public void UpdateOrderBarCode(string Code, string OrderCode) { string tsql = "update HW_BarCode set MateState=2,OrderCode=@OrderCode where BarCode=@Code and IsDelete=0 and MateState=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteDataTable(cmd); } #endregion #region 查询空余货架 public CK_StorePostion GetPostionModel(int OrderId, string OrderCode, int MateState) { CK_StorePostion model = null; string tsql = @" if(select count(0) from HW_OrderPostion where OrderCode=@OrderCode and IsUse=1)>0 begin select PostionCode,PostionId from HW_OrderPostion where OrderCode=@OrderCode and IsUse=1 end else begin declare @PostionCode nvarchar(50),@PostionId int set @PostionCode='' set @PostionId=0 select top 1 @PostionCode=PostionCode,@PostionId=PostionId from CK_StorePostion where StoreId=4 and PostionId not in (select PostionId from HW_OrderPostion where isuse=1) if @PostionId>0 begin INSERT INTO [HW_OrderPostion]([OrderId],[PostionCode],[PostionId],[IsUse],OrderCode,MateState) values(@OrderId,@PostionCode,@PostionId,1,@OrderCode,@MateState) end select PostionCode=@PostionCode,PostionId=@PostionId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询空余货架 public CK_StorePostion GetPostionModel2(int OrderId, string OrderCode, int MateState) { CK_StorePostion model = null; string tsql = @" if(select count(0) from HW_OrderPostion where OrderCode=@OrderCode and IsUse=1)>0 begin update HW_OrderPostion set MateState=@MateState where OrderCode=@OrderCode and IsUse=1 select PostionCode,PostionId from HW_OrderPostion where OrderCode=@OrderCode and IsUse=1 end else begin declare @PostionCode nvarchar(50),@PostionId int set @PostionCode='' set @PostionId=0 select top 1 @PostionCode=PostionCode,@PostionId=PostionId from CK_StorePostion where StoreId=5 and PostionId not in (select PostionId from HW_OrderPostion where isuse=1) if @PostionId>0 begin INSERT INTO [HW_OrderPostion]([OrderId],[PostionCode],[PostionId],[IsUse],OrderCode,MateState) values(@OrderId,@PostionCode,@PostionId,1,@OrderCode,@MateState) end select PostionCode=@PostionCode,PostionId=@PostionId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@MateState", DbType.String, MateState); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 匹配完成 public string UpdatePostion(int OrderId, string JoinOrderCode, string OrderCode) { string tsql = @" declare @PostionCode nvarchar(50) select @PostionCode=PostionCode from HW_OrderPostion where OrderCode=@OrderCode and IsUse=1 update HW_OrderPostion set IsUse=2,MateState=2 where OrderCode=@OrderCode and IsUse=1 if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=2 where JoinOrderCode=@JoinOrderCode update a set a.LockNum=a.GoodsNum from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfoNew set MateState=2 where OrderId=@OrderId update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId end select PostionCode=@PostionCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 匹配加1 public void UpdatePostion2(int OrderId, string JoinOrderCode, string OrderCode, int DetailId) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update DT_OrderInfo set MateState=1 where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=1 where JoinOrderCode=@JoinOrderCode update a set a.LockNum=isnull(a.LockNum,0)+1 from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode and a.DetailId=@DetailId end else begin update DT_OrderInfo set MateState=1 where OrderId=@OrderId update DT_OrderInfoNew set MateState=1 where OrderId=@OrderId update DT_OrderGoods set LockNum=isnull(LockNum,0)+1 where OrderId=@OrderId and DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.ExecuteNonQuery(cmd); } #endregion #region 匹配完成3 public void UpdatePostion3(int OrderId, string JoinOrderCode, string OrderCode) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update HW_OrderPostion set IsUse=2,MateState=2 where OrderCode=@JoinOrderCode and IsUse=1 update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=2 where JoinOrderCode=@JoinOrderCode update a set a.LockNum=a.GoodsNum from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update HW_OrderPostion set IsUse=2,MateState=2 where OrderCode=@OrderCode and IsUse=1 update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfoNew set MateState=2 where OrderId=@OrderId update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 匹配完成4 public void UpdatePostion4(int OrderId, string JoinOrderCode, string OrderCode) { string tsql = @" if @JoinOrderCode is not null and @JoinOrderCode<>'' begin update HW_OrderPostion set MateState=2 where OrderCode=@JoinOrderCode and IsUse=1 update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=2 where JoinOrderCode=@JoinOrderCode update a set a.LockNum=a.GoodsNum from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update HW_OrderPostion set MateState=2 where OrderCode=@OrderCode and IsUse=1 update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfoNew set MateState=2 where OrderId=@OrderId update DT_OrderGoods set LockNum=GoodsNum where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 查询匹配订单 public List GetOrderPostion(int StoreId, int MateState) { List list = null; string tsql = @" select a.OrderCode,a.OrderId,c.PostionCode,a.MateState from HW_OrderPostion a inner join CK_StorePostion c on a.PostionId=c.PostionId where a.IsUse=1 and c.StoreId=@StoreId and MateState=@MateState"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询匹配订单 public List GetOrderPostion2(int StoreId, int MateState) { List list = null; string tsql = @" select a.OrderCode,a.OrderId,d.GoodsNum,LockNum=isnull(d.LockNum,0),GoodsLeftNum=d.GoodsNum-isnull(d.LockNum,0),f.GoodsCode,e.TypeCode,e.TypeDesc from HW_OrderPostion a inner join DT_OrderInfoNew b on a.OrderCode=b.PlatOrderCode inner join DT_OrderGoods d on b.OrderId=d.OrderId inner join HW_GoodsDetail e on d.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId inner join CK_StorePostion c on a.PostionId=c.PostionId where a.IsUse=1 and c.StoreId=@StoreId and a.MateState=@MateState union select a.OrderCode,a.OrderId,d.GoodsNum,LockNum=isnull(d.LockNum,0),GoodsLeftNum=d.GoodsNum-isnull(d.LockNum,0),f.GoodsCode,e.TypeCode,e.TypeDesc from HW_OrderPostion a inner join DT_OrderInfoNew b on a.OrderCode=b.JoinOrderCode inner join DT_OrderGoods d on b.OrderId=d.OrderId inner join HW_GoodsDetail e on d.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId inner join CK_StorePostion c on a.PostionId=c.PostionId where a.IsUse=1 and c.StoreId=@StoreId and a.MateState=@MateState"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配库位 public List GetOrderPostion3(int StoreId) { List list = null; string tsql = @" select Id=e.OrderGoodsId,f.PostionCode,e.DetailId,Num=sum(e.KCNum) from HW_OrderPostion a inner join DT_OrderInfoNew b on a.OrderCode=b.PlatOrderCode inner join DT_OrderGoods d on b.OrderId=d.OrderId inner join HW_GoodsInDetail e on d.Id=e.OrderGoodsId inner join CK_StorePostion f on e.PostionId=f.PostionId inner join CK_StorePostion c on a.PostionId=c.PostionId where a.IsUse=1 and c.StoreId=@StoreId group by e.OrderGoodsId,f.PostionCode,e.DetailId union select Id=e.OrderGoodsId,f.PostionCode,e.DetailId,Num=sum(e.KCNum) from HW_OrderPostion a inner join DT_OrderInfoNew b on a.OrderCode=b.JoinOrderCode inner join DT_OrderGoods d on b.OrderId=d.OrderId inner join HW_GoodsInDetail e on d.Id=e.OrderGoodsId inner join CK_StorePostion f on e.PostionId=f.PostionId inner join CK_StorePostion c on a.PostionId=c.PostionId where a.IsUse=1 and c.StoreId=@StoreId group by e.OrderGoodsId,f.PostionCode,e.DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改匹配 public void DeleteOrderMate() { string tsql = "delete from HW_OrderMate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 修改 public void UpdateScan(int Code) { string tsql = "update HW_BarCode set IsScan=1 where Id=@Code"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Code); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单货物匹配 public int SaveOrderMate(HW_OrderMate Model) { string tsql = @" if @Id>0 begin Update [HW_OrderMate] set [InId]=@InId,[GoodsOrderId]=@GoodsOrderId,[Num]=@Num,[PostionId]=@PostionId,[DetailId]=@DetailId where Id=@Id end else begin INSERT INTO [HW_OrderMate]([InId],[GoodsOrderId],[Num],[PostionId],[DetailId])values(@InId,@GoodsOrderId,@Num,@PostionId,@DetailId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@GoodsOrderId", DbType.Int32, Model.GoodsOrderId); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询订单明细匹配库位 public List GetOrderMateList(string inids) { List list = null; string tsql = @" select * from HW_OrderMate where isnull(ismate,0)=0 and GoodsOrderId in (" + inids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 取消匹配 public void UpdateOrderMate(string OrderCode) { string tsql = @" update HW_BarCode set MateState=0 where OrderCode=@OrderCode update HW_OrderPostion set IsUse=2 where OrderCode=@OrderCode update b set b.OrderGoodsId=0 from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.PlatOrderCode=@OrderCode or c.JoinOrderCode=@OrderCode update a set a.locknum=0 from DT_OrderGoods a inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.PlatOrderCode=@OrderCode or c.JoinOrderCode=@OrderCode update DT_OrderInfonew set MateState=0 where PlatOrderCode=@OrderCode or JoinOrderCode=@OrderCode update DT_OrderInfo set MateState=0 where PlatOrderCode=@OrderCode or JoinOrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 取消匹配 public void UpdateOrderMate2(int Id) { string tsql = @" update HW_BarCode set MateState=0 where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 取消匹配 public void UpdateOrderMate4(string OrderCode) { string tsql = @" update HW_BarCode set MateState=0 where OrderCode=@OrderCode update HW_OrderPostion set IsUse=2 where OrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 取消匹配 public void UpdateOrderMate3(string OrderCode) { string tsql = @" update HW_BarCode set MateState=0 where OrderCode=@OrderCode update HW_OrderPostion set IsUse=2 where OrderCode=@OrderCode update b set b.OrderGoodsId=0 from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.PlatOrderCode=@OrderCode or c.JoinOrderCode=@OrderCode update a set a.locknum=0 from DT_OrderGoods a inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.PlatOrderCode=@OrderCode or c.JoinOrderCode=@OrderCode update DT_OrderInfonew set MateState=0 where PlatOrderCode=@OrderCode or JoinOrderCode=@OrderCode update DT_OrderInfo set MateState=0 where PlatOrderCode=@OrderCode or JoinOrderCode=@OrderCode update b set b.IsMate=0 from DT_OrderGoods a inner join HW_OrderMate b on a.Id=b.OrderGoodsId inner join DT_OrderInfoNew c on a.OrderId=c.OrderId where c.PlatOrderCode=@OrderCode or c.JoinOrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 验证是否被匹配 public int IsDetailMate(int InId) { string tsql = @" select OrderGoodsId from HW_GoodsInDetail where InId=@InId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, InId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证是否被匹配 public void UpdateOrderLock() { string tsql = @" update b set b.LockNum=0 from DT_OrderInfoNew a inner join DT_OrderGoods b on a.OrderId=b.OrderId where State=1 and a.MateState=0 and b.LockNum>0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单扫描记录 public void SaveTrackCodeScanHWC(DT_TrackCodeScan Model) { string tsql = @" if @JoinOrderCode<>'' begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=getdate() where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=getdate() where JoinOrderCode=@JoinOrderCode update a set a.TotalWeight=@Weight,a.PostFee=@PostFee from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=@InDate,PrintState=1,PrintDate=getdate() where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PostDate=@InDate,PrintState=1,PrintDate=getdate() where orderid=@OrderId update DT_OrderXXInfo set TotalWeight=@Weight,PostFee=@PostFee where orderid=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, Model.BagUserId); db.AddInParameter(cmd, "@Weight", DbType.Int32, Model.Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, Model.OldPostFee); db.AddInParameter(cmd, "@Count", DbType.Int32, Model.Count); db.AddInParameter(cmd, "@IsSure", DbType.Int32, Model.IsSure); db.AddInParameter(cmd, "@SureDate", DbType.DateTime, Model.SureDate); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@TrackId", DbType.Int32, Model.TrackId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@IsCSM", DbType.String, Model.IsCSM); db.ExecuteNonQuery(cmd); } #endregion #region 查询运单号 public List Get_OrderTrack(int PostId,string OrderIds) { List list = null; string tsql = @" select TrackCode from DT_TrackCodeApply where State=1 and PostId=@PostId and OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public List GetCountListMyOrder(int CompanyId, int UserId, DateTime? SDate, DateTime? EDate, string GoodsCode) { string tsql = ""; List list = null; tsql = @" select OrderDate=convert(nvarchar(10),d.OrderDate,120),Num=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo f on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b on f.GoodsId=b.GoodsId inner join DT_OrderGoods c on b.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and a.UserId=@UserId and d.OrderDate>=@SDate and d.OrderDate<@EDate and d.State>0 and d.State<3 group by convert(nvarchar(10),d.OrderDate,120)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public List Get_OrderUser(int IsBJ,int CompanyId, int OrderState, int PlatId, int ShopId, int UserId, DateTime? SDate, DateTime? EDate, string GoodsCode,string OrderCode,string TrackCode,string Name) { List list = null; string tsql = @" if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.GoodsNum,a.PlatOrderCode,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,OrderState2,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName from DT_OrderInfo a inner join ( select distinct d.OrderId from HW_GoodsUser a inner join HW_GoodsInfo f on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b on f.GoodsId=b.GoodsId inner join DT_OrderGoods c on b.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@ShopId=0 or d.ShopId=@ShopId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and (@OrderCode='' or d.PlatOrderCode like '%'+@OrderCode+'%') and a.UserId=@UserId and d.OrderDate>=@SDate and d.OrderDate<@EDate and d.State>0 and d.State<3)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId left join JC_Express d on c.Post=d.ExpressID where a.OrderName='标记回看' and (@OrderState=-1 or a.OrderState2=@OrderState) and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') order by a.OrderDate end else begin select a.OrderId,a.PlatId,a.ShopId,a.GoodsNum,a.PlatOrderCode,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,OrderState2,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName from DT_OrderInfo a inner join ( select distinct d.OrderId from HW_GoodsUser a inner join HW_GoodsInfo f on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b on f.GoodsId=b.GoodsId inner join DT_OrderGoods c on b.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@ShopId=0 or d.ShopId=@ShopId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and (@OrderCode='' or d.PlatOrderCode like '%'+@OrderCode+'%') and a.UserId=@UserId and d.OrderDate>=@SDate and d.OrderDate<@EDate and d.State>0 and d.State<3)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId left join JC_Express d on c.Post=d.ExpressID where (@OrderState=-1 or a.OrderState2=@OrderState) and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') order by a.OrderDate end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public List Get_OrderUser2(int IsBJ,int CompanyId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, string OrderCode, string TrackCode, string Name) { List list = null; string tsql = @" if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName from DT_OrderInfo a inner join (select distinct e.OrderId from DT_OrderGoods e inner join HW_GoodsDetail b on e.DetailId=b.DetailId inner join HW_GoodsInfo f on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId left join JC_Express d on c.Post=d.ExpressID where a.OrderName='标记回看' and a.CompanyId=@CompanyId and (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.OrderDate>=@SDate and a.OrderDate<@EDate and a.State>0 and a.State<3 order by a.OrderDate end else begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName from DT_OrderInfo a inner join (select distinct e.OrderId from DT_OrderGoods e inner join HW_GoodsDetail b on e.DetailId=b.DetailId inner join HW_GoodsInfo f on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId left join JC_Express d on c.Post=d.ExpressID where a.CompanyId=@CompanyId and (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.OrderDate>=@SDate and a.OrderDate<@EDate and a.State>0 and a.State<3 order by a.OrderDate end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 标记 public void UpdateOrderBJ(string OrderName, int OrderId) { string tsql = @" update DT_OrderInfo set OrderName=@OrderName where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderName", DbType.String, OrderName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改成本价 public void UpdateOrderGoodsFee(int Id,decimal? GoodsFee) { string tsql = @" update DT_OrderGoods set GoodsFee=@GoodsFee*GoodsNum where Id=@Id update HW_GoodsInDetail set Price=@GoodsFee where OrderGoodsId=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 查询我的订单 public List Get_OrderGoods(int CompanyId, int PlatId, int ShopId, int UserId, DateTime? SDate, DateTime? EDate, string GoodsCode) { List list = null; string tsql = @" select a.OrderId,a.GoodsFee,e.GoodsCode,d.TypeDesc,e.GoodsName,a.TCFee,a.GoodsNum,ImgUrl=e.FirstImgUrl,e.FeeRate,a.Id from DT_OrderGoods a inner join ( select distinct d.OrderId from HW_GoodsUser a inner join HW_GoodsInfo f on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b on f.GoodsId=b.GoodsId inner join DT_OrderGoods c on b.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@ShopId=0 or d.ShopId=@ShopId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and a.UserId=@UserId and d.OrderDate>=@SDate and d.OrderDate<@EDate and d.State>0 and d.State<3)b on a.OrderId=b.OrderId inner join HW_GoodsDetail d on a.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public List Get_OrderGoods2(int CompanyId, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode) { List list = null; string tsql = @" select a.OrderId,a.GoodsFee,e.GoodsCode,d.TypeDesc,e.GoodsName,a.TCFee,a.GoodsNum,ImgUrl=e.FirstImgUrl,e.FeeRate,a.Id from DT_OrderGoods a inner join HW_GoodsDetail d on a.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId inner join DT_OrderInfo f on a.OrderId=f.OrderId where f.CompanyId=@CompanyId and (@GoodsCode='' or e.GoodsCode=@GoodsCode) and (@PlatId=0 or f.PlatId=@PlatId) and (@ShopId=0 or f.ShopId=@ShopId) and f.OrderDate>=@SDate and f.OrderDate<@EDate and f.State>0 and f.State<3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改跟踪码 public void UpdateDDTrackCode() { string tsql = @" update a set TrackCode2= dbo.[getOrderTrackCode](a.OrderId,2) from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.PostState=1 and a.TrackCode2 is null"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 查询店铺 public List Get_ShopList(int CompanyId) { List list = null; string tsql = @" select ShopId,plattype, ShopName,PlatName=dbo.GetPlatName(ShopId) from JC_Shop where CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 验证赔款申请 public DT_BackOrder GetBackOrder(string OrderCode) { DT_BackOrder model = null; string tsql = @" select OrderCode=PlatOrderCode,OrderId,ShopId,ShopName=dbo.GetShopName(ShopId),TotalPrice=dbo.MoneyUSDChange(TotalPrice,MoneyCode,companyid),GoodsCode=dbo.getGoodsCoode(OrderId) from DT_OrderInfo where PlatOrderCode=@OrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询我的订单 public List Get_OrderGoodsForBack(string OrderIds) { List list = null; string tsql = @" select Fee1=isnull(b.PostPrice,0)*a.GoodsNum,GDFee=isnull(b.Price,0)*a.GoodsNum,Fee2=isnull(b.HWCFee,0)*a.GoodsNum,a.OrderId from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds+")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public List Get_OrderGoodsForBack2(string OrderIds) { List list = null; string tsql = @" select Fee1=isnull(PostFee,0),PostId=Post,OrderId from DT_OrderXXInfo where OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改跟踪码 public void UpdateCode(string OldCode,string NewCode) { string tsql = @" update DT_TrackCodeApply set TrackCode=@NewCode where TrackCode=@OldCode and State=1 update DT_TrackCodeScan set TrackCode=@NewCode where TrackCode=@OldCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OldCode", DbType.String, OldCode); db.AddInParameter(cmd, "@NewCode", DbType.String, NewCode); db.ExecuteNonQuery(cmd); } #endregion #region 货物成本 public void GetGoodsFee() { string tsql = @" update c set c.TotalWeight=b.Weight,c.PostFee=b.PostFee from DT_OrderInfo a inner join ( select OrderId,Weight=SUM(Weight),PostFee=SUM(PostFee) from DT_TrackCodeScan group by OrderId)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId where a.IsJoin=0 and b.PostFee>0 and isnull(c.PostFee,0)<=0 --计算成本 update a set a.GoodsFee=b.Price*a.GoodsNum from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfo c on a.OrderId=c.OrderId where a.GoodsFee is null and b.Price>0 update a set a.HWCFee=65*c.Solid from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.StoreId in (5,6) and a.HWCFee is null and c.Solid>0 update b set b.TCFee=a.hwcfee*b.GoodsNum from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where a.KCNum>0 and a.hwcfee>0 and b.TCFee is null update a set a.Fee3=TCFee from DT_OrderInfo a inner join(select OrderId,TCFee=SUM(isnull(TCFee,0)) from DT_OrderGoods group by OrderId)b on a.OrderId=b.OrderId where b.TCFee>0 and a.Fee3 is null --海外在途 update a set a.GoodsInNum2=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where isnull(b.OutInNum,0)b.GoodsNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteDataTable(cmd); } #endregion #region 货物成本 public static void GetGoodsFee2(int OrderId,decimal fee) { string tsql = @" update DT_OrderXXInfo set Fee13=@fee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@fee", DbType.Decimal, fee); db.ExecuteDataTable(cmd); } #endregion } }