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) public async Task<ResultModel<WipBarcode>> PutWipBarcode([FromBody] WipBarcode wipBarcode)
{ {
ResultModel<WipBarcode> result = new ResultModel<WipBarcode>(); ResultModel<WipBarcode> result = new ResultModel<WipBarcode>();
var wipNo = wipBarcode.WipNO;
//2025-06-19 BB.Wang Modify
try try
{ {
var result_old = _context.WipBarcodes.Where(w => w.WipNO == wipNo).ToList(); wipBarcode.UpdateDate = DateTime.Now;
if (result_old.Count != 0) var sSQL = @" UPDATE JHAMES.WIP_BARCODE SET
{ START_NO =: StartNO,
foreach (var item in result_old) END_NO =: EndNO,
{ REMARKS =: Remarks,
_context.Entry(item).State = EntityState.Modified; UPDATE_DATE =: UpdateDate
_context.Entry<WipBarcode>(item).Property("CreateDate").IsModified = false; WHERE WIP_NO =: WipNO
_context.Entry<WipBarcode>(item).Property("CreateUserID").IsModified = false; ";
item.UpdateDate = DateTime.Now; await _context.Database.DapperExecuteAsync(sSQL, wipBarcode);
item.Remarks = wipBarcode.Remarks;
}
}
else
{
_context.WipBarcodes.Add(wipBarcode);
}
await _context.SaveChangesAsync();
result.Success = true; result.Success = true;
result.Msg = "OK"; 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) catch (Exception ex)
{ {
result.Success = false; result.Success = false;

Loading…
Cancel
Save