diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index 8e3d86d9..6b167c91 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -9,6 +9,9 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Rendering; using AMESCoreStudio.Web.ViewModels; using System.ComponentModel.DataAnnotations; +using System.IO; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Hosting; namespace AMESCoreStudio.Web.Controllers { @@ -18,13 +21,15 @@ namespace AMESCoreStudio.Web.Controllers public readonly IREP _repApi; public readonly IPPS _ppsApi; public readonly IBAS _basApi; + private readonly IWebHostEnvironment _env; - public REPController(ILogger logger, IREP repApi, IPPS ppsApi,IBAS basApi) + public REPController(ILogger logger, IREP repApi, IPPS ppsApi,IBAS basApi, IWebHostEnvironment env) { _logger = logger; _repApi = repApi; _ppsApi = ppsApi; _basApi = basApi; + _env = env; } @@ -153,6 +158,43 @@ namespace AMESCoreStudio.Web.Controllers { model.ngRepair = result4[0]; } + + var result5 = await _repApi.GetNgRepairBlob(result4[0].RepairID); + if (result5.Count != 0) + { + model.ngRepairBlob = result5[0]; + + if (result5[0].ImageName1 != "" && result5[0].ImageName1 != null) + { + ViewBag.Image1Url = $"\\REPImage\\" + result5[0].ImageName1; + } + else + { + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + } + if (result5[0].ImageName2 != "" && result5[0].ImageName2 != null) + { + ViewBag.Image2Url = $"\\REPImage\\" + result5[0].ImageName2; + } + else + { + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + } + if (result5[0].ImageName3 != "" && result5[0].ImageName3 != null) + { + ViewBag.Image3Url = $"\\REPImage\\" + result5[0].ImageName3; + } + else + { + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } + } + else + { + ViewBag.Image1Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image2Url = $"\\REPImage\\" + "noimage.jfif"; + ViewBag.Image3Url = $"\\REPImage\\" + "noimage.jfif"; + } } return View(model); @@ -160,7 +202,7 @@ namespace AMESCoreStudio.Web.Controllers //頁面提交,id=0 添加,id>0 修改 [HttpPost] - public async Task REP001RSaveAsync(REP001ViewModel model) + public async Task REP001RSaveAsync(REP001ViewModel model, IFormFile formFile1, IFormFile formFile2, IFormFile formFile3) { IResultModel result; var userID = ""; @@ -177,7 +219,88 @@ namespace AMESCoreStudio.Web.Controllers model.ngComponent.ReplyDate = System.DateTime.Now; model.ngComponent.Status = 1; - result = await _repApi.PutNgComponent((int)model.ngComponent.ComponentID,JsonConvert.SerializeObject(model.ngComponent)); + string FileName1 = string.Empty; + string NewName1 = string.Empty; + string FilePath1 = string.Empty; + + string FileName2 = string.Empty; + string NewName2 = string.Empty; + string FilePath2 = string.Empty; + + string FileName3 = string.Empty; + string NewName3 = string.Empty; + string FilePath3 = string.Empty; + + if (formFile1 != null) + { + if (formFile1.Length > 0) + { + //取得使用者上傳檔案的原始檔名 + FileName1 = Path.GetFileName(formFile1.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName1); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName1 = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + FilePath1 = $"\\REPImage\\";//本機目錄 + using (var stream = new FileStream(_env.WebRootPath + FilePath1 + NewName1, FileMode.Create)) + { + await formFile1.CopyToAsync(stream); + } + } + } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); + } + + if (formFile2 != null) + { + if (formFile2.Length > 0) + { + //取得使用者上傳檔案的原始檔名 + FileName2 = Path.GetFileName(formFile2.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName2); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName2 = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + FilePath2 = $"\\REPImage\\";//本機目錄 + using (var stream = new FileStream(_env.WebRootPath + FilePath2 + NewName2, FileMode.Create)) + { + await formFile2.CopyToAsync(stream); + } + } + } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); + } + + if (formFile3 != null) + { + if (formFile3.Length > 0) + { + //取得使用者上傳檔案的原始檔名 + FileName3 = Path.GetFileName(formFile3.FileName); + //取原始檔名中的副檔名 + var fileExt = Path.GetExtension(FileName3); + //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 + NewName3 = Path.GetRandomFileName() + fileExt; + //指定要寫入的路徑、檔名和副檔名 + FilePath3 = $"\\REPImage\\";//本機目錄 + using (var stream = new FileStream(_env.WebRootPath + FilePath3 + NewName3, FileMode.Create)) + { + await formFile3.CopyToAsync(stream); + } + } + } + else + { + ModelState.AddModelError("error", "請選擇要上傳檔案"); + } + + result = await _repApi.PutNgComponent((int)model.ngComponent.ComponentID, JsonConvert.SerializeObject(model.ngComponent)); if (model.repairRecord.ComponentID > 0) { @@ -190,6 +313,11 @@ namespace AMESCoreStudio.Web.Controllers result = await _repApi.PostRepairRecord(JsonConvert.SerializeObject(model.repairRecord)); } + if (model.ngRepair.Missing == "Y") + { + model.ngRepair.RepairNo = "N/A"; + } + if (model.ngRepair.RepairID > 0) { result = await _repApi.PutNgRepair((int)model.ngRepair.RepairID, JsonConvert.SerializeObject(model.ngRepair)); @@ -200,6 +328,51 @@ namespace AMESCoreStudio.Web.Controllers model.ngRepair.ComponentID = model.ngComponent.ComponentID; result = await _repApi.PostNgRepair(JsonConvert.SerializeObject(model.ngRepair)); } + if (NewName1 == string.Empty && NewName2 == string.Empty && NewName3 == string.Empty) + { } + else + { + decimal repairID = 0; + if (model.ngRepair.RepairID == 0) + { + var ng_repair = await _repApi.GetNgRepairByComponent(model.ngRepair.ComponentID); + repairID = ng_repair[0].RepairID; + } + else + { + repairID = model.ngRepair.RepairID; + } + + if (model.ngRepairBlob == null) + { + NgRepairBlob ng_repair_blob = new NgRepairBlob(); + ng_repair_blob.ImageName1 = NewName1; + ng_repair_blob.ImageName2 = NewName2; + ng_repair_blob.ImageName3 = NewName3; + ng_repair_blob.RepairID = repairID; + + model.ngRepairBlob = ng_repair_blob; + } + else + { + model.ngRepairBlob.ImageName1 = NewName1; + model.ngRepairBlob.ImageName2 = NewName2; + model.ngRepairBlob.ImageName2 = NewName3; + model.ngRepairBlob.RepairID = repairID; + } + + result = await _repApi.PostNgRepairBlob(JsonConvert.SerializeObject(model.ngRepairBlob)); + } + + //if (result.Success) + //{ + // var _msg = model.ngRepairBlob.RepairID == 0 ? "新增成功!" : "修改成功!"; + // return RedirectToAction("Refresh", "Home", new { msg = _msg }); + //} + //else + //{ + // ModelState.AddModelError("error", result.Msg); + //} if (result.Success) { @@ -219,6 +392,7 @@ namespace AMESCoreStudio.Web.Controllers } } + return View("REP001R", model); //return RedirectToAction("REP001V", "REP", new { id = model.ngComponent.NgID }); } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs index 8fcf3ba4..d70a4755 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs @@ -84,7 +84,14 @@ namespace AMESCoreStudio.Web /// /// [WebApiClient.Attributes.HttpGet("api/NgRepairs/Component/{id}")] - ITask> GetNgRepairByComponent(int id); + ITask> GetNgRepairByComponent(decimal id); + + /// + /// 根據COMPONENT_ID獲取指定維修图片資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/NgRepairBlobs/{id}")] + ITask> GetNgRepairBlob(decimal id); /// /// 新增不良維修資料 @@ -100,6 +107,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpPut("api/NgRepairs/{id}")] ITask> PutNgRepair(int id, [FromBody, RawJsonContent] string model); + /// + /// 新增不良維修資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/NgRepairBlobs")] + ITask> PostNgRepairBlob([FromBody, RawJsonContent] string model); + #endregion } } diff --git a/AMESCoreStudio.Web/ViewModels/REP/REP001ViewModel.cs b/AMESCoreStudio.Web/ViewModels/REP/REP001ViewModel.cs index caffd52b..8256bf43 100644 --- a/AMESCoreStudio.Web/ViewModels/REP/REP001ViewModel.cs +++ b/AMESCoreStudio.Web/ViewModels/REP/REP001ViewModel.cs @@ -18,5 +18,7 @@ namespace AMESCoreStudio.Web.ViewModels public NgRepair ngRepair { get; set; } + public NgRepairBlob ngRepairBlob { get; set; } + } } diff --git a/AMESCoreStudio.Web/Views/REP/REP001.cshtml b/AMESCoreStudio.Web/Views/REP/REP001.cshtml index 89358031..fb472fc7 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001.cshtml @@ -100,8 +100,9 @@ }, { field: 'right', - width: 200, + width: 120, title: '操作', + align: 'center', fixed: 'right', templet: function (d) { return ' 檢視 ' diff --git a/AMESCoreStudio.Web/Views/REP/REP001R.cshtml b/AMESCoreStudio.Web/Views/REP/REP001R.cshtml index de8539d9..b8f30721 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001R.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001R.cshtml @@ -155,6 +155,18 @@ +
+
+ +
+ + + + +
+ +
+
@@ -202,6 +214,44 @@
+
+
+ +
+
+
+
+ + + + +
+
+
+
+ + + + +
+
+
+
+ + + + +
+
@Html.ValidationMessage("error") @@ -224,6 +274,12 @@ parent.hg.msg(error); } }); + + $("#saveimage1").click(function (event) { + alert('save1'); + + + }); diff --git a/AMESCoreStudio.Web/Views/REP/REP001V.cshtml b/AMESCoreStudio.Web/Views/REP/REP001V.cshtml index cb99a2cd..b8a32041 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001V.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001V.cshtml @@ -135,7 +135,7 @@ }, { field: 'right', - width: 80, + width: 120, title: '操作', align: 'center', fixed: 'right', diff --git a/AMESCoreStudio.Web/wwwroot/REPImage/noimage.jfif b/AMESCoreStudio.Web/wwwroot/REPImage/noimage.jfif new file mode 100644 index 00000000..c76ca765 Binary files /dev/null and b/AMESCoreStudio.Web/wwwroot/REPImage/noimage.jfif differ diff --git a/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj b/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj index a354489a..149334b3 100644 --- a/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj +++ b/AMESCoreStudio.WebApi/AMESCoreStudio.WebApi.csproj @@ -5,7 +5,7 @@ - C:\Users\USER\Desktop\AMES1025\AMESCoreStudio.WebApi\AMESCoreStudio.WebApi.xml + AMESCoreStudio.WebApi\AMESCoreStudio.WebApi.xml Off diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs index 876b2d38..f2b73f28 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs @@ -47,7 +47,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// // GET: api/NgRepairBlobs/5 [HttpGet("{id}")] - public async Task>> GetNgRepairBlob(int id) + public async Task>> GetNgRepairBlob(decimal id) { IQueryable q = _context.NgRepairBlobs; q = q.Where(p => p.RepairID.Equals(id)); @@ -121,12 +121,19 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES { ResultModel result = new ResultModel(); + var ng_repair_blob = await _context.NgRepairBlobs.FindAsync(ngRepairBlob.RepairID); + if (ng_repair_blob != null) + { + _context.NgRepairBlobs.Remove(ng_repair_blob); + await _context.SaveChangesAsync(); + } + _context.NgRepairBlobs.Add(ngRepairBlob); try { await _context.SaveChangesAsync(); } - catch (DbUpdateException) + catch (DbUpdateException e1) { if (NgRepairBlobExists(ngRepairBlob.RepairID)) { diff --git a/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs b/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs index 9efb7a9f..69db4f13 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs @@ -35,7 +35,6 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 圖檔1 /// - [Required] [Column("IMAGE_BLOB1")] [DataMember] public byte[] ImageBlob1 { get; set; } @@ -43,7 +42,6 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 圖檔名稱2 /// - [Required] [Column("IMAGE_NAME2")] [StringLength(50)] [DataMember] @@ -53,7 +51,6 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 圖檔2 /// - [Required] [Column("IMAGE_BLOB2")] [DataMember] public byte[] ImageBlob2 { get; set; } @@ -62,7 +59,6 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 圖檔名稱3 /// - [Required] [Column("IMAGE_NAME3")] [StringLength(50)] [DataMember] @@ -72,7 +68,6 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// /// 圖檔3 /// - [Required] [Column("IMAGE_BLOB3")] [DataMember] public byte[] ImageBlob3 { get; set; }