كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - Hazem1 - 04-10-18
بسم الله الرحمن الرحيم
إخواني الكِرام هذا كود نسخ قاعدة البيانات :
PHP كود :
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
كيف يُمكن إدخال أداة ال Progress Bar كي تتزامن مع عملية نسخ قاعدة البيانات، لأني استطعت إدراجها ولكن مجرد شكل وليس بالتزامن، وجزاكم الله خيراً
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - rnmr - 04-10-18
جرب هذا
كود :
My.Computer.FileSystem.CopyFile(Application.StartupPath & "/A18.accdb", "D:\Backup\BupDB-" & Now.Date.ToString("dd-MM-yyyy") & "A18.accdb", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - Hazem1 - 04-10-18
(04-10-18, 09:47 PM)rnmr كتب : جرب هذا
كود :
My.Computer.FileSystem.CopyFile(Application.StartupPath & "/A18.accdb", "D:\Backup\BupDB-" & Now.Date.ToString("dd-MM-yyyy") & "A18.accdb", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
أخي الكريم rnmr هل ممكن توضح لي فائدة الكود في عملية الارتباط بأداة ال ProgressBar لأني أشعر أن وظيفته في إطار عملية النسخ.
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - rnmr - 04-10-18
وظيفة الكود يظهر نافذة النسخ أو النقل الخاصة بالنظام والذي هو يمتلك تزامن عملية النقل أو النسخ.
جرب هذا
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
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - Hazem1 - 04-10-18
(04-10-18, 10:01 PM)rnmr كتب : وظيفة الكود يظهر نافذة النسخ أو النقل الخاصة بالنظام والذي هو يمتلك تزامن عملية النقل أو النسخ.
وماذا تفرق معك طالما ترى عملية النسخ أو النقل أمامك.
أخي الكريم [b]rnmr ، عفواً لم أقصد أضايقك بالسؤال ولكن وددت أفهم الفائدة منه، وجزاك الله خيراً، المقصد أخي الفاضل هو استخدام أداة ال ProgressBar بحيث تظهر العد من 1 إلى 100 ولكن بشكلٍ حقيقي يتزامن فعلياً مع عملية النسخ وفقاً لحجم قاعدة البيانات، وليس بشكل وهمي، هذه الأكواد المُستخدمة ولكنها لا تتزامن مع عملية النسخ بشكل حقيقي[/b]
زر النسخ :
PHP كود :
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", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing) Timer1.Enabled = True
وهذا في أداة Timer :
PHP كود :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If ProgressBar1.Value <= ProgressBar1.Maximum - 1 Then ProgressBar1.Value += 1 End If End Sub
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - princelovelorn - 04-10-18
جرب الطريقة التالية
كود :
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
RE: كيف يُمكن أدخال أداة ال Progress Bar للتزامن مع نسخ قاعدة بيانات الأكسس؟ - Hazem1 - 05-10-18
(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 الكود يعمل مع فارق السرعة مع الأخ الكريم [b][b]rnmr ، أسعدكما الله ورزقكما الجنة وأغناكما من فضله، و جزى الله خيراً أخانا elgokr ، فقد ساعدني بكود النسخ وحفزني على تطويره، (اسأل الله أن يجمعنا في الجنة إخوانًا على سُرُرٍ مُتقابلين ).[/b][/b]
|