Files
EgtCAM5/MTableDb/MTableDbV.xaml.vb
T
Emmanuele Sassi db6662ec48 EgtCAM5 :
- Aggiunta ricerca su MTable lavorazioni ordinate.
- Aggiunta possibilità in MTable di spostare anche le righe della tabella associazioni.
- Migliorie varie.
2017-07-21 17:52:04 +00:00

155 lines
6.6 KiB
VB.net

Imports System.Windows
Imports System.Windows.Controls.Primitives
Imports EgtCAM5.EgtCAM5
Imports EgtWPFLib5
Public Class MTableDbV
Private m_MTableDbVM As MTableDbVM
Private m_EditCell As DataGridCell
Sub New(Owner As Window, MTableDbVM As MTableDbVM)
MyBase.New(Owner)
' This call is required by the designer.
InitializeComponent()
Me.DataContext = MTableDbVM
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_MTableDbVM = MTableDbVM
End Sub
Private Sub LeftTableMouseDown(sender As Object, e As MouseButtonEventArgs)
m_MTableDbVM.FocusedTable = MTableDbVM.Tables.LEFTTABLE
m_MTableDbVM.ResetRightTableSelection()
End Sub
Private Sub RowMouseDown(sender As Object, e As MouseButtonEventArgs)
m_MTableDbVM.FocusedTable = MTableDbVM.Tables.RIGHTTABLE
m_MTableDbVM.ResetLeftTableSelection()
End Sub
Private Sub RowRightClick(sender As Object, e As MouseButtonEventArgs)
m_MTableDbVM.FocusedTable = MTableDbVM.Tables.RIGHTTABLE
m_MTableDbVM.ResetLeftTableSelection()
e.Handled = True
End Sub
Private Sub CellLeftClick(sender As Object, e As MouseButtonEventArgs)
Dim CurrCell As DataGridCell = Nothing
If TypeOf sender Is DataGridCell Then
CurrCell = DirectCast(sender, DataGridCell)
End If
Dim SelectedRow As MTableMachiningGridBoxItem = DirectCast(CurrCell.DataContext, MTableMachiningGridBoxItem)
Dim bFirstInGroup As Boolean = True
For TableIndex = 0 To MTableDbVM.refMTableDbVM.TablesList.Count - 1
Dim CurrTable As MTableListBoxItem = MTableDbVM.refMTableDbVM.TablesList(TableIndex)
If CurrTable.IsSelected Then
Dim CurrMachiningIndex As Integer = CurrTable.SelMachine.MachiningList.IndexOf(SelectedRow)
If CurrMachiningIndex > 0 AndAlso CurrTable.SelMachine.MachiningList(CurrMachiningIndex - 1).GroupId = SelectedRow.GroupId Then
bFirstInGroup = False
End If
End If
Next
Dim bSelCell As Boolean = False
If Not IsNothing(CurrCell) AndAlso TypeOf CurrCell.DataContext Is MTableMachiningGridBoxItem Then
If CurrCell.IsSelected And SelectedRow.GroupId <> 0 Then
If (bFirstInGroup And (CurrCell.Column Is MachiningDataGrid.Columns(1))) Then
CurrCell.IsEditing = True
If Not IsNothing(m_EditCell) AndAlso m_EditCell IsNot CurrCell Then m_EditCell.IsEditing = False
m_EditCell = CurrCell
bSelCell = True
ElseIf Not CurrCell.IsEditing And CurrCell.Column Is MachiningDataGrid.Columns(4) Then
SelectedRow.Join = Not SelectedRow.Join
End If
End If
If Not CurrCell.IsSelected Or ((Not bFirstInGroup Or CurrCell.Column IsNot MachiningDataGrid.Columns(1)) And CurrCell.Column IsNot MachiningDataGrid.Columns(4)) Or SelectedRow.GroupId = 0 Then
If Not IsNothing(m_EditCell) AndAlso m_EditCell.IsEditing Then
m_EditCell.IsEditing = False
Else
m_MTableDbVM.LeftSelect(SelectedRow)
End If
End If
End If
If Not bSelCell And Not CurrCell.IsEditing Or CurrCell.Column Is MachiningDataGrid.Columns(4) Then
If Not IsNothing(m_EditCell) Then m_EditCell.IsEditing = False
Keyboard.ClearFocus()
MachiningDataGrid.Focus()
e.Handled = True
End If
End Sub
Private Sub CellRightClick(sender As Object, e As MouseButtonEventArgs)
Dim CurrCell As DataGridCell = Nothing
If TypeOf sender Is DataGridCell Then
CurrCell = DirectCast(sender, DataGridCell)
End If
If Not IsNothing(CurrCell) AndAlso TypeOf CurrCell.DataContext Is MTableMachiningGridBoxItem Then
Dim SelectedRow As MTableMachiningGridBoxItem = DirectCast(CurrCell.DataContext, MTableMachiningGridBoxItem)
m_MTableDbVM.RightSelect(SelectedRow)
End If
If Not IsNothing(m_EditCell) Then m_EditCell.IsEditing = False
CurrCell.IsEditing = False
Keyboard.ClearFocus()
MachiningDataGrid.Focus()
e.Handled = True
End Sub
Private Sub RowMouseUp(sender As Object, e As MouseButtonEventArgs)
'e.Handled = True
End Sub
Private Sub CellRightUp(sender As Object, e As MouseButtonEventArgs)
e.Handled = True
End Sub
Private Sub CellMouseUp(sender As Object, e As MouseButtonEventArgs)
'e.Handled = True
End Sub
Public Function GetCell(row As Integer, column As Integer) As DataGridCell
Dim rowContainer As DataGridRow = GetRow(row)
If rowContainer IsNot Nothing Then
Dim presenter As DataGridCellsPresenter = FindChild(Of DataGridCellsPresenter)(rowContainer)
' try to get the cell but it may possibly be virtualized
Dim cell As DataGridCell = DirectCast(presenter.ItemContainerGenerator.ContainerFromIndex(column), DataGridCell)
If cell Is Nothing Then
' now try to bring into view and retreive the cell
MachiningDataGrid.ScrollIntoView(rowContainer, MachiningDataGrid.Columns(column))
cell = DirectCast(presenter.ItemContainerGenerator.ContainerFromIndex(column), DataGridCell)
End If
Return cell
End If
Return Nothing
End Function
Public Function GetRow(index As Integer) As DataGridRow
Dim row As DataGridRow = DirectCast(MachiningDataGrid.ItemContainerGenerator.ContainerFromIndex(index), DataGridRow)
If row Is Nothing Then
' may be virtualized, bring into view and try again
MachiningDataGrid.ScrollIntoView(MachiningDataGrid.Items(index))
row = DirectCast(MachiningDataGrid.ItemContainerGenerator.ContainerFromIndex(index), DataGridRow)
End If
Return row
End Function
Public Function FindChild(Of T As Class)(dependencyObject As DependencyObject) As T
Dim target As DependencyObject = dependencyObject
Do
target = DirectCast(VisualTreeHelper.GetChild(target, 0), DependencyObject)
Loop While target IsNot Nothing AndAlso Not (TypeOf target Is T)
Return TryCast(target, T)
End Function
Private Sub CsvWindowV_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
' Carico e imposto posizione finestra
WinPosFromIniToWindow(S_DOORS, K_MTABLEWINPLACE, Me)
End Sub
Private Sub CsvWindowV_Unloaded(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
' Salvo posizione finestra
WinPosFromWindowToIni(Me, S_DOORS, K_MTABLEWINPLACE)
End Sub
End Class