Imports System
Imports System.ComponentModel

Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering

Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation
Imports DevExpress.ExpressApp.ConditionalAppearance


'<EditorStateRuleAttribute("Disable Customers when is not empty in invoice ContractProductHeader", "Customers", ViewType.DetailView, "IsNull(Customers) = False", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Disable CustomersFrom when is not empty in invoice ContractProductHeader", "CustomersFrom", ViewType.DetailView, "IsNull(CustomersFrom) = False", EditorState.Disabled)> _
'<EditorStateRuleAttribute("Disable CurrencyName when is not empty in invoice CurrencyName", "CurrencyName", ViewType.DetailView, "IsNull(CurrencyName) = False", EditorState.Disabled)> _

<DefaultClassOptions()> _
<NavigationItem("Contracts")> _
<DefaultProperty("DisplayName")> _
<FileAttachment("File")> _
<Appearance("Hide row_NettoPriceDEV when DEV is HUF", AppearanceItemType.ViewItem, "CurrencyName.ShortName = 'HUF'", TargetItems:="row_NettoPriceDEV", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide row_NettoPriceHUF when DEV isnot HUF", AppearanceItemType.ViewItem, "CurrencyName.ShortName <> 'HUF'", TargetItems:="row_NettoPriceHUF", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide row_ContractProductRows when ContractTemplate.PartnerType=ePayabels", AppearanceItemType.ViewItem, "ContractTemplate.PartnerType=1", TargetItems:="row_ContractProductRows", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide row_Products when ContractTemplate.PartnerType= eReceivables", AppearanceItemType.ViewItem, "ContractTemplate.PartnerType=0", TargetItems:="row_Products", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide ContractProductRows when CurrencyName is nothing", AppearanceItemType.LayoutItem, "IsNull(CurrencyName) = True", TargetItems:="ContractProductRows", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Hide ContractProductRows when CurrencyName is nothingViewItem", AppearanceItemType.ViewItem, "IsNull(CurrencyName) = True", TargetItems:="ContractProductRows", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable ALL property when State = State.Ready", AppearanceItemType.ViewItem, "State = 1", TargetItems:="*", Enabled:=False)> _
<Appearance("Disable Customers when is not empty in invoice ContractProductHeader", TargetItems:="Customers", Criteria:="IsNull(Customers) = False", Enabled:=False, Context:="DetailView")> _
<Appearance("Disable CustomersFrom when is not empty in invoice ContractProductHeader", TargetItems:="CustomersFrom", Criteria:="IsNull(CustomersFrom) = False", Enabled:=False, Context:="DetailView")> _
<Appearance("Disable CurrencyName when is not empty in invoice CurrencyName", TargetItems:="CurrencyName", Criteria:="IsNull(CurrencyName) = False", Enabled:=False, Context:="DetailView")> _
<Appearance("Disable aTotable_ConProd_Payabels when State = State.Ready", AppearanceItemType.Action, "State = 1", TargetItems:="aTotable_ConProd_Payabels", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable aTotableD_ConProd when State = State.Ready", AppearanceItemType.Action, "State = 1", TargetItems:="aTotableD_ConProd_Payabels", visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("Disable aBackToRowEdit_ConProd_Payabels when State = State.Ready", AppearanceItemType.Action, "State = 1", TargetItems:="aBackToRowEdit_ConProd_Payabels", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class ContractProductHeader
    Inherits Contracts
    Public Sub New(ByVal session As Session)
        MyBase.New(session)

    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        Me.row_VAT = Session.FindObject(Of VAT)(CriteriaOperator.Parse("DefaultForBusinnes='True'"))
        Me.row_Units = Session.FindObject(Of Units)(CriteriaOperator.Parse("DefaultForBusinnes='True'"))
        Me.HRResponsible = Session.FindObject(Of HRPerson) _
            (CriteriaOperator.Parse("User=?", Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))))
    End Sub
    Private _CustomersStoreHouse As Customers 'Tároló tulajdonosa ha contract product-ról van szó
    Private _AddressStoreHouse As Address 'Tárolási cím !
    Private _Customers2 As Customers 'Az adásvétel vevője, ha szállító, eladója ha vevő
    '---------------NonPersistent Propertys-----------------
    Private _row_Products As Products
    Private _row_ContractProductRows As ContractProductRows
    Private _row_QTT As Double
    Private _row_NettoPriceHUF As Double '-- Nettó egységár (HUF)
    Private _row_NettoPriceDEV As Double '-- Nettó egységár (DEV)
    Private _row_VAT As VAT 'ÁFA kód
    Private _row_Units As Units '-- Mennyiségi egység
    Private _row_RowGroup1 As String 'Csoportosító sor1
    Private _row_RowGroup2 As String 'Csoportosító sor2
    Private _row_PaymentOption As PaymentOption
    Private _row_APCSheetByProducts As APCSheetByProducts 'Termeltetési szerződés
    <RuleRequiredField("ContractProductHeader.CustomersStoreHouse", DefaultContexts.Save, TargetCriteria:="ContractTemplate.PartnerType = 1")> _
    Property CustomersStoreHouse As Customers
        Get
            Return _CustomersStoreHouse
        End Get
        Set(value As Customers)
            SetPropertyValue("CustomersStoreHouse", _CustomersStoreHouse, value)
        End Set
    End Property
    <RuleRequiredField("ContractProductHeader.Customers2", DefaultContexts.Save, TargetCriteria:="ContractTemplate.PartnerType='ePayabels'")> _
    Property Customers2 As Customers
        Get
            Return _Customers2
        End Get
        Set(value As Customers)
            SetPropertyValue("Customers2", _Customers2, value)
        End Set
    End Property
    <RuleRequiredField("ContractProductHeader.AddressStoreHouse", DefaultContexts.Save, TargetCriteria:="ContractTemplate.PartnerType='ePayabels'")> _
    Property AddressStoreHouse As Address
        Get
            Return _AddressStoreHouse
        End Get
        Set(value As Address)
            SetPropertyValue("AddressStoreHouse", _AddressStoreHouse, value)
        End Set
    End Property
    <Aggregated()> _
    <Association("ContractProductHeader-ContractProductRows", GetType(ContractProductRows)), VisibleInListView(False)> _
        ReadOnly Property ContractProductRows() As XPCollection(Of ContractProductRows)
        Get
            Return GetCollection(Of ContractProductRows)("ContractProductRows")
        End Get
    End Property

    '---------------NonPersistent Propertys-----------------
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    Property row_Products As Products
        Get
            Return _row_Products
        End Get
        Set(value As Products)
            SetPropertyValue("row_Products", _row_Products, value)
            If value IsNot Nothing Then
                Me.row_Units = value.Units
                Me.row_VAT = value.VAT
            End If
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    <DataSourceCriteria("(QTT-QTT_Out)>0 AND ContractProductHeader.ContractTemplate.PartnerType=1")> _
    Property row_ContractProductRows As ContractProductRows
        Get
            Return _row_ContractProductRows
        End Get
        Set(value As ContractProductRows)
            SetPropertyValue("row_ContractProductRows", _row_ContractProductRows, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value IsNot Nothing Then
                    Me.row_Units = value.Units
                    Me.row_VAT = value.VAT
                End If
            End If
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    Property row_QTT As Double
        Get
            Return _row_QTT
        End Get
        Set(value As Double)
            SetPropertyValue("row_QTT", _row_QTT, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    Property row_NettoPriceHUF As Double
        Get
            Return _row_NettoPriceHUF
        End Get
        Set(value As Double)
            SetPropertyValue("row_NettoPriceHUF", _row_NettoPriceHUF, value)
        End Set
    End Property
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    Property row_NettoPriceDEV As Double
        Get
            Return _row_NettoPriceDEV
        End Get
        Set(value As Double)
            SetPropertyValue("row_NettoPriceDEV", _row_NettoPriceDEV, value)
        End Set
    End Property
    '<RuleRequiredField("ContractProductHeader-row_Customers", "aTotable_ConProd_Payabels_Contexts", TargetCriteria:="IsNull(row_VAT)=True")> _
    <NonPersistent()> _
    <ImmediatePostData()> _
    <VisibleInListView(False)> _
    Property row_VAT As VAT
        Get
            Return _row_VAT
        End Get
        Set(value As VAT)
            SetPropertyValue("row_VAT", _row_VAT, value)
        End Set
    End Property
    <NonPersistent()> _
   <ImmediatePostData()> _
   <VisibleInListView(False)> _
    Property row_Units As Units
        Get
            Return _row_Units
        End Get
        Set(value As Units)
            SetPropertyValue("row_Units", _row_Units, value)
        End Set
    End Property
    <NonPersistent()> _
   <ImmediatePostData()> _
   <VisibleInListView(False)> _
    Property row_RowGroup1 As String
        Get
            Return _row_RowGroup1
        End Get
        Set(value As String)
            SetPropertyValue("row_RowGroup1", _row_RowGroup1, value)
        End Set
    End Property
    <NonPersistent()> _
  <ImmediatePostData()> _
  <VisibleInListView(False)> _
    Property row_RowGroup2 As String
        Get
            Return _row_RowGroup2
        End Get
        Set(value As String)
            SetPropertyValue("row_RowGroup2", _row_RowGroup2, value)
        End Set
    End Property
    <NonPersistent()> _
<ImmediatePostData()> _
<VisibleInListView(False)> _
    Property row_PaymentOption As PaymentOption
        Get
            Return _row_PaymentOption
        End Get
        Set(value As PaymentOption)
            SetPropertyValue("row_PaymentOption", _row_PaymentOption, value)
        End Set
    End Property
    '<RuleRequiredField("ContractProductHeader-row_APCSheetByProducts", "aToTable_OrderIn", targetcriteria:="OrderInParameters.IsAPCSheet=True")> _
    <NonPersistent> _
    <DataSourceCriteria("APCSheetHeader.Customers='@This.Customers' and APCSheetHeader.CustomersFrom='@This.CustomersFrom'")> _
    Property row_APCSheetByProducts As APCSheetByProducts
        Get
            Return _row_APCSheetByProducts
        End Get
        Set(value As APCSheetByProducts)
            SetPropertyValue("row_APCSheetByProducts", _row_APCSheetByProducts, value)
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If value.Products IsNot Nothing Then
                    row_Products = value.Products
                    row_QTT = value.SumContractQuantity
                    row_Units = value.Products.Units
                End If
            End If
        End Set
    End Property

End Class
