2 changed files with 343 additions and 0 deletions
@ -0,0 +1,243 @@ |
|||||
|
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 SNKeyPartsController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="context"></param>
|
||||
|
public SNKeyPartsController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/SNKeyParts
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<SNKeyPart>>> GetSNKeyPart(int page = 0, int limit = 10) |
||||
|
{ |
||||
|
IQueryable<SNKeyPart> q = _context.SNKeyParts; |
||||
|
if (page > 0) |
||||
|
{ |
||||
|
q = q.OrderBy(p => p.StockInNo + p.KPItem).Skip((page - 1) * limit).Take(limit); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
q = q.OrderBy(p => p.StockInNo + p.KPItem); |
||||
|
} |
||||
|
|
||||
|
var snKeyPart = await q.ToListAsync(); |
||||
|
return snKeyPart; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="no"></param>
|
||||
|
/// <param name="page"></param>
|
||||
|
/// <param name="limit"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/SNKeyParts/StockInNo/S
|
||||
|
[HttpGet("StockInNo/{no}")] |
||||
|
public async Task<ActionResult<IEnumerable<SNKeyPart>>> GetSNKeyPartByStockInNo(string no,int page = 0, int limit = 10) |
||||
|
{ |
||||
|
IQueryable<SNKeyPart> q = _context.SNKeyParts; |
||||
|
|
||||
|
if (no != null) |
||||
|
{ |
||||
|
if (no != "*") |
||||
|
{ |
||||
|
q = q.Where(p => p.StockInNo.Equals(no)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (page > 0) |
||||
|
{ |
||||
|
q = q.OrderBy(p => p.StockInNo + p.KPItem).Skip((page - 1) * limit).Take(limit); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
q = q.OrderBy(p => p.StockInNo + p.KPItem); |
||||
|
} |
||||
|
|
||||
|
var snKeyPart = await q.ToListAsync(); |
||||
|
return snKeyPart; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// GET: api/SNKeyParts/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<SNKeyPart>>> GetSNKeyPart(string id) |
||||
|
{ |
||||
|
string[] param = id.Split(','); |
||||
|
string stockInNo = param[0]; |
||||
|
int kpItem = int.Parse(param[1]); |
||||
|
|
||||
|
IQueryable<SNKeyPart> q = _context.SNKeyParts; |
||||
|
q = q.Where(p => p.StockInNo.Equals(stockInNo) && p.KPItem.Equals(kpItem)); |
||||
|
|
||||
|
var snKeyPart = await q.ToListAsync(); |
||||
|
|
||||
|
if (snKeyPart == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return snKeyPart; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改外包機種資料
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <param name="sNKeyPart"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// PUT: api/SNKeyParts/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<SNKeyPart>> PutSNKeyPart(string id, SNKeyPart sNKeyPart) |
||||
|
{ |
||||
|
ResultModel<SNKeyPart> result = new ResultModel<SNKeyPart>(); |
||||
|
|
||||
|
string[] param = id.Split(','); |
||||
|
string stockInNo = param[0]; |
||||
|
int kpItem = int.Parse(param[1]); |
||||
|
|
||||
|
if (stockInNo != sNKeyPart.StockInNo) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "入庫單號錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
if (kpItem != sNKeyPart.KPItem) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "入庫單號項次錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.Entry(sNKeyPart).State = EntityState.Modified; |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateConcurrencyException) |
||||
|
{ |
||||
|
if (!SNKeyPartExists(stockInNo,kpItem)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "入庫單號&項次錯誤"; |
||||
|
return result; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="sNKeyPart"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// POST: api/SNKeyParts
|
||||
|
// 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<SNKeyPart>> PostSNKeyPart(SNKeyPart sNKeyPart) |
||||
|
{ |
||||
|
ResultModel<SNKeyPart> result = new ResultModel<SNKeyPart>(); |
||||
|
|
||||
|
if (SNKeyPartExists(sNKeyPart.StockInNo, sNKeyPart.KPItem)) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "資料重複:"+ sNKeyPart.StockInNo+","+ sNKeyPart.KPItem; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.SNKeyParts.Add(sNKeyPart); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
} |
||||
|
catch (DbUpdateException) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
/// <param name="id"></param>
|
||||
|
/// <returns></returns>
|
||||
|
// DELETE: api/SNKeyParts/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ResultModel<SNKeyPart>> DeleteSNKeyPart(string id) |
||||
|
{ |
||||
|
ResultModel<SNKeyPart> result = new ResultModel<SNKeyPart>(); |
||||
|
|
||||
|
string[] param = id.Split(','); |
||||
|
string stockInNo = param[0]; |
||||
|
int kpItem = int.Parse(param[1]); |
||||
|
|
||||
|
var snKeyPart = await _context.SNKeyParts.Where(p => p.StockInNo == stockInNo && p.KPItem == kpItem).FirstOrDefaultAsync(); |
||||
|
|
||||
|
if (snKeyPart == null) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = "資料不存在"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
_context.SNKeyParts.Remove(snKeyPart); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private bool SNKeyPartExists(string stockInNo,int kpItem) |
||||
|
{ |
||||
|
return _context.SNKeyParts.Any(e => e.StockInNo == stockInNo && e.KPItem == kpItem); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,100 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using System.Runtime.Serialization; |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Models.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 外包機種資料
|
||||
|
/// </summary>
|
||||
|
[Table("SN_KEYPART", Schema = "JHAMES")] |
||||
|
[DataContract] |
||||
|
public class SNKeyPart |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 入庫單號
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("STOCK_IN_NO")] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[DataMember] |
||||
|
public string StockInNo { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 入庫料號
|
||||
|
/// </summary>
|
||||
|
[Column("STOCK_IN_PN")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "入庫料號")] |
||||
|
public string StockInPn { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件日期
|
||||
|
/// </summary>
|
||||
|
[Column("KP_DATE")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "組件日期")] |
||||
|
public DateTime KPDate { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件序號
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("KP_ITEM")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "組件序號")] |
||||
|
public int KPItem { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件SN
|
||||
|
/// </summary>
|
||||
|
[Column("KP_SN")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "組件SN")] |
||||
|
public string KPSn { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件MB
|
||||
|
/// </summary>
|
||||
|
[Column("KP_MB")] |
||||
|
[DataMember] |
||||
|
[Required(ErrorMessage = "{0},不能空白")] |
||||
|
[Display(Name = "組件MB")] |
||||
|
public string KPMb { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件MAC
|
||||
|
/// </summary>
|
||||
|
[Column("KP_MAC")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "組件MAC")] |
||||
|
public string KPMac { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 組件Panel
|
||||
|
/// </summary>
|
||||
|
[Column("KP_PANEL")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "組件Panel")] |
||||
|
public string KPPanel { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立者
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "建立者")] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立日期
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
[Display(Name = "建立日期")] |
||||
|
public DateTime CreateDate { get; set; } = DateTime.Now; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue