0bc3faa4bf
- Spostamento Parametri e metodi lettura/scrittura delle Operazioni in EgtWPFLib5 - Creazione diverse "paginette" per ciascun tipo di Operazione
149 lines
4.6 KiB
VB.net
149 lines
4.6 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Globalization
|
|
Imports EgtUILib
|
|
|
|
Public Module Utility
|
|
|
|
Friend Const ToolDrawUUIDName As String = "*AUTOMATIC*"
|
|
|
|
Friend Function DoubleToString(dVal As Double, ByVal nNumDec As Integer) As String
|
|
Dim sFormat As String = "F" + Math.Abs(nNumDec).ToString()
|
|
Dim sVal As String = dVal.ToString(sFormat, CultureInfo.InvariantCulture)
|
|
If nNumDec > 0 Then
|
|
Return sVal.TrimEnd("0".ToCharArray()).TrimEnd(".".ToCharArray)
|
|
Else
|
|
Return sVal
|
|
End If
|
|
End Function
|
|
|
|
Friend Function StringToDouble(sVal As String, ByRef dVal As Double) As Boolean
|
|
Return EgtLuaEvalNumExpr(sVal, dVal)
|
|
End Function
|
|
|
|
Friend Function StringToInt(sVal As String, ByRef nVal As Integer) As Boolean
|
|
Dim dVal As Double = 0
|
|
If Not StringToDouble(sVal, dVal) Then Return False
|
|
nVal = CInt(Math.Round(dVal))
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function LenToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
|
|
Return DoubleToString(EgtToUiUnits(dVal), nNumDec)
|
|
End Function
|
|
|
|
Friend Function StringToLen(ByVal sVal As String, ByRef dVal As Double) As Boolean
|
|
If EgtLuaEvalNumExpr(sVal, dVal) Then
|
|
dVal = EgtFromUiUnits(dVal)
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Friend Function IsUUID(UUID As String) As Boolean
|
|
Dim result As Guid
|
|
Return Guid.TryParse(UUID, result)
|
|
End Function
|
|
|
|
Friend Sub UpdateUI()
|
|
' Costringo ad aggiornare UI
|
|
Dim nDummy As Integer
|
|
Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, _
|
|
New Action(Function() nDummy = 0))
|
|
End Sub
|
|
|
|
Public Structure IdNameStruct
|
|
|
|
Private m_Id As Integer
|
|
Public Property Id As Integer
|
|
Get
|
|
Return m_Id
|
|
End Get
|
|
Set(value As Integer)
|
|
m_Id = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_Name As String
|
|
Public Property Name As String
|
|
Get
|
|
Return m_Name
|
|
End Get
|
|
Set(value As String)
|
|
m_Name = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(Id As Integer, Name As String)
|
|
m_Id = Id
|
|
m_Name = Name
|
|
End Sub
|
|
|
|
Public Overrides Function ToString() As String
|
|
Return Name
|
|
End Function
|
|
|
|
Friend Shared Function IndFromId(Id As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
|
|
For i = 0 To List.Count - 1
|
|
If List(i).Id = Id Then Return i
|
|
Next
|
|
Return 0
|
|
End Function
|
|
|
|
Friend Shared Function IdFromInd(Ind As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
|
|
Return List(Ind).Id
|
|
End Function
|
|
|
|
Public Shared Function IndFromId(Id As Integer, List As ObservableCollection(Of Object)) As Integer
|
|
For i = 0 To List.Count - 1
|
|
If TypeOf (List(i)) Is IdNameStruct AndAlso DirectCast(List(i), IdNameStruct).Id = Id Then
|
|
Return i
|
|
End If
|
|
Next
|
|
Return 0
|
|
End Function
|
|
|
|
Public Shared Function IdFromInd(Ind As Integer, List As ObservableCollection(Of Object)) As Integer
|
|
If TypeOf (List(Ind)) Is IdNameStruct Then
|
|
Return DirectCast(List(Ind), IdNameStruct).Id
|
|
End If
|
|
Return 0
|
|
End Function
|
|
|
|
End Structure
|
|
|
|
#Region "Positioning test"
|
|
|
|
Public Class WinPos
|
|
Public nFlag As Integer
|
|
Public nLeft As Integer
|
|
Public nTop As Integer
|
|
Public nWidth As Integer
|
|
Public nHeight As Integer
|
|
End Class
|
|
|
|
Friend Sub WinPosToWindow(Window As Window, WinPos As WinPos)
|
|
Window.WindowStartupLocation = WindowStartupLocation.Manual
|
|
Window.Top = WinPos.nTop
|
|
Window.Left = WinPos.nLeft
|
|
Window.Height = WinPos.nHeight
|
|
Window.Width = WinPos.nWidth
|
|
Window.WindowState = If(WinPos.nFlag = 1, WindowState.Maximized, WindowState.Normal)
|
|
End Sub
|
|
|
|
Friend Sub WindowToWinPos(Window As Window, WinPos As WinPos)
|
|
WinPos.nTop = CInt(Window.Top)
|
|
WinPos.nLeft = CInt(Window.Left)
|
|
WinPos.nHeight = CInt(Window.Height)
|
|
WinPos.nWidth = CInt(Window.Width)
|
|
WinPos.nFlag = If(Window.WindowState = WindowState.Maximized, 1, 0)
|
|
If Window.WindowState = WindowState.Maximized Then
|
|
WinPos.nHeight = CInt(Window.RestoreBounds.Height)
|
|
WinPos.nWidth = CInt(Window.RestoreBounds.Width)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
End Module
|