Private Sub Retrieve_Data()
''On Error GoTo ERR1
Dim strSql As String
Dim intRow As Long
Dim intCol As Integer
Dim i As Integer
Dim GetTotRow As Long
Dim lRet As Long
Dim strSqlXls As String
Dim bStopRetrieve As Boolean
bStopRetrieve = False
If F1.NumSheets > 1 Then
F1.DeleteSheets 2, F1.NumSheets - 1
End If
F1.Sheet = 1
If l_blnRetrieveData = True Then
MsgBox "κΈ°μ‘΄ μ‘°νμ€μ
λλ€. μ μν κΈ°λ€λ Έλ€κ° μ‘°ν λ²νΌμ λλ¬μ μ‘°νν΄μ£ΌμΈμ.", vbOKOnly, "μλ¦Ό"
Exit Sub
End If
l_blnRetrieveData = True
''cmdMenu(l_intCancel).Enabled = True ' μ·¨μλ²νΌ νμ±ν
l_intTitleRows = m_ex_lExcelTitleRows
If F1.MaxRow > l_intTitleRows Then
DoEvents
F1.ClearRange l_intTitleRows + 1, 1, F1.MaxRow, F1.MaxCol, F1ClearAll
End If
''Call g_frmxxx.ShowWaiting(1, 0, "μ‘°νλ₯Ό μν μμ
μνΈ(Factor μ°λ Sheet) Clear μ€ μ
λλ€..")
DoEvents
If F1.NumSheets > 1 Then
F1.DeleteSheets 2, F1.NumSheets - 1
End If
If F1_1.NumSheets > 1 Then
F1_1.DeleteSheets 2, F1.NumSheets - 1
End If
''Call g_frmxxx.ShowWaiting(1, 0, "μ‘°ν μ€λΉ μ€μ
λλ€..")
DoEvents
F1.Row = l_intTitleRows + 1
F1.Col = 1
lblListCount.Caption = ""
Dim strSql_OrderBy As String
strSql_OrderBy = " "
strSql = strSql & strSql_OrderBy
'----------------------------------------------------------------------------------------------------
Dim strSql1 As String
strSql1 = Replace(strSql, "select /*+rule*/ t.*", "select /*+rule*/ count(*) cnt")
strSql1 = Replace(strSql1, strSql_OrderBy, "")
'-- λ μ½λ countλ₯Ό μ»λλ€. --
Set g_adoRs = New ADODB.Recordset
g_adoRs.Open strSql1, g_adoCn
Dim lRecordCount As Long
lRecordCount = g_adoRs!cnt
If g_adoRs.State <> adStateClosed Then g_adoRs.Close
'-- 4λ§κ±΄ μ΄ν λ μ½λ λͺ©λ‘ μ‘°ν νλ€. --
If lRecordCount >= 0 And lRecordCount <= 40000 Then
Set g_adoRs = New ADODB.Recordset
g_adoCn.CursorLocation = adUseServer
g_adoRs.Open strSql, g_adoCn
g_adoCn.CursorLocation = adUseClient
F1.MaxCol = m_ex_lExcelTitleCols
m_ex_lExcelRowEnd = lRecordCount + m_ex_lExcelTitleRows
If g_adoRs.EOF = True Then
'-- νμ΄ν, λ°μ΄ν° ν, ν¬λ§·, μ λ ¬ μ€μ --
Call exSetWidthHeight(F1)
GoTo NoData
End If
''Call g_frmxxx.ShowWaiting(1, 0, "λ°μ΄ν° μ‘°ν μ€λΉμ€ μ
λλ€..")
DoEvents
ReDim l_ary_retrieve(lRecordCount, exFindTitleIDX("wc_oc_bt_price"))
''Call g_frmxxx.ShowWaiting(1, 0, "λ°μ΄ν° μ‘°ν μ€ μ
λλ€..")
DoEvents
Dim rowcnt As Long
'----------------------------------------------------------------------------------------------------
'--F1μ μ‘°ν λͺ©λ‘μ λΏλ €μ£Όμ.
'----------------------------------------------------------------------------------------------------
'-- F1 λ°μ΄ν° 첫λ²μ§Έ μ€λ‘ μ΄λ --
m_ex_lRowIndex = m_ex_lExcelRowStart
Dim intViewDbColStart As Integer
intViewDbColStart = 3
For rowcnt = 1 To lRecordCount
If (m_ex_lRowIndex - m_ex_lExcelTitleRows) Mod 100 = 0 Or (m_ex_lRowIndex - m_ex_lExcelTitleRows) = (lRecordCount) Then
g_frmWait.lblcount.Caption = CStr(m_ex_lRowIndex - m_ex_lExcelTitleRows) & " / " & (lRecordCount)
lblListCount.Caption = "μ‘°νλͺ©λ‘ : " & g_frmWait.lblcount.Caption
DoEvents
End If
If rowcnt >= 40000 Then
m_ex_lExcelRowEnd = m_ex_lRowIndex
Exit For
End If
If CancelFlag = True Then
' μ·¨μλ₯Ό λλ μΌλ―λ‘, μ‘°νλ₯Ό μ’
λ£νλ€.
If MsgBox("μ‘°νλ₯Ό μ€λ¨νμκ² μ΅λκΉ?", vbQuestion + vbYesNo, "μ λ΄") = vbYes Then
bStopRetrieve = True
MsgBox "μ‘°νμ€ μ·¨μλ₯Ό μ ννμμΌλ―λ‘, μ‘°νλ₯Ό μ€λ¨ν©λλ€.", vbInformation + vbOKOnly, "μ λ΄"
Unload g_frmWait
CancelFlag = False
''cmdMenu(l_intCancel).Enabled = False
GoTo COPY
Else
CancelFlag = False
End If
End If
'-- λ°μ΄ν° λ€μ μ€λ‘ μ΄λ --
m_ex_lRowIndex = m_ex_lRowIndex + 1
'-- λ€μ λ μ½λ μ
μΌλ‘ μ΄λ --
g_adoRs.MoveNext
Next
'----------------------------------------------------------------------------------------------------
COPY:
F1.SetSelection l_intTitleRows + 1, 1, l_intTitleRows + lRecordCount, m_ex_lExcelTitleCols
F1.SetBorder -1, 1, 1, 1, 1, 0, -1, RGB(190, 190, 190), RGB(190, 190, 190), RGB(190, 190, 190), RGB(190, 190, 190)
'-- νμ΄ν, λ°μ΄ν° ν, ν¬λ§·, μ λ ¬ μ€μ --
Call exSetWidthHeight(F1)
'-- Sheet λ³΅μ¬ --
F1_1.ClearRange 1, 1, F1_1.MaxRow, F1_1.MaxCol, F1ClearAll
F1_1.CopyAll F1.SS
F1_1.FixedRows = 3
'-- Sheet λ³΅μ¬ λ --
F1.SetSelection 1, 1, 1, 1
Unload g_frmWait
F1.Modified = False
m_ex_bModified = False
l_blnRetrieveData = False
''cmdMenu(l_intCancel).Enabled = False
ReDim UPDATE_PRICE_INFOItem(0)
g_adoCn.CursorLocation = adUseClient
If g_adoRs.State <> adStateClosed Then g_adoRs.Close
'-- 4λ§κ±΄ μ΄κ³Ό λ μ½λμ λν μ²λ¦¬ λΆκΈ° --
Else
Unload g_frmWait
If lRecordCount > 1048500 Then
MsgBox "μ΅λ건μκ° 1,048,500 건μ λμΌλ©΄ νμν μ μμ΅λλ€. ", vbInformation + vbOKOnly, "μ λ΄!"
GoTo CANCEL_RETRIEVE
End If
If MsgBox(Str(lRecordCount) & "κ±΄μ΄ μ‘°νλμμ΅λλ€." & vbCrLf & vbCrLf & "40,000κ±΄μ΄ λμΌλ―λ‘, Excel λ‘ μ§μ νμν©λλ€." & vbCrLf & vbCrLf & "Excel Export λ₯Ό μ§ννμκ² μ΅λκΉ?", vbInformation + vbYesNo, "μ λ΄!") = vbNo Then
GoTo CANCEL_RETRIEVE
End If
MsgBox "건μκ° λ§μΌλ―λ‘, μ‘°νμ μκ°μ΄ λ§μ΄ 걸릴 μ μμ΅λλ€." & vbCrLf & vbCrLf & "κΈ°λ€λ €μ£ΌμκΈ° λ°λλλ€." & vbCrLf & vbCrLf & " *) μ§νμ€, κ°λ³ Excelμμ
μ νμ€ μ μμ΅λλ€.", vbInformation + vbOKOnly, "μ λ΄!"
'-- μ΄λ €λ νμΌλͺ
μΌλ‘ μμ
μ΄ μ΄λ €μμΌλ©΄ λ©μΈμ§ μΆλ ₯ ν μ’
λ£ --
lRet = gGet_ProgHwnd("xxxtemp.xlsx")
If lRet <> 0 Then
MsgBox "xxxtemp νμΌμ΄ μ΄λ―Έ μ΄λ € μμ΅λλ€. λ«μ νμ μ‘°νν΄μ£ΌμΈμ.", vbCritical, "νμΈ"
Exit Sub
End If
GetTotRow = lRecordCount
''Call g_frmxxx.ShowWaiting(1, 0, CStr(lRecordCount) & " 건μ λ°μ΄ν°λ₯Ό κ°μ Έμ€λ μ€....")
''cmdMenu(l_intCancel).Enabled = True ' μ·¨μλ²νΌ νμ±ν
'-- μμ
νμΌμ μ§μ μ°κΈ° --
Dim strXlFileName As String
Dim strConnExcel As String
Dim adoConnExcel As ADODB.Connection
strXlFileName = "c:\xxxtemp.xlsx"
If Dir(strXlFileName) <> "" Then
Kill strXlFileName
DoEvents
End If
strConnExcel = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\xxxtemp.xlsx;Extended Properties='Excel 12.0 xml;HDR=YES';"
Set adoConnExcel = CreateObject("ADODB.Connection")
adoConnExcel.ConnectionString = strConnExcel
adoConnExcel.CursorLocation = adUseServer
adoConnExcel.Open
strSqlXls = "CREATE TABLE Sheet1 ("
For i = 1 To m_ex_lExcelTitleCols
If i > 1 Then strSqlXls = strSqlXls & ", "
'-- Chr(34) : " --
strSqlXls = strSqlXls & Chr(34) & Left$("(" & i & ")" & exTitleItem(i).sColName, 100) & Chr(34) & " TEXT "
Next
strSqlXls = strSqlXls & ")"
adoConnExcel.Execute strSqlXls
Set g_adoRs = New ADODB.Recordset
g_adoCn.CursorLocation = adUseServer
g_adoRs.Open strSql, g_adoCn
g_adoCn.CursorLocation = adUseClient
F1.MaxCol = m_ex_lExcelTitleCols
m_ex_lExcelRowEnd = lRecordCount + m_ex_lExcelTitleRows
''Call g_frmxxx.ShowWaiting(1, 0, "μμ
λ‘μ λ°μ΄ν° μ‘°ν μ€λΉμ€ μ
λλ€..")
DoEvents
ReDim l_ary_retrieve(lRecordCount, exFindTitleIDX("wc_oc_bt_price"))
''Call g_frmxxx.ShowWaiting(1, 0, "μμ
λ‘μ λ°μ΄ν° μ‘°ν μ€ μ
λλ€..")
DoEvents
'----------------------------------------------------------------------------------------------------
'--F1μ μ μ₯ μ€λ₯ λͺ©λ‘μ λΏλ €μ£Όμ.
'----------------------------------------------------------------------------------------------------
intViewDbColStart = 3
For rowcnt = 1 To lRecordCount
strSqlXls = "INSERT INTO Sheet1 VALUES ("
For i = 1 To m_ex_lExcelTitleCols
If i > 1 Then strSqlXls = strSqlXls & ", "
strSqlXls = strSqlXls & "'" & Replace(NullToBlank(g_adoRs(intViewDbColStart + i - 2).Value), "'", "`") & "'"
Next
strSqlXls = strSqlXls & ")"
adoConnExcel.Execute strSqlXls
If (rowcnt) Mod 100 = 0 Or (rowcnt) = (lRecordCount) Then
g_frmWait.lblcount.Caption = CStr(rowcnt) & " / " & (lRecordCount)
lblListCount.Caption = "μ‘°νλͺ©λ‘ : " & g_frmWait.lblcount.Caption
DoEvents
End If
If CancelFlag = True Then
' μ·¨μλ₯Ό λλ μΌλ―λ‘, μ‘°νλ₯Ό μ’
λ£νλ€.
If MsgBox("μ‘°νλ₯Ό μ€λ¨νμκ² μ΅λκΉ?", vbQuestion + vbYesNo, "μ λ΄") = vbYes Then
bStopRetrieve = True
MsgBox "μ‘°νμ€ μ·¨μλ₯Ό μ ννμμΌλ―λ‘, μ‘°νλ₯Ό μ€λ¨ν©λλ€.", vbInformation + vbOKOnly, "μ λ΄"
CancelFlag = False
''cmdMenu(l_intCancel).Enabled = False
GoTo STOP_RETRIEVE
Else
CancelFlag = False
End If
End If
'-- λ€μ λ μ½λ μ
μΌλ‘ μ΄λ --
g_adoRs.MoveNext
Next
'----------------------------------------------------------------------------------------------------
STOP_RETRIEVE:
''Call g_frmxxx.ShowWaiting(1, 0, "μμ
νμΌμ μ¬λμ€....")
DoEvents
adoConnExcel.Close
Set adoConnExcel = Nothing
DoEvents
Shell "rundll32 url,FileProtocolHandler " & strXlFileName, vbMaximizedFocus
Unload g_frmWait
''cmdMenu(l_intCancel).Enabled = False
MsgBox "Excelλ‘μ Exportκ° μλ£λμμ΅λλ€.", vbOKOnly + vbInformation, "μ λ΄!"
CANCEL_RETRIEVE:
Unload g_frmWait
F1.Modified = False
m_ex_bModified = False
l_blnRetrieveData = False
''cmdMenu(l_intCancel).Enabled = False
ReDim UPDATE_PRICE_INFOItem(0)
g_adoCn.CursorLocation = adUseClient
If g_adoRs.State <> adStateClosed Then g_adoRs.Close
End If
Set g_adoRs = Nothing
Exit Sub
NoData:
F1.ClearRange m_ex_lExcelTitleRows + 1, 1, F1.MaxRow, F1.MaxCol, F1ClearAll
Unload g_frmWait
g_frmxxx.StatusBar.Panels(g_frmxxx.m_StatusIdx).Text = "μ‘°νν λ°μ΄ν°κ° μμ΅λλ€"
l_blnRetrieveData = False
MsgBox "μ‘°νν λ°μ΄ν°κ° μμ΅λλ€. ", vbOKOnly, "νμΈμ°½"
If g_adoRs.State <> adStateClosed Then g_adoRs.Close
Set g_adoRs = Nothing
Exit Sub
ERR1:
Unload g_frmWait
MsgBox Err.Description, vbOKOnly, "μ€λ₯"
l_blnRetrieveData = False
''cmdMenu(l_intCancel).Enabled = False
g_adoCn.CursorLocation = adUseClient
If g_adoRs.State <> adStateClosed Then g_adoRs.Close
Set g_adoRs = Nothing
End Sub