8 changed files with 464 additions and 5 deletions
@ -0,0 +1,173 @@ |
|||
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; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class PlmBomsController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="context"></param>
|
|||
public PlmBomsController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
// GET: api/PlmBoms
|
|||
[HttpGet] |
|||
public async Task<ActionResult<IEnumerable<PlmBom>>> GetPlmBom() |
|||
{ |
|||
return await _context.PlmBoms.ToListAsync(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 根據零件位置查詢料號
|
|||
/// </summary>
|
|||
/// <param name="itemNo">料號</param>
|
|||
/// <param name="locationNo">零件位置</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("GetPlmBom4REP001")] |
|||
public async Task<ActionResult<IEnumerable<PlmBom>>> GetPlmBom4REP001(string itemNo,string locationNo) |
|||
{ |
|||
IQueryable<PlmBom> q = _context.PlmBoms; |
|||
q = q.Where(p => p.MatnrP.Equals(itemNo) && (p.Ebort1.Contains(locationNo) || p.Ebort2.Contains(locationNo))); |
|||
|
|||
var plmBom = await q.ToListAsync(); |
|||
|
|||
return plmBom; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// GET: api/PlmBoms/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<PlmBom>> GetPlmBom(string id) |
|||
{ |
|||
var plmBom = await _context.PlmBoms.FindAsync(id); |
|||
|
|||
if (plmBom == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return plmBom; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="plmBom"></param>
|
|||
/// <returns></returns>
|
|||
// PUT: api/PlmBoms/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<IActionResult> PutPlmBom(string id, PlmBom plmBom) |
|||
{ |
|||
if (id != plmBom.BomID) |
|||
{ |
|||
return BadRequest(); |
|||
} |
|||
|
|||
_context.Entry(plmBom).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateConcurrencyException) |
|||
{ |
|||
if (!PlmBomExists(id)) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
return NoContent(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="plmBom"></param>
|
|||
/// <returns></returns>
|
|||
// POST: api/PlmBoms
|
|||
// 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<ActionResult<PlmBom>> PostPlmBom(PlmBom plmBom) |
|||
{ |
|||
_context.PlmBoms.Add(plmBom); |
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateException) |
|||
{ |
|||
if (PlmBomExists(plmBom.BomID)) |
|||
{ |
|||
return Conflict(); |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
return CreatedAtAction("GetPlmBom", new { id = plmBom.BomID }, plmBom); |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// DELETE: api/PlmBoms/5
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ActionResult<PlmBom>> DeletePlmBom(string id) |
|||
{ |
|||
var plmBom = await _context.PlmBoms.FindAsync(id); |
|||
if (plmBom == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
_context.PlmBoms.Remove(plmBom); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return plmBom; |
|||
} |
|||
|
|||
private bool PlmBomExists(string id) |
|||
{ |
|||
return _context.PlmBoms.Any(e => e.BomID == id); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,138 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System.Runtime.Serialization; |
|||
|
|||
|
|||
#nullable disable |
|||
|
|||
namespace AMESCoreStudio.WebApi.Models.AMES |
|||
{ |
|||
/// <summary>
|
|||
/// PLM BOM
|
|||
/// </summary>
|
|||
[Table("PLM_BOM", Schema = "JHAMES")] |
|||
public partial class PlmBom |
|||
{ |
|||
/// <summary>
|
|||
/// 建BOM日期
|
|||
/// </summary>
|
|||
[Column("BOM_DATE")] |
|||
[StringLength(8)] |
|||
[Required] |
|||
[DataMember] |
|||
public string BomDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 建BOM時間
|
|||
/// </summary>
|
|||
[Required] |
|||
[DataMember] |
|||
[Column("BOM_TIME")] |
|||
[StringLength(6)] |
|||
public string BomTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// BOM_ID
|
|||
/// </summary>
|
|||
[Key] |
|||
[Required] |
|||
[DataMember] |
|||
[Column("BOM_ID")] |
|||
[StringLength(15)] |
|||
public string BomID { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// MATNR_P
|
|||
/// </summary>
|
|||
[Column("MATNR_P")] |
|||
[StringLength(18)] |
|||
[DataMember] |
|||
public string MatnrP { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// MATNR_OLD
|
|||
/// </summary>
|
|||
[Column("MATNR_OLD")] |
|||
[StringLength(18)] |
|||
[DataMember] |
|||
public string MatnrOld { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// MATNR_NEW
|
|||
/// </summary>
|
|||
[Required] |
|||
[Column("MATNR_NEW")] |
|||
[StringLength(18)] |
|||
[DataMember] |
|||
public string MatnrNew { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// QTY
|
|||
/// </summary>
|
|||
[Column("QTY")] |
|||
[StringLength(18)] |
|||
[DataMember] |
|||
public float Qty { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 狀態
|
|||
/// </summary>
|
|||
[Required] |
|||
[DataMember] |
|||
[Column("STATUS")] |
|||
[StringLength(3)] |
|||
public string Status { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// MATNR_GROUP
|
|||
/// </summary>
|
|||
[Column("MATNR_GROUP")] |
|||
[StringLength(3)] |
|||
[DataMember] |
|||
public string MatnrGroup { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// MAIN_SUBSTITUTE
|
|||
/// </summary>
|
|||
[Column("MAIN_SUBSTITUTE")] |
|||
[StringLength(3)] |
|||
[DataMember] |
|||
public string MainSubstitute { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// EBORT1
|
|||
/// </summary>
|
|||
[DataMember] |
|||
[Column("EBORT1")] |
|||
[StringLength(4000)] |
|||
public string Ebort1 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// EBORT2
|
|||
/// </summary>
|
|||
[DataMember] |
|||
[Column("EBORT2")] |
|||
[StringLength(4000)] |
|||
public string Ebort2 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// ECN_ID
|
|||
/// </summary>
|
|||
[DataMember] |
|||
[Column("ECN_ID")] |
|||
[StringLength(15)] |
|||
public string EcnID { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 建立日期
|
|||
/// </summary>
|
|||
[Required] |
|||
[Column("CREATEDATE")] |
|||
[DataMember] |
|||
public DateTime CreateDate { get; set; } = DateTime.Now; |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue