8 changed files with 367 additions and 50 deletions
@ -0,0 +1,134 @@ |
|||||
|
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 BarcodeOutfitController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
public BarcodeOutfitController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
// GET: api/BarcodeOutfit
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeOutfit>>> GetBarcodeOutfits() |
||||
|
{ |
||||
|
return await _context.BarcodeOutfits.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
// GET: api/BarcodeOutfit/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<BarcodeOutfit>> GetBarcodeOutfit(string id) |
||||
|
{ |
||||
|
var barcodeOutfit = await _context.BarcodeOutfits.FindAsync(id); |
||||
|
|
||||
|
if (barcodeOutfit == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return barcodeOutfit; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 查詢 By BarcodeNo
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">條碼料號</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpGet("ByBarcodeNo/{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<BarcodeOutfit>>> GetBarcodeOutfitByBarcodeNo(string id) |
||||
|
{ |
||||
|
var barcodeOutfit = await _context.BarcodeOutfits.Where(w => w.BarcodeNo == id).ToListAsync(); |
||||
|
|
||||
|
return barcodeOutfit; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新內部序號對應的治具序號明細
|
||||
|
/// </summary>
|
||||
|
/// <param name="barcodeOutfit"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPut] |
||||
|
public async Task<ResultModel<BarcodeOutfit>> PutBarcodeOutfit(BarcodeOutfit barcodeOutfit) |
||||
|
{ |
||||
|
ResultModel<BarcodeOutfit> result = new ResultModel<BarcodeOutfit>(); |
||||
|
_context.Entry(barcodeOutfit).State = EntityState.Modified; |
||||
|
barcodeOutfit.UpdateDate = DateTime.Now; |
||||
|
barcodeOutfit.UpdateUserID = 0; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = ex.InnerException.Message; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 新增內部序號對應的治具序號明細
|
||||
|
/// </summary>
|
||||
|
/// <param name="barcodeOutfit"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
public async Task<ResultModel<BarcodeOutfit>> PostBarcodeOutfit(BarcodeOutfit barcodeOutfit) |
||||
|
{ |
||||
|
ResultModel<BarcodeOutfit> result = new ResultModel<BarcodeOutfit>(); |
||||
|
_context.BarcodeOutfits.Add(barcodeOutfit); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = ex.InnerException.Message; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// DELETE: api/BarcodeOutfit/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ActionResult<BarcodeOutfit>> DeleteBarcodeOutfit(string id) |
||||
|
{ |
||||
|
var barcodeOutfit = await _context.BarcodeOutfits.FindAsync(id); |
||||
|
if (barcodeOutfit == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
_context.BarcodeOutfits.Remove(barcodeOutfit); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
return barcodeOutfit; |
||||
|
} |
||||
|
|
||||
|
private bool BarcodeOutfitExists(string id) |
||||
|
{ |
||||
|
return _context.BarcodeOutfits.Any(e => e.BarcodeNo == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,91 @@ |
|||||
|
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>
|
||||
|
/// 內部序號對應的治具序號明細
|
||||
|
/// </summary>
|
||||
|
[Table("BARCODE_OUTFIT", Schema = "JHAMES")] |
||||
|
public partial class BarcodeOutfit |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 生產序號
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("BARCODE_NO")] |
||||
|
[StringLength(20)] |
||||
|
[DataMember] |
||||
|
public string BarcodeNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 工單號碼
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("WIP_NO")] |
||||
|
[StringLength(30)] |
||||
|
[DataMember] |
||||
|
public string WipNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 設備編號
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("OUTFIT_NO")] |
||||
|
[StringLength(12)] |
||||
|
[DataMember] |
||||
|
public string OutfitNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 站別
|
||||
|
/// </summary>
|
||||
|
[Column("STATION_ID")] |
||||
|
[DataMember] |
||||
|
public int StationID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立UserID
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立日期
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime CreateDate { get; set; } = DateTime.Now; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新UserID
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int UpdateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新日期
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime? UpdateDate { get; set; } = DateTime.Now; |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 工作站基本資料
|
||||
|
/// </summary>
|
||||
|
[ForeignKey("StationID")] |
||||
|
[DataMember] |
||||
|
public virtual BAS.Stations GetStation { get; set; } |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue