Imports System.Data.SqlClient
Imports System.Runtime.InteropServices


Public Class frmConfig
#Region "Mov. Pantalla"
    <DllImport("user32.Dll", EntryPoint:="ReleaseCapture")>
    Private Shared Sub ReleaseCapture()

    End Sub

    <DllImport("user32.Dll", EntryPoint:="SendMessage")>
    Private Shared Sub SendMessage(hWnd As IntPtr, wMsg As Integer, wParam As Integer, lParam As Integer)

    End Sub

#End Region

    Private Sub PanelBarraTitulo_MouseMove(sender As Object, e As MouseEventArgs) Handles PanelBarraTitulo.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub frmConfig_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub
    Private Sub lblEmpresa_MouseMove(sender As Object, e As MouseEventArgs) Handles lblEmpresa.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub btnCerrar_Click(sender As Object, e As EventArgs) Handles btnCerrar.Click
        Me.Close()
        CerrarFormulario()
    End Sub

    Private Sub btnEncriptar_Click(sender As Object, e As EventArgs) Handles btnEncriptar.Click
        Me.DatoEncrip.Text = Encriptar(Dato.Text)
    End Sub

    Private Sub btnDesencriptar_Click(sender As Object, e As EventArgs) Handles btnDesencriptar.Click
        Me.DatoEncrip.Text = Desencriptar(Dato.Text)
    End Sub

    Private Sub btnTransfer_Click_1(sender As Object, e As EventArgs) Handles btnTransfer.Click
        Dim varMaestra As String = Me.txtCnString.Text
        Dim VarSecundaria As String = Me.txtCnStringLOCAL.Text

        Me.txtCnString.Text = VarSecundaria
        Me.txtCnStringLOCAL.Text = varMaestra
    End Sub

    Private Sub btnPath_Click_1(sender As Object, e As EventArgs) Handles btnPath.Click
        With OpenFileDialog1
            '.InitialDirectory = "C:\"
            .Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg|PNGs|*.png"
            .FilterIndex = 4
        End With

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            Logo.Image = Image.FromFile(OpenFileDialog1.FileName)
            Me.txtPath.Text = OpenFileDialog1.FileName
        Else
            Exit Sub

        End If
    End Sub

    Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click
        Me.txtCnString.Text = ""
        Me.txtCnStringLOCAL.Text = ""
        Me.txtPath.Text = ""
        Me.txtEmpresa.Text = ""
        Me.txtPassword.Text = ""
        Me.txtNoReloj.Text = ""
    End Sub

    Private Sub btnVer_Click(sender As Object, e As EventArgs) Handles btnVer.Click
        Dim cstring As String = Desencriptar(My.Settings.ConnString)
        Dim cstringLocal As String = Desencriptar(My.Settings.ConnStringLoc)
        Dim varEmpresa As String = Desencriptar(My.Settings.Empresa)
        Dim varPass As String = Desencriptar(My.Settings.MasterPass)
        Dim varLogo As String = Desencriptar(My.Settings.LogoEmp)
        'Dim varReloj As String = Desencriptar(My.Settings.NoReloj)

        Me.txtCnString.Text = cstring
        Me.txtCnStringLOCAL.Text = cstringLocal
        Me.txtEmpresa.Text = varEmpresa
        Me.txtPassword.Text = varPass
        'Me.txtNoReloj.Text = varReloj
        Me.txtPath.Text = varLogo
        If Me.txtPath.Text <> "" Then
            Logo.Image = Image.FromFile(varLogo)
        End If
    End Sub

    Private Sub btnGuardar_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click
        If MsgBox("Seguro(a) de guardar estos datos de Configuración?", MsgBoxStyle.YesNo, "Mensaje del Sistema") = vbYes Then
            Try
                My.Settings.ConnString = Encriptar(txtCnString.Text)
                My.Settings.ConnStringLoc = Encriptar(txtCnStringLOCAL.Text)
                My.Settings.Empresa = Encriptar(txtEmpresa.Text)
                My.Settings.MasterPass = Encriptar(txtPassword.Text)
                My.Settings.LogoEmp = Encriptar(txtPath.Text)
                My.Settings.Save()
                MsgBox("Listo, información registrada con éxito", vbInformation, "Mensaje del Sistema")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            MsgBox("Operación Cancelada", vbInformation, "Mensaje del Sistema")
        End If
    End Sub

    Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
        Dim con As New SqlConnection(Me.txtCnString.Text)

        Try
            con.Open()
            con.Close()
            MsgBox("Conexión exitosa!", MsgBoxStyle.Information, "Mensaje del Sistema")
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Information)
        End Try


        con.Close()
    End Sub


End Class