using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Printing;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using DemoMasterDetails.Model;
using Prism.Commands;
using Syncfusion.UI.Xaml.Grid;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace DemoMasterDetails
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public DelegateCommand PrintCommand { get; set; }

        public MainPage()
        {
            this.InitializeComponent();
            this.PrintCommand = new DelegateCommand(PrintGrid);
            this.dataGrid.DetailsViewExpanding += DataGrid_DetailsViewExpanding;
        }

        private void DataGrid_DetailsViewExpanding(object sender, GridDetailsViewExpandingEventArgs e)
        {
            var vm = this.DataContext as ViewModel.ViewModel;
            var orderInfo = e.Record as OrderInfo;
            var orderDetails = vm?.OrderDetails.Where(order => order.OrderID == orderInfo?.OrderID);
            e.DetailsViewItemsSource["OrderDetails"] = orderDetails;
        }

        private void PrintGrid()
        {
            this.dataGrid.PrintSettings = new PrintSettings();
            this.dataGrid.PrintSettings.CanPrintStackedHeaders = true;
            this.dataGrid.PrintSettings.PrintPageOrientation = PrintOrientation.Landscape;
            this.dataGrid.PrintSettings.AllowRepeatHeaders = true;
            this.dataGrid.PrintSettings.PrintPageMargin = new Thickness(40);
            this.dataGrid.PrintSettings.PrintManagerBase = new GridPrintManager(this.dataGrid);
            this.dataGrid.PrintSettings.PrintManagerBase.Print();
 
        }
    }
}
