diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index 0f700498..903cae4e 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -409,6 +409,64 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetNgKeyparts(int id) + { + var result = await _repApi.GetNgKeyparts(id); + + if (result.Count > 0) + { + return Json(new Table() { code = 0, msg = "", data = result, count = result.Count }); + } + + return Json(new Table() { count = 0, data = null }); + } + + public IActionResult REP001KC(int id) + { + ViewBag.ComponentID = id; + + var model = new NgKeypart(); + if (id > 0) + { + model.ComponentID = id; + } + + return View(model); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task REP001KCSaveAsync(NgKeypart model) + { + IResultModel result; + + result = await _repApi.PostNgKeypart(JsonConvert.SerializeObject(model)); + + if (result.Success) + { + return RedirectToAction("Refresh", "Home", new { msg = "" }); + } + else + { + return Json(new Result() { success = false, msg = result.Msg }); + } + } + + public async Task REP001KDAsync(int id) + { + var result = await _repApi.DeleteNgKeypart(id); + if (result.Success) + { + return Json(new Result() { success = true, msg = "" }); + } + else + { + return Json(new Result() { success = false, msg = result.Msg }); + } + } + public IActionResult REP001B(string id) { ViewBag.ImageUrl = $"\\REPImage\\" + id; @@ -461,8 +519,152 @@ namespace AMESCoreStudio.Web.Controllers return Json(new { _msg = string.Format("維修描述保存成功!") }); } + public async Task SaveNgKeypart(int component_id, string old_part_no,string new_part_no) + { + IResultModel result; + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + int user_id = 0; + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + + NgKeypart model = new NgKeypart(); + model.ComponentID = component_id; + model.OldPartNo = old_part_no; + model.NewPartNo = new_part_no; + model.UpdateUserID = user_id; + model.UpdateDate = System.DateTime.Now; + model.CreateUserID = user_id; + model.CreateDate = System.DateTime.Now; + + result = await _repApi.PostNgKeypart(JsonConvert.SerializeObject(model)); + + //return Json(new { _msg = string.Format("新增成功!") }); + return Json(new { _msg = result.Msg }); + } + + public async Task SaveNgKeypartNew(int component_id, string old_part_no, string new_part_no) + { + IResultModel result; + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + int user_id = 0; + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + + NgKeypart ng_key_part = new NgKeypart(); + ng_key_part.ComponentID = component_id; + ng_key_part.OldPartNo = old_part_no; + ng_key_part.NewPartNo = new_part_no; + ng_key_part.UpdateUserID = user_id; + ng_key_part.UpdateDate = System.DateTime.Now; + ng_key_part.CreateUserID = user_id; + ng_key_part.CreateDate = System.DateTime.Now; + + result = await _repApi.PostNgKeypart(JsonConvert.SerializeObject(ng_key_part)); + + int id = component_id; + ViewBag.ComponentID = id; + + await GetRMAReasonList(); + await GetRepairTypeList(); + await GetNGReasonList(); + await GetRepairResponsibleUnitList(); + + HttpContext.Response.Cookies.Append("UserID4REP001", userID.ToString()); + + REP001NewViewModel model = new REP001NewViewModel(); + var result1 = await _repApi.GetNgComponent(id); + + var ng_reason = await _ppsApi.GetNGReason(result1[0].NgNo); + if (ng_reason.Count != 0) + { + model.ngReason = ng_reason[0]; + } + + if (result1[0].ErrorDesc == "" || result1[0].ErrorDesc == null) + { + result1[0].ErrorDesc = ng_reason[0].NGReasonDesc; + } + + if (result1.Count != 0) + { + model.ngComponent = result1[0]; + + var ng_keypart = await _repApi.GetNgKeyparts((int)result1[0].ComponentID); + if (ng_keypart.Count != 0) + { + model.NgKeyparts = ng_keypart; + } + + var result2 = await _repApi.GetNgInfo((int)result1[0].NgID); + if (result2.Count != 0) + { + model.ngInfo = result2[0]; + } + + var result3 = await _repApi.GetRepairRecord((int)result1[0].ComponentID); + if (result3.Count != 0) + { + model.repairRecord = result3[0]; + + var result31 = await _repApi.GetRepairRecordByNgID((int)result1[0].NgID); + string repair_desc = ""; + for (int r = 0; r < result31.Count; r++) + { + repair_desc = repair_desc + result31[r].RepairDesc + "\r\n"; + } + + model.repairRecord.RepairDesc = repair_desc; + } + + var result4 = await _repApi.GetNgRepairByComponent((int)result1[0].ComponentID); + if (result4.Count != 0) + { + model.ngRepair = result4[0]; + + + var result5 = await _repApi.GetNgRepairBlob(result4[0].RepairID); + if (result5.Count != 0) + { + model.ngRepairBlob = result5[0]; + } + else + { + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } + } + else + { + NgRepair ngRepair = new NgRepair(); + model.ngRepair = ngRepair; + + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } + } + + return View(model); + } + + public async Task REP001R(int id) { + ViewBag.ComponentID = id; + await GetRMAReasonList(); await GetRepairTypeList(); await GetNGReasonList(); @@ -471,7 +673,7 @@ namespace AMESCoreStudio.Web.Controllers var userID = HttpContext.Request.Cookies["UserID"]; HttpContext.Response.Cookies.Append("UserID4REP001", userID.ToString()); - REP001ViewModel model = new REP001ViewModel(); + REP001NewViewModel model = new REP001NewViewModel(); var result1 = await _repApi.GetNgComponent(id); var ng_reason = await _ppsApi.GetNGReason(result1[0].NgNo); @@ -489,6 +691,12 @@ namespace AMESCoreStudio.Web.Controllers { model.ngComponent = result1[0]; + var ng_keypart = await _repApi.GetNgKeyparts((int)result1[0].ComponentID); + if (ng_keypart.Count != 0) + { + model.NgKeyparts = ng_keypart; + } + var result2 = await _repApi.GetNgInfo((int)result1[0].NgID); if (result2.Count != 0) { diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs index 260519fc..11069f6a 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs @@ -354,5 +354,26 @@ namespace AMESCoreStudio.Web /// [WebApiClient.Attributes.HttpGet("api/NgRepairs/GetRepairData4REP013")] ITask> GetRepairData4REP013(string wipNo, string itemNo, string dateStart, string dateEnd, int page, int limit); + + /// + /// 根據ComponentID獲取維修不良組件資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/NgKeyparts/ComponentID/{id}")] + ITask> GetNgKeyparts(decimal id); + + /// + /// 新增維修組件 + /// + /// + [WebApiClient.Attributes.HttpPost("api/NgKeyparts")] + ITask> PostNgKeypart([FromBody, RawJsonContent] string model); + + /// + /// 刪除維修組件 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/NgKeyparts/{id}")] + ITask> DeleteNgKeypart(int id); } } diff --git a/AMESCoreStudio.Web/ViewModels/REP/REP001NewViewModel.cs b/AMESCoreStudio.Web/ViewModels/REP/REP001NewViewModel.cs new file mode 100644 index 00000000..3e1f7d9f --- /dev/null +++ b/AMESCoreStudio.Web/ViewModels/REP/REP001NewViewModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.WebApi.Models.BAS; +using AMESCoreStudio.WebApi.DTO.AMES; + +namespace AMESCoreStudio.Web.ViewModels +{ + public class REP001NewViewModel + { + public NgInfo ngInfo { get; set; } + + public NgComponent ngComponent { get; set; } + + public RepairRecord repairRecord { get; set; } + + public NgRepair ngRepair { get; set; } + + public NgRepairBlob ngRepairBlob { get; set; } + + public NGReason ngReason { get; set; } + + public NgKeypart NgKeypart { get; set; } + + public IEnumerable NgKeyparts { get; set; } + } +} diff --git a/AMESCoreStudio.Web/Views/REP/REP001KC.cshtml b/AMESCoreStudio.Web/Views/REP/REP001KC.cshtml new file mode 100644 index 00000000..3f059db4 --- /dev/null +++ b/AMESCoreStudio.Web/Views/REP/REP001KC.cshtml @@ -0,0 +1,53 @@ +@model AMESCoreStudio.WebApi.Models.AMES.NgKeypart + + +@{ ViewData["Title"] = "REP001KC"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + +
+
+
+
+ + +
+ + + +
+ +
+ + + +
+ @Html.ValidationMessage("error") +
+ +
+ +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} diff --git a/AMESCoreStudio.Web/Views/REP/REP001R.cshtml b/AMESCoreStudio.Web/Views/REP/REP001R.cshtml index d27edeba..15ecd3fc 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001R.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001R.cshtml @@ -1,4 +1,4 @@ -@model AMESCoreStudio.Web.ViewModels.REP001ViewModel +@model AMESCoreStudio.Web.ViewModels.REP001NewViewModel @{ ViewData["Title"] = "REP001R"; @@ -275,19 +275,76 @@
- + +
+
+ + @{ + int i = 0; + } + + + + + + + + + + + + @if (Model.NgKeyparts != null) + { + @foreach (var data in Model.NgKeyparts) + { + + + + + + + i++; + } + } + +
+ 不良組件編號 + + 舊組件序號 + + 新組件序號 + + +
+ + + + + + + + + + 刪除 +
+ +
+
+
- - + + @**@
- +
- - + + @**@
+   
+
@@ -570,6 +627,57 @@ }); + $('#btnKeypartInsertNew').click(function () { + var component_id = $('#txtComponentID').val(); + var old_part_no = $('#txtOldPartNo').val(); + var new_part_no = $('#txtNewPartNo').val(); + + $.ajax({ + url: '@Url.Action("SaveNgKeypart", "REP")', + dataType: 'json', + data: { "component_id": component_id, "old_part_no": old_part_no, "new_part_no": new_part_no }, + cache: false, + type: "POST", + success: function (data, textStatus, jqXHR) { + if (data._msg != undefined) { + parent.hg.msg("新增成功!"); + var newData = `${data._msg}${old_part_no}${new_part_no}刪除`; + $('#MydataTable').append(newData); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert("Found error when using Ajax!!"); + } + }); + + + }); + + $('#btnKeypartInsert').click(function () { + var component_id = $('#txtComponentID').val(); + var old_part_no = $('#txtOldPartNo').val(); + var new_part_no = $('#txtNewPartNo').val(); + + $.ajax({ + url: '@Url.Action("SaveNgKeypart", "REP")', + dataType: 'json', + data: { "component_id": component_id, "old_part_no": old_part_no, "new_part_no": new_part_no }, + cache: false, + type: "POST", + success: function (data, textStatus, jqXHR) { + if (data._msg != undefined) { + parent.hg.msg("新增成功!"); + location.reload(); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert("Found error when using Ajax!!"); + } + }); + + + }); + var tableCols = [[ { field: 'repairID', @@ -599,7 +707,7 @@ } } - //通过行tool删除,lay-event="del" + //通过行tool删除,lay-event="del2" function del(obj) { if (obj.data.imageName) { hg.confirm("圖片資料:" + obj.data.imageName + ",确定要删除吗?", function () { @@ -624,8 +732,62 @@ } } + // Table 刪除 + function Remove(button, OldNo, NewNo, KeypartID) { + hg.confirm("舊組件序號:" + OldNo + ",新組件序號:" + NewNo + ",確定要删除嗎?", function () { + + $.ajax({ + url: '@Url.Action("REP001KD", "REP")', + dataType: 'json', + data: { id: KeypartID }, + cache: false, + type: "POST", + success: function (data) { + if (data.success) { + hg.msg("删除成功!"); + var row = $(button).closest("TR"); + var table = $("#MydataTable")[0]; + table.deleteRow(row[0].rowIndex); + + } + + }, + error: function (jqXHR, textStatus, errorThrown) { + hg.msg("Found error when using Ajax!!"); + } + }); + }); + }; + + + //通过行tool删除,lay-event="del" + function del2(obj) { + if (obj.data.oldPartNo) { + hg.confirm("組件資料:" + obj.data.oldPartNo + ",确定要删除吗?", function () { + $.ajax({ + url: '/REP/REP001KD', + data: { id: obj.data.keypartID }, + type: 'POST', + success: function (data) { + if (data.success) { + obj.del(); //只删本地数据 + hg.msghide("删除成功!"); + } + else { + hg.msg(data.msg); + } + }, + error: function () { + hg.msg("网络请求失败!"); + } + }); + }); + } + } + //基本数据表格 var table = hg.table.datatable('test', '維修圖片資料', '/REP/GetNgRepairBlob/' + @Model.ngRepair.RepairID, {}, tableCols, false, false, 'full-100'); + diff --git a/AMESCoreStudio.Web/Views/REP/REP001V.cshtml b/AMESCoreStudio.Web/Views/REP/REP001V.cshtml index 389f2b16..1705f8da 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001V.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001V.cshtml @@ -171,6 +171,7 @@ function repair(obj) { if (obj.data.componentID) { hg.open('維修輸入', '/REP/REP001R/' + obj.data.componentID, 1080, 540); + //hg.open('維修輸入', '/REP/REP001R/' + obj.data.componentID, '', '', true); } } diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/NgKeypartsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgKeypartsController.cs new file mode 100644 index 00000000..d64763ee --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgKeypartsController.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class NgKeypartsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public NgKeypartsController(AMESContext context) + { + _context = context; + } + + /// + /// + /// + /// + // GET: api/NgKeyparts + [HttpGet] + public async Task>> GetNgKeypart() + { + return await _context.NgKeyparts.ToListAsync(); + } + + /// + /// + /// + /// + /// + // GET: api/NgKeyparts/5 + [HttpGet("{id}")] + public async Task>> GetNgKeypart(int id) + { + IQueryable q = _context.NgKeyparts; + q = q.Where(p => p.KeypartID.Equals(id)); + + var ngKeypart = await q.ToListAsync(); + + if (ngKeypart == null) + { + return NotFound(); + } + + return ngKeypart; + } + + /// + /// + /// + /// + /// + // GET: api/NgKeyparts/5 + [HttpGet("ComponentID/{id}")] + public async Task>> GetNgKeypartByComponentID(int id) + { + IQueryable q = _context.NgKeyparts; + + q = q.Where(p => p.ComponentID.Equals(id)); + + try + { + var ngKeypart = await q.ToListAsync(); + + if (ngKeypart == null) + { + return NotFound(); + } + + return ngKeypart; + } + catch (Exception e1) + { + return NotFound(); + } + } + + /// + /// + /// + /// + /// + /// + // PUT: api/NgKeyparts/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> PutNgKeypart(int id, NgKeypart ngKeypart) + { + ResultModel result = new ResultModel(); + if (id != ngKeypart.KeypartID) + { + result.Success = false; + result.Msg = "不良組件ID錯誤"; + return result; + } + + _context.Entry(ngKeypart).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!NgKeypartExists(id)) + { + result.Success = false; + result.Msg = "不良組件ID不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/NgKeyparts + // 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> PostNgKeypart(NgKeypart ngKeypart) + { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); + ngKeypart.KeypartID = helper.GetIDKey("KEYPART_ID").Result; + + _context.NgKeyparts.Add(ngKeypart); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException ex) + { + if (NgKeypartExists(ngKeypart.KeypartID)) + { + result.Success = false; + result.Msg = "不良組件ID重複"; + return result; + } + else + { + result.Success = false; + result.Msg = ex.InnerException.Message; + return result; + } + } + + result.Success = true; + result.Msg = ngKeypart.KeypartID.ToString(); + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/NgKeyparts/5 + [HttpDelete("{id}")] + public async Task> DeleteNgKeypart(int id) + { + ResultModel result = new ResultModel(); + + var ngKeypart = await _context.NgKeyparts.FindAsync(id); + if (ngKeypart == null) + { + result.Success = false; + result.Msg = "不良組件ID不存在"; + return result; + } + + _context.NgKeyparts.Remove(ngKeypart); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool NgKeypartExists(int id) + { + return _context.NgKeyparts.Any(e => e.KeypartID == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/NgKeypart.cs b/AMESCoreStudio.WebApi/Models/AMES/NgKeypart.cs new file mode 100644 index 00000000..4d16a09f --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/NgKeypart.cs @@ -0,0 +1,82 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +#nullable disable + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 維修不良組件資料檔 + /// + [Table("NG_KEYPART", Schema = "JHAMES")] + public partial class NgKeypart + { + /// + /// 不良組件ID + /// + [Key] + [Column("KEYPART_ID")] + [DataMember] + [Required] + [Display(Name = "不良組件ID")] + public int KeypartID { get; set; } + + /// + /// 不良零件ID + /// + [Column("COMPONENT_ID")] + [DataMember] + [Required] + [Display(Name = "不良零件ID")] + public int ComponentID { get; set; } + + /// + /// 舊組件序號 + /// + //[Required] + [Column("OLD_PART_NO")] + [DataMember] + [Display(Name = "舊組件序號")] + public string OldPartNo { get; set; } + + /// + /// 新組件序號 + /// + //[Required] + [Column("NEW_PART_NO")] + [DataMember] + [Display(Name = "新組件序號")] + public string NewPartNo { get; set; } + + /// + /// 創建者ID + /// + [Column("CREATE_USERID")] + [DataMember] + public int CreateUserID { get; set; } = 0; + + /// + /// 創建日期 + /// + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "不良時間")] + public DateTime CreateDate { get; set; } = System.DateTime.Now; + + /// + /// 更新者ID + /// + [Column("UPDATE_USERID")] + [DataMember] + public int UpdateUserID { get; set; } = 0; + + /// + /// 更新日期 + /// + [Column("UPDATE_DATE", TypeName = "DATE")] + [DataMember] + public DateTime UpdateDate { get; set; } = System.DateTime.Now; + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 173d9cc4..7807edb2 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -1000,6 +1000,11 @@ namespace AMESCoreStudio.WebApi /// 测试文本 /// public DbSet TestInfoes { get; set; } + + /// + /// 維修不良序號 + /// + public DbSet NgKeyparts { get; set; } } }