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

Public Class FrmAppPago
#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

    Private Sub PanelBarraTitulo_MouseMove(sender As Object, e As MouseEventArgs) Handles PanelBarraTitulo.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

#End Region

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

    Private Sub txtPassword_Click(sender As Object, e As EventArgs) Handles txtPassword.Click
        txtPassword.Text = ""
        txtPassword.Focus()
    End Sub
    Private Sub txtPassword_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPassword.KeyDown
        If e.KeyCode = Keys.Enter Then
            Acceso()
        End If
    End Sub
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Acceso()

    End Sub
    Sub Acceso()
        GlobalVariables.VarClaveOK = ObtenerClave("Aplicar Pagos", Me.txtPassword.Text)
        GlobalVariables.varUsuarioAcceso = DLookup("Usuario", "Claves", "Clave='" & txtPassword.Text & "' and Opcion='Aplicar Pagos'")

        If GlobalVariables.VarClaveOK = True Then
            If MsgBox("Atención!, esta acción dará por pagado el documento actual, esta seguro(a) de continuar?", vbYesNo, "Mensaje del Sistema") = vbYes Then
                QryInsUpDel("UPDATE Invoices SET Pagado =1, FechaPag='" & FechaPag.Value.ToString("yyyy-MM-dd") & "', RefPago='" & RefPago.Text & "', Aplico='" & GlobalVariables.varUsuarioAcceso & "', estatus='PAGADA' WHERE Id=" & GlobalVariables.VarIDReg & "")
                FrmCobranza.CargarDGV()

                If GlobalVariables.VarOrigenPago = True Then
                    FrmInvoices.Pagado.Checked = True
                    FrmInvoices.FechaPag.Format = DateTimePickerFormat.Short
                    FrmInvoices.FechaPag.Value = FechaPag.Value
                    FrmInvoices.RefPago.Text = RefPago.Text
                    FrmInvoices.Estatus.Text = "PAGADA"
                End If
                Me.Close()
            Else
                MsgBox("Operación abortada!", MsgBoxStyle.Information, "Mensaje del Sistema")
                Exit Sub
            End If
        Else
            MsgBox("Password incorrecto o usuario no autorizado.", MsgBoxStyle.Information, "Mensaje del Sistema")
            Exit Sub
        End If
    End Sub

    Private Sub FechaPag_MouseDown(sender As Object, e As MouseEventArgs) Handles FechaPag.MouseDown
        Select Case e.Button
            Case Windows.Forms.MouseButtons.Left
                FechaPag.Format = DateTimePickerFormat.Short
                FechaPag.Value = Date.Today
            Case Windows.Forms.MouseButtons.Right
                FechaPag.Format = DateTimePickerFormat.Custom
                FechaPag.CustomFormat = " "
        End Select
    End Sub

    Private Sub FechaPag_Validated(sender As Object, e As EventArgs) Handles FechaPag.Validated
        Pagado.Checked = True
        RefPago.Focus()
    End Sub
End Class