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

540 lines
15 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtWPFLib5
Imports Newtonsoft.Json
Imports EgtUILib
Imports System.Windows.Forms
Public Class EstimationDetailPageVM
Inherits VMBase
Public Enum EstimationDetailPages
GENERAL = 0
BILLING = 1
WINDOWDEFAULT = 2
WINDOWLIST = 3
PRICING = 4
PRINT = 5
End Enum
Private m_CurrEstimation As Estimation
Public ReadOnly Property CurrEstimation As Estimation
Get
Return m_CurrEstimation
End Get
End Property
Friend Sub SetCurrEstimation(value As Estimation)
m_CurrEstimation = value
NotifyPropertyChanged(NameOf(SelProfile))
NotifyPropertyChanged(NameOf(SelWoodType))
NotifyPropertyChanged(NameOf(SelColor))
NotifyPropertyChanged(NameOf(SelGlass))
NotifyPropertyChanged(NameOf(SelFrameConfiguration))
NotifyPropertyChanged(NameOf(SelSashConfiguration))
NotifyPropertyChanged(NameOf(WindowList))
End Sub
Private m_SelPage As EstimationDetailPages
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 EstimationDetailPages)
Dim bOk As Boolean = True
' Esco dallo stato corrente
Select Case m_SelPage
Case EstimationDetailPages.GENERAL
'bOk = ExitHOME()
Case EstimationDetailPages.BILLING
'bOk = ExitESTIMATING()
Case EstimationDetailPages.WINDOWDEFAULT
' bOk = ExitPRODUCING()
Case EstimationDetailPages.WINDOWLIST
'bOk = ExitDESIGNING()
End Select
If bOk Then
' Entro nel nuovo stato
m_SelPage = Page
Select Case m_SelPage
Case EstimationDetailPages.GENERAL
'bOk = InitHOME()
Case EstimationDetailPages.BILLING
'bOk = InitESTIMATING()
Case EstimationDetailPages.WINDOWDEFAULT
'bOk = InitPRODUCING()
Case EstimationDetailPages.WINDOWLIST
End Select
End If
NotifyPropertyChanged(NameOf(SelPage))
End Sub
#Region "Window Parameters"
Private m_ProfileList As New List(Of String)
Public ReadOnly Property ProfileList As List(Of String)
Get
Return m_ProfileList
End Get
End Property
Public Property SelProfile As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.Profile
End Get
Set(value As String)
m_CurrEstimation.Profile = value
End Set
End Property
Private m_WoodTypeList As New List(Of String)
Public ReadOnly Property WoodTypeList As List(Of String)
Get
Return m_WoodTypeList
End Get
End Property
Private m_SelWoodType As String
Public Property SelWoodType As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.WoodType
End Get
Set(value As String)
m_CurrEstimation.WoodType = value
End Set
End Property
Private m_ColorList As New List(Of String)
Public ReadOnly Property ColorList As List(Of String)
Get
Return m_ColorList
End Get
End Property
Private m_SelColor As String
Public Property SelColor As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.Color
End Get
Set(value As String)
m_CurrEstimation.Color = value
End Set
End Property
Private m_GlassList As New List(Of String)
Public ReadOnly Property GlassList As List(Of String)
Get
Return m_GlassList
End Get
End Property
Private m_SelGlass As String
Public Property SelGlass As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.Glass
End Get
Set(value As String)
m_CurrEstimation.Glass = value
End Set
End Property
Private m_FrameConfigurationList As New List(Of String)
Public ReadOnly Property FrameConfigurationList As List(Of String)
Get
Return m_FrameConfigurationList
End Get
End Property
Private m_SelFrameConfiguration As String
Public Property SelFrameConfiguration As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.FrameConfiguration
End Get
Set(value As String)
m_CurrEstimation.FrameConfiguration = value
End Set
End Property
Private m_SashConfigurationList As New List(Of String)
Public ReadOnly Property SashConfigurationList As List(Of String)
Get
Return m_SashConfigurationList
End Get
End Property
Private m_SelSashConfiguration As String
Public Property SelSashConfiguration As String
Get
If IsNothing(m_CurrEstimation) Then Return ""
Return m_CurrEstimation.SashConfiguration
End Get
Set(value As String)
m_CurrEstimation.SashConfiguration = value
End Set
End Property
Public ReadOnly Property WindowList As ObservableCollection(Of WindowRow)
Get
If IsNothing(m_CurrEstimation) Then Return New ObservableCollection(Of WindowRow)
Return m_CurrEstimation.WindowList
End Get
End Property
Private m_SelWindow As WindowRow
Public Property SelWindow As WindowRow
Get
Return m_SelWindow
End Get
Set(value As WindowRow)
m_SelWindow = value
End Set
End Property
#End Region
' Definizione comandi
Private m_cmdNewWindow As ICommand
Private m_cmdOk As ICommand
Private m_cmdCancel As ICommand
Sub New()
Map.SetRefEstimationDetailPageVM(Me)
' carico lista profili
Dim ProfileFileList() As String = Directory.GetFiles(Map.refMainWindowVM.MainWindowM.sProfileDir)
For Each ProfileFile In ProfileFileList
m_ProfileList.Add(Path.GetFileNameWithoutExtension(ProfileFile))
Next
' carico lista tipi di legno
m_WoodTypeList.Add("Pino")
m_WoodTypeList.Add("Abete")
m_WoodTypeList.Add("Faggio")
m_WoodTypeList.Add("Castagno")
m_WoodTypeList.Add("Quercia")
' carico lista colori
m_ColorList.Add("Trasparente")
m_ColorList.Add("Bianco")
m_ColorList.Add("Marrone")
' carico lista vetri
m_GlassList.Add("Trasparente")
m_GlassList.Add("Bianco")
m_GlassList.Add("Marrone")
' carico lista configurazioni frame
m_FrameConfigurationList.Add("Orizzontale")
m_FrameConfigurationList.Add("Verticale")
m_FrameConfigurationList.Add("45Deg")
' carico lista configurazioni sash
m_SashConfigurationList.Add("Orizzontale")
m_SashConfigurationList.Add("Verticale")
m_SashConfigurationList.Add("45Deg")
End Sub
Friend Function InitEstimationDetailPage() As Boolean
'If IsNothing(m_CurrEstimation) Then
' ' devo creare nuovo preventivo
' Dim FolderList() As String = Directory.GetDirectories(Map.refMainWindowVM.MainWindowM.sEstimationDir)
' Dim EstimationIndex As Integer = 0
' If FolderList.Count > 0 Then
' EstimationIndex = FolderList.Max(Of Integer)(Function(x) Integer.Parse(Path.GetFileNameWithoutExtension(x)))
' End If
' Directory.CreateDirectory(Map.refMainWindowVM.MainWindowM.sEstimationDir & "\" & (EstimationIndex + 1).ToString())
'Else
'End If
Return True
End Function
'Private Function WriteJsonGenWinParam(FilePath As String) As Boolean
' Dim GenWinParam As New JsonGenWinParam(m_SelProfile, m_SelWoodType, m_SelColor, m_SelGlass, m_SelFrameConfiguration, m_SelSashConfiguration)
' Dim WinList As New List(Of JsonWindowRow)
' For Each Window In m_WindowList
' WinList.Add(New JsonWindowRow(Window.nId, Window.sName, Window.dWidth, Window.dHeight, Window.sImage, Window.sWoodType, Window.sColor, Window.sGlass))
' Next
' Dim JsonFromWindow As String = JsonConvert.SerializeObject(GenWinParam, Formatting.Indented)
' If File.Exists(FilePath) Then
' Try
' File.Delete(FilePath)
' Catch ex As Exception
' EgtOutLog("Error! Impossible deleting file!")
' Return False
' End Try
' End If
' File.WriteAllText(FilePath, JsonFromWindow)
' Return True
'End Function
'Private Function ReadJsonGenWinParam(FilePath As String) As Boolean
' If Not File.Exists(FilePath) Then Return False
' Dim sReadedFile As String = File.ReadAllText(FilePath)
' Dim WindowFromJson As JsonGenWinParam = JsonConvert.DeserializeObject(Of JsonGenWinParam)(sReadedFile)
' m_SelProfile = WindowFromJson.SelProfile
' m_SelWoodType = WindowFromJson.SelWoodType
' m_SelColor = WindowFromJson.SelColor
' m_SelGlass = WindowFromJson.SelGlass
' m_SelFrameConfiguration = WindowFromJson.SelFrameConfiguration
' m_SelSashConfiguration = WindowFromJson.SelSashConfiguration
' NotifyPropertyChanged(NameOf(SelProfile))
' NotifyPropertyChanged(NameOf(SelWoodType))
' NotifyPropertyChanged(NameOf(SelColor))
' NotifyPropertyChanged(NameOf(SelGlass))
' NotifyPropertyChanged(NameOf(SelFrameConfiguration))
' NotifyPropertyChanged(NameOf(SelSashConfiguration))
' Return True
'End Function
Friend Function NewWindowId() As Integer
Dim nId As Integer = 0
If m_CurrEstimation.WindowList.Count > 0 Then
nId = m_CurrEstimation.WindowList.Max(Function(x) x.nId)
End If
Return nId + 10
End Function
Friend Function AddWindow(nId As Integer) As Boolean
m_CurrEstimation.WindowList.Add(New WindowRow(nId, "", 0, 0, "", "", "", ""))
NotifyPropertyChanged(NameOf(WindowList))
Return True
End Function
Friend Sub OpenWindow()
Dim NewWindowWndVM As New NewWindowWndVM
Dim NewWindowWnd As New NewWindowWndV(Application.Current.MainWindow, NewWindowWndVM)
NewWindowWndVM.Init(SelWindow.nId)
NewWindowWnd.ShowDialog()
End Sub
#Region "COMMANDS"
#Region "NewWindow"
Public ReadOnly Property NewWindow_Command As ICommand
Get
If m_cmdNewWindow Is Nothing Then
m_cmdNewWindow = New Command(AddressOf NewWindow)
End If
Return m_cmdNewWindow
End Get
End Property
Public Sub NewWindow(nPage As Integer)
' apro finestra con lista dei template
Dim NewWindowWndVM As New NewWindowWndVM
Dim NewWindowWnd As New NewWindowWndV(Application.Current.MainWindow, NewWindowWndVM)
NewWindowWndVM.Init(0)
NewWindowWnd.ShowDialog()
End Sub
#End Region ' NewWindow
#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(nPage As Integer)
' salvo preventivo
Estimation.WriteEstimation(m_CurrEstimation)
' torno in lista preventivi
Map.refCRMPageVM.SetSelPage(CRMPages.ESTIMATIONLIST)
End Sub
#End Region ' Ok
#Region "Cancel"
Public ReadOnly Property Cancel_Command As ICommand
Get
If m_cmdCancel Is Nothing Then
m_cmdCancel = New Command(AddressOf Cancel)
End If
Return m_cmdCancel
End Get
End Property
Public Sub Cancel(nPage As Integer)
' elimino preventivo
' torno in lista preventivi
Map.refCRMPageVM.SetSelPage(CRMPages.ESTIMATIONLIST)
End Sub
#End Region ' Cancel
#End Region ' COMMANDS
End Class
Public Class TemplateRow
Private m_nId As Integer
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_sName As String
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_dWidth As Double
Public ReadOnly Property dWidth As Double
Get
Return m_dWidth
End Get
End Property
Private m_dHeight As Double
Public ReadOnly Property dHeight As Double
Get
Return m_dHeight
End Get
End Property
Private m_sImagePath As String
Public ReadOnly Property sImagePath As String
Get
Return m_sImagePath
End Get
End Property
Sub New(nId As Integer, sName As String, dWidth As Double, dHeight As Double)
m_nId = nId
m_sName = sName
m_dWidth = dWidth
m_dHeight = dHeight
m_sImagePath = Map.refMainWindowVM.MainWindowM.sTemplateDir & "\" & nId & ".png"
End Sub
End Class
Public Class EstimationRow
Private m_nId As Integer
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_sName As String
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_sWoodType As String
Public ReadOnly Property sWoodType As String
Get
Return m_sWoodType
End Get
End Property
Private m_sColor As String
Public ReadOnly Property sColor As String
Get
Return m_sColor
End Get
End Property
Private m_sGlass As String
Public ReadOnly Property sGlass As String
Get
Return m_sGlass
End Get
End Property
Sub New(nId As Integer)
m_nId = nId
End Sub
End Class
Public Class WindowRow
Private m_nId As Integer
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_sName As String
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_dWidth As Double
Public ReadOnly Property dWidth As Double
Get
Return m_dWidth
End Get
End Property
Private m_dHeight As Double
Public ReadOnly Property dHeight As Double
Get
Return m_dHeight
End Get
End Property
Private m_sImage As String
Public ReadOnly Property sImage As String
Get
Return m_sImage
End Get
End Property
Private m_sWoodType As String
Public ReadOnly Property sWoodType As String
Get
Return m_sWoodType
End Get
End Property
Private m_sColor As String
Public ReadOnly Property sColor As String
Get
Return m_sColor
End Get
End Property
Private m_sGlass As String
Public ReadOnly Property sGlass As String
Get
Return m_sGlass
End Get
End Property
Sub New(nId As Integer, sName As String, dWidth As Double, dHeight As Double, sImage As String, sWoodType As String, sColor As String, sGlass As String)
m_nId = nId
m_sName = sName
m_dWidth = dWidth
m_dHeight = dHeight
m_sImage = sImage
m_sWoodType = sWoodType
m_sColor = sColor
m_sGlass = sGlass
End Sub
End Class