You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.5 KiB
145 lines
4.5 KiB
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using AMESCoreStudio.WebApi.Models.AMES;
|
|
using AMESCoreStudio.CommonTools.Result;
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class WipLockController : Controller
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public WipLockController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工單鎖定資料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<WipLock>>> GetWipLock()
|
|
{
|
|
IQueryable<WipLock> q = _context.WipLocks;
|
|
q = q.OrderBy(p => p.WipNO);
|
|
var WipLock = await q.ToListAsync();
|
|
return WipLock;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工單鎖定資料 to WipNO
|
|
/// </summary>
|
|
/// <param name="WipNO">工單編號</param>
|
|
/// <returns></returns>
|
|
// GET: api/RolePrograms/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<IEnumerable<WipLock>>> GetWipLock(string WipNO)
|
|
{
|
|
IQueryable<WipLock> q = _context.WipLocks;
|
|
|
|
q = q.Where(p => p.WipNO == WipNO);
|
|
|
|
var WipLock = await q.ToListAsync();
|
|
|
|
if (WipLock == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return WipLock;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 製程工單鎖定查詢
|
|
/// </summary>
|
|
/// <param name="wipNO">工單</param>
|
|
/// <param name="lockstatus">工單狀態</param>
|
|
/// <param name="locktype">鎖定類型</param>
|
|
/// <param name="itemno">料號</param>
|
|
/// <param name="lockreasontype">鎖定原因類別</param>
|
|
/// <param name="stationid">站別</param>
|
|
/// <param name="date_str">鎖定日期起</param>
|
|
/// <param name="date_end">鎖定日期迄</param>
|
|
/// <returns></returns>
|
|
[Route("[action]")]
|
|
[HttpGet]
|
|
public async Task<ResultModel<WipLock>> GetWipLockQuery(string wipNO, string lockstatus, string locktype
|
|
, string itemno, string lockreasontype, int stationid = 0, string date_str = null, string date_end = null)
|
|
{
|
|
IQueryable<WipLock> q = _context.WipLocks;
|
|
|
|
if (!string.IsNullOrWhiteSpace(wipNO))
|
|
q = q.Where(w => w.WipNO == wipNO);
|
|
|
|
if (!string.IsNullOrWhiteSpace(lockstatus))
|
|
q = q.Where(w => w.LockStatus == lockstatus);
|
|
|
|
if (!string.IsNullOrWhiteSpace(locktype))
|
|
q = q.Where(w => w.LockType == locktype);
|
|
|
|
if (!string.IsNullOrWhiteSpace(lockreasontype))
|
|
q = q.Where(w => w.LockReasonType == lockreasontype);
|
|
|
|
if (stationid != 0)
|
|
q = q.Where(w => w.StationID == stationid);
|
|
|
|
DateTime dateValue;
|
|
if (DateTime.TryParse(date_str, out dateValue))
|
|
{
|
|
q = q.Where(w => w.LockDate >= DateTime.Parse(date_str));
|
|
}
|
|
|
|
if (DateTime.TryParse(date_end, out dateValue))
|
|
{
|
|
q = q.Where(w => w.LockDate <= DateTime.Parse(date_end));
|
|
}
|
|
ResultModel<WipLock> result = new ResultModel<WipLock>();
|
|
result.Data = await q.ToListAsync();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增工單鎖定資料檔
|
|
/// </summary>
|
|
/// <param name="wiplock"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<ResultModel<WipLock>> PostWipLock([FromBody] WipLock wiplock)
|
|
{
|
|
ResultModel<WipLock> result = new ResultModel<WipLock>();
|
|
Helper helper = new Helper(_context);
|
|
wiplock.WipLockID = helper.GetIDKey("WIP_LOCK_ID").Result;
|
|
wiplock.UnLockUserID = 0;
|
|
|
|
_context.WipLocks.Add(wiplock);
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Success = false;
|
|
result.Msg = ex.Message;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|