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 { /// /// /// [Route("api/[controller]")] [ApiController] public class WipLockController : Controller { private readonly AMESContext _context; /// /// /// /// public WipLockController(AMESContext context) { _context = context; } /// /// 工單鎖定資料 /// /// [HttpGet] public async Task>> GetWipLock() { IQueryable q = _context.WipLocks; q = q.OrderBy(p => p.WipNO); var WipLock = await q.ToListAsync(); return WipLock; } /// /// 工單鎖定資料 to WipNO /// /// 工單編號 /// // GET: api/RolePrograms/5 [HttpGet("{id}")] public async Task>> GetWipLock(string WipNO) { IQueryable q = _context.WipLocks; q = q.Where(p => p.WipNO == WipNO); var WipLock = await q.ToListAsync(); if (WipLock == null) { return NotFound(); } return WipLock; } /// /// 製程工單鎖定查詢 /// /// 工單 /// 工單狀態 /// 鎖定類型 /// 料號 /// 鎖定原因類別 /// 站別 /// 鎖定日期起 /// 鎖定日期迄 /// [Route("[action]")] [HttpGet] public async Task> GetWipLockQuery(string wipNO, string lockstatus, string locktype , string itemno, string lockreasontype, int stationid = 0, string date_str = null, string date_end = null) { IQueryable 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 result = new ResultModel(); result.Data = await q.ToListAsync(); return result; } /// /// 新增工單鎖定資料檔 /// /// /// [HttpPost] public async Task> PostWipLock([FromBody] WipLock wiplock) { ResultModel result = new ResultModel(); 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; } } }