using System; using System.Text; using System.Data; using System.Data.Common; using System.Linq; using System.Data.SqlClient; using System.Collections.Generic; using NetLibrary; using NetLibrary.Data; using NetLibrary.ReportPrint; using TradeModel; namespace TradeData { public class HuoWuData { #region 分页查询 public List GetListHW_GoodsInfo(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,a.GoodsNum,a.GoodsLockNum,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State"; ser.Tables = @"HW_GoodsInfo a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; 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; } public List GetListHW_GoodsInfoNew(int CompanyId, string SKU, int IsSafe, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%' or a.SKU2 like '%'+@SKU+'%' or a.SKU3 like '%'+@SKU+'%' or a.SKU4 like '%'+@SKU+'%') and (@IsSafe=0 or a.SafeNum>=a.GoodsNum) "; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,GoodsNum=dbo.GetGoodsNum(a.GoodsId),a.GoodsLockNum,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State,SupplierName"; if (SKU != ""||IsSafe == 1) { ser.Tables = @"(select *,SupplierName=dbo.getGoodsSupplier(GoodsId) from HW_GoodsInfo where GoodsId in (" + tsql1 + "))a"; } else ser.Tables = @"(select *,SupplierName=dbo.getGoodsSupplier(GoodsId) from HW_GoodsInfo)a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; 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); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@IsSafe", DbType.Int32, IsSafe); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } public List GetListHW_GoodsInfoNewForTM(int CompanyId, string SKU, int IsDH,int IsBH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%' or a.SKU2 like '%'+@SKU+'%' or a.SKU3 like '%'+@SKU+'%' or a.SKU4 like '%'+@SKU+'%' or a.SKU5 like '%'+@SKU+'%' or a.SKU6 like '%'+@SKU+'%' or a.TypeCode like '%'+@SKU+'%' or a.TypeDesc like '%'+@SKU+'%' or b.GoodsName like '%'+@SKU+'%' or b.GoodsCode like '%'+@SKU+'%') and (@IsDH=0 or a.NoGoods=1) and (@IsSafe=0 or a.SafeNum>0) "; string[] templist = SKU.Split(' '); if(templist.Length>1) { tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId WHERE (a.TypeCode LIKE '%" + templist[0] + @"%' OR a.TypeDesc LIKE '%" + templist[0] + @"%' OR b.GoodsCode LIKE '%" + templist[0] + @"%' OR b.GoodsOldCode LIKE '%" + templist[0] + @"%' OR b.GoodsName LIKE '%" + templist[0] + @"%') and (a.TypeCode LIKE '%" + templist[1] + @"%' OR a.TypeDesc LIKE '%" + templist[1] + @"%' OR b.GoodsCode LIKE '%" + templist[1] + @"%' OR b.GoodsOldCode LIKE '%" + templist[1] + @"%' OR b.GoodsName LIKE '%" + templist[1] + @"%') "; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,b.GoodsNum,b.GoodsInNum,b.LeftNum,b.GoodsHJNum2,b.GoodsHJNum3,b.GoodsHJNum4,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,b.GoodsHJNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State,NoGoodsState=case when a.NoGoods=1 then '是' else '否' end,a.Cert,a.UpOff"; if (SKU != "" || IsDH == 1||IsBH==1) { ser.Tables = @"(select * from HW_GoodsInfo a where GoodsId in (" + tsql1 + @"))a left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),GoodsInNum=isnull(SUM(GoodsInNum),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail group by GoodsId)b on a.GoodsId=b.GoodsId"; } else ser.Tables = @"HW_GoodsInfo a left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsInNum=isnull(SUM(GoodsInNum),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail group by GoodsId)b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; 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); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@IsDH", DbType.Int32, IsDH); db.AddInParameter(cmd, "@IsSafe", DbType.Int32, IsBH); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public List GetListHW_GoodsDetail(int StoreId,RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,a.AutoPlan,a.NoGoods,a.MinBuyNum,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),b.Cert,b.JYPrice"; if (StoreId>0) { ser.Tables = @"HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId"; } else ser.Tables = @"HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "DetailId"; 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 static void Delete_GoodsUser(int Id) { string tsql = @" delete from HW_GoodsUser 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 GetListGoodsUser(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.GoodsId,a.UserId,a.ShopId,b.Name,c.ShopName,d.GoodsCode,d.FirstImgUrl,d.GoodsNum"; ser.Tables = @"HW_GoodsUser a inner join jc_userinfo b on a.UserId=b.UserId inner join jc_shop c on a.shopid=c.shopid inner join Hw_GoodsInfo d on a.GoodsId=d.GoodsId "; 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 GetSNGoodsList(int CompanyId) { List list = null; string tsql = @" select GoodsId,GoodsCode,GoodsName,SortName from HW_GoodsInfo where state=1 and companyid=@CompanyID order by sortname "; 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 GetGoodsSPDetail(int GoodsId) { List list = null; string tsql = @" select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.GoodsId=@GoodsId order by a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物明细列表 public List GetGoodsSPDetailForTM(int BuyUserId,int GoodsId, int SupplierId) { List list = null; string tsql = @" if @SupplierId>0 begin select a.DetailId,a.TypeCode,a.TypeDesc,a.SKU1,a.GoodsNum,a.GoodsInNum,a.GoodsPlanNum,a.SafeNum,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0)-isnull(a.SafeNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)+isnull(a.SafeNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price is not null and a.Price>0 then a.Price else b.NowPrice end,b.FirstImgUrl,b.GoodsOldCode,b.GoodsId,GRemark=b.GoodsRemark,b.DeptRemark,b.NoticeDays from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where isnull(b.NoGoods,0)=0 and isnull(a.NoGoods,0)=0 and b.Supplier=@SupplierId and b.GoodsId in (select distinct GoodsId from HW_GoodsDetail where (isnull(GoodsNum,0)+isnull(GoodsInNum,0)-isnull(GoodsPlanNum,0)-isnull(a.SafeNum,0))<0) order by a.GoodsId,a.TypeCode end else if @SupplierId>0 and @BuyUserId>0 begin select a.DetailId,a.TypeCode,a.TypeDesc,a.SKU1,a.GoodsNum,a.GoodsInNum,a.GoodsPlanNum,a.SafeNum,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0)-isnull(a.SafeNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)+isnull(a.SafeNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price is not null and a.Price>0 then a.Price else b.NowPrice end,b.FirstImgUrl,b.GoodsOldCode,b.GoodsId,GRemark=b.GoodsRemark,b.DeptRemark,b.NoticeDays from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join CG_GoodsMate c on b.GoodsId=c.GoodsId where isnull(b.NoGoods,0)=0 and isnull(a.NoGoods,0)=0 and c.BuyerUserId=@BuyUserId and b.Supplier=@SupplierId and b.GoodsId in (select distinct GoodsId from HW_GoodsDetail where (isnull(GoodsNum,0)+isnull(GoodsInNum,0)-isnull(GoodsPlanNum,0)-isnull(a.SafeNum,0))<0) order by a.GoodsId,a.TypeCode end else begin select a.DetailId,a.TypeCode,a.TypeDesc,a.SKU1,a.GoodsNum,a.GoodsInNum,a.GoodsPlanNum,a.SafeNum,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0)-isnull(a.SafeNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)+isnull(a.SafeNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price is not null and a.Price>0 then a.Price else b.NowPrice end,b.FirstImgUrl,b.GoodsOldCode,b.GoodsId,GRemark=b.GoodsRemark,b.DeptRemark,b.NoticeDays from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where isnull(b.NoGoods,0)=0 and isnull(a.NoGoods,0)=0 and a.GoodsId=@GoodsId order by a.TypeCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@BuyUserId", DbType.Int32, BuyUserId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@SupplierId", DbType.Int32, SupplierId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物备注 public int GetNowGoodsRemark(int DetailId,int Days) { string tsql = @" declare @Id int set @Id=0 select top 1 @Id=a.Id from CG_PurchaseGoods a inner join CG_Purchase b on a.ChaseId=b.ChaseId where a.GoodsDetailId=@DetailId and DATEDIFF(day,b.InDate,GETDATE())<@Days select @Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Days", DbType.Int32, Days); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询今天购买过的 public List GetChaseToday(string GoodsIds, DateTime? SDate) { List list = null; string tsql = @" select distinct c.GoodsId 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 a.IsDelete=0 and c.GoodsId in (" + GoodsIds + ") and a.InDate>=@SDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 根据明细ID查询货物 public HW_GoodsSPDetail GetGoodsDetailForTM(int DetailId) { HW_GoodsSPDetail model = null; string tsql = @" SELECT TypeCode,TypeDesc,b.GoodsCode,b.GoodsOldCode FROM [HW_GoodsDetail] a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId WHERE DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); //DataSet ds = db.ExecuteDataSet(cmd); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询货物明细列表根据供应商 public List GetGoodsForSupplier(int SupplierId) { List list = null; string tsql = @" select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId --inner join JC_SupplierGoods c on b.GoodsId=c.GoodsId where b.state=1 and b.Supplier=@SupplierId order by a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SupplierId", DbType.Int32, SupplierId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物明细列表 public List GetGoodsSPDetailNew(int CompanyId,string GoodsCode) { List list = null; string tsql = @" select top 300 a.*,BuyNum=0,b.GoodsCode,b.GoodsName,GoodsLeftNum=a.GoodsNum+a.GoodsInNum-a.GoodsPlanNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or a.SKU1 like '%'+@GoodsCode+'%' or b.GoodsName like '%'+@GoodsCode+'%') order by a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物明细列表 public List GetGoodsSPDetailNew(int CompanyId,int IsLeft, string GoodsCode) { List list = null; string tsql = ""; if (IsLeft == 0) { tsql = @" select top 300 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or a.SKU1 like '%'+@GoodsCode+'%' or b.GoodsName like '%'+@GoodsCode+'%') order by a.SKU1 "; } else { tsql = @" select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or b.GoodsCode=@GoodsCode or a.SKU1 like '%'+@GoodsCode+'%' or b.GoodsName like '%'+@GoodsCode+'%') order by a.SKU1 "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物明细列表 public List GetGoodsSPDetailFromType(int CompanyId,int Type, int IsLeft, string GoodsCode) { List list = null; string tsql = ""; if (IsLeft == 0) { tsql = @" if @Type=1 begin select top 300 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and a.SKU1 like '%'+@GoodsCode+'%' order by a.SKU1 end else if @Type=2 begin select top 300 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.GoodsCode like '%'+@GoodsCode+'%' order by a.SKU1 end else begin select top 300 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price 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 a.SKU1 end "; } else { tsql = @" if @Type=1 begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or a.SKU1 like '%'+@GoodsCode+'%') order by a.SKU1 end else if @Type=2 begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%') order by a.SKU1 end else begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=a.Price from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or b.GoodsName like '%'+@GoodsCode+'%') order by a.SKU1 end "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Type", DbType.Int32, Type); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物明细列表 public List GetGoodsSPDetailFromTypeForTM(int CompanyId, int Type, int IsLeft, string GoodsCode) { List list = null; string tsql = ""; if (IsLeft == 0) { tsql = @" if @Type=1 begin select top 1000 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and a.SKU1 like '%'+@GoodsCode+'%' order by b.GoodsId,a.TypeCode end else if @Type=2 begin select top 1000 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode like '%'+@GoodsCode+'%' or b.GoodsOldCode like '%'+@GoodsCode+'%') order by b.GoodsId,a.TypeCode end else begin select top 300 a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end 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 { tsql = @" if @Type=1 begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or a.SKU1 like '%'+@GoodsCode+'%') order by b.GoodsId,a.TypeCode end else if @Type=2 begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%' or b.GoodsOldCode like '%'+@GoodsCode+'%') order by b.GoodsId,a.TypeCode end else begin select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and (@GoodsCode='' or b.GoodsName 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, "@Type", DbType.Int32, Type); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物明细列表 public List GetGoodsSPDetailForOrder(string OrderIs) { List list = null; string tsql = ""; tsql = @" select a.OrderId,d.GoodsCode,d.GoodsName,c.TypeCode,c.TypeDesc,a.PlatOrderCode,a.JoinOrderCode,b.GoodsNum,BuyNum=b.GoodsNum,FirstImgUrl=case when c.FirstImgUrl is not null and c.FirstImgUrl<>'' then c.FirstImgUrl else d.FirstImgUrl end,Price=case when c.Price is not null then c.Price else d.NowPrice end,c.DetailId,d.GoodsId 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 where isnull(a.IsCG,0)=0 and a.OrderId in (" + OrderIs + ") order by a.PlatOrderCode,a.JoinOrderCode"; 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 GetGoodsSort(int CompanyId) { List list = null; string tsql = @" select * from HW_GoodsSort where IsUse=1 and CompanyId=@CompanyId order by ParentCode,SortNo "; 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 GetGoodsSortOne(int CompanyId) { List list = null; string tsql = @" select * from HW_GoodsSort where IsUse=1 and CompanyId=@CompanyId and ParentId is null order by SortNo "; 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 返回货物分类Model public HW_GoodsSortModel GetSortModelModel(int SortId) { HW_GoodsSortModel model = null; string tsql = "select * from HW_GoodsSort where SortId=@SortId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 保存货物分类 /// /// 保存货物分类 /// public int SaveGoodsSort(HW_GoodsSortModel Model) { string tsql = @" if @SortId>0 begin Update [HW_GoodsSort] set [SortCode]=@SortCode,[ParentId]=@ParentId,[Layer]=@Layer,[SortName]=@SortName,[HGCode]=@HGCode,[EnglishCode]=@EnglishCode,[EnglishName]=@EnglishName,[SortNo]=@SortNo,[IsUse]=@IsUse,[CompanyId]=@CompanyId,[ParentCode]=@ParentCode,[ParentSort]=@ParentSort,BagFee=@BagFee where SortId=@SortId end else begin INSERT INTO [HW_GoodsSort]([SortCode],[ParentId],[Layer],[SortName],[HGCode],[EnglishCode],[EnglishName],[SortNo],[IsUse],[CompanyId],[ParentCode],[ParentSort],BagFee)values(@SortCode,@ParentId,@Layer,@SortName,@HGCode,@EnglishCode,@EnglishName,@SortNo,@IsUse,@CompanyId,@ParentCode,@ParentSort,@BagFee) end select @SortId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortCode", DbType.String, Model.SortCode); db.AddInParameter(cmd, "@ParentId", DbType.Int32, Model.ParentId); db.AddInParameter(cmd, "@Layer", DbType.Int32, Model.Layer); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@EnglishCode", DbType.String, Model.EnglishCode); db.AddInParameter(cmd, "@EnglishName", DbType.String, Model.EnglishName); db.AddInParameter(cmd, "@SortNo", DbType.String, Model.SortNo); db.AddInParameter(cmd, "@IsUse", DbType.Int32, Model.IsUse); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@ParentCode", DbType.String, Model.ParentCode); db.AddInParameter(cmd, "@ParentSort", DbType.String, Model.ParentSort); db.AddInParameter(cmd, "@BagFee", DbType.Decimal, Model.BagFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除分类 public void DeleteGoodsSort(int SortId,int CompanyId) { string tsql = @" update HW_GoodsSort set isuse=0 where SortId=@SortId update HW_GoodsSort set isuse=0 where ParentId=@SortId update HW_GoodsSort set isuse=0 where ParentId in (select @SortId from HW_GoodsSort where isuse=0 and CompanyId=@CompanyId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 验证字母编码 public int IsGoodsEgCode(int CompanyId,int SortId, string EnglishCode, int ParentId) { string tsql = @" if @ParentId=0 begin select count(0) from HW_GoodsSort where IsUse=1 and CompanyId=@CompanyId and EnglishCode=@EnglishCode and SortId<>@SortId and ParentId is null end else begin select count(0) from HW_GoodsSort where IsUse=1 and CompanyId=@CompanyId and EnglishCode=@EnglishCode and SortId<>@SortId and ParentId=@ParentId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, "@EnglishCode", DbType.String, EnglishCode); db.AddInParameter(cmd, "@ParentId", DbType.Int32, ParentId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回货物编号 public HW_GoodsCode GetGoodsCode(int SortId) { HW_GoodsCode model = null; string tsql = @" declare @EnglishCode nvarchar(50),@Num int select @EnglishCode=isnull(ParentCode,'')+EnglishCode from HW_GoodsSort where SortId=@SortId select @Num=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId=@SortId select GoodsCode=@EnglishCode,SortCode=@Num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回货物编号 public HW_GoodsCode GetGoodsCodeNew(int SortId,int CompanyId) { HW_GoodsCode model = null; string tsql = @" declare @EnglishCode nvarchar(50),@Num int select @EnglishCode=isnull(ParentCode,'')+EnglishCode from HW_GoodsSort where SortId=@SortId select @Num=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId in (select distinct SortId from HW_GoodsSort where isnull(ParentCode,'')+EnglishCode=@EnglishCode and CompanyId=@CompanyId) select GoodsCode=@EnglishCode,SortCode=@Num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回货物编号 public HW_GoodsCode GetGoodsCodeForTM(int SortId, int CompanyId) { HW_GoodsCode model = null; string tsql = @" declare @EnglishCode nvarchar(50),@Num int set @Num=0 select @EnglishCode=isnull(ParentCode,'')+EnglishCode from HW_GoodsSort where SortId=@SortId select @Num=isnull(max(GoodsNo),0)+1 from HW_GoodsCode where EnglishCode=@EnglishCode if @Num<=1 begin select @Num=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId in (select distinct SortId from HW_GoodsSort where isnull(ParentCode,'')+EnglishCode=@EnglishCode and CompanyId=@CompanyId) end select GoodsCode=@EnglishCode,SortCode=@Num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回货物明细编号 public string GetDetailCode(int GoodsId) { string tsql = @" select top 1 TypeCode from HW_GoodsDetail where GoodsId=@GoodsId order by DetailId desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); string a=Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证分类能否删除 public int IsSortGoods(int SortId) { string tsql = @" declare @Flag int select @Flag=COUNT(0) from HW_GoodsSort where ParentId=@SortId and IsUse=1 if @Flag=0 begin select @Flag=COUNT(0) from HW_GoodsInfo where State=1 and SortId=@SortId if @Flag>0 begin set @Flag=2 end end else begin set @Flag=1 end select @Flag "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物 /// /// 保存货物 /// public int SaveGoodsInfo(HW_Goods Model) { string tsql = @" if @GoodsId>0 begin Update [HW_GoodsInfo] set [GoodsCode]=@GoodsCode,[GoodsEg]=@GoodsEg,[GoodsOldCode]=@GoodsOldCode,[SortId]=@SortId,[SortName]=@SortName,[SupplierId]=@SupplierId,[GoodsName]=@GoodsName,[GoodsEnglisgName]=@GoodsEnglisgName,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,[InPrice]=@InPrice,[NowPrice]=@NowPrice,[Weight]=@Weight,[WeightUnit]=@WeightUnit,[Solid]=@Solid,[SolidUnit]=@SolidUnit,[Position]=@Position,[InDate]=@InDate,[UpdateDate]=@UpdateDate,[FirstImgUrl]=@FirstImgUrl,[GoodsImageIds]=@GoodsImageIds,[CompanyId]=@CompanyId,[GoodsPlanNum]=@GoodsPlanNum,[GoodsOutNum]=@GoodsOutNum,[GoodsInNum]=@GoodsInNum,[SafeNum]=@SafeNum,[HGCode]=@HGCode,[HGCompanyCode]=@HGCompanyCode,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[AvgTime]=@AvgTime,[State]=@State where GoodsId=@GoodsId end else begin select @GoodsNo=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId=@SortId INSERT INTO [HW_GoodsInfo]([GoodsCode],[GoodsEg],[GoodsNo],[GoodsOldCode],[SortId],[SortName],[SupplierId],[GoodsName],[GoodsEnglisgName],[GoodsNum],[GoodsLockNum],[InPrice],[NowPrice],[Weight],[WeightUnit],[Solid],[SolidUnit],[Position],[InDate],[UpdateDate],[FirstImgUrl],[GoodsImageIds],[CompanyId],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[SafeNum],[HGCode],[HGCompanyCode],[UpdateName],[GoodsRemark],[AutoPlan],[NoGoods],[AvgTime],[State])values(@GoodsCode,@GoodsEg,@GoodsNo,@GoodsOldCode,@SortId,@SortName,@SupplierId,@GoodsName,@GoodsEnglisgName,@GoodsNum,@GoodsLockNum,@InPrice,@NowPrice,@Weight,@WeightUnit,@Solid,@SolidUnit,@Position,@InDate,@UpdateDate,@FirstImgUrl,@GoodsImageIds,@CompanyId,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@SafeNum,@HGCode,@HGCompanyCode,@UpdateName,@GoodsRemark,@AutoPlan,@NoGoods,@AvgTime,@State) set @GoodsId=@@IDENTITY end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsOldCode", DbType.String, Model.GoodsOldCode); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SupplierId", DbType.String, Model.SupplierId); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsEnglisgName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, Model.NowPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@WeightUnit", DbType.String, Model.WeightUnit); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@SolidUnit", DbType.String, Model.SolidUnit); db.AddInParameter(cmd, "@Position", DbType.Int32, Model.Position); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@HGCompanyCode", DbType.String, Model.HGCompanyCode); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物 /// /// 保存货物 /// public int SaveGoodsInfoForTM(HW_Goods Model) { string tsql = @" if @GoodsId>0 begin Update [HW_GoodsInfo] set GoodsOldCode=@GoodsOldCode,[SupplierId]=@SupplierId,Supplier=@Supplier,[GoodsName]=@GoodsName,[GoodsEnglisgName]=@GoodsEnglisgName,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,[InPrice]=@InPrice,[NowPrice]=@NowPrice,[Weight]=@Weight,[Weight2]=@Weight2,[WeightUnit]=@WeightUnit,[Solid]=@Solid,[SolidUnit]=@SolidUnit,[Position]=@Position,[UpdateDate]=@UpdateDate,[FirstImgUrl]=@FirstImgUrl,[GoodsImageIds]=@GoodsImageIds,[CompanyId]=@CompanyId,[GoodsPlanNum]=@GoodsPlanNum,[GoodsOutNum]=@GoodsOutNum,[GoodsInNum]=@GoodsInNum,[SafeNum]=@SafeNum,[HGCode]=@HGCode,[HGCompanyCode]=@HGCompanyCode,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[AvgTime]=@AvgTime,[State]=@State,[DeptRemark]=@DeptRemark,[NoticeDays]=@NoticeDays,[GoodsInfo]=@GoodsInfo,[DefaultCity]=@DefaultCity,[PageFee]=@PageFee,[PostPrice]=@PostPrice,GoodsSupplyCode=@GoodsSupplyCode,BGPrice=@BGPrice,NoticeShop=@NoticeShop,[NetWeight]=@NetWeight,[Long]=@Long,[Width]=@Width,[Height]=@Height,[Long2]=@Long2,[Width2]=@Width2,[Height2]=@Height2,[BoxRate]=@BoxRate,Cert=@Cert,FeeRate=@FeeRate,JYPrice=@JYPrice where GoodsId=@GoodsId end else begin --select @GoodsNo=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId=@SortId INSERT INTO [HW_GoodsInfo]([GoodsCode],[GoodsEg],[GoodsNo],[GoodsOldCode],[SortId],[SortName],[SupplierId],[GoodsName],[GoodsEnglisgName],[GoodsNum],[GoodsLockNum],[InPrice],[NowPrice],[Weight],[WeightUnit],[Solid],[SolidUnit],[Position],[InDate],[UpdateDate],[FirstImgUrl],[GoodsImageIds],[CompanyId],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[SafeNum],[HGCode],[HGCompanyCode],[UpdateName],[GoodsRemark],[AutoPlan],[NoGoods],[AvgTime],[State],[DeptRemark],[NoticeDays],[GoodsInfo],[DefaultCity],[PageFee],[PostPrice],GoodsSupplyCode,BGPrice,NoticeShop,[NetWeight],[Long],[Width],[Height],[BoxRate],Cert,FeeRate,JYPrice)values(@GoodsCode,@GoodsEg,@GoodsNo,@GoodsOldCode,@SortId,@SortName,@SupplierId,@GoodsName,@GoodsEnglisgName,@GoodsNum,@GoodsLockNum,@InPrice,@NowPrice,@Weight,@WeightUnit,@Solid,@SolidUnit,@Position,@InDate,@UpdateDate,@FirstImgUrl,@GoodsImageIds,@CompanyId,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@SafeNum,@HGCode,@HGCompanyCode,@UpdateName,@GoodsRemark,@AutoPlan,@NoGoods,@AvgTime,@State,@DeptRemark,@NoticeDays,@GoodsInfo,@DefaultCity,@PageFee,@PostPrice,@GoodsSupplyCode,@BGPrice,@NoticeShop,@NetWeight,@Long,@Width,@Height,@BoxRate,@Cert,@FeeRate,@JYPrice) set @GoodsId=SCOPE_IDENTITY() update XP_GoodsSelect set GoodsCode=@GoodsCode,IsAdd=1 where Id=@XPId INSERT INTO [HW_GoodsCode]([EnglishCode],[GoodsNo]) values(@GoodsEg,@GoodsNo) end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsOldCode", DbType.String, Model.GoodsOldCode); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SupplierId", DbType.String, Model.SupplierId); db.AddInParameter(cmd, "@Supplier", DbType.Int32, Model.Supplier); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsEnglisgName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, Model.NowPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@WeightUnit", DbType.String, Model.WeightUnit); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@SolidUnit", DbType.String, Model.SolidUnit); db.AddInParameter(cmd, "@Position", DbType.Int32, Model.Position); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@HGCompanyCode", DbType.String, Model.HGCompanyCode); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@NoticeDays", DbType.Int32, Model.NoticeDays); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, Model.GoodsInfo); db.AddInParameter(cmd, "@DefaultCity", DbType.String, Model.DefaultCity); db.AddInParameter(cmd, "@PageFee", DbType.Decimal, Model.PageFee); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@GoodsSupplyCode", DbType.String, Model.GoodsSupplyCode); db.AddInParameter(cmd, "@BGPrice", DbType.Decimal, Model.BGPrice); db.AddInParameter(cmd, "@NoticeShop", DbType.String, Model.NoticeShop); db.AddInParameter(cmd, "@XPId", DbType.Int32, Model.XPId); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, Model.NetWeight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Long2", DbType.Decimal, Model.Long2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, Model.Width2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, Model.Height2); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, Model.BoxRate); db.AddInParameter(cmd, "@Cert", DbType.String, Model.Cert); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@JYPrice", DbType.Decimal, Model.JYPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物 /// /// 保存货物 /// public int SaveGoodsInfoForHWC(HW_Goods Model) { string tsql = @" select top 1 @SortId=SortId from HW_GoodsSort where SortName=@SortName and CompanyId=@CompanyId if @SortId=0 begin INSERT INTO [dbo].[HW_GoodsSort] ([SortCode] ,[ParentId] ,[Layer] ,[SortName] ,[EnglishCode] ,[EnglishName] ,[SortNo] ,[IsUse] ,[CompanyId]) values(0,null,1,@SortName,'O','O',1,1,@CompanyId) set @SortId=SCOPE_IDENTITY() end if @GoodsId>0 begin Update [HW_GoodsInfo] set [SupplierId]=@SupplierId,Supplier=@Supplier,[GoodsName]=@GoodsName,[GoodsEnglisgName]=@GoodsEnglisgName,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,[InPrice]=@InPrice,[NowPrice]=@NowPrice,[Weight]=@Weight,[Weight2]=@Weight2,[WeightUnit]=@WeightUnit,[Solid]=@Solid,[SolidUnit]=@SolidUnit,[Position]=@Position,[UpdateDate]=@UpdateDate,[FirstImgUrl]=@FirstImgUrl,[GoodsImageIds]=@GoodsImageIds,[CompanyId]=@CompanyId,[GoodsPlanNum]=@GoodsPlanNum,[GoodsOutNum]=@GoodsOutNum,[GoodsInNum]=@GoodsInNum,[SafeNum]=@SafeNum,[HGCode]=@HGCode,[HGCompanyCode]=@HGCompanyCode,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[AvgTime]=@AvgTime,[State]=@State,[DeptRemark]=@DeptRemark,[NoticeDays]=@NoticeDays,[GoodsInfo]=@GoodsInfo,[DefaultCity]=@DefaultCity,[PageFee]=@PageFee,[PostPrice]=@PostPrice,GoodsSupplyCode=@GoodsSupplyCode,BGPrice=@BGPrice,NoticeShop=@NoticeShop,[NetWeight]=@NetWeight,[Long]=@Long,[Width]=@Width,[Height]=@Height,[Long2]=@Long2,[Width2]=@Width2,[Height2]=@Height2,[BoxRate]=@BoxRate,Cert=@Cert,FeeRate=@FeeRate,JYPrice=@JYPrice where GoodsId=@GoodsId end else begin INSERT INTO [HW_GoodsInfo]([GoodsCode],[GoodsEg],[GoodsNo],[GoodsOldCode],[SortId],[SortName],[SupplierId],[GoodsName],[GoodsEnglisgName],[GoodsNum],[GoodsLockNum],[InPrice],[NowPrice],[Weight],[WeightUnit],[Solid],[SolidUnit],[Position],[InDate],[UpdateDate],[FirstImgUrl],[GoodsImageIds],[CompanyId],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[SafeNum],[HGCode],[HGCompanyCode],[UpdateName],[GoodsRemark],[AutoPlan],[NoGoods],[AvgTime],[State],[DeptRemark],[NoticeDays],[GoodsInfo],[DefaultCity],[PageFee],[PostPrice],GoodsSupplyCode,BGPrice,NoticeShop,[NetWeight],[Long],[Width],[Height],[BoxRate],Cert,FeeRate,JYPrice)values(@GoodsCode,@GoodsEg,@GoodsNo,@GoodsOldCode,@SortId,@SortName,@SupplierId,@GoodsName,@GoodsEnglisgName,@GoodsNum,@GoodsLockNum,@InPrice,@NowPrice,@Weight,@WeightUnit,@Solid,@SolidUnit,@Position,@InDate,@UpdateDate,@FirstImgUrl,@GoodsImageIds,@CompanyId,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@SafeNum,@HGCode,@HGCompanyCode,@UpdateName,@GoodsRemark,@AutoPlan,@NoGoods,@AvgTime,@State,@DeptRemark,@NoticeDays,@GoodsInfo,@DefaultCity,@PageFee,@PostPrice,@GoodsSupplyCode,@BGPrice,@NoticeShop,@NetWeight,@Long,@Width,@Height,@BoxRate,@Cert,@FeeRate,@JYPrice) set @GoodsId=SCOPE_IDENTITY() end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsOldCode", DbType.String, Model.GoodsOldCode); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SupplierId", DbType.String, Model.SupplierId); db.AddInParameter(cmd, "@Supplier", DbType.Int32, Model.Supplier); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsEnglisgName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, Model.NowPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@WeightUnit", DbType.String, Model.WeightUnit); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@SolidUnit", DbType.String, Model.SolidUnit); db.AddInParameter(cmd, "@Position", DbType.Int32, Model.Position); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@HGCompanyCode", DbType.String, Model.HGCompanyCode); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@NoticeDays", DbType.Int32, Model.NoticeDays); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, Model.GoodsInfo); db.AddInParameter(cmd, "@DefaultCity", DbType.String, Model.DefaultCity); db.AddInParameter(cmd, "@PageFee", DbType.Decimal, Model.PageFee); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@GoodsSupplyCode", DbType.String, Model.GoodsSupplyCode); db.AddInParameter(cmd, "@BGPrice", DbType.Decimal, Model.BGPrice); db.AddInParameter(cmd, "@NoticeShop", DbType.String, Model.NoticeShop); db.AddInParameter(cmd, "@XPId", DbType.Int32, Model.XPId); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, Model.NetWeight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Long2", DbType.Decimal, Model.Long2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, Model.Width2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, Model.Height2); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, Model.BoxRate); db.AddInParameter(cmd, "@Cert", DbType.String, Model.Cert); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@JYPrice", DbType.Decimal, Model.JYPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物编号 public int IsGoodsCode(int CompanyId, int GoodsId, string GoodsCode) { string tsql = @" select count(0) from HW_GoodsInfo where state=1 and CompanyId=@CompanyId and GoodsId<>@GoodsId and GoodsCode=@GoodsCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物编号 public int GetGoodsCodeId(int CompanyId, string GoodsCode) { string tsql = @" declare @GoodsId int set @GoodsId=0 select top 1 @GoodsId=GoodsId from HW_GoodsInfo where state=1 and CompanyId=@CompanyId and GoodsCode=@GoodsCode select GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证选品 public int IsGoodsXP(int XPId) { string tsql = @" select count(0) from XP_GoodsSelect where Id=@XPId and IsAdd=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@XPId", DbType.Int32, XPId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物编号 public static int GetGoodsId(int CompanyId, string GoodsCode) { string tsql = @" declare @GoodsId int set @GoodsId=0 select top 1 @GoodsId=GoodsId from HW_GoodsInfo where state=1 and CompanyId=@CompanyId and GoodsId<>@GoodsId and (GoodsCode=@GoodsCode or GoodsOldCode=@GoodsCode) select GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物sku public int IsGoodsSKU(int CompanyId,int DetailId, string SKU) { string tsql = @" select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and (a.SKU1=@SKU or a.SKU2=@SKU or a.SKU3=@SKU or a.SKU4=@SKU or a.SKU4=@SKU) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物sku public string IsSKU(int CompanyId, int DetailId, string SKU1, string SKU2, string SKU3, string SKU4, string SKU5, string SKU6, string SKU7, string SKU8) { string tsql = @" declare @Mess nvarchar(500) set @Mess='' if @SKU1<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU1=@SKU1)>0 begin set @Mess=@Mess+@SKU1+'已经存在'; end if @SKU2<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU2=@SKU2)>0 begin set @Mess=@Mess+@SKU2+'已经存在'; end if @SKU3<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU3=@SKU3)>0 begin set @Mess=@Mess+@SKU3+'已经存在'; end if @SKU4<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU4=@SKU4)>0 begin set @Mess=@Mess+@SKU4+'已经存在'; end if @SKU5<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU5=@SKU5)>0 begin set @Mess=@Mess+@SKU5+'已经存在'; end if @SKU6<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU6=@SKU6)>0 begin set @Mess=@Mess+@SKU6+'已经存在'; end if @SKU7<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU7=@SKU7)>0 begin set @Mess=@Mess+@SKU7+'已经存在'; end if @SKU8<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.State=1 and a.DetailId<>@DetailId and a.SKU8=@SKU8)>0 begin set @Mess=@Mess+@SKU8+'已经存在'; end select @Mess "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@SKU1", DbType.String, SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, SKU8); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物sku public string IsSKU2( int DetailId, string SKU1, string SKU2, string SKU3, string SKU4, string SKU5, string SKU6, string SKU7, string SKU8,int skuid) { string tsql = @" declare @Mess nvarchar(500) set @Mess='' if @SKU1<>'' and "+skuid+@"=1 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU1=@SKU1)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU1,'')='')=0) begin set @Mess=@Mess+@SKU1+'已经存在'; end if @SKU2<>'' and " + skuid + @"=2 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU2=@SKU2)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU2,'')='')=0) begin set @Mess=@Mess+@SKU2+'已经存在'; end if @SKU3<>'' and " + skuid + @"=3 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU3=@SKU3)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU3,'')='')=0) begin set @Mess=@Mess+@SKU3+'已经存在'; end if @SKU4<>'' and " + skuid + @"=4 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU4=@SKU4)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU4,'')='')=0) begin set @Mess=@Mess+@SKU4+'已经存在'; end if @SKU5<>'' and " + skuid + @"=5 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU5=@SKU5)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU5,'')='')=0) begin set @Mess=@Mess+@SKU5+'已经存在'; end if @SKU6<>'' and " + skuid + @"=6 and ((select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU6=@SKU6)>0 or (select count(0) from HW_GoodsDetail where DetailId=@DetailId and ISNULL(SKU6,'')='')=0) begin set @Mess=@Mess+@SKU6+'已经存在'; end if @SKU7<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU7=@SKU7)>0 begin set @Mess=@Mess+@SKU7+'已经存在'; end if @SKU8<>'' and (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.State=1 and a.DetailId<>@DetailId and a.SKU8=@SKU8)>0 begin set @Mess=@Mess+@SKU8+'已经存在'; end select @Mess "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@SKU1", DbType.String, SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, SKU8); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证货物明细 public string IsGoodDetail(string GoodsCodeA, string GoodsCodeB, string GoodsDetailA, string GoodsDetailB) { string tsql = @" declare @Mess nvarchar(500) set @Mess='' if (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.TypeCode='"+GoodsDetailA+@"' AND b.GoodsCode='"+GoodsCodeA+@"')=0 begin set @Mess=@Mess+'"+GoodsCodeA+"-"+GoodsDetailA+@"+不存在'; end if (select count(0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.TypeCode='" + GoodsDetailB + @"' AND b.GoodsCode='" + GoodsCodeB + @"')=0 begin set @Mess=@Mess+'" + GoodsCodeB + "-" + GoodsDetailB + @"+不存在'; end select @Mess "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物明细ID public int GoodDetail(string GoodsCode, string GoodsDetail) { string tsql = @" select DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.TypeCode='" + GoodsDetail + @"' AND b.GoodsCode='" + GoodsCode + @"' "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物ID public int GetGoodID(string GoodsCode) { string tsql = @" SELECT GoodsId FROM dbo.HW_GoodsInfo where GoodsCode='" + GoodsCode + @"' "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 货物明细合并 public string ChangeGoodDetail(int detailA, int detailB) { try { string tsql = @" UPDATE dbo.CG_PurchaseGoods SET GoodsDetailId='" + detailA + @"' WHERE GoodsDetailId='" + detailB + @"' UPDATE dbo.DT_OrderGoods SET DetailId='" + detailA + @"' WHERE DetailId='" + detailB + @"' UPDATE dbo.DT_OrderGoodsChange SET NowDetailId='" + detailA + @"' WHERE NowDetailId='" + detailB + @"' UPDATE dbo.DT_OrderGoodsChange SET OldDetailId='" + detailA + @"' WHERE OldDetailId='" + detailB + @"' UPDATE dbo.HW_GoodsInDetail SET DetailId='" + detailA + @"' WHERE DetailId='" + detailB + @"' UPDATE dbo.HW_GoodsInRecordDetail SET DetailId='" + detailA + @"' WHERE DetailId='" + detailB + @"' UPDATE dbo.HW_GoodsOutDetail SET DetailId='" + detailA + @"' WHERE DetailId='" + detailB + @"' "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteScalar(cmd); return ""; } catch { return "更新失败!"; } } #endregion #region 保存货物明细 /// /// 保存货物明细 /// public int SaveGoodsDetail(HW_GoodsDetail Model) { string tsql = @" if @DetailId>0 begin Update [HW_GoodsDetail] set [GoodsId]=@GoodsId,[TypeCode]=@TypeCode,[TypeDesc]=@TypeDesc,[SKU1]=@SKU1,[SKU2]=@SKU2,[SKU3]=@SKU3,[SKU4]=@SKU4,[SKU5]=@SKU5,[SKU6]=@SKU6,[SKU7]=@SKU7,[SKU8]=@SKU8,[Weight]=@Weight,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[MinBuyNum]=@MinBuyNum,[Price]=@Price,[GoodsImageIds]=@GoodsImageIds,[FirstImgUrl]=@FirstImgUrl,[UpdateDate]=@UpdateDate,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[SaleDays]=@SaleDays,[AvgTime]=@AvgTime,[SafeNum]=@SafeNum,[Solid]=@Solid where DetailId=@DetailId end else begin INSERT INTO [HW_GoodsDetail]([GoodsId],[TypeCode],[TypeDesc],[SKU1],[SKU2],[SKU3],[SKU4],[SKU5],[SKU6],[SKU7],[SKU8],[Weight],[AutoPlan],[NoGoods],[MinBuyNum],[GoodsNum],[GoodsLockNum],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[Price],[GoodsImageIds],[FirstImgUrl],[UpdateDate],[UpdateName],[GoodsRemark],[SaleDays],[AvgTime],[SafeNum],[Solid])values(@GoodsId,@TypeCode,@TypeDesc,@SKU1,@SKU2,@SKU3,@SKU4,@SKU5,@SKU6,@SKU7,@SKU8,@Weight,@AutoPlan,@NoGoods,@MinBuyNum,@GoodsNum,@GoodsLockNum,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@Price,@GoodsImageIds,@FirstImgUrl,@UpdateDate,@UpdateName,@GoodsRemark,@SaleDays,@AvgTime,@SafeNum,@Solid) set @DetailId=@@IDENTITY end select @DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, Model.SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, Model.SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, Model.SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, Model.SKU8); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@MinBuyNum", DbType.Int32, Model.MinBuyNum); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@SaleDays", DbType.Decimal, Model.SaleDays); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物明细 /// /// 保存货物明细 /// public int SaveGoodsDetail2(HW_GoodsDetail Model) { string tsql = @" if @DetailId>0 begin Update [HW_GoodsDetail] set [GoodsId]=@GoodsId,[TypeCode]=@TypeCode,[TypeDesc]=@TypeDesc,[SKU1]=@SKU1,[SKU2]=@SKU2,[SKU3]=@SKU3,[SKU4]=@SKU4,[SKU5]=@SKU5,[SKU6]=@SKU6,[SKU7]=@SKU7,[SKU8]=@SKU8,[Weight]=@Weight,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[MinBuyNum]=@MinBuyNum,[Price]=@Price,[GoodsImageIds]=@GoodsImageIds,[FirstImgUrl]=@FirstImgUrl,[UpdateDate]=@UpdateDate,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[SaleDays]=@SaleDays,[AvgTime]=@AvgTime,[SafeNum]=@SafeNum,[Solid]=@Solid where DetailId=@DetailId end else begin INSERT INTO [HW_GoodsDetail]([GoodsId],[TypeCode],[TypeDesc],[SKU1],[SKU2],[SKU3],[SKU4],[SKU5],[SKU6],[SKU7],[SKU8],[Weight],[AutoPlan],[NoGoods],[MinBuyNum],[GoodsNum],[GoodsLockNum],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[Price],[GoodsImageIds],[FirstImgUrl],[UpdateDate],[UpdateName],[GoodsRemark],[SaleDays],[AvgTime],[SafeNum],[Solid])values(@GoodsId,@TypeCode,@TypeDesc,@SKU1,@SKU2,@SKU3,@SKU4,@SKU5,@SKU6,@SKU7,@SKU8,@Weight,@AutoPlan,@NoGoods,@MinBuyNum,@GoodsNum,@GoodsLockNum,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@Price,@GoodsImageIds,@FirstImgUrl,@UpdateDate,@UpdateName,@GoodsRemark,@SaleDays,@AvgTime,@SafeNum,@Solid) set @DetailId=@@IDENTITY end select @DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, Model.SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, Model.SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, Model.SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, Model.SKU8); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@MinBuyNum", DbType.Int32, Model.MinBuyNum); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@SaleDays", DbType.Decimal, Model.SaleDays); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物SKU public int SaveGoodsDetail2(HW_GoodsDetail Model,int skuid) { string tsql = @" if @DetailId>0 begin if " + skuid + @"=1 begin Update [HW_GoodsDetail] set [SKU1]=@SKU1 where DetailId=@DetailId end if " + skuid + @"=2 begin Update [HW_GoodsDetail] set [SKU2]=@SKU2 where DetailId=@DetailId end if " + skuid + @"=3 begin Update [HW_GoodsDetail] set [SKU3]=@SKU3 where DetailId=@DetailId end if " + skuid + @"=4 begin Update [HW_GoodsDetail] set [SKU4]=@SKU4 where DetailId=@DetailId end if " + skuid + @"=5 begin Update [HW_GoodsDetail] set [SKU5]=@SKU5 where DetailId=@DetailId end if " + skuid + @"=6 begin Update [HW_GoodsDetail] set [SKU6]=@SKU6 where DetailId=@DetailId end end select @DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, Model.SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, Model.SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, Model.SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, Model.SKU8); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物链接 /// /// 保存货物链接 /// public int SaveBuyLink(HW_BuyLink Model) { string tsql = @" if @LinkId>0 begin Update [HW_BuyLink] set [GoodsId]=@GoodsId,[LinkUrl]=@LinkUrl,[LinkName]=@LinkName,[LinkDesc]=@LinkDesc where LinkId=@LinkId end else begin INSERT INTO [HW_BuyLink]([GoodsId],[LinkUrl],[LinkName],[LinkDesc])values(@GoodsId,@LinkUrl,@LinkName,@LinkDesc) set @LinkId=@@IDENTITY end select @LinkId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@LinkId", DbType.Int32, Model.LinkId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@LinkUrl", DbType.String, Model.LinkUrl); db.AddInParameter(cmd, "@LinkName", DbType.String, Model.LinkName); db.AddInParameter(cmd, "@LinkDesc", DbType.String, Model.LinkDesc); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回货物Model public HW_Goods GetGoodsModel(int GoodsId) { HW_Goods model = null; string tsql = "select * from HW_GoodsInfo where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回货物明细 public string GetGoodsDetailTypeDesc(int GoodsId,string TypeCode) { string tsql = "select top 1 TypeDesc from HW_GoodsDetail where GoodsId=@GoodsId and TypeCode=@TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@TypeCode", DbType.String, TypeCode); string a=Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物明细列表 public List GetGoodsDetail(int GoodsId) { List list = null; string tsql = @" select *,LeftNum=GoodsNum+GoodsInNum-GoodsPlanNum,NoGoodsState=case when NoGoods=1 then '是' else '否' end from HW_GoodsDetail where GoodsId=@GoodsId ORDER BY TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 根据明细查询货物 public List GetGoodsFromDetail(string SKU,int IsSafe,int CompanyId) { List list = null; string tsql = @" select distinct a.GoodsId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%') and (@IsSafe=0 or a.SafeNum>=a.GoodsNum) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@IsSafe", DbType.Int32, IsSafe); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物明细 public List GetGoodsDetailList(string GoodsIds) { List list = null; string tsql = @" select a.*,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.GoodsId in (" + GoodsIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsIds", DbType.String, GoodsIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物库位列表 public List GetGoodsPostion(int GoodsId) { List list = null; string tsql = @" select * from HW_GoodsPostion where DetailId in (select DetailId from HW_GoodsDetail where GoodsId=@GoodsId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物链接列表 public List GetGoodsBuyLink(int GoodsId) { List list = null; string tsql = @" select * from HW_BuyLink where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存货物所属仓库 /// /// 保存货物所属仓库 /// public int SavePostion(HW_GoodsPostion Model) { string tsql = @" if @Id>0 begin Update [HW_GoodsPostion] set [DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,State=1 where Id=@Id end else begin INSERT INTO [HW_GoodsPostion]([DetailId],[StoreId],[PostionId],[GoodsNum],[GoodsLockNum],State)values(@DetailId,@StoreId,@PostionId,@GoodsNum,@GoodsLockNum,1) set @Id=@@IDENTITY end if @State=-1 begin delete from HW_GoodsPostion where DetailId=@DetailId and state=0 end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 设置删除状态所属仓库 /// /// 设置删除状态所属仓库 /// public int SetPostionState(int DetailId) { string tsql = @" update HW_GoodsPostion set State=0 where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物上架店铺 public List GetGoodsShop(int GoodsId) { List list = null; string tsql = @" select * from HW_Shop a where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 删除货物明细 public int DeleteGoodsInfo(int GoodsId) { string tsql = @" if(select COUNT(0) 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 (b.GoodsNum>0 or b.GoodsPlanNum>0 or b.GoodsInNum>0) AND a.GoodsId=@GoodsId)=0 begin delete from HW_GoodsDetail where GoodsId=@GoodsId delete from HW_GoodsInfo where GoodsId=@GoodsId select 0 end else begin select 1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除货物明细 public void DeleteGoodsDetail(int DetailId) { string tsql = @" delete from HW_GoodsDetail where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.ExecuteNonQuery(cmd); } #endregion #region 删除货物明细 public int DeleteGoodsDetail2(int DetailId) { string tsql = @" declare @Id int set @Id=0 select top 1 @Id=DetailId from HW_GoodsDetail where DetailId=@DetailId and (GoodsNum>0 or GoodsInNum>0 or GoodsPlanNum>0) if @Id=0 begin select top 1 @Id=Id from DT_OrderGoods where DetailId=@DetailId end if @Id=0 begin select top 1 @Id=Id from CG_PurchaseGoods where GoodsDetailId=@DetailId end if @Id=0 begin delete from HW_GoodsDetail where DetailId=@DetailId end select Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除货物明细 public int DeleteGoodsDetail3(int DetailId) { string tsql = @" declare @Id int set @Id=0 select top 1 @Id=DetailId from HW_GoodsDetail where DetailId=@DetailId and (GoodsNum>0 or GoodsInNum>0 or GoodsPlanNum>0) if @Id=0 begin delete from HW_GoodsDetail where DetailId=@DetailId end select Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除货物明细 public void DeleteBuyLink(int LinkId) { string tsql = @" delete from HW_BuyLink where LinkId=@LinkId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@LinkId", DbType.Int32, LinkId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物信息 public void UpdateGoodsInfo(int GoodsId,string GoodsInfo) { string tsql = @" update HW_GoodsInfo set GoodsInfo=@GoodsInfo where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, GoodsInfo); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物信息 public void UpdateGoodsInfo(int GoodsId, string GoodsInfo, string UpdateName) { string tsql = @" update HW_GoodsInfo set GoodsInfo=@GoodsInfo,UpdateName=@UpdateName where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, GoodsInfo); db.AddInParameter(cmd, "@UpdateName", DbType.String, UpdateName); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物最新价格 public void UpdateGoodsPrice(int GoodsId, decimal? NowPrice) { string tsql = @" update HW_GoodsInfo set NowPrice=@NowPrice where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, NowPrice); db.ExecuteNonQuery(cmd); } #endregion #region 保存删除货物店铺 public int SaveShop(HW_Shop Model) { string tsql = @" if @Id>0 begin Update [HW_Shop] set [GoodsId]=@GoodsId,[ShopId]=@ShopId where Id=@Id end else begin INSERT INTO [HW_Shop]([GoodsId],[ShopId])values(@GoodsId,@ShopId) 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, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物店铺 public int SaveShopForTM(HW_Shop Model) { string tsql = @" set @Id=0 select top 1 @Id=Id from HW_Shop where [GoodsId]=@GoodsId and [ShopId]=@ShopId if @Id=0 begin INSERT INTO [HW_Shop]([GoodsId],[ShopId],InName,InDate)values(@GoodsId,@ShopId,@InName,getdate()) 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, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除货物店铺 public void DeleteShop(int GoodsId) { string tsql = @" delete from HW_Shop where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 删除货物店铺 public void DeleteShopForTM(string Ids,int GoodsId) { string tsql = ""; if (Ids != "") { tsql = @"delete from HW_Shop where GoodsId=@GoodsId and Id not in ("+Ids+")"; } else tsql = @"delete from HW_Shop where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 获取分类名称 public string GetGoodsSortName(int SortId) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("[GetSortName]"); db.AddInParameter(cmd, "@SortId", DbType.Int32, SortId); string name=Convert.ToString(db.ExecuteScalar(cmd)); return name; } #endregion #region 查询仓库货物 public List GetCKGoodsList(int StoreId, int PostionId,string Name) { List list = null; string tsql = @" select a.InId,a.DetailId,c.GoodsName,c.GoodsCode,b.SKU1,b.TypeDesc,b.TypeCode,GoodsNum=KCNum,d.PostionCode,a.InDate from HW_GoodsInDetail 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 where a.StoreId=@StoreId and a.OrderGoodsId=0 and KCNum>0 and (@PostionId=0 or a.PostionId=@PostionId) and (@Name='' or c.goodsname like '%'+@Name+'%' or c.goodscode like '%'+@Name+'%' or b.TypeDesc like '%'+@Name+'%' or b.SKU1 like '%'+@Name+'%') order by a.DetailId,b.SKU1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@Name", DbType.String, Name); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 移库仓库货物 public void MoveCKGoods(int OldStoreId, int OldPostionId, int InId, int NewStoreId, int NewPostionId) { string tsql = @" update HW_GoodsInDetail set StoreId=@NewStoreId,PostionId=@NewPostionId where InId=@InId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OldStoreId", DbType.Int32, OldStoreId); db.AddInParameter(cmd, "@OldPostionId", DbType.Int32, OldPostionId); db.AddInParameter(cmd, "@InId", DbType.Int32, InId); db.AddInParameter(cmd, "@NewStoreId", DbType.Int32, NewStoreId); db.AddInParameter(cmd, "@NewPostionId", DbType.Int32, NewPostionId); db.ExecuteNonQuery(cmd); } #endregion #region 查询货物初始入库库位列表 public List GetFirstGoodsInList(int GoodsId) { List list = null; string tsql = @" select * from HW_GoodsInList where ChaseId=0 and DetailId in (select DetailId from HW_GoodsDetail where GoodsId=@GoodsId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存货物入库批次 public int SaveGoodsInList(HW_GoodsInList Model) { string tsql = @" if @InId>0 begin Update [HW_GoodsInList] set [DetailId]=@DetailId,[ChaseId]=@ChaseId,[Price]=@Price,[GoodsNum]=@GoodsNum,[PostPrice]=@PostPrice,[StoreId]=@StoreId,[PostionId]=@PostionId,[InDate]=@InDate,[InUserId]=@InUserId where InId=@InId end else begin INSERT INTO [HW_GoodsInList]([DetailId],[ChaseId],[Price],[GoodsNum],[GoodsLockNum],[PostPrice],[StoreId],[PostionId],[InDate],[InUserId],GoodsOldNum)values(@DetailId,@ChaseId,@Price,@GoodsNum,@GoodsLockNum,@PostPrice,@StoreId,@PostionId,@InDate,@InUserId,@GoodsNum) set @InId=SCOPE_IDENTITY() end select @InId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物入库批次明细 public void SaveGoodsInListNew(HW_GoodsInList Model) { string tsql = @" --while @GoodsNum>0 if @GoodsNum>0 begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[UpDateTime],KCNum)values(@DetailId,@ChaseId,@StoreId,@PostionId,@Price,@PostPrice,@InDate,@InUserId,0,null,@GoodsNum) --set @GoodsNum=@GoodsNum-1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 保存货物出库记录 public int SaveGoodsOut(HW_GoodsOutRecord Model) { string tsql = @" if @OutId>0 begin Update [HW_GoodsOutList] set [OutCode]=@OutCode,[OutReason]=@OutReason,[Remark]=@Remark,[OutNum]=@OutNum,[InUserId]=@InUserId,[InDate]=@InDate,[InName]=@InName,[CompanyId]=@CompanyId where OutId=@OutId end else begin INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId])values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId) set @OutId=SCOPE_IDENTITY() end select @OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物出库记录 public int SaveGoodsOutForTM(HW_GoodsOutRecord Model) { string tsql = @" if @OutId>0 begin Update [HW_GoodsOutList] set [OutCode]=@OutCode,[OutReason]=@OutReason,[Remark]=@Remark,[OutNum]=@OutNum,[InUserId]=@InUserId,[InDate]=@InDate,[InName]=@InName,[CompanyId]=@CompanyId,IsDelete=@IsDelete,OrderId=@OrderId where OutId=@OutId end else begin INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId)values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId) set @OutId=SCOPE_IDENTITY() end select @OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单打印 public int UpdateOrderPrint(HW_GoodsOutRecord Model) { string tsql = @" INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId) values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId) set @OutId=SCOPE_IDENTITY() INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId]) select @OutId,GoodsNum,DetailId,0,0 from DT_OrderGoods where OrderId=@OrderId update a set a.CKDetailId=d.Id from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join HW_GoodsOutList c on b.OrderId=c.OrderId inner join HW_GoodsOutDetail d on c.OutId=d.OutId and b.DetailId=d.DetailId where b.OrderId=@OrderId update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update b set b.GoodsPlanNum=b.GoodsPlanNum-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"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单打印 public int UpdateOrderPrint22(HW_GoodsOutRecord Model) { string tsql = @" INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId) values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId) set @OutId=SCOPE_IDENTITY() INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId]) select @OutId,GoodsNum,DetailId,0,0 from DT_OrderGoods where OrderId=@OrderId update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update b set b.GoodsPlanNum=b.GoodsPlanNum-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"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物出库明细 public int SaveGoodsOutDetail(HW_GoodsOutDetail Model) { string tsql = @" if @Id>0 begin Update [HW_GoodsOutDetail] set [OutId]=@OutId,[OutNum]=@OutNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId where Id=@Id end else begin INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId])values(@OutId,@OutNum,@DetailId,@StoreId,@PostionId) 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, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if(Model.OutInnerInList!=null) { foreach (var md in Model.OutInnerInList) { md.OutDetailId = a; SaveGoodsOutInnerIn(md); } } return a; } #endregion #region 保存货物出库明细 public int SaveGoodsOutDetailNew(HW_GoodsOutCK Model) { string tsql = @" if @Id>0 begin Update [HW_GoodsOutDetail] set [OutId]=@OutId,[OutNum]=@OutNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId where Id=@Id end else begin INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId])values(@OutId,@OutNum,@DetailId,@StoreId,@PostionId) 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, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存出库货物对应批次 public void SaveGoodsOutInnerIn(HW_GoodsOutInnerIn Model) { string tsql = @" INSERT INTO [HW_GoodsOutInnerIn]([OutDetailId],[InId],[Num])values(@OutDetailId,@InId,@Num) update HW_GoodsInList set GoodsNum=GoodsNum-@Num where InId=@InId update b set b.GoodsNum=b.GoodsNum-@Num from HW_GoodsInList a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.InId=@InId update c set c.GoodsNum=c.GoodsNum-@Num from HW_GoodsInList a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.InId=@InId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OutDetailId", DbType.Int32, Model.OutDetailId); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.ExecuteNonQuery(cmd); } #endregion #region 保存出库货物对应批次 public void SaveGoodsOutInnerInNew(HW_GoodsOutCK Model) { string tsql = @" update HW_GoodsDetail set GoodsNum=GoodsNum-1 where DetailId=@DetailId update HW_GoodsInDetail set OrderGoodsId=-1,UpDateTime=getdate() where inid in (select top 1 inid from HW_GoodsInDetail where DetailId=@DetailId and OrderGoodsId=0 and StoreId=@StoreId and PostionId=@PostionId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.ExecuteNonQuery(cmd); } #endregion #region 保存出库货物数量调整 public void SaveGoodsOutGoodsNum(int OutId) { string tsql = @" update a set a.GoodsNum=dbo.GetStoreGoodsNum(a.DetailId) from HW_GoodsDetail a inner join HW_GoodsOutDetail b on a.DetailId=b.DetailId where b.OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32,OutId); db.ExecuteNonQuery(cmd); } #endregion #region 保存出库货物对应批次 public void SaveGoodsOutInnerForTM(HW_GoodsOutCK Model) { string tsql = @" --update HW_GoodsDetail set GoodsNum=dbo.GetStoreGoodsNum(DetailId) where DetailId=@DetailId update HW_GoodsInDetail set OrderGoodsId=-1,UpDateTime=getdate(),CKDetailId=@Id where inid in (select top 1 inid from HW_GoodsInDetail where DetailId=@DetailId and OrderGoodsId=0 and StoreId=@StoreId and PostionId=@PostionId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.ExecuteNonQuery(cmd); } #endregion #region 保存出库货物对应批次 public int SaveGoodsOutInnerForTM2(int DetailId, int PostionId, int StoreId, int GoodsNum, int CKDetailId) { string tsql = @" declare @OldInId int,@InId int,@KCNum int,@OutNum int set @OutNum=0 while @GoodsNum>0 begin set @OldInId=0 select top 1 @OldInId=InId,@KCNum=KCNum from HW_GoodsInDetail where OrderGoodsId=0 and PostionId=@PostionId and DetailId=@DetailId if @OldInId>0 and @GoodsNum=@KCNum begin update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=@CKDetailId where InId=@OldInId set @OutNum=@OutNum+@KCNum end else if @OldInId>0 and @GoodsNum<@KCNum begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],StoreId=@StoreId,PostionId=@PostionId,[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=-1,KCNum=@GoodsNum,getdate(),[RKDetailId],CKDetailId=@CKDetailId from [HW_GoodsInDetail] where InId=@OldInId update HW_GoodsInDetail set KCNum=KCNum-@GoodsNum where InId=@OldInId set @OutNum=@OutNum+@GoodsNum end else if @OldInId>0 and @GoodsNum>@KCNum begin update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=@CKDetailId,UpDateTime=getdate() where InId=@OldInId set @OutNum=@OutNum+@KCNum end if @OldInId=0 begin set @GoodsNum=0 end else begin set @GoodsNum=@GoodsNum-@KCNum end end update HW_GoodsDetail set GoodsNum=GoodsNum-@OutNum where DetailId=@DetailId select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, CKDetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存入库库货物对应批次 public void SaveGoodsInInnerIn(HW_GoodsInRK Model) { string tsql = @" if @StoreId is null or @StoreId=0 select @StoreId=StoreId from CK_StorePostion where PostionId=@PostionId update HW_GoodsDetail set GoodsNum=GoodsNum+@InNum where DetailId=@DetailId --while @InNum>0 if @InNum>0 begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[UpDateTime],RKDetailId,KCNum,OldNum)values(@DetailId,0,@StoreId,@PostionId,@Price,@PostPrice,GETDATE(),@InUserId,0,null,@RKDetailId,@InNum,@InNum) --set @InNum=@InNum-1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InNum", DbType.Int32, Model.InNum); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@InUserId", DbType.Decimal, Model.InUserId); db.AddInParameter(cmd, "@RKDetailId", DbType.Decimal, Model.RKDetailId); db.ExecuteNonQuery(cmd); } #endregion #region 复制入库批次 public void SaveGoodsInInnerInCopy(int OrderId,int DetailId, int StoreId, int PostionId,int IsOld) { string tsql = @" if @IsOld=1 begin update a set OrderGoodsId=0,CKDetailId=0,InDate=getdate() from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId and a.DetailId=@DetailId end else begin update a set OrderGoodsId=0,CKDetailId=0,StoreId=@OrderId,PostionId=@PostionId,a.InDate=getdate() from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId and a.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@IsOld", DbType.Int32, IsOld); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.ExecuteNonQuery(cmd); } #endregion #region 复制入库批次 public void SaveGoodsInInnerInCopy2(string OrderId, int DetailId, int StoreId, int PostionId, int IsOld) { string tsql = @" if @IsOld=1 begin update a set OrderGoodsId=0,CKDetailId=0 from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.OrderId=@OrderId and DetailId=@DetailId end else begin update a set OrderGoodsId=0,CKDetailId=0,StoreId=@OrderId,PostionId=@PostionId from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where b.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, "@IsOld", DbType.Int32, IsOld); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询出库记录 public List GetListHW_GoodsOutList(string SKU,RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OutId=cast(a.OutId as int),a.OutCode,a.OutReason,a.Remark,a.OutNum,a.InUserId,a.InDate,a.InName"; if (SKU != "") { ser.Tables = @"(select * from HW_GoodsOutList where outid in (select distinct a.outid from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + SKU + "' or b.TypeDesc='" + SKU + "'))a"; } else ser.Tables = @"HW_GoodsOutList a "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OutId"; 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 GetListHW_GoodsOutListForTM(int TJ, string Name, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OutId=cast(a.OutId as int),a.OutCode,a.OutReason,a.Remark,a.OutNum,a.InUserId,a.InDate,a.InName,b.PlatOrderCode"; if (Name != "") { if (TJ == 1) { ser.Tables = @"(select * from HW_GoodsOutList where OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsCode='" + Name + "' or e.GoodsOldCode='" + Name + "'))a"; } else if (TJ == 2) { ser.Tables = @"(select * from HW_GoodsOutList where OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsName like '%" + Name + "%'))a"; } else if (TJ == 3) { ser.Tables = @"(select * from HW_GoodsOutList where OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + Name + "' or b.SKU2='" + Name + "' or b.SKU3='" + Name + "' or b.SKU4='" + Name + "' or b.SKU5='" + Name + "'))a"; } else if (TJ == 4) { ser.Tables = @"(select * from HW_GoodsOutList where OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode='" + Name + "' or b.PostionDesc='" + Name + "'))a"; } } else ser.Tables = @"HW_GoodsOutList a"; ser.Tables +=" left join DT_OrderInfo 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 = "OutId"; 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 GetGoodsOutCK(int DetailId) { List list = null; string tsql = @" select a.*,DetailId=@DetailId,b.StoreName,c.PostionDesc,OutNum=0 from (select StoreId,PostionId,GoodsNum=SUM(GoodsNum) from HW_GoodsInList where DetailId=@DetailId and GoodsNum>0 group by StoreId,PostionId)a inner join CK_StoreHouse b on a.StoreId=b.StoreId left join CK_StorePostion c on a.PostionId=c.PostionId"; 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 GetGoodsCKDetail(int CompanyId, string GoodsCode) { List list = null; string tsql = @" select top 300 a.*,BuyNum=0,b.GoodsCode,b.GoodsName,GoodsLeftNum=a.GoodsNum+a.GoodsInNum-a.GoodsPlanNum from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or a.SKU1=@GoodsCode or b.GoodsName=@GoodsCode) order by a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物明细列表 public List GetGoodsOutDetail(int CompanyId, string GoodsCode) { List list = null; string tsql = @" select b.GoodsName,a.DetailId,a.sku1,a.TypeCode,a.GoodsNum,a.GoodsPlanNum,a.GoodsInNum,GoodsLockNum=(select SUM(isnull(GoodsLockNum,0)) from HW_GoodsInList where DetailId=a.DetailId) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or a.SKU1=@GoodsCode or b.GoodsName=@GoodsCode) order by a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物批次列表 public List GetGoodsOutDetailNew(int CompanyId, string GoodsCode) { List list = null; string tsql = @" select a.*,c.GoodsName,b.SKU1,d.StoreName,PostionDesc=isnull(e.PostionDesc,'无'),c.FirstImgUrl from (select DetailId,StoreId,PostionId=ISNULL(PostionId,0),GoodsNum=COUNT(0) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,StoreId,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_StoreHouse d on a.StoreId=d.StoreId left join CK_StorePostion e on a.PostionId=e.PostionId where c.CompanyId=@CompanyId and (c.GoodsCode=@GoodsCode or b.SKU1=@GoodsCode or c.GoodsName=@GoodsCode) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物批次列表 public List GetGoodsOutDetailForTM(int CompanyId, string GoodsCode,string TypeCode) { List list = null; string tsql = @" select a.*,c.GoodsName,C.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.SKU1,d.StoreName,PostionDesc=isnull(e.PostionCode,'无') from (select DetailId,StoreId,PostionId=ISNULL(PostionId,0),GoodsNum=sum(KCNum) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,StoreId,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_StoreHouse d on a.StoreId=d.StoreId inner join CK_StorePostion e on a.PostionId=e.PostionId where c.CompanyId=@CompanyId and (c.GoodsCode=@GoodsCode or c.GoodsOldCode=@GoodsCode or b.SKU1=@GoodsCode or c.GoodsName=@GoodsCode) and (@TypeCode='' or b.TypeCode=@TypeCode) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); 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 查询货物入库明细 public List GetGoodsInDetailNew(int CompanyId, string GoodsCode) { List list = null; string tsql = @" select a.*,b.GoodsName,Price=(select top 1 Price from HW_GoodsInDetail where DetailId=a.DetailId order by InId desc),PostPrice=(select top 1 PostPrice from HW_GoodsInDetail where DetailId=a.DetailId order by InId desc) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@GoodsCode or a.SKU1=@GoodsCode or b.GoodsName=@GoodsCode)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物入库明细 public List GetGoodsInDetailForTM(int CompanyId, string GoodsCode,string TypeCode) { List list = null; string tsql = @" select a.DetailId,a.TypeCode,a.TypeDesc,a.GoodsNum,b.GoodsName,b.GoodsCode,b.GoodsOldCode,Price=isnull(a.Price,0.0),PostPrice=0.0 from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsOldCode=@GoodsCode or b.GoodsCode=@GoodsCode or a.SKU1=@GoodsCode or b.GoodsName=@GoodsCode) and (@TypeCode='' or a.TypeCode=@TypeCode)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); 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 查询货物入库列表 public List GetGoodsCKInList(int DetailId, int StoreId, int PostionId) { List list = null; string tsql = @" select * from HW_GoodsInList where DetailId=@DetailId and GoodsNum>0 and StoreId=@StoreId and PostionId=@PostionId order by InId "; 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, "@PostionId", DbType.Int32, PostionId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 删除出库记录 public void DeleteOut(int OutId) { string tsql = @" update d set d.GoodsNum=d.GoodsNum+c.Num from HW_GoodsOutDetail a inner join HW_GoodsOutList b on a.OutId=b.OutId inner join HW_GoodsOutInnerIn c on a.Id=c.OutDetailId inner join HW_GoodsInList d on c.InId=d.InId where b.OutId=@OutId delete from HW_GoodsOutInnerIn where id in (select c.Id from HW_GoodsOutDetail a inner join HW_GoodsOutList b on a.OutId=b.OutId inner join HW_GoodsOutInnerIn c on a.Id=c.OutDetailId where b.OutId=@OutId) delete from HW_GoodsOutDetail where OutId=@OutId delete from HW_GoodsOutList where OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); db.ExecuteNonQuery(cmd); } #endregion #region 验证是否能删除入库记录 public int IsDeleteIn(int InId) { string tsql = @" if(select COUNT(0) from HW_GoodsInDetail a inner join HW_GoodsInRecordDetail b on a.RKDetailId=b.Id inner join HW_GoodsInRecord c on b.InId=c.Id where c.Id=@InId and a.OrderGoodsId<>0)>0 begin select 0 end else if(select COUNT(0) from CG_Purchase a inner join HW_GoodsInRecord c on a.ChaseId=c.Id where c.Id=@InId and a.State=3)>0 begin select 1 end else begin select 2 end "; 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 int DeleteIn(HW_GoodsInRecordDetail md) { string tsql = @" delete from HW_GoodsInDetail where RKDetailId=@Id and OrderGoodsId=0 --delete from CG_ChaseInStore where Id in (select top 1 Id from CG_ChaseInStore where ChaseId=@ChaseId and GoodsDetailId=@DetailId and GoodsNum=@InNum and State=1) update CG_PurchaseGoods set InGoodsNum=InGoodsNum-@InNum where ChaseId=@ChaseId and GoodsDetailId=@DetailId update CG_Purchase set GoodsState=0,State=2,DoneDate=null where ChaseId=@ChaseId update HW_GoodsDetail set GoodsNum=dbo.GetStoreGoodsNum(@DetailId),GoodsInNum=dbo.GetBuyGoodsNum(@DetailId) where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, md.Id); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, md.ChaseId); db.AddInParameter(cmd, "@InNum", DbType.Int32, md.InNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除入库记录 public int DeleteInRecord(int Id) { string tsql = @" delete from HW_GoodsInRecordDetail where InId=@Id delete from HW_GoodsInRecord where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回出库Model public HW_GoodsOutRecord GetOutCKModel(int OutId) { HW_GoodsOutRecord model = null; string tsql = "select * from HW_GoodsOutList where OutId=@OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回出库明细 public List GetOutCKDetailList(int OutId) { List list = null; string tsql = @" select a.*,e.GoodsName,b.SKU1,b.TypeDesc,PostionDesc=isnull(d.PostionCode,'无') from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId left join CK_StorePostion d on a.PostionId=d.PostionId where OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回出库明细 public List GetOutCKDetailListForTM(int OutId) { List list = null; string tsql = @" select a.*,e.GoodsId,e.GoodsCode,e.GoodsOldCode,e.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where a.OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 导入货物 public int ExcelSaveGoods(HW_GoodsExcelModel Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUAdd"); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@SortName1", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortName2", DbType.String, Model.SortName2); db.AddInParameter(cmd, "@SortName3", DbType.String, Model.SortName3); db.AddInParameter(cmd, "@EnglishCode1", DbType.String, Model.EnglishCode1); db.AddInParameter(cmd, "@EnglishCode2", DbType.String, Model.EnglishCode2); db.AddInParameter(cmd, "@EnglishCode3", DbType.String, Model.EnglishCode3); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Postion", DbType.String, Model.Postion); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入货物 public int ExcelSaveGoodsNew(HW_GoodsExcelModel Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUAddNew"); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@SortName1", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortName2", DbType.String, Model.SortName2); db.AddInParameter(cmd, "@SortName3", DbType.String, Model.SortName3); db.AddInParameter(cmd, "@EnglishCode1", DbType.String, Model.EnglishCode1); db.AddInParameter(cmd, "@EnglishCode2", DbType.String, Model.EnglishCode2); db.AddInParameter(cmd, "@EnglishCode3", DbType.String, Model.EnglishCode3); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Postion", DbType.String, Model.Postion); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入货物2 public int ExcelSaveGoodsNew2(HW_GoodsExcelModel Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUAddNew2"); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsEnglishName", DbType.String, Model.GoodsEngLishName); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Link1", DbType.String, Model.Link1); db.AddInParameter(cmd, "@LinkName1", DbType.String, Model.LinkName1); db.AddInParameter(cmd, "@Link2", DbType.String, Model.Link2); db.AddInParameter(cmd, "@LinkName2", DbType.String, Model.LinkName2); db.AddInParameter(cmd, "@Link3", DbType.String, Model.Link3); db.AddInParameter(cmd, "@LinkName3", DbType.String, Model.LinkName3); db.AddInParameter(cmd, "@Link4", DbType.String, Model.Link4); db.AddInParameter(cmd, "@LinkName4", DbType.String, Model.LinkName4); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入货物 public int ExcelSaveGoods2(HW_GoodsExcelModel Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUAdd2"); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@SortName1", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortName2", DbType.String, Model.SortName2); db.AddInParameter(cmd, "@SortName3", DbType.String, Model.SortName3); db.AddInParameter(cmd, "@EnglishCode1", DbType.String, Model.EnglishCode1); db.AddInParameter(cmd, "@EnglishCode2", DbType.String, Model.EnglishCode2); db.AddInParameter(cmd, "@EnglishCode3", DbType.String, Model.EnglishCode3); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Postion", DbType.String, Model.Postion); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入货物海外仓 public int ExcelSaveGoodsHWC(HW_GoodsExcelModel Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUImport"); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsEnglishName", DbType.String, Model.GoodsEngLishName); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Link1", DbType.String, Model.Link1); db.AddInParameter(cmd, "@LinkName1", DbType.String, Model.LinkName1); db.AddInParameter(cmd, "@Link2", DbType.String, Model.Link2); db.AddInParameter(cmd, "@LinkName2", DbType.String, Model.LinkName2); db.AddInParameter(cmd, "@Link3", DbType.String, Model.Link3); db.AddInParameter(cmd, "@LinkName3", DbType.String, Model.LinkName3); db.AddInParameter(cmd, "@Link4", DbType.String, Model.Link4); db.AddInParameter(cmd, "@LinkName4", DbType.String, Model.LinkName4); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region sku入库位 public int UpdateSKUPostion(int CompanyId, string SKU, string PostionCode) { string tsql = @" declare @DetailId int,@PostionId int,@StoreId int select top 1 @DetailId=a.DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.SKU1=@SKU and b.companyid=@CompanyId select @PostionId=a.PostionId,@StoreId=a.StoreId from CK_StorePostion a inner join CK_StoreHouse b on a.StoreId=b.StoreId where b.CompanyId=@CompanyId and a.PostionCode=@PostionCode if @PostionId is null begin select 0 end else if @DetailId is null begin select 1 end else begin update HW_GoodsInDetail set StoreId=@StoreId,PostionId=@PostionId where DetailId=@DetailId and PostionId=@PostionId select 2 end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public int ImportTrackCodeClear(string TrackCode) { string tsql = @" declare @OrderId int,@OrderCode nvarchar(50) select @OrderId=OrderId,@OrderCode=OrderCode from DT_TrackCodeApply where state=1 and (REPLACE(TrackCode,' ','')=@TrackCode or TrackCode2=@TrackCode) if @OrderId>0 begin update DT_OrderInfo set Fee1=0,Fee2=0 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0 where OrderId=@OrderId select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public int ImportTrackCode(string TrackCode, decimal PostFee,decimal? PostFee2) { string tsql = @" declare @OrderId int,@OrderCode nvarchar(50) select @OrderId=OrderId,@OrderCode=OrderCode from DT_TrackCodeApply where state=1 and (REPLACE(TrackCode,' ','')=@TrackCode or TrackCode2=@TrackCode) if @OrderId>0 begin update DT_OrderInfo set Fee1=isnull(Fee1,0)+@PostFee,Fee2=isnull(Fee2,0)+@PostFee2 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=PostFee+@PostFee where OrderId=@OrderId if(select count(0) from DT_TrackCodeScan where TrackCode=@TrackCode)>0 update DT_TrackCodeScan set PostFee=@PostFee,OldPostFee=@PostFee where REPLACE(TrackCode,' ','')=@TrackCode else begin INSERT INTO [dbo].[DT_TrackCodeScan] ([PostId] ,[TrackCode] ,[InDate] ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId] ,[Weight] ,[PostFee] ,[OldPostFee]) select [PostId] ,[TrackCode] ,[InDate]=GETDATE() ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId]=1 ,[Weight]=0 ,[PostFee]=@PostFee ,[OldPostFee]=@PostFee from DT_TrackCodeApply where State=1 and REPLACE(TrackCode,' ','')=@TrackCode end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, PostFee2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public int ImportTrackCode2Clear(string OrderCode) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin update DT_OrderInfo set Fee1=0 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0 where OrderId=@OrderId select 1 end else begin select 0 end "; 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 ImportTrackCode2(string OrderCode,string TrackCode, decimal PostFee) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin update DT_OrderInfo set Fee1=isnull(Fee1,0)+@PostFee where OrderId=@OrderId update DT_OrderXXInfo set PostFee=isnull(PostFee,0)+@PostFee,TrackState=1,LogisticsId=11,Post=221 where OrderId=@OrderId if(select count(0) from DT_TrackCodeApply where state=1 and OrderId=@OrderId)=0 begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[TrackCode2] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[UpdateTime] ,[OrderCode] ,[OldPostFee] ,[ScanState] ,[ScanDate]) VALUES (221 ,1 ,@TrackCode ,null ,GETDATE() ,'' ,@OrderId ,1 ,null ,@OrderCode ,null ,null ,null ) end if(select count(0) from DT_TrackCodeScan where OrderId=@OrderId)>0 update DT_TrackCodeScan set PostFee=@PostFee,OldPostFee=@PostFee where OrderId=@OrderId else begin INSERT INTO [dbo].[DT_TrackCodeScan] ([PostId] ,[TrackCode] ,[InDate] ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId] ,[Weight] ,[PostFee] ,[OldPostFee]) select [PostId] ,[TrackCode] ,[InDate]=GETDATE() ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId]=1 ,[Weight]=0 ,[PostFee]=@PostFee ,[OldPostFee]=@PostFee from DT_TrackCodeApply where State=1 and OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public int ImportTrackCode3Clear(string OrderCode) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin delete from DT_TrackCodeApply where OrderId=@OrderId end select 1 "; 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 ImportTrackCode3(int PostId,string OrderCode, string TrackCode,string Name,string SKU) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin if(select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and state=1)=0 begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[TrackCode2] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[UpdateTime] ,[OrderCode] ,[OldPostFee] ,[ScanState] ,[ScanDate] ,[SKU]) values(@PostId,1,@TrackCode,null,getdate(),@Name,@OrderId,1,null,@OrderCode,null,0,null,@SKU) update DT_OrderXXInfo set PostError=null,TrackState=1,LogisticsId=10,Post=65 where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1,LogisticsId=10,Post=65 where OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存入库记录 public int SaveGoodsInRecord(HW_GoodsInRecord Model) { string tsql=@" if @Id>0 begin Update [HW_GoodsInRecord] set [InCode]=@InCode,[InReason]=@InReason,[Remark]=@Remark,[InNum]=@InNum,[InUserId]=@InUserId,[InDate]=@InDate,[InName]=@InName,[CompanyId]=@CompanyId where Id=@Id end else begin INSERT INTO [HW_GoodsInRecord]([InCode],[InReason],[Remark],[InNum],[InUserId],[InDate],[InName],[CompanyId])values(@InCode,@InReason,@Remark,@InNum,@InUserId,@InDate,@InName,@CompanyId) 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,"@InCode", DbType.String,Model.InCode); db.AddInParameter(cmd,"@InReason", DbType.String,Model.InReason); db.AddInParameter(cmd,"@Remark", DbType.String,Model.Remark); db.AddInParameter(cmd,"@InNum", DbType.Int32,Model.InNum); db.AddInParameter(cmd,"@InUserId", DbType.Int32,Model.InUserId); db.AddInParameter(cmd,"@InDate", DbType.DateTime,Model.InDate); db.AddInParameter(cmd,"@InName", DbType.String,Model.InName); db.AddInParameter(cmd,"@CompanyId", DbType.Int32,Model.CompanyId); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存入库记录 public int SaveGoodsInRecordForTM(HW_GoodsInRecord Model) { string tsql = @" if @Id>0 begin Update [HW_GoodsInRecord] set [InCode]=@InCode,[InReason]=@InReason,[Remark]=@Remark,[InNum]=@InNum,[InUserId]=@InUserId,[InDate]=@InDate,[InName]=@InName,[CompanyId]=@CompanyId,[ChaseId]=@ChaseId,[IsDelete]=@IsDelete where Id=@Id end else begin INSERT INTO [HW_GoodsInRecord]([InCode],[InReason],[Remark],[InNum],[InUserId],[InDate],[InName],[CompanyId],[ChaseId],[IsDelete])values(@InCode,@InReason,@Remark,@InNum,@InUserId,@InDate,@InName,@CompanyId,@ChaseId,@IsDelete) 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, "@InCode", DbType.String, Model.InCode); db.AddInParameter(cmd, "@InReason", DbType.String, Model.InReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@InNum", DbType.Int32, Model.InNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public void DeleteGoodsInRecord(int Id) { string tsql=@" delete from HW_GoodsInRecord 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 HW_GoodsInRecord GetGoodsInRecordModel(int Id) { HW_GoodsInRecord model = null; string tsql="select * from HW_GoodsInRecord 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 List GetListHW_GoodsInRecord(string SKU,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.InCode,a.InReason,a.Remark,a.InNum,a.InUserId,a.InDate,a.InName,a.CompanyId"; if (SKU != "") { ser.Tables = @"(select * from HW_GoodsInRecord where inid in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + SKU + "' or b.TypeDesc='" + SKU + "'))a"; } else ser.Tables = @"HW_GoodsInRecord a"; 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 int SaveInRecordDetail(HW_GoodsInRK Model) { string tsql = @" select top 1 @StoreId=StoreId from CK_StorePostion where PostionId=@PostionId if @Id>0 begin Update [HW_GoodsInRecordDetail] set [InId]=@InId,[InNum]=@InNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId where Id=@Id end else begin INSERT INTO [HW_GoodsInRecordDetail]([InId],[InNum],[DetailId],[StoreId],[PostionId])values(@InId,@InNum,@DetailId,@StoreId,@PostionId) 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, "@InNum", DbType.Int32, Model.InNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存入库明细 public int SaveInRecordDetailForTM(HW_GoodsInRK Model) { string tsql = @" select top 1 @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @Id>0 begin Update [HW_GoodsInRecordDetail] set [InId]=@InId,[InNum]=@InNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId where Id=@Id end else begin INSERT INTO [HW_GoodsInRecordDetail]([InId],[InNum],[DetailId],[StoreId],[PostionId])values(@InId,@InNum,@DetailId,@StoreId,@PostionId) 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, "@InNum", DbType.Int32, Model.InNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回入库明细 public List GetRKDetailList(int Id) { List list = null; string tsql = @" select a.*,e.GoodsName,b.SKU1,b.TypeDesc,c.StoreName,PostionDesc=isnull(d.PostionDesc,'无') from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId inner join CK_StoreHouse c on a.StoreId=c.StoreId left join CK_StorePostion d on a.PostionId=d.PostionId where a.InId=@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 返回入库明细 public List GetRKDetailForTM(int Id) { List list = null; string tsql = @" select a.*,e.GoodsName,e.GoodsCode,e.GoodsOldCode,b.SKU1,b.TypeDesc,PostionDesc=f.PostionCode from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId inner join CK_StorePostion f on a.PostionId=f.PostionId where a.InId=@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 返回入库明细 public List GetRKDetailForTM2(int Id) { List list = null; string tsql = @" select a.*,b.ChaseId from HW_GoodsInRecordDetail a inner join HW_GoodsInRecord b on a.InId=b.Id where a.InId=@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 分页查询 public List GetListHW_GoodsInRecordForTM(int TJ,string Name, 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.InCode,a.InReason,a.Remark,a.InNum,a.InUserId,a.InDate,a.InName,a.CompanyId,b.ChaseCode"; if (Name != "") { if (TJ == 1) { ser.Tables = @"(select * from HW_GoodsInRecord where id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsCode='" + Name + "' or e.GoodsOldCode='" + Name + "'))a"; } else if (TJ == 2) { ser.Tables = @"(select * from HW_GoodsInRecord where id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsName like '%" + Name + "%'))a"; } else if (TJ == 3) { ser.Tables = @"(select * from HW_GoodsInRecord where id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + Name + "' or b.SKU2='" + Name + "' or b.SKU3='" + Name + "' or b.SKU4='" + Name + "' or b.SKU5='" + Name + "'))a"; } else if (TJ == 4) { ser.Tables = @"(select * from HW_GoodsInRecord where id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode='" + Name + "' or b.PostionDesc='" + Name + "'))a"; } } else ser.Tables = @"HW_GoodsInRecord a"; ser.Tables +=" left join CG_Purchase b on a.ChaseId=b.ChaseId"; 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 GetRKDetailListForTM(int Id) { List list = null; string tsql = @" select a.*,e.GoodsId,e.GoodsCode,e.GoodsOldCode,e.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc,c.StoreName,PostionDesc=isnull(d.PostionDesc,'无') from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId inner join CK_StoreHouse c on d.StoreId=c.StoreId where a.InId=@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 保存产品比较 public int SaveProductCompare(CP_ProductCompare Model) { string tsql = @" if @Id>0 begin Update [CP_ProductCompare] set [ProductName]=@ProductName,[InUserId]=@InUserId,[PlatId]=@PlatId,[InDate]=@InDate,[IsUse]=@IsUse,[CompanyId]=@CompanyId where Id=@Id end else begin INSERT INTO [CP_ProductCompare]([ProductName],[InUserId],[PlatId],[InDate],[IsUse],[CompanyId])values(@ProductName,@InUserId,@PlatId,@InDate,@IsUse,@CompanyId) 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, "@ProductName", DbType.String, Model.ProductName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@IsUse", DbType.Int32, Model.IsUse); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询产品比较 public List GetListCP_ProductCompare(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.ProductName,a.InUserId,a.PlatId,a.InDate,a.IsUse,IsUseName=case when a.IsUse=1 then '是' else '否' end"; ser.Tables = @"CP_ProductCompare a"; 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 int SaveProductCompareDetail(CP_ProductCompareDetail Model) { string tsql = @" select top 1 @Id=Id from CP_ProductCompareDetail where [CompareId]=@CompareId and [ProductId]=@ProductId if @Id>0 begin Update [CP_ProductCompareDetail] set [CompareId]=@CompareId,[ProductId]=@ProductId,[IsSelf]=1,[ProductDesc]=@ProductDesc where Id=@Id end else begin INSERT INTO [CP_ProductCompareDetail]([CompareId],[ProductId],[IsSelf],[ProductDesc])values(@CompareId,@ProductId,1,@ProductDesc) 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, "@CompareId", DbType.Int32, Model.CompareId); db.AddInParameter(cmd, "@ProductId", DbType.String, Model.ProductId); db.AddInParameter(cmd, "@IsSelf", DbType.Int32, Model.IsSelf); db.AddInParameter(cmd, "@ProductDesc", DbType.String, Model.ProductDesc); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public void DeleteCompareDetail(int CompareId) { string tsql = @" delete from CP_ProductCompareDetail where CompareId=@CompareId and IsSelf=0 update CP_ProductCompareDetail set IsSelf=0 where CompareId=@CompareId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompareId", DbType.Int32, CompareId); db.ExecuteNonQuery(cmd); } #endregion #region 保存产品比较记录 public int SaveProductCompareRecord(CP_ProductCompareRecord Model) { string tsql = @" select top 1 @Id=Id from CP_ProductCompareRecord where rid=@rid and DetailId=@DetailId if @Id>0 begin select 0 end else begin INSERT INTO [CP_ProductCompareRecord]([DetailId],[countryName],[price],[quantity],[date],[memberid],[name],[rid])values(@DetailId,@countryName,@price,@quantity,@date,@memberid,@name,@rid) set @Id=SCOPE_IDENTITY() select @Id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@countryName", DbType.String, Model.countryName); db.AddInParameter(cmd, "@price", DbType.Decimal, Model.price); db.AddInParameter(cmd, "@quantity", DbType.Int32, Model.quantity); db.AddInParameter(cmd, "@date", DbType.DateTime, Model.date); db.AddInParameter(cmd, "@memberid", DbType.String, Model.memberid); db.AddInParameter(cmd, "@name", DbType.String, Model.name); db.AddInParameter(cmd, "@rid", DbType.String, Model.rid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物明细列表根据供应商 public List GetProductCount(string DetailIds, DateTime? SDate, DateTime? EDate) { List list = null; string tsql = @" select Num=SUM(quantity),AvgPrice=case when count(0)>0 then SUM(price)/count(0) else 0 end,MaxPrice=MAX(price),MinPrice=MIN(price),Countdate=convert(nvarchar(10),date,120),DetailId from CP_ProductCompareRecord where DetailId in (" + DetailIds + ") and date>=@SDate and date<@EDate group by DetailId,convert(nvarchar(10),date,120)"; 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 List GetCompareDetailList(int CompareId) { List list = null; string tsql = @"select * from CP_ProductCompareDetail where CompareId=@CompareId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompareId", DbType.Int32, CompareId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 删除货物比较 public void DeleteProductCompare(int Id) { string tsql = @" delete from CP_ProductCompare 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 GetCompareUseNum(int CompanyId) { string tsql = @"select count(0) from CP_ProductCompare where IsUse=1 and CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); int a =Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回打印货物 public List GetPrintGoods(int CompanyId, int Type, string Name,string Code, DateTime? SDate, DateTime? EDate) { List list = null; string tsql = @" if @Type=1 begin select b.GoodsName,b.GoodsCode,b.GoodsOldCode,a.TypeCode,a.TypeDesc,a.GoodsNum,PrintNum=a.GoodsNum-a.GoodsLockNum,PostionCode=(select top 1 b.PostionCode from HW_GoodsInDetail aa inner join CK_StorePostion b on aa.PostionId=b.PostionId where b.IsLS=0 and aa.DetailId=a.DetailId and aa.CKDetailId=0) from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (b.GoodsCode=@Name or b.GoodsOldCode=@Name) and (@Code='' or TypeCode=@Code) and b.State=1 end else if @Type=2 begin select d.GoodsName,d.GoodsCode,d.GoodsOldCode,c.TypeCode,c.TypeDesc,a.GoodsNum,PrintNum=a.GoodsNum,PostionCode=(select top 1 b.PostionCode from HW_GoodsInDetail aa inner join CK_StorePostion b on aa.PostionId=b.PostionId where b.IsLS=0 and aa.DetailId=a.GoodsDetailId and aa.CKDetailId=0) from CG_PurchaseGoods a inner join CG_Purchase b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c on a.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where d.CompanyId=@CompanyId and b.ChaseCode=@Name end else if @Type=3 begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,a.GoodsNum,PrintNum=a.GoodsNum,PostionCode=(select top 1 b.PostionCode from HW_GoodsInDetail aa inner join CK_StorePostion b on aa.PostionId=b.PostionId where b.IsLS=0 and aa.DetailId=a.DetailId and aa.CKDetailId=0) from ( select DetailId,GoodsNum=Sum(a.KCNum) from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode=@Name and a.OrderGoodsId=0 and (@SDate is null or a.InDate>=@SDate) and (@EDate is null or a.InDate<@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 c.CompanyId=@CompanyId end else if @Type=4 begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,a.GoodsNum,PrintNum=a.GoodsNum,PostionCode=(select top 1 b.PostionCode from HW_GoodsInDetail aa inner join CK_StorePostion b on aa.PostionId=b.PostionId where b.IsLS=0 and aa.DetailId=a.DetailId and aa.CKDetailId=0) 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 c.CompanyId=@CompanyId and d.PlatOrderCode=@Name end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Type", DbType.Int32, Type); db.AddInParameter(cmd, "@Code", DbType.String, Code); db.AddInParameter(cmd, "@Name", DbType.String, Name); 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 GetPrintGoodsCode(int ChaseId) { List list = null; string tsql = @" select a.Id,b.ChaseId,DetailId=a.GoodsDetailId,d.GoodsName,d.GoodsCode,d.GoodsOldCode,c.TypeCode,c.TypeDesc,a.GoodsNum,YPrintNum=isnull(e.Num,0),PrintNum=a.GoodsNum-isnull(e.Num,0) from CG_PurchaseGoods a inner join CG_Purchase b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c on a.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId left join HW_BarCodeNum e on a.Id=e.ChaseDetailId where b.ChaseId=@ChaseId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回打印货物 public List GetPrintGoodsCode2(string ChaseCode) { List list = null; string tsql = @" select a.Id,b.ChaseId,DetailId=a.GoodsDetailId,d.GoodsName,d.GoodsCode,d.GoodsOldCode,c.TypeCode,c.TypeDesc,a.GoodsNum,YPrintNum=isnull(e.Num,0),PrintNum=a.GoodsNum-isnull(e.Num,0) from CG_PurchaseGoods a inner join CG_Purchase b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c on a.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId left join HW_BarCodeNum e on a.Id=e.ChaseDetailId where b.ChaseCode=@ChaseCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseCode", DbType.String, ChaseCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页查询库存 public List GetList_GoodsLeft(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.*,LockNum=isnull(b.LockNum,0),c.StoreName,c.StoreCode,d.PostionDesc,d.PostionCode,f.GoodsName,f.GoodsCode,f.GoodsOldCode,f.CompanyId,e.TypeCode,e.TypeDesc"; ser.Tables = @"(select a.DetailId,a.StoreId,a.PostionId,GoodsNum=sum(KCNum) from ( select a.DetailId,a.StoreId,a.PostionId,islock=0 from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderGoodsId=0 union all select a.DetailId,a.StoreId,a.PostionId,islock=1 from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OutNum is null or c.OutNum=0)a group by a.DetailId,a.StoreId,a.PostionId)a inner join CK_StoreHouse c on a.StoreId=c.StoreId inner join CK_StorePostion d on a.PostionId=d.PostionId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId left join (select a.DetailId,a.StoreId,a.PostionId,LockNum=sum(KCNum) from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join DT_OrderGoods c on a.OrderGoodsId=c.Id where c.OutNum is null or c.OutNum=0 group by a.DetailId,a.StoreId,a.PostionId)b on a.DetailId=b.DetailId and a.StoreId=b.StoreId and a.PostionId=b.PostionId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; 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 GetList_GoodsLeftForTM(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.DetailId,a.PostionId,a.GoodsNum,a.LockNum,LeftNum=a.GoodsNum-a.LockNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,TypeCode=b.sku1,b.TypeDesc,e.StoreName,d.PostionCode,d.PostionDesc"; ser.Tables = @"(select DetailId,PostionId,GoodsNum=SUM(GoodsNum),LockNum=SUM(LockNum) from ( select DetailId,PostionId,GoodsNum=sum(KCNum),LockNum=0 from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,PostionId union select DetailId,PostionId,GoodsNum=0,LockNum=sum(KCNum) from HW_GoodsInDetail where CKDetailId=0 and OrderGoodsId>0 group by DetailId,PostionId)a group by DetailId,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 inner join CK_StoreHouse e on d.StoreId=e.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; 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 static List GetListGoodsInDetail2(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"InId=cast(a.InId as int),a.DetailId,a.StoreId,a.PostionId,a.InDate,a.InUserId,a.KCNum,a.UpDateTime,d.PostionCode,d.PostionBox,c.GoodsName,c.GoodsCode,b.SKU1,b.TypeDesc"; ser.Tables = @"HW_GoodsInDetail2 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"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "InId"; 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 DataTable GetList_GoodsLeftExcel(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"a.DetailId,a.PostionId,a.GoodsNum,a.LockNum,LeftNum=a.GoodsNum-a.LockNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,e.StoreName,d.PostionCode,d.PostionDesc,pk=''"; ser.Tables = @"(select DetailId,PostionId,GoodsNum=SUM(GoodsNum),LockNum=SUM(LockNum) from ( select DetailId,PostionId,GoodsNum=sum(KCNum),LockNum=0 from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,PostionId union select DetailId,PostionId,GoodsNum=0,LockNum=sum(KCNum) from HW_GoodsInDetail where CKDetailId=0 and OrderGoodsId>0 group by DetailId,PostionId)a group by DetailId,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 inner join CK_StoreHouse e on d.StoreId=e.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 查询库存 public DataTable GetList_GoodsLeftList(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"a.*,GoodsNum=isnull(a.UseGoodsNum,0),LockNum=isnull(g.LockGoodsNum,0),UseGoodsNum=isnull(a.UseGoodsNum,0),c.StoreName,c.StoreCode,PostionDesc=d.PostionDesc+'['+d.PostionCode+']',d.PostionCode,NewPostionCode='',f.GoodsName,f.GoodsCode,f.GoodsOldCode,f.CompanyId,e.TypeCode,e.TypeDesc,pk='',OutNum=0,IsOut='false'"; ser.Tables = @"HW_GoodsDetail e inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId left join (select a.DetailId,a.StoreId,a.PostionId,UseGoodsNum=sum(KCNum) from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderGoodsId=0 and isnull(CKDetailId,0)=0 group by a.DetailId,a.StoreId,a.PostionId)a on e.DetailId=a.DetailId left join (select a.DetailId,a.StoreId,a.PostionId,LockGoodsNum=sum(KCNum) from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderGoodsId<>0 and isnull(CKDetailId,0)=0 group by a.DetailId,a.StoreId,a.PostionId)g on a.DetailId=g.DetailId and a.PostionId=g.PostionId left join CK_StoreHouse c on a.StoreId=c.StoreId left join CK_StorePostion d on a.PostionId=d.PostionId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 保存扫描记录 public int SaveScanImportRecord(HW_ScanImportRecord Model) { string tsql = @" if @Id>0 begin Update [HW_ScanImportRecord] set [Title]=@Title,[ScanContent]=@ScanContent,[ScanType]=@ScanType,[CompanyId]=@CompanyId,[InUserId]=@InUserId where Id=@Id end else begin INSERT INTO [HW_ScanImportRecord]([Title],[ScanContent],[ScanType],[CompanyId],[InUserId])values(@Title,@ScanContent,@ScanType,@CompanyId,@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, "@Title", DbType.String, Model.Title); db.AddInParameter(cmd, "@ScanContent", DbType.String, Model.ScanContent); db.AddInParameter(cmd, "@ScanType", DbType.Int32, Model.ScanType); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回扫描记录 public List GetScanImportRecordList(int CompanyId, int ScanType) { List list = null; string tsql = @"select top 15 * from HW_ScanImportRecord where CompanyId=@CompanyId and ScanType=@ScanType order by Id desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@ScanType", DbType.Int32, ScanType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回Model public HW_ScanImportRecord GetScanImportRecordModel(int Id) { HW_ScanImportRecord model = null; string tsql = "select * from HW_ScanImportRecord 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 static int SaveHW_Log(HW_Log Model) { string tsql = @" if @Id>0 begin Update [HW_Log] set [DetailId]=@DetailId,[ChangeNum]=@ChangeNum,[InName]=@InName,[InDate]=@InDate,[ChageType]=@ChageType where Id=@Id end else begin INSERT INTO [HW_Log]([DetailId],[ChangeNum],[InName],[InDate],[ChageType])values(@DetailId,@ChangeNum,@InName,getdate(),@ChageType) 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, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@ChangeNum", DbType.Int32, Model.ChangeNum); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@ChageType", DbType.Int32, Model.ChageType); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改库存对应出库明细id public int UpdateGoodsOutId(int OrderGoodsId, int OutDetailId) { string tsql = @" update HW_GoodsInDetail set CKDetailId=@OutDetailId where OrderGoodsId=@OrderGoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, OrderGoodsId); db.AddInParameter(cmd, "@OutDetailId", DbType.Int32, OutDetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 读取店铺 public List GetShop(string ShopName) { string tsql = @" select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where ShopName=@ShopName order by PlatType "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopName", DbType.String, ShopName); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 验证店铺名字 public int IsShopName(int CompanyId, string ShopName) { string tsql = @" declare @ShopId int set @ShopId=0 select top 1 @ShopId=ShopId from JC_Shop where companyid=@CompanyId and ShopName=@ShopName select ShopId=@ShopId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@ShopName", DbType.String, ShopName); int a=Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public string Save(HW_OnOffList Model) { string tsql = @" if @OnOffID>0 begin Update [HW_OnOffList] set [productIds]=@productIds,[GoodsCode]=@GoodsCode,[ShopName]=@ShopName,[OnOffFlag]=@OnOffFlag,[ShopID]=@ShopID,[ProductURL]=@ProductURL where OnOffID=@OnOffID end else begin INSERT INTO [HW_OnOffList]([productIds],[GoodsCode],[ShopName],[OnOffFlag],[ShopID],[ProductURL],[NewTime])values(@productIds,@GoodsCode,@ShopName,@OnOffFlag,@ShopID,@ProductURL,@NewTime) set @OnOffID=SCOPE_IDENTITY() end select @OnOffID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OnOffID", DbType.Int32, Model.OnOffID); db.AddInParameter(cmd, "@productIds", DbType.String, Model.productIds); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@ShopName", DbType.String, Model.ShopName); db.AddInParameter(cmd, "@OnOffFlag", DbType.Int32, Model.OnOffFlag); db.AddInParameter(cmd, "@ShopID", DbType.Int32, Model.ShopID); db.AddInParameter(cmd, "@ProductURL", DbType.String, Model.ProductURL); db.AddInParameter(cmd, "@NewTime", DbType.DateTime, Model.NewTime); string a = Convert.ToString(db.ExecuteScalar(cmd)); tsql = @" if @OnOffDetailID>0 begin Update [HW_OnOffDetail] set [OnTime]=@OnTime,[OffTime]=@OffTime,[IntervalTime]=@IntervalTime,[ByTheTime]=@ByTheTime where OnOffDetailID=@OnOffDetailID end else begin INSERT INTO [HW_OnOffDetail]([OnOffID],[OnTime],[OffTime],[IntervalTime],[ByTheTime])values(@OnOffID,@OnTime,@OffTime,@IntervalTime,@ByTheTime) end "; cmd = db.GetSqlStringCommand(tsql); string ids = ""; int tempconunt = 0; foreach (var item in Model.ListModel) { //if (tempconunt == 0) ids = item.OnOffID.ToString(); //else // ids += ", " + item.OnOffID; cmd.Parameters.Clear(); db.AddInParameter(cmd, "@OnOffID", DbType.Int32, a); db.AddInParameter(cmd, "@OnOffDetailID", DbType.Int32, item.OnOffDetailID); db.AddInParameter(cmd, "@OnTime", DbType.String, item.OnTime); db.AddInParameter(cmd, "@OffTime", DbType.String, item.OffTime); db.AddInParameter(cmd, "@IntervalTime", DbType.Int32, item.IntervalTime); db.AddInParameter(cmd, "@ByTheTime", DbType.DateTime, item.ByTheTime); db.ExecuteNonQuery(cmd); tempconunt++; } //if (Model.OnOffID > 0) //{ //tsql = "delete from HW_OnOffDetail where OnOffID=@OnOffID and OnOffDetailID not in (" + ids + ")"; //cmd = db.GetSqlStringCommand(tsql); //db.AddInParameter(cmd, "@OnOffID", DbType.Int32, Model.OnOffID); //db.ExecuteNonQuery(cmd); //} return a; } #endregion #region 删除 public void Delete(int OnOffID) { string tsql = @" delete from HW_OnOffList where OnOffID=@OnOffID delete from HW_OnOffDetail where OnOffID=@OnOffID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OnOffID", DbType.Int32, OnOffID); db.ExecuteNonQuery(cmd); } #endregion #region 删除明细 public void DeleteDetail(int OnOffDetailID) { string tsql = @" delete from HW_OnOffDetail where OnOffDetailID=@OnOffDetailID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OnOffDetailID", DbType.Int32, OnOffDetailID); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static HW_OnOffList GetModel(int OnOffID) { HW_OnOffList model = null; string tsql = "select * from HW_OnOffList where OnOffID=@OnOffID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OnOffID", DbType.Int32, OnOffID); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 分页查询 public List GetListHW_OnOffList(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OnOffID=cast(a.OnOffID as int),a.productIds,a.GoodsCode,a.ShopName,a.ShopID,a.OnOffFlag,a.ProductURL"; ser.Tables = @"HW_OnOffList a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OnOffID"; 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 GetListHW_OnOffDetailList(RefParameterCollection where, RefParameterCollection DetailWhere, int PageIndex, int PageSize, string Sort, out int RowCount) { if (DetailWhere == null) DetailWhere = new RefParameterCollection(); if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.OnOffID,a.productIds,a.GoodsCode,a.ShopName,a.ShopID,a.OnOffFlag,a.ProductURL"; ser.Tables = @"HW_OnOffList a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); if (DetailWhere.Count > 0) { QueryOrdService ser2 = new QueryOrdService(); ser2.Fields = "OnOffID"; ser2.Tables = "HW_OnOffDetail"; ser2.Filter = DetailWhere.GetWhere(System.Data.CommandType.Text); string detailTsql = ser2.GetText(); if (ser.Filter == "") { ser.Filter = " where "; } else { ser.Filter += " and "; } ser.Filter += " OnOffID in (" + detailTsql + ")"; } ser.PageIndex = PageIndex; ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OnOffID"; 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; } #region 返回入库明细 public HW_OnOffList GetListHW_OnOffList(int Id) { HW_OnOffList model = null; string tsql = @" SELECT * FROM HW_OnOffList where OnOffID=@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 List GetListHW_OnOffDetailList(int Id) { List list = null; string tsql = @" SELECT * FROM HW_OnOffDetail where OnOffID=@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 保存 public string SaveHW_OnOffDetail(HW_OnOffDetail Model) { string tsql = @" if @OnOffDetailID>0 begin Update [HW_OnOffDetail] set [OnOffID]=@OnOffID,[OnTime]=@OnTime,[OffTime]=@OffTime,[IntervalTime]=@IntervalTime,[ByTheTime]=@ByTheTime where OnOffDetailID=@OnOffDetailID end else begin INSERT INTO [HW_OnOffDetail]([OnOffID],[OnTime],[OffTime],[IntervalTime],[ByTheTime])values(@OnOffID,@OnTime,@OffTime,@IntervalTime,@ByTheTime) set @OnOffDetailID=SCOPE_IDENTITY() end select @OnOffDetailID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OnOffDetailID", DbType.Int32, Model.OnOffDetailID); db.AddInParameter(cmd, "@OnOffID", DbType.Int32, Model.OnOffID); db.AddInParameter(cmd, "@OnTime", DbType.DateTime, Model.OnTime); db.AddInParameter(cmd, "@OffTime", DbType.DateTime, Model.OffTime); db.AddInParameter(cmd, "@IntervalTime", DbType.Int32, Model.IntervalTime); db.AddInParameter(cmd, "@ByTheTime", DbType.DateTime, Model.ByTheTime); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #endregion #region 标记无货 public void UpdateNoGoods(string GoodsIds) { string tsql = @" update HW_GoodsInfo set NoGoods=1 where GoodsId in (" + GoodsIds+ ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 取消无货 public void UpdateCancelNoGoods(string GoodsIds) { string tsql = @" update HW_GoodsInfo set NoGoods=0 where GoodsId in (" + GoodsIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 标记无货 public void UpdateNoGoodsDetail(string DetailIds) { string tsql = @" update HW_GoodsDetail set NoGoods=1 where DetailId in (" + DetailIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 取消无货 public void UpdateCancelNoGoodsDetail(string DetailIds) { string tsql = @" update HW_GoodsDetail set NoGoods=0 where DetailId in (" + DetailIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 保存备货 public void UpdateGoodsSafeNum(int SafeNum, int DetailId) { string tsql = @" update HW_GoodsDetail set SafeNum=@SafeNum where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, SafeNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.ExecuteNonQuery(cmd); } #endregion #region 返回备货记录 public List GetSafeNumList(int GoodsId, int IsBH, string TypeCode) { List list = null; string tsql = @"select DetailId,TypeCode,TypeDesc,safeNum=isnull(safeNum,0),safeOldNum=isnull(safeNum,0) from HW_GoodsDetail where GoodsId=@GoodsId and (@IsBH=0 or safeNum>0) and (@TypeCode='' or TypeCode=@TypeCode or TypeDesc like '%'+@TypeCode+ '%') order by TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@IsBH", DbType.Int32, IsBH); db.AddInParameter(cmd, "@TypeCode", DbType.String, TypeCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回要压价的货物记录 public List GetLowPriceList(DateTime? InDate, DateTime? SDate, int GoodsId) { List list = null; string tsql = @"select DetailId,GoodsId,TypeCode,TypeDesc,LowPrice=(select min(b.GoodsPrice) from CG_Purchase aa inner join CG_PurchaseGoods b on aa.ChaseId=b.ChaseId where aa.GoodsState>0 and b.InGoodsNum>0 and aa.IsDelete=0 and b.GoodsDetailId=a.DetailId and aa.InDate>=@SDate and aa.InDate<@InDate),LowPrice1=(select min(b.GoodsPrice) from CG_Purchase aa inner join CG_PurchaseGoods b on aa.ChaseId=b.ChaseId where aa.GoodsState>0 and b.InGoodsNum>0 and aa.IsDelete=0 and b.GoodsDetailId=a.DetailId) from HW_GoodsDetail a where GoodsId=@GoodsId order by TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public int SaveBuyPriceOff(HW_GoodsYJDetail Model) { string tsql = @" select top 1 @Id=Id from HW_BuyPriceOff where DetailId=@DetailId and datediff(day,InDate,@InDate)=0 if @Id>0 begin Update [HW_BuyPriceOff] set [GoodsId]=@GoodsId,[DetailId]=@DetailId,[InDate]=@InDate,[LowPrice]=@LowPrice,[Price]=@Price,[OffPrice]=@OffPrice,[Num]=@Num,[InName]=@InName,[UserId]=@UserId where Id=@Id end else begin INSERT INTO [HW_BuyPriceOff]([GoodsId],[DetailId],[InDate],[LowPrice],[Price],[OffPrice],[Num],[InName],[UserId])values(@GoodsId,@DetailId,@InDate,@LowPrice,@Price,@OffPrice,@Num,@InName,@UserId) 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, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@LowPrice", DbType.Decimal, Model.LowPrice); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@OffPrice", DbType.Decimal, Model.OffPrice); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询压价 public List GetListHW_BuyPriceOff(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.GoodsId,a.DetailId,a.InDate,a.LowPrice,a.Price,a.OffPrice,a.Num,a.InName,a.UserId,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc"; ser.Tables = @"HW_BuyPriceOff a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId"; 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 DeleteBuyPriceOff(int Id) { string tsql = @" delete from HW_BuyPriceOff 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 DeleteBuyPriceList(string Ids) { string tsql = @" delete from HW_BuyPriceOff where Id in (" + Ids + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 返回要压价记录 public DataTable GetLowGoodsPriceList(DateTime? SDate, DateTime? EDate) { string tsql = @"select c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,a.Price,a.DetailId,a.InDate,OffPrice=0.00,GoodsNum=0,TotalPrice=0.00 from HW_BuyPriceOff a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.InDate>=@SDate and a.InDate<@EDate order by b.GoodsId,b.TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable dt = db.ExecuteDataTable(cmd); return dt; } #endregion #region 返回三个月最低压 public Decimal GetLowGoodsPrice(DateTime? InDate, DateTime? SDate, int DetailId) { string tsql = @" declare @Price decimal set @Price=0 select @Price=MIN(Price) from HW_GoodsInDetail where DetailId=@DetailId and InDate>=@SDate and InDate<@InDate and OrderGoodsId>0 and CKDetailId>0 if @Price=0 begin select @Price=MIN(Price) from HW_GoodsInDetail a where DetailId in (select distinct a.DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.DetailId=DetailId) and InDate>=@SDate and InDate<@InDate and OrderGoodsId>0 and CKDetailId>0 end select Price=isnull(@Price,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); decimal a =Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回订单总数 public int GetSumGoodsNum(DateTime? InDate, DateTime? SDate, int DetailId, decimal Price) { string tsql = @" select GoodsNum=isnull(SUM(a.GoodsNum),0) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsInDetail c on a.Id=c.OrderGoodsId where a.DetailId=@DetailId and c.Price=@Price and b.State=2 and b.PostDate>=@SDate and b.PostDate<@InDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@Price", DbType.Decimal, Price); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 刷新库存 public void UpdateGoodsNum(int GoodsId) { string tsql = @" update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0 where GoodsId=@GoodsId 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_OrderInfo 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 and a.GoodsId=@GoodsId update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetail a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsNum<>b.GoodsNum and a.GoodsId=@GoodsId update a set a.GoodsInNum=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.BackNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and isnull(IsGJ,0)=0 and isnull(a.IsFactory,0)=0 and isnull(a.IsBH,0)=0 and a.State<3 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId where a.GoodsInNum<>b.GoodsNum and a.GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 保存HW_Quality public static int SaveQuality(HW_Quality Model) { string tsql = @" if @QualityID>0 begin Update [HW_Quality] set [Goodcode]=@Goodcode,[ProductUrl]=@ProductUrl,[ModelPicture]=@ModelPicture,[OriginalPicture]=@OriginalPicture,[CustomProblem]=@CustomProblem,[ColorDif]=@ColorDif,[Infringement]=@Infringement,[QualitOpinion]=@QualitOpinion,[ViceOpinion]=@ViceOpinion,[ManagerOpinion]=@ManagerOpinion,[CategoryID]=@CategoryID,[ClothAll]=@ClothAll,[Problem1]=@Problem1,[Problem2]=@Problem2,[Problem3]=@Problem3,[Problem4]=@Problem4,[Problem5]=@Problem5,[Problem6]=@Problem6,[Problem7]=@Problem7,[Problem8]=@Problem8,[Problem9]=@Problem9,[Problem10]=@Problem10,[SizeTable]=@SizeTable,[VicApply]=@VicApply,[ManApply]=@ManApply,[QuApply]=@QuApply,[GroupName]=@GroupName,[NeedQuality]=@NeedQuality,[color]=@color where QualityID=@QualityID end else begin INSERT INTO [HW_Quality]([Goodcode],[ProductUrl],[ModelPicture],[OriginalPicture],[CustomProblem],[ColorDif],[Infringement],[QualitOpinion],[ViceOpinion],[ManagerOpinion],[CategoryID],[ClothAll],[Problem1],[Problem2],[Problem3],[Problem4],[Problem5],[Problem6],[Problem7],[Problem8],[Problem9],[Problem10],[InDate],[SizeTable],[VicApply],[ManApply],[QuApply],[GroupName],[NeedQuality],[color])values(@Goodcode,@ProductUrl,@ModelPicture,@OriginalPicture,@CustomProblem,@ColorDif,@Infringement,@QualitOpinion,@ViceOpinion,@ManagerOpinion,@CategoryID,@ClothAll,@Problem1,@Problem2,@Problem3,@Problem4,@Problem5,@Problem6,@Problem7,@Problem8,@Problem9,@Problem10,@InDate,@SizeTable,@VicApply,@ManApply,@QuApply,@GroupName,@NeedQuality,@color) set @QualityID=SCOPE_IDENTITY() end select @QualityID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@QualityID", DbType.Int32, Model.QualityID); db.AddInParameter(cmd, "@Goodcode", DbType.String, Model.Goodcode); db.AddInParameter(cmd, "@ProductUrl", DbType.String, Model.ProductUrl); db.AddInParameter(cmd, "@ModelPicture", DbType.String, Model.ModelPicture); db.AddInParameter(cmd, "@OriginalPicture", DbType.String, Model.OriginalPicture); db.AddInParameter(cmd, "@CustomProblem", DbType.String, Model.CustomProblem); db.AddInParameter(cmd, "@ColorDif", DbType.String, Model.ColorDif); db.AddInParameter(cmd, "@Infringement", DbType.String, Model.Infringement); db.AddInParameter(cmd, "@QualitOpinion", DbType.String, Model.QualitOpinion); db.AddInParameter(cmd, "@ViceOpinion", DbType.String, Model.ViceOpinion); db.AddInParameter(cmd, "@ManagerOpinion", DbType.String, Model.ManagerOpinion); db.AddInParameter(cmd, "@CategoryID", DbType.Int32, Model.CategoryID); db.AddInParameter(cmd, "@ClothAll", DbType.String, Model.ClothAll); db.AddInParameter(cmd, "@Problem1", DbType.String, Model.Problem1); db.AddInParameter(cmd, "@Problem2", DbType.String, Model.Problem2); db.AddInParameter(cmd, "@Problem3", DbType.String, Model.Problem3); db.AddInParameter(cmd, "@Problem4", DbType.String, Model.Problem4); db.AddInParameter(cmd, "@Problem5", DbType.String, Model.Problem5); db.AddInParameter(cmd, "@Problem6", DbType.String, Model.Problem6); db.AddInParameter(cmd, "@Problem7", DbType.String, Model.Problem7); db.AddInParameter(cmd, "@Problem8", DbType.String, Model.Problem8); db.AddInParameter(cmd, "@Problem9", DbType.String, Model.Problem9); db.AddInParameter(cmd, "@Problem10", DbType.String, Model.Problem10); db.AddInParameter(cmd, "@SizeTable", DbType.String, Model.SizeTable); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@VicApply", DbType.Int32, Model.VicApply); db.AddInParameter(cmd, "@ManApply", DbType.Int32, Model.ManApply); db.AddInParameter(cmd, "@QuApply", DbType.Int32, Model.QuApply); db.AddInParameter(cmd, "@GroupName", DbType.String, Model.GroupName); db.AddInParameter(cmd, "@NeedQuality", DbType.Int32, Model.NeedQuality); db.AddInParameter(cmd, "@color", DbType.String, Model.color); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); // tsql = @" //if @QualitySizeID>0 //begin //Update [HW_QualitySize] set [QualityID]=@QualityID,[Size]=@Size,[Chest]=@Chest,[SleeveLength]=@SleeveLength,[ColthLength]=@ColthLength,[ShoulderBreadth]=@ShoulderBreadth,[WaistCircue]=@WaistCircue,[HipCircue]=@HipCircue,[PantHeight]=@PantHeight,[LegOpen]=@LegOpen,[ThighCircue]=@ThighCircue,[FeetLong]=@FeetLong where QualitySizeID=@QualitySizeID //end //else //begin //INSERT INTO [HW_QualitySize]([QualityID],[Size],[Chest],[SleeveLength],[ColthLength],[ShoulderBreadth],[WaistCircue],[HipCircue],[PantHeight],[LegOpen],[ThighCircue],[FeetLong])values(@QualityID,@Size,@Chest,@SleeveLength,@ColthLength,@ShoulderBreadth,@WaistCircue,@HipCircue,@PantHeight,@LegOpen,@ThighCircue,@FeetLong) //end //"; // cmd = db.GetSqlStringCommand(tsql); // string ids = ""; // foreach (var item in Model.ListModel) // { // ids += ", " + item.QualityID; // cmd.Parameters.Clear(); // db.AddInParameter(cmd, "@QualitySizeID", DbType.Int32, a); // db.AddInParameter(cmd, "@QualityID", DbType.Int32, item.QualityID); // db.AddInParameter(cmd, "@Size", DbType.String, item.Size); // db.AddInParameter(cmd, "@Chest", DbType.String, item.Chest); // db.AddInParameter(cmd, "@SleeveLength", DbType.String, item.SleeveLength); // db.AddInParameter(cmd, "@ColthLength", DbType.String, item.ColthLength); // db.AddInParameter(cmd, "@ShoulderBreadth", DbType.String, item.ShoulderBreadth); // db.AddInParameter(cmd, "@WaistCircue", DbType.String, item.WaistCircue); // db.AddInParameter(cmd, "@HipCircue", DbType.String, item.HipCircue); // db.AddInParameter(cmd, "@PantHeight", DbType.String, item.PantHeight); // db.AddInParameter(cmd, "@LegOpen", DbType.String, item.LegOpen); // db.AddInParameter(cmd, "@ThighCircue", DbType.String, item.ThighCircue); // db.AddInParameter(cmd, "@FeetLong", DbType.String, item.FeetLong); // db.ExecuteNonQuery(cmd); // } // if (Model.QualityID > 0) // { // tsql = "delete from HW_QualitySize where QualityID=@QualityID and QualitySizeID not in (" + ids + ")"; // cmd = db.GetSqlStringCommand(tsql); // db.AddInParameter(cmd, "@QualityID", DbType.Int32, Model.QualityID); // db.ExecuteNonQuery(cmd); // } return a; } #endregion #region 保存HW_Quality public static int SaveQualityTry(HW_Quality Model) { string tsql = @" if @QualityID>0 begin Update [HW_Quality] set [TryTable]=@TryTable where QualityID=@QualityID end select @QualityID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@QualityID", DbType.Int32, Model.QualityID); db.AddInParameter(cmd, "@TryTable", DbType.String, Model.TryTable); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除HW_Quality public static void DeleteQuality(int QualityID) { string tsql = @" delete from HW_Quality where QualityID=@QualityID delete from HW_QualitySize where QualityID=@QualityID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@QualityID", DbType.Int32, QualityID); db.ExecuteNonQuery(cmd); } #endregion #region 返回HW_Quality Model public static HW_Quality GetQualityModel(int QualityID) { HW_Quality model = null; string tsql = "select * from HW_Quality where QualityID=@QualityID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@QualityID", DbType.Int32, QualityID); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 分页查询HW_Quality public static List GetListHW_Quality(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"QualityID=cast(a.QualityID as int),a.Goodcode,a.ProductUrl,a.ModelPicture,a.OriginalPicture,a.CustomProblem,a.ColorDif,a.Infringement,a.QualitOpinion,ViceOpinion=(CASE WHEN VicApply=1 THEN ViceOpinion+'已审核' ELSE ViceOpinion+'未审核' END),ManagerOpinion=(CASE WHEN ManApply=1 THEN ManagerOpinion+'已审核' ELSE ManagerOpinion+'未审核' END),a.CategoryID,a.ClothAll,a.Problem1,a.Problem2,a.Problem3,a.Problem4,a.color"; ser.Tables = @"HW_Quality a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "QualityID"; 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 static List GetCategory() { string tsql = @" SELECT DISTINCT CategoryName,State FROM dbo.HW_QuCategory "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取类别 public static List GetProblem(int state) { string tsql = @" SELECT * FROM dbo.HW_QuCategory where State=@state "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@state", DbType.Int32, state); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取类别 public static List GetProblem() { string tsql = @" SELECT * FROM dbo.HW_QuCategory "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 查询质检数据 public static HW_Quality GetQualityList(string Goodcode) { HW_Quality model = null; string tsql = @" SELECT top 1 * FROM dbo.HW_Quality where Goodcode=@Goodcode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Goodcode", DbType.String, Goodcode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询质检编号是否存在 public static int ChexkQuality(string Goodcode, int QualityID) { int rowcount=0; string tsql = @" SELECT top 1 * FROM dbo.HW_Quality where Goodcode=@Goodcode and QualityID!=@QualityID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Goodcode", DbType.String, Goodcode); db.AddInParameter(cmd, "@QualityID", DbType.Int32, QualityID); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) rowcount = tb.Rows.Count; return rowcount; } #endregion #region 保存条码数量 public int SaveBarCodeNum(HW_BarCodeNum Model) { string tsql = @" select @Id=Id from HW_BarCodeNum where ChaseId=@ChaseId and [ChaseDetailId]=@ChaseDetailId if @Id>0 begin Update [HW_BarCodeNum] set [Num]=isnull(Num,0)+@Num,[InDate]=@InDate,[InName]=@InName where Id=@Id end else begin INSERT INTO [HW_BarCodeNum]([ChaseId],[ChaseDetailId],[DetailId],[Num],[InDate],[InName])values(@ChaseId,@ChaseDetailId,@DetailId,@Num,@InDate,@InName) 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, "@ChaseDetailId", DbType.Int32, Model.ChaseDetailId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public List GetListHW_NoMate(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.GoodsId,b.ShopName,c.GoodsCode"; ser.Tables = @"HW_NoMate a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId"; 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 int SaveNoMate(HW_NoMateModel Model) { string tsql = @" select top 1 @GoodsId=GoodsId from HW_GoodsInfo where (GoodsCode=@GoodsCode or GoodsOldCode=@GoodsCode) if @GoodsId>0 begin INSERT INTO [HW_NoMate]([ShopId],[GoodsId])values(@ShopId,@GoodsId) set @Id=SCOPE_IDENTITY() end else begin set @Id=0 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, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public void DeleteNoMate(int Id) { string tsql = @" delete from HW_NoMate 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 UpdateGoodsOutNum() { string tsql = @" update HW_GoodsDetail set GoodsHJNum=0 where GoodsHJNum is null update HW_GoodsDetail set GoodsHJNum2=0 where GoodsHJNum2 is null --累计销量 update a set a.GoodsHJNum=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 group by b.DetailId)b on a.DetailId=b.DetailId --最近30天销量 update a set a.GoodsHJNum2=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<30 group by b.DetailId)b on a.DetailId=b.DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 返回skuModel public static HW_GoodsDetail GetGoodsDetailModel(string GoodsCode) { HW_GoodsDetail model = null; string tsql = @"select top 1 b.* from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where a.GoodsCode=@GoodsCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 修改订单打印 public int UpdateOrderPrint2(HW_GoodsOutRecord Model) { string tsql = @" INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId) values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId) set @OutId=SCOPE_IDENTITY() INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId]) select @OutId,GoodsNum,DetailId,0,0 from DT_OrderGoods where OrderId=@OrderId update DT_OrderInfo set PrintState=1,PrintDate=getdate(),MateState=2 where OrderId=@OrderId update DT_OrderInfoNew set PrintState=1,PrintDate=getdate(),MateState=2 where OrderId=@OrderId update b set b.GoodsPlanNum=b.GoodsPlanNum-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"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物库存 public List GetGoodsKCCount(int GoodsId) { List list = null; string tsql = @" select e.StoreName,d.PostionCode,a.Num from ( select a.StoreId,a.PostionId,c.GoodsId,Num=SUM(a.kcnum) 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 KCNum>0 and CKDetailId=0 and c.GoodsId=@GoodsId group by a.StoreId,a.PostionId,c.GoodsId)a inner join CK_StorePostion d on a.PostionId=d.PostionId inner join CK_StoreHouse e on d.StoreId=e.StoreId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public static int Save_GoodsUser(HW_GoodsUser Model) { string tsql = @" select @Id=Id from HW_GoodsUser where [GoodsId]=@GoodsId and [UserId]=@UserId and [ShopId]=@ShopId if @Id>0 begin Update [HW_GoodsUser] set [GoodsId]=@GoodsId,[UserId]=@UserId,[ShopId]=@ShopId where Id=@Id end else begin INSERT INTO [HW_GoodsUser]([GoodsId],[UserId],[ShopId])values(@GoodsId,@UserId,@ShopId) 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, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_GoodsUser(int GoodsId, int UserId) { string tsql = @" delete from HW_GoodsUser where GoodsId=@GoodsId and UserId=@UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 导入跟踪码 public int ImportGoodsInfo(string GoodsCode,string GoodsInfo) { string tsql = @" update HW_GoodsInfo set GoodsInfo=@GoodsInfo where GoodsCode=@GoodsCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, GoodsInfo); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public int Save_GoodsInDetailHWC(HW_GoodsInDetailHWC Model) { string tsql = @" select @DetailId=a.DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (a.SKU1=@SKU or a.SKU2=@SKU or a.SKU3=@SKU or a.SKU4=@SKU or a.SKU5=@SKU) select @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @DetailId=0 begin select -1 end else if @PostionId=0 begin select -2 end else if @InId>0 begin Update [HW_GoodsInDetailHWC] set [DetailId]=@DetailId,[ChaseId]=@ChaseId,[StoreId]=@StoreId,[PostionId]=@PostionId,[Price]=@Price,[PostPrice]=@PostPrice,[InDate]=@InDate,[InUserId]=@InUserId,[OrderGoodsId]=@OrderGoodsId,[KCNum]=@KCNum,[UpDateTime]=@UpDateTime,[RKDetailId]=@RKDetailId,[CKDetailId]=@CKDetailId,[OldNum]=@OldNum,[HWCFee]=@HWCFee,[CompanyId]=@CompanyId where InId=@InId end else begin if @Price<=0 begin select top 1 @Price=Price,@PostPrice=PostPrice from HW_GoodsInDetailHWC where DetailId=@DetailId and Price>0 order by InId desc end INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],[OldNum],[HWCFee],[CompanyId]) values(@DetailId,@ChaseId,@StoreId,@PostionId,@Price,@PostPrice,@InDate,@InUserId,@OrderGoodsId,@KCNum,@UpDateTime,@RKDetailId,@CKDetailId,@OldNum,@HWCFee,@CompanyId) set @InId=SCOPE_IDENTITY() end select @InId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, Model.OrderGoodsId); db.AddInParameter(cmd, "@KCNum", DbType.Int32, Model.KCNum); db.AddInParameter(cmd, "@UpDateTime", DbType.DateTime, Model.UpDateTime); db.AddInParameter(cmd, "@RKDetailId", DbType.Int32, Model.RKDetailId); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, Model.CKDetailId); db.AddInParameter(cmd, "@OldNum", DbType.Int32, Model.OldNum); db.AddInParameter(cmd, "@HWCFee", DbType.Decimal, Model.HWCFee); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public int Save_GoodsInDetailHWC2(HW_GoodsInDetailHWC Model) { string tsql = @" select @DetailId=a.DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and a.SKU=@SKU select @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @DetailId=0 begin select -1 end else if @PostionId=0 begin select -2 end else if @InId>0 begin Update [HW_GoodsInDetailHWC] set [DetailId]=@DetailId,[ChaseId]=@ChaseId,[StoreId]=@StoreId,[PostionId]=@PostionId,[Price]=@Price,[PostPrice]=@PostPrice,[InDate]=@InDate,[InUserId]=@InUserId,[OrderGoodsId]=@OrderGoodsId,[KCNum]=@KCNum,[UpDateTime]=@UpDateTime,[RKDetailId]=@RKDetailId,[CKDetailId]=@CKDetailId,[OldNum]=@OldNum,[HWCFee]=@HWCFee,[CompanyId]=@CompanyId where InId=@InId end else begin update HW_GoodsInDetailHWC set OrderGoodsId=-1,UpDateTime=@UpDateTime where OrderGoodsId=0 and KCNum>0 and PostionId=@PostionId and companyid=@companyid and DetailId=@DetailId if @Price<=0 begin select top 1 @Price=Price,@PostPrice=PostPrice from HW_GoodsInDetailHWC where DetailId=@DetailId and Price>0 order by InId desc end INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],[OldNum],[HWCFee],[CompanyId]) values(@DetailId,@ChaseId,@StoreId,@PostionId,@Price,@PostPrice,@InDate,@InUserId,@OrderGoodsId,@KCNum,@UpDateTime,@RKDetailId,@CKDetailId,@OldNum,@HWCFee,@CompanyId) set @InId=SCOPE_IDENTITY() end select @InId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, Model.OrderGoodsId); db.AddInParameter(cmd, "@KCNum", DbType.Int32, Model.KCNum); db.AddInParameter(cmd, "@UpDateTime", DbType.DateTime, Model.UpDateTime); db.AddInParameter(cmd, "@RKDetailId", DbType.Int32, Model.RKDetailId); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, Model.CKDetailId); db.AddInParameter(cmd, "@OldNum", DbType.Int32, Model.OldNum); db.AddInParameter(cmd, "@HWCFee", DbType.Decimal, Model.HWCFee); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 清空库存 public static void ClearKC(int CompanyId,DateTime UpTime) { string tsql = @"update HW_GoodsInDetailHWC set OrderGoodsId=-1,UpDateTime=@UpDateTime where OrderGoodsId=0 and KCNum>0 and CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@UpDateTime", DbType.DateTime, UpTime); db.ExecuteNonQuery(cmd); } #endregion #region 计算合计 public static void SumKC(int CompanyId) { string tsql = @"delete from HW_GoodsInDetail2 where companyid=@companyid if @CompanyId>1 begin INSERT INTO [HW_GoodsInDetail2] ([DetailId] ,[StoreId] ,[PostionId] ,[InDate] ,[InUserId] ,[KCNum] ,[UpDateTime],companyid) select DetailId,StoreId,PostionId,GETDATE(),1,KCNum=SUM(KCNum),null,companyid=@CompanyId from HW_GoodsInDetailHWC where StoreId=6 and companyid=@CompanyId and OrderGoodsId=0 and KCNum>0 group by StoreId,PostionId,DetailId end else begin INSERT INTO [HW_GoodsInDetail2] ([DetailId] ,[StoreId] ,[PostionId] ,[InDate] ,[InUserId] ,[KCNum] ,[UpDateTime],companyid) select DetailId,StoreId,PostionId,GETDATE(),1,KCNum=SUM(KCNum),null,companyid=@CompanyId from HW_GoodsInDetail where StoreId=6 and OrderGoodsId=0 and KCNum>0 group by StoreId,PostionId,DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public int Save_GoodsMove(HW_GoodsMove Model) { string tsql = @" select top 1 @NewPostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @Id>0 begin Update [HW_GoodsMove] set [OldPostionId]=@OldPostionId,[NewPostionId]=@NewPostionId,[DetailId]=@DetailId,[Num]=@Num,[InDate]=@InDate,[InName]=@InName where Id=@Id end else begin INSERT INTO [HW_GoodsMove]([OldPostionId],[NewPostionId],[DetailId],[Num],[InDate],[InName])values(@OldPostionId,@NewPostionId,@DetailId,@Num,@InDate,@InName) 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, "@OldPostionId", DbType.Int32, Model.OldPostionId); db.AddInParameter(cmd, "@NewPostionId", DbType.Int32, Model.NewPostionId); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public int Save_GoodsMove2(HW_GoodsMove Model) { string tsql = @" select top 1 @Num=KCNum,@DetailId=DetailId from HW_GoodsInDetail where InId=@InId if @Id>0 begin Update [HW_GoodsMove] set [OldPostionId]=@OldPostionId,[NewPostionId]=@NewPostionId,[DetailId]=@DetailId,[Num]=@Num,[InDate]=@InDate,[InName]=@InName where Id=@Id end else begin INSERT INTO [HW_GoodsMove]([OldPostionId],[NewPostionId],[DetailId],[Num],[InDate],[InName])values(@OldPostionId,@NewPostionId,@DetailId,@Num,@InDate,@InName) 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, "@OldPostionId", DbType.Int32, Model.OldPostionId); db.AddInParameter(cmd, "@NewPostionId", DbType.Int32, Model.NewPostionId); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public List GetListGoodsMove(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.OldPostionId,a.NewPostionId,a.DetailId,a.Num,a.InDate,a.InName,b.PostionCode,NewPostionCode=c.PostionCode,e.GoodsCode,d.TypeCode,d.SKU1,d.TypeDesc"; ser.Tables = @"HW_GoodsMove a inner join CK_StorePostion b on a.OldPostionId=b.PostionId inner join CK_StorePostion c on a.NewPostionId=c.PostionId inner join HW_GoodsDetail d on a.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId"; 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 static List GetListFeeReport(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.InDate,a.FeeType,a.TotalFee,a.FeeDesc,a.CompanyId,a.Num,a.Num2,a.Dec,a.Dec2"; ser.Tables = @"CK_FeeReport a"; 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 public void SaveGoodsInInnerIn2(HW_GoodsInRK Model) { string sql = @"if @StoreId is null or @StoreId=0 select @StoreId=StoreId from CK_StorePostion where PostionId=@PostionId update HW_GoodsDetail set GoodsNum=GoodsNum+@InNum where DetailId=@DetailId if @InNum>0 begin declare @HWCFee money select top 1 @Price=[Price],@PostPrice=[PostPrice],@HWCFee=[HWCFee] from [HW_GoodsInDetail] where DetailId=@DetailId order by InId desc INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],[OldNum],[Companyid],[HWCFee]) values(@DetailId,0,@StoreId,@PostionId,@Price,@PostPrice,GETDATE(),@InUserId,0,@InNum,null,@RKDetailId,0,@InNum,@Companyid,@HWCFee) end "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(sql); database.AddInParameter(sqlStringCommand, "@InNum", DbType.Int32, Model.InNum); database.AddInParameter(sqlStringCommand, "@PostionId", DbType.Int32, Model.PostionId); database.AddInParameter(sqlStringCommand, "@DetailId", DbType.Int32, Model.DetailId); database.AddInParameter(sqlStringCommand, "@StoreId", DbType.Int32, Model.StoreId); database.AddInParameter(sqlStringCommand, "@Price", DbType.Decimal, Model.Price); database.AddInParameter(sqlStringCommand, "@PostPrice", DbType.Decimal, Model.PostPrice); database.AddInParameter(sqlStringCommand, "@InUserId", DbType.Decimal, Model.InUserId); database.AddInParameter(sqlStringCommand, "@RKDetailId", DbType.Decimal, Model.RKDetailId); database.AddInParameter(sqlStringCommand, "@Companyid", DbType.Decimal, Model.Companyid); database.ExecuteNonQuery(sqlStringCommand); } public List GetGoodsCKDetail22(int CompanyId, string GoodsCode) { string query = "select a.* from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and b.GoodsCode=@GoodsCode order by a.TypeCode"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@CompanyId", DbType.Int32, CompanyId); database.AddInParameter(sqlStringCommand, "@GoodsCode", DbType.String, GoodsCode); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } } }