add-修改CTU移库,添加移库记录

master
liuwf 1 year ago
parent 714966307b
commit 9fbe84cf2c

@ -0,0 +1,120 @@
//-----------------------------------------------------------------------
//<copyright>
// * Copyright (C) 2021 KEHAIDASOFT All Rights Reserved
// * version : 4.0.30319.42000
// * author : khd by t4-2
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Khd.Core.Domain.Models
{
[Table("wms_move")]
public class WmsMove
{
[Key]
[Column("move_id")]
public long MoveId { get; set; }
[Required]
[Column("task_code")]
[MaxLength(128)]
public string TaskCode { get; set; }
[Required]
[Column("warehouse_id")]
public long WarehouseId { get; set; }
[Required]
[Column("ori_location_code")]
[MaxLength(64)]
public string OriLocationCode { get; set; }
[Required]
[Column("target_location_code")]
[MaxLength(64)]
public string TargetLocationCode { get; set; }
[Column("instock_batch")]
[MaxLength(64)]
public string InstockBatch { get; set; }
[Column("material_id")]
public long? MaterialId { get; set; }
[Column("plan_amount")]
public decimal? PlanAmount { get; set; }
[Column("real_outstock_amount")]
public decimal RealOutstockAmount { get; set; } = 0.000000m;
[Column("real_instock_amount")]
public decimal RealInstockAmount { get; set; } = 0.000000m;
[Required]
[Column("operation_type")]
[MaxLength(1)]
public string OperationType { get; set; }
[Required]
[Column("move_way")]
[MaxLength(1)]
public string MoveWay { get; set; }
[Required]
[Column("move_type")]
[MaxLength(1)]
public string MoveType { get; set; }
[Column("apply_reason")]
[MaxLength(500)]
public string ApplyReason { get; set; }
[Column("audit_reason")]
[MaxLength(500)]
public string AuditReason { get; set; }
[Required]
[Column("audit_status")]
[MaxLength(1)]
public string AuditStatus { get; set; }
[Required]
[Column("execute_status")]
[MaxLength(1)]
public string ExecuteStatus { get; set; }
[Column("apply_by")]
[MaxLength(64)]
public string ApplyBy { get; set; }
[Column("apply_date")]
public DateTime? ApplyDate { get; set; }
[Column("audit_by")]
[MaxLength(64)]
public string AuditBy { get; set; }
[Column("audit_date")]
public DateTime? AuditDate { get; set; }
[Column("update_by")]
[MaxLength(64)]
public string UpdateBy { get; set; }
[Column("update_date")]
public DateTime? UpdateDate { get; set; }
[Column("begin_time")]
public DateTime? BeginTime { get; set; }
[Column("end_time")]
public DateTime? EndTime { get; set; }
}
}

@ -0,0 +1,92 @@
//-----------------------------------------------------------------------
//<copyright>
// * Copyright (C) 2021 KEHAIDASOFT All Rights Reserved
// * version : 4.0.30319.42000
// * author : khd by t4-2
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Khd.Core.Domain.Models
{
[Table("wms_move_detail")]
public class WmsMoveDetail
{
[Key]
[Column("move_detail_id")]
public long MoveDetailId { get; set; }
[Required]
[Column("move_id")]
public long MoveId { get; set; }
[Column("material_barcode")]
[MaxLength(64)]
public string? MaterialBarcode { get; set; }
[Column("instock_batch")]
[MaxLength(64)]
public string? InstockBatch { get; set; }
[Required]
[Column("material_id")]
public long MaterialId { get; set; }
[Column("location_code")]
[MaxLength(64)]
public string? LocationCode { get; set; }
[Required]
[Column("plan_amount")]
public decimal PlanAmount { get; set; }
[Column("real_amount")]
public decimal? RealAmount { get; set; }
[Column("real_instock_amount")]
public decimal? RealInstockAmount { get; set; }
[Required]
[Column("execute_status")]
[MaxLength(1)]
public string ExecuteStatus { get; set; }
[Column("execute_person")]
[MaxLength(64)]
public string? ExecutePerson { get; set; }
[Column("execute_time")]
public DateTime? ExecuteTime { get; set; }
[Column("execute_end_time")]
public DateTime? ExecuteEndTime { get; set; }
[Column("machine_name")]
[MaxLength(64)]
public string? MachineName { get; set; }
[Column("create_by")]
[MaxLength(64)]
public string? CreateBy { get; set; }
[Column("create_date")]
public DateTime? CreateDate { get; set; }
[Column("update_by")]
[MaxLength(64)]
public string? UpdateBy { get; set; }
[Column("update_date")]
public DateTime? UpdateDate { get; set; }
[Column("active_flag")]
[MaxLength(1)]
public string? ActiveFlag { get; set; }
}
}

@ -19,6 +19,8 @@ namespace Khd.Core.EntityFramework
public DbSet<WmsInventoryCheckDetail> WmsInventoryCheckDetail { get; set; }
public DbSet<MesBaseMaterialInfo> MesBaseMaterialInfo { get; set; }
public DbSet<WmsRawReturn> WmsRawReturn { get; set; }
public DbSet<WmsMove> WmsMove { get; set; }
public DbSet<WmsMoveDetail> WmsMoveDetail { get; set; }
public DbSet<WmsRawReturnDetail> WmsRawReturnDetail { get; set; }
public DbSet<WcsTaskManual> WcsTaskManual { get; set; }
public DbSet<BaseDictionary> BaseDictionary { get; set; }

@ -943,14 +943,19 @@ namespace Khd.Core.Wcs.Wcs
var wmsRawStocks = dbContext.WmsRawStock
.Where(t => t.saleOrderId == (wmsRawOutstock.saleOrderId == null ? 0 : wmsRawOutstock.saleOrderId))
.Where(t => t.warehouseId == 311)
.ToList();
.Where(t => t.materialId == wmsRawOutstock.materialId)
.Where(t => t.totalAmount > t.frozenAmount)
.ToList();
var wmsRawStockLocations = wmsRawStocks.Select(x => x.locationCode).ToList();
var AllWmsBaseLocations = dbContext.WmsBaseLocation
.Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1")
.Where(t => t.warehouseId == 311).ToList();
.Where(t => t.warehouseId == 311)
.Where(t => t.locationStatus == "1").ToList();
var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.warehouseId == 311)
.Where(t => wmsRawStockLocations.Contains(t.locationCode))
.ToList();
var bill = from a in wmsBaseLocations
from b in wmsRawStocks
@ -961,196 +966,207 @@ namespace Khd.Core.Wcs.Wcs
bill = bill.OrderBy(t => t.b.instockDate.Value.Date);//按某个时间段
foreach (var item in bill)
{
var fistbill = bill.First();
if (fistbill != null)
// 目标库位
var fistbill = item;
int? locRow = 0;
if (fistbill.a.locRow % 2 == 1)
{
int? locRow = 0;
if (fistbill.a.locRow % 2 == 1)
locRow = fistbill.a.locRow + 1;
}
else
{
locRow = fistbill.a.locRow - 1;
}
wmsBaseLocation = fistbill.a;
// 目标库位处于深库位,判断是否需要移库浅库位
if (wmsBaseLocation.locDeep == 1)
{
int? row = 0;
if (wmsBaseLocation.locRow % 2 == 1)
{
locRow = fistbill.a.locRow + 1;
row = wmsBaseLocation.locRow + 1;
}
else
{
locRow = fistbill.a.locRow - 1;
row = wmsBaseLocation.locRow - 1;
}
var lastbill = bill.Where(t => t.a.locRow == locRow)
.Where(t => t.a.locColumn == fistbill.a.locColumn)
.Where(t => t.a.locDeep == 2)
.FirstOrDefault();
wmsBaseLocation = fistbill.a;
if (lastbill != null)
var lowLocationBill = bill.Where(t => t.a.locRow == locRow).Where(t => t.a.locColumn == wmsBaseLocation.locColumn).Where(t => t.a.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
if (lastbill.b.instockDate != null && fistbill.b.instockDate != null)
//对应的浅库位满足条件,直接出浅库位
wmsBaseLocation = lowLocationBill.a;
}
else
{
//目标出库库位对应的浅库位
WmsBaseLocation? fromBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row)
.Where(t => t.locColumn == wmsBaseLocation.locColumn)
.Where(t => t.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (fromBaseLocation != null && !string.IsNullOrEmpty(fromBaseLocation.containerCode)&& fromBaseLocation.locationStatus=="1")
{
if (wmsBaseLocation.locDeep == 1)
// 浅库位有库存
WmsRawStock? wmsRawStock1 = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == fromBaseLocation.locationCode);
if (wmsRawStock1 != null)
{
int? row = 0;
if (wmsBaseLocation.locRow % 2 == 1)
#region 找寻移库目标库位
// 寻找移库目的库位
WmsBaseLocation? toLocation = null;
var moveLocationList = AllWmsBaseLocations.Where(t => t.warehouseId == fromBaseLocation.warehouseId)
.Where(t => t.warehouseId != fromBaseLocation.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode)).OrderBy(t => t.locDeep).ToList();
foreach (WmsBaseLocation itemLocation in moveLocationList)
{
row = wmsBaseLocation.locRow + 1;
}
else
{
row = wmsBaseLocation.locRow - 1;
}
var lowLocationBill = bill.Where(t => t.a.locRow == locRow).Where(t => t.a.locColumn == wmsBaseLocation.locColumn).Where(t => t.a.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
wmsBaseLocation = lowLocationBill.a;
}
else
{
WmsBaseLocation? fromBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
.Where(t => t.locColumn == wmsBaseLocation.locColumn)
.Where(t => t.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (fromBaseLocation != null && !string.IsNullOrEmpty(fromBaseLocation.containerCode))
if (itemLocation.locDeep == 1)
{
WmsRawStock? wmsRawStock1 = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == fromBaseLocation.locationCode);
if (wmsRawStock1 != null)
bool hasLocation = AllWmsBaseLocations
.Where(t => t.locRow == (itemLocation.locRow % 2 == 1 ? (itemLocation.locRow + 1) : (itemLocation.locRow - 1)))
.Where(t => t.locColumn == itemLocation.locColumn)
.Where(t => t.locationStatus == "1" && string.IsNullOrEmpty(t.containerCode))
.Any();
if (!hasLocation)
{
WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.Where(t => t.locColumn > wmsBaseLocation.locColumn)
.OrderBy(t => t.locColumn)
.FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.Where(t => t.locColumn < wmsBaseLocation.locColumn)
.OrderByDescending(t => t.locColumn)
.FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.warehouseId != wmsBaseLocation.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault();
if (toLocation != null)
{
if (toLocation.locDeep == 1)
{
bool hasLocation = AllWmsBaseLocations
.Where(t => t.locRow == (toLocation.locRow % 2 == 1 ? (toLocation.locRow + 1) : (toLocation.locRow - 1)))
.Where(t => t.locColumn == toLocation.locColumn)
.Any();
if (!hasLocation)
{
Console.WriteLine(DateTime.Now + $":目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
_logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
continue;
}
}
var RemoveTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
taskType = StaticTaskType.ThirdRemove,
containerNo = wmsRawStock1.palletInfoCode,
createBy = "WCS",
createTime = DateTime.Now.AddSeconds(-10),
taskStatus = 0,
currPointId = fromBaseLocation.locationId,
currPointNo = fromBaseLocation.locationCode,
nextPointId = baseEquip.objid,
nextPointNo = baseEquip.equipNo,
endPointId = toLocation.locationId,
endPointNo = toLocation.locationCode,
equipmentNo = baseEquip.equipNo,
useFlag = 1,
qty = 1
};
SystemData.LockOutLocation(toLocation, dbContext);
SystemData.LockOutLocation(fromBaseLocation, dbContext);
toLocation.locationStatus = "4";
toLocation.updateBy = "WCS";
toLocation.updateTime = DateTime.Now;
fromBaseLocation.updateBy = "WCS";
fromBaseLocation.updateTime = DateTime.Now;
fromBaseLocation.locationStatus = "4";
dbContext.Update(toLocation);
dbContext.Update(fromBaseLocation);
dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog);
}
else
{
continue;
}
Console.WriteLine(DateTime.Now + $":目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
_logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
continue;
}
else
{
continue;
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
}
}
}
if (wmsBaseLocation != null)
{
wmsRawStock = wmsRawStocks.Where(t => t.locationCode == wmsBaseLocation.locationCode).First();
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == wmsRawStock.palletInfoCode);
if (mesBasePalletInfo != null)
{
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode);
if (mesBaseBarcodeInfo != null)
{
WmsRawOutstockDetail wmsRawOutstockDetail = new WmsRawOutstockDetail()
if (toLocation == null)
{
rawOutstockDetailId = StaticData.SnowId.NextId(),
createBy = "WCS",
createDate = DateTime.Now,
executeStatus = "0",
erpAmount = 0,
erpStatus = "0",
instockBatch = mesBaseBarcodeInfo.batchCode,
stackAmount = 1,
locationCode = wmsBaseLocation.locationCode,
rawOutstockId = wmsRawOutstock.rawOutstockId,
planAmount = 1,
outstockWay = "2",
outstockPerson = "WCS",
outstockTime = DateTime.Now,
materialProductionDate = mesBaseBarcodeInfo.productionDate,
materialBarcode = mesBasePalletInfo.materialBarcode,
materialId = wmsRawOutstock.materialId,
machineName = mesBaseBarcodeInfo.machineName,
outstockAmount = 1,
taskCode = wmsRawOutstock.taskCode
};
wcsTask = new WcsTask()
// 找寻下一个可出库库存
continue;
}
var RemoveTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
orderId = wmsRawOutstock.rawOutstockId,
taskType = StaticTaskType.ThirdRawToFlip,
containerNo = wmsRawStock.palletInfoCode,
taskType = StaticTaskType.ThirdRemove,
containerNo = wmsRawStock1.palletInfoCode,
createBy = "WCS",
createTime = DateTime.Now,
createTime = DateTime.Now.AddSeconds(-10),
taskStatus = 0,
materialId = wmsRawOutstock.materialId,
currPointId = wmsBaseLocation.locationId,
currPointNo = wmsBaseLocation.locationCode,
currPointId = fromBaseLocation.locationId,
currPointNo = fromBaseLocation.locationCode,
nextPointId = baseEquip.objid,
nextPointNo = baseEquip.equipNo,
endPointId = endEquip.objid,
endPointNo = endEquip.equipNo,
equipmentNo = endEquip.equipNo,
endPointId = toLocation.locationId,
endPointNo = toLocation.locationCode,
equipmentNo = baseEquip.equipNo,
useFlag = 1,
qty = 1
};
SystemData.LockOutLocation(wmsBaseLocation, dbContext);
wmsBaseLocation.locationStatus = "6";
dbContext.Update(wmsBaseLocation);
dbContext.Add(wmsRawOutstockDetail);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
dbContext.Remove(wcsTaskManual);
dbContext.Add(wcsTask);
SystemData.LockOutLocation(toLocation, dbContext);
SystemData.LockOutLocation(fromBaseLocation, dbContext);
toLocation.locationStatus = "4";
toLocation.updateBy = "WCS";
toLocation.updateTime = DateTime.Now;
fromBaseLocation.updateBy = "WCS";
fromBaseLocation.updateTime = DateTime.Now;
fromBaseLocation.locationStatus = "4";
dbContext.Update(toLocation);
dbContext.Update(fromBaseLocation);
dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog);
dbContext.SaveChanges();
#endregion
}
}
else
{
//浅库位状态异常,找寻下一个可出库库存
continue;
}
}
}
if (wmsBaseLocation != null)
{
wmsRawStock = wmsRawStocks.Where(t => t.locationCode == wmsBaseLocation.locationCode).First();
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == wmsRawStock.palletInfoCode);
if (mesBasePalletInfo != null)
{
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode);
if (mesBaseBarcodeInfo != null)
{
WmsRawOutstockDetail wmsRawOutstockDetail = new WmsRawOutstockDetail()
{
rawOutstockDetailId = StaticData.SnowId.NextId(),
createBy = "WCS",
createDate = DateTime.Now,
executeStatus = "0",
erpAmount = 0,
erpStatus = "0",
instockBatch = mesBaseBarcodeInfo.batchCode,
stackAmount = 1,
locationCode = wmsBaseLocation.locationCode,
rawOutstockId = wmsRawOutstock.rawOutstockId,
planAmount = 1,
outstockWay = "2",
outstockPerson = "WCS",
outstockTime = DateTime.Now,
materialProductionDate = mesBaseBarcodeInfo.productionDate,
materialBarcode = mesBasePalletInfo.materialBarcode,
materialId = wmsRawOutstock.materialId,
machineName = mesBaseBarcodeInfo.machineName,
outstockAmount = 1,
taskCode = wmsRawOutstock.taskCode
};
wcsTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
orderId = wmsRawOutstock.rawOutstockId,
taskType = StaticTaskType.ThirdRawToFlip,
containerNo = wmsRawStock.palletInfoCode,
createBy = "WCS",
createTime = DateTime.Now,
taskStatus = 0,
materialId = wmsRawOutstock.materialId,
currPointId = wmsBaseLocation.locationId,
currPointNo = wmsBaseLocation.locationCode,
nextPointId = baseEquip.objid,
nextPointNo = baseEquip.equipNo,
endPointId = endEquip.objid,
endPointNo = endEquip.equipNo,
equipmentNo = endEquip.equipNo,
useFlag = 1,
qty = 1
};
SystemData.LockOutLocation(wmsBaseLocation, dbContext);
wmsBaseLocation.locationStatus = "6";
dbContext.Update(wmsBaseLocation);
dbContext.Add(wmsRawOutstockDetail);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
dbContext.Remove(wcsTaskManual);
dbContext.Add(wcsTask);
dbContext.Add(wcsTaskLog);
dbContext.SaveChanges();
}
}
}
}
}
}
@ -1343,29 +1359,34 @@ namespace Khd.Core.Wcs.Wcs
}
else
{
WmsBaseLocation? wmsBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
// 外侧浅库位
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row)
.Where(t => t.locColumn == location.locColumn)
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
if ( !string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
{
WmsProductStock? wmsProductStock = dbContext.WmsProductStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode);
if (wmsProductStock != null)
{
WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.warehouseId != location.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault();
#region 找寻移库目标库位
WmsBaseLocation? toLocation = null;
if (toLocation != null)
var moveLocationList = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.warehouseId != location.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode) && t.locationStatus == "1").OrderBy(t => t.locDeep).ToList();
foreach (WmsBaseLocation itemLocation in moveLocationList)
{
if (toLocation.locDeep == 1)
if (itemLocation.locDeep == 1)
{
bool hasLocation = AllWmsBaseLocations
.Where(t => t.locRow == (toLocation.locRow % 2 == 1 ? (toLocation.locRow + 1) : (toLocation.locRow - 1)))
.Where(t => t.locColumn == toLocation.locColumn)
.Where(t => t.locRow == (itemLocation.locRow % 2 == 1 ? (itemLocation.locRow + 1) : (itemLocation.locRow - 1)))
.Where(t => t.locColumn == itemLocation.locColumn)
.Where(t => t.locationStatus == "1" && string.IsNullOrEmpty(t.containerCode))
.Any();
if (!hasLocation)
{
@ -1373,53 +1394,130 @@ namespace Khd.Core.Wcs.Wcs
_logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
continue;
}
}
var RemoveTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
orderId = item.productOutstockId,
taskType = StaticTaskType.FiveRemove,
containerNo = wmsProductStock.palletInfoCode,
createBy = "WCS",
createTime = DateTime.Now.AddSeconds(-10),
taskStatus = 0,
materialId = item.productId,
currPointId = wmsBaseLocation.locationId,
currPointNo = wmsBaseLocation.locationCode,
nextPointId = agvEquip.objid,
nextPointNo = agvEquip.equipNo,
endPointId = toLocation.locationId,
endPointNo = toLocation.locationCode,
equipmentNo = agvEquip.equipNo,
useFlag = 1,
qty = 1
};
SystemData.LockOutLocation(toLocation, dbContext);
SystemData.LockOutLocation(wmsBaseLocation, dbContext);
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
toLocation.locationStatus = "4";
toLocation.updateBy = "WCS";
toLocation.updateTime = DateTime.Now;
wmsBaseLocation.updateBy = "WCS";
wmsBaseLocation.updateTime = DateTime.Now;
wmsBaseLocation.locationStatus = "4";
dbContext.Update(toLocation);
dbContext.Update(wmsBaseLocation);
dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog);
}
else
if (toLocation == null)
{
// 找寻下一个可出库库存
continue;
}
var RemoveTask = new WcsTask()
{
objid = StaticData.SnowId.NextId(),
orderId = item.productOutstockId,
taskType = StaticTaskType.SecondRemove,
containerNo = wmsBaseLocation.containerCode,
createBy = "WCS",
createTime = DateTime.Now.AddSeconds(-10),
taskStatus = 0,
materialId = item.productId,
currPointId = wmsBaseLocation.locationId,
currPointNo = wmsBaseLocation.locationCode,
nextPointId = agvEquip.objid,
nextPointNo = agvEquip.equipNo,
endPointId = toLocation.locationId,
endPointNo = toLocation.locationCode,
equipmentNo = agvEquip.equipNo,
useFlag = 1,
qty = 1
};
SystemData.LockOutLocation(toLocation, dbContext);
SystemData.LockOutLocation(wmsBaseLocation, dbContext);
toLocation.locationStatus = "4";
toLocation.updateBy = "WCS";
toLocation.updateTime = DateTime.Now;
wmsBaseLocation.updateBy = "WCS";
wmsBaseLocation.updateTime = DateTime.Now;
wmsBaseLocation.locationStatus = "4";
dbContext.Update(toLocation);
dbContext.Update(wmsBaseLocation);
dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog);
#endregion
//WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
// .Where(t => t.locDeep == 1)
// .Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
//toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
// .Where(t => t.warehouseId != location.locationId)
// .Where(t => string.IsNullOrEmpty(t.containerCode))
// .FirstOrDefault();
//if (toLocation != null)
//{
// if (toLocation.locDeep == 1)
// {
// bool hasLocation = AllWmsBaseLocations
// .Where(t => t.locRow == (toLocation.locRow % 2 == 1 ? (toLocation.locRow + 1) : (toLocation.locRow - 1)))
// .Where(t => t.locColumn == toLocation.locColumn)
// .Any();
// if (!hasLocation)
// {
// Console.WriteLine(DateTime.Now + $":目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
// _logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
// continue;
// }
// }
// var RemoveTask = new WcsTask()
// {
// objid = StaticData.SnowId.NextId(),
// orderId = item.productOutstockId,
// taskType = StaticTaskType.FiveRemove,
// containerNo = wmsProductStock.palletInfoCode,
// createBy = "WCS",
// createTime = DateTime.Now.AddSeconds(-10),
// taskStatus = 0,
// materialId = item.productId,
// currPointId = wmsBaseLocation.locationId,
// currPointNo = wmsBaseLocation.locationCode,
// nextPointId = agvEquip.objid,
// nextPointNo = agvEquip.equipNo,
// endPointId = toLocation.locationId,
// endPointNo = toLocation.locationCode,
// equipmentNo = agvEquip.equipNo,
// useFlag = 1,
// qty = 1
// };
// SystemData.LockOutLocation(toLocation, dbContext);
// SystemData.LockOutLocation(wmsBaseLocation, dbContext);
// toLocation.locationStatus = "4";
// toLocation.updateBy = "WCS";
// toLocation.updateTime = DateTime.Now;
// wmsBaseLocation.updateBy = "WCS";
// wmsBaseLocation.updateTime = DateTime.Now;
// wmsBaseLocation.locationStatus = "4";
// dbContext.Update(toLocation);
// dbContext.Update(wmsBaseLocation);
// dbContext.Add(RemoveTask);
// WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
// dbContext.Add(wcsTaskLog);
//}
//else
//{
// continue;
//}
}
else
{
continue;
}
}
else if (wmsBaseLocation != null && wmsBaseLocation.locationStatus != "1")
else
{
Console.WriteLine(DateTime.Now + $":{wmsBaseLocation.locationCode}库位状态异常,无法移库");
_logger.Info($"{wmsBaseLocation.locationCode}库位状态异常,无法移库");
@ -1529,7 +1627,9 @@ namespace Khd.Core.Wcs.Wcs
//获取最早入库时间
foreach (var item in proOutStock)
{
task = dbContext.WcsTask.Where(t => t.nextPointId == 8 && t.taskStatus <= 7).Any();
if (task) break;
var wmsproStocks = proStock
.Where(t => t.productId == item.productId && t.saleOrderId == (item.saleOrderId == null ? 0 : item.saleOrderId) && t.warehouseId == item.warehouseId)
.Select(t => t.locationCode)
@ -1539,6 +1639,7 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1")
.Where(t => t.locationStatus == "1")
.Where(t => t.warehouseId == item.warehouseId)
.Where(t => t.warehouseId == item.warehouseId).ToList();
var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.warehouseId == item.warehouseId)
@ -1553,7 +1654,7 @@ namespace Khd.Core.Wcs.Wcs
dbContext.SaveChanges();
continue;
}
var bill = from a in wmsBaseLocations
from b in proStock
where a.locationCode == b.locationCode
@ -1591,6 +1692,7 @@ namespace Khd.Core.Wcs.Wcs
}
else
{
// 目标出库库位对应的浅库位
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row)
.Where(t => t.locColumn == location.locColumn)

@ -16,11 +16,11 @@
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<hc:ThemeResources/>
<hc:Theme/>-->
@ -389,24 +389,24 @@
<Button.ContentTemplate>
<DataTemplate>
<Grid>
<!-- 主内容 -->
<TextBlock Text="{Binding Code}"
<!-- 主内容 -->
<TextBlock Text="{Binding Code}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="20"
RenderTransformOrigin="0.5, 0.5">
<TextBlock.RenderTransform>
<RotateTransform Angle="90"/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock.RenderTransform>
<RotateTransform Angle="90"/>
</TextBlock.RenderTransform>
</TextBlock>
<!-- 圆点 -->
<Ellipse Width="5" Height="5"
<!-- 圆点 -->
<Ellipse Width="5" Height="5"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,0,0,0"
Fill="Red" Visibility="{Binding isFreeze}"/>
</Grid>
</Grid>
</DataTemplate>
</Button.ContentTemplate>
</Button>
@ -1297,9 +1297,9 @@
<TextBlock Text=" 库位锁定" FontSize="30"/>
</StackPanel>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
@ -2099,14 +2099,14 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="167*"/>
<RowDefinition Height="167*"/>
<RowDefinition Height="167*"/>
<RowDefinition Height="167*"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="166.667"/>
<RowDefinition Height="167*"/>
<RowDefinition Height="167*"/>
<RowDefinition Height="167*"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="119.048"/>
</Grid.RowDefinitions>
<TextBlock Text="扫描入库" FontSize="50" Grid.ColumnSpan="6" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text="扫描料箱号:" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="75"/>
@ -2125,7 +2125,7 @@
<hc:TextBox x:Name="materialName" IsReadOnly="True" hc:InfoElement.ShowClearButton="True" FontSize="50" Width="900" HorizontalAlignment="Left" VerticalAlignment="Center" Height="100" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="3"/>
<hc:TextBox x:Name="materialSpec" IsReadOnly="True" hc:InfoElement.ShowClearButton="True" FontSize="50" Width="900" HorizontalAlignment="Left" VerticalAlignment="Center" Height="100" Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="3"/>
<hc:TextBox x:Name="txtInScan" FontSize="50" IsReadOnly="True" Width="900" HorizontalAlignment="Left" VerticalAlignment="Center" Height="100" Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="3" KeyDown="ScanInKeyDown" />
<Button Content="确认入库" Grid.Row="6" Grid.ColumnSpan="6" Width="300" Height="100" FontSize="50" Background="#346DFF" Foreground="White" Click="InRawBaseLocaltion_Click"/>
<Button Content="确认入库" Grid.Row="6" Grid.ColumnSpan="2" Width="300" Height="100" FontSize="50" Background="#346DFF" Foreground="White" Click="InRawBaseLocaltion_Click" Grid.Column="2" HorizontalAlignment="Left" Margin="125,0,0,10" VerticalAlignment="Bottom"/>
<Button Content="取消预调度" x:Name="CancelPreScheduling" Grid.Row="6" Grid.ColumnSpan="2" Width="328" Height="100" FontSize="50" Background="#346DFF" Foreground="White" HorizontalAlignment="Left" Grid.Column="4" Margin="222,0,0,0" Click="CancelPreScheduling_Click"/>
<Button Content="一键收料" Grid.Row="7" Grid.ColumnSpan="2" Width="328" Height="100" FontSize="50" Background="#346DFF" Foreground="White" Click="callPlc_Click" HorizontalAlignment="Left" Grid.Column="4" Margin="222,0,0,0"/>
<TextBlock Grid.Row="7" Text="提示信息:" HorizontalAlignment="Center" Grid.Column="1" Grid.ColumnSpan="1" Width="250" Height="100" FontSize="50" Foreground="White" />
@ -2309,15 +2309,15 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderBrush="White" BorderThickness="2" Grid.ColumnSpan="1" Grid.Column="4" Grid.RowSpan="2" Margin="20 0 0 0">
<StackPanel Orientation="Vertical" >
<TextBlock x:Name="OutOrder" Background="Transparent" Grid.ColumnSpan="2" Grid.RowSpan="2" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<TextBlock x:Name="thisOutEndStation" Background="Transparent" Grid.ColumnSpan="2" Grid.RowSpan="2" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,20,0,0"/>
</StackPanel>
</Border>
<Border BorderBrush="White" BorderThickness="0" Grid.ColumnSpan="1" Grid.Column="6" Grid.RowSpan="2" Margin="20 0 0 0">
<Border BorderBrush="White" BorderThickness="0" Grid.ColumnSpan="1" Grid.Column="6" Grid.RowSpan="2" Margin="20 0 0 0">
<StackPanel Orientation="Vertical" >
<Button Content="选择出库" Background="#346DFF" Foreground="White" FontSize="50" Margin="20,0,0,0" Height="100" Width="250" Click="SelectOutBtn_Click"/>
@ -2325,7 +2325,7 @@
</StackPanel>
</Border>
<Border BorderBrush="White" BorderThickness="2" Grid.Column="0" Grid.ColumnSpan="6" Grid.Row="6" Grid.RowSpan="2" Margin="20">
@ -2456,7 +2456,7 @@
<Grid>
<hc:TextBox hc:InfoElement.ShowClearButton="True" IsReadOnly="True" x:Name="outMaterialNameTxt" FontSize="50" LostFocus="txtOutBox_TextChanged" Width="700" HorizontalAlignment="Left" VerticalAlignment="Center" Height="80" Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="3"/>
</Grid>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Row="3" Grid.ColumnSpan="6">
<TextBlock Text="物料规格:" Width="280" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50"/>
@ -2598,6 +2598,7 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -2609,14 +2610,14 @@
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="原料箱号:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<hc:TextBox x:Name="rawSourceBox" TextChanged="rawSourceBox_TextChanged" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="rawSourceBox" TextChanged="rawSourceBox_TextChanged" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<Button Click="rawSourceBoxClear_Click" HorizontalAlignment="Right" Height="100" Panel.ZIndex="1" Width="100" Margin="-100,0,0,0" Grid.Column="5" Grid.Row="2">
<Image Source="..\Resources\cancel.png"/>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="原条码号:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="rawSourceBarCode" FontSize="40" TextChanged="rawSourceBarCode_TextChanged" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="rawSourceBarCode" FontSize="40" TextChanged="rawSourceBarCode_TextChanged" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<Button Click="rawSourceBarCodeClear_Click" HorizontalAlignment="Right" Height="100" Panel.ZIndex="1" Width="100" Margin="-100,0,0,0" Grid.Column="5" Grid.Row="2">
<Image Source="..\Resources\cancel.png"/>
</Button>
@ -2624,7 +2625,7 @@
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="移库料箱:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeSourceBox" FontSize="40" TextChanged="removeSourceBox_TextChanged" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="removeSourceBox" FontSize="40" TextChanged="removeSourceBox_TextChanged" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<Button Click="removeSourceBoxClear_Click" HorizontalAlignment="Right" Height="100" Panel.ZIndex="1" Width="100" Margin="-100,0,0,0" Grid.Column="5" Grid.Row="2">
<Image Source="..\Resources\cancel.png"/>
</Button>
@ -2633,7 +2634,7 @@
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="移库条码:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeSourceBarCode" FontSize="40" TextChanged="removeSourceBarCode_TextChanged" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="removeSourceBarCode" FontSize="40" TextChanged="removeSourceBarCode_TextChanged" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<Button Click="removeSourceBarCodeClear_Click" HorizontalAlignment="Right" Height="100" Panel.ZIndex="1" Width="100" Margin="-100,0,0,0" Grid.Column="5" Grid.Row="2">
<Image Source="..\Resources\cancel.png"/>
</Button>
@ -2641,35 +2642,40 @@
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="物料名称:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="rawSourceMaterialName" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="rawSourceMaterialName" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="物料规格:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="rawSourceMaterialSpec" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="rawSourceMaterialSpec" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="物料名称:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeSourceMaterialName" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="removeSourceMaterialName" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="物料规格:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeSourceMaterialSpec" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="removeSourceMaterialSpec" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="移库数量:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeScan" FontSize="40" Width="500" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<hc:TextBox x:Name="removeScan" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
</StackPanel>
<Button Content="确认移库" Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="4" Width="500" Height="150" FontSize="75" Background="#346DFF" Foreground="White" Click="btnRemoveConfirmBox_Click"/>
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="5">
<TextBlock Text="物料库存:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<hc:TextBox x:Name="removeTotalStock" FontSize="40" Width="600" Height="100" Margin="0,0,0,0" hc:InfoElement.ShowClearButton="True"/>
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Left" Margin="100 0 0 0 ">
</StackPanel>
<Button Content="确认移库" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="4" Width="500" Height="150" FontSize="75" Background="#346DFF" Foreground="White" Click="btnRemoveConfirmBox_Click"/>
<StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Left" Margin="100 0 0 0 ">
<TextBlock Text="提示信息:" FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock x:Name="RemoveMsg" HorizontalAlignment="Left" FontSize="40" Foreground="White" Width="1200" Height="60" Margin="10,0,0,0" />
<TextBlock x:Name="RemoveMsg" HorizontalAlignment="Left" FontSize="40" Foreground="White" Width="1200" Height="60" Margin="10,0,0,0" />
</StackPanel>
</Grid>

@ -21,6 +21,7 @@ using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing.Printing;
@ -32,6 +33,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using System.Windows.Threading;
using Z.EntityFramework.Plus;
using static HandyControl.Tools.Interop.InteropValues;
@ -4507,6 +4509,7 @@ namespace Khd.Core.Wpf.Form
{
removeSourceMaterialName.Text = "";
removeSourceMaterialSpec.Text = "";
this.removeTotalStock.Text = "";
return;
}
string barCode = removeSourceBarCode.Text;
@ -4527,6 +4530,7 @@ namespace Khd.Core.Wpf.Form
// removeSourceMaterialSpec.Text = "";
// return;
//}
var material = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == barCode);
if (material == null)
{
@ -4548,6 +4552,12 @@ namespace Khd.Core.Wpf.Form
}
}
//判断目标库位是否有该物料
WmsRawStock? removeStock = dbContext.WmsRawStock.Where(t => t.instockBatch == this.removeSourceBarCode.Text).FirstOrDefault();
if (removeStock != null)
{
this.removeTotalStock.Text = string.Format("{0:0.00}", removeStock.totalAmount);
}
}
catch (Exception ex)
{
@ -4587,57 +4597,132 @@ namespace Khd.Core.Wpf.Form
this.RemoveMsg.Text = "移库数量需要大于0!";
return;
}
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
WmsRawStock? wmsRawStock = dbContext.WmsRawStock
WmsRawStock? sourceWmsRawStock = dbContext.WmsRawStock
.Where(t => t.instockBatch == this.rawSourceBarCode.Text).FirstOrDefault();
if (amount > (wmsRawStock.totalAmount-wmsRawStock.frozenAmount))
if (sourceWmsRawStock == null)
{
this.RemoveMsg.Text = "该条码无库存,请核查";
return;
}
if (amount > (sourceWmsRawStock.totalAmount- sourceWmsRawStock.frozenAmount))
{
this.RemoveMsg.Text = "移库数量不能大于库存数量";
return;
}
try
{
WmsBaseLocation removeLocation = dbContext.WmsBaseLocation.Where(t => t.containerCode == this.removeSourceBox.Text).First();
WmsBaseLocation rawLocation = dbContext.WmsBaseLocation.Where(t => t.containerCode == this.rawSourceBox.Text).First();
WmsBaseLocation sourceLocation = dbContext.WmsBaseLocation.Where(t => t.containerCode == this.rawSourceBox.Text).First();
//1.先校验物料类型是否一致
var rawBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.rawSourceBarCode.Text);
var removeBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.removeSourceBarCode.Text);
if (rawBarcodeInfo.materialId != removeBarcodeInfo.materialId)
{
this.RemoveMsg.Text = "两个条码物料类型不同,请更换目标条码!";
this.RemoveMsg.Text = "两个条码物料类型不同,请更换移库目标条码!";
return;
}
if (rawBarcodeInfo.PurchaseOrderId != removeBarcodeInfo.PurchaseOrderId)
{
this.RemoveMsg.Text = "两个条码采购订单不同,请更换移库目标条码!";
return;
}
//判断目标库位是否有该物料
WmsRawStock? targetStock = dbContext.WmsRawStock.Where(t => t.palletInfoCode == this.removeSourceBox.Text && t.materialId == rawBarcodeInfo.materialId).FirstOrDefault();
if (targetStock == null || (targetStock != null && removeBarcodeInfo.batchFlag == "0"))
WmsRawStock? removeStock = dbContext.WmsRawStock.Where(t => t.instockBatch == this.removeSourceBarCode.Text).FirstOrDefault();
if (removeStock != null)
{
// 更新 WmsRawStock 中的记录
dbContext.WmsRawStock
.Where(t => t.locationCode == rawLocation.locationCode)
.Where(t => t.instockBatch == this.rawSourceBarCode.Text)
.Update(t => new WmsRawStock
{
locationCode = removeLocation.locationCode, // 更新 locationCode
palletInfoCode = removeLocation.containerCode // 更新 palletInfoCode
});
sourceWmsRawStock.totalAmount -= decimal.Parse(this.removeScan.Text);
removeStock.totalAmount += decimal.Parse(this.removeScan.Text);
dbContext.WmsRawStock.Update(removeStock);
dbContext.WmsRawStock.Update(sourceWmsRawStock);
}
else
{
targetStock.totalAmount += decimal.Parse(this.removeScan.Text);
dbContext.WmsRawStock.Update(targetStock);
sourceWmsRawStock.totalAmount -= decimal.Parse(this.removeScan.Text);
removeStock = new WmsRawStock()
{
materialId = removeBarcodeInfo.materialId,
supplierId = removeBarcodeInfo.manufacturerId,
instockBatch = this.removeSourceBarCode.Text,
locationCode = removeLocation.locationCode,
stockType = "1",
palletInfoCode = removeLocation.containerCode,
totalAmount = decimal.Parse(this.removeScan.Text),
activeFlag = "1",
occupyAmount = 0,
completeFlag = "1",
frozenAmount = 0,
instockDate = System.DateTime.Now,
rawStockId = Global.SnowId.NextId(),
saleOrderId = removeBarcodeInfo.saleOrderId == null ? 0 : removeBarcodeInfo.saleOrderId,
warehouseFloor = 5,
warehouseId = 512,
createBy = "扫描入库",
createDate = System.DateTime.Now,
safeFlag = removeBarcodeInfo.safeFlag
};
dbContext.WmsRawStock.Add(removeStock);
dbContext.WmsRawStock.Update(sourceWmsRawStock);
}
#region 插入移库记录
if (sourceWmsRawStock.totalAmount == 0)
{
dbContext.WmsRawStock.Remove(sourceWmsRawStock);
}
#region 插入移库记录
WmsMove wmsMove = new WmsMove();
wmsMove.MoveId = Global.SnowId.NextId();
wmsMove.TaskCode = Global.SnowId.NextId().ToString();
wmsMove.WarehouseId = removeLocation.warehouseId;
wmsMove.OriLocationCode = sourceLocation.locationCode;
wmsMove.TargetLocationCode = removeLocation.locationCode;
wmsMove.InstockBatch = sourceWmsRawStock.instockBatch;
wmsMove.MaterialId = sourceWmsRawStock.materialId;
wmsMove.PlanAmount = decimal.Parse(this.removeScan.Text);
wmsMove.RealOutstockAmount = decimal.Parse(this.removeScan.Text);
wmsMove.RealInstockAmount = decimal.Parse(this.removeScan.Text);
wmsMove.OperationType = "1" ;
wmsMove.MoveWay = "1" ;
wmsMove.MoveType = "1" ;
wmsMove.AuditStatus = "1" ;
wmsMove.ExecuteStatus = "2" ;
wmsMove.UpdateBy = "WPF" ;
wmsMove.UpdateDate = DateTime.Now ;
wmsMove.BeginTime = DateTime.Now ;
wmsMove.EndTime = DateTime.Now ;
WmsMoveDetail wmsMoveDetail = new WmsMoveDetail();
wmsMoveDetail.MoveId = wmsMove.MoveId;
wmsMoveDetail.MaterialBarcode = rawBarcodeInfo.barcodeInfo;
wmsMoveDetail.InstockBatch = rawBarcodeInfo.batchCode;
wmsMoveDetail.MaterialId = (long)rawBarcodeInfo.materialId;
wmsMoveDetail.LocationCode = removeLocation.locationCode;
wmsMoveDetail.PlanAmount = decimal.Parse(this.removeScan.Text);
wmsMoveDetail.RealInstockAmount = decimal.Parse(this.removeScan.Text);
wmsMoveDetail.RealAmount = decimal.Parse(this.removeScan.Text);
wmsMoveDetail.ExecuteStatus = "2";
wmsMoveDetail.ExecuteTime = DateTime.Now;
wmsMoveDetail.ExecuteEndTime = DateTime.Now;
wmsMoveDetail.ExecutePerson = "WPF";
wmsMoveDetail.UpdateBy = "WPF";
wmsMoveDetail.UpdateDate = DateTime.Now;
dbContext.WmsMove.Add(wmsMove);
dbContext.WmsMoveDetail.Add(wmsMoveDetail);
#endregion
dbContext.SaveChanges();
this.RemoveMsg.Text = "移库成功!";
this.RemoveMsg.Text = $"移库成功!,原料箱库存:{string.Format("{0:0.00}", sourceWmsRawStock.totalAmount)},新料箱库存:{string.Format("{0:0.00}", removeStock.totalAmount)}";
removeSourceBarCode.Text = string.Empty;
removeSourceMaterialName.Text = "";
removeSourceMaterialSpec.Text = "";
@ -4645,11 +4730,11 @@ namespace Khd.Core.Wpf.Form
rawSourceMaterialName.Text = "";
rawSourceMaterialSpec.Text = "";
this.removeScan.Text = "";
this.removeTotalStock.Text = "";
}
catch
catch (Exception ex)
{
Console.Write("移库失败!,异常:"+ ex.Message);
}
}

Loading…
Cancel
Save