9 changed files with 783 additions and 9 deletions
@ -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<NgKeypart> NgKeyparts { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
@model AMESCoreStudio.WebApi.Models.AMES.NgKeypart |
||||
|
|
||||
|
|
||||
|
@{ ViewData["Title"] = "REP001KC"; |
||||
|
Layout = "~/Views/Shared/_FormLayout.cshtml"; } |
||||
|
|
||||
|
<style> |
||||
|
.control-label { |
||||
|
justify-content: flex-end !important; |
||||
|
} |
||||
|
</style> |
||||
|
|
||||
|
<div class="row"> |
||||
|
<div class="col-sm-12"> |
||||
|
<form enctype="multipart/form-data" method="post" asp-action="REP001KCSave"> |
||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div> |
||||
|
<input type="hidden" asp-for="ComponentID" value="@ViewBag.ComponentID" /> |
||||
|
|
||||
|
<div class="form-group form-inline my-sm-1"> |
||||
|
<label asp-for="OldPartNo" class="control-label col-sm-3"></label> |
||||
|
<input id="test1" asp-for="OldPartNo" class="form-control col-sm-9" placeholder="請輸入舊組件序號" /> |
||||
|
<span asp-validation-for="OldPartNo" class="text-danger offset-sm-3 my-sm-1"></span> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-group form-inline my-sm-1"> |
||||
|
<label asp-for="NewPartNo" class="control-label col-sm-3"></label> |
||||
|
<input id="test1" asp-for="NewPartNo" class="form-control col-sm-9" placeholder="請輸入新組件序號" /> |
||||
|
<span asp-validation-for="NewPartNo" class="text-danger offset-sm-3 my-sm-1"></span> |
||||
|
</div> |
||||
|
<span style="color: firebrick;word-break: break-all;" class="text-danger offset-sm-3">@Html.ValidationMessage("error")</span> |
||||
|
<div class="form-group"> |
||||
|
<input type="submit" value="儲存" class="btn btn-primary offset-sm-3" /> |
||||
|
</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> |
||||
|
|
||||
|
|
||||
|
} |
@ -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 |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
[Route("api/[controller]")]
|
||||
|
[ApiController] |
||||
|
public class NgKeypartsController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public NgKeypartsController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgKeyparts
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<NgKeypart>>> GetNgKeypart() |
||||
|
{ |
||||
|
return await _context.NgKeyparts.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgKeyparts/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<NgKeypart>>> GetNgKeypart(int id) |
||||
|
{ |
||||
|
IQueryable<NgKeypart> q = _context.NgKeyparts; |
||||
|
q = q.Where(p => p.KeypartID.Equals(id)); |
||||
|
|
||||
|
var ngKeypart = await q.ToListAsync(); |
||||
|
|
||||
|
if (ngKeypart == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return ngKeypart; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/NgKeyparts/5
|
||||
|
[HttpGet("ComponentID/{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<NgKeypart>>> GetNgKeypartByComponentID(int id) |
||||
|
{ |
||||
|
IQueryable<NgKeypart> 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(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="ngKeypart"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// 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<ResultModel<NgKeypart>> PutNgKeypart(int id, NgKeypart ngKeypart) |
||||
|
{ |
||||
|
ResultModel<NgKeypart> result = new ResultModel<NgKeypart>(); |
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="ngKeypart"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// 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<ResultModel<NgKeypart>> PostNgKeypart(NgKeypart ngKeypart) |
||||
|
{ |
||||
|
ResultModel<NgKeypart> result = new ResultModel<NgKeypart>(); |
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/NgKeyparts/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ResultModel<NgKeypart>> DeleteNgKeypart(int id) |
||||
|
{ |
||||
|
ResultModel<NgKeypart> result = new ResultModel<NgKeypart>(); |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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 |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 維修不良組件資料檔
|
||||
|
/// </summary>
|
||||
|
[Table("NG_KEYPART", Schema = "JHAMES")] |
||||
|
public partial class NgKeypart |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 不良組件ID
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("KEYPART_ID")] |
||||
|
[DataMember] |
||||
|
[Required] |
||||
|
[Display(Name = "不良組件ID")] |
||||
|
public int KeypartID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 不良零件ID
|
||||
|
/// </summary>
|
||||
|
[Column("COMPONENT_ID")] |
||||
|
[DataMember] |
||||
|
[Required] |
||||
|
[Display(Name = "不良零件ID")] |
||||
|
public int ComponentID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 舊組件序號
|
||||
|
/// </summary>
|
||||
|
//[Required]
|
||||
|
[Column("OLD_PART_NO")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "舊組件序號")] |
||||
|
public string OldPartNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 新組件序號
|
||||
|
/// </summary>
|
||||
|
//[Required]
|
||||
|
[Column("NEW_PART_NO")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "新組件序號")] |
||||
|
public string NewPartNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 創建者ID
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 創建日期
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "不良時間")] |
||||
|
public DateTime CreateDate { get; set; } = System.DateTime.Now; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新者ID
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int UpdateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新日期
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_DATE", TypeName = "DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime UpdateDate { get; set; } = System.DateTime.Now; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue