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
<DefaultClassOptions(), NavigationItem(False), CreatableItem(False)> _
<Appearance("Hide detail action when DocumentNumber is empty", AppearanceItemType:="Action", criteria:="isnull(DocumentNumber)=True or DocumentNumber=''", targetitems:="aProjectDeleteRow;aProjectAddRow;aProjectEditRow", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class ProjectHeader
    Inherits BaseObject

    Private _JobNumberObjects As JobNumberObjects
    Private _ProjectType As ProjectType
    Private _DocumentNumber As String
    Private _CustomersFrom As CustomersFrom
    Private _G2antt As String
    Private _GanttChart As String
    Private _ShortName As String
    Private _Description As String

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If DocumentNumber = "" Then
            DocumentNumber = Me.ProjectType.NumberGenerator.GetNewNumber(Me.ProjectType.NumberGenerator)
        End If
    End Sub

    Property JobNumberObjects As JobNumberObjects
        Get
            Return _JobNumberObjects
        End Get
        Set(value As JobNumberObjects)
            SetPropertyValue("JobNumberObjects", _JobNumberObjects, value)
        End Set
    End Property
    <RuleRequiredField("ProjectHeader-ProjectType", DefaultContexts.Save)>
    <ImmediatePostData(True), DataSourceCriteria("CustomersFrom='@This.CustomersFrom'")>
    Property ProjectType As ProjectType
        Get
            Return _ProjectType
        End Get
        Set(value As ProjectType)
            SetPropertyValue("ProjectType", _ProjectType, value)
        End Set
    End Property
    Property DocumentNumber As String
        Get
            Return _DocumentNumber
        End Get
        Set(value As String)
            SetPropertyValue("DocumentNumber", _DocumentNumber, value)
        End Set
    End Property
    Property CustomersFrom As CustomersFrom
        Get
            Return _CustomersFrom
        End Get
        Set(value As CustomersFrom)
            SetPropertyValue("CustomersFrom", _CustomersFrom, value)
        End Set
    End Property
    <Size(-1)> _
    Property G2antt As String
        Get
            Return _G2antt
        End Get
        Set(value As String)
            SetPropertyValue("G2antt", _G2antt, value)
        End Set
    End Property
    <Size(-1)> _
    Property GanttChart As String
        Get
            Return _GanttChart
        End Get
        Set(value As String)
            SetPropertyValue("GanttChart", _GanttChart, value)
        End Set
    End Property
    Property ShortName As String
        Get
            Return _ShortName
        End Get
        Set(value As String)
            SetPropertyValue("ShortName", _ShortName, value)
        End Set
    End Property
    <Size(-1)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property

    ReadOnly Property ProjectRows As XPCollection(Of ProjectRows)
        Get
            Return New XPCollection(Of ProjectRows)(Session, CriteriaOperator.Parse("ProjectHeader=?", Me))
        End Get
    End Property
    <Association("ProjectHeader-ProjectQuestion", GetType(ProjectQuestion)), VisibleInListView(False)> _
    ReadOnly Property ProjectQuestion As XPCollection(Of ProjectQuestion)
        Get
            Return GetCollection(Of ProjectQuestion)("ProjectQuestion")
        End Get
    End Property
    <Association("ProjectHeader-ProjectHRPerson", GetType(ProjectHRPerson)), VisibleInListView(False)> _
    ReadOnly Property ProjectHRPerson As XPCollection(Of ProjectHRPerson)
        Get
            Return GetCollection(Of ProjectHRPerson)("ProjectHRPerson")
        End Get
    End Property
    <Association("ProjectHeader-ProjectSubcontractor", GetType(ProjectSubcontractor)), VisibleInListView(False)> _
    ReadOnly Property ProjectSubcontractor As XPCollection(Of ProjectSubcontractor)
        Get
            Return GetCollection(Of ProjectSubcontractor)("ProjectSubcontractor")
        End Get
    End Property
    <Association("ProjectHeader-ProjectCustomers", GetType(ProjectCustomers)), VisibleInListView(False)> _
    ReadOnly Property ProjectCustomers As XPCollection(Of ProjectCustomers)
        Get
            Return GetCollection(Of ProjectCustomers)("ProjectCustomers")
        End Get
    End Property
    <Association("ProjectHeader-ProjectContacts", GetType(ProjectContacts)), VisibleInListView(False)> _
    ReadOnly Property ProjectContacts As XPCollection(Of ProjectContacts)
        Get
            Return GetCollection(Of ProjectContacts)("ProjectContacts")
        End Get
    End Property
End Class
