diff --git a/AMESCoreStudio.WebApi/Code/BarcodeContext.cs b/AMESCoreStudio.WebApi/Code/BarcodeContext.cs
deleted file mode 100644
index 377a3c7e..00000000
--- a/AMESCoreStudio.WebApi/Code/BarcodeContext.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using AMESCoreStudio.WebApi.Models.AMES;
-using AMESCoreStudio.WebApi.Controllers.AMES;
-using AMESCoreStudio.WebApi.Controllers.BAS;
-
-namespace AMESCoreStudio.WebApi
-{
- ///
- ///
- ///
- public class BarcodeContext
- {
- private readonly AMESContext _context;
-
- public BarcodeContext(AMESContext context)
- {
- _context = context;
- }
-
- ///
- /// 確認工單狀態
- ///
- /// 工單號碼
- /// 生產單位
- /// 流程
- /// 站別
- /// 線別
- ///
- public async Task CheckWipNoSationAsync(string WipNo, string UnitNo, int FlowRuleID, int Station, int Line)
- {
- WipInfosController wipInfosController = new WipInfosController(_context);
-
- var q = await wipInfosController.GetWipInfoByWipNo(WipNo);
- if (q.Value.Count() == 0)
- return "找不到工單號碼:" + WipNo;
-
- var WipNoItem = q.Value.Where(w => w.WipNO == WipNo && w.UnitNO == UnitNo).ToList();
- if (WipNoItem.Count == 0)
- return "工單號碼:" + WipNo + ",尚未設定此生產單位";
-
- if (!WipNoItem.Where(w => w.FlowRuleID == FlowRuleID).Any())
- return "工單號碼:" + WipNo + ",尚未設定此流程站";
-
- if (WipNoItem.Where(w => w.StatusNO == "Y").Any())
- return "工單號碼:" + WipNo + ",該工單已經投入完工,請切換工單";
-
- WipLockController wipLockController = new WipLockController(_context);
- var q1 = await wipLockController.GetWipLockByWipNO(WipNo);
- if (q1.Data.Where(w => w.LockStatus == "0" && w.StationID == Station).Any())
- return "工單號碼:" + WipNo + ",工單在當前站別被鎖定,不可過站";
-
- int WipID = WipNoItem.FirstOrDefault().WipID;
- LineInfoesController lineInfoesController = new LineInfoesController(_context);
- var q2 = await lineInfoesController.GetLineInfoByWipID(WipID);
- if (!q2.Value.Where(w => w.LineID == Line).Any())
- return "工單號碼:" + WipNo + ",工單尚未開線,不可過站";
-
-
- return "";
- }
-
- ///
- /// 內部序號是否被鎖定
- ///
- ///
- ///
- ///
- public async Task CheckBarCodeStationAsync(string WipNo, string BarCode)
- {
- BarcodeInfoesController barcodeInfoesController = new BarcodeInfoesController(_context);
-
- // 序號與工單相同視為序號
- if (BarCode.IndexOf(WipNo) != -1)
- {
- // 判斷BarCodeInfo 是否有條碼序號資料
- var q = await barcodeInfoesController.GetBarcodeInfoesByNo(BarCode);
- if (q.Value.Count() != 0)
- {
- // 判斷條碼序號是否有被鎖定
- BarcodeLockController barcodeLockController = new BarcodeLockController(_context);
- var q1 = await barcodeLockController.GetBarcodeLockByBarCodeID(q.Value.FirstOrDefault().BarcodeID);
- if (q1.Value.Where(w => w.LockStatus == 0).Any())
- {
- return "條碼編號:" + BarCode + ",已被鎖定,無法過站";
- }
- }
- }
- return "";
- }
-
- ///
- /// 判斷內部序號對應工單號買
- ///
- /// 內部序號
- ///
- public async Task CheckBarCodeFromWip(string BarCode)
- {
- //if (BarCode.Length <= 4)
- return "NG, 找不到相關工單號碼";
-
-
- }
- }
-}
diff --git a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
index d16f6bc9..7f759b07 100644
--- a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
+++ b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi;
using AMESCoreStudio.WebApi.Models.AMES;
using AMESCoreStudio.CommonTools.Result;
+using AMESCoreStudio.WebApi.Controllers.BAS;
namespace AMESCoreStudio.WebApi.Controllers.AMES
{
@@ -29,25 +30,6 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
_context = context;
}
-
- ///
- ///
- ///
- ///
- // GET: api/NGReasons
- [HttpGet]
- public string GetBarCodeCheck(string wipno = null, string unitno = null, string stations = null, string inputbarcode = null)
- {
-
-
- IQueryable q = _context.NGReasons;
- q = q.OrderBy(p => p.NGClassNo + p.NGReasonNo);
-
-
-
- return "";
- }
-
///
/// 判斷工單狀態
///
@@ -60,146 +42,141 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
[HttpGet("BarCodeDataCheck")]
public IActionResult GetBarCodeDataCheck(string wipno, string unitno, int station, int line, int flowrule)
{
- BarcodeContext barcodeContext = new BarcodeContext(_context);
- var result = barcodeContext.CheckWipNoSationAsync(WipNo: wipno, UnitNo: unitno, FlowRuleID: flowrule, Station: station, Line: line);
+ var result = CheckWipNoSationAsync(WipNo: wipno, UnitNo: unitno, FlowRuleID: flowrule, Station: station, Line: line);
return Ok(result.Result);
}
///
- ///
+ /// 判斷內部序號
///
- ///
+ ///
+ ///
///
- // GET: api/NGReasons/5
- [HttpGet("{id}")]
- public async Task>> GetNGReason(string id)
+ [HttpGet("BarCodeFromWip")]
+ public IActionResult CheckBarCodeFromWip(string barcode, string wipno)
{
- IQueryable q = _context.NGReasons;
- q = q.Where(p => p.NGReasonNo.Equals(id));
-
- var ngReason = await q.ToListAsync();
+ ResultModel resultModel = new ResultModel { Success = false };
+ if (barcode.Length <= 4)
+ {
+ resultModel.Msg = "內部序號小於4個字數";
+ return Ok(resultModel);
+ }
- if (ngReason == null)
+ WipInfosController wipInfosController = new WipInfosController(_context);
+ IQueryable q = _context.WipBarcodes.Where(w => w.StartNO.Contains(barcode.Substring(0, (barcode.Length - 4))));
+ if (!q.Any())
{
- return NotFound();
+ resultModel.Msg = "找不到內部序號:" + barcode + " 對應相關工單號碼";
+ return Ok(resultModel);
}
- return ngReason;
+
+ return Ok(resultModel);
}
///
- ///
+ /// 確認工單狀態
///
- ///
- ///
+ /// 工單號碼
+ /// 生產單位
+ /// 流程
+ /// 站別
+ /// 線別
///
- // PUT: api/NGReasons/5
- // To protect from overposting attacks, enable the specific properties you want to bind to, for
- // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
- [HttpPut("{id}")]
- public async Task> PutNGReason(string id, [FromBody] NGReason nGReason)
+ private async Task CheckWipNoSationAsync(string WipNo, string UnitNo, int FlowRuleID, int Station, int Line)
{
- ResultModel result = new ResultModel();
+ ResultModel resultModel = new ResultModel();
+
+ resultModel.Success = false;
+
+ WipInfosController wipInfosController = new WipInfosController(_context);
+
+ var q = await wipInfosController.GetWipInfoByWipNo(WipNo);
+ if (q.Value.Count() == 0)
+ {
+ resultModel.Msg = "找不到工單號碼:" + WipNo;
+ return resultModel;
+ }
- if (id != nGReason.NGReasonNo)
+ var WipNoItem = q.Value.Where(w => w.WipNO == WipNo && w.UnitNO == UnitNo).ToList();
+ if (WipNoItem.Count == 0)
{
- result.Success = false;
- result.Msg = "原因代碼錯誤";
- return result;
+ resultModel.Msg = "工單號碼:" + WipNo + ",尚未設定此生產單位";
+ return resultModel;
}
- _context.Entry(nGReason).State = EntityState.Modified;
+ if (!WipNoItem.Where(w => w.FlowRuleID == FlowRuleID).Any())
+ {
+ resultModel.Msg = "工單號碼:" + WipNo + ",尚未設定此流程站";
+ return resultModel;
+ }
+ if (WipNoItem.Where(w => w.StatusNO == "Y").Any())
+ {
+ resultModel.Msg = "工單號碼:" + WipNo + ",該工單已經投入完工,請切換工單";
+ return resultModel;
+ }
- try
+ WipLockController wipLockController = new WipLockController(_context);
+ var q1 = await wipLockController.GetWipLockByWipNO(WipNo);
+ if (q1.Data.Where(w => w.LockStatus == "0" && w.StationID == Station).Any())
{
- await _context.SaveChangesAsync();
+ resultModel.Msg = "工單號碼:" + WipNo + ",工單在當前站別被鎖定,不可過站";
+ return resultModel;
}
- catch (DbUpdateConcurrencyException)
+
+ int WipID = WipNoItem.FirstOrDefault().WipID;
+ LineInfoesController lineInfoesController = new LineInfoesController(_context);
+ var q2 = await lineInfoesController.GetLineInfoByWipID(WipID);
+ if (!q2.Value.Where(w => w.LineID == Line).Any())
{
- if (!NGReasonExists(id))
- {
- result.Success = false;
- result.Msg = "原因代碼不存在";
- return result;
- }
- else
- {
- throw;
- }
+ resultModel.Msg = "工單號碼:" + WipNo + ",工單尚未開線,不可過站";
+ return resultModel;
}
- result.Success = true;
- result.Msg = "OK";
- return result;
+ resultModel.Success = true;
+ return resultModel;
}
///
- ///
+ /// 內部序號是否被鎖定
///
- ///
+ /// 工單號碼
+ /// 內部序號
///
- // POST: api/NGReasons
- // To protect from overposting attacks, enable the specific properties you want to bind to, for
- // more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
- [HttpPost]
- public async Task> PostNGReason([FromBody] NGReason nGReason)
+ private async Task CheckBarCodeStationAsync(string WipNo, string BarCode)
{
- ResultModel result = new ResultModel();
+ BarcodeInfoesController barcodeInfoesController = new BarcodeInfoesController(_context);
- _context.NGReasons.Add(nGReason);
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateException)
+ // 序號與工單相同視為序號
+ if (BarCode.IndexOf(WipNo) != -1)
{
- if (NGReasonExists(nGReason.NGReasonNo))
- {
- result.Success = false;
- result.Msg = "原因代碼重複";
- return result;
- }
- else
+ // 判斷BarCodeInfo 是否有條碼序號資料
+ var q = await barcodeInfoesController.GetBarcodeInfoesByNo(BarCode);
+ if (q.Value.Count() != 0)
{
- throw;
+ // 判斷條碼序號是否有被鎖定
+ BarcodeLockController barcodeLockController = new BarcodeLockController(_context);
+ var q1 = await barcodeLockController.GetBarcodeLockByBarCodeID(q.Value.FirstOrDefault().BarcodeID);
+ if (q1.Value.Where(w => w.LockStatus == 0).Any())
+ {
+ return "條碼編號:" + BarCode + ",已被鎖定,無法過站";
+ }
}
}
-
- result.Success = true;
- result.Msg = "OK";
- return result;
+ return "";
}
///
- ///
+ /// 判斷內部序號對應工單號買
///
- ///
+ /// 內部序號
///
- // DELETE: api/NGReasons/5
- [HttpDelete("{id}")]
- public async Task> DeleteNGReason(string id)
+ private async Task CheckBarCodeFromWip(string BarCode)
{
- ResultModel result = new ResultModel();
+ //if (BarCode.Length <= 4)
+ return "NG, 找不到相關工單號碼";
- var nGReason = await _context.NGReasons.FindAsync(id);
- if (nGReason == null)
- {
- result.Success = false;
- result.Msg = "原因代碼不存在";
- return result;
- }
-
- _context.NGReasons.Remove(nGReason);
- await _context.SaveChangesAsync();
- result.Success = true;
- result.Msg = "OK";
- return result;
- }
-
- private bool NGReasonExists(string id)
- {
- return _context.NGReasons.Any(e => e.NGReasonNo == id);
}
}
}