Browse Source

調整wip_barcode的更新方式

master
BB.Wang 15 hours ago
parent
commit
76993ff3e7
  1. 61
      AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs

61
AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs

@ -167,30 +167,53 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
public async Task<ResultModel<WipBarcode>> PutWipBarcode([FromBody] WipBarcode wipBarcode)
{
ResultModel<WipBarcode> result = new ResultModel<WipBarcode>();
var wipNo = wipBarcode.WipNO;
//2025-06-19 BB.Wang Modify
try
{
var result_old = _context.WipBarcodes.Where(w => w.WipNO == wipNo).ToList();
if (result_old.Count != 0)
{
foreach (var item in result_old)
{
_context.Entry(item).State = EntityState.Modified;
_context.Entry<WipBarcode>(item).Property("CreateDate").IsModified = false;
_context.Entry<WipBarcode>(item).Property("CreateUserID").IsModified = false;
item.UpdateDate = DateTime.Now;
item.Remarks = wipBarcode.Remarks;
}
}
else
{
_context.WipBarcodes.Add(wipBarcode);
}
await _context.SaveChangesAsync();
wipBarcode.UpdateDate = DateTime.Now;
var sSQL = @" UPDATE JHAMES.WIP_BARCODE SET
START_NO =: StartNO,
END_NO =: EndNO,
REMARKS =: Remarks,
UPDATE_DATE =: UpdateDate
WHERE WIP_NO =: WipNO
";
await _context.Database.DapperExecuteAsync(sSQL, wipBarcode);
result.Success = true;
result.Msg = "OK";
}
#region 2025-06-19 BB.Wang remark
//var wipNo = wipBarcode.WipNO;
//try
//{
// var result_old = _context.WipBarcodes.Where(w => w.WipNO == wipNo).ToList();
// if (result_old.Count != 0)
// {
// foreach (var item in result_old)
// {
// _context.Entry(item).State = EntityState.Modified;
// _context.Entry<WipBarcode>(item).Property("CreateDate").IsModified = false;
// _context.Entry<WipBarcode>(item).Property("CreateUserID").IsModified = false;
// //2025-06-19 BB.Wang add 增加資料更新時,UPDATE序號起訖
// item.StartNO = wipBarcode.StartNO;
// item.EndNO = wipBarcode.EndNO;
// item.UpdateDate = DateTime.Now;
// item.Remarks = wipBarcode.Remarks;
// }
// }
// else
// {
// _context.WipBarcodes.Add(wipBarcode);
// }
// await _context.SaveChangesAsync();
// result.Success = true;
// result.Msg = "OK";
//}
#endregion
catch (Exception ex)
{
result.Success = false;

Loading…
Cancel
Save