Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base

Public Class OrderInVC
	Inherits DevExpress.ExpressApp.ViewController

	Public Sub New()
		MyBase.New()

		'This call is required by the Component Designer.
		InitializeComponent()
		RegisterActions(components) 

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        If View.Id = "OrderInHeader_DetailView" Then
            AddHandler View.ControlsCreated, AddressOf OrderInHeader_DetailView_ControlCreated
        End If
    End Sub

    Private Sub OrderInHeader_DetailView_ControlCreated(sender As Object, e As EventArgs)
        If View.Id = "OrderInHeader_DetailView" Then
            Dim _row_Products_Editor As DevExpress.ExpressApp.Win.Editors.LookupPropertyEditor
            _row_Products_Editor = TryCast(View, DetailView).FindItem("row_Products")

            AddHandler _row_Products_Editor.ControlValueChanged, AddressOf _row_Products_Editor_ControlValueChanged
        End If
    End Sub

    Private Sub _row_Products_Editor_ControlValueChanged(sender As Object, e As EventArgs)
        Dim _row_QTT As DevExpress.ExpressApp.Win.Editors.DoublePropertyEditor
        Dim _OrderInHeader As OrderInHeader = TryCast(View.SelectedObjects(0), OrderInHeader)
        _row_QTT = TryCast(View, DetailView).FindItem("row_QTT")
        If _row_QTT IsNot Nothing Then
            Dim _row_Products_Editor As DevExpress.ExpressApp.Win.Editors.LookupPropertyEditor
            _row_Products_Editor = TryCast(View, DetailView).FindItem("row_Products")

            If _row_Products_Editor IsNot Nothing Then
                Dim _ProductSelect As SISBusiness.Module.ProductSelect = TryCast(_row_Products_Editor.ControlValue, SISBusiness.Module.ProductSelect)
                If _ProductSelect IsNot Nothing Then
                    If _ProductSelect.Products IsNot Nothing Then
                        'row_qtt_ProductSelect.Products.DecimalOut
                        Dim _SpinEdit As DevExpress.XtraEditors.SpinEdit
                        _SpinEdit = TryCast(_row_QTT.Control, DevExpress.XtraEditors.SpinEdit)
                        If _SpinEdit IsNot Nothing Then
                            Select Case _ProductSelect.Products.DecimalOut
                                Case 0
                                    _SpinEdit.Properties.Mask.EditMask = "#,##0"
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = True
                                Case 1
                                    _SpinEdit.Properties.Mask.EditMask = "#,##0.0"
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = True
                                Case 2
                                    _SpinEdit.Properties.Mask.EditMask = "#,##0.00"
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = True
                                Case 3
                                    _SpinEdit.Properties.Mask.EditMask = "#,##0.000"
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = True
                                Case 4
                                    _SpinEdit.Properties.Mask.EditMask = "#,##0.0000"
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = True
                                Case Else
                                    _SpinEdit.Properties.Mask.EditMask = ""
                                    _SpinEdit.Properties.Mask.UseMaskAsDisplayFormat = False
                            End Select
                        End If
                    End If
                End If
            End If
        End If
    End Sub

End Class
