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.
 
 
 
 
 

166 lines
5.0 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AMESCoreStudio.WebApi.Models.SYS;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Localization;
using Microsoft.AspNetCore.Http;
using AMESCoreStudio.Web.Models;
using AMESCoreStudio.CommonTools.Result;
using static AMESCoreStudio.Web.ViewModels.LAB.LAB003ViewModel;
using AMESCoreStudio.WebApi.Models.AMES;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AMESCoreStudio.Web.Controllers
{
public class LABController : Controller
{
public readonly ISYS _sysApi;
public readonly ILAB _labApi;
public LABController(ILogger<LABController> logger, ILAB labApi, ISYS sysApi, IPCS pcsApi, IStringLocalizer<SharedResource> sharedLocalizer)
{
_sysApi = sysApi;
_labApi = labApi;
}
public async Task<IActionResult> LAB003(string mat)
{
var id = GetLogInUserID();
ViewBag.UserID = id;
var result = await _sysApi.GetUserInfo(id);
var name = result[0].UserName;
ViewBag.UserName = name;
return View();
}
public async Task<IActionResult> LAB004()
{
int id = GetLogInUserID();
var result = await _sysApi.GetUserInfo(id);
var name = result[0].UserNo;
ViewBag.userno = name;
return View();
}
public async Task<IActionResult> LAB003U(string OrderNo)
{
List<LabelItemReqModel> model = new List<LabelItemReqModel>();
model = await _labApi.GetLabelReq(OrderNo);
return View(model);
}
[HttpGet]
public async Task<IActionResult> GetLab004(string OrderNo, string ModelNo, DateTime? strdate, DateTime? enddate, string UserNo)
{
List<dynamic> xx = new List<dynamic>();
UserInfo User = new UserInfo();
if (UserNo != null)
User = await _sysApi.GetUserInfoByUserNo(UserNo);
var result = await _labApi.GetLabelItemMaster(OrderNo, ModelNo, strdate, enddate, User.UserID);
if (result!=null)
{
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.Data.Count() });
}
return Json(new Table() { count = 0, data = null });
}
public async Task<IActionResult> LAB003P(string LabMat)
{
var result = await _labApi.GetLabelPicture(LabMat);
var x = "file://////"+result.Data.FirstOrDefault();
ViewBag.Picture = x;
return View(result.Data);
}
[HttpPost]
public async Task<IActionResult> SaveParamLAB003([FromBody] List<Labmodel> Lab)
{
IResultModel result;
foreach (var name in Lab)
{
name.UserId = GetLogInUserID();
}
result = await _labApi.PostLabelItemMaster(JsonConvert.SerializeObject(Lab));
return Json(new Result() { success = result.Success, msg = result.Msg });
}
[HttpGet]
public async Task<JsonResult> GetLabelField(string Labmat)
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
result = await _labApi.GetLabelField(Labmat);
return Json(new Result() { success = result.Success, msg = result.Msg, data = result.Data });
}
[HttpGet]
public async Task<string> GetOrderSn(string OderNo)
{
int Sn = 1;
ResultModel<dynamic> result = new ResultModel<dynamic>();
result = await _labApi.GetLabelItemMaster(OderNo, null,null, null, -1);
if(result.Data.Any())
{
var r2 = result.Data.Max(x => x.ordeR_NO).ToString();
Sn = int.Parse(r2.Substring(7)) + 1;
}
string sSn = Sn.ToString("000");
return sSn;
}
[HttpGet]
public async Task<string> GetSampleSn(int Qty)
{
ResultModel<string> result = new ResultModel<string>();
result = await _labApi.GetSampleSerialRulesNEW(Qty);
return result.Msg;
}
[HttpGet]
public async Task<JsonResult> GetLabel(string Model)
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
result = await _labApi.GetLabel(Model);
return Json(new Result() { success = result.Success, msg = result.Msg, data = result.Data });
}
public int GetLogInUserID()
{
int user_id = 0;
HttpContext.Request.Cookies.TryGetValue("UserID", out string userID);
if (userID != null)
{
if (int.Parse(userID.ToString()) >= 0)
{
user_id = int.Parse(userID.ToString());
}
}
return user_id;
}
}
}