Imports Funcion.Funcion
Imports System.IO

Public Class Backup
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        InitializeComponent()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ComponentModel.IContainer


    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents WinPopup1 As WinPopup.WinPopup
    Friend WithEvents BottomRightColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents TopLeftColor As LaMarvin.Windows.Forms.ColorPicker
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Tool As System.Windows.Forms.ToolTip
    Friend WithEvents dlImportar As System.Windows.Forms.OpenFileDialog
    Friend WithEvents cmdSalir As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents cmdDirección As System.Windows.Forms.Label
    Friend WithEvents cmdBackup As System.Windows.Forms.Label
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents dlBackup As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Backup))
        Me.cmdBackup = New System.Windows.Forms.Label
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.TopLeftColor = New LaMarvin.Windows.Forms.ColorPicker
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.WinPopup1 = New WinPopup.WinPopup
        Me.BottomRightColor = New LaMarvin.Windows.Forms.ColorPicker
        Me.Tool = New System.Windows.Forms.ToolTip(Me.components)
        Me.dlImportar = New System.Windows.Forms.OpenFileDialog
        Me.cmdSalir = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label9 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.cmdDirección = New System.Windows.Forms.Label
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.dlBackup = New System.Windows.Forms.FolderBrowserDialog
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.CheckBox2 = New System.Windows.Forms.CheckBox
        Me.GroupBox2.SuspendLayout()
        Me.Panel2.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'cmdBackup
        '
        Me.cmdBackup.ForeColor = System.Drawing.Color.Black
        Me.cmdBackup.Image = CType(resources.GetObject("cmdBackup.Image"), System.Drawing.Image)
        Me.cmdBackup.Location = New System.Drawing.Point(272, 240)
        Me.cmdBackup.Name = "cmdBackup"
        Me.cmdBackup.Size = New System.Drawing.Size(64, 22)
        Me.cmdBackup.TabIndex = 169
        Me.cmdBackup.Text = "&Backup"
        Me.cmdBackup.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TextBox3
        '
        Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox3.Location = New System.Drawing.Point(8, 24)
        Me.TextBox3.MaxLength = 0
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(296, 20)
        Me.TextBox3.TabIndex = 9
        Me.TextBox3.Text = "TextBox3"
        '
        'TopLeftColor
        '
        Me.TopLeftColor.Color = System.Drawing.SystemColors.Control
        Me.TopLeftColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        Me.TopLeftColor.ForeColor = System.Drawing.Color.Cyan
        Me.TopLeftColor.Location = New System.Drawing.Point(399, 261)
        Me.TopLeftColor.Name = "TopLeftColor"
        Me.TopLeftColor.Size = New System.Drawing.Size(12, 12)
        Me.TopLeftColor.TabIndex = 2
        Me.TopLeftColor.Text = "ColorPicker1"
        Me.TopLeftColor.TextDisplayed = False
        Me.TopLeftColor.Visible = False
        '
        'WinPopup1
        '
        Me.WinPopup1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.WinPopup1.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.WinPopup1.ImeMode = System.Windows.Forms.ImeMode.NoControl
        Me.WinPopup1.Location = New System.Drawing.Point(168, 160)
        Me.WinPopup1.Name = "WinPopup1"
        Me.WinPopup1.Size = New System.Drawing.Size(230, 100)
        Me.WinPopup1.TabIndex = 94
        Me.WinPopup1.Visible = False
        Me.WinPopup1.WinPopupAutoHide = False
        Me.WinPopup1.WinPopupAutoShow = False
        Me.WinPopup1.WinPopupGosth = False
        Me.WinPopup1.WinPopupGosthSpeed = 25
        '
        'BottomRightColor
        '
        Me.BottomRightColor.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.BottomRightColor.Color = System.Drawing.SystemColors.Control
        Me.BottomRightColor.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        Me.BottomRightColor.Location = New System.Drawing.Point(0, 0)
        Me.BottomRightColor.Name = "BottomRightColor"
        Me.BottomRightColor.Size = New System.Drawing.Size(12, 12)
        Me.BottomRightColor.TabIndex = 1
        Me.BottomRightColor.Text = "ColorPicker1"
        Me.BottomRightColor.TextDisplayed = False
        Me.BottomRightColor.Visible = False
        '
        'cmdSalir
        '
        Me.cmdSalir.ForeColor = System.Drawing.Color.Black
        Me.cmdSalir.Image = CType(resources.GetObject("cmdSalir.Image"), System.Drawing.Image)
        Me.cmdSalir.Location = New System.Drawing.Point(336, 240)
        Me.cmdSalir.Name = "cmdSalir"
        Me.cmdSalir.Size = New System.Drawing.Size(64, 22)
        Me.cmdSalir.TabIndex = 169
        Me.cmdSalir.Text = "&Salir"
        Me.cmdSalir.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Purple
        Me.Label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label5.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.Color.Black
        Me.Label5.Location = New System.Drawing.Point(0, 0)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(424, 80)
        Me.Label5.TabIndex = 172
        '
        'Label8
        '
        Me.Label8.BackColor = System.Drawing.Color.Purple
        Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label8.ForeColor = System.Drawing.Color.White
        Me.Label8.Location = New System.Drawing.Point(28, 32)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(360, 24)
        Me.Label8.TabIndex = 175
        Me.Label8.Text = "Es muy importante saber que hacer backup de sus datos todos los dias ayudará a ma" & _
        "ntener la consistencia de los datos en caso de fallas en el Servidor"
        '
        'Label7
        '
        Me.Label7.BackColor = System.Drawing.Color.Purple
        Me.Label7.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.ForeColor = System.Drawing.Color.White
        Me.Label7.Location = New System.Drawing.Point(12, 8)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(400, 16)
        Me.Label7.TabIndex = 174
        Me.Label7.Text = "Eliga una Dirección para el Backup  - Choose Path"
        Me.Label7.TextAlign = System.Drawing.ContentAlignment.BottomLeft
        '
        'Label9
        '
        Me.Label9.BackColor = System.Drawing.SystemColors.Control
        Me.Label9.ForeColor = System.Drawing.Color.Blue
        Me.Label9.Location = New System.Drawing.Point(20, 88)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(376, 16)
        Me.Label9.TabIndex = 176
        Me.Label9.Text = "Proceso de Copia de Seguridad de la Base de Datos"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.cmdDirección)
        Me.GroupBox2.Controls.Add(Me.TextBox3)
        Me.GroupBox2.ForeColor = System.Drawing.Color.Blue
        Me.GroupBox2.Location = New System.Drawing.Point(20, 112)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(384, 72)
        Me.GroupBox2.TabIndex = 178
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Destination Folder"
        '
        'cmdDirección
        '
        Me.cmdDirección.ForeColor = System.Drawing.Color.Black
        Me.cmdDirección.Image = CType(resources.GetObject("cmdDirección.Image"), System.Drawing.Image)
        Me.cmdDirección.Location = New System.Drawing.Point(312, 23)
        Me.cmdDirección.Name = "cmdDirección"
        Me.cmdDirección.Size = New System.Drawing.Size(64, 22)
        Me.cmdDirección.TabIndex = 176
        Me.cmdDirección.Text = "Browse..."
        Me.cmdDirección.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Panel2
        '
        Me.Panel2.Controls.Add(Me.GroupBox1)
        Me.Panel2.Location = New System.Drawing.Point(0, -240)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(500, 12)
        Me.Panel2.TabIndex = 180
        '
        'GroupBox1
        '
        Me.GroupBox1.Location = New System.Drawing.Point(16, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(500, 2)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        '
        'GroupBox3
        '
        Me.GroupBox3.Location = New System.Drawing.Point(16, 0)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(500, 2)
        Me.GroupBox3.TabIndex = 0
        Me.GroupBox3.TabStop = False
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.Panel2)
        Me.Panel1.Controls.Add(Me.GroupBox3)
        Me.Panel1.Location = New System.Drawing.Point(-38, 232)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(500, 2)
        Me.Panel1.TabIndex = 179
        '
        'CheckBox1
        '
        Me.CheckBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.CheckBox1.ForeColor = System.Drawing.Color.Blue
        Me.CheckBox1.Location = New System.Drawing.Point(24, 184)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(184, 24)
        Me.CheckBox1.TabIndex = 180
        Me.CheckBox1.Text = "Comprimir a ZIP"
        '
        'CheckBox2
        '
        Me.CheckBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.CheckBox2.ForeColor = System.Drawing.Color.Blue
        Me.CheckBox2.Location = New System.Drawing.Point(24, 208)
        Me.CheckBox2.Name = "CheckBox2"
        Me.CheckBox2.Size = New System.Drawing.Size(184, 24)
        Me.CheckBox2.TabIndex = 181
        Me.CheckBox2.Text = "Eliminar Archivos Temporales"
        '
        'Backup
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(410, 272)
        Me.Controls.Add(Me.WinPopup1)
        Me.Controls.Add(Me.TopLeftColor)
        Me.Controls.Add(Me.BottomRightColor)
        Me.Controls.Add(Me.CheckBox2)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.cmdSalir)
        Me.Controls.Add(Me.cmdBackup)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.KeyPreview = True
        Me.MaximizeBox = False
        Me.Name = "Backup"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Copia de Seguridad de Ondanet"
        Me.GroupBox2.ResumeLayout(False)
        Me.Panel2.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Direccion As String
    Dim Color1, Color2 As String

    Private Sub Salir(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 27 Then
            Close()
        End If
    End Sub

    Private Sub _Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        limpiar()
        Texto()
    End Sub

    Private Sub limpiar()
        TextBox3.Text = ""
        TextBox3.Focus()
    End Sub

    Private Sub Texto()
        Tool.SetToolTip(Me.cmdBackup, "Realiza la Copia de Seguridad de la Base de Datos")
        Tool.SetToolTip(Me.cmdSalir, "Abandona la pantalla")
        Tool.SetToolTip(Me.cmdDirección, "Busca la Dirección para Exportar")
    End Sub

    Private Sub cmdDirección_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDirección.Click
        BuscarDireccion()
    End Sub

    Private Sub BuscarDireccion()
        dlBackup.Description = "Hacer Copia de Seguridad a: "
        dlBackup.RootFolder = Environment.SpecialFolder.MyComputer
        dlBackup.ShowNewFolderButton = True
        If dlBackup.ShowDialog = DialogResult.OK Then
            TextBox3.Text = dlBackup.SelectedPath
            Direccion = dlBackup.SelectedPath
        End If
        If TextBox3.Text Is Nothing Then
            Mensaje("No ha Seleccionado directorio Válido para la Copia de Seguridad")
            Exit Sub
        End If
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If keyascii = 13 Then
            cmdBackup.Focus()
        End If
        If keyascii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
        If e.KeyCode = Keys.F9 Then
            BuscarDireccion()
        End If
    End Sub

    Private Sub _Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBackup.Click
        If Directory.Exists(Direccion) = False Then
            Mensaje("No existe el directorio del backup")
            TextBox3.Focus()
            Exit Sub
        End If
        'If (MessageBox.Show("Esta Seguro que desea Realizar el Backup...", "Copia de Seguridad", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)) = DialogResult.Yes Then
        HacerBackup()
        'Else
        '    Mensaje("Operación cancelada por el Usuario " & UsuDescripcion & " ")
        'End If
    End Sub

    Public Sub HacerBackup()
        Dim clase As New SentBackup.Backup

        Try
            If clase.Backup(Direccion, CheckBox1.Checked, CheckBox2.Checked) = True Then
                MsgBox("Copia de Seguridad realizada exitosamente....", MsgBoxStyle.Information, "Copia de Seguridad")
            End If
        Catch ex As Exception
            MsgBox("Ha ocurrido un error grave durante la Copia de Seguridad...", MsgBoxStyle.Critical, "Copia de Seguridad")
        End Try
    End Sub

    Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
        Me.Close()
    End Sub

    Private Sub cmdSalir_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSalir.MouseLeave
        Me.cmdSalir.ForeColor = System.Drawing.Color.Black
    End Sub

    Private Sub cmdSalir_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cmdSalir.MouseMove
        Me.cmdSalir.ForeColor = System.Drawing.Color.LightSeaGreen
    End Sub

    Private Sub cmdBackup_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cmdBackup.MouseMove
        Me.cmdBackup.ForeColor = System.Drawing.Color.LightSeaGreen
    End Sub

    Private Sub cmdBackup_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBackup.MouseLeave
        Me.cmdBackup.ForeColor = System.Drawing.Color.Black
    End Sub

    Private Sub frmImportacionVenta_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Escape Then
            Me.Close()
        End If
    End Sub

End Class
