1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- Imports System.IO
- Imports System.Net
- Imports System.Threading.Tasks
- Public Class SYS_UPDATE
- ReadOnly ds2 As New DataSet
- Private Sub Set_清單1()
- FDT_dgv.DataSource = Nothing : ds2.Clear()
- FDT_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- FDT_dgv.ColumnHeadersHeight = 25
- FDT_dgv.AllowUserToAddRows = False
- SQL_FTP資料夾路徑分配()
- da.Fill(ds2) : FDT_dgv.DataSource = ds2.Tables(0) : conn.Close()
- End Sub
- Private Sub SYS_UPDATE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- 資料數 = 5
- Target = "https://gcm-smart.com/ERP/BIFENG/"
- End Sub
- Private Async Sub SYS_UPDATE_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
- MyModule1.進度條() : Delay(30000)
- MyModule1.進度條() : Dim Str As String = Application.StartupPath
- MyModule1.進度條() : If File.Exists(Str + "\BIFENG-ERP-SYS.exe") Then : File.Delete(Str + "\BIFENG-ERP-SYS.exe") : End If
- Dim downloadUrl As String = Target & "BIFENG-ERP-SYS.exe"
- Dim savePath As String = Str + "\BIFENG-ERP-SYS.exe"
- ' 開始異步下載
- Await DownloadFileAsync(downloadUrl, savePath)
- MyModule1.進度條() : Shell(Str + "\BIFENG-ERP-SYS.exe", vbNormalFocus)
- Me.Close()
- End Sub
- Private WithEvents downloader As New WebClient()
- Private Async Function DownloadFileAsync(downloadUrl As String, savePath As String) As Task
- Try
- ' 使用異步方式下載檔案
- Await downloader.DownloadFileTaskAsync(New Uri(downloadUrl), savePath)
- ' 下載完成後的處理
- MessageBox.Show("下載完成!")
- Catch ex As Exception
- MessageBox.Show($"下載失敗: {ex.Message}")
- End Try
- End Function
- Public Sub Delay(ByRef Interval As Double) 'Interval单位为毫秒
- Dim time As DateTime = DateTime.Now
- Dim Span As Double = Interval * 1234
- While ((DateTime.Now.Ticks - time.Ticks) < Span)
- Application.DoEvents()
- End While
- End Sub
- End Class
|