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("SubcontractorDocuments - Hide XML properties, when IsDashboard = False", _
    AppearanceItemType.ViewItem, "IsDashboard = False", _
    TargetItems:="XML_ServerName;XML_UserName;XML_DatabaseName;XML_Password;XML_SqlType", _
    visibility:=Editors.ViewItemVisibility.Hide)> _
<Appearance("SubcontractorDocuments - ObjectCreated Disable all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="ObjectCreated", Enabled:=False)> _
<Appearance("SubcontractorDocuments - UserCreated Disable all time", AppearanceItemType.ViewItem, "1=1", TargetItems:="UserCreated", Enabled:=False)> _
Public Class SubcontractorDocuments
    Inherits FileAttachmentBase
    Private _Subcontractor As Subcontractor
    Private _Group1 As String '1. csoportosítás
    Private _Group2 As String '2. csoportosítás
    Private _ObjectCreated As Date ' Objektum mikor készült
    Private _UserCreated As User 'Ki készítette
    Private _IsDashboard As Boolean 'Műszerfal-e
    Private _XML_ServerName As String
    Private _XML_UserName As String
    Private _XML_DatabaseName As String
    Private _XML_Password As String
    Private _XML_SqlType As eSQLType

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        IsDashboard = False
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If Session.IsNewObject(Me) Then
            ObjectCreated = GetSQLTime(Session)
            UserCreated = Session.GetObjectByKey(Of User)(Session.GetKeyValue(SecuritySystem.CurrentUser))
        End If
    End Sub
    <Association("Subcontractor-SubcontractorDocuments", GetType(Subcontractor))> _
    Property Subcontractor As Subcontractor
        Get
            Return _Subcontractor
        End Get
        Set(value As Subcontractor)
            SetPropertyValue("Subcontractor", _Subcontractor, value)
        End Set
    End Property
    <NonCloneable> _
    Property ObjectCreated As Date
        Get
            Return _ObjectCreated
        End Get
        Set(ByVal 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 Group1 As String
        Get
            Return _Group1
        End Get
        Set(value As String)
            SetPropertyValue("Group1", _Group1, value)
        End Set
    End Property
    Property Group2 As String
        Get
            Return _Group2
        End Get
        Set(value As String)
            SetPropertyValue("Group2", _Group2, value)
        End Set
    End Property
    <ImmediatePostData()> _
    Property IsDashboard As Boolean
        Get
            Return _IsDashboard
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsDashboard", _IsDashboard, value)
        End Set
    End Property
    <RuleRequiredField("SubcontractorDocuments - XML_ServerName", DefaultContexts.Save, TargetCriteria:="IsDashboard=True")> _
    Property XML_ServerName As String
        Get
            Return _XML_ServerName
        End Get
        Set(value As String)
            SetPropertyValue("XML_ServerName", _XML_ServerName, value)
        End Set
    End Property
    <RuleRequiredField("SubcontractorDocuments - XML_UserName", DefaultContexts.Save, TargetCriteria:="IsDashboard=True")> _
    Property XML_UserName As String
        Get
            Return _XML_UserName
        End Get
        Set(value As String)
            SetPropertyValue("XML_UserName", _XML_UserName, value)
        End Set
    End Property
    <RuleRequiredField("SubcontractorDocuments - XML_DatabaseName", DefaultContexts.Save, TargetCriteria:="IsDashboard=True")> _
    Property XML_DatabaseName As String
        Get
            Return _XML_DatabaseName
        End Get
        Set(value As String)
            SetPropertyValue("XML_DatabaseName", _XML_DatabaseName, value)
        End Set
    End Property
    <PasswordPropertyText(True)> _
    <ValueConverter(GetType(Encryption))> _
    <RuleRequiredField("SubcontractorDocuments - XML_Password", DefaultContexts.Save, TargetCriteria:="IsDashboard=True")> _
    Property XML_Password As String
        Get
            Return _XML_Password
        End Get
        Set(value As String)
            SetPropertyValue("XML_Password", _XML_Password, value)
        End Set
    End Property
    <RuleRequiredField("SubcontractorDocuments - XML_SqlType", DefaultContexts.Save, TargetCriteria:="IsDashboard=True")> _
    Property XML_SqlType As eSQLType
        Get
            Return _XML_SqlType
        End Get
        Set(value As eSQLType)
            SetPropertyValue("XML_SqlType", _XML_SqlType, value)
        End Set
    End Property

End Class
