Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SYS-UPDATE.vb 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Imports System.IO
  2. Imports System.Net
  3. Imports System.Threading.Tasks
  4. Public Class SYS_UPDATE
  5. ReadOnly ds2 As New DataSet
  6. Private Sub Set_清單1()
  7. FDT_dgv.DataSource = Nothing : ds2.Clear()
  8. FDT_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  9. FDT_dgv.ColumnHeadersHeight = 25
  10. FDT_dgv.AllowUserToAddRows = False
  11. SQL_FTP資料夾路徑分配()
  12. da.Fill(ds2) : FDT_dgv.DataSource = ds2.Tables(0) : conn.Close()
  13. End Sub
  14. Private Sub SYS_UPDATE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  15. 資料數 = 5
  16. Target = "https://gcm-smart.com/ERP/BIFENG/"
  17. End Sub
  18. Private Async Sub SYS_UPDATE_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  19. MyModule1.進度條() : Delay(30000)
  20. MyModule1.進度條() : Dim Str As String = Application.StartupPath
  21. MyModule1.進度條() : If File.Exists(Str + "\BIFENG-ERP-SYS.exe") Then : File.Delete(Str + "\BIFENG-ERP-SYS.exe") : End If
  22. Dim downloadUrl As String = Target & "BIFENG-ERP-SYS.exe"
  23. Dim savePath As String = Str + "\BIFENG-ERP-SYS.exe"
  24. ' 開始異步下載
  25. Await DownloadFileAsync(downloadUrl, savePath)
  26. MyModule1.進度條() : Shell(Str + "\BIFENG-ERP-SYS.exe", vbNormalFocus)
  27. Me.Close()
  28. End Sub
  29. Private WithEvents downloader As New WebClient()
  30. Private Async Function DownloadFileAsync(downloadUrl As String, savePath As String) As Task
  31. Try
  32. ' 使用異步方式下載檔案
  33. Await downloader.DownloadFileTaskAsync(New Uri(downloadUrl), savePath)
  34. ' 下載完成後的處理
  35. MessageBox.Show("下載完成!")
  36. Catch ex As Exception
  37. MessageBox.Show($"下載失敗: {ex.Message}")
  38. End Try
  39. End Function
  40. Public Sub Delay(ByRef Interval As Double) 'Interval单位为毫秒
  41. Dim time As DateTime = DateTime.Now
  42. Dim Span As Double = Interval * 1234
  43. While ((DateTime.Now.Ticks - time.Ticks) < Span)
  44. Application.DoEvents()
  45. End While
  46. End Sub
  47. End Class