terça-feira, 30 de agosto de 2011

on

Botão para Gerar BackUp
Try          
                Dim SaveDialog As New SaveFileDialog
                SaveDialog.Filter = "Arquivo BackUp|*.accdb"
                SaveDialog.Title = "Selecione o backup de destino"
                If SaveDialog.ShowDialog = Windows.Forms.DialogResult.Cancel Then
                    MsgBox("Operação de Backup abortada pelo usuário", MsgBoxStyle.Information, "BackUp Não gerado")
                    Exit Sub
                Else
                    If File.Exists(SaveDialog.FileName) Then
                        File.Delete(SaveDialog.FileName)
                    End If
                    File.Copy(Application.StartupPath & "\SysVendas.accdb", SaveDialog.FileName)
                    Dim Writer As System.IO.TextWriter
                    Writer = New StreamWriter(SaveDialog.FileName & ".txt", FileMode.Create)
                    Writer.WriteLine(SaveDialog.FileName)
                    Writer.Flush()
                    Writer.Close()
                    MsgBox("Backup criado com sucesso.", MsgBoxStyle.Information, "BackUp Gerado")
                End If           

        Catch ex As Exception

        End Try

Botão para Restaurar Gerar BackUp
Try           
                Dim OpenDialog As New OpenFileDialog
                OpenDialog.Title = "Selecione o local para acessar o backup"
                OpenDialog.Filter = "Arquivo Backup|*.accdb"
                If OpenDialog.ShowDialog = Windows.Forms.DialogResult.Cancel Then
                    MsgBox("Acesso ao backup abortado", MsgBoxStyle.Exclamation, "BackUp não realizado")
                    Exit Sub
                Else
                    If File.Exists(Application.StartupPath & "\SysVendas.accdb") Then
                        File.Delete(Application.StartupPath & "\SysVendas.accdb")
                        File.Delete(OpenDialog.FileName & ".txt")
                    End If
                    File.Move(OpenDialog.FileName, Application.StartupPath & "\SysVendas.accdb")
                    MsgBox("Backup Restaurado. Novas alterações terão efeito depois de reiniciar o aplicativo. O programa será encerrado agora.", MsgBoxStyle.Exclamation, "BackUp Acessado. Reinicar Aplicativo")
                    Me.Close()
                End If

        Catch ex As Exception

        End Try

1 comentários: