Files
Emmanuele Sassi 9acbbab49e - introdotto BottomRail
- migliorie a grafica e CRM
2025-04-01 11:13:50 +02:00

195 lines
6.1 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib.EgtInterface
Imports EgtWPFLib5
Public Class NewWindowWndVM
Inherits VMBase
Public Enum NewWindowPages
TEMPATELIST = 0
EDIT = 1
End Enum
Friend Event m_CloseWindow(bDialogResult As Boolean)
Private m_ManageWindowVM As ManageWindowVM
Public ReadOnly Property ManageWindowVM As ManageWindowVM
Get
Return m_ManageWindowVM
End Get
End Property
Private m_nId As Integer
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_bNewWindow As Boolean = False
Private m_SelPage As NewWindowPages
Public Property SelPage As Integer
Get
Return m_SelPage
End Get
Set(value As Integer)
SetSelPage(value)
End Set
End Property
Friend Sub SetSelPage(Page As NewWindowPages)
Dim bOk As Boolean = True
' Esco dallo stato corrente
Select Case m_SelPage
Case NewWindowPages.TEMPATELIST
'bOk = ExitHOME()
Case NewWindowPages.EDIT
'bOk = ExitESTIMATING()
End Select
If bOk Then
' Entro nel nuovo stato
m_SelPage = Page
Select Case m_SelPage
Case NewWindowPages.TEMPATELIST
'bOk = InitHOME()
Case NewWindowPages.EDIT
'bOk = InitESTIMATING()
End Select
End If
NotifyPropertyChanged(NameOf(SelPage))
End Sub
Private m_TemplateList As New ObservableCollection(Of TemplateRow)
Public ReadOnly Property TemplateList As ObservableCollection(Of TemplateRow)
Get
Return m_TemplateList
End Get
End Property
Private m_SelTemplate As TemplateRow
Public Property SelTemplate As TemplateRow
Get
Return m_SelTemplate
End Get
Set(value As TemplateRow)
m_SelTemplate = value
End Set
End Property
' Definizione comandi
Private m_cmdOk As ICommand
Sub New()
m_ManageWindowVM = New ManageWindowVM
End Sub
Friend Sub Init(nId As Integer)
If nId > 0 Then
m_nId = nId
m_ManageWindowVM.Read(Map.refMainWindowVM.MainWindowM.sEstimationDir & "\" & Map.refEstimationDetailPageVM.CurrEstimation.nId & "\" & m_nId & ".jwd")
m_SelPage = NewWindowPages.EDIT
Else
m_bNewWindow = True
m_nId = Map.refEstimationDetailPageVM.NewWindowId()
' carico template
Dim TemplateFiles() As String = Directory.GetFiles(Map.refMainWindowVM.MainWindowM.sTemplateDir)
For Each Template In TemplateFiles
If Path.GetExtension(Template).ToLower <> ".jwd" Then Continue For
Dim TemplateData() As String = Path.GetFileNameWithoutExtension(Template).Split("_"c)
Dim nTemplateId As Integer = 0
Integer.TryParse(TemplateData(0), nTemplateId)
Dim sName As String = ""
If TemplateData.Count > 1 Then
sName = TemplateData(1)
End If
Dim dWidth As Double = 0
If TemplateData.Count > 2 Then
StringToDouble(TemplateData(2), dWidth)
End If
Dim dHeight As Double = 0
If TemplateData.Count > 3 Then
StringToDouble(TemplateData(3), dHeight)
End If
m_TemplateList.Add(New TemplateRow(nTemplateId, sName, dWidth, dHeight))
Next
End If
End Sub
Public Sub TemplateConfirmed()
m_ManageWindowVM.Read(Map.refMainWindowVM.MainWindowM.sTemplateDir & "\" & SelTemplate.nId & "_" & SelTemplate.sName & "_" & SelTemplate.dWidth & "_" & SelTemplate.dHeight & ".jwd")
SetSelPage(NewWindowPages.EDIT)
End Sub
Friend Function OpenWindow(sFilePath As String) As Boolean
Dim bOk As Boolean = False
If String.IsNullOrEmpty(sFilePath) Then
' Recupero cartella dell'ultimo progetto aperto
Dim sDir As String = ""
GetMainPrivateProfileString(S_MRUFILES, K_FILE & 1, "", sDir)
If Not String.IsNullOrWhiteSpace(sDir) Then
sDir = Path.GetDirectoryName(sDir)
End If
Dim OpenFileDialog As New Windows.Forms.OpenFileDialog With {
.Title = "Open",
.Filter = "Window project|*.jwd",
.FilterIndex = 1,
.InitialDirectory = sDir
}
If Not OpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then Return False
sFilePath = OpenFileDialog.FileName
End If
Map.refManageWindowVM.Read(sFilePath)
Return bOk
End Function
Public Sub SaveWindow()
' Recupero cartella dell'ultimo progetto aperto
Dim sDir As String = ""
GetMainPrivateProfileString(S_MRUFILES, K_FILE & 1, "", sDir)
If Not String.IsNullOrWhiteSpace(sDir) Then
sDir = Path.GetDirectoryName(sDir)
End If
Dim SaveFileDialog As New Windows.Forms.SaveFileDialog With {
.Title = "Open",
.Filter = "Window project|*.jwd",
.FilterIndex = 1,
.InitialDirectory = sDir
}
If Not SaveFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then Return
Map.refManageWindowVM.Write(SaveFileDialog.FileName)
EgtSaveFile(Path.ChangeExtension(SaveFileDialog.FileName, ".nge"), NGE.BIN)
End Sub
#Region "COMMANDS"
#Region "Ok"
Public ReadOnly Property Ok_Command As ICommand
Get
If m_cmdOk Is Nothing Then
m_cmdOk = New Command(AddressOf Ok)
End If
Return m_cmdOk
End Get
End Property
Public Sub Ok()
If m_bNewWindow Then
' aggiungo riga della finestra all'ordine
Map.refEstimationDetailPageVM.AddWindow(m_nId)
End If
' salvo finestra
Dim sWindowPath As String = Map.refMainWindowVM.MainWindowM.sEstimationDir & "\" & Map.refEstimationDetailPageVM.CurrEstimation.nId & "\" & m_nId & ".jwd"
m_ManageWindowVM.Write(sWindowPath)
m_ManageWindowVM.SetDShowMode(ManageWindowVM.DShowModes.MODESIMPLE3D)
m_ManageWindowVM.GetImage(Path.ChangeExtension(sWindowPath, ".png"))
RaiseEvent m_CloseWindow(True)
End Sub
#End Region ' Ok
#End Region ' COMMANDS
End Class