diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs index 51f5764d..037efde3 100644 --- a/AMESCoreStudio.Web/Controllers/PCSController.cs +++ b/AMESCoreStudio.Web/Controllers/PCSController.cs @@ -1533,6 +1533,11 @@ namespace AMESCoreStudio.Web.Controllers } model.wipMAC = await _pcsApi.GetWipMAC(model.wipInfo.WipNO); + if (model.wipMAC != null) + { + model.wipMAC.StartNO = model.wipMAC.Title + model.wipMAC.StartNO; + model.wipMAC.EndNO = model.wipMAC.Title + model.wipMAC.EndNO; + } model.wipLabel = await _pcsApi.GetWipLabel(model.wipInfo.WipNO); @@ -1623,6 +1628,11 @@ namespace AMESCoreStudio.Web.Controllers } model.wipMAC = await _pcsApi.GetWipMAC(model.wipInfo.WipNO); + if (model.wipMAC != null) + { + model.wipMAC.StartNO = model.wipMAC.Title + model.wipMAC.StartNO; + model.wipMAC.EndNO = model.wipMAC.Title + model.wipMAC.EndNO; + } model.wipLabel = await _pcsApi.GetWipLabel(model.wipInfo.WipNO); @@ -1750,6 +1760,14 @@ namespace AMESCoreStudio.Web.Controllers return View("PCS003", model); } + // 判斷MAC是否正確 + var CheckMACMsg = CheckMACData(model); + if (!string.IsNullOrWhiteSpace(CheckMACMsg)) + { + ModelState.AddModelError("error", CheckMACMsg); + return View("PCS003", model); + } + result = await _pcsApi.PutWipInfo(JsonConvert.SerializeObject(model.wipInfo)); if (result.Success) { @@ -1828,11 +1846,11 @@ namespace AMESCoreStudio.Web.Controllers // MAC if (!string.IsNullOrWhiteSpace(model.wipMAC.StartNO) && !string.IsNullOrWhiteSpace(model.wipMAC.EndNO)) { - var mACInfo = await _pcsApi.GetMACInfo(model.wipAtt.ItemNO); - if (mACInfo != null) + if (model.wipMAC.StartNO.Length == 12) { - model.wipMAC.Title = mACInfo.Title; - model.wipMAC.ClassGroup = mACInfo.ClassGroup; + model.wipMAC.Title = model.wipMAC.StartNO.Substring(0, 6).ToUpper(); + model.wipMAC.StartNO = model.wipMAC.StartNO.Substring(model.wipMAC.StartNO.Length - 6, 6).ToUpper(); + model.wipMAC.EndNO = model.wipMAC.EndNO.Substring(model.wipMAC.EndNO.Length - 6, 6).ToUpper(); if (!string.IsNullOrWhiteSpace(model.wipMAC.WipNO)) result = await _pcsApi.PutWipMAC(JsonConvert.SerializeObject(model.wipMAC)); else @@ -1840,7 +1858,23 @@ namespace AMESCoreStudio.Web.Controllers model.wipMAC.WipNO = model.wipInfo.WipNO; result = await _pcsApi.PostWipMAC(JsonConvert.SerializeObject(model.wipMAC)); } - result = await _pcsApi.PutMACInfoByClassGroup(mACInfo.ClassGroup, model.wipMAC.EndNO); + } + else + { + var mACInfo = await _pcsApi.GetMACInfo(model.wipAtt.ItemNO); + if (mACInfo != null) + { + model.wipMAC.Title = mACInfo.Title; + model.wipMAC.ClassGroup = mACInfo.ClassGroup; + if (!string.IsNullOrWhiteSpace(model.wipMAC.WipNO)) + result = await _pcsApi.PutWipMAC(JsonConvert.SerializeObject(model.wipMAC)); + else + { + model.wipMAC.WipNO = model.wipInfo.WipNO; + result = await _pcsApi.PostWipMAC(JsonConvert.SerializeObject(model.wipMAC)); + } + result = await _pcsApi.PutMACInfoByClassGroup(mACInfo.ClassGroup, model.wipMAC.EndNO); + } } } // KeyParts @@ -1963,9 +1997,53 @@ namespace AMESCoreStudio.Web.Controllers ModelState.AddModelError("error", result.Msg); } } - return View(); + return View(model); } + /// + /// CheckMAC 資料是否正確 + /// + /// + public string CheckMACData(WipDataViewModel model) + { + string StartNO = model.wipMAC.StartNO.ToString(); + string EndNO = model.wipMAC.EndNO.ToString(); + // 資料為空 + if (string.IsNullOrWhiteSpace(StartNO) && string.IsNullOrWhiteSpace(EndNO)) + return ""; + + if (StartNO.Length != 12 || EndNO.Length != 12) + return "MAC長度有誤"; + + if (StartNO.ToUpper().Substring(0, 6) != EndNO.ToUpper().Substring(0, 6)) + return "MAC前綴不一樣"; + + // 轉十進位 + var Entire = new Code.Entire(); + try + { + // 最小值 + var StartNONum = int.Parse(Entire.DecHex(StartNO.Substring(StartNO.Length - 6, 6), "HexToDec")); + // 最大值 + var EndNONum = int.Parse(Entire.DecHex(EndNO.Substring(EndNO.Length - 6, 6), "HexToDec")); + + // 取MAC區間小於工單數 + if (EndNONum - StartNONum + 1 < model.wipInfo.PlanQTY) + return "MAC區間小於工單數量"; + + // 判斷MAC區間是否有重複使用 + var result = _pcsApi.GetCheckMAC(StartNO, EndNO).InvokeAsync().Result; + + if (!result.Success) + return result.Msg; + else + return ""; + } + catch + { + return "MAC後6碼格式有誤"; + } + } public async Task GetMAC(string itemno, int planQTY) { diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 68b158de..f85b69d2 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -208,6 +208,9 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/WipMAC/{id}")] ITask GetWipMAC(string id); + [WebApiClient.Attributes.HttpGet("api/WipMAC/CheckMAC/{startNo}/{endNo}")] + ITask> GetCheckMAC(string startNo, string endNo); + [WebApiClient.Attributes.HttpPost("api/WipMAC")] ITask> PostWipMAC([FromBody, RawJsonContent] string model); diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipMACController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipMACController.cs index 83eaf805..9fd1e52b 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipMACController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipMACController.cs @@ -55,65 +55,39 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return WipMAC; } - ///// - ///// SOP文件查詢 - ///// - ///// 料號 - ///// 生產單位 - ///// 檔案名稱 - ///// 狀態 - ///// 建立日期起 - ///// 建立日期迄 - ///// - //[Route("[action]")] - //[HttpGet] - //public async Task> GetWipMACQuery(string itemNo = null, string unitNo = null - // , string fileName = null, string state = null, string date_str = null, string date_end = null) - //{ - // IQueryable q = _context.WipMACs; - - // if (!string.IsNullOrWhiteSpace(itemNo)) - // q = q.Where(w => w.ItemNo == itemNo); - - // if (!string.IsNullOrWhiteSpace(unitNo)) - // q = q.Where(w => w.UnitNo == unitNo); - - // if (!string.IsNullOrWhiteSpace(fileName)) - // q = q.Where(w => w.FileName.Contains(fileName)); - - // if (!string.IsNullOrWhiteSpace(state)) - // q = q.Where(w => w.State == state); - - - // DateTime dateValue; - // if (DateTime.TryParse(date_str, out dateValue)) - // { - // q = q.Where(w => w.CreateDate >= DateTime.Parse(date_str)); - // } - - // if (DateTime.TryParse(date_end, out dateValue)) - // { - // q = q.Where(w => w.CreateDate <= DateTime.Parse(date_end)); - // } - - // ResultModel result = new ResultModel(); - // result.Data = await q.Select(s => new WipMACDto - // { - // WipMACID = s.WipMACID, - // ItemNo = s.ItemNo, - // UnitName = s.FactoryUnit.UnitName, - // FileName = s.FileName, - // FilePath = s.FilePath, - // State = s.State == "Y" ? "使用中" : "停用", - // NewName = s.NewName, - // CreateDate = s.CreateDate, - // CreateUserID = s.CreateUserID, - // UpdateDate = s.UpdateDate, - // UpdateUserID = s.UpdateUserID - // }).ToListAsync(); - - // return result; - //} + /// + /// 確認MAC區間是否有重複 + /// + /// MAC起 + /// MAC迄 + /// + [HttpGet("CheckMAC/{startNo}/{endNo}")] + public async Task> GetCheckMAC(string startNo, string endNo) + { + ResultModel result = new ResultModel(); + // 前綴 + string Title = startNo.ToUpper().Substring(0, 6); + string start = startNo.Substring(startNo.Length - 6, 6).ToUpper(); + string end = endNo.Substring(endNo.Length - 6, 6).ToUpper(); + + IQueryable q = _context.WipMACs.Where(w => w.Title == Title); + var WipMAC = await q.Where(w => (string.Compare(w.StartNO, start) <= 0 && string.Compare(start, w.EndNO) <= 0) + || (string.Compare(w.StartNO, end) <= 0 && string.Compare(end, w.EndNO) <= 0)).ToListAsync(); + + if (WipMAC.Count !=0) + { + result.Success = false; + result.Msg = "有重複MAC區間"; + } + else + { + result.Success = true; + result.Msg = "OK"; + } + return result; + + } + [HttpPost] public async Task> PostWipMAC([FromBody] WipMAC WipMAC) diff --git a/AMESCoreStudio.WebApi/Models/AMES/WipMAC.cs b/AMESCoreStudio.WebApi/Models/AMES/WipMAC.cs index ec1a3915..2334b40b 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/WipMAC.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/WipMAC.cs @@ -29,7 +29,7 @@ namespace AMESCoreStudio.WebApi.Models.AMES [Column("START_NO")] [DataMember] [Required(ErrorMessage = "{0},不能空白")] - [StringLength(6)] + [StringLength(12)] [Display(Name = "MAC起")] public string StartNO { get; set; } @@ -39,7 +39,7 @@ namespace AMESCoreStudio.WebApi.Models.AMES [Key] [Column("END_NO")] [DataMember] - [StringLength(6)] + [StringLength(12)] [Required(ErrorMessage = "{0},不能空白")] [Display(Name = "MAC迄")] public string EndNO { get; set; }