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 System.Drawing
Imports DevExpress.ExpressApp.Utils
Public Enum eFullNameOrder
    eFirstNameLastName = 0
    eLastNameFirstName = 1
End Enum
<DefaultClassOptions()> _
<NavigationItem("Customers"), DefaultProperty("DisplayName")> _
Public Class Contacts
    Inherits Person
    Private _ContactNumber As String = ""
    Private _Customers As Customers
    Private _User As User
    Private _ContactsNG As ContactsNG
    Private _CRM_Leads As CRM_Leads
    Private _AccountName As String
    Private _ImportedID As Long
    Private _Position As String
    Private _IsOutlookSync As Boolean ' Van-e Outlook szinkronizáció
    Private _IsExchangeSync As Boolean  'Van-e Excahnge szinkronizáció
    Private _EntryID_Outlook As String
    Private _ContactItemFolderEntryID_Outlook As String
    Private _EntryID_Exchange As String

    Private _BusinessTelephoneNumber As String
    Private _BusinessFaxNumber As String
    Private _HomeFaxNumber As String
    Private _HomeTelephoneNumber As String
    Private _MobileTelephoneNumber As String

    Private _IsChristmasCard As Boolean = False
    Private _Title As String 'Titulus
    Private _FullNameOrder As eFullNameOrder = eFullNameOrder.eLastNameFirstName
    Private _Description As String
    Private _EMailPrivate As String 'Privát e-mail címe
    Private _EMail2 As String
    Private _EMail3 As String

    Private _Checked As Boolean = False
    Private _CheckedDate As DateTime
    Private _CheckStatus As String

    Private _CropProtectionRegistrationNumber As String 'Növényvédelmi regisztrációs szám (kamarai szám, igazolvány adat)
    Private _ChambersRegistrationNumber As String 'Kamarai nyilvántartási szám
    Private _ChamberNumber As String 'Kamarai tagsági szám
    Private _IsAssetsHandlingResponsible As Boolean
    Private _IsInvoiceResponsible As Boolean
    Private _PrivateVATNumber As String 'Adóazonosító jele
    Private _MotherName As String 'Anyja neve
    Private _BirthPlace As String 'Születési város
    Private _TAJNumber As String 'Társadalom biztosítási szám

    Private _IdentityCardNumber As String 'Személyi igazolvány száma
    Private _IdentityNumber As String 'Személyi igazolvány száma


    '<RuleUniqueValue("Contact-Email", DefaultContexts.Save)> _
    Overloads Property Email As String
        Get
            Return MyBase.Email
        End Get
        Set(value As String)
            MyBase.Email = value
        End Set
    End Property

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub
    Public Overrides Sub AfterConstruction()
        MyBase.AfterConstruction()
        ContactsNG = Session.FindObject(Of ContactsNG)(1, CriteriaOperator.Parse("Oid=Oid"))
        IsOutlookSync = False
        IsExchangeSync = False
        IsAssetsHandlingResponsible = True
        IsInvoiceResponsible = False
    End Sub
    Protected Overrides Sub OnSaving()
        MyBase.OnSaving()
        If _ContactsNG Is Nothing Then
        Else
            If _ContactNumber = "" Then
                If Session.IsNewObject(Me) = True Then
                    _ContactNumber = _ContactsNG.NumberGenerator.GetNewNumber(_ContactsNG.NumberGenerator)
                End If
            Else
            End If
        End If
        If Checked = True Then
            CheckedDate = GetSQLTime(Session)
        End If
    End Sub

    <NonCloneable()> _
    Property ContactNumber As String
        Get
            Return _ContactNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("ContactNumber", _ContactNumber, value)
        End Set
    End Property
    <Association("Contacts", GetType(Customers))> _
    Property Customers As Customers
        Get
            Return _Customers
        End Get
        Set(ByVal value As Customers)
            SetPropertyValue("Customers", _Customers, value)
        End Set
    End Property
    <NonCloneable()> _
    Property User() As User
        Get
            Return _User
        End Get
        Set(ByVal value As User)
            SetPropertyValue("User", _User, value)
        End Set
    End Property
    <RuleRequiredField("Contacts-ContactsNG", DefaultContexts.Save)> _
    <VisibleInDetailView(False)> _
    <VisibleInListView(False)> _
    <VisibleInLookupListView(False)> _
    Property ContactsNG As ContactsNG
        Get
            If _ContactsNG Is Nothing Then
                If (Not IsSaving) AndAlso (Not IsLoading) Then
                    _ContactsNG = Session.FindObject(Of ContactsNG)(1, CriteriaOperator.Parse("Oid=Oid"))
                End If
            End If
            Return _ContactsNG
        End Get
        Set(ByVal value As ContactsNG)
            SetPropertyValue("ContactsNG", _ContactsNG, value)
        End Set
    End Property
    <Browsable(False)> _
    <NonCloneable()> _
    Property CRM_Leads As CRM_Leads
        Get
            Return _CRM_Leads
        End Get
        Set(value As CRM_Leads)
            SetPropertyValue("CRM_Leads", _CRM_Leads, value)
        End Set
    End Property
    <Browsable(False)> _
    <Size(255)> _
    Property AccountName As String
        Get
            Return _AccountName
        End Get
        Set(value As String)
            SetPropertyValue("AccountName", _AccountName, value)
        End Set
    End Property
    <Browsable(False)>
    Property ImportedID As Long
        Get
            Return _ImportedID
        End Get
        Set(value As Long)
            SetPropertyValue("ImportedID", _ImportedID, value)
        End Set
    End Property
    Property Position As String
        Get
            Return _Position
        End Get
        Set(value As String)
            SetPropertyValue("Position", _Position, value)
        End Set
    End Property
    Public Property IsOutlookSync() As Boolean
        Get
            Return _IsOutlookSync
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsOutlookSync", _IsOutlookSync, value)
        End Set
    End Property
    Public Property IsExchangeSync() As Boolean
        Get
            Return _IsExchangeSync
        End Get
        Set(ByVal value As Boolean)
            SetPropertyValue("IsExchangeSync", _IsExchangeSync, value)
        End Set
    End Property
    <Size(-1)> _
    Public Property EntryIDOutlook() As String
        Get
            Return _EntryID_Outlook
        End Get
        Set(ByVal value As String)
            SetPropertyValue("EntryIDOutlook", _EntryID_Outlook, value)
        End Set
    End Property
    <Size(-1)> _
    Property ContactItemFolderEntryID_Outlook As String
        Get
            Return _ContactItemFolderEntryID_Outlook
        End Get
        Set(value As String)
            SetPropertyValue("ContactItemFolderEntryID_Outlook", _ContactItemFolderEntryID_Outlook, value)
        End Set
    End Property
    <Size(-1)> _
    Public Property EntryIDExchange() As String
        Get
            Return _EntryID_Exchange
        End Get
        Set(ByVal value As String)
            SetPropertyValue("EntryIDExchange", _EntryID_Exchange, value)
        End Set
    End Property

    <Size(255)> _
    Property BusinessTelephoneNumber As String
        Get
            Return _BusinessTelephoneNumber
        End Get
        Set(value As String)
            SetPropertyValue("BusinessTelephoneNumber", _BusinessTelephoneNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property BusinessFaxNumber As String
        Get
            Return _BusinessFaxNumber
        End Get
        Set(value As String)
            SetPropertyValue("BusinessFaxNumber", _BusinessFaxNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property HomeFaxNumber As String
        Get
            Return _HomeFaxNumber
        End Get
        Set(value As String)
            SetPropertyValue("HomeFaxNumber", _HomeFaxNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property HomeTelephoneNumber As String
        Get
            Return _HomeTelephoneNumber
        End Get
        Set(value As String)
            SetPropertyValue("HomeTelephoneNumber", _HomeTelephoneNumber, value)
        End Set
    End Property
    <Size(255)> _
    Property MobileTelephoneNumber As String
        Get
            Return _MobileTelephoneNumber
        End Get
        Set(value As String)
            SetPropertyValue("MobileTelephoneNumber", _MobileTelephoneNumber, 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 IsChristmasCard As Boolean
        Get
            Return _IsChristmasCard
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsChristmasCard", _IsChristmasCard, value)
        End Set
    End Property
    Property Title As String
        Get
            Return _Title
        End Get
        Set(value As String)
            SetPropertyValue("Title", _Title, value)
        End Set
    End Property
    Property FullNameOrder As eFullNameOrder
        Get
            Return _FullNameOrder
        End Get
        Set(value As eFullNameOrder)
            SetPropertyValue("FullNameOrder", _FullNameOrder, value)
        End Set
    End Property
    <Size(255)> _
    Property EMailPrivate As String
        Get
            Return _EMailPrivate
        End Get
        Set(value As String)
            SetPropertyValue("EMailPrivate", _EMailPrivate, value)
        End Set
    End Property
    <Size(255)> _
    Property EMail2 As String
        Get
            Return _EMail2
        End Get
        Set(value As String)
            SetPropertyValue("EMail2", _EMail2, value)
        End Set
    End Property
    <Size(255)> _
    Property EMail3 As String
        Get
            Return _EMail3
        End Get
        Set(value As String)
            SetPropertyValue("EMail3", _EMail3, value)
        End Set
    End Property

    <ImmediatePostData> _
    Property Checked As Boolean
        Get
            Return _Checked
        End Get
        Set(value As Boolean)
            SetPropertyValue("Checked", _Checked, value)
        End Set
    End Property
    Property CheckStatus As String
        Get
            Return _CheckStatus
        End Get
        Set(value As String)
            SetPropertyValue("CheckStatus", _CheckStatus, value)
        End Set
    End Property
    Property CheckedDate As Date
        Get
            Return _CheckedDate
        End Get
        Set(value As Date)
            SetPropertyValue("CheckedDate", _CheckedDate, value)
        End Set
    End Property

    Property CropProtectionRegistrationNumber As String
        Get
            Return _CropProtectionRegistrationNumber
        End Get
        Set(value As String)
            SetPropertyValue("CropProtectionRegistrationNumber", _CropProtectionRegistrationNumber, value)
        End Set
    End Property
    Property ChambersRegistrationNumber As String
        Get
            Return _ChambersRegistrationNumber
        End Get
        Set(value As String)
            SetPropertyValue("ChambersRegistrationNumber", _ChambersRegistrationNumber, value)
        End Set
    End Property
    Property ChamberNumber As String
        Get
            Return _ChamberNumber
        End Get
        Set(value As String)
            SetPropertyValue("ChamberNumber", _ChamberNumber, value)
        End Set
    End Property

    <Size(255)> _
    Property IsAssetsHandlingResponsible As Boolean
        Get
            Return _IsAssetsHandlingResponsible
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsAssetsHandlingResponsible", _IsAssetsHandlingResponsible, value)
        End Set
    End Property
    Property IsInvoiceResponsible As Boolean
        Get
            Return _IsInvoiceResponsible
        End Get
        Set(value As Boolean)
            SetPropertyValue("IsInvoiceResponsible", _IsInvoiceResponsible, value)
        End Set
    End Property

    Public Property PrivateVATNumber() As String
        Get
            Return _PrivateVATNumber
        End Get
        Set(ByVal value As String)
            SetPropertyValue("PrivateVATNumber", _PrivateVATNumber, value)
        End Set
    End Property
    Property MotherName As String
        Get
            Return _MotherName
        End Get
        Set(value As String)
            SetPropertyValue("MotherName", _MotherName, value)
        End Set
    End Property
    Property BirthPlace As String
        Get
            Return _BirthPlace
        End Get
        Set(value As String)
            SetPropertyValue("BirthPlace", _BirthPlace, value)
        End Set
    End Property
    Property TAJNumber As String
        Get
            Return _TAJNumber
        End Get
        Set(value As String)
            SetPropertyValue("TAJNumber", _TAJNumber, value)
        End Set
    End Property
    Property IdentityCardNumber As String
        Get
            Return _IdentityCardNumber
        End Get
        Set(value As String)
            SetPropertyValue("IdentityCardNumber", _IdentityCardNumber, value)
        End Set
    End Property
    Property IdentityNumber As String
        Get
            Return _IdentityNumber
        End Get
        Set(value As String)
            SetPropertyValue("IdentityNumber", _IdentityNumber, value)
        End Set
    End Property

    '-----------ReadOnly---------------------
    Overloads ReadOnly Property DisplayName As String
        Get
            If Me.FullNameOrder = eFullNameOrder.eFirstNameLastName Then
                Return String.Format("{0} {1} {2} {3} {4}", Me.Title, Me.FirstName, Me.LastName, Me.MobileTelephoneNumber, Me.Email)
            Else
                Return String.Format("{0} {1} {2} {3} {4}", Me.LastName, Me.FirstName, Me.Title, Me.MobileTelephoneNumber, Me.Email)
            End If
        End Get
    End Property
    ReadOnly Property DisplayNamePostal As String
        Get
            If Me.FullNameOrder = eFullNameOrder.eFirstNameLastName Then
                Return String.Format("{0} {1} {2}", Me.Title, Me.FirstName, Me.LastName)
            Else
                Return String.Format("{0} {1} {2}", Me.LastName, Me.FirstName, Me.Title)
            End If
        End Get
    End Property
    ReadOnly Property SysncTypeImage As Image
        Get
            Dim _ReturnImage As Image = Nothing
            If IsOutlookSync And Not IsExchangeSync Then _ReturnImage = ImageLoader.Instance.GetImageInfo("Outlook2010").Image
            If IsExchangeSync And Not IsOutlookSync Then _ReturnImage = ImageLoader.Instance.GetImageInfo("mail_exchange").Image
            If Not IsOutlookSync And Not IsExchangeSync Then _ReturnImage = ImageLoader.Instance.GetImageInfo("NoImage").Image
            If IsExchangeSync And IsExchangeSync Then _ReturnImage = ImageLoader.Instance.GetImageInfo("selection_recycle").Image

            Return _ReturnImage
        End Get
    End Property

    '--------------------XPCollections-----------------
    <VisibleInListView(False)> _
    ReadOnly Property CRM_Opportunities As XPCollection(Of CRM_Opportunities)
        Get
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                Return New XPCollection(Of CRM_Opportunities)(Session, CriteriaOperator.Parse("Contacts.Oid=?", Me.Oid))
            Else
                Return Nothing
            End If
        End Get
    End Property
    <VisibleInListView(False)> _
    ReadOnly Property CRM_Leads_Activity As XPCollection(Of CRM_Leads_Activity)
        Get
            If Session.IsObjectsLoading = False And Session.IsObjectsSaving = False Then
                If Me.CRM_Leads IsNot Nothing Then
                    Return New XPCollection(Of CRM_Leads_Activity)(Session, CriteriaOperator.Parse("CRM_Leads.Oid=?", Me.CRM_Leads.Oid))
                Else
                    Return Nothing
                End If
            Else
                Return Nothing
            End If
        End Get
    End Property


End Class



