Imports DevExpress.Xpf.Editors
Imports DevExpress.Xpf.Core.Native
Imports System.Reflection

Public Class dxwIdentificacion
    Public Version As String
    Public Cancelar As Boolean

    Public Sub New()
        ' Esta llamada es exigida por el diseñador.
        InitializeComponent()
        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub
    Public Sub New(EnlaceRestablecer As String)


        ' Esta llamada es exigida por el diseñador.
        InitializeComponent()
        hlRestablecerPass.NavigationUrl = EnlaceRestablecer
        hlRestablecerPass.Visibility = Visibility.Visible
        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Cancelar = False
        Me.Close()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Cancelar = True
        Me.Close()
    End Sub

    Private Sub Window_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles gc.PreviewKeyDown
        If e.Key = Key.Return Then
            If teUsuario.Text <> "" And Me.pbeContrasenna.Text <> "" Then
                Cancelar = False
                Me.Close()
            Else
                Dim te As BaseEdit = LayoutHelper.FindParentObject(Of BaseEdit)(Keyboard.FocusedElement)
                If te Is Nothing Then
                    FocusManager.SetFocusedElement(Me, teUsuario)
                Else
                    If te.Name.ToUpper = "TEUSUARIO" Then
                        FocusManager.SetFocusedElement(Me, pbeContrasenna)
                    Else
                        FocusManager.SetFocusedElement(Me, teUsuario)
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub dxwIdentificacion_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        'FocusManager.SetFocusedElement(Me, teUsuario)
        Application.Current.Dispatcher.BeginInvoke(New Action(Function() Me.Focus()), System.Windows.Threading.DispatcherPriority.Send)
        Application.Current.Dispatcher.BeginInvoke(New Action(Function() teUsuario.Focus()), System.Windows.Threading.DispatcherPriority.Send)
        'BeginInvoke(New Action(Function() sigo.Focus()), Windows.Threading.DispatcherPriority.ContextIdle)
    End Sub

    Private Sub dxwIdentificacion_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'FocusManager.SetFocusedElement(Me, teUsuario)
        teUsuario.Focus()
        Application.Current.Dispatcher.BeginInvoke(New Action(Function() Me.Focus()), System.Windows.Threading.DispatcherPriority.Send)
        Application.Current.Dispatcher.BeginInvoke(New Action(Function() teUsuario.Focus()), System.Windows.Threading.DispatcherPriority.Send)
        Cancelar = True
        lVersion.Content = Version '"Versión " + My.Application.Info.Version.ToString
    End Sub

    Private Sub hlRestablecerPass_RequestNavigation(sender As Object, e As HyperlinkEditRequestNavigationEventArgs)
        Process.Start(e.NavigationUrl)
    End Sub
End Class
