17-07-18, 09:33 PM
السلام عليكم ورحمة الله وبركاته
مثال سريع يحتوي كافة الملفات اللازمة
تذكر انك تحتاج للتعديل على خيارات mysql وبعض مافي جملة الاتصال
والتالي كلاس الفورم
PHP كود :
Imports MySql.Data.MySqlClient
Public Class Form1
Private Function gname() As String
Dim t As String = Now.Year & Now.Month & Now.Day & Now.Hour & Now.Minute & Now.Second & Now.Millisecond
Return t
End Function
Dim constr As String = ""
Dim dbpath As String = ""
Dim sconstr As String = ""
Private Sub pic1(ByVal l As Boolean)
If pic.InvokeRequired Then
pic.Invoke(New Action(Of Boolean)(AddressOf pic1), l)
Else
pic.Visible = l
End If
End Sub
Private Sub lbl1(ByVal l As String)
If lbl.InvokeRequired Then
lbl.Invoke(New Action(Of String)(AddressOf lbl1), l)
Else
lbl.Text = l
End If
End Sub
Private Sub lblc(ByVal l As Color)
If lbl.InvokeRequired Then
lbl.Invoke(New Action(Of Color)(AddressOf lblc), l)
Else
lbl.ForeColor = l
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fbd As New FolderBrowserDialog
If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
txtdbpath.Text = fbd.SelectedPath & "\"
End If
My.Settings.Apath = txtdbpath.Text
My.Settings.Save()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If MsgBox("متاكد من بدء النسخ؟", MsgBoxStyle.Critical + MsgBoxStyle.YesNo) = MsgBoxResult.No Then Exit Sub
If b1.IsBusy = False Then
For Each h As Control In Me.Controls
If TypeOf h Is Button Then
h.Enabled = False
End If
Next
constr = txtconstr.Text
dbpath = txtdbpath.Text
b1.RunWorkerAsync()
End If
End Sub
Private Sub b1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles b1.DoWork
pic1(True)
lbl1("النسخ يعمل")
lblc(Color.Red)
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand()
Using mb As New MySqlBackup(cmd)
cmd.Connection = con
If con.State = ConnectionState.Closed Then con.Open()
mb.ExportToFile(dbpath & gname() & "_vb4arb.sql")
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Using
End Sub
Private Sub b1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles b1.RunWorkerCompleted
pic1(False)
lbl1("إنتهى النسخ او التصدير او سحب القاعدة")
lblc(Color.Green)
Me.Invoke(New MethodInvoker(Sub()
For Each h As Control In Me.Controls
If TypeOf h Is Button Then
h.Enabled = True
End If
Next
End Sub))
End Sub
Dim fname As String = ""
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
If MsgBox("متاكد من بدء الاسترجاع؟", MsgBoxStyle.Critical + MsgBoxStyle.YesNo) = MsgBoxResult.No Then Exit Sub
Dim f As New OpenFileDialog
If f.ShowDialog = Windows.Forms.DialogResult.OK Then
fname = f.FileName
End If
If b2.IsBusy = False Then
For Each h As Control In Me.Controls
If TypeOf h Is Button Then
h.Enabled = False
End If
Next
sconstr = txtsconstr.Text
b2.RunWorkerAsync()
End If
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
txtdbpath.Text = My.Settings.Apath
End Sub
Private Sub b2_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles b2.DoWork
pic1(True)
lbl1("الاسترجاع يعمل")
lblc(Color.Red)
Using con As New MySqlConnection(sconstr)
Using cmd As New MySqlCommand()
Using mb As New MySqlBackup(cmd)
cmd.Connection = con
If con.State = ConnectionState.Closed Then con.Open()
' mb.ExportToFile(dbpath & gname() & ".sql")
mb.ImportFromFile(fname)
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Using
End Sub
Private Sub b2_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles b2.RunWorkerCompleted
pic1(False)
lbl1("إنتهى الاسترجاع")
lblc(Color.Green)
Me.Invoke(New MethodInvoker(Sub()
For Each h As Control In Me.Controls
If TypeOf h Is Button Then
h.Enabled = True
End If
Next
End Sub))
End Sub
End Class