diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index 8b4180ec..d25050e9 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -131,6 +131,32 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetNgRepairBlob(int id) + { + var result = await _repApi.GetNgRepairBlob(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 REP001B(string id) + { + ViewBag.ImageUrl = $"\\REPImage\\" + id; + return View(); + } + + public async Task REP001D(string id) + { + var result = await _repApi.DeleteNgRepairBlob(id); + return Json(new Result() { success = true, msg = "" }); + } + public async Task REP001R(int id) { await GetRMAReasonList(); @@ -167,30 +193,30 @@ namespace AMESCoreStudio.Web.Controllers { 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"; - } + //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 { @@ -212,7 +238,7 @@ namespace AMESCoreStudio.Web.Controllers //頁面提交,id=0 添加,id>0 修改 [HttpPost] - public async Task REP001RSaveAsync(REP001ViewModel model, IFormFile formFile1, IFormFile formFile2, IFormFile formFile3) + public async Task REP001RSaveAsync(REP001ViewModel model, IFormFile formFile) { IResultModel result; var userID = ""; @@ -229,79 +255,25 @@ namespace AMESCoreStudio.Web.Controllers model.ngComponent.ReplyDate = System.DateTime.Now; model.ngComponent.Status = 1; - 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", "請選擇要上傳檔案"); - } + string FileName = string.Empty; + string NewName = string.Empty; + string FilePath = string.Empty; - if (formFile3 != null) + if (formFile != null) { - if (formFile3.Length > 0) + if (formFile.Length > 0) { //取得使用者上傳檔案的原始檔名 - FileName3 = Path.GetFileName(formFile3.FileName); + FileName = Path.GetFileName(formFile.FileName); //取原始檔名中的副檔名 - var fileExt = Path.GetExtension(FileName3); + var fileExt = Path.GetExtension(FileName); //為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱 - NewName3 = Path.GetRandomFileName() + fileExt; + NewName = Path.GetRandomFileName() + fileExt; //指定要寫入的路徑、檔名和副檔名 - FilePath3 = $"\\REPImage\\";//本機目錄 - using (var stream = new FileStream(_env.WebRootPath + FilePath3 + NewName3, FileMode.Create)) + FilePath = $"\\REPImage\\";//本機目錄 + using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create)) { - await formFile3.CopyToAsync(stream); + await formFile.CopyToAsync(stream); } } } @@ -339,7 +311,7 @@ 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) + if (NewName == string.Empty) { } else { @@ -357,18 +329,14 @@ namespace AMESCoreStudio.Web.Controllers 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.ImageName = NewName; 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.ImageName = NewName; model.ngRepairBlob.RepairID = repairID; } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs index 940813af..ca15f9c8 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs @@ -87,7 +87,7 @@ namespace AMESCoreStudio.Web ITask> GetNgRepairByComponent(decimal id); /// - /// 根據COMPONENT_ID獲取指定維修图片資料 + /// 根據REPAIR_ID獲取指定維修图片資料 /// /// [WebApiClient.Attributes.HttpGet("api/NgRepairBlobs/{id}")] @@ -115,12 +115,19 @@ namespace AMESCoreStudio.Web ITask> PutNgRepair(int id, [FromBody, RawJsonContent] string model); /// - /// 新增不良維修資料 + /// 新增維修圖片資料 /// /// [WebApiClient.Attributes.HttpPost("api/NgRepairBlobs")] ITask> PostNgRepairBlob([FromBody, RawJsonContent] string model); + /// + /// 刪除維修圖片資料 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/NgRepairBlobs/{id}")] + ITask> DeleteNgRepairBlob(string id); + #endregion } } diff --git a/AMESCoreStudio.Web/Views/REP/REP001B.cshtml b/AMESCoreStudio.Web/Views/REP/REP001B.cshtml new file mode 100644 index 00000000..82009ac7 --- /dev/null +++ b/AMESCoreStudio.Web/Views/REP/REP001B.cshtml @@ -0,0 +1,46 @@ +@{ ViewData["Title"] = "REP001B"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; } + + + +
+
+
+
+
+ +
+
+
+
+ +
+ +@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 a62a9af5..828fdf2f 100644 --- a/AMESCoreStudio.Web/Views/REP/REP001R.cshtml +++ b/AMESCoreStudio.Web/Views/REP/REP001R.cshtml @@ -332,38 +332,16 @@ -
-
- - - - -
-
-
+
- - -
-
-
- - - - -
+
+
@@ -371,9 +349,9 @@
-
+
@section Scripts { @@ -390,9 +368,66 @@ $("#saveimage1").click(function (event) { alert('save1'); - + }); + + var tableCols = [[ + { + field: 'repairID', + title: '維修編號', + width: 120 + }, + { + field: 'imageName', + title: '維修圖片' + }, + { + field: 'right', + width: 200, + title: '操作', + align: 'center', + fixed: 'right', + templet: function (d) { + return ' 預覽 删除 ' + } + }] + ]; + + function detail(obj) { + if (obj.data.imageName) { + //alert(obj.data.imageName); + hg.open('預覽圖片資料', '/REP/REP001B/' + obj.data.imageName, '', '', true); + } + } + + //通过行tool删除,lay-event="del" + function del(obj) { + if (obj.data.imageName) { + hg.confirm("圖片資料:" + obj.data.imageName + ",确定要删除吗?", function () { + $.ajax({ + url: '/REP/REP001D', + data: { id: obj.data.imageName }, + 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.WebApi/Controllers/AMES/NgRepairBlobsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs index f2b73f28..a01b92e0 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs @@ -121,12 +121,14 @@ 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 @@ -159,7 +161,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// // DELETE: api/NgRepairBlobs/5 [HttpDelete("{id}")] - public async Task> DeleteNgRepairBlob(decimal id) + public async Task> DeleteNgRepairBlob(string id) { ResultModel result = new ResultModel(); @@ -167,7 +169,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES if (ngRepairBlob == null) { result.Success = false; - result.Msg = "不良維修ID不存在"; + result.Msg = "維修圖片不存在"; return result; } diff --git a/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs b/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs index 69db4f13..25893b78 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs @@ -19,58 +19,25 @@ namespace AMESCoreStudio.WebApi.Models.AMES [Column("REPAIR_ID", TypeName = "NUMBER")] [DataMember] [Required] - [Key] public decimal RepairID { get; set; } /// - /// 圖檔名稱1 + /// 圖檔名稱 /// [Required] - [Column("IMAGE_NAME1")] + [Column("IMAGE_NAME")] [StringLength(50)] [DataMember] + [Key] [Display(Name = "圖檔名稱1")] - public string ImageName1 { get; set; } - - /// - /// 圖檔1 - /// - [Column("IMAGE_BLOB1")] - [DataMember] - public byte[] ImageBlob1 { get; set; } - - /// - /// 圖檔名稱2 - /// - [Column("IMAGE_NAME2")] - [StringLength(50)] - [DataMember] - [Display(Name = "圖檔名稱2")] - public string ImageName2 { get; set; } - - /// - /// 圖檔2 - /// - [Column("IMAGE_BLOB2")] - [DataMember] - public byte[] ImageBlob2 { get; set; } - - - /// - /// 圖檔名稱3 - /// - [Column("IMAGE_NAME3")] - [StringLength(50)] - [DataMember] - [Display(Name = "圖檔名稱3")] - public string ImageName3 { get; set; } + public string ImageName { get; set; } /// - /// 圖檔3 + /// 圖檔 /// - [Column("IMAGE_BLOB3")] + [Column("IMAGE_BLOB")] [DataMember] - public byte[] ImageBlob3 { get; set; } + public byte[] ImageBlob { get; set; } ///