From 7993662370dff15af3d13d40cbc913abfe87d176 Mon Sep 17 00:00:00 2001 From: KwakJooYoung Date: Wed, 10 Dec 2025 17:44:14 +0900 Subject: [PATCH] =?UTF-8?q?item=5Fdata=5Flist=20ArrayList=EB=A5=BC=20item?= =?UTF-8?q?=5Fproduct=5Flist,=20item=5Fcomponent=5Flist=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frmMySqlTest.vb | 174 +++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 91 deletions(-) diff --git a/frmMySqlTest.vb b/frmMySqlTest.vb index 8d29388..92ad761 100644 --- a/frmMySqlTest.vb +++ b/frmMySqlTest.vb @@ -24,10 +24,13 @@ Public Class frmMySqlTest Dim prod_code As String Dim sales_packing_cnt_col_nm As String Dim sales_packing_serial_col_nm As String - Dim cnt As String + Dim cnt As Integer Dim serial As String End Structure - Private item_data_list As New ArrayList + Private item_product_list() As item_info + Private item_component_list() As item_info + Public item_product_max_index As Integer + Public item_component_max_index As Integer Private cmd As String Private dbcmd As String @@ -116,7 +119,14 @@ Public Class frmMySqlTest End Sub Private Sub setItemData() - dbcmd = "SELECT CAST(ProdCode AS CHAR), SalesPackingCntColNm, SalesPackingSerialColNm FROM " & prod_table & " WHERE ProdCode <> 2 GROUP BY ProdCode ORDER BY ProdCode asc;" + dbcmd = "SELECT CAST(MAX(ProdCode) AS CHAR) FROM " & prod_table & ";" + If DBQueryReader(dbcmd) Then + item_product_max_index = sqlDataQuery(0) + ReDim item_product_list(item_product_max_index) + End If + + '제품 ProdCode는 1부터 시작하며, ProSet(1),LuxSet(2)는 같은 컬럼을 사용하고 있어 중복되기 때문에 2부터 조회 + dbcmd = "SELECT CAST(ProdCode AS CHAR), SalesPackingCntColNm, SalesPackingSerialColNm FROM " & prod_table & " WHERE ProdCode > 1 GROUP BY ProdCode ORDER BY ProdCode ASC;" If DBQueryReader(dbcmd) Then Dim RowCount As Int16 = (sqlDataQuery.Length / 3) - 1 Dim dataSetCount As Int32 = 0 @@ -134,10 +144,16 @@ Public Class frmMySqlTest End If dataSetCount += 1 Next - item_data_list.Add(item_data) + item_product_list(item_data.prod_code) = item_data Next End If + dbcmd = "SELECT CAST(MAX(ProdCode) AS CHAR) FROM " & component_table & ";" + If DBQueryReader(dbcmd) Then + item_component_max_index = sqlDataQuery(0) + ReDim item_component_list(item_component_max_index) + End If + dbcmd = "SELECT CAST(ProdCode AS CHAR), SalesPackingCntColNm FROM " & component_table & " GROUP BY ProdCode ORDER BY ProdCode asc;" If DBQueryReader(dbcmd) Then Dim RowCount As Int16 = (sqlDataQuery.Length / 2) - 1 @@ -154,30 +170,36 @@ Public Class frmMySqlTest End If dataSetCount += 1 Next - item_data_list.Add(item_data) + item_component_list(item_data.prod_code) = item_data Next End If '제품 정보 조회 쿼리 생성 query_product = Nothing - For Each item_data As item_info In item_data_list - If item_data.item_type = "P" Then + For i = 0 To item_product_max_index + If item_product_list(i).sales_packing_cnt_col_nm <> Nothing Then If query_product = Nothing Then - query_product = "'" & item_data.prod_code & "', IFNULL(" & item_data.sales_packing_serial_col_nm & ",'NULL'), IFNULL(" & item_data.sales_packing_cnt_col_nm & ",'0')" + query_product = "IFNULL(" & item_product_list(i).sales_packing_serial_col_nm & ",'NULL'), IFNULL(" & item_product_list(i).sales_packing_cnt_col_nm & ",'0')" Else - query_product = query_product & ",'" & item_data.prod_code & "', IFNULL(" & item_data.sales_packing_serial_col_nm & ",'NULL'), IFNULL(" & item_data.sales_packing_cnt_col_nm & ",'0')" + query_product = query_product & ", IFNULL(" & item_product_list(i).sales_packing_serial_col_nm & ",'NULL'), IFNULL(" & item_product_list(i).sales_packing_cnt_col_nm & ",'0')" End If End If Next '구성품 정보 조회 쿼리 생성 query_component = Nothing - For Each item_data As item_info In item_data_list - If item_data.item_type = "C" Then + For i = 0 To item_component_max_index + If item_component_list(i).sales_packing_cnt_col_nm <> Nothing Then If query_component = Nothing Then - query_component = "'" & item_data.prod_code & "', IFNULL(" & item_data.sales_packing_cnt_col_nm & ",'0')" + query_component = "IFNULL(" & item_component_list(i).sales_packing_cnt_col_nm & ",'0')" Else - query_component = query_component & ",'" & item_data.prod_code & "', IFNULL(" & item_data.sales_packing_cnt_col_nm & ",'0')" + query_component = query_component & ", IFNULL(" & item_component_list(i).sales_packing_cnt_col_nm & ",'0')" + End If + Else + If query_component = Nothing Then + query_component = "'0'" + Else + query_component = query_component & ", '0'" End If End If Next @@ -198,9 +220,13 @@ Public Class frmMySqlTest basic_data_select(i) = "NULL" Next - For Each item_data As item_info In item_data_list - item_data.cnt = 0 - item_data.serial = Nothing + For i = 0 To item_product_max_index + item_product_list(i).cnt = 0 + item_product_list(i).serial = Nothing + Next + + For i = 0 To item_component_max_index + item_component_list(i).cnt = 0 Next End Sub @@ -281,7 +307,6 @@ Public Class frmMySqlTest dbcmd = "SELECT IFNULL(sale.PackingCode,'NULL') , IFNULL(sale.`Data`,'NULL') , IFNULL(sale.note, '') - , IFNULL(otb.Order_Code,'NULL') , IFNULL(otb.Orderer_Name,'NULL') , IFNULL(otb.Phone_Number,'NULL') @@ -302,74 +327,36 @@ Public Class frmMySqlTest '제품 정보 조회 dbcmd = "SELECT " & query_product & " FROM " & sales_db & " WHERE PackingCode = '" & packing_code & "'" If DBQueryReader(dbcmd) Then - Dim RowCount As Int16 = (sqlDataQuery.Length / 3) - 1 + Dim RowCount As Int16 = (sqlDataQuery.Length / 2) Dim dataSetCount As Int32 = 0 - Dim prod_code As String - Dim serial As String - Dim cnt As String - For row = 0 To RowCount - For col = 0 To 2 + For row = 2 To RowCount '제품 ProdCode는 1부터 시작하며, ProSet(1),LuxSet(2)는 같은 컬럼을 사용하고 있어 중복되기 때문에 ProdCode 2부터 설정 + For col = 0 To 1 If col = 0 Then - prod_code = sqlDataQuery(dataSetCount) + item_product_list(row).serial = sqlDataQuery(dataSetCount) ElseIf col = 1 Then - serial = sqlDataQuery(dataSetCount) - ElseIf col = 2 Then - cnt = sqlDataQuery(dataSetCount) + item_product_list(row).cnt = sqlDataQuery(dataSetCount) End If dataSetCount += 1 Next - For i = 0 To item_data_list.Count - 1 - Dim item_data As item_info = item_data_list(i) - If item_data.item_type = "P" And item_data.prod_code = prod_code Then - item_data.serial = serial - item_data.cnt = cnt - item_data_list(i) = item_data - - '모든 제품의 시리얼번호를 검색 - If serial <> "NULL" Then - Dim serial_array() As String = serial.Split("/") - For j = 0 To serial_array.Length - 1 - If Len(serial_array(j)) <> 0 Then - all_serial_list.Add(serial_array(j)) - End If - Next + '모든 제품의 시리얼번호를 검색 + If item_product_list(row).serial <> "NULL" Then + Dim serial_array() As String = item_product_list(row).serial.Split("/") + For j = 0 To serial_array.Length - 1 + If Len(serial_array(j)) <> 0 Then + all_serial_list.Add(serial_array(j)) End If - - Exit For - End If - Next + Next + End If Next End If '구성품 정보 조회 dbcmd = "SELECT " & query_component & " FROM " & sales_db & " WHERE PackingCode = '" & packing_code & "'" If DBQueryReader(dbcmd) Then - Dim RowCount As Int16 = (sqlDataQuery.Length / 2) - 1 - Dim dataSetCount As Int32 = 0 - Dim prod_code As String - Dim cnt As String - - For row = 0 To RowCount - For col = 0 To 1 - If col = 0 Then - prod_code = sqlDataQuery(dataSetCount) - ElseIf col = 1 Then - cnt = sqlDataQuery(dataSetCount) - End If - dataSetCount += 1 - Next - - For i = 0 To item_data_list.Count - 1 - Dim item_data As item_info = item_data_list(i) - If item_data.item_type = "C" And item_data.prod_code = prod_code Then - item_data.cnt = cnt - - item_data_list(i) = item_data - Exit For - End If - Next + For i = 0 To sqlDataQuery.Length - 1 + item_component_list(i).cnt = sqlDataQuery(i) Next End If @@ -381,26 +368,19 @@ Public Class frmMySqlTest Dim dgv_switch As Boolean Try - For Each item_data As item_info In item_data_list + For i = 0 To item_product_max_index dgv_switch = False item_name = Nothing - If item_data.cnt > 0 Then - If item_data.item_type = "P" And item_data.prod_code = "1" Or item_data.prod_code = "2" Then 'Pro_Set, Lux_Set - If Mid(item_data.serial, 1, 2) = "10" Then + If item_product_list(i).cnt > 0 Then + If i = 1 Or i = 2 Then 'Pro_Set, Lux_Set + If Mid(item_product_list(i).serial, 1, 2) = "10" Then item_name = "DUALSONIC Pro 1Set (KR)" Else item_name = "DUALSONIC Lux 1Set (KR)" End If - ElseIf item_data.item_type = "P" Then - dbcmd = "SELECT ItemName FROM " & prod_db & " WHERE ProdCode = '" & item_data.prod_code & "' AND ItemName NOT LIKE '%체험%' LIMIT 1" - - If DBQueryReader(dbcmd) Then - item_name = sqlDataQuery(0) - End If Else - dbcmd = "SELECT ItemName FROM " & component_db & " WHERE ProdCode = '" & item_data.prod_code & "' LIMIT 1" - + dbcmd = "SELECT ItemName FROM " & prod_db & " WHERE ProdCode = '" & i & "' AND ItemName NOT LIKE '%체험%' LIMIT 1" If DBQueryReader(dbcmd) Then item_name = sqlDataQuery(0) End If @@ -410,7 +390,26 @@ Public Class frmMySqlTest End If If dgv_switch = True Then - dgv_pack_item.Rows.Add(item_name, item_data.cnt, item_data.serial) + dgv_pack_item.Rows.Add(item_name, item_product_list(i).cnt, item_product_list(i).serial) + End If + Next + + For i = 0 To item_component_max_index + dgv_switch = False + item_name = Nothing + + If item_component_list(i).cnt > 0 Then + dbcmd = "SELECT ItemName FROM " & component_db & " WHERE ProdCode = '" & i & "' LIMIT 1" + + If DBQueryReader(dbcmd) Then + item_name = sqlDataQuery(0) + End If + + dgv_switch = True + End If + + If dgv_switch = True Then + dgv_pack_item.Rows.Add(item_name, item_component_list(i).cnt, item_component_list(i).serial) End If Next @@ -486,18 +485,11 @@ Public Class frmMySqlTest msg_cnt = MsgBox("패킹에 포함된 시리얼번호를 삭제하시겠습니까?", vbExclamation + vbOKCancel) If msg_cnt = 1 Then 'STEP_01 : jomtTesterDB.jomtSalesPackingTbl 테이블 시리얼번호 삭제 - Dim remain_serial_data() As String + Dim remain_serial_data() As String = item_product_list(product_serial_type).serial.Replace(txbPacking.Text, "").Split("/") Dim update_serial_str As String = "" Dim update_serial_cnt As UInt16 = 0 Dim update_note_str As String = basic_data_select(basic_info.pack_note) - For Each item_data As item_info In item_data_list - If item_data.item_type = "P" And item_data.prod_code = product_serial_type Then - remain_serial_data = item_data.serial.Replace(txbPacking.Text, "").Split("/") - Exit For - End If - Next - For i = 0 To remain_serial_data.Length - 1 If Len(remain_serial_data(i)) <> 0 Then If update_serial_str = "" Then