Imports System.ComponentModel
Imports System.IO
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports EgtBEAMWALL.Core.ConstBeam
Imports EgtUILib
Imports EgtWPFLib5
Imports EgtBEAMWALL

Public Class OpenProjectFileDialogV

   Private WithEvents m_OpenProjFileDialogVM As OpenProjectFileDialogVM

#Region "CONSTRUCTOR"

   Sub New(Owner As Window, OpenProjFileDialogVM As OpenProjectFileDialogVM)
      ' Funzione che interpreta l'xaml
      InitializeComponent()
      Me.Owner = Owner
      Me.DataContext = OpenProjFileDialogVM
      ' Assegno al riferimento locale al VM il VM preso dal DataContext
      m_OpenProjFileDialogVM = OpenProjFileDialogVM
      AddHandler Me.Loaded, AddressOf OpenProjectFileDialog_Loaded
      AddHandler Me.Closing, AddressOf OpenProjectFileDialog_Closing
   End Sub

#End Region    ' CONSTRUCTOR

#Region "METHODS"

   Public Function EgtShowDialog(ProjectType As ProjectType) As Boolean?
      m_OpenProjFileDialogVM.Init(ProjectType)
      ' mostro la finestra di dialogo
      Return Me.ShowDialog()
   End Function
   Public Function EgtShowDialog(ProjectType As ProjectType, ProjectList As List(Of ProjectFileVM)) As Boolean?
      m_OpenProjFileDialogVM.Init(ProjectType, ProjectList)
      ' mostro la finestra di dialogo
      Return Me.ShowDialog()
   End Function

   Public Function EgtShowDialog(ProjectType As ProjectType, GoToProd As Boolean) As Boolean?
      m_OpenProjFileDialogVM.Init(ProjectType, Nothing, GoToProd)
      ' mostro la finestra di dialogo
      Return Me.ShowDialog()
   End Function

   Private Sub OpenProjectFileDialog_Loaded(sender As Object, e As RoutedEventArgs)
      ' Carico e imposto posizione finestra
      WinPosFromIniToWindow(S_OPENFILEDIALOG, K_VIEWOPTIMWINPLACE, Me)
   End Sub

   Private Sub OpenProjectFileDialog_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs)
      If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then
         e.Cancel = True
         Return
      End If
      ' Salvo posizione finestra (se non minimizzata)
      WinPosFromWindowToIni(Me, S_OPENFILEDIALOG, K_VIEWOPTIMWINPLACE)
   End Sub

#End Region    ' METHODS

#Region "EVENTS"

   Private Sub ProjectList_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs)
      m_OpenProjFileDialogVM.ProjDoubleClick()
   End Sub

#End Region    ' EVENTS

   Private Sub OpenBtn_Click(sender As Object, e As RoutedEventArgs) Handles OpenBtn.Click
      DialogResult = m_OpenProjFileDialogVM.VerifySelected()
   End Sub

   Private Sub CloseWindow(bDialogResult As Boolean) Handles m_OpenProjFileDialogVM.m_CloseWindow
      Me.DialogResult = bDialogResult
   End Sub

End Class