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

Public Enum eProjectBarType
    eDeadline = 0
    eProjectSummary = 1
    eSummary = 2
    eMilestone = 3
    eProgress = 4
    eSplit = 5
    eTask = 6
End Enum
Public Enum eTaskDuty
    eNotSet = -1
    ePartnerTask = 0 'Partner feladata
    eSubcontractorTask = 1 'Alvállalkozó feladata
    eMyTask = 2 'A mi feladatunk
End Enum
<DefaultClassOptions()> _
<NavigationItem(False)> _
<CreatableItem(False)> _
<Appearance("ProjectRows - Disable RowPos all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="RowPos", Enabled:=False)> _
Public Class ProjectRows
    Inherits BaseObject
    Private _ProjectRows As ProjectRows 'Melyik hierarchiára mutat
    Private _ProjectHeader As ProjectHeader 'Melyik projecthez tartozik
    Private _RowPos As String '1,1.1,1.1.1 ez a hierarchia, automatikusan adható legyen, mint a fk. számlaszámok
    Private _TaskName As String 'Feladat megnevezése
    Private _DateStart As Date ' Kezdete
    Private _DateEnd As Date 'Vége
    Private _ProjectBarType As eProjectBarType 'Bar tipus
    Private _AlertPeriod As AlertPeriod 'Figyelmeztetés a lejárat előtt és után
    Private _TaskDuty As eTaskDuty ' Kinek a felelőssége
    Private _Description As String 'Egyéb megjegyzés ehhez a feladathoz
    Private _PercentCompleted As Double '? százalékban van elkészülve

    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 String.IsNullOrEmpty(RowPos) Then
            Dim _ProjectRows_Collection As New XPCollection(Of ProjectRows)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                    Session, CriteriaOperator.Parse("ProjectHeader=? AND IsNull(ProjectRows)=True", ProjectHeader))
            If _ProjectRows_Collection.Count = 0 Then
                RowPos = "1" + ProjectHeader.ProjectType.SeparatorChar
            Else
                RowPos = (_ProjectRows_Collection.Count).ToString + ProjectHeader.ProjectType.SeparatorChar
            End If
        End If
    End Sub
    <ImmediatePostData(True), DataSourceCriteria("ProjectHeader='@This.ProjectHeader' and Oid<>'@This.Oid'")>
    Property ProjectRows As ProjectRows
        Get
            Return _ProjectRows
        End Get
        Set(value As ProjectRows)
            SetPropertyValue("ProjectRows", _ProjectRows, value)
            If Not Session.IsObjectsLoading And Not Session.IsObjectsSaving Then
                Dim _ProjectRows_Collection As New XPCollection(Of ProjectRows)(Session, CriteriaOperator.Parse("ProjectHeader=? AND ProjectRows=?", ProjectHeader, value))
                If value Is Nothing Then
                    RowPos = Nothing
                Else
                    If _ProjectRows_Collection.Count = 0 Then
                        RowPos = value.RowPos + "1" + ProjectHeader.ProjectType.SeparatorChar
                    Else
                        RowPos = value.RowPos + (_ProjectRows_Collection.Count + 1).ToString + ProjectHeader.ProjectType.SeparatorChar
                    End If
                End If

            End If

        End Set
    End Property
    Property ProjectHeader As ProjectHeader
        Get
            Return _ProjectHeader
        End Get
        Set(value As ProjectHeader)
            SetPropertyValue("ProjectHeader", _ProjectHeader, value)
        End Set
    End Property
    Property RowPos As String
        Get
            Return _RowPos
        End Get
        Set(value As String)
            SetPropertyValue("RowPos", _RowPos, value)
        End Set
    End Property
    <Size(255)> _
    Property TaskName As String
        Get
            Return _TaskName
        End Get
        Set(value As String)
            SetPropertyValue("TaskName", _TaskName, value)
        End Set
    End Property
    Property DateStart As Date
        Get
            Return _DateStart
        End Get
        Set(value As Date)
            SetPropertyValue("DateStart", _DateStart, value)
        End Set
    End Property
    Property DateEnd As Date
        Get
            Return _DateEnd
        End Get
        Set(value As Date)
            SetPropertyValue("DateEnd", _DateEnd, value)
        End Set
    End Property
    Property ProjectBarType As eProjectBarType
        Get
            Return _ProjectBarType
        End Get
        Set(value As eProjectBarType)
            SetPropertyValue("ProjectBarType", _ProjectBarType, value)
        End Set
    End Property
    ReadOnly Property SumDay As Long
        Get
            Return DateDiff(DateInterval.Day, Me.DateStart, Me.DateEnd)
        End Get
    End Property
    Property AlertPeriod As AlertPeriod
        Get
            Return _AlertPeriod
        End Get
        Set(value As AlertPeriod)
            SetPropertyValue("AlertPeriod", _AlertPeriod, value)
        End Set
    End Property
    <ImmediatePostData> _
    Property TaskDuty As eTaskDuty
        Get
            Return _TaskDuty
        End Get
        Set(value As eTaskDuty)
            SetPropertyValue("TaskDuty", _TaskDuty, 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
    Property PercentCompleted As Double
        Get
            Return _PercentCompleted
        End Get
        Set(value As Double)
            SetPropertyValue("PercentCompleted", _PercentCompleted, value)
        End Set
    End Property

    '-------ReadOnly----------------
    <Browsable(False)> _
    ReadOnly Property ProjectRows_Child As XPCollection(Of ProjectRows)
        Get
            Dim _ProjectRows_Collection As New XPCollection(Of ProjectRows)(Session, CriteriaOperator.Parse("ProjectRows=?", Me))
            If _ProjectRows_Collection Is Nothing Then
                Return Nothing
            Else
                Return _ProjectRows_Collection
            End If
        End Get
    End Property
    <Association("ProjectRows-ProjectRowsCustomers", GetType(ProjectRowsCustomers)), VisibleInListView(False)> _
    ReadOnly Property ProjectRowsCustomers As XPCollection(Of ProjectRowsCustomers)
        Get
            Return GetCollection(Of ProjectRowsCustomers)("ProjectRowsCustomers")
        End Get
    End Property
    <Association("ProjectRows-ProjectRowsContacts", GetType(ProjectRowsContacts)), VisibleInListView(False)> _
    ReadOnly Property ProjectRowsContacts As XPCollection(Of ProjectRowsContacts)
        Get
            Return GetCollection(Of ProjectRowsContacts)("ProjectRowsContacts")
        End Get
    End Property
    <Association("ProjectRows-ProjectRowsHRPerson", GetType(ProjectRowsHRPerson)), VisibleInListView(False)> _
    ReadOnly Property ProjectRowsHRPerson As XPCollection(Of ProjectRowsHRPerson)
        Get
            Return GetCollection(Of ProjectRowsHRPerson)("ProjectRowsHRPerson")
        End Get
    End Property
    <Association("ProjectRows-ProjectRowsSubcontractor", GetType(ProjectRowsSubcontractor)), VisibleInListView(False)> _
    ReadOnly Property ProjectRowsSubcontractor As XPCollection(Of ProjectRowsSubcontractor)
        Get
            Return GetCollection(Of ProjectRowsSubcontractor)("ProjectRowsSubcontractor")
        End Get
    End Property
End Class
