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.
207 lines
6.1 KiB
207 lines
6.1 KiB
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 ProductionIndexesController : ControllerBase
|
|
{
|
|
private readonly AMESContext _context;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public ProductionIndexesController(AMESContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/ProductionIndexes
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<ProductionIndex>>> GetProductionIndex()
|
|
{
|
|
return await _context.ProductionIndexes.ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sdate"></param>
|
|
/// <param name="edate"></param>
|
|
/// <returns></returns>
|
|
[Route("[action]")]
|
|
[HttpGet]
|
|
public async Task<ResultModel<dynamic>> GetProductionIndex4RPT001(string sdate, string edate)
|
|
{
|
|
ResultModel<dynamic> result = new ResultModel<dynamic>();
|
|
var q = from q1 in _context.ProductionIndexes
|
|
select new
|
|
{
|
|
q1.ProductionID,
|
|
q1.ProductionDate,
|
|
q1.EA,
|
|
q1.EATime,
|
|
q1.AATime,
|
|
q1.ActualTime,
|
|
q1.OverTime,
|
|
q1.InvalidTime,
|
|
q1.Productivity,
|
|
q1.Efficiency,
|
|
q1.Attendance
|
|
|
|
};
|
|
DateTime dateValue;
|
|
if (sdate != "*")
|
|
{
|
|
|
|
if (DateTime.TryParse(sdate, out dateValue))
|
|
{
|
|
q = q.Where(p => p.ProductionDate >= DateTime.Parse(sdate));
|
|
}
|
|
}
|
|
if (edate != "*")
|
|
{
|
|
if (DateTime.TryParse(edate, out dateValue))
|
|
{
|
|
q = q.Where(p => p.ProductionDate <= DateTime.Parse(edate));
|
|
}
|
|
|
|
}
|
|
|
|
q = q.OrderBy(p => p.ProductionDate);
|
|
|
|
//紀錄筆數
|
|
result.DataTotal = q.Count();
|
|
|
|
result.Data = await q.ToListAsync();
|
|
|
|
if (result == null)
|
|
{
|
|
result.Msg = "查無資料";
|
|
result.Success = false;
|
|
return result;
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Msg = "OK";
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
// GET: api/ProductionIndexes/5
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<ProductionIndex>> GetProductionIndex(int id)
|
|
{
|
|
var productionIndex = await _context.ProductionIndexes.FindAsync(id);
|
|
|
|
if (productionIndex == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return productionIndex;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="productionIndex"></param>
|
|
/// <returns></returns>
|
|
// PUT: api/ProductionIndexes/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> PutProductionIndex(int id, ProductionIndex productionIndex)
|
|
{
|
|
if (id != productionIndex.ProductionID)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
_context.Entry(productionIndex).State = EntityState.Modified;
|
|
|
|
try
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch (DbUpdateConcurrencyException)
|
|
{
|
|
if (!ProductionIndexExists(id))
|
|
{
|
|
return NotFound();
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="productionIndex"></param>
|
|
/// <returns></returns>
|
|
// POST: api/ProductionIndexes
|
|
// 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<ProductionIndex>> PostProductionIndex(ProductionIndex productionIndex)
|
|
{
|
|
_context.ProductionIndexes.Add(productionIndex);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return CreatedAtAction("GetProductionIndex", new { id = productionIndex.ProductionID }, productionIndex);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
// DELETE: api/ProductionIndexes/5
|
|
[HttpDelete("{id}")]
|
|
public async Task<ActionResult<ProductionIndex>> DeleteProductionIndex(int id)
|
|
{
|
|
var productionIndex = await _context.ProductionIndexes.FindAsync(id);
|
|
if (productionIndex == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
_context.ProductionIndexes.Remove(productionIndex);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return productionIndex;
|
|
}
|
|
|
|
private bool ProductionIndexExists(int id)
|
|
{
|
|
return _context.ProductionIndexes.Any(e => e.ProductionID == id);
|
|
}
|
|
}
|
|
}
|
|
|