Option Explicit On
Option Strict On
Imports System.IO
Imports System.IO.StreamWriter
Imports System.Windows.Forms
Public Class frmSeguridad
Implements IDisposable
Private Shadows disposed As Boolean = False
Private objReg As New GestionaReg.Tablas.EntreTablas
Private respaldar As New SaveFileDialog
Public Sub New()
MyBase.New
InitializeComponent()
Me.SuspendLayout()
Me.StartPosition = FormStartPosition.WindowsDefaultLocation
Me.ClientSize = New System.Drawing.Size(650, 230)
Me.ResumeLayout(False)
AddHandler btnbackup.Click, AddressOf Backup
AddHandler btnRestore.Click, AddressOf Restore
AddHandler btnSalir.Click, AddressOf Salir
End Sub
Private Sub frmSeguridad_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Backup(sender As System.Object, e As System.EventArgs)
Try
Dim cmd As String
Dim carpeta As New FolderBrowserDialog
Dim miFecha As String = Format(Now.Today, "dd/MM/yyyy")
MessageBox.Show("Ahora tiene que buscar la ubicación donde depositara el Backup")
carpeta.ShowDialog()
txtDestino.Text = carpeta.SelectedPath & "\" & "Fincas" & "_" & miFecha & ".sql"
If MessageBox.Show("¿Es correcto el destino del Backup?", "Backup BD", MessageBoxButtons.YesNo) = MsgBoxResult.Yes Then
Open()
cmd = "C:\Archivos de Programa\Mariadb 10.1\Bin\mysqldump -user=root -password= -host=localhost -database=fincas > """ & txtDestino.Text & """"
Shell(cmd, AppWinStyle.MaximizedFocus, True)
If objReg.ExisteFile(txtDestino.Text) = True Then
MsgBox("El Backup se ejecuto correctamente", MsgBoxStyle.Information, "Proceso finalizado")
Else
MsgBox("Ocurrio un error inesperado en la creación del Backup", MsgBoxStyle.Critical, "Informacion")
End If
Close()
Else
txtDestino.Text = ""
cmd = Nothing
MsgBox("Intente de nuevo la creación del Backup", MsgBoxStyle.Critical, "Informacion")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Restore(sender As System.Object, e As System.EventArgs)
Dim ficheros As New SaveFileDialog
Dim cmd As String
Dim carpeta As New FolderBrowserDialog
ficheros.DefaultExt = "sql"
Label2.Text = "Origen"
MessageBox.Show("Ahora tiene que buscar el backup que quiere restaurar")
ficheros.Filter = "File MYSQL (*.sql)|*.sql"
If ficheros.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtDestino.Text = txtDestino.Text & "\" & ficheros.FileName
If MessageBox.Show("¿Es correcto el Origen del Backup?", "Restore BD", MessageBoxButtons.YesNo) = MsgBoxResult.Yes Then
Try
Open()
cmd = "C:\Archivos de Programa\Mariadb 10.1\bin\mysql -u root -p fincas < " & txtDestino.Text
Shell(cmd, AppWinStyle.MaximizedFocus, True)
Close()
MsgBox("El Backup se ejecuto correctamente", MsgBoxStyle.Information, "Proceso finalizado")
Catch ex As Exception
MsgBox("Ocurrio un error inesperado en la creación del Backup", MsgBoxStyle.Critical, "Informacion")
End Try
Else
txtDestino.Text = ""
MsgBox("Intente de nuevo la recuperación de la BD", MsgBoxStyle.Critical, "Informacion")
End If
End If
Close()
End Sub
Private Sub Salir(sender As System.Object, e As System.EventArgs)
Try
txtDestino.Text = Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
Dispose()
End Try
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class