تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟
#7
(04-10-18, 10:01 PM)rnmr كتب : وظيفة الكود يظهر نافذة النسخ أو النقل الخاصة بالنظام والذي هو يمتلك تزامن عملية النقل أو النسخ.

جرب هذا


https://stackoverflow.com/a/34939234
كود :
Dim [sourceFile] As String = Application.StartupPath & "/A18.accdb"
Dim [targetFile] As String = "D:\Backup\BupDB-" & Now.Date.ToString("dd-MM-yyyy") & "A18.accdb"

CopyFileWithProgress([sourceFile], [targetFile], Me.ProgressBar1)
كود :
Private Sub CopyFileWithProgress([sourceFile] As String, [targetFile] As String, [progress] As ProgressBar)
   'Create the file stream for the source file
   Dim streamRead As New System.IO.FileStream([sourceFile], System.IO.FileMode.Open)
   'Create the file stream for the destination file
   Dim streamWrite As New System.IO.FileStream([targetFile], System.IO.FileMode.Create)
   'Determine the size in bytes of the source file (-1 as our position starts at 0)
   Dim lngLen As Long = streamRead.Length - 1
   Dim byteBuffer(1048576) As Byte   'our stream buffer
   Dim intBytesRead As Integer    'number of bytes read

   While streamRead.Position < lngLen    'keep streaming until EOF
       'Read from the Source
       intBytesRead = (streamRead.Read(byteBuffer, 0, 1048576))
       'Write to the Target
       streamWrite.Write(byteBuffer, 0, intBytesRead)
       'Display the progress
       [progress].Value = CInt(streamRead.Position / lngLen * 100)
       Application.DoEvents()    'do it
   End While

   'Clean up
   streamWrite.Flush()
   streamWrite.Close()
   streamRead.Close()
End Sub
جزاك الله خيراً أخي [b]rnmr، الكود يعمل بشكل صحيح، سامحني أتعبتك معي، يسر الله لك كل أمر ورزقك الهُدى والتُقى والعفاف والغنى.
[/b]

(04-10-18, 10:49 PM)princelovelorn كتب : جرب الطريقة التالية
كود :
   Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
       Try
           If My.Settings.BupDB < Now.Date Then
               If con.State = ConnectionState.Open Then con.Close()
               If (Not System.IO.Directory.Exists("D:\Backup\")) Then IO.Directory.CreateDirectory("D:\Backup\")
               My.Computer.FileSystem.CopyFile(Application.StartupPath & "/A18.accdb", "D:\Backup\BupDB-" & Now.Date.ToString("dd-MM-yyyy") & "A18.accdb", True)
           End If

           PBR()

       Catch ex As Exception
           MessageBox.Show(ex.Message, "رسالة الخطأ")
       End Try

   End Sub
   Sub PBR()
       With ProgressBar1
           .Minimum = 1
           .Maximum = 100000
           .Value = 1
           .Step = 1
           For i As Integer = .Minimum To .Maximum
               .PerformStep()
           Next i
       End With
       MsgBox("تمت العملية بنجاح")
   End Sub

مشكور أخي الغالي princelovelorn الكود يعمل مع فارق السرعة Wink مع الأخ الكريم [b][b]rnmr ، أسعدكما الله ورزقكما الجنة وأغناكما من فضله، و جزى الله خيراً أخانا elgokr ، فقد ساعدني بكود النسخ وحفزني على تطويره، (اسأل الله أن يجمعنا في الجنة إخوانًا على سُرُرٍ مُتقابلين ).[/b][/b]
عن أبي هريرة - رضي الله عنه - قال: قال رسول الله - صلى الله عليه وسلم -: ((كلمتان خفيفتان على اللسان، ثقيلتان في الميزان، حبيبتان إلى الرحمن: سبحان الله وبحمده، سبحان الله العظيم))؛ متفق عليه.

الرد }}}
تم الشكر بواسطة: elgokr , princelovelorn , ابو روضة


الردود في هذا الموضوع
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - بواسطة Hazem1 - 05-10-18, 12:18 AM


التنقل السريع :


يقوم بقرائة الموضوع: