863 lines
31 KiB
VB.net
863 lines
31 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class OptionPanelSlabVM
|
|
Inherits VMBase
|
|
|
|
Public Event SlabIsSelectedOFFICE(ByRef sender As Object, ByVal e As EventArgs)
|
|
|
|
Public sSlabId As String
|
|
Public sProjectAssigned As String
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Public ReadOnly Property SelSlab As Slab
|
|
Get
|
|
If IsNothing(PhotoMap.refProjectVM) Then Return Nothing
|
|
Return PhotoMap.refProjectVM.SelSlab
|
|
End Get
|
|
End Property
|
|
|
|
Private m_StateList As New List(Of IdNameStruct)
|
|
Public Property StateList As List(Of IdNameStruct)
|
|
Get
|
|
If IsNothing(PhotoMap.refProjectVM) Then Return Nothing
|
|
m_StateList = PhotoMap.refProjectVM.StateList
|
|
Return PhotoMap.refProjectVM.StateList
|
|
End Get
|
|
Set(value As List(Of IdNameStruct))
|
|
m_StateList = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_LastState As IdNameStruct
|
|
Private m_SelState As New IdNameStruct
|
|
Public Property SelState As IdNameStruct
|
|
Get
|
|
Return m_SelState
|
|
End Get
|
|
Set(value As IdNameStruct)
|
|
If Not SelSlab.SetStatus(value.Id) Then
|
|
Application.Current.Dispatcher.BeginInvoke(New Action(Sub()
|
|
m_SelState = m_LastState
|
|
NotifyPropertyChanged("SelState")
|
|
End Sub), System.Windows.Threading.DispatcherPriority.ContextIdle, Nothing)
|
|
Else
|
|
m_SelState = value
|
|
NotifyPropertyChanged("SelState")
|
|
End If
|
|
End Set
|
|
End Property
|
|
Public Sub SetSelState(CurrState As IdNameStruct)
|
|
m_SelState = CurrState
|
|
m_LastState = m_SelState
|
|
NotifyPropertyChanged("SelState")
|
|
End Sub
|
|
|
|
|
|
Public ReadOnly Property MaterialList As List(Of String)
|
|
Get
|
|
If IsNothing(PhotoMap.refProjectVM) Then Return Nothing
|
|
Return PhotoMap.refProjectVM.MaterialList
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property PhotoCommand_Visibility As Visibility
|
|
Get
|
|
If Not IsNothing(PhotoMap.refProjectVM) Then
|
|
Select Case PhotoMap.refProjectVM.SelProjectMode
|
|
Case ProjectSlabVM.ProjectModeOpt.DETAIL
|
|
Return Visibility.Collapsed
|
|
Case ProjectSlabVM.ProjectModeOpt.NEWSLAB
|
|
Return Visibility.Visible
|
|
End Select
|
|
End If
|
|
Return Visibility.Collapsed
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Remove_Visibility As Visibility
|
|
Get
|
|
' se OmgaOFFICE nascondo il bottone
|
|
If MainData.bIsOmagOFFICE Then
|
|
Return Visibility.Collapsed
|
|
End If
|
|
' se OmagPHOTO
|
|
If Not IsNothing(PhotoMap.refProjectVM) Then
|
|
Select Case PhotoMap.refProjectVM.SelProjectMode
|
|
Case ProjectSlabVM.ProjectModeOpt.DETAIL
|
|
Return Visibility.Visible
|
|
Case ProjectSlabVM.ProjectModeOpt.NEWSLAB
|
|
Return Visibility.Collapsed
|
|
End Select
|
|
End If
|
|
Return Visibility.Collapsed
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property OkMsg_Visibility As Visibility
|
|
Get
|
|
' se OmgaOFFICE nascondo il bottone
|
|
If MainData.bIsOmagOFFICE Then
|
|
Return Visibility.Collapsed
|
|
End If
|
|
' se OmagPHOTO
|
|
Return Visibility.Visible
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Select_Visibility As Visibility
|
|
Get
|
|
' se OmgaOFFICE nascondo il bottone
|
|
If MainData.bIsOmagOFFICE Then
|
|
Return Visibility.Visible
|
|
End If
|
|
' se OmagPHOTO
|
|
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
|
|
|
|
Private m_Select_IsEnabled As Boolean = True
|
|
Public Property Select_IsEnabled As Boolean
|
|
Get
|
|
Return m_Select_IsEnabled
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_Select_IsEnabled = value
|
|
NotifyPropertyChanged("Select_IsEnabled")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_EnableParameters As Boolean = Not MainData.bIsOmagOFFICE
|
|
Public ReadOnly Property EnableParameters As Boolean
|
|
Get
|
|
Return m_EnableParameters
|
|
End Get
|
|
End Property
|
|
|
|
' la stampa delle etichette è abilitata solo dal programma OmagPHOTO
|
|
Public ReadOnly Property Print_Visibility As Visibility
|
|
Get
|
|
' se OmgaOFFICE nascondo il bottone
|
|
If MainData.bIsOmagOFFICE Then
|
|
Return Visibility.Collapsed
|
|
End If
|
|
' se OmagPHOTO
|
|
Return MainData.bVisibilityPrinter
|
|
|
|
|
|
End Get
|
|
End Property
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property IdMsg As String
|
|
Get
|
|
Return EgtMsg(MSG_SLAB + 1)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property BlockMsg As String
|
|
Get
|
|
Return "Blocco"
|
|
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
|
|
If Not IsNothing(PhotoMap.refProjectVM) Then
|
|
Select Case PhotoMap.refProjectVM.SelProjectMode
|
|
Case ProjectSlabVM.ProjectModeOpt.DETAIL
|
|
Return EgtMsg(MSG_OPTIONPANEL + 1)
|
|
Case ProjectSlabVM.ProjectModeOpt.NEWSLAB
|
|
Return EgtMsg(MSG_OPTIONPANEL + 2)
|
|
End Select
|
|
End If
|
|
Return "OkMsg"
|
|
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
|
|
|
|
Public ReadOnly Property SelectMsg As String
|
|
Get
|
|
Return EgtMsg(92060)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property PrintMsg As String
|
|
Get
|
|
Return EgtMsg(92059)
|
|
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
|
|
Private m_cmdSelected As ICommand
|
|
Private m_cmdPrint As ICommand
|
|
Private m_cmdRefreshPhoto As ICommand
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in StoneMap
|
|
PhotoMap.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()
|
|
' aggiungo la colonna per indicare se la lastra è in lettura in qualche programma
|
|
ManageDb.AddIsSelectedColumn()
|
|
' costruisco la tabella per indicare le modifiche effettuate
|
|
ManageDb.CreateDataTimeTable()
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Sub InitOptionPanel()
|
|
Select Case PhotoMap.refProjectVM.SelProjectMode
|
|
Case ProjectSlabVM.ProjectModeOpt.DETAIL
|
|
SelSlab.SetOrigValues()
|
|
SelSlab.ResetIsModified()
|
|
If MainData.bIsOmagOFFICE AndAlso SelSlab.State <> 1 Then
|
|
Select_IsEnabled = False
|
|
Else
|
|
Select_IsEnabled = True
|
|
End If
|
|
Case ProjectSlabVM.ProjectModeOpt.NEWSLAB
|
|
' verifico se devo inserire il valore dell'id
|
|
Dim sLastId As String = String.Empty
|
|
Dim sLastBlock As String = String.Empty
|
|
|
|
sLastBlock = MainData.sLastBlock
|
|
sLastId = Slab.GenerateIdNbr(sLastBlock)
|
|
|
|
NotifyPropertyChanged("EnableSlabId")
|
|
NotifyPropertyChanged("VisibilityBlock")
|
|
' Creo nuova lastra corrente con valori di default
|
|
PhotoMap.refProjectVM.SelSlab = New Slab(sLastId, sLastBlock, 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
|
|
|
|
' restituisce la lastra con l'identificativo indicato, altrimenti "nothing"
|
|
Private Function GetSlabById(ByVal sIdSlab As String) As Slab
|
|
Dim CurrSlab As Slab = Nothing
|
|
If Not String.IsNullOrEmpty(sIdSlab) Then
|
|
For Each ItemSlab In PhotoMap.refListPageVM.SlabList
|
|
If ItemSlab.Id = sIdSlab Then
|
|
CurrSlab = ItemSlab
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
Return CurrSlab
|
|
End Function
|
|
|
|
Public Function GetProjectAssigned(Optional ByVal sLocal_SlabId As String = "") As String
|
|
Dim ProjectSlab As String = String.Empty
|
|
Dim PreviousSlabOFFICE As Slab
|
|
' Aggiorno la precedente lastra selezionata
|
|
PreviousSlabOFFICE = GetSlabById(sLocal_SlabId)
|
|
If IsNothing(PreviousSlabOFFICE) Then
|
|
PreviousSlabOFFICE = GetSlabById(sSlabId)
|
|
End If
|
|
|
|
If Not IsNothing(PreviousSlabOFFICE) Then
|
|
ProjectSlab = PreviousSlabOFFICE.ProjectAssignedTo
|
|
End If
|
|
Return ProjectSlab
|
|
End Function
|
|
|
|
Public Sub SetMaterialFromDB()
|
|
Dim MatList As List(Of String) = ManageDb.FindAllMaterialInDB()
|
|
PhotoMap.refProjectVM.MaterialList.Clear()
|
|
For Each Item In MatList
|
|
PhotoMap.refProjectVM.MaterialList.Add(Item)
|
|
Next
|
|
PhotoMap.refOptionPanelVM.NotifyPropertyChanged("MaterialList")
|
|
End Sub
|
|
|
|
Public Sub Save()
|
|
SelSlab.IsSelected = 0
|
|
Select Case PhotoMap.refProjectVM.SelProjectMode
|
|
Case ProjectSlabVM.ProjectModeOpt.DETAIL
|
|
If SelSlab.IsModified Then
|
|
' Aggiorno la lastra con le modifiche (senza modificare la data)
|
|
Dim Query As String = "UPDATE " & Slab.DB_SLABS & " SET " &
|
|
If(SelSlab.IsModifiedId, Slab.DB_ID & " = '" & SelSlab.Id & "', ", "") &
|
|
If(SelSlab.IsModifiedImagePath, Slab.DB_IMAGEPATH & " = '" & SelSlab.ImagePath & "', ", "") &
|
|
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 & "',", "") &
|
|
Slab.DB_ISSELECTED & " = " & SelSlab.IsSelected.ToString
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= " WHERE Id = '" & SelSlab.OrigId & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
End If
|
|
Case ProjectSlabVM.ProjectModeOpt.NEWSLAB
|
|
' Copio immagine
|
|
Dim sImgSource As String
|
|
If SelSlab.ImagePath = "*" Then
|
|
sImgSource = PhotoMap.refProjectVM.m_Camera.ImageDir & "\" & Camera.FINAL_IMAGE
|
|
Else
|
|
sImgSource = SelSlab.ImagePath
|
|
End If
|
|
Dim sCopyImagePath As String = CopyPhoto(sImgSource)
|
|
If Not String.IsNullOrEmpty(sCopyImagePath) Then
|
|
SelSlab.ImagePath = sCopyImagePath
|
|
Else
|
|
Dim sMsg As String = "Error copying image or auxiliary info"
|
|
LibMap.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 & ", " &
|
|
Slab.DB_ISSELECTED & ")" &
|
|
" VALUES ('" & SelSlab.Id & "', " &
|
|
"'" & SelSlab.ImagePath & "', " &
|
|
SelSlab.State & ", " &
|
|
"'" & SelSlab.ProjectAssignedTo & "', " &
|
|
"'" & SelSlab.Material & "', " &
|
|
SelSlab.Thickness & ", " &
|
|
"'" & SelSlab.WarehousePosition & "', " &
|
|
"Date('" & (String.Format("{0:yyyy-MM-dd}", SelSlab.AddedDate)) & "'), " &
|
|
SelSlab.IsSelected & ")"
|
|
ManageDb.ExecuteQuery(Query)
|
|
|
|
' comunico al programma che ha eseguito la chiamata l'aggiornamento dell'indice dell'ultima lastra inserita
|
|
If Not MainData.bEnableTextId Then WriteMainPrivateProfileString(S_GENERAL, "LastBlock", SelSlab.sNameBlock)
|
|
MainData.sLastBlock = SelSlab.sNameBlock
|
|
End Select
|
|
PhotoMap.refOptionPanelVM.IsSelected()
|
|
SelSlab.ResetIsModified()
|
|
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 PhotoMap.refProjectVM.m_Camera.GetCameraLink() Then
|
|
If PhotoMap.refProjectVM.m_Camera.CameraClick() Then
|
|
SelSlab.ImagePath = "*"
|
|
Else
|
|
LibMap.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
|
|
PhotoMap.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 PhotoMap.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
|
|
' Aggiorno visualizzazione
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Function CopyPhoto(OrigPath As String) As String
|
|
Dim OrigTxtPath As String = Path.ChangeExtension(OrigPath, "txt")
|
|
Dim ImgName As String = ValidateFileName(SelSlab.Id)
|
|
Dim ImgExt As String = Path.GetExtension(OrigPath)
|
|
Dim nI As Integer = 0
|
|
Dim NewImgPath As String = Path.Combine(MainData.sPhotoDir, ImgName & ImgExt)
|
|
While File.Exists(NewImgPath)
|
|
nI += 1
|
|
NewImgPath = Path.Combine(MainData.sPhotoDir, ImgName & "_" & nI.ToString() & ImgExt)
|
|
End While
|
|
Dim NewTxtPath As String = Path.ChangeExtension(NewImgPath, "txt")
|
|
Try
|
|
File.Copy(OrigPath, NewImgPath, True)
|
|
File.Copy(OrigTxtPath, NewTxtPath, True)
|
|
Catch ex As Exception
|
|
Return String.Empty
|
|
End Try
|
|
Return Path.GetFileName(NewImgPath)
|
|
End Function
|
|
|
|
Private Function ValidateFileName(sFileName As String) As String
|
|
Dim sTemp As String = sFileName
|
|
For Each badChar As Char In Path.GetInvalidFileNameChars()
|
|
sTemp = sTemp.Replace(badChar, "_")
|
|
Next
|
|
Return sTemp
|
|
End Function
|
|
|
|
#End Region ' PhotoCommand
|
|
|
|
#Region "Select"
|
|
|
|
Public ReadOnly Property EnableSlabId As Boolean
|
|
Get
|
|
Return MainData.bEnableTextId
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property VisibilityBlock As Visibility
|
|
Get
|
|
Return MainData.vVisibilityBlock
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Selected_Command As ICommand
|
|
Get
|
|
If m_cmdSelected Is Nothing Then
|
|
m_cmdSelected = New Command(AddressOf Selected)
|
|
End If
|
|
Return m_cmdSelected
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub SetAvailableSlab(Optional ByVal sLocal_SlabId As String = "")
|
|
Dim Query As String
|
|
Dim PreviousSlabOFFICE As Slab
|
|
' Aggiorno la precedente lastra selezionata
|
|
PreviousSlabOFFICE = GetSlabById(sLocal_SlabId)
|
|
If IsNothing(PreviousSlabOFFICE) Then
|
|
PreviousSlabOFFICE = GetSlabById(sSlabId)
|
|
End If
|
|
|
|
If Not IsNothing(PreviousSlabOFFICE) Then
|
|
' Assegno lo stato AVAILABLE
|
|
If PreviousSlabOFFICE.State <> Slab.StateOpt.TAKEN Then
|
|
PreviousSlabOFFICE.SetStatus(Slab.StateOpt.AVAILABLE)
|
|
End If
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_STATE & " = '" & PreviousSlabOFFICE.State & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & PreviousSlabOFFICE.Id & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
' Cancello il Progetto
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_PROJASSIGNEDTO & " = '" & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & PreviousSlabOFFICE.Id & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub SetAssignedSlab(Optional ByVal sLocal_SlabId As String = "")
|
|
Dim Query As String
|
|
Dim PreviousSlabOFFICE As Slab
|
|
' Aggiorno la precedente lastra selezionata
|
|
PreviousSlabOFFICE = GetSlabById(sLocal_SlabId)
|
|
If IsNothing(PreviousSlabOFFICE) Then
|
|
PreviousSlabOFFICE = GetSlabById(sSlabId)
|
|
End If
|
|
|
|
If Not IsNothing(PreviousSlabOFFICE) Then
|
|
' Assegno lo stato ASSIGNED
|
|
If PreviousSlabOFFICE.State <> Slab.StateOpt.TAKEN Then
|
|
PreviousSlabOFFICE.SetStatus(Slab.StateOpt.ASSIGNED)
|
|
End If
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_STATE & " = '" & PreviousSlabOFFICE.State & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & PreviousSlabOFFICE.Id & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
' Assegno il Progetto
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_PROJASSIGNEDTO & " = '" & sProjectAssigned & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & PreviousSlabOFFICE.Id & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub Selected(ByVal param As Object)
|
|
PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST
|
|
Dim Query As String
|
|
' Aggiorno la lastra con le modifiche
|
|
' Assegno lo stato ASSIGNED
|
|
PhotoMap.refProjectVM.SelSlab.SetStatus(Slab.StateOpt.ASSIGNED)
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_STATE & " = '" & SelSlab.State & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & SelSlab.OrigId & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
' Assegno il Progetto
|
|
If Not String.IsNullOrEmpty(sProjectAssigned) Then
|
|
SelSlab.ProjectAssignedTo = sProjectAssigned
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_PROJASSIGNEDTO & " = '" & sProjectAssigned & "', "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= "WHERE Id = '" & SelSlab.Id & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
End If
|
|
PhotoMap.refProjectVM.SelSlab.IsSelected = 0
|
|
PhotoMap.refOptionPanelVM.IsSelected()
|
|
' comunico l'evento di modifica della pagina
|
|
RaiseEvent SlabIsSelectedOFFICE(Me, EventArgs.Empty)
|
|
End Sub
|
|
|
|
Public Sub IsSelected()
|
|
Dim Query As String
|
|
Query = "UPDATE " & Slab.DB_SLABS & " SET " & Slab.DB_ISSELECTED & " = " & SelSlab.IsSelected & ", "
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
Query &= " WHERE Id = '" & SelSlab.OrigId & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
|
|
Query = "UPDATE " & Slab.DB_DATATIME & " SET " & "LastModify" & " = " & "'" & (String.Format("{0:MM/dd/yy H:mm:ss}", DateTime.Now)) & "'"
|
|
Query &= " WHERE Id = " & "'" & MainData.sUser & "'"
|
|
ManageDb.ExecuteQuery(Query)
|
|
Query = String.Empty
|
|
End Sub
|
|
|
|
#End Region ' SelectCommand
|
|
|
|
#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)
|
|
Save()
|
|
PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.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)
|
|
PhotoMap.refProjectVM.SelSlab.IsSelected = 0
|
|
PhotoMap.refOptionPanelVM.IsSelected()
|
|
PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST
|
|
SelSlab.ResetIsModified()
|
|
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)
|
|
' chiedo conferma
|
|
If MessageBox.Show(EgtMsg(MSG_OPTIONPANEL + 5), "", MessageBoxButton.YesNo, MessageBoxImage.Question) <>
|
|
MessageBoxResult.Yes Then Return
|
|
Dim sImagePath As String = SelSlab.ImagePath
|
|
PhotoMap.refProjectVM.SelSlab.IsSelected = 0
|
|
PhotoMap.refOptionPanelVM.IsSelected()
|
|
' 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 = MainData.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
|
|
PhotoMap.refProjectVM.SlabList.Remove(SelSlab)
|
|
' torno alla lista
|
|
PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST
|
|
SelSlab.ResetIsModified()
|
|
End Sub
|
|
|
|
#End Region ' Remove
|
|
|
|
#Region "Print"
|
|
|
|
Public ReadOnly Property Print_Command As ICommand
|
|
Get
|
|
If m_cmdPrint Is Nothing Then
|
|
m_cmdPrint = New Command(AddressOf PrintLabel)
|
|
End If
|
|
Return m_cmdPrint
|
|
End Get
|
|
End Property
|
|
|
|
Private Sub CreateDataFile(sFilePath As String)
|
|
Dim sFileText As New List(Of String)
|
|
' inserisco il capitolo del [Main]
|
|
sFileText.Add("[Main]")
|
|
sFileText.Add("Var1=$Name$," & SelSlab.Id)
|
|
sFileText.Add("Var2=$Status$," & SelSlab.State.ToString)
|
|
sFileText.Add("Var3=$Project$," & SelSlab.ProjectAssignedTo)
|
|
sFileText.Add("Var4=$Material$," & SelSlab.Material)
|
|
sFileText.Add("Var5=$Thickness$," & SelSlab.Thickness)
|
|
sFileText.Add("Var6=$Storage$," & SelSlab.WarehousePosition)
|
|
Try
|
|
File.WriteAllLines(sFilePath, sFileText)
|
|
Catch ex As Exception
|
|
EgtOutLog(ex.ToString)
|
|
End Try
|
|
End Sub
|
|
|
|
Public Sub PrintLabel()
|
|
' verifico se sono stati modificati dei campi
|
|
Dim bModified As Boolean = SelSlab.IsModified
|
|
If bModified Then
|
|
If MessageBox.Show(EgtMsg(92200), EgtMsg(92201), MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.No Then
|
|
Return
|
|
End If
|
|
' salvo nel db
|
|
Save()
|
|
End If
|
|
|
|
Dim FileTEMPLATE As String = MainData.sTemplateFilePrinter
|
|
Dim FileName As String = DateTime.Now.ToString
|
|
FileName = FileName.Replace("/"c, "_")
|
|
FileName = FileName.Replace(":"c, "_")
|
|
FileName = FileName.Replace(" "c, "&")
|
|
Dim FileINI As String = MainData.sDataFilePrinter & "\" & FileName & ".ini"
|
|
' carea file dati da OmagPHOTO
|
|
CreateDataFile(FileINI)
|
|
Dim ProcsPrint As Process() = Process.GetProcessesByName(MainData.sZebraPrinterExe)
|
|
Process.Start(MainData.sZebraPrinterExe, FileTEMPLATE & " " & FileINI)
|
|
|
|
'If ProcsPrint.Length() > 0 Then
|
|
' ShowWindow(ProcsPrint(0).MainWindowHandle, 3)
|
|
'Else
|
|
' Process.Start("c:\EgtProg\OmagPHOTO\ZebraPrinterUtilityR32.exe", FileTEMPLATE & "," & FileINI)
|
|
'End If
|
|
|
|
Dim sFileError As String = MainData.sDataFilePrinter & "\" & "Error.txt"
|
|
ReadFileErrorPrinter(sFileError)
|
|
|
|
If bModified Then
|
|
PhotoMap.refProjectVM.SelProjectMode = ProjectSlabVM.ProjectModeOpt.LIST
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ReadFileErrorPrinter(sPathFileError As String)
|
|
Dim sErrorMsg As String = String.Empty
|
|
'Dim sPathFileError As String = m_sDataRoot & "\Temp\" & "Error.txt"
|
|
' provo a recuperare il mesaggio di errore
|
|
If File.Exists(sPathFileError) Then
|
|
Dim sAllLines As String() = File.ReadAllLines(sPathFileError)
|
|
' verifico che ci sia almeno una riga nel file degli errori
|
|
If sAllLines.Count > 0 Then
|
|
' verifico che la prima riga non sia vuota
|
|
Dim Index As Integer = 0
|
|
While String.IsNullOrEmpty(sAllLines(Index))
|
|
Index += 1
|
|
If Index > sAllLines.Count Then
|
|
EgtOutLog("Il messaggio di errore della stampante non è comprensibile: " & sAllLines(Index))
|
|
Return
|
|
End If
|
|
End While
|
|
Dim sItems As String() = sAllLines(Index).Split("=")
|
|
'verifico che sia avvenuto lo split
|
|
If sItems.Count > 1 Then
|
|
' verifico che il termine dopo il segno di uguale sia un numero
|
|
Dim nErrorIndex As Integer = -1
|
|
Try
|
|
nErrorIndex = CInt(sItems(1))
|
|
' se nErrorIndex=0 significa che non ci sono errori
|
|
If nErrorIndex < 1 Then
|
|
Return
|
|
End If
|
|
Catch ex As Exception
|
|
EgtOutLog("Il messaggio di errore della stampante non è comprensibile: " & sAllLines(Index))
|
|
Return
|
|
End Try
|
|
sErrorMsg = EgtMsg(nErrorIndex + 91460)
|
|
End If
|
|
End If
|
|
End If
|
|
' eventualmente stampo il messaggio
|
|
If Not String.IsNullOrEmpty(sErrorMsg) Then
|
|
LibMap.refStatusBarVM.SetOutputMessage(sErrorMsg, 5, MSG_TYPE.ERROR_)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' Print
|
|
|
|
#Region "RefreshPhoto"
|
|
Public ReadOnly Property RefreshPhoto_Command As ICommand
|
|
Get
|
|
If m_cmdRefreshPhoto Is Nothing Then
|
|
m_cmdRefreshPhoto = New Command(AddressOf RefeshPhoto)
|
|
End If
|
|
Return m_cmdRefreshPhoto
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub RefeshPhoto(ByVal param As Object)
|
|
If Not String.IsNullOrEmpty(SelSlab.ImagePath) Then
|
|
PostPhoto(SelSlab.ImagePath, String.Empty)
|
|
EgtZoom(ZM.ALL)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' RefreshPhoto
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|