Files
EgtPHOTOLib/SearchPanelSlab/SearchPanelSlabVM.vb

406 lines
12 KiB
VB.net

Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Public Class SearchPanelSlabVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Friend Event ScrollToTop()
Private m_Search_IsEnabled As Boolean
Public Property Search_IsEnabled As Boolean
Get
Return m_Search_IsEnabled
End Get
Set(value As Boolean)
m_Search_IsEnabled = value
NotifyPropertyChanged("Search_IsEnabled")
End Set
End Property
Private m_Search_IsChecked As Boolean
Public Property Search_IsChecked As Boolean
Get
Return m_Search_IsChecked
End Get
Set(value As Boolean)
m_Search_IsChecked = value
End Set
End Property
Private m_Id As String
Public Property Id As String
Get
Return m_Id
End Get
Set(value As String)
m_Id = value
End Set
End Property
Private m_ImagePath As String
Public Property ImagePath As String
Get
Return m_ImagePath
End Get
Set(value As String)
m_ImagePath = value
End Set
End Property
Private m_StateList As List(Of IdNameStruct)
Public ReadOnly Property StateList As List(Of IdNameStruct)
Get
Return m_StateList
End Get
End Property
Friend Sub SetStateList(StateList As List(Of IdNameStruct))
m_StateList = StateList
End Sub
Private m_State As Slab.StateOpt
Public Property State As Integer
Get
Return m_State
End Get
Set(value As Integer)
m_State = value
NotifyPropertyChanged("State")
End Set
End Property
Private m_ProjectAssignedTo As String
Public Property ProjectAssignedTo As String
Get
Return m_ProjectAssignedTo
End Get
Set(value As String)
m_ProjectAssignedTo = value
End Set
End Property
Private m_MaterialList As List(Of String)
Public ReadOnly Property MaterialList As List(Of String)
Get
Return m_MaterialList
End Get
End Property
Private m_Material As String
Public Property Material As String
Get
Return m_Material
End Get
Set(value As String)
m_Material = value
End Set
End Property
Private m_Thickness As Double
Public Property Thickness As String
Get
If m_Thickness < EPS_SMALL Then Return ""
Return LenToString(m_Thickness, 2)
End Get
Set(value As String)
Dim dThickness As Double = 0
If StringToLen(value, dThickness) And dThickness > -EPS_ZERO Then
m_Thickness = dThickness
Else
NotifyPropertyChanged("Thickness")
' Non sono ammessi spessori negativi
Dim sMsg As String = EgtMsg(MSG_RAWPARTPAGEUC + 18)
LibMap.refStatusBarVM.SetOutputMessage(sMsg, 5, MSG_TYPE.ERROR_)
End If
End Set
End Property
Private m_WarehousePosition As String
Public Property WarehousePosition As String
Get
Return m_WarehousePosition
End Get
Set(value As String)
m_WarehousePosition = value
End Set
End Property
Private m_StartAddedDate As Nullable(Of Date)
Public Property StartAddedDate As Nullable(Of Date)
Get
Return m_StartAddedDate
End Get
Set(value As Nullable(Of Date))
m_StartAddedDate = value
End Set
End Property
Private m_EndAddedDate As Nullable(Of Date)
Public Property EndAddedDate As Nullable(Of Date)
Get
Return m_EndAddedDate
End Get
Set(value As Nullable(Of Date))
m_EndAddedDate = value
End Set
End Property
Private m_ThicknessTolerance As Double
Private m_SearchPanel_Visibility As Visibility
Public ReadOnly Property SearchPanel_Visibility As Visibility
Get
Return m_SearchPanel_Visibility
End Get
End Property
Public Sub SetSearchPanel_Visibility(IsVisible As Boolean)
If IsVisible Then
m_SearchPanel_Visibility = Visibility.Visible
Else
m_SearchPanel_Visibility = Visibility.Collapsed
End If
NotifyPropertyChanged("SearchPanel_Visibility")
End Sub
#Region "Messages"
Public ReadOnly Property IdMsg As String
Get
Return EgtMsg(MSG_SLAB + 1)
End Get
End Property
Public ReadOnly Property ImagePathMsg As String
Get
Return EgtMsg(MSG_SLAB + 2)
End Get
End Property
Public ReadOnly Property StateMsg As String
Get
Return EgtMsg(MSG_SLAB + 3)
End Get
End Property
Public ReadOnly Property ProjectAssignedToMsg As String
Get
Return EgtMsg(MSG_SLAB + 4)
End Get
End Property
Public ReadOnly Property MaterialMsg As String
Get
Return EgtMsg(MSG_RAWPARTPAGEUC + 9)
End Get
End Property
Public ReadOnly Property ThicknessMsg As String
Get
Return EgtMsg(MSG_RAWPARTPAGEUC + 5)
End Get
End Property
Public ReadOnly Property WarehousePositionMsg As String
Get
Return EgtMsg(MSG_SLAB + 5)
End Get
End Property
Public ReadOnly Property StartAddedDateMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 3)
End Get
End Property
Public ReadOnly Property EndAddedDateMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 4)
End Get
End Property
Public ReadOnly Property ResetMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 5)
End Get
End Property
Public ReadOnly Property SearchMsg As String
Get
Return EgtMsg(MSG_SEARCHPANEL + 1)
End Get
End Property
#End Region ' Messages
' Definizione comandi
Private m_cmdReset As ICommand
Private m_cmdSearch As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in StoneMap
PhotoMap.SetRefSearchPanelVM(Me)
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Public Sub InitSearchPanel()
' Creo lista materiali
If MainData.bIsOmagOFFICE Then
' carico l'elelnco di tutti i materiali presenti nel DB
PhotoMap.refOptionPanelVM.SetMaterialFromDB()
m_MaterialList = PhotoMap.refOptionPanelVM.MaterialList
Else
m_MaterialList = New List(Of String)(PhotoMap.refProjectVM.MaterialList)
m_MaterialList.Insert(0, String.Empty)
End If
NotifyPropertyChanged("MaterialList")
' Leggo tolleranza spessore
m_ThicknessTolerance = GetMainPrivateProfileDouble(S_SEARCH, K_THICKNESSTOLERANCE, 0)
End Sub
Public Sub SetSearch_IsChecked(value As Boolean)
m_Search_IsChecked = value
SetSearchPanel_Visibility(m_Search_IsChecked)
NotifyPropertyChanged("Search_IsChecked")
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "Reset"
''' <summary>
''' Returns a command that do New.
''' </summary>
Public ReadOnly Property Reset_Command As ICommand
Get
If m_cmdReset Is Nothing Then
m_cmdReset = New Command(AddressOf Reset)
End If
Return m_cmdReset
End Get
End Property
''' <summary>
''' Execute the New. This method is invoked by the NewCommand.
''' </summary>
Friend Sub Reset(Optional bUseDefaults As Boolean = False)
m_Id = String.Empty
NotifyPropertyChanged("Id")
m_ImagePath = String.Empty
NotifyPropertyChanged("ImagePath")
m_State = Nothing
NotifyPropertyChanged("State")
m_ProjectAssignedTo = String.Empty
NotifyPropertyChanged("ProjectAssignedTo")
m_Material = String.Empty
NotifyPropertyChanged("Material")
m_Thickness = 0
NotifyPropertyChanged("Thickness")
m_WarehousePosition = String.Empty
NotifyPropertyChanged("WarehousePosition")
m_StartAddedDate = Nothing
NotifyPropertyChanged("StartAddedDate")
m_EndAddedDate = Nothing
NotifyPropertyChanged("EndAddedDate")
Search()
End Sub
#End Region ' Reset
#Region "Search"
''' <summary>
''' Returns a command that do Search.
''' </summary>
Public ReadOnly Property Search_Command As ICommand
Get
If m_cmdSearch Is Nothing Then
m_cmdSearch = New Command(AddressOf Search)
End If
Return m_cmdSearch
End Get
End Property
''' <summary>
''' Execute the Search. This method is invoked by the SearchCommand.
''' </summary>
Public Sub Search()
' attivo l'autoscroll
PhotoMap.refListPageVM.bAutoScrollOnTopList = True
Dim Query As String = "SELECT * FROM " & Slab.DB_SLABS & " "
Dim bFirstWhere As Boolean = True
If Not String.IsNullOrWhiteSpace(m_Id) OrElse
Not String.IsNullOrWhiteSpace(m_ImagePath) OrElse
Not m_State = 0 OrElse
Not String.IsNullOrWhiteSpace(m_ProjectAssignedTo) OrElse
Not String.IsNullOrWhiteSpace(m_Material) OrElse
m_Thickness > EPS_SMALL OrElse
Not String.IsNullOrWhiteSpace(m_WarehousePosition) OrElse
Not IsNothing(m_StartAddedDate) Then
Query &= "WHERE "
If Not String.IsNullOrWhiteSpace(m_Id) Then
Query &= Slab.DB_ID & " like '%" & m_Id.Trim & "%' AND "
bFirstWhere = True
End If
If Not String.IsNullOrWhiteSpace(m_ImagePath) Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_IMAGEPATH & " like '%" & m_ImagePath & "%' AND "
End If
If Not m_State = 0 Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_STATE & " = " & m_State & " AND "
End If
If Not String.IsNullOrWhiteSpace(m_ProjectAssignedTo) Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_PROJASSIGNEDTO & " like '%" & m_ProjectAssignedTo & "%' AND "
End If
If Not String.IsNullOrWhiteSpace(m_Material) Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_MATERIAL & " = '" & m_Material & "' AND "
End If
If m_Thickness > EPS_SMALL Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_THICKNESS & " BETWEEN " & m_Thickness - m_ThicknessTolerance & " AND " & m_Thickness + m_ThicknessTolerance & " AND "
End If
If Not String.IsNullOrWhiteSpace(m_WarehousePosition) Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_WAREHOUSEPOS & " like '%" & m_WarehousePosition & "%' AND "
End If
If Not IsNothing(m_StartAddedDate) Then
If Not IsNothing(m_EndAddedDate) Then
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_ADDEDDATE & " BETWEEN Date('" & (String.Format("{0:yyyy-MM-dd}", m_StartAddedDate)) & "') AND Date('" & (String.Format("{0:yyyy-MM-dd}", m_EndAddedDate)) & "') AND "
Else
EvalWhere(bFirstWhere, Query)
Query &= Slab.DB_ADDEDDATE & " = Date('" & (String.Format("{0:yyyy-MM-dd}", m_StartAddedDate)) & "') AND "
End If
End If
Query = Query.Substring(0, Query.Length - 5)
End If
PhotoMap.refProjectVM.SlabList = New ObservableCollection(Of Slab)(ManageDb.ExecuteSlabReaderQuery(Query))
RaiseEvent ScrollToTop()
End Sub
Private Sub EvalWhere(ByRef bFirst As Boolean, ByRef Query As String)
If bFirst Then
bFirst = False
Else
Query &= " AND "
End If
End Sub
#End Region ' Search
#End Region ' Commands
End Class