diff --git a/AMESCoreStudio.Web/Controllers/PTDController.cs b/AMESCoreStudio.Web/Controllers/PTDController.cs index 46edfcc8..a307acdc 100644 --- a/AMESCoreStudio.Web/Controllers/PTDController.cs +++ b/AMESCoreStudio.Web/Controllers/PTDController.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using AMESCoreStudio.CommonTools.Result; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Microsoft.AspNetCore.Mvc.Rendering; +using AMESCoreStudio.Web.Models; namespace AMESCoreStudio.Web.Controllers { @@ -13,19 +15,22 @@ namespace AMESCoreStudio.Web.Controllers { public readonly IPCS _pcsApi; public readonly IKCS _kcsApi; + public readonly IBAS _basApi; + public readonly ISYS _sysApi; - public PTDController(IPCS pcsApi, IKCS kcsApi) + public PTDController(IPCS pcsApi, IKCS kcsApi, IBAS basApi, ISYS sysApi) { _pcsApi = pcsApi; _kcsApi = kcsApi; + _basApi = basApi; + _sysApi = sysApi; } + #region "PTD001 DN單查詢" public async Task PTD001() - { + { return View(); } - - public async Task PTD001AAsync(string dnNo, string lineNo) { ViewData["Title"] = "查詢條件 - 出貨DN單: " + dnNo + " Line No:" + lineNo; @@ -38,7 +43,7 @@ namespace AMESCoreStudio.Web.Controllers try { //組表頭 - IResultModel DNDetail = await _pcsApi.GetZDNDetail4PTD001(dnNo,lineNo); + IResultModel DNDetail = await _pcsApi.GetZDNDetail4PTD001(dnNo, lineNo); if (DNDetail.DataTotal > 0) { dataList = ""; @@ -85,7 +90,7 @@ namespace AMESCoreStudio.Web.Controllers dataList += ""; break; default: - + break; } } @@ -99,7 +104,7 @@ namespace AMESCoreStudio.Web.Controllers IResultModel result = await _pcsApi.GetDNInfo4PTD001(dnNo, lineNo); if (result.DataTotal > 0) { - + kpDataList = kpDataList + "
 " + jp[i].Value + "
"; @@ -211,7 +216,7 @@ namespace AMESCoreStudio.Web.Controllers kpDataList = kpDataList + ""; break; case 5: - strStartDate = ""; + strStartDate = ""; break; default: kpDataList = kpDataList + ""; @@ -239,5 +244,174 @@ namespace AMESCoreStudio.Web.Controllers ViewData["list"] = dataList; return View(); } + + #endregion + + #region "PTD002 一段式入出庫作業" + public async Task PTD002() + { + if (Request.Cookies["_AMESCookie"] != null) + { + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + if (userID != null) + { + var user_info = await _sysApi.GetUserInfo(int.Parse(userID)); + var factory_info = await _basApi.GetFactoryInfo(user_info[0].FactoryID); + ViewData["RBU"] = factory_info[0].Address; + } + + } + + return View(); + } + #endregion + + #region "PTD003 作業查詢" + public async Task PTD003() + { + if (Request.Cookies["_AMESCookie"] != null) + { + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + if (userID != "") + { + var user_info = await _sysApi.GetUserInfo(int.Parse(userID)); + List factory_info = await _basApi.GetFactoryInfo(user_info[0].FactoryID); + ViewData["RBU"] = factory_info[0].Address; + } + + } + List RecordTypes = await _pcsApi.GetRecordTypes(); + + var SelectListItem = new List(); + + foreach (String RecordTypeID in RecordTypes) + { + SelectListItem.Add(new SelectListItem(RecordTypeID, RecordTypeID)); + } + ViewBag.RecordType = SelectListItem; + ViewBag.StartDate = System.DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd"); + ViewBag.EndDate = System.DateTime.Now.ToString("yyyy/MM/dd"); + ViewBag.WorkCenter = "TWM0"; + + + return View(); + } + public async Task PTD003QueryAsync(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd) + { + if (recordNumber == null || recordNumber == "") + return Json(new Table() { count = 0, data = null }); + + var result = await _pcsApi.GetData4PTD003(recordType, recordNumber, lineNo, materialNo, shippingSN, dateStart, dateEnd); + 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, msg =result.Msg }); + } + + [HttpPost] + public async Task GetCustomerJson(string recordNumber) + { + string strCustomer = await _pcsApi.GetCustomer(recordNumber); + + var item = new List(); + + item.Add(new SelectListItem(strCustomer, strCustomer)); + + //将数据Json化并传到前台视图 + return Json(new { data = item }); + } + + #endregion + + #region "PTD004 單頭說明維護" + public IActionResult PTD004() + { + return View(); + } + //新增頁面 + public IActionResult PTD004C() + { + return View(); + } + //修改页面 + [HttpGet] + public async Task PTD004UAsync(string id) + { + + var result = await _basApi.GetFactoryUnit(id); + + if (result.Count == 0) + { + return View(); + } + return View(result[0]); + } + public async Task PTD004DAsync(string id) + { + var result = await _basApi.DeleteFactoryUnit(id); + return Json(new Result() { success = true, msg = "" }); + } + //頁面提交,SEQ=0 添加,id>0 修改 + [HttpPost] + public async Task PTD004SaveAsync(WebApi.Models.BAS.FactoryUnit model) + { + + if (ModelState.IsValid) + { + IResultModel result; + if (model.SEQ == 0) + { + + result = await _basApi.PostFactoryUnit(JsonConvert.SerializeObject(model)); + } + else + { + result = await _basApi.PutFactoryUnit(model.UnitNo, JsonConvert.SerializeObject(model)); + } + + if (result.Success) + { + var _msg = model.SEQ == 0 ? "添加成功!" : "修改成功!"; + 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); + } + } + } + if (model.SEQ == 0) + { + return View("PTD004C", model); + } + return View("PTD004U", model); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetFactoryUnitsAsync() + { + var result = await _basApi.GetFactoryUnits(); + + 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 + + } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index b7c3fdfd..0765f54b 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -1844,5 +1844,14 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/WipInfos/GetDNInfo4PTD001")] ITask> GetDNInfo4PTD001(string dnNo, string lineNo); + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetRecordTypes")] + ITask> GetRecordTypes(); + + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetData4PTD003")] + ITask> GetData4PTD003(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd); + + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetCustomer/{recordNumber}")] + ITask GetCustomer(string recordNumber); + } } diff --git a/AMESCoreStudio.Web/Views/PTD/PTD003.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD003.cshtml new file mode 100644 index 00000000..dc2ccaad --- /dev/null +++ b/AMESCoreStudio.Web/Views/PTD/PTD003.cshtml @@ -0,0 +1,293 @@ +@{ + ViewData["Title"] = "查詢作業"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + +
+
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
 " + jp[i].Value + " " + jp[i].Value + " " + jp[i].Value + " " + jp[i].Value + "
s + + + + +@section Scripts{ + + + +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index b7c1c154..67d6ce4b 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -2785,6 +2785,183 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); return result; } + [Route("[action]")] + [HttpGet] + public async Task> GetRecordTypes() + { + try + { + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + string strSQL = $@"select RecordTypeID from SFIS_PTD.dbo.ZProductTrans group by RecordTypeID"; + DataTable dtRecordTypes = new DataTable(); + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.HasRows) + { + dtRecordTypes = DataReaderToDataTable(reader); + } + } + } + + List list = new List(); + foreach (DataRow row in dtRecordTypes.Rows) + { + list.Add(row["RecordTypeID"].ToString()); + } + + return list; + } + catch (Exception e) + { + throw e; + } + } + + [Route("[action]")] + [HttpGet] + public async Task> GetData4PTD003(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd) + { + try + { + ResultModel result = new ResultModel(); + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + string strSQL = $@"SELECT a.RecordTypeID ,a.RecordNumber ,a.RCLineNO 'LineNo', + a.SerialNumber 'SN',a.ProductID ,b.SoldCustomerID 'Customer',a.LocationID 'Location', + a.CreatorID ,a.CreateDate + FROM SFIS_PTD.dbo.ZProductTrans a join SFIS_PTD.dbo.ZDNDetail b on (a.RecordNumber = b.DNNO and a.RCLineNO = b.DNLineNO) where 1=1 "; + if (recordType != null && recordType != "") + { + strSQL += $" And a.RecordTypeID ='{recordType}'"; + } + + if (recordNumber != null && recordNumber != "") + { + strSQL += $" And a.RecordNumber ='{recordNumber}'"; + } + + if (lineNo != null && lineNo != "") + { + strSQL += $" And a.RCLineNO ='{lineNo}'"; + } + + if (materialNo != null && materialNo != "") + { + strSQL += $" And a.ProductID like '{materialNo}%'"; + } + + if (shippingSN != null && shippingSN != "") + { + strSQL += $" And a.SerialNumber like '{shippingSN}%'"; + } + + if (dateStart != null && dateEnd != null) + { + if (DateTime.Parse(dateStart) > DateTime.Parse(dateEnd)) + { + result.Msg = "起 不可大於 迄!"; + result.Success = false; + return result; + } + strSQL += $" And a.CreateDate Between '{dateStart}' And '{dateEnd}'"; + } + + DataTable dtZProductTrans = new DataTable(); + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.HasRows) + { + dtZProductTrans = DataReaderToDataTable(reader); + } + } + } + + List list = new List(); + foreach (DataRow row in dtZProductTrans.Rows) + { + dynamic dyn = new ExpandoObject(); + list.Add(dyn); + foreach (DataColumn column in dtZProductTrans.Columns) + { + var dic = (IDictionary)dyn; + dic[column.ColumnName] = row[column]; + } + } + + result.DataTotal = list.Count(); + result.Data = list; + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + catch (Exception e) + { + throw e; + } + } + + [HttpGet("GetCustomer/{recordNumber}")] + public async Task GetCustomer(string recordNumber) + { + try + { + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + string strSQL = $@"Select top 1 SoldCustomerID 'Customer' from SFIS_PTD.dbo.ZDNDetail where DNNo ='{recordNumber}'"; + string strCustomer = ""; + + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.Read()) + { + + strCustomer = reader.GetString(0); + } + } + } + + return strCustomer; + } + catch (Exception e) + { + throw e; + } + } } } diff --git a/AMESCoreStudio.WebApi/Models/BAS/FactoryInfo.cs b/AMESCoreStudio.WebApi/Models/BAS/FactoryInfo.cs index ff56d00a..005382bb 100644 --- a/AMESCoreStudio.WebApi/Models/BAS/FactoryInfo.cs +++ b/AMESCoreStudio.WebApi/Models/BAS/FactoryInfo.cs @@ -66,6 +66,7 @@ namespace AMESCoreStudio.WebApi.Models.BAS /// 地址 /// [Column("ADDRESS")] + [DataMember] public string Address { get; set; } ///