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("Support")> _
<Appearance("Answer - Hide QuestionInProgressState, when QuestionStatus <> 8", AppearanceItemType.ViewItem, "QuestionStatus <> 8", TargetItems:="QuestionInProgressState", visibility:=Editors.ViewItemVisibility.Hide)> _
Public Class Answer
    Inherits BaseObject
    Private _Question As Question
    Private _QuestionStatus As eQuestionStatus
    Private _IssueType As eIssueType
    Private _DocumentNumber As String
    Private _Description As String
    Private _ObjectCreated As Date
    Private _UserCreated As User
    Private _Attachment As FileData
    Private _QuestionInProgressState As QuestionInProgressState

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
    End Sub
    Protected Overrides Sub OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = Now
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
            If NumberGenerator IsNot Nothing Then
                DocumentNumber = NumberGenerator.GetNewNumber(NumberGenerator, Year(Now).ToString)
            End If
        End If
    End Sub
    Property Question As Question
        Get
            Return _Question
        End Get
        Set(value As Question)
            SetPropertyValue("Question", _Question, value)
        End Set
    End Property
    <RuleValueComparison("", DefaultContexts.Save, ValueComparisonType.NotEquals, "eActive")> _
    Property QuestionStatus As eQuestionStatus
        Get
            Return _QuestionStatus
        End Get
        Set(value As eQuestionStatus)
            SetPropertyValue("QuestionStatus", _QuestionStatus, value)
        End Set
    End Property
    Property IssueType As eIssueType
        Get
            Return _IssueType
        End Get
        Set(value As eIssueType)
            SetPropertyValue("IssueType", _IssueType, 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
    <Size(-1)> _
    <VisibleInListView(False)> _
    <RuleRequiredField("Answer-Description", DefaultContexts.Save)> _
    Property Description As String
        Get
            Return _Description
        End Get
        Set(value As String)
            SetPropertyValue("Description", _Description, value)
        End Set
    End Property
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(value As Date)
            SetPropertyValue("ObjectCreated", _ObjectCreated, value)
        End Set
    End Property
    <NonCloneable> _
    Property UserCreated As User
        Get
            Return _UserCreated
        End Get
        Set(value As User)
            SetPropertyValue("UserCreated", _UserCreated, value)
        End Set
    End Property
    <VisibleInListView(False)> _
    Property Attachment As FileData
        Get
            Return _Attachment
        End Get
        Set(value As FileData)
            SetPropertyValue("Attachment", _Attachment, value)
        End Set
    End Property
    Property QuestionInProgressState As QuestionInProgressState
        Get
            Return _QuestionInProgressState
        End Get
        Set(value As QuestionInProgressState)
            SetPropertyValue("QuestionInProgressState", _QuestionInProgressState, value)
        End Set
    End Property

    '-------------ReadOnly----------------
    <Browsable(False)> _
    ReadOnly Property NumberGenerator As NumberGenerator
        Get
            Return TryCast(Session.FindObject(Of SupportNG)(CriteriaOperator.Parse("SupportType=1")), SupportNG).NumberGenerator
        End Get
    End Property
    <VisibleInListView(False)> _
    <Size(-1)> _
    ReadOnly Property HTMLEvents As String
        Get
            If Question IsNot Nothing Then
                Return Question.HTMLEvents
            Else
                Return ""
            End If
        End Get
    End Property
    <VisibleInListView(False), VisibleInLookupListView(False)> _
    ReadOnly Property EventsAttachments As XPCollection(Of FileData)
        Get
            Dim _FileData_Collection As New XPCollection(Of FileData)(Session, CriteriaOperator.Parse("1=2"))
            Dim _Events_Collection As New XPCollection(Of Events)(Session, CriteriaOperator.Parse("Question=?", Me.Question))
            Dim _Events As [Events]
            For Each _Events In _Events_Collection
                If _Events.Attachment IsNot Nothing Then
                    _FileData_Collection.Add(_Events.Attachment)
                End If
            Next
            Return _FileData_Collection
        End Get
    End Property
End Class



