Arjuna Aircraft Ident.: F-MBSD | Si tu veux. Le voilà :
Code :
- Private m_strRemoteHost As String 'the web server to connect to
- Private m_strFilePath As String 'relative path to the file to retrieve
- Private m_strHttpResponse As String 'the server response
- Private m_bResponseReceived As Boolean
- Private m_strRemotePort As String
- Private fileType As String
- Private currentDoc As String
- Private m_bytes() As Byte
- Private dom As DOMDocument
- Private canRefresh As Boolean
- Private language As String * 3
- Const siteRoot = "http://gemseas-devl.euro.med.ge.com:8081/egx/"
- Private Type t_lp
- login As String * 30
- pass As String * 30
- language As String * 3
- End Type
- Private Sub Command1_Click()
- Dim tabpro() As String
- Dim i As Integer
- Dim strURL As String
- Dim errMsg As String
- Dim errNb As Integer
- Dim nbDocs As Integer
-
- If codpro.Text = "" Then
- fillCodpro
- End If
- errNb = 0
- nbDocs = 0
- If Len(Trim(codpro.Text)) = 0 Then
- MsgBox ("Please type at least a product code." )
- codpro.Text = ""
- Exit Sub
- End If
- tabpro = Split(UCase(codpro.Text), "," )
- ProgressBar1.Max = UBound(tabpro) + 1
- ProgressBar2.Max = 3
- On Error GoTo ERROR_HANDLER
- If Not auth(errMsg) Then
- errNb = errNb + 1
- MsgBox errMsg
- codpro.Text = ""
- Exit Sub
- End If
- For i = LBound(tabpro) To UBound(tabpro)
- currentDoc = Trim(tabpro(i))
- ProgressBar1.Value = i
- Label5.Caption = currentDoc
- If Trim(currentDoc) <> "" Then
- nbDocs = nbDocs + 1
- downLoadFile siteRoot & "W_PRO_SPR_D_print.asp?CHP:CODPRO=" & currentDoc & "&LOG=" & Text1.Text & "&PASS=" & Text2.Text & "&CODLAN=" & language, "root"
- If fileType = "root" Then
- If m_strHttpResponse = "404" Then
- MsgBox "Product " & currentDoc & " doesn't exist."
- errNb = errNb + 1
- Else
- If Not FileExists(App.Path & "\documents\" & currentDoc) Then
- MkDir App.Path & "\documents\" & currentDoc
- End If
- saveFile getLinks(getImages(getCSS(m_strHttpResponse))), currentDoc & ".doc", App.Path & "\documents\"
- End If
- End If
- End If
- Next
- EXIT_LABEL:
- If errNb = 0 Then
- MsgBox "Documents downloaded successfully"
- Else
- MsgBox nbDocs - errNb & " documents downloaded and " & errNb & " aborted on error."
- End If
- codpro.Text = ""
- Exit Sub
-
- ERROR_HANDLER:
- If Err.Number = 5 Then
- strURL = strURL & "/"
- Resume 0
- Else
- MsgBox "Error was occurred." & vbCrLf & _
- "Error #: " & Err.Number & vbCrLf & _
- "Description: " & Err.Description, vbExclamation
- GoTo EXIT_LABEL
- End If
- End Sub
- Sub downLoadFile(url As String, lfileType As String)
- Dim objRegExp As RegExp
- Dim objMatch As Match
- Dim colMatches As MatchCollection
-
- url = Replace(url, " ", "%20" )
- Set objRegExp = New RegExp
- objRegExp.Pattern = "(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)"
- objRegExp.IgnoreCase = True
- objRegExp.Global = True
-
- If objRegExp.Test(url) Then
-
- m_strProtocol = objRegExp.Replace(url, "$1" )
- m_strRemoteHost = objRegExp.Replace(url, "$2" )
- m_strRemotePort = objRegExp.Replace(url, "$3" )
- m_strFilePath = objRegExp.Replace(url, "$4" )
-
- If Len(m_strRemotePort) = 0 Then
- m_strRemotePort = "80"
- Else
- m_strRemotePort = Right(m_strRemotePort, Len(m_strRemotePort) - 1)
- End If
-
- fileType = lfileType
-
- m_strHttpResponse = ""
- m_bResponseReceived = False
-
- With wscHttp
- .Close
- .LocalPort = 0
- .Connect m_strRemoteHost, m_strRemotePort
- Do While .State < 8
- DoEvents
- Loop
- If .State = 9 Then
- MsgBox ("Error: Disconnected from server." )
- End If
- End With
- Else
- If LCase(Left(url, 7)) <> "mailto:" Then
- On Error GoTo ERR_HANDLER_DWL
- ReDim m_bytes(FileLen(url))
- intFile = FreeFile
- Open url For Binary Access Read As #intFile
- Get #intFile, , m_bytes
- Close #intFile
- m_strHttpResponse = "m_bytes()"
- Else
- m_strHttpResponse = ""
- End If
- End If
-
- Exit Sub
- ERR_HANDLER_DWL:
- m_strHttpResponse = ""
- End Sub
- Private Sub Form_Load()
- Dim intFile As Integer
- Dim lp As t_lp
-
- canRefresh = True
- Load frmSplash
- frmSplash.Show
- frmSplash.Refresh
-
- On Error GoTo noFile
- intFile = FreeFile
- Open App.Path & "\documents\_" For Random As #intFile
- Get #intFile, , lp
- Close #intFile
-
- Text1.Text = Trim(lp.login)
- Text2.Text = Trim(lp.pass)
- language = Trim(lp.language)
- If language = "" Then
- language = "ENG"
- End If
- On Error GoTo 0
-
- Set dom = New DOMDocument
-
- dom.async = False
- If Not dom.Load(siteRoot & "bin/menus.xml.asp?CODLAN=" & language) Then
- MsgBox "Can't contact server, or data error. Can't initialize filters."
- End
- End If
-
- refreshFilters
- Unload frmSplash
- Exit Sub
- noFile:
- Close #intFile
- Text1.Text = ""
- Text2.Text = ""
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Dim intFile As Integer
- Dim lp As t_lp
-
- lp.login = Text1.Text
- lp.pass = Text2.Text
- lp.language = language
-
- On Error GoTo noFile
- intFile = FreeFile
- Open App.Path & "\documents\_" For Random As #intFile
- Put #intFile, , lp
- Close #intFile
- End
- Exit Sub
- noFile:
- Close #intFile
- MsgBox "Can't save your settings !"
- End
- End Sub
- Private Sub ImageCombo1_Click()
- refreshFilters
- End Sub
- Private Sub ImageCombo2_Click()
- refreshFilters
- End Sub
- Private Sub ImageCombo3_Click()
- refreshFilters
- End Sub
- Private Sub ImageCombo4_Click()
- If ImageCombo4.SelectedItem.Key <> "" Then
- canRefresh = True
- Load frmSplash
- frmSplash.Show
- frmSplash.Refresh
-
- Set dom = New DOMDocument
-
- dom.async = False
- If Not dom.Load(siteRoot & "bin/menus.xml.asp?CODLAN=" & ImageCombo4.SelectedItem.Key) Then
- MsgBox "Can't contact server, or data error. Can't initialize filters."
- End
- End If
-
- Unload frmSplash
- End If
- refreshFilters
- End Sub
- Private Sub ImageCombo5_Click()
- refreshFilters
- End Sub
- Private Sub wscHttp_Close()
- Dim strHttpResponseHeader As String
-
- If Not m_bResponseReceived Then
- strHttpResponseHeader = Left$(m_strHttpResponse, _
- InStr(1, m_strHttpResponse, _
- vbCrLf & vbCrLf) - 1)
- m_strHttpResponse = Mid(m_strHttpResponse, _
- InStr(1, m_strHttpResponse, _
- vbCrLf & vbCrLf) + 4)
- m_bResponseReceived = True
- End If
- End Sub
- Private Sub wscHttp_Connect()
- Dim strHttpRequest As String
-
- strHttpRequest = "GET " & m_strFilePath & " HTTP/1.1" & vbCrLf
- strHttpRequest = strHttpRequest & "Host: " & m_strRemoteHost & vbCrLf
- strHttpRequest = strHttpRequest & "Connection: close" & vbCrLf
- strHttpRequest = strHttpRequest & "Accept: */*" & vbCrLf
- strHttpRequest = strHttpRequest & vbCrLf
- wscHttp.SendData strHttpRequest
- End Sub
- Private Sub wscHttp_DataArrival(ByVal bytesTotal As Long)
- On Error Resume Next
-
- Dim strData As String
-
- wscHttp.GetData strData
- m_strHttpResponse = m_strHttpResponse & strData
- End Sub
- Sub saveFile(content As String, fileName As String, filePath As String)
- If LCase(Left(fileName, 7)) <> "mailto:" Then
- If content <> "m_bytes()" Then
- intFile = FreeFile
- Open filePath & fileName For Binary Access Write As #intFile
- Put #intFile, , content
- Close #intFile
- Else
- intFile = FreeFile
- Open filePath & fileName For Binary Access Write As #intFile
- Put #intFile, , m_bytes
- Close #intFile
- End If
- End If
- End Sub
- Function getImages(ByRef document As String)
- Dim objRegExp As RegExp
- Dim objMatch As Match
- Dim colMatches As MatchCollection
- Dim myDoc As String
- Dim myDoc2 As String
- Dim imgFileName As String
- Dim j As Integer
-
- ProgressBar2.Value = 2
- Label6.Caption = "Pictures"
-
- myDoc = document
- myDoc2 = document
- Set objRegExp = New RegExp
- objRegExp.Pattern = "(<img[^>]*?src=['|""])([^'|^""]+?)(['|""].*?> )"
- objRegExp.IgnoreCase = True
- objRegExp.Global = True
-
- If (objRegExp.Test(myDoc2)) Then
- Set colMatches = objRegExp.Execute(myDoc2)
- j = 0
- ProgressBar3.Max = colMatches.Count
- For Each objMatch In colMatches
- imgFileName = Right(objRegExp.Replace(objMatch.Value, "$2" ), Len(objRegExp.Replace(objMatch.Value, "$2" )) - InStrRev(Replace(objRegExp.Replace(objMatch.Value, "$2" ), "\", "/" ), "/" ))
- j = j + 1
- ProgressBar3.Value = j
- Label7.Caption = imgFileName
- frmMain.Refresh
- myDoc = Replace(myDoc, objMatch.Value, objRegExp.Replace(objMatch.Value, "$1" & currentDoc & "\" & imgFileName & "$3" ), 1, 1)
- downLoadFile objRegExp.Replace(objMatch.Value, "$2" ), "img"
- saveFile m_strHttpResponse, imgFileName, App.Path & "\documents\" & currentDoc & "\"
- Next
- End If
- getImages = myDoc
- End Function
- Function getCSS(ByVal document As String) As String
- Dim objRegExp As RegExp
- Dim objMatch As Match
- Dim colMatches As MatchCollection
- Dim myDoc As String
- Dim myDoc2 As String
- Dim cssFileName As String
- Dim j As Integer
-
- ProgressBar2.Value = 1
- Label6.Caption = "Layout"
-
- myDoc = document
- myDoc2 = document
- Set objRegExp = New RegExp
- objRegExp.Pattern = "(<link[^>]*?href=['|""])([^'|^""]+?)(['|""].*?> )"
- objRegExp.IgnoreCase = True
- objRegExp.Global = True
-
- If (objRegExp.Test(myDoc2)) Then
- Set colMatches = objRegExp.Execute(myDoc2)
- j = 0
- ProgressBar3.Max = colMatches.Count
- For Each objMatch In colMatches
- cssFileName = Right(objRegExp.Replace(objMatch.Value, "$2" ), Len(objRegExp.Replace(objMatch.Value, "$2" )) - InStrRev(Replace(objRegExp.Replace(objMatch.Value, "$2" ), "\", "/" ), "/" ))
- j = j + 1
- ProgressBar3.Value = j
- Label7.Caption = cssFileName
- frmMain.Refresh
- myDoc = Replace(myDoc, objMatch.Value, objRegExp.Replace(objMatch.Value, "$1" & currentDoc & "\" & cssFileName & "$3" ), 1, 1)
- downLoadFile objRegExp.Replace(objMatch.Value, "$2" ), "css"
- saveFile m_strHttpResponse, cssFileName, App.Path & "\documents\" & currentDoc & "\"
- Next
- End If
- getCSS = myDoc
- End Function
- Function getLinks(ByRef document As String)
- Dim objRegExp As RegExp
- Dim objMatch As Match
- Dim colMatches As MatchCollection
- Dim myDoc As String
- Dim myDoc2 As String
- Dim linkFileName As String
- Dim j As Integer
-
- ProgressBar2.Value = 3
- Label6.Caption = "Documents"
-
- myDoc = document
- myDoc2 = document
- Set objRegExp = New RegExp
- objRegExp.Pattern = "(<a[^>]*?href=['|""])([^'|^""]+?)(['|""].*?> )"
- objRegExp.IgnoreCase = True
- objRegExp.Global = True
- If (objRegExp.Test(myDoc2)) Then
- Set colMatches = objRegExp.Execute(myDoc2)
- j = 0
- ProgressBar3.Max = colMatches.Count
- For Each objMatch In colMatches
- linkFileName = Right(objRegExp.Replace(objMatch.Value, "$2" ), Len(objRegExp.Replace(objMatch.Value, "$2" )) - InStrRev(Replace(objRegExp.Replace(objMatch.Value, "$2" ), "\", "/" ), "/" ))
- j = j + 1
- ProgressBar3.Value = j
- Label7.Caption = linkFileName
- frmMain.Refresh
- myDoc = Replace(myDoc, objMatch.Value, objRegExp.Replace(objMatch.Value, "$1" & currentDoc & "\" & linkFileName & "$3" ), 1, 1)
- downLoadFile objRegExp.Replace(objMatch.Value, "$2" ), "link"
- saveFile m_strHttpResponse, linkFileName, App.Path & "\documents\" & currentDoc & "\"
- Next
- End If
- getLinks = myDoc
- End Function
- Function auth(ByRef errMsg As String) As Boolean
- downLoadFile siteRoot & "verifLogin.asp?log=" & Text1.Text & "&pass=" & Text2.Text, ""
- errMsg = m_strHttpResponse
- If errMsg = "OK" Then
- auth = True
- Else
- auth = False
- End If
- End Function
- Public Function FileExists(ByVal strFileName As String) As Boolean
- Dim dtm As Date
- On Error GoTo ErrHandler
- dtm = FileSystem.FileDateTime(strFileName)
- FileExists = True
- Exit Function
- ErrHandler:
- FileExists = False
- End Function
- Sub refreshFilters()
- Dim fam As String
- Dim sfa As String
- Dim ssf As String
- Dim bt As String
-
- If canRefresh Then
- canRefresh = False
- If ImageCombo1.SelLength <> 0 Then
- fam = ImageCombo1.SelectedItem.Key
- End If
- If ImageCombo2.SelLength <> 0 Then
- sfa = ImageCombo2.SelectedItem.Key
- End If
- If ImageCombo3.SelLength <> 0 Then
- ssf = ImageCombo3.SelectedItem.Key
- End If
- If ImageCombo4.SelLength <> 0 Then
- language = ImageCombo4.SelectedItem.Key
- End If
- If ImageCombo5.SelLength <> 0 Then
- bt = ImageCombo5.SelectedItem.Key
- End If
-
- ImageCombo1.ComboItems.Clear
- ImageCombo2.ComboItems.Clear
- ImageCombo3.ComboItems.Clear
- ImageCombo4.ComboItems.Clear
- ImageCombo5.ComboItems.Clear
-
- ' Families
- fillFamily fam, sfa, ssf
- fillBT bt
- fillLanguage language
-
- ImageCombo1.Refresh
- ImageCombo2.Refresh
- ImageCombo3.Refresh
- ImageCombo4.Refresh
- ImageCombo5.Refresh
-
- canRefresh = True
- End If
- End Sub
- Sub fillFamily(fam As String, sfa As String, ssf As String)
- Dim myItem As ComboItem
- Dim el
- Dim curItem As Integer
-
- curItem = 1
- Set myItem = ImageCombo1.ComboItems.Add(, "", "All" )
- myItem.Selected = True
- For Each el In dom.selectSingleNode("interface/families" ).childNodes
- curItem = curItem + 1
- If el.tagName = "fam" Then
- Set myItem = ImageCombo1.ComboItems.Add(, el.Attributes(0).Value, el.Attributes(1).Value)
- If myItem.Key = fam Then
- myItem.Selected = True
- End If
- End If
- Next
-
- fillSubFamily fam, sfa, ssf
- End Sub
- Sub fillSubFamily(fam As String, sfa As String, ssf As String)
- Dim myItem As ComboItem
- Dim el
- Dim el2
- Dim curItem As Integer
-
- curItem = 1
- Set myItem = ImageCombo2.ComboItems.Add(, "", "All" )
- myItem.Selected = True
-
- If fam <> "" Then
- For Each el In dom.selectSingleNode("interface/families" ).childNodes
- If el.tagName = "fam" Then
- If el.Attributes(0).Value = fam Then
- For Each el2 In el.childNodes
- curItem = curItem + 1
- If el2.tagName = "sfa" Then
- Set myItem = ImageCombo2.ComboItems.Add(, el2.Attributes(0).Value, el2.Attributes(1).Value)
- If myItem.Key = sfa Then
- myItem.Selected = True
- End If
- End If
- Next
-
- End If
- End If
- Next
- End If
-
- fillSubSubFamily fam, sfa, ssf
- End Sub
- Sub fillSubSubFamily(fam As String, sfa As String, ssf As String)
- Dim myItem As ComboItem
- Dim el
- Dim el2
- Dim el3
- Dim curItem As Integer
-
- curItem = 1
- Set myItem = ImageCombo3.ComboItems.Add(, "", "All" )
- myItem.Selected = True
-
- If fam <> "" And sfa <> "" Then
- For Each el In dom.selectSingleNode("interface/families" ).childNodes
- If el.tagName = "fam" Then
- If el.Attributes(0).Value = fam Then
- For Each el2 In el.childNodes
- If el2.tagName = "sfa" Then
- If el2.Attributes(0).Value = sfa Then
- For Each el3 In el2.childNodes
- curItem = curItem + 1
- If el3.tagName = "ssf" Then
- Set myItem = ImageCombo3.ComboItems.Add(, el3.Attributes(0).Value, el3.Attributes(1).Value)
- If myItem.Key = ssf Then
- myItem.Selected = True
- End If
- End If
- Next
- End If
- End If
- Next
- End If
- End If
- Next
- End If
- End Sub
- Sub fillLanguage(language As String)
- Dim myItem As ComboItem
- Dim el
- Dim curItem As Integer
-
- curItem = 1
- For Each el In dom.selectSingleNode("interface/languages" ).childNodes
- curItem = curItem + 1
- If el.tagName = "lan" Then
- Set myItem = ImageCombo4.ComboItems.Add(, el.Attributes(0).Value, el.Attributes(1).Value)
- If myItem.Key = language Then
- myItem.Selected = True
- End If
- End If
- Next
- End Sub
- Sub fillBT(bt As String)
- Dim myItem As ComboItem
- Dim el
- Dim curItem As Integer
-
- curItem = 1
- Set myItem = ImageCombo5.ComboItems.Add(, "", "All" )
- myItem.Selected = True
- For Each el In dom.selectSingleNode("interface/bts" ).childNodes
- curItem = curItem + 1
- If el.tagName = "bt" Then
- Set myItem = ImageCombo5.ComboItems.Add(, el.Attributes(0).Value, el.Attributes(1).Value)
- If myItem.Key = bt Then
- myItem.Selected = True
- End If
- End If
- Next
- End Sub
- Sub fillCodpro()
- Dim inet As InternetExplorer
-
- Set inet = New InternetExplorer
- inet.Visible = False
- inet.Navigate siteRoot & "bin/codpros.asp?FAM=" & ImageCombo1.SelectedItem.Key & "&SFA=" & ImageCombo2.SelectedItem.Key & "&SSF=" & ImageCombo3.SelectedItem.Key & "&BT=" & ImageCombo5.SelectedItem.Key
- Do While Not inet.readyState = READYSTATE_COMPLETE
- DoEvents
- Loop
- codpro.Text = inet.document.body.innerHTML
- End Sub
|
PS: j'ai laissé les url et tout, m'en fout c'est des adresses internes
PS²: Par contre, c'est loin de faire ce que tu veux à mon avis, ce programme sert à télécharger des documents à partir d'une appli intranet, donc c'est pas du tout gééraliste, à mon avis tu ne pourras pas en faire grand chose Message édité par Arjuna le 15-04-2004 à 11:03:56
|