Files
OmagPHOTO/OptionPanel/OptionPanelVM.vb
T
Emmanuele Sassi e60bef9257 OmagPHOTO :
- Aggiunto AboutBox.
- Migliorie varie.
2017-12-01 18:39:12 +00:00

407 lines
14 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class OptionPanelVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Public ReadOnly Property SelSlab As Slab
Get
Return Map.refProjectVM.SelSlab
End Get
End Property
Public ReadOnly Property StateList As List(Of IdNameStruct)
Get
Return Map.refProjectVM.StateList
End Get
End Property
Public ReadOnly Property MaterialList As List(Of String)
Get
Return Map.refProjectVM.MaterialList
End Get
End Property
Public ReadOnly Property PhotoCommand_Visibility As Visibility
Get
Select Case Map.refProjectVM.SelProjectMode
Case ProjectVM.ProjectModeOpt.DETAIL
Return Visibility.Collapsed
Case ProjectVM.ProjectModeOpt.NEWSLAB
Return Visibility.Visible
End Select
Return Visibility.Collapsed
End Get
End Property
Public ReadOnly Property Remove_Visibility As Visibility
Get
Select Case Map.refProjectVM.SelProjectMode
Case ProjectVM.ProjectModeOpt.DETAIL
Return Visibility.Visible
Case ProjectVM.ProjectModeOpt.NEWSLAB
Return Visibility.Collapsed
End Select
Return Visibility.Collapsed
End Get
End Property
Private m_Ok_IsEnabled As Boolean = True
Public Property Ok_IsEnabled As Boolean
Get
Return m_Ok_IsEnabled
End Get
Set(value As Boolean)
m_Ok_IsEnabled = value
NotifyPropertyChanged("Ok_IsEnabled")
End Set
End Property
#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 OkMsg As String
Get
Select Case Map.refProjectVM.SelProjectMode
Case ProjectVM.ProjectModeOpt.DETAIL
Return EgtMsg(MSG_OPTIONPANEL + 1)
Case ProjectVM.ProjectModeOpt.NEWSLAB
Return EgtMsg(MSG_OPTIONPANEL + 2)
End Select
End Get
End Property
Public ReadOnly Property CancelMsg As String
Get
Return EgtMsg(MSG_OPTIONPANEL + 3)
End Get
End Property
Public ReadOnly Property RemoveMsg As String
Get
Return EgtMsg(MSG_OPTIONPANEL + 4)
End Get
End Property
#End Region ' Messages
#Region "ToolTip"
Public ReadOnly Property PhotoToolTip As String
Get
Return EgtMsg(MSG_RAWPARTTAB + 2)
End Get
End Property
#End Region ' ToolTip
' Definizione comandi
Private m_cmdPhoto As ICommand
Private m_cmdOk As ICommand
Private m_cmdCancel As ICommand
Private m_cmdRemove As ICommand
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in Map
Map.SetRefOptionPanelVM(Me)
' Assegno funzione per disabilitare bottone di conferma alla lista
Slab.m_IsEnabledBtn = AddressOf IsEnabledBtn
' Funzioni per creare nuovo file Db con tabella
''CreateDbFile()
''CreateTable()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub InitOptionPanel()
Select Case Map.refProjectVM.SelProjectMode
Case ProjectVM.ProjectModeOpt.DETAIL
SelSlab.SetOrigValues()
SelSlab.ResetIsModified()
Case ProjectVM.ProjectModeOpt.NEWSLAB
' Creo nuova lastra corrente con valori di default
Map.refProjectVM.SelSlab = New Slab(String.Empty, String.Empty, Slab.StateOpt.AVAILABLE, String.Empty, String.Empty, 0, String.Empty)
' Creo nuovo progetto
EgtNewFile()
EgtZoom(ZM.ALL)
End Select
' Aggiorno visualizzazione bottone foto perchè potrei essere passato da mod detail a newslab
NotifyPropertyChanged("PhotoCommand_Visibility")
NotifyPropertyChanged("Remove_Visibility")
NotifyPropertyChanged("OkMsg")
NotifyPropertyChanged("SelSlab")
' Aggiorno stato bottone di conferma
IsEnabledBtn(SelSlab.IsValid)
End Sub
Private Sub IsEnabledBtn(IsEnabled As Boolean)
Ok_IsEnabled = IsEnabled
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "PhotoCommand"
Public ReadOnly Property PhotoCommand As ICommand
Get
If m_cmdPhoto Is Nothing Then
m_cmdPhoto = New Command(AddressOf Photo)
End If
Return m_cmdPhoto
End Get
End Property
Public Sub Photo(ByVal param As Object)
' Se macchina fotografica collegata, faccio una foto
If Map.refMainWindowVM.m_Camera.GetCameraLink() Then
If Map.refMainWindowVM.m_Camera.CameraClick() Then
SelSlab.ImagePath = "*"
Else
Map.refStatusBarVM.SetOutputMessage(EgtMsg(90313), 5, MSG_TYPE.ERROR_) 'Fotografia non riuscita
End If
' Altrimenti lancio browser di immagini
Else
PhotoFromFile()
End If
End Sub
Friend Sub PostPhoto(sPath As String, sContour As String)
' Carico la foto
Map.refDetailPageVM.LoadPhoto(sPath)
' Se richiesto il riconoscimento del contorno
'If Not String.IsNullOrEmpty(sContour) Then
' If Not m_MainWindow.m_CurrentProjectPageUC.LoadContour(sContour) Then
' m_MainWindow.m_CurrentProjectPageUC.SetWarningMessage(EgtMsg(90324)) 'Riconoscimento contorno non riuscito
' End If
'End If
' Aggiorno visualizzazione
EgtZoom(ZM.ALL)
End Sub
Friend Sub PhotoFromFile()
' Apro dialogo per scelta immagine
Dim PhotoDlg As New Microsoft.Win32.OpenFileDialog
PhotoDlg.Title = "Open"
PhotoDlg.Filter = "Image file(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp"
PhotoDlg.FilterIndex = 1
GetMainPrivateProfileString(S_GENERAL, K_IMAGEDIR, "", PhotoDlg.InitialDirectory)
If Not PhotoDlg.ShowDialog Then Return
Dim sPhoto As String = PhotoDlg.FileName
' Assegno la path dell'immagine selezionata
SelSlab.ImagePath = sPhoto
' Altri dati foto
' Carico immagine
If Not Map.refDetailPageVM.LoadPhoto(sPhoto) Then
' Errore nel caricamento della fotografia
MessageBox.Show(EgtMsg(MSG_RAWPARTTAB + 1), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
'' Carico contorno
'EstPhoto.LoadContour(sPhoto)
'Dim nCntId As Integer = EstPhoto.GetContour()
'' Se disponibile, imposto possibilità di contorno da foto
'If nCntId = GDB_ID.NULL Then
' If m_TypeList.Count = 3 Then m_TypeList.Remove(2)
'Else
' If m_TypeList.Count = 2 Then m_TypeList.Add(EgtMsg(MSG_RAWPARTPAGEUC + 35))
' SelType = Type.FROM_PHOTO
' NotifyPropertyChanged("SelType")
'End If
'' Se sporge dalla tavola, lo centro sulla stessa
'If nCntId <> GDB_ID.NULL Then
' Dim b3Cnt As New BBox3d
' EgtGetBBoxGlob(nCntId, GDB_BB.STANDARD, b3Cnt)
' Dim b3Tab As New BBox3d(m_ptTableMin, m_ptTableMin + New Vector3d(m_dTableLength, m_dTableWidth, 0))
' If Not b3Tab.EnclosesXY(b3Cnt) Then ModifyPhoto(b3Tab.Center() - b3Cnt.Center())
'End If
' Aggiorno visualizzazione
EgtZoom(ZM.ALL)
End Sub
Private Function CopyPhoto(OrigPath As String) As String
Dim OrigTxtPath As String = Path.ChangeExtension(OrigPath, "txt")
Dim NewImgPath As String = Map.refMainWindowVM.MainWindowM.sPhotoDir & "\" & SelSlab.Id & Path.GetExtension(OrigPath)
Dim NewTxtPath As String = Path.ChangeExtension(NewImgPath, "txt")
Try
File.Copy(OrigPath, NewImgPath, True)
File.Copy(OrigTxtPath, NewTxtPath, True)
Catch ex As FileNotFoundException
' non è un problema
Catch ex As Exception
Return String.Empty
End Try
Return SelSlab.Id & Path.GetExtension(OrigPath)
End Function
#End Region ' PhotoCommand
#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(ByVal param As Object)
Select Case Map.refProjectVM.SelProjectMode
Case ProjectVM.ProjectModeOpt.DETAIL
If SelSlab.IsModified Then
' Aggiorno la lastra con le modifiche
Dim Query As String = "UPDATE " & Slab.DB_SLABS & " SET " &
If(SelSlab.IsModifiedId, Slab.DB_ID & " = '" & SelSlab.Id & "', ", "") &
If(SelSlab.IsModifiedState, Slab.DB_STATE & " = '" & SelSlab.State & "', ", "") &
If(SelSlab.IsModifiedProjectAssignedTo, Slab.DB_PROJASSIGNEDTO & " = '" & SelSlab.ProjectAssignedTo & "', ", "") &
If(SelSlab.IsModifiedMaterial, Slab.DB_MATERIAL & " = '" & SelSlab.Material & "', ", "") &
If(SelSlab.IsModifiedThickness, Slab.DB_THICKNESS & " = '" & SelSlab.Thickness & "', ", "") &
If(SelSlab.IsModifiedWarehousePosition, Slab.DB_WAREHOUSEPOS & " = '" & SelSlab.WarehousePosition & "'", "")
Query = Query.TrimEnd(","c, " "c)
Query &= "WHERE Id = '" & SelSlab.OrigId & "'"
ManageDb.ExecuteQuery(Query)
End If
Case ProjectVM.ProjectModeOpt.NEWSLAB
' Copio immagine
Dim sImgSource As String
If SelSlab.ImagePath = "*" Then
sImgSource = Map.refMainWindowVM.m_Camera.ImageDir & "\" & Camera.FINAL_IMAGE
Else
sImgSource = SelSlab.ImagePath
End If
SelSlab.ImagePath = CopyPhoto(sImgSource)
If String.IsNullOrEmpty(SelSlab.ImagePath) Then
Dim sMsg As String = ""
Map.refStatusBarVM.SetOutputMessage(sMsg, 5, MSG_TYPE.ERROR_)
Return
End If
' Aggiungo la nuova lastra al Db
Dim Query As String = "INSERT INTO " & Slab.DB_SLABS & " (" & Slab.DB_ID & ", " & Slab.DB_IMAGEPATH & ", " & Slab.DB_STATE & ", " & Slab.DB_PROJASSIGNEDTO & ", " & Slab.DB_MATERIAL & ", " & Slab.DB_THICKNESS & ", " & Slab.DB_WAREHOUSEPOS & ", " & Slab.DB_ADDEDDATE & ")" &
" VALUES ('" & SelSlab.Id & "', " &
"'" & SelSlab.ImagePath & "', " &
SelSlab.State & ", " &
"'" & SelSlab.ProjectAssignedTo & "', " &
"'" & SelSlab.Material & "', " &
SelSlab.Thickness & ", " &
"'" & SelSlab.WarehousePosition & "', " &
"Date('" & (String.Format("{0:yyyy-MM-dd}", SelSlab.AddedDate)) & "'))"
ManageDb.ExecuteQuery(Query)
End Select
Map.refProjectVM.SelProjectMode = ProjectVM.ProjectModeOpt.LIST
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(ByVal param As Object)
Map.refProjectVM.SelProjectMode = ProjectVM.ProjectModeOpt.LIST
End Sub
#End Region ' Cancel
#Region "Remove"
Public ReadOnly Property Remove_Command As ICommand
Get
If m_cmdRemove Is Nothing Then
m_cmdRemove = New Command(AddressOf Remove)
End If
Return m_cmdRemove
End Get
End Property
Public Sub Remove(ByVal param As Object)
Dim sImagePath As String = SelSlab.ImagePath
' elimino dal Db
Dim Query As String = "DELETE FROM " & Slab.DB_SLABS & " WHERE " &
Slab.DB_ID & " = '" & SelSlab.Id & "'"
If ManageDb.ExecuteQuery(Query) <> 0 Then
' elimino anche la relativa foto
Try
If Not File.Exists(sImagePath) Then
sImagePath = Map.refMainWindowVM.MainWindowM.sPhotoDir & "\" & sImagePath
End If
File.Delete(sImagePath)
File.Delete(Path.ChangeExtension(sImagePath, "txt"))
Catch ex As FileNotFoundException
' non è un problema
Catch ex As Exception
' non è un problema
End Try
End If
' elimino dalla lista
Map.refProjectVM.SlabList.Remove(SelSlab)
' torno alla lista
Map.refProjectVM.SelProjectMode = ProjectVM.ProjectModeOpt.LIST
End Sub
#End Region ' Remove
#End Region ' COMMANDS
End Class