Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Core.ConstBeam
Imports EgtUILib

Public Class OpenProjectFileDialogVM
   Inherits Core.OpenProjectFileDialogVM

#Region "METHODS"

   Public Overrides Function Init(ProjectType As ProjectType, Optional CurrProjectList As List(Of ProjectFileVM) = Nothing, Optional GoToProd As Boolean = False) As Boolean?
      m_ProjectType = ProjectType
      ' carico colonne
      LoadColumns(m_ProjectType)
      NotifyPropertyChanged(NameOf(FilterTypeList))
      m_SelFilterType = m_FilterTypeList(0)
      ' carico lista progetti
      If IsNothing(CurrProjectList) OrElse CurrProjectList.Count = 0 Then
         RefreshProjectList(GoToProd)
      Else
         m_ProjectList = New ObservableCollection(Of ProjectFileVM)(CurrProjectList)
         NotifyPropertyChanged(NameOf(ProjectList))
      End If
      m_ProjectList_View = CollectionViewSource.GetDefaultView(m_ProjectList)
      m_ProjectList_View.Filter = AddressOf ProjectFilter
   End Function

   Public Overrides Sub RefreshProjectList(Optional GoToProd As Boolean = False)
      m_ProjectList.Clear()
      ' calcolo periodo e righe
      Dim dtStart As DateTime
      Dim dtEnd As DateTime
      Dim nRowQuantity As Integer = 20
      Select Case SelRowQuantity
         Case RowQuantities.FIFTY
            nRowQuantity = 50
         Case RowQuantities.HUNDRED
            nRowQuantity = 100
         Case RowQuantities.HUNDREDANDFIFTY
            nRowQuantity = 150
      End Select
      Select Case m_SelDayType
         Case DayTypes.LASTMONTH
            dtEnd = DateTime.Today + TimeSpan.FromDays(1)
            dtStart = dtEnd - TimeSpan.FromDays(30.5)
         Case DayTypes.LAST3MONTHS
            dtEnd = DateTime.Today + TimeSpan.FromDays(1)
            dtStart = dtEnd - TimeSpan.FromDays(30.5 * 3)
         Case DayTypes.LAST6MONTHS
            dtEnd = DateTime.Today + TimeSpan.FromDays(1)
            dtStart = dtEnd - TimeSpan.FromDays(30.5 * 6)
         Case DayTypes.PERIOD
            dtStart = dtStartDate + TimeSpan.FromDays(1)
            dtEnd = dtEndDate
      End Select
      ' leggo da db
      If m_ProjectType = ProjectType.PROD Then
         Dim DbProjectList As New List(Of ProdFileM)
         DbProjectList = DbControllers.m_ProdController.GetLastDesc(dtStart, dtEnd, nRowQuantity, True)
         For Each Project In DbProjectList
            m_ProjectList.Add(New ProdFileVM(Project))
         Next
      End If

   End Sub

#End Region    ' METHODS

End Class
