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
Imports System.Drawing
Imports DevExpress.ExpressApp.Utils

<DefaultClassOptions()> _
<NavigationItem("Outlook e-mail")> _
<Appearance("Hide EntryID", AppearanceItemType.ViewItem, "1=1", TargetItems:="EntryID", visibility:=Editors.ViewItemVisibility.Hide)> _
<DeferredDeletion(False)> _
<CreatableItem(False)> _
Public Class OutlookEMailIn
    Inherits BaseObject

    Private _SenderName As String
    Private _SenderEmailAddress As String
    Private _EmailSubject As String
    Private _EmailBody As String
    Private _EntryID As String
    Private _ObjectCreated As Date 'Mikor készült az objektum
    Private _OwnerUser As User
    Private _UserCreated As User 'Ki készítette
    Private _ReceivedTime As Date
    Private _ReceiverEmailAdress As String '
    Private _Qualified As Boolean 'Elintézett-e?
    Private _IsReaded As Boolean 'Elolvasott-e?

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        MyBase.AfterConstruction()
       
        IsReaded = False
        Qualified = False
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            Dim _CurrentUser As User = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))

            ObjectCreated = GetSQLTime(Session)
            UserCreated = _CurrentUser
        End If
    End Sub
    <Size(255)> _
    Property SenderName As String
        Get
            Return _SenderName
        End Get
        Set(value As String)
            SetPropertyValue("SenderName", _SenderName, value)
        End Set
    End Property
    <Size(255)> _
    Property SenderEmailAddress As String
        Get
            Return _SenderEmailAddress
        End Get
        Set(value As String)
            SetPropertyValue("SenderEmailAddress", _SenderEmailAddress, value)
        End Set
    End Property
    <Size(255)> _
    Property EmailSubject As String
        Get
            Return _EmailSubject
        End Get
        Set(value As String)
            SetPropertyValue("EmailSubject", _EmailSubject, value)
        End Set
    End Property
    <Size(-1)> _
    Property EmailBody As String
        Get
            Return _EmailBody
        End Get
        Set(value As String)
            SetPropertyValue("EmailBody", _EmailBody, value)
        End Set
    End Property
    <Size(255)> _
    <Browsable(False)> _
    Property EntryID As String
        Get
            Return _EntryID
        End Get
        Set(value As String)
            SetPropertyValue("EntryID", _EntryID, 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
    Property ReceivedTime As Date
        Get
            Return _ReceivedTime
        End Get
        Set(value As Date)
            SetPropertyValue("ReceivedTime", _ReceivedTime, value)
        End Set
    End Property
    Property OwnerUser As User
        Get
            Return _OwnerUser
        End Get
        Set(value As User)
            SetPropertyValue("OwnerUser", _OwnerUser, value)
        End Set
    End Property
    Property ReceiverEmailAdress As String
        Get
            Return _ReceiverEmailAdress
        End Get
        Set(value As String)
            SetPropertyValue("ReceiverEmailAdress", _ReceiverEmailAdress, value)
        End Set
    End Property
    Property Qualified As Boolean
        Get
            Return _Qualified
        End Get
        Set(value As Boolean)
            SetPropertyValue("Qualified", _Qualified, value)
        End Set
    End Property
    Property IsReaded As Boolean
        Get
            Return _IsReaded
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsReaded", _IsReaded, value)
        End Set
    End Property

    '-------------ReadOnly---------------
    <VisibleInListView(False)> _
    <Association("OutlookEMailIn-OutlookEMailAttachments", GetType(OutlookEMailAttachments)), Aggregated()> _
    ReadOnly Property OutlookEMailAttachments As XPCollection(Of OutlookEMailAttachments)
        Get
            Return GetCollection(Of OutlookEMailAttachments)("OutlookEMailAttachments")
        End Get
    End Property
    ReadOnly Property OutllokEmailInHasAttachments As Image
        Get
            Dim _ReturnImage As Image = Nothing
            If Me.OutlookEMailAttachments.Count > 0 Then _ReturnImage = ImageLoader.Instance.GetImageInfo("Action_FileAttachment_Attach").Image
            If Me.OutlookEMailAttachments.Count = 0 Then _ReturnImage = ImageLoader.Instance.GetImageInfo("NoImage").Image
            Return _ReturnImage
        End Get
    End Property
End Class
