diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs
index 674a7399..99bc7bd5 100644
--- a/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs
+++ b/AMESCoreStudio.WebApi/Controllers/AMES/BarcodeInfoesController.cs
@@ -659,6 +659,169 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
return result;
}
+ ///
+ /// 重新結轉寫入條碼資料
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPut("WriteBarcodeInfo4DataCarrierAgain/{barcodeNo}/{wipID}/{stationID}/{extraBarcodeNo}/{boxNo}")]
+ public async Task> WriteBarcodeInfo4DataCarrierAgain(string barcodeNo, int wipID, int stationID, string extraBarcodeNo, string boxNo)
+ {
+ Helper helper = new Helper(_context);
+ ResultModel result = new ResultModel();
+
+ try
+ {
+ IQueryable w = _context.WipInfos;
+ w = w.Where(p => p.WipID.Equals(wipID));
+ var wipInfo = await w.ToListAsync();
+
+ IQueryable u = _context.FactoryUnits;
+ u = u.Where(p => p.UnitNo.Equals(wipInfo[0].UnitNO));
+ var unitInfo = await u.ToListAsync();
+
+ IQueryable b = _context.BarcodeInfoes;
+ b = b.Where(p => p.BarcodeNo.Equals(barcodeNo));
+ var barcodeInfo = await b.ToListAsync();
+
+ if (barcodeInfo.Count == 0)
+ {
+ BarcodeInfo barcode_info = new BarcodeInfo();
+ barcode_info.BarcodeID = helper.GetIDKey("BARCODE_ID").Result;
+ barcode_info.BarcodeNo = barcodeNo;
+ barcode_info.WipID = wipID;
+ barcode_info.StationID = stationID;
+ barcode_info.ExtraBarcodeNo = extraBarcodeNo;
+ barcode_info.BoxNo = boxNo;
+ barcode_info.StatusNo = unitInfo[0].UnitCode;
+ barcode_info.RuleStatus = "P";
+ barcode_info.StatusID = -1;
+ barcode_info.CreateDate = DateTime.Now;
+
+ _context.BarcodeInfoes.Add(barcode_info);
+ await _context.SaveChangesAsync();
+ }
+ else
+ {
+ if (barcodeInfo[0].WipID == wipID)
+ {
+ //删除WIP_ID過站
+ var oldBarcodeStation = await _context.BarcodeStation.Where(m => m.BarcodeID == barcodeInfo[0].BarcodeID && m.WipID == wipID && m.StationID == stationID).ToListAsync();
+ if (oldBarcodeStation != null)
+ {
+ for (int i = 0; i < oldBarcodeStation.Count; i++)
+ {
+ try
+ {
+ _context.BarcodeStation.Remove(oldBarcodeStation[i]);
+ await _context.SaveChangesAsync();
+ }
+ catch { }
+ }
+ }
+
+ //删除旧组件
+ var oldBarcodeItem = await _context.BarcodeItems.Where(m => m.BarcodeID == barcodeInfo[0].BarcodeID && m.WipID == wipID).ToListAsync();
+ if (oldBarcodeItem != null)
+ {
+ for (int i = 0; i < oldBarcodeItem.Count; i++)
+ {
+ try
+ {
+ _context.BarcodeItems.Remove(oldBarcodeItem[i]);
+ await _context.SaveChangesAsync();
+ }
+ catch { }
+ }
+ }
+
+ _context.Entry(barcodeInfo[0]).State = EntityState.Modified;
+ //設置容器空間某一個模型的某一個欄位 不提交到資料庫
+ _context.Entry(barcodeInfo[0]).Property("CreateDate").IsModified = false;
+ _context.Entry(barcodeInfo[0]).Property("CreateUserID").IsModified = false;
+
+ barcodeInfo[0].WipID = wipID;
+ barcodeInfo[0].StationID = stationID;
+ barcodeInfo[0].StatusNo = unitInfo[0].UnitCode;
+ barcodeInfo[0].ExtraBarcodeNo = extraBarcodeNo;
+ barcodeInfo[0].BoxNo = boxNo;
+ barcodeInfo[0].RuleStatus = "P";
+ barcodeInfo[0].StatusID = -1;
+ barcodeInfo[0].UpdateDate = DateTime.Now;
+
+ try
+ {
+ await _context.SaveChangesAsync();
+ result.Success = true;
+ result.Msg = "OK";
+ }
+ catch (Exception ex)
+ {
+ result.Success = false;
+ result.Msg = ex.InnerException.Message;
+ }
+ }
+ else
+ {
+ _context.Entry(barcodeInfo[0]).State = EntityState.Modified;
+ //設置容器空間某一個模型的某一個欄位 不提交到資料庫
+ _context.Entry(barcodeInfo[0]).Property("CreateDate").IsModified = false;
+ _context.Entry(barcodeInfo[0]).Property("CreateUserID").IsModified = false;
+
+ barcodeInfo[0].WipID = wipID;
+ barcodeInfo[0].StationID = stationID;
+ barcodeInfo[0].StatusNo = unitInfo[0].UnitCode;
+ barcodeInfo[0].ExtraBarcodeNo = extraBarcodeNo;
+ barcodeInfo[0].BoxNo = boxNo;
+ barcodeInfo[0].RuleStatus = "P";
+ barcodeInfo[0].StatusID = -1;
+ barcodeInfo[0].UpdateDate = DateTime.Now;
+
+ try
+ {
+ await _context.SaveChangesAsync();
+ result.Success = true;
+ result.Msg = "OK";
+ }
+ catch (Exception ex)
+ {
+ result.Success = false;
+ result.Msg = ex.InnerException.Message;
+ }
+ }
+
+ }
+
+ var q = from q1 in _context.BarcodeInfoes
+ select new
+ {
+ q1.BarcodeID,
+ q1.BarcodeNo
+ };
+
+ q = q.Where(w => w.BarcodeNo.Equals(barcodeNo));
+
+
+ //紀錄筆數
+ result.DataTotal = q.Count();
+ result.Success = true;
+ result.Data = await q.ToListAsync();
+ result.Msg = "OK";
+ }
+ catch (Exception ex)
+ {
+ result.Success = false;
+ result.Msg = ex.InnerException.Message;
+ }
+
+ return result;
+ }
+
+
///
/// 更新條碼资料
///