Private Sub BtnRestore_Click(sender As Object, e As EventArgs) Handles BtnRestore.Click
If MsgBox("هل تريد عمل نسخة احتياطية قبل عملية الاستعادة", MsgBoxStyle.YesNo + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "استعادة نسخة احتياطية") = MsgBoxResult.Yes Then
If Label1.Text.Length = 0 Then
Button1.PerformClick()
End If
BtnBackup.PerformClick()
End If
Dim data As String = "data11.mdb"
Dim mdbnew As String = ""
If File.Exists(data) Then
File.Delete(data)
End If
Dim opfd As New OpenFileDialog
opfd.Filter = "Zip File *.Zip|*.Zip"
If opfd.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Using zip As ZipFile = ZipFile.Read(opfd.FileName)
zip.ExtractAll(Application.StartupPath) 'zip_entry.Extract'
End Using
mdbnew = opfd.SafeFileName
mdbnew = mdbnew.Replace("zip", "Mol")
My.Computer.FileSystem.RenameFile(Application.StartupPath & "\" & mdbnew, "data11.mdb")
End If
MessageBox.Show("تم إستعادة النسخة الاحتياطية بنجاح", "تم", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub BtnBackup_Click(sender As Object, e As EventArgs) Handles BtnBackup.Click
If IO.Directory.Exists(Label1.Text + "\data11.mdb") = False Then
IO.Directory.CreateDirectory(Label1.Text)
End If
If IO.File.Exists(Application.StartupPath & "\Compact_data11.mdb") Then
IO.File.Delete(Application.StartupPath & "\Compact_data11.mdb")
End If
Dim Engine
Engine = CreateObject("JRO.JetEngine")
Engine.CompactDatabase("provider=microsoft.Jet.oledb.4.0;data source=" & Application.StartupPath & "\data11.mdb;user id=admin;jet oledb:database password=343282",
"provider=microsoft.Jet.oledb.4.0;data source=" & Application.StartupPath & "\Compact_data11.mdb;user id=admin;jet oledb:database password=343282")
Dim DBFilename, NewFileName As String
DBFilename = Application.StartupPath & "\Compact_data11.mdb"
NewFileName = Label1.Text + "\data11.mdb"
NewFileName = "data11" & Now.ToString("@yyyy-MM-dd@HH-mm-ss") & ".Mol"
NewFileName = Label1.Text + "\data11" & Now.ToString("(yyyy-MM-dd) (HH-mm-ss)") & ".Mol"
Dim sr As New IO.FileStream(DBFilename, IO.FileMode.Open) 'source file'
Dim sw As New IO.FileStream(NewFileName, IO.FileMode.Create) 'target file, defaults overwrite'
Dim len As Long = sr.Length - 1
ProgressBar1.Visible = True
For i As Long = 0 To len
sw.WriteByte(sr.ReadByte)
If i Mod 1000 = 0 Then
ProgressBar1.Value = i * 100 / len
Application.DoEvents()
Label6.Text = ProgressBar1.Value & "% تمّت عمليّة ضغط قاعدة البيانات "
End If
Next
ProgressBar1.Value = 0
ProgressBar1.Visible = False
sr.Close()
' كود معرفة حجم قاعدة البيانات بعد ضغطها'
Dim sc As New IO.FileStream(Application.StartupPath & "\data11.mdb", FileMode.Open)
Dim x As String
x = sc.Length / 1024
sc.Close()
'كود حذف قاعدة البيانات القديمة'
IO.File.Delete(Application.StartupPath & "\data11.mdb")
'كود اعادة تسمية قاعدة البيانات التي تم ضغطها واصلاحها'
My.Computer.FileSystem.RenameFile(Application.StartupPath & "\Compact_data11.mdb", "data11.mdb")
Label5.Text = x & " " & " ك.ب "
Label8.Text = sw.Length / 1024 & " ك.ب "
Label6.Text = ""
Label7.Text = NewFileName
Label2.Text = Now.ToString("(yyyy-MM-dd) (H H-mm-ss)")
Dim Open As New OpenFileDialog
Dim dir As New DirectoryInfo(Label1.Text)
Control.CheckForIllegalCrossThreadCalls = False
If b.IsBusy = False Then
b.RunWorkerAsync()
End If
Using zip As ZipFile = New ZipFile(Label1.Text & "\data11" & Now.ToString("(yyyy-MM-dd) (HH-mm-ss)") & ".zip")
' Add the file to the Zip archive's root folder.'
zip.AddFile(NewFileName, "")
' Save the Zip file.
zip.Save()
End Using
MsgBox("تم ضغط واصلاح ونسخ قاعدة البيانات بنجاح " & vbCrLf & vbCrLf & NewFileName & " مكان نسخ القاعدة" & vbCrLf & "حجم قاعدة البيانات قبل الضغط " & x & " ك.ب " & vbCrLf & "حجم قاعدة البيانات بعد الضغط " & sw.Length / 1024 & " ك.ب ", 64 + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading, "النّسخ الإحتياطي")
sr.Close()
sw.Close()
System.IO.File.Delete(NewFileName)
End Sub