using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Xpo;

namespace Nuvolar.Module.Controllers
{
    // For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/clsDevExpressExpressAppViewControllertopic.aspx.
    public partial class DeliveryNoteOut_VC : ViewController
    {
        public DeliveryNoteOut_VC()
        {
            InitializeComponent();
            // Target required Views (via the TargetXXX properties) and create their Actions.
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // 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 aPrintSelectedDeliveryNoteOuts_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            XPObjectSpace _ocur = View.ObjectSpace as XPObjectSpace;
            DeliveryNoteOutHeader _DeliveryNoteOutHeader = View.SelectedObjects[0] as DeliveryNoteOutHeader;
            

            if (_DeliveryNoteOutHeader.DeliveryNoteOutType.ReportDataV2!=null)
            {
                XAFPrintHelper _XAFPrintHelper = new XAFPrintHelper(_ocur, Frame, _DeliveryNoteOutHeader.DeliveryNoteOutType.ReportDataV2, CriteriaOperator.Parse("DeliveryNoteOutHeader.Oid=?", _DeliveryNoteOutHeader.Oid));
                _XAFPrintHelper.ShowPreviewV2PDF();

                //XtraReport report = ReportDataProvider.ReportsStorage.LoadReport(_DeliveryNoteOutHeader.DeliveryNoteOutType.ReportDataV2);
                //var dataSource = (DevExpress.Persistent.Base.ReportsV2.ISupportCriteria)report.DataSource;
                //dataSource.Criteria = CriteriaOperator.Parse("DeliveryNoteOutHeader.Oid=?", _DeliveryNoteOutHeader.Oid);

                //Frame.GetController<ReportServiceController>().SetupBeforePrint(report, null, null, false, null, false);
                //report.ShowPreview();

            }
        }
    }
}
