Files
EgtCAM5/Utility.vb
T
Dario Sassi 8008a9e48e EgtCAM5 1.8b2 :
- corretto problema con sottotipo lavorazione in gestione DB lavorazioni.
2017-03-07 11:22:32 +00:00

126 lines
3.8 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.Globalization
Imports EgtUILib
Public Module Utility
Friend Const ToolDrawUUIDName As String = "*AUTOMATIC*"
Friend Function DoubleToString(ByVal 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(ByVal sVal As String, ByRef dVal As Double) As Boolean
Return EgtLuaEvalNumExpr(sVal, dVal)
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
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