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.
3924 lines
126 KiB
3924 lines
126 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using AMESCoreStudio.Web.Models;
|
|
using Newtonsoft.Json;
|
|
using AMESCoreStudio.WebApi;
|
|
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using AMESCoreStudio.WebApi.Models.AMES;
|
|
using AMESCoreStudio.WebApi.Models.BAS;
|
|
using AMESCoreStudio.CommonTools.Result;
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.IO;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using ClosedXML.Excel;
|
|
using System;
|
|
using AMESCoreStudio.Web.ViewModels.WHS;
|
|
|
|
namespace AMESCoreStudio.Web.Controllers
|
|
{
|
|
public class WHSController : Controller
|
|
{
|
|
private readonly ILogger<WHSController> _logger;
|
|
public readonly IWHS _whsApi;
|
|
public readonly IBAS _basApi;
|
|
public readonly IPCS _pcsApi;
|
|
public readonly ISYS _sysApi;
|
|
public readonly IPPS _ppsApi;
|
|
private readonly IWebHostEnvironment _env;
|
|
|
|
public WHSController(ILogger<WHSController> logger, IWHS whsApi,IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi,IWebHostEnvironment env)
|
|
{
|
|
_logger = logger;
|
|
_whsApi = whsApi;
|
|
_basApi = basApi;
|
|
_pcsApi = pcsApi;
|
|
_sysApi = sysApi;
|
|
_ppsApi = ppsApi;
|
|
_env = env;
|
|
}
|
|
|
|
#region
|
|
private void GetFlagList()
|
|
{
|
|
|
|
var FlagList = new List<SelectListItem>();
|
|
|
|
|
|
FlagList.Add(new SelectListItem("Y", "Y"));
|
|
FlagList.Add(new SelectListItem("N", "N"));
|
|
|
|
ViewBag.FlagList = FlagList;
|
|
}
|
|
|
|
|
|
private async Task GetWorkGroupsList()
|
|
{
|
|
var result = await _whsApi.GetWorkGroups();
|
|
|
|
var GroupList = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
GroupList.Add(new SelectListItem(result[i].GroupName, result[i].GroupID.ToString()));
|
|
}
|
|
ViewBag.GroupList = GroupList;
|
|
}
|
|
private async Task GetWorkClassList()
|
|
{
|
|
var result = await _whsApi.GetWorkClasses();
|
|
|
|
var GroupList = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
GroupList.Add(new SelectListItem(result[i].ClassName, result[i].ClassID.ToString()));
|
|
}
|
|
ViewBag.WClassList = GroupList;
|
|
}
|
|
private async Task GetFactoryUnitsList()
|
|
{
|
|
var result = await _basApi.GetFactoryUnits();
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
UnitItems.Add(new SelectListItem("全部", "0"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString()));
|
|
}
|
|
ViewBag.FactoryUnit = UnitItems;
|
|
}
|
|
private async Task GetFactoryUnitsList2()
|
|
{
|
|
var result = await _basApi.GetFactoryUnits();
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString()));
|
|
}
|
|
UnitItems.Add(new SelectListItem("其他", "0"));
|
|
|
|
ViewBag.FactoryUnit = UnitItems;
|
|
}
|
|
private async Task GetFactoryUnitsList3()
|
|
{
|
|
var result = await _basApi.GetFactoryUnits();
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
|
|
UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString()));
|
|
}
|
|
ViewBag.FactoryUnit = UnitItems;
|
|
}
|
|
private async Task GetFactoryList()
|
|
{
|
|
var result = await _basApi.GetFactoryInfoes();
|
|
|
|
var FactoryItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
if (result[i].StatusNo == "A") //yiru add 2022-10-11
|
|
FactoryItems.Add(new SelectListItem(result[i].FactoryNameCh, result[i].FactoryID.ToString()));
|
|
}
|
|
ViewBag.FactoryList = FactoryItems;
|
|
}
|
|
private async Task GetStationList()
|
|
{
|
|
var result = await _basApi.GetStationses();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
StationItems.Add( new SelectListItem("N/A", "-1"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString()));
|
|
}
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
|
|
|
|
private async Task GetLineList()
|
|
{
|
|
var result = await _basApi.GetLineInfoes();
|
|
|
|
var LineItems = new List<SelectListItem>();
|
|
LineItems.Add( new SelectListItem("N/A", "0"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
LineItems.Add(new SelectListItem(result[i].LineDesc , result[i].LineID.ToString()));
|
|
}
|
|
ViewBag.LineList = LineItems;
|
|
}
|
|
private async Task GetLineList2()
|
|
{
|
|
var result = await _basApi.GetLineInfoes();
|
|
|
|
var LineItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
LineItems.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString()));
|
|
}
|
|
ViewBag.LineList = LineItems;
|
|
}
|
|
private async Task GetDeptList()
|
|
{
|
|
var result = await _sysApi.GetDeptInfoes();
|
|
|
|
var DeptItems = new List<SelectListItem>();
|
|
DeptItems.Add(new SelectListItem("N/A", "0"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
DeptItems.Add(new SelectListItem(result[i].DeptName, result[i].DeptID.ToString()));
|
|
}
|
|
ViewBag.DeptList = DeptItems;
|
|
}
|
|
private async Task GetDeptList2()
|
|
{
|
|
var result = await _sysApi.GetDeptInfoes();
|
|
|
|
var DeptItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
DeptItems.Add(new SelectListItem(result[i].DeptName, result[i].DeptID.ToString()));
|
|
}
|
|
ViewBag.DeptList = DeptItems;
|
|
}
|
|
private void GetSideList()
|
|
{
|
|
|
|
var SideItems = new List<SelectListItem>() ;
|
|
SideItems.Add(new SelectListItem("N/A", "N/A"));
|
|
SideItems.Add(new SelectListItem("正面", "正面"));
|
|
SideItems.Add(new SelectListItem("背面", "背面"));
|
|
|
|
ViewBag.SideList = SideItems;
|
|
}
|
|
private void GetClassList()
|
|
{
|
|
|
|
var ClassItems = new List<SelectListItem>();
|
|
ClassItems.Add(new SelectListItem("白班", "1"));
|
|
ClassItems.Add(new SelectListItem("夜班", "2"));
|
|
|
|
ViewBag.ClassList = ClassItems;
|
|
}
|
|
private async Task GetStationListByUnit(string unit)
|
|
{
|
|
var result = await _basApi.GetStationses();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
StationItems.Add(new SelectListItem("N/A", "0"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
if(result[i].UnitNo==unit)
|
|
StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString()));
|
|
}
|
|
if(StationItems.Count==0)
|
|
StationItems.Add(new SelectListItem("N/A", ""));
|
|
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
private async Task GetExceptionClassesList()
|
|
{
|
|
var result = await _whsApi.GetExceptionClasses();
|
|
|
|
var ExceptionClasses = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
ExceptionClasses.Add(new SelectListItem(result[i].ExceptionClassName, result[i].ExceptionClassNo));
|
|
}
|
|
|
|
ViewBag.ExceptionClasses = ExceptionClasses;
|
|
}
|
|
private async Task GetExceptionCodesList()
|
|
{
|
|
var result = await _whsApi.GetExceptionCodes();
|
|
|
|
var GetExceptionCodes = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
GetExceptionCodes.Add(new SelectListItem(result[i].ExceptionDescCH, result[i].ExceptionNo));
|
|
}
|
|
|
|
ViewBag.ExceptionCodes = GetExceptionCodes;
|
|
}
|
|
private async Task GetStationList2()
|
|
{
|
|
var result = await _basApi.GetStationses();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString()));
|
|
}
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
|
|
private async Task GetExceptionReasonList()
|
|
{
|
|
var result = await _whsApi.GetExceptionReasons();
|
|
|
|
var GetExceptionReasons = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
GetExceptionReasons.Add(new SelectListItem(result[i].ReasonDescCH, result[i].ReasonNo));
|
|
}
|
|
|
|
ViewBag.ExceptionReasons = GetExceptionReasons;
|
|
}
|
|
|
|
|
|
private async Task GetUserInfo()
|
|
{
|
|
var result = await _sysApi.GetUserInfoes();
|
|
|
|
var UserItems = new List<SelectListItem>();
|
|
foreach (var item in result.Data)
|
|
{
|
|
UserItems.Add(new SelectListItem(item.UserName, item.UserID.ToString()));
|
|
}
|
|
ViewBag.UserList = UserItems;
|
|
}
|
|
#endregion
|
|
|
|
#region WHS001工作群組維護相關
|
|
|
|
public IActionResult WHS001()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public IActionResult WHS001C()
|
|
{
|
|
GetFlagList();
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS001UAsync(int id)
|
|
{
|
|
GetFlagList();
|
|
var result = await _whsApi.GetWorkGroups(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS001DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkGroups(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS001CSaveAsync(WorkGroup model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkGroups(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success) //yiru modify 2022-09-27
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS001C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS001USaveAsync(WorkGroup model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkGroups(model.GroupID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success) //yiru modify 2022 - 09 - 27
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS001U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkGroupsAsync()
|
|
{
|
|
var result = await _whsApi.GetWorkGroups();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS002條碼狀態維護相關
|
|
|
|
public IActionResult WHS002()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS002C()
|
|
{
|
|
await GetWorkGroupsList();
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS002UAsync(int id)
|
|
{
|
|
await GetWorkGroupsList();
|
|
var result = await _whsApi.GetWorkClasses(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS002DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkClass(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS002CSaveAsync(WorkClass model)
|
|
{
|
|
if (ModelState.IsValid) //yiru modify 2022-09-27
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkClass(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success) //yiru modify 2022-09-27
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS002C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS002USaveAsync(WorkClass model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkClass(model.ClassID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success) //yiru modify 2022-09-27
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS002U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkClassesAsync()
|
|
{
|
|
var result = await _whsApi.GetWorkClasses();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS003/WHS005標準工時維護相關
|
|
public async Task<IActionResult> WHS003()
|
|
{
|
|
await GetFactoryUnitsList();
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS003C()
|
|
{
|
|
// await GetStationListByUnit(unit);
|
|
await GetFactoryUnitsList();
|
|
// var result = await _basApi.GetFactoryUnit(unit);
|
|
//await GetMFGType();
|
|
// ViewBag.LineID = lineID;
|
|
// ViewBag.UnitNo = unit;
|
|
// ViewBag.FactoryU = result[0].UnitName;
|
|
GetSideList();
|
|
await GetStation4WHS019C();
|
|
|
|
return View();
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS003UAsync(int id)
|
|
{
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
GetSideList();
|
|
var result = await _whsApi.GetStandardWorkTime(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS003DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteStandardWorkTime(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS003CSaveAsync(StandardWorkTime model)
|
|
{
|
|
if (ModelState.IsValid) //yiru modify 2022-09-27
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostStandardWorkTime(JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS003C", model);
|
|
}
|
|
public async Task<IActionResult> WHS003USaveAsync(StandardWorkTime model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutStandardWorkTime(model.StandardID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS003U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetStandardWorkTimesAsync()
|
|
{
|
|
var result = await _whsApi.GetStandardWorkTimes();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetStandardWorkTimes2Async(string u,int l,string i)
|
|
{
|
|
if (l == 0) //yiru modify 2022-10-04
|
|
{
|
|
l = -99;
|
|
}
|
|
|
|
// return Json(new Table() { count = 0, data = null });
|
|
/*
|
|
if (string.IsNullOrEmpty(i)) //若沒輸入料號查詢 就不帶出資料
|
|
return Json(new Table() { count = 0, data = null });
|
|
*/
|
|
if (string.IsNullOrEmpty(i))
|
|
{
|
|
i = "Null";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(u))
|
|
{
|
|
u = "Null";
|
|
}
|
|
|
|
if (u == "0")
|
|
{
|
|
u = "Null";
|
|
}
|
|
|
|
var result = await _whsApi.GetStandardWorkTimes003(u,l,i);
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
public async Task<IActionResult> WHS005()
|
|
{
|
|
await GetFactoryUnitsList();
|
|
return View();
|
|
}
|
|
public async Task<IActionResult> GetStandardWorkTimes005Async(string u, string l, string i)
|
|
{
|
|
if (string.IsNullOrEmpty(l))
|
|
return Json(new Table() { count = 0, data = null });
|
|
if (string.IsNullOrEmpty(i))
|
|
i = "Null";
|
|
if (string.IsNullOrEmpty(u) || u=="0")
|
|
u = "Null";
|
|
|
|
var result = await _whsApi.GetStandardWorkTimes005(u, l, i);
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS006每日工時資料維護相關
|
|
|
|
public async Task<IActionResult> WHS006()
|
|
{
|
|
//廠別
|
|
await GetFactoryList();
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//部門
|
|
await GetDeptList2();
|
|
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS006C()
|
|
{
|
|
|
|
//廠別
|
|
await GetFactoryList();
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//線別
|
|
//await GetLineList2();
|
|
//站別
|
|
//await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS006UAsync(int id)
|
|
{
|
|
//廠別
|
|
await GetFactoryList();
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
var result = await _whsApi.GetWorkManPower(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS006DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkManPower(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS006CSaveAsync(WorkManPower model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkManPower(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS006C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS006USaveAsync(WorkManPower model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkManPower(model.PowerID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS006U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkManPowersByQueryAsync(string fid, string uid, string lid, string cID, string sID, string uNo, string dID, string sd, string ed)
|
|
{
|
|
if (fid == null)
|
|
{
|
|
fid = "*";
|
|
}
|
|
if (uid == null)
|
|
{
|
|
uid = "*";
|
|
}
|
|
if (lid == null)
|
|
{
|
|
lid = "*";
|
|
}
|
|
if (cID == null)
|
|
{
|
|
cID = "*";
|
|
}
|
|
if (sID == null)
|
|
{
|
|
sID = "*";
|
|
}
|
|
if (uNo == null)
|
|
{
|
|
uNo = "*";
|
|
}
|
|
if (dID == null)
|
|
{
|
|
dID = "*";
|
|
}
|
|
if (sd == null)
|
|
{
|
|
sd = System.DateTime.Now.AddDays(-1).ToString();
|
|
}
|
|
if (ed == null )
|
|
{
|
|
ed = System.DateTime.Now.ToString();
|
|
}
|
|
|
|
//var result = await _whsApi.GetWorkManPowersByQuery( factoryid, unitid, lineid, classID, stationID, userNo, sdate, edate);
|
|
var result = await _whsApi.GetWorkManPowersByQuery(fid, uid, lid, cID, sID, uNo , dID, sd, ed);
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS008工時援入/外維護相關
|
|
|
|
public async Task<IActionResult> WHS008()
|
|
{
|
|
await GetFactoryUnitsList2();
|
|
await GetFactoryList();
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS008C()
|
|
{
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//其他部門
|
|
await GetDeptList();
|
|
|
|
var user_id = Request.Cookies["UserID"];
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
|
|
SupportUser model = new SupportUser();
|
|
model.UserNo = user_info[0].UserNo;
|
|
model.UserNane = user_info[0].UserName;
|
|
|
|
return View(model);
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS008UAsync(int id,string type)
|
|
{
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//其他部門
|
|
await GetDeptList();
|
|
ViewBag.type = type;
|
|
|
|
var result = await _whsApi.GetSupportUser(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS008DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteSupportUser(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS008CSaveAsync(SupportUser model)
|
|
{
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//其他部門
|
|
await GetDeptList();
|
|
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
var Msg = string.Empty;
|
|
if (model.UnitNoI != "0")
|
|
{
|
|
if (model.StationIDI == -1)
|
|
{
|
|
//Msg += "請選擇援入站別\r\n";
|
|
}
|
|
if (model.LineIDI == 0)
|
|
{
|
|
//Msg += "請選擇援入線別\r\n";
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (model.OtherDeptI == "0")
|
|
{
|
|
Msg += "請選擇援入其他部門\r\n";
|
|
}
|
|
|
|
}
|
|
|
|
if (model.UnitNoO != "0")
|
|
{
|
|
if (model.StationIDO == -1)
|
|
{
|
|
//Msg += "請選擇援出站別\r\n";
|
|
}
|
|
if (model.LineIDO == 0)
|
|
{
|
|
//Msg += "請選擇援出線別\r\n";
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (model.OtherDeptO == "0")
|
|
{
|
|
Msg += "請選擇援出其他部門\r\n";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Msg))
|
|
{
|
|
|
|
|
|
|
|
ModelState.AddModelError("error", Msg);
|
|
return View("WHS008C",model);
|
|
}
|
|
else
|
|
{
|
|
IResultModel result;
|
|
result = await _whsApi.PostSupportUser(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return View("WHS008C", model);
|
|
}
|
|
public async Task<IActionResult> WHS008USaveAsync(SupportUser model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutSupportUser(model.SupportID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS008U", model);
|
|
}
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetSupportUsersAsync()
|
|
{
|
|
var result = await _whsApi.GetSupportUsers();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
public async Task<IActionResult> GetSupportUser2Async(string f, string type, string unit, string sd, string ed)
|
|
{
|
|
|
|
var result = await _whsApi.GetSupportUserByQuery( f,type, unit, sd, ed);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS009異常工時維護相關
|
|
|
|
public async Task<IActionResult> WHS009()
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//判定單位
|
|
await GetDeptList2();
|
|
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS009C()
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList();
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
//負責人
|
|
//內部/外部
|
|
//EXCEPTION_Class
|
|
//EXCEPTION_CODE
|
|
await GetExceptionReasonList();
|
|
|
|
return View();
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS009UAsync(string id)
|
|
{
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList();
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
//班別
|
|
GetClassList();
|
|
//其他部門
|
|
await GetDeptList();
|
|
|
|
await GetExceptionClassesList();
|
|
|
|
await GetExceptionCodesList();
|
|
|
|
await GetExceptionReasonList();
|
|
|
|
await GetUserInfo();
|
|
|
|
|
|
var result = await _whsApi.GetExceptionWorktime(id);
|
|
var result2 = await _whsApi.GetExceptionCode(result[0].ExceptionNo);
|
|
ViewBag.ClassNo = result2[0].ExceptionClassNo;
|
|
var result3 = await _whsApi.GetExceptionClass(result2[0].ExceptionClassNo);
|
|
ViewBag.GroupNo = result3[0].ExceptionGroupNo;
|
|
|
|
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS009DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteSupportUser(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS009CSaveAsync(ExceptionWorktime model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
if (model.PersonNo != null)
|
|
{
|
|
var Reasons = await _whsApi.GetExceptionReason(model.PersonNo);
|
|
model.ReasonNameCh = Reasons[0].ReasonDescCH;
|
|
}
|
|
if (model.Measure != null)
|
|
{
|
|
model.MeasureDate = System.DateTime.Now;
|
|
}
|
|
|
|
|
|
result = await _whsApi.PostExceptionWorktime(JsonConvert.SerializeObject(model)); //yiru modify 2022-10-04
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS009C", model);
|
|
}
|
|
public async Task<IActionResult> WHS009USaveAsync(ExceptionWorktime model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutExceptionWorktime(model.ExceptionID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
await GetExceptionClassesList();
|
|
|
|
await GetExceptionCodesList();
|
|
|
|
var result2 = await _whsApi.GetExceptionCode(model.ExceptionNo);
|
|
ViewBag.ClassNo = result2[0].ExceptionClassNo;
|
|
var result3 = await _whsApi.GetExceptionClass(result2[0].ExceptionClassNo);
|
|
ViewBag.GroupNo = result3[0].ExceptionGroupNo;
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS009U", model);
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> WHS009R(int id)
|
|
{
|
|
ViewBag.ExceptionWorktimeID = id;
|
|
|
|
return View();
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> WHS009RSaveAsync(ExceptionWorktimeBlob model, IFormFile formFile)
|
|
{
|
|
IResultModel result;
|
|
var userID = "";
|
|
HttpContext.Request.Cookies.TryGetValue("UserID", out userID);
|
|
int user_id = 0;
|
|
if (userID != null)
|
|
{
|
|
if (int.Parse(userID.ToString()) >= 0)
|
|
{
|
|
user_id = int.Parse(userID.ToString());
|
|
}
|
|
}
|
|
model.CreateUserID = user_id;
|
|
model.CreateDate = System.DateTime.Now;
|
|
model.UpdateUserID = user_id;
|
|
model.UpdateDate = System.DateTime.Now;
|
|
string FileName = string.Empty;
|
|
string NewName = string.Empty;
|
|
string FilePath = string.Empty;
|
|
|
|
|
|
if (formFile != null)
|
|
{
|
|
if (formFile.Length > 0)
|
|
{
|
|
//取得使用者上傳檔案的原始檔名
|
|
FileName = Path.GetFileName(formFile.FileName);
|
|
//取原始檔名中的副檔名
|
|
var fileExt = Path.GetExtension(FileName);
|
|
//為避免使用者上傳的檔案名稱發生重複,重新給一個亂數名稱
|
|
NewName = Path.GetRandomFileName() + fileExt;
|
|
//指定要寫入的路徑、檔名和副檔名
|
|
FilePath = $"\\WHSFile\\";//本機目錄
|
|
|
|
if (!System.IO.Directory.Exists(_env.WebRootPath + FilePath))
|
|
{
|
|
System.IO.Directory.CreateDirectory(_env.WebRootPath + FilePath);
|
|
}
|
|
|
|
using (var stream = new FileStream(_env.WebRootPath + FilePath + NewName, FileMode.Create))
|
|
{
|
|
await formFile.CopyToAsync(stream);
|
|
}
|
|
|
|
//var fileProvider = _fileServerProvider.GetProvider("/aa");
|
|
//var fileInfo = fileProvider.GetFileInfo(formFile.FileName);
|
|
//fileInfo = fileProvider.GetFileInfo(formFile.FileName);
|
|
////遠端目錄
|
|
//using (var stream = new FileStream(fileInfo.PhysicalPath, FileMode.Create))
|
|
//{
|
|
// await formFile.CopyToAsync(stream);
|
|
|
|
model.ImageName = NewName;
|
|
|
|
model.FilePath = FilePath;// fileInfo.PhysicalPath;
|
|
|
|
result = await _whsApi.PostExceptionWorktimeBlobs(JsonConvert.SerializeObject(model));
|
|
if (result.Success)
|
|
{
|
|
//var _msg = "上傳成功!";
|
|
ViewBag.ExceptionWorktimeID = model.ExceptionWorktimeID;
|
|
|
|
return View("WHS009R");
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", "請選擇要上傳檔案");
|
|
}
|
|
|
|
|
|
ViewBag.ExceptionWorktimeID = model.ExceptionWorktimeID;
|
|
|
|
|
|
return View("WHS009R");
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> GetExceptionWorktimeBlobsByQueryAsync(int id)
|
|
{
|
|
if (id == 0)
|
|
return Json(new Table() { count = 0, data = null });
|
|
|
|
var result = await _whsApi.GetExceptionWorktimeBlobs(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionWorktimeByQueryAsync(string factoryNo, string unitNo, string lineID, string deptID, string sdate, string edate)
|
|
{
|
|
if (factoryNo == null)
|
|
{
|
|
//factoryNo = "*";
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineID == null)
|
|
{
|
|
lineID = "*";
|
|
}
|
|
if (deptID == null)
|
|
{
|
|
deptID = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
|
|
|
|
var result = await _whsApi.GetExceptionWorktimeByQueryWHS009(factoryNo, unitNo, lineID, deptID, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
public async Task<IActionResult> GetExceptionWorktimeByQueryAndBlobAsync(string factoryNo, string unitNo, string lineID, string deptID, string sdate, string edate)
|
|
{
|
|
if (factoryNo == null)
|
|
{
|
|
//factoryNo = "*";
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineID == null)
|
|
{
|
|
lineID = "*";
|
|
}
|
|
if (deptID == null)
|
|
{
|
|
deptID = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
|
|
|
|
var result = await _whsApi.GetExceptionWorktimeByQueryWHS009(factoryNo, unitNo, lineID, deptID, sdate, edate);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
foreach (var item in result)
|
|
{
|
|
var Bolbresult = await _whsApi.GetExceptionWorktimeBlobs(item.ExceptionID );
|
|
item.StationID = Bolbresult.Count;
|
|
|
|
}
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
|
|
}
|
|
|
|
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> GetWipAttAsync(string id)
|
|
{
|
|
|
|
var result = await _pcsApi.GetWipAtt(id);
|
|
|
|
|
|
if (result != null)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = 1 });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
public async Task<IActionResult> GetCountTimesAsync(string id)
|
|
{
|
|
string sTime, eTime;
|
|
var timeArr = id.Split("%");
|
|
sTime = timeArr[0];
|
|
eTime = timeArr[1];
|
|
sTime = sTime.Replace("T", " ");
|
|
eTime = eTime.Replace("T", " ");
|
|
System.DateTime dateValue1, dateValue2;
|
|
var result = 0.0;
|
|
if (System.DateTime.TryParse(sTime, out dateValue1) && System.DateTime.TryParse(eTime, out dateValue2))
|
|
{
|
|
if (dateValue2 < dateValue1)
|
|
{
|
|
return Json(new Table() { count = 0, msg = "起始時間大於結束時間!!!", data = null });
|
|
}
|
|
else
|
|
{
|
|
result = new System.TimeSpan(dateValue2.Ticks - dateValue1.Ticks).TotalMinutes;
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = 1 });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return Json(new Table() { count = 0, msg = "時間格是有誤!!", data = null });
|
|
|
|
}
|
|
|
|
#region old
|
|
//var timeArr = id.Split(":");
|
|
//sHour = timeArr[0];
|
|
//sMin = timeArr[1];
|
|
//eHour = timeArr[2];
|
|
//eMin = timeArr[3];
|
|
|
|
//string sHour, sMin, eHour, eMin;
|
|
//var timeArr = id.Split(":");
|
|
//sHour = timeArr[0];
|
|
//sMin = timeArr[1];
|
|
//eHour = timeArr[2];
|
|
//eMin = timeArr[3];
|
|
|
|
|
|
// int dateValue,hour=0,min=0;
|
|
|
|
// if (int.TryParse(sHour, out dateValue) && int.TryParse(eHour, out dateValue) && int.TryParse(sMin, out dateValue) && int.TryParse(eMin, out dateValue))
|
|
// {
|
|
// if (int.Parse(eHour) > int.Parse(sHour))
|
|
// {
|
|
// hour = int.Parse(eHour) - int.Parse(sHour) - 1;
|
|
|
|
// min = (60 - int.Parse(sMin)) + int.Parse(eMin);
|
|
|
|
// }
|
|
// else if (int.Parse(eHour) == int.Parse(sHour))
|
|
// {
|
|
// hour = 0;
|
|
// if (int.Parse(sMin) >= int.Parse(sHour))
|
|
// {
|
|
// return Json(new Table() { count = 0, data = null });
|
|
// }
|
|
// else
|
|
// {
|
|
// min = (60 - int.Parse(sMin)) + int.Parse(eMin);
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// return Json(new Table() { count = 0, data = null });
|
|
// }
|
|
// }
|
|
// else {
|
|
|
|
// return Json(new Table() { count = 0, data = null });
|
|
// }
|
|
|
|
// var result =hour*60+min;
|
|
|
|
//return Json(new Table() { code = 0, msg = "", data = result, count = 1 });
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> GetExceptionReasonsByExceptionNoAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionReason(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
#endregion
|
|
|
|
#region WHS011重工標準工時維護相關
|
|
|
|
public async Task<IActionResult> WHS011()
|
|
{
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C2();
|
|
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS011C()
|
|
{
|
|
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C2();
|
|
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS011UAsync(int id)
|
|
{
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C2();
|
|
|
|
var result = await _whsApi.GetStandardWorkTimeRework(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS011DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteStandardWorkTimeRework(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS011CSaveAsync(StandardWorkTimeRework model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostStandardWorkTimeRework(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS011C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS011USaveAsync(StandardWorkTimeRework model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutStandardWorkTimeRework(model.ReworkStandardID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS011U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetStandardWorkTimeReworkByQueryAsync(string wipno, int sid)
|
|
{
|
|
if (wipno == null || wipno == "0")
|
|
{
|
|
wipno = "*";
|
|
}
|
|
|
|
var result = await _whsApi.GetStandardWorkTimeReworkByQuery(wipno, sid);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS013線上無效工時查詢
|
|
|
|
public async Task<IActionResult> WHS013()
|
|
{
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//判定單位
|
|
await GetDeptList2();
|
|
|
|
return View();
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionWorktimeOlineByQueryAsync(string factoryid, string unitid, string lineid, string deptid, string sdate, string edate)
|
|
{
|
|
if (factoryid == null )
|
|
{
|
|
factoryid = "*";
|
|
}
|
|
if (unitid == null)
|
|
{
|
|
unitid = "*";
|
|
}
|
|
if (lineid == null)
|
|
{
|
|
lineid = "*";
|
|
}
|
|
if (deptid == null)
|
|
{
|
|
deptid = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
|
|
|
|
var result = await _whsApi.GetExceptionWorktimeOlineByQuery(factoryid, unitid, lineid, deptid, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region WHS014 異常工時類別維護相關
|
|
|
|
public IActionResult WHS014()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public IActionResult WHS014C()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS014UAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionClass(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS014DAsync(string id)
|
|
{
|
|
var result = await _whsApi.DeleteExceptionClass(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS014CSaveAsync(ExceptionClass model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostExceptionClass(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS014C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS014USaveAsync(ExceptionClass model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutExceptionClass(model.ExceptionClassNo, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS014U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionClassesAsync()
|
|
{
|
|
var result = await _whsApi.GetExceptionClasses();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionClassesByQureyAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionClassesByGroup(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS015 異常工時代碼維護相關
|
|
|
|
public IActionResult WHS015()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS015C()
|
|
{
|
|
|
|
await GetExceptionClassesList();
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS015UAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionCode(id);
|
|
var result2 = await _whsApi.GetExceptionClass(result[0].ExceptionClassNo);
|
|
await GetExceptionClassesList();
|
|
ViewBag.ExceptionGroupNo = result2[0].ExceptionGroupNo;
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS015DAsync(string id)
|
|
{
|
|
var result = await _whsApi.DeleteExceptionCode(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS015CSaveAsync(ExceptionCode model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostExceptionCode(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS015C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS015USaveAsync(ExceptionCode model)
|
|
{
|
|
var value = ViewBag.ExceptionGroupNo;
|
|
await GetExceptionClassesList();
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutExceptionCode(model.ExceptionNo, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
|
|
ViewBag.ExceptionGroupNo = value;
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS015U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionCodesAsync()
|
|
{
|
|
var result = await _whsApi.GetExceptionCodes();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionCodesByQureyAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionCodesByQuery(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region WHS016 異常工時原因維護相關
|
|
|
|
public IActionResult WHS016()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public IActionResult WHS016C()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS016UAsync(string id)
|
|
{
|
|
await GetExceptionClassesList();
|
|
await GetExceptionCodesList();
|
|
var result = await _whsApi.GetExceptionReason(id);
|
|
var result2 = await _whsApi.GetExceptionCode(result[0].ExceptionNo);
|
|
ViewBag.ClassNo = result2[0].ExceptionClassNo;
|
|
var result3 = await _whsApi.GetExceptionClass(result2[0].ExceptionClassNo);
|
|
ViewBag.GroupNo = result3[0].ExceptionGroupNo;
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS016DAsync(string id)
|
|
{
|
|
var result = await _whsApi.DeleteExceptionReason(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS016CSaveAsync(ExceptionReason model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostExceptionReason(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
|
|
await GetExceptionClassesList();
|
|
await GetExceptionCodesList();
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS016C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS016USaveAsync(ExceptionReason model)
|
|
{
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutExceptionReason(model.ReasonNo, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
|
|
await GetExceptionClassesList();
|
|
await GetExceptionCodesList();
|
|
var result1 = await _whsApi.GetExceptionReason(model.ReasonNo);
|
|
var result2 = await _whsApi.GetExceptionCode(result1[0].ExceptionNo);
|
|
ViewBag.ClassNo = result2[0].ExceptionClassNo;
|
|
var result3 = await _whsApi.GetExceptionClass(result2[0].ExceptionClassNo);
|
|
ViewBag.GroupNo = result3[0].ExceptionGroupNo;
|
|
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS016U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionReasonsAsync()
|
|
{
|
|
var result = await _whsApi.GetExceptionReasons();
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetExceptionReasonsByQueryAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetExceptionReasonsByQuery(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
public async Task<IActionResult> WHS017()
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//判定單位
|
|
await GetDeptList2();
|
|
|
|
return View();
|
|
}
|
|
|
|
|
|
#region WHS018生產工時維護相關
|
|
|
|
public async Task<IActionResult> WHS018()
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
//製程單位
|
|
await GetFactoryUnitsList3();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList2();
|
|
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS018C()
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
|
|
|
|
return View();
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS018UAsync(string id)
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollection(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
//完工页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS018FAsync(string id)
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollection(id);
|
|
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS018DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteSupportUser(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS018CSaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkingHoursCollection(JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS018C", model);
|
|
}
|
|
public async Task<IActionResult> WHS018USaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingHoursCollection(model.TimeSheetID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS018U", model);
|
|
}
|
|
public async Task<IActionResult> WHS018FSaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
|
|
result = await _whsApi.PutWorkingHoursCollection(model.TimeSheetID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS018F", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingHoursCollectionByQueryAsync(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate)
|
|
{
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineid == null)
|
|
{
|
|
lineid = "*";
|
|
}
|
|
if (stationid == null)
|
|
{
|
|
stationid = "*";
|
|
}
|
|
if (itemno == null)
|
|
{
|
|
itemno = "*";
|
|
}
|
|
if (user == null)
|
|
{
|
|
user = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollectionByQuery( unitNo, lineid, stationid, wipno, itemno, user, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
//List < AMESCoreStudio.WebApi.DTO.AMES.WorkingHoursCollectionDto > workingHoursCollectionDto = new List<AMESCoreStudio.WebApi.DTO.AMES.WorkingHoursCollectionDto>();
|
|
|
|
//foreach (var data in result)
|
|
//{
|
|
// var dd = _context.StandardWorkTimes.Where(w => w.ItemNo == data.ItemNo);
|
|
// var d1 = dd.Where(w => w.UnitNo == data.UnitNo);
|
|
// var d2 = d1.Where(w => w.LineID == data.LineID);
|
|
// var d3 = d2.Where(w => w.StationID == data.StationID).FirstOrDefault();
|
|
// data.RuleCNT = d3.OPCNT;
|
|
// data.RuleTime = d3.TotalCT;
|
|
// var p1 = _context.UserInfoes.Where(w => w.UserID == data.CreateUserID).FirstOrDefault();
|
|
// data.CreateUser = p1.UserName;
|
|
// if (data.UpdateUserID != null)
|
|
// {
|
|
// var p2 = _context.UserInfoes.Where(w => w.UserID == data.UpdateUserID).FirstOrDefault();
|
|
// data.UpdateUser = p2.UserName;
|
|
// }
|
|
// if (data.TotalCT != null)
|
|
// {
|
|
// data.Effective = (data.RuleCNT * data.RuleTime) / (data.TotalCT * data.OPCNT); //標準工時 * 人數 / 該筆資料的實際標工(TOTAL_CT) * 人數 * 100 %
|
|
// }
|
|
//
|
|
//}
|
|
|
|
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
public async Task<IActionResult> GetWorkingHoursCollectionDtoByQueryAsync(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate)
|
|
{
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineid == null)
|
|
{
|
|
lineid = "*";
|
|
}
|
|
if (stationid == null)
|
|
{
|
|
stationid = "*";
|
|
}
|
|
if (itemno == null)
|
|
{
|
|
itemno = "*";
|
|
}
|
|
if (wipno == null)
|
|
{
|
|
wipno = "*";
|
|
}
|
|
|
|
if (user == null)
|
|
{
|
|
user = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollectionDtoByQuery(unitNo, lineid, stationid, wipno, itemno, user, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region WHS019生產工時報工相關
|
|
|
|
private async Task GetFactoryUnitsByUser(string unitNo)
|
|
{
|
|
var result = await _basApi.GetFactoryUnit(unitNo);
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString()));
|
|
}
|
|
ViewBag.FactoryUnit = UnitItems;
|
|
}
|
|
|
|
private async Task GetLineListByUnit(string unitNo)
|
|
{
|
|
var result = await _basApi.GetLineInfoByUnit(unitNo);
|
|
|
|
var LineItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
LineItems.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString()));
|
|
}
|
|
ViewBag.LineList = LineItems;
|
|
}
|
|
|
|
private async Task GetStation4WHS019()
|
|
{
|
|
var result = await _whsApi.GetStationWorkingHours();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
foreach (StationWorkingHour stationWorkingHour in result.Data)
|
|
{
|
|
StationItems.Add(new SelectListItem(stationWorkingHour.StationWHName, stationWorkingHour.StationWHID.ToString()));
|
|
}
|
|
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
|
|
|
|
|
|
private async Task GetStation4WHS019C2()
|
|
{
|
|
var result = await _whsApi.GetStationWorkingHours();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
StationItems.Add(new SelectListItem("N/A", "-1"));
|
|
foreach (StationWorkingHour stationWorkingHour in result.Data)
|
|
{
|
|
if (stationWorkingHour.TypeNo == "正常站")
|
|
{
|
|
StationItems.Add(new SelectListItem(stationWorkingHour.StationWHName, stationWorkingHour.StationWHID.ToString()));
|
|
}
|
|
}
|
|
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetStationses4WHS019Async(string unit_no)
|
|
{
|
|
List<StationWorkingHour> result = await _whsApi.GetStationWorkingHour2(unit_no);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetClassInfoJsonAsync(string unit_no)
|
|
{
|
|
var result = await _basApi.GetClassInfoByUnit(unit_no);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
private async Task GetStation4WHS019C()
|
|
{
|
|
var result = await _whsApi.GetStationWorkingHours();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
foreach (StationWorkingHour stationWorkingHour in result.Data)
|
|
{
|
|
if (stationWorkingHour.TypeNo == "正常站")
|
|
{
|
|
StationItems.Add(new SelectListItem(stationWorkingHour.StationWHName, stationWorkingHour.StationWHID.ToString()));
|
|
}
|
|
}
|
|
|
|
ViewBag.StationList = StationItems;
|
|
}
|
|
|
|
public async Task<IActionResult> WHS019()
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
|
|
//製程單位
|
|
await GetFactoryUnitsByUser(user_info[0].UnitNo);
|
|
|
|
//線別
|
|
//await GetLineList2();
|
|
await GetLineListByUnit(user_info[0].UnitNo);
|
|
|
|
//站別
|
|
//await GetStationList2();
|
|
await GetStation4WHS019();
|
|
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS019C()
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
ViewBag.UserID = user_id;
|
|
//製程單位
|
|
//await GetFactoryUnitsList2();
|
|
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
|
|
|
|
//製程單位
|
|
//await GetFactoryUnitsByUser(user_info[0].UnitNo);
|
|
await GetFactoryUnitsByUser(null);
|
|
|
|
var unit_no = user_info[0].UnitNo;
|
|
if (unit_no == null || unit_no == "")
|
|
{
|
|
var unit_Info = await _basApi.GetFactoryUnit(null);
|
|
unit_no = unit_Info[0].UnitNo;
|
|
}
|
|
|
|
//班別
|
|
await GetClassInfoList(unit_no);
|
|
|
|
var class_info = await _basApi.GetClassInfoByUnit(unit_no);
|
|
int class_id = -1;
|
|
int class_time = int.Parse(System.DateTime.Now.ToString("HHmm"));
|
|
for (int i = 0; i < class_info.Count; i++)
|
|
{
|
|
if (class_time <= 2359)
|
|
{
|
|
if (int.Parse(class_info[i].BeginTime.Replace(":", "")) <= class_time && int.Parse(class_info[i].EndTime.Replace(":", "")) >= class_time)
|
|
{
|
|
class_id = class_info[i].ClassID;
|
|
}
|
|
else if (int.Parse(class_info[i].BeginTime.Replace(":", "")) <= class_time && int.Parse(class_info[i].EndTime.Replace(":", "")) <= int.Parse(class_info[i].BeginTime.Replace(":", "")))
|
|
{
|
|
class_id = class_info[i].ClassID;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (int.Parse(class_info[i].BeginTime.Replace(":", "")) >= class_time && int.Parse(class_info[i].EndTime.Replace(":", "")) >= class_time)
|
|
{
|
|
class_id = class_info[i].ClassID;
|
|
}
|
|
}
|
|
}
|
|
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
//await GetLineList2();
|
|
await GetLineListByUnit(unit_no);
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
|
|
|
|
WorkingHoursCollection model = new WorkingHoursCollection();
|
|
model.OpenTime = System.DateTime.Now;
|
|
model.UnitNo = unit_no;
|
|
model.ClassID = class_id;
|
|
|
|
//return View();
|
|
return View(model);
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS019UAsync(string id)
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
ViewBag.UserID = user_id;
|
|
//製程單位
|
|
//await GetFactoryUnitsList2();
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
|
|
//製程單位
|
|
await GetFactoryUnitsByUser(user_info[0].UnitNo);
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
//await GetLineList2();
|
|
await GetLineListByUnit(user_info[0].UnitNo);
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
|
|
//班別
|
|
await GetClassInfoList(user_info[0].UnitNo);
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollection(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
//完工页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS019EAsync(string id)
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
ViewBag.UserID = user_id;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
//班別
|
|
await GetClassInfoList(user_info[0].UnitNo);
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollection(id);
|
|
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
//完工修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS019U1Async(string id)
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
ViewBag.UserID = user_id;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
//await GetStationList();
|
|
await GetStation4WHS019C();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
//班別
|
|
await GetClassInfoList(user_info[0].UnitNo);
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollection(id);
|
|
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS019DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteSupportUser(id);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS019CSaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkingHoursCollection(JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS019C", model);
|
|
}
|
|
public async Task<IActionResult> WHS019USaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingHoursCollection(model.TimeSheetID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
ViewBag.UserID = user_id;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS019U", model);
|
|
}
|
|
public async Task<IActionResult> WHS019ESaveAsync(WorkingHoursCollection model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
|
|
result = await _whsApi.PutWorkingHoursCollection(model.TimeSheetID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
var tt = Request.Cookies["UserID"];
|
|
ViewBag.UserID = tt;
|
|
//製程單位
|
|
await GetFactoryUnitsList2();
|
|
//廠別
|
|
await GetFactoryList();
|
|
//線別
|
|
await GetLineList2();
|
|
//站別
|
|
await GetStationList();
|
|
//班別
|
|
GetClassList();
|
|
//判定單位部門
|
|
await GetDeptList();
|
|
|
|
|
|
ModelState.AddModelError("error", result.Msg);
|
|
|
|
}
|
|
}
|
|
return View("WHS019E", model);
|
|
}
|
|
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingHoursCollectionByQuery4WHS019Async(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate)
|
|
{
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineid == null || lineid == "0")
|
|
{
|
|
lineid = "*";
|
|
}
|
|
if (stationid == null || stationid == "0")
|
|
{
|
|
stationid = "*";
|
|
}
|
|
if (itemno == null)
|
|
{
|
|
itemno = "*";
|
|
}
|
|
if (user == null)
|
|
{
|
|
user = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollectionByQuery(unitNo, lineid, stationid, wipno, itemno, user, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
//List < AMESCoreStudio.WebApi.DTO.AMES.WorkingHoursCollectionDto > workingHoursCollectionDto = new List<AMESCoreStudio.WebApi.DTO.AMES.WorkingHoursCollectionDto>();
|
|
|
|
//foreach (var data in result)
|
|
//{
|
|
// var dd = _context.StandardWorkTimes.Where(w => w.ItemNo == data.ItemNo);
|
|
// var d1 = dd.Where(w => w.UnitNo == data.UnitNo);
|
|
// var d2 = d1.Where(w => w.LineID == data.LineID);
|
|
// var d3 = d2.Where(w => w.StationID == data.StationID).FirstOrDefault();
|
|
// data.RuleCNT = d3.OPCNT;
|
|
// data.RuleTime = d3.TotalCT;
|
|
// var p1 = _context.UserInfoes.Where(w => w.UserID == data.CreateUserID).FirstOrDefault();
|
|
// data.CreateUser = p1.UserName;
|
|
// if (data.UpdateUserID != null)
|
|
// {
|
|
// var p2 = _context.UserInfoes.Where(w => w.UserID == data.UpdateUserID).FirstOrDefault();
|
|
// data.UpdateUser = p2.UserName;
|
|
// }
|
|
// if (data.TotalCT != null)
|
|
// {
|
|
// data.Effective = (data.RuleCNT * data.RuleTime) / (data.TotalCT * data.OPCNT); //標準工時 * 人數 / 該筆資料的實際標工(TOTAL_CT) * 人數 * 100 %
|
|
// }
|
|
//
|
|
//}
|
|
|
|
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
public async Task<IActionResult> GetWorkingHoursCollectionDtoByQuery4WHS019Async(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate)
|
|
{
|
|
if (unitNo == null)
|
|
{
|
|
unitNo = "*";
|
|
}
|
|
if (lineid == null || lineid == "0")
|
|
{
|
|
lineid = "*";
|
|
}
|
|
if (stationid == null || stationid == "0")
|
|
{
|
|
stationid = "*";
|
|
}
|
|
if (itemno == null)
|
|
{
|
|
itemno = "*";
|
|
}
|
|
else
|
|
{
|
|
itemno = itemno.ToUpper();
|
|
}
|
|
|
|
if (wipno == null)
|
|
{
|
|
wipno = "*";
|
|
}
|
|
|
|
if (user == null)
|
|
{
|
|
user = "*";
|
|
}
|
|
if (sdate == null || edate == null)
|
|
{
|
|
sdate = "*";
|
|
edate = "*";
|
|
}
|
|
|
|
var result = await _whsApi.GetWorkingHoursCollectionDtoByQuery(unitNo, lineid, stationid, wipno, itemno, user, sdate, edate);
|
|
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
[HttpPost]
|
|
public async Task<JsonResult> GetStationSide(int station_id)
|
|
{
|
|
//var station = await _basApi.GetStations(station_id);
|
|
var result = await _whsApi.GetStationWorkingHour(station_id);
|
|
//将資料Json化并传到前台视图
|
|
if (result == null)
|
|
{
|
|
return Json(new { data = "" });
|
|
}
|
|
else if (result.Count == 0)
|
|
{
|
|
return Json(new { data = "" });
|
|
}
|
|
else
|
|
{
|
|
return Json(new { data = result[0].Side });
|
|
}
|
|
}
|
|
|
|
#region WHS020報工站別維護相關
|
|
|
|
private async Task GetClassInfoList(string unitNo)
|
|
{
|
|
var result = await _basApi.GetClassInfoByUnit(unitNo);
|
|
|
|
var ClassItems = new List<SelectListItem>();
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
ClassItems.Add(new SelectListItem(result[i].ClassDesc, result[i].ClassID.ToString()));
|
|
}
|
|
ViewBag.ClassInfoList = ClassItems;
|
|
}
|
|
|
|
private void GetSideTypeList()
|
|
{
|
|
var SideTypeList = new List<SelectListItem>();
|
|
|
|
SideTypeList.Add(new SelectListItem("A面", "A面"));
|
|
SideTypeList.Add(new SelectListItem("B面", "B面"));
|
|
|
|
ViewBag.SideTypeList = SideTypeList;
|
|
}
|
|
|
|
private async Task GetStationNameList()
|
|
{
|
|
var result = await _basApi.GetStationses();
|
|
|
|
var StationItems = new List<SelectListItem>();
|
|
StationItems.Add(new SelectListItem("N/A", "N/A"));
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationName));
|
|
}
|
|
ViewBag.StationNameList = StationItems;
|
|
}
|
|
|
|
public IActionResult WHS020()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS020C()
|
|
{
|
|
GetSideTypeList();
|
|
await GetFactoryUnitsList3();
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS020UAsync(int id)
|
|
{
|
|
GetSideTypeList();
|
|
await GetFactoryUnitsList3();
|
|
|
|
var result = await _whsApi.GetStationWorkingHour(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS020DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteStationWorkingHour(id);
|
|
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS020CSaveAsync(StationWorkingHour model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostStationWorkingHour(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS020C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS020USaveAsync(StationWorkingHour model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutStationWorkingHour(model.StationWHID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS020U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetStationWorkingHoursAsync(int page = 0, int limit = 10)
|
|
{
|
|
var result = await _whsApi.GetStationWorkingHours(page,limit);
|
|
|
|
if (result.DataTotal > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
#endregion
|
|
|
|
public async Task<IActionResult> WHS021()
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
|
|
var user_info = await _sysApi.GetUserInfo(int.Parse(user_id));
|
|
|
|
//製程單位
|
|
await GetFactoryUnitsByUser(user_info[0].UnitNo);
|
|
|
|
//線別
|
|
//await GetLineList2();
|
|
await GetLineListByUnit(user_info[0].UnitNo);
|
|
|
|
//站別
|
|
await GetStation4WHS019();
|
|
|
|
return View();
|
|
}
|
|
|
|
|
|
#region WHS022報工站別維護相關
|
|
|
|
|
|
|
|
public IActionResult WHS022()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS022C()
|
|
{
|
|
GetSideTypeList();
|
|
await GetFactoryUnitsList3();
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS022UAsync(int id)
|
|
{
|
|
await GetFactoryUnitsList3();
|
|
|
|
var result = await _whsApi.GetWorkingUnit(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS022DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkingUnit(id);
|
|
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS022CSaveAsync(WorkingUnit model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkingUnit(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS022C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS022USaveAsync(WorkingUnit model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingUnit(model.WorkingUnitID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS022U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingUnitsAsync(int page = 0, int limit = 10)
|
|
{
|
|
var result = await _whsApi.GetWorkingUnits(page, limit);
|
|
|
|
if (result.DataTotal > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region WHS023報工線別基本資料相關
|
|
private async Task GetWorkingUnit(string Type)
|
|
{
|
|
var result = await _whsApi.GetWorkingUnits();
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
|
|
if (Type == "all")
|
|
{
|
|
UnitItems.Add(new SelectListItem("全部", "all"));
|
|
}
|
|
for (int i = 0; i < result.Count; i++)
|
|
if (result[i].StatusNo == "A")
|
|
{
|
|
UnitItems.Add(new SelectListItem(result[i].WorkingUnitName, result[i].WorkingUnitNo.ToString()));
|
|
}
|
|
|
|
ViewBag.WorkingUnitNo = UnitItems;
|
|
}
|
|
public async Task<IActionResult> WHS023()
|
|
{
|
|
await GetWorkingUnit("all");
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS023C()
|
|
{
|
|
|
|
await GetWorkingUnit("");
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS023UAsync(int id)
|
|
{
|
|
await GetWorkingUnit("");
|
|
|
|
var result = await _whsApi.GetWorkingLine(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS023DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkingLine(id);
|
|
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS023CSaveAsync(WorkingLine model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkingLine(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS023C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS023USaveAsync(WorkingLine model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingLine(model.WorkingLineID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS023U", model);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WHS024報工工作站基本資料相關
|
|
|
|
public async Task<IActionResult> WHS024()
|
|
{
|
|
await GetWorkingUnit("all");
|
|
return View();
|
|
}
|
|
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS024C()
|
|
{
|
|
|
|
await GetWorkingUnit("");
|
|
return View();
|
|
}
|
|
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS024UAsync(int id)
|
|
{
|
|
await GetWorkingUnit("");
|
|
|
|
var result = await _whsApi.GetWorkingStation(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
return View(result[0]);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS024DAsync(int id)
|
|
{
|
|
var result = await _whsApi.DeleteWorkingStation(id);
|
|
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
|
|
//頁面提交,id=0 添加,id>0 修改
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS024CSaveAsync(WorkingStation model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PostWorkingStation(JsonConvert.SerializeObject(model));
|
|
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "添加成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS024C", model);
|
|
}
|
|
|
|
public async Task<IActionResult> WHS024USaveAsync(WorkingStation model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingStation(model.WorkingStationID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors != null)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS024U", model);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingStationsAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetWorkingStationsbyMultiUnit(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingLinesAsync(string id)
|
|
{
|
|
// var result = await _whsApi.GetWorkingLinesbyUnit(id);
|
|
var result = await _whsApi.GetWorkingLinesbyMultiUnit(id);
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region WHS025標準工時維護相關
|
|
public async Task<IActionResult> WHS025()
|
|
{
|
|
await GetWorkingUnit("all");
|
|
return View();
|
|
}
|
|
//新增頁面
|
|
public async Task<IActionResult> WHS025C()
|
|
{
|
|
await GetWorkingUnit(""); //報工生產單位
|
|
await GetFactoryUnitsListbyWH005(""); //途程生產單位
|
|
GetSideList();
|
|
return View();
|
|
}
|
|
//修改页面
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS025UAsync(int id)
|
|
{
|
|
await GetWorkingUnit(""); //報工生產單位
|
|
|
|
GetSideList();
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTime(id);
|
|
|
|
if (result.Count == 0)
|
|
{
|
|
return View();
|
|
}
|
|
|
|
return View(result[0]);
|
|
}
|
|
public async Task<IActionResult> WHS025DAsync(int id)
|
|
{
|
|
var deleteUserID = int.Parse(Request.Cookies["UserID"]);
|
|
var result = await _whsApi.DeleteWorkingStandardWorkTime(id, deleteUserID);
|
|
return Json(new Result() { success = true, msg = "" });
|
|
}
|
|
[HttpPost]
|
|
public async Task<IActionResult> WHS025CSaveAsync(WHS025ViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return View("WHS025C", model);
|
|
|
|
// 若 WorkingLineIDs 為空,直接回傳錯誤
|
|
if (model.WorkingLineIDs == null)
|
|
{
|
|
ModelState.AddModelError("error", "請至少選擇一個線別");
|
|
return View("WHS025C", model);
|
|
}
|
|
// 複製 model 中的其他欄位,產生新的物件
|
|
var item = new WorkingStandardWorkTime
|
|
{
|
|
WorkingStandardID = model.WorkingStandardID,
|
|
ItemNo = model.ItemNo,
|
|
WorkingUnitNo = model.WorkingUnitNo,
|
|
UnitNo = model.UnitNo,
|
|
WorkingStationID = model.WorkingStationID,
|
|
Side = model.Side,
|
|
OpCnt = model.OpCnt,
|
|
Ct = model.Ct,
|
|
StationID = model.StationID,
|
|
MachineCnt = model.MachineCnt,
|
|
Remark = model.Remark,
|
|
CreateUserID = model.CreateUserID,
|
|
UpdateUserID = model.UpdateUserID,
|
|
CreateDate = model.CreateDate,
|
|
UpdateDate = model.UpdateDate
|
|
};
|
|
|
|
foreach (var lineId in model.WorkingLineIDs)
|
|
{
|
|
item.WorkingLineID = lineId; // ⭐ 關鍵:取代為迴圈內的 lineId
|
|
|
|
var json = JsonConvert.SerializeObject(item);
|
|
var result = await _whsApi.PostWorkingStandardWorkTime(json);
|
|
if (!result.Success)
|
|
{
|
|
// 其中一筆失敗就回傳錯誤
|
|
ModelState.AddModelError("error", $"線別ID {lineId} 錯誤:{result.Msg}");
|
|
return View("WHS025C", model);
|
|
}
|
|
|
|
}
|
|
|
|
return RedirectToAction("Refresh", "Home", new { msg = "添加成功!" });
|
|
|
|
|
|
//if (ModelState.IsValid)
|
|
//{
|
|
// IResultModel result;
|
|
|
|
|
|
// result = await _whsApi.PostWorkingStandardWorkTime(JsonConvert.SerializeObject(model));
|
|
|
|
// if (result.Success)
|
|
// {
|
|
// var _msg = "添加成功!";
|
|
// return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
// }
|
|
// else
|
|
// {
|
|
|
|
// ModelState.AddModelError("error", result.Msg);
|
|
|
|
// }
|
|
//}
|
|
//return View("WHS025C", model);
|
|
}
|
|
public async Task<IActionResult> WHS025USaveAsync(WorkingStandardWorkTime model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
IResultModel result;
|
|
|
|
result = await _whsApi.PutWorkingStandardWorkTime(model.WorkingStandardID, JsonConvert.SerializeObject(model));
|
|
|
|
if (result.Success)
|
|
{
|
|
var _msg = "修改成功!";
|
|
return RedirectToAction("Refresh", "Home", new { msg = _msg });
|
|
}
|
|
else
|
|
{
|
|
if (result.Errors.Count > 0)
|
|
{
|
|
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("error", result.Msg);
|
|
}
|
|
}
|
|
}
|
|
return View("WHS025U", model);
|
|
}
|
|
[HttpGet]
|
|
public async Task<IActionResult> WHS025LAsync(int id)
|
|
{
|
|
return View(id);
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingUnitNobyUnitAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetWorkingUnitbyNo(id);
|
|
var data = new List<FactoryUnit>();
|
|
|
|
if (result != null && result.Count > 0)
|
|
{
|
|
var unitNo = result[0].UnitNo;
|
|
var resultUnit = await _basApi.GetFactoryUnits();
|
|
|
|
for (int i = 0; i < resultUnit.Count; i++)
|
|
{
|
|
if (resultUnit[i].UnitNo == unitNo )
|
|
|
|
data.Add(new FactoryUnit
|
|
{
|
|
UnitNo = resultUnit[i].UnitNo,
|
|
UnitName = resultUnit[i].UnitName
|
|
});
|
|
|
|
}
|
|
return Json(new Table { code = 0, msg = "", data = data, count = 1 });
|
|
|
|
|
|
}
|
|
|
|
return Json(new Table { code = 0, msg = "No data found", data = null, count = 0 });
|
|
}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingLinesbyUnitAsync(string id)
|
|
{
|
|
// var result = await _whsApi.GetWorkingLinesbyUnit(id);
|
|
var result = await _whsApi.GetWorkingLinesbyMultiUnit(id);
|
|
if (result.Count> 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingStationsbyUnitAsync(string id)
|
|
{
|
|
var result = await _whsApi.GetWorkingStationsbyUnit(id);
|
|
|
|
if (result.Count > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
|
|
//[ResponseCache(Duration = 0)]
|
|
//[HttpGet]
|
|
//public async Task<IActionResult> GetWorkingStandardWorkTimesAsync()
|
|
//{
|
|
// var result = await _whsApi.GetWorkingStandardWorkTimes();
|
|
|
|
// if (result.DataTotal > 0)
|
|
// {
|
|
// return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
// }
|
|
|
|
// return Json(new Table() { count = 0, data = null });
|
|
//}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimes2Async(string u, int l, string i, int page = 0, int limit = 10)
|
|
{
|
|
if (l == 0)
|
|
{
|
|
l = -99;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(i))
|
|
{
|
|
i = "Null";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(u))
|
|
{
|
|
u = "Null";
|
|
}
|
|
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimesbyMultiQuery(u, l, i, page, limit);
|
|
if (result.DataTotal > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
private async Task GetFactoryUnitsListbyWH005(string Types)
|
|
{
|
|
var result = await _basApi.GetFactoryUnits();
|
|
|
|
var UnitItems = new List<SelectListItem>();
|
|
if (Types == "all")
|
|
{
|
|
UnitItems.Add(new SelectListItem("全部", "0"));
|
|
}
|
|
for (int i = 0; i < result.Count; i++)
|
|
{
|
|
UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString()));
|
|
}
|
|
ViewBag.FactoryUnit = UnitItems;
|
|
}
|
|
|
|
[ResponseCache(Duration = 0)]
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimesLogAsync(int id, int page = 0, int limit = 10)
|
|
{
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimeLogMulti(id,page,limit);
|
|
if (result.DataTotal > 0)
|
|
{
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
}
|
|
|
|
return Json(new Table() { count = 0, data = null });
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 標準工時批次Excel匯入
|
|
/// </summary>
|
|
/// <param name="Uploader"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<JsonResult> WHS025ExcelUpload(IFormFile Uploader)
|
|
{
|
|
var user_id = Request.Cookies["UserID"];
|
|
//通過上傳檔案流初始化Mapper
|
|
using (var workbook = new XLWorkbook(Uploader.OpenReadStream()))
|
|
{
|
|
try
|
|
{
|
|
List<WorkingStandardWorkTime> workingST = new List<WorkingStandardWorkTime>();
|
|
|
|
string Msg = string.Empty;
|
|
var worksheet = workbook.Worksheet(1);
|
|
// 定義資料起始/結束 Cell
|
|
var firstCell = worksheet.FirstCellUsed();
|
|
var lastCell = worksheet.LastCellUsed();
|
|
|
|
// 使用資料起始/結束 Cell,來定義出一個資料範圍
|
|
var data = worksheet.Range(firstCell.Address, lastCell.Address);
|
|
var rowCount = data.RowCount();
|
|
var columnCount = data.ColumnCount();
|
|
var ErrorMsg = "";
|
|
var recordKeys = new HashSet<string>(); // 用於檢查組合是否重複
|
|
for (int i = 2; i <= rowCount; i++)
|
|
{
|
|
var rowMsg = $"[第{i}列] ";
|
|
try
|
|
{
|
|
var ItemNo = data.Cell(i, 1).GetString().Trim();
|
|
var WorkingUnitName = data.Cell(i, 2).GetString().Trim();
|
|
var WorkingLineName = data.Cell(i, 3).GetString().Trim();
|
|
var WorkingStationName = data.Cell(i, 4).GetString().Trim();
|
|
// var UnitName = data.Cell(i, 5).GetString().Trim();
|
|
var Side = data.Cell(i, 5).GetString().Trim();
|
|
var OpCntStr = data.Cell(i, 6).GetString().Trim();
|
|
var CtStr = data.Cell(i, 7).GetString().Trim();
|
|
var StationID = data.Cell(i, 8).GetString().Trim();
|
|
var MachineCntStr = data.Cell(i, 9).GetString().Trim();
|
|
var Remark = data.Cell(i, 10).GetString().Trim();
|
|
|
|
// 組合唯一鍵
|
|
var rowKey = $"{ItemNo}|{WorkingUnitName}|{WorkingLineName}|{WorkingStationName}|{Side}";
|
|
if (recordKeys.Contains(rowKey))
|
|
{
|
|
ErrorMsg += $"{rowMsg}資料重複:相同的料號與單位線別站別已存在。\n";
|
|
continue;
|
|
}
|
|
recordKeys.Add(rowKey);
|
|
|
|
if (string.IsNullOrWhiteSpace(ItemNo)) { ErrorMsg += $"{rowMsg}料號不得為空\n"; continue; }
|
|
|
|
if (string.IsNullOrWhiteSpace(WorkingUnitName)) { ErrorMsg += $"{rowMsg}報工生產單位不得為空\n"; continue; }
|
|
if (string.IsNullOrWhiteSpace(WorkingLineName)) { ErrorMsg += $"{rowMsg}報工線別不得為空\n"; continue; }
|
|
if (string.IsNullOrWhiteSpace(WorkingStationName)) { ErrorMsg += $"{rowMsg}報工站別不得為空\n"; continue; }
|
|
// if (string.IsNullOrWhiteSpace(UnitName)) { ErrorMsg += $"{rowMsg}途程單位不得為空\n"; continue; }
|
|
List<string> validSides = new List<string> { "正面", "背面" };
|
|
if (string.IsNullOrWhiteSpace(Side)) { ErrorMsg += $"{rowMsg}面別不得為空\n"; continue; }
|
|
else if (!validSides.Contains(Side))
|
|
{
|
|
ErrorMsg += $"{rowMsg}面別資料錯誤,請使用 N/A、正面、背面\n";
|
|
continue;
|
|
}
|
|
|
|
if (!int.TryParse(OpCntStr, out int OpCnt))
|
|
{
|
|
ErrorMsg += $"{rowMsg}人數格式錯誤\n"; continue;
|
|
}
|
|
if (OpCnt <= 0)
|
|
{
|
|
ErrorMsg += $"{rowMsg}人數必須大於 0\n"; continue;
|
|
}
|
|
|
|
if (!int.TryParse(CtStr, out int Ct))
|
|
{
|
|
ErrorMsg += $"{rowMsg}CT格式錯誤\n"; continue;
|
|
}
|
|
if (Ct <= 0)
|
|
{
|
|
ErrorMsg += $"{rowMsg}CT 必須大於 0\n"; continue;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(StationID))
|
|
{
|
|
ErrorMsg += $"{rowMsg}工站ID不得為空\n"; continue;
|
|
}
|
|
|
|
if (!int.TryParse(MachineCntStr, out int MachineCnt))
|
|
{
|
|
ErrorMsg += $"{rowMsg}機台數格式錯誤\n"; continue;
|
|
}
|
|
if (MachineCnt < 0)
|
|
{
|
|
ErrorMsg += $"{rowMsg}機台數不得為負值\n"; continue;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(Remark) && Remark.Length > 500)
|
|
{
|
|
ErrorMsg += $"{rowMsg}備註過長,限制500字以內\n"; continue;
|
|
}
|
|
// 資料對應檢查
|
|
var WU = await _whsApi.GetWorkingUnitbyName(WorkingUnitName);
|
|
var WL = await _whsApi.GetWorkingLinebyName(WorkingLineName);
|
|
var WS = await _whsApi.GetWorkingStationbyName(WorkingStationName);
|
|
// var UN = await _whsApi.GetFactoryUnitbyName(UnitName);
|
|
|
|
if (WU.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工生產單位「{WorkingUnitName}」\n"; continue; }
|
|
if (WL.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工線別「{WorkingLineName}」\n"; continue; }
|
|
if (WS.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工站別「{WorkingStationName}」\n"; continue; }
|
|
// if (UN.Count == 0) { ErrorMsg += $"{rowMsg}查無 途程生產單位「{UnitName}」\n"; continue; }
|
|
|
|
// 加入清單
|
|
workingST.Add(new WorkingStandardWorkTime
|
|
{
|
|
WorkingUnitNo = WU[0].WorkingUnitNo,
|
|
WorkingLineID = WL[0].WorkingLineID,
|
|
WorkingStationID = WS[0].WorkingStationID,
|
|
// UnitNo = UN[0].UnitNo,
|
|
UnitNo = WU[0].UnitNo,
|
|
ItemNo = ItemNo,
|
|
Side = Side,
|
|
OpCnt = OpCnt,
|
|
Ct = Ct,
|
|
StationID = StationID,
|
|
MachineCnt = MachineCnt,
|
|
Remark = Remark,
|
|
CreateDate = System.DateTime.Now,
|
|
CreateUserID = int.Parse(user_id),
|
|
UpdateDate = System.DateTime.Now,
|
|
UpdateUserID = int.Parse(user_id)
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorMsg += $"{rowMsg}資料處理異常: {ex.Message}\n";
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(ErrorMsg))
|
|
{
|
|
return Json(new Result() { success = false, msg = $"匯入失敗:\n{ErrorMsg}", data = null });
|
|
}
|
|
else
|
|
{
|
|
var postData = await _whsApi.PostWorkingStandardWorkTimeList(JsonConvert.SerializeObject(workingST));
|
|
|
|
return Json(new Result() { success = true, msg = "匯入成功", data = null });
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Json(new { data = ex.Message, success = false });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//将資料Json化并传到前台视图
|
|
return Json(new { data = "", success = true });
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|