Browse Source

1.修改前判維修輸入

1.1.NG_REPAIR_BLOB資料表結構修改
1.2.修改維修圖片的維護方式,呈現方式
PTD
Marvin 3 years ago
parent
commit
37c496e211
  1. 162
      AMESCoreStudio.Web/Controllers/REPController.cs
  2. 11
      AMESCoreStudio.Web/HttpApis/AMES/IREP.cs
  3. 46
      AMESCoreStudio.Web/Views/REP/REP001B.cshtml
  4. 89
      AMESCoreStudio.Web/Views/REP/REP001R.cshtml
  5. 6
      AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs
  6. 47
      AMESCoreStudio.WebApi/Models/AMES/NgRepairBlob.cs

162
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<IActionResult> 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<IActionResult> REP001D(string id)
{
var result = await _repApi.DeleteNgRepairBlob(id);
return Json(new Result() { success = true, msg = "" });
}
public async Task<IActionResult> 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<IActionResult> REP001RSaveAsync(REP001ViewModel model, IFormFile formFile1, IFormFile formFile2, IFormFile formFile3)
public async Task<IActionResult> 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;
}

11
AMESCoreStudio.Web/HttpApis/AMES/IREP.cs

@ -87,7 +87,7 @@ namespace AMESCoreStudio.Web
ITask<List<NgRepair>> GetNgRepairByComponent(decimal id);
/// <summary>
/// 根據COMPONENT_ID獲取指定維修图片資料
/// 根據REPAIR_ID獲取指定維修图片資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/NgRepairBlobs/{id}")]
@ -115,12 +115,19 @@ namespace AMESCoreStudio.Web
ITask<ResultModel<NgRepair>> PutNgRepair(int id, [FromBody, RawJsonContent] string model);
/// <summary>
/// 新增不良維修資料
/// 新增維修圖片資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpPost("api/NgRepairBlobs")]
ITask<ResultModel<NgRepairBlob>> PostNgRepairBlob([FromBody, RawJsonContent] string model);
/// <summary>
/// 刪除維修圖片資料
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/NgRepairBlobs/{id}")]
ITask<ResultModel<NgRepairBlob>> DeleteNgRepairBlob(string id);
#endregion
}
}

46
AMESCoreStudio.Web/Views/REP/REP001B.cshtml

@ -0,0 +1,46 @@
@{ ViewData["Title"] = "REP001B";
Layout = "~/Views/Shared/_AMESLayout.cshtml"; }
<style>
.control-label {
justify-content: flex-end !important;
}
.text-error {
color: #dc3545 !important;
}
.my-read-only-class {
cursor: not-allowed;
}
</style>
<div class="layui-card">
<div class="col-sm-12">
<form enctype="multipart/form-data" class="layui-form" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<img class="layui-upload-img" id="upload-normal-img" src="@ViewBag.ImageUrl" width="1024" height="560">
</div>
</div>
</form>
</div>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial");
await Html.RenderPartialAsync("_FileinputScriptsPartial"); }
<script type="text/javascript">
$(document).ready(function () {
var error = '@Html.ValidationMessage("error")';
if ($(error).text() != '') {
parent.hg.msg(error);
}
});
</script>
}

89
AMESCoreStudio.Web/Views/REP/REP001R.cshtml

@ -332,38 +332,16 @@
<label class="layui-form-label" style="color:red">維修圖片上傳</label>
</div>
</div>
<div class="layui-form-item">
<div class="layui-form-item" style="text-align:center">
<div class="layui-inline">
<img class="layui-upload-img" id="upload-normal-img1" src="@ViewBag.Image1Url" width="200" height="160">
<label asp-for="ngRepairBlob.ImageName1" class="layui-form-label"></label>
<label class="layui-btn">
<input type="file" name="formFile1">
<input type="file" name="formFile">
@*<i class="layui-icon">&#xe67c;</i>上傳文件*@
</label>
<input type="button" id="saveimage1" value="圖片1保存" class="layui-btn" style="visibility:hidden" />
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<img class="layui-upload-img" id="upload-normal-img2" src="@ViewBag.Image2Url" width="200" height="160">
<label asp-for="ngRepairBlob.ImageName2" class="layui-form-label"></label>
<label class="layui-btn">
<input type="file" name="formFile2">
@*<i class="layui-icon">&#xe67c;</i>上傳文件*@
</label>
<input type="button" value="圖片2保存" class="layui-btn" style="visibility:hidden" />
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<img class="layui-upload-img" id="upload-normal-img2" src="@ViewBag.Image3Url" width="200" height="160">
<label asp-for="ngRepairBlob.ImageName3" class="layui-form-label"></label>
<label class="layui-btn">
<input type="file" name="formFile3">
@*<i class="layui-icon">&#xe67c;</i>上傳文件*@
</label>
<input type="button" value="圖片3保存" class="layui-btn" style="visibility:hidden" />
</div>
<div class="layui-card-body">
<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<div style="text-align:center">
<div class="layui-inline">
@ -371,9 +349,9 @@
<input type="submit" value="確認" class="btn btn-primary offset-sm-3" />
</div>
</div>
</form>
</div>
</div>
@section Scripts {
@ -393,6 +371,63 @@
});
var tableCols = [[
{
field: 'repairID',
title: '維修編號',
width: 120
},
{
field: 'imageName',
title: '維修圖片'
},
{
field: 'right',
width: 200,
title: '操作',
align: 'center',
fixed: 'right',
templet: function (d) {
return '<a class="layui-btn layui-btn-normal layui-btn-xs layui-icon layui-icon-read" lay-event="detail"> 預覽 </a> <a class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete" lay-event="del"> 删除 </a>'
}
}]
];
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');
</script>

6
AMESCoreStudio.WebApi/Controllers/AMES/NgRepairBlobsController.cs

@ -121,12 +121,14 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
{
ResultModel<NgRepairBlob> result = new ResultModel<NgRepairBlob>();
/*
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
/// <returns></returns>
// DELETE: api/NgRepairBlobs/5
[HttpDelete("{id}")]
public async Task<ResultModel<NgRepairBlob>> DeleteNgRepairBlob(decimal id)
public async Task<ResultModel<NgRepairBlob>> DeleteNgRepairBlob(string id)
{
ResultModel<NgRepairBlob> result = new ResultModel<NgRepairBlob>();
@ -167,7 +169,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
if (ngRepairBlob == null)
{
result.Success = false;
result.Msg = "不良維修ID不存在";
result.Msg = "維修圖片不存在";
return result;
}

47
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; }
/// <summary>
/// 圖檔名稱1
/// 圖檔名稱
/// </summary>
[Required]
[Column("IMAGE_NAME1")]
[Column("IMAGE_NAME")]
[StringLength(50)]
[DataMember]
[Key]
[Display(Name = "圖檔名稱1")]
public string ImageName1 { get; set; }
/// <summary>
/// 圖檔1
/// </summary>
[Column("IMAGE_BLOB1")]
[DataMember]
public byte[] ImageBlob1 { get; set; }
/// <summary>
/// 圖檔名稱2
/// </summary>
[Column("IMAGE_NAME2")]
[StringLength(50)]
[DataMember]
[Display(Name = "圖檔名稱2")]
public string ImageName2 { get; set; }
/// <summary>
/// 圖檔2
/// </summary>
[Column("IMAGE_BLOB2")]
[DataMember]
public byte[] ImageBlob2 { get; set; }
/// <summary>
/// 圖檔名稱3
/// </summary>
[Column("IMAGE_NAME3")]
[StringLength(50)]
[DataMember]
[Display(Name = "圖檔名稱3")]
public string ImageName3 { get; set; }
public string ImageName { get; set; }
/// <summary>
/// 圖檔3
/// 圖檔
/// </summary>
[Column("IMAGE_BLOB3")]
[Column("IMAGE_BLOB")]
[DataMember]
public byte[] ImageBlob3 { get; set; }
public byte[] ImageBlob { get; set; }
/// <summary>

Loading…
Cancel
Save