From adc301b64e37dd60de8d59f8518833d2ceba3513 Mon Sep 17 00:00:00 2001 From: "vick_wang419@hotmail.com.tw" Date: Wed, 10 Jan 2024 22:09:40 +0800 Subject: [PATCH] =?UTF-8?q?PTD=20=E9=9C=80=E6=B1=82=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0(=E9=82=84=E5=8E=9F=E4=BD=9C=E6=A5=AD?= =?UTF-8?q?=E3=80=81=E4=B8=80=E6=AE=B5=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PTDController.cs | 27 +- AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 7 + AMESCoreStudio.Web/Views/PTD/PTD002.cshtml | 36 ++- AMESCoreStudio.Web/Views/PTD/PTD008.cshtml | 238 ++++++++++++++++++ .../Controllers/AMES/WipInfosController.cs | 165 ++++++++++++ .../Models/AMES/PTD101AMESModel.cs | 19 ++ 6 files changed, 485 insertions(+), 7 deletions(-) create mode 100644 AMESCoreStudio.Web/Views/PTD/PTD008.cshtml diff --git a/AMESCoreStudio.Web/Controllers/PTDController.cs b/AMESCoreStudio.Web/Controllers/PTDController.cs index c05b237b..6a65f80b 100644 --- a/AMESCoreStudio.Web/Controllers/PTDController.cs +++ b/AMESCoreStudio.Web/Controllers/PTDController.cs @@ -131,7 +131,7 @@ namespace AMESCoreStudio.Web.Controllers kpDataList = kpDataList + " Material(料號)"; break; case 3: - kpDataList = kpDataList + " 出貨料號"; + kpDataList = kpDataList + " 出貨序號"; break; case 4: kpDataList = kpDataList + " 生產序號"; @@ -559,5 +559,30 @@ namespace AMESCoreStudio.Web.Controllers #endregion + #region "PTD008 還原作業" + public async Task PTD008() + { + return View(); + } + public async Task PTD008QueryAsync(string recordNumber, string lineNo, string materialNo, string shippingSN) + { + if (string.IsNullOrEmpty(recordNumber) || string.IsNullOrEmpty(lineNo) || string.IsNullOrEmpty(materialNo)) + return Json(new Table() { count = 0, data = null }); + + var result = await _pcsApi.GetData4PTD008(recordNumber, lineNo, materialNo, shippingSN); + 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 PTD008_Commit(string data) + { + var result = await _pcsApi.PostPTD008Commit(data); + //将数据Json化并传到前台视图 + return Json(new { data = result }); + } + #endregion } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 74d84c52..1d508e08 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -2019,5 +2019,12 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpPost("api/WipInfos/PostPTD007Commit")] ITask> PostPTD007Commit([FromBody, RawJsonContent] string model); #endregion + + #region "PTD008 還原作業" + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetData4PTD008")] + ITask> GetData4PTD008(string recordNumber, string lineNo, string materialNo, string shippingSN); + [WebApiClient.Attributes.HttpPost("api/WipInfos/PostPTD008Commit")] + ITask> PostPTD008Commit([FromBody, RawJsonContent] string model); + #endregion } } diff --git a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml index 92bae685..1b9a6b53 100644 --- a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml +++ b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml @@ -277,14 +277,32 @@ if (event.keyCode == 13) { var endSN = document.getElementById('endSN'); var frontSN = document.getElementById('frontSN'); - - endSN.focus(); - endSN.select(); + var dnNo = document.getElementById('recordNumber'); + var lineNo = document.getElementById('lineNo'); + var material = document.getElementById('PartNumber'); + var table = layui.table; + var rowAmount = table.cache['query'].length; + if (document.getElementById('PCSUnit').checked) { - endSN.value = frontSN.value; - } + rowAmount++; + var newRowData = { + itemNo: rowAmount, + dnNo: dnNo.value, + lineNo: lineNo.value, + material: material.value, + sn: frontSN.value + }; + // Add the new row data to the table + hg.table.addRow('query', newRowData); + frontSN.focus(); + frontSN.select(); + } + else { + endSN.focus(); + endSN.select(); + } } }); $('#endSN').on('keypress', function (event) { @@ -403,6 +421,12 @@ } }); layer.msg('扣帳成功!', { icon: 1 }); + + //清空SN資訊 + $("#endSN").val(''); + $("#frontSN").val(''); + $("#SNData").val(''); + } else { layer.msg('扣帳失敗,原因:' + result.data.msg, { icon: 2 }); } @@ -567,7 +591,7 @@ } ]]; //基本数据表格 - var table = hg.table.datatable('query', '扣帳資訊', '', {}, tableCols, toolbar, false, 'full-100'); + var table = hg.table.datatable('query', '扣帳資訊', '', {}, tableCols, "", false, 'full-100'); } diff --git a/AMESCoreStudio.Web/Views/PTD/PTD008.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD008.cshtml new file mode 100644 index 00000000..e237e6c2 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PTD/PTD008.cshtml @@ -0,0 +1,238 @@ +@{ + ViewData["Title"] = "還原作業"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + +
+
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+ + +@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 9da27b89..d53061c9 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -3976,5 +3976,170 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); } #endregion + + #region "PTD008 還原作業" + [Route("[action]")] + [HttpGet] + public async Task> GetData4PTD008( string recordNumber, string lineNo, string materialNo, string shippingSN) + { + 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 RecordTypeID,RecordNumber,RCLineNO 'LineNo', + SerialNumber 'SN',ProductID + FROM SFIS_PTD.dbo.ZProductTrans where RecordNumber ='{recordNumber}' And RCLineNO ='{lineNo}' + And ProductID = '{materialNo}'"; + if (shippingSN != null && shippingSN != "") + { + strSQL += $" And SerialNumber = '{shippingSN}'"; + } + + 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; + } + } + [Route("[action]")] + [HttpPost] + public async Task> PostPTD008Commit(PTD008CommitDataModel Data) + { + ResultModel result = new ResultModel(); + Collection colSQL = new Collection(); + try + { + string strSQL = ""; + string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); + + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + + foreach (PTD008TableDataModel SNData in Data.tableData) + { + + if (Data.type == 0) //還原 + { + strSQL = $"Select HistoryID,RecordTypeID,ModifyDate from [SFIS_PTD].[dbo].[ZProductTrans] " + + $"where [SerialNumber] = '{SNData.sn}' " + + $"Order by HistoryID desc offset 1 row fetch next 1 rows only "; + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.Read()) + { + strSQL = $"Update [SFIS_PTD].[dbo].[ZSNInfo] set RecordTypeID ='{reader["RecordTypeID"]}',ModifyDate ='{reader["ModifyDate"]}',LatestHistoryID ='{reader["HistoryID"]}' " + + $"where SerialNumber ='{SNData.sn}'"; + colSQL.Add(strSQL); + } + else + { + strSQL = $"Delete [SFIS_PTD].[dbo].[ZSNInfo] where SerialNumber ='{SNData.sn}'"; + colSQL.Add(strSQL); + } + } + } + } + else if (SNData.recordTypeID != "292" + && SNData.recordTypeID != "101") //狀態為 292 樣品入庫、101 樣品入庫 才能刪除 + { + throw new Exception(SNData.recordTypeID + "狀態不能刪除!"); + } + + strSQL = $"Delete [SFIS_PTD].[dbo].[ZProductTrans] " + + $"where [SerialNumber] = '{SNData.sn}' " + + $"and RecordNumber = '{SNData.recordNumber}' and RCLineNO ='{SNData.lineNo}' " + + $"and ProductID ='{SNData.productID}'"; + colSQL.Add(strSQL); + } + + using (var cmd = connPTD.CreateCommand()) + { + using (var transaction = connPTD.BeginTransaction()) + { + try + { + foreach (string query in colSQL) + { + cmd.CommandText = query; + cmd.Transaction = transaction; + cmd.ExecuteNonQuery(); + } + + // Commit the transaction + transaction.Commit(); + } + catch (Exception ex) + { + // Rollback the transaction in case of an exception + transaction.Rollback(); + throw ex; // Rethrow the exception after rollback + } + } + } + + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.Message; + } + return result; + } + #endregion } } diff --git a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs index 7846160a..f512a082 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs @@ -117,6 +117,25 @@ namespace AMESCoreStudio.WebApi.Models.AMES } + #endregion + + #region "PTD008 還原作業" + + public class PTD008CommitDataModel + { + public int type { get; set; } + public List tableData { get; set; } + } + public class PTD008TableDataModel + { + public string recordNumber { get; set; } + public string lineNo { get; set; } + public string productID { get; set; } + public string sn { get; set; } + public string recordTypeID { get; set; } + public string result { get; set; } + } + #endregion #region "PTD006 備貨作業"