/// <summary> /// 出库解冻 /// </summary> /// <param name="stocksInfo"></param> /// <param name="tranDetailsId"></param> /// <param name="loginUser"></param> /// <returns></returns> public bool StocksThaw(StocksInfo stocksInfo, long tranDetailsId, string loginUser) { //包装数、冻结数、散装数、库存数、采购金额做递减 string sql = "update [LES].[TT_WMM_STOCKS] " + "set [PACKAGE] = [PACKAGE] - @PACKAGE" + ",[FROZEN_STOCKS] = [FROZEN_STOCKS] - @FROZEN_STOCKS" + ",[FRAGMENT_NUM] = [FRAGMENT_NUM] - @FRAGMENT_NUM " + ",[STOCKS_NUM] = [STOCKS_NUM] - @STOCKS_NUM " + ",[SALE_PART_PRICE] = [SALE_PART_PRICE] -s @SALE_PART_PRICE" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE() " + "where [ID] = @ID;" + "update [LES].[TT_WMM_TRAN_DETAILS] " + "set [TRAN_STATE] = @TRAN_STATE" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE() " + "where [ID] = @TRAN_DETAILS_ID;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PACKAGE", DbType.Int32, stocksInfo.Package); db.AddInParameter(cmd, "@FROZEN_STOCKS", DbType.Decimal, stocksInfo.FrozenStocks); db.AddInParameter(cmd, "@FRAGMENT_NUM", DbType.Decimal, stocksInfo.FragmentNum); db.AddInParameter(cmd, "@STOCKS_NUM", DbType.Decimal, stocksInfo.StocksNum); //db.AddInParameter(cmd, "@SALE_PART_PRICE", DbType.Decimal, stocksInfo.SalePartPrice); db.AddInParameter(cmd, "@MODIFY_USER", DbType.AnsiString, loginUser); db.AddInParameter(cmd, "@ID", DbType.Int64, stocksInfo.Id); db.AddInParameter(cmd, "@TRAN_STATE", DbType.Int32, (int)WmmTranStateConstants.Done); db.AddInParameter(cmd, "@TRAN_DETAILS_ID", DbType.Int64, tranDetailsId); return(db.ExecuteNonQuery(cmd) > 0 ? true : false); }
/// <summary> /// /// </summary> /// <param name="stocksInfo"></param> /// <param name="tranDetailsId"></param> /// <returns></returns> public bool StocksUp(StocksInfo stocksInfo, long tranDetailsId, string loginUser) { string sql = "update [LES].[TT_WMM_STOCKS] " + "set [STOCKS] = [STOCKS] + @STOCKS" + ",[AVAILBLE_STOCKS] = [AVAILBLE_STOCKS] + @AVAILBLE_STOCKS" + ",[FRAGMENT_NUM] = [FRAGMENT_NUM] + @FRAGMENT_NUM " + ",[STOCKS_NUM] = [STOCKS_NUM] + @STOCKS_NUM " + ",[PURCHASE_PART_PRICE] = [PURCHASE_PART_PRICE] + @PURCHASE_PART_PRICE" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE() " + "where [ID] = @ID;" + "update [LES].[TT_WMM_TRAN_DETAILS] " + "set [TRAN_STATE] = @TRAN_STATE" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE() " + "where [ID] = @TRAN_DETAILS_ID;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@STOCKS", DbType.Int32, stocksInfo.Stocks); db.AddInParameter(cmd, "@AVAILBLE_STOCKS", DbType.Decimal, stocksInfo.AvailbleStocks); db.AddInParameter(cmd, "@FRAGMENT_NUM", DbType.Decimal, stocksInfo.FragmentNum); db.AddInParameter(cmd, "@STOCKS_NUM", DbType.Decimal, stocksInfo.StocksNum); //db.AddInParameter(cmd, "@PURCHASE_PART_PRICE", DbType.Decimal, stocksInfo.PurchasePartPrice); db.AddInParameter(cmd, "@MODIFY_USER", DbType.AnsiString, loginUser); db.AddInParameter(cmd, "@ID", DbType.Int64, stocksInfo.Id); db.AddInParameter(cmd, "@TRAN_STATE", DbType.Int32, (int)WmmTranStateConstants.Done); db.AddInParameter(cmd, "@TRAN_DETAILS_ID", DbType.Int64, tranDetailsId); return(db.ExecuteNonQuery(cmd) > 0 ? true : false); }
/// <summary> /// 原库冻结 /// </summary> /// <param name="stocksInfo"></param> /// <param name="tranDetailsId"></param> /// <param name="loginUser"></param> /// <returns></returns> public bool StocksStatusThaw(StocksInfo stocksInfo, long tranDetailsId, string loginUser) { //可用数做累加 //冻结数做递减 string sql = "update [LES].[TT_WMM_STOCKS] " + ",[AVAILBLE_STOCKS] = [AVAILBLE_STOCKS] + @AVAILBLE_STOCKS" + ",[FROZEN_STOCKS] = [FROZEN_STOCKS] - @FROZEN_STOCKS" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE() " + "where [ID] = @ID;" + "update [LES].[TT_WMM_TRAN_DETAILS] " + "set [TRAN_STATE] = @TRAN_STATE" + ",[MODIFY_USER] = @MODIFY_USER" + ",[MODIFY_DATE] = GETDATE()" + "where [ID] = @TRAN_DETAILS_ID;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@AVAILBLE_STOCKS", DbType.Decimal, stocksInfo.AvailbleStocks); db.AddInParameter(cmd, "@FROZEN_STOCKS", DbType.Decimal, stocksInfo.FrozenStocks); db.AddInParameter(cmd, "@MODIFY_USER", DbType.AnsiString, loginUser); db.AddInParameter(cmd, "@ID", DbType.Int64, stocksInfo.Id); db.AddInParameter(cmd, "@TRAN_STATE", DbType.Int32, (int)WmmTranStateConstants.Done); db.AddInParameter(cmd, "@TRAN_DETAILS_ID", DbType.Int64, tranDetailsId); return(db.ExecuteNonQuery(cmd) > 0 ? true : false); }
/// <summary> /// 根据匹配库存数据更新交易记录 /// </summary> /// <param name="stocksInfo"></param> /// <param name="tranDetailsInfo"></param> public static void GetTranDetailsInfo(StocksInfo stocksInfo, ref TranDetailsInfo tranDetailsInfo) { if (stocksInfo == null) { return; } ///是否已结算 tranDetailsInfo.SettledFlag = stocksInfo.SettledFlag; ///库存的逻辑外键 //tranDetailsInfo.StocksFid = stocksInfo.Fid; ///来源库位 tranDetailsInfo.Dloc = stocksInfo.Dloc; ///匹配数量 if (stocksInfo.MatchedQty != null) { tranDetailsInfo.ActualQty = stocksInfo.MatchedQty; ///重新计算包装数量 if (tranDetailsInfo.Package == null || tranDetailsInfo.Package.GetValueOrDefault() == 0) { tranDetailsInfo.Package = 1; } tranDetailsInfo.ActualPackageQty = Convert.ToInt32(Math.Ceiling(stocksInfo.MatchedQty.GetValueOrDefault() / tranDetailsInfo.Package.GetValueOrDefault())); } ///如果没有供应商则根据库存数据中的供应商赋值 if (string.IsNullOrEmpty(tranDetailsInfo.SupplierNum)) { tranDetailsInfo.SupplierNum = stocksInfo.SupplierNum; } ///SETTLED_FLAG }
/// <summary> /// 用于单据衔接 /// </summary> /// <param name="stocksInfo"></param> /// <param name="tranDetailsInfo"></param> public static void GetTranDetailsInfo2(StocksInfo stocksInfo, ref TranDetailsInfo tranDetailsInfo) { if (stocksInfo == null) { return; } tranDetailsInfo.BatchNo = stocksInfo.BatchNo; tranDetailsInfo.PartNo = stocksInfo.PartNo; tranDetailsInfo.BarcodeData = stocksInfo.BarcodeData; tranDetailsInfo.WmNo = stocksInfo.WmNo; tranDetailsInfo.ZoneNo = stocksInfo.ZoneNo; tranDetailsInfo.Dloc = stocksInfo.Dloc; tranDetailsInfo.MeasuringUnitNo = stocksInfo.PartUnits; tranDetailsInfo.Package = stocksInfo.Package; tranDetailsInfo.Max = stocksInfo.Max; tranDetailsInfo.Min = stocksInfo.Min; tranDetailsInfo.SupplierNum = stocksInfo.SupplierNum; tranDetailsInfo.PartCname = stocksInfo.PartCname; tranDetailsInfo.PartNickname = stocksInfo.PartNickname; tranDetailsInfo.PackageModel = stocksInfo.PackageModel; tranDetailsInfo.PartCls = stocksInfo.PartCls; tranDetailsInfo.PartUnits = stocksInfo.PartUnits; tranDetailsInfo.IsBatch = stocksInfo.IsBatch; //tranDetailsInfo.OriginPlace = stocksInfo.OriginPlace; tranDetailsInfo.PartPrice = stocksInfo.PartPrice; //tranDetailsInfo.CostCenter = stocksInfo.CostCenter; //tranDetailsInfo.SettledFlag = stocksInfo.SettledFlag; tranDetailsInfo.Keeper = stocksInfo.Keeper; tranDetailsInfo.StocksFid = stocksInfo.Fid; }
/// <summary> /// 将交易记录加工为库存投放数据 /// </summary> /// <param name="tranDetailsInfo"></param> /// <param name="zonesInfo"></param> /// <param name="sourceFlag"></param> /// <returns></returns> private StocksInfo HandlingStocksData(TranDetailsInfo tranDetailsInfo, MaintainPartsInfo maintainPartsInfo, ZonesInfo zonesInfo, bool sourceFlag) { ///新建库存对象 StocksInfo stocksInfo = stocksBLL.CreateStocksInfo(loginUser); ///更新物料基础信息 stocksBLL.UpdateMaintainPartsInfo(maintainPartsInfo, ref stocksInfo); ///来源库存对象信息填充 if (sourceFlag) { stocksBLL.GetSourceStocksInfo(tranDetailsInfo, ref stocksInfo); } ///目标库存对象信息填充 else { stocksBLL.GetTargetStocksInfo(tranDetailsInfo, zonesInfo, ref stocksInfo); } ///根据库存管理维度获取更新条件 string stockUpdateConditions = GetStockUpdateConditions(ref stocksInfo); ///若交易数据指定了库存数据外键,则根据外键获取主键 if (sourceFlag && tranDetailsInfo.StocksFid != null) { stocksInfo.Id = stocksBLL.GetStocksId(tranDetailsInfo.StocksFid.GetValueOrDefault()); } ///获取库存数据主键 if (stocksInfo.Id == 0) { stocksInfo.Id = stocksBLL.GetStocksId(stocksInfo, stockUpdateConditions); } return(stocksInfo); }
/// <summary> /// 根据标记生成更新库存条件 /// </summary> /// <param name="stocksInfo"></param> /// <returns></returns> private string GetStockUpdateConditions(ref StocksInfo stocksInfo) { string stockUpdateConditions = string.Empty; ///恒定条件为物料号、仓库、存储区、库位 ///PART_NO stockUpdateConditions += "and [PART_NO] = N'" + stocksInfo.PartNo + "' "; ///WM_NO stockUpdateConditions += "and [WM_NO] = N'" + stocksInfo.WmNo + "' "; ///ZONE_NO stockUpdateConditions += "and [ZONE_NO] = N'" + stocksInfo.ZoneNo + "' "; ///DLOC stockUpdateConditions += "and isnull([DLOC],'') = N'" + stocksInfo.Dloc + "' "; ///SUPPLIER_NUM stockUpdateConditions += supplierFlag ? "and isnull([SUPPLIER_NUM],'') = N'" + stocksInfo.SupplierNum + "' " : string.Empty; stocksInfo.SupplierNum = supplierFlag ? stocksInfo.SupplierNum : string.Empty; ///PLANT stockUpdateConditions += plantFlag ? "and isnull([PLANT],'') = N'" + stocksInfo.Plant + "' " : string.Empty; stocksInfo.Plant = plantFlag ? stocksInfo.Plant : string.Empty; ///PACKAGE_MODEL stockUpdateConditions += packageModelFlag ? "and isnull([PACKAGE_MODEL],'') = N'" + stocksInfo.PackageModel + "' " : string.Empty; stocksInfo.PackageModel = packageModelFlag ? stocksInfo.PackageModel : string.Empty; stocksInfo.Package = packageModelFlag ? stocksInfo.Package : 0; ///PART_CLS stockUpdateConditions += partClsFlag ? "and isnull([PART_CLS],'') = N'" + stocksInfo.PartCls + "' " : string.Empty; stocksInfo.PartCls = partClsFlag ? stocksInfo.PartCls : string.Empty; ///BATCH_NO,需要系统配置与物料仓储信息批次标记同时开启时才真正启用批次 if (batchFlag && stocksInfo.IsBatch.GetValueOrDefault() == 1) { stockUpdateConditions += "and isnull([BATCH_NO],'') = N'" + stocksInfo.BatchNo + "' "; } else { stocksInfo.BatchNo = string.Empty; } ///BARCODE_DATA stockUpdateConditions += barcodeFlag ? "and isnull([BARCODE_DATA],'') = N'" + stocksInfo.BarcodeData + "' " : string.Empty; stocksInfo.BarcodeData = barcodeFlag ? stocksInfo.BarcodeData : string.Empty; stocksInfo.BarcodeType = barcodeFlag ? stocksInfo.BarcodeType : string.Empty; ///ORIGIN_PLACE //stockUpdateConditions += originPlaceFlag ? "and isnull([ORIGIN_PLACE],'') = N'" + stocksInfo.OriginPlace + "' " : string.Empty; //stocksInfo.OriginPlace = originPlaceFlag ? stocksInfo.OriginPlace : string.Empty; ///COST_CENTER //stockUpdateConditions += costCenterFlag ? "and isnull([COST_CENTER],'') = N'" + stocksInfo.CostCenter + "' " : string.Empty; //stocksInfo.CostCenter = costCenterFlag ? stocksInfo.CostCenter : string.Empty; ///SETTLED_FLAG stockUpdateConditions += settlementFlag ? "and isnull([SETTLED_FLAG],0) = " + (stocksInfo.SettledFlag.GetValueOrDefault() ? 1 : 0) + " " : string.Empty; stocksInfo.SettledFlag = settlementFlag ? stocksInfo.SettledFlag : null; return(stockUpdateConditions); }
/// <summary> /// 将数量及金额取得逆值 /// </summary> /// <param name="stocksInfo"></param> private void UndoStock(ref StocksInfo stocksInfo) { ///包装数量 stocksInfo.Stocks = 0 - stocksInfo.Stocks.GetValueOrDefault(); ///散件数量 stocksInfo.FragmentNum = 0 - stocksInfo.FragmentNum.GetValueOrDefault(); ///库存件数 stocksInfo.StocksNum = 0 - stocksInfo.StocksNum.GetValueOrDefault(); ///采购价值 //stocksInfo.PurchasePartPrice = 0 - stocksInfo.PurchasePartPrice.GetValueOrDefault(); /////销售价值 //stocksInfo.SalePartPrice = 0 - stocksInfo.SalePartPrice.GetValueOrDefault(); }
public Task <StocksInfo[]> GetStocksInfo(string symbol) { GetStockInfonvoked = true; if (symbol == "MSFT") { var stocksInfo = new StocksInfo[5]; return(Task.FromResult(stocksInfo)); } else if (symbol == "GOOG") { return(Task.FromResult <StocksInfo[]>(null)); } else { throw new InvalidOperationException(); } }
/// <summary> /// InitStockInfo /// </summary> /// <param name="info"></param> /// <returns></returns> public long InitStockInfo(StocksInfo info) { Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(TT_WMS_STOCKS_INSERT); db.AddInParameter(dbCommand, "@FID", DbType.Guid, info.Id); db.AddInParameter(dbCommand, "@PLANT", DbType.String, info.Plant); db.AddInParameter(dbCommand, "@ASSEMBLY_LINE", DbType.String, info.AssemblyLine); db.AddInParameter(dbCommand, "@PLANT_ZONE", DbType.String, info.PlantZone); db.AddInParameter(dbCommand, "@WORKSHOP", DbType.String, info.Workshop); db.AddInParameter(dbCommand, "@SUPPLIER_NUM", DbType.String, info.SupplierNum); db.AddInParameter(dbCommand, "@PART_NO", DbType.String, info.PartNo); db.AddInParameter(dbCommand, "@PART_CNAME", DbType.String, info.PartCname); db.AddInParameter(dbCommand, "@PART_ENAME", DbType.String, info.PartEname); db.AddInParameter(dbCommand, "@PART_NICKNAME", DbType.String, info.PartNickname); db.AddInParameter(dbCommand, "@PART_UNITS", DbType.String, info.PartUnits); db.AddInParameter(dbCommand, "@PACKAGE_MODEL", DbType.String, info.PackageModel); db.AddInParameter(dbCommand, "@PACKAGE", DbType.Decimal, info.Package); db.AddInParameter(dbCommand, "@LOGICAL_PK", DbType.String, info.LogicalPk); db.AddInParameter(dbCommand, "@ROUTE", DbType.String, info.Route); db.AddInParameter(dbCommand, "@ZONE_NO", DbType.String, info.ZoneNo); db.AddInParameter(dbCommand, "@WM_NO", DbType.String, info.WmNo); db.AddInParameter(dbCommand, "@OCCUPY_AREA", DbType.Decimal, info.OccupyArea); db.AddInParameter(dbCommand, "@DLOC", DbType.String, info.Dloc); db.AddInParameter(dbCommand, "@MAX", DbType.Decimal, info.Max); db.AddInParameter(dbCommand, "@MIN", DbType.Decimal, info.Min); db.AddInParameter(dbCommand, "@ROW_NUMBER", DbType.Int32, info.RowNumber); db.AddInParameter(dbCommand, "@LINE_NUMBER", DbType.Int32, info.LineNumber); db.AddInParameter(dbCommand, "@HIGH_NUMBER", DbType.Int32, info.HighNumber); db.AddInParameter(dbCommand, "@MATERIAL_GROUP", DbType.String, info.MaterialGroup); db.AddInParameter(dbCommand, "@KEEPER", DbType.String, info.Keeper); db.AddInParameter(dbCommand, "@TRANSER", DbType.String, info.Transer); db.AddInParameter(dbCommand, "@INFORMATIONER", DbType.String, info.Informationer); db.AddInParameter(dbCommand, "@ELOC", DbType.String, info.Eloc); db.AddInParameter(dbCommand, "@SAFE_STOCK", DbType.Decimal, info.SafeStock); db.AddInParameter(dbCommand, "@STOCKS", DbType.Int32, 0); db.AddInParameter(dbCommand, "@FROZEN_STOCKS", DbType.Decimal, 0); db.AddInParameter(dbCommand, "@AVAILBLE_STOCKS", DbType.Decimal, 0); db.AddInParameter(dbCommand, "@IS_BATCH", DbType.Int32, info.IsBatch); db.AddInParameter(dbCommand, "@WMS_RULE", DbType.String, info.WmsRule); db.AddInParameter(dbCommand, "@COUNTER", DbType.Decimal, info.Counter); db.AddInParameter(dbCommand, "@FRAGMENT_NUM", DbType.Decimal, 0); db.AddInParameter(dbCommand, "@STOCKS_NUM", DbType.Decimal, 0); db.AddInParameter(dbCommand, "@PART_WEIGHT", DbType.Decimal, info.PartWeight); db.AddInParameter(dbCommand, "@PART_CLS", DbType.String, info.PartCls); db.AddInParameter(dbCommand, "@IS_REPACK", DbType.Int32, info.IsRepack); db.AddInParameter(dbCommand, "@REPACK_ROUTE", DbType.String, info.RepackRoute); db.AddInParameter(dbCommand, "@IS_TRIGGER_PULL", DbType.Int32, info.IsTriggerPull); db.AddInParameter(dbCommand, "@TRIGGER_WM_NO", DbType.String, info.TriggerWmNo); db.AddInParameter(dbCommand, "@TRIGGER_ZONE_NO", DbType.String, info.TriggerZoneNo); db.AddInParameter(dbCommand, "@TRIGGER_DLOC", DbType.String, info.TriggerDloc); db.AddInParameter(dbCommand, "@EMG_TIME", DbType.Int32, info.EmgTime); db.AddInParameter(dbCommand, "@SUPPER_ZONE_DLOC", DbType.String, info.SupperZoneDloc); db.AddInParameter(dbCommand, "@CHECK_TYPE", DbType.Int32, info.CheckType); db.AddInParameter(dbCommand, "@BUSINESS_PK", DbType.String, info.BusinessPk); db.AddInParameter(dbCommand, "@BATCH_NO", DbType.String, info.BatchNo); db.AddInParameter(dbCommand, "@BARCODE_DATA", DbType.String, info.BarcodeData); db.AddInParameter(dbCommand, "@BARCODE_TYPE", DbType.String, info.BarcodeType); //db.AddInParameter(dbCommand, "@ORIGIN_PLACE", DbType.String, info.OriginPlace); //db.AddInParameter(dbCommand, "@PURCHASE_PART_PRICE", DbType.Decimal, info.PurchasePartPrice); //db.AddInParameter(dbCommand, "@SALE_PART_PRICE", DbType.Decimal, info.SalePartPrice); //db.AddInParameter(dbCommand, "@COST_CENTER", DbType.String, info.CostCenter); db.AddInParameter(dbCommand, "@COMMENTS", DbType.String, info.Comments); //db.AddInParameter(dbCommand, "@VALID_FLAG", DbType.Boolean, info.ValidFlag); db.AddInParameter(dbCommand, "@CREATE_USER", DbType.String, info.CreateUser); db.AddInParameter(dbCommand, "@CREATE_DATE", DbType.DateTime, info.CreateDate); //db.AddInParameter(dbCommand, "@MODIFY_USER", DbType.String, info.ModifyUser); //db.AddInParameter(dbCommand, "@MODIFY_DATE", DbType.DateTime, info.ModifyDate); db.AddInParameter(dbCommand, "@PART_PRICE", DbType.Decimal, info.PartPrice); //db.AddInParameter(dbCommand, "@SETTLED_FLAG", DbType.Boolean, info.SettledFlag); //db.AddInParameter(dbCommand, "@PRIOR_USE_FLAG", DbType.Boolean, info.PriorUseFlag); return(long.Parse("0" + db.ExecuteScalar(dbCommand))); }
/// <summary> /// Handler /// </summary> public void Handler() { InitConfigFlag(); ///获取未同步的交易记录 List <TranDetailsInfo> tranDetailsInfos = new TranDetailsBLL().GetList("[TRAN_STATE] = " + (int)WmmTranStateConstants.Created + "", "[ID]"); if (tranDetailsInfos.Count == 0) { return; } ///仓库 List <string> wmNos = tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.WmNo)).Select(d => d.WmNo).ToList(); wmNos.AddRange(tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.TargetWm)).Select(d => d.TargetWm).ToList()); List <WarehouseInfo> warehouseInfos = new WarehouseBLL().GetList("[WAREHOUSE] in ('" + string.Join("','", wmNos.ToArray()) + "')", string.Empty); ///存储区 List <string> zoneNos = tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.ZoneNo)).Select(d => d.ZoneNo).ToList(); zoneNos.AddRange(tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.TargetZone)).Select(d => d.TargetZone).ToList()); List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("[ZONE_NO] in ('" + string.Join("','", zoneNos.ToArray()) + "')", string.Empty); ///工厂 List <PlantInfo> plantInfos = new PlantBLL().GetListForInterfaceDataSync(); ///供应商 List <SupplierInfo> supplierInfos = new SupplierBLL().GetListForInterfaceDataSync(tranDetailsInfos.Select(d => d.SupplierNum).ToList()); ///物料 List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetListForInterfaceDataSync(tranDetailsInfos.Select(d => d.PartNo).ToList()); ///逐条处理 foreach (var tranDetailsInfo in tranDetailsInfos) { StringBuilder stringBuilder = new StringBuilder(); ///工厂 PlantInfo plantInfo = plantInfos.FirstOrDefault(d => d.Plant == tranDetailsInfo.Plant); ///供应商 SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == tranDetailsInfo.SupplierNum); ///目标仓库 WarehouseInfo targetWarehouseInfo = warehouseInfos.FirstOrDefault(d => d.Warehouse == tranDetailsInfo.TargetWm); ///目标存储区 ZonesInfo targetZonesInfo = zonesInfos.FirstOrDefault(d => d.ZoneNo == tranDetailsInfo.TargetZone); ///目标工厂 PlantInfo targetPlantInfo = targetZonesInfo == null ? null : plantInfos.FirstOrDefault(d => d.Plant == targetZonesInfo.Plant); ///来源 ZonesInfo sourceZonesInfo = zonesInfos.FirstOrDefault(d => d.ZoneNo == tranDetailsInfo.ZoneNo); ///来源工厂 PlantInfo sourcePlantInfo = sourceZonesInfo == null ? null : plantInfos.FirstOrDefault(d => d.Plant == sourceZonesInfo.Plant); ///物料信息 MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == tranDetailsInfo.PartNo && d.Plant == tranDetailsInfo.Plant); ///创建库存对象 StocksInfo stocksInfo = null; /// switch (tranDetailsInfo.TranType.GetValueOrDefault()) { ///物料入库 case (int)WmmTranTypeConstants.Inbound: ///目标可用库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///撤销入库 case (int)WmmTranTypeConstants.UndoInbound: stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); UndoStock(ref stocksInfo); stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///物料出库 case (int)WmmTranTypeConstants.Outbound: ///来源可用库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///撤销出库 case (int)WmmTranTypeConstants.UndoOutbound: stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); UndoStock(ref stocksInfo); stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///冻结入库 case (int)WmmTranTypeConstants.FrozenInbound: ///目标冻结库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///冻结出库 case (int)WmmTranTypeConstants.FrozenOutbound: ///来源冻结库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///物料冻结 case (int)WmmTranTypeConstants.MaterialFreezing: ///来源可用库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///目标冻结库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///状态冻结 case (int)WmmTranTypeConstants.StateFreezing: ///来源可用库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///来源冻结库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///物料解冻 case (int)WmmTranTypeConstants.MaterialThawing: ///来源冻结库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///目标可用库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///状态解冻 case (int)WmmTranTypeConstants.StateThawing: ///来源可用库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///来源冻结库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///冻结移动 case (int)WmmTranTypeConstants.FrozenMovement: ///来源冻结库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///目标冻结库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; ///物料移动 case (int)WmmTranTypeConstants.Movement: ///来源可用库存减少 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true); stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser)); ///目标可用库存增加 stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false); stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser)); break; default: continue; } ///SAP移动数据 stringBuilder.AppendFormat(CreateSapTranData(tranDetailsInfo, sourceZonesInfo, targetZonesInfo, sourcePlantInfo, targetPlantInfo)); ///SRM入库数据 stringBuilder.AppendFormat(CreateSrmTranData(tranDetailsInfo, supplierInfo, targetWarehouseInfo)); ///WMS入库数据 stringBuilder.AppendFormat(CreateVmiTranData(tranDetailsInfo, supplierInfo, targetWarehouseInfo)); #region 执行 using (TransactionScope trans = new TransactionScope()) { if (stringBuilder.Length > 0) { BLL.LES.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString()); } trans.Complete(); } #endregion Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + stocksInfo.PartNo + "|" + tranDetailsInfo.TranType.GetValueOrDefault() + "|" + stocksInfo.WmNo + "|" + stocksInfo.ZoneNo + "|" + stocksInfo.Dloc + "|"); } }