using System;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;

namespace Nuvolar.Module.BusinessObjects.Financial
{
    [DefaultClassOptions, NavigationItem(false), CreatableItem(false), NonPersistent]

    public class PCIEdit : BaseObject
    {
        public PCIEdit(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();

        }
        private LiquidAssets _LiquidAssets;
        private PCIGroup _PCIGroup;
        private string _DocumentNumber;
        private DateTime _DateExecution;
        private double _CurrencyRate;

        [ImmediatePostData]
        public LiquidAssets LiquidAssets
        {
            get { return _LiquidAssets; }
            set
            {
                SetPropertyValue("LiquidAssets", ref _LiquidAssets, value);
                //GLRows.Load();
            }
        }
        public PCIGroup PCIGroup
        {
            get { return _PCIGroup; }
            set { SetPropertyValue("PCIGroup", ref _PCIGroup, value); }
        }
        public DateTime DateExecution
        {
            get { return _DateExecution; }
            set { SetPropertyValue("DateExecution", ref _DateExecution, value); }
        }

        [ImmediatePostData]
        public string DocumentNumber
        {
            get { return _DocumentNumber; }
            set { SetPropertyValue("DocumentNumber", ref _DocumentNumber, value); }
        }

        public XPCollection<GLRows> GLRows
        {
            get
            {
                XPCollection<GLRows> _GRLRows_Nothing = new XPCollection<GLRows>(Session, CriteriaOperator.Parse("1=2"));
                if (this.LiquidAssets == null)
                {
                    return _GRLRows_Nothing;
                }
                if (this.LiquidAssets.LiquidAssetsType == eLiquidAssetsType.NormalBank)

                {
                    GLBank _GLBank = Session.FindObject<GLBank>(CriteriaOperator.Parse("IsEditable=True AND LiquidAssets_Main.Oid= ? AND DocumentNumber=?",
                        this.LiquidAssets.Oid, this.DocumentNumber));
                    if (_GLBank != null)
                    {
                        return _GLBank.GLRows;
                    }
                    else
                    {
                        return _GRLRows_Nothing;
                    }
                }
                else
                {
                    return _GRLRows_Nothing;
                };

            }
        }
    }
}