From 639d1155b5d27d31ca21d98ecd55546fd552feb4 Mon Sep 17 00:00:00 2001 From: "vick_wang419@hotmail.com.tw" Date: Thu, 30 Nov 2023 22:01:33 +0800 Subject: [PATCH] fix:GetDNInfo4PTD001 --- .../Controllers/AMES/WipInfosController.cs | 174 +++++++++++++++++- 1 file changed, 169 insertions(+), 5 deletions(-) diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index 67d6ce4b..566b9fd1 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -2574,7 +2574,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S /// [Route("[action]")] [HttpGet] - public async Task> GetDNInfo4PTD001(string dnNo,string lineNo) + public async Task> GetDNInfo4PTD001(string dnNo, string lineNo) { ResultModel result = new ResultModel(); @@ -2630,7 +2630,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S { dtBarcode = DataReaderToDataTable(reader); } else { dtBarcode.Merge(DataReaderToDataTable(reader)); } - + } } } @@ -2647,7 +2647,7 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S string kp_sql = @"select kp_no, max(kp_qty) kp_qty from( select item_no as kp_no,count(item_no) kp_qty,barcode_id from jhames.barcode_item where barcode_id in (" + strbarcode_id + ") group by item_no,barcode_id) a group by kp_no order by kp_no"; - + using (var cmd = conn.CreateCommand()) { cmd.CommandText = kp_sql; @@ -2735,6 +2735,170 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); } dtBarcode.AcceptChanges(); + + try + { + if (kp_no.StartsWith("MB") && !kp_no.StartsWith("MB_MAC")) + { + + bool createMacCol = true; + + bool findFlag = false; + + string mac_sql = string.Format("select partbarcode from jhames.c_sfis_keyparts where productsn = '{0}' and parttypeid='MAC'", part_no); + + using (var esun_cmd = conn.CreateCommand()) + { + esun_cmd.CommandText = mac_sql; + esun_cmd.CommandTimeout = 0; + + using (var esun_reader = await esun_cmd.ExecuteReaderAsync()) + { + if (esun_reader.HasRows) + { + findFlag = true; + + List esun_list = new List(); + DataTable esun_table = new DataTable(); + + esun_table = DataReaderToDataTable(esun_reader); + + if (esun_table != null) + { + WriteTraceLog("query mac by mb trace 005:esun_talbe rows qty:" + esun_table.Rows.Count); + } + + if (esun_table.Rows.Count > 0) + { + if (createMacCol) + { + for (int m = 0; m < esun_table.Rows.Count; m++) + { + if (dtItem.Rows.Count == 1) + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#MAC" + (m + 1).ToString()); + } + catch { } + } + else + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()); + } + catch { } + } + } + dtBarcode.AcceptChanges(); + createMacCol = false; + } + + WriteTraceLog("query mac by mb trace 006"); + + string mac = ""; + for (int m = 0; m < esun_table.Rows.Count; m++) + { + //mac = esun_table.Rows[m]["part_barcode"].ToString().Trim(); + mac = esun_table.Rows[m]["PARTBARCODE"].ToString().Trim(); + if (dtItem.Rows.Count == 1) + { + dtBarcode.Rows[i]["KP_" + kp_no + "#MAC" + (m + 1).ToString()] = mac; + } + else + { + dtBarcode.Rows[i]["KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()] = mac; + } + dtBarcode.AcceptChanges(); + } + + WriteTraceLog("query mac by mb trace 007"); + } + } + } + } + + //从barcode_item读取结转数据 + if (!findFlag) + { + string mac_sql2 = string.Format("select a.part_no from jhames.barcode_item a,jhames.barcode_info b where a.barcode_id = b.barcode_id and b.barcode_no = '{0}' and item_no like 'MAC%'", part_no); + + using (var esun_cmd = conn.CreateCommand()) + { + esun_cmd.CommandText = mac_sql2; + esun_cmd.CommandTimeout = 0; + + using (var esun_reader = await esun_cmd.ExecuteReaderAsync()) + { + if (esun_reader.HasRows) + { + findFlag = true; + + List esun_list = new List(); + DataTable esun_table = new DataTable(); + + esun_table = DataReaderToDataTable(esun_reader); + + if (esun_table != null) + { + WriteTraceLog("query mac by mb trace 005:esun_talbe rows qty:" + esun_table.Rows.Count); + } + + if (esun_table.Rows.Count > 0) + { + if (createMacCol) + { + for (int m = 0; m < esun_table.Rows.Count; m++) + { + if (dtItem.Rows.Count == 1) + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#MAC" + (m + 1).ToString()); + } + catch { } + } + else + { + try + { + dtBarcode.Columns.Add("KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()); + } + catch { } + } + } + dtBarcode.AcceptChanges(); + createMacCol = false; + } + + string mac = ""; + for (int m = 0; m < esun_table.Rows.Count; m++) + { + //mac = esun_table.Rows[m]["part_barcode"].ToString().Trim(); + mac = esun_table.Rows[m]["PART_NO"].ToString().Trim(); + if (dtItem.Rows.Count == 1) + { + dtBarcode.Rows[i]["KP_" + kp_no + "#MAC" + (m + 1).ToString()] = mac; + } + else + { + dtBarcode.Rows[i]["KP_" + kp_no + "#" + (k + 1).ToString() + "_MAC" + (m + 1).ToString()] = mac; + } + dtBarcode.AcceptChanges(); + } + } + } + } + } + } + } + } + catch (Exception e1) + { + string err = e1.Message; + WriteTraceLog("query mac by mb trace 999:" + e1.Message); + } } dtBarcode.AcceptChanges(); } @@ -2755,9 +2919,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); //dtBarcode.Columns["ExtraBarcodeNo"].ColumnName = "出貨料號"; //dtBarcode.Columns["BarcodeNo"].ColumnName = "生產序號"; dtBarcode.AcceptChanges(); - } + } - List list = new List(); + List list = new List(); foreach (DataRow row in dtBarcode.Rows) { dynamic dyn = new ExpandoObject();