diff --git a/AMESCoreStudio.Web/Controllers/PPSController.cs b/AMESCoreStudio.Web/Controllers/PPSController.cs index 04ee1100..211460b6 100644 --- a/AMESCoreStudio.Web/Controllers/PPSController.cs +++ b/AMESCoreStudio.Web/Controllers/PPSController.cs @@ -51,6 +51,19 @@ namespace AMESCoreStudio.Web.Controllers ViewBag.SectionList = SectionList; } + private async Task GetLineList() + { + var result = await _basApi.GetLineInfoes(); + + var LineList = new List(); + + for (int i = 0; i < result.Count; i++) + { + LineList.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString())); + } + ViewBag.LineList = LineList; + } + private async Task GetErrorGroupList() { var result = await _ppsApi.GetErrorGroups(); @@ -184,6 +197,21 @@ namespace AMESCoreStudio.Web.Controllers return Json(new { data = item }); } + [HttpPost] + public async Task GetLineJson(string unit_no) + { + var result = await _basApi.GetLineInfoByUnit(unit_no); + + var item = new List(); + + for (int i = 0; i < result.Count; i++) + { + item.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString())); + } + //将数据Json化并传到前台视图 + return Json(new { data = item }); + } + private async Task GetStatusList() { var StatusList = new List(); @@ -409,6 +437,120 @@ namespace AMESCoreStudio.Web.Controllers #endregion + #region PPS003機種C/T資料維護相關 + + public IActionResult PPS003() + { + return View(); + } + + //新增頁面 + public async Task PPS003C() + { + await GetSectionList(); + await GetLineList(); + + return View(); + } + + //修改页面 + [HttpGet] + public async Task PPS003UAsync(string id) + { + await GetSectionList(); + await GetLineList(); + + var result = await _ppsApi.GetCycleTime(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + + public async Task PPS003DAsync(string id) + { + var result = await _ppsApi.DeleteCycleTime(id); + return Json(new Result() { success = true, msg = "" }); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task PPS003CSaveAsync(CycleTime model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PostCycleTime(JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "添加成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("PPS003C", model); + } + + public async Task PPS003USaveAsync(CycleTime model) + { + if (ModelState.IsValid) + { + IResultModel result; + + result = await _ppsApi.PutCycleTime(model.ItemNo + "," + model.LineID.ToString(), JsonConvert.SerializeObject(model)); + + if (result.Success) + { + var _msg = "修改成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + } + return View("PPS003U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetCycleTimesAsync(int page = 1, int limit = 10) + { + var result = await _ppsApi.GetCycleTimes(page,limit); + var result_total = await _ppsApi.GetCycleTimes(0, limit); + + if (result.Count > 0) + { + return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count }); + } + + return Json(new Table() { count = 0, data = null }); + } + + #endregion + #region PPS005異常群組維護相關 public IActionResult PPS005() diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs index 35530915..6e8144b2 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPPS.cs @@ -90,6 +90,45 @@ namespace AMESCoreStudio.Web #endregion + #region PPS003 機種C/T資料維護 + + /// + /// 新增機種C/T資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/CycleTimes")] + ITask> PostCycleTime([FromBody, RawJsonContent] string model); + + /// + /// 更新機種C/T資料 + /// + /// + [WebApiClient.Attributes.HttpPut("api/CycleTimes/{id}")] + ITask> PutCycleTime(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除機種C/T資料 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/CycleTimes/{id}")] + ITask> DeleteCycleTime(string id); + + /// + /// 根據ID獲取指定機種C/T資料資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/CycleTimes/{id}")] + ITask> GetCycleTime(string id); + + /// + /// 獲取機種C/T資料資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/CycleTimes")] + ITask> GetCycleTimes(int page = 1, int limit = 10); + + #endregion + #region PPS005 異常群組維護 /// diff --git a/AMESCoreStudio.Web/Views/Home/Framework.cshtml b/AMESCoreStudio.Web/Views/Home/Framework.cshtml index d8ee93a6..fb51c365 100644 --- a/AMESCoreStudio.Web/Views/Home/Framework.cshtml +++ b/AMESCoreStudio.Web/Views/Home/Framework.cshtml @@ -171,6 +171,9 @@
  • 條碼狀態維護
  • +
  • + 機種C/T資料維護 +
  • 異常群組維護
  • diff --git a/AMESCoreStudio.Web/Views/PPS/PPS003.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS003.cshtml new file mode 100644 index 00000000..33c5c37b --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS003.cshtml @@ -0,0 +1,113 @@ +@{ + ViewData["Title"] = "機種C/T資料維護"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
    +
    +
    +
    +
    @ViewBag.Title
    +
    +
    +
    +
    +
    +
    +
    + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/PPS/PPS003C.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS003C.cshtml new file mode 100644 index 00000000..27399c42 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS003C.cshtml @@ -0,0 +1,136 @@ +@model AMESCoreStudio.WebApi.Models.AMES.CycleTime + + +@{ ViewData["Title"] = "PPS003C"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.Web/Views/PPS/PPS003U.cshtml b/AMESCoreStudio.Web/Views/PPS/PPS003U.cshtml new file mode 100644 index 00000000..2c483558 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PPS/PPS003U.cshtml @@ -0,0 +1,106 @@ +@model AMESCoreStudio.WebApi.Models.AMES.CycleTime + + +@{ ViewData["Title"] = "PPS003U"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + + +
    +
    +
    +
    + + + +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    + @Html.ValidationMessage("error") +
    + +
    + +
    +
    +
    + +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} + diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/CycleTimesController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/CycleTimesController.cs index dae53fab..dbcdf773 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/CycleTimesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/CycleTimesController.cs @@ -7,11 +7,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using AMESCoreStudio.WebApi; using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; namespace AMESCoreStudio.WebApi.Controllers.AMES { /// - /// + /// 機種C/T資料維護 /// [Route("api/[controller]")] [ApiController] @@ -34,9 +35,27 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// // GET: api/CycleTimes [HttpGet] - public async Task>> GetCycleTime() + public async Task>> GetCycleTime(int page = 1, int limit = 10) { - return await _context.CycleTimes.ToListAsync(); + IQueryable q = _context.CycleTimes; + if (page > 0) + { + q = q.OrderBy(p => p.ItemNo + p.LineID).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ItemNo + p.LineID); + } + + var cycleTime = await q.ToListAsync(); + + foreach (var data in cycleTime) + { + data.Unit = _context.FactoryUnits.Find(data.SectionNo); + data.Line = _context.LineInfoes.Find(data.LineID); + } + + return cycleTime; } /// @@ -46,9 +65,22 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// // GET: api/CycleTimes/5 [HttpGet("{id}")] - public async Task> GetCycleTime(string id) + public async Task>> GetCycleTime(string id) { - var cycleTime = await _context.CycleTimes.FindAsync(id); + string[] param = id.Split(','); + string itemNo = param[0]; + int lineId = int.Parse(param[1]); + + IQueryable q = _context.CycleTimes; + q = q.Where(p => p.ItemNo.Equals(itemNo) && p.LineID.Equals(lineId)); + + var cycleTime = await q.ToListAsync(); + + foreach (var data in cycleTime) + { + data.Unit = _context.FactoryUnits.Find(data.SectionNo); + data.Line = _context.LineInfoes.Find(data.LineID); + } if (cycleTime == null) { @@ -68,11 +100,27 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES // 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 PutCycleTime(string id, CycleTime cycleTime) + public async Task> PutCycleTime(string id, [FromBody] CycleTime cycleTime) { - if (id != cycleTime.ItemNo) + ResultModel result = new ResultModel(); + string[] param = id.Split(','); + string itemNo = param[0]; + int lineId = int.Parse(param[1]); + + cycleTime.UpdateDate = DateTime.Now; + + if (itemNo != cycleTime.ItemNo) + { + result.Success = false; + result.Msg = "料號錯誤"; + return result; + } + + if (lineId != cycleTime.LineID) { - return BadRequest(); + result.Success = false; + result.Msg = "線別ID錯誤"; + return result; } _context.Entry(cycleTime).State = EntityState.Modified; @@ -83,9 +131,11 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } catch (DbUpdateConcurrencyException) { - if (!CycleTimeExists(id)) + if (!CycleTimeExists(itemNo, lineId)) { - return NotFound(); + result.Success = false; + result.Msg = "料號錯誤"; + return result; } else { @@ -93,7 +143,9 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } } - return NoContent(); + result.Success = true; + result.Msg = "OK"; + return result; } /// @@ -105,8 +157,13 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES // 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> PostCycleTime(CycleTime cycleTime) + public async Task> PostCycleTime([FromBody] CycleTime cycleTime) { + ResultModel result = new ResultModel(); + + cycleTime.CreateDate = DateTime.Now; + cycleTime.CreateUserId = 0; + _context.CycleTimes.Add(cycleTime); try { @@ -114,9 +171,11 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } catch (DbUpdateException) { - if (CycleTimeExists(cycleTime.ItemNo)) + if (CycleTimeExists(cycleTime.ItemNo, cycleTime.LineID)) { - return Conflict(); + result.Success = false; + result.Msg = "資料重複"; + return result; } else { @@ -124,7 +183,9 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } } - return CreatedAtAction("GetCycleTime", new { id = cycleTime.ItemNo }, cycleTime); + result.Success = true; + result.Msg = "OK"; + return result; } /// @@ -134,23 +195,32 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// // DELETE: api/CycleTimes/5 [HttpDelete("{id}")] - public async Task> DeleteCycleTime(string id) + public async Task> DeleteCycleTime(string id) { - var cycleTime = await _context.CycleTimes.FindAsync(id); + ResultModel result = new ResultModel(); + string[] param = id.Split(','); + string itemNo = param[0]; + int lineId = int.Parse(param[1]); + + var cycleTime = await _context.CycleTimes.Where(p => p.ItemNo == itemNo && p.LineID == lineId).FirstOrDefaultAsync(); if (cycleTime == null) { - return NotFound(); + result.Success = false; + result.Msg = "資料不存在"; + return result; } _context.CycleTimes.Remove(cycleTime); await _context.SaveChangesAsync(); - return cycleTime; + result.Success = true; + result.Msg = "OK"; + return result; } - private bool CycleTimeExists(string id) + private bool CycleTimeExists(string itemNo,int lineId) { - return _context.CycleTimes.Any(e => e.ItemNo == id); + return _context.CycleTimes.Any(e => e.ItemNo == itemNo && e.LineID == lineId); } } } diff --git a/AMESCoreStudio.WebApi/Models/AMES/CycleTime.cs b/AMESCoreStudio.WebApi/Models/AMES/CycleTime.cs index 1ef8a297..86b90bf3 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/CycleTime.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/CycleTime.cs @@ -2,14 +2,14 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.Serialization; +using AMESCoreStudio.WebApi.Models.BAS; namespace AMESCoreStudio.WebApi.Models.AMES { /// - /// 标准工时资料表 + /// 機種C/T資料表 /// [Table("CYCLE_TIME", Schema = "JHAMES")] - [DataContract] public class CycleTime { /// @@ -106,19 +106,19 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 週產出 /// - [Column("WI_CNT")] + [Column("WI_UNIT")] [DataMember] [Required(ErrorMessage = "{0},不能空白")] [Display(Name = "週產出")] - public decimal WICnt { get; set; } + public decimal WIUnit { get; set; } /// - /// 料號 + /// 備註 /// - [Column("ITEM_NO")] + [Column("MEMO")] [Required(ErrorMessage = "{0},不能空白")] - [Display(Name = "料號")] - [StringLength(30, ErrorMessage = "{0},不能大于{1}")] + [Display(Name = "備註")] + [StringLength(100, ErrorMessage = "{0},不能大于{1}")] [DataMember] public string Memo { get; set; } @@ -145,5 +145,15 @@ namespace AMESCoreStudio.WebApi.Models.AMES [DataMember] [Display(Name = "修改日期")] public DateTime UpdateDate { get; set; } + + /// + /// 線別資料 + /// + public virtual AMESCoreStudio.WebApi.Models.BAS.LineInfo Line { get; set; } + + /// + /// 製程資料 + /// + public virtual AMESCoreStudio.WebApi.Models.BAS.FactoryUnit Unit { get; set; } } } diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index f2c509d7..91111c19 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -86,11 +86,13 @@ namespace AMESCoreStudio.WebApi modelBuilder.Entity().HasKey(c => new { c.WipID, c.CreateDate}); modelBuilder.Entity().HasKey(c => new { c.ItemNo, c.LineID }); + modelBuilder.Entity().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.SectionNo).IsRequired(); + modelBuilder.Entity().HasOne(r => r.Line).WithMany().HasForeignKey(r => r.LineID).IsRequired(); modelBuilder.Entity().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.UnitNo).IsRequired(); modelBuilder.Entity().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.UnitNo).IsRequired(); modelBuilder.Entity().HasOne(r => r.Dept).WithMany().HasForeignKey(r => r.DeptID).IsRequired(); - modelBuilder.Entity < AMESCoreStudio.WebApi.Models.BAS.Stations>().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.UnitNo).IsRequired(); + modelBuilder.Entity().HasOne(r => r.Unit).WithMany().HasForeignKey(r => r.UnitNo).IsRequired(); }