using System;
using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.Data.Filtering;
using System.Collections.Generic;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Xpo;
using DevExpress.Xpo;
using DevExpress.Persistent.BaseImpl;
using System.Runtime.InteropServices;
 
namespace SISBusiness.Module
{
    // For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
    public partial class AuditTrailVCC : ViewController
    {
        public AuditTrailVCC()
        {
            InitializeComponent();
            RegisterActions(components);
            TargetViewType = ViewType.ListView;
            // Target required Views (via the TargetXXX properties) and create their Actions.
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            Frame.GetController<AuditTrailVCC>().aGetAuditTrailC.Active.SetItemValue("", false);
                        
        if( View.Id.Contains("AuditDataItemPersistent")) {
            Frame.GetController<AuditTrailVCC>().aGetAuditTrailC.Active.SetItemValue("", false);
        }
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
        }
        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            base.OnDeactivated();
        }

        private void aGetAuditTrail_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            
            //XPObjectSpace _ocur = View.ObjectSpace as XPObjectSpace;
            //XPCollection<AuditDataItemPersistent> _AuditDataItemPersistent_Collection = default(XPCollection<AuditDataItemPersistent>);
            //XPObjectSpace _onew = (XPObjectSpace)Application.CreateObjectSpace();
            //CollectionSource _CS = new CollectionSource(_onew, typeof(AuditDataItemPersistent));

            //_AuditDataItemPersistent_Collection = AuditedObjectWeakReference.GetAuditTrail(_ocur.Session, View.SelectedObjects[0]);

            //_CS.BeginUpdateCriteria();
            //_CS.Criteria.Clear();
            //_CS.Criteria["First"] = CriteriaOperator.Parse("1=2");
            //_CS.EndUpdateCriteria();

            //if (_AuditDataItemPersistent_Collection != null) {
            //    foreach ( var _AuditDataItemPersistent in _AuditDataItemPersistent_Collection) {
            //        _CS.Add(_onew.GetObject(_AuditDataItemPersistent));
            //    }

            //    e.ShowViewParameters.CreatedView = Application.CreateListView("AuditDataItemPersistent_ListView", _CS, false);
            //    e.ShowViewParameters.NewWindowTarget = NewWindowTarget.Separate;
            //    e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;

            //}
        }
    }
}
